KVM: selftests: Clear dirty ring states between two modes in dirty_log_test
authorGavin Shan <gshan@redhat.com>
Thu, 10 Nov 2022 10:49:13 +0000 (18:49 +0800)
committerMarc Zyngier <maz@kernel.org>
Thu, 10 Nov 2022 13:11:58 +0000 (13:11 +0000)
commit7167190ddb863bd061c0c6b61f4cec94184b40da
tree95c2a21a3cf1bf47f6d6073a4756c199f4d749d1
parenta737f5ffb1e883e580730122be11c9eb832a7749
KVM: selftests: Clear dirty ring states between two modes in dirty_log_test

There are two states, which need to be cleared before next mode
is executed. Otherwise, we will hit failure as the following messages
indicate.

- The variable 'dirty_ring_vcpu_ring_full' shared by main and vcpu
  thread. It's indicating if the vcpu exit due to full ring buffer.
  The value can be carried from previous mode (VM_MODE_P40V48_4K) to
  current one (VM_MODE_P40V48_64K) when VM_MODE_P40V48_16K isn't
  supported.

- The current ring buffer index needs to be reset before next mode
  (VM_MODE_P40V48_64K) is executed. Otherwise, the stale value is
  carried from previous mode (VM_MODE_P40V48_4K).

  # ./dirty_log_test -M dirty-ring
  Setting log mode to: 'dirty-ring'
  Test iterations: 32, interval: 10 (ms)
  Testing guest mode: PA-bits:40,  VA-bits:48,  4K pages
  guest physical test memory offset: 0xffbfffc000
    :
  Dirtied 995328 pages
  Total bits checked: dirty (1012434), clear (7114123), track_next (966700)
  Testing guest mode: PA-bits:40,  VA-bits:48, 64K pages
  guest physical test memory offset: 0xffbffc0000
  vcpu stops because vcpu is kicked out...
  vcpu continues now.
  Notifying vcpu to continue
  Iteration 1 collected 0 pages
  vcpu stops because dirty ring is full...
  vcpu continues now.
  vcpu stops because dirty ring is full...
  vcpu continues now.
  vcpu stops because dirty ring is full...
  ==== Test Assertion Failure ====
  dirty_log_test.c:369: cleared == count
  pid=10541 tid=10541 errno=22 - Invalid argument
     1 0x0000000000403087: dirty_ring_collect_dirty_pages at dirty_log_test.c:369
     2 0x0000000000402a0b: log_mode_collect_dirty_pages at dirty_log_test.c:492
     3  (inlined by) run_test at dirty_log_test.c:795
     4  (inlined by) run_test at dirty_log_test.c:705
     5 0x0000000000403a37: for_each_guest_mode at guest_modes.c:100
     6 0x0000000000401ccf: main at dirty_log_test.c:938
     7 0x0000ffff9ecd279b: ?? ??:0
     8 0x0000ffff9ecd286b: ?? ??:0
     9 0x0000000000401def: _start at ??:?
  Reset dirty pages (0) mismatch with collected (35566)

Fix the issues by clearing 'dirty_ring_vcpu_ring_full' and the ring
buffer index before next new mode is to be executed.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221110104914.31280-7-gshan@redhat.com
tools/testing/selftests/kvm/dirty_log_test.c