Skip to content

Commit 2f8ebe4

Browse files
committed
Merge tag 'kvm-x86-selftests-6.8-rcN' of https://github.com/kvm-x86/linux into HEAD
KVM selftests fixes/cleanups (and one KVM x86 cleanup) for 6.8: - Remove redundant newlines from error messages. - Delete an unused variable in the AMX test (which causes build failures when compiling with -Werror). - Fail instead of skipping tests if open(), e.g. of /dev/kvm, fails with an error code other than ENOENT (a Hyper-V selftest bug resulted in an EMFILE, and the test eventually got skipped). - Fix TSC related bugs in several Hyper-V selftests. - Fix a bug in the dirty ring logging test where a sem_post() could be left pending across multiple runs, resulting in incorrect synchronization between the main thread and the vCPU worker thread. - Relax the dirty log split test's assertions on 4KiB mappings to fix false positives due to the number of mappings for memslot 0 (used for code and data that is NOT being dirty logged) changing, e.g. due to NUMA balancing. - Have KVM's gtod_is_based_on_tsc() return "bool" instead of an "int" (the function generates boolean values, and all callers treat the return value as a bool).
2 parents 22d0bc0 + 6fd78be commit 2f8ebe4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+237
-240
lines changed

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2506,7 +2506,7 @@ static u64 compute_guest_tsc(struct kvm_vcpu *vcpu, s64 kernel_ns)
25062506
}
25072507

25082508
#ifdef CONFIG_X86_64
2509-
static inline int gtod_is_based_on_tsc(int mode)
2509+
static inline bool gtod_is_based_on_tsc(int mode)
25102510
{
25112511
return mode == VDSO_CLOCKMODE_TSC || mode == VDSO_CLOCKMODE_HVCLOCK;
25122512
}

tools/testing/selftests/kvm/aarch64/arch_timer.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static void *test_vcpu_run(void *arg)
248248
REPORT_GUEST_ASSERT(uc);
249249
break;
250250
default:
251-
TEST_FAIL("Unexpected guest exit\n");
251+
TEST_FAIL("Unexpected guest exit");
252252
}
253253

254254
return NULL;
@@ -287,7 +287,7 @@ static int test_migrate_vcpu(unsigned int vcpu_idx)
287287

288288
/* Allow the error where the vCPU thread is already finished */
289289
TEST_ASSERT(ret == 0 || ret == ESRCH,
290-
"Failed to migrate the vCPU:%u to pCPU: %u; ret: %d\n",
290+
"Failed to migrate the vCPU:%u to pCPU: %u; ret: %d",
291291
vcpu_idx, new_pcpu, ret);
292292

293293
return ret;
@@ -326,12 +326,12 @@ static void test_run(struct kvm_vm *vm)
326326

327327
pthread_mutex_init(&vcpu_done_map_lock, NULL);
328328
vcpu_done_map = bitmap_zalloc(test_args.nr_vcpus);
329-
TEST_ASSERT(vcpu_done_map, "Failed to allocate vcpu done bitmap\n");
329+
TEST_ASSERT(vcpu_done_map, "Failed to allocate vcpu done bitmap");
330330

331331
for (i = 0; i < (unsigned long)test_args.nr_vcpus; i++) {
332332
ret = pthread_create(&pt_vcpu_run[i], NULL, test_vcpu_run,
333333
(void *)(unsigned long)i);
334-
TEST_ASSERT(!ret, "Failed to create vCPU-%d pthread\n", i);
334+
TEST_ASSERT(!ret, "Failed to create vCPU-%d pthread", i);
335335
}
336336

337337
/* Spawn a thread to control the vCPU migrations */
@@ -340,7 +340,7 @@ static void test_run(struct kvm_vm *vm)
340340

341341
ret = pthread_create(&pt_vcpu_migration, NULL,
342342
test_vcpu_migration, NULL);
343-
TEST_ASSERT(!ret, "Failed to create the migration pthread\n");
343+
TEST_ASSERT(!ret, "Failed to create the migration pthread");
344344
}
345345

346346

@@ -384,7 +384,7 @@ static struct kvm_vm *test_vm_create(void)
384384
if (kvm_has_cap(KVM_CAP_COUNTER_OFFSET))
385385
vm_ioctl(vm, KVM_ARM_SET_COUNTER_OFFSET, &test_args.offset);
386386
else
387-
TEST_FAIL("no support for global offset\n");
387+
TEST_FAIL("no support for global offset");
388388
}
389389

390390
for (i = 0; i < nr_vcpus; i++)

tools/testing/selftests/kvm/aarch64/hypercalls.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ static void test_fw_regs_before_vm_start(struct kvm_vcpu *vcpu)
175175
/* First 'read' should be an upper limit of the features supported */
176176
vcpu_get_reg(vcpu, reg_info->reg, &val);
177177
TEST_ASSERT(val == FW_REG_ULIMIT_VAL(reg_info->max_feat_bit),
178-
"Expected all the features to be set for reg: 0x%lx; expected: 0x%lx; read: 0x%lx\n",
178+
"Expected all the features to be set for reg: 0x%lx; expected: 0x%lx; read: 0x%lx",
179179
reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit), val);
180180

181181
/* Test a 'write' by disabling all the features of the register map */
182182
ret = __vcpu_set_reg(vcpu, reg_info->reg, 0);
183183
TEST_ASSERT(ret == 0,
184-
"Failed to clear all the features of reg: 0x%lx; ret: %d\n",
184+
"Failed to clear all the features of reg: 0x%lx; ret: %d",
185185
reg_info->reg, errno);
186186

187187
vcpu_get_reg(vcpu, reg_info->reg, &val);
188188
TEST_ASSERT(val == 0,
189-
"Expected all the features to be cleared for reg: 0x%lx\n", reg_info->reg);
189+
"Expected all the features to be cleared for reg: 0x%lx", reg_info->reg);
190190

191191
/*
192192
* Test enabling a feature that's not supported.
@@ -195,7 +195,7 @@ static void test_fw_regs_before_vm_start(struct kvm_vcpu *vcpu)
195195
if (reg_info->max_feat_bit < 63) {
196196
ret = __vcpu_set_reg(vcpu, reg_info->reg, BIT(reg_info->max_feat_bit + 1));
197197
TEST_ASSERT(ret != 0 && errno == EINVAL,
198-
"Unexpected behavior or return value (%d) while setting an unsupported feature for reg: 0x%lx\n",
198+
"Unexpected behavior or return value (%d) while setting an unsupported feature for reg: 0x%lx",
199199
errno, reg_info->reg);
200200
}
201201
}
@@ -216,7 +216,7 @@ static void test_fw_regs_after_vm_start(struct kvm_vcpu *vcpu)
216216
*/
217217
vcpu_get_reg(vcpu, reg_info->reg, &val);
218218
TEST_ASSERT(val == 0,
219-
"Expected all the features to be cleared for reg: 0x%lx\n",
219+
"Expected all the features to be cleared for reg: 0x%lx",
220220
reg_info->reg);
221221

222222
/*
@@ -226,7 +226,7 @@ static void test_fw_regs_after_vm_start(struct kvm_vcpu *vcpu)
226226
*/
227227
ret = __vcpu_set_reg(vcpu, reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit));
228228
TEST_ASSERT(ret != 0 && errno == EBUSY,
229-
"Unexpected behavior or return value (%d) while setting a feature while VM is running for reg: 0x%lx\n",
229+
"Unexpected behavior or return value (%d) while setting a feature while VM is running for reg: 0x%lx",
230230
errno, reg_info->reg);
231231
}
232232
}
@@ -265,7 +265,7 @@ static void test_guest_stage(struct kvm_vm **vm, struct kvm_vcpu **vcpu)
265265
case TEST_STAGE_HVC_IFACE_FALSE_INFO:
266266
break;
267267
default:
268-
TEST_FAIL("Unknown test stage: %d\n", prev_stage);
268+
TEST_FAIL("Unknown test stage: %d", prev_stage);
269269
}
270270
}
271271

@@ -294,7 +294,7 @@ static void test_run(void)
294294
REPORT_GUEST_ASSERT(uc);
295295
break;
296296
default:
297-
TEST_FAIL("Unexpected guest exit\n");
297+
TEST_FAIL("Unexpected guest exit");
298298
}
299299
}
300300

tools/testing/selftests/kvm/aarch64/page_fault_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ static bool punch_hole_in_backing_store(struct kvm_vm *vm,
414414
if (fd != -1) {
415415
ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
416416
0, paging_size);
417-
TEST_ASSERT(ret == 0, "fallocate failed\n");
417+
TEST_ASSERT(ret == 0, "fallocate failed");
418418
} else {
419419
ret = madvise(hva, paging_size, MADV_DONTNEED);
420-
TEST_ASSERT(ret == 0, "madvise failed\n");
420+
TEST_ASSERT(ret == 0, "madvise failed");
421421
}
422422

423423
return true;
@@ -501,7 +501,7 @@ static bool handle_cmd(struct kvm_vm *vm, int cmd)
501501

502502
void fail_vcpu_run_no_handler(int ret)
503503
{
504-
TEST_FAIL("Unexpected vcpu run failure\n");
504+
TEST_FAIL("Unexpected vcpu run failure");
505505
}
506506

507507
void fail_vcpu_run_mmio_no_syndrome_handler(int ret)

tools/testing/selftests/kvm/aarch64/smccc_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void expect_call_denied(struct kvm_vcpu *vcpu)
178178
struct ucall uc;
179179

180180
if (get_ucall(vcpu, &uc) != UCALL_SYNC)
181-
TEST_FAIL("Unexpected ucall: %lu\n", uc.cmd);
181+
TEST_FAIL("Unexpected ucall: %lu", uc.cmd);
182182

183183
TEST_ASSERT(uc.args[1] == SMCCC_RET_NOT_SUPPORTED,
184184
"Unexpected SMCCC return code: %lu", uc.args[1]);

tools/testing/selftests/kvm/aarch64/vpmu_counter_access.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ static void test_create_vpmu_vm_with_pmcr_n(uint64_t pmcr_n, bool expect_fail)
517517

518518
if (expect_fail)
519519
TEST_ASSERT(pmcr_orig == pmcr,
520-
"PMCR.N modified by KVM to a larger value (PMCR: 0x%lx) for pmcr_n: 0x%lx\n",
520+
"PMCR.N modified by KVM to a larger value (PMCR: 0x%lx) for pmcr_n: 0x%lx",
521521
pmcr, pmcr_n);
522522
else
523523
TEST_ASSERT(pmcr_n == get_pmcr_n(pmcr),
524-
"Failed to update PMCR.N to %lu (received: %lu)\n",
524+
"Failed to update PMCR.N to %lu (received: %lu)",
525525
pmcr_n, get_pmcr_n(pmcr));
526526
}
527527

@@ -594,12 +594,12 @@ static void run_pmregs_validity_test(uint64_t pmcr_n)
594594
*/
595595
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id), &reg_val);
596596
TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0,
597-
"Initial read of set_reg: 0x%llx has unimplemented counters enabled: 0x%lx\n",
597+
"Initial read of set_reg: 0x%llx has unimplemented counters enabled: 0x%lx",
598598
KVM_ARM64_SYS_REG(set_reg_id), reg_val);
599599

600600
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(clr_reg_id), &reg_val);
601601
TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0,
602-
"Initial read of clr_reg: 0x%llx has unimplemented counters enabled: 0x%lx\n",
602+
"Initial read of clr_reg: 0x%llx has unimplemented counters enabled: 0x%lx",
603603
KVM_ARM64_SYS_REG(clr_reg_id), reg_val);
604604

605605
/*
@@ -611,12 +611,12 @@ static void run_pmregs_validity_test(uint64_t pmcr_n)
611611

612612
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(set_reg_id), &reg_val);
613613
TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0,
614-
"Read of set_reg: 0x%llx has unimplemented counters enabled: 0x%lx\n",
614+
"Read of set_reg: 0x%llx has unimplemented counters enabled: 0x%lx",
615615
KVM_ARM64_SYS_REG(set_reg_id), reg_val);
616616

617617
vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(clr_reg_id), &reg_val);
618618
TEST_ASSERT((reg_val & (~valid_counters_mask)) == 0,
619-
"Read of clr_reg: 0x%llx has unimplemented counters enabled: 0x%lx\n",
619+
"Read of clr_reg: 0x%llx has unimplemented counters enabled: 0x%lx",
620620
KVM_ARM64_SYS_REG(clr_reg_id), reg_val);
621621
}
622622

tools/testing/selftests/kvm/demand_paging_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args)
4545

4646
/* Let the guest access its memory */
4747
ret = _vcpu_run(vcpu);
48-
TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
48+
TEST_ASSERT(ret == 0, "vcpu_run failed: %d", ret);
4949
if (get_ucall(vcpu, NULL) != UCALL_SYNC) {
5050
TEST_ASSERT(false,
51-
"Invalid guest sync status: exit_reason=%s\n",
51+
"Invalid guest sync status: exit_reason=%s",
5252
exit_reason_str(run->exit_reason));
5353
}
5454

tools/testing/selftests/kvm/dirty_log_perf_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args)
8888
ret = _vcpu_run(vcpu);
8989
ts_diff = timespec_elapsed(start);
9090

91-
TEST_ASSERT(ret == 0, "vcpu_run failed: %d\n", ret);
91+
TEST_ASSERT(ret == 0, "vcpu_run failed: %d", ret);
9292
TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC,
93-
"Invalid guest sync status: exit_reason=%s\n",
93+
"Invalid guest sync status: exit_reason=%s",
9494
exit_reason_str(run->exit_reason));
9595

9696
pr_debug("Got sync event from vCPU %d\n", vcpu_idx);

tools/testing/selftests/kvm/dirty_log_test.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void default_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err)
262262
"vcpu run failed: errno=%d", err);
263263

264264
TEST_ASSERT(get_ucall(vcpu, NULL) == UCALL_SYNC,
265-
"Invalid guest sync status: exit_reason=%s\n",
265+
"Invalid guest sync status: exit_reason=%s",
266266
exit_reason_str(run->exit_reason));
267267

268268
vcpu_handle_sync_stop();
@@ -376,7 +376,10 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
376376

377377
cleared = kvm_vm_reset_dirty_ring(vcpu->vm);
378378

379-
/* Cleared pages should be the same as collected */
379+
/*
380+
* Cleared pages should be the same as collected, as KVM is supposed to
381+
* clear only the entries that have been harvested.
382+
*/
380383
TEST_ASSERT(cleared == count, "Reset dirty pages (%u) mismatch "
381384
"with collected (%u)", cleared, count);
382385

@@ -410,17 +413,11 @@ static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err)
410413
pr_info("vcpu continues now.\n");
411414
} else {
412415
TEST_ASSERT(false, "Invalid guest sync status: "
413-
"exit_reason=%s\n",
416+
"exit_reason=%s",
414417
exit_reason_str(run->exit_reason));
415418
}
416419
}
417420

418-
static void dirty_ring_before_vcpu_join(void)
419-
{
420-
/* Kick another round of vcpu just to make sure it will quit */
421-
sem_post(&sem_vcpu_cont);
422-
}
423-
424421
struct log_mode {
425422
const char *name;
426423
/* Return true if this mode is supported, otherwise false */
@@ -433,7 +430,6 @@ struct log_mode {
433430
uint32_t *ring_buf_idx);
434431
/* Hook to call when after each vcpu run */
435432
void (*after_vcpu_run)(struct kvm_vcpu *vcpu, int ret, int err);
436-
void (*before_vcpu_join) (void);
437433
} log_modes[LOG_MODE_NUM] = {
438434
{
439435
.name = "dirty-log",
@@ -452,7 +448,6 @@ struct log_mode {
452448
.supported = dirty_ring_supported,
453449
.create_vm_done = dirty_ring_create_vm_done,
454450
.collect_dirty_pages = dirty_ring_collect_dirty_pages,
455-
.before_vcpu_join = dirty_ring_before_vcpu_join,
456451
.after_vcpu_run = dirty_ring_after_vcpu_run,
457452
},
458453
};
@@ -513,14 +508,6 @@ static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err)
513508
mode->after_vcpu_run(vcpu, ret, err);
514509
}
515510

516-
static void log_mode_before_vcpu_join(void)
517-
{
518-
struct log_mode *mode = &log_modes[host_log_mode];
519-
520-
if (mode->before_vcpu_join)
521-
mode->before_vcpu_join();
522-
}
523-
524511
static void generate_random_array(uint64_t *guest_array, uint64_t size)
525512
{
526513
uint64_t i;
@@ -719,6 +706,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
719706
struct kvm_vm *vm;
720707
unsigned long *bmap;
721708
uint32_t ring_buf_idx = 0;
709+
int sem_val;
722710

723711
if (!log_mode_supported()) {
724712
print_skip("Log mode '%s' not supported",
@@ -788,12 +776,22 @@ static void run_test(enum vm_guest_mode mode, void *arg)
788776
/* Start the iterations */
789777
iteration = 1;
790778
sync_global_to_guest(vm, iteration);
791-
host_quit = false;
779+
WRITE_ONCE(host_quit, false);
792780
host_dirty_count = 0;
793781
host_clear_count = 0;
794782
host_track_next_count = 0;
795783
WRITE_ONCE(dirty_ring_vcpu_ring_full, false);
796784

785+
/*
786+
* Ensure the previous iteration didn't leave a dangling semaphore, i.e.
787+
* that the main task and vCPU worker were synchronized and completed
788+
* verification of all iterations.
789+
*/
790+
sem_getvalue(&sem_vcpu_stop, &sem_val);
791+
TEST_ASSERT_EQ(sem_val, 0);
792+
sem_getvalue(&sem_vcpu_cont, &sem_val);
793+
TEST_ASSERT_EQ(sem_val, 0);
794+
797795
pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu);
798796

799797
while (iteration < p->iterations) {
@@ -819,15 +817,21 @@ static void run_test(enum vm_guest_mode mode, void *arg)
819817
assert(host_log_mode == LOG_MODE_DIRTY_RING ||
820818
atomic_read(&vcpu_sync_stop_requested) == false);
821819
vm_dirty_log_verify(mode, bmap);
822-
sem_post(&sem_vcpu_cont);
823820

824-
iteration++;
821+
/*
822+
* Set host_quit before sem_vcpu_cont in the final iteration to
823+
* ensure that the vCPU worker doesn't resume the guest. As
824+
* above, the dirty ring test may stop and wait even when not
825+
* explicitly request to do so, i.e. would hang waiting for a
826+
* "continue" if it's allowed to resume the guest.
827+
*/
828+
if (++iteration == p->iterations)
829+
WRITE_ONCE(host_quit, true);
830+
831+
sem_post(&sem_vcpu_cont);
825832
sync_global_to_guest(vm, iteration);
826833
}
827834

828-
/* Tell the vcpu thread to quit */
829-
host_quit = true;
830-
log_mode_before_vcpu_join();
831835
pthread_join(vcpu_thread, NULL);
832836

833837
pr_info("Total bits checked: dirty (%"PRIu64"), clear (%"PRIu64"), "

tools/testing/selftests/kvm/get-reg-list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void check_supported(struct vcpu_reg_list *c)
152152
continue;
153153

154154
__TEST_REQUIRE(kvm_has_cap(s->capability),
155-
"%s: %s not available, skipping tests\n",
155+
"%s: %s not available, skipping tests",
156156
config_name(c), s->name);
157157
}
158158
}

0 commit comments

Comments
 (0)