[PATCH kexec-tools 3/4] Add arch_do_unload hook for arch-specific cleanup
Shivang Upadhyay
shivangu at linux.ibm.com
Wed Oct 22 06:46:08 PDT 2025
Provide a new `arch_do_unload` hook that allows architectures to perform
cleanup actions during kexec unload. On ppc64, this hook resets the boot
CPU.
Signed-off-by: Shivang Upadhyay <shivangu at linux.ibm.com>
---
kexec/arch/arm/kexec-arm.c | 4 ++++
kexec/arch/arm64/kexec-arm64.c | 4 ++++
kexec/arch/cris/kexec-cris.c | 4 ++++
kexec/arch/hppa/kexec-hppa.c | 4 ++++
kexec/arch/i386/kexec-x86.c | 4 ++++
kexec/arch/ia64/kexec-ia64.c | 4 ++++
kexec/arch/loongarch/kexec-loongarch.c | 4 ++++
kexec/arch/m68k/kexec-m68k.c | 4 ++++
kexec/arch/mips/kexec-mips.c | 4 ++++
kexec/arch/ppc/kexec-ppc.c | 4 ++++
kexec/arch/ppc64/kexec-ppc64.c | 8 ++++++++
kexec/arch/riscv/kexec-riscv.c | 4 ++++
kexec/arch/s390/kexec-s390.c | 4 ++++
kexec/arch/sh/kexec-sh.c | 4 ++++
kexec/arch/x86_64/kexec-x86_64.c | 5 +++++
kexec/kexec.c | 1 +
kexec/kexec.h | 1 +
17 files changed, 67 insertions(+)
diff --git a/kexec/arch/arm/kexec-arm.c b/kexec/arch/arm/kexec-arm.c
index 4216327..af5b511 100644
--- a/kexec/arch/arm/kexec-arm.c
+++ b/kexec/arch/arm/kexec-arm.c
@@ -153,3 +153,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c
index 9091f40..58256cf 100644
--- a/kexec/arch/arm64/kexec-arm64.c
+++ b/kexec/arch/arm64/kexec-arm64.c
@@ -1369,3 +1369,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/cris/kexec-cris.c b/kexec/arch/cris/kexec-cris.c
index 6d048d3..44557ad 100644
--- a/kexec/arch/cris/kexec-cris.c
+++ b/kexec/arch/cris/kexec-cris.c
@@ -113,3 +113,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/hppa/kexec-hppa.c b/kexec/arch/hppa/kexec-hppa.c
index b2c74ab..ef0eab5 100644
--- a/kexec/arch/hppa/kexec-hppa.c
+++ b/kexec/arch/hppa/kexec-hppa.c
@@ -151,3 +151,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/i386/kexec-x86.c b/kexec/arch/i386/kexec-x86.c
index eac01e5..f10b545 100644
--- a/kexec/arch/i386/kexec-x86.c
+++ b/kexec/arch/i386/kexec-x86.c
@@ -216,3 +216,7 @@ int arch_do_exclude_segment(struct kexec_info *info, struct kexec_segment *segme
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/ia64/kexec-ia64.c b/kexec/arch/ia64/kexec-ia64.c
index 548a3af..54c8588 100644
--- a/kexec/arch/ia64/kexec-ia64.c
+++ b/kexec/arch/ia64/kexec-ia64.c
@@ -249,3 +249,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/loongarch/kexec-loongarch.c b/kexec/arch/loongarch/kexec-loongarch.c
index ea0c316..e8713c8 100644
--- a/kexec/arch/loongarch/kexec-loongarch.c
+++ b/kexec/arch/loongarch/kexec-loongarch.c
@@ -386,3 +386,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/m68k/kexec-m68k.c b/kexec/arch/m68k/kexec-m68k.c
index 4824a02..cbbaaac 100644
--- a/kexec/arch/m68k/kexec-m68k.c
+++ b/kexec/arch/m68k/kexec-m68k.c
@@ -113,3 +113,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/mips/kexec-mips.c b/kexec/arch/mips/kexec-mips.c
index fb5a5d4..6fb481c 100644
--- a/kexec/arch/mips/kexec-mips.c
+++ b/kexec/arch/mips/kexec-mips.c
@@ -193,3 +193,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/ppc/kexec-ppc.c b/kexec/arch/ppc/kexec-ppc.c
index d3dad0f..7892385 100644
--- a/kexec/arch/ppc/kexec-ppc.c
+++ b/kexec/arch/ppc/kexec-ppc.c
@@ -970,3 +970,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c
index 6653246..48afc85 100644
--- a/kexec/arch/ppc64/kexec-ppc64.c
+++ b/kexec/arch/ppc64/kexec-ppc64.c
@@ -979,3 +979,11 @@ int arch_do_exclude_segment(struct kexec_info *info, struct kexec_segment *segme
return 0;
}
+
+void arch_do_unload(void)
+{
+ /*
+ * setting the reboot cpu to 0
+ */
+ system("echo 0 > /sys/kernel/reboot/cpu");
+}
diff --git a/kexec/arch/riscv/kexec-riscv.c b/kexec/arch/riscv/kexec-riscv.c
index f34b468..a5a12a0 100644
--- a/kexec/arch/riscv/kexec-riscv.c
+++ b/kexec/arch/riscv/kexec-riscv.c
@@ -524,3 +524,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/s390/kexec-s390.c b/kexec/arch/s390/kexec-s390.c
index ad3eb93..86c9fb8 100644
--- a/kexec/arch/s390/kexec-s390.c
+++ b/kexec/arch/s390/kexec-s390.c
@@ -273,3 +273,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/sh/kexec-sh.c b/kexec/arch/sh/kexec-sh.c
index 7b9ac1c..5231402 100644
--- a/kexec/arch/sh/kexec-sh.c
+++ b/kexec/arch/sh/kexec-sh.c
@@ -262,3 +262,7 @@ int arch_do_exclude_segment(struct kexec_info *UNUSED(info), struct kexec_segmen
{
return 0;
}
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/arch/x86_64/kexec-x86_64.c b/kexec/arch/x86_64/kexec-x86_64.c
index f7f59f6..6a0e872 100644
--- a/kexec/arch/x86_64/kexec-x86_64.c
+++ b/kexec/arch/x86_64/kexec-x86_64.c
@@ -197,3 +197,8 @@ int arch_do_exclude_segment(struct kexec_info *info, struct kexec_segment *segme
return 0;
}
+
+
+void arch_do_unload(void)
+{
+}
diff --git a/kexec/kexec.c b/kexec/kexec.c
index 6bf12d7..25b5391 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -1752,6 +1752,7 @@ int main(int argc, char *argv[])
}
if (!do_kexec_file_syscall)
result = k_unload(kexec_flags);
+ arch_do_unload();
}
if (do_load && (result == 0)) {
if (do_kexec_file_syscall) {
diff --git a/kexec/kexec.h b/kexec/kexec.h
index a2e19c4..d0bccb5 100644
--- a/kexec/kexec.h
+++ b/kexec/kexec.h
@@ -310,6 +310,7 @@ extern int do_hotplug;
void arch_usage(void);
/* Return non-zero if segment needs to be excluded from SHA calculation, else 0. */
int arch_do_exclude_segment(struct kexec_info *info, struct kexec_segment *segment);
+void arch_do_unload(void);
int arch_process_options(int argc, char **argv);
int arch_compat_trampoline(struct kexec_info *info);
void arch_update_purgatory(struct kexec_info *info);
--
2.51.0
More information about the kexec
mailing list