stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel
@ 2015-06-30 10:48 shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 01/22] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() shannon.zhao
                   ` (21 more replies)
  0 siblings, 22 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Shannon Zhao <shannon.zhao@linaro.org>

For KVM/ARM there are many fixes which have been applied upstream while
not committed to stable kernels. Here we backport the important fixes
to 3.14.y stable kernel.

We have compile-tested each patch on arm/arm64/x86 to make sure the
series are bisectable and have booted the resulting kernel on Fastmodel
and started 2 VMs for arm/arm64, and have boot-tested on TC2 and
started a guest.

These patches are applied on the top of 3.14.46.

Note in this series patch 1, 2, 7, 21, 22 are different from the
original patch and I've noted the changes in the commit message.

Thanks,
Shannon

Ard Biesheuvel (3):
  ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault()
  arm/arm64: KVM: fix potential NULL dereference in user_mem_abort()
  arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn()

Christoffer Dall (10):
  arm/arm64: KVM: Fix set_clear_sgi_pend_reg offset
  arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE
  arm/arm64: KVM: vgic: Fix error code in kvm_vgic_create()
  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

Geoff Levand (1):
  arm64/kvm: Fix assembler compatibility of macros

Joel Schopp (1):
  arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc

Marc Zyngier (4):
  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

Mark Rutland (1):
  arm64: KVM: fix unmapping with 48-bit VAs

Steve Capper (1):
  arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort

Vladimir Murzin (1):
  arm: kvm: fix CPU hotplug

 Documentation/virtual/kvm/api.txt    |   3 +-
 arch/arm/include/asm/kvm_emulate.h   |   5 ++
 arch/arm/include/asm/kvm_mmu.h       |  15 +----
 arch/arm/kvm/arm.c                   |  38 ++++++++++--
 arch/arm/kvm/guest.c                 |   1 -
 arch/arm/kvm/mmu.c                   | 110 ++++++++++++++++++++++++++++++++---
 arch/arm64/include/asm/kvm_arm.h     |  32 ++++++----
 arch/arm64/include/asm/kvm_emulate.h |   7 +++
 arch/arm64/include/asm/kvm_mmu.h     |  21 ++-----
 arch/arm64/kvm/guest.c               |   1 -
 arch/arm64/kvm/hyp.S                 |   1 +
 arch/arm64/kvm/reset.c               |   1 -
 include/kvm/arm_arch_timer.h         |  10 ++--
 virt/kvm/arm/arch_timer.c            |  30 +++++++---
 virt/kvm/arm/vgic.c                  |  25 +++++---
 15 files changed, 224 insertions(+), 76 deletions(-)

-- 
2.1.0


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 01/22] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault()
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 02/22] KVM: ARM: vgic: plug irq injection race shannon.zhao
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Ard Biesheuvel,
	Marc Zyngier

From: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Since we don't backport commit 9804788 (arm/arm64: KVM: Support
KVM_CAP_READONLY_MEM), ingore the changes in kvm_handle_guest_abort
introduced by this patch.

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'

Acked-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 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(-)

diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
index 0cbdb8e..630869e 100644
--- a/arch/arm/include/asm/kvm_mmu.h
+++ b/arch/arm/include/asm/kvm_mmu.h
@@ -78,17 +78,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));
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 70ed2c1..049c56e 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -746,6 +746,14 @@ static bool transparent_hugepage_adjust(pfn_t *pfnp, phys_addr_t *ipap)
 	return false;
 }
 
+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,
 			  struct kvm_memory_slot *memslot,
 			  unsigned long fault_status)
@@ -761,7 +769,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	pfn_t pfn;
 	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;
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 8e138c7..737da74 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -93,19 +93,6 @@ void kvm_clear_hyp_idmap(void);
 #define	kvm_set_pte(ptep, pte)		set_pte(ptep, pte)
 #define	kvm_set_pmd(pmdp, pmd)		set_pmd(pmdp, pmd)
 
-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) {}
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 02/22] KVM: ARM: vgic: plug irq injection race
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 01/22] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 03/22] arm/arm64: KVM: Fix set_clear_sgi_pend_reg offset shannon.zhao
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Marc Zyngier

From: Marc Zyngier <marc.zyngier@arm.com>

Since we don't backport commit 227844f (arm/arm64: KVM: Rename irq_state
to irq_pending) for linux-3.14.y, here we still use vgic_update_irq_state
instead of vgic_update_irq_pending.

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.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 virt/kvm/arm/vgic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 1316e55..2187318 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1387,7 +1387,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;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 03/22] arm/arm64: KVM: Fix set_clear_sgi_pend_reg offset
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 01/22] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 02/22] KVM: ARM: vgic: plug irq injection race shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 04/22] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc shannon.zhao
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

commit 0fea6d7628ed6e25a9ee1b67edf7c859718d39e8 upstream.

The sgi values calculated in read_set_clear_sgi_pend_reg() and
write_set_clear_sgi_pend_reg() were horribly incorrectly multiplied by 4
with catastrophic results in that subfunctions ended up overwriting
memory not allocated for the expected purpose.

This showed up as bugs in kfree() and the kernel complaining a lot of
you turn on memory debugging.

This addresses: http://marc.info/?l=kvm&m=141164910007868&w=2

Reported-by: Shannon Zhao <zhaoshenglong@huawei.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 virt/kvm/arm/vgic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 2187318..5309a1d 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -674,7 +674,7 @@ static bool read_set_clear_sgi_pend_reg(struct kvm_vcpu *vcpu,
 {
 	struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
 	int sgi;
-	int min_sgi = (offset & ~0x3) * 4;
+	int min_sgi = (offset & ~0x3);
 	int max_sgi = min_sgi + 3;
 	int vcpu_id = vcpu->vcpu_id;
 	u32 reg = 0;
@@ -695,7 +695,7 @@ static bool write_set_clear_sgi_pend_reg(struct kvm_vcpu *vcpu,
 {
 	struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
 	int sgi;
-	int min_sgi = (offset & ~0x3) * 4;
+	int min_sgi = (offset & ~0x3);
 	int max_sgi = min_sgi + 3;
 	int vcpu_id = vcpu->vcpu_id;
 	u32 reg;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 04/22] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (2 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 03/22] arm/arm64: KVM: Fix set_clear_sgi_pend_reg offset shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 05/22] arm: kvm: fix CPU hotplug shannon.zhao
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Joel Schopp

From: Joel Schopp <joel.schopp@amd.com>

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 ]

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Joel Schopp <joel.schopp@amd.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 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(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index df6e75e..55c1ebf 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -427,9 +427,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);
 }
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 00fbaa7..2bc2602 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -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)
 
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 737da74..a030d16 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -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)
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 05/22] arm: kvm: fix CPU hotplug
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (3 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 04/22] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 06/22] arm/arm64: KVM: fix potential NULL dereference in user_mem_abort() shannon.zhao
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Vladimir Murzin

From: Vladimir Murzin <vladimir.murzin@arm.com>

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.

Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com>
Acked-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/arm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 55c1ebf..fb9c291 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -825,7 +825,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;
 	}
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 06/22] arm/arm64: KVM: fix potential NULL dereference in user_mem_abort()
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (4 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 05/22] arm: kvm: fix CPU hotplug shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 07/22] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE shannon.zhao
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Ard Biesheuvel

From: Ard Biesheuvel <ard.biesheuvel@linaro.org>

commit 37b544087ef3f65ca68465ba39291a07195dac26 upstream.

Handle the potential NULL return value of find_vma_intersection()
before dereferencing it.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/mmu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 049c56e..8cd0387 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -778,6 +778,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	/* Let's check if we will get back a huge page backed by hugetlbfs */
 	down_read(&current->mm->mmap_sem);
 	vma = find_vma_intersection(current->mm, hva, hva + 1);
+	if (unlikely(!vma)) {
+		kvm_err("Failed to find VMA for hva 0x%lx\n", hva);
+		up_read(&current->mm->mmap_sem);
+		return -EFAULT;
+	}
+
 	if (is_vm_hugetlb_page(vma)) {
 		hugetlb = true;
 		gfn = (fault_ipa & PMD_MASK) >> PAGE_SHIFT;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 07/22] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (5 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 06/22] arm/arm64: KVM: fix potential NULL dereference in user_mem_abort() shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 08/22] arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort shannon.zhao
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

Since we don't backport commit 8eef912 (arm/arm64: KVM: map MMIO regions
at creation time) for linux-3.14.y, the context of this patch is
different, while the change itself is same.

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.

Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/mmu.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 8cd0387..d122772 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -926,6 +926,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, memslot, fault_status);
 	if (ret == 0)
 		ret = 1;
@@ -1150,6 +1153,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;
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 08/22] arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (6 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 07/22] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 09/22] arm64: KVM: fix unmapping with 48-bit VAs shannon.zhao
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Steve Capper

From: Steve Capper <steve.capper@linaro.org>

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.

Signed-off-by: Steve Capper <steve.capper@linaro.org>
Reviewed-by: Kim Phillips <kim.phillips@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index d122772..2206385 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -850,7 +850,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 		}
 		coherent_cache_guest_page(vcpu, hva, PAGE_SIZE);
 		ret = stage2_set_pte(kvm, memcache, fault_ipa, &new_pte,
-				     mem_type == PAGE_S2_DEVICE);
+			pgprot_val(mem_type) == pgprot_val(PAGE_S2_DEVICE));
 	}
 
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 09/22] arm64: KVM: fix unmapping with 48-bit VAs
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (7 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 08/22] arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 10/22] arm/arm64: KVM: vgic: Fix error code in kvm_vgic_create() shannon.zhao
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable
  Cc: gregkh, christoffer.dall, shannon.zhao, Mark Rutland,
	Catalin Marinas, Jungseok Lee, Marc Zyngier, Paolo Bonzini

From: Mark Rutland <mark.rutland@arm.com>

commit 7cbb87d67e38cfc55680290a706fd7517f10050d upstream.

Currently if using a 48-bit VA, tearing down the hyp page tables (which
can happen in the absence of a GICH or GICV resource) results in the
rather nasty splat below, evidently becasue we access a table that
doesn't actually exist.

Commit 38f791a4e499792e (arm64: KVM: Implement 48 VA support for KVM EL2
and Stage-2) added a pgd_none check to __create_hyp_mappings to account
for the additional level of tables, but didn't add a corresponding check
to unmap_range, and this seems to be the source of the problem.

This patch adds the missing pgd_none check, ensuring we don't try to
access tables that don't exist.

Original splat below:

kvm [1]: Using HYP init bounce page @83fe94a000
kvm [1]: Cannot obtain GICH resource
Unable to handle kernel paging request at virtual address ffff7f7fff000000
pgd = ffff800000770000
[ffff7f7fff000000] *pgd=0000000000000000
Internal error: Oops: 96000004 [#1] PREEMPT SMP
Modules linked in:
CPU: 1 PID: 1 Comm: swapper/0 Not tainted 3.18.0-rc2+ #89
task: ffff8003eb500000 ti: ffff8003eb45c000 task.ti: ffff8003eb45c000
PC is at unmap_range+0x120/0x580
LR is at free_hyp_pgds+0xac/0xe4
pc : [<ffff80000009b768>] lr : [<ffff80000009cad8>] pstate: 80000045
sp : ffff8003eb45fbf0
x29: ffff8003eb45fbf0 x28: ffff800000736000
x27: ffff800000735000 x26: ffff7f7fff000000
x25: 0000000040000000 x24: ffff8000006f5000
x23: 0000000000000000 x22: 0000007fffffffff
x21: 0000800000000000 x20: 0000008000000000
x19: 0000000000000000 x18: ffff800000648000
x17: ffff800000537228 x16: 0000000000000000
x15: 000000000000001f x14: 0000000000000000
x13: 0000000000000001 x12: 0000000000000020
x11: 0000000000000062 x10: 0000000000000006
x9 : 0000000000000000 x8 : 0000000000000063
x7 : 0000000000000018 x6 : 00000003ff000000
x5 : ffff800000744188 x4 : 0000000000000001
x3 : 0000000040000000 x2 : ffff800000000000
x1 : 0000007fffffffff x0 : 000000003fffffff

Process swapper/0 (pid: 1, stack limit = 0xffff8003eb45c058)
Stack: (0xffff8003eb45fbf0 to 0xffff8003eb460000)
fbe0:                                     eb45fcb0 ffff8003 0009cad8 ffff8000
fc00: 00000000 00000080 00736140 ffff8000 00736000 ffff8000 00000000 00007c80
fc20: 00000000 00000080 006f5000 ffff8000 00000000 00000080 00743000 ffff8000
fc40: 00735000 ffff8000 006d3030 ffff8000 006fe7b8 ffff8000 00000000 00000080
fc60: ffffffff 0000007f fdac1000 ffff8003 fd94b000 ffff8003 fda47000 ffff8003
fc80: 00502b40 ffff8000 ff000000 ffff7f7f fdec6000 00008003 fdac1630 ffff8003
fca0: eb45fcb0 ffff8003 ffffffff 0000007f eb45fd00 ffff8003 0009b378 ffff8000
fcc0: ffffffea 00000000 006fe000 ffff8000 00736728 ffff8000 00736120 ffff8000
fce0: 00000040 00000000 00743000 ffff8000 006fe7b8 ffff8000 0050cd48 00000000
fd00: eb45fd60 ffff8003 00096070 ffff8000 006f06e0 ffff8000 006f06e0 ffff8000
fd20: fd948b40 ffff8003 0009a320 ffff8000 00000000 00000000 00000000 00000000
fd40: 00000ae0 00000000 006aa25c ffff8000 eb45fd60 ffff8003 0017ca44 00000002
fd60: eb45fdc0 ffff8003 0009a33c ffff8000 006f06e0 ffff8000 006f06e0 ffff8000
fd80: fd948b40 ffff8003 0009a320 ffff8000 00000000 00000000 00735000 ffff8000
fda0: 006d3090 ffff8000 006aa25c ffff8000 00735000 ffff8000 006d3030 ffff8000
fdc0: eb45fdd0 ffff8003 000814c0 ffff8000 eb45fe50 ffff8003 006aaac4 ffff8000
fde0: 006ddd90 ffff8000 00000006 00000000 006d3000 ffff8000 00000095 00000000
fe00: 006a1e90 ffff8000 00735000 ffff8000 006d3000 ffff8000 006aa25c ffff8000
fe20: 00735000 ffff8000 006d3030 ffff8000 eb45fe50 ffff8003 006fac68 ffff8000
fe40: 00000006 00000006 fe293ee6 ffff8003 eb45feb0 ffff8003 004f8ee8 ffff8000
fe60: 004f8ed4 ffff8000 00735000 ffff8000 00000000 00000000 00000000 00000000
fe80: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
fea0: 00000000 00000000 00000000 00000000 00000000 00000000 000843d0 ffff8000
fec0: 004f8ed4 ffff8000 00000000 00000000 00000000 00000000 00000000 00000000
fee0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ff00: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ff20: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ff40: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ff60: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ff80: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ffa0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
ffc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000005 00000000
ffe0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Call trace:
[<ffff80000009b768>] unmap_range+0x120/0x580
[<ffff80000009cad4>] free_hyp_pgds+0xa8/0xe4
[<ffff80000009b374>] kvm_arch_init+0x268/0x44c
[<ffff80000009606c>] kvm_init+0x24/0x260
[<ffff80000009a338>] arm_init+0x18/0x24
[<ffff8000000814bc>] do_one_initcall+0x88/0x1a0
[<ffff8000006aaac0>] kernel_init_freeable+0x148/0x1e8
[<ffff8000004f8ee4>] kernel_init+0x10/0xd4
Code: 8b000263 92628479 d1000720 eb01001f (f9400340)
---[ end trace 3bc230562e926fa4 ]---
Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Jungseok Lee <jungseoklee85@gmail.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/mmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 2206385..f574732 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -197,7 +197,8 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp,
 	pgd = pgdp + pgd_index(addr);
 	do {
 		next = kvm_pgd_addr_end(addr, end);
-		unmap_puds(kvm, pgd, addr, next);
+		if (!pgd_none(*pgd))
+			unmap_puds(kvm, pgd, addr, next);
 	} while (pgd++, addr = next, addr != end);
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 10/22] arm/arm64: KVM: vgic: Fix error code in kvm_vgic_create()
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (8 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 09/22] arm64: KVM: fix unmapping with 48-bit VAs shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 11/22] arm64/kvm: Fix assembler compatibility of macros shannon.zhao
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable
  Cc: gregkh, christoffer.dall, shannon.zhao, Andre Przywara,
	Marc Zyngier, Paolo Bonzini

From: Christoffer Dall <christoffer.dall@linaro.org>

commit 6b50f54064a02b77a7b990032b80234fee59bcd6 upstream.

If we detect another vCPU is running we just exit and return 0 as if we
succesfully created the VGIC, but the VGIC wouldn't actual be created.

This shouldn't break in-kernel behavior because the kernel will not
observe the failed the attempt to create the VGIC, but userspace could
be rightfully confused.

Cc: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 virt/kvm/arm/vgic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 5309a1d..c324a52 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1611,7 +1611,7 @@ out:
 
 int kvm_vgic_create(struct kvm *kvm)
 {
-	int i, vcpu_lock_idx = -1, ret = 0;
+	int i, vcpu_lock_idx = -1, ret;
 	struct kvm_vcpu *vcpu;
 
 	mutex_lock(&kvm->lock);
@@ -1626,6 +1626,7 @@ int kvm_vgic_create(struct kvm *kvm)
 	 * vcpu->mutex.  By grabbing the vcpu->mutex of all VCPUs we ensure
 	 * that no other VCPUs are run while we create the vgic.
 	 */
+	ret = -EBUSY;
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		if (!mutex_trylock(&vcpu->mutex))
 			goto out_unlock;
@@ -1633,11 +1634,10 @@ int kvm_vgic_create(struct kvm *kvm)
 	}
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
-		if (vcpu->arch.has_run_once) {
-			ret = -EBUSY;
+		if (vcpu->arch.has_run_once)
 			goto out_unlock;
-		}
 	}
+	ret = 0;
 
 	spin_lock_init(&kvm->arch.vgic.lock);
 	kvm->arch.vgic.vctrl_base = vgic_vctrl_base;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 11/22] arm64/kvm: Fix assembler compatibility of macros
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (9 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 10/22] arm/arm64: KVM: vgic: Fix error code in kvm_vgic_create() shannon.zhao
@ 2015-06-30 10:48 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 12/22] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() shannon.zhao
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:48 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Geoff Levand, Will Deacon

From: Geoff Levand <geoff@infradead.org>

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)'

Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Geoff Levand <geoff@infradead.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm64/include/asm/kvm_arm.h | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 2bc2602..ea68925 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -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)
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 12/22] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn()
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (10 preceding siblings ...)
  2015-06-30 10:48 ` [PATCH for 3.14.y stable 11/22] arm64/kvm: Fix assembler compatibility of macros shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 13/22] arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag shannon.zhao
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Ard Biesheuvel,
	Marc Zyngier

From: Ard Biesheuvel <ard.biesheuvel@linaro.org>

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.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/mmu.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index f574732..5b12c49 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -755,6 +755,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,
 			  struct kvm_memory_slot *memslot,
 			  unsigned long fault_status)
@@ -825,7 +830,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;
 
 	spin_lock(&kvm->mmu_lock);
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 13/22] arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (11 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 12/22] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 14/22] arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option shannon.zhao
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

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.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/arm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index fb9c291..4a7f538 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -678,7 +678,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;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 14/22] arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (12 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 13/22] arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 15/22] arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu shannon.zhao
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

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.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 Documentation/virtual/kvm/api.txt | 3 ++-
 arch/arm/kvm/arm.c                | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 6cd63a9..bc6d617 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2344,7 +2344,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).
 
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 4a7f538..9c58125 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -680,6 +680,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;
 }
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 15/22] arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (13 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 14/22] arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 16/22] arm/arm64: KVM: Introduce stage2_unmap_vm shannon.zhao
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

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.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 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(-)

diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h
index 0fa90c9..853e2be 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -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;
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 9c58125..077f82d0 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -675,6 +675,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.
 	 */
diff --git a/arch/arm/kvm/guest.c b/arch/arm/kvm/guest.c
index b23a59c..2786eae 100644
--- a/arch/arm/kvm/guest.c
+++ b/arch/arm/kvm/guest.c
@@ -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;
 }
 
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index dd8ecfc3..681cb90 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -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;
diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c
index 0874557..a8d81fa 100644
--- a/arch/arm64/kvm/guest.c
+++ b/arch/arm64/kvm/guest.c
@@ -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;
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 16/22] arm/arm64: KVM: Introduce stage2_unmap_vm
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (14 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 15/22] arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 17/22] arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized shannon.zhao
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

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.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 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(+)

diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
index 630869e..9f79231 100644
--- a/arch/arm/include/asm/kvm_mmu.h
+++ b/arch/arm/include/asm/kvm_mmu.h
@@ -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,
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 077f82d0..039df03 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -675,6 +675,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);
 
 	/*
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 5b12c49..524b4b5 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -556,6 +556,71 @@ static void unmap_stage2_range(struct kvm *kvm, phys_addr_t start, u64 size)
 	unmap_range(kvm, kvm->arch.pgd, start, size);
 }
 
+static void stage2_unmap_memslot(struct kvm *kvm,
+				 struct kvm_memory_slot *memslot)
+{
+	hva_t hva = memslot->userspace_addr;
+	phys_addr_t addr = memslot->base_gfn << PAGE_SHIFT;
+	phys_addr_t size = PAGE_SIZE * memslot->npages;
+	hva_t reg_end = hva + size;
+
+	/*
+	 * A memory region could potentially cover multiple VMAs, and any holes
+	 * between them, so iterate over all of them to find out if we should
+	 * unmap any of them.
+	 *
+	 *     +--------------------------------------------+
+	 * +---------------+----------------+   +----------------+
+	 * |   : VMA 1     |      VMA 2     |   |    VMA 3  :    |
+	 * +---------------+----------------+   +----------------+
+	 *     |               memory region                |
+	 *     +--------------------------------------------+
+	 */
+	do {
+		struct vm_area_struct *vma = find_vma(current->mm, hva);
+		hva_t vm_start, vm_end;
+
+		if (!vma || vma->vm_start >= reg_end)
+			break;
+
+		/*
+		 * Take the intersection of this VMA with the memory region
+		 */
+		vm_start = max(hva, vma->vm_start);
+		vm_end = min(reg_end, vma->vm_end);
+
+		if (!(vma->vm_flags & VM_PFNMAP)) {
+			gpa_t gpa = addr + (vm_start - memslot->userspace_addr);
+			unmap_stage2_range(kvm, gpa, vm_end - vm_start);
+		}
+		hva = vm_end;
+	} while (hva < reg_end);
+}
+
+/**
+ * stage2_unmap_vm - Unmap Stage-2 RAM mappings
+ * @kvm: The struct kvm pointer
+ *
+ * Go through the memregions and unmap any reguler RAM
+ * backing memory already mapped to the VM.
+ */
+void stage2_unmap_vm(struct kvm *kvm)
+{
+	struct kvm_memslots *slots;
+	struct kvm_memory_slot *memslot;
+	int idx;
+
+	idx = srcu_read_lock(&kvm->srcu);
+	spin_lock(&kvm->mmu_lock);
+
+	slots = kvm_memslots(kvm);
+	kvm_for_each_memslot(memslot, slots)
+		stage2_unmap_memslot(kvm, memslot);
+
+	spin_unlock(&kvm->mmu_lock);
+	srcu_read_unlock(&kvm->srcu, idx);
+}
+
 /**
  * kvm_free_stage2_pgd - free all stage-2 tables
  * @kvm:	The KVM struct pointer for the VM.
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index a030d16..0d51874 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -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,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 17/22] arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (15 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 16/22] arm/arm64: KVM: Introduce stage2_unmap_vm shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers shannon.zhao
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

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.

Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Reviewed-by: Eric Auger <eric.auger@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/arm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 039df03..2e74a61 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -220,6 +220,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;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (16 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 17/22] arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-07-01 18:36   ` Greg KH
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 19/22] arm64: KVM: Fix TLB invalidation by IPA/VMID shannon.zhao
                   ` (3 subsequent siblings)
  21 siblings, 1 reply; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao

From: Christoffer Dall <christoffer.dall@linaro.org>

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.

Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/kvm/arm.c           | 13 +++++++++++--
 include/kvm/arm_arch_timer.h | 10 ++++------
 virt/kvm/arm/arch_timer.c    | 30 ++++++++++++++++++++++--------
 3 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 2e74a61..f6a52a2 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -441,6 +441,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))
@@ -452,12 +453,20 @@ 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 (unlikely(!vgic_initialized(vcpu->kvm))) {
-		ret = kvm_vgic_init(vcpu->kvm);
+	if (unlikely(!vgic_initialized(kvm))) {
+		ret = kvm_vgic_init(kvm);
 		if (ret)
 			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;
 }
 
diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h
index 6d9aedd..327b155 100644
--- a/include/kvm/arm_arch_timer.h
+++ b/include/kvm/arm_arch_timer.h
@@ -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) {}
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 5081e80..c6fe405 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -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)
@@ -307,12 +309,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();
 }
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 19/22] arm64: KVM: Fix TLB invalidation by IPA/VMID
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (17 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 20/22] arm64: KVM: Fix HCR setting for 32bit guests shannon.zhao
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Marc Zyngier,
	Paolo Bonzini

From: Marc Zyngier <marc.zyngier@arm.com>

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.

Reported-by: Mario Smarduch <m.smarduch@samsung.com>
Tested-by: Mario Smarduch <m.smarduch@samsung.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm64/kvm/hyp.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 5dfc8331..3aaf3bc 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -629,6 +629,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,
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 20/22] arm64: KVM: Fix HCR setting for 32bit guests
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (18 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 19/22] arm64: KVM: Fix TLB invalidation by IPA/VMID shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 21/22] arm64: KVM: Do not use pgd_index to index stage-2 pgd shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 22/22] arm/arm64: KVM: Keep elrsr/aisr in sync with software model shannon.zhao
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Marc Zyngier,
	Paolo Bonzini

From: Marc Zyngier <marc.zyngier@arm.com>

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.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm64/include/asm/kvm_emulate.h | 2 ++
 arch/arm64/kvm/reset.c               | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 681cb90..91f33c2 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -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)
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 70a7816..0b43265 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -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;
 		}
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 21/22] arm64: KVM: Do not use pgd_index to index stage-2 pgd
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (19 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 20/22] arm64: KVM: Fix HCR setting for 32bit guests shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 22/22] arm/arm64: KVM: Keep elrsr/aisr in sync with software model shannon.zhao
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable; +Cc: gregkh, christoffer.dall, shannon.zhao, Marc Zyngier

From: Marc Zyngier <marc.zyngier@arm.com>

Since we don't backport commit c647355 (KVM: arm: Add initial dirty page
locking support) for linux-3.14.y, there is no stage2_wp_range in
arch/arm/kvm/mmu.c. So ignore the change in stage2_wp_range introduced
by this patch.

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.

Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 arch/arm/include/asm/kvm_mmu.h   | 3 ++-
 arch/arm/kvm/mmu.c               | 6 +++---
 arch/arm64/include/asm/kvm_mmu.h | 2 ++
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
index 9f79231..7d35af3 100644
--- a/arch/arm/include/asm/kvm_mmu.h
+++ b/arch/arm/include/asm/kvm_mmu.h
@@ -117,13 +117,14 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd)
 	(__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);
 	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)
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 524b4b5..c612e37 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -194,7 +194,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);
 		if (!pgd_none(*pgd))
@@ -264,7 +264,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);
@@ -649,7 +649,7 @@ static pmd_t *stage2_get_pmd(struct kvm *kvm, struct kvm_mmu_memory_cache *cache
 	pud_t *pud;
 	pmd_t *pmd;
 
-	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)
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 0d51874..15a8a86 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -69,6 +69,8 @@
 #define PTRS_PER_S2_PGD (1 << (KVM_PHYS_SHIFT - PGDIR_SHIFT))
 #define S2_PGD_ORDER	get_order(PTRS_PER_S2_PGD * sizeof(pgd_t))
 
+#define kvm_pgd_index(addr)    (((addr) >> PGDIR_SHIFT) & (PTRS_PER_S2_PGD - 1))
+
 int create_hyp_mappings(void *from, void *to);
 int create_hyp_io_mappings(void *from, void *to, phys_addr_t);
 void free_boot_hyp_pgd(void);
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH for 3.14.y stable 22/22] arm/arm64: KVM: Keep elrsr/aisr in sync with software model
  2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
                   ` (20 preceding siblings ...)
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 21/22] arm64: KVM: Do not use pgd_index to index stage-2 pgd shannon.zhao
@ 2015-06-30 10:49 ` shannon.zhao
  21 siblings, 0 replies; 26+ messages in thread
From: shannon.zhao @ 2015-06-30 10:49 UTC (permalink / raw)
  To: stable
  Cc: gregkh, christoffer.dall, shannon.zhao, Marc Zyngier,
	Alex Bennée

From: Christoffer Dall <christoffer.dall@linaro.org>

Note the upstream one of this patch requires applying full GICv3 support
but it's out of the scope of stable kernel. So this patch has a huge
modification for stable kernel comparing to the upstream one.

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.

Cc: Marc Zyngier <marc.zyngier@arm.com>
Reported-by: Alex Bennee <alex.bennee@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
 virt/kvm/arm/vgic.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index c324a52..152ec76 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1042,6 +1042,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;
 	}
 
@@ -1055,6 +1056,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;
@@ -1209,6 +1211,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;
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers
  2015-06-30 10:49 ` [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers shannon.zhao
@ 2015-07-01 18:36   ` Greg KH
  2015-07-02  4:06     ` Shannon Zhao
  0 siblings, 1 reply; 26+ messages in thread
From: Greg KH @ 2015-07-01 18:36 UTC (permalink / raw)
  To: shannon.zhao; +Cc: stable, christoffer.dall

On Tue, Jun 30, 2015 at 06:49:06PM +0800, shannon.zhao@linaro.org wrote:
> From: Christoffer Dall <christoffer.dall@linaro.org>
> 
> 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.
> 
> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>

{sigh}

You modified this patch and didn't say you modified it, despite me
asking you to do so.  Why should I trust that the other patches you sent
weren't also modified?

Ugh.  I've stopped here in the series, and I'm really annoyed at this
whole series and just how long it's taken to get this right for a
feature that almost no one cares about...

greg k-h

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers
  2015-07-01 18:36   ` Greg KH
@ 2015-07-02  4:06     ` Shannon Zhao
  2015-07-02  4:30       ` Greg KH
  0 siblings, 1 reply; 26+ messages in thread
From: Shannon Zhao @ 2015-07-02  4:06 UTC (permalink / raw)
  To: Greg KH; +Cc: stable, christoffer.dall



On 2015/7/2 2:36, Greg KH wrote:
> On Tue, Jun 30, 2015 at 06:49:06PM +0800, shannon.zhao@linaro.org wrote:
>> From: Christoffer Dall <christoffer.dall@linaro.org>
>>
>> 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.
>>
>> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
>> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> 
> {sigh}
> 
> You modified this patch and didn't say you modified it, despite me
> asking you to do so.  
I don't think so. If you really have a look at this patch, you should
recognize that this patch is doing the same thing as the original patch
does.

> Why should I trust that the other patches you sent
Trust? Don't say that please. I never felt your trust even from the
beginning of this backport.

> weren't also modified?
> 
> Ugh.  I've stopped here in the series, and I'm really annoyed at this
> whole series and just how long it's taken to get this right for a
> feature that almost no one cares about...
> 
> greg k-h
> 

-- 
Shannon

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers
  2015-07-02  4:06     ` Shannon Zhao
@ 2015-07-02  4:30       ` Greg KH
  0 siblings, 0 replies; 26+ messages in thread
From: Greg KH @ 2015-07-02  4:30 UTC (permalink / raw)
  To: Shannon Zhao; +Cc: stable, christoffer.dall

On Thu, Jul 02, 2015 at 12:06:13PM +0800, Shannon Zhao wrote:
> 
> 
> On 2015/7/2 2:36, Greg KH wrote:
> > On Tue, Jun 30, 2015 at 06:49:06PM +0800, shannon.zhao@linaro.org wrote:
> >> From: Christoffer Dall <christoffer.dall@linaro.org>
> >>
> >> 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.
> >>
> >> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
> >> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> >> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> > 
> > {sigh}
> > 
> > You modified this patch and didn't say you modified it, despite me
> > asking you to do so.  
> I don't think so. If you really have a look at this patch, you should
> recognize that this patch is doing the same thing as the original patch
> does.

Same thing, yes, but you had to modify it, so it is different from the
original patch.  And that's the point, you modified this patch and
didn't say you did so.  And I only caught it because I had to check all
of these patches, which I shouldn't have had to do...

> > Why should I trust that the other patches you sent
> Trust? Don't say that please. I never felt your trust even from the
> beginning of this backport.

Heh, fair enough, it's been a rough series :)

greg k-h

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-07-02  4:30 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-30 10:48 [PATCH for 3.14.y stable 00/22] Backport fixes of KVM/ARM to 3.14.y stable kernel shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 01/22] ARM/arm64: KVM: fix use of WnR bit in kvm_is_write_fault() shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 02/22] KVM: ARM: vgic: plug irq injection race shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 03/22] arm/arm64: KVM: Fix set_clear_sgi_pend_reg offset shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 04/22] arm/arm64: KVM: Fix VTTBR_BADDR_MASK and pgd alloc shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 05/22] arm: kvm: fix CPU hotplug shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 06/22] arm/arm64: KVM: fix potential NULL dereference in user_mem_abort() shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 07/22] arm/arm64: KVM: Ensure memslots are within KVM_PHYS_SIZE shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 08/22] arm: kvm: STRICT_MM_TYPECHECKS fix for user_mem_abort shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 09/22] arm64: KVM: fix unmapping with 48-bit VAs shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 10/22] arm/arm64: KVM: vgic: Fix error code in kvm_vgic_create() shannon.zhao
2015-06-30 10:48 ` [PATCH for 3.14.y stable 11/22] arm64/kvm: Fix assembler compatibility of macros shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 12/22] arm/arm64: kvm: drop inappropriate use of kvm_is_mmio_pfn() shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 13/22] arm/arm64: KVM: Don't clear the VCPU_POWER_OFF flag shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 14/22] arm/arm64: KVM: Correct KVM_ARM_VCPU_INIT power off option shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 15/22] arm/arm64: KVM: Reset the HCR on each vcpu when resetting the vcpu shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 16/22] arm/arm64: KVM: Introduce stage2_unmap_vm shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 17/22] arm/arm64: KVM: Don't allow creating VCPUs after vgic_initialized shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 18/22] arm/arm64: KVM: Require in-kernel vgic for the arch timers shannon.zhao
2015-07-01 18:36   ` Greg KH
2015-07-02  4:06     ` Shannon Zhao
2015-07-02  4:30       ` Greg KH
2015-06-30 10:49 ` [PATCH for 3.14.y stable 19/22] arm64: KVM: Fix TLB invalidation by IPA/VMID shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 20/22] arm64: KVM: Fix HCR setting for 32bit guests shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 21/22] arm64: KVM: Do not use pgd_index to index stage-2 pgd shannon.zhao
2015-06-30 10:49 ` [PATCH for 3.14.y stable 22/22] arm/arm64: KVM: Keep elrsr/aisr in sync with software model shannon.zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).