Skip to contentSkip to conversation

KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages

PATCH In review Like Xu 3 participants 3 messages Aug 17 – Aug 18

Subsystems (3)
lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 KVM: selftests: arm64: Skip sea_to_user without 1GB hugepages

sea_to_user backs guest memory with 1GB hugepages but never checks any are reserved, aborting instead of skipping when the host has none:

kvm_syscalls.h:68: mem != MAP_FAILED, errno=12 (ENOMEM) not ok 1 selftests: kvm: sea_to_user # exit=254

Check for enough free hugepages up front so the test skips cleanly.

---
 tools/testing/selftests/kvm/arm64/sea_to_user.c |  6 ++++++
 tools/testing/selftests/kvm/include/test_util.h |  1 +
 tools/testing/selftests/kvm/lib/test_util.c     | 15 +++++++++++++++
 3 files changed, 22 insertions(+)
tools/testing/selftests/kvm/arm64/sea_to_user.c +6 -0
index e96d8982c28b8..fc4f81702d0b6 100644
@@ -260,6 +260,12 @@ static struct kvm_vm *vm_create_with_sea_handler(struct kvm_vcpu **vcpu)
 	alignment = max(backing_page_size, guest_page_size);
 	num_guest_pages = VM_MEM_SIZE / guest_page_size;
 
+	/*
+	 * The region is backed by 1GB hugepages; skip gracefully rather than
+	 * failing with mmap() -ENOMEM if the host has none reserved.
+	 */
+	TEST_REQUIRE(get_free_hugepages(backing_page_size) >= VM_MEM_SIZE);
+
 	vm = __vm_create_with_one_vcpu(vcpu, num_guest_pages, guest_code);
 	vm_init_descriptor_tables(vm);
 	vcpu_init_descriptor_tables(*vcpu);
tools/testing/selftests/kvm/include/test_util.h +1 -0
index a56271c237ae9..0624922c2735d 100644
@@ -168,6 +168,7 @@ struct vm_mem_backing_src_alias {
 bool thp_configured(void);
 size_t get_trans_hugepagesz(void);
 size_t get_def_hugetlb_pagesz(void);
+size_t get_free_hugepages(size_t page_size);
 const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(u32 i);
 size_t get_backing_src_pagesz(u32 i);
 bool is_backing_src_hugetlb(u32 i);
tools/testing/selftests/kvm/lib/test_util.c +15 -0
index bab1bd2b775b6..29f9c1d60b1b7 100644
@@ -222,6 +222,21 @@ size_t get_def_hugetlb_pagesz(void)
 	TEST_FAIL("Error in reading /proc/meminfo");
 }
 
+size_t get_free_hugepages(size_t page_size)
+{
+	char path[128];
+	size_t free;
+
+	snprintf(path, sizeof(path),
+		 "/sys/kernel/mm/hugepages/hugepages-%zukB/free_hugepages",
+		 page_size >> 10);
+	if (!test_sysfs_path(path))
+		return 0;
+
+	free = get_sysfs_val(path);
+	return free * page_size;
+}
+
 #define ANON_FLAGS	(MAP_PRIVATE | MAP_ANONYMOUS)
 #define ANON_HUGE_FLAGS	(ANON_FLAGS | MAP_HUGETLB)
 
Signature · 1 line
2.43.7
maintainer
#1 lore raw

+ Jiaqi.

Quoted 8 lines · Like Xu

sea_to_user backs guest memory with 1GB hugepages but never checks any are reserved, aborting instead of skipping when the host has none:

kvm_syscalls.h:68: mem != MAP_FAILED, errno=12 (ENOMEM) not ok 1 selftests: kvm: sea_to_user # exit=254

Check for enough free hugepages up front so the test skips cleanly.

See my comments at [1].

This test is totally borked, and Jiaqi stopped replying. It is a liability, and I'd like it *removed*. But if you want to fix it, please go ahead.

	M.

[1] https://lore.kernel.org/all/[email protected]/

Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw
Quoted 12 lines · Marc Zyngier

+ Jiaqi.

Quoted 7 lines · Like Xu

sea_to_user backs guest memory with 1GB hugepages but never checks any are reserved, aborting instead of skipping when the host has none:

kvm_syscalls.h:68: mem != MAP_FAILED, errno=12 (ENOMEM) not ok 1 selftests: kvm: sea_to_user # exit=254

Quoted 7 lines
Quoted 1 line

Check for enough free hugepages up front so the test skips cleanly.

See my comments at [1].

This test is totally borked, and Jiaqi stopped replying. It is a liability, and I'd like it *removed*. But if you want to fix it, please go ahead.

Sorry the test was written in a way that is highly customized to my testing environment, and I have been occupied with many other work-related tasks.

Like, I can help review the patches for the test during this weekend, if that's not too late for you.

Quoted 7 lines
        M.

[1] https://lore.kernel.org/all/[email protected]/

--
Without deviation from the norm, progress is not possible.