Skip to content

Commit 24ee25a

Browse files
committed
Merge branch 'x86-kdump-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 kdump updates from Ingo Molnar: "This solves a kdump artifact where encrypted memory contents are dumped, instead of unencrypted ones. The solution also happens to simplify the kdump code, to everyone's delight" * 'x86-kdump-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/crash: Align function arguments on opening braces x86/kdump: Remove the backup region handling x86/kdump: Always reserve the low 1M when the crashkernel option is specified x86/crash: Add a forward declaration of struct kimage
2 parents 64d6a12 + 9eff303 commit 24ee25a

File tree

7 files changed

+46
-178
lines changed

7 files changed

+46
-178
lines changed

arch/x86/include/asm/crash.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
#ifndef _ASM_X86_CRASH_H
33
#define _ASM_X86_CRASH_H
44

5+
struct kimage;
6+
57
int crash_load_segments(struct kimage *image);
68
int crash_setup_memmap_entries(struct kimage *image,
79
struct boot_params *params);
810
void crash_smp_send_stop(void);
911

12+
#ifdef CONFIG_KEXEC_CORE
13+
void __init crash_reserve_low_1M(void);
14+
#else
15+
static inline void __init crash_reserve_low_1M(void) { }
16+
#endif
17+
1018
#endif /* _ASM_X86_CRASH_H */

arch/x86/include/asm/kexec.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ struct kimage;
6666
# define KEXEC_ARCH KEXEC_ARCH_X86_64
6767
#endif
6868

69-
/* Memory to backup during crash kdump */
70-
#define KEXEC_BACKUP_SRC_START (0UL)
71-
#define KEXEC_BACKUP_SRC_END (640 * 1024UL - 1) /* 640K */
72-
7369
/*
7470
* This function is responsible for capturing register states if coming
7571
* via panic otherwise just fix up the ss and sp if coming via kernel
@@ -154,12 +150,6 @@ struct kimage_arch {
154150
pud_t *pud;
155151
pmd_t *pmd;
156152
pte_t *pte;
157-
/* Details of backup region */
158-
unsigned long backup_src_start;
159-
unsigned long backup_src_sz;
160-
161-
/* Physical address of backup segment */
162-
unsigned long backup_load_addr;
163153

164154
/* Core ELF header buffer */
165155
void *elf_headers;

arch/x86/include/asm/purgatory.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
#include <linux/purgatory.h>
77

88
extern void purgatory(void);
9-
/*
10-
* These forward declarations serve two purposes:
11-
*
12-
* 1) Make sparse happy when checking arch/purgatory
13-
* 2) Document that these are required to be global so the symbol
14-
* lookup in kexec works
15-
*/
16-
extern unsigned long purgatory_backup_dest;
17-
extern unsigned long purgatory_backup_src;
18-
extern unsigned long purgatory_backup_sz;
199
#endif /* __ASSEMBLY__ */
2010

2111
#endif /* _ASM_PURGATORY_H */

arch/x86/kernel/crash.c

Lines changed: 36 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/export.h>
2525
#include <linux/slab.h>
2626
#include <linux/vmalloc.h>
27+
#include <linux/memblock.h>
2728

2829
#include <asm/processor.h>
2930
#include <asm/hardirq.h>
@@ -39,6 +40,7 @@
3940
#include <asm/virtext.h>
4041
#include <asm/intel_pt.h>
4142
#include <asm/crash.h>
43+
#include <asm/cmdline.h>
4244

4345
/* Used while preparing memory map entries for second kernel */
4446
struct crash_memmap_data {
@@ -68,6 +70,19 @@ static inline void cpu_crash_vmclear_loaded_vmcss(void)
6870
rcu_read_unlock();
6971
}
7072

73+
/*
74+
* When the crashkernel option is specified, only use the low
75+
* 1M for the real mode trampoline.
76+
*/
77+
void __init crash_reserve_low_1M(void)
78+
{
79+
if (cmdline_find_option(boot_command_line, "crashkernel", NULL, 0) < 0)
80+
return;
81+
82+
memblock_reserve(0, 1<<20);
83+
pr_info("Reserving the low 1M of memory for crashkernel\n");
84+
}
85+
7186
#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
7287

7388
static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
@@ -173,8 +188,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
173188

174189
#ifdef CONFIG_KEXEC_FILE
175190

176-
static unsigned long crash_zero_bytes;
177-
178191
static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
179192
{
180193
unsigned int *nr_ranges = arg;
@@ -189,8 +202,7 @@ static struct crash_mem *fill_up_crash_elf_data(void)
189202
unsigned int nr_ranges = 0;
190203
struct crash_mem *cmem;
191204

192-
walk_system_ram_res(0, -1, &nr_ranges,
193-
get_nr_ram_ranges_callback);
205+
walk_system_ram_res(0, -1, &nr_ranges, get_nr_ram_ranges_callback);
194206
if (!nr_ranges)
195207
return NULL;
196208

@@ -217,15 +229,19 @@ static int elf_header_exclude_ranges(struct crash_mem *cmem)
217229
{
218230
int ret = 0;
219231

232+
/* Exclude the low 1M because it is always reserved */
233+
ret = crash_exclude_mem_range(cmem, 0, 1<<20);
234+
if (ret)
235+
return ret;
236+
220237
/* Exclude crashkernel region */
221238
ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
222239
if (ret)
223240
return ret;
224241

225-
if (crashk_low_res.end) {
242+
if (crashk_low_res.end)
226243
ret = crash_exclude_mem_range(cmem, crashk_low_res.start,
227-
crashk_low_res.end);
228-
}
244+
crashk_low_res.end);
229245

230246
return ret;
231247
}
@@ -246,16 +262,13 @@ static int prepare_elf_headers(struct kimage *image, void **addr,
246262
unsigned long *sz)
247263
{
248264
struct crash_mem *cmem;
249-
Elf64_Ehdr *ehdr;
250-
Elf64_Phdr *phdr;
251-
int ret, i;
265+
int ret;
252266

253267
cmem = fill_up_crash_elf_data();
254268
if (!cmem)
255269
return -ENOMEM;
256270

257-
ret = walk_system_ram_res(0, -1, cmem,
258-
prepare_elf64_ram_headers_callback);
271+
ret = walk_system_ram_res(0, -1, cmem, prepare_elf64_ram_headers_callback);
259272
if (ret)
260273
goto out;
261274

@@ -265,24 +278,8 @@ static int prepare_elf_headers(struct kimage *image, void **addr,
265278
goto out;
266279

267280
/* By default prepare 64bit headers */
268-
ret = crash_prepare_elf64_headers(cmem,
269-
IS_ENABLED(CONFIG_X86_64), addr, sz);
270-
if (ret)
271-
goto out;
281+
ret = crash_prepare_elf64_headers(cmem, IS_ENABLED(CONFIG_X86_64), addr, sz);
272282

273-
/*
274-
* If a range matches backup region, adjust offset to backup
275-
* segment.
276-
*/
277-
ehdr = (Elf64_Ehdr *)*addr;
278-
phdr = (Elf64_Phdr *)(ehdr + 1);
279-
for (i = 0; i < ehdr->e_phnum; phdr++, i++)
280-
if (phdr->p_type == PT_LOAD &&
281-
phdr->p_paddr == image->arch.backup_src_start &&
282-
phdr->p_memsz == image->arch.backup_src_sz) {
283-
phdr->p_offset = image->arch.backup_load_addr;
284-
break;
285-
}
286283
out:
287284
vfree(cmem);
288285
return ret;
@@ -296,8 +293,7 @@ static int add_e820_entry(struct boot_params *params, struct e820_entry *entry)
296293
if (nr_e820_entries >= E820_MAX_ENTRIES_ZEROPAGE)
297294
return 1;
298295

299-
memcpy(&params->e820_table[nr_e820_entries], entry,
300-
sizeof(struct e820_entry));
296+
memcpy(&params->e820_table[nr_e820_entries], entry, sizeof(struct e820_entry));
301297
params->e820_entries++;
302298
return 0;
303299
}
@@ -321,19 +317,11 @@ static int memmap_exclude_ranges(struct kimage *image, struct crash_mem *cmem,
321317
unsigned long long mend)
322318
{
323319
unsigned long start, end;
324-
int ret = 0;
325320

326321
cmem->ranges[0].start = mstart;
327322
cmem->ranges[0].end = mend;
328323
cmem->nr_ranges = 1;
329324

330-
/* Exclude Backup region */
331-
start = image->arch.backup_load_addr;
332-
end = start + image->arch.backup_src_sz - 1;
333-
ret = crash_exclude_mem_range(cmem, start, end);
334-
if (ret)
335-
return ret;
336-
337325
/* Exclude elf header region */
338326
start = image->arch.elf_load_addr;
339327
end = start + image->arch.elf_headers_sz - 1;
@@ -356,28 +344,28 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
356344
memset(&cmd, 0, sizeof(struct crash_memmap_data));
357345
cmd.params = params;
358346

359-
/* Add first 640K segment */
360-
ei.addr = image->arch.backup_src_start;
361-
ei.size = image->arch.backup_src_sz;
362-
ei.type = E820_TYPE_RAM;
363-
add_e820_entry(params, &ei);
347+
/* Add the low 1M */
348+
cmd.type = E820_TYPE_RAM;
349+
flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
350+
walk_iomem_res_desc(IORES_DESC_NONE, flags, 0, (1<<20)-1, &cmd,
351+
memmap_entry_callback);
364352

365353
/* Add ACPI tables */
366354
cmd.type = E820_TYPE_ACPI;
367355
flags = IORESOURCE_MEM | IORESOURCE_BUSY;
368356
walk_iomem_res_desc(IORES_DESC_ACPI_TABLES, flags, 0, -1, &cmd,
369-
memmap_entry_callback);
357+
memmap_entry_callback);
370358

371359
/* Add ACPI Non-volatile Storage */
372360
cmd.type = E820_TYPE_NVS;
373361
walk_iomem_res_desc(IORES_DESC_ACPI_NV_STORAGE, flags, 0, -1, &cmd,
374-
memmap_entry_callback);
362+
memmap_entry_callback);
375363

376364
/* Add e820 reserved ranges */
377365
cmd.type = E820_TYPE_RESERVED;
378366
flags = IORESOURCE_MEM;
379367
walk_iomem_res_desc(IORES_DESC_RESERVED, flags, 0, -1, &cmd,
380-
memmap_entry_callback);
368+
memmap_entry_callback);
381369

382370
/* Add crashk_low_res region */
383371
if (crashk_low_res.end) {
@@ -388,8 +376,7 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
388376
}
389377

390378
/* Exclude some ranges from crashk_res and add rest to memmap */
391-
ret = memmap_exclude_ranges(image, cmem, crashk_res.start,
392-
crashk_res.end);
379+
ret = memmap_exclude_ranges(image, cmem, crashk_res.start, crashk_res.end);
393380
if (ret)
394381
goto out;
395382

@@ -409,55 +396,12 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
409396
return ret;
410397
}
411398

412-
static int determine_backup_region(struct resource *res, void *arg)
413-
{
414-
struct kimage *image = arg;
415-
416-
image->arch.backup_src_start = res->start;
417-
image->arch.backup_src_sz = resource_size(res);
418-
419-
/* Expecting only one range for backup region */
420-
return 1;
421-
}
422-
423399
int crash_load_segments(struct kimage *image)
424400
{
425401
int ret;
426402
struct kexec_buf kbuf = { .image = image, .buf_min = 0,
427403
.buf_max = ULONG_MAX, .top_down = false };
428404

429-
/*
430-
* Determine and load a segment for backup area. First 640K RAM
431-
* region is backup source
432-
*/
433-
434-
ret = walk_system_ram_res(KEXEC_BACKUP_SRC_START, KEXEC_BACKUP_SRC_END,
435-
image, determine_backup_region);
436-
437-
/* Zero or postive return values are ok */
438-
if (ret < 0)
439-
return ret;
440-
441-
/* Add backup segment. */
442-
if (image->arch.backup_src_sz) {
443-
kbuf.buffer = &crash_zero_bytes;
444-
kbuf.bufsz = sizeof(crash_zero_bytes);
445-
kbuf.memsz = image->arch.backup_src_sz;
446-
kbuf.buf_align = PAGE_SIZE;
447-
/*
448-
* Ideally there is no source for backup segment. This is
449-
* copied in purgatory after crash. Just add a zero filled
450-
* segment for now to make sure checksum logic works fine.
451-
*/
452-
ret = kexec_add_buffer(&kbuf);
453-
if (ret)
454-
return ret;
455-
image->arch.backup_load_addr = kbuf.mem;
456-
pr_debug("Loaded backup region at 0x%lx backup_start=0x%lx memsz=0x%lx\n",
457-
image->arch.backup_load_addr,
458-
image->arch.backup_src_start, kbuf.memsz);
459-
}
460-
461405
/* Prepare elf headers and add a segment */
462406
ret = prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz);
463407
if (ret)

arch/x86/kernel/machine_kexec_64.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -298,48 +298,6 @@ static void load_segments(void)
298298
);
299299
}
300300

301-
#ifdef CONFIG_KEXEC_FILE
302-
/* Update purgatory as needed after various image segments have been prepared */
303-
static int arch_update_purgatory(struct kimage *image)
304-
{
305-
int ret = 0;
306-
307-
if (!image->file_mode)
308-
return 0;
309-
310-
/* Setup copying of backup region */
311-
if (image->type == KEXEC_TYPE_CRASH) {
312-
ret = kexec_purgatory_get_set_symbol(image,
313-
"purgatory_backup_dest",
314-
&image->arch.backup_load_addr,
315-
sizeof(image->arch.backup_load_addr), 0);
316-
if (ret)
317-
return ret;
318-
319-
ret = kexec_purgatory_get_set_symbol(image,
320-
"purgatory_backup_src",
321-
&image->arch.backup_src_start,
322-
sizeof(image->arch.backup_src_start), 0);
323-
if (ret)
324-
return ret;
325-
326-
ret = kexec_purgatory_get_set_symbol(image,
327-
"purgatory_backup_sz",
328-
&image->arch.backup_src_sz,
329-
sizeof(image->arch.backup_src_sz), 0);
330-
if (ret)
331-
return ret;
332-
}
333-
334-
return ret;
335-
}
336-
#else /* !CONFIG_KEXEC_FILE */
337-
static inline int arch_update_purgatory(struct kimage *image)
338-
{
339-
return 0;
340-
}
341-
#endif /* CONFIG_KEXEC_FILE */
342-
343301
int machine_kexec_prepare(struct kimage *image)
344302
{
345303
unsigned long start_pgtable;
@@ -353,11 +311,6 @@ int machine_kexec_prepare(struct kimage *image)
353311
if (result)
354312
return result;
355313

356-
/* update purgatory as needed */
357-
result = arch_update_purgatory(image);
358-
if (result)
359-
return result;
360-
361314
return 0;
362315
}
363316

0 commit comments

Comments
 (0)