Re: [RFC v2 11/12] KVM: arm/arm64: Implement KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION

2018-03-28 Thread Auger Eric
Hi Peter, On 28/03/18 20:55, Peter Maydell wrote: > On 27 March 2018 at 15:04, Eric Auger wrote: >> Now all the internals are ready to handle multiple redistributor >> regions, let's allow the userspace to register them. >> >> Signed-off-by: Eric Auger >> --- >> virt/kvm/arm/vgic/vgic-kvm-devic

Re: [GIT PULL] KVM/ARM updates for v4.17

2018-03-28 Thread Radim Krčmář
2018-03-28 13:51+0100, Marc Zyngier: > Paolo, Radim, > > This is the (rather big) set of updates for KVM/ARM for v4.17. The > main features are the set of VHE optimizations taking advantage of > CPUs implementing ARMv8.1, together with the EL2 randomization patches > that are the foundation for mi

Re: [RFC v2 11/12] KVM: arm/arm64: Implement KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION

2018-03-28 Thread Peter Maydell
On 27 March 2018 at 15:04, Eric Auger wrote: > Now all the internals are ready to handle multiple redistributor > regions, let's allow the userspace to register them. > > Signed-off-by: Eric Auger > --- > virt/kvm/arm/vgic/vgic-kvm-device.c | 40 > +++-- > virt/k

Re: [PATCH v2 08/11] firmware: arm_sdei: Add ACPI GHES registration helper

2018-03-28 Thread James Morse
Hi kbuild test robot, On 25/03/18 02:41, kbuild test robot wrote: > I love your patch! Yet something to improve: > > [auto build test ERROR on pm/linux-next] > [also build test ERROR on v4.16-rc6] > [cannot apply to arm64/for-next/core next-20180323] This is the potential conflict I referred to

Re: [PATCH 02/11] ACPI / APEI: Generalise the estatus queue's add/remove and notify code

2018-03-28 Thread James Morse
Hi Borislav, On 27/03/18 18:25, Borislav Petkov wrote: > On Mon, Mar 19, 2018 at 02:29:13PM +, James Morse wrote: >> I don't think the die_lock really helps here, do we really want to wait for a >> remote CPU to finish printing an OOPs about user-space's bad memory accesses, >> before we bring

Re: [PATCH v2 05/11] arm64: KVM/mm: Move SEA handling behind a single 'claim' interface

2018-03-28 Thread James Morse
Hi Marc, On 26/03/18 18:49, Marc Zyngier wrote: > On 22/03/18 18:14, James Morse wrote: >> To ensure APEI always takes the same locks when processing a notification >> we need the nmi-like callers to always call APEI in_nmi(). Add a helper >> to do the work and claim the notification. >> >> When K

[PATCH 85/85] arm64: Add temporary ERRATA_MIDR_ALL_VERSIONS compatibility macro

2018-03-28 Thread Marc Zyngier
MIDR_ALL_VERSIONS is changing, and won't have the same meaning in 4.17, and the right thing to use will be ERRATA_MIDR_ALL_VERSIONS. In order to cope with the merge window, let's add a compatibility macro that will allow a relatively smooth transition, and that can be removed post 4.17-rc1. Signe

[PATCH 84/85] Revert "arm64: KVM: Use SMCCC_ARCH_WORKAROUND_1 for Falkor BP hardening"

2018-03-28 Thread Marc Zyngier
Creates far too many conflicts with arm64/for-next/core, to be resent post -rc1. This reverts commit f9f5dc19509bbef6f5e675346f1a7d7b846bdb12. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/cpucaps.h | 2 +- arch/arm64/include/asm/kvm_asm.h | 2 ++ arch/arm64/kernel/bpi.S |

[PATCH 83/85] KVM: arm/arm64: vgic-its: Fix potential overrun in vgic_copy_lpi_list

2018-03-28 Thread Marc Zyngier
vgic_copy_lpi_list() parses the LPI list and picks LPIs targeting a given vcpu. We allocate the array containing the intids before taking the lpi_list_lock, which means we can have an array size that is not equal to the number of LPIs. This is particularly obvious when looking at the path coming f

[PATCH 81/85] arm64: KVM: Use SMCCC_ARCH_WORKAROUND_1 for Falkor BP hardening

2018-03-28 Thread Marc Zyngier
From: Shanker Donthineni The function SMCCC_ARCH_WORKAROUND_1 was introduced as part of SMC V1.1 Calling Convention to mitigate CVE-2017-5715. This patch uses the standard call SMCCC_ARCH_WORKAROUND_1 for Falkor chips instead of Silicon provider service ID 0xC2001700. Cc: # 4.14+ Signed-off-by:

[PATCH 82/85] KVM: arm/arm64: vgic: Disallow Active+Pending for level interrupts

2018-03-28 Thread Marc Zyngier
It was recently reported that VFIO mediated devices, and anything that VFIO exposes as level interrupts, do no strictly follow the expected logic of such interrupts as it only lowers the input line when the guest has EOId the interrupt at the GIC level, rather than when it Acked the interrupt at th

[PATCH 80/85] KVM: arm: Reserve bit in KVM_REG_ARM encoding for secure/nonsecure

2018-03-28 Thread Marc Zyngier
From: Peter Maydell We have a KVM_REG_ARM encoding that we use to expose KVM guest registers to userspace. Define that bit 28 in this encoding indicates secure vs nonsecure, so we can distinguish the secure and nonsecure banked versions of a banked AArch32 register. For KVM currently, all guest

[PATCH 79/85] arm64: Enable ARM64_HARDEN_EL2_VECTORS on Cortex-A57 and A72

2018-03-28 Thread Marc Zyngier
Cortex-A57 and A72 are vulnerable to the so-called "variant 3a" of Meltdown, where an attacker can speculatively obtain the value of a privileged system register. By enabling ARM64_HARDEN_EL2_VECTORS on these CPUs, obtaining VBAR_EL2 is not disclosing the hypervisor mappings anymore. Acked-by: Ca

[PATCH 77/85] arm64: Make BP hardening slot counter available

2018-03-28 Thread Marc Zyngier
We're about to need to allocate hardening slots from other parts of the kernel (in order to support ARM64_HARDEN_EL2_VECTORS). Turn the counter into an atomic_t and make it available to the rest of the kernel. Also add BP_HARDEN_EL2_SLOTS as the number of slots instead of the hardcoded 4... Acked

[PATCH 78/85] arm64: KVM: Allow mapping of vectors outside of the RAM region

2018-03-28 Thread Marc Zyngier
We're now ready to map our vectors in weird and wonderful locations. On enabling ARM64_HARDEN_EL2_VECTORS, a vector slot gets allocated if this hasn't been already done via ARM64_HARDEN_BRANCH_PREDICTOR and gets mapped outside of the normal RAM region, next to the idmap. That way, being able to ob

[PATCH 75/85] arm64: KVM: Allow far branches from vector slots to the main vectors

2018-03-28 Thread Marc Zyngier
So far, the branch from the vector slots to the main vectors can at most be 4GB from the main vectors (the reach of ADRP), and this distance is known at compile time. If we were to remap the slots to an unrelated VA, things would break badly. A way to achieve VA independence would be to load the a

[PATCH 76/85] arm/arm64: KVM: Introduce EL2-specific executable mappings

2018-03-28 Thread Marc Zyngier
Until now, all EL2 executable mappings were derived from their EL1 VA. Since we want to decouple the vectors mapping from the rest of the hypervisor, we need to be able to map some text somewhere else. The "idmap" region (for lack of a better name) is ideally suited for this, as we have a huge ran

[PATCH 74/85] arm64: KVM: Reserve 4 additional instructions in the BPI template

2018-03-28 Thread Marc Zyngier
So far, we only reserve a single instruction in the BPI template in order to branch to the vectors. As we're going to stuff a few more instructions there, let's reserve a total of 5 instructions, which we're going to patch later on as required. We also introduce a small refactor of the vectors the

[PATCH 72/85] arm64: KVM: Move stashing of x0/x1 into the vector code itself

2018-03-28 Thread Marc Zyngier
All our useful entry points into the hypervisor are starting by saving x0 and x1 on the stack. Let's move those into the vectors by introducing macros that annotate whether a vector is valid or not, thus indicating whether we want to stash registers or not. The only drawback is that we now also st

[PATCH 73/85] arm64: KVM: Move BP hardening vectors into .hyp.text section

2018-03-28 Thread Marc Zyngier
There is no reason why the BP hardening vectors shouldn't be part of the HYP text at compile time, rather than being mapped at runtime. Also introduce a new config symbol that controls the compilation of bpi.S. Acked-by: Catalin Marinas Reviewed-by: Andrew Jones Signed-off-by: Marc Zyngier ---

[PATCH 71/85] arm64: KVM: Move vector offsetting from hyp-init.S to kvm_get_hyp_vector

2018-03-28 Thread Marc Zyngier
We currently provide the hyp-init code with a kernel VA, and expect it to turn it into a HYP va by itself. As we're about to provide the hypervisor with mappings that are not necessarily in the memory range, let's move the kern_hyp_va macro to kvm_get_hyp_vector. No functionnal change. Acked-by:

[PATCH 69/85] arm64: KVM: Introduce EL2 VA randomisation

2018-03-28 Thread Marc Zyngier
The main idea behind randomising the EL2 VA is that we usually have a few spare bits between the most significant bit of the VA mask and the most significant bit of the linear mapping. Those bits could be a bunch of zeroes, and could be useful to move things around a bit. Of course, the more memor

[PATCH 70/85] arm64: Update the KVM memory map documentation

2018-03-28 Thread Marc Zyngier
Update the documentation to reflect the new tricks we play on the EL2 mappings... Acked-by: Christoffer Dall Acked-by: Catalin Marinas Signed-off-by: Marc Zyngier --- Documentation/arm64/memory.txt | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/arm64/

[PATCH 68/85] arm64: KVM: Dynamically compute the HYP VA mask

2018-03-28 Thread Marc Zyngier
As we're moving towards a much more dynamic way to compute our HYP VA, let's express the mask in a slightly different way. Instead of comparing the idmap position to the "low" VA mask, we directly compute the mask by taking into account the idmap's (VA_BIT-1) bit. No functionnal change. Acked-by

[PATCH 67/85] arm64: insn: Allow ADD/SUB (immediate) with LSL #12

2018-03-28 Thread Marc Zyngier
The encoder for ADD/SUB (immediate) can only cope with 12bit immediates, while there is an encoding for a 12bit immediate shifted by 12 bits to the left. Let's fix this small oversight by allowing the LSL_12 bit to be set. Reviewed-by: Christoffer Dall Acked-by: Catalin Marinas Signed-off-by: M

[PATCH 65/85] KVM: arm/arm64: Move HYP IO VAs to the "idmap" range

2018-03-28 Thread Marc Zyngier
We so far mapped our HYP IO (which is essentially the GICv2 control registers) using the same method as for memory. It recently appeared that is a bit unsafe: We compute the HYP VA using the kern_hyp_va helper, but that helper is only designed to deal with kernel VAs coming from the linear map, an

[PATCH 64/85] KVM: arm64: Fix HYP idmap unmap when using 52bit PA

2018-03-28 Thread Marc Zyngier
Unmapping the idmap range using 52bit PA is quite broken, as we don't take into account the right number of PGD entries, and rely on PTRS_PER_PGD. The result is that pgd_index() truncates the address, and we end-up in the weed. Let's introduce a new unmap_hyp_idmap_range() that knows about this, t

[PATCH 63/85] KVM: arm/arm64: Fix idmap size and alignment

2018-03-28 Thread Marc Zyngier
Although the idmap section of KVM can only be at most 4kB and must be aligned on a 4kB boundary, the rest of the code expects it to be page aligned. Things get messy when tearing down the HYP page tables when PAGE_SIZE is 64K, and the idmap section isn't 64K aligned. Let's fix this by computing al

[PATCH 66/85] arm64; insn: Add encoder for the EXTR instruction

2018-03-28 Thread Marc Zyngier
Add an encoder for the EXTR instruction, which also implements the ROR variant (where Rn == Rm). Acked-by: Catalin Marinas Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/insn.h | 6 ++ arch/arm64/kernel/insn.c | 32 +++

[PATCH 62/85] KVM: arm/arm64: Keep GICv2 HYP VAs in kvm_vgic_global_state

2018-03-28 Thread Marc Zyngier
As we're about to change the way we map devices at HYP, we need to move away from kern_hyp_va on an IO address. One way of achieving this is to store the VAs in kvm_vgic_global_state, and use that directly from the HYP code. This requires a small change to create_hyp_io_mappings so that it can als

[PATCH 61/85] KVM: arm/arm64: Move ioremap calls to create_hyp_io_mappings

2018-03-28 Thread Marc Zyngier
Both HYP io mappings call ioremap, followed by create_hyp_io_mappings. Let's move the ioremap call into create_hyp_io_mappings itself, which simplifies the code a bit and allows for further refactoring. Reviewed-by: Christoffer Dall Acked-by: Catalin Marinas Signed-off-by: Marc Zyngier --- arc

[PATCH 60/85] KVM: arm/arm64: Demote HYP VA range display to being a debug feature

2018-03-28 Thread Marc Zyngier
Displaying the HYP VA information is slightly counterproductive when using VA randomization. Turn it into a debug feature only, and adjust the last displayed value to reflect the top of RAM instead of ~0. Acked-by: Christoffer Dall Acked-by: Catalin Marinas Signed-off-by: Marc Zyngier --- virt

[PATCH 59/85] KVM: arm/arm64: Do not use kern_hyp_va() with kvm_vgic_global_state

2018-03-28 Thread Marc Zyngier
kvm_vgic_global_state is part of the read-only section, and is usually accessed using a PC-relative address generation (adrp + add). It is thus useless to use kern_hyp_va() on it, and actively problematic if kern_hyp_va() becomes non-idempotent. On the other hand, there is no way that the compiler

[PATCH 58/85] arm64: cpufeatures: Drop the ARM64_HYP_OFFSET_LOW feature flag

2018-03-28 Thread Marc Zyngier
Now that we can dynamically compute the kernek/hyp VA mask, there is no need for a feature flag to trigger the alternative patching. Let's drop the flag and everything that depends on it. Acked-by: Christoffer Dall Acked-by: Catalin Marinas Reviewed-by: Suzuki K Poulose Signed-off-by: Marc Zyng

[PATCH 56/85] arm64: insn: Add encoder for bitwise operations using literals

2018-03-28 Thread Marc Zyngier
We lack a way to encode operations such as AND, ORR, EOR that take an immediate value. Doing so is quite involved, and is all about reverse engineering the decoding algorithm described in the pseudocode function DecodeBitMasks(). This has been tested by feeding it all the possible literal values a

[PATCH 57/85] arm64: KVM: Dynamically patch the kernel/hyp VA mask

2018-03-28 Thread Marc Zyngier
So far, we're using a complicated sequence of alternatives to patch the kernel/hyp VA mask on non-VHE, and NOP out the masking altogether when on VHE. The newly introduced dynamic patching gives us the opportunity to simplify that code by patching a single instruction with the correct mask (instea

[PATCH 55/85] arm64: insn: Add N immediate encoding

2018-03-28 Thread Marc Zyngier
We're missing the a way to generate the encoding of the N immediate, which is only a single bit used in a number of instruction that take an immediate. Acked-by: Christoffer Dall Reviewed-by: Catalin Marinas Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/insn.h | 1 + arch/arm64/kernel

[PATCH 54/85] arm64: alternatives: Add dynamic patching feature

2018-03-28 Thread Marc Zyngier
We've so far relied on a patching infrastructure that only gave us a single alternative, without any way to provide a range of potential replacement instructions. For a single feature, this is an all or nothing thing. It would be interesting to have a more flexible grained way of patching the kern

[PATCH 53/85] KVM: arm/arm64: Avoid VGICv3 save/restore on VHE with no IRQs

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We can finally get completely rid of any calls to the VGICv3 save/restore functions when the AP lists are empty on VHE systems. This requires carefully factoring out trap configuration from saving and restoring state, and carefully choosing what to do on the VHE and non-VH

[PATCH 52/85] KVM: arm/arm64: Move VGIC APR save/restore to vgic put/load

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall The APRs can only have bits set when the guest acknowledges an interrupt in the LR and can only have a bit cleared when the guest EOIs an interrupt in the LR. Therefore, if we have no LRs with any pending/active interrupts, the APR cannot change value and there is no need

[PATCH 50/85] KVM: arm/arm64: Move arm64-only vgic-v2-sr.c file to arm64

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall The vgic-v2-sr.c file now only contains the logic to replay unaligned accesses to the virtual CPU interface on 16K and 64K page systems, which is only relevant on 64-bit platforms. Therefore move this file to the arm64 KVM tree, remove the compile directive from the 32-bit

[PATCH 51/85] KVM: arm/arm64: Handle VGICv3 save/restore from the main VGIC code on VHE

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Just like we can program the GICv2 hypervisor control interface directly from the core vgic code, we can do the same for the GICv3 hypervisor control interface on VHE systems. We do this by simply calling the save/restore functions when we have VHE and we can then get rid

[PATCH 49/85] KVM: arm/arm64: Handle VGICv2 save/restore from the main VGIC code

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We can program the GICv2 hypervisor control interface logic directly from the core vgic code and can instead do the save/restore directly from the flush/sync functions, which can lead to a number of future optimizations. Signed-off-by: Christoffer Dall Signed-off-by: Marc

[PATCH 48/85] KVM: arm/arm64: Get rid of vgic_elrsr

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall There is really no need to store the vgic_elrsr on the VGIC data structures as the only need we have for the elrsr is to figure out if an LR is inactive when we save the VGIC state upon returning from the guest. We can might as well store this in a temporary local variable

[PATCH 46/85] KVM: arm64: Configure c15, PMU, and debug register traps on cpu load/put for VHE

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We do not have to change the c15 trap setting on each switch to/from the guest on VHE systems, because this setting only affects guest EL1/EL0 (and therefore not the VHE host). The PMU and debug trap configuration can also be done on vcpu load/put instead, because they don

[PATCH 45/85] KVM: arm64: Directly call VHE and non-VHE FPSIMD enabled functions

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall There is no longer a need for an alternative to choose the right function to tell us whether or not FPSIMD was enabled for the VM, because we can simply can the appropriate functions directly from within the _vhe and _nvhe run functions. Reviewed-by: Marc Zyngier Reviewed

[PATCH 47/85] KVM: arm64: Cleanup __activate_traps and __deactive_traps for VHE and non-VHE

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall To make the code more readable and to avoid the overhead of a function call, let's get rid of a pair of the alternative function selectors and explicitly call the VHE and non-VHE functions using the has_vhe() static key based selector instead, telling the compiler to try to

[PATCH 44/85] KVM: arm64: Move common VHE/non-VHE trap config in separate functions

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall As we are about to be more lazy with some of the trap configuration register read/writes for VHE systems, move the logic that is currently shared between VHE and non-VHE into a separate function which can be called from either the world-switch path or from vcpu_load/vcpu_pu

[PATCH 43/85] KVM: arm64: Defer saving/restoring 32-bit sysregs to vcpu load/put

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall When running a 32-bit VM (EL1 in AArch32), the AArch32 system registers can be deferred to vcpu load/put on VHE systems because neither the host kernel nor host userspace uses these registers. Note that we can't save DBGVCR32_EL2 conditionally based on the state of the deb

[PATCH 41/85] KVM: arm64: Defer saving/restoring 64-bit sysregs to vcpu load/put on VHE

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Some system registers do not affect the host kernel's execution and can therefore be loaded when we are about to run a VCPU and we don't have to restore the host state to the hardware before the time when we are actually about to return to userspace or schedule out the VCPU

[PATCH 42/85] KVM: arm64: Prepare to handle deferred save/restore of 32-bit registers

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall 32-bit registers are not used by a 64-bit host kernel and can be deferred, but we need to rework the accesses to these register to access the latest values depending on whether or not guest system registers are loaded on the CPU or only reside in memory. Reviewed-by: Marc

[PATCH 39/85] KVM: arm/arm64: Prepare to handle deferred save/restore of SPSR_EL1

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall SPSR_EL1 is not used by a VHE host kernel and can be deferred, but we need to rework the accesses to this register to access the latest value depending on whether or not guest system registers are loaded on the CPU or only reside in memory. The handling of accessing the va

[PATCH 40/85] KVM: arm64: Prepare to handle deferred save/restore of ELR_EL1

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall ELR_EL1 is not used by a VHE host kernel and can be deferred, but we need to rework the accesses to this register to access the latest value depending on whether or not guest system registers are loaded on the CPU or only reside in memory. Reviewed-by: Marc Zyngier Review

[PATCH 38/85] KVM: arm64: Introduce framework for accessing deferred sysregs

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We are about to defer saving and restoring some groups of system registers to vcpu_put and vcpu_load on supported systems. This means that we need some infrastructure to access system registes which supports either accessing the memory backing of the register or directly a

[PATCH 37/85] KVM: arm64: Rewrite system register accessors to read/write functions

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Currently we access the system registers array via the vcpu_sys_reg() macro. However, we are about to change the behavior to some times modify the register file directly, so let's change this to two primitives: * Accessor macros vcpu_write_sys_reg() and vcpu_read_sys_reg

[PATCH 36/85] KVM: arm64: Change 32-bit handling of VM system registers

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We currently handle 32-bit accesses to trapped VM system registers using the 32-bit index into the coproc array on the vcpu structure, which is a union of the coproc array and the sysreg array. Since all the 32-bit coproc indices are created to correspond to the architectu

[PATCH 35/85] KVM: arm64: Don't save the host ELR_EL2 and SPSR_EL2 on VHE systems

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall On non-VHE systems we need to save the ELR_EL2 and SPSR_EL2 so that we can return to the host in EL1 in the same state and location where we issued a hypercall to EL2, but on VHE ELR_EL2 and SPSR_EL2 are not useful because we never enter a guest as a result of an exception

[PATCH 34/85] KVM: arm64: Unify non-VHE host/guest sysreg save and restore functions

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall There is no need to have multiple identical functions with different names for saving host and guest state. When saving and restoring state for the host and guest, the state is the same for both contexts, and that's why we have the kvm_cpu_context structure. Delete one ve

[PATCH 33/85] KVM: arm/arm64: Remove leftover comment from kvm_vcpu_run_vhe

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall The comment only applied to SPE on non-VHE systems, so we simply remove it. Suggested-by: Andrew Jones Acked-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/switch.c | 4 1 file change

[PATCH 32/85] KVM: arm64: Introduce separate VHE/non-VHE sysreg save/restore functions

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall As we are about to handle system registers quite differently between VHE and non-VHE systems. In preparation for that, we need to split some of the handling functions between VHE and non-VHE functionality. For now, we simply copy the non-VHE functions, but we do change th

[PATCH 31/85] KVM: arm64: Rewrite sysreg alternatives to static keys

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall As we are about to move calls around in the sysreg save/restore logic, let's first rewrite the alternative function callers, because it is going to make the next patches much easier to read. Acked-by: Marc Zyngier Reviewed-by: Andrew Jones Signed-off-by: Christoffer Dall

[PATCH 30/85] KVM: arm64: Move userspace system registers into separate function

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall There's a semantic difference between the EL1 registers that control operation of a kernel running in EL1 and EL1 registers that only control userspace execution in EL0. Since we can defer saving/restoring the latter, move them into their own function. The ARMv8 ARM (ARM

[PATCH 29/85] KVM: arm64: Remove noop calls to timer save/restore from VHE switch

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall The VHE switch function calls __timer_enable_traps and __timer_disable_traps which don't do anything on VHE systems. Therefore, simply remove these calls from the VHE switch function and make the functions non-conditional as they are now only called from the non-VHE switch

[PATCH 28/85] KVM: arm64: Don't deactivate VM on VHE systems

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall There is no need to reset the VTTBR to zero when exiting the guest on VHE systems. VHE systems don't use stage 2 translations for the EL2&0 translation regime used by the host. Reviewed-by: Andrew Jones Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-

[PATCH 27/85] KVM: arm64: Remove kern_hyp_va() use in VHE switch function

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall VHE kernels run completely in EL2 and therefore don't have a notion of kernel and hyp addresses, they are all just kernel addresses. Therefore don't call kern_hyp_va() in the VHE switch function. Reviewed-by: Andrew Jones Reviewed-by: Marc Zyngier Signed-off-by: Christo

[PATCH 24/85] KVM: arm64: Improve debug register save/restore flow

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Instead of having multiple calls from the world switch path to the debug logic, each figuring out if the dirty bit is set and if we should save/restore the debug registers, let's just provide two hooks to the debug save/restore functionality, one for switching to the guest

[PATCH 26/85] KVM: arm64: Introduce VHE-specific kvm_vcpu_run

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall So far this is mostly (see below) a copy of the legacy non-VHE switch function, but we will start reworking these functions in separate directions to work on VHE and non-VHE in the most optimal way in later patches. The only difference after this patch between the VHE and

[PATCH 25/85] KVM: arm64: Factor out fault info population and gic workarounds

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall The current world-switch function has functionality to detect a number of cases where we need to fixup some part of the exit condition and possibly run the guest again, before having restored the host state. This includes populating missing fault info, emulating GICv2 CPU

[PATCH 23/85] KVM: arm64: Slightly improve debug save/restore functions

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall The debug save/restore functions can be improved by using the has_vhe() static key instead of the instruction alternative. Using the static key uses the same paradigm as we're going to use elsewhere, it makes the code more readable, and it generates slightly better code (n

[PATCH 21/85] KVM: arm/arm64: Introduce vcpu_el1_is_32bit

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We have numerous checks around that checks if the HCR_EL2 has the RW bit set to figure out if we're running an AArch64 or AArch32 VM. In some cases, directly checking the RW bit (given its unintuitive name), is a bit confusing, and that's not going to improve as we move lo

[PATCH 20/85] KVM: arm/arm64: Add kvm_vcpu_load_sysregs and kvm_vcpu_put_sysregs

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall As we are about to move a bunch of save/restore logic for VHE kernels to the load and put functions, we need some infrastructure to do this. Reviewed-by: Andrew Jones Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm/inclu

[PATCH 22/85] KVM: arm64: Move debug dirty flag calculation out of world switch

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall There is no need to figure out inside the world-switch if we should save/restore the debug registers or not, we might as well do that in the higher level debug setup code, making it easier to optimize down the line. Reviewed-by: Julien Thierry Reviewed-by: Marc Zyngier R

[PATCH 17/85] KVM: arm64: Rework hyp_panic for VHE and non-VHE

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall VHE actually doesn't rely on clearing the VTTBR when returning to the host kernel, and that is the current key mechanism of hyp_panic to figure out how to attempt to return to a state good enough to print a panic statement. Therefore, we split the hyp_panic function into t

[PATCH 19/85] KVM: arm/arm64: Get rid of vcpu->arch.irq_lines

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We currently have a separate read-modify-write of the HCR_EL2 on entry to the guest for the sole purpose of setting the VF and VI bits, if set. Since this is most rarely the case (only when using userspace IRQ chip and interrupts are in flight), let's get rid of this operat

[PATCH 18/85] KVM: arm64: Move HCR_INT_OVERRIDE to default HCR_EL2 guest flag

2018-03-28 Thread Marc Zyngier
From: Shih-Wei Li We always set the IMO and FMO bits in the HCR_EL2 when running the guest, regardless if we use the vgic or not. By moving these flags to HCR_GUEST_FLAGS we can avoid one of the extra save/restore operations of HCR_EL2 in the world switch code, and we can also soon get rid of th

[PATCH 16/85] KVM: arm64: Avoid storing the vcpu pointer on the stack

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We already have the percpu area for the host cpu state, which points to the VCPU, so there's no need to store the VCPU pointer on the stack on every context switch. We can be a little more clever and just use tpidr_el2 for the percpu offset and load the VCPU pointer from t

[PATCH 15/85] KVM: arm/arm64: Move vcpu_load call after kvm_vcpu_first_run_init

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Moving the call to vcpu_load() in kvm_arch_vcpu_ioctl_run() to after we've called kvm_vcpu_first_run_init() simplifies some of the vgic and there is also no need to do vcpu_load() for things such as handling the immediate_exit flag. Reviewed-by: Julien Grall Reviewed-by:

[PATCH 14/85] KVM: arm/arm64: Avoid vcpu_load for other vcpu ioctls than KVM_RUN

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Calling vcpu_load() registers preempt notifiers for this vcpu and calls kvm_arch_vcpu_load(). The latter will soon be doing a lot of heavy lifting on arm/arm64 and will try to do things such as enabling the virtual timer and setting us up to handle interrupts from the time

[PATCH 12/85] KVM: arm/arm64: vgic: Don't populate multiple LRs with the same vintid

2018-03-28 Thread Marc Zyngier
The vgic code is trying to be clever when injecting GICv2 SGIs, and will happily populate LRs with the same interrupt number if they come from multiple vcpus (after all, they are distinct interrupt sources). Unfortunately, this is against the letter of the architecture, and the GICv2 architecture

[PATCH 13/85] kvm: arm/arm64: vgic-v3: Tighten synchronization for guests using v2 on v3

2018-03-28 Thread Marc Zyngier
On guest exit, and when using GICv2 on GICv3, we use a dsb(st) to force synchronization between the memory-mapped guest view and the system-register view that the hypervisor uses. This is incorrect, as the spec calls out the need for "a DSB whose required access type is both loads and stores with

[PATCH 11/85] KVM: arm/arm64: Reduce verbosity of KVM init log

2018-03-28 Thread Marc Zyngier
From: Ard Biesheuvel On my GICv3 system, the following is printed to the kernel log at boot: kvm [1]: 8-bit VMID kvm [1]: IDMAP page: d20e35000 kvm [1]: HYP VA range: 8000: kvm [1]: vgic-v2@2c02 kvm [1]: GIC system register CPU interface enabled kvm [1]:

[PATCH 10/85] KVM: arm/arm64: Reset mapped IRQs on VM reset

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall We currently don't allow resetting mapped IRQs from userspace, because their state is controlled by the hardware. But we do need to reset the state when the VM is reset, so we provide a function for the 'owner' of the mapped interrupt to reset the interrupt state. Current

[PATCH 09/85] KVM: arm/arm64: Avoid vcpu_load for other vcpu ioctls than KVM_RUN

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall Calling vcpu_load() registers preempt notifiers for this vcpu and calls kvm_arch_vcpu_load(). The latter will soon be doing a lot of heavy lifting on arm/arm64 and will try to do things such as enabling the virtual timer and setting us up to handle interrupts from the time

[PATCH 08/85] KVM: arm/arm64: vgic: Add missing irq_lock to vgic_mmio_read_pending

2018-03-28 Thread Marc Zyngier
From: Andre Przywara Our irq_is_pending() helper function accesses multiple members of the vgic_irq struct, so we need to hold the lock when calling it. Add that requirement as a comment to the definition and take the lock around the call in vgic_mmio_read_pending(), where we were missing it befo

[PATCH 07/85] KVM: arm/arm64: No need to zero CNTVOFF in kvm_timer_vcpu_put() for VHE

2018-03-28 Thread Marc Zyngier
From: Shanker Donthineni In AArch64/AArch32, the virtual counter uses a fixed virtual offset of zero in the following situations as per ARMv8 specifications: 1) HCR_EL2.E2H is 1, and CNTVCT_EL0/CNTVCT are read from EL2. 2) HCR_EL2.{E2H, TGE} is {1, 1}, and either: — CNTVCT_EL0 is read from No

[PATCH 06/85] KVM: arm: Enable emulation of the physical timer

2018-03-28 Thread Marc Zyngier
From: Jérémy Fanguède Set the handlers to emulate read and write operations for CNTP_CTL, CNTP_CVAL and CNTP_TVAL registers in such a way that VMs can use the physical timer. Signed-off-by: Jérémy Fanguède Signed-off-by: Christoffer Dall --- arch/arm/kvm/coproc.c | 61

[PATCH 05/85] KVM: arm64: Enable the EL1 physical timer for AArch32 guests

2018-03-28 Thread Marc Zyngier
From: Jérémy Fanguède Some 32bits guest OS can use the CNTP timer, however KVM does not handle the accesses, injecting a fault instead. Use the proper handlers to emulate the EL1 Physical Timer (CNTP) register accesses of AArch32 guests. Signed-off-by: Jérémy Fanguède Signed-off-by: Alvise Rig

[PATCH 03/85] arm64/kvm: Prohibit guest LOR accesses

2018-03-28 Thread Marc Zyngier
From: Mark Rutland We don't currently limit guest accesses to the LOR registers, which we neither virtualize nor context-switch. As such, guests are provided with unusable information/controls, and are not isolated from each other (or the host). To prevent these issues, we can trap register acce

[PATCH 04/85] arm64: KVM: Move CPU ID reg trap setup off the world switch path

2018-03-28 Thread Marc Zyngier
From: Dave Martin The HCR_EL2.TID3 flag needs to be set when trapping guest access to the CPU ID registers is required. However, the decision about whether to set this bit does not need to be repeated at every switch to the guest. Instead, it's sufficient to make this decision once and record t

[PATCH 02/85] ARM: kvm: fix building with gcc-8

2018-03-28 Thread Marc Zyngier
From: Arnd Bergmann In banked-sr.c, we use a top-level '__asm__(".arch_extension virt")' statement to allow compilation of a multi-CPU kernel for ARMv6 and older ARMv7-A that don't normally support access to the banked registers. This is considered to be a programming error by the gcc developers

[GIT PULL] KVM/ARM updates for v4.17

2018-03-28 Thread Marc Zyngier
Paolo, Radim, This is the (rather big) set of updates for KVM/ARM for v4.17. The main features are the set of VHE optimizations taking advantage of CPUs implementing ARMv8.1, together with the EL2 randomization patches that are the foundation for mitigating the so-called variant 3a security issue

[PATCH 01/85] KVM: arm/arm64: Fix arch timers with userspace irqchips

2018-03-28 Thread Marc Zyngier
From: Christoffer Dall When introducing support for irqchip in userspace we needed a way to mask the timer signal to prevent the guest continuously exiting due to a screaming timer. We did this by disabling the corresponding percpu interrupt on the host interrupt controller, because we cannot re