linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL] KVM/ARM Updates for 3.14
@ 2014-01-08 22:47 Christoffer Dall
  2014-01-08 22:47 ` [PATCH 1/5] arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings Christoffer Dall
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Christoffer Dall @ 2014-01-08 22:47 UTC (permalink / raw)
  To: linux-arm-kernel

The following changes since commit d6d63b51fe3bfea0cf596993afa480b0b3b02c32:

  Merge tag 'kvm-s390-20131128' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into kvm-next (2013-11-28 15:30:16 +0100)

are available in the git repository at:


  git://git.linaro.org/people/christoffer.dall/linux-kvm-arm.git tags/kvm-arm-for-3.14

for you to fetch changes up to 61466710de078c697106fa5b70ec7afc9feab520:

  KVM: ARM: Remove duplicate include (2014-01-08 13:54:00 -0800)

----------------------------------------------------------------
KVM/ARM Changes for 3.14

 - Changes to idmap use for keystone compatibility
 - Documentation fixes
 - Fix PSCI race occasionally preventing 2nd CPUs from boot
 - Relax THP alignment requirement
 - Remove duplicate header include

----------------------------------------------------------------
Anup Patel (1):
      KVM: Documentation: Fix typo for KVM_ARM_VCPU_INIT ioctl

Christoffer Dall (1):
      arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive

Marc Zyngier (1):
      arm/arm64: KVM: relax the requirements of VMA alignment for THP

Sachin Kamat (1):
      KVM: ARM: Remove duplicate include

Santosh Shilimkar (1):
      arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

 Documentation/virtual/kvm/api.txt |  2 +-
 arch/arm/include/asm/kvm_mmu.h    |  1 +
 arch/arm/kvm/arm.c                | 30 +++++++++++++++++++-----------
 arch/arm/kvm/handle_exit.c        |  2 --
 arch/arm/kvm/mmu.c                | 24 +++++++++++++-----------
 arch/arm/kvm/psci.c               | 11 ++++++-----
 arch/arm64/include/asm/kvm_mmu.h  |  1 +
 7 files changed, 41 insertions(+), 30 deletions(-)

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

* [PATCH 1/5] arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings
  2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
@ 2014-01-08 22:47 ` Christoffer Dall
  2014-01-08 22:47 ` [PATCH 2/5] KVM: Documentation: Fix typo for KVM_ARM_VCPU_INIT ioctl Christoffer Dall
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Christoffer Dall @ 2014-01-08 22:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Santosh Shilimkar <santosh.shilimkar@ti.com>

KVM initialisation fails on architectures implementing virt_to_idmap()
because virt_to_phys() on such architectures won't fetch you the correct
idmap page.

So update the KVM ARM code to use the virt_to_idmap() to fix the issue.
Since the KVM code is shared between arm and arm64, we create
kvm_virt_to_phys() and handle the redirection in respective headers.

Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 arch/arm/include/asm/kvm_mmu.h   | 1 +
 arch/arm/kvm/mmu.c               | 8 ++++----
 arch/arm64/include/asm/kvm_mmu.h | 1 +
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
index 77de4a4..2d122ad 100644
--- a/arch/arm/include/asm/kvm_mmu.h
+++ b/arch/arm/include/asm/kvm_mmu.h
@@ -140,6 +140,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__cpuc_flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		virt_to_idmap((unsigned long)(x))
 
 #endif	/* !__ASSEMBLY__ */
 
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 5809069..659db0e 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -916,9 +916,9 @@ int kvm_mmu_init(void)
 {
 	int err;
 
-	hyp_idmap_start = virt_to_phys(__hyp_idmap_text_start);
-	hyp_idmap_end = virt_to_phys(__hyp_idmap_text_end);
-	hyp_idmap_vector = virt_to_phys(__kvm_hyp_init);
+	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
+	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
+	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
 
 	if ((hyp_idmap_start ^ hyp_idmap_end) & PAGE_MASK) {
 		/*
@@ -945,7 +945,7 @@ int kvm_mmu_init(void)
 		 */
 		kvm_flush_dcache_to_poc(init_bounce_page, len);
 
-		phys_base = virt_to_phys(init_bounce_page);
+		phys_base = kvm_virt_to_phys(init_bounce_page);
 		hyp_idmap_vector += phys_base - hyp_idmap_start;
 		hyp_idmap_start = phys_base;
 		hyp_idmap_end = phys_base + len;
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 680f74e..7f1f940 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -136,6 +136,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		__virt_to_phys((unsigned long)(x))
 
 #endif /* __ASSEMBLY__ */
 #endif /* __ARM64_KVM_MMU_H__ */
-- 
1.8.5.2

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

* [PATCH 2/5] KVM: Documentation: Fix typo for KVM_ARM_VCPU_INIT ioctl
  2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
  2014-01-08 22:47 ` [PATCH 1/5] arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings Christoffer Dall
@ 2014-01-08 22:47 ` Christoffer Dall
  2014-01-08 22:47 ` [PATCH 3/5] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive Christoffer Dall
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Christoffer Dall @ 2014-01-08 22:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Anup Patel <anup.patel@linaro.org>

Fix minor typo in "Parameters:" of KVM_ARM_VCPU_INIT documentation.

Signed-off-by: Anup Patel <anup.patel@linaro.org>
Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 Documentation/virtual/kvm/api.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index a30035d..aad3244 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -2327,7 +2327,7 @@ current state.  "addr" is ignored.
 Capability: basic
 Architectures: arm, arm64
 Type: vcpu ioctl
-Parameters: struct struct kvm_vcpu_init (in)
+Parameters: struct kvm_vcpu_init (in)
 Returns: 0 on success; -1 on error
 Errors:
  ?EINVAL: ???the target is unknown, or the combination of features is invalid.
-- 
1.8.5.2

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

* [PATCH 3/5] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive
  2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
  2014-01-08 22:47 ` [PATCH 1/5] arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings Christoffer Dall
  2014-01-08 22:47 ` [PATCH 2/5] KVM: Documentation: Fix typo for KVM_ARM_VCPU_INIT ioctl Christoffer Dall
@ 2014-01-08 22:47 ` Christoffer Dall
  2014-01-08 22:47 ` [PATCH 4/5] arm/arm64: KVM: relax the requirements of VMA alignment for THP Christoffer Dall
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Christoffer Dall @ 2014-01-08 22:47 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 arch/arm/kvm/arm.c  | 30 +++++++++++++++++++-----------
 arch/arm/kvm/psci.c | 11 ++++++-----
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 2a700e0..151eb91 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -478,15 +478,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;
 }
 
@@ -700,6 +691,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)
 {
@@ -713,8 +722,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: {
diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c
index 0881bf1..448f60e 100644
--- a/arch/arm/kvm/psci.c
+++ b/arch/arm/kvm/psci.c
@@ -54,15 +54,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 */
@@ -79,6 +79,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;
-- 
1.8.5.2

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

* [PATCH 4/5] arm/arm64: KVM: relax the requirements of VMA alignment for THP
  2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
                   ` (2 preceding siblings ...)
  2014-01-08 22:47 ` [PATCH 3/5] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive Christoffer Dall
@ 2014-01-08 22:47 ` Christoffer Dall
  2014-01-08 22:47 ` [PATCH 5/5] KVM: ARM: Remove duplicate include Christoffer Dall
  2014-01-15 11:15 ` [GIT PULL] KVM/ARM Updates for 3.14 Paolo Bonzini
  5 siblings, 0 replies; 7+ messages in thread
From: Christoffer Dall @ 2014-01-08 22:47 UTC (permalink / raw)
  To: linux-arm-kernel

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

The THP code in KVM/ARM is a bit restrictive in not allowing a THP
to be used if the VMA is not 2MB aligned. Actually, it is not so much
the VMA that matters, but the associated memslot:

A process can perfectly mmap a region with no particular alignment
restriction, and then pass a 2MB aligned address to KVM. In this
case, KVM will only use this 2MB aligned region, and will ignore
the range between vma->vm_start and memslot->userspace_addr.

It can also choose to place this memslot at whatever alignment it
wants in the IPA space. In the end, what matters is the relative
alignment of the user space and IPA mappings with respect to a
2M page. They absolutely must be the same if you want to use THP.

Cc: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 arch/arm/kvm/mmu.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 659db0e..7789857 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -667,14 +667,16 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 		gfn = (fault_ipa & PMD_MASK) >> PAGE_SHIFT;
 	} else {
 		/*
-		 * Pages belonging to VMAs not aligned to the PMD mapping
-		 * granularity cannot be mapped using block descriptors even
-		 * if the pages belong to a THP for the process, because the
-		 * stage-2 block descriptor will cover more than a single THP
-		 * and we loose atomicity for unmapping, updates, and splits
-		 * of the THP or other pages in the stage-2 block range.
+		 * Pages belonging to memslots that don't have the same
+		 * alignment for userspace and IPA cannot be mapped using
+		 * block descriptors even if the pages belong to a THP for
+		 * the process, because the stage-2 block descriptor will
+		 * cover more than a single THP and we loose atomicity for
+		 * unmapping, updates, and splits of the THP or other pages
+		 * in the stage-2 block range.
 		 */
-		if (vma->vm_start & ~PMD_MASK)
+		if ((memslot->userspace_addr & ~PMD_MASK) !=
+		    ((memslot->base_gfn << PAGE_SHIFT) & ~PMD_MASK))
 			force_pte = true;
 	}
 	up_read(&current->mm->mmap_sem);
-- 
1.8.5.2

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

* [PATCH 5/5] KVM: ARM: Remove duplicate include
  2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
                   ` (3 preceding siblings ...)
  2014-01-08 22:47 ` [PATCH 4/5] arm/arm64: KVM: relax the requirements of VMA alignment for THP Christoffer Dall
@ 2014-01-08 22:47 ` Christoffer Dall
  2014-01-15 11:15 ` [GIT PULL] KVM/ARM Updates for 3.14 Paolo Bonzini
  5 siblings, 0 replies; 7+ messages in thread
From: Christoffer Dall @ 2014-01-08 22:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Sachin Kamat <sachin.kamat@linaro.org>

trace.h was included twice. Remove duplicate inclusion.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
---
 arch/arm/kvm/handle_exit.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c
index a920790..0de91fc 100644
--- a/arch/arm/kvm/handle_exit.c
+++ b/arch/arm/kvm/handle_exit.c
@@ -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)
-- 
1.8.5.2

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

* [GIT PULL] KVM/ARM Updates for 3.14
  2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
                   ` (4 preceding siblings ...)
  2014-01-08 22:47 ` [PATCH 5/5] KVM: ARM: Remove duplicate include Christoffer Dall
@ 2014-01-15 11:15 ` Paolo Bonzini
  5 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2014-01-15 11:15 UTC (permalink / raw)
  To: linux-arm-kernel

Il 08/01/2014 23:47, Christoffer Dall ha scritto:
>   git://git.linaro.org/people/christoffer.dall/linux-kvm-arm.git tags/kvm-arm-for-3.14

Pulled, thanks.

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

end of thread, other threads:[~2014-01-15 11:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-08 22:47 [GIT PULL] KVM/ARM Updates for 3.14 Christoffer Dall
2014-01-08 22:47 ` [PATCH 1/5] arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings Christoffer Dall
2014-01-08 22:47 ` [PATCH 2/5] KVM: Documentation: Fix typo for KVM_ARM_VCPU_INIT ioctl Christoffer Dall
2014-01-08 22:47 ` [PATCH 3/5] arm: KVM: Don't return PSCI_INVAL if waitqueue is inactive Christoffer Dall
2014-01-08 22:47 ` [PATCH 4/5] arm/arm64: KVM: relax the requirements of VMA alignment for THP Christoffer Dall
2014-01-08 22:47 ` [PATCH 5/5] KVM: ARM: Remove duplicate include Christoffer Dall
2014-01-15 11:15 ` [GIT PULL] KVM/ARM Updates for 3.14 Paolo Bonzini

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