linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kexec: Fix kdump failure with notsc
@ 2016-07-07  7:20 Wei Jiangang
  2016-07-07  8:46 ` kbuild test robot
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Jiangang @ 2016-07-07  7:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: x86, kexec, tglx, mingo, hpa, ebiederm, fenghua.yu, izumi.taku,
	Wei Jiangang

If we specify the 'notsc' boot parameter for the dump-capture kernel,
and then trigger a crash(panic) by using "ALT-SysRq-c" or "echo c >
/proc/sysrq-trigger",
the dump-capture kernel will hang in calibrate_delay_converge():

    /* wait for "start of" clock tick */
    ticks = jiffies;
    while (ticks == jiffies)
        ; /* nothing */

serial log of the hang is as follows:

    tsc: Fast TSC calibration using PIT
    tsc: Detected 2099.947 MHz processor
    Calibrating delay loop...

The reason is that the dump-capture kernel hangs in while loops and
waits for jiffies to be updated, but no timer interrupts is passed
to BSP by APIC.

In fact, the local APIC was disabled in reboot and crash path by
lapic_shutdown(). We need to put APIC in legacy mode in kexec jump path
(put the system into PIT during the crash kernel),
so that the dump-capture kernel can get timer interrupts.

BTW,
I found the buggy commit 522e66464467 ("x86/apic: Disable I/O APIC
before shutdown of the local APIC") via bisection.

Originally, I want to revert it.
But Ingo Molnar comments that "By reverting the change can paper over
the bug, but re-introduce the bug that can result in certain CPUs hanging
if IO-APIC sends an APIC message if the lapic is disabled prematurely"
And I think it's pertinent.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
---
 arch/x86/include/asm/apic.h        | 5 +++++
 arch/x86/kernel/apic/apic.c        | 9 +++++++++
 arch/x86/kernel/machine_kexec_32.c | 5 ++---
 arch/x86/kernel/machine_kexec_64.c | 5 ++---
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index bc27611fa58f..5d7e635e580a 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -128,6 +128,7 @@ extern void clear_local_APIC(void);
 extern void disconnect_bsp_APIC(int virt_wire_setup);
 extern void disable_local_APIC(void);
 extern void lapic_shutdown(void);
+extern int lapic_disabled(void);
 extern void sync_Arb_IDs(void);
 extern void init_bsp_APIC(void);
 extern void setup_local_APIC(void);
@@ -165,6 +166,10 @@ extern int setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask);
 
 #else /* !CONFIG_X86_LOCAL_APIC */
 static inline void lapic_shutdown(void) { }
+static inline int lapic_disabled(void)
+{
+	return 0;
+}
 #define local_apic_timer_c2_ok		1
 static inline void init_apic_mappings(void) { }
 static inline void disable_local_APIC(void) { }
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 60078a67d7e3..d1df250994bb 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -133,6 +133,9 @@ static inline void imcr_apic_to_pic(void)
 }
 #endif
 
+/* Local APIC is disabled by the kernel for crash or reboot path */
+static int disabled_local_apic;
+
 /*
  * Knob to control our willingness to enable the local APIC.
  *
@@ -1097,10 +1100,16 @@ void lapic_shutdown(void)
 #endif
 		disable_local_APIC();
 
+	disabled_local_apic = 1;
 
 	local_irq_restore(flags);
 }
 
+int lapic_disabled(void)
+{
+	return disabled_local_apic;
+}
+
 /**
  * sync_Arb_IDs - synchronize APIC bus arbitration IDs
  */
diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
index 469b23d6acc2..c934a7868e6b 100644
--- a/arch/x86/kernel/machine_kexec_32.c
+++ b/arch/x86/kernel/machine_kexec_32.c
@@ -202,14 +202,13 @@ void machine_kexec(struct kimage *image)
 	local_irq_disable();
 	hw_breakpoint_disable();
 
-	if (image->preserve_context) {
+	if (image->preserve_context || lapic_disabled()) {
 #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.
+		 * one form or other. kexec jump path also need one.
 		 */
 		disable_IO_APIC();
 #endif
diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
index 5a294e48b185..4925a6bb932a 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -269,14 +269,13 @@ void machine_kexec(struct kimage *image)
 	local_irq_disable();
 	hw_breakpoint_disable();
 
-	if (image->preserve_context) {
+	if (image->preserve_context || lapic_disabled()) {
 #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.
+		 * one form or other. kexec jump path also need one.
 		 */
 		disable_IO_APIC();
 #endif
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kexec: Fix kdump failure with notsc
  2016-07-07  7:20 [PATCH] kexec: Fix kdump failure with notsc Wei Jiangang
@ 2016-07-07  8:46 ` kbuild test robot
  2016-07-07 10:26   ` Wei, Jiangang
  0 siblings, 1 reply; 3+ messages in thread
From: kbuild test robot @ 2016-07-07  8:46 UTC (permalink / raw)
  To: Wei Jiangang
  Cc: kbuild-all, linux-kernel, x86, kexec, tglx, mingo, hpa, ebiederm,
	fenghua.yu, izumi.taku, Wei Jiangang

[-- Attachment #1: Type: text/plain, Size: 1496 bytes --]

Hi,

[auto build test ERROR on tip/x86/core]
[also build test ERROR on v4.7-rc6 next-20160706]
[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/Wei-Jiangang/kexec-Fix-kdump-failure-with-notsc/20160707-152535
config: x86_64-randconfig-s5-07071541 (attached as .config)
compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   arch/x86/kernel/machine_kexec_64.c: In function 'machine_kexec':
>> arch/x86/kernel/machine_kexec_64.c:272:33: error: implicit declaration of function 'lapic_disabled' [-Werror=implicit-function-declaration]
     if (image->preserve_context || lapic_disabled()) {
                                    ^~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/lapic_disabled +272 arch/x86/kernel/machine_kexec_64.c

   266		save_ftrace_enabled = __ftrace_enabled_save();
   267	
   268		/* Interrupts aren't acceptable while we reboot */
   269		local_irq_disable();
   270		hw_breakpoint_disable();
   271	
 > 272		if (image->preserve_context || lapic_disabled()) {
   273	#ifdef CONFIG_X86_IO_APIC
   274			/*
   275			 * We need to put APICs in legacy mode so that we can

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 30554 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kexec: Fix kdump failure with notsc
  2016-07-07  8:46 ` kbuild test robot
@ 2016-07-07 10:26   ` Wei, Jiangang
  0 siblings, 0 replies; 3+ messages in thread
From: Wei, Jiangang @ 2016-07-07 10:26 UTC (permalink / raw)
  To: lkp
  Cc: kexec, linux-kernel, tglx, fenghua.yu, ebiederm, x86, hpa, mingo,
	Izumi, Taku, kbuild-all

Hi all,

I fixed the compile error and sent the v2.
Please ignore this serial.

Thanks,
wei

On Thu, 2016-07-07 at 16:46 +0800, kbuild test robot wrote:
> Hi,
> 
> [auto build test ERROR on tip/x86/core]
> [also build test ERROR on v4.7-rc6 next-20160706]
> [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/Wei-Jiangang/kexec-Fix-kdump-failure-with-notsc/20160707-152535
> config: x86_64-randconfig-s5-07071541 (attached as .config)
> compiler: gcc-6 (Debian 6.1.1-1) 6.1.1 20160430
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=x86_64 
> 
> All errors (new ones prefixed by >>):
> 
>    arch/x86/kernel/machine_kexec_64.c: In function 'machine_kexec':
> >> arch/x86/kernel/machine_kexec_64.c:272:33: error: implicit declaration of function 'lapic_disabled' [-Werror=implicit-function-declaration]
>      if (image->preserve_context || lapic_disabled()) {
>                                     ^~~~~~~~~~~~~~
>    cc1: some warnings being treated as errors
> 
> vim +/lapic_disabled +272 arch/x86/kernel/machine_kexec_64.c
> 
>    266		save_ftrace_enabled = __ftrace_enabled_save();
>    267	
>    268		/* Interrupts aren't acceptable while we reboot */
>    269		local_irq_disable();
>    270		hw_breakpoint_disable();
>    271	
>  > 272		if (image->preserve_context || lapic_disabled()) {
>    273	#ifdef CONFIG_X86_IO_APIC
>    274			/*
>    275			 * We need to put APICs in legacy mode so that we can
> 
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-07 10:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-07  7:20 [PATCH] kexec: Fix kdump failure with notsc Wei Jiangang
2016-07-07  8:46 ` kbuild test robot
2016-07-07 10:26   ` Wei, Jiangang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).