riscv: kexec: Fxiup crash_save percpu and machine_kexec_mask_interrupts
Subsystems (4)
v4 cover riscv: kexec: Fxiup crash_save percpu and machine_kexec_mask_interrupts
From: Guo Ren <[email protected]>
Current riscv kexec can't crash_save percpu states and disable interrupts properly. The patch series fix them, make kexec work correct.
Also cleanup arm64, x86 declarations in asm/smp.h.
Changlogs:
v4:
- Add cpu_ops[cpu]->cpu_stop() in ipi_cpu_crash_stop
- Wording optimization in comments
V3:
https://lore.kernel.org/linux-riscv/[email protected]/
- Fixup compile problem with !SMP, which reported by [email protected]
- Cleanup declarations in asm/smp.h
- Add reviewed-by
V2:
https://lore.kernel.org/linux-riscv/[email protected]/
- Add Fixes tags
- Remove extern from bool smp_crash_stop_failed(void)
V1:
https://lore.kernel.org/linux-riscv/[email protected]/
Guo Ren (3):
riscv: kexec: Fixup irq controller broken in kexec crash path
riscv: kexec: Fixup crash_smp_send_stop without multi cores
arch: crash: Remove duplicate declaration in smp.h
arch/arm64/include/asm/smp.h | 1 - arch/riscv/include/asm/smp.h | 3 + arch/riscv/kernel/machine_kexec.c | 46 +++++++++++---- arch/riscv/kernel/smp.c | 97 ++++++++++++++++++++++++++++++- arch/x86/include/asm/crash.h | 1 - 5 files changed, 133 insertions(+), 15 deletions(-)
Signature · 7 lines
2.36.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v4 1/3 riscv: kexec: Fixup irq controller broken in kexec crash path
From: Guo Ren <[email protected]>
If a crash happens on cpu3 and all interrupts are binding on cpu0, the bad irq routing will cause a crash kernel which can't receive any irq. Because crash kernel won't clean up all harts' PLIC enable bits in enable registers. This patch is similar to 9141a003a491 ("ARM: 7316/1:
kexec: EOI active and mask all interrupts in kexec crash path") and 78fd584cdec0 ("arm64: kdump: implement machine_crash_shutdown()"), and PowerPC also has the same mechanism.
--- arch/riscv/kernel/machine_kexec.c | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
arch/riscv/kernel/machine_kexec.c +35 -0
@@ -15,6 +15,8 @@#include <linux/compiler.h> /* For unreachable() */ #include <linux/cpu.h> /* For cpu_down() */ #include <linux/reboot.h> +#include <linux/interrupt.h> +#include <linux/irq.h> /* * kexec_image_info - Print received image details
@@ -154,6 +156,37 @@ void crash_smp_send_stop(void) cpus_stopped =1 ; } +static void machine_kexec_mask_interrupts (void ) +{ +unsigned int i; +struct irq_desc *desc; + +for_each_irq_desc (i, desc) { +struct irq_chip *chip; +int ret; + + chip =irq_desc_get_chip (desc); +if (!chip) +continue ; + +/* +* First try to remove the active state. If this +* fails, try to EOI the interrupt. +*/ + ret =irq_set_irqchip_state (i,IRQCHIP_STATE_ACTIVE , false); + +if (ret &&irqd_irq_inprogress (&desc->irq_data) && + chip->irq_eoi) + chip->irq_eoi (&desc->irq_data); + +if (chip->irq_mask) + chip->irq_mask (&desc->irq_data); + +if (chip->irq_disable && !irqd_irq_disabled (&desc->irq_data)) + chip->irq_disable (&desc->irq_data); + } +} +/* * machine_crash_shutdown - Prepare to kexec after a kernel crash *
@@ -169,6 +202,8 @@ machine_crash_shutdown(struct pt_regs *regs)crash_smp_send_stop ();crash_save_cpu (regs,smp_processor_id ()); +machine_kexec_mask_interrupts (); +pr_info ("Starting crashdump kernel...\n" ); }
Signature · 7 lines
2.36.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v4 2/3 riscv: kexec: Fixup crash_smp_send_stop without multi cores
In reply to [email protected]From: Guo Ren <[email protected]>
Current crash_smp_send_stop is the same as the generic one in kernel/panic and misses crash_save_cpu in percpu. This patch is inspired by 78fd584cdec0 ("arm64: kdump: implement machine_crash_shutdown()") and adds the same mechanism for riscv.
--- arch/riscv/include/asm/smp.h | 3 + arch/riscv/kernel/machine_kexec.c | 21 ++----- arch/riscv/kernel/smp.c | 97 ++++++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 18 deletions(-)
arch/riscv/include/asm/smp.h +3 -0
@@ -50,6 +50,9 @@ void riscv_set_ipi_ops(const struct riscv_ipi_ops *ops);/* Clear IPI for current CPU */ void riscv_clear_ipi (void ); +/* Check other CPUs stop or not */ +bool smp_crash_stop_failed (void ); +/* Secondary hart entry */ asmlinkage void smp_callin(void);
arch/riscv/kernel/machine_kexec.c +5 -16
@@ -140,22 +140,6 @@ void machine_shutdown(void)#endif } -/* Override the weak function in kernel/panic.c */ -void crash_smp_send_stop (void ) -{ -static int cpus_stopped; - -/* -* This function can be called twice in panic path, but obviously -* we execute this only once. -*/ -if (cpus_stopped) -return ; - -smp_send_stop (); - cpus_stopped =1 ; -} -static void machine_kexec_mask_interrupts (void ) {unsigned int i;
@@ -230,6 +214,11 @@ machine_kexec(struct kimage *image)void *control_code_buffer =page_address (image->control_code_page);riscv_kexec_method kexec_method =NULL ; +#ifdef CONFIG_SMP +WARN (smp_crash_stop_failed (), +"Some CPUs may be stale, kdump will be unreliable.\n" ); +#endif +if (image->type !=KEXEC_TYPE_CRASH ) kexec_method = control_code_buffer;else
arch/riscv/kernel/smp.c +95 -2
144 lines not on this page · raw message
Signature · 7 lines
2.36.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v4 3/3 arch: crash: Remove duplicate declaration in smp.h
In reply to [email protected]From: Guo Ren <[email protected]>
Remove crash_smp_send_stop declarations in arm64, x86 asm/smp.h which has been done in include/linux/smp.h.
--- arch/arm64/include/asm/smp.h | 1 - arch/x86/include/asm/crash.h | 1 - 2 files changed, 2 deletions(-)
arch/arm64/include/asm/smp.h +0 -1
@@ -141,7 +141,6 @@ static inline void cpu_panic_kernel(void)*/ bool cpus_are_stuck_in_kernel (void ); -extern void crash_smp_send_stop (void );extern bool smp_crash_stop_failed (void );extern void panic_smp_self_stop (void );
arch/x86/include/asm/crash.h +0 -1
@@ -7,6 +7,5 @@ struct kimage;int crash_load_segments (struct kimage *image);int crash_setup_memmap_entries (struct kimage *image,struct boot_params *params); -void crash_smp_send_stop (void );#endif /* _ASM_X86_CRASH_H */
Signature · 7 lines
2.36.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH V4 3/3] arch: crash: Remove duplicate declaration in smp.h
Am Mittwoch, 21. September 2022, 05:31:34 CEST schrieb [email protected]:
Quoted 4 lines
From: Guo Ren <[email protected]>
Remove
crash_smp_send_stopdeclarations in arm64, x86asm/smp.hwhich has been done ininclude/linux/smp.h.
nit: the commit message could reference the commit that brought in the generic declarations, which was
6f1f942cd5fb ("smp: kernel/panic.c - silence warnings")other than that
Quoted 34 lines
Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Acked-by Catalin Marinas <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Thomas Gleixner <[email protected]>--- arch/arm64/include/asm/smp.h | 1 - arch/x86/include/asm/crash.h | 1 - 2 files changed, 2 deletions(-)arch/arm64/include/asm/smp.h +0
-1@@ -141,7 +141,6 @@ static inline void cpu_panic_kernel(void)*/ bool cpus_are_stuck_in_kernel (void ); -extern void crash_smp_send_stop (void );extern bool smp_crash_stop_failed (void );extern void panic_smp_self_stop (void );arch/x86/include/asm/crash.h +0
-1@@ -7,6 +7,5 @@ struct kimage;int crash_load_segments (struct kimage *image);int crash_setup_memmap_entries (struct kimage *image,struct boot_params *params); -void crash_smp_send_stop (void );#endif /* _ASM_X86_CRASH_H */
Re: [PATCH V4 3/3] arch: crash: Remove duplicate declaration in smp.h
Quoted 10 lines · Heiko Stuebner
Am Mittwoch, 21. September 2022, 05:31:34 CEST schrieb [email protected]:
Quoted 4 lines
From: Guo Ren <[email protected]>
Remove
crash_smp_send_stopdeclarations in arm64, x86asm/smp.hwhich has been done ininclude/linux/smp.h.nit: the commit message could reference the commit that brought in the generic declarations, which was
6f1f942cd5fb ("smp: kernel/panic.c - silence warnings")
Good advice, thx.
Quoted 43 lines
other than that
Reviewed-by Heiko Stuebner <[email protected]>Quoted 34 lines
Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Acked-by Catalin Marinas <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Thomas Gleixner <[email protected]>--- arch/arm64/include/asm/smp.h | 1 - arch/x86/include/asm/crash.h | 1 - 2 files changed, 2 deletions(-)arch/arm64/include/asm/smp.h +0
-1@@ -141,7 +141,6 @@ static inline void cpu_panic_kernel(void)*/ bool cpus_are_stuck_in_kernel (void ); -extern void crash_smp_send_stop (void );extern bool smp_crash_stop_failed (void );extern void panic_smp_self_stop (void );arch/x86/include/asm/crash.h +0
-1@@ -7,6 +7,5 @@ struct kimage;int crash_load_segments (struct kimage *image);int crash_setup_memmap_entries (struct kimage *image,struct boot_params *params); -void crash_smp_send_stop (void );#endif /* _ASM_X86_CRASH_H */
Signature · 2 lines
Best Regards Guo Ren