kexec.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs
@ 2025-11-10  4:31 Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 1/5] Documentation/ABI: add kexec and kdump sysfs interface Sourabh Jain
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  4:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sourabh Jain, Aditya Gupta, Andrew Morton, Baoquan he, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

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 [02/05].

While doing this cleanup, missing ABI documentation for the old sysfs
interfaces is added, and those entries are marked as deprecated
[01/05 and 03/05]. New ABI documentation is also added for the
reorganized interfaces. [04/05]

Along with this reorganization, a new sysfs file,
/sys/kernel/kexec/crash_cma_ranges, is introduced to export crashkernel
CMA reservation details to user space [05/05]. This helps tools determine the
total crashkernel reserved memory and warn users that capturing user
pages while CMA is reserved may cause incomplete or unreliable dumps.

Changlog:
---------

v2 -> v3:
 - Add the missing hunk to export crash_cma_ranges sysfs [05/05]
 - Declare kexec_kobj static [02/05]

Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: kexec@lists.infradead.org

Sourabh Jain (5):
  Documentation/ABI: add kexec and kdump sysfs interface
  kexec: move sysfs entries to /sys/kernel/kexec
  Documentation/ABI: mark old kexec sysfs deprecated
  kexec: document new kexec and kdump sysfs ABIs
  crash: export crashkernel CMA reservation to userspace

 .../ABI/obsolete/sysfs-kernel-kexec-kdump     |  59 ++++++++
 .../ABI/testing/sysfs-kernel-kexec-kdump      |  61 ++++++++
 kernel/kexec_core.c                           | 135 ++++++++++++++++++
 kernel/ksysfs.c                               |  68 +--------
 4 files changed, 256 insertions(+), 67 deletions(-)
 create mode 100644 Documentation/ABI/obsolete/sysfs-kernel-kexec-kdump
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-kexec-kdump

-- 
2.51.1



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

* [PATCH v3 1/5] Documentation/ABI: add kexec and kdump sysfs interface
  2025-11-10  4:31 [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs Sourabh Jain
@ 2025-11-10  4:31 ` Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 2/5] kexec: move sysfs entries to /sys/kernel/kexec Sourabh Jain
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  4:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sourabh Jain, Aditya Gupta, Andrew Morton, Baoquan he, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

Add 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/crash_elfcorehdr_size

Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: kexec@lists.infradead.org
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
 .../ABI/testing/sysfs-kernel-kexec-kdump      | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-kexec-kdump

diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
new file mode 100644
index 000000000000..96b24565b68e
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
@@ -0,0 +1,43 @@
+What:		/sys/kernel/kexec_loaded
+Date:		Jun 2006
+Contact:	kexec@lists.infradead.org
+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:		Jun 2006
+Contact:	kexec@lists.infradead.org
+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:		Dec 2009
+Contact:	kexec@lists.infradead.org
+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/crash_elfcorehdr_size
+Date:		Aug 2023
+Contact:	kexec@lists.infradead.org
+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
-- 
2.51.1



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

* [PATCH v3 2/5] kexec: move sysfs entries to /sys/kernel/kexec
  2025-11-10  4:31 [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 1/5] Documentation/ABI: add kexec and kdump sysfs interface Sourabh Jain
@ 2025-11-10  4:31 ` Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 3/5] Documentation/ABI: mark old kexec sysfs deprecated Sourabh Jain
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  4:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sourabh Jain, Aditya Gupta, Andrew Morton, Baoquan he, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, 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.

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.

Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: kexec@lists.infradead.org
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
Changelog:

v2 -> v3:
 - Declare kexec_kobj static

---
 kernel/kexec_core.c | 118 ++++++++++++++++++++++++++++++++++++++++++++
 kernel/ksysfs.c     |  68 +------------------------
 2 files changed, 119 insertions(+), 67 deletions(-)

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index fa00b239c5d9..7476a46de5d6 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -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,120 @@ 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);
+
+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_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_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);
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index eefb67d9883c..a9e6354d9e25 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -12,7 +12,7 @@
 #include <linux/sysfs.h>
 #include <linux/export.h>
 #include <linux/init.h>
-#include <linux/kexec.h>
+#include <linux/vmcore_info.h>
 #include <linux/profile.h>
 #include <linux/stat.h>
 #include <linux/sched.h>
@@ -119,50 +119,6 @@ static ssize_t profiling_store(struct kobject *kobj,
 KERNEL_ATTR_RW(profiling);
 #endif
 
-#ifdef CONFIG_KEXEC_CORE
-static ssize_t kexec_loaded_show(struct kobject *kobj,
-				 struct kobj_attribute *attr, char *buf)
-{
-	return sysfs_emit(buf, "%d\n", !!kexec_image);
-}
-KERNEL_ATTR_RO(kexec_loaded);
-
-#ifdef CONFIG_CRASH_DUMP
-static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
-				       struct kobj_attribute *attr, char *buf)
-{
-	return sysfs_emit(buf, "%d\n", kexec_crash_loaded());
-}
-KERNEL_ATTR_RO(kexec_crash_loaded);
-
-static ssize_t kexec_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 kexec_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;
-}
-KERNEL_ATTR_RW(kexec_crash_size);
-
-#endif /* CONFIG_CRASH_DUMP*/
-#endif /* CONFIG_KEXEC_CORE */
-
 #ifdef CONFIG_VMCORE_INFO
 
 static ssize_t vmcoreinfo_show(struct kobject *kobj,
@@ -174,18 +130,6 @@ static ssize_t vmcoreinfo_show(struct kobject *kobj,
 }
 KERNEL_ATTR_RO(vmcoreinfo);
 
-#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);
-}
-KERNEL_ATTR_RO(crash_elfcorehdr_size);
-
-#endif
-
 #endif /* CONFIG_VMCORE_INFO */
 
 /* whether file capabilities are enabled */
@@ -255,18 +199,8 @@ static struct attribute * kernel_attrs[] = {
 #ifdef CONFIG_PROFILING
 	&profiling_attr.attr,
 #endif
-#ifdef CONFIG_KEXEC_CORE
-	&kexec_loaded_attr.attr,
-#ifdef CONFIG_CRASH_DUMP
-	&kexec_crash_loaded_attr.attr,
-	&kexec_crash_size_attr.attr,
-#endif
-#endif
 #ifdef CONFIG_VMCORE_INFO
 	&vmcoreinfo_attr.attr,
-#ifdef CONFIG_CRASH_HOTPLUG
-	&crash_elfcorehdr_size_attr.attr,
-#endif
 #endif
 #ifndef CONFIG_TINY_RCU
 	&rcu_expedited_attr.attr,
-- 
2.51.1



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

* [PATCH v3 3/5] Documentation/ABI: mark old kexec sysfs deprecated
  2025-11-10  4:31 [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 1/5] Documentation/ABI: add kexec and kdump sysfs interface Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 2/5] kexec: move sysfs entries to /sys/kernel/kexec Sourabh Jain
@ 2025-11-10  4:31 ` Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 4/5] kexec: document new kexec and kdump sysfs ABIs Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace Sourabh Jain
  4 siblings, 0 replies; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  4:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sourabh Jain, Aditya Gupta, Andrew Morton, Baoquan he, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

The 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

Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: kexec@lists.infradead.org
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
 .../sysfs-kernel-kexec-kdump                     | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 rename Documentation/ABI/{testing => obsolete}/sysfs-kernel-kexec-kdump (61%)

diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/obsolete/sysfs-kernel-kexec-kdump
similarity index 61%
rename from Documentation/ABI/testing/sysfs-kernel-kexec-kdump
rename to Documentation/ABI/obsolete/sysfs-kernel-kexec-kdump
index 96b24565b68e..96b4d41721cc 100644
--- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
+++ b/Documentation/ABI/obsolete/sysfs-kernel-kexec-kdump
@@ -1,3 +1,19 @@
+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 |
++------------------------------------+-----------------------------------------+
+
+
 What:		/sys/kernel/kexec_loaded
 Date:		Jun 2006
 Contact:	kexec@lists.infradead.org
-- 
2.51.1



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

* [PATCH v3 4/5] kexec: document new kexec and kdump sysfs ABIs
  2025-11-10  4:31 [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs Sourabh Jain
                   ` (2 preceding siblings ...)
  2025-11-10  4:31 ` [PATCH v3 3/5] Documentation/ABI: mark old kexec sysfs deprecated Sourabh Jain
@ 2025-11-10  4:31 ` Sourabh Jain
  2025-11-10  4:31 ` [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace Sourabh Jain
  4 siblings, 0 replies; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  4:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sourabh Jain, Aditya Gupta, Andrew Morton, Baoquan he, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

Add 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

Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: kexec@lists.infradead.org
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
 .../ABI/testing/sysfs-kernel-kexec-kdump      | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-kexec-kdump

diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
new file mode 100644
index 000000000000..00c00f380fea
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
@@ -0,0 +1,51 @@
+What:		/sys/kernel/kexec/*
+Date:		Nov 2025
+Contact:	kexec@lists.infradead.org
+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:	kexec@lists.infradead.org
+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:	kexec@lists.infradead.org
+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:	kexec@lists.infradead.org
+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:	kexec@lists.infradead.org
+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
-- 
2.51.1



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

* [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace
  2025-11-10  4:31 [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs Sourabh Jain
                   ` (3 preceding siblings ...)
  2025-11-10  4:31 ` [PATCH v3 4/5] kexec: document new kexec and kdump sysfs ABIs Sourabh Jain
@ 2025-11-10  4:31 ` Sourabh Jain
  2025-11-10  7:08   ` Baoquan he
  4 siblings, 1 reply; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  4:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: Sourabh Jain, Aditya Gupta, Andrew Morton, Baoquan he, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

Add a sysfs entry /sys/kernel/kexec/crash_cma_ranges to expose all
CMA crashkernel ranges.

This allows userspace tools configuring kdump to determine how much
memory is reserved for crashkernel. If CMA is used, tools can warn
users when attempting to capture user pages with CMA reservation.

The new sysfs hold the CMA ranges in below format:

cat /sys/kernel/kexec/crash_cma_ranges
100000000-10c7fffff

Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan he <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org
Cc: kexec@lists.infradead.org
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
Changelog:
 - Add the missing hunk to export crash_cma_ranges sysfs

---
 .../ABI/testing/sysfs-kernel-kexec-kdump        | 10 ++++++++++
 kernel/kexec_core.c                             | 17 +++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
index 00c00f380fea..f59051b5d96d 100644
--- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
+++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
@@ -49,3 +49,13 @@ Description:	read only
 		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:	kexec@lists.infradead.org
+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
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 7476a46de5d6..da6ff72b4669 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -1271,6 +1271,22 @@ static ssize_t crash_size_store(struct kobject *kobj,
 }
 static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size);
 
+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);
+
 #ifdef CONFIG_CRASH_HOTPLUG
 static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
 			       struct kobj_attribute *attr, char *buf)
@@ -1289,6 +1305,7 @@ static struct attribute *kexec_attrs[] = {
 #ifdef CONFIG_CRASH_DUMP
 	&crash_loaded_attr.attr,
 	&crash_size_attr.attr,
+	&crash_cma_ranges_attr.attr,
 #ifdef CONFIG_CRASH_HOTPLUG
 	&crash_elfcorehdr_size_attr.attr,
 #endif
-- 
2.51.1



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

* Re: [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace
  2025-11-10  4:31 ` [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace Sourabh Jain
@ 2025-11-10  7:08   ` Baoquan he
  2025-11-10  8:39     ` Sourabh Jain
  0 siblings, 1 reply; 10+ messages in thread
From: Baoquan he @ 2025-11-10  7:08 UTC (permalink / raw)
  To: Sourabh Jain
  Cc: linux-kernel, Aditya Gupta, Andrew Morton, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

On 11/10/25 at 10:01am, Sourabh Jain wrote:
> Add a sysfs entry /sys/kernel/kexec/crash_cma_ranges to expose all
> CMA crashkernel ranges.

I am not against this way. While wondering if it's more appropriate to
export them into iomem_resource just like crashk_res and crashk_low_res
doing.

> 
> This allows userspace tools configuring kdump to determine how much
> memory is reserved for crashkernel. If CMA is used, tools can warn
> users when attempting to capture user pages with CMA reservation.
> 
> The new sysfs hold the CMA ranges in below format:
> 
> cat /sys/kernel/kexec/crash_cma_ranges
> 100000000-10c7fffff
> 
> Cc: Aditya Gupta <adityag@linux.ibm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan he <bhe@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Hari Bathini <hbathini@linux.ibm.com>
> Cc: Jiri Bohac <jbohac@suse.cz>
> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
> Cc: Pingfan Liu <piliu@redhat.com>
> Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: kexec@lists.infradead.org
> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> ---
> Changelog:
>  - Add the missing hunk to export crash_cma_ranges sysfs
> 
> ---
>  .../ABI/testing/sysfs-kernel-kexec-kdump        | 10 ++++++++++
>  kernel/kexec_core.c                             | 17 +++++++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
> index 00c00f380fea..f59051b5d96d 100644
> --- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
> +++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
> @@ -49,3 +49,13 @@ Description:	read only
>  		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:	kexec@lists.infradead.org
> +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
> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> index 7476a46de5d6..da6ff72b4669 100644
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -1271,6 +1271,22 @@ static ssize_t crash_size_store(struct kobject *kobj,
>  }
>  static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size);
>  
> +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);
> +
>  #ifdef CONFIG_CRASH_HOTPLUG
>  static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
>  			       struct kobj_attribute *attr, char *buf)
> @@ -1289,6 +1305,7 @@ static struct attribute *kexec_attrs[] = {
>  #ifdef CONFIG_CRASH_DUMP
>  	&crash_loaded_attr.attr,
>  	&crash_size_attr.attr,
> +	&crash_cma_ranges_attr.attr,
>  #ifdef CONFIG_CRASH_HOTPLUG
>  	&crash_elfcorehdr_size_attr.attr,
>  #endif
> -- 
> 2.51.1
> 



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

* Re: [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace
  2025-11-10  7:08   ` Baoquan he
@ 2025-11-10  8:39     ` Sourabh Jain
  2025-11-11  1:15       ` Baoquan he
  0 siblings, 1 reply; 10+ messages in thread
From: Sourabh Jain @ 2025-11-10  8:39 UTC (permalink / raw)
  To: Baoquan he
  Cc: linux-kernel, Aditya Gupta, Andrew Morton, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec



On 10/11/25 12:38, Baoquan he wrote:
> On 11/10/25 at 10:01am, Sourabh Jain wrote:
>> Add a sysfs entry /sys/kernel/kexec/crash_cma_ranges to expose all
>> CMA crashkernel ranges.
> I am not against this way. While wondering if it's more appropriate to
> export them into iomem_resource just like crashk_res and crashk_low_res
> doing.

Handling conflict is challenging. Hence we don't export crashk_res and
crashk_low_res to iomem on powerpc. Checkout [1]

And I think conflicts can occur regardless of the order in which System 
RAM and
Crash CMA ranges are added to iomem.

[1] 
https://lore.kernel.org/all/20251016142831.144515-1-sourabhjain@linux.ibm.com/

- Sourabh Jain

>
>> This allows userspace tools configuring kdump to determine how much
>> memory is reserved for crashkernel. If CMA is used, tools can warn
>> users when attempting to capture user pages with CMA reservation.
>>
>> The new sysfs hold the CMA ranges in below format:
>>
>> cat /sys/kernel/kexec/crash_cma_ranges
>> 100000000-10c7fffff
>>
>> Cc: Aditya Gupta <adityag@linux.ibm.com>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: Baoquan he <bhe@redhat.com>
>> Cc: Dave Young <dyoung@redhat.com>
>> Cc: Hari Bathini <hbathini@linux.ibm.com>
>> Cc: Jiri Bohac <jbohac@suse.cz>
>> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
>> Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
>> Cc: Pingfan Liu <piliu@redhat.com>
>> Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>> Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
>> Cc: Vivek Goyal <vgoyal@redhat.com>
>> Cc: linuxppc-dev@lists.ozlabs.org
>> Cc: kexec@lists.infradead.org
>> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>> ---
>> Changelog:
>>   - Add the missing hunk to export crash_cma_ranges sysfs
>>
>> ---
>>   .../ABI/testing/sysfs-kernel-kexec-kdump        | 10 ++++++++++
>>   kernel/kexec_core.c                             | 17 +++++++++++++++++
>>   2 files changed, 27 insertions(+)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
>> index 00c00f380fea..f59051b5d96d 100644
>> --- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
>> +++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
>> @@ -49,3 +49,13 @@ Description:	read only
>>   		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:	kexec@lists.infradead.org
>> +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
>> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
>> index 7476a46de5d6..da6ff72b4669 100644
>> --- a/kernel/kexec_core.c
>> +++ b/kernel/kexec_core.c
>> @@ -1271,6 +1271,22 @@ static ssize_t crash_size_store(struct kobject *kobj,
>>   }
>>   static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size);
>>   
>> +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);
>> +
>>   #ifdef CONFIG_CRASH_HOTPLUG
>>   static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
>>   			       struct kobj_attribute *attr, char *buf)
>> @@ -1289,6 +1305,7 @@ static struct attribute *kexec_attrs[] = {
>>   #ifdef CONFIG_CRASH_DUMP
>>   	&crash_loaded_attr.attr,
>>   	&crash_size_attr.attr,
>> +	&crash_cma_ranges_attr.attr,
>>   #ifdef CONFIG_CRASH_HOTPLUG
>>   	&crash_elfcorehdr_size_attr.attr,
>>   #endif
>> -- 
>> 2.51.1
>>



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

* Re: [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace
  2025-11-10  8:39     ` Sourabh Jain
@ 2025-11-11  1:15       ` Baoquan he
  2025-11-11  5:52         ` Sourabh Jain
  0 siblings, 1 reply; 10+ messages in thread
From: Baoquan he @ 2025-11-11  1:15 UTC (permalink / raw)
  To: Sourabh Jain
  Cc: linux-kernel, Aditya Gupta, Andrew Morton, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec

On 11/10/25 at 02:09pm, Sourabh Jain wrote:
> 
> 
> On 10/11/25 12:38, Baoquan he wrote:
> > On 11/10/25 at 10:01am, Sourabh Jain wrote:
> > > Add a sysfs entry /sys/kernel/kexec/crash_cma_ranges to expose all
> > > CMA crashkernel ranges.
> > I am not against this way. While wondering if it's more appropriate to
> > export them into iomem_resource just like crashk_res and crashk_low_res
> > doing.
> 
> Handling conflict is challenging. Hence we don't export crashk_res and
> crashk_low_res to iomem on powerpc. Checkout [1]
> 
> And I think conflicts can occur regardless of the order in which System RAM
> and
> Crash CMA ranges are added to iomem.
> 
> [1] https://lore.kernel.org/all/20251016142831.144515-1-sourabhjain@linux.ibm.com/

Then I would suggest you add this reason and the link into patch log
to keep a record. One day people may post patch to 'optimize' this.

> 
> > 
> > > This allows userspace tools configuring kdump to determine how much
> > > memory is reserved for crashkernel. If CMA is used, tools can warn
> > > users when attempting to capture user pages with CMA reservation.
> > > 
> > > The new sysfs hold the CMA ranges in below format:
> > > 
> > > cat /sys/kernel/kexec/crash_cma_ranges
> > > 100000000-10c7fffff
> > > 
> > > Cc: Aditya Gupta <adityag@linux.ibm.com>
> > > Cc: Andrew Morton <akpm@linux-foundation.org>
> > > Cc: Baoquan he <bhe@redhat.com>
> > > Cc: Dave Young <dyoung@redhat.com>
> > > Cc: Hari Bathini <hbathini@linux.ibm.com>
> > > Cc: Jiri Bohac <jbohac@suse.cz>
> > > Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
> > > Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
> > > Cc: Pingfan Liu <piliu@redhat.com>
> > > Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
> > > Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
> > > Cc: Vivek Goyal <vgoyal@redhat.com>
> > > Cc: linuxppc-dev@lists.ozlabs.org
> > > Cc: kexec@lists.infradead.org
> > > Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> > > ---
> > > Changelog:
> > >   - Add the missing hunk to export crash_cma_ranges sysfs
> > > 
> > > ---
> > >   .../ABI/testing/sysfs-kernel-kexec-kdump        | 10 ++++++++++
> > >   kernel/kexec_core.c                             | 17 +++++++++++++++++
> > >   2 files changed, 27 insertions(+)
> > > 
> > > diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
> > > index 00c00f380fea..f59051b5d96d 100644
> > > --- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
> > > +++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
> > > @@ -49,3 +49,13 @@ Description:	read only
> > >   		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:	kexec@lists.infradead.org
> > > +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
> > > diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
> > > index 7476a46de5d6..da6ff72b4669 100644
> > > --- a/kernel/kexec_core.c
> > > +++ b/kernel/kexec_core.c
> > > @@ -1271,6 +1271,22 @@ static ssize_t crash_size_store(struct kobject *kobj,
> > >   }
> > >   static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size);
> > > +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);
> > > +
> > >   #ifdef CONFIG_CRASH_HOTPLUG
> > >   static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
> > >   			       struct kobj_attribute *attr, char *buf)
> > > @@ -1289,6 +1305,7 @@ static struct attribute *kexec_attrs[] = {
> > >   #ifdef CONFIG_CRASH_DUMP
> > >   	&crash_loaded_attr.attr,
> > >   	&crash_size_attr.attr,
> > > +	&crash_cma_ranges_attr.attr,
> > >   #ifdef CONFIG_CRASH_HOTPLUG
> > >   	&crash_elfcorehdr_size_attr.attr,
> > >   #endif
> > > -- 
> > > 2.51.1
> > > 
> 



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

* Re: [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace
  2025-11-11  1:15       ` Baoquan he
@ 2025-11-11  5:52         ` Sourabh Jain
  0 siblings, 0 replies; 10+ messages in thread
From: Sourabh Jain @ 2025-11-11  5:52 UTC (permalink / raw)
  To: Baoquan he
  Cc: linux-kernel, Aditya Gupta, Andrew Morton, Dave Young,
	Hari Bathini, Jiri Bohac, Madhavan Srinivasan,
	Mahesh J Salgaonkar, Pingfan Liu, Ritesh Harjani (IBM),
	Shivang Upadhyay, Vivek Goyal, linuxppc-dev, kexec



On 11/11/25 06:45, Baoquan he wrote:
> On 11/10/25 at 02:09pm, Sourabh Jain wrote:
>>
>> On 10/11/25 12:38, Baoquan he wrote:
>>> On 11/10/25 at 10:01am, Sourabh Jain wrote:
>>>> Add a sysfs entry /sys/kernel/kexec/crash_cma_ranges to expose all
>>>> CMA crashkernel ranges.
>>> I am not against this way. While wondering if it's more appropriate to
>>> export them into iomem_resource just like crashk_res and crashk_low_res
>>> doing.
>> Handling conflict is challenging. Hence we don't export crashk_res and
>> crashk_low_res to iomem on powerpc. Checkout [1]
>>
>> And I think conflicts can occur regardless of the order in which System RAM
>> and
>> Crash CMA ranges are added to iomem.
>>
>> [1] https://lore.kernel.org/all/20251016142831.144515-1-sourabhjain@linux.ibm.com/
> Then I would suggest you add this reason and the link into patch log
> to keep a record. One day people may post patch to 'optimize' this.


Yeah, I will include it in v3. Thanks for the review.

- Sourabh Jain


>
>>>> This allows userspace tools configuring kdump to determine how much
>>>> memory is reserved for crashkernel. If CMA is used, tools can warn
>>>> users when attempting to capture user pages with CMA reservation.
>>>>
>>>> The new sysfs hold the CMA ranges in below format:
>>>>
>>>> cat /sys/kernel/kexec/crash_cma_ranges
>>>> 100000000-10c7fffff
>>>>
>>>> Cc: Aditya Gupta <adityag@linux.ibm.com>
>>>> Cc: Andrew Morton <akpm@linux-foundation.org>
>>>> Cc: Baoquan he <bhe@redhat.com>
>>>> Cc: Dave Young <dyoung@redhat.com>
>>>> Cc: Hari Bathini <hbathini@linux.ibm.com>
>>>> Cc: Jiri Bohac <jbohac@suse.cz>
>>>> Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
>>>> Cc: Mahesh J Salgaonkar <mahesh@linux.ibm.com>
>>>> Cc: Pingfan Liu <piliu@redhat.com>
>>>> Cc: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>>>> Cc: Shivang Upadhyay <shivangu@linux.ibm.com>
>>>> Cc: Vivek Goyal <vgoyal@redhat.com>
>>>> Cc: linuxppc-dev@lists.ozlabs.org
>>>> Cc: kexec@lists.infradead.org
>>>> Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>>>> ---
>>>> Changelog:
>>>>    - Add the missing hunk to export crash_cma_ranges sysfs
>>>>
>>>> ---
>>>>    .../ABI/testing/sysfs-kernel-kexec-kdump        | 10 ++++++++++
>>>>    kernel/kexec_core.c                             | 17 +++++++++++++++++
>>>>    2 files changed, 27 insertions(+)
>>>>
>>>> diff --git a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
>>>> index 00c00f380fea..f59051b5d96d 100644
>>>> --- a/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
>>>> +++ b/Documentation/ABI/testing/sysfs-kernel-kexec-kdump
>>>> @@ -49,3 +49,13 @@ Description:	read only
>>>>    		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:	kexec@lists.infradead.org
>>>> +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
>>>> diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
>>>> index 7476a46de5d6..da6ff72b4669 100644
>>>> --- a/kernel/kexec_core.c
>>>> +++ b/kernel/kexec_core.c
>>>> @@ -1271,6 +1271,22 @@ static ssize_t crash_size_store(struct kobject *kobj,
>>>>    }
>>>>    static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size);
>>>> +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);
>>>> +
>>>>    #ifdef CONFIG_CRASH_HOTPLUG
>>>>    static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
>>>>    			       struct kobj_attribute *attr, char *buf)
>>>> @@ -1289,6 +1305,7 @@ static struct attribute *kexec_attrs[] = {
>>>>    #ifdef CONFIG_CRASH_DUMP
>>>>    	&crash_loaded_attr.attr,
>>>>    	&crash_size_attr.attr,
>>>> +	&crash_cma_ranges_attr.attr,
>>>>    #ifdef CONFIG_CRASH_HOTPLUG
>>>>    	&crash_elfcorehdr_size_attr.attr,
>>>>    #endif
>>>> -- 
>>>> 2.51.1
>>>>



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

end of thread, other threads:[~2025-11-11  5:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10  4:31 [PATCH v3 0/5] kexec: reorganize sysfs interface and add new kexec sysfs Sourabh Jain
2025-11-10  4:31 ` [PATCH v3 1/5] Documentation/ABI: add kexec and kdump sysfs interface Sourabh Jain
2025-11-10  4:31 ` [PATCH v3 2/5] kexec: move sysfs entries to /sys/kernel/kexec Sourabh Jain
2025-11-10  4:31 ` [PATCH v3 3/5] Documentation/ABI: mark old kexec sysfs deprecated Sourabh Jain
2025-11-10  4:31 ` [PATCH v3 4/5] kexec: document new kexec and kdump sysfs ABIs Sourabh Jain
2025-11-10  4:31 ` [PATCH v3 5/5] crash: export crashkernel CMA reservation to userspace Sourabh Jain
2025-11-10  7:08   ` Baoquan he
2025-11-10  8:39     ` Sourabh Jain
2025-11-11  1:15       ` Baoquan he
2025-11-11  5:52         ` Sourabh Jain

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).