Reading /dev/cpu/*/msr from userspace: operation not permitted

后端 未结 2 1523
傲寒
傲寒 2021-01-02 18:53

I am trying to write a simple application that can read msr registers, and am running this application from userspace.

I have loaded the msr module and given read p

相关标签:
2条回答
  • 2021-01-02 19:09

    You can see vfs_read:

    ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
    {
        ret = rw_verify_area(READ, file, pos, count);
        if (ret >= 0) {
            ...
            if (file->f_op->read)  // your driver read .
                ret = file->f_op->read(file, buf, count, pos);
            else
                ret = do_sync_read(file, buf, count, pos);
            ....
    
        }
        // here,  if the ret is  13.  your error will be occur.
        return ret;
    }
    
    0 讨论(0)
  • 2021-01-02 19:15

    Changes in the mainline Linux kernel since around 3.7 now require an executable to have capability CAP_SYS_RAWIO to open the MSR device file [2]. Besides loading the MSR kernel module and setting the appropriate file permissions on the msr device file, one must grant the CAP_SYS_RAWIO capability to any user executable that needs access to the MSR driver, using the command below:

    sudo setcap cap_sys_rawio=ep <user_executable>
    
    0 讨论(0)
提交回复
热议问题