Skip to content

Commit 88a6f89

Browse files
Eric DeVolderakpm00
authored andcommitted
crash: memory and CPU hotplug sysfs attributes
Introduce the crash_hotplug attribute for memory and CPUs for use by userspace. These attributes directly facilitate the udev rule for managing userspace re-loading of the crash kernel upon hot un/plug changes. For memory, expose the crash_hotplug attribute to the /sys/devices/system/memory directory. For example: # udevadm info --attribute-walk /sys/devices/system/memory/memory81 looking at device '/devices/system/memory/memory81': KERNEL=="memory81" SUBSYSTEM=="memory" DRIVER=="" ATTR{online}=="1" ATTR{phys_device}=="0" ATTR{phys_index}=="00000051" ATTR{removable}=="1" ATTR{state}=="online" ATTR{valid_zones}=="Movable" looking at parent device '/devices/system/memory': KERNELS=="memory" SUBSYSTEMS=="" DRIVERS=="" ATTRS{auto_online_blocks}=="offline" ATTRS{block_size_bytes}=="8000000" ATTRS{crash_hotplug}=="1" For CPUs, expose the crash_hotplug attribute to the /sys/devices/system/cpu directory. For example: # udevadm info --attribute-walk /sys/devices/system/cpu/cpu0 looking at device '/devices/system/cpu/cpu0': KERNEL=="cpu0" SUBSYSTEM=="cpu" DRIVER=="processor" ATTR{crash_notes}=="277c38600" ATTR{crash_notes_size}=="368" ATTR{online}=="1" looking at parent device '/devices/system/cpu': KERNELS=="cpu" SUBSYSTEMS=="" DRIVERS=="" ATTRS{crash_hotplug}=="1" ATTRS{isolated}=="" ATTRS{kernel_max}=="8191" ATTRS{nohz_full}==" (null)" ATTRS{offline}=="4-7" ATTRS{online}=="0-3" ATTRS{possible}=="0-7" ATTRS{present}=="0-3" With these sysfs attributes in place, it is possible to efficiently instruct the udev rule to skip crash kernel reloading for kernels configured with crash hotplug support. For example, the following is the proposed udev rule change for RHEL system 98-kexec.rules (as the first lines of the rule file): # The kernel updates the crash elfcorehdr for CPU and memory changes SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" When examined in the context of 98-kexec.rules, the above rules test if crash_hotplug is set, and if so, the userspace initiated unload-then-reload of the crash kernel is skipped. CPU and memory checks are separated in accordance with CONFIG_HOTPLUG_CPU and CONFIG_MEMORY_HOTPLUG kernel config options. If an architecture supports, for example, memory hotplug but not CPU hotplug, then the /sys/devices/system/memory/crash_hotplug attribute file is present, but the /sys/devices/system/cpu/crash_hotplug attribute file will NOT be present. Thus the udev rule skips userspace processing of memory hot un/plug events, but the udev rule will evaluate false for CPU events, thus allowing userspace to process CPU hot un/plug events (ie the unload-then-reload of the kdump capture kernel). Link: https://lkml.kernel.org/r/20230814214446.6659-5-eric.devolder@oracle.com Signed-off-by: Eric DeVolder <eric.devolder@oracle.com> Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Hari Bathini <hbathini@linux.ibm.com> Acked-by: Baoquan He <bhe@redhat.com> Cc: Akhil Raj <lf32.dev@gmail.com> Cc: Bjorn Helgaas <bhelgaas@google.com> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dave Young <dyoung@redhat.com> Cc: David Hildenbrand <david@redhat.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Mimi Zohar <zohar@linux.ibm.com> Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Sean Christopherson <seanjc@google.com> Cc: Takashi Iwai <tiwai@suse.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Weißschuh <linux@weissschuh.net> Cc: Valentin Schneider <vschneid@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f7cc804 commit 88a6f89

File tree

7 files changed

+76
-0
lines changed

7 files changed

+76
-0
lines changed

Documentation/ABI/testing/sysfs-devices-memory

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ Description:
110110
link is created for memory section 9 on node0.
111111

112112
/sys/devices/system/node/node0/memory9 -> ../../memory/memory9
113+
114+
What: /sys/devices/system/memory/crash_hotplug
115+
Date: Aug 2023
116+
Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
117+
Description:
118+
(RO) indicates whether or not the kernel directly supports
119+
modifying the crash elfcorehdr for memory hot un/plug and/or
120+
on/offline changes.

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,11 @@ Description:
686686
(RO) the list of CPUs that are isolated and don't
687687
participate in load balancing. These CPUs are set by
688688
boot parameter "isolcpus=".
689+
690+
What: /sys/devices/system/cpu/crash_hotplug
691+
Date: Aug 2023
692+
Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
693+
Description:
694+
(RO) indicates whether or not the kernel directly supports
695+
modifying the crash elfcorehdr for CPU hot un/plug and/or
696+
on/offline changes.

Documentation/admin-guide/mm/memory-hotplug.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ The following files are currently defined:
291291
Availability depends on the CONFIG_ARCH_MEMORY_PROBE
292292
kernel configuration option.
293293
``uevent`` read-write: generic udev file for device subsystems.
294+
``crash_hotplug`` read-only: when changes to the system memory map
295+
occur due to hot un/plug of memory, this file contains
296+
'1' if the kernel updates the kdump capture kernel memory
297+
map itself (via elfcorehdr), or '0' if userspace must update
298+
the kdump capture kernel memory map.
299+
300+
Availability depends on the CONFIG_MEMORY_HOTPLUG kernel
301+
configuration option.
294302
====================== =========================================================
295303

296304
.. note::

Documentation/core-api/cpu_hotplug.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,24 @@ will receive all events. A script like::
741741

742742
can process the event further.
743743

744+
When changes to the CPUs in the system occur, the sysfs file
745+
/sys/devices/system/cpu/crash_hotplug contains '1' if the kernel
746+
updates the kdump capture kernel list of CPUs itself (via elfcorehdr),
747+
or '0' if userspace must update the kdump capture kernel list of CPUs.
748+
749+
The availability depends on the CONFIG_HOTPLUG_CPU kernel configuration
750+
option.
751+
752+
To skip userspace processing of CPU hot un/plug events for kdump
753+
(i.e. the unload-then-reload to obtain a current list of CPUs), this sysfs
754+
file can be used in a udev rule as follows:
755+
756+
SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"
757+
758+
For a CPU hot un/plug event, if the architecture supports kernel updates
759+
of the elfcorehdr (which contains the list of CPUs), then the rule skips
760+
the unload-then-reload of the kdump capture kernel.
761+
744762
Kernel Inline Documentations Reference
745763
======================================
746764

drivers/base/cpu.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ static ssize_t print_cpus_nohz_full(struct device *dev,
282282
static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL);
283283
#endif
284284

285+
#ifdef CONFIG_CRASH_HOTPLUG
286+
static ssize_t crash_hotplug_show(struct device *dev,
287+
struct device_attribute *attr,
288+
char *buf)
289+
{
290+
return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
291+
}
292+
static DEVICE_ATTR_ADMIN_RO(crash_hotplug);
293+
#endif
294+
285295
static void cpu_device_release(struct device *dev)
286296
{
287297
/*
@@ -469,6 +479,9 @@ static struct attribute *cpu_root_attrs[] = {
469479
#ifdef CONFIG_NO_HZ_FULL
470480
&dev_attr_nohz_full.attr,
471481
#endif
482+
#ifdef CONFIG_CRASH_HOTPLUG
483+
&dev_attr_crash_hotplug.attr,
484+
#endif
472485
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
473486
&dev_attr_modalias.attr,
474487
#endif

drivers/base/memory.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,16 @@ static ssize_t auto_online_blocks_store(struct device *dev,
490490

491491
static DEVICE_ATTR_RW(auto_online_blocks);
492492

493+
#ifdef CONFIG_CRASH_HOTPLUG
494+
#include <linux/kexec.h>
495+
static ssize_t crash_hotplug_show(struct device *dev,
496+
struct device_attribute *attr, char *buf)
497+
{
498+
return sysfs_emit(buf, "%d\n", crash_hotplug_memory_support());
499+
}
500+
static DEVICE_ATTR_RO(crash_hotplug);
501+
#endif
502+
493503
/*
494504
* Some architectures will have custom drivers to do this, and
495505
* will not need to do it from userspace. The fake hot-add code
@@ -889,6 +899,9 @@ static struct attribute *memory_root_attrs[] = {
889899

890900
&dev_attr_block_size_bytes.attr,
891901
&dev_attr_auto_online_blocks.attr,
902+
#ifdef CONFIG_CRASH_HOTPLUG
903+
&dev_attr_crash_hotplug.attr,
904+
#endif
892905
NULL
893906
};
894907

include/linux/kexec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
486486
static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
487487
#endif
488488

489+
#ifndef crash_hotplug_cpu_support
490+
static inline int crash_hotplug_cpu_support(void) { return 0; }
491+
#endif
492+
493+
#ifndef crash_hotplug_memory_support
494+
static inline int crash_hotplug_memory_support(void) { return 0; }
495+
#endif
496+
489497
#else /* !CONFIG_KEXEC_CORE */
490498
struct pt_regs;
491499
struct task_struct;

0 commit comments

Comments
 (0)