From: Dan Williams <dan.j.williams@intel.com>
To: Dave Young <dyoung@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Taku Izumi <izumi.taku@jp.fujitsu.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
linux-efi <linux-efi@vger.kernel.org>, X86 ML <x86@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Kexec Mailing List <kexec@lists.infradead.org>
Subject: Re: [PATCH v4 3/4] efi: Fix efi_memmap_alloc() leaks
Date: Mon, 6 Jan 2020 20:24:32 -0800 [thread overview]
Message-ID: <CAPcyv4jbf2WR2ZU55564fORxKLf8tGH1XbYBpRfTvPouGWk2mg@mail.gmail.com> (raw)
In-Reply-To: <20200107035824.GA19080@dhcp-128-65.nay.redhat.com>
On Mon, Jan 6, 2020 at 7:58 PM Dave Young <dyoung@redhat.com> wrote:
>
> On 01/06/20 at 04:40pm, Dan Williams wrote:
> > With efi_fake_memmap() and efi_arch_mem_reserve() the efi table may be
> > updated and replaced multiple times. When that happens a previous
> > dynamically allocated efi memory map can be garbage collected. Use the
> > new EFI_MEMMAP_{SLAB,MEMBLOCK} flags to detect when a dynamically
> > allocated memory map is being replaced.
> >
> > Debug statements in efi_memmap_free() reveal:
> >
> > efi: __efi_memmap_free:37: phys: 0x23ffdd580 size: 2688 flags: 0x2
> > efi: __efi_memmap_free:37: phys: 0x9db00 size: 2640 flags: 0x2
> > efi: __efi_memmap_free:37: phys: 0x9e580 size: 2640 flags: 0x2
> >
> > ...a savings of 7968 bytes on a qemu boot with 2 entries specified to
> > efi_fake_mem=.
> >
> > Cc: Taku Izumi <izumi.taku@jp.fujitsu.com>
> > Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> > ---
> > drivers/firmware/efi/memmap.c | 24 ++++++++++++++++++++++++
> > 1 file changed, 24 insertions(+)
> >
> > diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c
> > index 04dfa56b994b..bffa320d2f9a 100644
> > --- a/drivers/firmware/efi/memmap.c
> > +++ b/drivers/firmware/efi/memmap.c
> > @@ -29,6 +29,28 @@ static phys_addr_t __init __efi_memmap_alloc_late(unsigned long size)
> > return PFN_PHYS(page_to_pfn(p));
> > }
> >
> > +static void __init __efi_memmap_free(u64 phys, unsigned long size, unsigned long flags)
> > +{
> > + if (flags & EFI_MEMMAP_MEMBLOCK) {
> > + if (slab_is_available())
> > + memblock_free_late(phys, size);
> > + else
> > + memblock_free(phys, size);
> > + } else if (flags & EFI_MEMMAP_SLAB) {
> > + struct page *p = pfn_to_page(PHYS_PFN(phys));
> > + unsigned int order = get_order(size);
> > +
> > + free_pages((unsigned long) page_address(p), order);
> > + }
> > +}
> > +
> > +static void __init efi_memmap_free(void)
> > +{
> > + __efi_memmap_free(efi.memmap.phys_map,
> > + efi.memmap.desc_size * efi.memmap.nr_map,
> > + efi.memmap.flags);
> > +}
> > +
> > /**
> > * efi_memmap_alloc - Allocate memory for the EFI memory map
> > * @num_entries: Number of entries in the allocated map.
> > @@ -100,6 +122,8 @@ static int __init __efi_memmap_init(struct efi_memory_map_data *data)
> > return -ENOMEM;
> > }
> >
> > + efi_memmap_free();
> > +
>
> This seems still not safe, see below function:
> arch/x86/platform/efi/efi.c:
> static void __init efi_clean_memmap(void)
> It use same memmap for both old and new, and filter out those invalid
> ranges in place, if the memory is freed then ..
In the efi_clean_memmap() case flags are 0, so efi_memmap_free() is a nop.
Would you feel better with an explicit?
WARN_ON(efi.memmap.phys_map == data->phys_map && (data->flags &
(EFI_MEMMAP_SLAB | EFI_MEMMAP_MEMBLOCK))
...not sure it's worth it.
>
> > map.phys_map = data->phys_map;
> > map.nr_map = data->size / data->desc_size;
> > map.map_end = map.map + data->size;
> >
next prev parent reply other threads:[~2020-01-07 4:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-07 0:40 [PATCH v4 0/4] efi: Fix handling of multiple efi_fake_mem= entries Dan Williams
2020-01-07 0:40 ` [PATCH v4 1/4] efi: Add a flags parameter to efi_memory_map Dan Williams
2020-01-07 0:40 ` [PATCH v4 2/4] efi: Add tracking for dynamically allocated memmaps Dan Williams
2020-01-07 0:40 ` [PATCH v4 3/4] efi: Fix efi_memmap_alloc() leaks Dan Williams
2020-01-07 3:58 ` Dave Young
2020-01-07 4:24 ` Dan Williams [this message]
2020-01-07 5:18 ` Dave Young
2020-01-07 17:49 ` Ard Biesheuvel
2020-01-07 0:40 ` [PATCH v4 4/4] efi: Fix handling of multiple efi_fake_mem= entries Dan Williams
2020-01-07 4:04 ` Dave Young
2020-01-07 4:16 ` Dan Williams
2020-01-07 5:19 ` Dave Young
2020-01-07 17:51 ` Ard Biesheuvel
2020-01-08 21:53 ` Dan Williams
2020-01-09 9:35 ` Ard Biesheuvel
2020-01-09 19:32 ` Dan Williams
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=CAPcyv4jbf2WR2ZU55564fORxKLf8tGH1XbYBpRfTvPouGWk2mg@mail.gmail.com \
--to=dan.j.williams@intel.com \
--cc=ard.biesheuvel@linaro.org \
--cc=dyoung@redhat.com \
--cc=izumi.taku@jp.fujitsu.com \
--cc=kexec@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=x86@kernel.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).