Messages in this thread Patch in this message | | | Date | Mon, 21 Feb 2000 22:35:52 +0000 (GMT) | From | Tigran Aivazian <> | Subject | [patch-2.3.47] microcode trimming support (+cleanup) |
| |
Hi Linus,
This patch improves /proc/driver/microcode to allow to clear and free the memory used by the saved copy of the microcode by doing something like:
# > /proc/driver/microcode
(or generally by opening it with O_WRONLY). This saves a page per CPU pair and makes some security-conscious humans happy...
Also some minor cleanups in BFS and a typo in mtrr.c
Regards, Tigran.
diff -urN -X dontdiff linux/arch/i386/kernel/microcode.c linux-mc/arch/i386/kernel/microcode.c --- linux/arch/i386/kernel/microcode.c Mon Feb 21 20:55:51 2000 +++ linux-mc/arch/i386/kernel/microcode.c Mon Feb 21 22:27:28 2000 @@ -20,6 +20,9 @@ * Initial release. * 1.01 18 February 2000, Tigran Aivazian <tigran@sco.com> * Added read() support + cleanups. + * 1.02 21 February 2000, Tigran Aivazian <tigran@sco.com> + * Added 'device trimming' support. open(O_WRONLY) zeroes + * and frees the saved copy of applied microcode. */ #include <linux/init.h> @@ -33,7 +36,7 @@ #include <asm/uaccess.h> #include <asm/processor.h> -#define MICROCODE_VERSION "1.01" +#define MICROCODE_VERSION "1.02" MODULE_DESCRIPTION("CPU (P6) microcode update driver"); MODULE_AUTHOR("Tigran Aivazian <tigran@ocston.org>"); @@ -53,7 +56,7 @@ /* * Bits in microcode_status. (31 bits of room for future expansion) */ -#define MICROCODE_IS_OPEN 0 /* set if /dev/microcode is in use */ +#define MICROCODE_IS_OPEN 0 /* set if device is in use */ static unsigned long microcode_status = 0; /* the actual array of microcode blocks, each 2048 bytes */ @@ -76,23 +79,12 @@ static int __init microcode_init(void) { - int size; - proc_microcode = create_proc_entry("microcode", S_IWUSR|S_IRUSR, proc_root_driver); if (!proc_microcode) { printk(KERN_ERR "microcode: can't create /proc/driver/microcode\n"); return -ENOMEM; } proc_microcode->ops = µcode_inops; - size = smp_num_cpus * sizeof(struct microcode); - mc_applied = kmalloc(size, GFP_KERNEL); - if (!mc_applied) { - remove_proc_entry("microcode", proc_root_driver); - printk(KERN_ERR "microcode: can't allocate memory for saved microcode\n"); - return -ENOMEM; - } - memset(mc_applied, 0, size); /* so that reading from offsets corresponding to failed - update makes this obvious */ printk(KERN_INFO "P6 Microcode Update Driver v%s registered\n", MICROCODE_VERSION); return 0; } @@ -100,7 +92,8 @@ static void __exit microcode_exit(void) { remove_proc_entry("microcode", proc_root_driver); - kfree(mc_applied); + if (mc_applied) + kfree(mc_applied); printk(KERN_INFO "P6 Microcode Update Driver v%s unregistered\n", MICROCODE_VERSION); } @@ -119,6 +112,15 @@ if (test_and_set_bit(MICROCODE_IS_OPEN, µcode_status)) return -EBUSY; + if ((file->f_flags & O_ACCMODE) == O_WRONLY) { + proc_microcode->size = 0; + if (mc_applied) { + memset(mc_applied, 0, smp_num_cpus * sizeof(struct microcode)); + kfree(mc_applied); + mc_applied = NULL; + } + } + MOD_INC_USE_COUNT; return 0; @@ -243,6 +245,16 @@ sizeof(struct microcode)); return -EINVAL; } + if (!mc_applied) { + int size = smp_num_cpus * sizeof(struct microcode); + mc_applied = kmalloc(size, GFP_KERNEL); + if (!mc_applied) { + printk(KERN_ERR "microcode: can't allocate memory for saved microcode\n"); + return -ENOMEM; + } + memset(mc_applied, 0, size); + } + lock_kernel(); microcode_num = len/sizeof(struct microcode); microcode = vmalloc(len); diff -urN -X dontdiff linux/arch/i386/kernel/mtrr.c linux-mc/arch/i386/kernel/mtrr.c --- linux/arch/i386/kernel/mtrr.c Mon Feb 21 20:55:51 2000 +++ linux-mc/arch/i386/kernel/mtrr.c Mon Feb 21 21:54:40 2000 @@ -1838,7 +1838,7 @@ proc_root_mtrr = create_proc_entry ("mtrr", S_IWUSR | S_IRUGO, &proc_root); proc_root_mtrr->ops = &proc_mtrr_inode_operations; #endif -#ifdev CONFIG_DEVFS_FS +#ifdef CONFIG_DEVFS_FS devfs_handle = devfs_register (NULL, "cpu/mtrr", 0, DEVFS_FL_DEFAULT, 0, 0, S_IFREG | S_IRUGO | S_IWUSR, 0, 0, &mtrr_fops, NULL); diff -urN -X dontdiff linux/fs/bfs/dir.c linux-mc/fs/bfs/dir.c --- linux/fs/bfs/dir.c Fri Feb 11 20:07:59 2000 +++ linux-mc/fs/bfs/dir.c Mon Feb 21 21:31:29 2000 @@ -76,9 +76,9 @@ } static struct file_operations bfs_dir_operations = { - read: bfs_dir_read, - readdir: bfs_readdir, - fsync: file_fsync, + read: bfs_dir_read, + readdir: bfs_readdir, + fsync: file_fsync, }; extern void dump_imap(const char *, struct super_block *); @@ -261,10 +261,6 @@ lookup: bfs_lookup, link: bfs_link, unlink: bfs_unlink, - symlink: NULL, - mkdir: NULL, - rmdir: NULL, - mknod: NULL, rename: bfs_rename, }; diff -urN -X dontdiff linux/fs/bfs/inode.c linux-mc/fs/bfs/inode.c --- linux/fs/bfs/inode.c Fri Feb 11 20:07:59 2000 +++ linux-mc/fs/bfs/inode.c Mon Feb 21 21:32:06 2000 @@ -209,15 +209,10 @@ static struct super_operations bfs_sops = { read_inode: bfs_read_inode, write_inode: bfs_write_inode, - put_inode: NULL, delete_inode: bfs_delete_inode, - notify_change: NULL, put_super: bfs_put_super, write_super: bfs_write_super, statfs: bfs_statfs, - remount_fs: NULL, - clear_inode: NULL, - umount_begin: NULL }; void dump_imap(const char *prefix, struct super_block * s) @@ -337,7 +332,6 @@ name: "bfs", fs_flags: FS_REQUIRES_DEV, read_super: bfs_read_super, - next: NULL }; #ifdef MODULE
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |