Skip to content

Commit 31ce8cc

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 816e761 commit 31ce8cc

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
@@ -592,42 +592,6 @@ static void __init get_systab_virt_addr(efi_memory_desc_t *md)
592592
}
593593
}
594594

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

843-
save_runtime_map();
844-
845807
BUG_ON(!efi.systab);
846808

847809
num_pages = ALIGN(efi.memmap.nr_map * efi.memmap.desc_size, PAGE_SIZE);
@@ -934,8 +896,6 @@ static void __init __efi_enter_virtual_mode(void)
934896
return;
935897
}
936898

937-
save_runtime_map();
938-
939899
BUG_ON(!efi.systab);
940900

941901
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)