History

KVM: selftests: aarch64: Fix check of dirty log PT write

The dirty log checks are mistakenly testing the first page in the page table (PT) memory region instead of the page holding the test data page PTE. This wasn't an issue before commit 406504c7b040 ("KVM: arm64: Fix S1PTW handling on RO memslots") as all PT pages (including the first page) were treated as writes. Fix the page_fault_test dirty logging tests by checking for the right page: the one for the PTE of the data test page.

Ricardo Koller committed 3 years ago

Commit 8b03c971 parent 42561751 file · +5 −2Browse files

Unified · Split

tools/testing/selftests/kvm/aarch64/page_fault_test.c+5−2
@@ -470,9 +470,12 @@ static bool handle_cmd(struct kvm_vm *vm, int cmd) · 469 unmodified lines
470470 {
471471 struct userspace_mem_region *data_region, *pt_region;
472472 bool continue_test = true;
473+ uint64_t pte_gpa, pte_pg;
473474
474475 data_region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA);
475476 pt_region = vm_get_mem_region(vm, MEM_REGION_PT);
477+ pte_gpa = addr_hva2gpa(vm, virt_get_pte_hva(vm, TEST_GVA));
478+ pte_pg = (pte_gpa - pt_region->region.guest_phys_addr) / getpagesize();
476479
477480 if (cmd == CMD_SKIP_TEST)
478481 continue_test = false;
@@ -485,13 +488,13 @@ static bool handle_cmd(struct kvm_vm *vm, int cmd) · 6 unmodified lines
485488 TEST_ASSERT(check_write_in_dirty_log(vm, data_region, 0),
486489 "Missing write in dirty log");
487490 if (cmd & CMD_CHECK_S1PTW_WR_IN_DIRTY_LOG)
488− TEST_ASSERT(check_write_in_dirty_log(vm, pt_region, 0),
491+ TEST_ASSERT(check_write_in_dirty_log(vm, pt_region, pte_pg),
489492 "Missing s1ptw write in dirty log");
490493 if (cmd & CMD_CHECK_NO_WRITE_IN_DIRTY_LOG)
491494 TEST_ASSERT(!check_write_in_dirty_log(vm, data_region, 0),
492495 "Unexpected write in dirty log");
493496 if (cmd & CMD_CHECK_NO_S1PTW_WR_IN_DIRTY_LOG)
494− TEST_ASSERT(!check_write_in_dirty_log(vm, pt_region, 0),
497+ TEST_ASSERT(!check_write_in_dirty_log(vm, pt_region, pte_pg),
495498 "Unexpected s1ptw write in dirty log");
496499
497500 return continue_test;