Commit 32ffa4f7 authored by Axel Rasmussen's avatar Axel Rasmussen Committed by Paolo Bonzini

KVM: selftests: compute correct demand paging size

This is a preparatory commit needed before we can use different kinds of
backing pages for guest memory.

Previously, we used perf_test_args.host_page_size, which is the host's
native page size (commonly 4K). For VM_MEM_SRC_ANONYMOUS this turns out
to be okay, but in a follow-up commit we want to allow using different
kinds of backing memory.

Take VM_MEM_SRC_ANONYMOUS_HUGETLB for example. Without this change, if
we used that backing page type, when we issued a UFFDIO_COPY ioctl we'd
only do so with 4K, rather than the full 2M of a backing hugepage. In
this case, UFFDIO_COPY returns -EINVAL (__mcopy_atomic_hugetlb checks
the size).
Signed-off-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
Message-Id: <20210519200339.829146-5-axelrasmussen@google.com>
Reviewed-by: default avatarBen Gardon <bgardon@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 25408e5a
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
static int nr_vcpus = 1; static int nr_vcpus = 1;
static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE; static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
static size_t demand_paging_size;
static char *guest_data_prototype; static char *guest_data_prototype;
static void *vcpu_worker(void *data) static void *vcpu_worker(void *data)
...@@ -84,7 +85,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr) ...@@ -84,7 +85,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr)
copy.src = (uint64_t)guest_data_prototype; copy.src = (uint64_t)guest_data_prototype;
copy.dst = addr; copy.dst = addr;
copy.len = perf_test_args.host_page_size; copy.len = demand_paging_size;
copy.mode = 0; copy.mode = 0;
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
...@@ -101,7 +102,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr) ...@@ -101,7 +102,7 @@ static int handle_uffd_page_request(int uffd, uint64_t addr)
PER_PAGE_DEBUG("UFFDIO_COPY %d \t%ld ns\n", tid, PER_PAGE_DEBUG("UFFDIO_COPY %d \t%ld ns\n", tid,
timespec_to_ns(ts_diff)); timespec_to_ns(ts_diff));
PER_PAGE_DEBUG("Paged in %ld bytes at 0x%lx from thread %d\n", PER_PAGE_DEBUG("Paged in %ld bytes at 0x%lx from thread %d\n",
perf_test_args.host_page_size, addr, tid); demand_paging_size, addr, tid);
return 0; return 0;
} }
...@@ -260,10 +261,12 @@ static void run_test(enum vm_guest_mode mode, void *arg) ...@@ -260,10 +261,12 @@ static void run_test(enum vm_guest_mode mode, void *arg)
perf_test_args.wr_fract = 1; perf_test_args.wr_fract = 1;
guest_data_prototype = malloc(perf_test_args.host_page_size); demand_paging_size = get_backing_src_pagesz(VM_MEM_SRC_ANONYMOUS);
guest_data_prototype = malloc(demand_paging_size);
TEST_ASSERT(guest_data_prototype, TEST_ASSERT(guest_data_prototype,
"Failed to allocate buffer for guest data pattern"); "Failed to allocate buffer for guest data pattern");
memset(guest_data_prototype, 0xAB, perf_test_args.host_page_size); memset(guest_data_prototype, 0xAB, demand_paging_size);
vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads)); vcpu_threads = malloc(nr_vcpus * sizeof(*vcpu_threads));
TEST_ASSERT(vcpu_threads, "Memory allocation failed"); TEST_ASSERT(vcpu_threads, "Memory allocation failed");
......
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