kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups
@ 2021-11-11  0:02 David Matlack
  2021-11-11  0:02 ` [PATCH v2 01/12] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array David Matlack
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:02 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

Fix hugepage bugs in the KVM selftests that specifically affect dirty
logging and demand paging tests.  Found while attempting to verify KVM
changes/fixes related to hugepages and dirty logging (patches incoming in
a separate series).

Clean up the perf_test_args util on top of the hugepage fixes to clarify
what "page size" means, and to improve confidence in the code doing what
it thinks it's doing.  In a few cases, users of perf_test_args were
duplicating (approximating?) calculations made by perf_test_args, and it
wasn't obvious that both pieces of code were guaranteed to end up with the
same result.

v2:
- Add separate align up/down helpers and use the throughout the series
  rather than openly coding the bitwise math [Ben, Paolo]
- Do no pad HugeTLB mmaps [Yanan]
- Drop "[PATCH 04/15] KVM: selftests: Force stronger HVA alignment (1gb)
  for hugepages" since HugeTLB does not require manual HVA alignment
  [David]
- Drop "[PATCH 15/15] KVM: selftests: Get rid of gorilla math in memslots
  modification test" since the gorilla math no longer exists [David]
- Drop "[PATCH 14/15] KVM: selftests: Track size of per-VM memslot in
  perf_test_args" since it was just a prep patch for [PATCH 15/15]
  [David]
- Update the series to kvm/next [David]

v1: https://lore.kernel.org/kvm/20210210230625.550939-1-seanjc@google.com/.

Sean Christopherson (12):
  KVM: selftests: Explicitly state indicies for vm_guest_mode_params
    array
  KVM: selftests: Expose align() helpers to tests
  KVM: selftests: Assert mmap HVA is aligned when using HugeTLB
  KVM: selftests: Require GPA to be aligned when backed by hugepages
  KVM: selftests: Use shorthand local var to access struct
    perf_tests_args
  KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args
  KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging
    test
  KVM: selftests: Move per-VM GPA into perf_test_args
  KVM: selftests: Remove perf_test_args.host_page_size
  KVM: selftests: Create VM with adjusted number of guest pages for perf
    tests
  KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation
  KVM: selftests: Sync perf_test_args to guest during VM creation

 .../selftests/kvm/access_tracking_perf_test.c |   8 +-
 .../selftests/kvm/demand_paging_test.c        |  31 +----
 .../selftests/kvm/dirty_log_perf_test.c       |  10 +-
 tools/testing/selftests/kvm/dirty_log_test.c  |   6 +-
 .../selftests/kvm/include/perf_test_util.h    |  18 +--
 .../testing/selftests/kvm/include/test_util.h |  26 ++++
 .../selftests/kvm/kvm_page_table_test.c       |   2 +-
 tools/testing/selftests/kvm/lib/elf.c         |   3 +-
 tools/testing/selftests/kvm/lib/kvm_util.c    |  44 +++---
 .../selftests/kvm/lib/perf_test_util.c        | 126 ++++++++++--------
 tools/testing/selftests/kvm/lib/test_util.c   |   5 +
 .../kvm/memslot_modification_stress_test.c    |  13 +-
 12 files changed, 153 insertions(+), 139 deletions(-)

-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 01/12] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
@ 2021-11-11  0:02 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests David Matlack
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:02 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Explicitly state the indices when populating vm_guest_mode_params to
make it marginally easier to visualize what's going on.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
[Added indices for new guest modes.]
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 041004c0fda7..b624c24290dd 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -187,15 +187,15 @@ const char *vm_guest_mode_string(uint32_t i)
 }
 
 const struct vm_guest_mode_params vm_guest_mode_params[] = {
-	{ 52, 48,  0x1000, 12 },
-	{ 52, 48, 0x10000, 16 },
-	{ 48, 48,  0x1000, 12 },
-	{ 48, 48, 0x10000, 16 },
-	{ 40, 48,  0x1000, 12 },
-	{ 40, 48, 0x10000, 16 },
-	{  0,  0,  0x1000, 12 },
-	{ 47, 64,  0x1000, 12 },
-	{ 44, 64,  0x1000, 12 },
+	[VM_MODE_P52V48_4K]	= { 52, 48,  0x1000, 12 },
+	[VM_MODE_P52V48_64K]	= { 52, 48, 0x10000, 16 },
+	[VM_MODE_P48V48_4K]	= { 48, 48,  0x1000, 12 },
+	[VM_MODE_P48V48_64K]	= { 48, 48, 0x10000, 16 },
+	[VM_MODE_P40V48_4K]	= { 40, 48,  0x1000, 12 },
+	[VM_MODE_P40V48_64K]	= { 40, 48, 0x10000, 16 },
+	[VM_MODE_PXXV48_4K]	= {  0,  0,  0x1000, 12 },
+	[VM_MODE_P47V64_4K]	= { 47, 64,  0x1000, 12 },
+	[VM_MODE_P44V64_4K]	= { 44, 64,  0x1000, 12 },
 };
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
  2021-11-11  0:02 ` [PATCH v2 01/12] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11 17:43   ` Ben Gardon
  2021-11-11  0:03 ` [PATCH v2 03/12] KVM: selftests: Assert mmap HVA is aligned when using HugeTLB David Matlack
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Refactor align() to work with non-pointers and split into separate
helpers for aligning up vs. down. Add align_ptr_up() for use with
pointers. Expose all helpers so that they can be used by tests and/or
other utilities.  The align_down() helper in particular will be used to
ensure gpa alignment for hugepages.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
[Added sepearate up/down helpers and replaced open-coded alignment
 bit math throughout the KVM selftests.]
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/dirty_log_test.c  |  6 ++---
 .../testing/selftests/kvm/include/test_util.h | 25 +++++++++++++++++++
 .../selftests/kvm/kvm_page_table_test.c       |  2 +-
 tools/testing/selftests/kvm/lib/elf.c         |  3 +--
 tools/testing/selftests/kvm/lib/kvm_util.c    | 13 ++--------
 .../selftests/kvm/lib/perf_test_util.c        |  4 +--
 6 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index 792c60e1b17d..3fcd89e195c7 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -115,7 +115,7 @@ static void guest_code(void)
 			addr = guest_test_virt_mem;
 			addr += (READ_ONCE(random_array[i]) % guest_num_pages)
 				* guest_page_size;
-			addr &= ~(host_page_size - 1);
+			addr = align_down(addr, host_page_size);
 			*(uint64_t *)addr = READ_ONCE(iteration);
 		}
 
@@ -737,14 +737,14 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	if (!p->phys_offset) {
 		guest_test_phys_mem = (vm_get_max_gfn(vm) -
 				       guest_num_pages) * guest_page_size;
-		guest_test_phys_mem &= ~(host_page_size - 1);
+		guest_test_phys_mem = align_down(guest_test_phys_mem, host_page_size);
 	} else {
 		guest_test_phys_mem = p->phys_offset;
 	}
 
 #ifdef __s390x__
 	/* Align to 1M (segment size) */
-	guest_test_phys_mem &= ~((1 << 20) - 1);
+	guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
 #endif
 
 	pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index f8fddc84c0d3..78c06310cc0e 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -117,4 +117,29 @@ static inline bool backing_src_is_shared(enum vm_mem_backing_src_type t)
 	return vm_mem_backing_src_alias(t)->flag & MAP_SHARED;
 }
 
+/* Aligns x up to the next multiple of size. Size must be a power of 2. */
+static inline uint64_t align_up(uint64_t x, uint64_t size)
+{
+	uint64_t mask = size - 1;
+
+	TEST_ASSERT(size != 0 && !(size & (size - 1)),
+		    "size not a power of 2: %lu", size);
+	return ((x + mask) & ~mask);
+}
+
+static inline uint64_t align_down(uint64_t x, uint64_t size)
+{
+	uint64_t x_aligned_up = align_up(x, size);
+
+	if (x == x_aligned_up)
+		return x;
+	else
+		return x_aligned_up - size;
+}
+
+static inline void *align_ptr_up(void *x, size_t size)
+{
+	return (void *)align_up((unsigned long)x, size);
+}
+
 #endif /* SELFTEST_KVM_TEST_UTIL_H */
diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
index 36407cb0ec85..3836322add00 100644
--- a/tools/testing/selftests/kvm/kvm_page_table_test.c
+++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
@@ -280,7 +280,7 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg)
 #ifdef __s390x__
 	alignment = max(0x100000, alignment);
 #endif
-	guest_test_phys_mem &= ~(alignment - 1);
+	guest_test_phys_mem = align_down(guest_test_virt_mem, alignment);
 
 	/* Set up the shared data structure test_args */
 	test_args.vm = vm;
diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c
index eac44f5d0db0..13e8e3dcf984 100644
--- a/tools/testing/selftests/kvm/lib/elf.c
+++ b/tools/testing/selftests/kvm/lib/elf.c
@@ -157,8 +157,7 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename)
 			"memsize of 0,\n"
 			"  phdr index: %u p_memsz: 0x%" PRIx64,
 			n1, (uint64_t) phdr.p_memsz);
-		vm_vaddr_t seg_vstart = phdr.p_vaddr;
-		seg_vstart &= ~(vm_vaddr_t)(vm->page_size - 1);
+		vm_vaddr_t seg_vstart = align_down(phdr.p_vaddr, vm->page_size);
 		vm_vaddr_t seg_vend = phdr.p_vaddr + phdr.p_memsz - 1;
 		seg_vend |= vm->page_size - 1;
 		size_t seg_size = seg_vend - seg_vstart + 1;
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index b624c24290dd..63375118d48f 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -22,15 +22,6 @@
 
 static int vcpu_mmap_sz(void);
 
-/* Aligns x up to the next multiple of size. Size must be a power of 2. */
-static void *align(void *x, size_t size)
-{
-	size_t mask = size - 1;
-	TEST_ASSERT(size != 0 && !(size & (size - 1)),
-		    "size not a power of 2: %lu", size);
-	return (void *) (((size_t) x + mask) & ~mask);
-}
-
 /*
  * Open KVM_DEV_PATH if available, otherwise exit the entire program.
  *
@@ -911,7 +902,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 		    region->mmap_start, errno);
 
 	/* Align host address */
-	region->host_mem = align(region->mmap_start, alignment);
+	region->host_mem = align_ptr_up(region->mmap_start, alignment);
 
 	/* As needed perform madvise */
 	if ((src_type == VM_MEM_SRC_ANONYMOUS ||
@@ -954,7 +945,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 			    "mmap of alias failed, errno: %i", errno);
 
 		/* Align host alias address */
-		region->host_alias = align(region->mmap_alias, alignment);
+		region->host_alias = align_ptr_up(region->mmap_alias, alignment);
 	}
 }
 
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 0ef80dbdc116..6b8d5020dc54 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -92,10 +92,10 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
 	guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
 			      perf_test_args.guest_page_size;
-	guest_test_phys_mem &= ~(perf_test_args.host_page_size - 1);
+	guest_test_phys_mem = align_down(guest_test_phys_mem, perf_test_args.host_page_size);
 #ifdef __s390x__
 	/* Align to 1M (segment size) */
-	guest_test_phys_mem &= ~((1 << 20) - 1);
+	guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
 #endif
 	pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 03/12] KVM: selftests: Assert mmap HVA is aligned when using HugeTLB
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
  2021-11-11  0:02 ` [PATCH v2 01/12] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array David Matlack
  2021-11-11  0:03 ` [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages David Matlack
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Manually padding and aligning the mmap region is only needed when using
THP. When using HugeTLB, mmap will always return an address aligned to
the HugeTLB page size. Add a comment to clarify this and assert the mmap
behavior for HugeTLB.

Cc: Ben Gardon <bgardon@google.com>
Cc: Yanan Wang <wangyanan55@huawei.com>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Aaron Lewis <aaronlewis@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
[Removed requirement that HugeTLB mmaps must be padded per Yanan's
 feedback and added assertion that mmap returns aligned addresses
 when using HugeTLB.]
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/include/test_util.h |  1 +
 tools/testing/selftests/kvm/lib/kvm_util.c      | 11 +++++++++++
 tools/testing/selftests/kvm/lib/test_util.c     |  5 +++++
 3 files changed, 17 insertions(+)

diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index 78c06310cc0e..99e0dcdc923f 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -104,6 +104,7 @@ size_t get_trans_hugepagesz(void);
 size_t get_def_hugetlb_pagesz(void);
 const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i);
 size_t get_backing_src_pagesz(uint32_t i);
+bool is_backing_src_hugetlb(uint32_t i);
 void backing_src_help(const char *flag);
 enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
 long get_run_delay(void);
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 63375118d48f..07f37456bba0 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -866,6 +866,12 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 	alignment = 1;
 #endif
 
+	/*
+	 * When using THP mmap is not guaranteed to returned a hugepage aligned
+	 * address so we have to pad the mmap. Padding is not needed for HugeTLB
+	 * because mmap will always return an address aligned to the HugeTLB
+	 * page size.
+	 */
 	if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
 		alignment = max(backing_src_pagesz, alignment);
 
@@ -901,6 +907,11 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 		    "test_malloc failed, mmap_start: %p errno: %i",
 		    region->mmap_start, errno);
 
+	TEST_ASSERT(!is_backing_src_hugetlb(src_type) ||
+		    region->mmap_start == align_ptr_up(region->mmap_start, backing_src_pagesz),
+		    "mmap_start %p is not aligned to HugeTLB page size 0x%lx",
+		    region->mmap_start, backing_src_pagesz);
+
 	/* Align host address */
 	region->host_mem = align_ptr_up(region->mmap_start, alignment);
 
diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c
index b72429108993..6d23878bbfe1 100644
--- a/tools/testing/selftests/kvm/lib/test_util.c
+++ b/tools/testing/selftests/kvm/lib/test_util.c
@@ -283,6 +283,11 @@ size_t get_backing_src_pagesz(uint32_t i)
 	}
 }
 
+bool is_backing_src_hugetlb(uint32_t i)
+{
+	return !!(vm_mem_backing_src_alias(i)->flag & MAP_HUGETLB);
+}
+
 static void print_available_backing_src_types(const char *prefix)
 {
 	int i;
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (2 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 03/12] KVM: selftests: Assert mmap HVA is aligned when using HugeTLB David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11 17:49   ` Ben Gardon
  2021-11-11  0:03 ` [PATCH v2 05/12] KVM: selftests: Use shorthand local var to access struct perf_tests_args David Matlack
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Assert that the GPA for a memslot backed by a hugepage is aligned to
the hugepage size and fix perf_test_util accordingly.  Lack of GPA
alignment prevents KVM from backing the guest with hugepages, e.g. x86's
write-protection of hugepages when dirty logging is activated is
otherwise not exercised.

Add a comment explaining that guest_page_size is for non-huge pages to
try and avoid confusion about what it actually tracks.

Cc: Ben Gardon <bgardon@google.com>
Cc: Yanan Wang <wangyanan55@huawei.com>
Cc: Andrew Jones <drjones@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Aaron Lewis <aaronlewis@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
[Used get_backing_src_pagesz() to determine alignment dynamically.]
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/lib/kvm_util.c       | 2 ++
 tools/testing/selftests/kvm/lib/perf_test_util.c | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 07f37456bba0..1f6a01c33dce 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -875,6 +875,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
 	if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
 		alignment = max(backing_src_pagesz, alignment);
 
+	ASSERT_EQ(guest_paddr, align_up(guest_paddr, backing_src_pagesz));
+
 	/* Add enough memory to align up if necessary */
 	if (alignment > 1)
 		region->mmap_size += alignment;
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 6b8d5020dc54..a015f267d945 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -55,11 +55,16 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 {
 	struct kvm_vm *vm;
 	uint64_t guest_num_pages;
+	uint64_t backing_src_pagesz = get_backing_src_pagesz(backing_src);
 	int i;
 
 	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
 
 	perf_test_args.host_page_size = getpagesize();
+	/*
+	 * Snapshot the non-huge page size.  This is used by the guest code to
+	 * access/dirty pages at the logging granularity.
+	 */
 	perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size;
 
 	guest_num_pages = vm_adjust_num_guest_pages(mode,
@@ -92,7 +97,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
 	guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
 			      perf_test_args.guest_page_size;
-	guest_test_phys_mem = align_down(guest_test_phys_mem, perf_test_args.host_page_size);
+	guest_test_phys_mem = align_down(guest_test_phys_mem, backing_src_pagesz);
 #ifdef __s390x__
 	/* Align to 1M (segment size) */
 	guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 05/12] KVM: selftests: Use shorthand local var to access struct perf_tests_args
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (3 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 06/12] KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args David Matlack
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Use 'pta' as a local pointer to the global perf_tests_args in order to
shorten line lengths and make the code borderline readable.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 .../selftests/kvm/lib/perf_test_util.c        | 35 ++++++++++---------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index a015f267d945..ccdc950c829e 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -24,7 +24,8 @@ static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
  */
 static void guest_code(uint32_t vcpu_id)
 {
-	struct perf_test_vcpu_args *vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
+	struct perf_test_args *pta = &perf_test_args;
+	struct perf_test_vcpu_args *vcpu_args = &pta->vcpu_args[vcpu_id];
 	uint64_t gva;
 	uint64_t pages;
 	int i;
@@ -37,9 +38,9 @@ static void guest_code(uint32_t vcpu_id)
 
 	while (true) {
 		for (i = 0; i < pages; i++) {
-			uint64_t addr = gva + (i * perf_test_args.guest_page_size);
+			uint64_t addr = gva + (i * pta->guest_page_size);
 
-			if (i % perf_test_args.wr_fract == 0)
+			if (i % pta->wr_fract == 0)
 				*(uint64_t *)addr = 0x0123456789ABCDEF;
 			else
 				READ_ONCE(*(uint64_t *)addr);
@@ -53,6 +54,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 				   uint64_t vcpu_memory_bytes, int slots,
 				   enum vm_mem_backing_src_type backing_src)
 {
+	struct perf_test_args *pta = &perf_test_args;
 	struct kvm_vm *vm;
 	uint64_t guest_num_pages;
 	uint64_t backing_src_pagesz = get_backing_src_pagesz(backing_src);
@@ -60,29 +62,29 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
 	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
 
-	perf_test_args.host_page_size = getpagesize();
+	pta->host_page_size = getpagesize();
 	/*
 	 * Snapshot the non-huge page size.  This is used by the guest code to
 	 * access/dirty pages at the logging granularity.
 	 */
-	perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size;
+	pta->guest_page_size = vm_guest_mode_params[mode].page_size;
 
 	guest_num_pages = vm_adjust_num_guest_pages(mode,
-				(vcpus * vcpu_memory_bytes) / perf_test_args.guest_page_size);
+				(vcpus * vcpu_memory_bytes) / pta->guest_page_size);
 
-	TEST_ASSERT(vcpu_memory_bytes % perf_test_args.host_page_size == 0,
+	TEST_ASSERT(vcpu_memory_bytes % pta->host_page_size == 0,
 		    "Guest memory size is not host page size aligned.");
-	TEST_ASSERT(vcpu_memory_bytes % perf_test_args.guest_page_size == 0,
+	TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0,
 		    "Guest memory size is not guest page size aligned.");
 	TEST_ASSERT(guest_num_pages % slots == 0,
 		    "Guest memory cannot be evenly divided into %d slots.",
 		    slots);
 
 	vm = vm_create_with_vcpus(mode, vcpus, DEFAULT_GUEST_PHY_PAGES,
-				  (vcpus * vcpu_memory_bytes) / perf_test_args.guest_page_size,
+				  (vcpus * vcpu_memory_bytes) / pta->guest_page_size,
 				  0, guest_code, NULL);
 
-	perf_test_args.vm = vm;
+	pta->vm = vm;
 
 	/*
 	 * If there should be more memory in the guest test region than there
@@ -96,7 +98,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 		    vcpu_memory_bytes);
 
 	guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
-			      perf_test_args.guest_page_size;
+			      pta->guest_page_size;
 	guest_test_phys_mem = align_down(guest_test_phys_mem, backing_src_pagesz);
 #ifdef __s390x__
 	/* Align to 1M (segment size) */
@@ -108,7 +110,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 	for (i = 0; i < slots; i++) {
 		uint64_t region_pages = guest_num_pages / slots;
 		vm_paddr_t region_start = guest_test_phys_mem +
-			region_pages * perf_test_args.guest_page_size * i;
+			region_pages * pta->guest_page_size * i;
 
 		vm_userspace_mem_region_add(vm, backing_src, region_start,
 					    PERF_TEST_MEM_SLOT_INDEX + i,
@@ -133,25 +135,26 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
 			   uint64_t vcpu_memory_bytes,
 			   bool partition_vcpu_memory_access)
 {
+	struct perf_test_args *pta = &perf_test_args;
 	vm_paddr_t vcpu_gpa;
 	struct perf_test_vcpu_args *vcpu_args;
 	int vcpu_id;
 
 	for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
-		vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
+		vcpu_args = &pta->vcpu_args[vcpu_id];
 
 		vcpu_args->vcpu_id = vcpu_id;
 		if (partition_vcpu_memory_access) {
 			vcpu_args->gva = guest_test_virt_mem +
 					 (vcpu_id * vcpu_memory_bytes);
 			vcpu_args->pages = vcpu_memory_bytes /
-					   perf_test_args.guest_page_size;
+					   pta->guest_page_size;
 			vcpu_gpa = guest_test_phys_mem +
 				   (vcpu_id * vcpu_memory_bytes);
 		} else {
 			vcpu_args->gva = guest_test_virt_mem;
 			vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
-					   perf_test_args.guest_page_size;
+					   pta->guest_page_size;
 			vcpu_gpa = guest_test_phys_mem;
 		}
 
@@ -159,6 +162,6 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
 
 		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
 			 vcpu_id, vcpu_gpa, vcpu_gpa +
-			 (vcpu_args->pages * perf_test_args.guest_page_size));
+			 (vcpu_args->pages * pta->guest_page_size));
 	}
 }
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 06/12] KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (4 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 05/12] KVM: selftests: Use shorthand local var to access struct perf_tests_args David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 07/12] KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging test David Matlack
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Capture the per-vCPU GPA in perf_test_vcpu_args so that tests can get
the GPA without having to calculate the GPA on their own.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/include/perf_test_util.h | 1 +
 tools/testing/selftests/kvm/lib/perf_test_util.c     | 9 ++++-----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
index df9f1a3a3ffb..20aec72fe7b8 100644
--- a/tools/testing/selftests/kvm/include/perf_test_util.h
+++ b/tools/testing/selftests/kvm/include/perf_test_util.h
@@ -18,6 +18,7 @@
 #define PERF_TEST_MEM_SLOT_INDEX	1
 
 struct perf_test_vcpu_args {
+	uint64_t gpa;
 	uint64_t gva;
 	uint64_t pages;
 
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index ccdc950c829e..d9c6bcb7964d 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -136,7 +136,6 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
 			   bool partition_vcpu_memory_access)
 {
 	struct perf_test_args *pta = &perf_test_args;
-	vm_paddr_t vcpu_gpa;
 	struct perf_test_vcpu_args *vcpu_args;
 	int vcpu_id;
 
@@ -149,19 +148,19 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
 					 (vcpu_id * vcpu_memory_bytes);
 			vcpu_args->pages = vcpu_memory_bytes /
 					   pta->guest_page_size;
-			vcpu_gpa = guest_test_phys_mem +
-				   (vcpu_id * vcpu_memory_bytes);
+			vcpu_args->gpa = guest_test_phys_mem +
+					 (vcpu_id * vcpu_memory_bytes);
 		} else {
 			vcpu_args->gva = guest_test_virt_mem;
 			vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
 					   pta->guest_page_size;
-			vcpu_gpa = guest_test_phys_mem;
+			vcpu_args->gpa = guest_test_phys_mem;
 		}
 
 		vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
 
 		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
-			 vcpu_id, vcpu_gpa, vcpu_gpa +
+			 vcpu_id, vcpu_args->gpa, vcpu_args->gpa +
 			 (vcpu_args->pages * pta->guest_page_size));
 	}
 }
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 07/12] KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging test
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (5 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 06/12] KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 08/12] KVM: selftests: Move per-VM GPA into perf_test_args David Matlack
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Grab the per-vCPU GPA and number of pages from perf_util in the demand
paging test instead of duplicating perf_util's calculations.

Note, this may or may not result in a functional change.  It's not clear
that the test's calculations are guaranteed to yield the same value as
perf_util, e.g. if guest_percpu_mem_size != vcpu_args->pages.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 .../selftests/kvm/demand_paging_test.c        | 21 +++++--------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 1510b21e6306..3c729a0a1ab1 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -322,26 +322,15 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 		TEST_ASSERT(pipefds, "Unable to allocate memory for pipefd");
 
 		for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++) {
-			vm_paddr_t vcpu_gpa;
+			struct perf_test_vcpu_args *vcpu_args;
 			void *vcpu_hva;
 			void *vcpu_alias;
-			uint64_t vcpu_mem_size;
 
-
-			if (p->partition_vcpu_memory_access) {
-				vcpu_gpa = guest_test_phys_mem +
-					   (vcpu_id * guest_percpu_mem_size);
-				vcpu_mem_size = guest_percpu_mem_size;
-			} else {
-				vcpu_gpa = guest_test_phys_mem;
-				vcpu_mem_size = guest_percpu_mem_size * nr_vcpus;
-			}
-			PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",
-				       vcpu_id, vcpu_gpa, vcpu_gpa + vcpu_mem_size);
+			vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
 
 			/* Cache the host addresses of the region */
-			vcpu_hva = addr_gpa2hva(vm, vcpu_gpa);
-			vcpu_alias = addr_gpa2alias(vm, vcpu_gpa);
+			vcpu_hva = addr_gpa2hva(vm, vcpu_args->gpa);
+			vcpu_alias = addr_gpa2alias(vm, vcpu_args->gpa);
 
 			/*
 			 * Set up user fault fd to handle demand paging
@@ -355,7 +344,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 					    pipefds[vcpu_id * 2], p->uffd_mode,
 					    p->uffd_delay, &uffd_args[vcpu_id],
 					    vcpu_hva, vcpu_alias,
-					    vcpu_mem_size);
+					    vcpu_args->pages * perf_test_args.guest_page_size);
 		}
 	}
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 08/12] KVM: selftests: Move per-VM GPA into perf_test_args
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (6 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 07/12] KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging test David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 09/12] KVM: selftests: Remove perf_test_args.host_page_size David Matlack
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Move the per-VM GPA into perf_test_args instead of storing it as a
separate global variable.  It's not obvious that guest_test_phys_mem
holds a GPA, nor that it's connected/coupled with per_vcpu->gpa.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 .../selftests/kvm/include/perf_test_util.h    |  8 +------
 .../selftests/kvm/lib/perf_test_util.c        | 21 +++++++------------
 .../kvm/memslot_modification_stress_test.c    |  2 +-
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
index 20aec72fe7b8..d7cde1ab2a85 100644
--- a/tools/testing/selftests/kvm/include/perf_test_util.h
+++ b/tools/testing/selftests/kvm/include/perf_test_util.h
@@ -29,6 +29,7 @@ struct perf_test_vcpu_args {
 struct perf_test_args {
 	struct kvm_vm *vm;
 	uint64_t host_page_size;
+	uint64_t gpa;
 	uint64_t guest_page_size;
 	int wr_fract;
 
@@ -37,13 +38,6 @@ struct perf_test_args {
 
 extern struct perf_test_args perf_test_args;
 
-/*
- * Guest physical memory offset of the testing memory slot.
- * This will be set to the topmost valid physical address minus
- * the test memory size.
- */
-extern uint64_t guest_test_phys_mem;
-
 struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 				   uint64_t vcpu_memory_bytes, int slots,
 				   enum vm_mem_backing_src_type backing_src);
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index d9c6bcb7964d..0fc2d834c1c7 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -10,8 +10,6 @@
 
 struct perf_test_args perf_test_args;
 
-uint64_t guest_test_phys_mem;
-
 /*
  * Guest virtual memory offset of the testing memory slot.
  * Must not conflict with identity mapped test code.
@@ -97,20 +95,18 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 		    guest_num_pages, vm_get_max_gfn(vm), vcpus,
 		    vcpu_memory_bytes);
 
-	guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
-			      pta->guest_page_size;
-	guest_test_phys_mem = align_down(guest_test_phys_mem, backing_src_pagesz);
+	pta->gpa = (vm_get_max_gfn(vm) - guest_num_pages) * pta->guest_page_size;
+	pta->gpa = align_down(pta->gpa, backing_src_pagesz);
 #ifdef __s390x__
 	/* Align to 1M (segment size) */
-	guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
+	pta->gpa = align_down(pta->gpa, 1 << 20);
 #endif
-	pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
+	pr_info("guest physical test memory offset: 0x%lx\n", pta->gpa);
 
 	/* Add extra memory slots for testing */
 	for (i = 0; i < slots; i++) {
 		uint64_t region_pages = guest_num_pages / slots;
-		vm_paddr_t region_start = guest_test_phys_mem +
-			region_pages * pta->guest_page_size * i;
+		vm_paddr_t region_start = pta->gpa + region_pages * pta->guest_page_size * i;
 
 		vm_userspace_mem_region_add(vm, backing_src, region_start,
 					    PERF_TEST_MEM_SLOT_INDEX + i,
@@ -118,7 +114,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 	}
 
 	/* Do mapping for the demand paging memory slot */
-	virt_map(vm, guest_test_virt_mem, guest_test_phys_mem, guest_num_pages);
+	virt_map(vm, guest_test_virt_mem, pta->gpa, guest_num_pages);
 
 	ucall_init(vm, NULL);
 
@@ -148,13 +144,12 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
 					 (vcpu_id * vcpu_memory_bytes);
 			vcpu_args->pages = vcpu_memory_bytes /
 					   pta->guest_page_size;
-			vcpu_args->gpa = guest_test_phys_mem +
-					 (vcpu_id * vcpu_memory_bytes);
+			vcpu_args->gpa = pta->gpa + (vcpu_id * vcpu_memory_bytes);
 		} else {
 			vcpu_args->gva = guest_test_virt_mem;
 			vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
 					   pta->guest_page_size;
-			vcpu_args->gpa = guest_test_phys_mem;
+			vcpu_args->gpa = pta->gpa;
 		}
 
 		vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
index 4cfcafea9f5a..d105180d5e8c 100644
--- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
+++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
@@ -80,7 +80,7 @@ static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay,
 	 * Add the dummy memslot just below the perf_test_util memslot, which is
 	 * at the top of the guest physical address space.
 	 */
-	gpa = guest_test_phys_mem - pages * vm_get_page_size(vm);
+	gpa = perf_test_args.gpa - pages * vm_get_page_size(vm);
 
 	for (i = 0; i < nr_modifications; i++) {
 		usleep(delay);
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 09/12] KVM: selftests: Remove perf_test_args.host_page_size
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (7 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 08/12] KVM: selftests: Move per-VM GPA into perf_test_args David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 10/12] KVM: selftests: Create VM with adjusted number of guest pages for perf tests David Matlack
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Remove perf_test_args.host_page_size and instead use getpagesize() so
that it's somewhat obvious that, for tests that care about the host page
size, they care about the system page size, not the hardware page size,
e.g. that the logic is unchanged if hugepages are in play.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/include/perf_test_util.h | 1 -
 tools/testing/selftests/kvm/lib/perf_test_util.c     | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
index d7cde1ab2a85..9348580dc5be 100644
--- a/tools/testing/selftests/kvm/include/perf_test_util.h
+++ b/tools/testing/selftests/kvm/include/perf_test_util.h
@@ -28,7 +28,6 @@ struct perf_test_vcpu_args {
 
 struct perf_test_args {
 	struct kvm_vm *vm;
-	uint64_t host_page_size;
 	uint64_t gpa;
 	uint64_t guest_page_size;
 	int wr_fract;
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 0fc2d834c1c7..a0aded8cfce3 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -60,7 +60,6 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
 	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
 
-	pta->host_page_size = getpagesize();
 	/*
 	 * Snapshot the non-huge page size.  This is used by the guest code to
 	 * access/dirty pages at the logging granularity.
@@ -70,7 +69,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 	guest_num_pages = vm_adjust_num_guest_pages(mode,
 				(vcpus * vcpu_memory_bytes) / pta->guest_page_size);
 
-	TEST_ASSERT(vcpu_memory_bytes % pta->host_page_size == 0,
+	TEST_ASSERT(vcpu_memory_bytes % getpagesize() == 0,
 		    "Guest memory size is not host page size aligned.");
 	TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0,
 		    "Guest memory size is not guest page size aligned.");
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 10/12] KVM: selftests: Create VM with adjusted number of guest pages for perf tests
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (8 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 09/12] KVM: selftests: Remove perf_test_args.host_page_size David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11  0:03 ` [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation David Matlack
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Use the already computed guest_num_pages when creating the so called
extra VM pages for a perf test, and add a comment explaining why the
pages are allocated as extra pages.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 tools/testing/selftests/kvm/lib/perf_test_util.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index a0aded8cfce3..b3154b5b0cfd 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -77,9 +77,13 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 		    "Guest memory cannot be evenly divided into %d slots.",
 		    slots);
 
+	/*
+	 * Pass guest_num_pages to populate the page tables for test memory.
+	 * The memory is also added to memslot 0, but that's a benign side
+	 * effect as KVM allows aliasing HVAs in meslots.
+	 */
 	vm = vm_create_with_vcpus(mode, vcpus, DEFAULT_GUEST_PHY_PAGES,
-				  (vcpus * vcpu_memory_bytes) / pta->guest_page_size,
-				  0, guest_code, NULL);
+				  guest_num_pages, 0, guest_code, NULL);
 
 	pta->vm = vm;
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (9 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 10/12] KVM: selftests: Create VM with adjusted number of guest pages for perf tests David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11 17:53   ` Ben Gardon
  2021-11-11  0:03 ` [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during " David Matlack
  2021-11-16 11:12 ` [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups Paolo Bonzini
  12 siblings, 1 reply; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Fill the per-vCPU args when creating the perf_test VM instead of having
the caller do so.  This helps ensure that any adjustments to the number
of pages (and thus vcpu_memory_bytes) are reflected in the per-VM args.
Automatically filling the per-vCPU args will also allow a future patch
to do the sync to the guest during creation.

Signed-off-by: Sean Christopherson <seanjc@google.com>
[Updated access_tracking_perf_test as well.]
Signed-off-by: David Matlack <dmatlack@google.com>
---
 .../selftests/kvm/access_tracking_perf_test.c |  5 +-
 .../selftests/kvm/demand_paging_test.c        |  5 +-
 .../selftests/kvm/dirty_log_perf_test.c       |  6 +-
 .../selftests/kvm/include/perf_test_util.h    |  6 +-
 .../selftests/kvm/lib/perf_test_util.c        | 71 ++++++++++---------
 .../kvm/memslot_modification_stress_test.c    |  6 +-
 6 files changed, 45 insertions(+), 54 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index 5d95113c7b7c..fdef6c906388 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -332,10 +332,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	int vcpus = params->vcpus;
 
 	vm = perf_test_create_vm(mode, vcpus, params->vcpu_memory_bytes, 1,
-				 params->backing_src);
-
-	perf_test_setup_vcpus(vm, vcpus, params->vcpu_memory_bytes,
-			      !overlap_memory_access);
+				 params->backing_src, !overlap_memory_access);
 
 	vcpu_threads = create_vcpu_threads(vcpus);
 
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 3c729a0a1ab1..0fee44f5e5ae 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -293,7 +293,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	int r;
 
 	vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
-				 p->src_type);
+				 p->src_type, p->partition_vcpu_memory_access);
 
 	perf_test_args.wr_fract = 1;
 
@@ -307,9 +307,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size,
-			      p->partition_vcpu_memory_access);
-
 	if (p->uffd_mode) {
 		uffd_handler_threads =
 			malloc(nr_vcpus * sizeof(*uffd_handler_threads));
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
index 7ffab5bd5ce5..62f9cc2a3146 100644
--- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
@@ -186,7 +186,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	struct timespec clear_dirty_log_total = (struct timespec){0};
 
 	vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size,
-				 p->slots, p->backing_src);
+				 p->slots, p->backing_src,
+				 p->partition_vcpu_memory_access);
 
 	perf_test_args.wr_fract = p->wr_fract;
 
@@ -206,9 +207,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size,
-			      p->partition_vcpu_memory_access);
-
 	sync_global_to_guest(vm, perf_test_args);
 
 	/* Start the iterations */
diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
index 9348580dc5be..91804be1cf53 100644
--- a/tools/testing/selftests/kvm/include/perf_test_util.h
+++ b/tools/testing/selftests/kvm/include/perf_test_util.h
@@ -39,10 +39,8 @@ extern struct perf_test_args perf_test_args;
 
 struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 				   uint64_t vcpu_memory_bytes, int slots,
-				   enum vm_mem_backing_src_type backing_src);
+				   enum vm_mem_backing_src_type backing_src,
+				   bool partition_vcpu_memory_access);
 void perf_test_destroy_vm(struct kvm_vm *vm);
-void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
-			   uint64_t vcpu_memory_bytes,
-			   bool partition_vcpu_memory_access);
 
 #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index b3154b5b0cfd..13c8bc22f4e1 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -48,9 +48,43 @@ static void guest_code(uint32_t vcpu_id)
 	}
 }
 
+void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
+			   uint64_t vcpu_memory_bytes,
+			   bool partition_vcpu_memory_access)
+{
+	struct perf_test_args *pta = &perf_test_args;
+	struct perf_test_vcpu_args *vcpu_args;
+	int vcpu_id;
+
+	for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
+		vcpu_args = &pta->vcpu_args[vcpu_id];
+
+		vcpu_args->vcpu_id = vcpu_id;
+		if (partition_vcpu_memory_access) {
+			vcpu_args->gva = guest_test_virt_mem +
+					 (vcpu_id * vcpu_memory_bytes);
+			vcpu_args->pages = vcpu_memory_bytes /
+					   pta->guest_page_size;
+			vcpu_args->gpa = pta->gpa + (vcpu_id * vcpu_memory_bytes);
+		} else {
+			vcpu_args->gva = guest_test_virt_mem;
+			vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
+					   pta->guest_page_size;
+			vcpu_args->gpa = pta->gpa;
+		}
+
+		vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
+
+		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
+			 vcpu_id, vcpu_args->gpa, vcpu_args->gpa +
+			 (vcpu_args->pages * pta->guest_page_size));
+	}
+}
+
 struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 				   uint64_t vcpu_memory_bytes, int slots,
-				   enum vm_mem_backing_src_type backing_src)
+				   enum vm_mem_backing_src_type backing_src,
+				   bool partition_vcpu_memory_access)
 {
 	struct perf_test_args *pta = &perf_test_args;
 	struct kvm_vm *vm;
@@ -119,6 +153,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 	/* Do mapping for the demand paging memory slot */
 	virt_map(vm, guest_test_virt_mem, pta->gpa, guest_num_pages);
 
+	perf_test_setup_vcpus(vm, vcpus, vcpu_memory_bytes, partition_vcpu_memory_access);
+
 	ucall_init(vm, NULL);
 
 	return vm;
@@ -129,36 +165,3 @@ void perf_test_destroy_vm(struct kvm_vm *vm)
 	ucall_uninit(vm);
 	kvm_vm_free(vm);
 }
-
-void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
-			   uint64_t vcpu_memory_bytes,
-			   bool partition_vcpu_memory_access)
-{
-	struct perf_test_args *pta = &perf_test_args;
-	struct perf_test_vcpu_args *vcpu_args;
-	int vcpu_id;
-
-	for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
-		vcpu_args = &pta->vcpu_args[vcpu_id];
-
-		vcpu_args->vcpu_id = vcpu_id;
-		if (partition_vcpu_memory_access) {
-			vcpu_args->gva = guest_test_virt_mem +
-					 (vcpu_id * vcpu_memory_bytes);
-			vcpu_args->pages = vcpu_memory_bytes /
-					   pta->guest_page_size;
-			vcpu_args->gpa = pta->gpa + (vcpu_id * vcpu_memory_bytes);
-		} else {
-			vcpu_args->gva = guest_test_virt_mem;
-			vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
-					   pta->guest_page_size;
-			vcpu_args->gpa = pta->gpa;
-		}
-
-		vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
-
-		pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
-			 vcpu_id, vcpu_args->gpa, vcpu_args->gpa +
-			 (vcpu_args->pages * pta->guest_page_size));
-	}
-}
diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
index d105180d5e8c..27af0bb8deb7 100644
--- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
+++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
@@ -105,16 +105,14 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	int vcpu_id;
 
 	vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
-				 VM_MEM_SRC_ANONYMOUS);
+				 VM_MEM_SRC_ANONYMOUS,
+				 p->partition_vcpu_memory_access);
 
 	perf_test_args.wr_fract = 1;
 
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size,
-			      p->partition_vcpu_memory_access);
-
 	/* Export the shared variables to the guest */
 	sync_global_to_guest(vm, perf_test_args);
 
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during VM creation
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (10 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation David Matlack
@ 2021-11-11  0:03 ` David Matlack
  2021-11-11 17:55   ` Ben Gardon
  2021-11-16 11:12 ` [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups Paolo Bonzini
  12 siblings, 1 reply; 19+ messages in thread
From: David Matlack @ 2021-11-11  0:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis, David Matlack

From: Sean Christopherson <seanjc@google.com>

Copy perf_test_args to the guest during VM creation instead of relying on
the caller to do so at their leisure.  Ideally, tests wouldn't even be
able to modify perf_test_args, i.e. they would have no motivation to do
the sync, but enforcing that is arguably a net negative for readability.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
[Set wr_fract=1 by default and add helper to override it since the new
 access_tracking_perf_test needs to set it dynamically.]
Signed-off-by: David Matlack <dmatlack@google.com>
---
 .../selftests/kvm/access_tracking_perf_test.c        |  3 +--
 tools/testing/selftests/kvm/demand_paging_test.c     |  5 -----
 tools/testing/selftests/kvm/dirty_log_perf_test.c    |  4 +---
 tools/testing/selftests/kvm/include/perf_test_util.h |  2 ++
 tools/testing/selftests/kvm/lib/perf_test_util.c     | 12 ++++++++++++
 .../selftests/kvm/memslot_modification_stress_test.c |  5 -----
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
index fdef6c906388..5364a2ed7c68 100644
--- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
+++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
@@ -277,8 +277,7 @@ static void run_iteration(struct kvm_vm *vm, int vcpus, const char *description)
 static void access_memory(struct kvm_vm *vm, int vcpus, enum access_type access,
 			  const char *description)
 {
-	perf_test_args.wr_fract = (access == ACCESS_READ) ? INT_MAX : 1;
-	sync_global_to_guest(vm, perf_test_args);
+	perf_test_set_wr_fract(vm, (access == ACCESS_READ) ? INT_MAX : 1);
 	iteration_work = ITERATION_ACCESS_MEMORY;
 	run_iteration(vm, vcpus, description);
 }
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 0fee44f5e5ae..26f8fd8a57ec 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -295,8 +295,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
 				 p->src_type, p->partition_vcpu_memory_access);
 
-	perf_test_args.wr_fract = 1;
-
 	demand_paging_size = get_backing_src_pagesz(p->src_type);
 
 	guest_data_prototype = malloc(demand_paging_size);
@@ -345,9 +343,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 		}
 	}
 
-	/* Export the shared variables to the guest */
-	sync_global_to_guest(vm, perf_test_args);
-
 	pr_info("Finished creating vCPUs and starting uffd threads\n");
 
 	clock_gettime(CLOCK_MONOTONIC, &start);
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
index 62f9cc2a3146..583b4d95aa98 100644
--- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
@@ -189,7 +189,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 				 p->slots, p->backing_src,
 				 p->partition_vcpu_memory_access);
 
-	perf_test_args.wr_fract = p->wr_fract;
+	perf_test_set_wr_fract(vm, p->wr_fract);
 
 	guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm);
 	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
@@ -207,8 +207,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	sync_global_to_guest(vm, perf_test_args);
-
 	/* Start the iterations */
 	iteration = 0;
 	host_quit = false;
diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
index 91804be1cf53..74e3622b3a6e 100644
--- a/tools/testing/selftests/kvm/include/perf_test_util.h
+++ b/tools/testing/selftests/kvm/include/perf_test_util.h
@@ -43,4 +43,6 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 				   bool partition_vcpu_memory_access);
 void perf_test_destroy_vm(struct kvm_vm *vm);
 
+void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract);
+
 #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 13c8bc22f4e1..77f9eb5667c9 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -94,6 +94,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
 	pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
 
+	/* By default vCPUs will write to memory. */
+	pta->wr_fract = 1;
+
 	/*
 	 * Snapshot the non-huge page size.  This is used by the guest code to
 	 * access/dirty pages at the logging granularity.
@@ -157,6 +160,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 
 	ucall_init(vm, NULL);
 
+	/* Export the shared variables to the guest. */
+	sync_global_to_guest(vm, perf_test_args);
+
 	return vm;
 }
 
@@ -165,3 +171,9 @@ void perf_test_destroy_vm(struct kvm_vm *vm)
 	ucall_uninit(vm);
 	kvm_vm_free(vm);
 }
+
+void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract)
+{
+	perf_test_args.wr_fract = wr_fract;
+	sync_global_to_guest(vm, perf_test_args);
+}
diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
index 27af0bb8deb7..df431d0da1ee 100644
--- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
+++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
@@ -108,14 +108,9 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 				 VM_MEM_SRC_ANONYMOUS,
 				 p->partition_vcpu_memory_access);
 
-	perf_test_args.wr_fract = 1;
-
 	vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
 	TEST_ASSERT(vcpu_threads, "Memory allocation failed");
 
-	/* Export the shared variables to the guest */
-	sync_global_to_guest(vm, perf_test_args);
-
 	pr_info("Finished creating vCPUs\n");
 
 	for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++)
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests
  2021-11-11  0:03 ` [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests David Matlack
@ 2021-11-11 17:43   ` Ben Gardon
  0 siblings, 0 replies; 19+ messages in thread
From: Ben Gardon @ 2021-11-11 17:43 UTC (permalink / raw)
  To: David Matlack
  Cc: Paolo Bonzini, kvm, Sean Christopherson, Andrew Jones,
	Jim Mattson, Yanan Wang, Peter Xu, Aaron Lewis

On Wed, Nov 10, 2021 at 4:03 PM David Matlack <dmatlack@google.com> wrote:
>
> From: Sean Christopherson <seanjc@google.com>
>
> Refactor align() to work with non-pointers and split into separate
> helpers for aligning up vs. down. Add align_ptr_up() for use with
> pointers. Expose all helpers so that they can be used by tests and/or
> other utilities.  The align_down() helper in particular will be used to
> ensure gpa alignment for hugepages.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> [Added sepearate up/down helpers and replaced open-coded alignment

Nit: separate

>  bit math throughout the KVM selftests.]
> Signed-off-by: David Matlack <dmatlack@google.com>

Reviewed-by: Ben Gardon <bgardon@google.com>

This is wonderful.

> ---
>  tools/testing/selftests/kvm/dirty_log_test.c  |  6 ++---
>  .../testing/selftests/kvm/include/test_util.h | 25 +++++++++++++++++++
>  .../selftests/kvm/kvm_page_table_test.c       |  2 +-
>  tools/testing/selftests/kvm/lib/elf.c         |  3 +--
>  tools/testing/selftests/kvm/lib/kvm_util.c    | 13 ++--------
>  .../selftests/kvm/lib/perf_test_util.c        |  4 +--
>  6 files changed, 34 insertions(+), 19 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
> index 792c60e1b17d..3fcd89e195c7 100644
> --- a/tools/testing/selftests/kvm/dirty_log_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_test.c
> @@ -115,7 +115,7 @@ static void guest_code(void)
>                         addr = guest_test_virt_mem;
>                         addr += (READ_ONCE(random_array[i]) % guest_num_pages)
>                                 * guest_page_size;
> -                       addr &= ~(host_page_size - 1);
> +                       addr = align_down(addr, host_page_size);
>                         *(uint64_t *)addr = READ_ONCE(iteration);
>                 }
>
> @@ -737,14 +737,14 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         if (!p->phys_offset) {
>                 guest_test_phys_mem = (vm_get_max_gfn(vm) -
>                                        guest_num_pages) * guest_page_size;
> -               guest_test_phys_mem &= ~(host_page_size - 1);
> +               guest_test_phys_mem = align_down(guest_test_phys_mem, host_page_size);
>         } else {
>                 guest_test_phys_mem = p->phys_offset;
>         }
>
>  #ifdef __s390x__
>         /* Align to 1M (segment size) */
> -       guest_test_phys_mem &= ~((1 << 20) - 1);
> +       guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
>  #endif
>
>         pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
> diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
> index f8fddc84c0d3..78c06310cc0e 100644
> --- a/tools/testing/selftests/kvm/include/test_util.h
> +++ b/tools/testing/selftests/kvm/include/test_util.h
> @@ -117,4 +117,29 @@ static inline bool backing_src_is_shared(enum vm_mem_backing_src_type t)
>         return vm_mem_backing_src_alias(t)->flag & MAP_SHARED;
>  }
>
> +/* Aligns x up to the next multiple of size. Size must be a power of 2. */
> +static inline uint64_t align_up(uint64_t x, uint64_t size)
> +{
> +       uint64_t mask = size - 1;
> +
> +       TEST_ASSERT(size != 0 && !(size & (size - 1)),
> +                   "size not a power of 2: %lu", size);
> +       return ((x + mask) & ~mask);
> +}
> +
> +static inline uint64_t align_down(uint64_t x, uint64_t size)
> +{
> +       uint64_t x_aligned_up = align_up(x, size);
> +
> +       if (x == x_aligned_up)
> +               return x;
> +       else
> +               return x_aligned_up - size;
> +}
> +
> +static inline void *align_ptr_up(void *x, size_t size)
> +{
> +       return (void *)align_up((unsigned long)x, size);
> +}
> +
>  #endif /* SELFTEST_KVM_TEST_UTIL_H */
> diff --git a/tools/testing/selftests/kvm/kvm_page_table_test.c b/tools/testing/selftests/kvm/kvm_page_table_test.c
> index 36407cb0ec85..3836322add00 100644
> --- a/tools/testing/selftests/kvm/kvm_page_table_test.c
> +++ b/tools/testing/selftests/kvm/kvm_page_table_test.c
> @@ -280,7 +280,7 @@ static struct kvm_vm *pre_init_before_test(enum vm_guest_mode mode, void *arg)
>  #ifdef __s390x__
>         alignment = max(0x100000, alignment);
>  #endif
> -       guest_test_phys_mem &= ~(alignment - 1);
> +       guest_test_phys_mem = align_down(guest_test_virt_mem, alignment);
>
>         /* Set up the shared data structure test_args */
>         test_args.vm = vm;
> diff --git a/tools/testing/selftests/kvm/lib/elf.c b/tools/testing/selftests/kvm/lib/elf.c
> index eac44f5d0db0..13e8e3dcf984 100644
> --- a/tools/testing/selftests/kvm/lib/elf.c
> +++ b/tools/testing/selftests/kvm/lib/elf.c
> @@ -157,8 +157,7 @@ void kvm_vm_elf_load(struct kvm_vm *vm, const char *filename)
>                         "memsize of 0,\n"
>                         "  phdr index: %u p_memsz: 0x%" PRIx64,
>                         n1, (uint64_t) phdr.p_memsz);
> -               vm_vaddr_t seg_vstart = phdr.p_vaddr;
> -               seg_vstart &= ~(vm_vaddr_t)(vm->page_size - 1);
> +               vm_vaddr_t seg_vstart = align_down(phdr.p_vaddr, vm->page_size);
>                 vm_vaddr_t seg_vend = phdr.p_vaddr + phdr.p_memsz - 1;
>                 seg_vend |= vm->page_size - 1;
>                 size_t seg_size = seg_vend - seg_vstart + 1;
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index b624c24290dd..63375118d48f 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -22,15 +22,6 @@
>
>  static int vcpu_mmap_sz(void);
>
> -/* Aligns x up to the next multiple of size. Size must be a power of 2. */
> -static void *align(void *x, size_t size)
> -{
> -       size_t mask = size - 1;
> -       TEST_ASSERT(size != 0 && !(size & (size - 1)),
> -                   "size not a power of 2: %lu", size);
> -       return (void *) (((size_t) x + mask) & ~mask);
> -}
> -
>  /*
>   * Open KVM_DEV_PATH if available, otherwise exit the entire program.
>   *
> @@ -911,7 +902,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>                     region->mmap_start, errno);
>
>         /* Align host address */
> -       region->host_mem = align(region->mmap_start, alignment);
> +       region->host_mem = align_ptr_up(region->mmap_start, alignment);
>
>         /* As needed perform madvise */
>         if ((src_type == VM_MEM_SRC_ANONYMOUS ||
> @@ -954,7 +945,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>                             "mmap of alias failed, errno: %i", errno);
>
>                 /* Align host alias address */
> -               region->host_alias = align(region->mmap_alias, alignment);
> +               region->host_alias = align_ptr_up(region->mmap_alias, alignment);
>         }
>  }
>
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index 0ef80dbdc116..6b8d5020dc54 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -92,10 +92,10 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>
>         guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
>                               perf_test_args.guest_page_size;
> -       guest_test_phys_mem &= ~(perf_test_args.host_page_size - 1);
> +       guest_test_phys_mem = align_down(guest_test_phys_mem, perf_test_args.host_page_size);
>  #ifdef __s390x__
>         /* Align to 1M (segment size) */
> -       guest_test_phys_mem &= ~((1 << 20) - 1);
> +       guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
>  #endif
>         pr_info("guest physical test memory offset: 0x%lx\n", guest_test_phys_mem);
>
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages
  2021-11-11  0:03 ` [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages David Matlack
@ 2021-11-11 17:49   ` Ben Gardon
  2021-11-11 19:21     ` Sean Christopherson
  0 siblings, 1 reply; 19+ messages in thread
From: Ben Gardon @ 2021-11-11 17:49 UTC (permalink / raw)
  To: David Matlack
  Cc: Paolo Bonzini, kvm, Sean Christopherson, Andrew Jones,
	Jim Mattson, Yanan Wang, Peter Xu, Aaron Lewis

On Wed, Nov 10, 2021 at 4:03 PM David Matlack <dmatlack@google.com> wrote:
>
> From: Sean Christopherson <seanjc@google.com>
>
> Assert that the GPA for a memslot backed by a hugepage is aligned to
> the hugepage size and fix perf_test_util accordingly.  Lack of GPA
> alignment prevents KVM from backing the guest with hugepages, e.g. x86's
> write-protection of hugepages when dirty logging is activated is
> otherwise not exercised.
>
> Add a comment explaining that guest_page_size is for non-huge pages to
> try and avoid confusion about what it actually tracks.
>
> Cc: Ben Gardon <bgardon@google.com>
> Cc: Yanan Wang <wangyanan55@huawei.com>
> Cc: Andrew Jones <drjones@redhat.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Aaron Lewis <aaronlewis@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> [Used get_backing_src_pagesz() to determine alignment dynamically.]
> Signed-off-by: David Matlack <dmatlack@google.com>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c       | 2 ++
>  tools/testing/selftests/kvm/lib/perf_test_util.c | 7 ++++++-
>  2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 07f37456bba0..1f6a01c33dce 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -875,6 +875,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>         if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
>                 alignment = max(backing_src_pagesz, alignment);
>
> +       ASSERT_EQ(guest_paddr, align_up(guest_paddr, backing_src_pagesz));
> +
>         /* Add enough memory to align up if necessary */
>         if (alignment > 1)
>                 region->mmap_size += alignment;
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index 6b8d5020dc54..a015f267d945 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -55,11 +55,16 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>  {
>         struct kvm_vm *vm;
>         uint64_t guest_num_pages;
> +       uint64_t backing_src_pagesz = get_backing_src_pagesz(backing_src);
>         int i;
>
>         pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
>
>         perf_test_args.host_page_size = getpagesize();
> +       /*
> +        * Snapshot the non-huge page size.  This is used by the guest code to
> +        * access/dirty pages at the logging granularity.
> +        */
>         perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size;

Is this comment correct? I wouldn't expect the guest page size to
determine the host dirty logging granularity.

>
>         guest_num_pages = vm_adjust_num_guest_pages(mode,
> @@ -92,7 +97,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>
>         guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
>                               perf_test_args.guest_page_size;
> -       guest_test_phys_mem = align_down(guest_test_phys_mem, perf_test_args.host_page_size);
> +       guest_test_phys_mem = align_down(guest_test_phys_mem, backing_src_pagesz);
>  #ifdef __s390x__
>         /* Align to 1M (segment size) */
>         guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation
  2021-11-11  0:03 ` [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation David Matlack
@ 2021-11-11 17:53   ` Ben Gardon
  0 siblings, 0 replies; 19+ messages in thread
From: Ben Gardon @ 2021-11-11 17:53 UTC (permalink / raw)
  To: David Matlack
  Cc: Paolo Bonzini, kvm, Sean Christopherson, Andrew Jones,
	Jim Mattson, Yanan Wang, Peter Xu, Aaron Lewis

On Wed, Nov 10, 2021 at 4:03 PM David Matlack <dmatlack@google.com> wrote:
>
> From: Sean Christopherson <seanjc@google.com>
>
> Fill the per-vCPU args when creating the perf_test VM instead of having
> the caller do so.  This helps ensure that any adjustments to the number
> of pages (and thus vcpu_memory_bytes) are reflected in the per-VM args.
> Automatically filling the per-vCPU args will also allow a future patch
> to do the sync to the guest during creation.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> [Updated access_tracking_perf_test as well.]
> Signed-off-by: David Matlack <dmatlack@google.com>

Reviewed-by: Ben Gardon <bgardon@google.com>

> ---
>  .../selftests/kvm/access_tracking_perf_test.c |  5 +-
>  .../selftests/kvm/demand_paging_test.c        |  5 +-
>  .../selftests/kvm/dirty_log_perf_test.c       |  6 +-
>  .../selftests/kvm/include/perf_test_util.h    |  6 +-
>  .../selftests/kvm/lib/perf_test_util.c        | 71 ++++++++++---------
>  .../kvm/memslot_modification_stress_test.c    |  6 +-
>  6 files changed, 45 insertions(+), 54 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
> index 5d95113c7b7c..fdef6c906388 100644
> --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
> +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
> @@ -332,10 +332,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         int vcpus = params->vcpus;
>
>         vm = perf_test_create_vm(mode, vcpus, params->vcpu_memory_bytes, 1,
> -                                params->backing_src);
> -
> -       perf_test_setup_vcpus(vm, vcpus, params->vcpu_memory_bytes,
> -                             !overlap_memory_access);
> +                                params->backing_src, !overlap_memory_access);
>
>         vcpu_threads = create_vcpu_threads(vcpus);
>
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index 3c729a0a1ab1..0fee44f5e5ae 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -293,7 +293,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         int r;
>
>         vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
> -                                p->src_type);
> +                                p->src_type, p->partition_vcpu_memory_access);
>
>         perf_test_args.wr_fract = 1;
>
> @@ -307,9 +307,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
>         TEST_ASSERT(vcpu_threads, "Memory allocation failed");
>
> -       perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size,
> -                             p->partition_vcpu_memory_access);
> -
>         if (p->uffd_mode) {
>                 uffd_handler_threads =
>                         malloc(nr_vcpus * sizeof(*uffd_handler_threads));
> diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
> index 7ffab5bd5ce5..62f9cc2a3146 100644
> --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
> @@ -186,7 +186,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         struct timespec clear_dirty_log_total = (struct timespec){0};
>
>         vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size,
> -                                p->slots, p->backing_src);
> +                                p->slots, p->backing_src,
> +                                p->partition_vcpu_memory_access);
>
>         perf_test_args.wr_fract = p->wr_fract;
>
> @@ -206,9 +207,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
>         TEST_ASSERT(vcpu_threads, "Memory allocation failed");
>
> -       perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size,
> -                             p->partition_vcpu_memory_access);
> -
>         sync_global_to_guest(vm, perf_test_args);
>
>         /* Start the iterations */
> diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
> index 9348580dc5be..91804be1cf53 100644
> --- a/tools/testing/selftests/kvm/include/perf_test_util.h
> +++ b/tools/testing/selftests/kvm/include/perf_test_util.h
> @@ -39,10 +39,8 @@ extern struct perf_test_args perf_test_args;
>
>  struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>                                    uint64_t vcpu_memory_bytes, int slots,
> -                                  enum vm_mem_backing_src_type backing_src);
> +                                  enum vm_mem_backing_src_type backing_src,
> +                                  bool partition_vcpu_memory_access);
>  void perf_test_destroy_vm(struct kvm_vm *vm);
> -void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
> -                          uint64_t vcpu_memory_bytes,
> -                          bool partition_vcpu_memory_access);
>
>  #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index b3154b5b0cfd..13c8bc22f4e1 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -48,9 +48,43 @@ static void guest_code(uint32_t vcpu_id)
>         }
>  }
>
> +void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
> +                          uint64_t vcpu_memory_bytes,
> +                          bool partition_vcpu_memory_access)
> +{
> +       struct perf_test_args *pta = &perf_test_args;
> +       struct perf_test_vcpu_args *vcpu_args;
> +       int vcpu_id;
> +
> +       for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
> +               vcpu_args = &pta->vcpu_args[vcpu_id];
> +
> +               vcpu_args->vcpu_id = vcpu_id;
> +               if (partition_vcpu_memory_access) {
> +                       vcpu_args->gva = guest_test_virt_mem +
> +                                        (vcpu_id * vcpu_memory_bytes);
> +                       vcpu_args->pages = vcpu_memory_bytes /
> +                                          pta->guest_page_size;
> +                       vcpu_args->gpa = pta->gpa + (vcpu_id * vcpu_memory_bytes);
> +               } else {
> +                       vcpu_args->gva = guest_test_virt_mem;
> +                       vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
> +                                          pta->guest_page_size;
> +                       vcpu_args->gpa = pta->gpa;
> +               }
> +
> +               vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
> +
> +               pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
> +                        vcpu_id, vcpu_args->gpa, vcpu_args->gpa +
> +                        (vcpu_args->pages * pta->guest_page_size));
> +       }
> +}
> +
>  struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>                                    uint64_t vcpu_memory_bytes, int slots,
> -                                  enum vm_mem_backing_src_type backing_src)
> +                                  enum vm_mem_backing_src_type backing_src,
> +                                  bool partition_vcpu_memory_access)
>  {
>         struct perf_test_args *pta = &perf_test_args;
>         struct kvm_vm *vm;
> @@ -119,6 +153,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>         /* Do mapping for the demand paging memory slot */
>         virt_map(vm, guest_test_virt_mem, pta->gpa, guest_num_pages);
>
> +       perf_test_setup_vcpus(vm, vcpus, vcpu_memory_bytes, partition_vcpu_memory_access);
> +
>         ucall_init(vm, NULL);
>
>         return vm;
> @@ -129,36 +165,3 @@ void perf_test_destroy_vm(struct kvm_vm *vm)
>         ucall_uninit(vm);
>         kvm_vm_free(vm);
>  }
> -
> -void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
> -                          uint64_t vcpu_memory_bytes,
> -                          bool partition_vcpu_memory_access)
> -{
> -       struct perf_test_args *pta = &perf_test_args;
> -       struct perf_test_vcpu_args *vcpu_args;
> -       int vcpu_id;
> -
> -       for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
> -               vcpu_args = &pta->vcpu_args[vcpu_id];
> -
> -               vcpu_args->vcpu_id = vcpu_id;
> -               if (partition_vcpu_memory_access) {
> -                       vcpu_args->gva = guest_test_virt_mem +
> -                                        (vcpu_id * vcpu_memory_bytes);
> -                       vcpu_args->pages = vcpu_memory_bytes /
> -                                          pta->guest_page_size;
> -                       vcpu_args->gpa = pta->gpa + (vcpu_id * vcpu_memory_bytes);
> -               } else {
> -                       vcpu_args->gva = guest_test_virt_mem;
> -                       vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
> -                                          pta->guest_page_size;
> -                       vcpu_args->gpa = pta->gpa;
> -               }
> -
> -               vcpu_args_set(vm, vcpu_id, 1, vcpu_id);
> -
> -               pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
> -                        vcpu_id, vcpu_args->gpa, vcpu_args->gpa +
> -                        (vcpu_args->pages * pta->guest_page_size));
> -       }
> -}
> diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> index d105180d5e8c..27af0bb8deb7 100644
> --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> @@ -105,16 +105,14 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         int vcpu_id;
>
>         vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
> -                                VM_MEM_SRC_ANONYMOUS);
> +                                VM_MEM_SRC_ANONYMOUS,
> +                                p->partition_vcpu_memory_access);
>
>         perf_test_args.wr_fract = 1;
>
>         vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
>         TEST_ASSERT(vcpu_threads, "Memory allocation failed");
>
> -       perf_test_setup_vcpus(vm, nr_vcpus, guest_percpu_mem_size,
> -                             p->partition_vcpu_memory_access);
> -
>         /* Export the shared variables to the guest */
>         sync_global_to_guest(vm, perf_test_args);
>
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during VM creation
  2021-11-11  0:03 ` [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during " David Matlack
@ 2021-11-11 17:55   ` Ben Gardon
  0 siblings, 0 replies; 19+ messages in thread
From: Ben Gardon @ 2021-11-11 17:55 UTC (permalink / raw)
  To: David Matlack
  Cc: Paolo Bonzini, kvm, Sean Christopherson, Andrew Jones,
	Jim Mattson, Yanan Wang, Peter Xu, Aaron Lewis

On Wed, Nov 10, 2021 at 4:03 PM David Matlack <dmatlack@google.com> wrote:
>
> From: Sean Christopherson <seanjc@google.com>
>
> Copy perf_test_args to the guest during VM creation instead of relying on
> the caller to do so at their leisure.  Ideally, tests wouldn't even be
> able to modify perf_test_args, i.e. they would have no motivation to do
> the sync, but enforcing that is arguably a net negative for readability.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> [Set wr_fract=1 by default and add helper to override it since the new
>  access_tracking_perf_test needs to set it dynamically.]
> Signed-off-by: David Matlack <dmatlack@google.com>

Reviewed-by: Ben Gardon <bgardon@google.com>

> ---
>  .../selftests/kvm/access_tracking_perf_test.c        |  3 +--
>  tools/testing/selftests/kvm/demand_paging_test.c     |  5 -----
>  tools/testing/selftests/kvm/dirty_log_perf_test.c    |  4 +---
>  tools/testing/selftests/kvm/include/perf_test_util.h |  2 ++
>  tools/testing/selftests/kvm/lib/perf_test_util.c     | 12 ++++++++++++
>  .../selftests/kvm/memslot_modification_stress_test.c |  5 -----
>  6 files changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/access_tracking_perf_test.c b/tools/testing/selftests/kvm/access_tracking_perf_test.c
> index fdef6c906388..5364a2ed7c68 100644
> --- a/tools/testing/selftests/kvm/access_tracking_perf_test.c
> +++ b/tools/testing/selftests/kvm/access_tracking_perf_test.c
> @@ -277,8 +277,7 @@ static void run_iteration(struct kvm_vm *vm, int vcpus, const char *description)
>  static void access_memory(struct kvm_vm *vm, int vcpus, enum access_type access,
>                           const char *description)
>  {
> -       perf_test_args.wr_fract = (access == ACCESS_READ) ? INT_MAX : 1;
> -       sync_global_to_guest(vm, perf_test_args);
> +       perf_test_set_wr_fract(vm, (access == ACCESS_READ) ? INT_MAX : 1);
>         iteration_work = ITERATION_ACCESS_MEMORY;
>         run_iteration(vm, vcpus, description);
>  }
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index 0fee44f5e5ae..26f8fd8a57ec 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -295,8 +295,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         vm = perf_test_create_vm(mode, nr_vcpus, guest_percpu_mem_size, 1,
>                                  p->src_type, p->partition_vcpu_memory_access);
>
> -       perf_test_args.wr_fract = 1;
> -
>         demand_paging_size = get_backing_src_pagesz(p->src_type);
>
>         guest_data_prototype = malloc(demand_paging_size);
> @@ -345,9 +343,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>                 }
>         }
>
> -       /* Export the shared variables to the guest */
> -       sync_global_to_guest(vm, perf_test_args);
> -
>         pr_info("Finished creating vCPUs and starting uffd threads\n");
>
>         clock_gettime(CLOCK_MONOTONIC, &start);
> diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c b/tools/testing/selftests/kvm/dirty_log_perf_test.c
> index 62f9cc2a3146..583b4d95aa98 100644
> --- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
> @@ -189,7 +189,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>                                  p->slots, p->backing_src,
>                                  p->partition_vcpu_memory_access);
>
> -       perf_test_args.wr_fract = p->wr_fract;
> +       perf_test_set_wr_fract(vm, p->wr_fract);
>
>         guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm_get_page_shift(vm);
>         guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
> @@ -207,8 +207,6 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>         vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
>         TEST_ASSERT(vcpu_threads, "Memory allocation failed");
>
> -       sync_global_to_guest(vm, perf_test_args);
> -
>         /* Start the iterations */
>         iteration = 0;
>         host_quit = false;
> diff --git a/tools/testing/selftests/kvm/include/perf_test_util.h b/tools/testing/selftests/kvm/include/perf_test_util.h
> index 91804be1cf53..74e3622b3a6e 100644
> --- a/tools/testing/selftests/kvm/include/perf_test_util.h
> +++ b/tools/testing/selftests/kvm/include/perf_test_util.h
> @@ -43,4 +43,6 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>                                    bool partition_vcpu_memory_access);
>  void perf_test_destroy_vm(struct kvm_vm *vm);
>
> +void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract);
> +
>  #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index 13c8bc22f4e1..77f9eb5667c9 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -94,6 +94,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>
>         pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
>
> +       /* By default vCPUs will write to memory. */
> +       pta->wr_fract = 1;
> +
>         /*
>          * Snapshot the non-huge page size.  This is used by the guest code to
>          * access/dirty pages at the logging granularity.
> @@ -157,6 +160,9 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
>
>         ucall_init(vm, NULL);
>
> +       /* Export the shared variables to the guest. */
> +       sync_global_to_guest(vm, perf_test_args);
> +
>         return vm;
>  }
>
> @@ -165,3 +171,9 @@ void perf_test_destroy_vm(struct kvm_vm *vm)
>         ucall_uninit(vm);
>         kvm_vm_free(vm);
>  }
> +
> +void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract)
> +{
> +       perf_test_args.wr_fract = wr_fract;
> +       sync_global_to_guest(vm, perf_test_args);
> +}
> diff --git a/tools/testing/selftests/kvm/memslot_modification_stress_test.c b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> index 27af0bb8deb7..df431d0da1ee 100644
> --- a/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> +++ b/tools/testing/selftests/kvm/memslot_modification_stress_test.c
> @@ -108,14 +108,9 @@ static void run_test(enum vm_guest_mode mode, void *arg)
>                                  VM_MEM_SRC_ANONYMOUS,
>                                  p->partition_vcpu_memory_access);
>
> -       perf_test_args.wr_fract = 1;
> -
>         vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
>         TEST_ASSERT(vcpu_threads, "Memory allocation failed");
>
> -       /* Export the shared variables to the guest */
> -       sync_global_to_guest(vm, perf_test_args);
> -
>         pr_info("Finished creating vCPUs\n");
>
>         for (vcpu_id = 0; vcpu_id < nr_vcpus; vcpu_id++)
> --
> 2.34.0.rc1.387.gb447b232ab-goog
>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages
  2021-11-11 17:49   ` Ben Gardon
@ 2021-11-11 19:21     ` Sean Christopherson
  0 siblings, 0 replies; 19+ messages in thread
From: Sean Christopherson @ 2021-11-11 19:21 UTC (permalink / raw)
  To: Ben Gardon
  Cc: David Matlack, Paolo Bonzini, kvm, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis

On Thu, Nov 11, 2021, Ben Gardon wrote:
> On Wed, Nov 10, 2021 at 4:03 PM David Matlack <dmatlack@google.com> wrote:
> >
> > From: Sean Christopherson <seanjc@google.com>
> >
> > Assert that the GPA for a memslot backed by a hugepage is aligned to
> > the hugepage size and fix perf_test_util accordingly.  Lack of GPA
> > alignment prevents KVM from backing the guest with hugepages, e.g. x86's
> > write-protection of hugepages when dirty logging is activated is
> > otherwise not exercised.
> >
> > Add a comment explaining that guest_page_size is for non-huge pages to
> > try and avoid confusion about what it actually tracks.
> >
> > Cc: Ben Gardon <bgardon@google.com>
> > Cc: Yanan Wang <wangyanan55@huawei.com>
> > Cc: Andrew Jones <drjones@redhat.com>
> > Cc: Peter Xu <peterx@redhat.com>
> > Cc: Aaron Lewis <aaronlewis@google.com>
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > [Used get_backing_src_pagesz() to determine alignment dynamically.]
> > Signed-off-by: David Matlack <dmatlack@google.com>
> > ---
> >  tools/testing/selftests/kvm/lib/kvm_util.c       | 2 ++
> >  tools/testing/selftests/kvm/lib/perf_test_util.c | 7 ++++++-
> >  2 files changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> > index 07f37456bba0..1f6a01c33dce 100644
> > --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> > @@ -875,6 +875,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
> >         if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
> >                 alignment = max(backing_src_pagesz, alignment);
> >
> > +       ASSERT_EQ(guest_paddr, align_up(guest_paddr, backing_src_pagesz));
> > +
> >         /* Add enough memory to align up if necessary */
> >         if (alignment > 1)
> >                 region->mmap_size += alignment;
> > diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> > index 6b8d5020dc54..a015f267d945 100644
> > --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> > +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> > @@ -55,11 +55,16 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
> >  {
> >         struct kvm_vm *vm;
> >         uint64_t guest_num_pages;
> > +       uint64_t backing_src_pagesz = get_backing_src_pagesz(backing_src);
> >         int i;
> >
> >         pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
> >
> >         perf_test_args.host_page_size = getpagesize();
> > +       /*
> > +        * Snapshot the non-huge page size.  This is used by the guest code to
> > +        * access/dirty pages at the logging granularity.
> > +        */
> >         perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size;
> 
> Is this comment correct? I wouldn't expect the guest page size to
> determine the host dirty logging granularity.

"guest page size" is a bit of a misnomer.  It's not the page size of the guest's
page tables, rather it's the non-huge page size of the PTEs that KVM uses to map
guest memory.  That info is exposed to the guest so that the guest and host agree
on the stride.

> >         guest_num_pages = vm_adjust_num_guest_pages(mode,
> > @@ -92,7 +97,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
> >
> >         guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
> >                               perf_test_args.guest_page_size;
> > -       guest_test_phys_mem = align_down(guest_test_phys_mem, perf_test_args.host_page_size);
> > +       guest_test_phys_mem = align_down(guest_test_phys_mem, backing_src_pagesz);
> >  #ifdef __s390x__
> >         /* Align to 1M (segment size) */
> >         guest_test_phys_mem = align_down(guest_test_phys_mem, 1 << 20);
> > --
> > 2.34.0.rc1.387.gb447b232ab-goog
> >

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups
  2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
                   ` (11 preceding siblings ...)
  2021-11-11  0:03 ` [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during " David Matlack
@ 2021-11-16 11:12 ` Paolo Bonzini
  12 siblings, 0 replies; 19+ messages in thread
From: Paolo Bonzini @ 2021-11-16 11:12 UTC (permalink / raw)
  To: David Matlack
  Cc: kvm, Sean Christopherson, Ben Gardon, Andrew Jones, Jim Mattson,
	Yanan Wang, Peter Xu, Aaron Lewis

On 11/11/21 01:02, David Matlack wrote:
> Fix hugepage bugs in the KVM selftests that specifically affect dirty
> logging and demand paging tests.  Found while attempting to verify KVM
> changes/fixes related to hugepages and dirty logging (patches incoming in
> a separate series).
> 
> Clean up the perf_test_args util on top of the hugepage fixes to clarify
> what "page size" means, and to improve confidence in the code doing what
> it thinks it's doing.  In a few cases, users of perf_test_args were
> duplicating (approximating?) calculations made by perf_test_args, and it
> wasn't obvious that both pieces of code were guaranteed to end up with the
> same result.

Queued, thanks.

Paolo

> v2:
> - Add separate align up/down helpers and use the throughout the series
>    rather than openly coding the bitwise math [Ben, Paolo]
> - Do no pad HugeTLB mmaps [Yanan]
> - Drop "[PATCH 04/15] KVM: selftests: Force stronger HVA alignment (1gb)
>    for hugepages" since HugeTLB does not require manual HVA alignment
>    [David]
> - Drop "[PATCH 15/15] KVM: selftests: Get rid of gorilla math in memslots
>    modification test" since the gorilla math no longer exists [David]
> - Drop "[PATCH 14/15] KVM: selftests: Track size of per-VM memslot in
>    perf_test_args" since it was just a prep patch for [PATCH 15/15]
>    [David]
> - Update the series to kvm/next [David]
> 
> v1: https://lore.kernel.org/kvm/20210210230625.550939-1-seanjc@google.com/.
> 
> Sean Christopherson (12):
>    KVM: selftests: Explicitly state indicies for vm_guest_mode_params
>      array
>    KVM: selftests: Expose align() helpers to tests
>    KVM: selftests: Assert mmap HVA is aligned when using HugeTLB
>    KVM: selftests: Require GPA to be aligned when backed by hugepages
>    KVM: selftests: Use shorthand local var to access struct
>      perf_tests_args
>    KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args
>    KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging
>      test
>    KVM: selftests: Move per-VM GPA into perf_test_args
>    KVM: selftests: Remove perf_test_args.host_page_size
>    KVM: selftests: Create VM with adjusted number of guest pages for perf
>      tests
>    KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation
>    KVM: selftests: Sync perf_test_args to guest during VM creation
> 
>   .../selftests/kvm/access_tracking_perf_test.c |   8 +-
>   .../selftests/kvm/demand_paging_test.c        |  31 +----
>   .../selftests/kvm/dirty_log_perf_test.c       |  10 +-
>   tools/testing/selftests/kvm/dirty_log_test.c  |   6 +-
>   .../selftests/kvm/include/perf_test_util.h    |  18 +--
>   .../testing/selftests/kvm/include/test_util.h |  26 ++++
>   .../selftests/kvm/kvm_page_table_test.c       |   2 +-
>   tools/testing/selftests/kvm/lib/elf.c         |   3 +-
>   tools/testing/selftests/kvm/lib/kvm_util.c    |  44 +++---
>   .../selftests/kvm/lib/perf_test_util.c        | 126 ++++++++++--------
>   tools/testing/selftests/kvm/lib/test_util.c   |   5 +
>   .../kvm/memslot_modification_stress_test.c    |  13 +-
>   12 files changed, 153 insertions(+), 139 deletions(-)
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2021-11-16 11:13 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11  0:02 [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups David Matlack
2021-11-11  0:02 ` [PATCH v2 01/12] KVM: selftests: Explicitly state indicies for vm_guest_mode_params array David Matlack
2021-11-11  0:03 ` [PATCH v2 02/12] KVM: selftests: Expose align() helpers to tests David Matlack
2021-11-11 17:43   ` Ben Gardon
2021-11-11  0:03 ` [PATCH v2 03/12] KVM: selftests: Assert mmap HVA is aligned when using HugeTLB David Matlack
2021-11-11  0:03 ` [PATCH v2 04/12] KVM: selftests: Require GPA to be aligned when backed by hugepages David Matlack
2021-11-11 17:49   ` Ben Gardon
2021-11-11 19:21     ` Sean Christopherson
2021-11-11  0:03 ` [PATCH v2 05/12] KVM: selftests: Use shorthand local var to access struct perf_tests_args David Matlack
2021-11-11  0:03 ` [PATCH v2 06/12] KVM: selftests: Capture per-vCPU GPA in perf_test_vcpu_args David Matlack
2021-11-11  0:03 ` [PATCH v2 07/12] KVM: selftests: Use perf util's per-vCPU GPA/pages in demand paging test David Matlack
2021-11-11  0:03 ` [PATCH v2 08/12] KVM: selftests: Move per-VM GPA into perf_test_args David Matlack
2021-11-11  0:03 ` [PATCH v2 09/12] KVM: selftests: Remove perf_test_args.host_page_size David Matlack
2021-11-11  0:03 ` [PATCH v2 10/12] KVM: selftests: Create VM with adjusted number of guest pages for perf tests David Matlack
2021-11-11  0:03 ` [PATCH v2 11/12] KVM: selftests: Fill per-vCPU struct during "perf_test" VM creation David Matlack
2021-11-11 17:53   ` Ben Gardon
2021-11-11  0:03 ` [PATCH v2 12/12] KVM: selftests: Sync perf_test_args to guest during " David Matlack
2021-11-11 17:55   ` Ben Gardon
2021-11-16 11:12 ` [PATCH v2 00/12] KVM: selftests: Hugepage fixes and cleanups Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).