Skip to content

Commit 0c55f86

Browse files
maciejsszmigierobonzini
authored andcommitted
selftests: kvm/set_memory_region_test: Fix race in move region test
The current memory region move test correctly handles the situation that the second (realigning) memslot move operation would temporarily trigger MMIO until it completes, however it does not handle the case in which the first (misaligning) move operation does this, too. This results in false test assertions in case it does so. Fix this by handling temporary MMIO from the first memslot move operation in the test guest code, too. Fixes: 8a0639f ("KVM: sefltests: Add explicit synchronization to move mem region test") Signed-off-by: Maciej S. Szmigiero <[email protected]> Message-Id: <0fdddb94bb0e31b7da129a809a308d91c10c0b5e.1606941224.git.maciej.szmigiero@oracle.com> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 9a2a0d3 commit 0c55f86

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tools/testing/selftests/kvm/set_memory_region_test.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,23 @@ static void guest_code_move_memory_region(void)
156156
GUEST_SYNC(0);
157157

158158
/*
159-
* Spin until the memory region is moved to a misaligned address. This
160-
* may or may not trigger MMIO, as the window where the memslot is
161-
* invalid is quite small.
159+
* Spin until the memory region starts getting moved to a
160+
* misaligned address.
161+
* Every region move may or may not trigger MMIO, as the
162+
* window where the memslot is invalid is usually quite small.
162163
*/
163164
val = guest_spin_on_val(0);
164165
GUEST_ASSERT_1(val == 1 || val == MMIO_VAL, val);
165166

166-
/* Spin until the memory region is realigned. */
167+
/* Spin until the misaligning memory region move completes. */
168+
val = guest_spin_on_val(MMIO_VAL);
169+
GUEST_ASSERT_1(val == 1 || val == 0, val);
170+
171+
/* Spin until the memory region starts to get re-aligned. */
172+
val = guest_spin_on_val(0);
173+
GUEST_ASSERT_1(val == 1 || val == MMIO_VAL, val);
174+
175+
/* Spin until the re-aligning memory region move completes. */
167176
val = guest_spin_on_val(MMIO_VAL);
168177
GUEST_ASSERT_1(val == 1, val);
169178

0 commit comments

Comments
 (0)