tip, x86-microcode: refactor microcode output messages
PATCH 2/2 tip, x86-microcode: refactor microcode output messages
From: Dmitry Adamushko <[email protected]>
Subject: x86-microcode: refactor microcode output messages
Provide a compound message for cpus with equal microcode version as follows:
[ 425.432384] microcode: original microcode versions [ 425.432400] microcode: CPU0-1: sig=0x6f2, pf=0x20, revision=0x56 ... [ 425.468367] microcode: updated microcode versions [ 425.468382] microcode: CPU0-1: sig=0x6f2, pf=0x20, revision=0x57
The new mechanism is used in microcode_init()
[ i.e. when loading a module ] and microcode_write(), i.e. when all the cpus are being updated at once.
reload_for_cpu() and update-all-cpus-upon-resuming() use the old approach - a new microcode version is being reported upon applying it.
Andreas, would you please try these changes with your setups?
My laptop's CPUs are of the most recent microcode revision so I can't test them thoroughly. Thanks in advance.
arch/x86/include/asm/microcode.h | 5 ++- arch/x86/kernel/microcode_amd.c | 11 +++- arch/x86/kernel/microcode_core.c | 108 ++++++++++++++++++++++++++++++++----- arch/x86/kernel/microcode_intel.c | 23 +++++--- 4 files changed, 122 insertions(+), 25 deletions(-)
---
arch/x86/include/asm/microcode.h +4 -1
@@ -14,6 +14,7 @@ enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };struct microcode_ops {void (*init)(struct device *device);void (*fini)(void ); +enum ucode_state (*request_microcode_user) (int cpu,const void __user *buf,size_t size);
@@ -28,8 +29,10 @@ struct microcode_ops {* are being called. * See also the "Synchronization" section in microcode_core.c. */ -int (*apply_microcode) (int cpu); +int (*apply_microcode) (int cpu,int verbose);int (*collect_cpu_info) (int cpu,struct cpu_signature *csig); + +int (*version_snprintf) (char *buf,int len,struct cpu_signature *csig); };struct ucode_cpu_info {
arch/x86/kernel/microcode_amd.c +9 -2
@@ -85,6 +85,11 @@ static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig)return 0 ; } +static int version_snprintf (char *buf,int len,struct cpu_signature *csig) +{ +return snprintf (buf, len,"patch_level=0x%x" , csig->rev); +} +static int get_matching_microcode (int cpu,void *mc,int rev) {struct microcode_header_amd *mc_header = mc;
@@ -122,7 +127,7 @@ static int get_matching_microcode(int cpu, void *mc, int rev)return 1 ; } -static int apply_microcode_amd (int cpu) +static int apply_microcode_amd (int cpu,int verbose) {u32 rev, dummy;int cpu_num =raw_smp_processor_id ();
@@ -146,7 +151,8 @@ static int apply_microcode_amd(int cpu)return -1 ; } -pr_info ("microcode: CPU%d: updated (new patch_level=0x%x)\n" , cpu, rev); +if (verbose) +printk (KERN_INFO "microcode: CPU%d: updated (new patch_level=0x%x)\n" , cpu, rev);return 0 ; }
@@ -359,6 +365,7 @@ static struct microcode_ops microcode_amd_ops = { .request_microcode_fw = request_microcode_fw, .collect_cpu_info = collect_cpu_info_amd, .apply_microcode = apply_microcode_amd, + .version_snprintf = version_snprintf, .microcode_fini_cpu = microcode_fini_cpu_amd, };
arch/x86/kernel/microcode_core.c +95 -13
191 lines not on this page · raw message
arch/x86/kernel/microcode_intel.c +14 -9
@@ -165,12 +165,14 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)/* get the current revision from MSR 0x8B */ rdmsr (MSR_IA32_UCODE_REV , val[0 ], csig->rev); -printk (KERN_INFO "microcode: CPU%d sig=0x%x, pf=0x%x, revision=0x%x\n" , - cpu_num, csig->sig, csig->pf, csig->rev); -return 0 ; } +static int version_snprintf (char *buf,int len,struct cpu_signature *csig) +{ +return snprintf (buf, len,"sig=0x%x, pf=0x%x, revision=0x%x" , csig->sig, csig->pf, csig->rev); +} +static inline int update_match_cpu (struct cpu_signature *csig,int sig,int pf) {return (!sigmatch (sig, csig->sig, pf, csig->pf)) ?0 :1 ;
@@ -297,7 +299,7 @@ get_matching_microcode(struct cpu_signature *cpu_sig, void *mc, int rev)return 0 ; } -static int apply_microcode (int cpu) +static int apply_microcode (int cpu,int verbose) {struct microcode_intel *mc_intel;struct ucode_cpu_info *uci;
@@ -332,12 +334,14 @@ static int apply_microcode(int cpu) cpu_num, mc_intel->hdr.rev);return -1 ; } -printk (KERN_INFO "microcode: CPU%d updated to revision " + +if (verbose) +printk (KERN_INFO "microcode: CPU%d updated to revision " "0x%x, date = %04x-%02x-%02x \n" , - cpu_num, val[1 ], - mc_intel->hdr.date &0xffff , - mc_intel->hdr.date >>24 , - (mc_intel->hdr.date >>16 ) &0xff ); + cpu_num, val[1 ], + mc_intel->hdr.date &0xffff , + mc_intel->hdr.date >>24 , + (mc_intel->hdr.date >>16 ) &0xff );return 0 ; }
@@ -468,6 +472,7 @@ static struct microcode_ops microcode_intel_ops = { .request_microcode_fw = request_microcode_fw, .collect_cpu_info = collect_cpu_info, .apply_microcode = apply_microcode, + .version_snprintf = version_snprintf, .microcode_fini_cpu = microcode_fini_cpu, };
Quoted 50 lines · dimm
arch/x86/kernel/microcode_core.c +50
-0+static int summarize_cpu_range (struct cpumask *range,struct cpu_signature *csig) +{ +char *cpu_str, *ver_str; +int ret =-1 ; + + cpu_str =kmalloc (128 ,GFP_KERNEL ); + ver_str =kmalloc (128 ,GFP_KERNEL ); +if (!cpu_str || !ver_str) + goto out; + +cpulist_scnprintf (cpu_str,128 , range); + microcode_ops->version_snprintf (ver_str,128 , csig); + +printk (KERN_INFO "microcode: CPU%s: %s\n" , cpu_str, ver_str); + ret =0 ; +out: +if (cpu_str) +kfree (cpu_str); +if (ver_str) +kfree (ver_str); + +return ret; +} + +static void summarize_cpu_info (void ) +{ +struct cpu_info_array_ctx *ctx_array; +cpumask_var_t cpulist; +int base, cpu, ret; + +if (!zalloc_cpumask_var (&cpulist,GFP_KERNEL )) +return ; + + ctx_array =kmalloc (nr_cpu_ids *sizeof (*ctx_array),GFP_KERNEL ); +if (!ctx_array) + goto out; + + ret =on_each_cpu (collect_cpu_info_array, ctx_array,1 ); +if (ret) + goto out; + + base =cpumask_first (cpu_online_mask); + cpu = base; +cpumask_set_cpu (cpu, cpulist); + +while ((cpu =cpumask_next (cpu, cpu_online_mask)) < nr_cpu_ids) { +if (memcmp (&ctx_array[base].cpu_sig, &ctx_array[cpu].cpu_sig, +sizeof (ctx_array[base].cpu_sig)) !=0 ) { +summarize_cpu_range (cpulist, &ctx_array[base].cpu_sig); +cpumask_clear (cpulist);
arch/x86/kernel/microcode_core.c static int apply_microcode_on_target(int cpu) · line 235
Quoted 10 lines
arch/x86/kernel/microcode_core.c +10
-0+ base = cpu; + } +cpumask_set_cpu (cpu, cpulist); + } +summarize_cpu_range (cpulist, &ctx_array[base].cpu_sig); +out: +free_cpumask_var (cpulist); +if (ctx_array) +kfree (ctx_array); +}
Could we please leave out this summarizing logic (it's bloaty and unnecessary), and just print a single line message when applying the microcode?
Thanks,
Ingo