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
470{470{
471 struct userspace_mem_region *data_region, *pt_region;471 struct userspace_mem_region *data_region, *pt_region;
472 bool continue_test = true;472 bool continue_test = true;
473 uint64_t pte_gpa, pte_pg;
473 474
474 data_region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA);475 data_region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA);
475 pt_region = vm_get_mem_region(vm, MEM_REGION_PT);476 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();
476 479
477 if (cmd == CMD_SKIP_TEST)480 if (cmd == CMD_SKIP_TEST)
478 continue_test = false;481 continue_test = false;
@@ -485,13 +488,13 @@ static bool handle_cmd(struct kvm_vm *vm, int cmd) · 6 unmodified lines
485 TEST_ASSERT(check_write_in_dirty_log(vm, data_region, 0),488 TEST_ASSERT(check_write_in_dirty_log(vm, data_region, 0),
486 "Missing write in dirty log");489 "Missing write in dirty log");
487 if (cmd & CMD_CHECK_S1PTW_WR_IN_DIRTY_LOG)490 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),
489 "Missing s1ptw write in dirty log");492 "Missing s1ptw write in dirty log");
490 if (cmd & CMD_CHECK_NO_WRITE_IN_DIRTY_LOG)493 if (cmd & CMD_CHECK_NO_WRITE_IN_DIRTY_LOG)
491 TEST_ASSERT(!check_write_in_dirty_log(vm, data_region, 0),494 TEST_ASSERT(!check_write_in_dirty_log(vm, data_region, 0),
492 "Unexpected write in dirty log");495 "Unexpected write in dirty log");
493 if (cmd & CMD_CHECK_NO_S1PTW_WR_IN_DIRTY_LOG)496 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),
495 "Unexpected s1ptw write in dirty log");498 "Unexpected s1ptw write in dirty log");
496 499
497 return continue_test;500 return continue_test;