Skip to content

Commit 7936502

Browse files
sourabhjainsmpe
authored andcommitted
crash: add a new kexec flag for hotplug support
Commit a72bbec ("crash: hotplug support for kexec_load()") introduced a new kexec flag, `KEXEC_UPDATE_ELFCOREHDR`. Kexec tool uses this flag to indicate to the kernel that it is safe to modify the elfcorehdr of the kdump image loaded using the kexec_load system call. However, it is possible that architectures may need to update kexec segments other then elfcorehdr. For example, FDT (Flatten Device Tree) on PowerPC. Introducing a new kexec flag for every new kexec segment may not be a good solution. Hence, a generic kexec flag bit, `KEXEC_CRASH_HOTPLUG_SUPPORT`, is introduced to share the CPU/Memory hotplug support intent between the kexec tool and the kernel for the kexec_load system call. Now we have two kexec flags that enables crash hotplug support for kexec_load system call. First is KEXEC_UPDATE_ELFCOREHDR (only used in x86), and second is KEXEC_CRASH_HOTPLUG_SUPPORT (for all architectures). To simplify the process of finding and reporting the crash hotplug support the following changes are introduced. 1. Define arch specific function to process the kexec flags and determine crash hotplug support 2. Rename the @update_elfcorehdr member of struct kimage to @hotplug_support and populate it for both kexec_load and kexec_file_load syscalls, because architecture can update more than one kexec segment 3. Let generic function crash_check_hotplug_support report hotplug support for loaded kdump image based on value of @hotplug_support To bring the x86 crash hotplug support in line with the above points, the following changes have been made: - Introduce the arch_crash_hotplug_support function to process kexec flags and determine crash hotplug support - Remove the arch_crash_hotplug_[cpu|memory]_support functions Signed-off-by: Sourabh Jain <[email protected]> Acked-by: Baoquan He <[email protected]> Acked-by: Hari Bathini <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 1180057 commit 7936502

File tree

10 files changed

+48
-44
lines changed

10 files changed

+48
-44
lines changed

arch/x86/include/asm/kexec.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,8 @@ extern void kdump_nmi_shootdown_cpus(void);
210210
void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
211211
#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
212212

213-
#ifdef CONFIG_HOTPLUG_CPU
214-
int arch_crash_hotplug_cpu_support(void);
215-
#define crash_hotplug_cpu_support arch_crash_hotplug_cpu_support
216-
#endif
217-
218-
#ifdef CONFIG_MEMORY_HOTPLUG
219-
int arch_crash_hotplug_memory_support(void);
220-
#define crash_hotplug_memory_support arch_crash_hotplug_memory_support
221-
#endif
213+
int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
214+
#define arch_crash_hotplug_support arch_crash_hotplug_support
222215

223216
unsigned int arch_crash_get_elfcorehdr_size(void);
224217
#define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size

arch/x86/kernel/crash.c

+17-11
Original file line numberDiff line numberDiff line change
@@ -402,20 +402,26 @@ int crash_load_segments(struct kimage *image)
402402
#undef pr_fmt
403403
#define pr_fmt(fmt) "crash hp: " fmt
404404

405-
/* These functions provide the value for the sysfs crash_hotplug nodes */
406-
#ifdef CONFIG_HOTPLUG_CPU
407-
int arch_crash_hotplug_cpu_support(void)
405+
int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
408406
{
409-
return crash_check_update_elfcorehdr();
410-
}
411-
#endif
412407

413-
#ifdef CONFIG_MEMORY_HOTPLUG
414-
int arch_crash_hotplug_memory_support(void)
415-
{
416-
return crash_check_update_elfcorehdr();
417-
}
408+
#ifdef CONFIG_KEXEC_FILE
409+
if (image->file_mode)
410+
return 1;
418411
#endif
412+
/*
413+
* Initially, crash hotplug support for kexec_load was added
414+
* with the KEXEC_UPDATE_ELFCOREHDR flag. Later, this
415+
* functionality was expanded to accommodate multiple kexec
416+
* segment updates, leading to the introduction of the
417+
* KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag bit. Consequently,
418+
* when the kexec tool sends either of these flags, it indicates
419+
* that the required kexec segment (elfcorehdr) is excluded from
420+
* the SHA calculation.
421+
*/
422+
return (kexec_flags & KEXEC_UPDATE_ELFCOREHDR ||
423+
kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT);
424+
}
419425

420426
unsigned int arch_crash_get_elfcorehdr_size(void)
421427
{

drivers/base/cpu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static ssize_t crash_hotplug_show(struct device *dev,
306306
struct device_attribute *attr,
307307
char *buf)
308308
{
309-
return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
309+
return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
310310
}
311311
static DEVICE_ATTR_ADMIN_RO(crash_hotplug);
312312
#endif

drivers/base/memory.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static DEVICE_ATTR_RW(auto_online_blocks);
535535
static ssize_t crash_hotplug_show(struct device *dev,
536536
struct device_attribute *attr, char *buf)
537537
{
538-
return sysfs_emit(buf, "%d\n", crash_hotplug_memory_support());
538+
return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
539539
}
540540
static DEVICE_ATTR_RO(crash_hotplug);
541541
#endif

include/linux/crash_core.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ static inline void arch_kexec_unprotect_crashkres(void) { }
4040
static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
4141
#endif
4242

43-
int crash_check_update_elfcorehdr(void);
43+
int crash_check_hotplug_support(void);
4444

45-
#ifndef crash_hotplug_cpu_support
46-
static inline int crash_hotplug_cpu_support(void) { return 0; }
47-
#endif
48-
49-
#ifndef crash_hotplug_memory_support
50-
static inline int crash_hotplug_memory_support(void) { return 0; }
45+
#ifndef arch_crash_hotplug_support
46+
static inline int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
47+
{
48+
return 0;
49+
}
5150
#endif
5251

5352
#ifndef crash_get_elfcorehdr_size

include/linux/kexec.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ struct kimage {
319319
/* If set, we are using file mode kexec syscall */
320320
unsigned int file_mode:1;
321321
#ifdef CONFIG_CRASH_HOTPLUG
322-
/* If set, allow changes to elfcorehdr of kexec_load'd image */
323-
unsigned int update_elfcorehdr:1;
322+
/* If set, it is safe to update kexec segments that are
323+
* excluded from SHA calculation.
324+
*/
325+
unsigned int hotplug_support:1;
324326
#endif
325327

326328
#ifdef ARCH_HAS_KIMAGE_ARCH
@@ -391,9 +393,10 @@ bool kexec_load_permitted(int kexec_image_type);
391393

392394
/* List of defined/legal kexec flags */
393395
#ifndef CONFIG_KEXEC_JUMP
394-
#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)
396+
#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
395397
#else
396-
#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)
398+
#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
399+
KEXEC_CRASH_HOTPLUG_SUPPORT)
397400
#endif
398401

399402
/* List of defined/legal kexec file flags */

include/uapi/linux/kexec.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define KEXEC_ON_CRASH 0x00000001
1414
#define KEXEC_PRESERVE_CONTEXT 0x00000002
1515
#define KEXEC_UPDATE_ELFCOREHDR 0x00000004
16+
#define KEXEC_CRASH_HOTPLUG_SUPPORT 0x00000008
1617
#define KEXEC_ARCH_MASK 0xffff0000
1718

1819
/*

kernel/crash_core.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,10 @@ static DEFINE_MUTEX(__crash_hotplug_lock);
493493

494494
/*
495495
* This routine utilized when the crash_hotplug sysfs node is read.
496-
* It reflects the kernel's ability/permission to update the crash
497-
* elfcorehdr directly.
496+
* It reflects the kernel's ability/permission to update the kdump
497+
* image directly.
498498
*/
499-
int crash_check_update_elfcorehdr(void)
499+
int crash_check_hotplug_support(void)
500500
{
501501
int rc = 0;
502502

@@ -508,10 +508,7 @@ int crash_check_update_elfcorehdr(void)
508508
return 0;
509509
}
510510
if (kexec_crash_image) {
511-
if (kexec_crash_image->file_mode)
512-
rc = 1;
513-
else
514-
rc = kexec_crash_image->update_elfcorehdr;
511+
rc = kexec_crash_image->hotplug_support;
515512
}
516513
/* Release lock now that update complete */
517514
kexec_unlock();
@@ -552,8 +549,8 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu,
552549

553550
image = kexec_crash_image;
554551

555-
/* Check that updating elfcorehdr is permitted */
556-
if (!(image->file_mode || image->update_elfcorehdr))
552+
/* Check that kexec segments update is permitted */
553+
if (!image->hotplug_support)
557554
goto out;
558555

559556
if (hp_action == KEXEC_CRASH_HP_ADD_CPU ||

kernel/kexec.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
135135
image->preserve_context = 1;
136136

137137
#ifdef CONFIG_CRASH_HOTPLUG
138-
if (flags & KEXEC_UPDATE_ELFCOREHDR)
139-
image->update_elfcorehdr = 1;
138+
if ((flags & KEXEC_ON_CRASH) && arch_crash_hotplug_support(image, flags))
139+
image->hotplug_support = 1;
140140
#endif
141141

142142
ret = machine_kexec_prepare(image);

kernel/kexec_file.c

+5
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
376376
if (ret)
377377
goto out;
378378

379+
#ifdef CONFIG_CRASH_HOTPLUG
380+
if ((flags & KEXEC_FILE_ON_CRASH) && arch_crash_hotplug_support(image, flags))
381+
image->hotplug_support = 1;
382+
#endif
383+
379384
ret = machine_kexec_prepare(image);
380385
if (ret)
381386
goto out;

0 commit comments

Comments
 (0)