Commit 0f55b67e authored by Andrew Jones's avatar Andrew Jones Committed by Paolo Bonzini

KVM: selftests: Don't require THP to run tests

Unless we want to test with THP, then we shouldn't require it to be
configured by the host kernel. Unfortunately, even advising with
MADV_NOHUGEPAGE does require it, so check for THP first in order
to avoid madvise failing with EINVAL.
Signed-off-by: default avatarAndrew Jones <drjones@redhat.com>
Message-Id: <20201029201703.102716-2-drjones@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 064eedf2
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#define KVM_UTIL_PGS_PER_HUGEPG 512 #define KVM_UTIL_PGS_PER_HUGEPG 512
...@@ -664,13 +665,21 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, ...@@ -664,13 +665,21 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
/* As needed perform madvise */ /* As needed perform madvise */
if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) { if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
ret = madvise(region->host_mem, npages * vm->page_size, struct stat statbuf;
src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
TEST_ASSERT(ret == 0, "madvise failed,\n" ret = stat("/sys/kernel/mm/transparent_hugepage", &statbuf);
" addr: %p\n" TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
" length: 0x%lx\n" "stat /sys/kernel/mm/transparent_hugepage");
" src_type: %x",
region->host_mem, npages * vm->page_size, src_type); TEST_ASSERT(ret == 0 || src_type != VM_MEM_SRC_ANONYMOUS_THP,
"VM_MEM_SRC_ANONYMOUS_THP requires THP to be configured in the host kernel");
if (ret == 0) {
ret = madvise(region->host_mem, npages * vm->page_size,
src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
TEST_ASSERT(ret == 0, "madvise failed, addr: %p length: 0x%lx src_type: %x",
region->host_mem, npages * vm->page_size, src_type);
}
} }
region->unused_phy_pages = sparsebit_alloc(); region->unused_phy_pages = sparsebit_alloc();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment