Skip to content

Commit 7c321eb

Browse files
lian-bosuryasaimadhu
authored andcommitted
x86/kdump: Remove the backup region handling
When the crashkernel kernel command line option is specified, the low 1M memory will always be reserved now. Therefore, it's not necessary to create a backup region anymore and also no need to copy the contents of the first 640k to it. Remove all the code related to handling that backup region. [ bp: Massage commit message. ] Signed-off-by: Lianbo Jiang <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] Cc: Dave Young <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jürgen Gross <[email protected]> Cc: [email protected] Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: [email protected] Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6f599d8 commit 7c321eb

File tree

5 files changed

+11
-162
lines changed

5 files changed

+11
-162
lines changed

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: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
188188

189189
#ifdef CONFIG_KEXEC_FILE
190190

191-
static unsigned long crash_zero_bytes;
192-
193191
static int get_nr_ram_ranges_callback(struct resource *res, void *arg)
194192
{
195193
unsigned int *nr_ranges = arg;
@@ -232,6 +230,11 @@ static int elf_header_exclude_ranges(struct crash_mem *cmem)
232230
{
233231
int ret = 0;
234232

233+
/* Exclude the low 1M because it is always reserved */
234+
ret = crash_exclude_mem_range(cmem, 0, 1<<20);
235+
if (ret)
236+
return ret;
237+
235238
/* Exclude crashkernel region */
236239
ret = crash_exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
237240
if (ret)
@@ -261,9 +264,7 @@ static int prepare_elf_headers(struct kimage *image, void **addr,
261264
unsigned long *sz)
262265
{
263266
struct crash_mem *cmem;
264-
Elf64_Ehdr *ehdr;
265-
Elf64_Phdr *phdr;
266-
int ret, i;
267+
int ret;
267268

268269
cmem = fill_up_crash_elf_data();
269270
if (!cmem)
@@ -282,22 +283,7 @@ static int prepare_elf_headers(struct kimage *image, void **addr,
282283
/* By default prepare 64bit headers */
283284
ret = crash_prepare_elf64_headers(cmem,
284285
IS_ENABLED(CONFIG_X86_64), addr, sz);
285-
if (ret)
286-
goto out;
287286

288-
/*
289-
* If a range matches backup region, adjust offset to backup
290-
* segment.
291-
*/
292-
ehdr = (Elf64_Ehdr *)*addr;
293-
phdr = (Elf64_Phdr *)(ehdr + 1);
294-
for (i = 0; i < ehdr->e_phnum; phdr++, i++)
295-
if (phdr->p_type == PT_LOAD &&
296-
phdr->p_paddr == image->arch.backup_src_start &&
297-
phdr->p_memsz == image->arch.backup_src_sz) {
298-
phdr->p_offset = image->arch.backup_load_addr;
299-
break;
300-
}
301287
out:
302288
vfree(cmem);
303289
return ret;
@@ -336,19 +322,11 @@ static int memmap_exclude_ranges(struct kimage *image, struct crash_mem *cmem,
336322
unsigned long long mend)
337323
{
338324
unsigned long start, end;
339-
int ret = 0;
340325

341326
cmem->ranges[0].start = mstart;
342327
cmem->ranges[0].end = mend;
343328
cmem->nr_ranges = 1;
344329

345-
/* Exclude Backup region */
346-
start = image->arch.backup_load_addr;
347-
end = start + image->arch.backup_src_sz - 1;
348-
ret = crash_exclude_mem_range(cmem, start, end);
349-
if (ret)
350-
return ret;
351-
352330
/* Exclude elf header region */
353331
start = image->arch.elf_load_addr;
354332
end = start + image->arch.elf_headers_sz - 1;
@@ -371,11 +349,11 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
371349
memset(&cmd, 0, sizeof(struct crash_memmap_data));
372350
cmd.params = params;
373351

374-
/* Add first 640K segment */
375-
ei.addr = image->arch.backup_src_start;
376-
ei.size = image->arch.backup_src_sz;
377-
ei.type = E820_TYPE_RAM;
378-
add_e820_entry(params, &ei);
352+
/* Add the low 1M */
353+
cmd.type = E820_TYPE_RAM;
354+
flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
355+
walk_iomem_res_desc(IORES_DESC_NONE, flags, 0, (1<<20)-1, &cmd,
356+
memmap_entry_callback);
379357

380358
/* Add ACPI tables */
381359
cmd.type = E820_TYPE_ACPI;
@@ -424,55 +402,12 @@ int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
424402
return ret;
425403
}
426404

427-
static int determine_backup_region(struct resource *res, void *arg)
428-
{
429-
struct kimage *image = arg;
430-
431-
image->arch.backup_src_start = res->start;
432-
image->arch.backup_src_sz = resource_size(res);
433-
434-
/* Expecting only one range for backup region */
435-
return 1;
436-
}
437-
438405
int crash_load_segments(struct kimage *image)
439406
{
440407
int ret;
441408
struct kexec_buf kbuf = { .image = image, .buf_min = 0,
442409
.buf_max = ULONG_MAX, .top_down = false };
443410

444-
/*
445-
* Determine and load a segment for backup area. First 640K RAM
446-
* region is backup source
447-
*/
448-
449-
ret = walk_system_ram_res(KEXEC_BACKUP_SRC_START, KEXEC_BACKUP_SRC_END,
450-
image, determine_backup_region);
451-
452-
/* Zero or postive return values are ok */
453-
if (ret < 0)
454-
return ret;
455-
456-
/* Add backup segment. */
457-
if (image->arch.backup_src_sz) {
458-
kbuf.buffer = &crash_zero_bytes;
459-
kbuf.bufsz = sizeof(crash_zero_bytes);
460-
kbuf.memsz = image->arch.backup_src_sz;
461-
kbuf.buf_align = PAGE_SIZE;
462-
/*
463-
* Ideally there is no source for backup segment. This is
464-
* copied in purgatory after crash. Just add a zero filled
465-
* segment for now to make sure checksum logic works fine.
466-
*/
467-
ret = kexec_add_buffer(&kbuf);
468-
if (ret)
469-
return ret;
470-
image->arch.backup_load_addr = kbuf.mem;
471-
pr_debug("Loaded backup region at 0x%lx backup_start=0x%lx memsz=0x%lx\n",
472-
image->arch.backup_load_addr,
473-
image->arch.backup_src_start, kbuf.memsz);
474-
}
475-
476411
/* Prepare elf headers and add a segment */
477412
ret = prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz);
478413
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

arch/x86/purgatory/purgatory.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,10 @@
1414

1515
#include "../boot/string.h"
1616

17-
unsigned long purgatory_backup_dest __section(.kexec-purgatory);
18-
unsigned long purgatory_backup_src __section(.kexec-purgatory);
19-
unsigned long purgatory_backup_sz __section(.kexec-purgatory);
20-
2117
u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(.kexec-purgatory);
2218

2319
struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(.kexec-purgatory);
2420

25-
/*
26-
* On x86, second kernel requries first 640K of memory to boot. Copy
27-
* first 640K to a backup region in reserved memory range so that second
28-
* kernel can use first 640K.
29-
*/
30-
static int copy_backup_region(void)
31-
{
32-
if (purgatory_backup_dest) {
33-
memcpy((void *)purgatory_backup_dest,
34-
(void *)purgatory_backup_src, purgatory_backup_sz);
35-
}
36-
return 0;
37-
}
38-
3921
static int verify_sha256_digest(void)
4022
{
4123
struct kexec_sha_region *ptr, *end;
@@ -66,7 +48,6 @@ void purgatory(void)
6648
for (;;)
6749
;
6850
}
69-
copy_backup_region();
7051
}
7152

7253
/*

0 commit comments

Comments
 (0)