x86: Move microcode loading earlier
PATCH 1/1 x86: Move microcode loading earlier
Move microcode loading earlier for the boot CPU and secondary CPUs so that it takes place before identify_cpu() is called for each CPU. Without this, the detected features may be wrong if the new microcode loading adjusts the feature bits. That could mean that some fixes (e.g. d6e9f8d4f35d ("x86/vmx: fix vmentry failure with TSX bits in LBR")) don't work as expected.
Previously during boot, the microcode loader was invoked for each secondary CPU started and then again for each CPU as part of an initcall. Simplify the code so that it is invoked exactly once for each CPU during boot.
--- xen/arch/x86/cpu/common.c | 2 + xen/arch/x86/microcode.c | 131 +++++++++++++++++----------------------- xen/arch/x86/microcode_amd.c | 3 +- xen/arch/x86/microcode_intel.c | 3 +- xen/arch/x86/setup.c | 2 + xen/arch/x86/smpboot.c | 33 +++++----- xen/include/asm-x86/processor.h | 4 ++ xen/include/xen/smp.h | 2 + 8 files changed, 85 insertions(+), 95 deletions(-)
xen/arch/x86/cpu/common.c +2 -0
@@ -252,6 +252,8 @@ static void __init early_cpu_detect(void)if (hap_paddr_bits >PADDR_BITS ) hap_paddr_bits =PADDR_BITS ; } + +initialize_cpu_data (0 ); }static void generic_identify (struct cpuinfo_x86 *c)
xen/arch/x86/microcode.c +54 -77
161 lines not on this page · raw message
xen/arch/x86/microcode_amd.c +1 -2
@@ -627,10 +627,9 @@ static const struct microcode_ops microcode_amd_ops = { .start_update = start_update, }; -static __init int microcode_init_amd (void ) +int __init microcode_init_amd (void ) {if ( boot_cpu_data.x86_vendor ==X86_VENDOR_AMD ) microcode_ops = µcode_amd_ops;return 0 ; } -presmp_initcall (microcode_init_amd);
xen/arch/x86/microcode_intel.c +1 -2
@@ -404,10 +404,9 @@ static const struct microcode_ops microcode_intel_ops = { .apply_microcode = apply_microcode, }; -static __init int microcode_init_intel (void ) +int __init microcode_init_intel (void ) {if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) microcode_ops = µcode_intel_ops;return 0 ; } -presmp_initcall (microcode_init_intel);
xen/arch/x86/setup.c +2 -0
@@ -1461,6 +1461,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)timer_init (); +early_microcode_init (); +identify_cpu (&boot_cpu_data);set_in_cr4 (X86_CR4_OSFXSR |X86_CR4_OSXMMEXCPT );
xen/arch/x86/smpboot.c +19 -14
@@ -83,22 +83,22 @@ static enum cpu_state {void *stack_base[NR_CPUS ]; +void initialize_cpu_data (unsigned int cpu) +{ + *(cpu_data + cpu) = boot_cpu_data; +} +static void smp_store_cpu_info (int id) { -struct cpuinfo_x86 *c = cpu_data + id;unsigned int socket; - *c = boot_cpu_data; -if ( id !=0 ) - { -identify_cpu (c); +identify_cpu (cpu_data + id); - socket =cpu_to_socket (id); -if ( !socket_cpumask[socket] ) - { - socket_cpumask[socket] = secondary_socket_cpumask; - secondary_socket_cpumask =NULL ; - } + socket =cpu_to_socket (id); +if ( !socket_cpumask[socket] ) + { + socket_cpumask[socket] = secondary_socket_cpumask; + secondary_socket_cpumask =NULL ; } }
@@ -332,6 +332,13 @@ void start_secondary(void *unused)cpu_init (); +initialize_cpu_data (cpu); + +if ( system_state <= SYS_STATE_smp_boot ) +early_microcode_update_cpu (false); +else +microcode_resume_cpu (cpu); +smp_callin ();init_percpu_time ();
@@ -364,8 +371,6 @@ void start_secondary(void *unused)local_irq_enable ();mtrr_ap_init (); -microcode_resume_cpu (cpu); -wmb ();startup_cpu_idle_loop (); }
@@ -780,7 +785,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)mtrr_aps_sync_begin ();/* Setup boot CPU information */ -smp_store_cpu_info (0 );/* Final full version of the data */ +initialize_cpu_data (0 );/* Final full version of the data */ print_cpu_info (0 ); boot_cpu_physical_apicid =get_apic_id ();
xen/include/asm-x86/processor.h +4 -0
@@ -563,6 +563,10 @@ int wrmsr_hypervisor_regs(uint32_t idx, uint64_t val);void microcode_set_module (unsigned int );int microcode_update (XEN_GUEST_HANDLE_PARAM (const_void ),unsigned long len);int microcode_resume_cpu (unsigned int cpu); +int early_microcode_update_cpu (bool_t start_update); +int early_microcode_init (void ); +int microcode_init_intel (void ); +int microcode_init_amd (void );enum get_cpu_vendor { gcv_host,
xen/include/xen/smp.h +2 -0
@@ -71,4 +71,6 @@ int alloc_cpu_id(void);extern void *stack_base[NR_CPUS ]; +void initialize_cpu_data (unsigned int cpu); +#endif /* __XEN_SMP_H__ */
Signature · 7 lines
2.7.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 7 lines · Ross Lagerwall
Move microcode loading earlier for the boot CPU and secondary CPUs so that it takes place before
identify_cpu()is called for each CPU. Without this, the detected features may be wrong if the new microcode loading adjusts the feature bits. That could mean that some fixes (e.g.d6e9f8d4f35d("x86/vmx: fix vmentry failure with TSX bits in LBR")) don't work as expected.
Quoted 6 lines
Previously during boot, the microcode loader was invoked for each secondary CPU started and then again for each CPU as part of an initcall. Simplify the code so that it is invoked exactly once for each CPU during boot.
Signed-off-by Ross Lagerwall <[email protected]>
CC'ing Julien. This should be taken in 4.9
This also resolves my LBR XTF test, so
Also, Reviewed-by: Andrew Cooper <[email protected]>, with 3 corrections (which I can fix on commit)
xen/arch/x86/microcode.c static struct notifier_block microcode_percpu_nfb = { · line 384
Quoted 6 lines
xen/arch/x86/microcode.c +1
-1@@ -409,50 +381,55 @@ static struct notifier_block microcode_percpu_nfb = { .notifier_call = microcode_percpu_callback, }; -static int __init microcode_presmp_init (void ) +int __init early_microcode_update_cpu (bool_t start_update)
s/bool_t/bool/ throughout.
xen/arch/x86/smpboot.c static enum cpu_state { · line 88
Quoted 11 lines
xen/arch/x86/smpboot.c +3
-0@@ -83,22 +83,22 @@ static enum cpu_state {void *stack_base[NR_CPUS ]; +void initialize_cpu_data (unsigned int cpu) +{ + *(cpu_data + cpu) = boot_cpu_data;
cpu_data[cpu] = boot_cpu_data;
xen/arch/x86/smpboot.c static enum cpu_state { · line 95
Quoted 12 lines
xen/arch/x86/smpboot.c +3
-5+} +static void smp_store_cpu_info (int id) { -struct cpuinfo_x86 *c = cpu_data + id;unsigned int socket; - *c = boot_cpu_data; -if ( id !=0 ) - { -identify_cpu (c); +identify_cpu (cpu_data + id);
&cpu_data[id]
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Hi Andrew,
Quoted 15 lines · Andrew Cooper
Quoted 7 lines · Ross Lagerwall
Move microcode loading earlier for the boot CPU and secondary CPUs so that it takes place before
identify_cpu()is called for each CPU. Without this, the detected features may be wrong if the new microcode loading adjusts the feature bits. That could mean that some fixes (e.g.d6e9f8d4f35d("x86/vmx: fix vmentry failure with TSX bits in LBR")) don't work as expected.Quoted 6 lines
Previously during boot, the microcode loader was invoked for each secondary CPU started and then again for each CPU as part of an initcall. Simplify the code so that it is invoked exactly once for each CPU during boot.
Signed-off-by Ross Lagerwall <[email protected]>
Quoted 8 lines
CC'ing Julien. This should be taken in 4.9
This also resolves my LBR XTF test, so
Tested-by Andrew Cooper <[email protected]>Also, Reviewed-by: Andrew Cooper <[email protected]>, with 3 corrections (which I can fix on commit)
Cheers,
Quoted 41 lines
xen/arch/x86/microcode.c static struct notifier_block microcode_percpu_nfb = { · line 384
Quoted 7 lines
xen/arch/x86/microcode.c +1
-1@@ -409,50 +381,55 @@ static struct notifier_block microcode_percpu_nfb = { .notifier_call = microcode_percpu_callback, }; -static int __init microcode_presmp_init (void ) +int __init early_microcode_update_cpu (bool_t start_update)s/bool_t/bool/ throughout.
xen/arch/x86/smpboot.c static enum cpu_state { · line 88
Quoted 11 lines
xen/arch/x86/smpboot.c +3
-0@@ -83,22 +83,22 @@ static enum cpu_state {void *stack_base[NR_CPUS ]; +void initialize_cpu_data (unsigned int cpu) +{ + *(cpu_data + cpu) = boot_cpu_data;cpu_data[cpu] =
boot_cpu_data;xen/arch/x86/smpboot.c static enum cpu_state { · line 95
Quoted 12 lines
xen/arch/x86/smpboot.c +3
-5+} +static void smp_store_cpu_info (int id) { -struct cpuinfo_x86 *c = cpu_data + id;unsigned int socket; - *c = boot_cpu_data; -if ( id !=0 ) - { -identify_cpu (c); +identify_cpu (cpu_data + id);&cpu_data[id]
~Andrew
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 18.04.17 at 17:47, <[email protected]> wrote:
Move microcode loading earlier for the boot CPU and secondary CPUs so that it takes place before
identify_cpu()is called for each CPU. Without this, the detected features may be wrong if the new microcode loading adjusts the feature bits. That could mean that some fixes (e.g.d6e9f8d4f35d("x86/vmx: fix vmentry failure with TSX bits in LBR")) don't work as expected.
Quoted 4 lines
Previously during boot, the microcode loader was invoked for each secondary CPU started and then again for each CPU as part of an initcall. Simplify the code so that it is invoked exactly once for each CPU during boot.
The elimination of those pre-SMP initcalls makes it rather desirable to also remove the respective ordering comment from x86/Makefile.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel