Re: [PATCH v4 1/8] mm: Do not enable PG_arch_2 for all 64-bit architectures

2022-09-21 Thread Steven Price
On 21/09/2022 04:51, Peter Collingbourne wrote: > From: Catalin Marinas > > Commit 4beba9486abd ("mm: Add PG_arch_2 page flag") introduced a new > page flag for all 64-bit architectures. However, even if an architecture > is 64-bit, it may still have limited spare bits in the 'flags' member of >

Re: [PATCH v4 4/8] mm: Add PG_arch_3 page flag

2022-09-21 Thread Steven Price
On 21/09/2022 04:51, Peter Collingbourne wrote: > As with PG_arch_2, this flag is only allowed on 64-bit architectures due > to the shortage of bits available. It will be used by the arm64 MTE code > in subsequent patches. NIT: It's now controlled by CONFIG_ARCH_USES_PG_ARCH_X and not technically

Re: [PATCH kernel v2] KVM: PPC: Make KVM_CAP_IRQFD_RESAMPLE support platform dependent

2022-09-21 Thread Marc Zyngier
On Tue, 20 Sep 2022 22:46:21 +0100, Alexey Kardashevskiy wrote: > > > > On 21/09/2022 02:08, Marc Zyngier wr > ote: > > On Tue, 20 Sep 2022 13:51:43 +0100, > > Alexey Kardashevskiy wrote: > >> > >> When introduced, IRQFD resampling worked on POWER8 with XICS. However > >> KVM on POWER9 has ne

Re: [PATCH kernel v3] KVM: PPC: Make KVM_CAP_IRQFD_RESAMPLE support platform dependent

2022-09-21 Thread Marc Zyngier
On Wed, 21 Sep 2022 05:49:25 +0100, Alexey Kardashevskiy wrote: > > When introduced, IRQFD resampling worked on POWER8 with XICS. However > KVM on POWER9 has never implemented it - the compatibility mode code > ("XICS-on-XIVE") misses the kvm_notify_acked_irq() call and the native > XIVE mode doe

Re: [PATCH] KVM: arm64: nvhe: Disable profile optimization

2022-09-21 Thread Marc Zyngier
On Wed, 21 Sep 2022 07:02:50 +0100, Denis Nikitin wrote: > > Adding a few more comments... > > On Tue, Sep 20, 2022 at 5:08 PM Denis Nikitin wrote: > > > > Hi Mark, > > > > Thank you for a quick response. > > > > On Tue, Sep 20, 2022 at 2:34 AM Marc Zyngier wrote: > > > > > > Hi Denis, > > > >

Re: [PATCH v3 1/7] KVM: arm64: Discard any SVE state when entering KVM guests

2022-09-21 Thread Marc Zyngier
On Tue, 20 Sep 2022 21:21:33 +0100, Mark Brown wrote: > > [1 ] > On Tue, Sep 20, 2022 at 05:44:01PM +0100, Marc Zyngier wrote: > > Mark Brown wrote: > > > > void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu) > > > { > > > BUG_ON(!current->mm); > > > - BUG_ON(test_thread_flag(TIF_SVE)); > >

Re: [PATCH v3 3/7] arm64/fpsimd: Have KVM explicitly say which FP registers to save

2022-09-21 Thread Marc Zyngier
On Tue, 20 Sep 2022 19:32:49 +0100, Mark Brown wrote: > > [1 ] > On Tue, Sep 20, 2022 at 06:52:59PM +0100, Marc Zyngier wrote: > > On Mon, 15 Aug 2022 23:55:25 +0100, > > Mark Brown wrote: > > > > enum fp_state { > > > + FP_STATE_TASK, /* Save based on current, invalid as fp_type */

[PATCH v3 0/6] KVM: arm64: Enable ring-based dirty memory tracking

2022-09-21 Thread Gavin Shan
This series enables the ring-based dirty memory tracking for ARM64. The feature has been available and enabled on x86 for a while. It is beneficial when the number of dirty pages is small in a checkpointing system or live migration scenario. More details can be found from fb04a1eddb1a ("KVM: X86: I

[PATCH v3 1/6] KVM: x86: Introduce KVM_REQ_RING_SOFT_FULL

2022-09-21 Thread Gavin Shan
This adds KVM_REQ_RING_SOFT_FULL, which is raised when the dirty ring of the specific VCPU becomes softly full in kvm_dirty_ring_push(). The VCPU is enforced to exit when the request is raised and its dirty ring is softly full on its entrance. Suggested-by: Marc Zyngier Signed-off-by: Gavin Shan

[PATCH v3 2/6] KVM: x86: Move declaration of kvm_cpu_dirty_log_size() to kvm_dirty_ring.h

2022-09-21 Thread Gavin Shan
Not all architectures like ARM64 need to override the function. Move its declaration to kvm_dirty_ring.h to avoid the following compiling warning on ARM64 when the feature is enabled. arch/arm64/kvm/../../../virt/kvm/dirty_ring.c:14:12:\ warning: no previous prototype for 'kvm_cpu_dirt

[PATCH v3 4/6] KVM: selftests: Use host page size to map ring buffer in dirty_log_test

2022-09-21 Thread Gavin Shan
In vcpu_map_dirty_ring(), the guest's page size is used to figure out the offset in the virtual area. It works fine when we have same page sizes on host and guest. However, it fails when the page sizes on host and guest are different on arm64, like below error messages indicates. # ./dirty_log_t

[PATCH v3 3/6] KVM: arm64: Enable ring-based dirty memory tracking

2022-09-21 Thread Gavin Shan
This enables the ring-based dirty memory tracking on ARM64. The feature is configured by CONFIG_HAVE_KVM_DIRTY_RING, detected and enabled by KVM_CAP_DIRTY_LOG_RING. A ring buffer is created on every VCPU when the feature is enabled. Each entry in the ring buffer is described by 'struct kvm_dirty_gf

[PATCH v3 5/6] KVM: selftests: Clear dirty ring states between two modes in dirty_log_test

2022-09-21 Thread Gavin Shan
There are two states, which need to be cleared before next mode is executed. Otherwise, we will hit failure as the following messages indicate. - The variable 'dirty_ring_vcpu_ring_full' shared by main and vcpu thread. It's indicating if the vcpu exit due to full ring buffer. The value can be

[PATCH v3 6/6] KVM: selftests: Automate choosing dirty ring size in dirty_log_test

2022-09-21 Thread Gavin Shan
In the dirty ring case, we rely on vcpu exit due to full dirty ring state. On ARM64 system, there are 4096 host pages when the host page size is 64KB. In this case, the vcpu never exits due to the full dirty ring state. The similar case is 4KB page size on host and 64KB page size on guest. The vcpu

[PATCH v8 00/14] KVM: selftests: Add aarch64/page_fault_test

2022-09-21 Thread Ricardo Koller
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 a

[PATCH v8 01/14] KVM: selftests: Add a userfaultfd library

2022-09-21 Thread Ricardo Koller
Move the generic userfaultfd code out of demand_paging_test.c into a common library, userfaultfd_util. This library consists of a setup and a stop function. The setup function starts a thread for handling page faults using the handler callback function. This setup returns a uffd_desc object which i

[PATCH v8 04/14] KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h macros

2022-09-21 Thread Ricardo Koller
Define macros for memory type indexes and construct DEFAULT_MAIR_EL1 with macros from asm/sysreg.h. The index macros can then be used when constructing PTEs (instead of using raw numbers). Reviewed-by: Andrew Jones Reviewed-by: Oliver Upton Signed-off-by: Ricardo Koller --- .../selftests/kvm/

[PATCH v8 02/14] KVM: selftests: aarch64: Add virt_get_pte_hva() library function

2022-09-21 Thread Ricardo Koller
Add a library function to get the PTE (a host virtual address) of a given GVA. This will be used in a future commit by a test to clear and check the access flag of a particular page. Reviewed-by: Oliver Upton Reviewed-by: Andrew Jones Signed-off-by: Ricardo Koller --- .../selftests/kvm/includ

[PATCH v8 03/14] KVM: selftests: Add missing close and munmap in __vm_mem_region_delete()

2022-09-21 Thread Ricardo Koller
Deleting a memslot (when freeing a VM) is not closing the backing fd, nor it's unmapping the alias mapping. Fix by adding the missing close and munmap. Reviewed-by: Andrew Jones Reviewed-by: Oliver Upton Reviewed-by: Ben Gardon Signed-off-by: Ricardo Koller --- tools/testing/selftests/kvm/lib

[PATCH v8 07/14] KVM: selftests: Add vm->memslots[] and enum kvm_mem_region_type

2022-09-21 Thread Ricardo Koller
The vm_create() helpers are hardcoded to place most page types (code, page-tables, stacks, etc) in the same memslot #0, and always backed with anonymous 4K. There are a couple of issues with that. First, tests willing to differ a bit, like placing page-tables in a different backing source type mu

[PATCH v8 06/14] KVM: selftests: Stash backing_src_type in struct userspace_mem_region

2022-09-21 Thread Ricardo Koller
Add the backing_src_type into struct userspace_mem_region. This struct already stores a lot of info about memory regions, except the backing source type. This info will be used by a future commit in order to determine the method for punching a hole. Reviewed-by: Oliver Upton Signed-off-by: Ricar

[PATCH v8 08/14] KVM: selftests: Fix alignment in virt_arch_pgd_alloc() and vm_vaddr_alloc()

2022-09-21 Thread Ricardo Koller
Refactor virt_arch_pgd_alloc() and vm_vaddr_alloc() in both RISC-V and aarch64 to fix the alignment of parameters in a couple of calls. This will make it easier to fix the alignment in a future commit that adds an extra parameter (that happens to be very long). No functional change intended. Sugg

[PATCH v8 10/14] KVM: selftests: aarch64: Add aarch64/page_fault_test

2022-09-21 Thread Ricardo Koller
Add a new test for stage 2 faults when using different combinations of guest accesses (e.g., write, S1PTW), backing source type (e.g., anon) and types of faults (e.g., read on hugetlbfs with a hole). The next commits will add different handling methods and more faults (e.g., uffd and dirty logging)

[PATCH v8 12/14] KVM: selftests: aarch64: Add dirty logging tests into page_fault_test

2022-09-21 Thread Ricardo Koller
Add some dirty logging tests into page_fault_test. Mark the data and/or page-table memslots for dirty logging, perform some accesses, and check that the dirty log bits are set or clean when expected. Signed-off-by: Ricardo Koller --- .../selftests/kvm/aarch64/page_fault_test.c | 75 +++

[PATCH v8 09/14] KVM: selftests: Use the right memslot for code, page-tables, and data allocations

2022-09-21 Thread Ricardo Koller
Now that kvm_vm allows specifying different memslots for code, page tables, and data, use the appropriate memslot when making allocations in common/libraty code. Change them accordingly: - code (allocated by lib/elf) use the CODE memslot - stacks, exception tables, and other core data pages (like

[PATCH v8 05/14] tools: Copy bitfield.h from the kernel sources

2022-09-21 Thread Ricardo Koller
Copy bitfield.h from include/linux/bitfield.h. A subsequent change will make use of some FIELD_{GET,PREP} macros defined in this header. The header was copied as-is, no changes needed. Cc: Jakub Kicinski Cc: Arnaldo Carvalho de Melo Reviewed-by: Oliver Upton Signed-off-by: Ricardo Koller ---

[PATCH v8 13/14] KVM: selftests: aarch64: Add readonly memslot tests into page_fault_test

2022-09-21 Thread Ricardo Koller
Add some readonly memslot tests into page_fault_test. Mark the data and/or page-table memslots as readonly, perform some accesses, and check that the right fault is triggered when expected (e.g., a store with no write-back should lead to an mmio exit). Signed-off-by: Ricardo Koller --- .../selft

[PATCH v8 11/14] KVM: selftests: aarch64: Add userfaultfd tests into page_fault_test

2022-09-21 Thread Ricardo Koller
Add some userfaultfd tests into page_fault_test. Punch holes into the data and/or page-table memslots, perform some accesses, and check that the faults are taken (or not taken) when expected. Signed-off-by: Ricardo Koller --- .../selftests/kvm/aarch64/page_fault_test.c | 190 +-

[PATCH v8 14/14] KVM: selftests: aarch64: Add mix of tests into page_fault_test

2022-09-21 Thread Ricardo Koller
Add some mix of tests into page_fault_test: memslots with all the pairwise combinations of read-only, userfaultfd, and dirty-logging. For example, writing into a read-only memslot which has a hole handled with userfaultfd. Signed-off-by: Ricardo Koller --- .../selftests/kvm/aarch64/page_fault_t