Skip to content

Commit ba125de

Browse files
xzpetersean-jc
authored andcommitted
KVM: selftests: Setup vcpu_alias only for minor mode test
This fixes two things: - Unbreaks MISSING mode test on anonymous memory type - Prefault alias mem before uffd thread creations, otherwise the uffd thread timing will be inaccurate when guest mem size is large, because it'll take prefault time into total time. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: James Houghton <jthoughton@google.com> Link: https://lore.kernel.org/r/20230427201112.2164776-2-peterx@redhat.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 56f413f commit ba125de

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

tools/testing/selftests/kvm/demand_paging_test.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static void prefault_mem(void *alias, uint64_t len)
128128

129129
static void run_test(enum vm_guest_mode mode, void *arg)
130130
{
131+
struct memstress_vcpu_args *vcpu_args;
131132
struct test_params *p = arg;
132133
struct uffd_desc **uffd_descs = NULL;
133134
struct timespec start;
@@ -145,24 +146,24 @@ static void run_test(enum vm_guest_mode mode, void *arg)
145146
"Failed to allocate buffer for guest data pattern");
146147
memset(guest_data_prototype, 0xAB, demand_paging_size);
147148

149+
if (p->uffd_mode == UFFDIO_REGISTER_MODE_MINOR) {
150+
for (i = 0; i < nr_vcpus; i++) {
151+
vcpu_args = &memstress_args.vcpu_args[i];
152+
prefault_mem(addr_gpa2alias(vm, vcpu_args->gpa),
153+
vcpu_args->pages * memstress_args.guest_page_size);
154+
}
155+
}
156+
148157
if (p->uffd_mode) {
149158
uffd_descs = malloc(nr_vcpus * sizeof(struct uffd_desc *));
150159
TEST_ASSERT(uffd_descs, "Memory allocation failed");
151-
152160
for (i = 0; i < nr_vcpus; i++) {
153-
struct memstress_vcpu_args *vcpu_args;
154161
void *vcpu_hva;
155-
void *vcpu_alias;
156162

157163
vcpu_args = &memstress_args.vcpu_args[i];
158164

159165
/* Cache the host addresses of the region */
160166
vcpu_hva = addr_gpa2hva(vm, vcpu_args->gpa);
161-
vcpu_alias = addr_gpa2alias(vm, vcpu_args->gpa);
162-
163-
prefault_mem(vcpu_alias,
164-
vcpu_args->pages * memstress_args.guest_page_size);
165-
166167
/*
167168
* Set up user fault fd to handle demand paging
168169
* requests.

0 commit comments

Comments
 (0)