Re: [PATCH v2 2/4] hv: set default MAX_EFI_MMAP_ENTRIES to 350

Eddie Dong

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On
Behalf Of Victor Sun
Sent: Monday, November 1, 2021 11:45 AM
To: acrn-dev@...
Subject: [acrn-dev] [PATCH v2 2/4] hv: set default MAX_EFI_MMAP_ENTRIES
to 350

In previous implementation we leave MAX_EFI_MMAP_ENTRIES in config tool
and let end user to configure it. However it is hard for end user to understand
how to configure it, also it is hard for board_inspector to get this value
automatically because this info is only meaningful during the kernel boot stage
and there is no such info available after boot in Linux toolset.

This patch hardcode the value to 350, and ASSERT if the board need more efi
mmap entries to run ACRN. User could modify the MAX_EFI_MMAP_ENTRIES
macro according to the hint of ASSERT message.

The More size of hv_memdesc[] only consume very little memory, the
overhead is (size * sizeof(struct efi_memory_desc)), i.e. (size * 40) in bytes.

Signed-off-by: Victor Sun <victor.sun@...>
hypervisor/common/efi_mmap.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/hypervisor/common/efi_mmap.c
b/hypervisor/common/efi_mmap.c index 015b8bdc2..40e0bc298 100644
--- a/hypervisor/common/efi_mmap.c
+++ b/hypervisor/common/efi_mmap.c
@@ -10,8 +10,10 @@
#include <efi_mmap.h>
#include <logmsg.h>

static uint16_t hv_memdesc_nr;
-static struct efi_memory_desc
+static struct efi_memory_desc hv_memdesc[MAX_EFI_MMAP_ENTRIES];

static void sort_efi_mmap_entries(void) { @@ -35,13 +37,12 @@ void
init_efi_mmap_entries(struct efi_info *uefi_info)

Should we add @pre for this?
In many cases, we use ASSERT for debug time, @pre to let FUSA make sure it is aways true.,
Acked-by: Eddie Dong <eddie.dong@...>

void *efi_memmap = (void *)((uint64_t)uefi_info->memmap |
((uint64_t)uefi_info->memmap_hi << 32U));
struct efi_memory_desc *efi_memdesc = (struct efi_memory_desc
uint32_t entry = 0U;
+ uint32_t efi_memdesc_nr = uefi_info->memmap_size /

- while ((void *)efi_memdesc < (efi_memmap + uefi_info->memmap_size))
- pr_err("Too many efi memmap entries, entries up %d are
- break;
- }
+ ASSERT(efi_memdesc_nr <= MAX_EFI_MMAP_ENTRIES, "Total %d efi
memmap entries found, but we only support %d.\n",
+ efi_memdesc_nr, MAX_EFI_MMAP_ENTRIES);

+ while ((void *)efi_memdesc < (efi_memmap + uefi_info->memmap_size))
hv_memdesc[entry] = *efi_memdesc;

/* Per UEFI spec, EFI_MEMORY_DESCRIPTOR array element
returned in MemoryMap.

Join to automatically receive all group messages.