linux-stable/tools/testing/selftests/kvm
Sean Christopherson 9f9aff002a KVM: selftests: Fix a semaphore imbalance in the dirty ring logging test
[ Upstream commit ba58f873cd ]

When finishing the final iteration of dirty_log_test testcase, set
host_quit _before_ the final "continue" so that the vCPU worker doesn't
run an extra iteration, and delete the hack-a-fix of an extra "continue"
from the dirty ring testcase.  This fixes a bug where the extra post to
sem_vcpu_cont may not be consumed, which results in failures in subsequent
runs of the testcases.  The bug likely was missed during development as
x86 supports only a single "guest mode", i.e. there aren't any subsequent
testcases after the dirty ring test, because for_each_guest_mode() only
runs a single iteration.

For the regular dirty log testcases, letting the vCPU run one extra
iteration is a non-issue as the vCPU worker waits on sem_vcpu_cont if and
only if the worker is explicitly told to stop (vcpu_sync_stop_requested).
But for the dirty ring test, which needs to periodically stop the vCPU to
reap the dirty ring, letting the vCPU resume the guest _after_ the last
iteration means the vCPU will get stuck without an extra "continue".

However, blindly firing off an post to sem_vcpu_cont isn't guaranteed to
be consumed, e.g. if the vCPU worker sees host_quit==true before resuming
the guest.  This results in a dangling sem_vcpu_cont, which leads to
subsequent iterations getting out of sync, as the vCPU worker will
continue on before the main task is ready for it to resume the guest,
leading to a variety of asserts, e.g.

  ==== Test Assertion Failure ====
  dirty_log_test.c:384: dirty_ring_vcpu_ring_full
  pid=14854 tid=14854 errno=22 - Invalid argument
     1  0x00000000004033eb: dirty_ring_collect_dirty_pages at dirty_log_test.c:384
     2  0x0000000000402d27: log_mode_collect_dirty_pages at dirty_log_test.c:505
     3   (inlined by) run_test at dirty_log_test.c:802
     4  0x0000000000403dc7: for_each_guest_mode at guest_modes.c:100
     5  0x0000000000401dff: main at dirty_log_test.c:941 (discriminator 3)
     6  0x0000ffff9be173c7: ?? ??:0
     7  0x0000ffff9be1749f: ?? ??:0
     8  0x000000000040206f: _start at ??:?
  Didn't continue vcpu even without ring full

Alternatively, the test could simply reset the semaphores before each
testcase, but papering over hacks with more hacks usually ends in tears.

Reported-by: Shaoqin Huang <shahuang@redhat.com>
Fixes: 84292e5659 ("KVM: selftests: Add dirty ring buffer test")
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Shaoqin Huang <shahuang@redhat.com>
Link: https://lore.kernel.org/r/20240202231831.354848-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-02-23 09:24:49 +01:00
..
aarch64 KVM/riscv changes for 6.6 2023-08-31 13:25:55 -04:00
include KVM selftests fixes for 6.6: 2023-10-15 08:25:18 -04:00
lib KVM: selftests: Remove obsolete and incorrect test case metadata 2023-10-04 12:53:05 -07:00
riscv KVM: riscv: selftests: Selectively filter-out AIA registers 2023-09-21 15:04:05 +05:30
s390x KVM: s390: selftests: Add selftest for single-stepping 2023-08-28 09:24:20 +00:00
x86_64 KVM: selftests: Avoid infinite loop in hyperv_features when invtsc is missing 2024-02-23 09:24:49 +01:00
.gitignore KVM: selftests: Use pattern matching in .gitignore 2022-12-27 06:00:46 -05:00
access_tracking_perf_test.c Merge remote-tracking branch 'kvm/queue' into HEAD 2022-12-12 15:54:07 -05:00
config KVM: selftests: Fixup config fragment for access_tracking_perf_test 2023-03-30 19:27:56 +01:00
demand_paging_test.c KVM: selftests: Allow specify physical cpu list in demand paging test 2023-06-06 17:29:49 -07:00
dirty_log_perf_test.c KVM: selftests: Allow specify physical cpu list in demand paging test 2023-06-06 17:29:49 -07:00
dirty_log_test.c KVM: selftests: Fix a semaphore imbalance in the dirty ring logging test 2024-02-23 09:24:49 +01:00
get-reg-list.c KVM: selftests: Add skip_set facility to get_reg_list test 2023-08-09 12:15:22 +05:30
guest_print_test.c KVM: selftests: Rip out old, param-based guest assert macros 2023-08-02 14:43:16 -07:00
hardware_disable_test.c
kvm_binary_stats_test.c KVM: selftests: Verify stats fd is usable after VM fd has been closed 2023-07-29 11:05:30 -04:00
kvm_create_max_vcpus.c
kvm_page_table_test.c KVM: selftests: use unified time type for comparison 2023-08-02 13:36:08 -07:00
Makefile KVM/riscv changes for 6.6 2023-08-31 13:25:55 -04:00
max_guest_memory_test.c KVM: selftests: Rename the ASSERT_EQ macro 2023-08-02 14:34:01 -07:00
memslot_modification_stress_test.c
memslot_perf_test.c KVM: selftests: Zero-initialize entire test_result in memslot perf test 2023-10-05 19:23:47 -07:00
rseq_test.c KVM: selftests: Fix build of rseq test 2023-01-30 16:29:45 +01:00
set_memory_region_test.c KVM: selftests: Rip out old, param-based guest assert macros 2023-08-02 14:43:16 -07:00
settings
steal_time.c KVM: selftests: Rip out old, param-based guest assert macros 2023-08-02 14:43:16 -07:00
system_counter_offset_test.c