3.12.42-stable review
cover 3.12.42-stable review
This is the start of the stable review cycle for the 3.12.42 release. There are 63 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Mon May 4 11:48:46 CEST 2015. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
http://kernel.org/pub/linux/kernel/people/jirislaby/stable-review/patch-3.12.42-rc1.xz
and the diffstat can be found below.
thanks,
js
===============
Alex Bennée (1):
arm64: KVM: export demux regids as KVM_REG_ARM64
Andre Przywara (1):
KVM: arm/arm64: vgic: fix GICD_ICFGR register accesses
Anup Patel (1):
arm64: KVM: Force undefined exception for Guest SMC intructions
Ard Biesheuvel (2):
ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn()
Christoffer Dall (15):
KVM: ARM: Update comments for kvm_handle_wfi
arm/arm64: KVM: arch_timer: Initialize cntvoff at kvm_init
ARM: KVM: Allow creating the VGIC after VCPUs arm/arm64: kvm: Set vcpu->cpu to -1 on vcpu_put
arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive arm/arm64: KVM: Fix and refactor unmap_range
arm/arm64: KVM: Complete WFI/WFE instructions arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu arm/arm64: KVM: Introduce stage2_unmap_vm
arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized arm/arm64: KVM: Require in-kernel vgic for the arch timers arm/arm64: KVM: Keep elrsr/aisr in sync with software model
Eric Auger (1):
ARM: KVM: Unmap IPA on memslot delete/move
Geoff Levand (1):
arm64/kvm: Fix assembler compatibility of macros
Haibin Wang (1):
KVM: ARM: vgic: Fix the overlap check action about setting the GICD &
GICC base address.
Joel Schopp (1):
arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc
Jonathan Austin (2):
KVM: ARM: Fix calculation of virtual CPU ID
KVM: ARM: fix the size of TTBCR_{T0SZ,T1SZ} masks
Kim Phillips (1):
ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping
Li Liu (1):
ARM: virt: fix wrong HSCTLR.EE bit setting
Lorenzo Pieralisi (1):
arm: kvm: implement CPU PM notifier
Marc Zyngier (22):
ARM: KVM: Yield CPU when vcpu executes a WFE
ARM: KVM: Fix MPIDR computing to support virtual clusters
ARM: KVM: fix L2CTLR to be per-cluster
arm/arm64: KVM: PSCI: use MPIDR to identify a target CPU
arm64: KVM: Yield CPU when vcpu executes a WFE arm/arm64: KVM: detect CPU reset on CPU_PM_EXIT
arm64: KVM: force cache clean on page fault when caches are off
arm64: KVM: allows discrimination of AArch32 sysreg access
arm64: KVM: trap VM system registers until MMU and caches are ON
ARM: KVM: introduce kvm_p*d_addr_end
arm64: KVM: flush VM pages before letting the guest enable caches
ARM: KVM: force cache clean on page fault when caches are off
ARM: KVM: fix handling of trapped 64bit coprocessor accesses
ARM: KVM: fix ordering of 64bit coprocessor accesses
ARM: KVM: introduce per-vcpu HYP Configuration Register
ARM: KVM: add world-switch for AMAIR{0,1}
ARM: KVM: trap VM system registers until MMU and caches are ON
ARM: KVM: fix non-VGIC compilation
KVM: ARM: vgic: plug irq injection race
arm64: KVM: Fix TLB invalidation by IPA/VMID
arm64: KVM: Fix HCR setting for 32bit guests
arm64: KVM: Do not use pgd_index to index stage-2 pgd
Pranavkumar Sawargaonkar (1):
ARM/ARM64: KVM: Nuke Hyp-mode tlbs before enabling MMU
Sachin Kamat (1):
KVM: ARM: Remove duplicate include
Steve Capper (1):
arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort
Victor Kamensky (1):
ARM64: KVM: store kvm_vcpu_fault_info est_el2 as word
Vladimir Murzin (1):
arm: kvm: fix CPU hotplug
Will Deacon (7):
ARM: KVM: disable KVM in Kconfig on big-endian systems
arm64: kvm: use inner-shareable barriers for inner-shareable
maintenance
kvm: arm64: vgic: fix hyp panic with 64k pages on juno platform
KVM: ARM/arm64: fix non-const declaration of function returning const
KVM: ARM/arm64: fix broken __percpu annotation
KVM: ARM/arm64: avoid returning negative error code as bool
KVM: vgic: return int instead of bool when checking I/O ranges
Documentation/virtual/kvm/api.txt | 3 +- arch/arm/include/asm/kvm_arm.h | 11 +- arch/arm/include/asm/kvm_asm.h | 4 +- arch/arm/include/asm/kvm_emulate.h | 10 ++ arch/arm/include/asm/kvm_host.h | 11 +- arch/arm/include/asm/kvm_mmu.h | 55 ++++-- arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kernel/hyp-stub.S | 2 +- arch/arm/kvm/Kconfig | 3 +- arch/arm/kvm/arm.c | 142 +++++++++------ arch/arm/kvm/coproc.c | 85 +++++++-- arch/arm/kvm/coproc.h | 14 +- arch/arm/kvm/coproc_a15.c | 19 +- arch/arm/kvm/handle_exit.c | 24 ++- arch/arm/kvm/init.S | 4 + arch/arm/kvm/interrupts.S | 11 +- arch/arm/kvm/interrupts_head.S | 21 ++- arch/arm/kvm/mmu.c | 331 ++++++++++++++++++++++++++++++----- arch/arm/kvm/psci.c | 27 ++- arch/arm64/include/asm/kvm_arm.h | 41 +++-- arch/arm64/include/asm/kvm_asm.h | 3 +- arch/arm64/include/asm/kvm_emulate.h | 12 ++ arch/arm64/include/asm/kvm_host.h | 4 +- arch/arm64/include/asm/kvm_mmu.h | 58 +++--- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/guest.c | 1 - arch/arm64/kvm/handle_exit.c | 23 ++- arch/arm64/kvm/hyp-init.S | 4 + arch/arm64/kvm/hyp.S | 42 ++++- arch/arm64/kvm/reset.c | 1 - arch/arm64/kvm/sys_regs.c | 103 +++++++++-- arch/arm64/kvm/sys_regs.h | 2 + include/kvm/arm_arch_timer.h | 10 +- include/kvm/arm_vgic.h | 5 + virt/kvm/arm/arch_timer.c | 30 +++- virt/kvm/arm/vgic.c | 76 ++++++-- 36 files changed, 917 insertions(+), 277 deletions(-)
Signature · 1 line
2.3.5
PATCH 1/63 KVM: ARM: Fix calculation of virtual CPU ID
From: Jonathan Austin <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 1158fca401e09665c440a9fe4fd4f131ee85c13b upstream.
KVM does not have a notion of multiple clusters for CPUs, just a linear array of CPUs. When using a system with cores in more than one cluster, the current method for calculating the virtual MPIDR will leak the (physical) cluster information into the virtual MPIDR. One effect of this is that Linux under KVM fails to boot multiple CPUs that aren't in the 0th cluster.
This patch does away with exposing the real MPIDR fields in favour of simply using the virtual CPU number (but preserving the U bit, as before).
--- arch/arm/kvm/coproc_a15.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
arch/arm/kvm/coproc_a15.c +4 -7
@@ -27,14 +27,11 @@static void reset_mpidr (struct kvm_vcpu *vcpu,const struct coproc_reg *r) {/* -* Compute guest MPIDR: -* (Even if we present only one VCPU to the guest on an SMP -* host we don't set the U bit in the MPIDR, or vice versa, as -* revealing the underlying hardware properties is likely to -* be the best choice). +* Compute guest MPIDR. No need to mess around with different clusters +* but we read the 'U' bit from the underlying hardware directly. */ - vcpu->arch.cp15[c0_MPIDR] = (read_cpuid_mpidr () & ~MPIDR_LEVEL_MASK ) - | (vcpu->vcpu_id &MPIDR_LEVEL_MASK ); + vcpu->arch.cp15[c0_MPIDR] = (read_cpuid_mpidr () &MPIDR_SMP_BITMASK ) + | vcpu->vcpu_id; }#include "coproc.h"
Signature · 1 line
2.3.5
PATCH 2/63 KVM: ARM: fix the size of TTBCR_{T0SZ,T1SZ} masks
From: Jonathan Austin <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 5e497046f005528464f9600a4ee04f49df713596 upstream.
The T{0,1}SZ fields of TTBCR are 3 bits wide when using the long descriptor format. Likewise, the T0SZ field of the HTCR is 3-bits. KVM currently defines TTBCR_T{0,1}SZ as 3, not 7.
The T0SZ mask is used to calculate the value for the HTCR, both to pick out TTBCR.T0SZ and mask off the equivalent field in the HTCR during read-modify-write. The incorrect mask size causes the (UNKNOWN) reset value of HTCR.T0SZ to leak in to the calculated HTCR value. Linux will hang when initializing KVM if HTCR's reset value has bit 2 set (sometimes the case on A7/TC2)
Fixing T0SZ allows A7 cores to boot and T1SZ is also fixed for completeness.
--- arch/arm/include/asm/kvm_arm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_arm.h +2 -2
@@ -95,12 +95,12 @@#define TTBCR_IRGN1 (3 << 24)#define TTBCR_EPD1 (1 << 23)#define TTBCR_A1 (1 << 22) -#define TTBCR_T1SZ (3 << 16) +#define TTBCR_T1SZ (7 << 16)#define TTBCR_SH0 (3 << 12)#define TTBCR_ORGN0 (3 << 10)#define TTBCR_IRGN0 (3 << 8)#define TTBCR_EPD0 (1 << 7) -#define TTBCR_T0SZ 3 +#define TTBCR_T0SZ (7 << 0)#define HTCR_MASK (TTBCR_T0SZ | TTBCR_IRGN0 | TTBCR_ORGN0 | TTBCR_SH0)/* Hyp System Trap Register */
Signature · 1 line
2.3.5
PATCH 3/63 ARM: KVM: Yield CPU when vcpu executes a WFE
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 1f5580986a3667e9d67b65d916bb4249fd86a400 upstream.
On an (even slightly) oversubscribed system, spinlocks are quickly becoming a bottleneck, as some vcpus are spinning, waiting for a lock to be released, while the vcpu holding the lock may not be running at all.
This creates contention, and the observed slowdown is 40x for hackbench. No, this isn't a typo.
The solution is to trap blocking WFEs and tell KVM that we're now spinning. This ensures that other vpus will get a scheduling boost, allowing the lock to be released more quickly. Also, using CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT slightly improves the performance when the VM is severely overcommited.
Quick test to estimate the performance: hackbench 1 process 1000
2xA15 host (baseline): 1.843s
2xA15 guest w/o patch: 2.083s
4xA15 guest w/o patch: 80.212s
8xA15 guest w/o patch: Could not be bothered to find out
2xA15 guest w/ patch: 2.102s
4xA15 guest w/ patch: 3.205s
8xA15 guest w/ patch: 6.887s
So we go from a 40x degradation to 1.5x in the 2x overcommit case, which is vaguely more acceptable.
--- arch/arm/include/asm/kvm_arm.h | 4 +++- arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/handle_exit.c | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_arm.h +3 -1
@@ -67,7 +67,7 @@*/ #define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \ HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \ - HCR_SWIO | HCR_TIDCP) + HCR_TWE | HCR_SWIO | HCR_TIDCP)#define HCR_VIRT_EXCP_MASK (HCR_VA | HCR_VI | HCR_VF)/* System Control Register (SCTLR) bits */
@@ -208,6 +208,8 @@#define HSR_EC_DABT (0x24)#define HSR_EC_DABT_HYP (0x25) +#define HSR_WFI_IS_WFE (1U << 0) +#define HSR_HVC_IMM_MASK ((1UL << 16) - 1)#define HSR_DABT_S1PTW (1U << 7)
arch/arm/kvm/Kconfig +1 -0
@@ -20,6 +20,7 @@ config KVM bool "Kernel-based Virtual Machine (KVM) support" select PREEMPT_NOTIFIERS select ANON_INODES + select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST depends on ARM_VIRT_EXT && ARM_LPAE
arch/arm/kvm/handle_exit.c +5 -1
@@ -84,7 +84,11 @@ static int handle_dabt_hyp(struct kvm_vcpu *vcpu, struct kvm_run *run)static int kvm_handle_wfi (struct kvm_vcpu *vcpu,struct kvm_run *run) {trace_kvm_wfi (*vcpu_pc (vcpu)); -kvm_vcpu_block (vcpu); +if (kvm_vcpu_get_hsr (vcpu) &HSR_WFI_IS_WFE ) +kvm_vcpu_on_spin (vcpu); +else +kvm_vcpu_block (vcpu); +return 1 ; }
Signature · 1 line
2.3.5
PATCH 4/63 ARM: KVM: Fix MPIDR computing to support virtual clusters
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 2d1d841bd44e24b58a3d3cc4fa793670aaa38fbf upstream.
In order to be able to support more than 4 A7 or A15 CPUs, we need to fix the MPIDR computing to reflect the fact that both A15 and A7 can only exist in clusters of at most 4 CPUs.
Fix the MPIDR computing to allow virtual clusters to be exposed to the guest.
--- arch/arm/kvm/coproc_a15.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm/kvm/coproc_a15.c +6 -4
@@ -27,11 +27,13 @@static void reset_mpidr (struct kvm_vcpu *vcpu,const struct coproc_reg *r) {/* -* Compute guest MPIDR. No need to mess around with different clusters -* but we read the 'U' bit from the underlying hardware directly. +* Compute guest MPIDR. We build a virtual cluster out of the +* vcpu_id, but we read the 'U' bit from the underlying +* hardware directly. */ - vcpu->arch.cp15[c0_MPIDR] = (read_cpuid_mpidr () &MPIDR_SMP_BITMASK ) - | vcpu->vcpu_id; + vcpu->arch.cp15[c0_MPIDR] = ((read_cpuid_mpidr () &MPIDR_SMP_BITMASK ) | + ((vcpu->vcpu_id >>2 ) <<MPIDR_LEVEL_BITS ) | + (vcpu->vcpu_id &3 )); }#include "coproc.h"
Signature · 1 line
2.3.5
PATCH 5/63 KVM: ARM: Update comments for kvm_handle_wfi
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 82ea046c95a3c3ddcfa058c8a270b9afb6e93700 upstream.
Update comments to reflect what is really going on and add the TWE bit to the comments in kvm_arm.h.
Also renames the function to kvm_handle_wfx like is done on arm64 for consistency and uber-correctness.
--- arch/arm/include/asm/kvm_arm.h | 1 + arch/arm/kvm/handle_exit.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-)
arch/arm/include/asm/kvm_arm.h +1 -0
@@ -57,6 +57,7 @@* TSC: Trap SMC * TSW: Trap cache operations by set/way * TWI: Trap WFI +* TWE: Trap WFE * TIDCP: Trap L2CTLR/L2ECTLR * BSU_IS: Upgrade barriers to the inner shareable domain * FB: Force broadcast of all maintainance operations
arch/arm/kvm/handle_exit.c +8 -6
@@ -73,15 +73,17 @@ static int handle_dabt_hyp(struct kvm_vcpu *vcpu, struct kvm_run *run) }/** -* kvm_handle_wfi - handle a wait-for-interrupts instruction executed by a guest +* kvm_handle_wfx - handle a WFI or WFE instructions trapped in guests * @vcpu: the vcpu pointer * @run: the kvm_run structure pointer * -* Simply sets the wait_for_interrupts flag on the vcpu structure, which will -* halt execution of world-switches and schedule other host processes until -* there is an incoming IRQ or FIQ to the VM. +* WFE: Yield the CPU and come back to this vcpu when the scheduler +* decides to. +* WFI: Simply call kvm_vcpu_block(), which will halt execution of +* world-switches and schedule other host processes until there is an +* incoming IRQ or FIQ to the VM. */ -static int kvm_handle_wfi (struct kvm_vcpu *vcpu,struct kvm_run *run) +static int kvm_handle_wfx (struct kvm_vcpu *vcpu,struct kvm_run *run) {trace_kvm_wfi (*vcpu_pc (vcpu));if (kvm_vcpu_get_hsr (vcpu) &HSR_WFI_IS_WFE )
@@ -93,7 +95,7 @@ static int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run) }static exit_handle_fn arm_exit_handlers[] = { - [HSR_EC_WFI ] = kvm_handle_wfi, + [HSR_EC_WFI ] = kvm_handle_wfx, [HSR_EC_CP15_32 ] = kvm_handle_cp15_32, [HSR_EC_CP15_64 ] = kvm_handle_cp15_64, [HSR_EC_CP14_MR ] = kvm_handle_cp14_access,
Signature · 1 line
2.3.5
PATCH 6/63 ARM: KVM: fix L2CTLR to be per-cluster
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 9cbb6d969cb6561de45d917b8bb9281cb374bb35 upstream.
The L2CTLR register contains the number of CPUs in this cluster.
Make sure the register content is actually relevant to the vcpu that is being configured by computing the number of cores that are part of its cluster.
--- arch/arm/kvm/coproc_a15.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/kvm/coproc_a15.c +4 -0
@@ -79,6 +79,10 @@ static void reset_l2ctlr(struct kvm_vcpu *vcpu, const struct coproc_reg *r) asmvolatile ("mrc p15, 1, %0, c9, c0, 2\n" :"=r" (l2ctlr)); l2ctlr &= ~(3 <<24 ); ncores =atomic_read (&vcpu->kvm->online_vcpus) -1 ; +/* How many cores in the current cluster and the next ones */ + ncores -= (vcpu->vcpu_id & ~3 ); +/* Cap it to the maximum number of cores in a single cluster */ + ncores =min (ncores,3U ); l2ctlr |= (ncores &3 ) <<24 ; vcpu->arch.cp15[c9_L2CTLR] = l2ctlr;
Signature · 1 line
2.3.5
PATCH 7/63 arm/arm64: KVM: PSCI: use MPIDR to identify a target CPU
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 79c648806f9034abf54332b78043bb242189d953 upstream.
The KVM PSCI code blindly assumes that vcpu_id and MPIDR are the same thing. This is true when vcpus are organized as a flat topology, but is wrong when trying to emulate any other topology (such as A15 clusters).
Change the KVM PSCI CPU_ON code to look at the MPIDR instead of the vcpu_id to pick a target CPU.
--- arch/arm/include/asm/kvm_emulate.h | 5 +++++ arch/arm/kvm/psci.c | 18 ++++++++++++++---- arch/arm64/include/asm/kvm_emulate.h | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_emulate.h +5 -0
@@ -157,4 +157,9 @@ static inline u32 kvm_vcpu_hvc_get_imm(struct kvm_vcpu *vcpu) return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK; } +static inline unsigned long kvm_vcpu_get_mpidr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.cp15[c0_MPIDR]; +} +#endif /* __ARM_KVM_EMULATE_H__ */
arch/arm/kvm/psci.c +14 -4
@@ -18,6 +18,7 @@#include <linux/kvm_host.h> #include <linux/wait.h> +#include <asm/cputype.h> #include <asm/kvm_emulate.h> #include <asm/kvm_psci.h>
@@ -34,22 +35,31 @@ static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu)static unsigned long kvm_psci_vcpu_on (struct kvm_vcpu *source_vcpu) {struct kvm *kvm = source_vcpu->kvm; -struct kvm_vcpu *vcpu; +struct kvm_vcpu *vcpu =NULL , *tmp;wait_queue_head_t *wq;unsigned long cpu_id; +unsigned long mpidr;phys_addr_t target_pc; +int i; cpu_id = *vcpu_reg (source_vcpu,1 );if (vcpu_mode_is_32bit (source_vcpu)) cpu_id &= ~((u32 )0 ); -if (cpu_id >=atomic_read (&kvm->online_vcpus)) +kvm_for_each_vcpu (i, tmp, kvm) { + mpidr =kvm_vcpu_get_mpidr (tmp); +if ((mpidr &MPIDR_HWID_BITMASK ) + == (cpu_id &MPIDR_HWID_BITMASK )) { + vcpu = tmp; +break ; + } + } + +if (!vcpu)return KVM_PSCI_RET_INVAL ; target_pc = *vcpu_reg (source_vcpu,2 ); - vcpu =kvm_get_vcpu (kvm, cpu_id); - wq =kvm_arch_vcpu_wq (vcpu);if (!waitqueue_active (wq))return KVM_PSCI_RET_INVAL ;
arch/arm64/include/asm/kvm_emulate.h +5 -0
@@ -177,4 +177,9 @@ static inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu) return kvm_vcpu_get_hsr(vcpu) & ESR_EL2_FSC_TYPE; } +static inline unsigned long kvm_vcpu_get_mpidr (struct kvm_vcpu *vcpu) +{ +return vcpu_sys_reg (vcpu,MPIDR_EL1 ); +} +#endif /* __ARM64_KVM_EMULATE_H__ */
Signature · 1 line
2.3.5
PATCH 8/63 arm64: KVM: Yield CPU when vcpu executes a WFE
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit d241aac798eb042e605f78c31a4122e583b2cd13 upstream.
On an (even slightly) oversubscribed system, spinlocks are quickly becoming a bottleneck, as some vcpus are spinning, waiting for a lock to be released, while the vcpu holding the lock may not be running at all.
The solution is to trap blocking WFEs and tell KVM that we're now spinning. This ensures that other vpus will get a scheduling boost, allowing the lock to be released more quickly. Also, using CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT slightly improves the performance when the VM is severely overcommited.
--- arch/arm64/include/asm/kvm_arm.h | 8 ++++++-- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/handle_exit.c | 18 +++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-)
arch/arm64/include/asm/kvm_arm.h +6 -2
@@ -63,6 +63,7 @@* TAC: Trap ACTLR * TSC: Trap SMC * TSW: Trap cache operations by set/way +* TWE: Trap WFE * TWI: Trap WFI * TIDCP: Trap L2CTLR/L2ECTLR * BSU_IS: Upgrade barriers to the inner shareable domain
@@ -72,8 +73,9 @@* FMO: Override CPSR.F and enable signaling with VF * SWIO: Turn set/way invalidates into set/way clean+invalidate */ -#define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \ - HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \ +#define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \ + HCR_BSU_IS | HCR_FB | HCR_TAC | \ + HCR_AMO | HCR_IMO | HCR_FMO | \ HCR_SWIO | HCR_TIDCP | HCR_RW)#define HCR_VIRT_EXCP_MASK (HCR_VA | HCR_VI | HCR_VF)
@@ -242,4 +244,6 @@#define ESR_EL2_EC_xABT_xFSR_EXTABT 0x10 +#define ESR_EL2_EC_WFI_ISS_WFE (1 << 0) +#endif /* __ARM64_KVM_ARM_H__ */
arch/arm64/kvm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config KVM select MMU_NOTIFIER select PREEMPT_NOTIFIERS select ANON_INODES + select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST select KVM_ARM_VGIC
arch/arm64/kvm/handle_exit.c +13 -5
@@ -47,21 +47,29 @@ static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) }/** -* kvm_handle_wfi - handle a wait-for-interrupts instruction executed by a guest +* kvm_handle_wfx - handle a wait-for-interrupts or wait-for-event +* instruction executed by a guest +* * @vcpu: the vcpu pointer * -* Simply call kvm_vcpu_block(), which will halt execution of +* WFE: Yield the CPU and come back to this vcpu when the scheduler +* decides to. +* WFI: Simply call kvm_vcpu_block(), which will halt execution of * world-switches and schedule other host processes until there is an * incoming IRQ or FIQ to the VM. */ -static int kvm_handle_wfi (struct kvm_vcpu *vcpu,struct kvm_run *run) +static int kvm_handle_wfx (struct kvm_vcpu *vcpu,struct kvm_run *run) { -kvm_vcpu_block (vcpu); +if (kvm_vcpu_get_hsr (vcpu) &ESR_EL2_EC_WFI_ISS_WFE ) +kvm_vcpu_on_spin (vcpu); +else +kvm_vcpu_block (vcpu); +return 1 ; }static exit_handle_fn arm_exit_handlers[] = { - [ESR_EL2_EC_WFI ] = kvm_handle_wfi, + [ESR_EL2_EC_WFI ] = kvm_handle_wfx, [ESR_EL2_EC_CP15_32 ] = kvm_handle_cp15_32, [ESR_EL2_EC_CP15_64 ] = kvm_handle_cp15_64, [ESR_EL2_EC_CP14_MR ] = kvm_handle_cp14_access,
Signature · 1 line
2.3.5
PATCH 9/63 arm/arm64: KVM: arch_timer: Initialize cntvoff at kvm_init
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit a1a64387adeeba7a34ce06f2774e81f496ee803b upstream.
Initialize the cntvoff at kvm_init_vm time, not before running the VCPUs at the first time because that will overwrite any potentially restored values from user space.
--- arch/arm/kvm/arm.c | 2 ++ virt/kvm/arm/vgic.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/kvm/arm.c +2 -0
@@ -137,6 +137,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)if (ret) goto out_free_stage2_pgd; +kvm_timer_init (kvm); +/* Mark the initial VMID generation invalid */ kvm->arch.vmid_gen =0 ;
virt/kvm/arm/vgic.c +0 -1
@@ -1410,7 +1410,6 @@ int kvm_vgic_init(struct kvm *kvm)for (i =VGIC_NR_PRIVATE_IRQS ; i <VGIC_NR_IRQS ; i +=4 )vgic_set_target_reg (kvm,0 , i); -kvm_timer_init (kvm); kvm->arch.vgic.ready = true; out:mutex_unlock (&kvm->lock);
Signature · 1 line
2.3.5
PATCH 10/63 ARM: KVM: Allow creating the VGIC after VCPUs
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit e1ba0207a1b3714bb3f000e506285ae5123cdfa7 upstream.
Rework the VGIC initialization slightly to allow initialization of the vgic cpu-specific state even if the irqchip (the VGIC) hasn't been created by user space yet. This is safe, because the vgic data structures are already allocated when the CPU is allocated if VGIC support is compiled into the kernel. Further, the init process does not depend on any other information and the sacrifice is a slight performance degradation for creating VMs in the no-VGIC case.
The reason is that the new device control API doesn't mandate creating the VGIC before creating the VCPU and it is unreasonable to require user space to create the VGIC before creating the VCPUs.
At the same time move the irqchip_in_kernel check out of kvm_vcpu_first_run_init and into the init function to make the per-vcpu and global init functions symmetric and add comments on the exported functions making it a bit easier to understand the init flow by only looking at vgic.c.
--- arch/arm/kvm/arm.c | 7 ++++--- virt/kvm/arm/vgic.c | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-)
arch/arm/kvm/arm.c +4 -3
@@ -463,6 +463,8 @@ static void update_vttbr(struct kvm *kvm)static int kvm_vcpu_first_run_init (struct kvm_vcpu *vcpu) { +int ret; +if (likely (vcpu->arch.has_run_once))return 0 ;
@@ -472,9 +474,8 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)* Initialize the VGIC before running a vcpu the first time on * this VM. */ -if (irqchip_in_kernel (vcpu->kvm) && -unlikely (!vgic_initialized (vcpu->kvm))) { -int ret =kvm_vgic_init (vcpu->kvm); +if (unlikely (!vgic_initialized (vcpu->kvm))) { + ret =kvm_vgic_init (vcpu->kvm);if (ret)return ret; }
virt/kvm/arm/vgic.c +19 -3
@@ -1244,15 +1244,19 @@ static irqreturn_t vgic_maintenance_handler(int irq, void *data)return IRQ_HANDLED ; } +/** +* kvm_vgic_vcpu_init - Initialize per-vcpu VGIC state +* @vcpu: pointer to the vcpu struct +* +* Initialize the vgic_cpu struct and vgic_dist struct fields pertaining to +* this vcpu and enable the VGIC for this VCPU +*/ int kvm_vgic_vcpu_init (struct kvm_vcpu *vcpu) {struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;struct vgic_dist *dist = &vcpu->kvm->arch.vgic;int i; -if (!irqchip_in_kernel (vcpu->kvm)) -return 0 ; -if (vcpu->vcpu_id >=VGIC_MAX_CPUS )return -EBUSY ;
@@ -1384,10 +1388,22 @@ out:return ret; } +/** +* kvm_vgic_init - Initialize global VGIC state before running any VCPUs +* @kvm: pointer to the kvm struct +* +* Map the virtual CPU interface into the VM before running any VCPUs. We +* can't do this at creation time, because user space must first set the +* virtual CPU interface address in the guest physical address space. Also +* initialize the ITARGETSRn regs to 0 on the emulated distributor. +*/ int kvm_vgic_init (struct kvm *kvm) {int ret =0 , i; +if (!irqchip_in_kernel (kvm)) +return 0 ; +mutex_lock (&kvm->lock);if (vgic_initialized (kvm))
Signature · 1 line
2.3.5
PATCH 11/63 arm/arm64: kvm: Set vcpu->cpu to -1 on vcpu_put
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit e9b152cb957cb194437f37e79f0f3c9d34fe53d6 upstream.
The arch-generic KVM code expects the cpu field of a vcpu to be -1 if the vcpu is no longer assigned to a cpu. This is used for the optimized make_all_cpus_request path and will be used by the vgic code to check that no vcpus are running.
--- arch/arm/kvm/arm.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/arm/kvm/arm.c +7 -0
@@ -340,6 +340,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu) { +/* +* The arch-generic KVM code expects the cpu field of a vcpu to be -1 +* if the vcpu is no longer assigned to a cpu. This is used for the +* optimized make_all_cpus_request path. +*/ + vcpu->cpu =-1 ; +kvm_arm_set_running_vcpu (NULL ); }
Signature · 1 line
2.3.5
PATCH 12/63 arm64: KVM: Force undefined exception for Guest SMC intructions
In reply to Jiri SlabyFrom: Anup Patel <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit e5cf9dcdbfd26cd4e1991db08755da900454efeb upstream.
The SMC-based PSCI emulation for Guest is going to be very different from the in-kernel HVC-based PSCI emulation hence for now just inject undefined exception when Guest executes SMC instruction.
--- arch/arm64/kvm/handle_exit.c | 3 --- 1 file changed, 3 deletions(-)
arch/arm64/kvm/handle_exit.c +0 -3
@@ -39,9 +39,6 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run)static int handle_smc (struct kvm_vcpu *vcpu,struct kvm_run *run) { -if (kvm_psci_call (vcpu)) -return 1 ; -kvm_inject_undefined (vcpu);return 1 ; }
Signature · 1 line
2.3.5
PATCH 13/63 arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 478a8237f656d86d25b3e4e4bf3c48f590156294 upstream.
The current KVM implementation of PSCI returns INVALID_PARAMETERS if the waitqueue for the corresponding CPU is not active. This does not seem correct, since KVM should not care what the specific thread is doing, for example, user space may not have called KVM_RUN on this VCPU yet or the thread may be busy looping to user space because it received a signal; this is really up to the user space implementation. Instead we should check specifically that the CPU is marked as being turned off, regardless of the VCPU thread state, and if it is, we shall simply clear the pause flag on the CPU and wake up the thread if it happens to be blocked for us.
Further, the implementation seems to be racy when executing multiple VCPU threads. There really isn't a reasonable user space programming scheme to ensure all secondary CPUs have reached kvm_vcpu_first_run_init before turning on the boot CPU.
Therefore, set the pause flag on the vcpu at VCPU init time (which can reasonably be expected to be completed for all CPUs by user space before running any VCPUs) and clear both this flag and the feature (in case the feature can somehow get set again in the future) and ping the waitqueue on turning on a VCPU using PSCI.
--- arch/arm/kvm/arm.c | 30 +++++++++++++++++++----------- arch/arm/kvm/psci.c | 11 ++++++----- 2 files changed, 25 insertions(+), 16 deletions(-)
arch/arm/kvm/arm.c +19 -11
@@ -487,15 +487,6 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)return ret; } -/* -* Handle the "start in power-off" case by calling into the -* PSCI code. -*/ -if (test_and_clear_bit (KVM_ARM_VCPU_POWER_OFF , vcpu->arch.features)) { - *vcpu_reg (vcpu,0 ) =KVM_PSCI_FN_CPU_OFF ; -kvm_psci_call (vcpu); - } -return 0 ; }
@@ -709,6 +700,24 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,return -EINVAL ; } +static int kvm_arch_vcpu_ioctl_vcpu_init (struct kvm_vcpu *vcpu, +struct kvm_vcpu_init *init) +{ +int ret; + + ret =kvm_vcpu_set_target (vcpu, init); +if (ret) +return ret; + +/* +* Handle the "start in power-off" case by marking the VCPU as paused. +*/ +if (__test_and_clear_bit (KVM_ARM_VCPU_POWER_OFF , vcpu->arch.features)) + vcpu->arch.pause = true; + +return 0 ; +} +long kvm_arch_vcpu_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -722,8 +731,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,if (copy_from_user (&init, argp,sizeof (init)))return -EFAULT ; -return kvm_vcpu_set_target (vcpu, &init); - +return kvm_arch_vcpu_ioctl_vcpu_init (vcpu, &init); }case KVM_SET_ONE_REG :case KVM_GET_ONE_REG : {
arch/arm/kvm/psci.c +6 -5
@@ -55,15 +55,15 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) } } -if (!vcpu) +/* +* Make sure the caller requested a valid CPU and that the CPU is +* turned off. +*/ +if (!vcpu || !vcpu->arch.pause)return KVM_PSCI_RET_INVAL ; target_pc = *vcpu_reg (source_vcpu,2 ); - wq =kvm_arch_vcpu_wq (vcpu); -if (!waitqueue_active (wq)) -return KVM_PSCI_RET_INVAL ; -kvm_reset_vcpu (vcpu);/* Gracefully handle Thumb2 entry point */
@@ -76,6 +76,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) vcpu->arch.pause = false;smp_mb ();/* Make sure the above is visible */ + wq =kvm_arch_vcpu_wq (vcpu);wake_up_interruptible (wq);return KVM_PSCI_RET_SUCCESS ;
Signature · 1 line
2.3.5
PATCH 14/63 KVM: ARM: Remove duplicate include
In reply to Jiri SlabyFrom: Sachin Kamat <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 61466710de078c697106fa5b70ec7afc9feab520 upstream.
trace.h was included twice. Remove duplicate inclusion.
--- arch/arm/kvm/handle_exit.c | 2 -- 1 file changed, 2 deletions(-)
arch/arm/kvm/handle_exit.c +0 -2
@@ -26,8 +26,6 @@#include "trace.h" -#include "trace.h" -typedef int (*exit_handle_fn )(struct kvm_vcpu *,struct kvm_run *);static int handle_svc_hyp (struct kvm_vcpu *vcpu,struct kvm_run *run)
Signature · 1 line
2.3.5
PATCH 15/63 arm: kvm: implement CPU PM notifier
In reply to Jiri SlabyFrom: Lorenzo Pieralisi <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 1fcf7ce0c60213994269fb59569ec161eb6e08d6 upstream.
Upon CPU shutdown and consequent warm-reboot, the hypervisor CPU state must be re-initialized. This patch implements a CPU PM notifier that upon warm-boot calls a KVM hook to reinitialize properly the hypervisor state so that the CPU can be safely resumed.
--- arch/arm/kvm/arm.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
arch/arm/kvm/arm.c +30 -0
@@ -17,6 +17,7 @@*/ #include <linux/cpu.h> +#include <linux/cpu_pm.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/kvm_host.h>
@@ -857,6 +858,33 @@ static struct notifier_block hyp_init_cpu_nb = { .notifier_call = hyp_init_cpu_notify, }; +#ifdef CONFIG_CPU_PM +static int hyp_init_cpu_pm_notifier (struct notifier_block *self, +unsigned long cmd, +void *v) +{ +if (cmd ==CPU_PM_EXIT ) { +cpu_init_hyp_mode (NULL ); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} + +static struct notifier_block hyp_init_cpu_pm_nb = { + .notifier_call = hyp_init_cpu_pm_notifier, +}; + +static void __init hyp_cpu_pm_init (void ) +{ +cpu_pm_register_notifier (&hyp_init_cpu_pm_nb); +} +#else +static inline void hyp_cpu_pm_init (void ) +{ +} +#endif +/** * Inits Hyp-mode on all online CPUs */
@@ -1017,6 +1045,8 @@ int kvm_arch_init(void *opaque) goto out_err; } +hyp_cpu_pm_init (); +kvm_coproc_table_init ();return 0 ; out_err:
Signature · 1 line
2.3.5
PATCH 16/63 arm/arm64: KVM: detect CPU reset on CPU_PM_EXIT
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit b20c9f29c5c25921c6ad18b50d4b61e6d181c3cc upstream.
Commit 1fcf7ce0c602 (arm: kvm: implement CPU PM notifier) added support for CPU power-management, using a cpu_notifier to re-init KVM on a CPU that entered CPU idle.
The code assumed that a CPU entering idle would actually be powered off, loosing its state entierely, and would then need to be reinitialized. It turns out that this is not always the case, and some HW performs CPU PM without actually killing the core. In this case, we try to reinitialize KVM while it is still live. It ends up badly, as reported by Andre Przywara (using a Calxeda Midway):
[ 3.663897] Kernel panic - not syncing: unexpected prefetch abort in Hyp mode at: 0x685760 [ 3.663897] unexpected data abort in Hyp mode at: 0xc067d150 [ 3.663897] unexpected HVC/SVC trap in Hyp mode at: 0xc0901dd0
The trick here is to detect if we've been through a full re-init or not by looking at HVBAR (VBAR_EL2 on arm64). This involves implementing the backend for __hyp_get_vectors in the main KVM HYP code (rather small), and checking the return value against the default one when the CPU notifier is called on CPU_PM_EXIT.
--- arch/arm/kvm/arm.c | 3 ++- arch/arm/kvm/interrupts.S | 11 ++++++++++- arch/arm64/kvm/hyp.S | 27 +++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-)
arch/arm/kvm/arm.c +2 -1
@@ -863,7 +863,8 @@ static int hyp_init_cpu_pm_notifier(struct notifier_block *self, unsigned long cmd, void *v) { -if (cmd ==CPU_PM_EXIT ) { +if (cmd ==CPU_PM_EXIT && +__hyp_get_vectors () == hyp_default_vectors) {cpu_init_hyp_mode (NULL );return NOTIFY_OK ; }
arch/arm/kvm/interrupts.S +10 -1
@@ -220,6 +220,10 @@ after_vfp_restore: * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are * passed in r0 and r1. * + * A function pointer with a value of 0xffffffff has a special meaning, + * and is used to implement __hyp_get_vectors in the same way as in + * arch/arm/kernel/hyp_stub.S. + * * The calling convention follows the standard AAPCS: * r0 - r3: caller save * r12: caller save
@@ -363,6 +367,11 @@ hyp_hvc: host_switch_to_hyp: pop {r0, r1, r2} + /* Check for __hyp_get_vectors */ + cmp r0, #-1 + mrceq p15, 4, r0, c12, c0, 0 @ get HVBAR + beq 1f + push {lr} mrs lr, SPSR push {lr}
@@ -378,7 +387,7 @@ THUMB( orr lr, #1) pop {lr} msr SPSR_csxf, lr pop {lr} - eret +1: eret guest_trap: load_vcpu @ Load VCPU pointer to r0
arch/arm64/kvm/hyp.S +25 -2
@@ -681,6 +681,24 @@ __hyp_panic_str: .align 2 +/* + * u64 kvm_call_hyp(void *hypfn, ...); + * + * This is not really a variadic function in the classic C-way and care must + * be taken when calling this to ensure parameters are passed in registers + * only, since the stack will change between the caller and the callee. + * + * Call the function with the first argument containing a pointer to the + * function you wish to call in Hyp mode, and subsequent arguments will be + * passed as x0, x1, and x2 (a maximum of 3 arguments in addition to the + * function pointer can be passed). The function being called must be mapped + * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are + * passed in r0 and r1. + * + * A function pointer with a value of 0 has a special meaning, and is + * used to implement __hyp_get_vectors in the same way as in + * arch/arm64/kernel/hyp_stub.S. + */ ENTRY(kvm_call_hyp) hvc #0 ret
@@ -724,7 +742,12 @@ el1_sync: // Guest trapped into EL2 pop x2, x3 pop x0, x1 - push lr, xzr + /* Check for __hyp_get_vectors */ + cbnz x0, 1f + mrs x0, vbar_el2 + b 2f + +1: push lr, xzr /* * Compute the function address in EL2, and shuffle the parameters.
@@ -737,7 +760,7 @@ el1_sync: // Guest trapped into EL2 blr lr pop lr, xzr - eret +2: eret el1_trap: /*
Signature · 1 line
2.3.5
PATCH 17/63 arm64: KVM: force cache clean on page fault when caches are off
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 2d58b733c87689d3d5144e4ac94ea861cc729145 upstream.
In order for the guest with caches off to observe data written contained in a given page, we need to make sure that page is committed to memory, and not just hanging in the cache (as guest accesses are completely bypassing the cache until it decides to enable it).
For this purpose, hook into the coherent_icache_guest_page function and flush the region if the guest SCTLR_EL1 register doesn't show the MMU and caches as being enabled. The function also get renamed to coherent_cache_guest_page.
--- arch/arm/include/asm/kvm_mmu.h | 6 +++--- arch/arm/kvm/mmu.c | 3 ++- arch/arm64/include/asm/kvm_mmu.h | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-)
arch/arm/include/asm/kvm_mmu.h +3 -3
@@ -105,7 +105,8 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)struct kvm ; -static inline void coherent_icache_guest_page (struct kvm *kvm,gfn_t gfn) +static inline void coherent_cache_guest_page (struct kvm_vcpu *vcpu,hva_t hva, +unsigned long size) {/* * If we are going to insert an instruction page and the icache is
@@ -120,8 +121,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, gfn_t gfn)* need any kind of flushing (DDI 0406C.b - Page B3-1392). */ if (icache_is_pipt ()) { -unsigned long hva =gfn_to_hva (kvm, gfn); -__cpuc_coherent_user_range (hva, hva +PAGE_SIZE ); +__cpuc_coherent_user_range (hva, hva + size); }else if (!icache_is_vivt_asid_tagged ()) {/* any kind of VIPT cache */ __flush_icache_all ();
arch/arm/kvm/mmu.c +2 -1
@@ -540,6 +540,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,int ret;bool write_fault, writable;unsigned long mmu_seq; +unsigned long hva =gfn_to_hva (vcpu->kvm, gfn);struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; write_fault =kvm_is_write_fault (kvm_vcpu_get_hsr (vcpu));
@@ -570,7 +571,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,return -EFAULT ; new_pte =pfn_pte (pfn,PAGE_S2 ); -coherent_icache_guest_page (vcpu->kvm, gfn); +coherent_cache_guest_page (vcpu, hva,PAGE_SIZE );spin_lock (&vcpu->kvm->mmu_lock);if (mmu_notifier_retry (vcpu->kvm, mmu_seq))
arch/arm64/include/asm/kvm_mmu.h +13 -6
@@ -105,7 +105,6 @@ static inline bool kvm_is_write_fault(unsigned long esr)return true; } -static inline void kvm_clean_dcache_area (void *addr,size_t size) {}static inline void kvm_clean_pgd (pgd_t *pgd) {}static inline void kvm_clean_pmd_entry (pmd_t *pmd) {}static inline void kvm_clean_pte (pte_t *pte) {}
@@ -118,18 +117,26 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)struct kvm ; -static inline void coherent_icache_guest_page (struct kvm *kvm,gfn_t gfn) +#define kvm_flush_dcache_to_poc (a,l) __flush_dcache_area((a), (l)) + +static inline bool vcpu_has_cache_enabled (struct kvm_vcpu *vcpu) +{ +return (vcpu_sys_reg (vcpu,SCTLR_EL1 ) &0b101 ) ==0b101 ; +} + +static inline void coherent_cache_guest_page (struct kvm_vcpu *vcpu,hva_t hva, +unsigned long size) { +if (!vcpu_has_cache_enabled (vcpu)) +kvm_flush_dcache_to_poc ((void *)hva, size); +if (!icache_is_aliasing ()) {/* PIPT */ -unsigned long hva =gfn_to_hva (kvm, gfn); -flush_icache_range (hva, hva +PAGE_SIZE ); +flush_icache_range (hva, hva + size); }else if (!icache_is_aivivt ()) {/* non ASID-tagged VIVT */ /* any kind of VIPT cache */ __flush_icache_all (); } } -#define kvm_flush_dcache_to_poc (a,l) __flush_dcache_area((a), (l)) -#endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */
Signature · 1 line
2.3.5
PATCH 18/63 arm64: KVM: allows discrimination of AArch32 sysreg access
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 2072d29c46b73e39b3c6c56c6027af77086f45fd upstream.
The current handling of AArch32 trapping is slightly less than perfect, as it is not possible (from a handler point of view) to distinguish it from an AArch64 access, nor to tell a 32bit from a 64bit access either.
Fix this by introducing two additional flags:
- is_aarch32: true if the access was made in AArch32 mode
- is_32bit: true if is_aarch32 == true and a MCR/MRC instruction was used to perform the access (as opposed to MCRR/MRRC).
This allows a handler to cover all the possible conditions in which a system register gets trapped.
--- arch/arm64/kvm/sys_regs.c | 6 ++++++ arch/arm64/kvm/sys_regs.h | 2 ++ 2 files changed, 8 insertions(+)
arch/arm64/kvm/sys_regs.c +6 -0
@@ -437,6 +437,8 @@ int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run)u32 hsr =kvm_vcpu_get_hsr (vcpu);int Rt2 = (hsr >>10 ) &0xf ; + params.is_aarch32 = true; + params.is_32bit = false; params.CRm = (hsr >>1 ) &0xf ; params.Rt = (hsr >>5 ) &0xf ; params.is_write = ((hsr &1 ) ==0 );
@@ -480,6 +482,8 @@ int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run)struct sys_reg_params params;u32 hsr =kvm_vcpu_get_hsr (vcpu); + params.is_aarch32 = true; + params.is_32bit = true; params.CRm = (hsr >>1 ) &0xf ; params.Rt = (hsr >>5 ) &0xf ; params.is_write = ((hsr &1 ) ==0 );
@@ -549,6 +553,8 @@ int kvm_handle_sys_reg(struct kvm_vcpu *vcpu, struct kvm_run *run)struct sys_reg_params params;unsigned long esr =kvm_vcpu_get_hsr (vcpu); + params.is_aarch32 = false; + params.is_32bit = false; params.Op0 = (esr >>20 ) &3 ; params.Op1 = (esr >>14 ) &0x7 ; params.CRn = (esr >>10 ) &0xf ;
arch/arm64/kvm/sys_regs.h +2 -0
@@ -30,6 +30,8 @@ struct sys_reg_params {u8 Op2;u8 Rt;bool is_write; +bool is_aarch32; +bool is_32bit;/* Only valid if is_aarch32 is true */ };struct sys_reg_desc {
Signature · 1 line
2.3.5
PATCH 19/63 arm64: KVM: trap VM system registers until MMU and caches are ON
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 4d44923b17bff283c002ed961373848284aaff1b upstream.
In order to be able to detect the point where the guest enables its MMU and caches, trap all the VM related system registers.
Once we see the guest enabling both the MMU and the caches, we can go back to a saner mode of operation, which is to leave these registers in complete control of the guest.
--- arch/arm64/include/asm/kvm_arm.h | 3 +- arch/arm64/include/asm/kvm_asm.h | 3 +- arch/arm64/kvm/sys_regs.c | 90 ++++++++++++++++++++++++++++++++++------ 3 files changed, 82 insertions(+), 14 deletions(-)
arch/arm64/include/asm/kvm_arm.h +2 -1
@@ -62,6 +62,7 @@* RW: 64bit by default, can be overriden for 32bit VMs * TAC: Trap ACTLR * TSC: Trap SMC +* TVM: Trap VM ops (until M+C set in SCTLR_EL1) * TSW: Trap cache operations by set/way * TWE: Trap WFE * TWI: Trap WFI
@@ -74,7 +75,7 @@* SWIO: Turn set/way invalidates into set/way clean+invalidate */ #define HCR_GUEST_FLAGS (HCR_TSC | HCR_TSW | HCR_TWE | HCR_TWI | HCR_VM | \ - HCR_BSU_IS | HCR_FB | HCR_TAC | \ + HCR_TVM | HCR_BSU_IS | HCR_FB | HCR_TAC | \ HCR_AMO | HCR_IMO | HCR_FMO | \ HCR_SWIO | HCR_TIDCP | HCR_RW)#define HCR_VIRT_EXCP_MASK (HCR_VA | HCR_VI | HCR_VF)
arch/arm64/include/asm/kvm_asm.h +2 -1
@@ -79,7 +79,8 @@#define c13_TID_URW (TPIDR_EL0 * 2)/* Thread ID, User R/W */ #define c13_TID_URO (TPIDRRO_EL0 * 2)/* Thread ID, User R/O */ #define c13_TID_PRIV (TPIDR_EL1 * 2)/* Thread ID, Privileged */ -#define c10_AMAIR (AMAIR_EL1 * 2)/* Aux Memory Attr Indirection Reg */ +#define c10_AMAIR0 (AMAIR_EL1 * 2)/* Aux Memory Attr Indirection Reg */ +#define c10_AMAIR1 (c10_AMAIR0 + 1)/* Aux Memory Attr Indirection Reg */ #define c14_CNTKCTL (CNTKCTL_EL1 * 2)/* Timer Control Register (PL1) */ #define NR_CP15_REGS (NR_SYS_REGS * 2)
arch/arm64/kvm/sys_regs.c +78 -12
153 lines not on this page · raw message
Signature · 1 line
2.3.5
PATCH 20/63 ARM: KVM: introduce kvm_p*d_addr_end
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit a3c8bd31af260a17d626514f636849ee1cd1f63e upstream.
The use of p*d_addr_end with stage-2 translation is slightly dodgy, as the IPA is 40bits, while all the p*d_addr_end helpers are taking an unsigned long (arm64 is fine with that as unligned long is 64bit).
The fix is to introduce 64bit clean versions of the same helpers, and use them in the stage-2 page table code.
--- arch/arm/include/asm/kvm_mmu.h | 13 +++++++++++++ arch/arm/kvm/mmu.c | 8 ++++---- arch/arm64/include/asm/kvm_mmu.h | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_mmu.h +13 -0
@@ -103,6 +103,19 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)pte_val (*pte) |=L_PTE_S2_RDWR ; } +/* Open coded p*d_addr_end that can deal with 64bit addresses */ +#define kvm_pgd_addr_end (addr, end) \ +({ u64 __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) + +#define kvm_pud_addr_end (addr,end) (end) + +#define kvm_pmd_addr_end (addr, end) \ +({ u64 __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) +struct kvm ; static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva,
arch/arm/kvm/mmu.c +4 -4
@@ -134,13 +134,13 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp, pgd = pgdp +pgd_index (addr); pud =pud_offset (pgd, addr);if (pud_none (*pud)) { - addr =pud_addr_end (addr, end); + addr =kvm_pud_addr_end (addr, end);continue ; } pmd =pmd_offset (pud, addr);if (pmd_none (*pmd)) { - addr =pmd_addr_end (addr, end); + addr =kvm_pmd_addr_end (addr, end);continue ; }
@@ -151,10 +151,10 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp,/* If we emptied the pte, walk back up the ladder */ if (page_empty (pte)) {clear_pmd_entry (kvm, pmd, addr); - next =pmd_addr_end (addr, end); + next =kvm_pmd_addr_end (addr, end);if (page_empty (pmd) && !page_empty (pud)) {clear_pud_entry (kvm, pud, addr); - next =pud_addr_end (addr, end); + next =kvm_pud_addr_end (addr, end); } }
arch/arm64/include/asm/kvm_mmu.h +4 -0
@@ -115,6 +115,10 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)pte_val (*pte) |=PTE_S2_RDWR ; } +#define kvm_pgd_addr_end (addr, end) pgd_addr_end(addr, end) +#define kvm_pud_addr_end (addr, end) pud_addr_end(addr, end) +#define kvm_pmd_addr_end (addr, end) pmd_addr_end(addr, end) +struct kvm ;#define kvm_flush_dcache_to_poc (a,l) __flush_dcache_area((a), (l))
Signature · 1 line
2.3.5
PATCH 21/63 arm64: KVM: flush VM pages before letting the guest enable caches
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 9d218a1fcf4c6b759d442ef702842fae92e1ea61 upstream.
When the guest runs with caches disabled (like in an early boot sequence, for example), all the writes are diectly going to RAM, bypassing the caches altogether.
Once the MMU and caches are enabled, whatever sits in the cache becomes suddenly visible, which isn't what the guest expects.
A way to avoid this potential disaster is to invalidate the cache when the MMU is being turned on. For this, we hook into the SCTLR_EL1 trapping code, and scan the stage-2 page tables, invalidating the pages/sections that have already been mapped in.
--- arch/arm/include/asm/kvm_mmu.h | 2 + arch/arm/kvm/mmu.c | 83 ++++++++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/kvm_mmu.h | 2 + arch/arm64/kvm/sys_regs.c | 5 ++- 4 files changed, 91 insertions(+), 1 deletion(-)
arch/arm/include/asm/kvm_mmu.h +2 -0
@@ -143,6 +143,8 @@ static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva,#define kvm_flush_dcache_to_poc (a,l) __cpuc_flush_dcache_area((a), (l)) +void stage2_flush_vm (struct kvm *kvm); +#endif /* !__ASSEMBLY__ */ #endif /* __ARM_KVM_MMU_H__ */
arch/arm/kvm/mmu.c +83 -0
89 lines not on this page · raw message
arch/arm64/include/asm/kvm_mmu.h +2 -0
@@ -142,5 +142,7 @@ static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva, } } +void stage2_flush_vm (struct kvm *kvm); +#endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */
arch/arm64/kvm/sys_regs.c +4 -1
@@ -27,6 +27,7 @@#include <asm/kvm_host.h> #include <asm/kvm_emulate.h> #include <asm/kvm_coproc.h> +#include <asm/kvm_mmu.h> #include <asm/cacheflush.h> #include <asm/cputype.h> #include <trace/events/kvm.h>
@@ -154,8 +155,10 @@ static bool access_sctlr(struct kvm_vcpu *vcpu, {access_vm_reg (vcpu, p, r); -if (vcpu_has_cache_enabled (vcpu))/* MMU+Caches enabled? */ +if (vcpu_has_cache_enabled (vcpu)) {/* MMU+Caches enabled? */ vcpu->arch.hcr_el2 &= ~HCR_TVM ; +stage2_flush_vm (vcpu->kvm); + }return true; }
Signature · 1 line
2.3.5
PATCH 22/63 ARM: KVM: force cache clean on page fault when caches are off
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 159793001d7d85af17855630c94f0a176848e16b upstream.
In order for a guest with caches disabled to observe data written contained in a given page, we need to make sure that page is committed to memory, and not just hanging in the cache (as guest accesses are completely bypassing the cache until it decides to enable it).
For this purpose, hook into the coherent_cache_guest_page function and flush the region if the guest SCTLR register doesn't show the MMU and caches as being enabled.
--- arch/arm/include/asm/kvm_mmu.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_mmu.h +9 -2
@@ -118,9 +118,18 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)struct kvm ; +#define kvm_flush_dcache_to_poc (a,l) __cpuc_flush_dcache_area((a), (l)) + +static inline bool vcpu_has_cache_enabled (struct kvm_vcpu *vcpu) +{ +return (vcpu->arch.cp15[c1_SCTLR] &0b101 ) ==0b101 ; +} +static inline void coherent_cache_guest_page (struct kvm_vcpu *vcpu,hva_t hva,unsigned long size) { +if (!vcpu_has_cache_enabled (vcpu)) +kvm_flush_dcache_to_poc ((void *)hva, size);/* * If we are going to insert an instruction page and the icache is * either VIPT or PIPT, there is a potential problem where the host
@@ -141,8 +150,6 @@ static inline void coherent_cache_guest_page(struct kvm_vcpu *vcpu, hva_t hva, } } -#define kvm_flush_dcache_to_poc (a,l) __cpuc_flush_dcache_area((a), (l)) -void stage2_flush_vm (struct kvm *kvm);#endif /* !__ASSEMBLY__ */
Signature · 1 line
2.3.5
PATCH 23/63 ARM: KVM: fix handling of trapped 64bit coprocessor accesses
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 46c214dd595381c880794413facadfa07fba5c95 upstream.
Commit 240e99cbd00a (ARM: KVM: Fix 64-bit coprocessor handling) changed the way we match the 64bit coprocessor access from user space, but didn't update the trap handler for the same set of registers.
The effect is that a trapped 64bit access is never matched, leading to a fault being injected into the guest. This went unnoticed as we didn't really trap any 64bit register so far.
Placing the CRm field of the access into the CRn field of the matching structure fixes the problem. Also update the debug feature to emit the expected string in case of failing match.
--- arch/arm/kvm/coproc.c | 4 ++-- arch/arm/kvm/coproc.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/arm/kvm/coproc.c +2 -2
@@ -323,7 +323,7 @@ int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) {struct coproc_params params; - params.CRm = (kvm_vcpu_get_hsr (vcpu) >>1 ) &0xf ; + params.CRn = (kvm_vcpu_get_hsr (vcpu) >>1 ) &0xf ; params.Rt1 = (kvm_vcpu_get_hsr (vcpu) >>5 ) &0xf ; params.is_write = ((kvm_vcpu_get_hsr (vcpu) &1 ) ==0 ); params.is_64bit = true;
@@ -331,7 +331,7 @@ int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run) params.Op1 = (kvm_vcpu_get_hsr (vcpu) >>16 ) &0xf ; params.Op2 =0 ; params.Rt2 = (kvm_vcpu_get_hsr (vcpu) >>10 ) &0xf ; - params.CRn =0 ; + params.CRm =0 ;return emulate_cp15 (vcpu, ¶ms); }
arch/arm/kvm/coproc.h +2 -2
@@ -58,8 +58,8 @@ static inline void print_cp_instr(const struct coproc_params *p) {/* Look, we even formatted it for you to paste into the table! */ if (p->is_64bit) { -kvm_pr_unimpl (" { CRm(%2lu), Op1(%2lu), is64, func_%s },\n" , - p->CRm, p->Op1, p->is_write ?"write" :"read" ); +kvm_pr_unimpl (" { CRm64(%2lu), Op1(%2lu), is64, func_%s },\n" , + p->CRn, p->Op1, p->is_write ?"write" :"read" ); }else { kvm_pr_unimpl(" { CRn(%2lu), CRm(%2lu), Op1(%2lu), Op2(%2lu), is32," " func_%s },\n",
Signature · 1 line
2.3.5
PATCH 24/63 ARM: KVM: fix ordering of 64bit coprocessor accesses
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 547f781378a22b65c2ab468f235c23001b5924da upstream.
Commit 240e99cbd00a (ARM: KVM: Fix 64-bit coprocessor handling) added an ordering dependency for the 64bit registers.
The order described is: CRn, CRm, Op1, Op2, 64bit-first.
Unfortunately, the implementation is: CRn, 64bit-first, CRm...
Move the 64bit test to be last in order to match the documentation.
--- arch/arm/kvm/coproc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm/kvm/coproc.h +3 -3
@@ -135,13 +135,13 @@ static inline int cmp_reg(const struct coproc_reg *i1,return -1 ;if (i1->CRn != i2->CRn)return i1->CRn - i2->CRn; -if (i1->is_64 != i2->is_64) -return i2->is_64 - i1->is_64;if (i1->CRm != i2->CRm)return i1->CRm - i2->CRm;if (i1->Op1 != i2->Op1)return i1->Op1 - i2->Op1; -return i1->Op2 - i2->Op2; +if (i1->Op2 != i2->Op2) +return i1->Op2 - i2->Op2; +return i2->is_64 - i1->is_64; }
Signature · 1 line
2.3.5
PATCH 25/63 ARM: KVM: introduce per-vcpu HYP Configuration Register
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit ac30a11e8e92a03dbe236b285c5cbae0bf563141 upstream.
So far, KVM/ARM used a fixed HCR configuration per guest, except for the VI/VF/VA bits to control the interrupt in absence of VGIC.
With the upcoming need to dynamically reconfigure trapping, it becomes necessary to allow the HCR to be changed on a per-vcpu basis.
The fix here is to mimic what KVM/arm64 already does: a per vcpu HCR field, initialized at setup time.
--- arch/arm/include/asm/kvm_arm.h | 1 - arch/arm/include/asm/kvm_host.h | 9 ++++++--- arch/arm/kernel/asm-offsets.c | 1 + arch/arm/kvm/guest.c | 1 + arch/arm/kvm/interrupts_head.S | 9 +++------ 5 files changed, 11 insertions(+), 10 deletions(-)
arch/arm/include/asm/kvm_arm.h +0 -1
@@ -69,7 +69,6 @@#define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \ HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \ HCR_TWE | HCR_SWIO | HCR_TIDCP) -#define HCR_VIRT_EXCP_MASK (HCR_VA | HCR_VI | HCR_VF)/* System Control Register (SCTLR) bits */ #define SCTLR_TE (1 << 30)
arch/arm/include/asm/kvm_host.h +6 -3
@@ -106,6 +106,12 @@ struct kvm_vcpu_arch {/* The CPU type we expose to the VM */ u32 midr; +/* HYP trapping configuration */ +u32 hcr; + +/* Interrupt related fields */ +u32 irq_lines;/* IRQ and FIQ levels */ +/* Exception Information */ struct kvm_vcpu_fault_info fault;
@@ -133,9 +139,6 @@ struct kvm_vcpu_arch {/* IO related fields */ struct kvm_decode mmio_decode; -/* Interrupt related fields */ -u32 irq_lines;/* IRQ and FIQ levels */ -/* Cache some mmu pages needed inside spinlock regions */ struct kvm_mmu_memory_cache mmu_page_cache;
arch/arm/kernel/asm-offsets.c +1 -0
@@ -174,6 +174,7 @@ int main(void) DEFINE(VCPU_FIQ_REGS, offsetof(struct kvm_vcpu, arch.regs.fiq_regs)); DEFINE(VCPU_PC, offsetof(struct kvm_vcpu, arch.regs.usr_regs.ARM_pc)); DEFINE(VCPU_CPSR, offsetof(struct kvm_vcpu, arch.regs.usr_regs.ARM_cpsr)); + DEFINE(VCPU_HCR, offsetof(struct kvm_vcpu, arch.hcr)); DEFINE(VCPU_IRQ_LINES, offsetof(struct kvm_vcpu, arch.irq_lines)); DEFINE(VCPU_HSR, offsetof(struct kvm_vcpu, arch.fault.hsr)); DEFINE(VCPU_HxFAR, offsetof(struct kvm_vcpu, arch.fault.hxfar));
arch/arm/kvm/guest.c +1 -0
@@ -38,6 +38,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {int kvm_arch_vcpu_setup (struct kvm_vcpu *vcpu) { + vcpu->arch.hcr =HCR_GUEST_MASK ;return 0 ; }
arch/arm/kvm/interrupts_head.S +3 -6
@@ -597,17 +597,14 @@ vcpu .req r0 @ vcpu pointer always in r0 /* Enable/Disable: stage-2 trans., trap interrupts, trap wfi, trap smc */ .macro configure_hyp_role operation - mrc p15, 4, r2, c1, c1, 0 @ HCR - bic r2, r2, #HCR_VIRT_EXCP_MASK - ldr r3, =HCR_GUEST_MASK .if \operation == vmentry - orr r2, r2, r3 + ldr r2, [vcpu, #VCPU_HCR] ldr r3, [vcpu, #VCPU_IRQ_LINES] orr r2, r2, r3 .else - bic r2, r2, r3 + mov r2, #0 .endif - mcr p15, 4, r2, c1, c1, 0 + mcr p15, 4, r2, c1, c1, 0 @ HCR .endm .macro load_vcpu
Signature · 1 line
2.3.5
PATCH 26/63 ARM: KVM: add world-switch for AMAIR{0,1}
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit af20814ee927ed888288d98917a766b4179c4fe0 upstream.
HCR.TVM traps (among other things) accesses to AMAIR0 and AMAIR1. In order to minimise the amount of surprise a guest could generate by trying to access these registers with caches off, add them to the list of registers we switch/handle.
--- arch/arm/include/asm/kvm_asm.h | 4 +++- arch/arm/kvm/coproc.c | 23 +++++++++++++++++++++++ arch/arm/kvm/interrupts_head.S | 12 ++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-)
arch/arm/include/asm/kvm_asm.h +3 -1
@@ -48,7 +48,9 @@#define c13_TID_URO 26/* Thread ID, User R/O */ #define c13_TID_PRIV 27/* Thread ID, Privileged */ #define c14_CNTKCTL 28/* Timer Control Register (PL1) */ -#define NR_CP15_REGS 29/* Number of regs (incl. invalid) */ +#define c10_AMAIR0 29/* Auxilary Memory Attribute Indirection Reg0 */ +#define c10_AMAIR1 30/* Auxilary Memory Attribute Indirection Reg1 */ +#define NR_CP15_REGS 31/* Number of regs (incl. invalid) */ #define ARM_EXCEPTION_RESET 0#define ARM_EXCEPTION_UNDEFINED 1
arch/arm/kvm/coproc.c +23 -0
@@ -113,6 +113,23 @@ done: }/* +* Generic accessor for VM registers. Only called as long as HCR_TVM +* is set. +*/ +static bool access_vm_reg (struct kvm_vcpu *vcpu, +const struct coproc_params *p, +const struct coproc_reg *r) +{ +BUG_ON (!p->is_write); + + vcpu->arch.cp15[r->reg] = *vcpu_reg (vcpu, p->Rt1); +if (p->is_64bit) + vcpu->arch.cp15[r->reg +1 ] = *vcpu_reg (vcpu, p->Rt2); + +return true; +} + +/* * We could trap ID_DFR0 and tell the guest we don't support performance * monitoring. Unfortunately the patch to make the kernel check ID_DFR0 was * NAKed, so it will read the PMCR anyway.
@@ -217,6 +234,12 @@ static const struct coproc_reg cp15_regs[] = { {CRn (10 ),CRm (2 ),Op1 (0 ),Op2 (1 ), is32, NULL, reset_unknown, c10_NMRR}, +/* AMAIR0/AMAIR1: swapped by interrupt.S. */ + { CRn(10), CRm( 3), Op1( 0), Op2( 0), is32, + access_vm_reg, reset_unknown, c10_AMAIR0}, + { CRn(10), CRm( 3), Op1( 0), Op2( 1), is32, + access_vm_reg, reset_unknown, c10_AMAIR1}, +/* VBAR: swapped by interrupt.S. */ { CRn(12), CRm( 0), Op1( 0), Op2( 0), is32, NULL, reset_val, c12_VBAR, 0x00000000 },
arch/arm/kvm/interrupts_head.S +10 -2
@@ -303,13 +303,17 @@ vcpu .req r0 @ vcpu pointer always in r0 mrc p15, 0, r2, c14, c1, 0 @ CNTKCTL mrrc p15, 0, r4, r5, c7 @ PAR + mrc p15, 0, r6, c10, c3, 0 @ AMAIR0 + mrc p15, 0, r7, c10, c3, 1 @ AMAIR1 .if \store_to_vcpu == 0 - push {r2,r4-r5} + push {r2,r4-r7} .else str r2, [vcpu, #CP15_OFFSET(c14_CNTKCTL)] add r12, vcpu, #CP15_OFFSET(c7_PAR) strd r4, r5, [r12] + str r6, [vcpu, #CP15_OFFSET(c10_AMAIR0)] + str r7, [vcpu, #CP15_OFFSET(c10_AMAIR1)] .endif .endm
@@ -322,15 +326,19 @@ vcpu .req r0 @ vcpu pointer always in r0 */ .macro write_cp15_state read_from_vcpu .if \read_from_vcpu == 0 - pop {r2,r4-r5} + pop {r2,r4-r7} .else ldr r2, [vcpu, #CP15_OFFSET(c14_CNTKCTL)] add r12, vcpu, #CP15_OFFSET(c7_PAR) ldrd r4, r5, [r12] + ldr r6, [vcpu, #CP15_OFFSET(c10_AMAIR0)] + ldr r7, [vcpu, #CP15_OFFSET(c10_AMAIR1)] .endif mcr p15, 0, r2, c14, c1, 0 @ CNTKCTL mcrr p15, 0, r4, r5, c7 @ PAR + mcr p15, 0, r6, c10, c3, 0 @ AMAIR0 + mcr p15, 0, r7, c10, c3, 1 @ AMAIR1 .if \read_from_vcpu == 0 pop {r2-r12}
Signature · 1 line
2.3.5
PATCH 27/63 ARM: KVM: trap VM system registers until MMU and caches are ON
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 8034699a42d68043b495c7e0cfafccd920707ec8 upstream.
In order to be able to detect the point where the guest enables its MMU and caches, trap all the VM related system registers.
Once we see the guest enabling both the MMU and the caches, we can go back to a saner mode of operation, which is to leave these registers in complete control of the guest.
--- arch/arm/include/asm/kvm_arm.h | 3 ++- arch/arm/kvm/coproc.c | 60 +++++++++++++++++++++++++++++------------- arch/arm/kvm/coproc.h | 4 +++ arch/arm/kvm/coproc_a15.c | 2 +- 4 files changed, 49 insertions(+), 20 deletions(-)
arch/arm/include/asm/kvm_arm.h +2 -1
@@ -55,6 +55,7 @@* The bits we set in HCR: * TAC: Trap ACTLR * TSC: Trap SMC +* TVM: Trap VM ops (until MMU and caches are on) * TSW: Trap cache operations by set/way * TWI: Trap WFI * TWE: Trap WFE
@@ -68,7 +69,7 @@*/ #define HCR_GUEST_MASK (HCR_TSC | HCR_TSW | HCR_TWI | HCR_VM | HCR_BSU_IS | \ HCR_FB | HCR_TAC | HCR_AMO | HCR_IMO | HCR_FMO | \ - HCR_TWE | HCR_SWIO | HCR_TIDCP) + HCR_TVM | HCR_TWE | HCR_SWIO | HCR_TIDCP)/* System Control Register (SCTLR) bits */ #define SCTLR_TE (1 << 30)
arch/arm/kvm/coproc.c +42 -18
111 lines not on this page · raw message
arch/arm/kvm/coproc.h +4 -0
@@ -153,4 +153,8 @@ static inline int cmp_reg(const struct coproc_reg *i1,#define is64 .is_64 = true#define is32 .is_64 = false +bool access_sctlr (struct kvm_vcpu *vcpu, +const struct coproc_params *p, +const struct coproc_reg *r); +#endif /* __ARM_KVM_COPROC_LOCAL_H__ */
arch/arm/kvm/coproc_a15.c +1 -1
@@ -130,7 +130,7 @@ static const struct coproc_reg a15_regs[] = {/* SCTLR: swapped by interrupt.S. */ {CRn (1 ),CRm (0 ),Op1 (0 ),Op2 (0 ), is32, - NULL, reset_val, c1_SCTLR, 0x00C50078 }, + access_sctlr, reset_val, c1_SCTLR, 0x00C50078 },/* ACTLR: trapped by HCR.TAC bit. */ { CRn( 1), CRm( 0), Op1( 0), Op2( 1), is32, access_actlr, reset_actlr, c1_ACTLR },
Signature · 1 line
2.3.5
PATCH 28/63 ARM: KVM: fix non-VGIC compilation
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 6cbde8253a8143ada18ec0d1711230747a7c1934 upstream.
Add a stub for kvm_vgic_addr when compiling without CONFIG_KVM_ARM_VGIC. The usefulness of this configurarion is extremely doubtful, but let's fix it anyway (until we decide that we'll always support a VGIC).
--- include/kvm/arm_vgic.h | 5 +++++ 1 file changed, 5 insertions(+)
include/kvm/arm_vgic.h +5 -0
@@ -171,6 +171,11 @@ static inline int kvm_vgic_set_addr(struct kvm *kvm, unsigned long type, u64 addreturn 0 ; } +static inline int kvm_vgic_addr (struct kvm *kvm,unsigned long type,u64 *addr,bool write) +{ +return -ENXIO ; +} +static inline int kvm_vgic_init (struct kvm *kvm) {return 0 ;
Signature · 1 line
2.3.5
PATCH 29/63 ARM: KVM: disable KVM in Kconfig on big-endian systems
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 4e4468fac4381b92eb333d94256e7fb8350f3de3 upstream.
KVM currently crashes and burns on big-endian hosts, so don't allow it to be selected until we've got that fixed.
--- arch/arm/kvm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kvm/Kconfig +1 -1
@@ -23,7 +23,7 @@ config KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST - depends on ARM_VIRT_EXT && ARM_LPAE + depends on ARM_VIRT_EXT && ARM_LPAE && !CPU_BIG_ENDIAN ---help--- Support hosting virtualized guest machines. You will also need to select one or more of the processor modules below.
Signature · 1 line
2.3.5
PATCH 30/63 KVM: arm/arm64: vgic: fix GICD_ICFGR register accesses
In reply to Jiri SlabyFrom: Andre Przywara <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit f2ae85b2ab3776b9e4e42e5b6fa090f40d396794 upstream.
Since KVM internally represents the ICFGR registers by stuffing two of them into one word, the offset for accessing the internal representation and the one for the MMIO based access are different. So keep the original offset around, but adjust the internal array offset by one bit.
--- virt/kvm/arm/vgic.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
virt/kvm/arm/vgic.c +4 -5
@@ -543,11 +543,10 @@ static bool handle_mmio_cfg_reg(struct kvm_vcpu *vcpu,u32 val;u32 *reg; - offset >>=1 ; reg =vgic_bitmap_get_reg (&vcpu->kvm->arch.vgic.irq_cfg, - vcpu->vcpu_id, offset); + vcpu->vcpu_id, offset >>1 ); -if (offset &2 ) +if (offset &4 ) val = *reg >>16 ;else val = *reg &0xffff ;
@@ -556,13 +555,13 @@ static bool handle_mmio_cfg_reg(struct kvm_vcpu *vcpu,vgic_reg_access (mmio, &val, offset,ACCESS_READ_VALUE |ACCESS_WRITE_VALUE );if (mmio->is_write) { -if (offset <4 ) { +if (offset <8 ) { *reg = ~0U ;/* Force PPIs/SGIs to 1 */ return false; } val =vgic_cfg_compress (val); -if (offset &2 ) { +if (offset &4 ) { *reg &=0xffff ; *reg |= val <<16 ; }else {
Signature · 1 line
2.3.5
PATCH 31/63 KVM: ARM: vgic: Fix the overlap check action about setting the GICD & GICC base address.
In reply to Jiri SlabyFrom: Haibin Wang <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 30c2117085bc4e05d091cee6eba79f069b41a9cd upstream.
Currently below check in vgic_ioaddr_overlap will always succeed, because the vgic dist base and vgic cpu base are still kept UNDEF after initialization. The code as follows will be return forever.
if (IS_VGIC_ADDR_UNDEF(dist) || IS_VGIC_ADDR_UNDEF(cpu))
return 0;So, before invoking the vgic_ioaddr_overlap, it needs to set the corresponding base address firstly.
--- virt/kvm/arm/vgic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic.c +3 -2
@@ -1475,10 +1475,11 @@ static int vgic_ioaddr_assign(struct kvm *kvm, phys_addr_t *ioaddr,if (addr + size < addr)return -EINVAL ; + *ioaddr = addr; ret =vgic_ioaddr_overlap (kvm);if (ret) -return ret; - *ioaddr = addr; + *ioaddr =VGIC_ADDR_UNDEF ; +return ret; }
Signature · 1 line
2.3.5
PATCH 32/63 arm64: kvm: use inner-shareable barriers for inner-shareable maintenance
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit ee9e101c11478680d579bd20bb38a4d3e2514fe3 upstream.
In order to ensure completion of inner-shareable maintenance instructions (cache and TLB) on AArch64, we can use the -ish suffix to the dsb instruction.
This patch relaxes our dsb sy instructions to dsb ish where possible.
--- arch/arm64/kvm/hyp.S | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/arm64/kvm/hyp.S +9 -3
@@ -617,9 +617,15 @@ ENTRY(__kvm_tlb_flush_vmid_ipa) * whole of Stage-1. Weep... */ tlbi ipas2e1is, x1 - dsb sy + /* + * We have to ensure completion of the invalidation at Stage-2, + * since a table walk on another CPU could refill a TLB with a + * complete (S1 + S2) walk based on the old Stage-2 mapping if + * the Stage-1 invalidation happened first. + */ + dsb ish tlbi vmalle1is - dsb sy + dsb ish isb msr vttbr_el2, xzr
@@ -630,7 +636,7 @@ ENTRY(__kvm_flush_vm_context) dsb ishst tlbi alle1is ic ialluis - dsb sy + dsb ish ret ENDPROC(__kvm_flush_vm_context)
Signature · 1 line
2.3.5
PATCH 33/63 kvm: arm64: vgic: fix hyp panic with 64k pages on juno platform
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 63afbe7a0ac184ef8485dac4914e87b211b5bfaa upstream.
If the physical address of GICV isn't page-aligned, then we end up creating a stage-2 mapping of the page containing it, which causes us to map neighbouring memory locations directly into the guest.
As an example, consider a platform with GICV at physical 0x2c02f000 running a 64k-page host kernel. If qemu maps this into the guest at 0x80010000, then guest physical addresses 0x80010000 - 0x8001efff will map host physical region 0x2c020000 - 0x2c02efff. Accesses to these physical regions may cause UNPREDICTABLE behaviour, for example, on the Juno platform this will cause an SError exception to EL3, which brings down the entire physical CPU resulting in RCU stalls / HYP panics / host crashing / wasted weeks of debugging.
SBSA recommends that systems alias the 4k GICV across the bounding 64k region, in which case GICV physical could be described as 0x2c020000 in the above scenario.
This patch fixes the problem by failing the vgic probe if the physical base address or the size of GICV aren't page-aligned. Note that this generated a warning in dmesg about freeing enabled IRQs, so I had to move the IRQ enabling later in the probe.
--- virt/kvm/arm/vgic.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
virt/kvm/arm/vgic.c +20 -4
@@ -1365,17 +1365,33 @@ int kvm_vgic_hyp_init(void) goto out_unmap; } -kvm_info ("%s@%llx IRQ%d\n" , vgic_node->name, - vctrl_res.start, vgic_maint_irq); -on_each_cpu (vgic_init_maintenance_interrupt,NULL ,1 ); -if (of_address_to_resource (vgic_node,3 , &vcpu_res)) {kvm_err ("Cannot obtain VCPU resource\n" ); ret = -ENXIO ; goto out_unmap; } + +if (!PAGE_ALIGNED (vcpu_res.start)) { +kvm_err ("GICV physical address 0x%llx not page aligned\n" , + (unsigned long long )vcpu_res.start); + ret = -ENXIO ; + goto out_unmap; + } + +if (!PAGE_ALIGNED (resource_size (&vcpu_res))) { +kvm_err ("GICV size 0x%llx not a multiple of page size 0x%lx\n" , + (unsigned long long )resource_size (&vcpu_res), +PAGE_SIZE ); + ret = -ENXIO ; + goto out_unmap; + } + vgic_vcpu_base = vcpu_res.start; +kvm_info ("%s@%llx IRQ%d\n" , vgic_node->name, + vctrl_res.start, vgic_maint_irq); +on_each_cpu (vgic_init_maintenance_interrupt,NULL ,1 ); + goto out; out_unmap:
Signature · 1 line
2.3.5
PATCH 34/63 arm/arm64: KVM: Fix and refactor unmap_range
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 4f853a714bf16338ff5261128e6c7ae2569e9505 upstream.
unmap_range() was utterly broken, to quote Marc, and broke in all sorts of situations. It was also quite complicated to follow and didn't follow the usual scheme of having a separate iterating function for each level of page tables.
Address this by refactoring the code and introduce a pgd_clear() function.
--- arch/arm/include/asm/kvm_mmu.h | 11 ++++ arch/arm/kvm/mmu.c | 106 +++++++++++++++++++++++---------------- arch/arm64/include/asm/kvm_mmu.h | 14 ++++++ 3 files changed, 89 insertions(+), 42 deletions(-)
arch/arm/include/asm/kvm_mmu.h +11 -0
@@ -116,6 +116,17 @@ static inline void kvm_set_s2pte_writable(pte_t *pte) (__boundary -1 < (end) -1 )? __boundary: (end); \ }) +static inline bool kvm_page_empty (void *ptr) +{ +struct page *ptr_page =virt_to_page (ptr); +return page_count (ptr_page) ==1 ; +} + + +#define kvm_pte_table_empty (ptep) kvm_page_empty(ptep) +#define kvm_pmd_table_empty (pmdp) kvm_page_empty(pmdp) +#define kvm_pud_table_empty (pudp) (0) +struct kvm ;#define kvm_flush_dcache_to_poc (a,l) __cpuc_flush_dcache_area((a), (l))
arch/arm/kvm/mmu.c +64 -42
129 lines not on this page · raw message
arch/arm64/include/asm/kvm_mmu.h +14 -0
@@ -119,6 +119,20 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)#define kvm_pud_addr_end (addr, end) pud_addr_end(addr, end)#define kvm_pmd_addr_end (addr, end) pmd_addr_end(addr, end) +static inline bool kvm_page_empty (void *ptr) +{ +struct page *ptr_page =virt_to_page (ptr); +return page_count (ptr_page) ==1 ; +} + +#define kvm_pte_table_empty (ptep) kvm_page_empty(ptep) +#ifndef CONFIG_ARM64_64K_PAGES +#define kvm_pmd_table_empty (pmdp) kvm_page_empty(pmdp) +#else +#define kvm_pmd_table_empty (pmdp) (0) +#endif +#define kvm_pud_table_empty (pudp) (0) +struct kvm ;#define kvm_flush_dcache_to_poc (a,l) __flush_dcache_area((a), (l))
Signature · 1 line
2.3.5
PATCH 35/63 ARM: KVM: Unmap IPA on memslot delete/move
In reply to Jiri SlabyFrom: Eric Auger <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit df6ce24f2ee485c4f9a5cb610063a5eb60da8267 upstream.
Currently when a KVM region is deleted or moved after KVM_SET_USER_MEMORY_REGION ioctl, the corresponding intermediate physical memory is not unmapped.
This patch corrects this and unmaps the region's IPA range in kvm_arch_commit_memory_region using unmap_stage2_range.
--- arch/arm/kvm/arm.c | 37 ------------------------------------- arch/arm/kvm/mmu.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 37 deletions(-)
arch/arm/kvm/arm.c +0 -37
@@ -155,16 +155,6 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, -struct kvm_memory_slot *dont) -{ -} - -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) -{ -return 0 ; -} -/** * kvm_arch_destroy_vm - destroy the VM data structure * @kvm: pointer to the KVM struct
@@ -222,33 +212,6 @@ long kvm_arch_dev_ioctl(struct file *filp,return -EINVAL ; } -void kvm_arch_memslots_updated (struct kvm *kvm) -{ -} - -int kvm_arch_prepare_memory_region (struct kvm *kvm, -struct kvm_memory_slot *memslot, -struct kvm_userspace_memory_region *mem, -enum kvm_mr_change change) -{ -return 0 ; -} - -void kvm_arch_commit_memory_region (struct kvm *kvm, -struct kvm_userspace_memory_region *mem, -const struct kvm_memory_slot *old, -enum kvm_mr_change change) -{ -} - -void kvm_arch_flush_shadow_all (struct kvm *kvm) -{ -} - -void kvm_arch_flush_shadow_memslot (struct kvm *kvm, -struct kvm_memory_slot *slot) -{ -}struct kvm_vcpu *kvm_arch_vcpu_create (struct kvm *kvm,unsigned int id) {
arch/arm/kvm/mmu.c +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.3.5
PATCH 36/63 ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping
In reply to Jiri SlabyFrom: Kim Phillips <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit b88657674d39fc2127d62d0de9ca142e166443c8 upstream.
A userspace process can map device MMIO memory via VFIO or /dev/mem, e.g., for platform device passthrough support in QEMU.
During early development, we found the PAGE_S2 memory type being used for MMIO mappings. This patch corrects that by using the more strongly ordered memory type for device MMIO mappings: PAGE_S2_DEVICE.
--- arch/arm/kvm/mmu.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/kvm/mmu.c +7 -2
@@ -647,6 +647,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,unsigned long mmu_seq;unsigned long hva =gfn_to_hva (vcpu->kvm, gfn);struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; +pgprot_t mem_type =PAGE_S2 ; write_fault =kvm_is_write_fault (kvm_vcpu_get_hsr (vcpu));if (fault_status ==FSC_PERM && !write_fault) {
@@ -675,7 +676,10 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (is_error_pfn (pfn))return -EFAULT ; - new_pte =pfn_pte (pfn,PAGE_S2 ); +if (kvm_is_mmio_pfn (pfn)) + mem_type =PAGE_S2_DEVICE ; + + new_pte =pfn_pte (pfn, mem_type);coherent_cache_guest_page (vcpu, hva,PAGE_SIZE );spin_lock (&vcpu->kvm->mmu_lock);
@@ -685,7 +689,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,kvm_set_s2pte_writable (&new_pte);kvm_set_pfn_dirty (pfn); } -stage2_set_pte (vcpu->kvm, memcache, fault_ipa, &new_pte, false); +stage2_set_pte (vcpu->kvm, memcache, fault_ipa, &new_pte, + mem_type ==PAGE_S2_DEVICE ); out_unlock:spin_unlock (&vcpu->kvm->mmu_lock);
Signature · 1 line
2.3.5
PATCH 37/63 arm64: KVM: export demux regids as KVM_REG_ARM64
In reply to Jiri SlabyFrom: Alex Bennée <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit efd48ceacea78e4d4656aa0a6bf4c5b92ed22130 upstream.
I suspect this is a -ECUTPASTE fault from the initial implementation. If we don't declare the register ID to be KVM_REG_ARM64 the KVM_GET_ONE_REG implementation kvm_arm_get_reg() returns -EINVAL and hilarity ensues.
The kvm/api.txt document describes all arm64 registers as starting with 0x60xx... (i.e KVM_REG_ARM64).
--- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +1 -1
@@ -962,7 +962,7 @@ static unsigned int num_demux_regs(void)static int write_demux_regids (u64 __user *uindices) { -u64 val =KVM_REG_ARM |KVM_REG_SIZE_U32 |KVM_REG_ARM_DEMUX ; +u64 val =KVM_REG_ARM64 |KVM_REG_SIZE_U32 |KVM_REG_ARM_DEMUX ;unsigned int i; val |=KVM_REG_ARM_DEMUX_ID_CCSIDR ;
Signature · 1 line
2.3.5
PATCH 38/63 ARM: virt: fix wrong HSCTLR.EE bit setting
In reply to Jiri SlabyFrom: Li Liu <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit af92394efc8be73edd2301fc15f9b57fd430cd18 upstream.
HSCTLR.EE is defined as bit[25] referring to arm manual DDI0606C.b(p1590).
--- arch/arm/kernel/hyp-stub.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kernel/hyp-stub.S +1 -1
@@ -135,7 +135,7 @@ ENTRY(__hyp_stub_install_secondary) THUMB( orr r7, #(1 << 30) ) @ HSCTLR.TE #ifdef CONFIG_CPU_BIG_ENDIAN - orr r7, #(1 << 9) @ HSCTLR.EE + orr r7, r7, #(1 << 25) @ HSCTLR.EE #endif mcr p15, 4, r7, c1, c0, 0 @ HSCTLR
Signature · 1 line
2.3.5
PATCH 39/63 ARM64: KVM: store kvm_vcpu_fault_info est_el2 as word
In reply to Jiri SlabyFrom: Victor Kamensky <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit ba083d20d8cfa9e999043cd89c4ebc964ccf8927 upstream.
esr_el2 field of struct kvm_vcpu_fault_info has u32 type. It should be stored as word. Current code works in LE case because existing puts least significant word of x1 into esr_el2, and it puts most significant work of x1 into next field, which accidentally is OK because it is updated again by next instruction. But existing code breaks in BE case.
--- arch/arm64/kvm/hyp.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/hyp.S +1 -1
@@ -817,7 +817,7 @@ el1_trap: mrs x2, far_el2 2: mrs x0, tpidr_el2 - str x1, [x0, #VCPU_ESR_EL2] + str w1, [x0, #VCPU_ESR_EL2] str x2, [x0, #VCPU_FAR_EL2] str x3, [x0, #VCPU_HPFAR_EL2]
Signature · 1 line
2.3.5
PATCH 40/63 KVM: ARM/arm64: fix non-const declaration of function returning const
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 6951e48bff0b55d2a8e825a953fc1f8e3a34bf1c upstream.
Sparse kicks up about a type mismatch for kvm_target_cpu:
arch/arm64/kvm/guest.c:271:25: error: symbol 'kvm_target_cpu' redeclared with different type (originally declared at ./arch/arm64/include/asm/kvm_host.h:45) - different modifiers
so fix this by adding the missing const attribute to the function declaration.
--- arch/arm/include/asm/kvm_host.h | 2 +- arch/arm64/include/asm/kvm_host.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_host.h +1 -1
@@ -47,7 +47,7 @@struct kvm_vcpu ;u32 *kvm_vcpu_reg (struct kvm_vcpu *vcpu,u8 reg_num,u32 mode); -int kvm_target_cpu (void ); +int __attribute_const__ kvm_target_cpu(void);int kvm_reset_vcpu (struct kvm_vcpu *vcpu);void kvm_reset_coprocs (struct kvm_vcpu *vcpu);
arch/arm64/include/asm/kvm_host.h +1 -1
@@ -42,7 +42,7 @@#define KVM_PAGES_PER_HPAGE (x) (1UL<<31)struct kvm_vcpu ; -int kvm_target_cpu (void ); +int __attribute_const__ kvm_target_cpu(void);int kvm_reset_vcpu (struct kvm_vcpu *vcpu);int kvm_arch_dev_ioctl_check_extension (long ext);
Signature · 1 line
2.3.5
PATCH 41/63 KVM: ARM/arm64: fix broken __percpu annotation
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 4000be423cb01a8d09de878bb8184511c49d4238 upstream.
Running sparse results in a bunch of noisy address space mismatches thanks to the broken __percpu annotation on kvm_get_running_vcpus.
This function returns a pcpu pointer to a pointer, not a pointer to a pcpu pointer. This patch fixes the annotation, which kills the warnings from sparse.
--- arch/arm/kvm/arm.c | 2 +- arch/arm64/include/asm/kvm_host.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/kvm/arm.c +1 -1
@@ -82,7 +82,7 @@ struct kvm_vcpu *kvm_arm_get_running_vcpu(void)/** * kvm_arm_get_running_vcpus - get the per-CPU array of currently running vcpus. */ -struct kvm_vcpu __percpu **kvm_get_running_vcpus (void ) +struct kvm_vcpu *__percpu *kvm_get_running_vcpus (void ) {return &kvm_arm_running_vcpu; }
arch/arm64/include/asm/kvm_host.h +1 -1
@@ -176,7 +176,7 @@ static inline int kvm_test_age_hva(struct kvm *kvm, unsigned long hva) }struct kvm_vcpu *kvm_arm_get_running_vcpu (void ); -struct kvm_vcpu __percpu **kvm_get_running_vcpus (void ); +struct kvm_vcpu *__percpu *kvm_get_running_vcpus (void );u64 kvm_call_hyp (void *hypfn, ...);
Signature · 1 line
2.3.5
PATCH 42/63 KVM: ARM/arm64: avoid returning negative error code as bool
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 18d457661fb9fa69352822ab98d39331c3d0e571 upstream.
is_valid_cache returns true if the specified cache is valid. Unfortunately, if the parameter passed it out of range, we return -ENOENT, which ends up as true leading to potential hilarity.
This patch returns false on the failure path instead.
--- arch/arm/kvm/coproc.c | 2 +- arch/arm64/kvm/sys_regs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/kvm/coproc.c +1 -1
@@ -621,7 +621,7 @@ static bool is_valid_cache(u32 val)u32 level, ctype;if (val >=CSSELR_MAX ) -return -ENOENT ; +return false;/* Bottom bit is Instruction or Data bit. Next 3 bits are level. */ level = (val >>1 );
arch/arm64/kvm/sys_regs.c +1 -1
@@ -836,7 +836,7 @@ static bool is_valid_cache(u32 val)u32 level, ctype;if (val >=CSSELR_MAX ) -return -ENOENT ; +return false;/* Bottom bit is Instruction or Data bit. Next 3 bits are level. */ level = (val >>1 );
Signature · 1 line
2.3.5
PATCH 43/63 KVM: vgic: return int instead of bool when checking I/O ranges
In reply to Jiri SlabyFrom: Will Deacon <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 1fa451bcc67fa921a04c5fac8dbcde7844d54512 upstream.
vgic_ioaddr_overlap claims to return a bool, but in reality it returns an int. Shut sparse up by fixing the type signature.
--- virt/kvm/arm/vgic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/vgic.c +1 -1
@@ -1468,7 +1468,7 @@ out:return ret; } -static bool vgic_ioaddr_overlap (struct kvm *kvm) +static int vgic_ioaddr_overlap (struct kvm *kvm) {phys_addr_t dist = kvm->arch.vgic.vgic_dist_base;phys_addr_t cpu = kvm->arch.vgic.vgic_cpu_base;
Signature · 1 line
2.3.5
PATCH 44/63 ARM/ARM64: KVM: Nuke Hyp-mode tlbs before enabling MMU
In reply to Jiri SlabyFrom: Pranavkumar Sawargaonkar <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit f6edbbf36da3a27b298b66c7955fc84e1dcca305 upstream.
X-Gene u-boot runs in EL2 mode with MMU enabled hence we might have stale EL2 tlb enteris when we enable EL2 MMU on each host CPU.
This can happen on any ARM/ARM64 board running bootloader in Hyp-mode (or EL2-mode) with MMU enabled.
This patch ensures that we flush all Hyp-mode (or EL2-mode) TLBs on each host CPU before enabling Hyp-mode (or EL2-mode) MMU.
--- arch/arm/kvm/init.S | 4 ++++ arch/arm64/kvm/hyp-init.S | 4 ++++ 2 files changed, 8 insertions(+)
arch/arm/kvm/init.S +4 -0
@@ -98,6 +98,10 @@ __do_hyp_init: mrc p15, 0, r0, c10, c2, 1 mcr p15, 4, r0, c10, c2, 1 + @ Invalidate the stale TLBs from Bootloader + mcr p15, 4, r0, c8, c7, 0 @ TLBIALLH + dsb ish + @ Set the HSCTLR to: @ - ARM/THUMB exceptions: Kernel config (Thumb-2 kernel) @ - Endianness: Kernel config
arch/arm64/kvm/hyp-init.S +4 -0
@@ -74,6 +74,10 @@ __do_hyp_init: msr mair_el2, x4 isb + /* Invalidate the stale TLBs from Bootloader */ + tlbi alle2 + dsb sy + mov x4, #SCTLR_EL2_FLAGS msr sctlr_el2, x4 isb
Signature · 1 line
2.3.5
PATCH 45/63 arm/arm64: KVM: Complete WFI/WFE instructions
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 05e0127f9e362b36aa35f17b1a3d52bca9322a3a upstream.
The architecture specifies that when the processor wakes up from a WFE or WFI instruction, the instruction is considered complete, however we currrently return to EL1 (or EL0) at the WFI/WFE instruction itself.
While most guests may not be affected by this because their local exception handler performs an exception returning setting the event bit or with an interrupt pending, some guests like UEFI will get wedged due this little mishap.
Simply skip the instruction when we have completed the emulation.
--- arch/arm/kvm/handle_exit.c | 2 ++ arch/arm64/kvm/handle_exit.c | 2 ++ 2 files changed, 4 insertions(+)
arch/arm/kvm/handle_exit.c +2 -0
@@ -89,6 +89,8 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)else kvm_vcpu_block (vcpu); +kvm_skip_instr (vcpu,kvm_vcpu_trap_il_is32bit (vcpu)); +return 1 ; }
arch/arm64/kvm/handle_exit.c +2 -0
@@ -62,6 +62,8 @@ static int kvm_handle_wfx(struct kvm_vcpu *vcpu, struct kvm_run *run)else kvm_vcpu_block (vcpu); +kvm_skip_instr (vcpu,kvm_vcpu_trap_il_is32bit (vcpu)); +return 1 ; }
Signature · 1 line
2.3.5
PATCH 46/63 ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault()
In reply to Jiri SlabyFrom: Ard Biesheuvel <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit a7d079cea2dffb112e26da2566dd84c0ef1fce97 upstream.
The ISS encoding for an exception from a Data Abort has a WnR bit[6] that indicates whether the Data Abort was caused by a read or a write instruction. While there are several fields in the encoding that are only valid if the ISV bit[24] is set, WnR is not one of them, so we can read it unconditionally.
Instead of fixing both implementations of kvm_is_write_fault() in place, reimplement it just once using kvm_vcpu_dabt_iswrite(), which already does the right thing with respect to the WnR bit. Also fix up the callers to pass 'vcpu'
--- arch/arm/include/asm/kvm_mmu.h | 11 ----------- arch/arm/kvm/mmu.c | 10 +++++++++- arch/arm64/include/asm/kvm_mmu.h | 13 ------------- 3 files changed, 9 insertions(+), 25 deletions(-)
arch/arm/include/asm/kvm_mmu.h +0 -11
@@ -72,17 +72,6 @@ static inline void kvm_set_pte(pte_t *pte, pte_t new_pte)flush_pmd_entry (pte); } -static inline bool kvm_is_write_fault (unsigned long hsr) -{ -unsigned long hsr_ec = hsr >>HSR_EC_SHIFT ; -if (hsr_ec ==HSR_EC_IABT ) -return false; -else if ((hsr &HSR_ISV ) && !(hsr &HSR_WNR )) -return false; -else -return true; -} -static inline void kvm_clean_pgd (pgd_t *pgd) {clean_dcache_area (pgd,PTRS_PER_S2_PGD *sizeof (pgd_t));
arch/arm/kvm/mmu.c +9 -1
@@ -636,6 +636,14 @@ out:return ret; } +static bool kvm_is_write_fault (struct kvm_vcpu *vcpu) +{ +if (kvm_vcpu_trap_is_iabt (vcpu)) +return false; + +return kvm_vcpu_dabt_iswrite (vcpu); +} +static int user_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa,gfn_t gfn,struct kvm_memory_slot *memslot,unsigned long fault_status)
@@ -649,7 +657,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache;pgprot_t mem_type =PAGE_S2 ; - write_fault =kvm_is_write_fault (kvm_vcpu_get_hsr (vcpu)); + write_fault =kvm_is_write_fault (vcpu);if (fault_status ==FSC_PERM && !write_fault) {kvm_err ("Unexpected L2 read permission error\n" );return -EFAULT ;
arch/arm64/include/asm/kvm_mmu.h +0 -13
@@ -92,19 +92,6 @@ void kvm_clear_hyp_idmap(void);#define kvm_set_pte (ptep, pte) set_pte(ptep, pte) -static inline bool kvm_is_write_fault (unsigned long esr) -{ -unsigned long esr_ec = esr >>ESR_EL2_EC_SHIFT ; - -if (esr_ec ==ESR_EL2_EC_IABT ) -return false; - -if ((esr &ESR_EL2_ISV ) && !(esr &ESR_EL2_WNR )) -return false; - -return true; -} -static inline void kvm_clean_pgd (pgd_t *pgd) {}static inline void kvm_clean_pmd_entry (pmd_t *pmd) {}static inline void kvm_clean_pte (pte_t *pte) {}
Signature · 1 line
2.3.5
PATCH 47/63 KVM: ARM: vgic: plug irq injection race
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 71afaba4a2e98bb7bdeba5078370ab43d46e67a1 upstream.
As it stands, nothing prevents userspace from injecting an interrupt before the guest's GIC is actually initialized.
This goes unnoticed so far (as everything is pretty much statically allocated), but ends up exploding in a spectacular way once we switch to a more dynamic allocation (the GIC data structure isn't there yet).
The fix is to test for the "ready" flag in the VGIC distributor before trying to inject the interrupt. Note that in order to avoid breaking userspace, we have to ignore what is essentially an error.
--- virt/kvm/arm/vgic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic.c +2 -1
@@ -1226,7 +1226,8 @@ out:int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int irq_num,bool level) { -if (vgic_update_irq_state (kvm, cpuid, irq_num, level)) +if (likely (vgic_initialized (kvm)) && +vgic_update_irq_state (kvm, cpuid, irq_num, level))vgic_kick_vcpus (kvm);return 0 ;
Signature · 1 line
2.3.5
PATCH 48/63 arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc
In reply to Jiri SlabyFrom: Joel Schopp <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit dbff124e29fa24aff9705b354b5f4648cd96e0bb upstream.
The current aarch64 calculation for VTTBR_BADDR_MASK masks only 39 bits and not all the bits in the PA range. This is clearly a bug that manifests itself on systems that allocate memory in the higher address space range.
[ Modified from Joel's original patch to be based on PHYS_MASK_SHIFT
instead of a hard-coded value and to move the alignment check of the allocation to mmu.c. Also added a comment explaining why we hardcode the IPA range and changed the stage-2 pgd allocation to be based on the 40 bit IPA range instead of the maximum possible 48 bit PA range.
- Christoffer ]
--- arch/arm/kvm/arm.c | 4 ++-- arch/arm64/include/asm/kvm_arm.h | 13 ++++++++++++- arch/arm64/include/asm/kvm_mmu.h | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-)
arch/arm/kvm/arm.c +2 -2
@@ -425,9 +425,9 @@ static void update_vttbr(struct kvm *kvm)/* update vttbr to be used with the new vmid */ pgd_phys =virt_to_phys (kvm->arch.pgd); +BUG_ON (pgd_phys & ~VTTBR_BADDR_MASK ); vmid = ((u64)(kvm->arch.vmid) <<VTTBR_VMID_SHIFT ) &VTTBR_VMID_MASK ; - kvm->arch.vttbr = pgd_phys &VTTBR_BADDR_MASK ; - kvm->arch.vttbr |= vmid; + kvm->arch.vttbr = pgd_phys | vmid;spin_unlock (&kvm_vmid_lock); }
arch/arm64/include/asm/kvm_arm.h +12 -1
@@ -122,6 +122,17 @@#define VTCR_EL2_T0SZ_MASK 0x3f#define VTCR_EL2_T0SZ_40B 24 +/* +* We configure the Stage-2 page tables to always restrict the IPA space to be +* 40 bits wide (T0SZ = 24). Systems with a PARange smaller than 40 bits are +* not known to exist and will break with this configuration. +* +* Note that when using 4K pages, we concatenate two first level page tables +* together. +* +* The magic numbers used for VTTBR_X in this patch can be found in Tables +* D4-23 and D4-25 in ARM DDI 0487A.b. +*/ #ifdef CONFIG_ARM64_64K_PAGES /* * Stage2 translation configuration:
@@ -151,7 +162,7 @@#endif #define VTTBR_BADDR_SHIFT (VTTBR_X - 1) -#define VTTBR_BADDR_MASK (((1LLU << (40 - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) +#define VTTBR_BADDR_MASK (((1LLU << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT)#define VTTBR_VMID_SHIFT (48LLU)#define VTTBR_VMID_MASK (0xffLLU << VTTBR_VMID_SHIFT)
arch/arm64/include/asm/kvm_mmu.h +2 -3
@@ -59,10 +59,9 @@#define KERN_TO_HYP (kva) ((unsigned long)kva - PAGE_OFFSET + HYP_PAGE_OFFSET)/* -* Align KVM with the kernel's view of physical memory. Should be -* 40bit IPA, with PGD being 8kB aligned in the 4KB page configuration. +* We currently only support a 40bit IPA. */ -#define KVM_PHYS_SHIFT PHYS_MASK_SHIFT +#define KVM_PHYS_SHIFT (40)#define KVM_PHYS_SIZE (1UL << KVM_PHYS_SHIFT)#define KVM_PHYS_MASK (KVM_PHYS_SIZE - 1UL)
Signature · 1 line
2.3.5
PATCH 49/63 arm: kvm: fix CPU hotplug
In reply to Jiri SlabyFrom: Vladimir Murzin <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 37a34ac1d4775aafbc73b9db53c7daebbbc67e6a upstream.
On some platforms with no power management capabilities, the hotplug implementation is allowed to return from a smp_ops.cpu_die() call as a function return. Upon a CPU onlining event, the KVM CPU notifier tries to reinstall the hyp stub, which fails on platform where no reset took place following a hotplug event, with the message:
CPU1: smp_ops.cpu_die() returned, trying to resuscitate
CPU1: Booted secondary processor
Kernel panic - not syncing: unexpected prefetch abort in Hyp mode at: 0x80409540
unexpected data abort in Hyp mode at: 0x80401fe8 unexpected HVC/SVC trap in Hyp mode at: 0x805c6170
since KVM code is trying to reinstall the stub on a system where it is already configured.
To prevent this issue, this patch adds a check in the KVM hotplug notifier that detects if the HYP stub really needs re-installing when a CPU is onlined and skips the installation call if the stub is already in place, which means that the CPU has not been reset.
--- arch/arm/kvm/arm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/kvm/arm.c +2 -1
@@ -810,7 +810,8 @@ static int hyp_init_cpu_notify(struct notifier_block *self,switch (action) {case CPU_STARTING :case CPU_STARTING_FROZEN : -cpu_init_hyp_mode (NULL ); +if (__hyp_get_vectors () == hyp_default_vectors) +cpu_init_hyp_mode (NULL );break ; }
Signature · 1 line
2.3.5
PATCH 50/63 arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit c3058d5da2222629bc2223c488a4512b59bb4baf upstream.
When creating or moving a memslot, make sure the IPA space is within the addressable range of the guest. Otherwise, user space can create too large a memslot and KVM would try to access potentially unallocated page table entries when inserting entries in the Stage-2 page tables.
--- arch/arm/kvm/mmu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm/kvm/mmu.c +11 -0
@@ -772,6 +772,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) memslot =gfn_to_memslot (vcpu->kvm, gfn); +/* Userspace should not be able to register out-of-bounds IPAs */ +VM_BUG_ON (fault_ipa >=KVM_PHYS_SIZE ); + ret =user_mem_abort (vcpu, fault_ipa, gfn, memslot, fault_status);if (ret ==0 ) ret =1 ;
@@ -996,6 +999,14 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem, enum kvm_mr_change change) { +/* +* Prevent userspace from creating a memory region outside of the IPA +* space addressable by the KVM guest IPA space. +*/ +if (memslot->base_gfn + memslot->npages >= + (KVM_PHYS_SIZE >>PAGE_SHIFT )) +return -EFAULT ; +return 0 ; }
Signature · 1 line
2.3.5
PATCH 51/63 arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort
In reply to Jiri SlabyFrom: Steve Capper <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 3d08c629244257473450a8ba17cb8184b91e68f8 upstream.
Commit:
b886576 ARM: KVM: user_mem_abort: support stage 2 MMIO page mapping
introduced some code in user_mem_abort that failed to compile if STRICT_MM_TYPECHECKS was enabled.
This patch fixes up the failing comparison.
--- arch/arm/kvm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kvm/mmu.c +1 -1
@@ -698,7 +698,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,kvm_set_pfn_dirty (pfn); }stage2_set_pte (vcpu->kvm, memcache, fault_ipa, &new_pte, - mem_type ==PAGE_S2_DEVICE ); +pgprot_val (mem_type) ==pgprot_val (PAGE_S2_DEVICE )); out_unlock:spin_unlock (&vcpu->kvm->mmu_lock);
Signature · 1 line
2.3.5
PATCH 52/63 arm64/kvm: Fix assembler compatibility of macros
In reply to Jiri SlabyFrom: Geoff Levand <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 286fb1cc32b11c18da3573a8c8c37a4f9da16e30 upstream.
Some of the macros defined in kvm_arm.h are useful in assembly files, but are not compatible with the assembler. Change any C language integer constant definitions using appended U, UL, or ULL to the UL() preprocessor macro. Also, add a preprocessor include of the asm/memory.h file which defines the UL() macro.
Fixes build errors like these when using kvm_arm.h in assembly source files:
Error: unexpected characters following instruction at operand 3 -- `and x0,x1,#((1U<<25)-1)'
--- arch/arm64/include/asm/kvm_arm.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
arch/arm64/include/asm/kvm_arm.h +11 -10
@@ -18,6 +18,7 @@#ifndef __ARM64_KVM_ARM_H__#define __ARM64_KVM_ARM_H__ +#include <asm/memory.h> #include <asm/types.h> /* Hyp Configuration Register (HCR) bits */
@@ -162,9 +163,9 @@#endif #define VTTBR_BADDR_SHIFT (VTTBR_X - 1) -#define VTTBR_BADDR_MASK (((1LLU << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) -#define VTTBR_VMID_SHIFT (48LLU) -#define VTTBR_VMID_MASK (0xffLLU << VTTBR_VMID_SHIFT) +#define VTTBR_BADDR_MASK (((UL(1) << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) +#define VTTBR_VMID_SHIFT (UL(48)) +#define VTTBR_VMID_MASK (UL(0xFF) << VTTBR_VMID_SHIFT)/* Hyp System Trap Register */ #define HSTR_EL2_TTEE (1 << 16)
@@ -187,13 +188,13 @@/* Exception Syndrome Register (ESR) bits */ #define ESR_EL2_EC_SHIFT (26) -#define ESR_EL2_EC (0x3fU << ESR_EL2_EC_SHIFT) -#define ESR_EL2_IL (1U << 25) +#define ESR_EL2_EC (UL(0x3f) << ESR_EL2_EC_SHIFT) +#define ESR_EL2_IL (UL(1) << 25)#define ESR_EL2_ISS (ESR_EL2_IL - 1)#define ESR_EL2_ISV_SHIFT (24) -#define ESR_EL2_ISV (1U << ESR_EL2_ISV_SHIFT) +#define ESR_EL2_ISV (UL(1) << ESR_EL2_ISV_SHIFT)#define ESR_EL2_SAS_SHIFT (22) -#define ESR_EL2_SAS (3U << ESR_EL2_SAS_SHIFT) +#define ESR_EL2_SAS (UL(3) << ESR_EL2_SAS_SHIFT)#define ESR_EL2_SSE (1 << 21)#define ESR_EL2_SRT_SHIFT (16)#define ESR_EL2_SRT_MASK (0x1f << ESR_EL2_SRT_SHIFT)
@@ -207,16 +208,16 @@#define ESR_EL2_FSC_TYPE (0x3c)#define ESR_EL2_CV_SHIFT (24) -#define ESR_EL2_CV (1U << ESR_EL2_CV_SHIFT) +#define ESR_EL2_CV (UL(1) << ESR_EL2_CV_SHIFT)#define ESR_EL2_COND_SHIFT (20) -#define ESR_EL2_COND (0xfU << ESR_EL2_COND_SHIFT) +#define ESR_EL2_COND (UL(0xf) << ESR_EL2_COND_SHIFT)#define FSC_FAULT (0x04)#define FSC_PERM (0x0c)/* Hyp Prefetch Fault Address Register (HPFAR/HDFAR) */ -#define HPFAR_MASK (~0xFUL) +#define HPFAR_MASK (~UL(0xf))#define ESR_EL2_EC_UNKNOWN (0x00)#define ESR_EL2_EC_WFI (0x01)
Signature · 1 line
2.3.5
PATCH 53/63 arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn()
In reply to Jiri SlabyFrom: Ard Biesheuvel <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 07a9748c78cfc39b54f06125a216b67b9c8f09ed upstream.
Instead of using kvm_is_mmio_pfn() to decide whether a host region should be stage 2 mapped with device attributes, add a new static function kvm_is_device_pfn() that disregards RAM pages with the reserved bit set, as those should usually not be mapped as device memory.
--- arch/arm/kvm/mmu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm/kvm/mmu.c +6 -1
@@ -644,6 +644,11 @@ static bool kvm_is_write_fault(struct kvm_vcpu *vcpu)return kvm_vcpu_dabt_iswrite (vcpu); } +static bool kvm_is_device_pfn (unsigned long pfn) +{ +return !pfn_valid (pfn); +} +static int user_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa,gfn_t gfn,struct kvm_memory_slot *memslot,unsigned long fault_status)
@@ -684,7 +689,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (is_error_pfn (pfn))return -EFAULT ; -if (kvm_is_mmio_pfn (pfn)) +if (kvm_is_device_pfn (pfn)) mem_type =PAGE_S2_DEVICE ; new_pte =pfn_pte (pfn, mem_type);
Signature · 1 line
2.3.5
PATCH 54/63 arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 03f1d4c17edb31b41b14ca3a749ae38d2dd6639d upstream.
If a VCPU was originally started with power off (typically to be brought up by PSCI in SMP configurations), there is no need to clear the POWER_OFF flag in the kernel, as this flag is only tested during the init ioctl itself.
--- arch/arm/kvm/arm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kvm/arm.c +1 -1
@@ -676,7 +676,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,/* * Handle the "start in power-off" case by marking the VCPU as paused. */ -if (__test_and_clear_bit (KVM_ARM_VCPU_POWER_OFF , vcpu->arch.features)) +if (test_bit (KVM_ARM_VCPU_POWER_OFF , vcpu->arch.features)) vcpu->arch.pause = true;return 0 ;
Signature · 1 line
2.3.5
PATCH 55/63 arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 3ad8b3de526a76fbe9466b366059e4958957b88f upstream.
The implementation of KVM_ARM_VCPU_INIT is currently not doing what userspace expects, namely making sure that a vcpu which may have been turned off using PSCI is returned to its initial state, which would be powered on if userspace does not set the KVM_ARM_VCPU_POWER_OFF flag.
Implement the expected functionality and clarify the ABI.
--- Documentation/virtual/kvm/api.txt | 3 ++- arch/arm/kvm/arm.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/virtual/kvm/api.txt +2 -1
@@ -2299,7 +2299,8 @@ should be created before this ioctl is invoked. Possible features: - KVM_ARM_VCPU_POWER_OFF: Starts the CPU in a power-off state. - Depends on KVM_CAP_ARM_PSCI. + Depends on KVM_CAP_ARM_PSCI. If not set, the CPU will be powered on + and execute guest code when KVM_RUN is called. - KVM_ARM_VCPU_EL1_32BIT: Starts the CPU in a 32bit mode. Depends on KVM_CAP_ARM_EL1_32BIT (arm64 only).
arch/arm/kvm/arm.c +2 -0
@@ -678,6 +678,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,*/ if (test_bit (KVM_ARM_VCPU_POWER_OFF , vcpu->arch.features)) vcpu->arch.pause = true; +else + vcpu->arch.pause = false;return 0 ; }
Signature · 1 line
2.3.5
PATCH 56/63 arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit b856a59141b1066d3c896a0d0231f84dabd040af upstream.
When userspace resets the vcpu using KVM_ARM_VCPU_INIT, we should also reset the HCR, because we now modify the HCR dynamically to enable/disable trapping of guest accesses to the VM registers.
This is crucial for reboot of VMs working since otherwise we will not be doing the necessary cache maintenance operations when faulting in pages with the guest MMU off.
--- arch/arm/include/asm/kvm_emulate.h | 5 +++++ arch/arm/kvm/arm.c | 2 ++ arch/arm/kvm/guest.c | 1 - arch/arm64/include/asm/kvm_emulate.h | 5 +++++ arch/arm64/kvm/guest.c | 1 - 5 files changed, 12 insertions(+), 2 deletions(-)
arch/arm/include/asm/kvm_emulate.h +5 -0
@@ -33,6 +33,11 @@ void kvm_inject_undefined(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); +static inline void vcpu_reset_hcr (struct kvm_vcpu *vcpu) +{ + vcpu->arch.hcr =HCR_GUEST_MASK ; +} +static inline bool vcpu_mode_is_32bit (struct kvm_vcpu *vcpu) {return 1 ;
arch/arm/kvm/arm.c +2 -0
@@ -673,6 +673,8 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,if (ret)return ret; +vcpu_reset_hcr (vcpu); +/* * Handle the "start in power-off" case by marking the VCPU as paused. */
arch/arm/kvm/guest.c +0 -1
@@ -38,7 +38,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {int kvm_arch_vcpu_setup (struct kvm_vcpu *vcpu) { - vcpu->arch.hcr =HCR_GUEST_MASK ;return 0 ; }
arch/arm64/include/asm/kvm_emulate.h +5 -0
@@ -38,6 +38,11 @@ void kvm_inject_undefined(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); +static inline void vcpu_reset_hcr (struct kvm_vcpu *vcpu) +{ + vcpu->arch.hcr_el2 =HCR_GUEST_FLAGS ; +} +static inline unsigned long *vcpu_pc (const struct kvm_vcpu *vcpu) {return (unsigned long *)&vcpu_gp_regs (vcpu)->regs.pc;
arch/arm64/kvm/guest.c +0 -1
@@ -38,7 +38,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {int kvm_arch_vcpu_setup (struct kvm_vcpu *vcpu) { - vcpu->arch.hcr_el2 =HCR_GUEST_FLAGS ;return 0 ; }
Signature · 1 line
2.3.5
PATCH 57/63 arm/arm64: KVM: Introduce stage2_unmap_vm
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 957db105c99792ae8ef61ffc9ae77d910f6471da upstream.
Introduce a new function to unmap user RAM regions in the stage2 page tables. This is needed on reboot (or when the guest turns off the MMU) to ensure we fault in pages again and make the dcache, RAM, and icache coherent.
Using unmap_stage2_range for the whole guest physical range does not work, because that unmaps IO regions (such as the GIC) which will not be recreated or in the best case faulted in on a page-by-page basis.
Call this function on secondary and subsequent calls to the KVM_ARM_VCPU_INIT ioctl so that a reset VCPU will detect the guest Stage-1 MMU is off when faulting in pages and make the caches coherent.
--- arch/arm/include/asm/kvm_mmu.h | 1 + arch/arm/kvm/arm.c | 7 +++++ arch/arm/kvm/mmu.c | 65 ++++++++++++++++++++++++++++++++++++++++ arch/arm64/include/asm/kvm_mmu.h | 1 + 4 files changed, 74 insertions(+)
arch/arm/include/asm/kvm_mmu.h +1 -0
@@ -47,6 +47,7 @@ int create_hyp_io_mappings(void *from, void *to, phys_addr_t);void free_boot_hyp_pgd (void );void free_hyp_pgds (void ); +void stage2_unmap_vm (struct kvm *kvm);int kvm_alloc_stage2_pgd (struct kvm *kvm);void kvm_free_stage2_pgd (struct kvm *kvm); int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
arch/arm/kvm/arm.c +7 -0
@@ -673,6 +673,13 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu,if (ret)return ret; +/* +* Ensure a rebooted VM will fault in RAM pages and detect if the +* guest MMU is turned off and flush the caches as needed. +*/ +if (vcpu->arch.has_run_once) +stage2_unmap_vm (vcpu->kvm); +vcpu_reset_hcr (vcpu);/*
arch/arm/kvm/mmu.c +65 -0
71 lines not on this page · raw message
arch/arm64/include/asm/kvm_mmu.h +1 -0
@@ -74,6 +74,7 @@ int create_hyp_io_mappings(void *from, void *to, phys_addr_t);void free_boot_hyp_pgd (void );void free_hyp_pgds (void ); +void stage2_unmap_vm (struct kvm *kvm);int kvm_alloc_stage2_pgd (struct kvm *kvm);void kvm_free_stage2_pgd (struct kvm *kvm); int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,
Signature · 1 line
2.3.5
PATCH 58/63 arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 716139df2517fbc3f2306dbe8eba0fa88dca0189 upstream.
When the vgic initializes its internal state it does so based on the number of VCPUs available at the time. If we allow KVM to create more VCPUs after the VGIC has been initialized, we are likely to error out in unfortunate ways later, perform buffer overflows etc.
--- arch/arm/kvm/arm.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/kvm/arm.c +5 -0
@@ -218,6 +218,11 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)int err;struct kvm_vcpu *vcpu; +if (irqchip_in_kernel (kvm) &&vgic_initialized (kvm)) { + err = -EBUSY ; + goto out; + } + vcpu =kmem_cache_zalloc (kvm_vcpu_cache,GFP_KERNEL );if (!vcpu) { err = -ENOMEM ;
Signature · 1 line
2.3.5
PATCH 59/63 arm/arm64: KVM: Require in-kernel vgic for the arch timers
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 05971120fca43e0357789a14b3386bb56eef2201 upstream.
It is curently possible to run a VM with architected timers support without creating an in-kernel VGIC, which will result in interrupts from the virtual timer going nowhere.
To address this issue, move the architected timers initialization to the time when we run a VCPU for the first time, and then only initialize (and enable) the architected timers if we have a properly created and initialized in-kernel VGIC.
When injecting interrupts from the virtual timer to the vgic, the current setup should ensure that this never calls an on-demand init of the VGIC, which is the only call path that could return an error from kvm_vgic_inject_irq(), so capture the return value and raise a warning if there's an error there.
We also change the kvm_timer_init() function from returning an int to be a void function, since the function always succeeds.
--- arch/arm/kvm/arm.c | 9 +++++++++ include/kvm/arm_arch_timer.h | 10 ++++------ virt/kvm/arm/arch_timer.c | 30 ++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 14 deletions(-)
arch/arm/kvm/arm.c +9 -0
@@ -439,6 +439,7 @@ static void update_vttbr(struct kvm *kvm)static int kvm_vcpu_first_run_init (struct kvm_vcpu *vcpu) { +struct kvm *kvm = vcpu->kvm;int ret;if (likely (vcpu->arch.has_run_once))
@@ -456,6 +457,14 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)return ret; } +/* +* Enable the arch timers only if we have an in-kernel VGIC +* and it has been properly initialized, since we cannot handle +* interrupts from the virtual timer with a userspace gic. +*/ +if (irqchip_in_kernel (kvm) &&vgic_initialized (kvm)) +kvm_timer_enable (kvm); +return 0 ; }
include/kvm/arm_arch_timer.h +4 -6
@@ -60,7 +60,8 @@ struct arch_timer_cpu {#ifdef CONFIG_KVM_ARM_TIMER int kvm_timer_hyp_init (void ); -int kvm_timer_init (struct kvm *kvm); +void kvm_timer_enable (struct kvm *kvm); +void kvm_timer_init (struct kvm *kvm);void kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu,const struct kvm_irq_level *irq);void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu);
@@ -73,11 +74,8 @@ static inline int kvm_timer_hyp_init(void)return 0 ; }; -static inline int kvm_timer_init (struct kvm *kvm) -{ -return 0 ; -} - +static inline void kvm_timer_enable (struct kvm *kvm) {} +static inline void kvm_timer_init (struct kvm *kvm) {}static inline void kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu,const struct kvm_irq_level *irq) {}static inline void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu) {}
virt/kvm/arm/arch_timer.c +22 -8
@@ -61,12 +61,14 @@ static void timer_disarm(struct arch_timer_cpu *timer)static void kvm_timer_inject_irq (struct kvm_vcpu *vcpu) { +int ret;struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; timer->cntv_ctl |=ARCH_TIMER_CTRL_IT_MASK ; -kvm_vgic_inject_irq (vcpu->kvm, vcpu->vcpu_id, - timer->irq->irq, - timer->irq->level); + ret =kvm_vgic_inject_irq (vcpu->kvm, vcpu->vcpu_id, + timer->irq->irq, + timer->irq->level); +WARN_ON (ret); }static irqreturn_t kvm_arch_timer_handler (int irq,void *dev_id)
@@ -273,12 +275,24 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)timer_disarm (timer); } -int kvm_timer_init (struct kvm *kvm) +void kvm_timer_enable (struct kvm *kvm) { -if (timecounter && wqueue) { - kvm->arch.timer.cntvoff =kvm_phys_timer_read (); +if (kvm->arch.timer.enabled) +return ; + +/* +* There is a potential race here between VCPUs starting for the first +* time, which may be enabling the timer multiple times. That doesn't +* hurt though, because we're just setting a variable to the same +* variable that it already was. The important thing is that all +* VCPUs have the enabled variable set, before entering the guest, if +* the arch timers are enabled. +*/ +if (timecounter && wqueue) kvm->arch.timer.enabled =1 ; - } +} -return 0 ; +void kvm_timer_init (struct kvm *kvm) +{ + kvm->arch.timer.cntvoff =kvm_phys_timer_read (); }
Signature · 1 line
2.3.5
PATCH 60/63 arm64: KVM: Fix TLB invalidation by IPA/VMID
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 55e858b75808347378e5117c3c2339f46cc03575 upstream.
It took about two years for someone to notice that the IPA passed to TLBI IPAS2E1IS must be shifted by 12 bits. Clearly our reviewing is not as good as it should be...
Paper bag time for me.
--- arch/arm64/kvm/hyp.S | 1 + 1 file changed, 1 insertion(+)
arch/arm64/kvm/hyp.S +1 -0
@@ -616,6 +616,7 @@ ENTRY(__kvm_tlb_flush_vmid_ipa) * Instead, we invalidate Stage-2 for this IPA, and the * whole of Stage-1. Weep... */ + lsr x1, x1, #12 tlbi ipas2e1is, x1 /* * We have to ensure completion of the invalidation at Stage-2,
Signature · 1 line
2.3.5
PATCH 61/63 arm64: KVM: Fix HCR setting for 32bit guests
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 801f6772cecea6cfc7da61aa197716ab64db5f9e upstream.
Commit b856a59141b1 (arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu) moved the init of the HCR register to happen later in the init of a vcpu, but left out the fixup done in kvm_reset_vcpu when preparing for a 32bit guest.
As a result, the 32bit guest is run as a 64bit guest, but the rest of the kernel still manages it as a 32bit. Fun follows.
Moving the fixup to vcpu_reset_hcr solves the problem for good.
--- arch/arm64/include/asm/kvm_emulate.h | 2 ++ arch/arm64/kvm/reset.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_emulate.h +2 -0
@@ -41,6 +41,8 @@ void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr);static inline void vcpu_reset_hcr (struct kvm_vcpu *vcpu) { vcpu->arch.hcr_el2 =HCR_GUEST_FLAGS ; +if (test_bit (KVM_ARM_VCPU_EL1_32BIT , vcpu->arch.features)) + vcpu->arch.hcr_el2 &= ~HCR_RW ; }static inline unsigned long *vcpu_pc (const struct kvm_vcpu *vcpu)
arch/arm64/kvm/reset.c +0 -1
@@ -90,7 +90,6 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)if (!cpu_has_32bit_el1 ())return -EINVAL ; cpu_reset = &default_regs_reset32; - vcpu->arch.hcr_el2 &= ~HCR_RW ; }else { cpu_reset = &default_regs_reset; }
Signature · 1 line
2.3.5
PATCH 62/63 arm64: KVM: Do not use pgd_index to index stage-2 pgd
In reply to Jiri SlabyFrom: Marc Zyngier <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit 04b8dc85bf4a64517e3cf20e409eeaa503b15cc1 upstream.
The kernel's pgd_index macro is designed to index a normal, page sized array. KVM is a bit diffferent, as we can use concatenated pages to have a bigger address space (for example 40bit IPA with 4kB pages gives us an 8kB PGD.
In the above case, the use of pgd_index will always return an index inside the first 4kB, which makes a guest that has memory above 0x8000000000 rather unhappy, as it spins forever in a page fault, whist the host happilly corrupts the lower pgd.
The obvious fix is to get our own kvm_pgd_index that does the right thing(tm).
Tested on X-Gene with a hacked kvmtool that put memory at a stupidly high address.
--- arch/arm/include/asm/kvm_mmu.h | 2 ++ arch/arm/kvm/mmu.c | 6 +++--- arch/arm64/include/asm/kvm_mmu.h | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-)
arch/arm/include/asm/kvm_mmu.h +2 -0
@@ -106,6 +106,8 @@ static inline void kvm_set_s2pte_writable(pte_t *pte) (__boundary -1 < (end) -1 )? __boundary: (end); \ }) +#define kvm_pgd_index (addr) pgd_index(addr) +static inline bool kvm_page_empty (void *ptr) {struct page *ptr_page =virt_to_page (ptr);
arch/arm/kvm/mmu.c +3 -3
@@ -177,7 +177,7 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp,phys_addr_t addr = start, end = start + size;phys_addr_t next; - pgd = pgdp +pgd_index (addr); + pgd = pgdp +kvm_pgd_index (addr); do { next = kvm_pgd_addr_end(addr, end); unmap_puds(kvm, pgd, addr, next);
@@ -236,7 +236,7 @@ static void stage2_flush_memslot(struct kvm *kvm,phys_addr_t next;pgd_t *pgd; - pgd = kvm->arch.pgd +pgd_index (addr); + pgd = kvm->arch.pgd +kvm_pgd_index (addr); do { next = kvm_pgd_addr_end(addr, end); stage2_flush_puds(kvm, pgd, addr, next);
@@ -624,7 +624,7 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache,pte_t *pte, old_pte;/* Create 2nd stage page table mapping - Level 1 */ - pgd = kvm->arch.pgd +pgd_index (addr); + pgd = kvm->arch.pgd +kvm_pgd_index (addr); pud =pud_offset (pgd, addr);if (pud_none (*pud)) {if (!cache)
arch/arm64/include/asm/kvm_mmu.h +2 -0
@@ -106,6 +106,8 @@ static inline void kvm_set_s2pte_writable(pte_t *pte)#define kvm_pud_addr_end (addr, end) pud_addr_end(addr, end)#define kvm_pmd_addr_end (addr, end) pmd_addr_end(addr, end) +#define kvm_pgd_index (addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_S2_PGD - 1)) +static inline bool kvm_page_empty (void *ptr) {struct page *ptr_page =virt_to_page (ptr);
Signature · 1 line
2.3.5
PATCH 63/63 arm/arm64: KVM: Keep elrsr/aisr in sync with software model
In reply to Jiri SlabyFrom: Christoffer Dall <[email protected]>
3.12-stable review patch. If anyone has any objections, please let me know.
===============
commit ae705930fca6322600690df9dc1c7d0516145a93 upstream.
There is an interesting bug in the vgic code, which manifests itself when the KVM run loop has a signal pending or needs a vmid generation rollover after having disabled interrupts but before actually switching to the guest.
In this case, we flush the vgic as usual, but we sync back the vgic state and exit to userspace before entering the guest. The consequence is that we will be syncing the list registers back to the software model using the GICH_ELRSR and GICH_EISR from the last execution of the guest, potentially overwriting a list register containing an interrupt.
This showed up during migration testing where we would capture a state where the VM has masked the arch timer but there were no interrupts, resulting in a hung test.
--- virt/kvm/arm/vgic.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
virt/kvm/arm/vgic.c +10 -0
@@ -881,6 +881,7 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) lr, irq, vgic_cpu->vgic_lr[lr]);BUG_ON (!test_bit (lr, vgic_cpu->lr_used)); vgic_cpu->vgic_lr[lr] |=GICH_LR_PENDING_BIT ; +__clear_bit (lr, (unsigned long *)vgic_cpu->vgic_elrsr);return true; }
@@ -894,6 +895,7 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq) vgic_cpu->vgic_lr[lr] =MK_LR_PEND (sgi_source_id, irq); vgic_cpu->vgic_irq_lr_map[irq] = lr;set_bit (lr, vgic_cpu->lr_used); +__clear_bit (lr, (unsigned long *)vgic_cpu->vgic_elrsr);if (!vgic_irq_is_edge (vcpu, irq)) vgic_cpu->vgic_lr[lr] |=GICH_LR_EOI ;
@@ -1048,6 +1050,14 @@ static bool vgic_process_maintenance(struct kvm_vcpu *vcpu)if (vgic_cpu->vgic_misr &GICH_MISR_U ) vgic_cpu->vgic_hcr &= ~GICH_HCR_UIE ; +/* +* In the next iterations of the vcpu loop, if we sync the vgic state +* after flushing it, but before entering the guest (this happens for +* pending signals and vmid rollovers), then make sure we don't pick +* up any old maintenance interrupts here. +*/ +memset (vgic_cpu->vgic_eisr,0 ,sizeof (vgic_cpu->vgic_eisr[0 ]) *2 ); +return level_pending; }
Signature · 1 line
2.3.5
Quoted 8 lines · Jiri Slaby
This is the start of the stable review cycle for the 3.12.42 release. There are 63 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Mon May 4 11:48:46 CEST 2015. Anything received after that time might be too late.
Build results:
total: 125 pass: 124 fail: 1
Failed builds:
arm64:allmodconfig
Qemu test results:
total: 27 pass: 27 fail: 0
Results are as expected.
Details are available at http://server.roeck-us.net:8010/builders.
Guenter
Quoted 9 lines · Guenter Roeck
Build results:
total: 125 pass: 124 fail: 1Failed builds:
arm64:allmodconfigQemu test results:
total: 27 pass: 27 fail: 0Results are as expected.
Quoted 1 line · Shuah Khan
Compiled and booted on my test system. No dmesg regressions.
Thank you both!
Signature · 2 lines
js suse labs
Quoted 8 lines · Jiri Slaby
This is the start of the stable review cycle for the 3.12.42 release. There are 63 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Mon May 4 11:48:46 CEST 2015. Anything received after that time might be too late.
Quoted 7 lines
The whole patch series can be found in one patch at:
http://kernel.org/pub/linux/kernel/people/jirislaby/stable-review/patch-3.12.42-rc1.xzand the diffstat can be found below.
thanks,
js
Compiled and booted on my test system. No dmesg regressions.
-- Shuah
Signature · 5 lines
Shuah Khan Sr. Linux Kernel Developer Open Source Innovation Group Samsung Research America (Silicon Valley) [email protected] | (970) 217-8978