From: Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
To: Jeffrey Hugo <jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Cc: linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org
Subject: Re: [PATCH V2 1/4] efi/libstub: Allocate headspace in efi_get_memory_map()
Date: Wed, 27 Jul 2016 15:57:50 +0100 [thread overview]
Message-ID: <20160727145750.GH31759@codeblueprint.co.uk> (raw)
In-Reply-To: <1469132894-17103-2-git-send-email-jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
On Thu, 21 Jul, at 02:28:11PM, Jeffrey Hugo wrote:
> efi_get_memory_map() allocates a buffer to store the memory map that it
> retrieves. This buffer may need to be reused by the client after
> ExitBootServices() is called, at which point allocations are not longer
> permitted. To support this usecase, provide the allocated buffer size back
> to the client, and allocate some additional headroom to account for any
> reasonable growth in the map that is likely to happen between the call to
> efi_get_memory_map() and the client reusing the buffer.
>
> Change-Id: Ib0686811581c59eee2eb60b4b62e1628e649d6f0
Please don't include these tags in your patch submission - they don't
mean anything in the upstream kernel and there's always the chance
I'll forget to strip it before applying your patch.
> Signed-off-by: Jeffrey Hugo <jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
> ---
> arch/x86/boot/compressed/eboot.c | 4 +--
> drivers/firmware/efi/libstub/efi-stub-helper.c | 36 +++++++++++++++++++-------
> drivers/firmware/efi/libstub/fdt.c | 8 +++---
> drivers/firmware/efi/libstub/random.c | 3 ++-
> include/linux/efi.h | 3 ++-
> 5 files changed, 37 insertions(+), 17 deletions(-)
[...]
> index 3bd127f9..3071269 100644
> --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> @@ -41,6 +41,8 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE;
> #define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
> #endif
>
> +#define EFI_MMAP_NR_SLACK_SLOTS 8
> +
> struct file_info {
> efi_file_handle_t *handle;
> u64 size;
> @@ -68,20 +70,24 @@ efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
> unsigned long *map_size,
> unsigned long *desc_size,
> u32 *desc_ver,
> - unsigned long *key_ptr)
> + unsigned long *key_ptr,
> + unsigned long *buff_size)
> {
> efi_memory_desc_t *m = NULL;
> efi_status_t status;
> unsigned long key;
> u32 desc_version;
>
> - *map_size = sizeof(*m) * 32;
> + *desc_size = sizeof(*m);
> + *map_size = *desc_size * 32;
> + *buff_size = *map_size;
> again:
> /*
> * Add an additional efi_memory_desc_t because we're doing an
> * allocation which may be in a new descriptor region.
> */
> - *map_size += sizeof(*m);
> + *map_size += *desc_size;
> + *buff_size = *map_size;
> status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
> *map_size, (void **)&m);
> if (status != EFI_SUCCESS)
Isn't this chunk of code unnecessary now? If we think 8 entries is
enough headroom for all scenarios then there's no need to allocate 9.
> @@ -91,8 +97,17 @@ again:
> key = 0;
> status = efi_call_early(get_memory_map, map_size, m,
> &key, desc_size, &desc_version);
> - if (status == EFI_BUFFER_TOO_SMALL) {
> + if (status == EFI_BUFFER_TOO_SMALL ||
> + (*buff_size - *map_size) / *desc_size < 8) {
Please pull this expression into a static inline wrapper, e.g.
static inline bool mmap_has_headroom(unsigned long buff_size,
unsigned long map_size,
unsigned long desc_size)
{
unsigned long slack = buff_size - map_size;
return slack / desc_size >= EFI_MMAP_NR_SLACK_SLOTS;
}
...
if (status == EFI_BUFFER_TOO_SMALL ||
!mmap_has_headroom(*buff_size, *map_size, *desc_size)) {
next prev parent reply other threads:[~2016-07-27 14:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-21 20:28 [PATCH V2 0/4] Handle EFI_INVALID_PARAMETER from ExitBootServices Jeffrey Hugo
[not found] ` <1469132894-17103-1-git-send-email-jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-07-21 20:28 ` [PATCH V2 1/4] efi/libstub: Allocate headspace in efi_get_memory_map() Jeffrey Hugo
[not found] ` <1469132894-17103-2-git-send-email-jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-07-27 14:57 ` Matt Fleming [this message]
[not found] ` <20160727145750.GH31759-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-07-27 16:22 ` Jeffrey Hugo
2016-07-21 20:28 ` [PATCH V2 2/4] efi/libstub: Introduce ExitBootServices helper Jeffrey Hugo
[not found] ` <1469132894-17103-3-git-send-email-jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-07-27 18:03 ` Matt Fleming
[not found] ` <20160727180318.GI31759-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-07-27 19:21 ` Jeffrey Hugo
[not found] ` <32feffc6-a789-fcce-0e53-cc473247bb76-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-08-01 12:03 ` Matt Fleming
2016-07-21 20:28 ` [PATCH V2 3/4] efi/libstub: Use efi_exit_boot_services() in FDT Jeffrey Hugo
2016-07-21 20:28 ` [PATCH V2 4/4] x86/efi: Use efi_exit_boot_services() Jeffrey Hugo
[not found] ` <1469132894-17103-5-git-send-email-jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-07-27 18:08 ` Matt Fleming
[not found] ` <20160727180839.GJ31759-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-07-27 18:51 ` Jeffrey Hugo
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=20160727145750.GH31759@codeblueprint.co.uk \
--to=matt-mf/unelci9gs6ibeejttw/xrex20p6io@public.gmane.org \
--cc=ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=jhugo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=timur-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).