x86 microcode: work_on_cpu and cleanup of the synchronization logic
PATCH 1/1 x86 microcode: work_on_cpu and cleanup of the synchronization logic
From: Dmitry Adamushko <[email protected]>
Subject: x86 microcode: work_on_cpu and cleanup of the synchronization logic
* Solve an issue described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a different way, without resorting to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks require to be run on a target cpu, others will do just fine on any other cpu.
We impose this requirement and update all the relevant places;
* cleanup of the synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu is being updated at any particular moment of time.
In general, there is no need for any additional sync. logic in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
- don't call sysfs_remove_group() from mc_sysdev_add() in case when a proper ucode was not found/loaded.
In general, I think that we shouldn't treat this case as an error. Say, what if a user upgrades manually via /dev/microcode later on? I'd say let's keep sysfs files around.
This also avoids warnings being triggered in some cases (there were a few reports on lkml). e.g. http://lkml.org/lkml/2009/4/16/453 and http://marc.info/?t=123964721700008&r=1&w=2
* some minor cleanups
Remarks:
* perhaps, error-handling need to be made more consistent;
* BUG_ON() in collect_cpu_info_local() and apply_microcode_local()
are signs of paranoia. Remove them?
This would also avoid the need for 'cpu' member in struct collect_for_cpu and remove struct apply_for_cpu altogether.
The reason why apply_for_cpu is there at all, is that gcc spews warnings for void* <-> int translations on my setup. Alternatively, define 'cpu' as long? (long <-> int or also re-define 'cpu' in callbacks' definitions - not good).
arch/x86/include/asm/microcode.h +8 -2
@@ -13,10 +13,16 @@ struct microcode_ops {int (*request_microcode_user) (int cpu,const void __user *buf,size_t size);int (*request_microcode_fw) (int cpu,struct device *device); -void (*apply_microcode) (int cpu); +void (*microcode_fini_cpu) (int cpu); +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +void (*apply_microcode) (int cpu);int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); -void (*microcode_fini_cpu) (int cpu); };struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +0 -10
@@ -17,7 +17,6 @@#include <linux/capability.h> #include <linux/miscdevice.h> #include <linux/firmware.h> -#include <linux/spinlock.h> #include <linux/cpumask.h> #include <linux/pci_ids.h> #include <linux/uaccess.h>
@@ -79,9 +78,6 @@ struct microcode_amd {#define UCODE_CONTAINER_SECTION_HDR 8#define UCODE_CONTAINER_HEADER_SIZE 12 -/* serialize access to the physical write */ -static DEFINE_SPINLOCK (microcode_update_lock); -static struct equiv_cpu_entry *equiv_cpu_table;static int collect_cpu_info_amd (int cpu,struct cpu_signature *csig)
@@ -146,7 +142,6 @@ static int get_matching_microcode(int cpu, void *mc, int rev)static void apply_microcode_amd (int cpu) { -unsigned long flags;u32 rev, dummy;int cpu_num =raw_smp_processor_id ();struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
@@ -158,11 +153,9 @@ static void apply_microcode_amd(int cpu)if (mc_amd ==NULL )return ; -spin_lock_irqsave (µcode_update_lock, flags);wrmsrl (MSR_AMD64_PATCH_LOADER , (u64)(long)&mc_amd->hdr.data_code);/* get patch id after patching */ rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy); -spin_unlock_irqrestore (µcode_update_lock, flags);/* check current patch id and patch's id for match */ if (rev != mc_amd->hdr.patch_id) {
@@ -327,9 +320,6 @@ static int request_microcode_fw(int cpu, struct device *device)const struct firmware *firmware;int ret; -/* We should bind the task to the CPU */ -BUG_ON (cpu !=raw_smp_processor_id ()); - ret =request_firmware (&firmware, fw_name, device);if (ret) {printk (KERN_ERR "microcode: failed to load file %s\n" , fw_name);
arch/x86/kernel/microcode_core.c +132 -92
344 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +0 -19
@@ -75,7 +75,6 @@#include <linux/miscdevice.h> #include <linux/firmware.h> #include <linux/smp_lock.h> -#include <linux/spinlock.h> #include <linux/cpumask.h> #include <linux/uaccess.h> #include <linux/vmalloc.h>
@@ -150,13 +149,9 @@ struct extended_sigtable {#define exttable_size (et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) -/* serialize access to the physical write to MSR 0x79 */ -static DEFINE_SPINLOCK (microcode_update_lock); -static int collect_cpu_info (int cpu_num,struct cpu_signature *csig) {struct cpuinfo_x86 *c = &cpu_data (cpu_num); -unsigned long flags;unsigned int val[2 ];memset (csig,0 ,sizeof (*csig));
@@ -176,15 +171,11 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig) csig->pf =1 << ((val[1 ] >>18 ) &7 ); } -/* serialize access to the physical write to MSR 0x79 */ -spin_lock_irqsave (µcode_update_lock, flags); -wrmsr (MSR_IA32_UCODE_REV ,0 ,0 );/* see notes above for revision 1.07. Apparent chip bug */ sync_core ();/* get the current revision from MSR 0x8B */ rdmsr (MSR_IA32_UCODE_REV , val[0 ], csig->rev); -spin_unlock_irqrestore (µcode_update_lock, flags);pr_debug ("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n" , csig->sig, csig->pf, csig->rev);
@@ -322,7 +313,6 @@ static void apply_microcode(int cpu) {struct microcode_intel *mc_intel;struct ucode_cpu_info *uci; -unsigned long flags;unsigned int val[2 ];int cpu_num;
@@ -336,9 +326,6 @@ static void apply_microcode(int cpu)if (mc_intel ==NULL )return ; -/* serialize access to the physical write to MSR 0x79 */ -spin_lock_irqsave (µcode_update_lock, flags); -/* write microcode via MSR 0x79 */ wrmsr(MSR_IA32_UCODE_WRITE, (unsigned long) mc_intel->bits,
@@ -351,7 +338,6 @@ static void apply_microcode(int cpu)/* get the current revision from MSR 0x8B */ rdmsr (MSR_IA32_UCODE_REV , val[0 ], val[1 ]); -spin_unlock_irqrestore (µcode_update_lock, flags);if (val[1 ] != mc_intel->hdr.rev) { printk(KERN_ERR "microcode: CPU%d update from revision " "0x%x to 0x%x failed\n",
@@ -445,8 +431,6 @@ static int request_microcode_fw(int cpu, struct device *device)const struct firmware *firmware;int ret; -/* We should bind the task to the CPU */ -BUG_ON (cpu !=raw_smp_processor_id ());sprintf (name,"intel-ucode/%02x-%02x-%02x" , c->x86, c->x86_model, c->x86_mask); ret =request_firmware (&firmware, name, device);
@@ -470,9 +454,6 @@ static int get_ucode_user(void *to, const void *from, size_t n)static int request_microcode_user (int cpu,const void __user *buf,size_t size) { -/* We should bind the task to the CPU */ -BUG_ON (cpu !=raw_smp_processor_id ()); -return generic_load_microcode (cpu, (void *)buf, size, &get_ucode_user); }
Quoted 2 lines · Dmitry Adamushko
From: Dmitry Adamushko <[email protected]>
Subject: x86 microcode:work_on_cpuand cleanup of the synchronization logic
Note, this does not apply cleanly to latest -git anymore, due to this fixlet for the warnings:
0917798: x86: fix microcode driver newly spewing warnings
Mind resending with that resolved?
arch/x86/include/asm/microcode.h
Quoted 1 line
arch/x86/include/asm/microcode.h +0
-0
( Patch submission nitpick: please always include a diffstat. Thanks! )
Ingo
The version below is based on the latest -git.
From: Dmitry Adamushko <[email protected]>
Subject: x86 microcode: work_on_cpu and cleanup of the synchronization logic
* Solve an issue described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a different way, without resorting to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks require to be run on a target cpu, others will do just fine on any other cpu.
We impose this requirement and update all the relevant places;
* cleanup of the synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu is being updated at any particular moment of time.
In general, there is no need for any additional sync. logic in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
* some minor cleanups
Remarks:
* BUG_ON() in collect_cpu_info_local() and apply_microcode_local() are signs of paranoia. Remove them?
This would also avoid the need for 'cpu' member in struct collect_for_cpu and remove struct apply_for_cpu altogether.
The reason why apply_for_cpu is there at all, is that gcc spews warnings for void* <-> int translations on my setup. Alternatively, define 'cpu' as long? (long <-> int or also re-define 'cpu' in callbacks' definitions -> not nice).
arch/x86/include/asm/microcode.h +8 -2
@@ -13,10 +13,16 @@ struct microcode_ops {int (*request_microcode_user) (int cpu,const void __user *buf,size_t size);int (*request_microcode_fw) (int cpu,struct device *device); -void (*apply_microcode) (int cpu); +void (*microcode_fini_cpu) (int cpu); +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +void (*apply_microcode) (int cpu);int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); -void (*microcode_fini_cpu) (int cpu); };struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +0 -10
@@ -17,7 +17,6 @@#include <linux/capability.h> #include <linux/miscdevice.h> #include <linux/firmware.h> -#include <linux/spinlock.h> #include <linux/cpumask.h> #include <linux/pci_ids.h> #include <linux/uaccess.h>
@@ -79,9 +78,6 @@ struct microcode_amd {#define UCODE_CONTAINER_SECTION_HDR 8#define UCODE_CONTAINER_HEADER_SIZE 12 -/* serialize access to the physical write */ -static DEFINE_SPINLOCK (microcode_update_lock); -static struct equiv_cpu_entry *equiv_cpu_table;static int collect_cpu_info_amd (int cpu,struct cpu_signature *csig)
@@ -146,7 +142,6 @@ static int get_matching_microcode(int cpu, void *mc, int rev)static void apply_microcode_amd (int cpu) { -unsigned long flags;u32 rev, dummy;int cpu_num =raw_smp_processor_id ();struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
@@ -158,11 +153,9 @@ static void apply_microcode_amd(int cpu)if (mc_amd ==NULL )return ; -spin_lock_irqsave (µcode_update_lock, flags);wrmsrl (MSR_AMD64_PATCH_LOADER , (u64)(long)&mc_amd->hdr.data_code);/* get patch id after patching */ rdmsr (MSR_AMD64_PATCH_LEVEL , rev, dummy); -spin_unlock_irqrestore (µcode_update_lock, flags);/* check current patch id and patch's id for match */ if (rev != mc_amd->hdr.patch_id) {
@@ -327,9 +320,6 @@ static int request_microcode_fw(int cpu, struct device *device)const struct firmware *firmware;int ret; -/* We should bind the task to the CPU */ -BUG_ON (cpu !=raw_smp_processor_id ()); - ret =request_firmware (&firmware, fw_name, device);if (ret) {printk (KERN_ERR "microcode: failed to load file %s\n" , fw_name);
arch/x86/kernel/microcode_core.c +133 -90
343 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +0 -19
@@ -75,7 +75,6 @@#include <linux/miscdevice.h> #include <linux/firmware.h> #include <linux/smp_lock.h> -#include <linux/spinlock.h> #include <linux/cpumask.h> #include <linux/uaccess.h> #include <linux/vmalloc.h>
@@ -150,13 +149,9 @@ struct extended_sigtable {#define exttable_size (et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) -/* serialize access to the physical write to MSR 0x79 */ -static DEFINE_SPINLOCK (microcode_update_lock); -static int collect_cpu_info (int cpu_num,struct cpu_signature *csig) {struct cpuinfo_x86 *c = &cpu_data (cpu_num); -unsigned long flags;unsigned int val[2 ];memset (csig,0 ,sizeof (*csig));
@@ -176,15 +171,11 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig) csig->pf =1 << ((val[1 ] >>18 ) &7 ); } -/* serialize access to the physical write to MSR 0x79 */ -spin_lock_irqsave (µcode_update_lock, flags); -wrmsr (MSR_IA32_UCODE_REV ,0 ,0 );/* see notes above for revision 1.07. Apparent chip bug */ sync_core ();/* get the current revision from MSR 0x8B */ rdmsr (MSR_IA32_UCODE_REV , val[0 ], csig->rev); -spin_unlock_irqrestore (µcode_update_lock, flags);pr_debug ("microcode: collect_cpu_info : sig=0x%x, pf=0x%x, rev=0x%x\n" , csig->sig, csig->pf, csig->rev);
@@ -322,7 +313,6 @@ static void apply_microcode(int cpu) {struct microcode_intel *mc_intel;struct ucode_cpu_info *uci; -unsigned long flags;unsigned int val[2 ];int cpu_num;
@@ -336,9 +326,6 @@ static void apply_microcode(int cpu)if (mc_intel ==NULL )return ; -/* serialize access to the physical write to MSR 0x79 */ -spin_lock_irqsave (µcode_update_lock, flags); -/* write microcode via MSR 0x79 */ wrmsr(MSR_IA32_UCODE_WRITE, (unsigned long) mc_intel->bits,
@@ -351,7 +338,6 @@ static void apply_microcode(int cpu)/* get the current revision from MSR 0x8B */ rdmsr (MSR_IA32_UCODE_REV , val[0 ], val[1 ]); -spin_unlock_irqrestore (µcode_update_lock, flags);if (val[1 ] != mc_intel->hdr.rev) { printk(KERN_ERR "microcode: CPU%d update from revision " "0x%x to 0x%x failed\n",
@@ -445,8 +431,6 @@ static int request_microcode_fw(int cpu, struct device *device)const struct firmware *firmware;int ret; -/* We should bind the task to the CPU */ -BUG_ON (cpu !=raw_smp_processor_id ());sprintf (name,"intel-ucode/%02x-%02x-%02x" , c->x86, c->x86_model, c->x86_mask); ret =request_firmware (&firmware, name, device);
@@ -470,9 +454,6 @@ static int get_ucode_user(void *to, const void *from, size_t n)static int request_microcode_user (int cpu,const void __user *buf,size_t size) { -/* We should bind the task to the CPU */ -BUG_ON (cpu !=raw_smp_processor_id ()); -return generic_load_microcode (cpu, (void *)buf, size, &get_ucode_user); }
2009/4/21 Dmitry Adamushko <[email protected]>:
Quoted 2 lines
The version below is based on the latest -git.
Sorry, forgot to add a diif-stat.
arch/x86/include/asm/microcode.h | 10 ++- arch/x86/kernel/microcode_amd.c | 10 -- arch/x86/kernel/microcode_core.c | 223 ++++++++++++++++++++++--------------- arch/x86/kernel/microcode_intel.c | 19 --- 4 files changed, 141 insertions(+), 121 deletions(-)
There are about 20 new comment lines.
Signature · 2 lines
Best regards, Dmitry Adamushko
Quoted 5 lines · Dmitry Adamushko
arch/x86/kernel/microcode_core.c +5
-0+static long collect_cpu_info_local (void *arg) +{ +struct collect_for_cpu *cfc = arg; + +BUG_ON (cfc->cpu !=raw_smp_processor_id ());
arch/x86/kernel/microcode_core.c MODULE_LICENSE("GPL"); · line 144
Quoted 10 lines
arch/x86/kernel/microcode_core.c +10
-0+ +return microcode_ops->collect_cpu_info (cfc->cpu, cfc->cpu_sig); +} + +static int collect_cpu_info_on_target (int cpu,struct cpu_signature *cpu_sig) +{ +struct collect_for_cpu cfc = { .cpu_sig = cpu_sig, .cpu = cpu }; + +return work_on_cpu (cpu, collect_cpu_info_local, &cfc); +}
Couldnt this be done without work_on_cpu(), by using smp_call_function()?
Ingo
2009/4/22 Ingo Molnar <[email protected]>:
Quoted 13 lines · Dmitry Adamushko
Quoted 11 lines
arch/x86/kernel/microcode_core.c +10
-0+static long collect_cpu_info_local (void *arg) +{ +struct collect_for_cpu *cfc = arg; + +BUG_ON (cfc->cpu !=raw_smp_processor_id ()); + +return microcode_ops->collect_cpu_info (cfc->cpu, cfc->cpu_sig); +} + +static int collect_cpu_info_on_target (int cpu,struct cpu_signature *cpu_sig)
Quoted 8 lines
arch/x86/kernel/microcode_core.c MODULE_LICENSE("GPL"); · line 144
Quoted 5 lines
arch/x86/kernel/microcode_core.c +5
-0+{ +struct collect_for_cpu cfc = { .cpu_sig = cpu_sig, .cpu = cpu }; + +return work_on_cpu (cpu, collect_cpu_info_local, &cfc); +}Couldnt this be done without
work_on_cpu(), by usingsmp_call_function()?
It should be definitely possible. Will send an updated version.
p.s. grrr... this idea should have come into my mind in the first place :-/
Quoted 3 lines
Ingo
Signature · 2 lines
Best regards, Dmitry Adamushko
Quoted 23 lines · Dmitry Adamushko
2009/4/22 Ingo Molnar <[email protected]>:
Quoted 13 lines · Dmitry Adamushko
Quoted 11 lines
arch/x86/kernel/microcode_core.c +10
-0+static long collect_cpu_info_local (void *arg) +{ +struct collect_for_cpu *cfc = arg; + +BUG_ON (cfc->cpu !=raw_smp_processor_id ()); + +return microcode_ops->collect_cpu_info (cfc->cpu, cfc->cpu_sig); +} + +static int collect_cpu_info_on_target (int cpu,struct cpu_signature *cpu_sig)Quoted 8 lines
arch/x86/kernel/microcode_core.c MODULE_LICENSE("GPL"); · line 144
Quoted 5 lines
arch/x86/kernel/microcode_core.c +5
-0+{ +struct collect_for_cpu cfc = { .cpu_sig = cpu_sig, .cpu = cpu }; + +return work_on_cpu (cpu, collect_cpu_info_local, &cfc); +}Couldnt this be done without
work_on_cpu(), by usingsmp_call_function()?
Quoted 3 lines
It should be definitely possible. Will send an updated version.
p.s. grrr... this idea should have come into my mind in the first place :-/
well you made all the hard work of tightening all the locking to make this all real easy, right?
Ingo
arch/x86/kernel/microcode_core.c static int mc_sysdev_add(struct sys_device *sys_dev) · line 404
Quoted 4 lines · Dmitry Adamushko
arch/x86/kernel/microcode_core.c +4
-0+microcode_init_cpu (cpu); +if (!uci->valid) { +WARN_ON (1 ); + err =-1
ahem :-)
Ingo
Version 3
diff with v.2
- use smp_call_function_single() instead of work_on_cpu() as suggested by Ingo;
- add 'enum ucode_state' as return value of request_microcode_{fw,user}
- minor cleanups
From: Dmitry Adamushko <[email protected]>
Subject: x86 microcode: smp_call_function_single() and cleanup of synchronization logic
* Solve an issue described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a different way, without resorting to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks must run on a target cpu, others will do just fine on any other. smp_call_function_single() is used to run these callbacks on a target cpu.
* cleanup of synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu is being updated at any particular moment of time.
In general, there is no need for any additional sync. mechanism in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
* use 'enum ucode_state' as return value of request_microcode_{fw,user} to
gain more flexibility by distinguishing between real error cases and situations when an appropriate ucode was not found (which is not an error per-se).
* some minor cleanups
arch/x86/include/asm/microcode.h | 19 ++- arch/x86/kernel/microcode_amd.c | 58 +++----- arch/x86/kernel/microcode_core.c | 261 ++++++++++++++++++++++--------------- arch/x86/kernel/microcode_intel.c | 74 ++++------- 4 files changed, 220 insertions(+), 192 deletions(-)
(some part of '+' is taken by comments)
arch/x86/include/asm/microcode.h +15 -4
@@ -9,14 +9,25 @@ struct cpu_signature {struct device ; +enum ucode_state {UCODE_ERROR ,UCODE_OK ,UCODE_NFOUND }; +struct microcode_ops { -int (*request_microcode_user) (int cpu,const void __user *buf,size_t size); -int (*request_microcode_fw) (int cpu,struct device *device); +enum ucode_state (*request_microcode_user) (int cpu, +const void __user *buf,size_t size); -void (*apply_microcode) (int cpu); +enum ucode_state (*request_microcode_fw) (int cpu, +struct device *device); -int (*collect_cpu_info) (int cpu,struct cpu_signature *csig);void (*microcode_fini_cpu) (int cpu); + +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +int (*apply_microcode) (int cpu); +int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); };struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +22 -36
148 lines not on this page · raw message
arch/x86/kernel/microcode_core.c +158 -103
408 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +25 -49
177 lines not on this page · raw message
Quoted 7 lines · Dmitry Adamushko
Version 3
diff with v.2
- use
smp_call_function_single()instead ofwork_on_cpu()as suggested by Ingo;
- add 'enumucode_state' as return value of request_microcode_{fw,user}
- minor cleanups
This version looks really nice structurally. What type of testing have you done on the patch, on what CPU type?
Thanks,
Ingo
2009/4/23 Ingo Molnar <[email protected]>:
Quoted 13 lines · Dmitry Adamushko
Quoted 8 lines
Version 3
diff with v.2
- use
smp_call_function_single()instead ofwork_on_cpu()as suggested by Ingo;
- add 'enumucode_state' as return value of request_microcode_{fw,user}
- minor cleanupsThis version looks really nice structurally. What type of testing have you done on the patch, on what CPU type?
Quite limited testing. It looks like there is no newer ucode availble for my dual-core Intel Core2 Duo (Thinkpad R60) so what I did is as follows:
- change update_match_revision() in microcode_intel.c in a way that allows loading of a ucode with a revision == the current revision (rev. 0x57 in my case). From the POV of the microcode module it nevertheless looks like an update;
- update via /dev/microcode (CONFIG_MICROCODE_OLD_INTERFACE) with a .dat file;
- suspend -> resume (reload of ucode via cpu-callbacks)
These tests worked for me.
Obviously, it'd be nice if more people could give it a try (e.g. update with a firmware image and also on AMD - although the changes in microcode_amd.c are quite straightforward).
p.s. argh... just noticed that the following line is redundant in microcode_core.c (forgot to remove it)
+enum { UCODE_UPDATE_ERR, UCODE_UPDATE_OK, UCODE_UPDATE_NAVAIL };
Quoted 5 lines
Thanks,
Ingo
Signature · 2 lines
Best regards, Dmitry Adamushko
Quoted 12 lines · Dmitry Adamushko
2009/4/23 Ingo Molnar <[email protected]>:
Quoted 11 lines · Dmitry Adamushko
Quoted 8 lines
Version 3
diff with v.2
- use
smp_call_function_single()instead ofwork_on_cpu()as suggested by Ingo;
- add 'enumucode_state' as return value of request_microcode_{fw,user}
- minor cleanupsThis version looks really nice structurally.
Yes, it looks the right way to go to me too.
Quoted 10 lines
Quoted 1 line
What type of testing have you done on the patch, on what CPU type?
Quite limited testing. It looks like there is no newer ucode availble for my dual-core Intel Core2 Duo (Thinkpad R60) so what I did is as follows:
- change
update_match_revision()inmicrocode_intel.cin a way that allows loading of a ucode with a revision == the current revision (rev.0x57in my case). From the POV of the microcode module it nevertheless looks like an update;
My P4 Xeon and Core2s and Atom all want newer microcode from the latest microcode.dat, and your version seems to work fine on them.
Quoted 6 lines
- update via
/dev/microcode(CONFIG_MICROCODE_OLD_INTERFACE) with a .dat file;- suspend -> resume (reload of ucode via cpu-callbacks)
These tests worked for me.
Yes, and I've also tried #if 0'ing the MICROCODE_OLD_INTERFACE code, converting the microcode.dat to binary, and placing that in /lib/firmware/intel-ucode/06-0f-0a or wherever: the firmware interface seems to be working too.
Quoted 4 lines
Obviously, it'd be nice if more people could give it a try (e.g. update with a firmware image and also on AMD - although the changes in
microcode_amd.care quite straightforward).
But like you I don't have an AMD to test.
And just like last time I came here, I find there are more alternative ways through all this than I'm familiar with, and have time to test:
device versus firmware, Intel versus AMD, startup versus resume versus online, builtin versus modular. I get easily confused without more time to spend on it.
That SYSTEM_RUNNING test you've flagged with "--dimm. Review this case":
yes, that's still necessary for when CONFIG_MICROCODE=y (and no initrd?), as I have - trying to get the firmware at that point will hang. I did try changing module_init(microcode_init) to late_initcall(microcode_init), but that didn't solve it. And skipping out at that point does leave CPU0 not updated. But you've not made anything worse there, and most people will have CONFIG_MICROCODE=m.
Quoted 5 lines
p.s. argh... just noticed that the following line is redundant in
microcode_core.c(forgot to remove it)+enum {
UCODE_UPDATE_ERR,UCODE_UPDATE_OK,UCODE_UPDATE_NAVAIL};
A couple of things that worried me.
I guess your mutex Synchronization works out, but are interrupts still disabled around the critical wrmsr()s, wherever they're getting called from?
And you've a habit of returning -1 in error cases, which later gets muddled in with errnos, so that it would amount to -EPERM, which is probably not what you want.
Hugh
2009/4/23 Hugh Dickins <[email protected]>:
Quoted 9 lines · Dmitry Adamushko
Quoted 5 lines
[ ... ]
- changeupdate_match_revision()inmicrocode_intel.cin a way that allows loading of a ucode with a revision == the current revision (rev.0x57in my case). From the POV of the microcode module it nevertheless looks like an update;My P4 Xeon and Core2s and Atom all want newer microcode from the latest microcode.dat, and your version seems to work fine on them.
Thanks for the tests and review!
Quoted 9 lines
[ ... ]
That
SYSTEM_RUNNINGtest you've flagged with "--dimm. Review this case":
yes, that's still necessary for whenCONFIG_MICROCODE=y(and no initrd?), as I have - trying to get the firmware at that point will hang. I did try changingmodule_init(microcode_init)tolate_initcall(microcode_init), but that didn't solve it. And skipping out at that point does leave CPU0 not updated. But you've not made anything worse there, and most people will haveCONFIG_MICROCODE=m.
Yeah. Then at least for the sake of consistency it makes sense to consider doing some kind of delayed update for CPU0 in this case. Will check.
Quoted 11 lines
Quoted 5 lines
p.s. argh... just noticed that the following line is redundant in
microcode_core.c(forgot to remove it)+enum {
UCODE_UPDATE_ERR,UCODE_UPDATE_OK,UCODE_UPDATE_NAVAIL};A couple of things that worried me.
I guess your mutex Synchronization works out, but are interrupts still disabled around the critical wrmsr()s, wherever they're getting called from?
Yes, *msr() calls are only done from functions that are now being called via smp_call_function_single(). The later seems to always do it with disabled interrupts. The only exception is mc_sysdev_resume() calling ->apply_microcode() directly but this one in turn is always called with disabled interrupts.
But now that you mentioned it I wonder if we may actually need a spinlock there... can we have multi-threaded cpus/cores with (all | some) shared msr registers?
Quoted 3 lines
And you've a habit of returning -1 in error cases, which later gets muddled in with errnos, so that it would amount to
-EPERM, which is probably not what you want.
Indeed, will fix. Thanks!
Quoted 3 lines
Hugh
Signature · 2 lines
Best regards, Dmitry Adamushko
Quoted 12 lines · Dmitry Adamushko
2009/4/23 Hugh Dickins <[email protected]>:
Quoted 4 lines
I guess your mutex Synchronization works out, but are interrupts still disabled around the critical wrmsr()s, wherever they're getting called from?
Yes,
*msr()calls are only done from functions that are now being called viasmp_call_function_single(). The later seems to always do it with disabled interrupts. The only exception ismc_sysdev_resume()calling ->apply_microcode() directly but this one in turn is always called with disabled interrupts.
Quoted 3 lines
But now that you mentioned it I wonder if we may actually need a spinlock there... can we have multi-threaded cpus/cores with (all | some) shared msr registers?
Good thinking, yes we can and do, unless I'm misinterpreting the evidence. Though P4 Xeon and Atom startup messages give the opposite impression, claiming to update all cpus from lower revision, more careful tests starting from "maxcpus=1" and then "echo 1 >online" (which, unless you've fiddled around putting the microcode_ctl'ed microcode.dat into /lib/firmware/intel-ucode/wherever, isn't able to update at online time on Intel) shows that the later onlined siblings already have the updated microcode applied to their previously onlined siblings. Which isn't surprising, but I'd been lulled into thinking the opposite by the startup sequence.
Please add "HT versus not" to my earlier list of confusions.
microcode_mutex still covers most cases: is it the case of onlining two threads at the same time that slips through? Is that permitted at the outer level? Though even if it is, I'd feel safest to have the spin_lock_irqsaves back (or if not, comment to say why not needed).
Hugh
2009/4/24 Hugh Dickins <[email protected]>:
Quoted 17 lines · Dmitry Adamushko
Quoted 12 lines
2009/4/23 Hugh Dickins <[email protected]>:
Quoted 4 lines
I guess your mutex Synchronization works out, but are interrupts still disabled around the critical wrmsr()s, wherever they're getting called from?
Yes,
*msr()calls are only done from functions that are now being called viasmp_call_function_single(). The later seems to always do it with disabled interrupts. The only exception ismc_sysdev_resume()calling ->apply_microcode() directly but this one in turn is always called with disabled interrupts.Quoted 3 lines
But now that you mentioned it I wonder if we may actually need a spinlock there... can we have multi-threaded cpus/cores with (all | some) shared msr registers?
Quoted 10 lines
Good thinking, yes we can and do, unless I'm misinterpreting the evidence. Though P4 Xeon and Atom startup messages give the opposite impression, claiming to update all cpus from lower revision, more careful tests starting from "maxcpus=1" and then "echo 1 >online" (which, unless you've fiddled around putting the microcode_ctl'ed microcode.dat into
/lib/firmware/intel-ucode/wherever, isn't able to update at online time on Intel) shows that the later onlined siblings already have the updated microcode applied to their previously onlined siblings. Which isn't surprising, but I'd been lulled into thinking the opposite by the startup sequence.
Ah, stupid me :-/ These differences in behavior during the startup and the later update reveal a real bug in my patch.
this part:
mutex_lock(µcode_mutex);
error = sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver); mutex_unlock(µcode_mutex);
sysdev_driver_register() calls mc_sysdev_driver's ->add() (which is mc_sysdev_add()) for each cpu in a loop. Obviously, "microcode_mutex" can't help to serialize these calls, oops. A very obvious thing but I missed it.
Quoted 6 lines
Please add "HT versus not" to my earlier list of confusions.
microcode_mutexstill covers most cases: is it the case of onlining two threads at the same time that slips through? Is that permitted at the outer level?
If the threads are onlined with cpu_up() then it should be ok - no concurrent cpu_up()s are allowed. I'll check it out.
Quoted 2 lines
Though even if it is, I'd feel safest to have
thespin_lock_irqsavesback (or if not, comment to say why not needed).
I'll verify regarding the initialization of HT threads (I'd imagine that it's indeed via cpu_up(), at the very least for the sake of consistency as they pretend to be 'normal' cpus to upper layers, e.g. can be offline/online-ed).
I'm also thinking if the synchronization with "microcode_mutex" is way too strong/restrictive in this case. Perhaps we actually can add some parallelism here (with spinlocks in arch-specific parts only where necessary).
On the other hand, I think that we can optimize cases when a few cpus are being updated one after another (upon modprobe microcode or writing into /dev/microcode).
Assumption: most of the CPUs (maybe with an exception of the boot-cpu when its ucode is updated by BIOS) upgrade from revisions A to B, where A and B are the same for all of them (well, at least B -- the most recent one [*]).
Then why bother loading/traversing firmware (or traversing .dat files) for each of them?
[*] btw., are all CPUs on SMP systems similar wrt model, stepping?
Even if not, we could do some caching so that if cpu-2 asks for intel-ucode/06-0f-0a and we know that cpu-1 has just done the same and still has a proper ucode in its buffer, then we just make a copy.
Quoted 3 lines
Hugh
Signature · 2 lines
Best regards, Dmitry Adamushko
Quoted 10 lines · Dmitry Adamushko
Assumption: most of the CPUs (maybe with an exception of the boot-cpu when its ucode is updated by BIOS) upgrade from revisions A to B, where A and B are the same for all of them (well, at least B -- the most recent one [*]).
Then why bother loading/traversing firmware (or traversing .dat files) for each of them?
[*] btw., are all CPUs on SMP systems similar wrt model, stepping?
I'm not an authority on these matters, but I think it's true to say:
that's almost always the case in practice, and some vendors refuse to support combinations of non-identical CPUs; but it's not necessarily the case. I think there was a product from one vendor (SGI??) which most commonly had a mixture.
Quoted 4 lines
Even if not, we could do some caching so that if cpu-2 asks for intel-ucode/06-0f-0a and we know that cpu-1 has just done the same and still has a proper ucode in its buffer, then we just make a copy.
Okay, but don't spend too much code and ingenuity upon it. And note that when Intel get around to it (and the distros have caught up), they will be moving away from the all-in-one /etc/microcode.dat MICROCODE_OLD_INTERFACE, to the /lib/firmware/intel-ucode/06-0f-0a style - so I don't think optimizing .dat read time is worth much.
Indeed, MICROCODE_OLD_INTERFACE is driven by /sbin/microcode_ctl anyway, I don't think you should be second-guessing what it might feed you.
Hugh
2009/4/24 Dmitry Adamushko <[email protected]>:
Quoted 34 lines
2009/4/24 Hugh Dickins <[email protected]>:
Quoted 17 lines · Dmitry Adamushko
Quoted 12 lines
2009/4/23 Hugh Dickins <[email protected]>:
Quoted 4 lines
I guess your mutex Synchronization works out, but are interrupts still disabled around the critical wrmsr()s, wherever they're getting called from?
Yes,
*msr()calls are only done from functions that are now being called viasmp_call_function_single(). The later seems to always do it with disabled interrupts. The only exception ismc_sysdev_resume()calling ->apply_microcode() directly but this one in turn is always called with disabled interrupts.Quoted 3 lines
But now that you mentioned it I wonder if we may actually need a spinlock there... can we have multi-threaded cpus/cores with (all | some) shared msr registers?
Quoted 10 lines
Good thinking, yes we can and do, unless I'm misinterpreting the evidence. Though P4 Xeon and Atom startup messages give the opposite impression, claiming to update all cpus from lower revision, more careful tests starting from "maxcpus=1" and then "echo 1 >online" (which, unless you've fiddled around putting the microcode_ctl'ed microcode.dat into
/lib/firmware/intel-ucode/wherever, isn't able to update at online time on Intel) shows that the later onlined siblings already have the updated microcode applied to their previously onlined siblings. Which isn't surprising, but I'd been lulled into thinking the opposite by the startup sequence.Ah, stupid me :-/ These differences in behavior during the startup and the later update reveal a real bug in my patch.
this part:
Quoted 8 lines
mutex_lock(µcode_mutex);
error =sysdev_driver_register(&cpu_sysdev_class, &mc_sysdev_driver);mutex_unlock(µcode_mutex);
sysdev_driver_register()calls mc_sysdev_driver's ->add() (which ismc_sysdev_add()) for each cpu in a loop. Obviously, "microcode_mutex" can't help to serialize these calls, oops. A very obvious thing but I missed it.
Well, never mind about this one. I might have really been in an altered state of mind and now need to wait until it comes back to (let's call it) normality.
All ucode operations are synchronous so obviously we don't need to serialize actions that run sequentially one after another. Sorry for the noise here.
But then I wonder why behavior (the fact that all threads seem to upgrade to a newer version during the startup but they seem to already be 'up-to-date' if onlined later) during the startup is different... Too pity that I can't see it with my setups (heh, I perhaps could play with it by actually downgrading cpus to older ucode).
Signature · 2 lines
Best regards, Dmitry Adamushko
Quoted 13 lines · Dmitry Adamushko
2009/4/24 Dmitry Adamushko <[email protected]>:
Quoted 12 lines
2009/4/24 Hugh Dickins <[email protected]>:
Quoted 11 lines
Good thinking, yes we can and do, unless I'm misinterpreting the evidence. Though P4 Xeon and Atom startup messages give the opposite impression, claiming to update all cpus from lower revision, more careful tests starting from "maxcpus=1" and then "echo 1 >online" (which, unless you've fiddled around putting the microcode_ctl'ed microcode.dat into
/lib/firmware/intel-ucode/wherever, isn't able to update at online time on Intel) shows that the later onlined siblings already have the updated microcode applied to their previously onlined siblings. Which isn't surprising, but I'd been lulled into thinking the opposite by the startup sequence.
...
Quoted 4 lines
But then I wonder why behavior (the fact that all threads seem to upgrade to a newer version during the startup but they seem to already be 'up-to-date' if onlined later) during the startup is different...
I believe it's because the module_init microcode_init() calls sysdev_driver_register(), which does mc_sysdev_add() of (all possible?) cpus, which for online cpus calls microcode_init_cpu(), which does collect_cpu_info() then, if SYSTEM_RUNNING, request_microcode_fw() and apply_microcode_on_target() (names with your patch applied).
If the microcode driver is builtin (so gets here before SYSTEM_RUNNING), or if it's for Intel with no firmware in /lib/firmware/intel-ucode/X-X-X yet, the cpu_sig is thus obtained for all online cpus, before initscripts run /sbin/microcode_ctl to update from /etc/microcode.dat successfully:
the "updated from revision" message shows uci->cpu_sig.rev as it was saved earlier, rather than reevaluating it just before update.
That's confusing for us, and confusing when resume shows updated from high revision to same high revision (though, I think, the revision should in fact have reverted during suspend); but might be even more worrying to HT users if it were corrected (it would seem as if only half their cpus got updated, when before all were). I don't know.
Quoted 2 lines
Too pity that I can't see it with my setups (heh, I perhaps could play with it by actually downgrading cpus to older ucode).
Please, Intel, ship this man some out-of-date hardware!
(You're sure your cpus really are up-to-date? I thought several of my boxes were, but then discovered a modinfo line in openSUSE 11.1's /etc/init.d/microcode.ctl, which had been added since 10.3, which was now disabling it when microcode driver built into kernel.)
Hugh
2009/4/24 Hugh Dickins <[email protected]>:
Quoted 33 lines · Dmitry Adamushko
Quoted 13 lines
2009/4/24 Dmitry Adamushko <[email protected]>:
Quoted 12 lines
2009/4/24 Hugh Dickins <[email protected]>:
Quoted 11 lines
Good thinking, yes we can and do, unless I'm misinterpreting the evidence. Though P4 Xeon and Atom startup messages give the opposite impression, claiming to update all cpus from lower revision, more careful tests starting from "maxcpus=1" and then "echo 1 >online" (which, unless you've fiddled around putting the microcode_ctl'ed microcode.dat into
/lib/firmware/intel-ucode/wherever, isn't able to update at online time on Intel) shows that the later onlined siblings already have the updated microcode applied to their previously onlined siblings. Which isn't surprising, but I'd been lulled into thinking the opposite by the startup sequence....
Quoted 4 lines
But then I wonder why behavior (the fact that all threads seem to upgrade to a newer version during the startup but they seem to already be 'up-to-date' if onlined later) during the startup is different...
I believe it's because the
module_initmicrocode_init()callssysdev_driver_register(), which doesmc_sysdev_add()of (all possible?) cpus, which for online cpus callsmicrocode_init_cpu(), which doescollect_cpu_info()then, ifSYSTEM_RUNNING,request_microcode_fw()andapply_microcode_on_target()(names with your patch applied).If the microcode driver is builtin (so gets here before
SYSTEM_RUNNING), or if it's for Intel with no firmware in/lib/firmware/intel-ucode/X-X-Xyet, thecpu_sigis thus obtained for all online cpus, before initscripts run/sbin/microcode_ctlto update from/etc/microcode.datsuccessfully:
the "updated from revision" message showsuci->cpu_sig.revas it was saved earlier, rather than reevaluating it just before update.
Quoted 5 lines
That's confusing for us, and confusing when resume shows updated from high revision to same high revision (though, I think, the revision should in fact have reverted during suspend); but might be even more worrying to HT users if it were corrected (it would seem as if only half their cpus got updated, when before all were). I don't know.
Perhaps, it doesn't make sense to cache 'cpu_sig' at all. I'll ponder on it a bit and send a new patch.
Thanks a lot for your feedback!
Quoted 11 lines
Quoted 3 lines
Too pity that I can't see it with my setups (heh, I perhaps could play with it by actually downgrading cpus to older ucode).
Please, Intel, ship this man some out-of-date hardware!
(You're sure your cpus really are up-to-date? I thought several of my boxes were, but then discovered a modinfo line in openSUSE 11.1's
/etc/init.d/microcode.ctl, which had been added since 10.3, which was now disabling it when microcode driver built into kernel.)
hmm, I downloaded - what seems to be - the recent .dat file from the Intel's site and run microcode_ctl (a binary, no additional scripts manually). I will check the site for updates again.
Quoted 3 lines
Hugh
Signature · 2 lines
Best regards, Dmitry Adamushko
Version 4
V3 -> V4
Changes are based on suggestions/review by Hugh Dickins. Thanks a lot!
- update "cleanup of synchronization logic of the 'microcode_core' part" with a remark regarding HT. From the high-level system's POV, HT threads (or cpu cores) look like separate logical cpus so no concurrent cpu_up/down() ops. are allowed.
Hence, 'microcode_mutex' should be enough to cover even those cases when HT threads share 'msr' registers;
- return -EINVAL instead of -1 (which is translated into -EPERM) in microcode_write(), reload_cpu() and mc_sysdev_add(). Other suggestions for an error code?
- report only a new revision in apply_microcode_intel(). The original revision is being printed out when microcode.ko is loaded.
The thread contains some other - possibly worthy - ideas, but these are likely subjects for other patches.
Tested only with updates via /dev/microcode and suspend/resume. However, there are no significant functional changes since V3 so testing that has been done by Hugh should be still relevant.
V2 -> V3
- use smp_call_function_single() instead of work_on_cpu() as suggested by Ingo;
- add 'enum ucode_state' as return value of request_microcode_{fw,user}
- minor cleanups
From: Dmitry Adamushko <[email protected]>
Subject: x86 microcode: smp_call_function_single() and cleanup of synchronization logic
* Solve an issue described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a different way, without resorting to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks must run
on a target cpu, others will do just fine on any other. smp_call_function_single() (as suggested by Ingo) is used to run these callbacks on a target cpu.
* cleanup of synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu (be it a full-fledged cpu, one of the cores or HT)
is being updated at any particular moment of time.
In general, there is no need for any additional sync. mechanism in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
* return -EINVAL instead of -1 (which is translated into -EPERM) in microcode_write(), reload_cpu() and mc_sysdev_add(). Other suggestions for an error code?
* use 'enum ucode_state' as return value of request_microcode_{fw,user} to
gain more flexibility by distinguishing between real error cases and situations when an appropriate ucode was not found (which is not an error per-se).
* some minor cleanups
Thanks a lot to Hugh Dickins for review/suggestions/testing!
arch/x86/include/asm/microcode.h | 19 ++- arch/x86/kernel/microcode_amd.c | 58 +++----- arch/x86/kernel/microcode_core.c | 275 ++++++++++++++++++++++--------------- arch/x86/kernel/microcode_intel.c | 92 +++++-------- 4 files changed, 234 insertions(+), 210 deletions(-)
(there are ~20 new comment lines)
arch/x86/include/asm/microcode.h +15 -4
@@ -9,14 +9,25 @@ struct cpu_signature {struct device ; +enum ucode_state {UCODE_ERROR ,UCODE_OK ,UCODE_NFOUND }; +struct microcode_ops { -int (*request_microcode_user) (int cpu,const void __user *buf,size_t size); -int (*request_microcode_fw) (int cpu,struct device *device); +enum ucode_state (*request_microcode_user) (int cpu, +const void __user *buf,size_t size); -void (*apply_microcode) (int cpu); +enum ucode_state (*request_microcode_fw) (int cpu, +struct device *device); -int (*collect_cpu_info) (int cpu,struct cpu_signature *csig);void (*microcode_fini_cpu) (int cpu); + +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +int (*apply_microcode) (int cpu); +int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); };struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +22 -36
148 lines not on this page · raw message
arch/x86/kernel/microcode_core.c +163 -112
444 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +34 -58
199 lines not on this page · raw message
2009/5/7 Dmitry Adamushko <[email protected]>:
Quoted 8 lines
Signed-off-by Dmitry Adamushko <[email protected]>CC Hugh Dickins <[email protected]>CC Rusty Russell <[email protected]>CC Ingo Molnar <[email protected]>CC Andreas Herrmann <[email protected]>CC Peter Oruba <[email protected]>CC Arjan van de Ven <[email protected]>
Quoted 7 lines
arch/x86/include/asm/microcode.h | 19 ++- arch/x86/kernel/microcode_amd.c | 58 +++----- arch/x86/kernel/microcode_core.c | 275 ++++++++++++++++++++++--------------- arch/x86/kernel/microcode_intel.c | 92 +++++-------- 4 files changed, 234 insertions(+), 210 deletions(-)(there are ~20 new comment lines)
My fault, I forgot to remove a minor debuging trick. The previous patch should be accompanied by the following.
Andreas, any chance you could give it a try with AMD setups? TIA.
(non-white-space-damaged version is enclosed)
--- arch/x86/kernel/microcode_intel-orig.c 2009-05-07
09:57:00.000000000 +0200
+++ arch/x86/kernel/microcode_intel.c 2009-05-07 09:57:47.000000000 +0200
@@ -179,7 +179,7 @@ static inline int update_match_cpu(struc
static inline int
update_match_revision(struct microcode_header_intel *mc_header, int rev) {
- return (mc_header->rev < rev) ? 0 : 1;
+ return (mc_header->rev <= rev) ? 0 : 1;
}
static int microcode_sanity_check(void *mc)
Signature · 2 lines
Best regards, Dmitry Adamushko
x86/kernel/microcode_intel.c renamed from x86/kernel/microcode_intel-orig.c +1 -1
@@ -179,7 +179,7 @@ static inline int update_match_cpu(strucstatic inline int update_match_revision (struct microcode_header_intel *mc_header,int rev) { -return (mc_header->rev < rev) ?0 :1 ; +return (mc_header->rev <= rev) ?0 :1 ; }static int microcode_sanity_check (void *mc)
Re: [PATCH, -tip] x86 microcode: smp_call_function_single() instead of set_cpus_allowed, cleanup of sync. logic
In reply to Dmitry AdamushkoFrom: Dmitry Adamushko <[email protected]>
Subject: x86 microcode: smp_call_function_single instead of set_cpus_allowed, cleanup of synchronization logic
* Solve issues described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a way that doesn't resort to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks must run
on a target cpu, others will do just fine on any other. smp_call_function_single() (as suggested by Ingo) is used to run these callbacks on a target cpu.
* cleanup of synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu (be it a full-fledged cpu, one of the cores or HT)
is being updated at any particular moment of time.
In general, there is no need for any additional sync. mechanism in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
* return -EINVAL instead of -1 (which is translated into -EPERM) in microcode_write(), reload_cpu() and mc_sysdev_add(). Other suggestions for an error code?
* use 'enum ucode_state' as return value of request_microcode_{fw,user} to
gain more flexibility by distinguishing between real error cases and situations when an appropriate ucode was not found (which is not an error per-se).
* some minor cleanups
Thanks a lot to Hugh Dickins for review/suggestions/testing!
Reference: http://marc.info/?l=linux-kernel&m=124025889012541&w=2
arch/x86/include/asm/microcode.h | 19 ++- arch/x86/kernel/microcode_amd.c | 58 +++----- arch/x86/kernel/microcode_core.c | 275 ++++++++++++++++++++++--------------- arch/x86/kernel/microcode_intel.c | 90 +++++-------- 4 files changed, 233 insertions(+), 209 deletions(-)
(~20 new comment lines)
arch/x86/include/asm/microcode.h +15 -4
@@ -9,14 +9,25 @@ struct cpu_signature {struct device ; +enum ucode_state {UCODE_ERROR ,UCODE_OK ,UCODE_NFOUND }; +struct microcode_ops { -int (*request_microcode_user) (int cpu,const void __user *buf,size_t size); -int (*request_microcode_fw) (int cpu,struct device *device); +enum ucode_state (*request_microcode_user) (int cpu, +const void __user *buf,size_t size); -void (*apply_microcode) (int cpu); +enum ucode_state (*request_microcode_fw) (int cpu, +struct device *device); -int (*collect_cpu_info) (int cpu,struct cpu_signature *csig);void (*microcode_fini_cpu) (int cpu); + +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +int (*apply_microcode) (int cpu); +int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); };struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +22 -36
148 lines not on this page · raw message
arch/x86/kernel/microcode_core.c +163 -112
444 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +33 -57
191 lines not on this page · raw message
[tip:x86/microcode] x86: microcode: use smp_call_function_single instead of set_cpus_allowed, cleanup of synchronization logic
Commit-ID: d96a8e336a5728bee825bfc015d52c981daaa528 Gitweb: http://git.kernel.org/tip/d96a8e336a5728bee825bfc015d52c981daaa528 Author: Dmitry Adamushko <[email protected]> AuthorDate: Mon, 11 May 2009 23:48:27 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 May 2009 10:23:25 +0200
x86: microcode: use smp_call_function_single instead of set_cpus_allowed, cleanup of synchronization logic
* Solve issues described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a way that doesn't resort to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks must run on a target cpu, others will do just fine on any other. smp_call_function_single() (as suggested by Ingo) is used to run these callbacks on a target cpu.
* cleanup of synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu (be it a full-fledged cpu, one of the cores or HT)
is being updated at any particular moment of time.
In general, there is no need for any additional sync. mechanism in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
* return -EINVAL instead of -1 (which is translated into -EPERM) in microcode_write(), reload_cpu() and mc_sysdev_add(). Other suggestions for an error code?
* use 'enum ucode_state' as return value of request_microcode_{fw, user} to gain more flexibility by distinguishing between real error cases and situations when an appropriate ucode was not found (which is not an error per-se).
* some minor cleanups
Thanks a lot to Hugh Dickins for review/suggestions/testing!
Reference: http://marc.info/?l=linux-kernel&m=124025889012541&w=2
[ Impact: refactor and clean up microcode driver locking code ]
LKML-Reference: <1242078507.5560.9.camel@earth>
arch/x86/include/asm/microcode.h | 25 ++ arch/x86/kernel/microcode_amd.c | 58 ++---- arch/x86/kernel/microcode_core.c | 326 +++++++++++++++++++++----------------- arch/x86/kernel/microcode_intel.c | 92 +++------- 4 files changed, 261 insertions(+), 240 deletions(-)
(~20 new comment lines)
--- arch/x86/include/asm/microcode.h | 25 ++- arch/x86/kernel/microcode_amd.c | 58 +++---- arch/x86/kernel/microcode_core.c | 326 +++++++++++++++++++++---------------- arch/x86/kernel/microcode_intel.c | 90 ++++------- 4 files changed, 260 insertions(+), 239 deletions(-)
arch/x86/include/asm/microcode.h +18 -7
@@ -9,20 +9,31 @@ struct cpu_signature {struct device ; +enum ucode_state {UCODE_ERROR ,UCODE_OK ,UCODE_NFOUND }; +struct microcode_ops { -int (*request_microcode_user) (int cpu,const void __user *buf,size_t size); -int (*request_microcode_fw) (int cpu,struct device *device); +enum ucode_state (*request_microcode_user) (int cpu, +const void __user *buf,size_t size); -void (*apply_microcode) (int cpu); +enum ucode_state (*request_microcode_fw) (int cpu, +struct device *device); -int (*collect_cpu_info) (int cpu,struct cpu_signature *csig);void (*microcode_fini_cpu) (int cpu); + +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +int (*apply_microcode) (int cpu); +int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); };struct ucode_cpu_info { -struct cpu_signature cpu_sig; -int valid; -void *mc; +struct cpu_signature cpu_sig; +int valid; +void *mc; };extern struct ucode_cpu_info ucode_cpu_info[];
arch/x86/kernel/microcode_amd.c +22 -36
148 lines not on this page · raw message
arch/x86/kernel/microcode_core.c +187 -139
535 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +33 -57
191 lines not on this page · raw message
[tip:x86/microcode] x86: microcode: use smp_call_function_single instead of set_cpus_allowed, cleanup of synchronization logic
In reply to Dmitry AdamushkoCommit-ID: 871b72dd1e12afc3f024479531d25a9339d2e3f9 Gitweb: http://git.kernel.org/tip/871b72dd1e12afc3f024479531d25a9339d2e3f9 Author: Dmitry Adamushko <[email protected]> AuthorDate: Mon, 11 May 2009 23:48:27 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 12 May 2009 10:36:44 +0200
x86: microcode: use smp_call_function_single instead of set_cpus_allowed, cleanup of synchronization logic
* Solve issues described in 6f66cbc63081fd70e3191b4dbb796746780e5ae1 in a way that doesn't resort to set_cpus_allowed();
* in fact, only collect_cpu_info and apply_microcode callbacks must run on a target cpu, others will do just fine on any other. smp_call_function_single() (as suggested by Ingo) is used to run these callbacks on a target cpu.
* cleanup of synchronization logic of the 'microcode_core' part
The generic 'microcode_core' part guarantees that only a single cpu (be it a full-fledged cpu, one of the cores or HT)
is being updated at any particular moment of time.
In general, there is no need for any additional sync. mechanism in arch-specific parts (the patch removes existing spinlocks).
See also the "Synchronization" section in microcode_core.c.
* return -EINVAL instead of -1 (which is translated into -EPERM) in microcode_write(), reload_cpu() and mc_sysdev_add(). Other suggestions for an error code?
* use 'enum ucode_state' as return value of request_microcode_{fw, user} to gain more flexibility by distinguishing between real error cases and situations when an appropriate ucode was not found (which is not an error per-se).
* some minor cleanups
Thanks a lot to Hugh Dickins for review/suggestions/testing!
Reference: http://marc.info/?l=linux-kernel&m=124025889012541&w=2
[ Impact: refactor and clean up microcode driver locking code ]
LKML-Reference: <1242078507.5560.9.camel@earth>
arch/x86/include/asm/microcode.h | 25 ++ arch/x86/kernel/microcode_amd.c | 58 ++---- arch/x86/kernel/microcode_core.c | 326 +++++++++++++++++++++----------------- arch/x86/kernel/microcode_intel.c | 92 +++------- 4 files changed, 261 insertions(+), 240 deletions(-)
(~20 new comment lines)
--- arch/x86/include/asm/microcode.h | 25 ++- arch/x86/kernel/microcode_amd.c | 58 +++---- arch/x86/kernel/microcode_core.c | 329 +++++++++++++++++++++---------------- arch/x86/kernel/microcode_intel.c | 90 ++++------- 4 files changed, 262 insertions(+), 240 deletions(-)
arch/x86/include/asm/microcode.h +18 -7
@@ -9,20 +9,31 @@ struct cpu_signature {struct device ; +enum ucode_state {UCODE_ERROR ,UCODE_OK ,UCODE_NFOUND }; +struct microcode_ops { -int (*request_microcode_user) (int cpu,const void __user *buf,size_t size); -int (*request_microcode_fw) (int cpu,struct device *device); +enum ucode_state (*request_microcode_user) (int cpu, +const void __user *buf,size_t size); -void (*apply_microcode) (int cpu); +enum ucode_state (*request_microcode_fw) (int cpu, +struct device *device); -int (*collect_cpu_info) (int cpu,struct cpu_signature *csig);void (*microcode_fini_cpu) (int cpu); + +/* +* The generic 'microcode_core' part guarantees that +* the callbacks below run on a target cpu when they +* are being called. +* See also the "Synchronization" section in microcode_core.c. +*/ +int (*apply_microcode) (int cpu); +int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); };struct ucode_cpu_info { -struct cpu_signature cpu_sig; -int valid; -void *mc; +struct cpu_signature cpu_sig; +int valid; +void *mc; };extern struct ucode_cpu_info ucode_cpu_info[];
arch/x86/kernel/microcode_amd.c +22 -36
148 lines not on this page · raw message
arch/x86/kernel/microcode_core.c +189 -140
537 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +33 -57
191 lines not on this page · raw message