diff mbox series

[RFC,1/7] efi/libstub: Ask efi_random_alloc() to skip unusable memory

Message ID 20240718085759.13247-2-piliu@redhat.com
State Superseded
Headers show
Series UEFI emulator for kexec | expand

Commit Message

Pingfan Liu July 18, 2024, 8:57 a.m. UTC
efi_random_alloc() demands EFI_ALLOCATE_ADDRESS when allocate_pages(),
but the current implement can not ensure the selected target locates
inside free area, that is to exclude EFI_BOOT_SERVICES_*,
EFI_RUNTIME_SERVICES_* etc.

Fix the issue by checking md->type.

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Jan Hendrik Farr <kernel@jfarr.cc>
Cc: Philipp Rudo <prudo@redhat.com>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
To: linux-arm-kernel@lists.infradead.org
To: kexec@lists.infradead.org
To: linux-efi@vger.kernel.org
---
 drivers/firmware/efi/libstub/randomalloc.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jarkko Sakkinen July 18, 2024, 5:19 p.m. UTC | #1
On Thu, 2024-07-18 at 16:57 +0800, Pingfan Liu wrote:
> efi_random_alloc() demands EFI_ALLOCATE_ADDRESS when allocate_pages(),
> but the current implement can not ensure the selected target locates
> inside free area, that is to exclude EFI_BOOT_SERVICES_*,
> EFI_RUNTIME_SERVICES_* etc.
> 
> Fix the issue by checking md->type.
> 
> Signed-off-by: Pingfan Liu <piliu@redhat.com>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Jan Hendrik Farr <kernel@jfarr.cc>
> Cc: Philipp Rudo <prudo@redhat.com>
> Cc: Lennart Poettering <mzxreary@0pointer.de>
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Dave Young <dyoung@redhat.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> To: linux-arm-kernel@lists.infradead.org
> To: kexec@lists.infradead.org
> To: linux-efi@vger.kernel.org

I'm on holiday up until end of next week so not going to go this trough
right now but I have minor complain ;-)

Please use:

       --[no-]cc-cover
           If this is set, emails found in Cc: headers in the first patch of the series (typically
           the cover letter) are added to the cc list for each email set. Default is the value of
           sendemail.ccCover configuration value; if that is unspecified, default to --no-cc-cover.
       [from "man git-send-email"]

This will make the commits less bloated and makes sure that everyone you
might want to CC will get always the same set of patches.

I'd also recommend to pick only one list for to-field because there can
be only one maintainer that in the end would take these patches. Change
rest to cc's. Now the process of managing these patches is ambiguous by
definition.

BR, Jarkko
Pingfan Liu July 19, 2024, 1:42 p.m. UTC | #2
On Fri, Jul 19, 2024 at 1:20 AM Jarkko Sakkinen <jarkko@kernel.org> wrote:
>
> On Thu, 2024-07-18 at 16:57 +0800, Pingfan Liu wrote:
> > efi_random_alloc() demands EFI_ALLOCATE_ADDRESS when allocate_pages(),
> > but the current implement can not ensure the selected target locates
> > inside free area, that is to exclude EFI_BOOT_SERVICES_*,
> > EFI_RUNTIME_SERVICES_* etc.
> >
> > Fix the issue by checking md->type.
> >
> > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> > Cc: Ard Biesheuvel <ardb@kernel.org>
> > Cc: Jan Hendrik Farr <kernel@jfarr.cc>
> > Cc: Philipp Rudo <prudo@redhat.com>
> > Cc: Lennart Poettering <mzxreary@0pointer.de>
> > Cc: Jarkko Sakkinen <jarkko@kernel.org>
> > Cc: Baoquan He <bhe@redhat.com>
> > Cc: Dave Young <dyoung@redhat.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Will Deacon <will@kernel.org>
> > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > To: linux-arm-kernel@lists.infradead.org
> > To: kexec@lists.infradead.org
> > To: linux-efi@vger.kernel.org
>
> I'm on holiday up until end of next week so not going to go this trough
> right now but I have minor complain ;-)
>
> Please use:
>
>        --[no-]cc-cover
>            If this is set, emails found in Cc: headers in the first patch of the series (typically
>            the cover letter) are added to the cc list for each email set. Default is the value of
>            sendemail.ccCover configuration value; if that is unspecified, default to --no-cc-cover.
>        [from "man git-send-email"]
>
> This will make the commits less bloated and makes sure that everyone you
> might want to CC will get always the same set of patches.
>
> I'd also recommend to pick only one list for to-field because there can
> be only one maintainer that in the end would take these patches. Change
> rest to cc's. Now the process of managing these patches is ambiguous by
> definition.
>

Sorry for the unnecessary noise, I will follow your suggestion in the
next round.

Thanks,

Pingfan

> BR, Jarkko
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
>
diff mbox series

Patch

diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
index c41e7b2091cdd..7304e767688f2 100644
--- a/drivers/firmware/efi/libstub/randomalloc.c
+++ b/drivers/firmware/efi/libstub/randomalloc.c
@@ -79,6 +79,8 @@  efi_status_t efi_random_alloc(unsigned long size,
 		efi_memory_desc_t *md = (void *)map->map + map_offset;
 		unsigned long slots;
 
+		if (!(md->type & (EFI_CONVENTIONAL_MEMORY || EFI_PERSISTENT_MEMORY)))
+			continue;
 		slots = get_entry_num_slots(md, size, ilog2(align), alloc_min,
 					    alloc_max);
 		MD_NUM_SLOTS(md) = slots;
@@ -111,6 +113,9 @@  efi_status_t efi_random_alloc(unsigned long size,
 		efi_physical_addr_t target;
 		unsigned long pages;
 
+		if (!(md->type & (EFI_CONVENTIONAL_MEMORY || EFI_PERSISTENT_MEMORY)))
+			continue;
+
 		if (total_mirrored_slots > 0 &&
 		    !(md->attribute & EFI_MEMORY_MORE_RELIABLE))
 			continue;