Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Sourabh Jain and committed by
Andrew Morton
cf4340bd 11047466

+142 -88
+141
kernel/kexec_core.c
··· 42 42 #include <linux/objtool.h> 43 43 #include <linux/kmsg_dump.h> 44 44 #include <linux/dma-map-ops.h> 45 + #include <linux/sysfs.h> 45 46 46 47 #include <asm/page.h> 47 48 #include <asm/sections.h> ··· 1226 1225 kexec_unlock(); 1227 1226 return error; 1228 1227 } 1228 + 1229 + static ssize_t loaded_show(struct kobject *kobj, 1230 + struct kobj_attribute *attr, char *buf) 1231 + { 1232 + return sysfs_emit(buf, "%d\n", !!kexec_image); 1233 + } 1234 + static struct kobj_attribute loaded_attr = __ATTR_RO(loaded); 1235 + 1236 + #ifdef CONFIG_CRASH_DUMP 1237 + static ssize_t crash_loaded_show(struct kobject *kobj, 1238 + struct kobj_attribute *attr, char *buf) 1239 + { 1240 + return sysfs_emit(buf, "%d\n", kexec_crash_loaded()); 1241 + } 1242 + static struct kobj_attribute crash_loaded_attr = __ATTR_RO(crash_loaded); 1243 + 1244 + #ifdef CONFIG_CRASH_RESERVE 1245 + static ssize_t crash_cma_ranges_show(struct kobject *kobj, 1246 + struct kobj_attribute *attr, char *buf) 1247 + { 1248 + 1249 + ssize_t len = 0; 1250 + int i; 1251 + 1252 + for (i = 0; i < crashk_cma_cnt; ++i) { 1253 + len += sysfs_emit_at(buf, len, "%08llx-%08llx\n", 1254 + crashk_cma_ranges[i].start, 1255 + crashk_cma_ranges[i].end); 1256 + } 1257 + return len; 1258 + } 1259 + static struct kobj_attribute crash_cma_ranges_attr = __ATTR_RO(crash_cma_ranges); 1260 + #endif 1261 + 1262 + static ssize_t crash_size_show(struct kobject *kobj, 1263 + struct kobj_attribute *attr, char *buf) 1264 + { 1265 + ssize_t size = crash_get_memory_size(); 1266 + 1267 + if (size < 0) 1268 + return size; 1269 + 1270 + return sysfs_emit(buf, "%zd\n", size); 1271 + } 1272 + static ssize_t crash_size_store(struct kobject *kobj, 1273 + struct kobj_attribute *attr, 1274 + const char *buf, size_t count) 1275 + { 1276 + unsigned long cnt; 1277 + int ret; 1278 + 1279 + if (kstrtoul(buf, 0, &cnt)) 1280 + return -EINVAL; 1281 + 1282 + ret = crash_shrink_memory(cnt); 1283 + return ret < 0 ? ret : count; 1284 + } 1285 + static struct kobj_attribute crash_size_attr = __ATTR_RW(crash_size); 1286 + 1287 + #ifdef CONFIG_CRASH_HOTPLUG 1288 + static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj, 1289 + struct kobj_attribute *attr, char *buf) 1290 + { 1291 + unsigned int sz = crash_get_elfcorehdr_size(); 1292 + 1293 + return sysfs_emit(buf, "%u\n", sz); 1294 + } 1295 + static struct kobj_attribute crash_elfcorehdr_size_attr = __ATTR_RO(crash_elfcorehdr_size); 1296 + 1297 + #endif /* CONFIG_CRASH_HOTPLUG */ 1298 + #endif /* CONFIG_CRASH_DUMP */ 1299 + 1300 + static struct attribute *kexec_attrs[] = { 1301 + &loaded_attr.attr, 1302 + #ifdef CONFIG_CRASH_DUMP 1303 + &crash_loaded_attr.attr, 1304 + &crash_size_attr.attr, 1305 + #ifdef CONFIG_CRASH_RESERVE 1306 + &crash_cma_ranges_attr.attr, 1307 + #endif 1308 + #ifdef CONFIG_CRASH_HOTPLUG 1309 + &crash_elfcorehdr_size_attr.attr, 1310 + #endif 1311 + #endif 1312 + NULL 1313 + }; 1314 + 1315 + struct kexec_link_entry { 1316 + const char *target; 1317 + const char *name; 1318 + }; 1319 + 1320 + static struct kexec_link_entry kexec_links[] = { 1321 + { "loaded", "kexec_loaded" }, 1322 + #ifdef CONFIG_CRASH_DUMP 1323 + { "crash_loaded", "kexec_crash_loaded" }, 1324 + { "crash_size", "kexec_crash_size" }, 1325 + #ifdef CONFIG_CRASH_RESERVE 1326 + {"crash_cma_ranges", "kexec_crash_cma_ranges"}, 1327 + #endif 1328 + #ifdef CONFIG_CRASH_HOTPLUG 1329 + { "crash_elfcorehdr_size", "crash_elfcorehdr_size" }, 1330 + #endif 1331 + #endif 1332 + }; 1333 + 1334 + static struct kobject *kexec_kobj; 1335 + ATTRIBUTE_GROUPS(kexec); 1336 + 1337 + static int __init init_kexec_sysctl(void) 1338 + { 1339 + int error; 1340 + int i; 1341 + 1342 + kexec_kobj = kobject_create_and_add("kexec", kernel_kobj); 1343 + if (!kexec_kobj) { 1344 + pr_err("failed to create kexec kobject\n"); 1345 + return -ENOMEM; 1346 + } 1347 + 1348 + error = sysfs_create_groups(kexec_kobj, kexec_groups); 1349 + if (error) 1350 + goto kset_exit; 1351 + 1352 + for (i = 0; i < ARRAY_SIZE(kexec_links); i++) { 1353 + error = compat_only_sysfs_link_entry_to_kobj(kernel_kobj, kexec_kobj, 1354 + kexec_links[i].target, 1355 + kexec_links[i].name); 1356 + if (error) 1357 + pr_err("Unable to create %s symlink (%d)", kexec_links[i].name, error); 1358 + } 1359 + 1360 + return 0; 1361 + 1362 + kset_exit: 1363 + kobject_put(kexec_kobj); 1364 + return error; 1365 + } 1366 + 1367 + subsys_initcall(init_kexec_sysctl);
+1 -88
kernel/ksysfs.c
··· 12 12 #include <linux/sysfs.h> 13 13 #include <linux/export.h> 14 14 #include <linux/init.h> 15 - #include <linux/kexec.h> 15 + #include <linux/vmcore_info.h> 16 16 #include <linux/profile.h> 17 17 #include <linux/stat.h> 18 18 #include <linux/sched.h> ··· 119 119 KERNEL_ATTR_RW(profiling); 120 120 #endif 121 121 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 - 184 122 #ifdef CONFIG_VMCORE_INFO 185 123 186 124 static ssize_t vmcoreinfo_show(struct kobject *kobj, ··· 129 191 (unsigned int)VMCOREINFO_NOTE_SIZE); 130 192 } 131 193 KERNEL_ATTR_RO(vmcoreinfo); 132 - 133 - #ifdef CONFIG_CRASH_HOTPLUG 134 - static ssize_t crash_elfcorehdr_size_show(struct kobject *kobj, 135 - struct kobj_attribute *attr, char *buf) 136 - { 137 - unsigned int sz = crash_get_elfcorehdr_size(); 138 - 139 - return sysfs_emit(buf, "%u\n", sz); 140 - } 141 - KERNEL_ATTR_RO(crash_elfcorehdr_size); 142 - 143 - #endif 144 194 145 195 #endif /* CONFIG_VMCORE_INFO */ 146 196 ··· 199 273 #ifdef CONFIG_PROFILING 200 274 &profiling_attr.attr, 201 275 #endif 202 - #ifdef CONFIG_KEXEC_CORE 203 - &kexec_loaded_attr.attr, 204 - #ifdef CONFIG_CRASH_DUMP 205 - &kexec_crash_loaded_attr.attr, 206 - &kexec_crash_size_attr.attr, 207 - #ifdef CONFIG_CRASH_RESERVE 208 - &kexec_crash_cma_ranges_attr.attr, 209 - #endif 210 - #endif 211 - #endif 212 276 #ifdef CONFIG_VMCORE_INFO 213 277 &vmcoreinfo_attr.attr, 214 - #ifdef CONFIG_CRASH_HOTPLUG 215 - &crash_elfcorehdr_size_attr.attr, 216 - #endif 217 278 #endif 218 279 #ifndef CONFIG_TINY_RCU 219 280 &rcu_expedited_attr.attr,