Re: [PATCH v3 4/4] hv: replace the CONFIG_PLATFORM_RAM_SIZE with get_e820_ram_size for vept
Xu, Anthony
We use either vept or sept, but not mixed.
Anthony
toggle quoted message
Show quoted text
Anthony
-----Original Message-----(get_e820_ram_size() * 8UL) / PAGE_SIZE
From: Wei, Chenli <chenli.wei@...>
Sent: Friday, February 11, 2022 8:25 PM
To: Wang, Yu1 <yu1.wang@...>; Xu, Anthony <anthony.xu@...>; acrn-dev@...
Cc: Wei, Chenli <chenli.wei@...>; Chenli Wei <chenli.wei@...>
Subject: [PATCH v3 4/4] hv: replace the CONFIG_PLATFORM_RAM_SIZE with get_e820_ram_size for vept
Now the vept table was alloc dynamically, but the table size of vept was
calcuated by the CONFIG_PLATFORM_RAM_SIZE which was predefined by config
tool.
It's not complete change and can't support single binary for different
boards/platforms.
So this patch will replace the CONFIG_PLATFORM_RAM_SIZE and get the
top ram size from hv_E820 interface for vept.
v2-->v3:
1.use ram size to replace the top address
v1-->v2:
1.update commit msg
Tracked-On: #6690
Signed-off-by: Chenli Wei <chenli.wei@...>
---
hypervisor/arch/x86/guest/vept.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/hypervisor/arch/x86/guest/vept.c b/hypervisor/arch/x86/guest/vept.c
index ac5f43177..e5792593d 100644
--- a/hypervisor/arch/x86/guest/vept.c
+++ b/hypervisor/arch/x86/guest/vept.c
@@ -26,15 +26,27 @@ static spinlock_t nept_desc_bucket_lock;
* and sharing of memory between L2 VMs.
*
* Page table entry need 8 bytes to represent every 4K page frame.
- * Total number of bytes = (CONFIG_PLATFORM_RAM_SIZE/4096) * 8
+ * Total number of bytes = (get_e820_ram_size() / 4096) * 8
* Number of pages needed = Total number of bytes needed/4096
*/
-#define TOTAL_SEPT_4K_PAGES_SIZE ((CONFIG_PLATFORM_RAM_SIZE * 8UL) / 4096UL)
-#define TOTAL_SEPT_4K_PAGES_NUM (TOTAL_SEPT_4K_PAGES_SIZE / PAGE_SIZE)
+static uint64_t get_total_sept_4k_page_size(void)
+{
+ return (get_e820_ram_size() * 8UL) / 4096UL;
+}allocate_vept_bitmap(void)
+
+static uint64_t get_total_sept_4k_page_num(void)
+{
+ return get_total_sept_4k_page_size() / PAGE_SIZE;
+}
static struct page_pool sept_page_pool;
static struct page *sept_pages;
-static uint64_t sept_page_bitmap[TOTAL_SEPT_4K_PAGES_NUM / 64U];
+static uint64_t *sept_page_bitmap;
+
+static void reserve_vept_bitmap(void)
+{allocate_buffer_for_sept_pages(void)
+ sept_page_bitmap = e820_alloc_memory((get_total_4k_page_num() / 64U), ~0UL);
+}
/*
* @brief Reserve space for SEPT 4K pages from platform E820 table
@@ -44,9 +56,12 @@ void reserve_buffer_for_sept_pages(void)
{
uint64_t page_base;
- page_base = e820_alloc_memory(TOTAL_SEPT_4K_PAGES_SIZE, ~0UL);
- set_paging_supervisor(page_base, TOTAL_SEPT_4K_PAGES_SIZE);
+ page_base = e820_alloc_memory(get_total_sept_4k_page_size(), ~0UL);
+
+ set_paging_supervisor(page_base, get_total_sept_4k_page_size());
+
sept_pages = (struct page *)page_base;
+ reserve_vept_bitmap();
}
static bool is_present_ept_entry(uint64_t ept_entry)
@@ -535,7 +550,7 @@ int32_t invept_vmexit_handler(struct acrn_vcpu *vcpu)
void init_vept(void)
{
sept_page_pool.start_page = sept_pages;
- sept_page_pool.bitmap_size = TOTAL_SEPT_4K_PAGES_NUM / 64U;
+ sept_page_pool.bitmap_size = get_total_sept_4k_page_num() / 64U;
sept_page_pool.bitmap = sept_page_bitmap;
sept_page_pool.dummy_page = NULL;
spinlock_init(&sept_page_pool.lock);
--
2.17.1