unlocked_ioctl vs normal ioctl

15 c linux synchronization kernel ioctl

在我的驱动程序的file_operations结构中,我有:

struct file_operations Fops = {
  read:    device_read,
  write:   device_write,
  unlocked_ioctl:   device_ioctl,
  ...
};
Run Code Online (Sandbox Code Playgroud)

即没有使用ioctl字段.这是否足以避免Big Kernel Lock并在没有任何同步的情况下进入device_ioctl()?或者我是否必须在代码的用户空间部分更改ioctl()调用?

use*_*904 10

阅读这篇LWN文章:http: //lwn.net/Articles/119652/

在2.6.33和2.6.35 rc之间的某个时间(使用git-diff来找出哪个提交)内核现在只在定义.ioctl时进行WARN.

这是向更明确和细粒度锁定迈进的一步.另请注意,仅更改函数签名和指针将进行编译,但会引入竞争条件的可能性(两个用户空间应用程序同时执行ioctl调用).

  • 从2.6.38(也许更早)开始,.ioctl已经消失了.你现在别无选择,只能使用.unlocked_ioctl. (4认同)

小智 8

嗯,我解决了这个问题.还需要更改device_ioctl函数的签名.没有inode参数,函数也应返回long.就像下面的补丁一样:

-static int st_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd_in, unsigned long arg)
+static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
{
Run Code Online (Sandbox Code Playgroud)

(来自:http://linux.derkeiler.com/Mailing-Lists/Kernel/2008-01/msg06799.html)


Joe*_*sen 8

Andi Kleem 在Linux内核邮件列表上发布了使用ioctlto unlocked_ioctl进行快速和脏的代码转换的方法:

[JANITOR PROPOSAL]将ioctl函数切换为 - > unlocked_ioctl

该配方解释了如何调整函数的参数并插入锁定和解锁调用.