Skip to contentSkip to conversation

KVM: selftests: Fix 32-bit truncation of vm_get_max_gfn()

PATCH Applied David Matlack 6 participants 13 messages May 21, 2021 – Jun 8, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: selftests: Fix 32-bit truncation of vm_get_max_gfn()

vm_get_max_gfn() casts vm->max_gfn from a uint64_t to an unsigned int, which causes the upper 32-bits of the max_gfn to get truncated.

Nobody noticed until now likely because vm_get_max_gfn() is only used as a mechanism to create a memslot in an unused region of the guest physical address space (the top), and the top of the 32-bit physical address space was always good enough.

This fix reveals a bug in memslot_modification_stress_test which was trying to create a dummy memslot past the end of guest physical memory. Fix that by moving the dummy memslot lower.

Fixes 52200d0d944e ("KVM: selftests: Remove duplicate guest mode handling")

---

v1 -> v2:
- Added Venkatesh's R-b line.
- Used PRIx64 to print uint64_t instead of %lx.

 tools/testing/selftests/kvm/include/kvm_util.h |  2 +-
 tools/testing/selftests/kvm/lib/kvm_util.c     |  2 +-
 .../testing/selftests/kvm/lib/perf_test_util.c |  4 +++-
 .../kvm/memslot_modification_stress_test.c     | 18 +++++++++++-------
 4 files changed, 16 insertions(+), 10 deletions(-)
tools/testing/selftests/kvm/include/kvm_util.h +1 -1
index 84982eb02b29..5d9b35d09251 100644
@@ -303,7 +303,7 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm);
 
 unsigned int vm_get_page_size(struct kvm_vm *vm);
 unsigned int vm_get_page_shift(struct kvm_vm *vm);
-unsigned int vm_get_max_gfn(struct kvm_vm *vm);
+uint64_t vm_get_max_gfn(struct kvm_vm *vm);
 int vm_get_fd(struct kvm_vm *vm);
 
 unsigned int vm_calc_num_guest_pages(enum vm_guest_mode mode, size_t size);
tools/testing/selftests/kvm/lib/kvm_util.c +1 -1
index 1af1009254c4..aeffbb1e7c7d 100644
@@ -2058,7 +2058,7 @@ unsigned int vm_get_page_shift(struct kvm_vm *vm)
 	return vm->page_shift;
 }
 
-unsigned int vm_get_max_gfn(struct kvm_vm *vm)
+uint64_t vm_get_max_gfn(struct kvm_vm *vm)
 {
 	return vm->max_gfn;
 }
tools/testing/selftests/kvm/lib/perf_test_util.c +3 -1
index 81490b9b4e32..abf381800a59 100644
@@ -2,6 +2,7 @@
 /*
  * Copyright (C) 2020, Google LLC.
  */
+#include <inttypes.h>
 
 #include "kvm_util.h"
 #include "perf_test_util.h"
@@ -80,7 +81,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
 	 */
 	TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
 		    "Requested more guest memory than address space allows.\n"
-		    "    guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n",
+		    "    guest pages: %" PRIx64 " max gfn: %" PRIx64
+		    " vcpus: %d wss: %" PRIx64 "]\n",
 		    guest_num_pages, vm_get_max_gfn(vm), vcpus,
 		    vcpu_memory_bytes);
 
tools/testing/selftests/kvm/memslot_modification_stress_test.c +11 -7
index 6096bf0a5b34..98351ba0933c 100644
@@ -71,14 +71,22 @@ struct memslot_antagonist_args {
 };
 
 static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay,
-			      uint64_t nr_modifications, uint64_t gpa)
+			       uint64_t nr_modifications)
 {
+	const uint64_t pages = 1;
+	uint64_t gpa;
 	int i;
 
+	/*
+	 * 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);
+
 	for (i = 0; i < nr_modifications; i++) {
 		usleep(delay);
 		vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, gpa,
-					    DUMMY_MEMSLOT_INDEX, 1, 0);
+					    DUMMY_MEMSLOT_INDEX, pages, 0);
 
 		vm_mem_region_delete(vm, DUMMY_MEMSLOT_INDEX);
 	}
@@ -120,11 +128,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
 	pr_info("Started all vCPUs\n");
 
 	add_remove_memslot(vm, p->memslot_modification_delay,
-			   p->nr_memslot_modifications,
-			   guest_test_phys_mem +
-			   (guest_percpu_mem_size * nr_vcpus) +
-			   perf_test_args.host_page_size +
-			   perf_test_args.guest_page_size);
+			   p->nr_memslot_modifications);
 
 	run_vcpus = false;
 
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · David Matlack

vm_get_max_gfn() casts vm->max_gfn from a uint64_t to an unsigned int, which causes the upper 32-bits of the max_gfn to get truncated.

Nobody noticed until now likely because vm_get_max_gfn() is only used as a mechanism to create a memslot in an unused region of the guest physical address space (the top), and the top of the 32-bit physical address space was always good enough.

Quoted 7 lines

This fix reveals a bug in memslot_modification_stress_test which was trying to create a dummy memslot past the end of guest physical memory. Fix that by moving the dummy memslot lower.

Fixes 52200d0d944e ("KVM: selftests: Remove duplicate guest mode handling")
Signature · 1 line
Peter Xu
Reviewed-by on v2 1/1
#2 lore raw
In reply to David Matlack
Quoted 21 lines · David Matlack

vm_get_max_gfn() casts vm->max_gfn from a uint64_t to an unsigned int, which causes the upper 32-bits of the max_gfn to get truncated.

Nobody noticed until now likely because vm_get_max_gfn() is only used as a mechanism to create a memslot in an unused region of the guest physical address space (the top), and the top of the 32-bit physical address space was always good enough.

This fix reveals a bug in memslot_modification_stress_test which was trying to create a dummy memslot past the end of guest physical memory. Fix that by moving the dummy memslot lower.

Fixes 52200d0d944e ("KVM: selftests: Remove duplicate guest mode handling")

---

v1 -> v2:
- Added Venkatesh's R-b line.
- Used PRIx64 to print uint64_t instead of %lx.

Quoted 6 lines
 tools/testing/selftests/kvm/include/kvm_util.h |  2 +-
 tools/testing/selftests/kvm/lib/kvm_util.c     |  2 +-
 .../testing/selftests/kvm/lib/perf_test_util.c |  4 +++-
 .../kvm/memslot_modification_stress_test.c     | 18 +++++++++++-------
 4 files changed, 16 insertions(+), 10 deletions(-)

Thanks,
drew

maintainer Applied
#3 lore raw
In reply to David Matlack
Quoted 108 lines · David Matlack

vm_get_max_gfn() casts vm->max_gfn from a uint64_t to an unsigned int, which causes the upper 32-bits of the max_gfn to get truncated.

Nobody noticed until now likely because vm_get_max_gfn() is only used as a mechanism to create a memslot in an unused region of the guest physical address space (the top), and the top of the 32-bit physical address space was always good enough.

This fix reveals a bug in memslot_modification_stress_test which was trying to create a dummy memslot past the end of guest physical memory. Fix that by moving the dummy memslot lower.

Fixes 52200d0d944e ("KVM: selftests: Remove duplicate guest mode handling")

---

v1 -> v2:
- Added Venkatesh's R-b line.
- Used PRIx64 to print uint64_t instead of %lx.

  tools/testing/selftests/kvm/include/kvm_util.h |  2 +-
  tools/testing/selftests/kvm/lib/kvm_util.c     |  2 +-
  .../testing/selftests/kvm/lib/perf_test_util.c |  4 +++-
  .../kvm/memslot_modification_stress_test.c     | 18 +++++++++++-------
  4 files changed, 16 insertions(+), 10 deletions(-)
tools/testing/selftests/kvm/include/kvm_util.h +1 -1
index 84982eb02b29..5d9b35d09251 100644
@@ -303,7 +303,7 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm);
 
  unsigned int vm_get_page_size(struct kvm_vm *vm);
  unsigned int vm_get_page_shift(struct kvm_vm *vm);
-unsigned int vm_get_max_gfn(struct kvm_vm *vm);
+uint64_t vm_get_max_gfn(struct kvm_vm *vm);
  int vm_get_fd(struct kvm_vm *vm);
 
  unsigned int vm_calc_num_guest_pages(enum vm_guest_mode mode, size_t size);
tools/testing/selftests/kvm/lib/kvm_util.c +1 -1
index 1af1009254c4..aeffbb1e7c7d 100644
@@ -2058,7 +2058,7 @@ unsigned int vm_get_page_shift(struct kvm_vm *vm)
  	return vm->page_shift;
  }
 
-unsigned int vm_get_max_gfn(struct kvm_vm *vm)
+uint64_t vm_get_max_gfn(struct kvm_vm *vm)
  {
  	return vm->max_gfn;
  }
tools/testing/selftests/kvm/lib/perf_test_util.c +3 -1
index 81490b9b4e32..abf381800a59 100644
@@ -2,6 +2,7 @@
  /*
   * Copyright (C) 2020, Google LLC.
   */
+#include <inttypes.h>
 
  #include "kvm_util.h"
  #include "perf_test_util.h"
@@ -80,7 +81,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
  	 */
  	TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
  		    "Requested more guest memory than address space allows.\n"
-		    "    guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n",
+		    "    guest pages: %" PRIx64 " max gfn: %" PRIx64
+		    " vcpus: %d wss: %" PRIx64 "]\n",
  		    guest_num_pages, vm_get_max_gfn(vm), vcpus,
  		    vcpu_memory_bytes);
 
tools/testing/selftests/kvm/memslot_modification_stress_test.c +10 -2
index 6096bf0a5b34..98351ba0933c 100644
@@ -71,14 +71,22 @@ struct memslot_antagonist_args {
  };
 
  static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay,
-			      uint64_t nr_modifications, uint64_t gpa)
+			       uint64_t nr_modifications)
  {
+	const uint64_t pages = 1;
+	uint64_t gpa;
  	int i;
 
+	/*
+	 * 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);
+
  	for (i = 0; i < nr_modifications; i++) {
  		usleep(delay);
  		vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, gpa,
-					    DUMMY_MEMSLOT_INDEX, 1, 0);
+					    DUMMY_MEMSLOT_INDEX, pages, 0);
 
  		vm_mem_region_delete(vm, DUMMY_MEMSLOT_INDEX);
  	}
@@ -120,11 +128,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
  	pr_info("Started all vCPUs\n");
 

tools/testing/selftests/kvm/memslot_modification_stress_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 134

Quoted 10 lines
tools/testing/selftests/kvm/memslot_modification_stress_test.c +1 -5
  	add_remove_memslot(vm, p->memslot_modification_delay,
-			   p->nr_memslot_modifications,
-			   guest_test_phys_mem +
-			   (guest_percpu_mem_size * nr_vcpus) +
-			   perf_test_args.host_page_size +
-			   perf_test_args.guest_page_size);
+			   p->nr_memslot_modifications);
 
  	run_vcpus = false;
 

Queued, thanks.

Paolo

#4 lore raw
In reply to David Matlack
Quoted 8 lines · David Matlack

vm_get_max_gfn() casts vm->max_gfn from a uint64_t to an unsigned int, which causes the upper 32-bits of the max_gfn to get truncated.

Nobody noticed until now likely because vm_get_max_gfn() is only used as a mechanism to create a memslot in an unused region of the guest physical address space (the top), and the top of the 32-bit physical address space was always good enough.

Quoted 7 lines

This fix reveals a bug in memslot_modification_stress_test which was trying to create a dummy memslot past the end of guest physical memory. Fix that by moving the dummy memslot lower.

Fixes 52200d0d944e ("KVM: selftests: Remove duplicate guest mode handling")

As a heads up:
I have not yet looked into this, but this broke demand_paging_test and kvm_page_table_test on s390:

not ok 4 selftests: kvm: demand_paging_test # exit=254 # selftests: kvm: dirty_log_test
# ==== Test Assertion Failure ====
# lib/kvm_util.c:900: ret == 0
# pid=245410 tid=245410 errno=22 - Invalid argument

#      1	0x0000000001005457: vm_userspace_mem_region_add at kvm_util.c:900
#      2	0x0000000001002cbf: run_test at dirty_log_test.c:757
#      3	 (inlined by) run_test at dirty_log_test.c:702
#      4	0x000000000100c055: for_each_guest_mode at guest_modes.c:37
#      5	0x00000000010022b5: main at dirty_log_test.c:929 (discriminator 3)
#      6	0x000003ff96fabdb3: ?? ??:0
#      7	0x000000000100241d: .annobin_lto.hot at crt1.o:?
#   KVM_SET_USER_MEMORY_REGION IOCTL failed,
#   rc: -1 errno: 22
#   slot: 1 flags: 0x1
#   guest_phys_addr: 0xfffffbfe00000 size: 0x40100000
# Test iterations: 32, interval: 10 (ms)
# Testing Log Mode 'dirty-log'
# Testing guest mode: PA-bits:52,  VA-bits:48,  4K pages
# guest physical test memory offset: 0xfffffbfe00000
not ok 5 selftests: kvm: dirty_log_test # exit=254
# selftests: kvm: kvm_create_max_vcpus
# KVM_CAP_MAX_VCPU_ID: 248
# KVM_CAP_MAX_VCPUS: 248
# Testing creating 248 vCPUs, with IDs 0...247.
ok 6 selftests: kvm: kvm_create_max_vcpus
# selftests: kvm: kvm_page_table_test
# ==== Test Assertion Failure ====
#   lib/kvm_util.c:900: ret == 0
#   pid=245454 tid=245454 errno=22 - Invalid argument
#      1	0x0000000001003e47: vm_userspace_mem_region_add at kvm_util.c:900
#      2	0x000000000100257d: pre_init_before_test at kvm_page_table_test.c:302
#      3	 (inlined by) run_test at kvm_page_table_test.c:374
#      4	0x000000000100aa45: for_each_guest_mode at guest_modes.c:37
#      5	0x0000000001001dd9: main at kvm_page_table_test.c:503
#      6	0x000003ff827abdb3: ?? ??:0
#      7	0x0000000001001e8d: .annobin_lto.hot at crt1.o:?
#   KVM_SET_USER_MEMORY_REGION IOCTL failed,
#   rc: -1 errno: 22
#   slot: 1 flags: 0x0
#   guest_phys_addr: 0xfffffbff00000 size: 0x40000000
not ok 7 selftests: kvm: kvm_page_table_test # exit=254
Quoted 102 lines

---

v1 -> v2:
- Added Venkatesh's R-b line.
- Used PRIx64 to print uint64_t instead of %lx.

  tools/testing/selftests/kvm/include/kvm_util.h |  2 +-
  tools/testing/selftests/kvm/lib/kvm_util.c     |  2 +-
  .../testing/selftests/kvm/lib/perf_test_util.c |  4 +++-
  .../kvm/memslot_modification_stress_test.c     | 18 +++++++++++-------
  4 files changed, 16 insertions(+), 10 deletions(-)
tools/testing/selftests/kvm/include/kvm_util.h +1 -1
index 84982eb02b29..5d9b35d09251 100644
@@ -303,7 +303,7 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm);
 
  unsigned int vm_get_page_size(struct kvm_vm *vm);
  unsigned int vm_get_page_shift(struct kvm_vm *vm);
-unsigned int vm_get_max_gfn(struct kvm_vm *vm);
+uint64_t vm_get_max_gfn(struct kvm_vm *vm);
  int vm_get_fd(struct kvm_vm *vm);
 
  unsigned int vm_calc_num_guest_pages(enum vm_guest_mode mode, size_t size);
tools/testing/selftests/kvm/lib/kvm_util.c +1 -1
index 1af1009254c4..aeffbb1e7c7d 100644
@@ -2058,7 +2058,7 @@ unsigned int vm_get_page_shift(struct kvm_vm *vm)
  	return vm->page_shift;
  }
 
-unsigned int vm_get_max_gfn(struct kvm_vm *vm)
+uint64_t vm_get_max_gfn(struct kvm_vm *vm)
  {
  	return vm->max_gfn;
  }
tools/testing/selftests/kvm/lib/perf_test_util.c +3 -1
index 81490b9b4e32..abf381800a59 100644
@@ -2,6 +2,7 @@
  /*
   * Copyright (C) 2020, Google LLC.
   */
+#include <inttypes.h>
 
  #include "kvm_util.h"
  #include "perf_test_util.h"
@@ -80,7 +81,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
  	 */
  	TEST_ASSERT(guest_num_pages < vm_get_max_gfn(vm),
  		    "Requested more guest memory than address space allows.\n"
-		    "    guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n",
+		    "    guest pages: %" PRIx64 " max gfn: %" PRIx64
+		    " vcpus: %d wss: %" PRIx64 "]\n",
  		    guest_num_pages, vm_get_max_gfn(vm), vcpus,
  		    vcpu_memory_bytes);
 
tools/testing/selftests/kvm/memslot_modification_stress_test.c +11 -7
index 6096bf0a5b34..98351ba0933c 100644
@@ -71,14 +71,22 @@ struct memslot_antagonist_args {
  };
 
  static void add_remove_memslot(struct kvm_vm *vm, useconds_t delay,
-			      uint64_t nr_modifications, uint64_t gpa)
+			       uint64_t nr_modifications)
  {
+	const uint64_t pages = 1;
+	uint64_t gpa;
  	int i;
 
+	/*
+	 * 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);
+
  	for (i = 0; i < nr_modifications; i++) {
  		usleep(delay);
  		vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, gpa,
-					    DUMMY_MEMSLOT_INDEX, 1, 0);
+					    DUMMY_MEMSLOT_INDEX, pages, 0);
 
  		vm_mem_region_delete(vm, DUMMY_MEMSLOT_INDEX);
  	}
@@ -120,11 +128,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
  	pr_info("Started all vCPUs\n");
 
  	add_remove_memslot(vm, p->memslot_modification_delay,
-			   p->nr_memslot_modifications,
-			   guest_test_phys_mem +
-			   (guest_percpu_mem_size * nr_vcpus) +
-			   perf_test_args.host_page_size +
-			   perf_test_args.guest_page_size);
+			   p->nr_memslot_modifications);
 
  	run_vcpus = false;
 
#5 lore raw
Quoted 23 lines · Christian Borntraeger
Quoted 8 lines · David Matlack

vm_get_max_gfn() casts vm->max_gfn from a uint64_t to an unsigned int, which causes the upper 32-bits of the max_gfn to get truncated.

Nobody noticed until now likely because vm_get_max_gfn() is only used as a mechanism to create a memslot in an unused region of the guest physical address space (the top), and the top of the 32-bit physical address space was always good enough.

Quoted 7 lines

This fix reveals a bug in memslot_modification_stress_test which was trying to create a dummy memslot past the end of guest physical memory. Fix that by moving the dummy memslot lower.

Fixes 52200d0d944e ("KVM: selftests: Remove duplicate guest mode handling")

As a heads up:
I have not yet looked into this, but this broke demand_paging_test and kvm_page_table_test on s390:

Quoted 16 lines

not ok 4 selftests: kvm: demand_paging_test # exit=254
# selftests: kvm: dirty_log_test
# ==== Test Assertion Failure ====
#   lib/kvm_util.c:900: ret == 0
#   pid=245410 tid=245410 errno=22 - Invalid argument
#      1    0x0000000001005457: vm_userspace_mem_region_add at kvm_util.c:900 #      2    0x0000000001002cbf: run_test at dirty_log_test.c:757 #      3     (inlined by) run_test at dirty_log_test.c:702
#      4    0x000000000100c055: for_each_guest_mode at guest_modes.c:37 #      5    0x00000000010022b5: main at dirty_log_test.c:929 (discriminator 3) #      6    0x000003ff96fabdb3: ?? ??:0
#      7    0x000000000100241d: .annobin_lto.hot at crt1.o:?
#   KVM_SET_USER_MEMORY_REGION IOCTL failed,
#   rc: -1 errno: 22
#   slot: 1 flags: 0x1
#   guest_phys_addr: 0xfffffbfe00000 size: 0x40100000

Ah. We do have a limit of 128TB for guest physical memory. The patch now made this apparent as we no longer cut the upper bits off.

#6 lore raw

PATCH 1/1 KVM: selftests: introduce P47V64 for s390x

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

---
 tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
 tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -1
index fcd8e3855111..6d3f71822976 100644
@@ -43,6 +43,7 @@ enum vm_guest_mode {
 	VM_MODE_P40V48_4K,
 	VM_MODE_P40V48_64K,
 	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,	/* For 48bits VA but ANY bits PA */
 	NUM_VM_MODES,
 };
 
@@ -60,7 +61,7 @@ enum vm_guest_mode {
 
 #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P52V48_4K
+#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
 #define MIN_PAGE_SHIFT			12U
 #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
index 28e528c19d28..d61ad15b1979 100644
@@ -175,6 +175,7 @@ const char *vm_guest_mode_string(uint32_t i)
 		[VM_MODE_P40V48_4K]	= "PA-bits:40,  VA-bits:48,  4K pages",
 		[VM_MODE_P40V48_64K]	= "PA-bits:40,  VA-bits:48, 64K pages",
 		[VM_MODE_PXXV48_4K]	= "PA-bits:ANY, VA-bits:48,  4K pages",
+		[VM_MODE_P47V64_4K]	= "PA-bits:47,  VA-bits:64,  4K pages",
 	};
 	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
 		       "Missing new mode strings?");
@@ -192,6 +193,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
 	{ 40, 48,  0x1000, 12 },
 	{ 40, 48, 0x10000, 16 },
 	{  0,  0,  0x1000, 12 },
+	{ 47, 64,  0x1000, 12 },
 };
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
@@ -277,6 +279,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
 		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
 #endif
 		break;
+	case VM_MODE_P47V64_4K:
+		vm->pgtable_levels = 4;
+		break;
 	default:
 		TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
 	}
Signature · 1 line
2.31.1
#7 lore raw

Re: [PATCH] KVM: selftests: introduce P47V64 for s390x

Quoted 15 lines · Christian Borntraeger

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

---
 tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
 tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +0 -0
index fcd8e3855111..6d3f71822976 100644

tools/testing/selftests/kvm/include/kvm_util.h enum vm_guest_mode { · line 46

Quoted 4 lines
tools/testing/selftests/kvm/include/kvm_util.h +1 -0
@@ -43,6 +43,7 @@ enum vm_guest_mode {
 	VM_MODE_P40V48_4K,
 	VM_MODE_P40V48_64K,
 	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,	/* For 48bits VA but ANY bits PA */

/* 64 bits VA but 47 bits PA */

Or, looking at the other entries above, just remove it.

Quoted 43 lines
tools/testing/selftests/kvm/include/kvm_util.h +1 -1
 	NUM_VM_MODES,
 };
 
@@ -60,7 +61,7 @@ enum vm_guest_mode {
 
 #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P52V48_4K
+#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
 #define MIN_PAGE_SHIFT			12U
 #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
index 28e528c19d28..d61ad15b1979 100644
@@ -175,6 +175,7 @@ const char *vm_guest_mode_string(uint32_t i)
 		[VM_MODE_P40V48_4K]	= "PA-bits:40,  VA-bits:48,  4K pages",
 		[VM_MODE_P40V48_64K]	= "PA-bits:40,  VA-bits:48, 64K pages",
 		[VM_MODE_PXXV48_4K]	= "PA-bits:ANY, VA-bits:48,  4K pages",
+		[VM_MODE_P47V64_4K]	= "PA-bits:47,  VA-bits:64,  4K pages",
 	};
 	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
 		       "Missing new mode strings?");
@@ -192,6 +193,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
 	{ 40, 48,  0x1000, 12 },
 	{ 40, 48, 0x10000, 16 },
 	{  0,  0,  0x1000, 12 },
+	{ 47, 64,  0x1000, 12 },
 };
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
@@ -277,6 +279,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
 		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
 #endif
 		break;
+	case VM_MODE_P47V64_4K:
+		vm->pgtable_levels = 4;
+		break;
 	default:
 		TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
 	}
#8 lore raw

Re: [PATCH] KVM: selftests: introduce P47V64 for s390x

Quoted 23 lines · Janosch Frank
Quoted 15 lines · Christian Borntraeger

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

---
  tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
  tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
  2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +0 -0
index fcd8e3855111..6d3f71822976 100644

tools/testing/selftests/kvm/include/kvm_util.h enum vm_guest_mode { · line 46

Quoted 4 lines
tools/testing/selftests/kvm/include/kvm_util.h +1 -0
@@ -43,6 +43,7 @@ enum vm_guest_mode {
  	VM_MODE_P40V48_4K,
  	VM_MODE_P40V48_64K,
  	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,	/* For 48bits VA but ANY bits PA */

/* 64 bits VA but 47 bits PA */

Quoted 1 line

Or, looking at the other entries above, just remove it.

Yes, will remove.

#9 lore raw

Re: [PATCH] KVM: selftests: introduce P47V64 for s390x

In reply to Christian Borntraeger
Quoted 52 lines · Christian Borntraeger

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

---
  tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
  tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
  2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -1
index fcd8e3855111..6d3f71822976 100644
@@ -43,6 +43,7 @@ enum vm_guest_mode {
  	VM_MODE_P40V48_4K,
  	VM_MODE_P40V48_64K,
  	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,	/* For 48bits VA but ANY bits PA */
  	NUM_VM_MODES,
  };
 
@@ -60,7 +61,7 @@ enum vm_guest_mode {
 
  #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P52V48_4K
+#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
  #define MIN_PAGE_SHIFT			12U
  #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/kvm_util.c +2 -0
index 28e528c19d28..d61ad15b1979 100644
@@ -175,6 +175,7 @@ const char *vm_guest_mode_string(uint32_t i)
  		[VM_MODE_P40V48_4K]	= "PA-bits:40,  VA-bits:48,  4K pages",
  		[VM_MODE_P40V48_64K]	= "PA-bits:40,  VA-bits:48, 64K pages",
  		[VM_MODE_PXXV48_4K]	= "PA-bits:ANY, VA-bits:48,  4K pages",
+		[VM_MODE_P47V64_4K]	= "PA-bits:47,  VA-bits:64,  4K pages",
  	};
  	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
  		       "Missing new mode strings?");
@@ -192,6 +193,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
  	{ 40, 48,  0x1000, 12 },
  	{ 40, 48, 0x10000, 16 },
  	{  0,  0,  0x1000, 12 },
+	{ 47, 64,  0x1000, 12 },
  };
  _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
  	       "Missing new mode params?");

tools/testing/selftests/kvm/lib/kvm_util.c struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) · line 283

Quoted 5 lines
tools/testing/selftests/kvm/lib/kvm_util.c +2 -0
@@ -277,6 +279,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
  		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
  #endif
  		break;
+	case VM_MODE_P47V64_4K:
+		vm->pgtable_levels = 4;

I will change that to 5 as well.

#10 lore raw

PATCH v2 1/1 KVM: selftests: introduce P47V64 for s390x

In reply to Christian Borntraeger

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

---
v1->v2:
- remove wrong comment
- use 5 levels of page tables

 tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
 tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -1
index fcd8e3855111..b602552b1ed0 100644
@@ -43,6 +43,7 @@ enum vm_guest_mode {
 	VM_MODE_P40V48_4K,
 	VM_MODE_P40V48_64K,
 	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,
 	NUM_VM_MODES,
 };
 
@@ -60,7 +61,7 @@ enum vm_guest_mode {
 
 #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P52V48_4K
+#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
 #define MIN_PAGE_SHIFT			12U
 #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
index 28e528c19d28..b126fab6c4e1 100644
@@ -175,6 +175,7 @@ const char *vm_guest_mode_string(uint32_t i)
 		[VM_MODE_P40V48_4K]	= "PA-bits:40,  VA-bits:48,  4K pages",
 		[VM_MODE_P40V48_64K]	= "PA-bits:40,  VA-bits:48, 64K pages",
 		[VM_MODE_PXXV48_4K]	= "PA-bits:ANY, VA-bits:48,  4K pages",
+		[VM_MODE_P47V64_4K]	= "PA-bits:47,  VA-bits:64,  4K pages",
 	};
 	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
 		       "Missing new mode strings?");
@@ -192,6 +193,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
 	{ 40, 48,  0x1000, 12 },
 	{ 40, 48, 0x10000, 16 },
 	{  0,  0,  0x1000, 12 },
+	{ 47, 64,  0x1000, 12 },
 };
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
@@ -277,6 +279,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
 		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
 #endif
 		break;
+	case VM_MODE_P47V64_4K:
+		vm->pgtable_levels = 5;
+		break;
 	default:
 		TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
 	}
Signature · 1 line
2.31.1
author Reviewed-by on v2 1/1
#11 lore raw

Re: [PATCH v2] KVM: selftests: introduce P47V64 for s390x

Quoted 3 lines · Christian Borntraeger

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

Thanks for the fix. My apologies for breaking s390.

The patch "KVM: selftests: Fix 32-bit truncation of vm_get_max_gfn()" has already been added to stable so you may want to add the following:

Fixes ef4c9f4f6546 ("KVM: selftests: Fix 32-bit truncation of vm_get_max_gfn()")
Quoted 2 lines
Quoted 62 lines

---
v1->v2:
- remove wrong comment
- use 5 levels of page tables

 tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
 tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -1
index fcd8e3855111..b602552b1ed0 100644
@@ -43,6 +43,7 @@ enum vm_guest_mode {
 	VM_MODE_P40V48_4K,
 	VM_MODE_P40V48_64K,
 	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,
 	NUM_VM_MODES,
 };
 
@@ -60,7 +61,7 @@ enum vm_guest_mode {
 
 #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P52V48_4K
+#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
 #define MIN_PAGE_SHIFT			12U
 #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
index 28e528c19d28..b126fab6c4e1 100644
@@ -175,6 +175,7 @@ const char *vm_guest_mode_string(uint32_t i)
 		[VM_MODE_P40V48_4K]	= "PA-bits:40,  VA-bits:48,  4K pages",
 		[VM_MODE_P40V48_64K]	= "PA-bits:40,  VA-bits:48, 64K pages",
 		[VM_MODE_PXXV48_4K]	= "PA-bits:ANY, VA-bits:48,  4K pages",
+		[VM_MODE_P47V64_4K]	= "PA-bits:47,  VA-bits:64,  4K pages",
 	};
 	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
 		       "Missing new mode strings?");
@@ -192,6 +193,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
 	{ 40, 48,  0x1000, 12 },
 	{ 40, 48, 0x10000, 16 },
 	{  0,  0,  0x1000, 12 },
+	{ 47, 64,  0x1000, 12 },
 };
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
@@ -277,6 +279,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
 		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
 #endif
 		break;
+	case VM_MODE_P47V64_4K:
+		vm->pgtable_levels = 5;
+		break;
 	default:
 		TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
 	}
Signature · 1 line
2.31.1
maintainer Applied
#12 lore raw

Re: [PATCH v2] KVM: selftests: introduce P47V64 for s390x

In reply to Christian Borntraeger
Quoted 56 lines · Christian Borntraeger

s390x can have up to 47bits of physical guest and 64bits of virtual address bits. Add a new address mode to avoid errors of testcases going beyond 47bits.

---
v1->v2:
- remove wrong comment
- use 5 levels of page tables

  tools/testing/selftests/kvm/include/kvm_util.h | 3 ++-
  tools/testing/selftests/kvm/lib/kvm_util.c     | 5 +++++
  2 files changed, 7 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -1
index fcd8e3855111..b602552b1ed0 100644
@@ -43,6 +43,7 @@ enum vm_guest_mode {
  	VM_MODE_P40V48_4K,
  	VM_MODE_P40V48_64K,
  	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
+	VM_MODE_P47V64_4K,
  	NUM_VM_MODES,
  };
 
@@ -60,7 +61,7 @@ enum vm_guest_mode {
 
  #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P52V48_4K
+#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
  #define MIN_PAGE_SHIFT			12U
  #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/kvm_util.c +2 -0
index 28e528c19d28..b126fab6c4e1 100644
@@ -175,6 +175,7 @@ const char *vm_guest_mode_string(uint32_t i)
  		[VM_MODE_P40V48_4K]	= "PA-bits:40,  VA-bits:48,  4K pages",
  		[VM_MODE_P40V48_64K]	= "PA-bits:40,  VA-bits:48, 64K pages",
  		[VM_MODE_PXXV48_4K]	= "PA-bits:ANY, VA-bits:48,  4K pages",
+		[VM_MODE_P47V64_4K]	= "PA-bits:47,  VA-bits:64,  4K pages",
  	};
  	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
  		       "Missing new mode strings?");
@@ -192,6 +193,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
  	{ 40, 48,  0x1000, 12 },
  	{ 40, 48, 0x10000, 16 },
  	{  0,  0,  0x1000, 12 },
+	{ 47, 64,  0x1000, 12 },
  };
  _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
  	       "Missing new mode params?");

tools/testing/selftests/kvm/lib/kvm_util.c struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) · line 287

Quoted 9 lines
tools/testing/selftests/kvm/lib/kvm_util.c +3 -0
@@ -277,6 +279,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
  		TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
  #endif
  		break;
+	case VM_MODE_P47V64_4K:
+		vm->pgtable_levels = 5;
+		break;
  	default:
  		TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
  	}

Queued, thanks.

Paolo