crash: Kernel handling of CPU and memory hot un/plug
Subsystems (11)
v25 cover crash: Kernel handling of CPU and memory hot un/plug
This series is dependent upon "refactor Kconfig to consolidate KEXEC and CRASH options".
https://lore.kernel.org/lkml/[email protected]/
Once the kdump service is loaded, if changes to CPUs or memory occur, either by hot un/plug or off/onlining, the crash elfcorehdr must also be updated.
The elfcorehdr describes to kdump the CPUs and memory in the system, and any inaccuracies can result in a vmcore with missing CPU context or memory regions.
The current solution utilizes udev to initiate an unload-then-reload of the kdump image (eg. kernel, initrd, boot_params, purgatory and elfcorehdr) by the userspace kexec utility. In the original post I outlined the significant performance problems related to offloading this activity to userspace.
This patchset introduces a generic crash handler that registers with the CPU and memory notifiers. Upon CPU or memory changes, from either hot un/plug or off/onlining, this generic handler is invoked and performs important housekeeping, for example obtaining the appropriate lock, and then invokes an architecture specific handler to do the appropriate elfcorehdr update.
Note the description in patch 'crash: change crash_prepare_elf64_headers() to for_each_possible_cpu()' and 'x86/crash: optimize CPU changes' that enables further optimizations related to CPU plug/unplug/online/offline performance of elfcorehdr updates.
In the case of x86_64, the arch specific handler generates a new elfcorehdr, and overwrites the old one in memory; thus no involvement with userspace needed.
To realize the benefits/test this patchset, one must make a couple of minor changes to userspace:
- Prevent udev from updating kdump crash kernel on hot un/plug changes. Add the following as the first lines to the RHEL udev rule file /usr/lib/udev/rules.d/98-kexec.rules:
# 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"
With this changeset applied, the two rules evaluate to false for CPU and memory change events and thus skip the userspace unload-then-reload of kdump.
- Change to the kexec_file_load for loading the kdump kernel:
Eg. on RHEL: in /usr/bin/kdumpctl, change to:
standard_kexec_args="-p -d -s"
which adds the -s to select kexec_file_load() syscall.
This kernel patchset also supports kexec_load() with a modified kexec userspace utility. A working changeset to the kexec userspace utility is posted to the kexec-tools mailing list here:
http://lists.infradead.org/pipermail/kexec/2023-May/027049.html
To use the kexec-tools patch, apply, build and install kexec-tools, then change the kdumpctl's standard_kexec_args to replace the -s with --hotplug. The removal of -s reverts to the kexec_load syscall and the addition of --hotplug invokes the changes put forth in the kexec-tools patch.
Regards,
eric
---
v25: 29jun2023
- Properly applied IS_ENABLED() to the function bodies of callbacks in drivers/base/cpu|memory.c.
- Re-ran compile and run-time testing of the impacted attributes for both enabled and not enabled config settings.
v24: 28jun2023
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.4.0
- Included Documentation/ABI/testing entries for the new sysfs crash_hotplug attributes, per Greg Kroah-Hartman.
- Refactored drivers/base/cpu|memory.c to use the .is_visible() method for attributes, per Greg Kroah-Hartman.
- Retained all existing Acks and RBs as the few changes as a result of Greg's requests were trivial.
v23: 12jun2023
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.4.0-rc6
- Refactored Kconfig, per Thomas. See series:
https://lore.kernel.org/lkml/[email protected]/
- Reworked commit messages to conform to style, per Thomas.
- Applied Baoquan He Acked-by to kexec_load() patch.
- Applied Hari Bathini Acked-by for the series.
- No code changes.
v22: 3may2023
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.3.0
- Improved support for kexec_load(), per Hari Bathini. See "crash: hotplug support for kexec_load()" which is the only change to this series.
- Applied Baoquan He's Acked-by for all other patches.
v21: 4apr2023
https://lkml.org/lkml/2023/4/4/1136
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.3.0-rc5
- Additional simplification of indentation in crash_handle_hotplug_event(), per Baoquan.
v20: 17mar2023
https://lkml.org/lkml/2023/3/17/1169
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.3.0-rc2
- Defaulting CRASH_HOTPLUG for x86 to Y, per Sourabh.
- Explicitly initializing image->hp_action, per Baoquan.
- Simplified kexec_trylock() in crash_handle_hotplug_event(), per Baoquan.
- Applied Sourabh's Reviewed-by to the series.
v19: 6mar2023
https://lkml.org/lkml/2023/3/6/1358
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.2.0
- Did away with offlinecpu, per Thomas Gleixner.
- Changed to CPUHP_BP_PREPARE_DYN instead of CPUHP_AP_ONLINE_DYN.
- Did away with elfcorehdr_index_valid, per Sourabh.
- Convert to for_each_possible_cpu() in crash_prepare_elf64_headers() per Sourabh.
- Small optimization for x86 cpu changes.
v18: 31jan2023
https://lkml.org/lkml/2023/1/31/1356
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.2.0-rc6
- Renamed struct kimage member hotplug_event to hp_action, and re-enumerated the KEXEC_CRASH_HP_x items, adding _NONE at 0.
- Moved to cpuhp state CPUHP_BP_PREPARE_DYN instead of CPUHP_AP_ONLINE_DYN in order to minimize window of time CPU is not reflected in elfcorehdr.
- Reworked some of the comments and commit messages to offer more of the why, than what, per Thomas Gleixner.
v17: 18jan2023
https://lkml.org/lkml/2023/1/18/1420
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.2.0-rc4
- Moved a bit of code around so that kexec_load()-only builds work, per Sourabh.
- Corrected computation of number of memory region Phdrs needed when x86 memory hotplug is not enabled, per Baoquan.
v16: 5jan2023
https://lkml.org/lkml/2023/1/5/673
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.2.0-rc2
- Corrected error identified by Baoquan.
v15: 9dec2022
https://lkml.org/lkml/2022/12/9/520
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.1.0-rc8
- Replaced arch_un/map_crash_pages() with direct use of kun/map_local_pages(), per Boris.
- Some x86 changes, per Boris.
v14: 16nov2022
https://lkml.org/lkml/2022/11/16/1645
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.1.0-rc5
- Introduced CRASH_HOTPLUG Kconfig item to better fine tune compilation of feature components, per Boris.
- Removed hp_action parameter to arch_crash_handle_hotplug_event() as it is unused.
v13: 31oct2022
https://lkml.org/lkml/2022/10/31/854
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.1.0-rc3, which means converting to use the new kexec_trylock() away from mutex_lock(kexec_mutex).
- Moved arch_un/map_crash_pages() into kexec.h and default implementation using k/unmap_local_pages().
- Changed more #ifdef's into IS_ENABLED()
- Changed CRASH_MAX_MEMORY_RANGES to 8192 from 32768, and it moved into x86 crash.c as #define rather Kconfig item, per Boris.
- Check number of Phdrs against PN_XNUM, max possible.
v12: 9sep2022
https://lkml.org/lkml/2022/9/9/1358
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.0-rc4
- Addressed some minor formatting items, per Baoquan
v11: 26aug2022
https://lkml.org/lkml/2022/8/26/963
https://lore.kernel.org/lkml/[email protected]/
- Rebased onto 6.0-rc2
- Redid the rework of __weak to use asm/kexec.h, per Baoquan
- Reworked some comments and minor items, per Baoquan
v10: 21jul2022
https://lkml.org/lkml/2022/7/21/1007
https://lore.kernel.org/lkml/[email protected]/
- Rebased to 5.19.0-rc7
- Per Sourabh, corrected build issue with arch_un/map_crash_pages() for architectures not supporting this feature.
- Per David Hildebrand, removed the WARN_ONCE() altogether.
- Per David Hansen, converted to use of kmap_local_page().
- Per Baoquan He, replaced use of __weak with the kexec technique.
v9: 13jun2022
https://lkml.org/lkml/2022/6/13/3382
https://lore.kernel.org/lkml/[email protected]/
- Rebased to 5.18.0
- Per Sourabh, moved crash_prepare_elf64_headers() into common crash_core.c to avoid compile issues with kexec_load only path.
- Per David Hildebrand, replaced mutex_trylock() with mutex_lock().
- Changed the __weak arch_crash_handle_hotplug_event() to utilize WARN_ONCE() instead of WARN(). Fix some formatting issues.
- Per Sourabh, introduced sysfs attribute crash_hotplug for memory and CPUs; for use by userspace (udev) to determine if the kernel performs crash hot un/plug support.
- Per Sourabh, moved the code detecting the elfcorehdr segment from arch/x86 into crash_core:handle_hotplug_event() so both kexec_load and kexec_file_load can benefit.
- Updated userspace kexec-tools kexec utility to reflect change to using CRASH_MAX_MEMORY_RANGES and get_nr_cpus().
- Updated the new proposed udev rules to reflect using the sysfs attributes crash_hotplug.
v8: 5may2022
https://lkml.org/lkml/2022/5/5/1133
https://lore.kernel.org/lkml/[email protected]/
- Per Borislav Petkov, eliminated CONFIG_CRASH_HOTPLUG in favor of CONFIG_HOTPLUG_CPU || CONFIG_MEMORY_HOTPLUG, ie a new define is not needed. Also use of IS_ENABLED() rather than #ifdef's. Renamed crash_hotplug_handler() to handle_hotplug_event(). And other corrections.
- Per Baoquan, minimized the parameters to the arch_crash_ handle_hotplug_event() to hp_action and cpu.
- Introduce KEXEC_CRASH_HP_INVALID_CPU definition, per Baoquan.
- Per Sourabh Jain, renamed and repurposed CRASH_HOTPLUG_ELFCOREHDR_SZ to CONFIG_CRASH_MAX_MEMORY_RANGES, mirroring kexec-tools change by David Hildebrand. Folded this patch into the x86 kexec_file_load support patch.
v7: 13apr2022
https://lkml.org/lkml/2022/4/13/850
https://lore.kernel.org/lkml/[email protected]/
- Resolved parameter usage to crash_hotplug_handler(), per Baoquan.
v6: 1apr2022
https://lkml.org/lkml/2022/4/1/1203
https://lore.kernel.org/lkml/[email protected]/
- Reword commit messages and some comment cleanup per Baoquan.
- Changed elf_index to elfcorehdr_index for clarity.
- Minor code changes per Baoquan.
v5: 3mar2022
https://lkml.org/lkml/2022/3/3/674
https://lore.kernel.org/lkml/[email protected]/
- Reworded description of CRASH_HOTPLUG_ELFCOREHDR_SZ, per David Hildenbrand.
- Refactored slightly a few patches per Baoquan recommendation.
v4: 9feb2022
https://lkml.org/lkml/2022/2/9/1406
https://lore.kernel.org/lkml/[email protected]/
- Refactored patches per Baoquan suggestsions.
- A few corrections, per Baoquan.
v3: 10jan2022
https://lkml.org/lkml/2022/1/10/1212
https://lore.kernel.org/lkml/[email protected]/
- Rebasing per Baoquan He request.
- Changed memory notifier per David Hildenbrand.
- Providing example kexec userspace change in cover letter.
RFC v2: 7dec2021
https://lkml.org/lkml/2021/12/7/1088
https://lore.kernel.org/lkml/[email protected]/
- Acting upon Baoquan He suggestion of removing elfcorehdr from the purgatory list of segments, removed purgatory code from patchset, and it is signficiantly simpler now.
RFC v1: 18nov2021
https://lkml.org/lkml/2021/11/18/845
https://lore.kernel.org/lkml/[email protected]/
- working patchset demonstrating kernel handling of hotplug updates to x86 elfcorehdr for kexec_file_load
RFC: 14dec2020
https://lkml.org/lkml/2020/12/14/532
https://lore.kernel.org/lkml/[email protected]/
- proposed concept of allowing kernel to handle hotplug update of elfcorehdr
---
Eric DeVolder (10):
drivers/base: refactor cpu.c to use .is_visible() drivers/base: refactor memory.c to use .is_visible()
crash: move a few code bits to setup support of crash hotplug
crash: add generic infrastructure for crash hotplug support
kexec: exclude elfcorehdr from the segment digest
crash: memory and CPU hotplug sysfs attributes
x86/crash: add x86 crash hotplug support
crash: hotplug support for kexec_load()
crash: change crash_prepare_elf64_headers() to for_each_possible_cpu() x86/crash: optimize CPU changes
.../ABI/testing/sysfs-devices-memory | 8 + .../ABI/testing/sysfs-devices-system-cpu | 8 + .../admin-guide/mm/memory-hotplug.rst | 8 + Documentation/core-api/cpu_hotplug.rst | 18 + arch/x86/Kconfig | 3 + arch/x86/include/asm/kexec.h | 18 + arch/x86/kernel/crash.c | 140 ++++++- drivers/base/cpu.c | 141 ++++--- drivers/base/memory.c | 242 +++++++----- include/linux/crash_core.h | 9 + include/linux/kexec.h | 63 +++- include/linux/tick.h | 2 +- include/uapi/linux/kexec.h | 1 + kernel/Kconfig.kexec | 35 ++ kernel/crash_core.c | 355 ++++++++++++++++++ kernel/kexec.c | 5 + kernel/kexec_core.c | 6 + kernel/kexec_file.c | 187 +-------- kernel/ksysfs.c | 15 + 19 files changed, 922 insertions(+), 342 deletions(-)
Signature · 1 line
2.31.1
PATCH v25 1/10 drivers/base: refactor cpu.c to use .is_visible()
Greg Kroah-Hartman requested that this file use the .is_visible() method instead of #ifdefs for the attributes in cpu.c.
static struct attribute *cpu_root_attrs[] = {
#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
&dev_attr_probe.attr,
&dev_attr_release.attr,
#endif
&cpu_attrs[0].attr.attr,
&cpu_attrs[1].attr.attr,
&cpu_attrs[2].attr.attr,
&dev_attr_kernel_max.attr,
&dev_attr_offline.attr,
&dev_attr_isolated.attr, #ifdef CONFIG_NO_HZ_FULL
&dev_attr_nohz_full.attr,
#endif
#ifdef CONFIG_GENERIC_CPU_AUTOPROBE
&dev_attr_modalias.attr,
#endif
NULL
};
To that end:
- the .is_visible() method is implemented, and IS_ENABLED(), rather than #ifdef, is used to determine the visibility of the attribute.
- the DEVICE_ATTR() attributes are moved outside of #ifdefs, so that those structs are always present for the cpu_root_attrs[].
- the function body of the callback functions are now wrapped with IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).
No functionality change intended.
--- drivers/base/cpu.c | 125 +++++++++++++++++++++++++++---------------- include/linux/tick.h | 2 +- 2 files changed, 81 insertions(+), 46 deletions(-)
drivers/base/cpu.c +80 -45
@@ -82,24 +82,27 @@ void unregister_cpu(struct cpu *cpu)per_cpu (cpu_sys_devices, logical_cpu) =NULL ;return ; } +#endif /* CONFIG_HOTPLUG_CPU */ -#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE static ssize_t cpu_probe_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) { -ssize_t cnt; -int ret; +if (IS_ENABLED (CONFIG_ARCH_CPU_PROBE_RELEASE )) { +ssize_t cnt; +int ret; - ret =lock_device_hotplug_sysfs (); -if (ret) -return ret; + ret =lock_device_hotplug_sysfs (); +if (ret) +return ret; - cnt =arch_cpu_probe (buf, count); + cnt =arch_cpu_probe (buf, count); -unlock_device_hotplug (); -return cnt; +unlock_device_hotplug (); +return cnt; + } +return 0 ; } static ssize_t cpu_release_store(struct device *dev,
@@ -107,23 +110,24 @@ static ssize_t cpu_release_store(struct device *dev,const char *buf, size_t count) { - ssize_t cnt; -int ret; + if (IS_ENABLED(CONFIG_ARCH_CPU_PROBE_RELEASE)) { + ssize_t cnt; +int ret; - ret =lock_device_hotplug_sysfs (); -if (ret) -return ret; + ret =lock_device_hotplug_sysfs (); +if (ret) +return ret; - cnt =arch_cpu_release (buf, count); + cnt =arch_cpu_release (buf, count); -unlock_device_hotplug (); -return cnt; +unlock_device_hotplug (); +return cnt; + } +return 0 ; } static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store); -#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */ -#endif /* CONFIG_HOTPLUG_CPU */ #ifdef CONFIG_KEXEC #include <linux/kexec.h>
@@ -273,14 +277,14 @@ static ssize_t print_cpus_isolated(struct device *dev, } static DEVICE_ATTR(isolated, 0444, print_cpus_isolated, NULL); -#ifdef CONFIG_NO_HZ_FULL static ssize_t print_cpus_nohz_full (struct device *dev,struct device_attribute *attr,char *buf) { -return sysfs_emit (buf,"%*pbl\n" ,cpumask_pr_args (tick_nohz_full_mask)); +if (IS_ENABLED (CONFIG_NO_HZ_FULL )) +return sysfs_emit (buf,"%*pbl\n" ,cpumask_pr_args (tick_nohz_full_mask)); +return 0 ; } static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL); -#endif static void cpu_device_release (struct device *dev) {
@@ -301,30 +305,32 @@ static void cpu_device_release(struct device *dev)*/ } -#ifdef CONFIG_GENERIC_CPU_AUTOPROBE static ssize_t print_cpu_modalias (struct device *dev,struct device_attribute *attr,char *buf) {int len =0 ; -u32 i; - - len +=sysfs_emit_at (buf, len, -"cpu:type:" CPU_FEATURE_TYPEFMT ":feature:" , -CPU_FEATURE_TYPEVAL ); - -for (i =0 ; i <MAX_CPU_FEATURES ; i++) -if (cpu_have_feature (i)) { -if (len +sizeof (",XXXX\n" ) >=PAGE_SIZE ) { -WARN (1 ,"CPU features overflow page\n" ); -break ; +if (IS_ENABLED (CONFIG_GENERIC_CPU_AUTOPROBE )) { +u32 i; + + len +=sysfs_emit_at (buf, len, +"cpu:type:" CPU_FEATURE_TYPEFMT ":feature:" , +CPU_FEATURE_TYPEVAL ); + +for (i =0 ; i <MAX_CPU_FEATURES ; i++) +if (cpu_have_feature (i)) { +if (len +sizeof (",XXXX\n" ) >=PAGE_SIZE ) { +WARN (1 ,"CPU features overflow page\n" ); +break ; + } + len +=sysfs_emit_at (buf, len,",%04X" , i); } - len +=sysfs_emit_at (buf, len,",%04X" , i); - } - len +=sysfs_emit_at (buf, len,"\n" ); + len +=sysfs_emit_at (buf, len,"\n" ); + }return len; } +#ifdef CONFIG_GENERIC_CPU_AUTOPROBE static int cpu_uevent (const struct device *dev,struct kobj_uevent_env *env) {char *buf =kzalloc (PAGE_SIZE ,GFP_KERNEL );
@@ -451,32 +457,61 @@ struct device *cpu_device_create(struct device *parent, void *drvdata, }EXPORT_SYMBOL_GPL (cpu_device_create); -#ifdef CONFIG_GENERIC_CPU_AUTOPROBE static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL); -#endif static struct attribute *cpu_root_attrs[] = { -#ifdef CONFIG_ARCH_CPU_PROBE_RELEASE &dev_attr_probe.attr, &dev_attr_release.attr, -#endif &cpu_attrs[0 ].attr.attr, &cpu_attrs[1 ].attr.attr, &cpu_attrs[2 ].attr.attr, &dev_attr_kernel_max.attr, &dev_attr_offline.attr, &dev_attr_isolated.attr, -#ifdef CONFIG_NO_HZ_FULL &dev_attr_nohz_full.attr, -#endif -#ifdef CONFIG_GENERIC_CPU_AUTOPROBE &dev_attr_modalias.attr, -#endifNULL }; +static umode_t +cpu_root_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int unused) +{ +umode_t mode = attr->mode; + +if (IS_ENABLED (CONFIG_ARCH_CPU_PROBE_RELEASE )) { +if (attr == &dev_attr_probe.attr) +return mode; +if (attr == &dev_attr_release.attr) +return mode; + } +if (attr == &cpu_attrs[0 ].attr.attr) +return mode; +if (attr == &cpu_attrs[1 ].attr.attr) +return mode; +if (attr == &cpu_attrs[2 ].attr.attr) +return mode; +if (attr == &dev_attr_kernel_max.attr) +return mode; +if (attr == &dev_attr_offline.attr) +return mode; +if (attr == &dev_attr_isolated.attr) +return mode; +if (IS_ENABLED (CONFIG_NO_HZ_FULL )) { +if (attr == &dev_attr_nohz_full.attr) +return mode; + } +if (IS_ENABLED (CONFIG_GENERIC_CPU_AUTOPROBE )) { +if (attr == &dev_attr_modalias.attr) +return mode; + } + +return 0 ; +} +static const struct attribute_group cpu_root_attr_group = { .attrs = cpu_root_attrs, + .is_visible = cpu_root_attr_is_visible, };static const struct attribute_group *cpu_root_attr_groups[] = {
include/linux/tick.h +1 -1
@@ -174,9 +174,9 @@ static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }static inline void tick_nohz_idle_stop_tick_protected (void ) { }#endif /* !CONFIG_NO_HZ_COMMON */ +extern cpumask_var_t tick_nohz_full_mask;#ifdef CONFIG_NO_HZ_FULL extern bool tick_nohz_full_running; -extern cpumask_var_t tick_nohz_full_mask;static inline bool tick_nohz_full_enabled (void ) {
Signature · 1 line
2.31.1
Greg KH
maintainerRe: [PATCH v25 01/10] drivers/base: refactor cpu.c to use .is_visible()
Quoted 3 lines · Eric DeVolder
- the function body of the callback functions are now wrapped with
IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).
Why do you need to do this last thing? Is it a code savings goal? Or something else? The file will not be present in the system if the option is not enabled, so it should be safe to not do this unless you feel it's necessary for some reason?
Not doing this would make the diff easier to read :)
thanks,
greg k-h
Re: [PATCH v25 01/10] drivers/base: refactor cpu.c to use .is_visible()
Quoted 9 lines · Greg KH
Quoted 3 lines · Eric DeVolder
- the function body of the callback functions are now wrapped with
IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).Why do you need to do this last thing? Is it a code savings goal? Or something else? The file will not be present in the system if the option is not enabled, so it should be safe to not do this unless you feel it's necessary for some reason?
To accommodate the request, all DEVICE_ATTR() must be unconditionally present in this file. The DEVICE_ATTR() requires the .show() callback. As the callback is referenced from a data structure, the callback has to be present for link. All the callbacks for these attributes are in this file.
I have two basic choices for gutting the function body if the config feature is not enabled. I can either use #ifdef or IS_ENABLED(). Thomas has made it clear I need to use IS_ENABLED(). I can certainly use #ifdef (which is what I did in v24).
Quoted 2 lines
Not doing this would make the diff easier to read :)
I agree this is messy. I'm not really sure what this request/effort achieves as these attributes are not strongly related (unlike cacheinfo) and the way the file was before results in less code.
At any rate, please indicate if you'd rather I use #ifdef. Thanks for your time!
eric
Quoted 4 lines
thanks,
greg k-h
Re: [PATCH v25 01/10] drivers/base: refactor cpu.c to use .is_visible()
Quoted 18 lines · Eric DeVolder
Quoted 9 lines · Greg KH
Quoted 3 lines · Eric DeVolder
- the function body of the callback functions are now wrapped with
IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).Why do you need to do this last thing? Is it a code savings goal? Or something else? The file will not be present in the system if the option is not enabled, so it should be safe to not do this unless you feel it's necessary for some reason?
To accommodate the request, all
DEVICE_ATTR()must be unconditionally present in this file. TheDEVICE_ATTR()requires the .show() callback. As the callback is referenced from a data structure, the callback has to be present for link. All the callbacks for these attributes are in this file.I have two basic choices for gutting the function body if the config feature is not enabled. I can either use #ifdef or
IS_ENABLED(). Thomas has made it clear I need to useIS_ENABLED(). I can certainly use #ifdef (which is what I did in v24).Quoted 1 line
Quoted 12 lines
Quoted 1 line
Not doing this would make the diff easier to read :)
I agree this is messy. I'm not really sure what this request/effort achieves as these attributes are not strongly related (unlike cacheinfo) and the way the file was before results in less code.
At any rate, please indicate if you'd rather I use #ifdef. Thanks for your time!
ericQuoted 4 lines
thanks,
greg k-h
Hi Greg,
I was wondering if you might weigh-in so that I can proceed.
I think there are three options on the table:
- use #ifdef to comment out these function bodies, which keeps the diff much more readable
- use IS_ENABLED() as Thomas has requested I do, but makes the diff more difficult to read
- remove this refactor altogether, perhaps post-poning until after this crash hotplug series merges, as this refactor is largely unrelated to crash hotplug.
Thank you for your time on this topic!
eric
Re: [PATCH v25 01/10] drivers/base: refactor cpu.c to use .is_visible()
Quoted 37 lines · Eric DeVolder
Quoted 18 lines · Eric DeVolder
Quoted 9 lines · Greg KH
Quoted 3 lines · Eric DeVolder
- the function body of the callback functions are now wrapped with
IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).Why do you need to do this last thing? Is it a code savings goal? Or something else? The file will not be present in the system if the option is not enabled, so it should be safe to not do this unless you feel it's necessary for some reason?
To accommodate the request, all
DEVICE_ATTR()must be unconditionally present in this file. TheDEVICE_ATTR()requires the .show() callback. As the callback is referenced from a data structure, the callback has to be present for link. All the callbacks for these attributes are in this file.I have two basic choices for gutting the function body if the config feature is not enabled. I can either use #ifdef or
IS_ENABLED(). Thomas has made it clear I need to useIS_ENABLED(). I can certainly use #ifdef (which is what I did in v24).Quoted 1 line
Quoted 12 lines
Quoted 1 line
Not doing this would make the diff easier to read :)
I agree this is messy. I'm not really sure what this request/effort achieves as these attributes are not strongly related (unlike cacheinfo) and the way the file was before results in less code.
At any rate, please indicate if you'd rather I use #ifdef. Thanks for your time!
ericQuoted 4 lines
thanks,
greg k-h
Hi Greg,
I was wondering if you might weigh-in so that I can proceed.
Quoted 8 lines
I think there are three options on the table:
- use #ifdef to comment out these function bodies, which keeps the diff much more readable
- useIS_ENABLED()as Thomas has requested I do, but makes the diff more difficult to read
- remove this refactor altogether, perhaps post-poning until after this crash hotplug series merges, as this refactor is largely unrelated to crash hotplug.Thank you for your time on this topic!
eric
Hi Greg,
If you have an opinion on how to proceed, please provide. Thanks,
eric
Greg KH
maintainerRe: [PATCH v25 01/10] drivers/base: refactor cpu.c to use .is_visible()
Quoted 56 lines · Eric DeVolder
Quoted 53 lines · Eric DeVolder
Quoted 27 lines · Eric DeVolder
Quoted 9 lines · Greg KH
Quoted 3 lines · Eric DeVolder
- the function body of the callback functions are now wrapped with
IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).Why do you need to do this last thing? Is it a code savings goal? Or something else? The file will not be present in the system if the option is not enabled, so it should be safe to not do this unless you feel it's necessary for some reason?
To accommodate the request, all
DEVICE_ATTR()must be unconditionally present in this file. TheDEVICE_ATTR()requires the .show() callback. As the callback is referenced from a data structure, the callback has to be present for link. All the callbacks for these attributes are in this file.I have two basic choices for gutting the function body if the config feature is not enabled. I can either use #ifdef or
IS_ENABLED(). Thomas has made it clear I need to useIS_ENABLED(). I can certainly use #ifdef (which is what I did in v24).Quoted 2 lines
Not doing this would make the diff easier to read :)
Quoted 12 lines
I agree this is messy. I'm not really sure what this request/effort achieves as these attributes are not strongly related (unlike cacheinfo) and the way the file was before results in less code.
At any rate, please indicate if you'd rather I use #ifdef. Thanks for your time!
ericQuoted 4 lines
thanks,
greg k-h
Hi Greg,
I was wondering if you might weigh-in so that I can proceed.I think there are three options on the table:
- use #ifdef to comment out these function bodies, which keeps the diff much more readable
- useIS_ENABLED()as Thomas has requested I do, but makes the diff more difficult to read
- remove this refactor altogether, perhaps post-poning until after this crash hotplug series merges, as this refactor is largely unrelated to
crash hotplug.
Quoted 5 lines
Quoted 2 lines
Thank you for your time on this topic!
ericHi Greg,
If you have an opinion on how to proceed, please provide.
Sorry, totally swamped by "stuff". I don't know, use your judgement here and send a new version, don't wait for me to weigh in on design decisions for longer than a week.
thanks,
greg k-h
PATCH v25 2/10 drivers/base: refactor memory.c to use .is_visible()
In reply to Eric DeVolderGreg Kroah-Hartman requested that this file use the .is_visible() method instead of #ifdefs for the attributes in memory.c.
static struct attribute *memory_memblk_attrs[] = {
&dev_attr_phys_index.attr, &dev_attr_state.attr, &dev_attr_phys_device.attr, &dev_attr_removable.attr,
#ifdef CONFIG_MEMORY_HOTREMOVE
&dev_attr_valid_zones.attr,
#endif
NULL
};
and
static struct attribute *memory_root_attrs[] = {
#ifdef CONFIG_ARCH_MEMORY_PROBE
&dev_attr_probe.attr,
#endif
#ifdef CONFIG_MEMORY_FAILURE
&dev_attr_soft_offline_page.attr,
&dev_attr_hard_offline_page.attr,
#endif
&dev_attr_block_size_bytes.attr,
&dev_attr_auto_online_blocks.attr,
NULL
};
To that end:
- the .is_visible() method is implemented, and IS_ENABLED(), rather than #ifdef, is used to determine the visibility of the attribute.
- the DEVICE_ATTR_xx() attributes are moved outside of #ifdefs, so that those structs are always present for the memory_memblk_attrs[] and memory_root_attrs[].
- the function body of the callback functions are now wrapped with IS_ENABLED(); as the callback function must exist now that the attribute is always compiled-in (though not necessarily visible).
No functionality change intended.
--- drivers/base/memory.c | 229 ++++++++++++++++++++++++++---------------- 1 file changed, 140 insertions(+), 89 deletions(-)
drivers/base/memory.c +140 -89
@@ -391,62 +391,66 @@ static ssize_t phys_device_show(struct device *dev, arch_get_memory_phys_device(start_pfn)); } -#ifdef CONFIG_MEMORY_HOTREMOVE static int print_allowed_zone (char *buf,int len,int nid,struct memory_group *group,unsigned long start_pfn,unsigned long nr_pages,int online_type,struct zone *default_zone) { -struct zone *zone; +if (IS_ENABLED (CONFIG_MEMORY_HOTREMOVE )) { +struct zone *zone; - zone =zone_for_pfn_range (online_type, nid, group, start_pfn, nr_pages); -if (zone == default_zone) -return 0 ; + zone =zone_for_pfn_range (online_type, nid, group, start_pfn, nr_pages); +if (zone == default_zone) +return 0 ; -return sysfs_emit_at (buf, len," %s" , zone->name); +return sysfs_emit_at (buf, len," %s" , zone->name); + } +return 0 ; }static ssize_t valid_zones_show (struct device *dev,struct device_attribute *attr,char *buf) { -struct memory_block *mem =to_memory_block (dev); -unsigned long start_pfn =section_nr_to_pfn (mem->start_section_nr); -unsigned long nr_pages =PAGES_PER_SECTION * sections_per_block; -struct memory_group *group = mem->group; -struct zone *default_zone; -int nid = mem->nid; -int len =0 ; +if (IS_ENABLED (CONFIG_MEMORY_HOTREMOVE )) { +struct memory_block *mem =to_memory_block (dev); +unsigned long start_pfn =section_nr_to_pfn (mem->start_section_nr); +unsigned long nr_pages =PAGES_PER_SECTION * sections_per_block; +struct memory_group *group = mem->group; +struct zone *default_zone; +int nid = mem->nid; +int len =0 ; -/* -* Check the existing zone. Make sure that we do that only on the -* online nodes otherwise the page_zone is not reliable -*/ -if (mem->state ==MEM_ONLINE ) {/* -* If !mem->zone, the memory block spans multiple zones and -* cannot get offlined. -*/ - default_zone = mem->zone; -if (!default_zone) -return sysfs_emit (buf,"%s\n" ,"none" ); - len +=sysfs_emit_at (buf, len,"%s" , default_zone->name); - goto out; - } +* Check the existing zone. Make sure that we do that only on the +* online nodes otherwise the page_zone is not reliable +*/ +if (mem->state ==MEM_ONLINE ) { +/* +* If !mem->zone, the memory block spans multiple zones and +* cannot get offlined. +*/ + default_zone = mem->zone; +if (!default_zone) +return sysfs_emit (buf,"%s\n" ,"none" ); + len +=sysfs_emit_at (buf, len,"%s" , default_zone->name); + goto out; + } - default_zone =zone_for_pfn_range (MMOP_ONLINE , nid, group, - start_pfn, nr_pages); + default_zone =zone_for_pfn_range (MMOP_ONLINE , nid, group, + start_pfn, nr_pages); - len +=sysfs_emit_at (buf, len,"%s" , default_zone->name); - len +=print_allowed_zone (buf, len, nid, group, start_pfn, nr_pages, -MMOP_ONLINE_KERNEL , default_zone); - len +=print_allowed_zone (buf, len, nid, group, start_pfn, nr_pages, -MMOP_ONLINE_MOVABLE , default_zone); + len +=sysfs_emit_at (buf, len,"%s" , default_zone->name); + len +=print_allowed_zone (buf, len, nid, group, start_pfn, nr_pages, +MMOP_ONLINE_KERNEL , default_zone); + len +=print_allowed_zone (buf, len, nid, group, start_pfn, nr_pages, +MMOP_ONLINE_MOVABLE , default_zone); out: - len +=sysfs_emit_at (buf, len,"\n" ); -return len; + len +=sysfs_emit_at (buf, len,"\n" ); +return len; + } +return 0 ; }static DEVICE_ATTR_RO (valid_zones); -#endif static DEVICE_ATTR_RO (phys_index);static DEVICE_ATTR_RW (state);
@@ -496,43 +500,43 @@ static DEVICE_ATTR_RW(auto_online_blocks);* as well as ppc64 will do all of their discovery in userspace * and will require this interface. */ -#ifdef CONFIG_ARCH_MEMORY_PROBE static ssize_t probe_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) { -u64 phys_addr; -int nid, ret; -unsigned long pages_per_block =PAGES_PER_SECTION * sections_per_block; +if (IS_ENABLED (CONFIG_ARCH_MEMORY_PROBE )) { +u64 phys_addr; +int nid, ret; +unsigned long pages_per_block =PAGES_PER_SECTION * sections_per_block; - ret =kstrtoull (buf,0 , &phys_addr); -if (ret) -return ret; + ret =kstrtoull (buf,0 , &phys_addr); +if (ret) +return ret; -if (phys_addr & ((pages_per_block <<PAGE_SHIFT ) -1 )) -return -EINVAL ; +if (phys_addr & ((pages_per_block <<PAGE_SHIFT ) -1 )) +return -EINVAL ; - ret =lock_device_hotplug_sysfs (); -if (ret) -return ret; + ret =lock_device_hotplug_sysfs (); +if (ret) +return ret; - nid =memory_add_physaddr_to_nid (phys_addr); - ret =__add_memory (nid, phys_addr, -MIN_MEMORY_BLOCK_SIZE * sections_per_block, -MHP_NONE ); + nid =memory_add_physaddr_to_nid (phys_addr); + ret =__add_memory (nid, phys_addr, +MIN_MEMORY_BLOCK_SIZE * sections_per_block, +MHP_NONE ); -if (ret) - goto out; +if (ret) + goto out; - ret = count; + ret = count; out: -unlock_device_hotplug (); -return ret; +unlock_device_hotplug (); +return ret; + } +return 0 ; }static DEVICE_ATTR_WO (probe); -#endif -#ifdef CONFIG_MEMORY_FAILURE /* * Support for offlining pages of memory */
@@ -542,15 +546,19 @@ static ssize_t soft_offline_page_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t count) { - int ret; -u64 pfn; -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; -if (kstrtoull (buf,0 , &pfn) <0 ) -return -EINVAL ; - pfn >>=PAGE_SHIFT ; - ret =soft_offline_page (pfn,0 ); -return ret ==0 ? count : ret; + if (IS_ENABLED(CONFIG_MEMORY_FAILURE)) { + int ret; +u64 pfn; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (kstrtoull (buf,0 , &pfn) <0 ) +return -EINVAL ; + pfn >>=PAGE_SHIFT ; + ret =soft_offline_page (pfn,0 ); +return ret ==0 ? count : ret; + } +return 0 ; }/* Forcibly offline a page, including killing processes. */
@@ -558,22 +566,25 @@ static ssize_t hard_offline_page_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t count) { - int ret; -u64 pfn; -if (!capable (CAP_SYS_ADMIN )) -return -EPERM ; -if (kstrtoull (buf,0 , &pfn) <0 ) -return -EINVAL ; - pfn >>=PAGE_SHIFT ; - ret =memory_failure (pfn,MF_SW_SIMULATED ); -if (ret == -EOPNOTSUPP ) - ret =0 ; -return ret ? ret : count; + if (IS_ENABLED(CONFIG_MEMORY_FAILURE)) { + int ret; +u64 pfn; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (kstrtoull (buf,0 , &pfn) <0 ) +return -EINVAL ; + pfn >>=PAGE_SHIFT ; + ret =memory_failure (pfn,MF_SW_SIMULATED ); +if (ret == -EOPNOTSUPP ) + ret =0 ; +return ret ? ret : count; + } +return 0 ; }static DEVICE_ATTR_WO (soft_offline_page);static DEVICE_ATTR_WO (hard_offline_page); -#endif /* See phys_device_show(). */ int __weak arch_get_memory_phys_device (unsigned long start_pfn)
@@ -611,14 +622,35 @@ static struct attribute *memory_memblk_attrs[] = { &dev_attr_state.attr, &dev_attr_phys_device.attr, &dev_attr_removable.attr, -#ifdef CONFIG_MEMORY_HOTREMOVE &dev_attr_valid_zones.attr, -#endifNULL }; +static umode_t +memory_memblk_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int unused) +{ +umode_t mode = attr->mode; + +if (attr == &dev_attr_phys_index.attr) +return mode; +if (attr == &dev_attr_state.attr) +return mode; +if (attr == &dev_attr_phys_device.attr) +return mode; +if (attr == &dev_attr_removable.attr) +return mode; +if (IS_ENABLED (CONFIG_MEMORY_HOTREMOVE )) { +if (attr == &dev_attr_valid_zones.attr) +return mode; + } + +return 0 ; +} +static const struct attribute_group memory_memblk_attr_group = { .attrs = memory_memblk_attrs, + .is_visible = memory_memblk_attr_is_visible, }; static const struct attribute_group *memory_memblk_attr_groups[] = {
@@ -878,22 +910,41 @@ void remove_memory_block_devices(unsigned long start, unsigned long size) }static struct attribute *memory_root_attrs[] = { -#ifdef CONFIG_ARCH_MEMORY_PROBE &dev_attr_probe.attr, -#endif - -#ifdef CONFIG_MEMORY_FAILURE &dev_attr_soft_offline_page.attr, &dev_attr_hard_offline_page.attr, -#endif - &dev_attr_block_size_bytes.attr, &dev_attr_auto_online_blocks.attr,NULL }; +static umode_t +memory_root_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int unused) +{ +umode_t mode = attr->mode; + +if (IS_ENABLED (CONFIG_ARCH_MEMORY_PROBE )) { +if (attr == &dev_attr_probe.attr) +return mode; + } +if (IS_ENABLED (CONFIG_MEMORY_FAILURE )) { +if (attr == &dev_attr_soft_offline_page.attr) +return mode; +if (attr == &dev_attr_hard_offline_page.attr) +return mode; + } +if (attr == &dev_attr_block_size_bytes.attr) +return mode; +if (attr == &dev_attr_auto_online_blocks.attr) +return mode; + +return 0 ; +} +static const struct attribute_group memory_root_attr_group = { .attrs = memory_root_attrs, + .is_visible = memory_root_attr_is_visible, };static const struct attribute_group *memory_root_attr_groups[] = {
Signature · 1 line
2.31.1
PATCH v25 3/10 crash: move a few code bits to setup support of crash hotplug
In reply to Eric DeVolderThe crash hotplug support leans on the work for the kexec_file_load() syscall. To also support the kexec_load() syscall, a few bits of code need to be move outside of CONFIG_KEXEC_FILE. As such, these bits are moved out of kexec_file.c and into a common location crash_core.c.
No functionality change intended.
--- include/linux/kexec.h | 30 +++---- kernel/crash_core.c | 182 ++++++++++++++++++++++++++++++++++++++++++ kernel/kexec_file.c | 181 ----------------------------------------- 3 files changed, 197 insertions(+), 196 deletions(-)
include/linux/kexec.h +15 -15
@@ -105,6 +105,21 @@ struct compat_kexec_segment { };#endif +/* Alignment required for elf header segment */ +#define ELF_CORE_HEADER_ALIGN 4096 + +struct crash_mem { +unsigned int max_nr_ranges; +unsigned int nr_ranges; +struct range ranges[]; +}; + +extern int crash_exclude_mem_range (struct crash_mem *mem, +unsigned long long mstart, +unsigned long long mend); +extern int crash_prepare_elf64_headers (struct crash_mem *mem,int need_kernel_map, +void **addr,unsigned long *sz); +#ifdef CONFIG_KEXEC_FILE struct purgatory_info {/*
@@ -230,21 +245,6 @@ static inline int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) }#endif -/* Alignment required for elf header segment */ -#define ELF_CORE_HEADER_ALIGN 4096 - -struct crash_mem { -unsigned int max_nr_ranges; -unsigned int nr_ranges; -struct range ranges[]; -}; - -extern int crash_exclude_mem_range (struct crash_mem *mem, -unsigned long long mstart, -unsigned long long mend); -extern int crash_prepare_elf64_headers (struct crash_mem *mem,int need_kernel_map, -void **addr,unsigned long *sz); -#ifndef arch_kexec_apply_relocations_add/* * arch_kexec_apply_relocations_add - apply relocations of type RELA
kernel/crash_core.c +182 -0
194 lines not on this page · raw message
kernel/kexec_file.c +0 -181
184 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v25 4/10 crash: add generic infrastructure for crash hotplug support
In reply to Eric DeVolderTo support crash hotplug, a mechanism is needed to update the crash elfcorehdr upon CPU or memory changes (eg. hot un/plug or off/ onlining). The crash elfcorehdr describes the CPUs and memory to be written into the vmcore.
To track CPU changes, callbacks are registered with the cpuhp mechanism via cpuhp_setup_state_nocalls(CPUHP_BP_PREPARE_DYN). The crash hotplug elfcorehdr update has no explicit ordering requirement (relative to other cpuhp states), so meets the criteria for utilizing CPUHP_BP_PREPARE_DYN. CPUHP_BP_PREPARE_DYN is a dynamic state and avoids the need to introduce a new state for crash hotplug. Also, CPUHP_BP_PREPARE_DYN is the last state in the PREPARE group, just prior to the STARTING group, which is very close to the CPU starting up in a plug/online situation, or stopping in a unplug/ offline situation. This minimizes the window of time during an actual plug/online or unplug/offline situation in which the elfcorehdr would be inaccurate. Note that for a CPU being unplugged or offlined, the CPU will still be present in the list of CPUs generated by crash_prepare_elf64_headers(). However, there is no need to explicitly omit the CPU, see justification in
'crash: change crash_prepare_elf64_headers() to for_each_possible_cpu()'.
To track memory changes, a notifier is registered to capture the memblock MEM_ONLINE and MEM_OFFLINE events via register_memory_notifier().
The CPU callbacks and memory notifiers invoke crash_handle_hotplug_event() which performs needed tasks and then dispatches the event to the architecture specific arch_crash_handle_hotplug_event() to update the elfcorehdr with the current state of CPUs and memory. During the process, the kexec_lock is held.
--- include/linux/crash_core.h | 9 +++ include/linux/kexec.h | 11 +++ kernel/Kconfig.kexec | 31 ++++++++ kernel/crash_core.c | 142 +++++++++++++++++++++++++++++++++++++ kernel/kexec_core.c | 6 ++ 5 files changed, 199 insertions(+)
include/linux/crash_core.h +9 -0
@@ -84,4 +84,13 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,int parse_crashkernel_low (char *cmdline,unsigned long long system_ram,unsigned long long *crash_size,unsigned long long *crash_base); +#define KEXEC_CRASH_HP_NONE 0 +#define KEXEC_CRASH_HP_ADD_CPU 1 +#define KEXEC_CRASH_HP_REMOVE_CPU 2 +#define KEXEC_CRASH_HP_ADD_MEMORY 3 +#define KEXEC_CRASH_HP_REMOVE_MEMORY 4 +#define KEXEC_CRASH_HP_INVALID_CPU -1U + +struct kimage ; +#endif /* LINUX_CRASH_CORE_H */
include/linux/kexec.h +11 -0
@@ -33,6 +33,7 @@ extern note_buf_t __percpu *crash_notes;#include <linux/compat.h> #include <linux/ioport.h> #include <linux/module.h> +#include <linux/highmem.h> #include <asm/kexec.h> /* Verify architecture specific macros are defined */
@@ -360,6 +361,12 @@ struct kimage {struct purgatory_info purgatory_info;#endif +#ifdef CONFIG_CRASH_HOTPLUG +int hp_action; +int elfcorehdr_index; +bool elfcorehdr_updated; +#endif +#ifdef CONFIG_IMA_KEXEC /* Virtual address of IMA measurement buffer for kexec syscall */ void *ima_buffer;
@@ -490,6 +497,10 @@ static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, gstatic inline void arch_kexec_pre_free_pages (void *vaddr,unsigned int pages) { }#endif +#ifndef arch_crash_handle_hotplug_event +static inline void arch_crash_handle_hotplug_event (struct kimage *image) { } +#endif +#else /* !CONFIG_KEXEC_CORE */ struct pt_regs ;struct task_struct ;
kernel/Kconfig.kexec +31 -0
@@ -107,4 +107,35 @@ config CRASH_DUMP For s390, this option also enables zfcpdump. See also <file:Documentation/s390/zfcpdump.rst> +config CRASH_HOTPLUG + bool "Update the crash elfcorehdr on system configuration changes" + default y + depends on CRASH_DUMP && (HOTPLUG_CPU || MEMORY_HOTPLUG) + depends on ARCH_SUPPORTS_CRASH_HOTPLUG + help + Enable direct update to the crash elfcorehdr (which contains + the list of CPUs and memory regions to be dumped upon a crash) + in response to hot plug/unplug or online/offline of CPUs or + memory. This is a much more advanced approach than userspace + attempting that. + + If unsure, say Y. + +config CRASH_MAX_MEMORY_RANGES + int "Specify the maximum number of memory regions for the elfcorehdr" + default 8192 + depends on CRASH_HOTPLUG + help + For the kexec_file_load() syscall path, specify the maximum number of + memory regions that the elfcorehdr buffer/segment can accommodate. + These regions are obtained via walk_system_ram_res(); eg. the + 'System RAM' entries in /proc/iomem. + This value is combined with NR_CPUS_DEFAULT and multiplied by + sizeof(Elf64_Phdr) to determine the final elfcorehdr memory buffer/ + segment size. + The value 8192, for example, covers a (sparsely populated) 1TiB system + consisting of 128MiB memblocks, while resulting in an elfcorehdr + memory buffer/segment size under 1MiB. This represents a sane choice + to accommodate both baremetal and virtual machine configurations. + endmenu
kernel/crash_core.c +142 -0
157 lines not on this page · raw message
kernel/kexec_core.c +6 -0
@@ -277,6 +277,12 @@ struct kimage *do_kimage_alloc_init(void)/* Initialize the list of unusable pages */ INIT_LIST_HEAD (&image->unusable_pages); +#ifdef CONFIG_CRASH_HOTPLUG + image->hp_action =KEXEC_CRASH_HP_NONE ; + image->elfcorehdr_index =-1 ; + image->elfcorehdr_updated = false; +#endif +return image; }
Signature · 1 line
2.31.1
PATCH v25 5/10 kexec: exclude elfcorehdr from the segment digest
In reply to Eric DeVolderWhen a crash kernel is loaded via the kexec_file_load() syscall, the kernel places the various segments (ie crash kernel, crash initrd, boot_params, elfcorehdr, purgatory, etc) in memory. For those architectures that utilize purgatory, a hash digest of the segments is calculated for integrity checking. The digest is embedded into the purgatory image prior to placing in memory.
Updates to the elfcorehdr in response to CPU and memory changes would cause the purgatory integrity checking to fail (at crash time, and no vmcore created). Therefore, the elfcorehdr segment is explicitly excluded from the purgatory digest, enabling updates to the elfcorehdr while also avoiding the need to recompute the hash digest and reload purgatory.
--- kernel/kexec_file.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/kexec_file.c +6 -0
@@ -726,6 +726,12 @@ static int kexec_calculate_store_digests(struct kimage *image)for (j = i =0 ; i < image->nr_segments; i++) {struct kexec_segment *ksegment; +#ifdef CONFIG_CRASH_HOTPLUG +/* Exclude elfcorehdr segment to allow future changes via hotplug */ +if (j == image->elfcorehdr_index) +continue ; +#endif + ksegment = &image->segment[i];/* * Skip purgatory as it will be modified once we put digest
Signature · 1 line
2.31.1
PATCH v25 6/10 crash: memory and CPU hotplug sysfs attributes
In reply to Eric DeVolderIntroduce 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).
--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++++++ .../ABI/testing/sysfs-devices-system-cpu | 8 ++++++++ .../admin-guide/mm/memory-hotplug.rst | 8 ++++++++ Documentation/core-api/cpu_hotplug.rst | 18 ++++++++++++++++++ drivers/base/cpu.c | 16 ++++++++++++++-- drivers/base/memory.c | 13 +++++++++++++ include/linux/kexec.h | 8 ++++++++ 7 files changed, 77 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-devices-memory +8 -0
@@ -110,3 +110,11 @@ Description: link is created for memory section 9 on node0. /sys/devices/system/node/node0/memory9 -> ../../memory/memory9 + +What: /sys/devices/system/cpu/crash_hotplug +Date: Jun 2023 +Contact: Linux kernel mailing list <[email protected]> +Description: + (RO) indicates whether or not the kernel directly supports + modifying the crash elfcorehdr for memory hot un/plug and/or + on/offline changes.
Documentation/ABI/testing/sysfs-devices-system-cpu +8 -0
@@ -686,3 +686,11 @@ Description: (RO) the list of CPUs that are isolated and don't participate in load balancing. These CPUs are set by boot parameter "isolcpus=". + +What: /sys/devices/system/cpu/crash_hotplug +Date: Jun 2023 +Contact: Linux kernel mailing list <[email protected]> +Description: + (RO) indicates whether or not the kernel directly supports + modifying the crash elfcorehdr for CPU hot un/plug and/or + on/offline changes.
Documentation/admin-guide/mm/memory-hotplug.rst +8 -0
@@ -291,6 +291,14 @@ The following files are currently defined: Availability depends on the CONFIG_ARCH_MEMORY_PROBE kernel configuration option. ``uevent`` read-write: generic udev file for device subsystems. +``crash_hotplug`` read-only: when changes to the system memory map + occur due to hot un/plug of memory, this file contains + '1' if the kernel updates the kdump capture kernel memory + map itself (via elfcorehdr), or '0' if userspace must update + the kdump capture kernel memory map. + + Availability depends on the CONFIG_MEMORY_HOTPLUG kernel + configuration option. ====================== ========================================================= .. note::
Documentation/core-api/cpu_hotplug.rst +18 -0
@@ -741,6 +741,24 @@ will receive all events. A script like:: can process the event further. +When changes to the CPUs in the system occur, the sysfs file +/sys/devices/system/cpu/crash_hotplug contains '1' if the kernel +updates the kdump capture kernel list of CPUs itself (via elfcorehdr), +or '0' if userspace must update the kdump capture kernel list of CPUs. + +The availability depends on the CONFIG_HOTPLUG_CPU kernel configuration +option. + +To skip userspace processing of CPU hot un/plug events for kdump +(ie the unload-then-reload to obtain a current list of CPUs), this sysfs +file can be used in a udev rule as follows: + + SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" + +For a cpu hot un/plug event, if the architecture supports kernel updates +of the elfcorehdr (which contains the list of CPUs), then the rule skips +the unload-then-reload of the kdump capture kernel. + Kernel Inline Documentations Reference ======================================
drivers/base/cpu.c +14 -2
@@ -20,6 +20,7 @@#include <linux/tick.h> #include <linux/pm_qos.h> #include <linux/sched/isolation.h> +#include <linux/kexec.h> #include "base.h"
@@ -130,8 +131,6 @@ static DEVICE_ATTR(probe, S_IWUSR, NULL, cpu_probe_store); static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store);#ifdef CONFIG_KEXEC -#include <linux/kexec.h> -static ssize_t crash_notes_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -286,6 +285,14 @@ static ssize_t print_cpus_nohz_full(struct device *dev, } static DEVICE_ATTR(nohz_full, 0444, print_cpus_nohz_full, NULL); +static ssize_t crash_hotplug_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%d\n" ,crash_hotplug_cpu_support ()); +} +static DEVICE_ATTR_ADMIN_RO (crash_hotplug); +static void cpu_device_release (struct device *dev) {/*
@@ -470,6 +477,7 @@ static struct attribute *cpu_root_attrs[] = { &dev_attr_isolated.attr, &dev_attr_nohz_full.attr, &dev_attr_modalias.attr, + &dev_attr_crash_hotplug.attr, NULL };
@@ -505,6 +513,10 @@ cpu_root_attr_is_visible(struct kobject *kobj,if (attr == &dev_attr_modalias.attr)return mode; } +if (IS_ENABLED (CONFIG_CRASH_HOTPLUG )) { +if (attr == &dev_attr_crash_hotplug.attr) +return mode; + }return 0 ; }
drivers/base/memory.c +13 -0
@@ -25,6 +25,7 @@#include <linux/atomic.h> #include <linux/uaccess.h> +#include <linux/kexec.h> #define MEMORY_CLASS_NAME "memory"
@@ -494,6 +495,13 @@ static ssize_t auto_online_blocks_store(struct device *dev,static DEVICE_ATTR_RW (auto_online_blocks); +static ssize_t crash_hotplug_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%d\n" ,crash_hotplug_memory_support ()); +} +static DEVICE_ATTR_RO (crash_hotplug); +/* * Some architectures will have custom drivers to do this, and * will not need to do it from userspace. The fake hot-add code
@@ -915,6 +923,7 @@ static struct attribute *memory_root_attrs[] = { &dev_attr_hard_offline_page.attr, &dev_attr_block_size_bytes.attr, &dev_attr_auto_online_blocks.attr, + &dev_attr_crash_hotplug.attr, NULL };
@@ -938,6 +947,10 @@ memory_root_attr_is_visible(struct kobject *kobj,return mode;if (attr == &dev_attr_auto_online_blocks.attr)return mode; +if (IS_ENABLED (CONFIG_CRASH_HOTPLUG )) { +if (attr == &dev_attr_crash_hotplug.attr) +return mode; + }return 0 ; }
include/linux/kexec.h +8 -0
@@ -501,6 +501,14 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {static inline void arch_crash_handle_hotplug_event (struct kimage *image) { }#endif +#ifndef crash_hotplug_cpu_support +static inline int crash_hotplug_cpu_support (void ) {return 0 ; } +#endif + +#ifndef crash_hotplug_memory_support +static inline int crash_hotplug_memory_support (void ) {return 0 ; } +#endif +#else /* !CONFIG_KEXEC_CORE */ struct pt_regs ;struct task_struct ;
Signature · 7 lines
2.31.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Randy Dunlap
reviewerRe: [PATCH v25 06/10] crash: memory and CPU hotplug sysfs attributes
Hi--
Quoted 23 lines · Eric DeVolder
Signed-off-by Eric DeVolder <[email protected]>Reviewed-by Sourabh Jain <[email protected]>Acked-by Hari Bathini <[email protected]>Acked-by Baoquan He <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++++++ .../ABI/testing/sysfs-devices-system-cpu | 8 ++++++++ .../admin-guide/mm/memory-hotplug.rst | 8 ++++++++ Documentation/core-api/cpu_hotplug.rst | 18 ++++++++++++++++++ drivers/base/cpu.c | 16 ++++++++++++++-- drivers/base/memory.c | 13 +++++++++++++ include/linux/kexec.h | 8 ++++++++ 7 files changed, 77 insertions(+), 2 deletions(-)Documentation/admin-guide/mm/memory-hotplug.rst +0
-0@@ -291,6 +291,14 @@ The following files are currently defined: Availability depends on the CONFIG_ARCH_MEMORY_PROBE kernel configuration option.
Documentation/admin-guide/mm/memory-hotplug.rst The following files are currently defined: · line 302
Quoted 10 lines
Documentation/admin-guide/mm/memory-hotplug.rst +8
-0``uevent`` read-write: generic udev file for device subsystems. +``crash_hotplug`` read-only: when changes to the system memory map + occur due to hot un/plug of memory, this file contains + '1' if the kernel updates the kdump capture kernel memory + map itself (via elfcorehdr), or '0' if userspace must update + the kdump capture kernel memory map. + + Availability depends on the CONFIG_MEMORY_HOTPLUG kernel + configuration option. ====================== =========================================================
Did you test build the documentation?
It looks to me like the end-of-table '=' signs line needs 3 more === to be long enough for the text above it.
Quoted 10 lines
Documentation/admin-guide/mm/memory-hotplug.rst +0
-0.. note::Documentation/core-api/cpu_hotplug.rst +0
-0@@ -741,6 +741,24 @@ will receive all events. A script like:: can process the event further.
Documentation/core-api/cpu_hotplug.rst will receive all events. A script like:: · line 753
Quoted 10 lines
Documentation/core-api/cpu_hotplug.rst +10
-0+When changes to the CPUs in the system occur, the sysfs file +/sys/devices/system/cpu/crash_hotplug contains '1' if the kernel +updates the kdump capture kernel list of CPUs itself (via elfcorehdr), +or '0' if userspace must update the kdump capture kernel list of CPUs. + +The availability depends on the CONFIG_HOTPLUG_CPU kernel configuration +option. + +To skip userspace processing of CPU hot un/plug events for kdump +(ie the unload-then-reload to obtain a current list of CPUs), this sysfs
i.e.
Documentation/core-api/cpu_hotplug.rst will receive all events. A script like:: · line 758
Quoted 5 lines
Documentation/core-api/cpu_hotplug.rst +5
-0+file can be used in a udev rule as follows: + + SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" + +For a cpu hot un/plug event, if the architecture supports kernel updates
CPU
for consistency
Documentation/core-api/cpu_hotplug.rst will receive all events. A script like:: · line 764
Quoted 6 lines
Documentation/core-api/cpu_hotplug.rst +3
-0+of the elfcorehdr (which contains the list of CPUs), then the rule skips +the unload-then-reload of the kdump capture kernel. + Kernel Inline Documentations Reference ======================================
Thanks.
Signature · 6 lines
~Randy _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v25 06/10] crash: memory and CPU hotplug sysfs attributes
Randy,
Thanks for looking at this! Inline comments below. eric
Quoted 32 lines · Randy Dunlap
Hi--
Quoted 29 lines · Eric DeVolder
Signed-off-by Eric DeVolder <[email protected]>Reviewed-by Sourabh Jain <[email protected]>Acked-by Hari Bathini <[email protected]>Acked-by Baoquan He <[email protected]>--- Documentation/ABI/testing/sysfs-devices-memory | 8 ++++++++ .../ABI/testing/sysfs-devices-system-cpu | 8 ++++++++ .../admin-guide/mm/memory-hotplug.rst | 8 ++++++++ Documentation/core-api/cpu_hotplug.rst | 18 ++++++++++++++++++ drivers/base/cpu.c | 16 ++++++++++++++-- drivers/base/memory.c | 13 +++++++++++++ include/linux/kexec.h | 8 ++++++++ 7 files changed, 77 insertions(+), 2 deletions(-)Documentation/admin-guide/mm/memory-hotplug.rst +5
-0@@ -291,6 +291,14 @@ The following files are currently defined: Availability depends on the CONFIG_ARCH_MEMORY_PROBE kernel configuration option. ``uevent`` read-write: generic udev file for device subsystems. +``crash_hotplug`` read-only: when changes to the system memory map + occur due to hot un/plug of memory, this file contains + '1' if the kernel updates the kdump capture kernel memory + map itself (via elfcorehdr), or '0' if userspace must update + the kdump capture kernel memory map.
Quoted 8 lines
Documentation/admin-guide/mm/memory-hotplug.rst The following files are currently defined: · line 302
Quoted 4 lines
Documentation/admin-guide/mm/memory-hotplug.rst +3
-0+ + Availability depends on the CONFIG_MEMORY_HOTPLUG kernel + configuration option. ====================== =========================================================Did you test build the documentation?
It looks to me like the end-of-table '=' signs line needs 3 more === to be long enough for the text above it.
Hmm, the 'make htmldocs' renders and views ok. Is there perhaps another method I should use?
Quoted 11 lines
Quoted 11 lines
Documentation/admin-guide/mm/memory-hotplug.rst +0
-0.. note::Documentation/core-api/cpu_hotplug.rst +0
-0@@ -741,6 +741,24 @@ will receive all events. A script like:: can process the event further.
Quoted 13 lines
Documentation/core-api/cpu_hotplug.rst will receive all events. A script like:: · line 753
Quoted 10 lines
Documentation/core-api/cpu_hotplug.rst +10
-0+When changes to the CPUs in the system occur, the sysfs file +/sys/devices/system/cpu/crash_hotplug contains '1' if the kernel +updates the kdump capture kernel list of CPUs itself (via elfcorehdr), +or '0' if userspace must update the kdump capture kernel list of CPUs. + +The availability depends on the CONFIG_HOTPLUG_CPU kernel configuration +option. + +To skip userspace processing of CPU hot un/plug events for kdump +(ie the unload-then-reload to obtain a current list of CPUs), this sysfsi.e.
got it, thanks.
Quoted 9 lines
Documentation/core-api/cpu_hotplug.rst will receive all events. A script like:: · line 758
Quoted 5 lines
Documentation/core-api/cpu_hotplug.rst +5
-0+file can be used in a udev rule as follows: + + SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" + +For a cpu hot un/plug event, if the architecture supports kernel updatesCPU
for consistency
got it, thanks.
Quoted 8 lines
Documentation/core-api/cpu_hotplug.rst will receive all events. A script like:: · line 764
Quoted 6 lines
Documentation/core-api/cpu_hotplug.rst +3
-0+of the elfcorehdr (which contains the list of CPUs), then the rule skips +the unload-then-reload of the kdump capture kernel. + Kernel Inline Documentations Reference ======================================Thanks.
Randy Dunlap
reviewerRe: [PATCH v25 06/10] crash: memory and CPU hotplug sysfs attributes
Quoted 5 lines · Eric DeVolder
Quoted 3 lines
Did you test build the documentation?
It looks to me like the end-of-table '=' signs line needs 3 more === to be long enough for the text above it.Hmm, the 'make htmldocs' renders and views ok. Is there perhaps another method I should use?
No, that's it.
Sorry about the noise.
Signature · 1 line
~Randy
Greg KH
maintainerRe: [PATCH v25 06/10] crash: memory and CPU hotplug sysfs attributes
In reply to Eric DeVolderReview
Quoted 2 lines · Eric DeVolder
(quoted diff) +2
-0+What: /sys/devices/system/cpu/crash_hotplug +Date: Jun 2023
It's not "Jun" anymore :(
Quoted 1 line
+Contact: Linux kernel mailing list <[email protected]>
Why are you not going to maintain this? Why is this up to me?
thanks,
greg k-h
Re: [PATCH v25 06/10] crash: memory and CPU hotplug sysfs attributes
Quoted 6 lines · Greg KH
Review
Quoted 2 lines · Eric DeVolder
(quoted diff) +2
-0+What: /sys/devices/system/cpu/crash_hotplug +Date: Jun 2023It's not "Jun" anymore :(
Quoted 7 lines
Quoted 1 line
+Contact: Linux kernel mailing list <[email protected]>
Why are you not going to maintain this? Why is this up to me?
thanks,
greg k-h
My apologies, I'll correct both in the next posting. Thanks!
eric
PATCH v25 7/10 x86/crash: add x86 crash hotplug support
In reply to Eric DeVolderWhen CPU or memory is hot un/plugged, or off/onlined, the crash elfcorehdr, which describes the CPUs and memory in the system, must also be updated.
A new elfcorehdr is generated from the available CPUs and memory and replaces the existing elfcorehdr. The segment containing the elfcorehdr is identified at run-time in crash_core:crash_handle_hotplug_event().
No modifications to purgatory (see 'kexec: exclude elfcorehdr from the segment digest') or boot_params (as the elfcorehdr= capture kernel command line parameter pointer remains unchanged and correct) are needed, just elfcorehdr.
For kexec_file_load(), the elfcorehdr segment size is based on NR_CPUS and CRASH_MAX_MEMORY_RANGES in order to accommodate a growing number of CPU and memory resources.
For kexec_load(), the userspace kexec utility needs to size the elfcorehdr segment in the same/similar manner.
To accommodate kexec_load() syscall in the absence of kexec_file_load() syscall support, prepare_elf_headers() and dependents are moved outside of CONFIG_KEXEC_FILE.
--- arch/x86/Kconfig | 3 + arch/x86/include/asm/kexec.h | 15 +++++ arch/x86/kernel/crash.c | 103 ++++++++++++++++++++++++++++++++--- 3 files changed, 114 insertions(+), 7 deletions(-)
arch/x86/Kconfig +3 -0
@@ -2058,6 +2058,9 @@ config ARCH_SUPPORTS_KEXEC_JUMP config ARCH_SUPPORTS_CRASH_DUMP def_bool X86_64 || (X86_32 && HIGHMEM) +config ARCH_SUPPORTS_CRASH_HOTPLUG + def_bool y + config PHYSICAL_START hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP) default "0x1000000"
arch/x86/include/asm/kexec.h +15 -0
@@ -209,6 +209,21 @@ typedef void crash_vmclear_fn(void);extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;extern void kdump_nmi_shootdown_cpus (void ); +#ifdef CONFIG_CRASH_HOTPLUG +void arch_crash_handle_hotplug_event (struct kimage *image); +#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event + +#ifdef CONFIG_HOTPLUG_CPU +static inline int crash_hotplug_cpu_support (void ) {return 1 ; } +#define crash_hotplug_cpu_support crash_hotplug_cpu_support +#endif + +#ifdef CONFIG_MEMORY_HOTPLUG +static inline int crash_hotplug_memory_support (void ) {return 1 ; } +#define crash_hotplug_memory_support crash_hotplug_memory_support +#endif +#endif +#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_KEXEC_H */
arch/x86/kernel/crash.c +96 -7
144 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v25 8/10 crash: hotplug support for kexec_load()
In reply to Eric DeVolderThe hotplug support for kexec_load() requires changes to the userspace kexec-tools and a little extra help from the kernel.
Given a kdump capture kernel loaded via kexec_load(), and a subsequent hotplug event, the crash hotplug handler finds the elfcorehdr and rewrites it to reflect the hotplug change. That is the desired outcome, however, at kernel panic time, the purgatory integrity check fails (because the elfcorehdr changed), and the capture kernel does not boot and no vmcore is generated.
Therefore, the userspace kexec-tools/kexec must indicate to the kernel that the elfcorehdr can be modified (because the kexec excluded the elfcorehdr from the digest, and sized the elfcorehdr memory buffer appropriately).
To facilitate hotplug support with kexec_load():
- a new kexec flag KEXEC_UPATE_ELFCOREHDR indicates that it is safe for the kernel to modify the kexec_load()'d elfcorehdr
- the /sys/kernel/crash_elfcorehdr_size node communicates the preferred size of the elfcorehdr memory buffer
- The sysfs crash_hotplug nodes (ie. /sys/devices/system/[cpu|memory]/crash_hotplug) dynamically take into account kexec_file_load() vs kexec_load() and KEXEC_UPDATE_ELFCOREHDR.
This is critical so that the udev rule processing of crash_hotplug is all that is needed to determine if the userspace unload-then-load of the kdump image is to be skipped, or not. The proposed udev rule change looks like:
# 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"
The table below indicates the behavior of kexec_load()'d kdump image updates (with the new udev crash_hotplug rule in place):
Kernel |Kexec
-------+-----+----
Old |Old |New
| a | a -------+-----+----
New | a | b
-------+-----+----
where kexec 'old' and 'new' delineate kexec-tools has the needed modifications for the crash hotplug feature, and kernel 'old' and 'new' delineate the kernel supports this crash hotplug feature.
Behavior 'a' indicates the unload-then-reload of the entire kdump image. For the kexec 'old' column, the unload-then-reload occurs due to the missing flag KEXEC_UPDATE_ELFCOREHDR. An 'old' kernel (with 'new' kexec) does not present the crash_hotplug sysfs node, which leads to the unload-then-reload of the kdump image.
Behavior 'b' indicates the desired optimized behavior of the kernel directly modifying the elfcorehdr and avoiding the unload-then-reload of the kdump image.
If the udev rule is not updated with crash_hotplug node check, then no matter any combination of kernel or kexec is new or old, the kdump image continues to be unload-then-reload on hotplug changes.
To fully support crash hotplug feature, there needs to be a rollout of kernel, kexec-tools and udev rule changes. However, the order of the rollout of these pieces does not matter; kexec_load()'d kdump images still function for hotplug as-is.
--- arch/x86/include/asm/kexec.h | 11 +++++++---- arch/x86/kernel/crash.c | 27 +++++++++++++++++++++++++++ include/linux/kexec.h | 14 ++++++++++++-- include/uapi/linux/kexec.h | 1 + kernel/Kconfig.kexec | 4 ++++ kernel/crash_core.c | 31 +++++++++++++++++++++++++++++++ kernel/kexec.c | 5 +++++ kernel/ksysfs.c | 15 +++++++++++++++ 8 files changed, 102 insertions(+), 6 deletions(-)
arch/x86/include/asm/kexec.h +7 -4
@@ -214,14 +214,17 @@ void arch_crash_handle_hotplug_event(struct kimage *image);#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event#ifdef CONFIG_HOTPLUG_CPU -static inline int crash_hotplug_cpu_support (void ) {return 1 ; } -#define crash_hotplug_cpu_support crash_hotplug_cpu_support +int arch_crash_hotplug_cpu_support (void ); +#define crash_hotplug_cpu_support arch_crash_hotplug_cpu_support#endif #ifdef CONFIG_MEMORY_HOTPLUG -static inline int crash_hotplug_memory_support (void ) {return 1 ; } -#define crash_hotplug_memory_support crash_hotplug_memory_support +int arch_crash_hotplug_memory_support (void ); +#define crash_hotplug_memory_support arch_crash_hotplug_memory_support#endif + +unsigned int arch_crash_get_elfcorehdr_size (void ); +#define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size#endif #endif /* __ASSEMBLY__ */
arch/x86/kernel/crash.c +27 -0
@@ -427,6 +427,33 @@ int crash_load_segments(struct kimage *image)#undef pr_fmt#define pr_fmt (fmt) "crash hp: " fmt +/* These functions provide the value for the sysfs crash_hotplug nodes */ +#ifdef CONFIG_HOTPLUG_CPU +int arch_crash_hotplug_cpu_support (void ) +{ +return crash_check_update_elfcorehdr (); +} +#endif + +#ifdef CONFIG_MEMORY_HOTPLUG +int arch_crash_hotplug_memory_support (void ) +{ +return crash_check_update_elfcorehdr (); +} +#endif + +unsigned int arch_crash_get_elfcorehdr_size (void ) +{ +unsigned int sz; + +/* kernel_map, VMCOREINFO and maximum CPUs */ + sz =2 +CONFIG_NR_CPUS_DEFAULT ; +if (IS_ENABLED (CONFIG_MEMORY_HOTPLUG )) + sz +=CONFIG_CRASH_MAX_MEMORY_RANGES ; + sz *=sizeof (Elf64_Phdr); +return sz; +} +/** * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes * @image: a pointer to kexec_crash_image
include/linux/kexec.h +12 -2
@@ -335,6 +335,10 @@ struct kimage { unsigned int preserve_context : 1;/* If set, we are using file mode kexec syscall */ unsigned int file_mode:1; +#ifdef CONFIG_CRASH_HOTPLUG +/* If set, allow changes to elfcorehdr of kexec_load'd image */ + unsigned int update_elfcorehdr:1; +#endif #ifdef ARCH_HAS_KIMAGE_ARCH struct kimage_arch arch;
@@ -411,9 +415,9 @@ bool kexec_load_permitted(int kexec_image_type);/* List of defined/legal kexec flags */ #ifndef CONFIG_KEXEC_JUMP -#define KEXEC_FLAGS KEXEC_ON_CRASH +#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)#else -#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT) +#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)#endif /* List of defined/legal kexec file flags */
@@ -501,6 +505,8 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {static inline void arch_crash_handle_hotplug_event (struct kimage *image) { }#endif +int crash_check_update_elfcorehdr (void ); +#ifndef crash_hotplug_cpu_supportstatic inline int crash_hotplug_cpu_support (void ) {return 0 ; }#endif
@@ -509,6 +515,10 @@ static inline int crash_hotplug_cpu_support(void) { return 0; }static inline int crash_hotplug_memory_support (void ) {return 0 ; }#endif +#ifndef crash_get_elfcorehdr_size +static inline unsigned int crash_get_elfcorehdr_size (void ) {return 0 ; } +#endif +#else /* !CONFIG_KEXEC_CORE */ struct pt_regs ;struct task_struct ;
include/uapi/linux/kexec.h +1 -0
@@ -12,6 +12,7 @@/* kexec flags for different usage scenarios */ #define KEXEC_ON_CRASH 0x00000001#define KEXEC_PRESERVE_CONTEXT 0x00000002 +#define KEXEC_UPDATE_ELFCOREHDR 0x00000004#define KEXEC_ARCH_MASK 0xffff0000/*
kernel/Kconfig.kexec +4 -0
@@ -138,4 +138,8 @@ config CRASH_MAX_MEMORY_RANGES memory buffer/segment size under 1MiB. This represents a sane choice to accommodate both baremetal and virtual machine configurations. + For the kexec_load() syscall path, CRASH_MAX_MEMORY_RANGES is part of + the computation behind the value provided through the + /sys/kernel/crash_elfcorehdr_size attribute. + endmenu
kernel/crash_core.c +31 -0
@@ -704,6 +704,33 @@ subsys_initcall(crash_save_vmcoreinfo_init);#ifdef CONFIG_CRASH_HOTPLUG #undef pr_fmt#define pr_fmt (fmt) "crash hp: " fmt + +/* +* This routine utilized when the crash_hotplug sysfs node is read. +* It reflects the kernel's ability/permission to update the crash +* elfcorehdr directly. +*/ +int crash_check_update_elfcorehdr (void ) +{ +int rc =0 ; + +/* Obtain lock while reading crash information */ +if (!kexec_trylock ()) { +pr_info ("kexec_trylock() failed, elfcorehdr may be inaccurate\n" ); +return 0 ; + } +if (kexec_crash_image) { +if (kexec_crash_image->file_mode) + rc =1 ; +else + rc = kexec_crash_image->update_elfcorehdr; + } +/* Release lock now that update complete */ +kexec_unlock (); + +return rc; +} +/* * To accurately reflect hot un/plug changes of cpu and memory resources * (including onling and offlining of those resources), the elfcorehdr
@@ -734,6 +761,10 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu) image = kexec_crash_image; +/* Check that updating elfcorehdr is permitted */ +if (!(image->file_mode || image->update_elfcorehdr)) + goto out; +if (hp_action ==KEXEC_CRASH_HP_ADD_CPU || hp_action ==KEXEC_CRASH_HP_REMOVE_CPU )pr_debug ("hp_action %u, cpu %u\n" , hp_action, cpu);
kernel/kexec.c +5 -0
@@ -129,6 +129,11 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,if (flags &KEXEC_PRESERVE_CONTEXT ) image->preserve_context =1 ; +#ifdef CONFIG_CRASH_HOTPLUG +if (flags &KEXEC_UPDATE_ELFCOREHDR ) + image->update_elfcorehdr =1 ; +#endif + ret =machine_kexec_prepare (image);if (ret) goto out;
kernel/ksysfs.c +15 -0
@@ -165,6 +165,18 @@ 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_CRASH_CORE */ /* whether file capabilities are enabled */
@@ -255,6 +267,9 @@ static struct attribute * kernel_attrs[] = {#endif #ifdef CONFIG_CRASH_CORE &vmcoreinfo_attr.attr, +#ifdef CONFIG_CRASH_HOTPLUG + &crash_elfcorehdr_size_attr.attr, +#endif #endif #ifndef CONFIG_TINY_RCU &rcu_expedited_attr.attr,
Signature · 1 line
2.31.1
PATCH v25 9/10 crash: change crash_prepare_elf64_headers() to for_each_possible_cpu()
In reply to Eric DeVolderThe function crash_prepare_elf64_headers() generates the elfcorehdr which describes the CPUs and memory in the system for the crash kernel. In particular, it writes out ELF PT_NOTEs for memory regions and the CPUs in the system.
With respect to the CPUs, the current implementation utilizes for_each_present_cpu() which means that as CPUs are added and removed, the elfcorehdr must again be updated to reflect the new set of CPUs.
The reasoning behind the move to use for_each_possible_cpu(), is:
- At kernel boot time, all percpu crash_notes are allocated for all possible CPUs; that is, crash_notes are not allocated dynamically when CPUs are plugged/unplugged. Thus the crash_notes for each possible CPU are always available.
- The crash_prepare_elf64_headers() creates an ELF PT_NOTE per CPU. Changing to for_each_possible_cpu() is valid as the crash_notes pointed to by each CPU PT_NOTE are present and always valid.
Furthermore, examining a common crash processing path of:
kernel panic -> crash kernel -> makedumpfile -> 'crash' analyzer
elfcorehdr /proc/vmcore vmcore
reveals how the ELF CPU PT_NOTEs are utilized:
- Upon panic, each CPU is sent an IPI and shuts itself down, recording its state in its crash_notes. When all CPUs are shutdown, the crash kernel is launched with a pointer to the elfcorehdr.
- The crash kernel via linux/fs/proc/vmcore.c does not examine or use the contents of the PT_NOTEs, it exposes them via /proc/vmcore.
- The makedumpfile utility uses /proc/vmcore and reads the CPU PT_NOTEs to craft a nr_cpus variable, which is reported in a header but otherwise generally unused. Makedumpfile creates the vmcore.
- The 'crash' dump analyzer does not appear to reference the CPU PT_NOTEs. Instead it looks-up the cpu_[possible|present|onlin]_mask symbols and directly examines those structure contents from vmcore memory. From that information it is able to determine which CPUs are present and online, and locate the corresponding crash_notes. Said differently, it appears that 'crash' analyzer does not rely on the ELF PT_NOTEs for CPUs; rather it obtains the information directly via kernel symbols and the memory within the vmcore.
(There maybe other vmcore generating and analysis tools that do use these PT_NOTEs, but 'makedumpfile' and 'crash' seems to be the most common solution.)
This results in the benefit of having all CPUs described in the elfcorehdr, and therefore reducing the need to re-generate the elfcorehdr on CPU changes, at the small expense of an additional 56 bytes per PT_NOTE for not-present-but-possible CPUs.
On systems where kexec_file_load() syscall is utilized, all the above is valid. On systems where kexec_load() syscall is utilized, there may be the need for the elfcorehdr to be regenerated once. The reason being that some archs only populate the 'present' CPUs from the /sys/devices/system/cpus entries, which the userspace 'kexec' utility uses to generate the userspace-supplied elfcorehdr. In this situation, one memory or CPU change will rewrite the elfcorehdr via the crash_prepare_elf64_headers() function and now all possible CPUs will be described, just as with kexec_file_load() syscall.
--- kernel/crash_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/crash_core.c +2 -2
@@ -364,8 +364,8 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, ehdr->e_ehsize =sizeof (Elf64_Ehdr); ehdr->e_phentsize =sizeof (Elf64_Phdr); -/* Prepare one phdr of type PT_NOTE for each present CPU */ -for_each_present_cpu (cpu) { +/* Prepare one phdr of type PT_NOTE for each possible CPU */ +for_each_possible_cpu (cpu) { phdr->p_type =PT_NOTE ; notes_addr =per_cpu_ptr_to_phys (per_cpu_ptr (crash_notes, cpu)); phdr->p_offset = phdr->p_paddr = notes_addr;
Signature · 1 line
2.31.1
PATCH v25 10/10 x86/crash: optimize CPU changes
In reply to Eric DeVoldercrash_prepare_elf64_headers() writes into the elfcorehdr an ELF PT_NOTE for all possible CPUs. As such, subsequent changes to CPUs (ie. hot un/plug, online/offline) do not need to rewrite the elfcorehdr.
The kimage->file_mode term covers kdump images loaded via the kexec_file_load() syscall. Since crash_prepare_elf64_headers() wrote the initial elfcorehdr, no update to the elfcorehdr is needed for CPU changes.
The kimage->elfcorehdr_updated term covers kdump images loaded via the kexec_load() syscall. At least one memory or CPU change must occur to cause crash_prepare_elf64_headers() to rewrite the elfcorehdr. Afterwards, no update to the elfcorehdr is needed for CPU changes.
This code is intentionally *NOT* hoisted into crash_handle_hotplug_event() as it would prevent the arch-specific handler from running for CPU changes. This would break PPC, for example, which needs to update other information besides the elfcorehdr, on CPU changes.
--- arch/x86/kernel/crash.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kernel/crash.c +10 -0
@@ -467,6 +467,16 @@ void arch_crash_handle_hotplug_event(struct kimage *image)unsigned long mem, memsz;unsigned long elfsz =0 ; +/* +* As crash_prepare_elf64_headers() has already described all +* possible CPUs, there is no need to update the elfcorehdr +* for additional CPU changes. +*/ +if ((image->file_mode || image->elfcorehdr_updated) && + ((image->hp_action ==KEXEC_CRASH_HP_ADD_CPU ) || + (image->hp_action ==KEXEC_CRASH_HP_REMOVE_CPU ))) +return ; +/* * Create the new elfcorehdr reflecting the changes to CPU and/or * memory resources.
Signature · 1 line
2.31.1