[RFC PATCH 3/3] KVM: selftests: Test user hypercalls

2022-11-09 Thread Oliver Upton
Signed-off-by: Oliver Upton --- tools/testing/selftests/kvm/.gitignore| 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/user_hypercalls.c | 130 ++ 3 files changed, 132 insertions(+) create mode 100644 tools/testing/selftests/kvm

[RFC PATCH 2/3] KVM: arm64: Allow userspace to trap SMCCC sub-ranges

2022-11-09 Thread Oliver Upton
to mix-and-match between calls handled in userspace vs. KVM. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_host.h | 5 arch/arm64/include/uapi/asm/kvm.h | 15 ++ arch/arm64/kvm/arm.c | 10 +++ arch/arm64/kvm/hypercalls.c

[RFC PATCH 1/3] KVM: arm64: Use a generalized accessor for SMCCC args

2022-11-09 Thread Oliver Upton
Avoid the need to introduce yet another accessor for every argument position with a generalized one instead. Align with the SMCCC specification and count arguments starting from 1. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_hypercalls.h | 22

[RFC PATCH 0/3] KVM: arm64: Allow userspace to trap hypercall ranges

2022-11-09 Thread Oliver Upton
ev Cc: kvmarm@lists.cs.columbia.edu Oliver Upton (3): KVM: arm64: Use a generalized accessor for SMCCC args KVM: arm64: Allow userspace to trap SMCCC sub-ranges KVM: selftests: Test user hypercalls arch/arm64/include/asm/kvm_host.h | 5 + arch/arm64/include/asm/kvm_hypercalls.h |

[RESEND PATCH] KVM: arm64: Move arch-specific headers out of include/kvm/

2022-11-09 Thread Oliver Upton
remaining residue into the arch-specific include path. No functional change intended. Signed-off-by: Oliver Upton --- The one time I forget to run checkpatch.pl I left the stupid Gerrit Change-Id in the commit message... MAINTAINERS | 1 - .../arm64

[PATCH] KVM: arm64: Move arch-specific headers out of include/kvm/

2022-11-09 Thread Oliver Upton
remaining residue into the arch-specific include path. No functional change intended. Signed-off-by: Oliver Upton Change-Id: Iec1caf5a426fba5003abff2dc7f814e0ba398e00 --- MAINTAINERS | 1 - .../arm64/include/asm/kvm_arch_timer.h | 5

Re: [PATCH v5 01/14] KVM: arm64: Combine visitor arguments into a context structure

2022-11-09 Thread Oliver Upton
Hi Gavin, On Thu, Nov 10, 2022 at 08:23:36AM +0800, Gavin Shan wrote: > On 11/8/22 5:56 AM, Oliver Upton wrote: > > Passing new arguments by value to the visitor callbacks is extremely > > inflexible for stuffing new parameters used by only some of the > > visitors. Us

Re: [PATCH v5 08/14] KVM: arm64: Protect stage-2 traversal with RCU

2022-11-09 Thread Oliver Upton
On Wed, Nov 09, 2022 at 09:53:45PM +, Sean Christopherson wrote: > On Mon, Nov 07, 2022, Oliver Upton wrote: > > Use RCU to safely walk the stage-2 page tables in parallel. Acquire and > > release the RCU read lock when traversing the page tables. Defer the > > freeing

Re: [PATCH v5 11/14] KVM: arm64: Make block->table PTE changes parallel-aware

2022-11-09 Thread Oliver Upton
On Wed, Nov 09, 2022 at 02:26:36PM -0800, Ben Gardon wrote: > On Mon, Nov 7, 2022 at 1:59 PM Oliver Upton wrote: > > > > In order to service stage-2 faults in parallel, stage-2 table walkers > > must take exclusive ownership of the PTE being worked on. An additional &

Re: [PATCH v5 10/14] KVM: arm64: Split init and set for table PTE

2022-11-09 Thread Oliver Upton
On Wed, Nov 09, 2022 at 02:26:26PM -0800, Ben Gardon wrote: > On Mon, Nov 7, 2022 at 1:58 PM Oliver Upton wrote: > > > > Create a helper to initialize a table and directly call > > smp_store_release() to install it (for now). Prepare for a subsequent > > change that ge

Re: [PATCH v5 05/14] KVM: arm64: Add a helper to tear down unlinked stage-2 subtrees

2022-11-09 Thread Oliver Upton
On Wed, Nov 09, 2022 at 02:23:33PM -0800, Ben Gardon wrote: > On Mon, Nov 7, 2022 at 1:57 PM Oliver Upton wrote: > > > > A subsequent change to KVM will move the tear down of an unlinked > > stage-2 subtree out of the critical path of the break-before-make > > sequen

Re: [PATCH v5 01/14] KVM: arm64: Combine visitor arguments into a context structure

2022-11-09 Thread Oliver Upton
On Wed, Nov 09, 2022 at 02:23:08PM -0800, Ben Gardon wrote: > On Mon, Nov 7, 2022 at 1:57 PM Oliver Upton wrote: > > > > Passing new arguments by value to the visitor callbacks is extremely > > inflexible for stuffing new parameters used by only some of the > > visito

Re: [PATCH v8 3/7] KVM: Support dirty ring in conjunction with bitmap

2022-11-07 Thread Oliver Upton
On Tue, Nov 08, 2022 at 08:44:52AM +0800, Gavin Shan wrote: > Frankly, I don't expect the capability to be disabled. Similar to > KVM_CAP_DIRTY_LOG_RING > or KVM_CAP_DIRTY_LOG_RING_ACQ_REL, it would a one-shot capability and only > enablement is > allowed. The disablement was suggested by Oliver

[PATCH v5 14/14] KVM: arm64: Handle stage-2 faults in parallel

2022-11-07 Thread Oliver Upton
(). Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 ++- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/pgtable.c | 5 +++-- arch/arm64/kvm/mmu.c | 31 ++- 4 files changed, 13 insertions(+), 28 deletions

[PATCH v5 13/14] KVM: arm64: Make table->block changes parallel-aware

2022-11-07 Thread Oliver Upton
stead let stage2_map_walker_try_leaf() deal with it. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 15 +++ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 238f29389617..f814422ef795 1

[PATCH v5 12/14] KVM: arm64: Make leaf->leaf PTE changes parallel-aware

2022-11-07 Thread Oliver Upton
: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 26 -- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index b9f0d792b8d9..238f29389617 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp

[PATCH v5 11/14] KVM: arm64: Make block->table PTE changes parallel-aware

2022-11-07 Thread Oliver Upton
y shared with another software walker. Elide the DSB + TLBI if the evicted PTE was invalid (and thus not subject to break-before-make). All of the atomics do nothing for now, as the stage-2 walker isn't fully ready to perform parallel walks. Signed-off-by: Oliver Upton ---

[PATCH v5 09/14] KVM: arm64: Atomically update stage 2 leaf attributes in parallel walks

2022-11-07 Thread Oliver Upton
walking in parallel. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 31 ++- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index d8d963521d4e..a34e2050f931 100644 --- a/arch/arm

[PATCH v5 08/14] KVM: arm64: Protect stage-2 traversal with RCU

2022-11-07 Thread Oliver Upton
n RCU. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 49 arch/arm64/kvm/hyp/pgtable.c | 10 +- arch/arm64/kvm/mmu.c | 14 +++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/arch/arm64/includ

[PATCH v5 10/14] KVM: arm64: Split init and set for table PTE

2022-11-07 Thread Oliver Upton
Create a helper to initialize a table and directly call smp_store_release() to install it (for now). Prepare for a subsequent change that generalizes PTE writes with a helper. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 20 ++-- 1 file changed, 10 insertions

[PATCH v5 06/14] KVM: arm64: Use an opaque type for pteps

2022-11-07 Thread Oliver Upton
conditionally annotated with RCU for the stage-2 MMU. Call the type a 'pteref' to avoid a naming collision with raw pteps. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 9 - arch/arm64/kvm/hyp/pgtable.c

[PATCH v5 07/14] KVM: arm64: Tear down unlinked stage-2 subtree after break-before-make

2022-11-07 Thread Oliver Upton
unlinked stage-2 is indirected as a subsequent change will use an RCU callback to trigger tear down. RCU is not available to pKVM, so there is a need to use different implementations on pKVM and non-pKVM VMs. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 + arch

[PATCH v5 03/14] KVM: arm64: Pass mm_ops through the visitor context

2022-11-07 Thread Oliver Upton
As a prerequisite for getting visitors off of struct kvm_pgtable, pass mm_ops through the visitor context. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 1 + arch/arm64/kvm/hyp/nvhe/setup.c | 3 +- arch/arm64/kvm/hyp/pgtable.c

[PATCH v5 05/14] KVM: arm64: Add a helper to tear down unlinked stage-2 subtrees

2022-11-07 Thread Oliver Upton
__kvm_pgtable_walk() as the subtree is no longer reachable from the root. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 11 +++ arch/arm64/kvm/hyp/pgtable.c | 23 +++ 2 files changed, 34 insertions(+) diff --git a/arch/arm64/include/asm

[PATCH v5 04/14] KVM: arm64: Don't pass kvm_pgtable through kvm_pgtable_walk_data

2022-11-07 Thread Oliver Upton
In order to tear down page tables from outside the context of kvm_pgtable (such as an RCU callback), stop passing a pointer through kvm_pgtable_walk_data. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 18 +- 1 file changed, 5

[PATCH v5 01/14] KVM: arm64: Combine visitor arguments into a context structure

2022-11-07 Thread Oliver Upton
visitor to contain the bit indicating the phase of the walk. Pass the entire set of flags through the context structure such that the walker can communicate additional state to the visitor callback. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtabl

[PATCH v5 02/14] KVM: arm64: Stash observed pte value in visitor context

2022-11-07 Thread Oliver Upton
Rather than reading the ptep all over the shop, read the ptep once from __kvm_pgtable_visit() and stick it in the visitor context. Reread the ptep after visiting a leaf in case the callback installed a new table underneath. No functional change intended. Signed-off-by: Oliver Upton --- arch

[PATCH v5 00/14] KVM: arm64: Parallel stage-2 fault handling

2022-11-07 Thread Oliver Upton
p...@linux.dev/ v4: https://lore.kernel.org/kvmarm/20221103091140.1040433-1-oliver.up...@linux.dev/ Oliver Upton (14): KVM: arm64: Combine visitor arguments into a context structure KVM: arm64: Stash observed pte value in visitor context KVM: arm64: Pass mm_ops through the visitor context KVM: arm

Re: [PATCH v7 4/9] KVM: Support dirty ring in conjunction with bitmap

2022-11-04 Thread Oliver Upton
On Sat, Nov 05, 2022 at 05:57:33AM +0800, Gavin Shan wrote: > On 11/5/22 4:12 AM, Oliver Upton wrote: > > I agree that we should address (1) like this, but in (2) requiring that > > no memslots were created before enabling the existing capabilities would > > be a change in AB

Re: [PATCH v2 01/14] arm64: Add ID_DFR0_EL1.PerfMon values for PMUv3p7 and IMP_DEF

2022-11-04 Thread Oliver Upton
On Fri, Oct 28, 2022 at 11:53:49AM +0100, Marc Zyngier wrote: > Align the ID_DFR0_EL1.PerfMon values with ID_AA64DFR0_EL1.PMUver. > > Signed-off-by: Marc Zyngier Reviewed-by: Oliver Upton FYI, another pile of ID reg changes is on the way that'll move DFR0 to a generated defi

Re: [PATCH v7 4/9] KVM: Support dirty ring in conjunction with bitmap

2022-11-04 Thread Oliver Upton
On Fri, Nov 04, 2022 at 02:57:15PM +0800, Gavin Shan wrote: > On 11/4/22 9:06 AM, Oliver Upton wrote: [...] > > Just to make sure we're on the same page, there's two issues: > > > > (1) If DIRTY_LOG_RING is enabled before memslot creation and > >

Re: [PATCH v7 4/9] KVM: Support dirty ring in conjunction with bitmap

2022-11-03 Thread Oliver Upton
On Fri, Nov 04, 2022 at 08:12:21AM +0800, Gavin Shan wrote: > Hi Oliver, > > On 11/4/22 7:32 AM, Oliver Upton wrote: > > On Mon, Oct 31, 2022 at 08:36:16AM +0800, Gavin Shan wrote: > > > ARM64 needs to dirty memory outside of a VCPU context when VGIC/ITS is > > &g

Re: [PATCH v7 4/9] KVM: Support dirty ring in conjunction with bitmap

2022-11-03 Thread Oliver Upton
On Mon, Oct 31, 2022 at 08:36:16AM +0800, Gavin Shan wrote: > ARM64 needs to dirty memory outside of a VCPU context when VGIC/ITS is > enabled. It's conflicting with that ring-based dirty page tracking always > requires a running VCPU context. > > Introduce a new flavor of dirty ring that requires

Re: [PATCH v4 07/14] KVM: arm64: Tear down unlinked stage-2 subtree after break-before-make

2022-11-03 Thread Oliver Upton
On Thu, Nov 03, 2022 at 02:31:00PM -0700, Ricardo Koller wrote: > On Thu, Nov 03, 2022 at 09:11:33AM +0000, Oliver Upton wrote: > > The break-before-make sequence is a bit annoying as it opens a window > > wherein memory is unmapped from the guest. KVM should replace the PTE &g

[PATCH v4 14/14] KVM: arm64: Handle stage-2 faults in parallel

2022-11-03 Thread Oliver Upton
(). Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 ++- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/pgtable.c | 5 +++-- arch/arm64/kvm/mmu.c | 31 ++- 4 files changed, 13 insertions(+), 28 deletions

[PATCH v4 13/14] KVM: arm64: Make table->block changes parallel-aware

2022-11-03 Thread Oliver Upton
stead let stage2_map_walker_try_leaf() deal with it. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 15 +++ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 5ae9ab1ec893..e088d01e6e82 1

[PATCH v4 12/14] KVM: arm64: Make leaf->leaf PTE changes parallel-aware

2022-11-03 Thread Oliver Upton
: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 26 -- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index ffcb0702034a..5ae9ab1ec893 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp

[PATCH v4 11/14] KVM: arm64: Make block->table PTE changes parallel-aware

2022-11-03 Thread Oliver Upton
y shared with another software walker. Elide the DSB + TLBI if the evicted PTE was invalid (and thus not subject to break-before-make). All of the atomics do nothing for now, as the stage-2 walker isn't fully ready to perform parallel walks. Signed-off-by: Oliver Upton ---

[PATCH v4 10/14] KVM: arm64: Split init and set for table PTE

2022-11-03 Thread Oliver Upton
Create a helper to initialize a table and directly call smp_store_release() to install it (for now). Prepare for a subsequent change that generalizes PTE writes with a helper. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 20 ++-- 1 file changed, 10 insertions

[PATCH v4 08/14] KVM: arm64: Protect stage-2 traversal with RCU

2022-11-03 Thread Oliver Upton
n RCU. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 49 arch/arm64/kvm/hyp/pgtable.c | 10 +- arch/arm64/kvm/mmu.c | 14 +++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/arch/arm64/includ

[PATCH v4 07/14] KVM: arm64: Tear down unlinked stage-2 subtree after break-before-make

2022-11-03 Thread Oliver Upton
unlinked stage-2 is indirected as a subsequent change will use an RCU callback to trigger tear down. RCU is not available to pKVM, so there is a need to use different implementations on pKVM and non-pKVM VMs. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 + arch

[PATCH v4 09/14] KVM: arm64: Atomically update stage 2 leaf attributes in parallel walks

2022-11-03 Thread Oliver Upton
walking in parallel. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 31 ++- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 156754d87b2a..2950058a2069 100644 --- a/arch/arm

[PATCH v4 06/14] KVM: arm64: Use an opaque type for pteps

2022-11-03 Thread Oliver Upton
conditionally annotated with RCU for the stage-2 MMU. Call the type a 'pteref' to avoid a naming collision with raw pteps. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 9 - arch/arm64/kvm/hyp/pgtable.c

[PATCH v4 05/14] KVM: arm64: Add a helper to tear down unlinked stage-2 subtrees

2022-11-03 Thread Oliver Upton
__kvm_pgtable_walk() as the subtree is no longer reachable from the root. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 11 +++ arch/arm64/kvm/hyp/pgtable.c | 23 +++ 2 files changed, 34 insertions(+) diff --git a/arch/arm64/include/asm

[PATCH v4 04/14] KVM: arm64: Don't pass kvm_pgtable through kvm_pgtable_walk_data

2022-11-03 Thread Oliver Upton
In order to tear down page tables from outside the context of kvm_pgtable (such as an RCU callback), stop passing a pointer through kvm_pgtable_walk_data. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 18 +- 1 file changed, 5

[PATCH v4 03/14] KVM: arm64: Pass mm_ops through the visitor context

2022-11-03 Thread Oliver Upton
As a prerequisite for getting visitors off of struct kvm_pgtable, pass mm_ops through the visitor context. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 1 + arch/arm64/kvm/hyp/nvhe/setup.c | 3 +- arch/arm64/kvm/hyp/pgtable.c

[PATCH v4 01/14] KVM: arm64: Combine visitor arguments into a context structure

2022-11-03 Thread Oliver Upton
visitor to contain the bit indicating the phase of the walk. Pass the entire set of flags through the context structure such that the walker can communicate additional state to the visitor callback. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtabl

[PATCH v4 00/14] KVM: arm64: Parallel stage-2 fault handling

2022-11-03 Thread Oliver Upton
https://lore.kernel.org/kvmarm/20221027221752.1683510-1-oliver.up...@linux.dev/ Oliver Upton (14): KVM: arm64: Combine visitor arguments into a context structure KVM: arm64: Stash observed pte value in visitor context KVM: arm64: Pass mm_ops through the visitor context KVM: arm64: Don

[PATCH v4 02/14] KVM: arm64: Stash observed pte value in visitor context

2022-11-03 Thread Oliver Upton
Rather than reading the ptep all over the shop, read the ptep once from __kvm_pgtable_visit() and stick it in the visitor context. Reread the ptep after visiting a leaf in case the callback installed a new table underneath. No functional change intended. Signed-off-by: Oliver Upton --- arch

Re: [PATCH v3 12/15] KVM: arm64: Make block->table PTE changes parallel-aware

2022-11-02 Thread Oliver Upton
On Tue, Nov 01, 2022 at 07:22:49PM -0700, Ricardo Koller wrote: > On Thu, Oct 27, 2022 at 10:22:47PM +0000, Oliver Upton wrote: > > In order to service stage-2 faults in parallel, stage-2 table walkers > > must take exclusive ownership of the PTE being worked on. An additional >

Re: [PATCH v3 09/15] KVM: arm64: Free removed stage-2 tables in RCU callback

2022-11-01 Thread Oliver Upton
On Tue, Nov 01, 2022 at 08:28:04PM +, Sean Christopherson wrote: > On Thu, Oct 27, 2022, Oliver Upton wrote: > > There is no real urgency to free a stage-2 subtree that was pruned. > > Nonetheless, KVM does the tear down in the stage-2 fault path while > > holding the M

Re: [PATCH v7 3/9] KVM: Check KVM_CAP_DIRTY_LOG_{RING, RING_ACQ_REL} prior to enabling them

2022-10-31 Thread Oliver Upton
bling it. It's rejected to enable the capability if it hasn't been > advertised. > > Fixes: 17601bfed909 ("KVM: Add KVM_CAP_DIRTY_LOG_RING_ACQ_REL capability and > config option") > Reported-by: Sean Christopherson > Suggested-by: Sean Christopherson >

Re: [PATCH v7 5/9] KVM: arm64: Improve no-running-vcpu report for dirty ring

2022-10-31 Thread Oliver Upton
On Mon, Oct 31, 2022 at 08:36:17AM +0800, Gavin Shan wrote: > KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP should be enabled only when KVM > device "kvm-arm-vgic-its" is used by userspace. Currently, it's the > only case where a running VCPU is missed for dirty ring. However, > there are potentially other de

Re: [PATCH 2/2] KVM: arm64: Redefine pKVM memory transitions in terms of source/target

2022-10-28 Thread Oliver Upton
Quentin, On Fri, Oct 28, 2022 at 09:57:04AM +, Quentin Perret wrote: > Hey Oliver, > > On Friday 28 Oct 2022 at 08:34:48 (+), Oliver Upton wrote: > > Perhaps it is just me, but the 'initiator' and 'completer' terms are > > slightly confusing de

Re: [PATCH v3 08/15] KVM: arm64: Protect stage-2 traversal with RCU

2022-10-28 Thread Oliver Upton
On Thu, Oct 27, 2022 at 10:17:45PM +, Oliver Upton wrote: > The use of RCU is necessary to safely change the stage-2 page tables in > parallel. Acquire and release the RCU read lock when traversing the page > tables. > > Use the _raw() flavor of rcu_dereference when changes to

[PATCH 2/2] KVM: arm64: Redefine pKVM memory transitions in terms of source/target

2022-10-28 Thread Oliver Upton
nded. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 68 +-- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 3636a24e1b34..3ea389a8166f 100644 --- a/arc

[PATCH 0/2] KVM: arm64: pKVM memory transitions cleanup

2022-10-28 Thread Oliver Upton
erminology (source/target) to describe the addresses involved in a memory transition Applies to 6.1-rc2. Politely compile tested, and that's just about it. Oliver Upton (2): KVM: arm64: Clean out the odd handling of completer_addr KVM: arm64: Redefine pKVM memory transitions in terms o

[PATCH 1/2] KVM: arm64: Clean out the odd handling of completer_addr

2022-10-28 Thread Oliver Upton
destination address into the destination context sub-struct. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 70 ++- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c

Re: [REPOST][URGENT] kvmarm mailing list migration

2022-10-27 Thread Oliver Upton
On Thu, Oct 13, 2022 at 04:09:20PM +0100, Marc Zyngier wrote: > [Reposting this, as it has been almost two weeks since the initial > announcement and we're still at sub-10% of the users having > subscribed to the new list] > > Hi all, > > As you probably all know, the kvmarm mailing has been h

Re: [PATCH v3 00/15] KVM: arm64: Parallel stage-2 fault handling

2022-10-27 Thread Oliver Upton
On Thu, Oct 27, 2022 at 10:17:37PM +, Oliver Upton wrote: > Presently KVM only takes a read lock for stage 2 faults if it believes > the fault can be fixed by relaxing permissions on a PTE (write unprotect > for dirty logging). Otherwise, stage 2 faults grab the write lock, which >

Re: [PATCH v2 07/15] KVM: arm64: Use an opaque type for pteps

2022-10-27 Thread Oliver Upton
On Thu, Oct 20, 2022 at 11:32:28AM +0300, Oliver Upton wrote: > On Wed, Oct 19, 2022 at 11:17:43PM +, Sean Christopherson wrote: > > On Fri, Oct 07, 2022, Oliver Upton wrote: [...] > > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > &

[PATCH v3 15/15] KVM: arm64: Handle stage-2 faults in parallel

2022-10-27 Thread Oliver Upton
(). Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 ++- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/pgtable.c | 5 +++-- arch/arm64/kvm/mmu.c | 31 ++- 4 files changed, 13 insertions(+), 28 deletions

[PATCH v3 14/15] KVM: arm64: Make table->block changes parallel-aware

2022-10-27 Thread Oliver Upton
d let stage2_map_walk_leaf() deal with it. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 15 +++ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 581ba688c6f7..d08e14008bfb 100644 --- a/arch/

[PATCH v3 13/15] KVM: arm64: Make leaf->leaf PTE changes parallel-aware

2022-10-27 Thread Oliver Upton
: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 26 -- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 1df858c21b2e..581ba688c6f7 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp

[PATCH v3 12/15] KVM: arm64: Make block->table PTE changes parallel-aware

2022-10-27 Thread Oliver Upton
y shared with another software walker. Elide the DSB + TLBI if the evicted PTE was invalid (and thus not subject to break-before-make). All of the atomics do nothing for now, as the stage-2 walker isn't fully ready to perform parallel walks. Signed-off-by: Oliver Upton ---

[PATCH v3 11/15] KVM: arm64: Split init and set for table PTE

2022-10-27 Thread Oliver Upton
Create a helper to initialize a table and directly call smp_store_release() to install it (for now). Prepare for a subsequent change that generalizes PTE writes with a helper. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 18 +- 1 file changed, 9 insertions

[PATCH v3 10/15] KVM: arm64: Atomically update stage 2 leaf attributes in parallel walks

2022-10-27 Thread Oliver Upton
walking in parallel. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 8 +++ arch/arm64/kvm/hyp/pgtable.c | 31 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/i

[PATCH v3 09/15] KVM: arm64: Free removed stage-2 tables in RCU callback

2022-10-27 Thread Oliver Upton
rcu_barrier() to the flush path. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 2 +- arch/arm64/kvm/mmu.c | 14 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm

[PATCH v3 08/15] KVM: arm64: Protect stage-2 traversal with RCU

2022-10-27 Thread Oliver Upton
the write lock). Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 41 arch/arm64/kvm/hyp/pgtable.c | 10 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm

[PATCH v3 07/15] KVM: arm64: Use an opaque type for pteps

2022-10-27 Thread Oliver Upton
conditionally annotated with RCU for the stage-2 MMU. Call the type a 'pteref' to avoid a naming collision with raw pteps. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 9 - arch/arm64/kvm/hyp/pgtable.c

[PATCH v3 06/15] KVM: arm64: Tear down unlinked stage-2 subtree after break-before-make

2022-10-27 Thread Oliver Upton
unlinked stage-2 is indirected as a subsequent change will use an RCU callback to trigger tear down. RCU is not available to pKVM, so there is a need to use different implementations on pKVM and non-pKVM VMs. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 + arch

[PATCH v3 05/15] KVM: arm64: Add a helper to tear down unlinked stage-2 subtrees

2022-10-27 Thread Oliver Upton
__kvm_pgtable_walk() as the subtree is no longer reachable from the root. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 11 +++ arch/arm64/kvm/hyp/pgtable.c | 23 +++ 2 files changed, 34 insertions(+) diff --git a/arch/arm64/include/asm

[PATCH v3 04/15] KVM: arm64: Don't pass kvm_pgtable through kvm_pgtable_walk_data

2022-10-27 Thread Oliver Upton
In order to tear down page tables from outside the context of kvm_pgtable (such as an RCU callback), stop passing a pointer through kvm_pgtable_walk_data. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 18 +- 1 file changed, 5

[PATCH v3 03/15] KVM: arm64: Pass mm_ops through the visitor context

2022-10-27 Thread Oliver Upton
As a prerequisite for getting visitors off of struct kvm_pgtable, pass mm_ops through the visitor context. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 1 + arch/arm64/kvm/hyp/nvhe/setup.c | 3 +- arch/arm64/kvm/hyp/pgtable.c

[PATCH v3 01/15] KVM: arm64: Combine visitor arguments into a context structure

2022-10-27 Thread Oliver Upton
visitor to contain the bit indicating the phase of the walk. Pass the entire set of flags through the context structure such that the walker can communicate additional state to the visitor callback. No functional change intended. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtabl

[PATCH v3 02/15] KVM: arm64: Stash observed pte value in visitor context

2022-10-27 Thread Oliver Upton
Rather than reading the ptep all over the shop, read the ptep once from __kvm_pgtable_visit() and stick it in the visitor context. Reread the ptep after visiting a leaf in case the callback installed a new table underneath. No functional change intended. Signed-off-by: Oliver Upton --- arch

[PATCH v3 00/15] KVM: arm64: Parallel stage-2 fault handling

2022-10-27 Thread Oliver Upton
l.org/kvmarm/20220830194132.962932-1-oliver.up...@linux.dev/ v2: https://lore.kernel.org/kvmarm/20221007232818.459650-1-oliver.up...@linux.dev/ Oliver Upton (15): KVM: arm64: Combine visitor arguments into a context structure KVM: arm64: Stash observed pte value in visitor context KVM: ar

Re: [PATCH v6 3/8] KVM: Add support for using dirty ring in conjunction with bitmap

2022-10-24 Thread Oliver Upton
On Mon, Oct 24, 2022 at 11:50:29PM +, Sean Christopherson wrote: > On Sat, Oct 22, 2022, Marc Zyngier wrote: > > On Fri, 21 Oct 2022 17:05:26 +0100, Sean Christopherson > > wrote: [...] > > > Would it be possible to require a dirty bitmap when an ITS is > > > created? That would allow trea

Re: [PATCH v2 5/9] KVM: arm64: selftests: Stop unnecessary test stage tracking of debug-exceptions

2022-10-20 Thread Oliver Upton
y are not so useful and are a bit pain to maintain. > > Signed-off-by: Reiji Watanabe Much cleaner! Reviewed-by: Oliver Upton -- Thanks, Oliver ___ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

Re: [PATCH v2 3/9] KVM: arm64: selftests: Remove the hard-coded {b,w}pn#0 from debug-exceptions

2022-10-20 Thread Oliver Upton
> so that guest_code() can use the function to reset those registers > even when non-zero {break,watch}points are specified for guest_code(). > Subsequent patches will add test cases for non-zero {break,watch}points. > > Signed-off-by: Reiji Watanabe > Reviewed-by: Ricardo Koller

Re: [PATCH v2 1/9] KVM: arm64: selftests: Use FIELD_GET() to extract ID register fields

2022-10-20 Thread Oliver Upton
_FEATURE_MASK(ID_AA64MMFR0_TGRAN4), val) != 0xf; > + *ps64k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN64), val) == 0; > + *ps16k = FIELD_GET(ARM64_FEATURE_MASK(ID_AA64MMFR0_TGRAN16), val) != 0; Not your code, but since we're here... Should we change the field values to us

Re: [PATCH v6 3/8] KVM: Add support for using dirty ring in conjunction with bitmap

2022-10-20 Thread Oliver Upton
On Wed, Oct 19, 2022 at 06:20:32AM +0800, Gavin Shan wrote: > Hi Peter, > > On 10/19/22 12:07 AM, Peter Xu wrote: > > On Tue, Oct 11, 2022 at 02:14:42PM +0800, Gavin Shan wrote: [...] > > IMHO it'll be great to start with something like below to describe the > > userspace's responsibility to pro

Re: [PATCH v2 15/15] KVM: arm64: Handle stage-2 faults in parallel

2022-10-20 Thread Oliver Upton
On Wed, Oct 19, 2022 at 11:32:36PM +, Sean Christopherson wrote: > On Fri, Oct 07, 2022, Oliver Upton wrote: > > @@ -1534,7 +1517,7 @@ bool kvm_set_spte_gfn(struct kvm *kvm, struct > > kvm_gfn_range *range) > > */ > > kvm_pgtable_stage2_map(kvm-

Re: [PATCH v2 08/15] KVM: arm64: Protect stage-2 traversal with RCU

2022-10-20 Thread Oliver Upton
On Wed, Oct 19, 2022 at 11:29:56PM +, Sean Christopherson wrote: > On Fri, Oct 07, 2022, Oliver Upton wrote: > > The use of RCU is necessary to safely change the stage-2 page tables in > > parallel. Acquire and release the RCU read lock when traversing the page > > tab

Re: [PATCH v2 07/15] KVM: arm64: Use an opaque type for pteps

2022-10-20 Thread Oliver Upton
On Wed, Oct 19, 2022 at 11:17:43PM +, Sean Christopherson wrote: > On Fri, Oct 07, 2022, Oliver Upton wrote: > > Use an opaque type for pteps and require visitors explicitly dereference > > the pointer before using. Protecting page table memory with RCU requires > > that

Re: [PATCH 5/6] KVM: selftests: memslot_perf_test: Consolidate memory sizes

2022-10-18 Thread Oliver Upton
On Mon, Oct 17, 2022 at 10:08:48PM +, Sean Christopherson wrote: > On Mon, Oct 17, 2022, Maciej S. Szmigiero wrote: > > > +#define MEM_EXTRA_SIZE 0x1 > > > > Also, an expression like "(64 << 10)" is more readable than a "1" > > with a tail of zeroes (it's easy to add one zero too

Re: [PATCH v5 3/7] KVM: x86: Allow to use bitmap in ring-based dirty page tracking

2022-10-18 Thread Oliver Upton
On Tue, Oct 18, 2022 at 10:38:10AM +0300, Oliver Upton wrote: > On Fri, Oct 14, 2022 at 12:55:35PM -0400, Peter Xu wrote: > > On Tue, Oct 11, 2022 at 01:12:43AM +0000, Oliver Upton wrote: > > > The VMM must know something about the architecture it is running on,

Re: [PATCH v5 3/7] KVM: x86: Allow to use bitmap in ring-based dirty page tracking

2022-10-18 Thread Oliver Upton
On Fri, Oct 14, 2022 at 12:55:35PM -0400, Peter Xu wrote: > On Tue, Oct 11, 2022 at 01:12:43AM +0000, Oliver Upton wrote: > > The VMM must know something about the architecture it is running on, as > > it calls KVM_DEV_ARM_ITS_SAVE_TABLES after all... > > IIUC this is still

Re: [PATCH] KVM: arm64: pkvm: Fixup boot mode to reflect that the kernel resumes from EL1

2022-10-11 Thread Oliver Upton
On Tue, Oct 11, 2022 at 05:54:00PM +0100, Marc Zyngier wrote: > The kernel has an awfully complicated boot sequence in order to cope > with the various EL2 configurations, including those that "enhanced" > the architecture. We go from EL2 to EL1, then back to EL2, staying > at EL2 if VHE capable an

Re: [PATCH v5 3/7] KVM: x86: Allow to use bitmap in ring-based dirty page tracking

2022-10-10 Thread Oliver Upton
On Mon, Oct 10, 2022 at 08:20:29PM -0400, Peter Xu wrote: > On Mon, Oct 10, 2022 at 11:58:22PM +0000, Oliver Upton wrote: > > I think this further drives the point home -- there's zero need for the > > bitmap with dirty ring on x86, so why even support it? The proposal

Re: [PATCH v5 3/7] KVM: x86: Allow to use bitmap in ring-based dirty page tracking

2022-10-10 Thread Oliver Upton
On Mon, Oct 10, 2022 at 07:49:15PM -0400, Peter Xu wrote: > On Mon, Oct 10, 2022 at 11:18:55PM +0000, Oliver Upton wrote: > > On Fri, Oct 07, 2022 at 10:31:49AM -0400, Peter Xu wrote: > > > > [...] > > > > > > - In kvm_vm_ioctl_enable_dirty_log_ring(), se

Re: [PATCH v5 3/7] KVM: x86: Allow to use bitmap in ring-based dirty page tracking

2022-10-10 Thread Oliver Upton
On Mon, Oct 10, 2022 at 11:18:55PM +, Oliver Upton wrote: > On Fri, Oct 07, 2022 at 10:31:49AM -0400, Peter Xu wrote: > > [...] > > > > - In kvm_vm_ioctl_enable_dirty_log_ring(), set 'dirty_ring_allow_bitmap' > > > to > > > true when

Re: [PATCH v5 3/7] KVM: x86: Allow to use bitmap in ring-based dirty page tracking

2022-10-10 Thread Oliver Upton
On Fri, Oct 07, 2022 at 10:31:49AM -0400, Peter Xu wrote: [...] > > - In kvm_vm_ioctl_enable_dirty_log_ring(), set 'dirty_ring_allow_bitmap' to > > true when the capability is KVM_CAP_DIRTY_LONG_RING_ACQ_REL > > What I wanted to do is to decouple the ACQ_REL with ALLOW_BITMAP, so mostly > as w

Re: [PATCH] KVM: arm64: selftests: Fix multiple versions of GIC creation

2022-10-09 Thread Oliver Upton
n my D05 (which > supports v2 emulation). Fix it. > > Fixes: 98f94ce42ac6 ("KVM: selftests: Move KVM_CREATE_DEVICE_TEST code to > separate helper") > Signed-off-by: Zenghui Yu Reviewed-by: Oliver Upton -- Thanks, Oliver > --- > tools/testing/selftests/kvm/aarch6

Re: [PATCH 02/14] KVM: arm64: Tear down unlinked stage-2 subtree after break-before-make

2022-10-09 Thread Oliver Upton
Hey Ricardo, On Tue, Sep 13, 2022 at 05:20:11PM -0700, Ricardo Koller wrote: [...] > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index d8127c25424c..5c0c8028d71c 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -763,17

Re: [PATCH v2 15/15] KVM: arm64: Handle stage-2 faults in parallel

2022-10-07 Thread Oliver Upton
On Sat, Oct 08, 2022 at 11:01:44AM +0800, kernel test robot wrote: [...] > All warnings (new ones prefixed by >>): > >arch/arm64/kvm/hyp/nvhe/mem_protect.c: In function '__host_stage2_idmap': > >> arch/arm64/kvm/hyp/nvhe/mem_protect.c:260:60: warning: implicit conversion > >> from 'enum ' t

[PATCH v3 2/2] KVM: arm64: Limit stage2_apply_range() batch size to largest block

2022-10-07 Thread Oliver Upton
eed to visit a leaf only once. Signed-off-by: Oliver Upton --- arch/arm64/include/asm/stage2_pgtable.h | 20 arch/arm64/kvm/mmu.c| 9 - 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch

[PATCH v3 0/2] KVM: arm64: Limit stage2_apply_range() batch size to largest block

2022-10-07 Thread Oliver Upton
as the batch size (Marc) Oliver Upton (2): KVM: arm64: Work out supported block level at compile time KVM: arm64: Limit stage2_apply_range() batch size to largest block arch/arm64/include/asm/kvm_pgtable.h| 18 +- arch/arm64/include/asm/stage2_pgtable.h |

[PATCH v3 1/2] KVM: arm64: Work out supported block level at compile time

2022-10-07 Thread Oliver Upton
Work out the minimum page table level where KVM supports block mappings at compile time. While at it, rewrite the comment around supported block mappings to directly describe what KVM supports instead of phrasing in terms of what it does not. Signed-off-by: Oliver Upton --- arch/arm64/include

[PATCH v2 15/15] KVM: arm64: Handle stage-2 faults in parallel

2022-10-07 Thread Oliver Upton
(). Signed-off-by: Oliver Upton --- arch/arm64/include/asm/kvm_pgtable.h | 3 ++- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/pgtable.c | 5 +++-- arch/arm64/kvm/mmu.c | 31 ++- 4 files changed, 13 insertions(+), 28 deletions

<    1   2   3   4   5   6   7   >