Re: [PATCH v3 4/4] hv: replace the CONFIG_PLATFORM_RAM_SIZE with get_e820_ram_size for vept


Xu, Anthony
 

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of chenli.wei
Sent: Monday, February 14, 2022 6:54 PM
To: acrn-dev@...; Wei, Chenli <chenli.wei@...>; Wang, Yu1 <yu1.wang@...>
Subject: Re: [acrn-dev] [PATCH v3 4/4] hv: replace the CONFIG_PLATFORM_RAM_SIZE with get_e820_ram_size for vept


On 2/15/2022 4:05 AM, Xu, Anthony wrote:
We use either vept or sept, but not mixed.

Anthony
I will check my interface and use the "sept" to named function.
What does 's' in "sept" mean?
The file name is vept.c, maybe we want to use vept.


Anthony





-----Original Message-----
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;
(get_e820_ram_size() * 8UL) / PAGE_SIZE
Done





+}
+
+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_vept_bitmap(void)
allocate_sept_bitmap(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)
allocate_buffer_for_sept_pages(void)
Done



{
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





Join {acrn-dev@lists.projectacrn.org to automatically receive all group messages.