Skip to content

Commit 7167190

Browse files
Gavin ShanMarc Zyngier
authored andcommitted
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 <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a737f5f commit 7167190

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tools/testing/selftests/kvm/dirty_log_test.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,15 @@ static void clear_log_create_vm_done(struct kvm_vm *vm)
226226
}
227227

228228
static void dirty_log_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
229-
void *bitmap, uint32_t num_pages)
229+
void *bitmap, uint32_t num_pages,
230+
uint32_t *unused)
230231
{
231232
kvm_vm_get_dirty_log(vcpu->vm, slot, bitmap);
232233
}
233234

234235
static void clear_log_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
235-
void *bitmap, uint32_t num_pages)
236+
void *bitmap, uint32_t num_pages,
237+
uint32_t *unused)
236238
{
237239
kvm_vm_get_dirty_log(vcpu->vm, slot, bitmap);
238240
kvm_vm_clear_dirty_log(vcpu->vm, slot, bitmap, 0, num_pages);
@@ -329,10 +331,9 @@ static void dirty_ring_continue_vcpu(void)
329331
}
330332

331333
static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
332-
void *bitmap, uint32_t num_pages)
334+
void *bitmap, uint32_t num_pages,
335+
uint32_t *ring_buf_idx)
333336
{
334-
/* We only have one vcpu */
335-
static uint32_t fetch_index = 0;
336337
uint32_t count = 0, cleared;
337338
bool continued_vcpu = false;
338339

@@ -349,7 +350,8 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
349350

350351
/* Only have one vcpu */
351352
count = dirty_ring_collect_one(vcpu_map_dirty_ring(vcpu),
352-
slot, bitmap, num_pages, &fetch_index);
353+
slot, bitmap, num_pages,
354+
ring_buf_idx);
353355

354356
cleared = kvm_vm_reset_dirty_ring(vcpu->vm);
355357

@@ -406,7 +408,8 @@ struct log_mode {
406408
void (*create_vm_done)(struct kvm_vm *vm);
407409
/* Hook to collect the dirty pages into the bitmap provided */
408410
void (*collect_dirty_pages) (struct kvm_vcpu *vcpu, int slot,
409-
void *bitmap, uint32_t num_pages);
411+
void *bitmap, uint32_t num_pages,
412+
uint32_t *ring_buf_idx);
410413
/* Hook to call when after each vcpu run */
411414
void (*after_vcpu_run)(struct kvm_vcpu *vcpu, int ret, int err);
412415
void (*before_vcpu_join) (void);
@@ -471,13 +474,14 @@ static void log_mode_create_vm_done(struct kvm_vm *vm)
471474
}
472475

473476
static void log_mode_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
474-
void *bitmap, uint32_t num_pages)
477+
void *bitmap, uint32_t num_pages,
478+
uint32_t *ring_buf_idx)
475479
{
476480
struct log_mode *mode = &log_modes[host_log_mode];
477481

478482
TEST_ASSERT(mode->collect_dirty_pages != NULL,
479483
"collect_dirty_pages() is required for any log mode!");
480-
mode->collect_dirty_pages(vcpu, slot, bitmap, num_pages);
484+
mode->collect_dirty_pages(vcpu, slot, bitmap, num_pages, ring_buf_idx);
481485
}
482486

483487
static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu, int ret, int err)
@@ -696,6 +700,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)
696700
struct kvm_vcpu *vcpu;
697701
struct kvm_vm *vm;
698702
unsigned long *bmap;
703+
uint32_t ring_buf_idx = 0;
699704

700705
if (!log_mode_supported()) {
701706
print_skip("Log mode '%s' not supported",
@@ -771,14 +776,16 @@ static void run_test(enum vm_guest_mode mode, void *arg)
771776
host_dirty_count = 0;
772777
host_clear_count = 0;
773778
host_track_next_count = 0;
779+
WRITE_ONCE(dirty_ring_vcpu_ring_full, false);
774780

775781
pthread_create(&vcpu_thread, NULL, vcpu_worker, vcpu);
776782

777783
while (iteration < p->iterations) {
778784
/* Give the vcpu thread some time to dirty some pages */
779785
usleep(p->interval * 1000);
780786
log_mode_collect_dirty_pages(vcpu, TEST_MEM_SLOT_INDEX,
781-
bmap, host_num_pages);
787+
bmap, host_num_pages,
788+
&ring_buf_idx);
782789

783790
/*
784791
* See vcpu_sync_stop_requested definition for details on why

0 commit comments

Comments
 (0)