From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Domsch Date: Fri, 13 Dec 2002 23:31:03 +0000 Subject: [Linux-ia64] [PATCH] efivars.c locking fixes Message-Id: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-ia64@vger.kernel.org With thanks to Peter Chubb and his preempt work, here's a patch for efivars.c that applies to both 2.4.x and 2.5.x to clean up the SMP locking issues discovered there. The efivar_lock was being held across calls to create_proc_entry(), and worse, kmalloc(). I believe this fixes those. This has been tested on a Big Sur on 2.5.50 and seems to work correctly. This hasn't been tested on 2.4.20 (though it patches, compiles and builds properly, and I expect it works fine), something immediately after efivars_init() finishes crashes and I haven't been able to track it down yet, though I'm pretty certain it's not something in efivars.c. Thanks, Matt -- Matt Domsch Sr. Software Engineer, Lead Engineer, Architect Dell Linux Solutions www.dell.com/linux Linux on Dell mailing lists @ http://lists.us.dell.com --- linux-2.5-ia64/arch/ia64/kernel/efivars.c Fri Dec 13 17:22:01 2002 +++ linux-2.5-ia64-test/arch/ia64/kernel/efivars.c Fri Dec 13 10:33:51 2002 @@ -29,6 +29,9 @@ * * Changelog: * + * 10 Dec 2002 - Matt Domsch + * fix locking per Peter Chubb's findings + * * 25 Mar 2002 - Matt Domsch * move uuid_unparse() to include/asm-ia64/efi.h:efi_guid_unparse() * @@ -73,7 +76,7 @@ MODULE_AUTHOR("Matt Domsch entry = create_proc_entry(short_name, 0600, efi_vars_dir); kfree(short_name); short_name = NULL; if (!new_efivar->entry) return 1; - new_efivar->entry->data = new_efivar; new_efivar->entry->read_proc = efivar_read; new_efivar->entry->write_proc = efivar_write; + spin_lock(&efivars_lock); list_add(&new_efivar->list, &efivar_list); - + spin_unlock(&efivars_lock); return 0; } @@ -326,6 +339,8 @@ efivar_write(struct file *file, const ch kfree(efivar); } + spin_unlock(&efivars_lock); + /* If this is a new variable, set up the proc entry for it. */ if (!found) { efivar_create_proc_entry(utf8_strsize(var_data->VariableName, @@ -336,7 +351,6 @@ efivar_write(struct file *file, const ch kfree(var_data); MOD_DEC_USE_COUNT; - spin_unlock(&efivars_lock); return size; } @@ -351,8 +365,6 @@ efivars_init(void) efi_char16_t *variable_name = kmalloc(1024, GFP_KERNEL); unsigned long variable_name_size = 1024; - spin_lock(&efivars_lock); - printk(KERN_INFO "EFI Variables Facility v%s\n", EFIVARS_VERSION); /* Since efi.c happens before procfs is available, @@ -365,8 +377,6 @@ efivars_init(void) efi_vars_dir = proc_mkdir("vars", efi_dir); - - /* Per EFI spec, the maximum storage allocated for both the variable name and variable data is 1024 bytes. */ @@ -398,7 +408,6 @@ efivars_init(void) } while (status != EFI_NOT_FOUND); kfree(variable_name); - spin_unlock(&efivars_lock); return 0; } @@ -408,17 +417,16 @@ efivars_exit(void) struct list_head *pos, *n; efivar_entry_t *efivar; - spin_lock(&efivars_lock); - + spin_lock(&efivars_lock); list_for_each_safe(pos, n, &efivar_list) { efivar = efivar_entry(pos); remove_proc_entry(efivar->entry->name, efi_vars_dir); list_del(&efivar->list); kfree(efivar); } - remove_proc_entry(efi_vars_dir->name, efi_dir); spin_unlock(&efivars_lock); + remove_proc_entry(efi_vars_dir->name, efi_dir); } module_init(efivars_init);