"KEXEC: correctly revert x2apic state when kexecing" broken?
Andrew,
we just got a report of a crash that very much looks like an effect from this patch. In particular, by reverting to xAPIC mode, disconnect_bsp_APIC() (called via disable_IO_APIC(), getting invoked _after_ __stop_this_cpu(), which is what causes the fiddling with the APIC mode by calling disable_local_APIC()) will use MMIO accesses to the APIC page, yet that one would never have got mapped by init_apic_mappings() if x2apic_enabled got set to non-zero before.
The problem appears to be the use of current_cpu_data by current_local_apic_mode(): The former becomes valid only in the call tree coming through smp_prepare_cpus(), which is _long_ after generic_apic_probe(). Was that patch really tested on a system with x2APIC pre-enabled?
In any case - thoughts about the patch below? I wonder whether always using boot_cpu_data wouldn't even be better (considering that we do so for various other features too).
Jan
x86: fix boot time APIC mode detection
current_cpu_data becomes valid only relatively late in the boot process, so looking there for a particular feature early in the game would generally give the appearance of the feature being unavailable.
Getting this wrong means that at kexec time the system would get returned to xAPIC mode, causing disconnect_bsp_APIC() to try to access the APIC page, which on systems with x2APIC pre-enabled will never get set up.
xen/arch/x86/apic.c +3 -1
@@ -1474,7 +1474,9 @@ enum apic_mode current_local_apic_mode(v/* Reading EXTD bit from the MSR is only valid if CPUID * says so, else reserved */ -if (cpu_has (¤t_cpu_data,X86_FEATURE_X2APIC ) +if ( (system_state >= SYS_STATE_active ? +cpu_has (¤t_cpu_data,X86_FEATURE_X2APIC ) : +boot_cpu_has (X86_FEATURE_X2APIC )) && (msr_contents &MSR_IA32_APICBASE_EXTD ) )return APIC_MODE_X2APIC ;
Quoted 11 lines · Jan Beulich
Andrew,
we just got a report of a crash that very much looks like an effect from this patch. In particular, by reverting to xAPIC mode,
disconnect_bsp_APIC()(called viadisable_IO_APIC(), getting invoked _after___stop_this_cpu(), which is what causes the fiddling with the APIC mode by callingdisable_local_APIC()) will use MMIO accesses to the APIC page, yet that one would never have got mapped byinit_apic_mappings()ifx2apic_enabledgot set to non-zero before.
Quoted 5 lines
The problem appears to be the use of
current_cpu_databycurrent_local_apic_mode(): The former becomes valid only in the call tree coming throughsmp_prepare_cpus(), which is _long_ aftergeneric_apic_probe(). Was that patch really tested on a system with x2APIC pre-enabled?
I cant remember for certain. I think it was just on systems which turned on x2apic and left hardware set up, causing interrupt format errors for the kdump kernel.
I would certainly agree with your assessment of the problem
Quoted 4 lines
In any case - thoughts about the patch below? I wonder whether always using
boot_cpu_datawouldn't even be better (considering that we do so for various other features too).
I would just go straight for boot_cpu_data. Most other things in __init functions do.
~Andrew
Quoted 32 lines
Jan
x86: fix boot time APIC mode detection
current_cpu_databecomes valid only relatively late in the boot process, so looking there for a particular feature early in the game would generally give the appearance of the feature being unavailable.Getting this wrong means that at kexec time the system would get returned to xAPIC mode, causing
disconnect_bsp_APIC()to try to access the APIC page, which on systems with x2APIC pre-enabled will never get set up.Signed-off-by Jan Beulich<[email protected]>xen/arch/x86/apic.c +3
-1@@ -1474,7 +1474,9 @@ enum apic_mode current_local_apic_mode(v/* Reading EXTD bit from the MSR is only valid if CPUID * says so, else reserved */ -if (cpu_has (¤t_cpu_data,X86_FEATURE_X2APIC ) +if ( (system_state>= SYS_STATE_active ? +cpu_has (¤t_cpu_data,X86_FEATURE_X2APIC ) : +boot_cpu_has (X86_FEATURE_X2APIC )) && (msr_contents&MSR_IA32_APICBASE_EXTD ) )return APIC_MODE_X2APIC ;