MIPS: kexec/kdump: Fix smp reboot and other issues
Subsystems (4)
v5 cover MIPS: kexec/kdump: Fix smp reboot and other issues
Hi Paul,
This is a rewrite of the series. Basically patches 1~3 address what we dissussed so far. Now it allows both methods - shutting off the nonboot CPUs and jumping to relocated_kexec_smp_wait on nonboot CPUs.
Caches are flushed before signaling reboot. CPUs are marked offline to prevent getting IPIs. Note that this is done prior to disabling local IRQ.
Patch #4 is unchnaged. Patch #5 is the previous #6 -- I'm still putting it in here with reasons mentioned in our discussion and in the patch description.
Thanks,
Dengcheng Zhu (5):
MIPS: kexec: Mark CPU offline before disabling local IRQ
MIPS: kexec: Make a framework for both jumping and halting on nonboot
CPUs
MIPS: kexec: CPS systems to halt nonboot CPUs
MIPS: kexec: Relax memory restriction
MIPS: kexec: Use prepare method from Generic for UHI platforms
arch/mips/Kconfig | 4 + arch/mips/cavium-octeon/smp.c | 7 ++ arch/mips/generic/Makefile | 1 - arch/mips/generic/kexec.c | 44 --------- arch/mips/include/asm/kexec.h | 11 ++- arch/mips/include/asm/smp-ops.h | 3 + arch/mips/include/asm/smp.h | 16 ++++ arch/mips/kernel/crash.c | 7 +- arch/mips/kernel/machine_kexec.c | 131 ++++++++++++++++++++++++-- arch/mips/kernel/smp-bmips.c | 7 ++ arch/mips/kernel/smp-cps.c | 80 +++++++++++----- arch/mips/loongson64/loongson-3/smp.c | 4 + 12 files changed, 232 insertions(+), 83 deletions(-) delete mode 100644 arch/mips/generic/kexec.c
Signature · 1 line
2.17.1
PATCH v5 1/5 MIPS: kexec: Mark CPU offline before disabling local IRQ
After changing CPU online status, it will not be sent any IPIs such as in __flush_cache_all() on software coherency systems. Do this before disabling local IRQ.
--- arch/mips/kernel/crash.c | 3 +++ arch/mips/kernel/machine_kexec.c | 3 +++ 2 files changed, 6 insertions(+)
arch/mips/kernel/crash.c +3 -0
@@ -36,6 +36,9 @@ static void crash_shutdown_secondary(void *passed_regs)if (!cpu_online (cpu))return ; +/* We won't be sent IPIs any more. */ +set_cpu_online (cpu, false); +local_irq_disable ();if (!cpumask_test_cpu (cpu, &cpus_in_crash))crash_save_cpu (regs, cpu);
arch/mips/kernel/machine_kexec.c +3 -0
@@ -118,6 +118,9 @@ machine_kexec(struct kimage *image) *ptr = (unsigned long )phys_to_virt (*ptr); } +/* Mark offline BEFORE disabling local irq. */ +set_cpu_online (smp_processor_id (), false); +/* * we do not want to be bothered. */
Signature · 1 line
2.17.1
PATCH v5 2/5 MIPS: kexec: Make a framework for both jumping and halting on nonboot CPUs
In reply to Dengcheng ZhuThe existing implementation lets machine_kexec() CPU jump to reboot code buffer, whereas other CPUs to relocated_kexec_smp_wait. The natural way to bring up an SMP new kernel would be to let CPU0 do it while others being halted. For those failing to do so, fall back to the jumping method.
--- arch/mips/cavium-octeon/smp.c | 7 +++ arch/mips/include/asm/kexec.h | 5 +- arch/mips/include/asm/smp-ops.h | 3 + arch/mips/include/asm/smp.h | 16 +++++ arch/mips/kernel/crash.c | 4 +- arch/mips/kernel/machine_kexec.c | 88 ++++++++++++++++++++++++--- arch/mips/kernel/smp-bmips.c | 7 +++ arch/mips/loongson64/loongson-3/smp.c | 4 ++ 8 files changed, 124 insertions(+), 10 deletions(-)
arch/mips/cavium-octeon/smp.c +7 -0
@@ -15,6 +15,7 @@#include <linux/sched/task_stack.h> #include <linux/init.h> #include <linux/export.h> +#include <linux/kexec.h> #include <asm/mmu_context.h> #include <asm/time.h>
@@ -424,6 +425,9 @@ const struct plat_smp_ops octeon_smp_ops = { .cpu_disable = octeon_cpu_disable, .cpu_die = octeon_cpu_die,#endif +#ifdef CONFIG_KEXEC + .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, +#endif };static irqreturn_t octeon_78xx_reched_interrupt (int irq,void *dev_id)
@@ -501,6 +505,9 @@ static const struct plat_smp_ops octeon_78xx_smp_ops = { .cpu_disable = octeon_cpu_disable, .cpu_die = octeon_cpu_die,#endif +#ifdef CONFIG_KEXEC + .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, +#endif };void __init octeon_setup_smp (void )
arch/mips/include/asm/kexec.h +3 -2
@@ -39,11 +39,12 @@ extern unsigned long kexec_args[4];extern int (*_machine_kexec_prepare)(struct kimage *);extern void (*_machine_kexec_shutdown)(void );extern void (*_machine_crash_shutdown)(struct pt_regs *regs); -extern void default_machine_crash_shutdown (struct pt_regs *regs); +void default_machine_crash_shutdown (struct pt_regs *regs); +void kexec_nonboot_cpu_jump (void ); +void kexec_reboot (void );#ifdef CONFIG_SMP extern const unsigned char kexec_smp_wait[];extern unsigned long secondary_kexec_args[4 ]; -extern void (*relocated_kexec_smp_wait) (void *);extern atomic_t kexec_ready_to_reboot;extern void (*_crash_smp_send_stop)(void );#endif
arch/mips/include/asm/smp-ops.h +3 -0
@@ -33,6 +33,9 @@ struct plat_smp_ops {int (*cpu_disable)(void );void (*cpu_die)(unsigned int cpu);#endif +#ifdef CONFIG_KEXEC +void (*kexec_nonboot_cpu)(void ); +#endif };extern void register_smp_ops (const struct plat_smp_ops *ops);
arch/mips/include/asm/smp.h +16 -0
@@ -91,6 +91,22 @@ static inline void __cpu_die(unsigned int cpu)extern void play_dead (void );#endif +#ifdef CONFIG_KEXEC +static inline void kexec_nonboot_cpu (void ) +{ +extern const struct plat_smp_ops *mp_ops;/* private */ + +return mp_ops->kexec_nonboot_cpu (); +} + +static inline void *kexec_nonboot_cpu_func (void ) +{ +extern const struct plat_smp_ops *mp_ops;/* private */ + +return mp_ops->kexec_nonboot_cpu; +} +#endif +/* * This function will set up the necessary IPIs for Linux to communicate * with the CPUs in mask.
arch/mips/kernel/crash.c +3 -1
@@ -46,7 +46,9 @@ static void crash_shutdown_secondary(void *passed_regs)while (!atomic_read (&kexec_ready_to_reboot))cpu_relax (); -relocated_kexec_smp_wait (NULL ); + +kexec_reboot (); +/* NOTREACHED */ }
arch/mips/kernel/machine_kexec.c +81 -7
140 lines not on this page · raw message
arch/mips/kernel/smp-bmips.c +7 -0
@@ -25,6 +25,7 @@#include <linux/linkage.h> #include <linux/bug.h> #include <linux/kernel.h> +#include <linux/kexec.h> #include <asm/time.h> #include <asm/pgtable.h>
@@ -423,6 +424,9 @@ const struct plat_smp_ops bmips43xx_smp_ops = { .cpu_disable = bmips_cpu_disable, .cpu_die = bmips_cpu_die,#endif +#ifdef CONFIG_KEXEC + .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, +#endif };const struct plat_smp_ops bmips5000_smp_ops = {
@@ -437,6 +441,9 @@ const struct plat_smp_ops bmips5000_smp_ops = { .cpu_disable = bmips_cpu_disable, .cpu_die = bmips_cpu_die,#endif +#ifdef CONFIG_KEXEC + .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, +#endif };#endif /* CONFIG_SMP */
arch/mips/loongson64/loongson-3/smp.c +4 -0
@@ -21,6 +21,7 @@#include <linux/sched/task_stack.h> #include <linux/smp.h> #include <linux/cpufreq.h> +#include <linux/kexec.h> #include <asm/processor.h> #include <asm/time.h> #include <asm/clock.h>
@@ -749,4 +750,7 @@ const struct plat_smp_ops loongson3_smp_ops = { .cpu_disable = loongson3_cpu_disable, .cpu_die = loongson3_cpu_die,#endif +#ifdef CONFIG_KEXEC + .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, +#endif };
Signature · 1 line
2.17.1
Re: [PATCH v5 2/5] MIPS: kexec: Make a framework for both jumping and halting on nonboot CPUs
Quoted 17 lines · Dengcheng Zhu
The existing implementation lets
machine_kexec()CPU jump to reboot code buffer, whereas other CPUs torelocated_kexec_smp_wait. The natural way to bring up an SMP new kernel would be to let CPU0 do it while others being halted. For those failing to do so, fall back to the jumping method.Signed-off-by Dengcheng Zhu <[email protected]>--- arch/mips/cavium-octeon/smp.c | 7 +++ arch/mips/include/asm/kexec.h | 5 +- arch/mips/include/asm/smp-ops.h | 3 + arch/mips/include/asm/smp.h | 16 +++++ arch/mips/kernel/crash.c | 4 +- arch/mips/kernel/machine_kexec.c | 88 ++++++++++++++++++++++++--- arch/mips/kernel/smp-bmips.c | 7 +++ arch/mips/loongson64/loongson-3/smp.c | 4 ++ 8 files changed, 124 insertions(+), 10 deletions(-)
[ snip ]
Quoted 19 lines
arch/mips/include/asm/kexec.h +3
-2@@ -39,11 +39,12 @@ extern unsigned long kexec_args[4];extern int (*_machine_kexec_prepare)(struct kimage *);extern void (*_machine_kexec_shutdown)(void );extern void (*_machine_crash_shutdown)(struct pt_regs *regs); -extern void default_machine_crash_shutdown (struct pt_regs *regs); +void default_machine_crash_shutdown (struct pt_regs *regs); +void kexec_nonboot_cpu_jump (void ); +void kexec_reboot (void );#ifdef CONFIG_SMP extern const unsigned char kexec_smp_wait[];extern unsigned long secondary_kexec_args[4 ]; -extern void (*relocated_kexec_smp_wait) (void *);extern atomic_t kexec_ready_to_reboot;extern void (*_crash_smp_send_stop)(void );#endif
[ snip ]
Quoted 10 lines
arch/mips/kernel/machine_kexec.c +0
-2@@ -19,15 +19,19 @@ extern const size_t relocate_new_kernel_size;extern unsigned long kexec_start_address;extern unsigned long kexec_indirection_page; -int (*_machine_kexec_prepare)(struct kimage *) =NULL ; -void (*_machine_kexec_shutdown)(void ) =NULL ;
arch/mips/kernel/machine_kexec.c extern const size_t relocate_new_kernel_size; · line 29
Quoted 10 lines
arch/mips/kernel/machine_kexec.c +4
-2-void (*_machine_crash_shutdown)(struct pt_regs *regs) =NULL ; +static unsigned long reboot_code_buffer; +#ifdef CONFIG_SMP -void (*relocated_kexec_smp_wait) (void *); +static void (*relocated_kexec_smp_wait)(void *); +atomic_t kexec_ready_to_reboot =ATOMIC_INIT (0 );void (*_crash_smp_send_stop)(void ) =NULL ;#endif
The above changes broke kexec support on Octeon, as relocated_kexec_smp_wait() is still called from octeon_kexec_smp_down():
| gcc-8 -Wp,-MD,arch/mips/cavium-octeon/.setup.o.d -nostdinc -isystem /usr/lib/gcc/mips-linux-gnu/8/include -I/<<PKGBUILDDIR>>/arch/mips/include -I./arch/mips/include/generated -I/<<PKGBUILDDIR>>/include -I./include -I/<<PKGBUILDDIR>>/arch/mips/include/uapi -I./arch/mips/include/generated/uapi -I/<<PKGBUILDDIR>>/include/uapi -I./include/generated/uapi -include /<<PKGBUILDDIR>>/include/linux/kconfig.h -include /<<PKGBUILDDIR>>/include/linux/compiler_types.h -I/<<PKGBUILDDIR>>/arch/mips/cavium-octeon -Iarch/mips/cavium-octeon -D__KERNEL__ -DVMLINUX_LOAD_ADDRESS=0xffffffff81100000 -DDATAOFFSET=0 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -DCC_HAVE_ASM_GOTO -mmcount-ra-address -DKBUILD_MCOUNT_RA_ADDRESS -mno-check-zero-division -mabi=64 -G 0 -mno-abicalls -fno-pic -pipe -msoft-float -DGAS_HAS_SET_HARDFLOAT -Wa,-msoft-float -ffreestanding -fno-stack-chec
k -march=octeon -Wa,--trap -Wa,-mfix-cn63xxp1 -DTOOLCHAIN_SUPPORTS_VIRT -DTOOLCHAIN_SUPPORTS_XPA -DTOOLCHAIN_SUPPORTS_CRC -DTOOLCHAIN_SUPPORTS_DSP -I/<<PKGBUILDDIR>>/arch/mips/include/asm/mach-cavium-octeon -I/<<PKGBUILDDIR>>/arch/mips/include/asm/mach-generic -msym32 -DKBUILD_64BIT_SYM32 -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-var-tracking-assignments -g -pg -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fmacro-prefix-map=/<<PKGBUILDDIR>>/= -Wno-packed-not-aligned -fdebug-
prefix-map=/<<PKGBUILDDIR>>=. -DKBUILD_BASENAME='"setup"' -DKBUILD_MODNAME='"setup"' -c -o arch/mips/cavium-octeon/.tmp_setup.o /<<PKGBUILDDIR>>/arch/mips/cavium-octeon/setup.c
| /<<PKGBUILDDIR>>/arch/mips/cavium-octeon/setup.c: In function 'octeon_kexec_smp_down': | /<<PKGBUILDDIR>>/arch/mips/cavium-octeon/setup.c:99:2: error: implicit declaration of function 'relocated_kexec_smp_wait'; did you mean 'octeon_kexec_smp_down'? [-Werror=implicit-function-declaration] | relocated_kexec_smp_wait(NULL); | ^~~~~~~~~~~~~~~~~~~~~~~~ | octeon_kexec_smp_down | | cc1: some warnings being treated as errors | make[7]: *** [/<<PKGBUILDDIR>>/scripts/Makefile.build:296: arch/mips/cavium-octeon/setup.o] Error 1 | make[6]: *** [/<<PKGBUILDDIR>>/scripts/Makefile.build:521: arch/mips/cavium-octeon] Error 2
Regards,
Aurelien
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
PATCH v5 3/5 MIPS: kexec: CPS systems to halt nonboot CPUs
In reply to Dengcheng ZhuShare code between play_dead() and cps_kexec_nonboot_cpu(). Register the latter to mp_ops for kexec.
--- arch/mips/kernel/smp-cps.c | 80 ++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 25 deletions(-)
arch/mips/kernel/smp-cps.c +55 -25
@@ -398,6 +398,55 @@ static void cps_smp_finish(void)local_irq_enable (); } +#if defined(CONFIG_HOTPLUG_CPU ) || defined(CONFIG_KEXEC ) + +enum cpu_death { +CPU_DEATH_HALT , +CPU_DEATH_POWER , +}; + +static void cps_shutdown_this_cpu (enum cpu_death death) +{ +unsigned int cpu, core, vpe_id; + + cpu =smp_processor_id (); + core =cpu_core (&cpu_data[cpu]); + +if (death ==CPU_DEATH_HALT ) { + vpe_id =cpu_vpe_id (&cpu_data[cpu]); + +pr_debug ("Halting core %d VP%d\n" , core, vpe_id); +if (cpu_has_mipsmt) { +/* Halt this TC */ +write_c0_tchalt (TCHALT_H ); +instruction_hazard (); + }else if (cpu_has_vp) { +write_cpc_cl_vp_stop (1 << vpe_id); + +/* Ensure that the VP_STOP register is written */ +wmb (); + } + }else { +pr_debug ("Gating power to core %d\n" , core); +/* Power down the core */ +cps_pm_enter_state (CPS_PM_POWER_GATED ); + } +} + +#ifdef CONFIG_KEXEC + +static void cps_kexec_nonboot_cpu (void ) +{ +if (cpu_has_mipsmt || cpu_has_vp) +cps_shutdown_this_cpu (CPU_DEATH_HALT ); +else +cps_shutdown_this_cpu (CPU_DEATH_POWER ); +} + +#endif /* CONFIG_KEXEC */ + +#endif /* CONFIG_HOTPLUG_CPU || CONFIG_KEXEC */ +#ifdef CONFIG_HOTPLUG_CPU static int cps_cpu_disable (void )
@@ -421,19 +470,15 @@ static int cps_cpu_disable(void) }static unsigned cpu_death_sibling; -static enum { -CPU_DEATH_HALT , -CPU_DEATH_POWER , -} cpu_death; +static enum cpu_death cpu_death;void play_dead (void ) { -unsigned int cpu, core, vpe_id; +unsigned int cpu;local_irq_disable ();idle_task_exit (); cpu =smp_processor_id (); - core =cpu_core (&cpu_data[cpu]); cpu_death =CPU_DEATH_POWER ;pr_debug ("CPU%d going offline\n" , cpu);
@@ -456,25 +501,7 @@ void play_dead(void)/* This CPU has chosen its way out */ (void )cpu_report_death (); -if (cpu_death ==CPU_DEATH_HALT ) { - vpe_id =cpu_vpe_id (&cpu_data[cpu]); - -pr_debug ("Halting core %d VP%d\n" , core, vpe_id); -if (cpu_has_mipsmt) { -/* Halt this TC */ -write_c0_tchalt (TCHALT_H ); -instruction_hazard (); - }else if (cpu_has_vp) { -write_cpc_cl_vp_stop (1 << vpe_id); - -/* Ensure that the VP_STOP register is written */ -wmb (); - } - }else { -pr_debug ("Gating power to core %d\n" , core); -/* Power down the core */ -cps_pm_enter_state (CPS_PM_POWER_GATED ); - } +cps_shutdown_this_cpu (cpu_death);/* This should never be reached */ panic ("Failed to offline CPU %u" , cpu);
@@ -593,6 +620,9 @@ static const struct plat_smp_ops cps_smp_ops = { .cpu_disable = cps_cpu_disable, .cpu_die = cps_cpu_die,#endif +#ifdef CONFIG_KEXEC + .kexec_nonboot_cpu = cps_kexec_nonboot_cpu, +#endif };bool mips_cps_smp_in_use (void )
Signature · 1 line
2.17.1
PATCH v5 4/5 MIPS: kexec: Relax memory restriction
In reply to Dengcheng ZhuWe can rely on the system kernel and the dump capture kernel themselves in memory usage.
Being restrictive with 512MB limit may cause kexec tool failure on some platforms.
--- arch/mips/include/asm/kexec.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/mips/include/asm/kexec.h +3 -3
@@ -12,11 +12,11 @@#include <asm/stacktrace.h> /* Maximum physical address we can use pages from */ -#define KEXEC_SOURCE_MEMORY_LIMIT (0x20000000) +#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)/* Maximum address we can reach in physical address mode */ -#define KEXEC_DESTINATION_MEMORY_LIMIT (0x20000000) +#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)/* Maximum address we can use for the control code buffer */ -#define KEXEC_CONTROL_MEMORY_LIMIT (0x20000000) +#define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)/* Reserve 3*4096 bytes for board-specific info */ #define KEXEC_CONTROL_PAGE_SIZE (4096 + 3*4096)
Signature · 1 line
2.17.1
PATCH v5 5/5 MIPS: kexec: Use prepare method from Generic for UHI platforms
In reply to Dengcheng ZhuOut-of-tree platforms may not be based on Generic as shown in customer communication. Share the prepare method with all using UHI boot protocol, and put into machine_kexec.c.
The benefit is that, when having kexec_args related problems, developers will naturally look into machine_kexec.c, where "CONFIG_UHI_BOOT" will be found, prompting them to add "select UHI_BOOT" to the platform Kconfig. It would otherwise require a lot debugging or online searching to be aware that the solution is in Generic code.
--- arch/mips/Kconfig | 4 +++ arch/mips/generic/Makefile | 1 - arch/mips/generic/kexec.c | 44 -------------------------------- arch/mips/kernel/machine_kexec.c | 42 +++++++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 46 deletions(-) delete mode 100644 arch/mips/generic/kexec.c
arch/mips/Kconfig +4 -0
@@ -132,6 +132,7 @@ config MIPS_GENERIC select USB_UHCI_BIG_ENDIAN_DESC if CPU_BIG_ENDIAN select USB_UHCI_BIG_ENDIAN_MMIO if CPU_BIG_ENDIAN select USE_OF + select UHI_BOOT help Select this to build a kernel which aims to support multiple boards, generally using a flattened device tree passed from the bootloader
@@ -2898,6 +2899,9 @@ config USE_OF select OF_EARLY_FLATTREE select IRQ_DOMAIN +config UHI_BOOT + bool + config BUILTIN_DTB bool
arch/mips/generic/Makefile +0 -1
@@ -15,5 +15,4 @@ obj-y += proc.o obj-$(CONFIG_YAMON_DT_SHIM) += yamon-dt.o obj-$(CONFIG_LEGACY_BOARD_SEAD3) += board-sead3.o obj-$(CONFIG_LEGACY_BOARD_OCELOT) += board-ocelot.o -obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_VIRT_BOARD_RANCHU) += board-ranchu.o
arch/mips/generic/kexec.c deleted +0 -44
44 lines not on this page · raw message
arch/mips/kernel/machine_kexec.c +41 -1
60 lines not on this page · raw message
Signature · 1 line
2.17.1
Hi Dengcheng,
Quoted 10 lines · Dengcheng Zhu
This is a rewrite of the series. Basically patches 1~3 address what we dissussed so far. Now it allows both methods - shutting off the nonboot CPUs and jumping to
relocated_kexec_smp_waiton nonboot CPUs.Caches are flushed before signaling reboot. CPUs are marked offline to prevent getting IPIs. Note that this is done prior to disabling local IRQ.
Patch #4 is unchnaged. Patch #5 is the previous #6 -- I'm still putting it in here with reasons mentioned in our discussion and in the patch description.
Thanks for putting in the time & effort to address my concerns :)
I've applied the series to mips-next for 4.20, with a minor tweak to patch 2 fixing CONFIG_SMP=n builds.
Paul