[kvm-unit-tests PATCH 2/3] arm64: timer: Use the proper RDist register name in GICv3

2020-02-11 Thread Zenghui Yu
We're actually going to read GICR_ISACTIVER0 and GICR_ISPENDR0 (in SGI_base frame of the redistribitor) to get the active/pending state of the timer interrupt. Fix this typo. And since they have the same value, there's no functional change. Signed-off-by: Zenghui Yu --- arm/timer.c |

[kvm-unit-tests PATCH 0/3] arm64: minor cleanups for timer test

2020-02-11 Thread Zenghui Yu
Hi Drew, There's some minor cleanups which based on your arm/queue branch for the timer test. Please consider taking them if they make the code a bit better :) Thanks Zenghui Yu (3): arm/arm64: gic: Move gic_state enumeration to asm/gic.h arm64: timer: Use the proper RDist register name in

[kvm-unit-tests PATCH 1/3] arm/arm64: gic: Move gic_state enumeration to asm/gic.h

2020-02-11 Thread Zenghui Yu
The status of each interrupt are defined by the GIC architecture and maintained by GIC hardware. They're not specified to the timer HW. Let's move this software enumeration to a more proper place. Signed-off-by: Zenghui Yu --- arm/timer.c | 7 --- lib/arm/asm/gic.h | 7 +++ 2 file

[kvm-unit-tests PATCH 3/3] arm64: timer: Use existing helpers to access counter/timers

2020-02-11 Thread Zenghui Yu
We already have some good helpers to access the counter and timer registers. Use them to avoid open coding the accessors again. Signed-off-by: Zenghui Yu --- arm/timer.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arm/timer.c b/arm/timer.c index 10a88f3.

Re: [kvm-unit-tests PATCH 2/3] arm64: timer: Use the proper RDist register name in GICv3

2020-02-11 Thread Alexandru Elisei
Hi, On 2/11/20 8:39 AM, Zenghui Yu wrote: > We're actually going to read GICR_ISACTIVER0 and GICR_ISPENDR0 (in > SGI_base frame of the redistribitor) to get the active/pending state > of the timer interrupt. Fix this typo. > > And since they have the same value, there's no functional change. > >

Re: [kvm-unit-tests PATCH 0/3] arm64: minor cleanups for timer test

2020-02-11 Thread Andrew Jones
On Tue, Feb 11, 2020 at 04:38:58PM +0800, Zenghui Yu wrote: > Hi Drew, > > There's some minor cleanups which based on your arm/queue branch for > the timer test. Please consider taking them if they make the code > a bit better :) > > Thanks > > Zenghui Yu (3): > arm/arm64: gic: Move gic_state

[PATCH kvm-unit-tests] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Andrew Jones
Let's bail out of the wait loop if we see the expected state to save about seven seconds of run time. Make sure we wait a bit before reading the registers, though, to somewhat mitigate the chance of the expected state being stale. Signed-off-by: Andrew Jones --- arm/timer.c | 17 ++--

Re: [PATCH kvm-unit-tests] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Alexandru Elisei
Hi, On 2/11/20 12:35 PM, Andrew Jones wrote: > Let's bail out of the wait loop if we see the expected state > to save about seven seconds of run time. Make sure we wait a > bit before reading the registers, though, to somewhat mitigate > the chance of the expected state being stale. > > Signed-off

Re: [PATCH kvm-unit-tests] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Andrew Jones
On Tue, Feb 11, 2020 at 12:49:23PM +, Alexandru Elisei wrote: > Hi, > > On 2/11/20 12:35 PM, Andrew Jones wrote: > > Let's bail out of the wait loop if we see the expected state > > to save about seven seconds of run time. Make sure we wait a > > bit before reading the registers, though, to so

[PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Andrew Jones
Let's bail out of the wait loop if we see the expected state to save over six seconds of run time. Make sure we wait a bit before reading the registers and double check again after, though, to somewhat mitigate the chance of seeing the expected state by accident. We also take this opportunity to p

Re: [PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Alexandru Elisei
Hi, On 2/11/20 1:37 PM, Andrew Jones wrote: > Let's bail out of the wait loop if we see the expected state > to save over six seconds of run time. Make sure we wait a bit > before reading the registers and double check again after, > though, to somewhat mitigate the chance of seeing the expected >

Re: [PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Andrew Jones
On Tue, Feb 11, 2020 at 01:52:35PM +, Alexandru Elisei wrote: > Hi, > > On 2/11/20 1:37 PM, Andrew Jones wrote: > > Let's bail out of the wait loop if we see the expected state > > to save over six seconds of run time. Make sure we wait a bit > > before reading the registers and double check a

Re: [PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Zenghui Yu
Hi Drew, On 2020/2/11 21:37, Andrew Jones wrote: Let's bail out of the wait loop if we see the expected state to save over six seconds of run time. Make sure we wait a bit before reading the registers and double check again after, though, to somewhat mitigate the chance of seeing the expected st

Re: [RFC PATCH 0/5] Removing support for 32bit KVM/arm host

2020-02-11 Thread Vladimir Murzin
On 2/10/20 2:13 PM, Marc Zyngier wrote: > KVM/arm was merged just over 7 years ago, and has lived a very quiet > life so far. It mostly works if you're prepared to deal with its > limitations, it has been a good prototype for the arm64 version, > but it suffers a few problems: > > - It is incomple

Re: [RFC PATCH 0/5] Removing support for 32bit KVM/arm host

2020-02-11 Thread Catalin Marinas
On Mon, Feb 10, 2020 at 02:13:19PM +, Marc Zyngier wrote: > KVM/arm was merged just over 7 years ago, and has lived a very quiet > life so far. It mostly works if you're prepared to deal with its > limitations, it has been a good prototype for the arm64 version, > but it suffers a few problems:

Re: [PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Zenghui Yu
On 2020/2/11 22:50, Zenghui Yu wrote: Hi Drew, On 2020/2/11 21:37, Andrew Jones wrote: Let's bail out of the wait loop if we see the expected state to save over six seconds of run time. Make sure we wait a bit before reading the registers and double check again after, though, to somewhat mitiga

Re: [kvm-unit-tests PATCH v2 4/9] arm: pmu: Check Required Event Support

2020-02-11 Thread Peter Maydell
On Thu, 30 Jan 2020 at 11:25, Eric Auger wrote: > > If event counters are implemented check the common events > required by the PMUv3 are implemented. > > Some are unconditionally required (SW_INCR, CPU_CYCLES, > either INST_RETIRED or INST_SPEC). Some others only are > required if the implementat

Re: [PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Andrew Jones
On Tue, Feb 11, 2020 at 10:50:58PM +0800, Zenghui Yu wrote: > Hi Drew, > > On 2020/2/11 21:37, Andrew Jones wrote: > > Let's bail out of the wait loop if we see the expected state > > to save over six seconds of run time. Make sure we wait a bit > > before reading the registers and double check ag

Re: [kvm-unit-tests PATCH v2 0/9] KVM: arm64: PMUv3 Event Counter Tests

2020-02-11 Thread Peter Maydell
On Thu, 30 Jan 2020 at 11:25, Eric Auger wrote: > > This series implements tests exercising the PMUv3 event counters. > It tests both the 32-bit and 64-bit versions. Overflow interrupts > also are checked. Those tests only are written for arm64. > > It allowed to reveal some issues related to SW_I

Re: [PATCH kvm-unit-tests v2] arm64: timer: Speed up gic-timer-state check

2020-02-11 Thread Andrew Jones
On Tue, Feb 11, 2020 at 11:32:14PM +0800, Zenghui Yu wrote: > On 2020/2/11 22:50, Zenghui Yu wrote: > > Hi Drew, > > > > On 2020/2/11 21:37, Andrew Jones wrote: > > > Let's bail out of the wait loop if we see the expected state > > > to save over six seconds of run time. Make sure we wait a bit >

Re: [kvm-unit-tests PATCH v2 0/9] KVM: arm64: PMUv3 Event Counter Tests

2020-02-11 Thread Andrew Jones
On Tue, Feb 11, 2020 at 03:42:38PM +, Peter Maydell wrote: > On Thu, 30 Jan 2020 at 11:25, Eric Auger wrote: > > > > This series implements tests exercising the PMUv3 event counters. > > It tests both the 32-bit and 64-bit versions. Overflow interrupts > > also are checked. Those tests only ar

Re: [kvm-unit-tests PATCH v2 6/9] arm: pmu: Test chained counter

2020-02-11 Thread Peter Maydell
On Thu, 30 Jan 2020 at 11:26, Eric Auger wrote: > > Add 2 tests exercising chained counters. The first one uses > CPU_CYCLES and the second one uses SW_INCR. > > Signed-off-by: Eric Auger > +static void test_chained_sw_incr(void) > +{ > + uint32_t events[] = { 0x0 /* SW_INCR */, 0x0 /* SW_I

Re: [kvm-unit-tests PATCH v2 5/9] arm: pmu: Basic event counter Tests

2020-02-11 Thread Peter Maydell
On Thu, 30 Jan 2020 at 11:26, Eric Auger wrote: > > Adds the following tests: > - event-counter-config: test event counter configuration > - basic-event-count: > - programs counters #0 and #1 to count 2 required events > (resp. CPU_CYCLES and INST_RETIRED). Counter #0 is preset > to a value

Re: [kvm-unit-tests PATCH v2 4/9] arm: pmu: Check Required Event Support

2020-02-11 Thread Peter Maydell
On Thu, 30 Jan 2020 at 11:25, Eric Auger wrote: > > If event counters are implemented check the common events > required by the PMUv3 are implemented. > > Some are unconditionally required (SW_INCR, CPU_CYCLES, > either INST_RETIRED or INST_SPEC). Some others only are > required if the implementat

Re: [PATCH v5 1/3] arm64: cpufeature: Extract capped fields

2020-02-11 Thread Suzuki Kuruppassery Poulose
On 27/01/2020 11:44, Andrew Murray wrote: When emulating ID registers there is often a need to cap the version bits of a feature such that the guest will not use features that do not yet exist. Let's add a helper that extracts a field and caps the version to a given value. Signed-off-by: Andrew

[PATCH v2 09/94] KVM: arm64: nv: Support virtual EL2 exceptions

2020-02-11 Thread Marc Zyngier
From: Jintack Lim Support injecting exceptions and performing exception returns to and from virtual EL2. This must be done entirely in software except when taking an exception from vEL0 to vEL2 when the virtual HCR_EL2.{E2H,TGE} == {1,1} (a VHE guest hypervisor). Signed-off-by: Jintack Lim Si

[PATCH v2 03/94] KVM: arm64: nv: Introduce nested virtualization VCPU feature

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Introduce the feature bit and a primitive that checks if the feature is set behind a static key check based on the cpus_have_const_cap check. Checking nested_virt_in_use() on systems without nested virt enabled should have neglgible overhead. We don't yet allow userspace

[PATCH v2 00/94] KVM: arm64: ARMv8.3/8.4 Nested Virtualization support

2020-02-11 Thread Marc Zyngier
This is a major rework of the NV series that I posted over 6 months ago[1], and a lot has changed since then: - Early ARMv8.4-NV support - ARMv8.4-TTL support in host and guest - ARMv8.5-GTG support in host and guest - Lots of comments addressed after the review - Rebased on v5.6-rc1 - Way too man

[PATCH v2 05/94] KVM: arm64: nv: Allow userspace to set PSR_MODE_EL2x

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall We were not allowing userspace to set a more privileged mode for the VCPU than EL1, but we should allow this when nested virtualization is enabled for the VCPU. Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/kvm/guest.c | 6 ++ 1 file cha

[PATCH v2 06/94] KVM: arm64: nv: Add EL2 system registers to vcpu context

2020-02-11 Thread Marc Zyngier
From: Jintack Lim ARM v8.3 introduces a new bit in the HCR_EL2, which is the NV bit. When this bit is set, accessing EL2 registers in EL1 traps to EL2. In addition, executing the following instructions in EL1 will trap to EL2: tlbi, at, eret, and msr/mrs instructions to access SP_EL1. Most of the

[PATCH v2 07/94] KVM: arm64: nv: Reset VMPIDR_EL2 and VPIDR_EL2 to sane values

2020-02-11 Thread Marc Zyngier
The VMPIDR_EL2 and VPIDR_EL2 are architecturally UNKNOWN at reset, but let's be nice to a guest hypervisor behaving foolishly and reset these to something reasonable anyway. Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 25 +

[PATCH v2 02/94] arm64: Add ARM64_HAS_NESTED_VIRT cpufeature

2020-02-11 Thread Marc Zyngier
From: Jintack Lim Add a new ARM64_HAS_NESTED_VIRT feature to indicate that the CPU has the ARMv8.3 nested virtualization capability. This will be used to support nested virtualization in KVM. Signed-off-by: Jintack Lim Signed-off-by: Andre Przywara Signed-off-by: Christoffer Dall Signed-off-

[PATCH v2 04/94] KVM: arm64: nv: Reset VCPU to EL2 registers if VCPU nested virt is set

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Reset the VCPU with PSTATE.M = EL2h when the nested virtualization feature is enabled on the VCPU. Signed-off-by: Christoffer Dall [maz: rework register reset not to use empty data structures] Signed-off-by: Marc Zyngier --- arch/arm64/kvm/reset.c | 32 +

[PATCH v2 08/94] KVM: arm64: nv: Add nested virt VCPU primitives for vEL2 VCPU state

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall When running a nested hypervisor we commonly have to figure out if the VCPU mode is running in the context of a guest hypervisor or guest guest, or just a normal guest. Add convenient primitives for this. Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier ---

[PATCH v2 01/94] KVM: arm64: Move __load_guest_stage2 to kvm_mmu.h

2020-02-11 Thread Marc Zyngier
Having __load_guest_stage2 in kvm_hyp.h is quickly going to trigger a circular include problem. In order to avoid this, let's move it to kvm_mmu.h, where it will be a better fit anyway. In the process, drop the __hyp_text annotation, which doesn't help as the function is marked as __always_inline.

[PATCH v2 47/94] KVM: arm64: nv: Handle traps for timer _EL02 and _EL2 sysregs accessors

2020-02-11 Thread Marc Zyngier
From: Andre Przywara Add trap handlers for the timer system registers accessed from a guest hypervisors using either _EL02 or _EL2 system register access instructions. Signed-off-by: Andre Przywara Signed-off-by: Jintack Lim Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/sysreg.h |

[PATCH v2 42/94] KVM: arm64: nv: Introduce sys_reg_desc.forward_trap

2020-02-11 Thread Marc Zyngier
From: Jintack Lim This introduces a function prototype to determine if we need to forward system instruction traps to the virtual EL2. The implementation of forward_trap functions for each system instruction will be added in later patches. Signed-off-by: Jintack Lim Signed-off-by: Marc Zyngier

[PATCH v2 23/94] KVM: arm64: nv: Respect virtual HCR_EL2.TWX setting

2020-02-11 Thread Marc Zyngier
From: Jintack Lim Forward exceptions due to WFI or WFE instructions to the virtual EL2 if they are not coming from the virtual EL2 and virtual HCR_EL2.TWX is set. Signed-off-by: Jintack Lim Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_nested.h | 2 ++ arch/arm64/kvm/Makefile

[PATCH v2 49/94] KVM: arm64: nv: Propagate CNTVOFF_EL2 to the virtual EL1 timer

2020-02-11 Thread Marc Zyngier
We need to allow a guest hypervisor to virtualize the virtual timer. FOr that, let's propagate CNTVOFF_EL2 to the guest's view of that timer. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 1 - arch/arm64/kvm/sys_regs.c | 7 ++- include/kvm/arm_arch_timer.h

[PATCH v2 79/94] KVM: arm64: nv: Move nested vgic state into the sysreg file

2020-02-11 Thread Marc Zyngier
The vgic nested state needs to be accessible from the VNCR page, and thus needs to be part of the normal sysreg file. Let's move it there. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 9 +++ arch/arm64/kvm/sys_regs.c | 53 -- include/kvm/arm_vgic

[PATCH v2 81/94] KVM: arm64: Add VNCR-capable timer accessors for arm64

2020-02-11 Thread Marc Zyngier
As promissed, we now add an arm64-specific set of timer accessors, which in some cases access the VNCR page instead of the struct timer fields. This requires moving the initialisation of the timer struct so that some of the helpers (such as arch_timer_ctx_index) can work correctly at an early stag

[PATCH v2 63/94] arm64: KVM: nv: Add handling of ARMv8.4-TTL TLB invalidation

2020-02-11 Thread Marc Zyngier
Support guest-provided information information to find out about the range of required invalidation. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_nested.h | 1 + arch/arm64/kvm/nested.c | 56 arch/arm64/kvm/sys_regs.c | 79 +++

[PATCH v2 40/94] KVM: arm64: nv: Unmap/flush shadow stage 2 page tables

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Unmap/flush shadow stage 2 page tables for the nested VMs as well as the stage 2 page table for the guest hypervisor. Note: A bunch of the code in mmu.c relating to MMU notifiers is currently dealt with in an extremely abrupt way, for example by clearing out an entire shad

[PATCH v2 37/94] KVM: arm64: nv: Support multiple nested Stage-2 mmu structures

2020-02-11 Thread Marc Zyngier
Add Stage-2 mmu data structures for virtual EL2 and for nested guests. We don't yet populate shadow Stage-2 page tables, but we now have a framework for getting to a shadow Stage-2 pgd. We allocate twice the number of vcpus as Stage-2 mmu structures because that's sufficient for each vcpu running

[PATCH v2 39/94] KVM: arm64: nv: Handle shadow stage 2 page faults

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall If we are faulting on a shadow stage 2 translation, we first walk the guest hypervisor's stage 2 page table to see if it has a mapping. If not, we inject a stage 2 page fault to the virtual EL2. Otherwise, we create a mapping in the shadow stage 2 page table. Note that we

[PATCH v2 80/94] KVM: arm64: Use accessors for timer ctl/cval/offset

2020-02-11 Thread Marc Zyngier
Instead of directly accessing the various fields in the timer data structures, add accessors that provide the same service. By making the weak, we'll be able to override them in a subsequent patch, making it possible to move them in the VNCR page, as they will be directly accessed by the guest. Si

[PATCH v2 51/94] KVM: arm64: nv: vgic-v3: Take cpu_if pointer directly instead of vcpu

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall If we move the used_lrs field to the version-specific cpu interface structure, the following functions only operate on the struct vgic_v3_cpu_if and not the full vcpu: __vgic_v3_save_state __vgic_v3_restore_state __vgic_v3_activate_traps __vgic_v3_deactivate_traps

[PATCH v2 26/94] KVM: arm64: nv: Respect virtual HCR_EL2.TVM and TRVM settings

2020-02-11 Thread Marc Zyngier
From: Jintack Lim Forward the EL1 virtual memory register traps to the virtual EL2 if they are not coming from the virtual EL2 and the virtual HCR_EL2.TVM or TRVM bit is set. This is for recursive nested virtualization. Signed-off-by: Jintack Lim Signed-off-by: Marc Zyngier --- arch/arm64/kv

[PATCH v2 58/94] arm64: KVM: nv: Honor SCTLR_EL2.SPAN on entering vEL2

2020-02-11 Thread Marc Zyngier
On entering vEL2, we must honor the SCTLR_EL2.SPAN bit so that PSTATE.PAN reflect the expected setting. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/emulate-nested.c | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/k

[PATCH v2 64/94] arm64: KVM: nv: Invalidate TLBs based on shadow S2 TTL-like information

2020-02-11 Thread Marc Zyngier
In order to be able to make S2 TLB invalidations more performant on NV, let's use a scheme derived from the ARMv8.4 TTL extension. If bits [56:55] in the descriptor are non-zero, they indicate a level which can be used as an invalidation range. Signed-off-by: Marc Zyngier --- arch/arm64/include

[PATCH v2 92/94] KVM: arm64: nv: Enable ARMv8.4-NV support

2020-02-11 Thread Marc Zyngier
As all the VNCR-capable system registers are nicely separated from the rest of the crowd, let's set HCR_EL2.NV2 on and let the ball rolling. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_emulate.h | 23 +-- arch/arm64/

[PATCH v2 66/94] arm64: Add SW reserved PTE/PMD bits

2020-02-11 Thread Marc Zyngier
Advertise bits [58:55] as reserved for SW in the S2 descriptors. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/pgtable-hwdef.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 6bf5e650da78..7eab0

[PATCH v2 90/94] KVM: arm64: nv: Sync nested timer state with ARMv8.4

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Emulating the ARMv8.4-NV timers is a bit odd, as the timers can be reconfigured behind our back without the hypervisor even noticing. In the VHE case, that's an actual regression in the architecture... Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- incl

[PATCH v2 84/94] KVM: arm64: VNCR-ize SP_EL1

2020-02-11 Thread Marc Zyngier
SP_EL1 being a VNCR-capable register, let's flag it as such, and repaint all the accesses Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 3 +-- arch/arm64/kvm/guest.c| 2 +- arch/arm64/kvm/hyp/sysreg-sr.c| 4 ++-- arch/arm64/kvm/sys_regs.c | 5 ++---

[PATCH v2 55/94] KVM: arm64: nv: Implement maintenance interrupt forwarding

2020-02-11 Thread Marc Zyngier
When we take a maintenance interrupt, we need to decide whether it is generated on an action from the guest, or if it is something that needs to be forwarded to the guest hypervisor. Signed-off-by: Marc Zyngier --- virt/kvm/arm/vgic/vgic-init.c | 30 ++ virt/kvm/

[PATCH v2 88/94] KVM: arm64: Add ARMv8.4 Enhanced Nested Virt cpufeature

2020-02-11 Thread Marc Zyngier
Add the detection code for the ARMv8.4-NV feature. Signed-off-by: Marc Zyngier --- arch/arm/include/asm/kvm_nested.h | 1 + arch/arm64/include/asm/cpucaps.h| 3 ++- arch/arm64/include/asm/kvm_nested.h | 6 ++ arch/arm64/kernel/cpufeature.c | 10 ++ 4 files changed, 19 i

[PATCH v2 33/94] KVM: arm64: nv: Hide RAS from nested guests

2020-02-11 Thread Marc Zyngier
We don't want to expose complicated features to guests until we have a good grasp on the basic CPU emulation. So let's pretend that RAS, doesn't exist in a nested guest. We already hide the feature bits, let's now make sure VDISR_EL1 will UNDEF. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys

[PATCH v2 27/94] KVM: arm64: nv: Respect the virtual HCR_EL2.NV1 bit setting

2020-02-11 Thread Marc Zyngier
From: Jintack Lim Forward ELR_EL1, SPSR_EL1 and VBAR_EL1 traps to the virtual EL2 if the virtual HCR_EL2.NV bit is set. This is for recursive nested virtualization. Signed-off-by: Jintack Lim Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/kvm/sys_regs.c

[PATCH v2 38/94] KVM: arm64: nv: Implement nested Stage-2 page table walk logic

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Based on the pseudo-code in the ARM ARM, implement a stage 2 software page table walker. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim [maz: heavily reworked for future ARMv8.4-TTL support] Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/esr.h

[PATCH v2 43/94] KVM: arm64: nv: Set a handler for the system instruction traps

2020-02-11 Thread Marc Zyngier
From: Jintack Lim When HCR.NV bit is set, execution of the EL2 translation regime address aranslation instructions and TLB maintenance instructions are trapped to EL2. In addition, execution of the EL1 translation regime address aranslation instructions and TLB maintenance instructions that are o

[PATCH v2 65/94] arm64: KVM: nv: Tag shadow S2 entries with nested level

2020-02-11 Thread Marc Zyngier
Populate bits [56:55] of the leaf entry with the level provided by the guest's S2 translation. Signed-off-by: Marc Zyngier --- arch/arm/include/asm/kvm_mmu.h | 5 + arch/arm64/include/asm/kvm_nested.h | 6 ++ virt/kvm/arm/mmu.c | 20 3 files c

[PATCH v2 70/94] arm64: KVM: nv: Add include containing the VNCR_EL2 offsets

2020-02-11 Thread Marc Zyngier
VNCR_EL2 points to a page containing a number of system registers accessed by a guest hypervisor when ARMv8.4-NV is enabled. Let's document the offsets in that page, as we are going to use this layout. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/vncr_mapping.h | 73 ++

[PATCH v2 52/94] KVM: arm64: nv: Nested GICv3 Support

2020-02-11 Thread Marc Zyngier
From: Jintack Lim When entering a nested VM, we set up the hypervisor control interface based on what the guest hypervisor has set. Especially, we investigate each list register written by the guest hypervisor whether HW bit is set. If so, we translate hw irq number from the guest's point of vie

[PATCH v2 57/94] arm64: KVM: nv: Add handling of EL2-specific timer registers

2020-02-11 Thread Marc Zyngier
Add the required handling for EL2 and EL02 registers, as well as EL1 registers used in the E2H context. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 72 +++ 1 file changed, 72 insertions(+) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kv

[PATCH v2 46/94] KVM: arm64: nv: Fold guest's HCR_EL2 configuration into the host's

2020-02-11 Thread Marc Zyngier
When entering a L2 guest (nested virt enabled, but not in hypervisor context), we need to honor the traps the L1 guest has asked enabled. For now, just OR the guest's HCR_EL2 into the host's. We may have to do some filtering in the future though. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/h

[PATCH v2 77/94] KVM: arm64: nv: Move sysreg reset check to boot time

2020-02-11 Thread Marc Zyngier
Our sysreg reset check has become a bit silly, as it only checks whether a reset callback actually exists for a given sysreg entry, and apply the method if available. Doing the check at each vcpu reset is pretty dumb, as the tables never change. It is thus perfectly possible to do the same checks a

[PATCH v2 82/94] KVM: arm64: Make struct kvm_regs userspace-only

2020-02-11 Thread Marc Zyngier
struct kvm_regs is used by userspace to indicate which register gets accessed by the {GET,SET}_ONE_REG API. But as we're about to refactor the layout of the in-kernel register structures, we need the kernel to move away from it. Let's make kvm_regs userspace only, and let the kernel map it to its

[PATCH v2 12/94] KVM: arm64: nv: Add EL2->EL1 translation helpers

2020-02-11 Thread Marc Zyngier
Some EL2 system registers immediately affect the current execution of the system, so we need to use their respective EL1 counterparts. For this we need to define a mapping between the two. These helpers will get used in subsequent patches. Co-developed-by: Andre Przywara Signed-off-by: Andre Prz

[PATCH v2 50/94] KVM: arm64: nv: Load timer before the GIC

2020-02-11 Thread Marc Zyngier
In order for vgic_v3_load_nested to be able to observe which timer interrupts have the HW bit set for the current context, the timers must have been loaded in the new mode and the right timer mapped to their corresponding HW IRQs. At the moment, we load the GIC first, meaning that timer interrupts

[PATCH v2 48/94] KVM: arm64: nv: arch_timer: Support hyp timer emulation

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Emulating EL2 also means emulating the EL2 timers. To do so, we expand our timer framework to deal with at most 4 timers. At any given time, two timers are using the HW timers, and the two others are purely emulated. The role of deciding which is which at any given time is

[PATCH v2 18/94] KVM: arm64: nv: Emulate PSTATE.M for a guest hypervisor

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall We can no longer blindly copy the VCPU's PSTATE into SPSR_EL2 and return to the guest and vice versa when taking an exception to the hypervisor, because we emulate virtual EL2 in EL1 and therefore have to translate the mode field from EL2 to EL1 and vice versa. Signed-off-

[PATCH v2 93/94] KVM: arm64: nv: Fast-track 'InHost' exception returns

2020-02-11 Thread Marc Zyngier
A significant part of the ARMv8.3-NV extension is to trap ERET instructions so that the hypervisor gets a chance to switch from a vEL2 L1 guest to an EL1 L2 guest. But this also has the unfortunate consequence of trapping ERET in unsuspecting circumstances, such as staying at vEL2 (interrupt handl

[PATCH v2 25/94] KVM: arm64: nv: Respect the virtual HCR_EL2.NV bit setting

2020-02-11 Thread Marc Zyngier
From: Jintack Lim Forward traps due to HCR_EL2.NV bit to the virtual EL2 if they are not coming from the virtual EL2 and the virtual HCR_EL2.NV bit is set. In addition to EL2 register accesses, setting NV bit will also make EL12 register accesses trap to EL2. To emulate this for the virtual EL2,

[PATCH v2 32/94] KVM: arm64: nv: Filter out unsupported features from ID regs

2020-02-11 Thread Marc Zyngier
As there is a number of features that we either can't support, or don't want to support right away with NV, let's add some basic filtering so that we don't advertize silly things to the EL2 guest. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_nested.h | 6 ++ arch/arm64/include/as

[PATCH v2 34/94] KVM: arm64: nv: Use ARMv8.5-GTG to advertise supported Stage-2 page sizes

2020-02-11 Thread Marc Zyngier
ARMv8.5-GTG gives the opportunity to advertize the supported Stage-2 page sizes to hypervisors, and allow them to differ from the page sizes supported at Stage-1. As KVM cannot support guest Stage-2 page sizes that are smaller than PAGE_SIZE (it would break the guest's isolation guarantees), let's

[PATCH v2 36/94] KVM: arm/arm64: nv: Factor out stage 2 page table data from struct kvm

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall As we are about to reuse our stage 2 page table manipulation code for shadow stage 2 page tables in the context of nested virtualization, we are going to manage multiple stage 2 page tables for a single VM. This requires some pretty invasive changes to our data structures,

[PATCH v2 89/94] KVM: arm64: nv: Synchronize PSTATE early on exit

2020-02-11 Thread Marc Zyngier
The NV code relies on predicates such as is_hyp_ctxt() being reliable. In turn, is_hyp_ctxt() relies on things like PSTATE and the virtual HCR_EL2 being accurate. But with ARMv8.4-NV removing trapping for a large part of the EL2 system registers (among which HCR_EL2), we can't use such trapping to

[PATCH v2 22/94] KVM: arm64: nv: Handle PSCI call via smc from the guest

2020-02-11 Thread Marc Zyngier
From: Jintack Lim VMs used to execute hvc #0 for the psci call if EL3 is not implemented. However, when we come to provide the virtual EL2 mode to the VM, the host OS inside the VM calls kvm_call_hyp() which is also hvc #0. So, it's hard to differentiate between them from the host hypervisor's po

[PATCH v2 11/94] KVM: arm64: nv: Handle trapped ERET from virtual EL2

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall When a guest hypervisor running virtual EL2 in EL1 executes an ERET instruction, we will have set HCR_EL2.NV which traps ERET to EL2, so that we can emulate the exception return in software. Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/incl

[PATCH v2 75/94] KVM: arm64: debug: Use ctxt_sys_reg() instead of raw sys_regs access

2020-02-11 Thread Marc Zyngier
Now that we have a wrapper for the sysreg accesses, let's use that consistently. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/debug-sr.c | 18 -- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c ind

[PATCH v2 14/94] KVM: arm64: nv: Handle virtual EL2 registers in vcpu_read/write_sys_reg()

2020-02-11 Thread Marc Zyngier
KVM internally uses accessor functions when reading or writing the guest's system registers. This takes care of accessing either the stored copy or using the "live" EL1 system registers when the host uses VHE. With the introduction of virtual EL2 we add a bunch of EL2 system registers, which now m

[PATCH v2 73/94] KVM: arm64: sve: Use __vcpu_sys_reg() instead of raw sys_regs access

2020-02-11 Thread Marc Zyngier
Now that we have a wrapper for the sysreg accesses, let's use that consistently. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/fpsimd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c index 525010504f9d..738ee805aa3c 10064

[PATCH v2 30/94] KVM: arm64: nv: Configure HCR_EL2 for nested virtualization

2020-02-11 Thread Marc Zyngier
From: Jintack Lim We enable nested virtualization by setting the HCR NV and NV1 bit. When the virtual E2H bit is set, we can support EL2 register accesses via EL1 registers from the virtual EL2 by doing trap-and-emulate. A better alternative, however, is to allow the virtual EL2 to access EL2 re

[PATCH v2 35/94] KVM: arm64: Check advertised Stage-2 page size capability

2020-02-11 Thread Marc Zyngier
With ARMv8.5-GTG, the hardware (or more likely a hypervisor) can advertise the supported Stage-2 page sizes. Let's check this at boot time. Signed-off-by: Marc Zyngier --- arch/arm/include/asm/kvm_mmu.h| 2 +- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kernel/cpufeature.c|

[PATCH v2 85/94] KVM: arm64: Disintegrate SPSR array

2020-02-11 Thread Marc Zyngier
As we're about to move SPSR_EL1 into the VNCR page, we need to disassociate it from the rest of the 32bit cruft. Let's break the array into individual fields. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_emulate.h | 4 ++-- arch/arm64/include/asm/kvm_host.h| 6 - arch/arm

[PATCH v2 29/94] KVM: arm64: nv: Forward debug traps to the nested guest

2020-02-11 Thread Marc Zyngier
On handling a debug trap, check whether we need to forward it to the guest before handling it. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_nested.h | 2 ++ arch/arm64/kvm/emulate-nested.c | 9 +++-- arch/arm64/kvm/sys_regs.c | 3 +++ 3 files changed, 12 insertion

[PATCH v2 71/94] KVM: arm64: Introduce accessor for ctxt->sys_reg

2020-02-11 Thread Marc Zyngier
In order to allow the disintegration of the per-vcpu sysreg array, let's introduce a new helper (ctxt_sys_reg()) that returns the in-memory copy of a system register, picked from a given context. __vcpu_sys_reg() is rewritten to use this helper. Signed-off-by: Marc Zyngier --- arch/arm64/includ

[PATCH v2 19/94] KVM: arm64: nv: Trap EL1 VM register accesses in virtual EL2

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall When running in virtual EL2 mode, we actually run the hardware in EL1 and therefore have to use the EL1 registers to ensure correct operation. By setting the HCR.TVM and HCR.TVRM we ensure that the virtual EL2 mode doesn't shoot itself in the foot when setting up what it b

[PATCH v2 72/94] KVM: arm64: sysreg: Use ctxt_sys_reg() instead of raw sys_regs access

2020-02-11 Thread Marc Zyngier
Now that we have a wrapper for the sysreg accesses, let's use that consistently. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_emulate.h | 6 +- arch/arm64/include/asm/kvm_host.h| 2 +- arch/arm64/kvm/hyp/at.c | 30 ++--- arch/arm64/kvm/hyp/switch.c |

[PATCH v2 15/94] KVM: arm64: nv: Handle SPSR_EL2 specially

2020-02-11 Thread Marc Zyngier
SPSR_EL2 needs special attention when running nested on ARMv8.3: If taking an exception while running at vEL2 (actually EL1), the HW will update the SPSR_EL1 register with the EL1 mode. We need to track this in order to make sure that accesses to the virtual view of SPSR_EL2 is correct. To do so,

[PATCH v2 59/94] arm64: KVM: nv: Handle SCTLR_EL2 RES0/RES1 bits

2020-02-11 Thread Marc Zyngier
Depending on the HCR_EL2.{E2H,TGE} values, SCTLR_EL2 has different RES0/RES1 constraints. Let's handle that. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 33 - 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c

[PATCH v2 69/94] arm64: KVM: Use TTL hint in when invalidating stage-2 translations

2020-02-11 Thread Marc Zyngier
Since we always have a precide idea of the level we're dealing with when invalidating TLBs, we can provide it to as a hint to our invalidation helper. Signed-off-by: Marc Zyngier --- arch/arm/include/asm/stage2_pgtable.h | 9 + arch/arm64/include/asm/stage2_pgtable.h | 9 + v

[PATCH v2 61/94] arm64: KVM: nv: Allow userspace to request KVM_ARM_VCPU_NESTED_VIRT

2020-02-11 Thread Marc Zyngier
Since we're (almost) feature complete, let's allow userspace to request KVM_ARM_VCPU_NESTED_VIRT by bumping the KVM_VCPU_MAX_FEATURES up. It's going to be great... Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git

[PATCH v2 45/94] KVM: arm64: nv: Trap and emulate TLBI instructions from virtual EL2

2020-02-11 Thread Marc Zyngier
From: Jintack Lim When supporting nested virtualization a guest hypervisor executing TLBI instructions must be trapped and emulated by the host hypervisor, because the guest hypervisor can only affect physical TLB entries relating to its own execution environment (virtual EL2 in EL1) but not to t

[PATCH v2 74/94] KVM: arm64: pauth: Use ctxt_sys_reg() instead of raw sys_regs access

2020-02-11 Thread Marc Zyngier
Now that we have a wrapper for the sysreg accesses, let's use that consistently. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/handle_exit.c | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 10

[PATCH v2 31/94] KVM: arm64: nv: Only toggle cache for virtual EL2 when SCTLR_EL2 changes

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall So far we were flushing almost the entire universe whenever a VM would load/unload the SCTLR_EL1 and the two versions of that register had different MMU enabled settings. This turned out to be so slow that it prevented forward progress for a nested VM, because a scheduler

[PATCH v2 67/94] arm64: Add level-hinted TLB invalidation helper

2020-02-11 Thread Marc Zyngier
Add a level-hinted TLB invalidation helper that only gets used if ARMv8.4-TTL gets detected. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/tlbflush.h | 30 ++ 1 file changed, 30 insertions(+) diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/inclu

[PATCH v2 91/94] KVM: arm64: nv: Allocate VNCR page when required

2020-02-11 Thread Marc Zyngier
If running a NV guest on an ARMv8.4-NV capable system, let's allocate an additional page that will be used by the hypervisor to fulfill system register accesses. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_host.h | 3 ++- arch/arm64/kvm/nested.c | 8 arch/arm64/

[PATCH v2 56/94] KVM: arm64: nv: Add nested GICv3 tracepoints

2020-02-11 Thread Marc Zyngier
From: Christoffer Dall Adding tracepoints to be able to peek into the shadow LRs used when running a guest guest. Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- virt/kvm/arm/vgic/vgic-nested-trace.h | 137 ++ virt/kvm/arm/vgic/vgic-v3-nested.c| 13

[PATCH v2 10/94] KVM: arm64: nv: Inject HVC exceptions to the virtual EL2

2020-02-11 Thread Marc Zyngier
From: Jintack Lim As we expect all PSCI calls from the L1 hypervisor to be performed using SMC when nested virtualization is enabled, it is clear that all HVC instruction from the VM (including from the virtual EL2) are supposed to handled in the virtual EL2. Forward these to EL2 as required. S

  1   2   >