Skip to content

KVM: selftests: Add aarch64/page_fault_test

Ricardo Koller kvm kvmarm 11 versions – Applied

Status from this message: Applied to next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v10 Latest14 patches 6 repliesApplied
  2. v914 patches 8 repliesSuperseded
  3. v814 patches 8 repliesSuperseded
Earlier versions · 8
VersionPostedPatchesRepliesStatus
v713 patches10 repliesSuperseded
v6 posting 2/213 patches1 replySuperseded
v6 posting 1/213 patches14 repliesApplied
v513 patches5 repliesSuperseded
v413 patches14 repliesSuperseded
v313 patches8 repliesSuperseded
v211 patches4 repliesSuperseded
v111 patches9 repliesSuperseded

Patches in v10 Applied

#Subject and filesSizeRepliesApplied
1/14KVM: selftests: Add a userfaultfd librarytools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/demand_paging_test.c tools/testing/selftests/kvm/include/userfaultfd_util.h +1 more+262 -1981 reply
2/14KVM: selftests: aarch64: Add virt_get_pte_hva() library functiontools/testing/selftests/kvm/include/aarch64/processor.h tools/testing/selftests/kvm/lib/aarch64/processor.c+12 -30 replies
3/14KVM: selftests: Add missing close and munmap in __vm_mem_region_delete()tools/testing/selftests/kvm/lib/kvm_util.c+6 -00 replies
4/14KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h macrostools/testing/selftests/kvm/include/aarch64/processor.h tools/testing/selftests/kvm/lib/aarch64/processor.c+20 -70 replies
5/14tools: Copy bitfield.h from the kernel sourcestools/include/linux/bitfield.h+176 -00 replies
6/14KVM: selftests: Stash backing_src_type in struct userspace_mem_regiontools/testing/selftests/kvm/include/kvm_util_base.h tools/testing/selftests/kvm/lib/kvm_util.c+2 -00 replies
7/14KVM: selftests: Add vm->memslots[] and enum kvm_mem_region_typetools/testing/selftests/kvm/include/kvm_util_base.h tools/testing/selftests/kvm/lib/kvm_util.c+34 -100 replies
8/14KVM: selftests: Fix alignment in virt_arch_pgd_alloc() and vm_vaddr_alloc()tools/testing/selftests/kvm/lib/aarch64/processor.c tools/testing/selftests/kvm/lib/riscv/processor.c+30 -240 replies
9/14KVM: selftests: Use the right memslot for code, page-tables, and data allocationstools/testing/selftests/kvm/include/kvm_util_base.h tools/testing/selftests/kvm/lib/aarch64/processor.c tools/testing/selftests/kvm/lib/elf.c +4 more+65 -400 replies
10/14KVM: selftests: aarch64: Add aarch64/page_fault_testtools/testing/selftests/kvm/.gitignore tools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/aarch64/page_fault_test.c +1 more+604 -00 replies
11/14KVM: selftests: aarch64: Add userfaultfd tests into page_fault_testtools/testing/selftests/kvm/aarch64/page_fault_test.c+187 -00 replies
12/14KVM: selftests: aarch64: Add dirty logging tests into page_fault_testtools/testing/selftests/kvm/aarch64/page_fault_test.c+76 -00 replies
13/14KVM: selftests: aarch64: Add readonly memslot tests into page_fault_testtools/testing/selftests/kvm/aarch64/page_fault_test.c+101 -10 replies
14/14KVM: selftests: aarch64: Add mix of tests into page_fault_testtools/testing/selftests/kvm/aarch64/page_fault_test.c+155 -00 replies

Reviews trailers per patch

9 of 14 patches have a Reviewed-by or Acked-by.

PatchOliver UptonBen GardonAndrew JonesSean Christopherson
1/14R-b R-b
2/14R-b R-b
3/14R-b R-b R-b
4/14R-b R-b
5/14R-b
6/14R-b
7/14R-b R-b
8/14R-b
9/14R-b R-b
10/14
11/14
12/14
13/14
14/14

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v10 thread

Cover letter [PATCH v10 00/14] KVM: selftests: Add aarch64/page_fault_test

This series adds a new aarch64 selftest for testing stage 2 fault handling for various combinations of guest accesses (e.g., write, S1PTW), backing sources (e.g., anon), and types of faults (e.g., read on hugetlbfs with a hole, write on a readonly memslot). Each test tries a different combination and then checks that the access results in the right behavior (e.g., uffd faults with the right address and write/read flag). Some interesting combinations are:

- loading an instruction leads to a stage 1 page-table-walk that misses on stage 2 because the backing memslot for the page table it not in host memory (a hole was punched right there) and the fault is handled using userfaultfd. The expected behavior is that this leads to a userfaultfd fault marked as a write. See commit c4ad98e4b72c ("KVM: arm64: Assume write fault on S1PTW permission fault on instruction fetch") for why that's a write.
- a cas (compare-and-swap) on a readonly memslot leads to a failed vcpu run.
- write-faulting on a memslot that's marked for userfaultfd handling and dirty logging should result in a uffd fault and having the respective bit set in the dirty log.

The first 8 commits of this series add library support. The first one adds a new userfaultfd library. Commits 2-5 add some misc library changes that will be used by the new test, like a library function to get the GPA of a PTE. Commits 6-8 breaks the implicit assumption that code and page tables live in memslot memslots should allocators use. This is then used by the new test to place the page tables in a specific memslot. The last 5 commits add the new selftest, one type of test at a time. It first adds core tests, then uffd, then dirty logging, then readonly memslots tests, and finally combinations of the previous ones (like uffd and dirty logging at the same time).

v9 -> v10: https://lore.kernel.org/kvmarm/[email protected]/
- collected r-b's from Andrew
- fixed indentation in several places (mainly alignment of params) [Sean]
- renamed args in uffd_setup [Sean]

v8 -> v9: https://lore.kernel.org/kvmarm/[email protected]/
- removed check before trying madvise(MADV_DONTNEED) on anon hugetlb. [Sean]
- renamed punch_hole_in_memslot() [Sean]
- changed the comment describing the accesses on "holes" [Sean]
- collectd r-b's from Sean

v7 -> v8: https://lore.kernel.org/kvmarm/[email protected]/
- applied Sean's suggestion of adding a fourth region: DATA, and renamed the old DATA one to DATA_TEST. [Sean]
- removed some unneeded code in page_fault_test.c. [Andrew]
- removed r-b's from Andrew and Oliver in commit "KVM: selftests: Use the right memslot for code, page-tables, and data allocations", as the commit changed quite a bit (again). Thanks for the reviews! would it have been OK to keep it? not sure how strict we all are about collecting r-b's on a commit that changed.

Ricardo Koller (14):
KVM: selftests: Add a userfaultfd library
KVM: selftests: aarch64: Add virt_get_pte_hva() library function
KVM: selftests: Add missing close and munmap in

    __vm_mem_region_delete()

KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h
macros
tools: Copy bitfield.h from the kernel sources
KVM: selftests: Stash backing_src_type in struct userspace_mem_region
KVM: selftests: Add vm->memslots[] and enum kvm_mem_region_type
KVM: selftests: Fix alignment in virt_arch_pgd_alloc() and
vm_vaddr_alloc()
KVM: selftests: Use the right memslot for code, page-tables, and data
allocations
KVM: selftests: aarch64: Add aarch64/page_fault_test
KVM: selftests: aarch64: Add userfaultfd tests into page_fault_test
KVM: selftests: aarch64: Add dirty logging tests into page_fault_test
KVM: selftests: aarch64: Add readonly memslot tests into
page_fault_test
KVM: selftests: aarch64: Add mix of tests into page_fault_test

 tools/include/linux/bitfield.h                |  176 +++
 tools/testing/selftests/kvm/.gitignore        |    1 +
 tools/testing/selftests/kvm/Makefile          |    2 +
 .../selftests/kvm/aarch64/page_fault_test.c   | 1112 +++++++++++++++++
 .../selftests/kvm/demand_paging_test.c        |  228 +---
 .../selftests/kvm/include/aarch64/processor.h |   35 +-
 .../selftests/kvm/include/kvm_util_base.h     |   31 +-
 .../selftests/kvm/include/userfaultfd_util.h  |   45 +
 .../selftests/kvm/lib/aarch64/processor.c     |   48 +-
 tools/testing/selftests/kvm/lib/elf.c         |    3 +-
 tools/testing/selftests/kvm/lib/kvm_util.c    |   82 +-
 .../selftests/kvm/lib/riscv/processor.c       |   29 +-
 .../selftests/kvm/lib/s390x/processor.c       |    8 +-
 .../selftests/kvm/lib/userfaultfd_util.c      |  186 +++
 .../selftests/kvm/lib/x86_64/processor.c      |   13 +-
 15 files changed, 1723 insertions(+), 276 deletions(-)
 create mode 100644 tools/include/linux/bitfield.h
 create mode 100644 tools/testing/selftests/kvm/aarch64/page_fault_test.c
 create mode 100644 tools/testing/selftests/kvm/include/userfaultfd_util.h
 create mode 100644 tools/testing/selftests/kvm/lib/userfaultfd_util.c
Signature · 1 line
2.38.0.413.g74048e4d9e-goog