kexec: reorganize kexec and kdump sysfs
Subsystems (4)
v6 cover kexec: reorganize kexec and kdump sysfs
All existing kexec and kdump sysfs entries are moved to a new location, /sys/kernel/kexec, to keep /sys/kernel/ clean and better organized. Symlinks are created at the old locations for backward compatibility and can be removed in the future [01/03].
While doing this cleanup, the old kexec and kdump sysfs entries are marked as deprecated in the existing ABI documentation [02/03]. This makes it clear that these older interfaces should no longer be used. New ABI documentation is added to describe the reorganized interfaces [03/03], so users and tools can rely on the updated sysfs interfaces going forward.
Changlog:
---------
v4 -> v5:
https://lore.kernel.org/all/[email protected]/
- Splitted patch series from the above patch series
v5 -> v6:
- Move /sys/kernel/kexec_crash_cma_ranges also to new /sys/kernel/kexec node
- Update commit messages
Note:
This patch series is dependent on the patches:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
Sourabh Jain (3):
kexec: move sysfs entries to /sys/kernel/kexec Documentation/ABI: mark old kexec sysfs deprecated Documentation/ABI: new kexec and kdump sysfs interface
.../ABI/obsolete/sysfs-kernel-kexec-kdump | 71 +++++++++ .../ABI/testing/sysfs-kernel-kexec-kdump | 26 ++-- kernel/kexec_core.c | 141 ++++++++++++++++++ kernel/ksysfs.c | 89 +---------- 4 files changed, 230 insertions(+), 97 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-kernel-kexec-kdump
Signature · 1 line
2.51.1
PATCH v6 1/3 kexec: move sysfs entries to /sys/kernel/kexec
Several kexec and kdump sysfs entries are currently placed directly under /sys/kernel/, which clutters the directory and makes it harder to identify unrelated entries. To improve organization and readability, these entries are now moved under a dedicated directory, /sys/kernel/kexec.
The following sysfs moved under new kexec sysfs node
+------------------------------------+------------------+ | Old sysfs name | New sysfs name | | (under /sys/kernel) | (under /sys/kernel/kexec) | +---------------------------+---------------------------+ | kexec_loaded | loaded | +---------------------------+---------------------------+ | kexec_crash_loaded | crash_loaded | +---------------------------+---------------------------+ | kexec_crash_size | crash_size | +---------------------------+---------------------------+ | crash_elfcorehdr_size | crash_elfcorehdr_size | +---------------------------+---------------------------+ | kexec_crash_cma_ranges | crash_cma_ranges | +---------------------------+---------------------------+
For backward compatibility, symlinks are created at the old locations so that existing tools and scripts continue to work. These symlinks can be removed in the future once users have switched to the new path.
While creating symlinks, entries are added in /sys/kernel/ that point to their new locations under /sys/kernel/kexec/. If an error occurs while adding a symlink, it is logged but does not stop initialization of the remaining kexec sysfs symlinks.
The /sys/kernel/<crash_elfcorehdr_size | kexec/crash_elfcorehdr_size> entry is now controlled by CONFIG_CRASH_DUMP instead of CONFIG_VMCORE_INFO, as CONFIG_CRASH_DUMP also enables CONFIG_VMCORE_INFO.
--- kernel/kexec_core.c | 141 ++++++++++++++++++++++++++++++++++++++++++++ kernel/ksysfs.c | 89 +--------------------------- 2 files changed, 142 insertions(+), 88 deletions(-)
kernel/kexec_core.c +141 -0
@@ -41,6 +41,7 @@#include <linux/objtool.h> #include <linux/kmsg_dump.h> #include <linux/dma-map-ops.h> +#include <linux/sysfs.h> #include <asm/page.h> #include <asm/sections.h>
@@ -1229,3 +1230,143 @@ int kernel_kexec(void)kexec_unlock ();return error; } + +static ssize_t loaded_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%d\n" , !!kexec_image); +} +static struct kobj_attribute loaded_attr =__ATTR_RO (loaded); + +#ifdef CONFIG_CRASH_DUMP +static ssize_t crash_loaded_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%d\n" ,kexec_crash_loaded ()); +} +static struct kobj_attribute crash_loaded_attr =__ATTR_RO (crash_loaded); + +#ifdef CONFIG_CRASH_RESERVE +static ssize_t crash_cma_ranges_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ + +ssize_t len =0 ; +int i; + +for (i =0 ; i < crashk_cma_cnt; ++i) { + len +=sysfs_emit_at (buf, len,"%08llx-%08llx\n" , + crashk_cma_ranges[i].start, + crashk_cma_ranges[i].end); + } +return len; +} +static struct kobj_attribute crash_cma_ranges_attr =__ATTR_RO (crash_cma_ranges); +#endif + +static ssize_t crash_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +ssize_t size =crash_get_memory_size (); + +if (size <0 ) +return size; + +return sysfs_emit (buf,"%zd\n" , size); +} +static ssize_t crash_size_store (struct kobject *kobj, +struct kobj_attribute *attr, +const char *buf,size_t count) +{ +unsigned long cnt; +int ret; + +if (kstrtoul (buf,0 , &cnt)) +return -EINVAL ; + + ret =crash_shrink_memory (cnt); +return ret <0 ? ret : count; +} +static struct kobj_attribute crash_size_attr =__ATTR_RW (crash_size); + +#ifdef CONFIG_CRASH_HOTPLUG +static ssize_t crash_elfcorehdr_size_show (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +unsigned int sz =crash_get_elfcorehdr_size (); + +return sysfs_emit (buf,"%u\n" , sz); +} +static struct kobj_attribute crash_elfcorehdr_size_attr =__ATTR_RO (crash_elfcorehdr_size); + +#endif /* CONFIG_CRASH_HOTPLUG */ +#endif /* CONFIG_CRASH_DUMP */ + +static struct attribute *kexec_attrs[] = { + &loaded_attr.attr, +#ifdef CONFIG_CRASH_DUMP + &crash_loaded_attr.attr, + &crash_size_attr.attr, +#ifdef CONFIG_CRASH_RESERVE + &crash_cma_ranges_attr.attr, +#endif +#ifdef CONFIG_CRASH_HOTPLUG + &crash_elfcorehdr_size_attr.attr, +#endif +#endif +NULL +}; + +struct kexec_link_entry { +const char *target; +const char *name; +}; + +static struct kexec_link_entry kexec_links[] = { + {"loaded" ,"kexec_loaded" }, +#ifdef CONFIG_CRASH_DUMP + {"crash_loaded" ,"kexec_crash_loaded" }, + {"crash_size" ,"kexec_crash_size" }, +#ifdef CONFIG_CRASH_RESERVE + {"crash_cma_ranges" ,"kexec_crash_cma_ranges" }, +#endif +#ifdef CONFIG_CRASH_HOTPLUG + {"crash_elfcorehdr_size" ,"crash_elfcorehdr_size" }, +#endif +#endif +}; + +static struct kobject *kexec_kobj; +ATTRIBUTE_GROUPS (kexec); + +static int __init init_kexec_sysctl (void ) +{ +int error; +int i; + + kexec_kobj =kobject_create_and_add ("kexec" , kernel_kobj); +if (!kexec_kobj) { +pr_err ("failed to create kexec kobject\n" ); +return -ENOMEM ; + } + + error =sysfs_create_groups (kexec_kobj, kexec_groups); +if (error) + goto kset_exit; + +for (i =0 ; i <ARRAY_SIZE (kexec_links); i++) { + error =compat_only_sysfs_link_entry_to_kobj (kernel_kobj, kexec_kobj, + kexec_links[i].target, + kexec_links[i].name); +if (error) +pr_err ("Unable to create %s symlink (%d)" , kexec_links[i].name, error); + } + +return 0 ; + +kset_exit: +kobject_put (kexec_kobj); +return error; +} + +subsys_initcall (init_kexec_sysctl);
kernel/ksysfs.c +1 -88
115 lines not on this page · raw message
Signature · 1 line
2.51.1
PATCH v6 2/3 Documentation/ABI: mark old kexec sysfs deprecated
In reply to Sourabh JainThe previous commit ("kexec: move sysfs entries to /sys/kernel/kexec") moved all existing kexec sysfs entries to a new location. The ABI document is updated to include a note about the deprecation of the old kexec sysfs entries.
The following kexec sysfs entries are deprecated:
- /sys/kernel/kexec_loaded
- /sys/kernel/kexec_crash_loaded
- /sys/kernel/kexec_crash_size
- /sys/kernel/crash_elfcorehdr_size
- /sys/kernel/kexec_crash_cma_ranges
---
.../sysfs-kernel-kexec-kdump | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
rename Documentation/ABI/{testing => obsolete}/sysfs-kernel-kexec-kdump (63%)Documentation/ABI/obsolete/sysfs-kernel-kexec-kdump renamed from Documentation/ABI/testing/sysfs-kernel-kexec-kdump +18 -0
@@ -1,3 +1,21 @@ +NOTE: all the ABIs listed in this file are deprecated and will be removed after 2028. + +Here are the alternative ABIs: ++------------------------------------+-----------------------------------------+ +| Deprecated | Alternative | ++------------------------------------+-----------------------------------------+ +| /sys/kernel/kexec_loaded | /sys/kernel/kexec/loaded | ++------------------------------------+-----------------------------------------+ +| /sys/kernel/kexec_crash_loaded | /sys/kernel/kexec/crash_loaded | ++------------------------------------+-----------------------------------------+ +| /sys/kernel/kexec_crash_size | /sys/kernel/kexec/crash_size | ++------------------------------------+-----------------------------------------+ +| /sys/kernel/crash_elfcorehdr_size | /sys/kernel/kexec/crash_elfcorehdr_size | ++------------------------------------+-----------------------------------------+ +| /sys/kernel/kexec_crash_cma_ranges | /sys/kernel/kexec/crash_cma_ranges | ++------------------------------------+-----------------------------------------+ + + What: /sys/kernel/kexec_loaded Date: Jun 2006 Contact: [email protected]
Signature · 1 line
2.51.1
PATCH v6 3/3 Documentation/ABI: new kexec and kdump sysfs interface
In reply to Sourabh JainAdd an ABI document for following kexec and kdump sysfs interface:
- /sys/kernel/kexec/loaded
- /sys/kernel/kexec/crash_loaded
- /sys/kernel/kexec/crash_size
- /sys/kernel/kexec/crash_elfcorehdr_size
- /sys/kernel/kexec/crash_cma_ranges
--- .../ABI/testing/sysfs-kernel-kexec-kdump | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-kernel-kexec-kdump
Documentation/ABI/testing/sysfs-kernel-kexec-kdump new file +61 -0
@@ -0,0 +1,61 @@ +What: /sys/kernel/kexec/* +Date: Nov 2025 +Contact: [email protected] +Description: + The /sys/kernel/kexec/* directory contains sysfs files + that provide information about the configuration status + of kexec and kdump. + +What: /sys/kernel/kexec/loaded +Date: Nov 2025 +Contact: [email protected] +Description: read only + Indicates whether a new kernel image has been loaded + into memory using the kexec system call. It shows 1 if + a kexec image is present and ready to boot, or 0 if none + is loaded. +User: kexec tools, kdump service + +What: /sys/kernel/kexec/crash_loaded +Date: Nov 2025 +Contact: [email protected] +Description: read only + Indicates whether a crash (kdump) kernel is currently + loaded into memory. It shows 1 if a crash kernel has been + successfully loaded for panic handling, or 0 if no crash + kernel is present. +User: Kexec tools, Kdump service + +What: /sys/kernel/kexec/crash_size +Date: Nov 2025 +Contact: [email protected] +Description: read/write + Shows the amount of memory reserved for loading the crash + (kdump) kernel. It reports the size, in bytes, of the + crash kernel area defined by the crashkernel= parameter. + This interface also allows reducing the crashkernel + reservation by writing a smaller value, and the reclaimed + space is added back to the system RAM. +User: Kdump service + +What: /sys/kernel/kexec/crash_elfcorehdr_size +Date: Nov 2025 +Contact: [email protected] +Description: read only + Indicates the preferred size of the memory buffer for the + ELF core header used by the crash (kdump) kernel. It defines + how much space is needed to hold metadata about the crashed + system, including CPU and memory information. This information + is used by the user space utility kexec to support updating the + in-kernel kdump image during hotplug operations. +User: Kexec tools + +What: /sys/kernel/kexec/crash_cma_ranges +Date: Nov 2025 +Contact: [email protected] +Description: read only + Provides information about the memory ranges reserved from + the Contiguous Memory Allocator (CMA) area that are allocated + to the crash (kdump) kernel. It lists the start and end physical + addresses of CMA regions assigned for crashkernel use. +User: kdump service
Signature · 1 line
2.51.1
Quoted 19 lines · Sourabh Jain
All existing kexec and kdump sysfs entries are moved to a new location,
/sys/kernel/kexec, to keep/sys/kernel/clean and better organized. Symlinks are created at the old locations for backward compatibility and can be removed in the future [01/03].While doing this cleanup, the old kexec and kdump sysfs entries are marked as deprecated in the existing ABI documentation [02/03]. This makes it clear that these older interfaces should no longer be used. New ABI documentation is added to describe the reorganized interfaces [03/03], so users and tools can rely on the updated sysfs interfaces going forward.
Changlog:
---------v4 -> v5:
https://lore.kernel.org/all/[email protected]/
- Splitted patch series from the above patch series
Quoted 8 lines
v5 -> v6:
- Move/sys/kernel/kexec_crash_cma_rangesalso to new/sys/kernel/kexecnode
- Update commit messagesNote:
This patch series is dependent on the patches:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
To the series,
Quoted 32 lines
Cc Aditya Gupta <[email protected]>Cc Andrew Morton <[email protected]>Cc Baoquan he <[email protected]>Cc Dave Young <[email protected]>Cc Hari Bathini <[email protected]>Cc Jiri Bohac <[email protected]>Cc Madhavan Srinivasan <[email protected]>Cc Mahesh J Salgaonkar <[email protected]>Cc Pingfan Liu <[email protected]>Cc Ritesh Harjani (IBM) <[email protected]>Cc Shivang Upadhyay <[email protected]>Cc Sourabh Jain <[email protected]>Cc Vivek Goyal <[email protected]>Sourabh Jain (3):
kexec: move sysfs entries to/sys/kernel/kexecDocumentation/ABI: mark old kexec sysfs deprecatedDocumentation/ABI: new kexec and kdump sysfs interface.../ABI/obsolete/sysfs-kernel-kexec-kdump | 71 +++++++++ .../ABI/testing/sysfs-kernel-kexec-kdump | 26 ++-- kernel/kexec_core.c | 141 ++++++++++++++++++ kernel/ksysfs.c | 89 +---------- 4 files changed, 230 insertions(+), 97 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-kernel-kexec-kdumpSignature · 1 line
2.51.1