cpu synchronization while doing MTRR register update
PATCH 1/1 cpu synchronization while doing MTRR register update
The current Xen code does not synchronize all the cpus while initializing MTRR registers when a cpu comes up.
As per IA32 SDM vol 3: Section: 10.11.8 MTRR Considerations in MP Systems, all the processors should be synchronized while updating MTRRs.
Processors starting with westmere are caching VMCS data for better VMX performance. These processors also has Hyper-threading support. With hyper-threading, when one thread's cache is disabled, it also disables cache for the sibling threads. And MTRR register updating procedure involves cache disabling. So if cpus are not synchronized, updating MTRR registers on a thread, results in the VMCS data from sibling threads becoming inaccessible, and it causes system failure.
With this patch while updating the MTRR registers, all the cpus are synchronized as per the IA32 SDM. Also at the boot time and resume time when multiple cpus are brought up, an optimization is added to delay the MTRR initialization until all the cpus are up, to avoid multiple times cpu synchronization.
Diffstat:
arch/x86/acpi/suspend.c | 2 - arch/x86/cpu/common.c | 2 - arch/x86/cpu/mtrr/main.c | 57 +++++++++++++++++++++++++++++--------- arch/x86/smpboot.c | 6 ++++ include/asm-x86/mtrr.h | 4 +++ 5 files changed, 56 insertions(+), 15 deletions(-)
Thanks & Regards,
Nitin
Linux Open Source Technology Center, Intel Corporation
-----------------------------------------------------------------------
The Mind is like a parachute; it works much better when it's open.
cpu synchronization while doing MTRR register update
The current Xen code does not synchronize all the cpus while initializing MTRR registers when a cpu comes up.
As per IA32 SDM vol 3: Section: 10.11.8 MTRR Considerations in MP Systems, all the processors should be synchronized while updating MTRRs.
Processors starting with westmere are caching VMCS data for better VMX performance. These processors also has Hyper-threading support. With hyper-threading, when one thread's cache is disabled, it also disables cache for the sibling threads. And MTRR register updating procedure involves cache disabling. So if cpus not synchronized, updating MTRR registers on a thread, results in the VMCS data from sibling threads becoming inaccessible, and it causes system failure.
With this patch while updating the MTRR registers, all the cpus are synchronized as per the IA32 SDM. Also at the boot time and resume time when multiple cpus are brought up, an optimization is added to delay the MTRR initialization until all the cpus have come up, to avoid multiple times cpu synchronization.
xen/arch/x86/acpi/suspend.c +1 -1
@@ -78,6 +78,6 @@ void restore_rest_processor_state(void)if (cpu_has_pat)wrmsrl (MSR_IA32_CR_PAT , host_pat); -mtrr_ap_init (); +mtrr_bp_restore ();mcheck_init (&boot_cpu_data); }
xen/arch/x86/cpu/common.c +0 -2
@@ -452,8 +452,6 @@ void __cpuinit identify_cpu(struct cpuinif (c == &boot_cpu_data)mtrr_bp_init (); -else -mtrr_ap_init (); }#ifdef CONFIG_X86_HT
xen/arch/x86/cpu/mtrr/main.c +45 -12
95 lines not on this page · raw message
xen/arch/x86/smpboot.c +6 -0
@@ -519,6 +519,7 @@ void __devinit start_secondary(void *unu/* We can take interrupts now: we're officially "up". */ local_irq_enable (); +mtrr_ap_init ();microcode_resume_cpu (cpu);
@@ -1194,6 +1195,7 @@ void __init smp_prepare_cpus(unsigned in cpu_callin_map =cpumask_of_cpu (0 );mb ();smp_boot_cpus (max_cpus); +mtrr_aps_sync_begin (); }void __devinit smp_prepare_boot_cpu (void )
@@ -1386,6 +1388,7 @@ void enable_nonboot_cpus(void)int cpu, error;printk ("Thawing cpus ...\n" ); +mtrr_aps_sync_begin ();for_each_cpu_mask (cpu, frozen_cpus) { error =cpu_up (cpu);if (!error) {
@@ -1395,6 +1398,7 @@ void enable_nonboot_cpus(void)printk ("Error taking cpu %d up: %d\n" , cpu, error);panic ("Not enough cpus" ); } +mtrr_aps_sync_end ();cpus_clear (frozen_cpus);/*
@@ -1461,6 +1465,8 @@ void __init smp_cpus_done(unsigned int m#ifdef CONFIG_X86_IO_APIC setup_ioapic_dest ();#endif +mtrr_save_state (); +mtrr_aps_sync_end ();#ifndef CONFIG_HOTPLUG_CPU /* * Disable executability of the SMP trampoline:
xen/include/asm-x86/mtrr.h +4 -0
@@ -71,5 +71,9 @@ extern uint8_t epte_get_entry_emt(extern void ept_change_entry_emt_with_range (struct domain *d,unsigned long start_gfn,unsigned long end_gfn);extern unsigned char pat_type_2_pte_flags (unsigned char pat_type); +extern int hold_mtrr_updates_on_aps; +extern void mtrr_aps_sync_begin (void ); +extern void mtrr_aps_sync_end (void ); +extern void mtrr_bp_restore (void );#endif /* __ASM_X86_MTRR_H__ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi,
Quoted 7 lines · Nitin A Kamble
Processors starting with westmere are caching VMCS data for better VMX performance. These processors also has Hyper-threading support. With hyper-threading, when one thread's cache is disabled, it also disables cache for the sibling threads. And MTRR register updating procedure involves cache disabling. So if cpus are not synchronized, updating MTRR registers on a thread, results in the VMCS data from sibling threads becoming inaccessible, and it causes system failure.
What's the observed failure here? Hang/crash on resume from S3? Or something more common?
Cheers,
Tim.
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]
Quoted 8 lines
-----Original Message-----
From: Tim Deegan [mailto:[email protected]]
What's the observed failure here? Hang/crash on resume from S3? Or something more common?Cheers,
Tim.
Tim,
The issue is observed at the cpu hotplug time. At the time of cpu hot add, the MTRR registers are initialized on that cpu, and that involves disabling cache. If there is an HVM guest up at that time, who is consuming sibling of the hotplug-ed cpu, then that sibling cpu will not able to access it's vmcs and results in system crash.
Thanks & Regards,
Nitin
Linux Open Source Technology Center, Intel Corporation
---------------------------------------------------------------------------
The Mind is like a parachute; it works much better when it's open.