Skip to content

Commit cf4340b

Browse files
sourabhjainsakpm00
authored andcommitted
kexec: move sysfs entries to /sys/kernel/kexec
Patch series "kexec: reorganize kexec and kdump sysfs", v6. 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. This patch (of 3): 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. Link: https://lkml.kernel.org/r/20251118114507.1769455-1-sourabhjain@linux.ibm.com Link: https://lkml.kernel.org/r/20251118114507.1769455-2-sourabhjain@linux.ibm.com Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Baoquan He <bhe@redhat.com> Cc: Aditya Gupta <adityag@linux.ibm.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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 1104746 commit cf4340b

2 files changed

Lines changed: 142 additions & 88 deletions

File tree

kernel/kexec_core.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/objtool.h>
4343
#include <linux/kmsg_dump.h>
4444
#include <linux/dma-map-ops.h>
45+
#include <linux/sysfs.h>
4546

4647
#include <asm/page.h>
4748
#include <asm/sections.h>
@@ -1225,3 +1226,143 @@ int kernel_kexec(void)
12251226
kexec_unlock();
12261227
return error;
12271228
}
1229+
1230+
static ssize_t loaded_show(struct kobject *kobj,
1231+
struct kobj_attribute *attr, char *buf)
1232+
{
1233+
return sysfs_emit(buf, "%d\n", !!kexec_image);
1234+
}
1235+
static struct kobj_attribute loaded_attr = __ATTR_RO(loaded);
1236+
1237+
#ifdef CONFIG_CRASH_DUMP
1238+
static ssize_t crash_loaded_show(struct kobject *kobj,
1239+
struct kobj_attribute *attr, char *buf)
1240+
{
1241+
return sysfs_emit(buf, "%d\n", kexec_crash_loaded());
1242+
}
1243+
static struct kobj_attribute crash_loaded_attr = __ATTR_RO(crash_loaded);
1244+
1245+
#ifdef CONFIG_CRASH_RESERVE
1246+
static ssize_t crash_cma_ranges_show(struct kobject *kobj,
1247+
struct kobj_attribute *attr, char *buf)
1248+
{
1249+
1250+
ssize_t len = 0;
1251+
int i;
1252+
1253+
for (i = 0; i < crashk_cma_cnt; ++i) {
1254+
len += sysfs_emit_at(buf, len, "%08llx-%08llx\n",
1255+
crashk_cma_ranges[i].start,
1256+
crashk_cma_ranges[i].end);
1257+
}
1258+
return len;
1259+
}
1260+
static struct kobj_attribute crash_cma_ranges_attr = __ATTR_RO(crash_cma_ranges);
1261+
#endif
1262+
1263+
static ssize_t crash_size_show(struct kobject *kobj,
1264+
struct kobj_attribute *attr, char *buf)
1265+
{
1266+
ssize_t size = crash_get_memory_size();
1267+
1268+
if (size < 0)
1269+
return size;
1270+
1271+
return sysfs_emit(buf, "%zd\n", size);
1272+
}
1273+
static ssize_t crash_size_store(struct kobject *kobj,
1274+
struct kobj_attribute *attr,
1275+
const char *buf, size_t count)
1276+
{
1277+
unsigned long cnt;
1278+
int ret;
1279+
1280+
if (kstrtoul(buf, 0, &cnt))
1281+
return -EINVAL;
1282+
1283+
ret = crash_shrink_memory(cnt);
1284+
return ret < 0 ? ret : count;
1285+
}
1286+
static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size);
1287+
1288+
#ifdef CONFIG_CRASH_HOTPLUG
1289+
static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
1290+
struct kobj_attribute *attr, char *buf)
1291+
{
1292+
unsigned int sz = crash_get_elfcorehdr_size();
1293+
1294+
return sysfs_emit(buf, "%u\n", sz);
1295+
}
1296+
static struct kobj_attribute crash_elfcorehdr_size_attr = __ATTR_RO(crash_elfcorehdr_size);
1297+
1298+
#endif /* CONFIG_CRASH_HOTPLUG */
1299+
#endif /* CONFIG_CRASH_DUMP */
1300+
1301+
static struct attribute *kexec_attrs[] = {
1302+
&loaded_attr.attr,
1303+
#ifdef CONFIG_CRASH_DUMP
1304+
&crash_loaded_attr.attr,
1305+
&crash_size_attr.attr,
1306+
#ifdef CONFIG_CRASH_RESERVE
1307+
&crash_cma_ranges_attr.attr,
1308+
#endif
1309+
#ifdef CONFIG_CRASH_HOTPLUG
1310+
&crash_elfcorehdr_size_attr.attr,
1311+
#endif
1312+
#endif
1313+
NULL
1314+
};
1315+
1316+
struct kexec_link_entry {
1317+
const char *target;
1318+
const char *name;
1319+
};
1320+
1321+
static struct kexec_link_entry kexec_links[] = {
1322+
{ "loaded", "kexec_loaded" },
1323+
#ifdef CONFIG_CRASH_DUMP
1324+
{ "crash_loaded", "kexec_crash_loaded" },
1325+
{ "crash_size", "kexec_crash_size" },
1326+
#ifdef CONFIG_CRASH_RESERVE
1327+
{"crash_cma_ranges", "kexec_crash_cma_ranges"},
1328+
#endif
1329+
#ifdef CONFIG_CRASH_HOTPLUG
1330+
{ "crash_elfcorehdr_size", "crash_elfcorehdr_size" },
1331+
#endif
1332+
#endif
1333+
};
1334+
1335+
static struct kobject *kexec_kobj;
1336+
ATTRIBUTE_GROUPS(kexec);
1337+
1338+
static int __init init_kexec_sysctl(void)
1339+
{
1340+
int error;
1341+
int i;
1342+
1343+
kexec_kobj = kobject_create_and_add("kexec", kernel_kobj);
1344+
if (!kexec_kobj) {
1345+
pr_err("failed to create kexec kobject\n");
1346+
return -ENOMEM;
1347+
}
1348+
1349+
error = sysfs_create_groups(kexec_kobj, kexec_groups);
1350+
if (error)
1351+
goto kset_exit;
1352+
1353+
for (i = 0; i < ARRAY_SIZE(kexec_links); i++) {
1354+
error = compat_only_sysfs_link_entry_to_kobj(kernel_kobj, kexec_kobj,
1355+
kexec_links[i].target,
1356+
kexec_links[i].name);
1357+
if (error)
1358+
pr_err("Unable to create %s symlink (%d)", kexec_links[i].name, error);
1359+
}
1360+
1361+
return 0;
1362+
1363+
kset_exit:
1364+
kobject_put(kexec_kobj);
1365+
return error;
1366+
}
1367+
1368+
subsys_initcall(init_kexec_sysctl);

kernel/ksysfs.c

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <linux/sysfs.h>
1313
#include <linux/export.h>
1414
#include <linux/init.h>
15-
#include <linux/kexec.h>
15+
#include <linux/vmcore_info.h>
1616
#include <linux/profile.h>
1717
#include <linux/stat.h>
1818
#include <linux/sched.h>
@@ -119,68 +119,6 @@ static ssize_t profiling_store(struct kobject *kobj,
119119
KERNEL_ATTR_RW(profiling);
120120
#endif
121121

122-
#ifdef CONFIG_KEXEC_CORE
123-
static ssize_t kexec_loaded_show(struct kobject *kobj,
124-
struct kobj_attribute *attr, char *buf)
125-
{
126-
return sysfs_emit(buf, "%d\n", !!kexec_image);
127-
}
128-
KERNEL_ATTR_RO(kexec_loaded);
129-
130-
#ifdef CONFIG_CRASH_DUMP
131-
static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
132-
struct kobj_attribute *attr, char *buf)
133-
{
134-
return sysfs_emit(buf, "%d\n", kexec_crash_loaded());
135-
}
136-
KERNEL_ATTR_RO(kexec_crash_loaded);
137-
138-
#ifdef CONFIG_CRASH_RESERVE
139-
static ssize_t kexec_crash_cma_ranges_show(struct kobject *kobj,
140-
struct kobj_attribute *attr, char *buf)
141-
{
142-
143-
ssize_t len = 0;
144-
int i;
145-
146-
for (i = 0; i < crashk_cma_cnt; ++i) {
147-
len += sysfs_emit_at(buf, len, "%08llx-%08llx\n",
148-
crashk_cma_ranges[i].start,
149-
crashk_cma_ranges[i].end);
150-
}
151-
return len;
152-
}
153-
KERNEL_ATTR_RO(kexec_crash_cma_ranges);
154-
#endif /* CONFIG_CRASH_RESERVE */
155-
156-
static ssize_t kexec_crash_size_show(struct kobject *kobj,
157-
struct kobj_attribute *attr, char *buf)
158-
{
159-
ssize_t size = crash_get_memory_size();
160-
161-
if (size < 0)
162-
return size;
163-
164-
return sysfs_emit(buf, "%zd\n", size);
165-
}
166-
static ssize_t kexec_crash_size_store(struct kobject *kobj,
167-
struct kobj_attribute *attr,
168-
const char *buf, size_t count)
169-
{
170-
unsigned long cnt;
171-
int ret;
172-
173-
if (kstrtoul(buf, 0, &cnt))
174-
return -EINVAL;
175-
176-
ret = crash_shrink_memory(cnt);
177-
return ret < 0 ? ret : count;
178-
}
179-
KERNEL_ATTR_RW(kexec_crash_size);
180-
181-
#endif /* CONFIG_CRASH_DUMP*/
182-
#endif /* CONFIG_KEXEC_CORE */
183-
184122
#ifdef CONFIG_VMCORE_INFO
185123

186124
static ssize_t vmcoreinfo_show(struct kobject *kobj,
@@ -192,18 +130,6 @@ static ssize_t vmcoreinfo_show(struct kobject *kobj,
192130
}
193131
KERNEL_ATTR_RO(vmcoreinfo);
194132

195-
#ifdef CONFIG_CRASH_HOTPLUG
196-
static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj,
197-
struct kobj_attribute *attr, char *buf)
198-
{
199-
unsigned int sz = crash_get_elfcorehdr_size();
200-
201-
return sysfs_emit(buf, "%u\n", sz);
202-
}
203-
KERNEL_ATTR_RO(crash_elfcorehdr_size);
204-
205-
#endif
206-
207133
#endif /* CONFIG_VMCORE_INFO */
208134

209135
/* whether file capabilities are enabled */
@@ -273,21 +199,8 @@ static struct attribute * kernel_attrs[] = {
273199
#ifdef CONFIG_PROFILING
274200
&profiling_attr.attr,
275201
#endif
276-
#ifdef CONFIG_KEXEC_CORE
277-
&kexec_loaded_attr.attr,
278-
#ifdef CONFIG_CRASH_DUMP
279-
&kexec_crash_loaded_attr.attr,
280-
&kexec_crash_size_attr.attr,
281-
#ifdef CONFIG_CRASH_RESERVE
282-
&kexec_crash_cma_ranges_attr.attr,
283-
#endif
284-
#endif
285-
#endif
286202
#ifdef CONFIG_VMCORE_INFO
287203
&vmcoreinfo_attr.attr,
288-
#ifdef CONFIG_CRASH_HOTPLUG
289-
&crash_elfcorehdr_size_attr.attr,
290-
#endif
291204
#endif
292205
#ifndef CONFIG_TINY_RCU
293206
&rcu_expedited_attr.attr,

0 commit comments

Comments
 (0)