diff mbox series

[kvm-unit-tests,05/39] x86/access: Refactor so called "page table pool" logic

Message ID 20211125012857.508243-6-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series x86/access: nVMX: Big overhaul | expand

Commit Message

Sean Christopherson Nov. 25, 2021, 1:28 a.m. UTC
Track the index instead of raw physical address in the page table pool
to make the "enough room" check a bit less magical.

Opportunistically append "_pa" to pt_pool to clarify that it's the base
physical address of the pool.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 x86/access.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Paolo Bonzini Nov. 26, 2021, 6:03 p.m. UTC | #1
On 11/25/21 02:28, Sean Christopherson wrote:
>   static _Bool ac_test_enough_room(ac_pool_t *pool)
>   {
> -	return pool->pt_pool_current + 5 * PAGE_SIZE <= pool->pt_pool_size;
> +	/* '120' is completely arbitrary. */
> +	return (pool->pt_pool_current + 5) < 120;

Since the initialization was:

	pool->pt_pool_size = 120 * 1024 * 1024 - pool->pt_pool;

This should be 120 * 2^20 / 2^12 = 120 * 256 = 30720, which
is also arbitrary of course.

At this point I'm not sure there's a huge improvement, but I'll trust 
you and go on reviewing...

Paolo

>   }
>   
>   static void ac_test_reset_pt_pool(ac_pool_t *pool)
diff mbox series

Patch

diff --git a/x86/access.c b/x86/access.c
index 749b50c..47b3d00 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -159,8 +159,7 @@  static inline void *va(pt_element_t phys)
 }
 
 typedef struct {
-	pt_element_t pt_pool;
-	unsigned pt_pool_size;
+	pt_element_t pt_pool_pa;
 	unsigned pt_pool_current;
 } ac_pool_t;
 
@@ -276,8 +275,7 @@  static void ac_env_int(ac_pool_t *pool)
 	set_idt_entry(14, &page_fault, 0);
 	set_idt_entry(0x20, &kernel_entry, 3);
 
-	pool->pt_pool = AT_PAGING_STRUCTURES_PHYS;
-	pool->pt_pool_size = 120 * 1024 * 1024 - pool->pt_pool;
+	pool->pt_pool_pa = AT_PAGING_STRUCTURES_PHYS;
 	pool->pt_pool_current = 0;
 }
 
@@ -362,15 +360,18 @@  static int ac_test_bump(ac_test_t *at)
 
 static pt_element_t ac_test_alloc_pt(ac_pool_t *pool)
 {
-	pt_element_t ret = pool->pt_pool + pool->pt_pool_current;
-	pool->pt_pool_current += PAGE_SIZE;
-	memset(va(ret), 0, PAGE_SIZE);
-	return ret;
+	pt_element_t pt;
+
+	pt = pool->pt_pool_pa + (pool->pt_pool_current * PAGE_SIZE);
+	pool->pt_pool_current++;
+	memset(va(pt), 0, PAGE_SIZE);
+	return pt;
 }
 
 static _Bool ac_test_enough_room(ac_pool_t *pool)
 {
-	return pool->pt_pool_current + 5 * PAGE_SIZE <= pool->pt_pool_size;
+	/* '120' is completely arbitrary. */
+	return (pool->pt_pool_current + 5) < 120;
 }
 
 static void ac_test_reset_pt_pool(ac_pool_t *pool)