i386 msr.c devfs support 1/2
PATCH 1/1 i386 msr.c devfs support 1/2
Please let me know if default permissions (644) are not appropriate. Tested on 2-way SMP kernel single CPU system; it correctly rejects access to no-existing CPU.
/dev/cpu/N is not removed on module unload. It is impossible to cleanly unregister directories shared by independent drivers given current devfs implementation (no actual refcounting)
-andrey
arch/i386/kernel/msr.c renamed from arch/i386/kernel/msr.c.devfs +13 -0
@@ -37,6 +37,8 @@#include <linux/major.h> #include <linux/fs.h> +#include <linux/devfs_fs_kernel.h> +#include <asm/processor.h> #include <asm/msr.h> #include <asm/uaccess.h>
@@ -263,17 +265,28 @@ static struct file_operations msr_fops =int __init msr_init (void ) { +int i; +if (register_chrdev (MSR_MAJOR ,"cpu/msr" , &msr_fops)) {printk (KERN_ERR "msr: unable to get major %d for msr\n" ,MSR_MAJOR );return -EBUSY ; } + +for (i =0 ; i <NR_CPUS ; i++) +devfs_mk_cdev (MKDEV (MSR_MAJOR , i),S_IFCHR |S_IRUGO |S_IWUSR , +"cpu/%d/msr" , i);return 0 ; } void __exit msr_exit(void) { +int i; + +for (i =0 ; i <NR_CPUS ; i++) +devfs_remove ("cpu/%d/msr" , i); +unregister_chrdev (MSR_MAJOR ,"cpu/msr" ); }
Quoted 1 line · Andrey Borzenkov
Please let me know if default permissions (644) are not appropriate.
bogus. They should be set to 600. Non-root access to MSRs (even read only) can cause instant lockup/reboot on some CPUs if user tries to read non-existant MSR.
Dave
Signature · 1 line
Dave Jones http://www.codemonkey.org.uk
Quoted 7 lines · Dave Jones
Quoted 1 line · Andrey Borzenkov
Please let me know if default permissions (644) are not appropriate.
bogus. They should be set to 600. Non-root access to MSRs (even read only) can cause instant lockup/reboot on some CPUs if user tries to read non-existant MSR.
update patch attached.
-andrey
arch/i386/kernel/msr.c renamed from tmp/linux-2.6.0-test3/arch/i386/kernel/msr.c +13 -0
@@ -37,6 +37,8 @@#include <linux/major.h> #include <linux/fs.h> +#include <linux/devfs_fs_kernel.h> +#include <asm/processor.h> #include <asm/msr.h> #include <asm/uaccess.h>
@@ -263,17 +265,28 @@ static struct file_operations msr_fops =int __init msr_init (void ) { +int i; +if (register_chrdev (MSR_MAJOR ,"cpu/msr" , &msr_fops)) {printk (KERN_ERR "msr: unable to get major %d for msr\n" ,MSR_MAJOR );return -EBUSY ; } + +for (i =0 ; i <NR_CPUS ; i++) +devfs_mk_cdev (MKDEV (MSR_MAJOR , i),S_IFCHR |S_IRUSR |S_IWUSR , +"cpu/%d/msr" , i);return 0 ; } void __exit msr_exit(void) { +int i; + +for (i =0 ; i <NR_CPUS ; i++) +devfs_remove ("cpu/%d/msr" , i); +unregister_chrdev (MSR_MAJOR ,"cpu/msr" ); }