Commit ba58f87
committed
KVM: selftests: Fix a semaphore imbalance in the dirty ring logging test
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 <[email protected]>
Fixes: 84292e5 ("KVM: selftests: Add dirty ring buffer test")
Reviewed-by: Peter Xu <[email protected]>
Reviewed-by: Shaoqin Huang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sean Christopherson <[email protected]>1 parent 9e62797 commit ba58f87
1 file changed
+27
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
380 | 383 | | |
381 | 384 | | |
382 | 385 | | |
| |||
415 | 418 | | |
416 | 419 | | |
417 | 420 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | 421 | | |
425 | 422 | | |
426 | 423 | | |
| |||
433 | 430 | | |
434 | 431 | | |
435 | 432 | | |
436 | | - | |
437 | 433 | | |
438 | 434 | | |
439 | 435 | | |
| |||
452 | 448 | | |
453 | 449 | | |
454 | 450 | | |
455 | | - | |
456 | 451 | | |
457 | 452 | | |
458 | 453 | | |
| |||
513 | 508 | | |
514 | 509 | | |
515 | 510 | | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | 511 | | |
525 | 512 | | |
526 | 513 | | |
| |||
719 | 706 | | |
720 | 707 | | |
721 | 708 | | |
| 709 | + | |
722 | 710 | | |
723 | 711 | | |
724 | 712 | | |
| |||
788 | 776 | | |
789 | 777 | | |
790 | 778 | | |
791 | | - | |
| 779 | + | |
792 | 780 | | |
793 | 781 | | |
794 | 782 | | |
795 | 783 | | |
796 | 784 | | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
797 | 795 | | |
798 | 796 | | |
799 | 797 | | |
| |||
819 | 817 | | |
820 | 818 | | |
821 | 819 | | |
822 | | - | |
823 | 820 | | |
824 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
825 | 832 | | |
826 | 833 | | |
827 | 834 | | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | 835 | | |
832 | 836 | | |
833 | 837 | | |
| |||
0 commit comments