Re: [PATCH v14 06/13] iommu/smmuv3: Allow stage 1 invalidation with unmanaged ASIDs

2021-04-01 Thread Kunkun Jiang
Hi Eric, On 2021/2/24 4:56, Eric Auger wrote: With nested stage support, soon we will need to invalidate S1 contexts and ranges tagged with an unmanaged asid, this latter being managed by the guest. So let's introduce 2 helpers that allow to invalidate with externally managed ASIDs

RE: [PATCH v14 13/13] iommu/smmuv3: Accept configs with more than one context descriptor

2021-04-01 Thread Shameerali Kolothum Thodi
> -Original Message- > From: Auger Eric [mailto:eric.au...@redhat.com] > Sent: 01 April 2021 12:49 > To: yuzenghui > Cc: eric.auger@gmail.com; io...@lists.linux-foundation.org; > linux-ker...@vger.kernel.org; k...@vger.kernel.org; > kvmarm@lists.cs.columbia.edu; w...@kernel.org;

Re: [PATCH v2] KVM: arm64: Initialize VCPU mdcr_el2 before loading it

2021-04-01 Thread Alexandru Elisei
Hi Marc, On 3/30/21 8:57 PM, Marc Zyngier wrote: > On Tue, 30 Mar 2021 18:49:54 +0100, > Alexandru Elisei wrote: >> Hi Marc, >> >> On 3/30/21 6:13 PM, Alexandru Elisei wrote: >>> [..] > +} > + > /** > * kvm_arm_reset_debug_ptr - reset the debug ptr to point to the vcpu >

Re: [PATCH v2] KVM: arm64: Initialize VCPU mdcr_el2 before loading it

2021-04-01 Thread Marc Zyngier
On Thu, 01 Apr 2021 14:55:54 +0100, Alexandru Elisei wrote: [...] > Had another go at this, and as I was looking at the code, I realized that > conceptually, trapping debug registers access (MDCR_EL2.TDA) is tied to: > > - KVM_ARM64_DEBUG_DIRTY *not* being set (guest is debugging itself and

Re: [PATCH v4 7/8] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace

2021-04-01 Thread Marc Zyngier
Hi Eric, On Thu, 01 Apr 2021 09:52:37 +0100, Eric Auger wrote: > > Commit 23bde34771f1 ("KVM: arm64: vgic-v3: Drop the > reporting of GICR_TYPER.Last for userspace") temporarily fixed > a bug identified when attempting to access the GICR_TYPER > register before the redistributor region setting,

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 31/03/21 21:47, Sean Christopherson wrote: > > Rereading things, a small chunk of the rwsem nastiness can go away. I > > don't see > > any reason to use rw_semaphore instead of rwlock_t. > > Wouldn't it be incorrect to lock a mutex (e.g. inside

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 26/03/21 03:19, Sean Christopherson wrote: > > + /* > > +* Reset the lock used to prevent memslot updates between MMU notifier > > +* range_start and range_end. At this point no more MMU notifiers will > > +* run, but the lock could

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 31/03/21 23:05, Sean Christopherson wrote: > > > Wouldn't it be incorrect to lock a mutex (e.g. inside*another* MMU > > > notifier's invalidate callback) while holding an rwlock_t? That makes > > > sense > > > because anybody that's busy waiting

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 31/03/21 18:41, Sean Christopherson wrote: > > > That said, the easiest way to avoid this would be to always update > > > mmu_notifier_count. > > Updating mmu_notifier_count requires taking mmu_lock, which would defeat the > > purpose of these

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 26/03/21 03:19, Sean Christopherson wrote: > > + /* > > +* Reset the lock used to prevent memslot updates between MMU notifier > > +* range_start and range_end. At this point no more MMU notifiers will > > +* run, but the lock could

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Sean Christopherson wrote: > On Wed, Mar 31, 2021, Paolo Bonzini wrote: > > On 31/03/21 21:47, Sean Christopherson wrote: > > I also thought of busy waiting on down_read_trylock if the MMU notifier > > cannot block, but that would also be invalid for the opposite reason (the

Re: [PATCH 16/18] KVM: Don't take mmu_lock for range invalidation unless necessary

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 26/03/21 03:19, Sean Christopherson wrote: > Also, related to the first part of the series, perhaps you could structure > the series in a slightly different way: > > 1) introduce the HVA walking API in common code, complete with on_lock and > patch

Re: [PATCH 10/18] KVM: Move x86's MMU notifier memslot walkers to generic code

2021-04-01 Thread Sean Christopherson
On Wed, Mar 31, 2021, Paolo Bonzini wrote: > On 26/03/21 03:19, Sean Christopherson wrote: > > +#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS > > + kvm_handle_hva_range(mn, address, address + 1, pte, kvm_set_spte_gfn); > > +#else > > struct kvm *kvm = mmu_notifier_to_kvm(mn); > > int idx; >

[PATCH v2 7/9] KVM: SVM: split svm_handle_invalid_exit

2021-04-01 Thread Maxim Levitsky
Split the check for having a vmexit handler to svm_check_exit_valid, and make svm_handle_invalid_exit only handle a vmexit that is already not valid. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/svm.c | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git

[PATCH v2 2/9] KVM: introduce KVM_CAP_SET_GUEST_DEBUG2

2021-04-01 Thread Maxim Levitsky
This capability will allow the user to know which KVM_GUESTDBG_* bits are supported. Signed-off-by: Maxim Levitsky --- Documentation/virt/kvm/api.rst | 3 +++ include/uapi/linux/kvm.h | 1 + 2 files changed, 4 insertions(+) diff --git a/Documentation/virt/kvm/api.rst

[PATCH v2 8/9] KVM: x86: add force_intercept_exceptions_mask

2021-04-01 Thread Maxim Levitsky
This parameter will be used by VMX and SVM code to force interception of a set of exceptions, given by a bitmask for guest debug and/or kvm debug. This option is not intended for production. This is based on an idea first shown here:

[PATCH v2 6/9] KVM: x86: implement KVM_GUESTDBG_BLOCKEVENTS

2021-04-01 Thread Maxim Levitsky
KVM_GUESTDBG_BLOCKEVENTS is a guest debug feature that will allow KVM to block all interrupts while running. It is mostly intended to be used together with single stepping, to make it more robust, and has the following benefits: * Resuming from a breakpoint is much more reliable: When resuming

[PATCH v2 9/9] KVM: SVM: implement force_intercept_exceptions_mask

2021-04-01 Thread Maxim Levitsky
Currently #TS interception is only done once. Also exception interception is not enabled for SEV guests. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/svm/svm.c | 70 + arch/x86/kvm/svm/svm.h | 6 ++-

[PATCH v2 0/9] KVM: my debug patch queue

2021-04-01 Thread Maxim Levitsky
Hi! I would like to publish two debug features which were needed for other stuff I work on. One is the reworked lx-symbols script which now actually works on at least gdb 9.1 (gdb 9.2 was reported to fail to load the debug symbols from the kernel for some reason, not related to this patch) and

[PATCH v2 1/9] scripts/gdb: rework lx-symbols gdb script

2021-04-01 Thread Maxim Levitsky
Fix several issues that are present in lx-symbols script: * Track module unloads by placing another software breakpoint at 'free_module' (force uninline this symbol just in case), and use remove-symbol-file gdb command to unload the symobls of the module that is unloading. That gives the

[PATCH v2 3/9] KVM: x86: implement KVM_CAP_SET_GUEST_DEBUG2

2021-04-01 Thread Maxim Levitsky
Store the supported bits into KVM_GUESTDBG_VALID_MASK macro, similar to how arm does this. Signed-off-by: Maxim Levitsky --- arch/x86/include/asm/kvm_host.h | 9 + arch/x86/kvm/x86.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h

[PATCH v2 5/9] KVM: s390x: implement KVM_CAP_SET_GUEST_DEBUG2

2021-04-01 Thread Maxim Levitsky
Define KVM_GUESTDBG_VALID_MASK and use it to implement this capabiity. Compile tested only. Signed-off-by: Maxim Levitsky --- arch/s390/include/asm/kvm_host.h | 4 arch/s390/kvm/kvm-s390.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/arch/s390/include/asm/kvm_host.h

[PATCH v2 4/9] KVM: aarch64: implement KVM_CAP_SET_GUEST_DEBUG2

2021-04-01 Thread Maxim Levitsky
Move KVM_GUESTDBG_VALID_MASK to kvm_host.h and use it to return the value of this capability. Compile tested only. Signed-off-by: Maxim Levitsky --- arch/arm64/include/asm/kvm_host.h | 4 arch/arm64/kvm/arm.c | 2 ++ arch/arm64/kvm/guest.c| 5 - 3 files

[PATCH] KVM: arm64: Fix a typo in the kvm_init_stage2_mmu documentation

2021-04-01 Thread Yoan Picchi
A single letter : strucrure -> structure Signed-off-by: Yoan Picchi --- arch/arm64/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 77cb2d28f..eed9fed86 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@

Re: [PATCH v14 13/13] iommu/smmuv3: Accept configs with more than one context descriptor

2021-04-01 Thread Auger Eric
Hi Shameer, On 4/1/21 2:38 PM, Shameerali Kolothum Thodi wrote: > > >> -Original Message- >> From: Auger Eric [mailto:eric.au...@redhat.com] >> Sent: 01 April 2021 12:49 >> To: yuzenghui >> Cc: eric.auger@gmail.com; io...@lists.linux-foundation.org; >> linux-ker...@vger.kernel.org;

Re: [PATCH v4 7/8] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace

2021-04-01 Thread Auger Eric
Hi Marc, On 4/1/21 3:42 PM, Marc Zyngier wrote: > Hi Eric, > > On Thu, 01 Apr 2021 09:52:37 +0100, > Eric Auger wrote: >> >> Commit 23bde34771f1 ("KVM: arm64: vgic-v3: Drop the >> reporting of GICR_TYPER.Last for userspace") temporarily fixed >> a bug identified when attempting to access the

Re: [PATCH v4 7/8] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace

2021-04-01 Thread Auger Eric
Hi Marc, On 4/1/21 7:30 PM, Marc Zyngier wrote: > On Thu, 01 Apr 2021 18:03:25 +0100, > Auger Eric wrote: >> >> Hi Marc, >> >> On 4/1/21 3:42 PM, Marc Zyngier wrote: >>> Hi Eric, >>> >>> On Thu, 01 Apr 2021 09:52:37 +0100, >>> Eric Auger wrote: Commit 23bde34771f1 ("KVM: arm64:

Re: [PATCH v4 7/8] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace

2021-04-01 Thread Marc Zyngier
On Thu, 01 Apr 2021 18:03:25 +0100, Auger Eric wrote: > > Hi Marc, > > On 4/1/21 3:42 PM, Marc Zyngier wrote: > > Hi Eric, > > > > On Thu, 01 Apr 2021 09:52:37 +0100, > > Eric Auger wrote: > >> > >> Commit 23bde34771f1 ("KVM: arm64: vgic-v3: Drop the > >> reporting of GICR_TYPER.Last for

Re: [PATCH v14 07/13] iommu/smmuv3: Implement cache_invalidate

2021-04-01 Thread Zenghui Yu
Hi Eric, On 2021/2/24 4:56, Eric Auger wrote: +static int +arm_smmu_cache_invalidate(struct iommu_domain *domain, struct device *dev, + struct iommu_cache_invalidate_info *inv_info) +{ + struct arm_smmu_cmdq_ent cmd = {.opcode = CMDQ_OP_TLBI_NSNH_ALL}; +

Re: [PATCH v4 1/8] KVM: arm64: vgic-v3: Fix some error codes when setting RDIST base

2021-04-01 Thread Marc Zyngier
Hi Eric, On Thu, 01 Apr 2021 09:52:31 +0100, Eric Auger wrote: > > KVM_DEV_ARM_VGIC_GRP_ADDR group doc says we should return > -EEXIST in case the base address of the redist is already set. > We currently return -EINVAL. > > However we need to return -EINVAL in case a legacy REDIST address >

Re: [PATCH v3 0/5] Debug info for nVHE hyp panics

2021-04-01 Thread Marc Zyngier
On Thu, 18 Mar 2021 14:33:06 +, Andrew Scull wrote: > Panics from arm64's nVHE hyp mode are hard to interpret. This series > adds some more debug info to help with diagnosis. > > Using BUG() in nVHE hyp gives a meaningful address to locate invariants > that fail to hold. The host can also

Re: [PATCH v14 06/13] iommu/smmuv3: Allow stage 1 invalidation with unmanaged ASIDs

2021-04-01 Thread Auger Eric
Hi Zenghui, On 3/30/21 11:17 AM, Zenghui Yu wrote: > On 2021/2/24 4:56, Eric Auger wrote: >> @@ -1936,7 +1950,12 @@ static void >> arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, >>   }, >>   }; >>   -    if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { >> +    if

[PATCH v4 8/8] KVM: selftests: aarch64/vgic-v3 init sequence tests

2021-04-01 Thread Eric Auger
The tests exercise the VGIC_V3 device creation including the associated KVM_DEV_ARM_VGIC_GRP_ADDR group attributes: - KVM_VGIC_V3_ADDR_TYPE_DIST/REDIST - KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION Some other tests dedicate to KVM_DEV_ARM_VGIC_GRP_REDIST_REGS group and especially the GICR_TYPER read.

[PATCH v4 0/8] KVM/ARM: Some vgic fixes and init sequence KVM selftests

2021-04-01 Thread Eric Auger
While writting vgic v3 init sequence KVM selftests I noticed some relatively minor issues. This was also the opportunity to try to fix the issue laterly reported by Zenghui, related to the RDIST_TYPER last bit emulation. The final patch is a first batch of VGIC init sequence selftests. Of course

[PATCH v4 1/8] KVM: arm64: vgic-v3: Fix some error codes when setting RDIST base

2021-04-01 Thread Eric Auger
KVM_DEV_ARM_VGIC_GRP_ADDR group doc says we should return -EEXIST in case the base address of the redist is already set. We currently return -EINVAL. However we need to return -EINVAL in case a legacy REDIST address is attempted to be set while REDIST_REGIONS were set. This case is discriminated

[PATCH v4 2/8] KVM: arm64: Fix KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION read

2021-04-01 Thread Eric Auger
The doc says: "The characteristics of a specific redistributor region can be read by presetting the index field in the attr data. Only valid for KVM_DEV_TYPE_ARM_VGIC_V3" Unfortunately the existing code fails to read the input attr data. Fixes: 04c110932225 ("KVM: arm/arm64: Implement

[PATCH v4 3/8] KVM: arm64: vgic-v3: Fix error handling in vgic_v3_set_redist_base()

2021-04-01 Thread Eric Auger
vgic_v3_insert_redist_region() may succeed while vgic_register_all_redist_iodevs fails. For example this happens while adding a redistributor region overlapping a dist region. The failure only is detected on vgic_register_all_redist_iodevs when vgic_v3_check_base() gets called in

[PATCH v4 4/8] KVM: arm/arm64: vgic: Reset base address on kvm_vgic_dist_destroy()

2021-04-01 Thread Eric Auger
On vgic_dist_destroy(), the addresses are not reset. However for kvm selftest purpose this would allow to continue the test execution even after a failure when running KVM_RUN. So let's reset the base addresses. Signed-off-by: Eric Auger --- v1 -> v2: - use dist-> in the else and add braces

[PATCH v4 5/8] docs: kvm: devices/arm-vgic-v3: enhance KVM_DEV_ARM_VGIC_CTRL_INIT doc

2021-04-01 Thread Eric Auger
kvm_arch_vcpu_precreate() returns -EBUSY if the vgic is already initialized. So let's document that KVM_DEV_ARM_VGIC_CTRL_INIT must be called after all vcpu creations. Signed-off-by: Eric Auger --- v1 -> v2: - Must be called after all vcpu creations -> Must be called after all VCPUs have

[PATCH v4 6/8] KVM: arm64: Simplify argument passing to vgic_uaccess_[read|write]

2021-04-01 Thread Eric Auger
vgic_uaccess() takes a struct vgic_io_device argument, converts it to a struct kvm_io_device and passes it to the read/write accessor functions, which convert it back to a struct vgic_io_device. Avoid the indirection by passing the struct vgic_io_device argument directly to

[PATCH v4 7/8] KVM: arm64: vgic-v3: Expose GICR_TYPER.Last for userspace

2021-04-01 Thread Eric Auger
Commit 23bde34771f1 ("KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace") temporarily fixed a bug identified when attempting to access the GICR_TYPER register before the redistributor region setting, but dropped the support of the LAST bit. Emulating the GICR_TYPER.Last bit

Re: [PATCH v4 1/8] KVM: arm64: vgic-v3: Fix some error codes when setting RDIST base

2021-04-01 Thread Auger Eric
Hi Marc, On 4/1/21 12:52 PM, Marc Zyngier wrote: > Hi Eric, > > On Thu, 01 Apr 2021 09:52:31 +0100, > Eric Auger wrote: >> >> KVM_DEV_ARM_VGIC_GRP_ADDR group doc says we should return >> -EEXIST in case the base address of the redist is already set. >> We currently return -EINVAL. >> >> However

Re: [PATCH v14 13/13] iommu/smmuv3: Accept configs with more than one context descriptor

2021-04-01 Thread Auger Eric
Hi Zenghui, On 3/30/21 11:23 AM, Zenghui Yu wrote: > Hi Eric, > > On 2021/2/24 4:56, Eric Auger wrote: >> In preparation for vSVA, let's accept userspace provided configs >> with more than one CD. We check the max CD against the host iommu >> capability and also the format (linear versus 2

Re: [PATCH v14 07/13] iommu/smmuv3: Implement cache_invalidate

2021-04-01 Thread Auger Eric
Hi Zenghui, On 4/1/21 8:11 AM, Zenghui Yu wrote: > Hi Eric, > > On 2021/2/24 4:56, Eric Auger wrote: >> +static int >> +arm_smmu_cache_invalidate(struct iommu_domain *domain, struct device >> *dev, >> +  struct iommu_cache_invalidate_info *inv_info) >> +{ >> +    struct