Enable legacy irq mode before jump to kexec/kdump kernel
Subsystems (4)
cover Enable legacy irq mode before jump to kexec/kdump kernel
Wei Jiangang reported kdump kernel always hang when "notsc" is specified in boot parameter. After debugging I found there's no timer interrupt in the current kexec/kdump kernel. This is caused by commit 522e66464467 ("x86/apic: Disable I/O APIC before shutdown of the local APIC"). Originally Eric posted below patch to make system be virtual wire mode in which 8259- equivalent PIC fields all interrupts and the LAPIC becomes a virtual wire. Like this interrupts can be delivered from PIC to CPU via the LAPIC's local interrupt 0 (LINTIN0). In virtual wire APIC mode is disabled while LAPIC is software enabled and its LINT0 and LINT1 need be programmed specifically.
But with commit 522e66464 you can see after disable_IO_APIC had setting virtual wire mode, lapic_shutdown disabled LAPIC again. Now virtual wire mode doesn't work, then it cause no timer interrupt during kdump kernel initialization stage until system enter into APIC mode.
So people may be wondering why only kdump kernel hang, the normal kernel with "notsc" can still work. This is because BIOS has already built PIC mode or virtual wire mode while kexec/kdump kernel doesn't go through BIOS initialization. That is why we have to change system to be PIC mode or virtual wire mode before jump to kexec/kdump kernel.
Then why kdump kernel didn't hang when "notsc" is not specified. This is because tsc_init will assign the already calibrated value to lpj_fine. Then kernel doesn't need to count cpu loops between jiffies with the help of timer interrupt. So "notsc" is not victim, but a informer.
In patch 1/3 disable_IO_APIC is changed to only contain code of changeing system to be PIC mode or virtual wire mode and is renamed as switch_to_legacy_irq_mode. Now only call clear_IO_APIC where IO-APIC need be disabled, and call switch_to_legacy_irq_mode before jump to kexe/kdump kernel.
Patch 2/3 and 3/3 are clean up patch.
Baoquan He (3):
x86/apic/kexec: Enable legacy irq mode before jump to kexec/kdump
kernel
x86/apic: Clean up the names of legacy irq mode setting related
functions
x86/apic: Clean up the apic delivery mode macro definition
arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/apicdef.h | 1 - arch/x86/include/asm/io_apic.h | 6 +++--- arch/x86/kernel/apic/apic.c | 19 +++++++++++-------- arch/x86/kernel/apic/io_apic.c | 32 +++++++++++++++++--------------- arch/x86/kernel/crash.c | 2 +- arch/x86/kernel/machine_kexec_32.c | 15 +++++---------- arch/x86/kernel/machine_kexec_64.c | 15 +++++---------- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/x86_init.c | 2 +- drivers/iommu/irq_remapping.c | 2 +- 11 files changed, 46 insertions(+), 52 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/3 x86/apic/kexec: Enable legacy irq mode before jump to kexec/kdump kernel
It's reported that if kernel parameter "notsc" is specified kdump kernel always hang after printing boot log as below:
---
tsc: Fast TSC calibration using PIT
tsc: Detected 2099.947 MHz processor
Calibrating delay loop...
---
The reason is no timer interrupt during kdump kernel initialization. With "notsc" specified the function tsc_init() will return early and won't assign already calibrated value to lpj_fine, we have to rely on timer interrupt to get cpu loops between jiffies. Then system hangs to wait for the never coming timer interrupt.
This is caused by buggy 'commit 522e66464467 ("x86/apic: Disable I/O APIC before shutdown of the local APIC")'. In normal kernel it defaults to be PIC mode or Virtual Wire mode during system initialization before APIC mode is enabled and this is done by BIOS initialization. With this timer interrupt can be handled in legacy irq way. But kexec/kdump kernel won't go through BIOS, so we have to set system as PIC or Virtual Wire mode before jump to kdump kernel code directly. This is done in disable_IO_APIC which includes two parts, firstly it calls clear_IO_APIC() to disable IO-APIC, then it sets LAPIC and IO-APIC to make system be PIC or Virtual Wire mode. In commit 522e66464 it put disable_IO_APIC earlier so that local apic is completely disabled.
So in this patch take clear_IO_APIC out from disable_IO_APIC and rename disable_IO_APIC as switch_to_legacy_irq_mode. Then only call clear_IO_APIC when IO-APIC need be disabled. And call switch_to_legacy_irq_mode before kexec/kdump jumping.
--- arch/x86/include/asm/io_apic.h | 3 ++- arch/x86/kernel/apic/io_apic.c | 12 ++++-------- arch/x86/kernel/crash.c | 2 +- arch/x86/kernel/machine_kexec_32.c | 15 +++++---------- arch/x86/kernel/machine_kexec_64.c | 15 +++++---------- arch/x86/kernel/reboot.c | 2 +- 6 files changed, 18 insertions(+), 31 deletions(-)
arch/x86/include/asm/io_apic.h +2 -1
@@ -191,7 +191,8 @@ static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)extern void setup_IO_APIC (void );extern void enable_IO_APIC (void ); -extern void disable_IO_APIC (void ); +extern void clear_IO_APIC (void ); +extern void switch_to_legacy_irq_mode (void );extern void setup_ioapic_dest (void );extern int IO_APIC_get_PCI_irq_vector (int bus,int devfn,int pin);extern void print_IO_APICs (void );
arch/x86/kernel/apic/io_apic.c +4 -8
@@ -587,7 +587,7 @@ static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin) mpc_ioapic_id(apic), pin); } -static void clear_IO_APIC (void ) +void clear_IO_APIC (void ) {int apic, pin;
@@ -1459,15 +1459,11 @@ void native_disable_io_apic(void) }/* -* Not an __init, needed by the reboot code +* Not an __init, needed by kexec/kdump code. +* For safety IO-APIC and Local APIC need be cleared before this. */ -void disable_IO_APIC (void ) +void switch_to_legacy_irq_mode (void ) { -/* -* Clear the IO-APIC before rebooting: -*/ -clear_IO_APIC (); -if (!nr_legacy_irqs ())return ;
arch/x86/kernel/crash.c +1 -1
@@ -182,7 +182,7 @@ void native_machine_crash_shutdown(struct pt_regs *regs)#ifdef CONFIG_X86_IO_APIC /* Prevent crash_kexec() from deadlocking on ioapic_lock. */ ioapic_zap_locks (); -disable_IO_APIC (); +clear_IO_APIC ();#endif lapic_shutdown ();#ifdef CONFIG_HPET_TIMER
arch/x86/kernel/machine_kexec_32.c +5 -10
@@ -202,18 +202,13 @@ void machine_kexec(struct kimage *image)local_irq_disable ();hw_breakpoint_disable (); -if (image->preserve_context) {#ifdef CONFIG_X86_IO_APIC -/* -* We need to put APICs in legacy mode so that we can -* get timer interrupts in second kernel. kexec/kdump -* paths already have calls to disable_IO_APIC() in -* one form or other. kexec jump path also need -* one. -*/ -disable_IO_APIC (); +/* +* We need to put APICs in legacy mode so that we can +* get timer interrupts in second kernel. +*/ +switch_to_legacy_irq_mode ();#endif - } control_page =page_address (image->control_code_page);memcpy (control_page, relocate_kernel,KEXEC_CONTROL_CODE_MAX_SIZE );
arch/x86/kernel/machine_kexec_64.c +5 -10
@@ -269,18 +269,13 @@ void machine_kexec(struct kimage *image)local_irq_disable ();hw_breakpoint_disable (); -if (image->preserve_context) {#ifdef CONFIG_X86_IO_APIC -/* -* We need to put APICs in legacy mode so that we can -* get timer interrupts in second kernel. kexec/kdump -* paths already have calls to disable_IO_APIC() in -* one form or other. kexec jump path also need -* one. -*/ -disable_IO_APIC (); +/* +* We need to put APICs in legacy mode so that we can +* get timer interrupts in second kernel. +*/ +switch_to_legacy_irq_mode ();#endif - } control_page =page_address (image->control_code_page) +PAGE_SIZE ;memcpy (control_page, relocate_kernel,KEXEC_CONTROL_CODE_MAX_SIZE );
arch/x86/kernel/reboot.c +1 -1
@@ -624,7 +624,7 @@ void native_machine_shutdown(void)* Even without the erratum, it still makes sense to quiet IO APIC * before disabling Local APIC. */ -disable_IO_APIC (); +clear_IO_APIC ();#endif #ifdef CONFIG_SMP
Signature · 1 line
2.5.5
PATCH 2/3 x86/apic: Clean up the names of legacy irq mode setting related functions
In reply to Baoquan HeX86 MP spec defines 3 different interrupt modes:
1) PIC Mode—bypasses all APIC components and forces the system to operate in single-processor mode.
2) Virtual Wire Mode—uses an APIC as a virtual wire, but otherwise operates the same as PIC Mode.
3) Symmetric I/O Mode—enables the system to operate with more than one processor.
The current disconnect_bsp_APIC includes two parts: one is to set system as PIC mode if it's available, the other is to change system back to Virtual Wire mode. Only PIC mode will detach the APIC from the interrupt system, Virtual Wire mode doesn't.
Besides Virutal Wire mode has two kinds: one is only setting Local APIC as Virtual Wire mode and interrupts are delivered from the PIC to the CPU which Local APIC connected to, the other is both Loca APIC and IO-APIC need be set as Virtual Wire mode.
So based on above knowledge, take IO-APIC Virtual Wire mode setting code out and wrap it inot a new function ioapic_set_virtual_wire_mode. Meanwhile change the name of disconnect_bsp_APIC as lapic_set_legacy_irq_mode. These makes the legacy irq mode setting more understandable.
--- arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/io_apic.h | 5 ++--- arch/x86/kernel/apic/apic.c | 11 ++++++----- arch/x86/kernel/apic/io_apic.c | 17 ++++++++++------- arch/x86/kernel/x86_init.c | 2 +- drivers/iommu/irq_remapping.c | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-)
arch/x86/include/asm/apic.h +1 -1
@@ -125,7 +125,7 @@ extern int get_physical_broadcast(void);extern int lapic_get_maxlvt (void );extern void clear_local_APIC (void ); -extern void disconnect_bsp_APIC (int virt_wire_setup); +extern void lapic_set_legacy_irq_mode (int virt_wire_setup);extern void disable_local_APIC (void );extern void lapic_shutdown (void );extern void sync_Arb_IDs (void );
arch/x86/include/asm/io_apic.h +2 -3
@@ -182,7 +182,7 @@ extern void disable_ioapic_support(void);extern void __init io_apic_init_mappings (void );extern unsigned int native_io_apic_read (unsigned int apic,unsigned int reg); -extern void native_disable_io_apic (void ); +extern void switch_to_legacy_irq_mode (void );static inline unsigned int io_apic_read (unsigned int apic,unsigned int reg) {
@@ -192,7 +192,6 @@ static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)extern void setup_IO_APIC (void );extern void enable_IO_APIC (void );extern void clear_IO_APIC (void ); -extern void switch_to_legacy_irq_mode (void );extern void setup_ioapic_dest (void );extern int IO_APIC_get_PCI_irq_vector (int bus,int devfn,int pin);extern void print_IO_APICs (void );
@@ -229,7 +228,7 @@ static inline void mp_save_irq(struct mpc_intsrc *m) { }static inline void disable_ioapic_support (void ) { }static inline void io_apic_init_mappings (void ) { }#define native_io_apic_read NULL -#define native_disable_io_apic NULL +#define switch_to_legacy_irq_mode NULLstatic inline void setup_IO_APIC (void ) { }static inline void enable_IO_APIC (void ) { }
arch/x86/kernel/apic/apic.c +6 -5
@@ -1934,13 +1934,14 @@ static void __init connect_bsp_APIC(void) }/** -* disconnect_bsp_APIC - detach the APIC from the interrupt system -* @virt_wire_setup: indicates, whether virtual wire mode is selected +* lapic_set_legacy_irq_mode - switch Local APIC back to be legacy irq mode. +* @virt_wire_setup: indicates, whether virtual wire mode is selected * -* Virtual wire mode is necessary to deliver legacy interrupts even when the -* APIC is disabled. +* If PIC mode is available, LAPIC need be disconnected with CPU. Otherwise +* enable LAPIC and set it to be virtual wire mode. However if IO-APIC has +* been virtual wire mode, LVT0 of LAPIC need be masked. */ -void disconnect_bsp_APIC (int virt_wire_setup) +void lapic_set_legacy_irq_mode (int virt_wire_setup) {unsigned int value;
arch/x86/kernel/apic/io_apic.c +10 -7
@@ -1430,7 +1430,7 @@ void __init enable_IO_APIC(void)clear_IO_APIC (); } -void native_disable_io_apic (void ) +static void ioapic_set_virtual_wire_mode (void ) {/* * If the i8259 is routed through an IOAPIC
@@ -1453,21 +1453,24 @@ void native_disable_io_apic(void)*/ ioapic_write_entry (ioapic_i8259.apic, ioapic_i8259.pin, entry); } - -if (boot_cpu_has (X86_FEATURE_APIC ) ||apic_from_smp_config ()) -disconnect_bsp_APIC (ioapic_i8259.pin !=-1 ); }/* -* Not an __init, needed by kexec/kdump code. -* For safety IO-APIC and Local APIC need be cleared before this. +* In legacy irq mode, full DOS compatibility with the uniprocessor PC/AT is +* provided by using the APICs in conjunction with standard 8259A-equivalent +* programmable interrupt controllers (PICs). It's necessary to deliver legacy +* interrupts even when APIC mode is not enabled. This is required by kexec/ +* kdump before enter into the 2nd kernel. */ void switch_to_legacy_irq_mode (void ) {if (!nr_legacy_irqs ())return ; - x86_io_apic_ops.disable (); +ioapic_set_virtual_wire_mode (); + +if (boot_cpu_has (X86_FEATURE_APIC ) ||apic_from_smp_config ()) +lapic_set_legacy_irq_mode (ioapic_i8259.pin !=-1 ); }#ifdef CONFIG_X86_32
arch/x86/kernel/x86_init.c +1 -1
@@ -138,5 +138,5 @@ void arch_restore_msi_irqs(struct pci_dev *dev)struct x86_io_apic_ops x86_io_apic_ops = { .read = native_io_apic_read, - .disable = native_disable_io_apic, + .disable = switch_to_legacy_irq_mode, };
drivers/iommu/irq_remapping.c +1 -1
@@ -37,7 +37,7 @@ static void irq_remapping_disable_io_apic(void)* now. */ if (boot_cpu_has (X86_FEATURE_APIC ) ||apic_from_smp_config ()) -disconnect_bsp_APIC (0 ); +lapic_set_legacy_irq_mode (0 ); }static void __init irq_remapping_modify_x86_ops (void )
Signature · 1 line
2.5.5
PATCH 3/3 x86/apic: Clean up the apic delivery mode macro definition
In reply to Baoquan HeArch x86 use ICR to send IPI, and the delivery mode in ICR can be set. They are defined like APIC_DM_xxxxx in arch/x86/include/asm/apicdef.h. LVT table also includes a delivery mode field to set the type of interrupt to be sent to processor, they are defined like APIC_MODE_xxxx. And ExtINT can only be set for LVT LINT0/1, ICR can't use ExtINT either.
However the current code defines APIC_DM_EXTINT and mixed the usage of it with APIC_MODE_EXTINT. Here clean it up.
--- arch/x86/include/asm/apicdef.h | 1 - arch/x86/kernel/apic/apic.c | 8 +++++--- arch/x86/kernel/apic/io_apic.c | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/include/asm/apicdef.h +0 -1
@@ -85,7 +85,6 @@#define APIC_DM_NMI 0x00400#define APIC_DM_INIT 0x00500#define APIC_DM_STARTUP 0x00600 -#define APIC_DM_EXTINT 0x00700#define APIC_VECTOR_MASK 0x000FF#define APIC_ICR2 0x310#define GET_APIC_DEST_FIELD (x) (((x) >> 24) & 0xFF)
arch/x86/kernel/apic/apic.c +5 -3
@@ -1163,7 +1163,8 @@ void __init init_bsp_APIC(void)/* * Set up the virtual wire mode. */ -apic_write (APIC_LVT0 ,APIC_DM_EXTINT ); + value =SET_APIC_DELIVERY_MODE (0 ,APIC_MODE_EXTINT ); +apic_write (APIC_LVT0 , value); value =APIC_DM_NMI ;if (!lapic_is_integrated ())/* 82489DX */ value |=APIC_LVT_LEVEL_TRIGGER ;
@@ -1377,10 +1378,11 @@ void setup_local_APIC(void)*/ value =apic_read (APIC_LVT0 ) &APIC_LVT_MASKED ;if (!cpu && (pic_mode || !value)) { - value =APIC_DM_EXTINT ; + value =SET_APIC_DELIVERY_MODE (0 ,APIC_MODE_EXTINT );apic_printk (APIC_VERBOSE ,"enabled ExtINT on CPU#%d\n" , cpu); }else { - value =APIC_DM_EXTINT |APIC_LVT_MASKED ; + value =SET_APIC_DELIVERY_MODE (0 ,APIC_MODE_EXTINT ); + value = value |APIC_LVT_MASKED ;apic_printk (APIC_VERBOSE ,"masked ExtINT on CPU#%d\n" , cpu); }apic_write (APIC_LVT0 , value);
arch/x86/kernel/apic/io_apic.c +5 -2
@@ -2053,6 +2053,7 @@ static inline void __init check_timer(void)int apic1, pin1, apic2, pin2;unsigned long flags;int no_pin1 =0 ; +unsigned int value;local_irq_save (flags);
@@ -2070,7 +2071,8 @@ static inline void __init check_timer(void)* The AEOI mode will finish them in the 8259A * automatically. */ -apic_write (APIC_LVT0 ,APIC_LVT_MASKED |APIC_DM_EXTINT ); + value =SET_APIC_DELIVERY_MODE (0 ,APIC_MODE_EXTINT ); +apic_write (APIC_LVT0 ,APIC_LVT_MASKED | value); legacy_pic->init (1 ); pin1 =find_isa_irq_pin (0 , mp_INT);
@@ -2171,7 +2173,8 @@ static inline void __init check_timer(void) legacy_pic->init (0 ); legacy_pic->make_irq (0 ); -apic_write (APIC_LVT0 ,APIC_DM_EXTINT ); + value =SET_APIC_DELIVERY_MODE (0 ,APIC_MODE_EXTINT ); +apic_write (APIC_LVT0 , value);unlock_ExtINT_logic ();
Signature · 1 line
2.5.5
Hi Baoquan He,
Well, Indeed there‘s a relationship between the dump-capture hangs in calibrate_delay_converge() and the interrupt mode.
but there‘s no essential difference between your patches and mine that calls disable_IO_APIC() again.
Actually, disable_IO_APIC will set APIC to virtual wire mode.
In fact,
Eric and Ingo suggested that "it should be fixed in the bootup path of the dump kernel, not the crash kernel reboot path", which is convincing and reasonable.
And i find a better method can fix the problem.
It's better to set virtual wire mode for apic in init_bsp_APIC(), which in the bootup path of dump kernel.
But now, init_bsp_APIC doesn't initialize the apic to vitual wire mode when smp_found_config is non-zero.
FYI, I'm working on this point. later i will send patches to mail list.
Wei
Quoted 56 lines · Baoquan He
Wei Jiangang reported kdump kernel always hang when "notsc" is specified in boot parameter. After debugging I found there's no timer interrupt in the current kexec/kdump kernel. This is caused by commit
522e66464467("x86/apic: Disable I/O APIC before shutdown of the local APIC"). Originally Eric posted below patch to make system be virtual wire mode in which 8259- equivalent PIC fields all interrupts and the LAPIC becomes a virtual wire. Like this interrupts can be delivered from PIC to CPU via the LAPIC's local interrupt 0 (LINTIN0). In virtual wire APIC mode is disabled while LAPIC is software enabled and its LINT0 and LINT1 need be programmed specifically.But with commit
522e66464you can see afterdisable_IO_APIChad setting virtual wire mode,lapic_shutdowndisabled LAPIC again. Now virtual wire mode doesn't work, then it cause no timer interrupt during kdump kernel initialization stage until system enter into APIC mode.So people may be wondering why only kdump kernel hang, the normal kernel with "notsc" can still work. This is because BIOS has already built PIC mode or virtual wire mode while kexec/kdump kernel doesn't go through BIOS initialization. That is why we have to change system to be PIC mode or virtual wire mode before jump to kexec/kdump kernel.
Then why kdump kernel didn't hang when "notsc" is not specified. This is because
tsc_initwill assign the already calibrated value tolpj_fine. Then kernel doesn't need to count cpu loops between jiffies with the help of timer interrupt. So "notsc" is not victim, but a informer.In patch 1/3
disable_IO_APICis changed to only contain code of changeing system to be PIC mode or virtual wire mode and is renamed asswitch_to_legacy_irq_mode. Now only callclear_IO_APICwhere IO-APIC need be disabled, and callswitch_to_legacy_irq_modebefore jump to kexe/kdump kernel.Patch 2/3 and 3/3 are clean up patch.
Baoquan He (3):
x86/apic/kexec: Enable legacy irq mode before jump to kexec/kdump
kernel
x86/apic: Clean up the names of legacy irq mode setting related
functions
x86/apic: Clean up the apic delivery mode macro definitionarch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/apicdef.h | 1 - arch/x86/include/asm/io_apic.h | 6 +++--- arch/x86/kernel/apic/apic.c | 19 +++++++++++-------- arch/x86/kernel/apic/io_apic.c | 32 +++++++++++++++++--------------- arch/x86/kernel/crash.c | 2 +- arch/x86/kernel/machine_kexec_32.c | 15 +++++---------- arch/x86/kernel/machine_kexec_64.c | 15 +++++---------- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/x86_init.c | 2 +- drivers/iommu/irq_remapping.c | 2 +- 11 files changed, 46 insertions(+), 52 deletions(-)
Hi Jiangang,
Quoted 8 lines · Jiangang
Hi Baoquan He,
Well, Indeed there‘s a relationship between the dump-capture hangs in
calibrate_delay_converge()and the interrupt mode.but there‘s no essential difference between your patches and mine that calls
disable_IO_APIC()again.
Actually,disable_IO_APICwill set APIC to virtual wire mode.
You didn't read my patch log carefully. disable_IO_APIC not only set APIC to PIC mode or virtual wire mode, but call clear_IO_APIC.
Quoted 5 lines
In fact,
Eric and Ingo suggested that "it should be fixed in the bootup path of the dump kernel, not the crash kernel reboot path", which is convincing and reasonable.
Well this patch doesn't do differently with Eric's original implemention in kexec/kdump path.
By taking out clear_IO_APIC from disable_IO_APIC, the left code of disable_IO_APIC will only do the virtual wire setting. So for kexec/kdump path, code basically is the same as Eric's method. But for poweroff/halt/reboot, it's enough to call clear_IO_APIC to disable IO-APIC.
Quoted 6 lines
And i find a better method can fix the problem.
It's better to set virtual wire mode for apic ininit_bsp_APIC(), which in the bootup path of dump kernel.
But now,init_bsp_APICdoesn't initialize the apic to vitual wire mode whensmp_found_configis non-zero.
And virtual wire mode have two kinds, IO-APIC virtual wire mode and LAPIC virtual wire mode. Please read code comments in init_bsp_APIC, IO-APIC virtual wire mode could be active or need be set, you can't detect IO-APIC pin connected to i8259 equvialent PIC.
Quoted 69 lines
FYI, I'm working on this point. later i will send patches to mail list.
Wei
Quoted 43 lines · Baoquan He
Wei Jiangang reported kdump kernel always hang when "notsc" is specified in boot parameter. After debugging I found there's no timer interrupt in the current kexec/kdump kernel. This is caused by commit
522e66464467("x86/apic: Disable I/O APIC before shutdown of the local APIC"). Originally Eric posted below patch to make system be virtual wire mode in which 8259- equivalent PIC fields all interrupts and the LAPIC becomes a virtual wire. Like this interrupts can be delivered from PIC to CPU via the LAPIC's local interrupt 0 (LINTIN0). In virtual wire APIC mode is disabled while LAPIC is software enabled and its LINT0 and LINT1 need be programmed specifically.But with commit
522e66464you can see afterdisable_IO_APIChad setting virtual wire mode,lapic_shutdowndisabled LAPIC again. Now virtual wire mode doesn't work, then it cause no timer interrupt during kdump kernel initialization stage until system enter into APIC mode.So people may be wondering why only kdump kernel hang, the normal kernel with "notsc" can still work. This is because BIOS has already built PIC mode or virtual wire mode while kexec/kdump kernel doesn't go through BIOS initialization. That is why we have to change system to be PIC mode or virtual wire mode before jump to kexec/kdump kernel.
Then why kdump kernel didn't hang when "notsc" is not specified. This is because
tsc_initwill assign the already calibrated value tolpj_fine. Then kernel doesn't need to count cpu loops between jiffies with the help of timer interrupt. So "notsc" is not victim, but a informer.In patch 1/3
disable_IO_APICis changed to only contain code of changeing system to be PIC mode or virtual wire mode and is renamed asswitch_to_legacy_irq_mode. Now only callclear_IO_APICwhere IO-APIC need be disabled, and callswitch_to_legacy_irq_modebefore jump to kexe/kdump kernel.Patch 2/3 and 3/3 are clean up patch.
Baoquan He (3):
x86/apic/kexec: Enable legacy irq mode before jump to kexec/kdump
kernel
x86/apic: Clean up the names of legacy irq mode setting related
functions
x86/apic: Clean up the apic delivery mode macro definitionQuoted 13 lines
arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/apicdef.h | 1 - arch/x86/include/asm/io_apic.h | 6 +++--- arch/x86/kernel/apic/apic.c | 19 +++++++++++-------- arch/x86/kernel/apic/io_apic.c | 32 +++++++++++++++++--------------- arch/x86/kernel/crash.c | 2 +- arch/x86/kernel/machine_kexec_32.c | 15 +++++---------- arch/x86/kernel/machine_kexec_64.c | 15 +++++---------- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/x86_init.c | 2 +- drivers/iommu/irq_remapping.c | 2 +- 11 files changed, 46 insertions(+), 52 deletions(-)_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Jiangang
Hi Baoquan He,
Well, Indeed there‘s a relationship between the dump-capture hangs in
calibrate_delay_converge()and the interrupt mode.but there‘s no essential difference between your patches and mine that calls
disable_IO_APIC()again.
Actually,disable_IO_APICwill set APIC to virtual wire mode.
Well, about this I want to explain a little bit. Usually people posted a patch, reviewers can give comments, suggestions or other ideas. During reviewing stage patch author need answer questions from people interested. So this is an interactive action, reviewers can also learn knowledge, meanwhile give comments.
When reviewing your patch, I have many questions, and only get two pieces of information, kdump kernel hang with notsc, and disable_IO_APIC can save it. You even can't answer people's question why disable_IO_APIC need be called twice with your patch. I have to dig code and read intel arch manual and MP spec and Eric's original patch thread, and add debug bug to verify all. How can it be like you said "no essential difference between your patches and mine"?
Quoted 11 lines
In fact,
Eric and Ingo suggested that "it should be fixed in the bootup path of the dump kernel, not the crash kernel reboot path", which is convincing and reasonable.And i find a better method can fix the problem.
It's better to set virtual wire mode for apic ininit_bsp_APIC(), which in the bootup path of dump kernel.
But now,init_bsp_APICdoesn't initialize the apic to vitual wire mode whensmp_found_configis non-zero.
This may be do-able, let's see what Eric and Ingo will say.
Quoted 69 lines
FYI, I'm working on this point. later i will send patches to mail list.
Wei
Quoted 43 lines · Baoquan He
Wei Jiangang reported kdump kernel always hang when "notsc" is specified in boot parameter. After debugging I found there's no timer interrupt in the current kexec/kdump kernel. This is caused by commit
522e66464467("x86/apic: Disable I/O APIC before shutdown of the local APIC"). Originally Eric posted below patch to make system be virtual wire mode in which 8259- equivalent PIC fields all interrupts and the LAPIC becomes a virtual wire. Like this interrupts can be delivered from PIC to CPU via the LAPIC's local interrupt 0 (LINTIN0). In virtual wire APIC mode is disabled while LAPIC is software enabled and its LINT0 and LINT1 need be programmed specifically.But with commit
522e66464you can see afterdisable_IO_APIChad setting virtual wire mode,lapic_shutdowndisabled LAPIC again. Now virtual wire mode doesn't work, then it cause no timer interrupt during kdump kernel initialization stage until system enter into APIC mode.So people may be wondering why only kdump kernel hang, the normal kernel with "notsc" can still work. This is because BIOS has already built PIC mode or virtual wire mode while kexec/kdump kernel doesn't go through BIOS initialization. That is why we have to change system to be PIC mode or virtual wire mode before jump to kexec/kdump kernel.
Then why kdump kernel didn't hang when "notsc" is not specified. This is because
tsc_initwill assign the already calibrated value tolpj_fine. Then kernel doesn't need to count cpu loops between jiffies with the help of timer interrupt. So "notsc" is not victim, but a informer.In patch 1/3
disable_IO_APICis changed to only contain code of changeing system to be PIC mode or virtual wire mode and is renamed asswitch_to_legacy_irq_mode. Now only callclear_IO_APICwhere IO-APIC need be disabled, and callswitch_to_legacy_irq_modebefore jump to kexe/kdump kernel.Patch 2/3 and 3/3 are clean up patch.
Baoquan He (3):
x86/apic/kexec: Enable legacy irq mode before jump to kexec/kdump
kernel
x86/apic: Clean up the names of legacy irq mode setting related
functions
x86/apic: Clean up the apic delivery mode macro definitionQuoted 13 lines
arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/apicdef.h | 1 - arch/x86/include/asm/io_apic.h | 6 +++--- arch/x86/kernel/apic/apic.c | 19 +++++++++++-------- arch/x86/kernel/apic/io_apic.c | 32 +++++++++++++++++--------------- arch/x86/kernel/crash.c | 2 +- arch/x86/kernel/machine_kexec_32.c | 15 +++++---------- arch/x86/kernel/machine_kexec_64.c | 15 +++++---------- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/x86_init.c | 2 +- drivers/iommu/irq_remapping.c | 2 +- 11 files changed, 46 insertions(+), 52 deletions(-)_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 6 lines · On Wed, 20 Jul 2016, [email protected] wrote:
Quoted 3 lines · Jiangang
In fact, Eric and Ingo suggested that "it should be fixed in the bootup
path of the dump kernel, not the crash kernel reboot path", which is convincing and reasonable.
Quoted 7 lines
Well this patch doesn't do differently with Eric's original implemention in kexec/kdump path.
By taking outclear_IO_APICfromdisable_IO_APIC, the left code ofdisable_IO_APICwill only do the virtual wire setting. So for kexec/kdump path, code basically is the same as Eric's method. But for poweroff/halt/reboot, it's enough to callclear_IO_APICto disable IO-APIC.
You're completely ignoring what Jiangang said:
"it should be fixed in the bootup path of the dump kernel, not the crash
kernel reboot path"
and that's the right way to do it. End of story.
Thanks,
tglx
Quoted 15 lines · Thomas Gleixner
Quoted 6 lines · On Wed, 20 Jul 2016, [email protected] wrote:
Quoted 3 lines · Jiangang
In fact, Eric and Ingo suggested that "it should be fixed in the bootup
path of the dump kernel, not the crash kernel reboot path", which is convincing and reasonable.Quoted 7 lines
Well this patch doesn't do differently with Eric's original implemention in kexec/kdump path.
By taking outclear_IO_APICfromdisable_IO_APIC, the left code ofdisable_IO_APICwill only do the virtual wire setting. So for kexec/kdump path, code basically is the same as Eric's method. But for poweroff/halt/reboot, it's enough to callclear_IO_APICto disable IO-APIC.
Quoted 6 lines
You're completely ignoring what Jiangang said:
"it should be fixed in the bootup path of the dump kernel, not the crash
kernel reboot path"and that's the right way to do it. End of story.
Thanks, tglx. What I did is like reverting commit 522e6646446. But it would be great if we can change to fix it in bootup path.
Thanks
Baoquan
kbuild test robot
build botRe: [PATCH 3/3] x86/apic: Clean up the apic delivery mode macro definition
In reply to Baoquan Hereproduce:
Hi,
[auto build test ERROR on iommu/next]
[also build test ERROR on v4.7-rc7 next-20160722]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baoquan-He/Enable-legacy-irq-mode-before-jump-to-kexec-kdump-kernel/20160724-054857 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next config: i386-randconfig-i0-201630 (attached as .config) compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
arch/x86/kvm/lapic.c: In function '__apic_accept_irq':
>> arch/x86/kvm/lapic.c:963:7: error: 'APIC_DM_EXTINT' undeclared (first use in this function)
case APIC_DM_EXTINT:
^ arch/x86/kvm/lapic.c:963:7: note: each undeclared identifier is reported only once for each function it appears in
vim +/APIC_DM_EXTINT +963 arch/x86/kvm/lapic.c
66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 957 smp_wmb(); 66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 958 set_bit(KVM_APIC_SIPI, &apic->pending_events); 3842d135f arch/x86/kvm/lapic.c Avi Kivity 2010-07-27 959 kvm_make_request(KVM_REQ_EVENT, vcpu); d76901750 arch/x86/kvm/lapic.c Marcelo Tosatti 2008-09-08 960 kvm_vcpu_kick(vcpu); 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 961 break; 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 962 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 @963 case APIC_DM_EXTINT: 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 964 /* 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 965 * Should only be called by kvm_apic_local_deliver() with LVT0, 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 966 * before NMI watchdog was enabled. Already handled by
:::::: The code at line 963 was first introduced by commit
:::::: 23930f9521c9c4d4aa96cdb9d1e1703f3782bb94 KVM: x86: Enable NMI Watchdog via in-kernel PIT source
:::::: TO: Jan Kiszka <[email protected]>
:::::: CC: Avi Kivity <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH 3/3] x86/apic: Clean up the apic delivery mode macro definition
In reply to Baoquan Hereproduce:
Hi,
[auto build test WARNING on iommu/next]
[also build test WARNING on v4.7-rc7 next-20160722]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baoquan-He/Enable-legacy-irq-mode-before-jump-to-kexec-kdump-kernel/20160724-054857 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next reproduce: # apt-get install sparse make ARCH=x86_64 allmodconfig make C=1 CF=-D__CHECK_ENDIAN__
sparse warnings: (new ones prefixed by >>)
include/linux/compiler.h:232:8: sparse: attribute 'no_sanitize_address': unknown attribute arch/x86/kvm/lapic.c:186:15: sparse: incompatible types in comparison expression (different address spaces) arch/x86/kvm/lapic.c:963:14: sparse: undefined identifier 'APIC_DM_EXTINT'
>> arch/x86/kvm/lapic.c:963:14: sparse: incompatible types for 'case' statement
arch/x86/kvm/lapic.c:699:15: sparse: incompatible types in comparison expression (different address spaces)
arch/x86/kvm/lapic.c:799:15: sparse: incompatible types in comparison expression (different address spaces)
arch/x86/kvm/lapic.c:963:14: sparse: Expected constant expression in case statement
arch/x86/kvm/lapic.c: In function '__apic_accept_irq':
arch/x86/kvm/lapic.c:963:7: error: 'APIC_DM_EXTINT' undeclared (first use in this function)
case APIC_DM_EXTINT:
^~~~~~~~~~~~~~ arch/x86/kvm/lapic.c:963:7: note: each undeclared identifier is reported only once for each function it appears in
vim +/case +963 arch/x86/kvm/lapic.c
c5ec15340 drivers/kvm/lapic.c He, Qing 2007-09-03 947 vcpu->vcpu_id);
c5ec15340 drivers/kvm/lapic.c He, Qing 2007-09-03 948 }
97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 949 break;
97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 950
97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 951 case APIC_DM_STARTUP:
1b10bf31a arch/x86/kvm/lapic.c Jan Kiszka 2008-09-30 952 apic_debug("SIPI to vcpu %d vector 0x%02x\n",
c5ec15340 drivers/kvm/lapic.c He, Qing 2007-09-03 953 vcpu->vcpu_id, vector);
6da7e3f64 arch/x86/kvm/lapic.c Gleb Natapov 2009-03-05 954 result = 1;
66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 955 apic->sipi_vector = vector;
66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 956 /* make sure sipi_vector is visible for the receiver */
66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 957 smp_wmb();
66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 958 set_bit(KVM_APIC_SIPI, &apic->pending_events);
3842d135f arch/x86/kvm/lapic.c Avi Kivity 2010-07-27 959 kvm_make_request(KVM_REQ_EVENT, vcpu);
d76901750 arch/x86/kvm/lapic.c Marcelo Tosatti 2008-09-08 960 kvm_vcpu_kick(vcpu);
97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 961 break;
97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 962
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 @963 case APIC_DM_EXTINT:
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 964 /*
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 965 * Should only be called by kvm_apic_local_deliver() with LVT0,
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 966 * before NMI watchdog was enabled. Already handled by
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 967 * kvm_apic_accept_pic_intr().
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 968 */
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 969 break;
23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 970
97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 971 default::::::: The code at line 963 was first introduced by commit
:::::: 23930f9521c9c4d4aa96cdb9d1e1703f3782bb94 KVM: x86: Enable NMI Watchdog via in-kernel PIT source
:::::: TO: Jan Kiszka <[email protected]> :::::: CC: Avi Kivity <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 3/3] x86/apic: Clean up the apic delivery mode macro definition
Quoted 1 line · kbuild test robot
Hi,
Sorry, I didn't notice this. And after checking code, APIC_DM_EXTINT could be added for kvm on purpose thought it's not defined in Intel Arch manual. I am not familiar with KVM, so please drop this patch to avoid warning. I will make time to study it later.
Thanks
Baoquan
Quoted 66 lines
[auto build test WARNING on iommu/next]
[also build test WARNING on v4.7-rc7 next-20160722]
[cannot apply to tip/x86/core]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Baoquan-He/Enable-legacy-irq-mode-before-jump-to-kexec-kdump-kernel/20160724-054857 base: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next reproduce: # apt-get install sparse make ARCH=x86_64 allmodconfig make C=1 CF=-D__CHECK_ENDIAN__sparse warnings: (new ones prefixed by >>)
include/linux/compiler.h:232:8: sparse: attribute 'no_sanitize_address': unknown attributearch/x86/kvm/lapic.c:186:15: sparse: incompatible types in comparison expression (different address spaces)arch/x86/kvm/lapic.c:963:14: sparse: undefined identifier 'APIC_DM_EXTINT'Quoted 1 line
Quoted 1 line
arch/x86/kvm/lapic.c:963:14: sparse: incompatible types for 'case' statement
arch/x86/kvm/lapic.c:699:15: sparse: incompatible types in comparison expression (different address spaces)arch/x86/kvm/lapic.c:799:15: sparse: incompatible types in comparison expression (different address spaces)arch/x86/kvm/lapic.c:963:14: sparse: Expected constant expression in case statementarch/x86/kvm/lapic.c: In function '__apic_accept_irq':
arch/x86/kvm/lapic.c:963:7: error: 'APIC_DM_EXTINT' undeclared (first use in this function)case APIC_DM_EXTINT: ^~~~~~~~~~~~~~
arch/x86/kvm/lapic.c:963:7: note: each undeclared identifier is reported only once for each function it appears invim +/case +963
arch/x86/kvm/lapic.cc5ec15340 drivers/kvm/lapic.c He, Qing 2007-09-03 947 vcpu->vcpu_id); c5ec15340 drivers/kvm/lapic.c He, Qing 2007-09-03 948 } 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 949 break; 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 950 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 951 case APIC_DM_STARTUP: 1b10bf31a arch/x86/kvm/lapic.c Jan Kiszka 2008-09-30 952 apic_debug("SIPI to vcpu %d vector 0x%02x\n", c5ec15340 drivers/kvm/lapic.c He, Qing 2007-09-03 953 vcpu->vcpu_id, vector); 6da7e3f64 arch/x86/kvm/lapic.c Gleb Natapov 2009-03-05 954 result = 1; 66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 955 apic->sipi_vector = vector; 66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 956 /* make sure sipi_vector is visible for the receiver */ 66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 957 smp_wmb(); 66450a21f arch/x86/kvm/lapic.c Jan Kiszka 2013-03-13 958 set_bit(KVM_APIC_SIPI, &apic->pending_events); 3842d135f arch/x86/kvm/lapic.c Avi Kivity 2010-07-27 959 kvm_make_request(KVM_REQ_EVENT, vcpu); d76901750 arch/x86/kvm/lapic.c Marcelo Tosatti 2008-09-08 960 kvm_vcpu_kick(vcpu); 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 961 break; 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 962 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 @963 case APIC_DM_EXTINT: 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 964 /* 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 965 * Should only be called by kvm_apic_local_deliver() with LVT0, 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 966 * before NMI watchdog was enabled. Already handled by 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 967 * kvm_apic_accept_pic_intr(). 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 968 */ 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 969 break; 23930f952 arch/x86/kvm/lapic.c Jan Kiszka 2008-09-26 970 97222cc83 drivers/kvm/lapic.c Eddie Dong 2007-09-12 971 default::::::: The code at line 963 was first introduced by commit
::::::23930f9521c9c4d4aa96cdb9d1e1703f3782bb94KVM: x86: Enable NMI Watchdog via in-kernel PIT source:::::: TO: Jan Kiszka <[email protected]> :::::: CC: Avi Kivity <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation