Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1712963
| From | Baoquan He <bhe@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v10 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor |
| Date | 2017-08-16 15:50 +0200 |
| Message-ID | <uf6RR-7G2-31@gated-at.bofh.it> (permalink) |
| References | <uep0t-5p7-1@gated-at.bofh.it> <uep0u-5p7-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
The existing map iteration helper for_each_efi_memory_desc_in_map can
only be used after OS initializes EFI subsystem to fill data of struct
efi_memory_map. Before that we also need iterate map descriptors which
are stored in several intermediate structures, like struct efi_boot_memmap
for arch independent usage and struct efi_info for x86 arch only.
Introduce efi_early_memdesc_ptr to get pointer to a map descriptor, and
replace several places of open code with it.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
v9->v10:
Use the 'EFI subsystem' instead of EFI since EFI usually means
firmware. Here we are talking about EFI subsystem inside kernel.
arch/x86/boot/compressed/eboot.c | 2 +-
drivers/firmware/efi/libstub/efi-stub-helper.c | 4 ++--
include/linux/efi.h | 21 +++++++++++++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index c3e869eaef0c..e007887a33b0 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -767,7 +767,7 @@ static efi_status_t setup_e820(struct boot_params *params,
m |= (u64)efi->efi_memmap_hi << 32;
#endif
- d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
+ d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
switch (d->type) {
case EFI_RESERVED_TYPE:
case EFI_RUNTIME_SERVICES_CODE:
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index b0184360efc6..50a9cab5a834 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -205,7 +205,7 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
unsigned long m = (unsigned long)map;
u64 start, end;
- desc = (efi_memory_desc_t *)(m + (i * desc_size));
+ desc = efi_early_memdesc_ptr(m, desc_size, i);
if (desc->type != EFI_CONVENTIONAL_MEMORY)
continue;
@@ -298,7 +298,7 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
unsigned long m = (unsigned long)map;
u64 start, end;
- desc = (efi_memory_desc_t *)(m + (i * desc_size));
+ desc = efi_early_memdesc_ptr(m, desc_size, i);
if (desc->type != EFI_CONVENTIONAL_MEMORY)
continue;
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 8269bcb8ccf7..ec296bc96bc5 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -1020,6 +1020,27 @@ extern int efi_memattr_init(void);
extern int efi_memattr_apply_permissions(struct mm_struct *mm,
efi_memattr_perm_setter fn);
+/*
+ * efi_early_memdesc_ptr - get the n-th efi memmap descriptor
+ * @map: the start of efi memmap
+ * @desc_size: the size of space for each efi memmap descriptor
+ * @n: the index of efi memmap descriptor
+ *
+ * EFI boot service provides function GetMemoryMap() to get a copy of the
+ * current memory map which is an array of memory descriptors, each of
+ * which describes a contiguous block of memory. And also get the size of
+ * map, and the size of each descriptor, etc. Note that per section 6.2 of
+ * UEFI Spec 2.6 Errata A, the returned size of each descriptor might not
+ * be equal to sizeof(efi_memory_memdesc_t) since efi_memory_memdesc_t may
+ * be extended in the future in response to hardware innovation. Thus OS
+ * MUST use the returned size of descriptor to find the start of each
+ * efi_memory_memdesc_t in the memory map array. This should only be used
+ * during bootup since for_each_efi_memory_desc_xxx is suggested after OS
+ * initializes EFI subsystem to fill data of struct efi_memory_map.
+ */
+#define efi_early_memdesc_ptr(map, desc_size, n) \
+ (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
+
/* Iterate through an efi_memory_map */
#define for_each_efi_memory_desc_in_map(m, md) \
for ((md) = (m)->map; \
--
2.5.5
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v9 0/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-14 17:00 +0200
[PATCH v9 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor Baoquan He <bhe@redhat.com> - 2017-08-14 17:00 +0200
Re: [PATCH v9 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor Matt Fleming <matt@codeblueprint.co.uk> - 2017-08-16 13:40 +0200
Re: [PATCH v9 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor Baoquan He <bhe@redhat.com> - 2017-08-16 15:20 +0200
[PATCH v10 1/2] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor Baoquan He <bhe@redhat.com> - 2017-08-16 15:50 +0200
[tip:x86/boot] efi: Introduce efi_early_memdesc_ptr to get pointer to memmap descriptor tip-bot for Baoquan He <tipbot@zytor.com> - 2017-08-17 12:30 +0200
[PATCH v9 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-14 17:00 +0200
[tip:x86/boot] x86/boot/KASLR: Prefer mirrored memory regions for the kernel physical address tip-bot for Baoquan He <tipbot@zytor.com> - 2017-08-17 12:30 +0200
Re: [PATCH v9 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-17 15:10 +0200
Re: [PATCH v9 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-08-18 17:20 +0200
Re: [PATCH v9 2/2] x86/boot/KASLR: Restrict kernel to be randomized in mirror regions Baoquan He <bhe@redhat.com> - 2017-08-19 03:30 +0200
csiph-web