Skip to content

Commit d79b6f4

Browse files
committed
procfs: Push down the bkl from ioctl
Push down the bkl from procfs's ioctl main handler to its users. Only three procfs users implement an ioctl (non unlocked) handler. Turn them into unlocked_ioctl and push down the Devil inside. v2: PDE(inode)->data doesn't need to be under bkl v3: And don't forget to git-add the result v4: Use wrappers to pushdown instead of an invasive and error prone handlers surgery. Signed-off-by: Frederic Weisbecker <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: John Kacur <[email protected]> Cc: KAMEZAWA Hiroyuki <[email protected]> Cc: Al Viro <[email protected]> Cc: Alexey Dobriyan <[email protected]>
1 parent 73296bc commit d79b6f4

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

drivers/char/i8k.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/seq_file.h>
2424
#include <linux/dmi.h>
2525
#include <linux/capability.h>
26+
#include <linux/smp_lock.h>
2627
#include <asm/uaccess.h>
2728
#include <asm/io.h>
2829

@@ -82,16 +83,15 @@ module_param(fan_mult, int, 0);
8283
MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
8384

8485
static int i8k_open_fs(struct inode *inode, struct file *file);
85-
static int i8k_ioctl(struct inode *, struct file *, unsigned int,
86-
unsigned long);
86+
static long i8k_ioctl(struct file *, unsigned int, unsigned long);
8787

8888
static const struct file_operations i8k_fops = {
8989
.owner = THIS_MODULE,
9090
.open = i8k_open_fs,
9191
.read = seq_read,
9292
.llseek = seq_lseek,
9393
.release = single_release,
94-
.ioctl = i8k_ioctl,
94+
.unlocked_ioctl = i8k_ioctl,
9595
};
9696

9797
struct smm_regs {
@@ -307,8 +307,8 @@ static int i8k_get_dell_signature(int req_fn)
307307
return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
308308
}
309309

310-
static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
311-
unsigned long arg)
310+
static int
311+
i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
312312
{
313313
int val = 0;
314314
int speed;
@@ -395,6 +395,17 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
395395
return 0;
396396
}
397397

398+
static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
399+
{
400+
long ret;
401+
402+
lock_kernel();
403+
ret = i8k_ioctl_unlocked(fp, cmd, arg);
404+
unlock_kernel();
405+
406+
return ret;
407+
}
408+
398409
/*
399410
* Print the information for /proc/i8k.
400411
*/

drivers/isdn/divert/divert_procfs.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/sched.h>
2020
#include <linux/isdnif.h>
2121
#include <net/net_namespace.h>
22+
#include <linux/smp_lock.h>
2223
#include "isdn_divert.h"
2324

2425

@@ -176,9 +177,7 @@ isdn_divert_close(struct inode *ino, struct file *filep)
176177
/*********/
177178
/* IOCTL */
178179
/*********/
179-
static int
180-
isdn_divert_ioctl(struct inode *inode, struct file *file,
181-
uint cmd, ulong arg)
180+
static int isdn_divert_ioctl_unlocked(struct file *file, uint cmd, ulong arg)
182181
{
183182
divert_ioctl dioctl;
184183
int i;
@@ -257,14 +256,25 @@ isdn_divert_ioctl(struct inode *inode, struct file *file,
257256
return copy_to_user((void __user *)arg, &dioctl, sizeof(dioctl)) ? -EFAULT : 0;
258257
} /* isdn_divert_ioctl */
259258

259+
static long isdn_divert_ioctl(struct file *file, uint cmd, ulong arg)
260+
{
261+
long ret;
262+
263+
lock_kernel();
264+
ret = isdn_divert_ioctl_unlocked(file, cmd, arg);
265+
unlock_kernel();
266+
267+
return ret;
268+
}
269+
260270
static const struct file_operations isdn_fops =
261271
{
262272
.owner = THIS_MODULE,
263273
.llseek = no_llseek,
264274
.read = isdn_divert_read,
265275
.write = isdn_divert_write,
266276
.poll = isdn_divert_poll,
267-
.ioctl = isdn_divert_ioctl,
277+
.unlocked_ioctl = isdn_divert_ioctl,
268278
.open = isdn_divert_open,
269279
.release = isdn_divert_close,
270280
};

net/sunrpc/cache.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,12 +1331,18 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
13311331
return cache_poll(filp, wait, cd);
13321332
}
13331333

1334-
static int cache_ioctl_procfs(struct inode *inode, struct file *filp,
1335-
unsigned int cmd, unsigned long arg)
1334+
static long cache_ioctl_procfs(struct file *filp,
1335+
unsigned int cmd, unsigned long arg)
13361336
{
1337+
long ret;
1338+
struct inode *inode = filp->f_path.dentry->d_inode;
13371339
struct cache_detail *cd = PDE(inode)->data;
13381340

1339-
return cache_ioctl(inode, filp, cmd, arg, cd);
1341+
lock_kernel();
1342+
ret = cache_ioctl(inode, filp, cmd, arg, cd);
1343+
unlock_kernel();
1344+
1345+
return ret;
13401346
}
13411347

13421348
static int cache_open_procfs(struct inode *inode, struct file *filp)
@@ -1359,7 +1365,7 @@ static const struct file_operations cache_file_operations_procfs = {
13591365
.read = cache_read_procfs,
13601366
.write = cache_write_procfs,
13611367
.poll = cache_poll_procfs,
1362-
.ioctl = cache_ioctl_procfs, /* for FIONREAD */
1368+
.unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */
13631369
.open = cache_open_procfs,
13641370
.release = cache_release_procfs,
13651371
};

0 commit comments

Comments
 (0)