mbox series

[v6,00/13] KVM: selftests: Add aarch64/page_fault_test

Message ID 20220906180930.230218-1-ricarkol@google.com (mailing list archive)
Headers show
Series KVM: selftests: Add aarch64/page_fault_test | expand

Message

Ricardo Koller Sept. 6, 2022, 6:09 p.m. UTC
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 (out of demand_paging_test.c). The next 3 add some
library functions to get the GPA of a PTE, and to get the fd of a backing
source. Commit 6 fixes a leaked fd when using shared backing stores. 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).

v5 -> v6: https://lore.kernel.org/kvmarm/20220823234727.621535-1-ricarkol@google.com/
- added "enum memslot_type" and all the related cleanups due to it [Andrew]
- default kvm_vm_mem_default with size=0 [Andrew,Sean]
- __vm_vaddr_alloc() taking "enum memslot_type" and all the related cleanups
  due to this change [Andrew]

v4 -> v5: https://lore.kernel.org/kvmarm/20220624213257.1504783-1-ricarkol@google.com/
- biggest change: followed suggestion from Sean and Andrew regarding a new
  arg for vm_create() to specify the guest memory layout. That's taken care
  of with these two new commits:
	KVM: selftests: Use the right memslot for code, page-tables, and data allocations
	KVM: selftests: Change ____vm_create() to take struct kvm_vm_mem_params
  plus the respective changes in the page_fault_test itself (mostly code reduction).
- dropped some commits that are not needed after the above change:
	KVM: selftests: aarch64: Export _virt_pg_map with a pt_memslot arg
	KVM: selftests: Add vm_alloc_page_table_in_memslot library function
	KVM: selftests: Add vm_mem_region_get_src_fd library function
- addressed Oliver comments in commit "KVM: selftests: aarch64: Add
  aarch64/page_fault_test"
- collect r-b's from Andrew

v3 -> v4: https://lore.kernel.org/kvmarm/20220408004120.1969099-1-ricarkol@google.com/
- rebased on top of latest kvm/queue.
- addressed Oliver comments: vm_get_pte_gpa rename, page_fault_test and
  other nits.
- adding MAIR entry for MT_DEVICE_nGnRnE. The value and indices are both
  0, so the change is really esthetic.

Ricardo Koller (13):
  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: Change ____vm_create() to take struct
    kvm_vm_mem_params
  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/Makefile          |    2 +
 .../selftests/kvm/aarch64/page_fault_test.c   | 1137 +++++++++++++++++
 .../selftests/kvm/demand_paging_test.c        |  228 +---
 .../selftests/kvm/include/aarch64/processor.h |   35 +-
 .../selftests/kvm/include/kvm_util_base.h     |   55 +-
 .../selftests/kvm/include/userfaultfd_util.h  |   46 +
 .../selftests/kvm/lib/aarch64/processor.c     |   29 +-
 tools/testing/selftests/kvm/lib/elf.c         |    3 +-
 tools/testing/selftests/kvm/lib/kvm_util.c    |  122 +-
 .../selftests/kvm/lib/riscv/processor.c       |    7 +-
 .../selftests/kvm/lib/s390x/processor.c       |    7 +-
 .../selftests/kvm/lib/userfaultfd_util.c      |  187 +++
 .../selftests/kvm/lib/x86_64/processor.c      |   13 +-
 14 files changed, 1789 insertions(+), 258 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

Comments

Marc Zyngier Sept. 19, 2022, 10:38 a.m. UTC | #1
On Tue, 6 Sep 2022 18:09:17 +0000, Ricardo Koller wrote:
> 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:
> 
> [...]

Given how long this has been around, I've picked this series up, applying
Oliver's fixes in the process. Any additional fixes will be added on top.

Applied to next, thanks!

[01/13] KVM: selftests: Add a userfaultfd library
        commit: b9e9f0060d69ace412846b3dda318189e74d80ea
[02/13] KVM: selftests: aarch64: Add virt_get_pte_hva() library function
        commit: b3e02786e384d83637fc29dca2af9604a6314e62
[03/13] KVM: selftests: Add missing close and munmap in __vm_mem_region_delete()
        commit: 77c071a5376c9fdc0c510138d081af5e6ead754d
[04/13] KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h macros
        commit: a68c2b6545af95729eb57fe39f173557d1f22649
[05/13] tools: Copy bitfield.h from the kernel sources
        commit: 8998ed5834af0a9cc3de8d5bd485576c654620fc
[06/13] KVM: selftests: Stash backing_src_type in struct userspace_mem_region
        commit: 20a8d07c0828592d72c756c98f2708e905bfabd3
[07/13] KVM: selftests: Change ____vm_create() to take struct kvm_vm_mem_params
        commit: cb7f9c457b94b2ad71eaf9621a9e7f3e9c3832db
[08/13] KVM: selftests: Use the right memslot for code, page-tables, and data allocations
        commit: 72ad71ddb5fae4dc26a2fa7e885213598baab9ad
[09/13] KVM: selftests: aarch64: Add aarch64/page_fault_test
        commit: fa7b86adf85be5de36a797df7b1509542af1f119
[10/13] KVM: selftests: aarch64: Add userfaultfd tests into page_fault_test
        commit: 596fcc0f6888241b0b2f02577a2b608f274b299d
[11/13] KVM: selftests: aarch64: Add dirty logging tests into page_fault_test
        commit: 0740d435146f69be9950df5dd45a31fbaec943ba
[12/13] KVM: selftests: aarch64: Add readonly memslot tests into page_fault_test
        commit: a9246644455d51faa4063749bb17aa7e060adc70
[13/13] KVM: selftests: aarch64: Add mix of tests into page_fault_test
        commit: 383d48a1442ca477732ea77d6231b3cc73b9d7f8

Cheers,

	M.
Sean Christopherson Sept. 19, 2022, 4:38 p.m. UTC | #2
On Mon, Sep 19, 2022, Marc Zyngier wrote:
> On Tue, 6 Sep 2022 18:09:17 +0000, Ricardo Koller wrote:
> > 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:
> > 
> > [...]
> 
> Given how long this has been around, I've picked this series up, applying
> Oliver's fixes in the process.

Any chance this can be undone?  A big reason why this is at v6 is because of the
common API changes, and due to KVM Forum I've effectively had three working days
since this was posted, and others have probably had even less, i.e. lack of reviews
on v6 isn't because no one cares.

It's not the end of the world if we have to fix things up on top, but we'd avoid
a decent amount of churn if we can instead unwind and do a v7.
Marc Zyngier Sept. 19, 2022, 4:57 p.m. UTC | #3
On Mon, 19 Sep 2022 17:38:14 +0100,
Sean Christopherson <seanjc@google.com> wrote:
> 
> On Mon, Sep 19, 2022, Marc Zyngier wrote:
> > On Tue, 6 Sep 2022 18:09:17 +0000, Ricardo Koller wrote:
> > > 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:
> > > 
> > > [...]
> > 
> > Given how long this has been around, I've picked this series up, applying
> > Oliver's fixes in the process.
> 
> Any chance this can be undone?  A big reason why this is at v6 is
> because of the common API changes, and due to KVM Forum I've
> effectively had three working days since this was posted, and others
> have probably had even less, i.e. lack of reviews on v6 isn't
> because no one cares.

Hey, I'm still not back at work, and won't be for another week! But
fair enough, if there is going to be a respin, I'd rather see that
(and I'm less hung up on tests having been in -next for some time
before sending out a PR that eventually reaches Linus).

> It's not the end of the world if we have to fix things up on top,
> but we'd avoid a decent amount of churn if we can instead unwind and
> do a v7.

No skin off my nose, as this leaves on its own topic branch. Now
dropped.

	M.
Ricardo Koller Sept. 19, 2022, 6:28 p.m. UTC | #4
On Mon, Sep 19, 2022 at 05:57:16PM +0100, Marc Zyngier wrote:
> On Mon, 19 Sep 2022 17:38:14 +0100,
> Sean Christopherson <seanjc@google.com> wrote:
> > 
> > On Mon, Sep 19, 2022, Marc Zyngier wrote:
> > > On Tue, 6 Sep 2022 18:09:17 +0000, Ricardo Koller wrote:
> > > > 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:
> > > > 
> > > > [...]
> > > 
> > > Given how long this has been around, I've picked this series up, applying
> > > Oliver's fixes in the process.
> > 
> > Any chance this can be undone?  A big reason why this is at v6 is
> > because of the common API changes, and due to KVM Forum I've
> > effectively had three working days since this was posted, and others
> > have probably had even less, i.e. lack of reviews on v6 isn't
> > because no one cares.
> 
> Hey, I'm still not back at work, and won't be for another week! But
> fair enough, if there is going to be a respin, I'd rather see that
> (and I'm less hung up on tests having been in -next for some time
> before sending out a PR that eventually reaches Linus).
> 
> > It's not the end of the world if we have to fix things up on top,
> > but we'd avoid a decent amount of churn if we can instead unwind and
> > do a v7.
> 
> No skin off my nose, as this leaves on its own topic branch. Now
> dropped.

Thank you both. Yes, this will make our lives easier (including getting
the changes internally).

Ricardo

> 
> 	M.
> 
> -- 
> Without deviation from the norm, progress is not possible.