Skip to content

Commit 5f0b0ec

Browse files
Ard BiesheuvelIngo Molnar
authored andcommitted
efi: Permit multiple entries in persistent memreserve data structure
In preparation of updating efi_mem_reserve_persistent() to cause less fragmentation when dealing with many persistent reservations, update the struct definition and the code that handles it currently so it can describe an arbitrary number of reservations using a single linked list entry. The actual optimization will be implemented in a subsequent patch. Tested-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arend van Spriel <arend.vanspriel@broadcom.com> Cc: Bhupesh Sharma <bhsharma@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Eric Snowberg <eric.snowberg@oracle.com> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Joe Perches <joe@perches.com> Cc: Jon Hunter <jonathanh@nvidia.com> Cc: Julien Thierry <julien.thierry@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Nathan Chancellor <natechancellor@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com> Cc: Sedat Dilek <sedat.dilek@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: YiFei Zhu <zhuyifei1999@gmail.com> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20181129171230.18699-10-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3db5e0b commit 5f0b0ec

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

drivers/firmware/efi/efi.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,33 @@ int __init efi_apply_persistent_mem_reservations(void)
602602

603603
while (prsv) {
604604
struct linux_efi_memreserve *rsv;
605-
606-
/* reserve the entry itself */
607-
memblock_reserve(prsv, sizeof(*rsv));
608-
609-
rsv = early_memremap(prsv, sizeof(*rsv));
610-
if (rsv == NULL) {
605+
u8 *p;
606+
int i;
607+
608+
/*
609+
* Just map a full page: that is what we will get
610+
* anyway, and it permits us to map the entire entry
611+
* before knowing its size.
612+
*/
613+
p = early_memremap(ALIGN_DOWN(prsv, PAGE_SIZE),
614+
PAGE_SIZE);
615+
if (p == NULL) {
611616
pr_err("Could not map UEFI memreserve entry!\n");
612617
return -ENOMEM;
613618
}
614619

615-
if (rsv->size)
616-
memblock_reserve(rsv->base, rsv->size);
620+
rsv = (void *)(p + prsv % PAGE_SIZE);
621+
622+
/* reserve the entry itself */
623+
memblock_reserve(prsv, EFI_MEMRESERVE_SIZE(rsv->size));
624+
625+
for (i = 0; i < atomic_read(&rsv->count); i++) {
626+
memblock_reserve(rsv->entry[i].base,
627+
rsv->entry[i].size);
628+
}
617629

618630
prsv = rsv->next;
619-
early_memunmap(rsv, sizeof(*rsv));
631+
early_memunmap(p, PAGE_SIZE);
620632
}
621633
}
622634

@@ -985,6 +997,7 @@ static int __init efi_memreserve_map_root(void)
985997
int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
986998
{
987999
struct linux_efi_memreserve *rsv;
1000+
int rsvsize = EFI_MEMRESERVE_SIZE(1);
9881001
int rc;
9891002

9901003
if (efi_memreserve_root == (void *)ULONG_MAX)
@@ -996,12 +1009,14 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
9961009
return rc;
9971010
}
9981011

999-
rsv = kmalloc(sizeof(*rsv), GFP_ATOMIC);
1012+
rsv = kmalloc(rsvsize, GFP_ATOMIC);
10001013
if (!rsv)
10011014
return -ENOMEM;
10021015

1003-
rsv->base = addr;
1004-
rsv->size = size;
1016+
rsv->size = 1;
1017+
atomic_set(&rsv->count, 1);
1018+
rsv->entry[0].base = addr;
1019+
rsv->entry[0].size = size;
10051020

10061021
spin_lock(&efi_mem_reserve_persistent_lock);
10071022
rsv->next = efi_memreserve_root->next;

drivers/firmware/efi/libstub/arm-stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ void install_memreserve_table(efi_system_table_t *sys_table_arg)
8686
}
8787

8888
rsv->next = 0;
89-
rsv->base = 0;
9089
rsv->size = 0;
90+
atomic_set(&rsv->count, 0);
9191

9292
status = efi_call_early(install_configuration_table,
9393
&memreserve_table_guid,

include/linux/efi.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,9 +1712,16 @@ extern struct efi_runtime_work efi_rts_work;
17121712
extern struct workqueue_struct *efi_rts_wq;
17131713

17141714
struct linux_efi_memreserve {
1715-
phys_addr_t next;
1716-
phys_addr_t base;
1717-
phys_addr_t size;
1715+
int size; // allocated size of the array
1716+
atomic_t count; // number of entries used
1717+
phys_addr_t next; // pa of next struct instance
1718+
struct {
1719+
phys_addr_t base;
1720+
phys_addr_t size;
1721+
} entry[0];
17181722
};
17191723

1724+
#define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \
1725+
(count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
1726+
17201727
#endif /* _LINUX_EFI_H */

0 commit comments

Comments
 (0)