Re: [PATCH v3 0/5] arm64: Treat ESR_ELx as a 64-bit register

2022-04-29 Thread Catalin Marinas
On Mon, 25 Apr 2022 12:44:39 +0100, Alexandru Elisei wrote:
> The ESR_EL{1,2} registers were originally 32-bit, then were extended to
> 64-bit with the upper 32 bits RES0, and in ARM DDI 0487H.a the FEAT_LS64
> feature was added which now makes use of the upper bits. This series aims
> to teach Linux to treat it consistently as a 64-bit register with the goal
> of making it easier to add support in the future for features that use the
> upper 32 bits.
> 
> [...]

Applied to arm64 (for-next/esr-elx-64-bit), thanks!

[1/5] arm64: Make ESR_ELx_xVC_IMM_MASK compatible with assembly
  https://git.kernel.org/arm64/c/a99ef9cb4b79
[2/5] arm64: compat: Do not treat syscall number as ESR_ELx for a bad syscall
  https://git.kernel.org/arm64/c/3fed9e551417
[3/5] arm64: Treat ESR_ELx as a 64-bit register
  https://git.kernel.org/arm64/c/8d56e5c5a99c
[4/5] KVM: arm64: Treat ESR_EL2 as a 64-bit register
  https://git.kernel.org/arm64/c/0b12620fddb8
[5/5] KVM: arm64: uapi: Add kvm_debug_exit_arch.hsr_high
  https://git.kernel.org/arm64/c/18f3976fdb5d

-- 
Catalin

___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [GIT PULL] KVM/arm64 fixes for 5.18, take #2

2022-04-29 Thread Paolo Bonzini

On 4/29/22 17:36, Marc Zyngier wrote:

Paolo,

Here's a trio of fixes for 5.18. Nothing terribly interesting, but
nonetheless important fixes (two of the bugs are related to AArch32).


Cool, will pull soon.  Please take a quick look at the flags->data ABI 
fix, it's one patch on top of 5.18 as you requested and if I hear 
nothing I'll send it ~Sunday morning to Linus.


Thanks,

Paolo


Please pull,

M.

The following changes since commit 21db83846683d3987666505a3ec38f367708199a:

   selftests: KVM: Free the GIC FD when cleaning up in arch_timer (2022-04-07 
08:46:13 +0100)

are available in the Git repository at:

   git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git 
tags/kvmarm-fixes-5.18-2

for you to fetch changes up to 85ea6b1ec915c9dd90caf3674b203999d8c7e062:

   KVM: arm64: Inject exception on out-of-IPA-range translation fault 
(2022-04-27 23:02:23 +0100)


KVM/arm64 fixes for 5.18, take #2

- Take care of faults occuring between the PARange and
   IPA range by injecting an exception

- Fix S2 faults taken from a host EL0 in protected mode

- Work around Oops caused by a PMU access from a 32bit
   guest when PMU has been created. This is a temporary
   bodge until we fix it for good.


Alexandru Elisei (1):
   KVM/arm64: Don't emulate a PMU for 32-bit guests if feature not set

Marc Zyngier (1):
   KVM: arm64: Inject exception on out-of-IPA-range translation fault

Will Deacon (1):
   KVM: arm64: Handle host stage-2 faults from 32-bit EL0

  arch/arm64/include/asm/kvm_emulate.h |  1 +
  arch/arm64/kvm/hyp/nvhe/host.S   | 18 +-
  arch/arm64/kvm/inject_fault.c| 28 
  arch/arm64/kvm/mmu.c | 19 +++
  arch/arm64/kvm/pmu-emul.c| 23 ++-
  5 files changed, 79 insertions(+), 10 deletions(-)



___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


[GIT PULL] KVM/arm64 fixes for 5.18, take #2

2022-04-29 Thread Marc Zyngier
Paolo,

Here's a trio of fixes for 5.18. Nothing terribly interesting, but
nonetheless important fixes (two of the bugs are related to AArch32).

Please pull,

M.

The following changes since commit 21db83846683d3987666505a3ec38f367708199a:

  selftests: KVM: Free the GIC FD when cleaning up in arch_timer (2022-04-07 
08:46:13 +0100)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git 
tags/kvmarm-fixes-5.18-2

for you to fetch changes up to 85ea6b1ec915c9dd90caf3674b203999d8c7e062:

  KVM: arm64: Inject exception on out-of-IPA-range translation fault 
(2022-04-27 23:02:23 +0100)


KVM/arm64 fixes for 5.18, take #2

- Take care of faults occuring between the PARange and
  IPA range by injecting an exception

- Fix S2 faults taken from a host EL0 in protected mode

- Work around Oops caused by a PMU access from a 32bit
  guest when PMU has been created. This is a temporary
  bodge until we fix it for good.


Alexandru Elisei (1):
  KVM/arm64: Don't emulate a PMU for 32-bit guests if feature not set

Marc Zyngier (1):
  KVM: arm64: Inject exception on out-of-IPA-range translation fault

Will Deacon (1):
  KVM: arm64: Handle host stage-2 faults from 32-bit EL0

 arch/arm64/include/asm/kvm_emulate.h |  1 +
 arch/arm64/kvm/hyp/nvhe/host.S   | 18 +-
 arch/arm64/kvm/inject_fault.c| 28 
 arch/arm64/kvm/mmu.c | 19 +++
 arch/arm64/kvm/pmu-emul.c| 23 ++-
 5 files changed, 79 insertions(+), 10 deletions(-)
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [PATCH 4/4] KVM: arm64: Unwind and dump nVHE hypervisor stacktrace

2022-04-29 Thread Mark Brown
On Wed, Apr 27, 2022 at 11:46:59AM -0700, Kalesh Singh wrote:
> On hyp_panic(), the hypervisor dumps the addresses for its stacktrace
> entries to a page shared with the host. The host then symbolizes and
> prints the hyp stacktrace before panicking itself.
> 
> Example stacktrace:
> 
> [  122.051187] kvm [380]: Invalid host exception to nVHE hyp!
> [  122.052467] kvm [380]: nVHE HYP call trace:
> [  122.052814] kvm [380]: [] 
> __kvm_nvhe___pkvm_vcpu_init_traps+0x1f0/0x1f0
> [  122.053865] kvm [380]: [] 
> __kvm_nvhe_hyp_panic+0x130/0x1c0
> [  122.054367] kvm [380]: [] 
> __kvm_nvhe___kvm_vcpu_run+0x10/0x10
> [  122.054878] kvm [380]: [] 
> __kvm_nvhe_handle___kvm_vcpu_run+0x30/0x50
> [  122.055412] kvm [380]: [] 
> __kvm_nvhe_handle_trap+0xbc/0x160
> [  122.055911] kvm [380]: [] 
> __kvm_nvhe___host_exit+0x64/0x64
> [  122.056417] kvm [380]:  end of nVHE HYP call trace 

This will be really helpful!

Reviewed-by: Mark Brown 


signature.asc
Description: PGP signature
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [PATCH 1/4] KVM: arm64: Compile stacktrace.nvhe.o

2022-04-29 Thread Mark Brown
On Wed, Apr 27, 2022 at 11:46:56AM -0700, Kalesh Singh wrote:

> Recompile stack unwinding code for use with the nVHE hypervisor. This is
> a preparatory patch that will allow reusing most of the kernel unwinding
> logic in the nVHE hypervisor.

This is substantially more than just the build change that the changelog
would seem to indicate...  it would I think be clearer to split this up
further with the code changes separated out and explained a bit more.
It's not just recompling the code for nVHE, there's also refactoring to
split out changes that don't apply in nVHE hypervisor like all the task
related code which is needed but not mentioned in the changlog at all.
Possibly a patch or two for the code motion then a separate patch for
the ifdefs and build changes?

I *think* the code is all fine but I'd need to go through it a few more
times to be sure I didn't miss anything.


signature.asc
Description: PGP signature
___
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm


Re: [PATCH v2] KVM: arm64: Inject exception on out-of-IPA-range translation fault

2022-04-29 Thread Alexandru Elisei
Hi,

On Thu, Apr 28, 2022 at 06:55:56PM +0100, Marc Zyngier wrote:
> On Thu, 28 Apr 2022 17:07:21 +0100,
> Alexandru Elisei  wrote:
> > 
> > Hi,
> > 
> > On Thu, Apr 28, 2022 at 04:22:58PM +0100, Marc Zyngier wrote:
> > > On Thu, 28 Apr 2022 09:46:21 +0100,
> > > Alexandru Elisei  wrote:
> > > > 
> > > > Hi,
> > > > 
> > > > On Wed, Apr 27, 2022 at 11:04:34PM +0100, Marc Zyngier wrote:
> > > > > When taking a translation fault for an IPA that is outside of
> > > > > the range defined by the hypervisor (between the HW PARange and
> > > > > the IPA range), we stupidly treat it as an IO and forward the access
> > > > > to userspace. Of course, userspace can't do much with it, and things
> > > > > end badly.
> > > > > 
> > > > > Arguably, the guest is braindead, but we should at least catch the
> > > > > case and inject an exception.
> > > > > 
> > > > > Check the faulting IPA against:
> > > > > - the sanitised PARange: inject an address size fault
> > > > > - the IPA size: inject an abort
> > > > > 
> > > > > Reported-by: Christoffer Dall 
> > > > > Signed-off-by: Marc Zyngier 
> > > > > ---
> > > > >  arch/arm64/include/asm/kvm_emulate.h |  1 +
> > > > >  arch/arm64/kvm/inject_fault.c| 28 
> > > > > 
> > > > >  arch/arm64/kvm/mmu.c | 19 +++
> > > > >  3 files changed, 48 insertions(+)
> > > > > 
> > > > > diff --git a/arch/arm64/include/asm/kvm_emulate.h 
> > > > > b/arch/arm64/include/asm/kvm_emulate.h
> > > > > index 7496deab025a..f71358271b71 100644
> > > > > --- a/arch/arm64/include/asm/kvm_emulate.h
> > > > > +++ b/arch/arm64/include/asm/kvm_emulate.h
> > > > > @@ -40,6 +40,7 @@ void kvm_inject_undefined(struct kvm_vcpu *vcpu);
> > > > >  void kvm_inject_vabt(struct kvm_vcpu *vcpu);
> > > > >  void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr);
> > > > >  void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);
> > > > > +void kvm_inject_size_fault(struct kvm_vcpu *vcpu);
> > > > >  
> > > > >  void kvm_vcpu_wfi(struct kvm_vcpu *vcpu);
> > > > >  
> > > > > diff --git a/arch/arm64/kvm/inject_fault.c 
> > > > > b/arch/arm64/kvm/inject_fault.c
> > > > > index b47df73e98d7..ba20405d2dc2 100644
> > > > > --- a/arch/arm64/kvm/inject_fault.c
> > > > > +++ b/arch/arm64/kvm/inject_fault.c
> > > > > @@ -145,6 +145,34 @@ void kvm_inject_pabt(struct kvm_vcpu *vcpu, 
> > > > > unsigned long addr)
> > > > >   inject_abt64(vcpu, true, addr);
> > > > >  }
> > > > >  
> > > > > +void kvm_inject_size_fault(struct kvm_vcpu *vcpu)
> > > > > +{
> > > > > + unsigned long addr, esr;
> > > > > +
> > > > > + addr  = kvm_vcpu_get_fault_ipa(vcpu);
> > > > > + addr |= kvm_vcpu_get_hfar(vcpu) & GENMASK(11, 0);
> > > > > +
> > > > > + if (kvm_vcpu_trap_is_iabt(vcpu))
> > > > > + kvm_inject_pabt(vcpu, addr);
> > > > > + else
> > > > > + kvm_inject_dabt(vcpu, addr);
> > > > > +
> > > > > + /*
> > > > > +  * If AArch64 or LPAE, set FSC to 0 to indicate an Address
> > > > > +  * Size Fault at level 0, as if exceeding PARange.
> > > > > +  *
> > > > > +  * Non-LPAE guests will only get the external abort, as there
> > > > > +  * is no way to to describe the ASF.
> > > > > +  */
> > > > > + if (vcpu_el1_is_32bit(vcpu) &&
> > > > > + !(vcpu_read_sys_reg(vcpu, TCR_EL1) & TTBCR_EAE))
> > > > > + return;
> > > > > +
> > > > > + esr = vcpu_read_sys_reg(vcpu, ESR_EL1);
> > > > > + esr &= ~GENMASK_ULL(5, 0);
> > > > > + vcpu_write_sys_reg(vcpu, esr, ESR_EL1);
> > > > > +}
> > > > > +
> > > > >  /**
> > > > >   * kvm_inject_undefined - inject an undefined instruction into the 
> > > > > guest
> > > > >   * @vcpu: The vCPU in which to inject the exception
> > > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> > > > > index 53ae2c0640bc..5400fc020164 100644
> > > > > --- a/arch/arm64/kvm/mmu.c
> > > > > +++ b/arch/arm64/kvm/mmu.c
> > > > > @@ -1337,6 +1337,25 @@ int kvm_handle_guest_abort(struct kvm_vcpu 
> > > > > *vcpu)
> > > > >   fault_ipa = kvm_vcpu_get_fault_ipa(vcpu);
> > > > >   is_iabt = kvm_vcpu_trap_is_iabt(vcpu);
> > > > >  
> > > > > + if (fault_status == FSC_FAULT) {
> > > > > + /* Beyond sanitised PARange (which is the IPA limit) */
> > > > > + if (fault_ipa >= BIT_ULL(get_kvm_ipa_limit())) {
> > > > > + kvm_inject_size_fault(vcpu);
> > > > > + return 1;
> > > > > + }
> > > > > +
> > > > > + /* Falls between the IPA range and the PARange? */
> > > > > + if (fault_ipa >= 
> > > > > BIT_ULL(vcpu->arch.hw_mmu->pgt->ia_bits)) {
> > > > > + fault_ipa |= kvm_vcpu_get_hfar(vcpu) & 
> > > > > GENMASK(11, 0);
> > > > > +
> > > > > + if (is_iabt)
> > > > > + kvm_inject_pabt(vcpu, fault_ipa);
> > > > > + else
> > > > > +