Skip to content

Commit ec4b8e2

Browse files
committed
efi/runtime-map: Use efi.memmap directly instead of a copy
Now that efi.memmap is available all of the time there's no need to allocate and build a separate copy of the EFI memory map. Furthermore, efi.memmap contains boot services regions but only those regions that have been reserved via efi_mem_reserve(). Using efi.memmap allows us to pass boot services across kexec reboot so that the ESRT and BGRT drivers will now work. Tested-by: Dave Young <dyoung@redhat.com> [kexec/kdump] Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> [arm] Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Leif Lindholm <leif.lindholm@linaro.org> Cc: Peter Jones <pjones@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk>
1 parent 7b02d53 commit ec4b8e2

File tree

3 files changed

+13
-66
lines changed

3 files changed

+13
-66
lines changed

arch/x86/platform/efi/efi.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -593,42 +593,6 @@ static void __init get_systab_virt_addr(efi_memory_desc_t *md)
593593
}
594594
}
595595

596-
static void __init save_runtime_map(void)
597-
{
598-
#ifdef CONFIG_KEXEC_CORE
599-
unsigned long desc_size;
600-
efi_memory_desc_t *md;
601-
void *tmp, *q = NULL;
602-
int count = 0;
603-
604-
if (efi_enabled(EFI_OLD_MEMMAP))
605-
return;
606-
607-
desc_size = efi.memmap.desc_size;
608-
609-
for_each_efi_memory_desc(md) {
610-
if (!(md->attribute & EFI_MEMORY_RUNTIME) ||
611-
(md->type == EFI_BOOT_SERVICES_CODE) ||
612-
(md->type == EFI_BOOT_SERVICES_DATA))
613-
continue;
614-
tmp = krealloc(q, (count + 1) * desc_size, GFP_KERNEL);
615-
if (!tmp)
616-
goto out;
617-
q = tmp;
618-
619-
memcpy(q + count * desc_size, md, desc_size);
620-
count++;
621-
}
622-
623-
efi_runtime_map_setup(q, count, desc_size);
624-
return;
625-
626-
out:
627-
kfree(q);
628-
pr_err("Error saving runtime map, efi runtime on kexec non-functional!!\n");
629-
#endif
630-
}
631-
632596
static void *realloc_pages(void *old_memmap, int old_shift)
633597
{
634598
void *ret;
@@ -841,8 +805,6 @@ static void __init kexec_enter_virtual_mode(void)
841805
return;
842806
}
843807

844-
save_runtime_map();
845-
846808
BUG_ON(!efi.systab);
847809

848810
num_pages = ALIGN(efi.memmap.nr_map * efi.memmap.desc_size, PAGE_SIZE);
@@ -935,8 +897,6 @@ static void __init __efi_enter_virtual_mode(void)
935897
return;
936898
}
937899

938-
save_runtime_map();
939-
940900
BUG_ON(!efi.systab);
941901

942902
if (efi_setup_page_tables(pa, 1 << pg_shift)) {

drivers/firmware/efi/runtime-map.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
#include <asm/setup.h>
1616

17-
static void *efi_runtime_map;
18-
static int nr_efi_runtime_map;
19-
static u32 efi_memdesc_size;
20-
2117
struct efi_runtime_map_entry {
2218
efi_memory_desc_t md;
2319
struct kobject kobj; /* kobject for each entry */
@@ -106,7 +102,8 @@ static struct kobj_type __refdata map_ktype = {
106102
static struct kset *map_kset;
107103

108104
static struct efi_runtime_map_entry *
109-
add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
105+
add_sysfs_runtime_map_entry(struct kobject *kobj, int nr,
106+
efi_memory_desc_t *md)
110107
{
111108
int ret;
112109
struct efi_runtime_map_entry *entry;
@@ -124,8 +121,7 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
124121
return ERR_PTR(-ENOMEM);
125122
}
126123

127-
memcpy(&entry->md, efi_runtime_map + nr * efi_memdesc_size,
128-
sizeof(efi_memory_desc_t));
124+
memcpy(&entry->md, md, sizeof(efi_memory_desc_t));
129125

130126
kobject_init(&entry->kobj, &map_ktype);
131127
entry->kobj.kset = map_kset;
@@ -142,12 +138,12 @@ add_sysfs_runtime_map_entry(struct kobject *kobj, int nr)
142138

143139
int efi_get_runtime_map_size(void)
144140
{
145-
return nr_efi_runtime_map * efi_memdesc_size;
141+
return efi.memmap.nr_map * efi.memmap.desc_size;
146142
}
147143

148144
int efi_get_runtime_map_desc_size(void)
149145
{
150-
return efi_memdesc_size;
146+
return efi.memmap.desc_size;
151147
}
152148

153149
int efi_runtime_map_copy(void *buf, size_t bufsz)
@@ -157,38 +153,33 @@ int efi_runtime_map_copy(void *buf, size_t bufsz)
157153
if (sz > bufsz)
158154
sz = bufsz;
159155

160-
memcpy(buf, efi_runtime_map, sz);
156+
memcpy(buf, efi.memmap.map, sz);
161157
return 0;
162158
}
163159

164-
void efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size)
165-
{
166-
efi_runtime_map = map;
167-
nr_efi_runtime_map = nr_entries;
168-
efi_memdesc_size = desc_size;
169-
}
170-
171160
int __init efi_runtime_map_init(struct kobject *efi_kobj)
172161
{
173162
int i, j, ret = 0;
174163
struct efi_runtime_map_entry *entry;
164+
efi_memory_desc_t *md;
175165

176-
if (!efi_runtime_map)
166+
if (!efi_enabled(EFI_MEMMAP))
177167
return 0;
178168

179-
map_entries = kzalloc(nr_efi_runtime_map * sizeof(entry), GFP_KERNEL);
169+
map_entries = kzalloc(efi.memmap.nr_map * sizeof(entry), GFP_KERNEL);
180170
if (!map_entries) {
181171
ret = -ENOMEM;
182172
goto out;
183173
}
184174

185-
for (i = 0; i < nr_efi_runtime_map; i++) {
186-
entry = add_sysfs_runtime_map_entry(efi_kobj, i);
175+
i = 0;
176+
for_each_efi_memory_desc(md) {
177+
entry = add_sysfs_runtime_map_entry(efi_kobj, i, md);
187178
if (IS_ERR(entry)) {
188179
ret = PTR_ERR(entry);
189180
goto out_add_entry;
190181
}
191-
*(map_entries + i) = entry;
182+
*(map_entries + i++) = entry;
192183
}
193184

194185
return 0;

include/linux/efi.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,6 @@ extern int efi_capsule_update(efi_capsule_header_t *capsule,
13571357

13581358
#ifdef CONFIG_EFI_RUNTIME_MAP
13591359
int efi_runtime_map_init(struct kobject *);
1360-
void efi_runtime_map_setup(void *, int, u32);
13611360
int efi_get_runtime_map_size(void);
13621361
int efi_get_runtime_map_desc_size(void);
13631362
int efi_runtime_map_copy(void *buf, size_t bufsz);
@@ -1367,9 +1366,6 @@ static inline int efi_runtime_map_init(struct kobject *kobj)
13671366
return 0;
13681367
}
13691368

1370-
static inline void
1371-
efi_runtime_map_setup(void *map, int nr_entries, u32 desc_size) {}
1372-
13731369
static inline int efi_get_runtime_map_size(void)
13741370
{
13751371
return 0;

0 commit comments

Comments
 (0)