Skip to contentSkip to conversation

KVM: selftests: Fixes for 5.14

GIT PULL Christian Borntraeger 2 participants 4 messages Jul 6, 2021 – Jul 8, 2021

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

Paolo,

The following changes since commit f8be156be163a052a067306417cd0ff679068c97:

KVM: do not allow mapping valid but non-reference-counted pages (2021-06-24 11:55:11 -0400)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git tags/kvm-s390-master-5.14-1

for you to fetch changes up to cd4220d23bf3f43cf720e82bdee681f383433ae2:

KVM: selftests: do not require 64GB in set_memory_region_test (2021-07-06 10:06:20 +0200)

----------------------------------------------------------------
KVM: selftests: Fixes

- provide memory model for IBM z196 and zEC12
- do not require 64GB of memory

----------------------------------------------------------------
Christian Borntraeger (2):
KVM: selftests: introduce P44V64 for z196 and EC12
KVM: selftests: do not require 64GB in set_memory_region_test

 tools/testing/selftests/kvm/include/kvm_util.h       |  3 ++-
 tools/testing/selftests/kvm/lib/guest_modes.c        | 16 ++++++++++++++++
 tools/testing/selftests/kvm/lib/kvm_util.c           |  5 +++++
 tools/testing/selftests/kvm/set_memory_region_test.c |  3 ++-
 4 files changed, 25 insertions(+), 2 deletions(-)
#1 lore raw

[GIT PULL 1/2] KVM: selftests: introduce P44V64 for z196 and EC12

Older machines like z196 and zEC12 do only support 44 bits of physical addresses. Make this the default and check via IBC if we are on a later machine. We then add P47V64 as an additional model.

---
 tools/testing/selftests/kvm/include/kvm_util.h |  3 ++-
 tools/testing/selftests/kvm/lib/guest_modes.c  | 16 ++++++++++++++++
 tools/testing/selftests/kvm/lib/kvm_util.c     |  5 +++++
 3 files changed, 23 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/include/kvm_util.h +2 -1
index 35739567189e..74d73532fce9 100644
@@ -44,6 +44,7 @@ enum vm_guest_mode {
 	VM_MODE_P40V48_64K,
 	VM_MODE_PXXV48_4K,	/* For 48bits VA but ANY bits PA */
 	VM_MODE_P47V64_4K,
+	VM_MODE_P44V64_4K,
 	NUM_VM_MODES,
 };
 
@@ -61,7 +62,7 @@ enum vm_guest_mode {
 
 #elif defined(__s390x__)
 
-#define VM_MODE_DEFAULT			VM_MODE_P47V64_4K
+#define VM_MODE_DEFAULT			VM_MODE_P44V64_4K
 #define MIN_PAGE_SHIFT			12U
 #define ptes_per_page(page_size)	((page_size) / 16)
 
tools/testing/selftests/kvm/lib/guest_modes.c +16 -0
index 25bff307c71f..c330f414ef96 100644
@@ -22,6 +22,22 @@ void guest_modes_append_default(void)
 		}
 	}
 #endif
+#ifdef __s390x__
+	{
+		int kvm_fd, vm_fd;
+		struct kvm_s390_vm_cpu_processor info;
+
+		kvm_fd = open_kvm_dev_path_or_exit();
+		vm_fd = ioctl(kvm_fd, KVM_CREATE_VM, 0);
+		kvm_device_access(vm_fd, KVM_S390_VM_CPU_MODEL,
+				  KVM_S390_VM_CPU_PROCESSOR, &info, false);
+		close(vm_fd);
+		close(kvm_fd);
+		/* Starting with z13 we have 47bits of physical address */
+		if (info.ibc >= 0x30)
+			guest_mode_append(VM_MODE_P47V64_4K, true, true);
+	}
+#endif
 }
 
 void for_each_guest_mode(void (*func)(enum vm_guest_mode, void *), void *arg)
tools/testing/selftests/kvm/lib/kvm_util.c +5 -0
index a2b732cf96ea..8606000c439e 100644
@@ -176,6 +176,7 @@ const char *vm_guest_mode_string(uint32_t i)
 		[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",
+		[VM_MODE_P44V64_4K]	= "PA-bits:44,  VA-bits:64,  4K pages",
 	};
 	_Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
 		       "Missing new mode strings?");
@@ -194,6 +195,7 @@ const struct vm_guest_mode_params vm_guest_mode_params[] = {
 	{ 40, 48, 0x10000, 16 },
 	{  0,  0,  0x1000, 12 },
 	{ 47, 64,  0x1000, 12 },
+	{ 44, 64,  0x1000, 12 },
 };
 _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) == NUM_VM_MODES,
 	       "Missing new mode params?");
@@ -282,6 +284,9 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
 	case VM_MODE_P47V64_4K:
 		vm->pgtable_levels = 5;
 		break;
+	case VM_MODE_P44V64_4K:
+		vm->pgtable_levels = 5;
+		break;
 	default:
 		TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
 	}
Signature · 1 line
2.31.1
#2 lore raw

[GIT PULL 2/2] KVM: selftests: do not require 64GB in set_memory_region_test

In reply to Christian Borntraeger

Unless the user sets overcommit_memory or has plenty of swap, the latest changes to the testcase will result in ENOMEM failures for hosts with less than 64GB RAM. As we do not use much of the allocated memory, we can use MAP_NORESERVE to avoid this error.

Cc Zenghui Yu <[email protected]>
Fixes 309505dd5685 ("KVM: selftests: Fix mapping length truncation in m{,un}map()")
---
 tools/testing/selftests/kvm/set_memory_region_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/set_memory_region_test.c +2 -1
index d8812f27648c..d31f54ac4e98 100644
@@ -377,7 +377,8 @@ static void test_add_max_memory_regions(void)
 		(max_mem_slots - 1), MEM_REGION_SIZE >> 10);
 
 	mem = mmap(NULL, (size_t)max_mem_slots * MEM_REGION_SIZE + alignment,
-		   PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		   PROT_READ | PROT_WRITE,
+		   MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
 	TEST_ASSERT(mem != MAP_FAILED, "Failed to mmap() host");
 	mem_aligned = (void *)(((size_t) mem + alignment - 1) & ~(alignment - 1));
 
Signature · 1 line
2.31.1