Skip to content

Commit 08ddbbd

Browse files
Ricardo KollerMarc Zyngier
authored andcommitted
KVM: selftests: aarch64: Test read-only PT memory regions
Extend the read-only memslot tests in page_fault_test to test read-only PT (Page table) memslots. Note that this was not allowed before commit 406504c ("KVM: arm64: Fix S1PTW handling on RO memslots") as all S1PTW faults were treated as writes which resulted in an (unrecoverable) exception inside the guest. Signed-off-by: Ricardo Koller <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8b03c97 commit 08ddbbd

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tools/testing/selftests/kvm/aarch64/page_fault_test.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,9 @@ static void help(char *name)
829829

830830
#define TEST_RO_MEMSLOT(_access, _mmio_handler, _mmio_exits) \
831831
{ \
832-
.name = SCAT3(ro_memslot, _access, _with_af), \
832+
.name = SCAT2(ro_memslot, _access), \
833833
.data_memslot_flags = KVM_MEM_READONLY, \
834+
.pt_memslot_flags = KVM_MEM_READONLY, \
834835
.guest_prepare = { _PREPARE(_access) }, \
835836
.guest_test = _access, \
836837
.mmio_handler = _mmio_handler, \
@@ -841,6 +842,7 @@ static void help(char *name)
841842
{ \
842843
.name = SCAT2(ro_memslot_no_syndrome, _access), \
843844
.data_memslot_flags = KVM_MEM_READONLY, \
845+
.pt_memslot_flags = KVM_MEM_READONLY, \
844846
.guest_test = _access, \
845847
.fail_vcpu_run_handler = fail_vcpu_run_mmio_no_syndrome_handler, \
846848
.expected_events = { .fail_vcpu_runs = 1 }, \
@@ -849,9 +851,9 @@ static void help(char *name)
849851
#define TEST_RO_MEMSLOT_AND_DIRTY_LOG(_access, _mmio_handler, _mmio_exits, \
850852
_test_check) \
851853
{ \
852-
.name = SCAT3(ro_memslot, _access, _with_af), \
854+
.name = SCAT2(ro_memslot, _access), \
853855
.data_memslot_flags = KVM_MEM_READONLY | KVM_MEM_LOG_DIRTY_PAGES, \
854-
.pt_memslot_flags = KVM_MEM_LOG_DIRTY_PAGES, \
856+
.pt_memslot_flags = KVM_MEM_READONLY | KVM_MEM_LOG_DIRTY_PAGES, \
855857
.guest_prepare = { _PREPARE(_access) }, \
856858
.guest_test = _access, \
857859
.guest_test_check = { _test_check }, \
@@ -863,7 +865,7 @@ static void help(char *name)
863865
{ \
864866
.name = SCAT2(ro_memslot_no_syn_and_dlog, _access), \
865867
.data_memslot_flags = KVM_MEM_READONLY | KVM_MEM_LOG_DIRTY_PAGES, \
866-
.pt_memslot_flags = KVM_MEM_LOG_DIRTY_PAGES, \
868+
.pt_memslot_flags = KVM_MEM_READONLY | KVM_MEM_LOG_DIRTY_PAGES, \
867869
.guest_test = _access, \
868870
.guest_test_check = { _test_check }, \
869871
.fail_vcpu_run_handler = fail_vcpu_run_mmio_no_syndrome_handler, \
@@ -875,6 +877,7 @@ static void help(char *name)
875877
{ \
876878
.name = SCAT2(ro_memslot_uffd, _access), \
877879
.data_memslot_flags = KVM_MEM_READONLY, \
880+
.pt_memslot_flags = KVM_MEM_READONLY, \
878881
.mem_mark_cmd = CMD_HOLE_DATA | CMD_HOLE_PT, \
879882
.guest_prepare = { _PREPARE(_access) }, \
880883
.guest_test = _access, \
@@ -890,6 +893,7 @@ static void help(char *name)
890893
{ \
891894
.name = SCAT2(ro_memslot_no_syndrome, _access), \
892895
.data_memslot_flags = KVM_MEM_READONLY, \
896+
.pt_memslot_flags = KVM_MEM_READONLY, \
893897
.mem_mark_cmd = CMD_HOLE_DATA | CMD_HOLE_PT, \
894898
.guest_test = _access, \
895899
.uffd_data_handler = _uffd_data_handler, \
@@ -1024,7 +1028,7 @@ static struct test_desc tests[] = {
10241028
guest_check_write_in_dirty_log,
10251029
guest_check_s1ptw_wr_in_dirty_log),
10261030
/*
1027-
* Try accesses when the data memory region is marked read-only
1031+
* Access when both the PT and data regions are marked read-only
10281032
* (with KVM_MEM_READONLY). Writes with a syndrome result in an
10291033
* MMIO exit, writes with no syndrome (e.g., CAS) result in a
10301034
* failed vcpu run, and reads/execs with and without syndroms do
@@ -1040,7 +1044,7 @@ static struct test_desc tests[] = {
10401044
TEST_RO_MEMSLOT_NO_SYNDROME(guest_st_preidx),
10411045

10421046
/*
1043-
* Access when both the data region is both read-only and marked
1047+
* The PT and data regions are both read-only and marked
10441048
* for dirty logging at the same time. The expected result is that
10451049
* for writes there should be no write in the dirty log. The
10461050
* readonly handling is the same as if the memslot was not marked
@@ -1065,7 +1069,7 @@ static struct test_desc tests[] = {
10651069
guest_check_no_write_in_dirty_log),
10661070

10671071
/*
1068-
* Access when the data region is both read-only and punched with
1072+
* The PT and data regions are both read-only and punched with
10691073
* holes tracked with userfaultfd. The expected result is the
10701074
* union of both userfaultfd and read-only behaviors. For example,
10711075
* write accesses result in a userfaultfd write fault and an MMIO

0 commit comments

Comments
 (0)