From: Joey Gouly <joey.gouly@arm.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: <linux-efi@vger.kernel.org>, <loongarch@lists.linux.dev>,
<linux@armlinux.org.uk>, Arnd Bergmann <arnd@arndb.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Huacai Chen <chenhuacai@loongson.cn>,
Xi Ruoyao <xry111@xry111.site>, <nd@arm.com>
Subject: Re: [PATCH 09/12] efi: libstub: install boot-time memory map as config table
Date: Tue, 20 Sep 2022 11:40:45 +0100 [thread overview]
Message-ID: <20220920104045.GA18686@e124191.cambridge.arm.com> (raw)
In-Reply-To: <20220918213544.2176249-10-ardb@kernel.org>
Hi Ard,
On Sun, Sep 18, 2022 at 11:35:41PM +0200, Ard Biesheuvel wrote:
> Expose the EFI boot time memory map to the kernel via a configuration
> table. This is arch agnostic and enables future changes that remove the
> dependency on DT on architectures that don't otherwise rely on it.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> drivers/firmware/efi/libstub/arm64-stub.c | 2 +-
> drivers/firmware/efi/libstub/efi-stub-helper.c | 2 +-
> drivers/firmware/efi/libstub/efistub.h | 3 ++-
> drivers/firmware/efi/libstub/mem.c | 26 ++++++++++++++++++--
> drivers/firmware/efi/libstub/randomalloc.c | 2 +-
> drivers/firmware/efi/libstub/relocate.c | 2 +-
> include/linux/efi.h | 1 +
> 7 files changed, 31 insertions(+), 7 deletions(-)
>
[..]
> diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c
> index 40721573e494..ed4c145afe11 100644
> --- a/drivers/firmware/efi/libstub/mem.c
> +++ b/drivers/firmware/efi/libstub/mem.c
> @@ -9,14 +9,20 @@
> * efi_get_memory_map() - get memory map
> * @map: pointer to memory map pointer to which to assign the
> * newly allocated memory map
> + * @install_cfg_tbl: whether or not to install the boot memory map as a
> + * configuration table
> *
> * Retrieve the UEFI memory map. The allocated memory leaves room for
> * up to EFI_MMAP_NR_SLACK_SLOTS additional memory map entries.
> *
> * Return: status code
> */
> -efi_status_t efi_get_memory_map(struct efi_boot_memmap **map)
> +efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
> + bool install_cfg_tbl)
> {
> + int memtype = install_cfg_tbl ? EFI_ACPI_RECLAIM_MEMORY
> + : EFI_LOADER_DATA;
> + efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID;
> struct efi_boot_memmap *m, tmp;
> efi_status_t status;
> unsigned long size;
> @@ -28,11 +34,23 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map)
> return EFI_LOAD_ERROR;
>
> size = tmp.map_size + tmp.desc_size * EFI_MMAP_NR_SLACK_SLOTS;
> - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, sizeof(*m) + size,
> + status = efi_bs_call(allocate_pool, memtype, sizeof(*m) + size,
> (void **)&m);
> if (status != EFI_SUCCESS)
> return status;
>
> + if (install_cfg_tbl) {
> + /*
> + * Installing a configuration table might allocate memory, and
> + * this may modify the memory map. This means we should install
> + * the configuration table first, and re-install or delete it
> + * as needed.
> + */
> + status = efi_bs_call(install_configuration_table, &tbl_guid, m);
> + if (status != EFI_SUCCESS)
> + goto free_map;
> + }
> +
> m->buff_size = m->map_size = size;
> status = efi_bs_call(get_memory_map, &m->map_size, m->map, &m->map_key,
> &m->desc_size, &m->desc_ver);
> @@ -40,6 +58,10 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map)
> if (status == EFI_SUCCESS) {
> *map = m;
> } else {
> + if (install_cfg_tbl)
> + efi_bs_call(install_configuration_table, &tbl_guid,
> + NULL);
> +free_map:
> efi_bs_call(free_pool, m);
> }
You have another commit about removing goto kludges, so maybe write this like the following,
rather than a goto into an 'else' statement?
diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c
index feef8d4be113..2f22ef7c5232 100644
--- a/drivers/firmware/efi/libstub/mem.c
+++ b/drivers/firmware/efi/libstub/mem.c
@@ -64,10 +64,12 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap *map)
*map->key_ptr = key;
if (map->desc_ver)
*map->desc_ver = desc_version;
- } else {
- efi_bs_call(free_pool, m);
}
+free_map:
+ if (status != EFI_SUCCESS)
+ efi_bs_call(free_pool, m);
+
fail:
*map->map = m;
return status;
(This is a diff against next-20220920, not your branch, but you get the idea)
Thanks,
Joey
next prev parent reply other threads:[~2022-09-20 10:41 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-18 21:35 [PATCH 00/12] efi: disentangle the generic EFI stub from FDT Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 01/12] efi: libstub: drop pointless get_memory_map() call Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 02/12] efi/arm: libstub: move ARM specific code out of generic routines Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 03/12] efi: libstub: fix up the last remaining open coded boot service call Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 04/12] efi: libstub: fix type confusion for load_options_size Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 05/12] efi: libstub: avoid efi_get_memory_map() for allocating the virt map Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 06/12] efi: libstub: simplify efi_get_memory_map() and struct efi_boot_memmap Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 07/12] efi: libstub: unify initrd loading between architectures Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 08/12] efi: libstub: remove DT dependency from generic stub Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 09/12] efi: libstub: install boot-time memory map as config table Ard Biesheuvel
2022-09-20 10:40 ` Joey Gouly [this message]
2022-09-20 11:37 ` Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 10/12] efi: libstub: remove pointless goto kludge Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 11/12] efi/loongarch: libstub: remove dependency on flattened DT Ard Biesheuvel
2022-09-19 1:58 ` Huacai Chen
2022-09-19 5:15 ` Ard Biesheuvel
2022-09-19 6:06 ` Huacai Chen
2022-09-19 6:22 ` Ard Biesheuvel
2022-09-19 6:33 ` Ard Biesheuvel
2022-09-19 10:33 ` Huacai Chen
2022-09-19 10:37 ` Ard Biesheuvel
2022-09-19 10:47 ` Huacai Chen
2022-09-19 10:49 ` Ard Biesheuvel
2022-09-19 11:15 ` Huacai Chen
2022-09-19 11:21 ` Ard Biesheuvel
2022-09-19 11:57 ` Huacai Chen
2022-09-19 12:10 ` Ard Biesheuvel
2022-09-19 12:14 ` Huacai Chen
2022-09-19 12:27 ` Ard Biesheuvel
2022-09-19 14:25 ` Huacai Chen
2022-09-19 14:32 ` Ard Biesheuvel
2022-09-19 14:43 ` Huacai Chen
2022-09-19 14:44 ` Ard Biesheuvel
2022-09-19 15:08 ` Huacai Chen
2022-09-19 15:50 ` Ard Biesheuvel
2022-09-20 1:44 ` Huacai Chen
2022-09-20 8:04 ` Ard Biesheuvel
2022-09-20 13:12 ` Huacai Chen
2022-09-20 14:53 ` Ard Biesheuvel
2022-09-18 21:35 ` [PATCH 12/12] efi: loongarch: add support for DT hardware descriptions Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220920104045.GA18686@e124191.cambridge.arm.com \
--to=joey.gouly@arm.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=chenhuacai@loongson.cn \
--cc=ilias.apalodimas@linaro.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=loongarch@lists.linux.dev \
--cc=nd@arm.com \
--cc=xry111@xry111.site \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox