kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoffer Dall <c.dall@virtualopensystems.com>
To: android-virt@lists.cs.columbia.edu, kvm@vger.kernel.org
Cc: Marc.Zyngier@arm.com, catalin.marinas@arm.com,
	tech@virtualopensystems.com, avi@redhat.com,
	peter.maydell@linaro.org
Subject: [PATCH v5 13/13] ARM: KVM: Support SMP guests
Date: Sun, 11 Dec 2011 05:25:42 -0500	[thread overview]
Message-ID: <20111211102542.21693.39782.stgit@localhost> (raw)
In-Reply-To: <20111211102403.21693.6887.stgit@localhost>

This patch is a beginning attempt to support SMP guests. So far we only
add locking for the second stage PGD stored on the kvm_arch struct.

WARNING: This code is untested and does not yet support SMP guests.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
---
 arch/arm/include/asm/kvm_host.h |   12 ++++++--
 arch/arm/kvm/arm.c              |    1 +
 arch/arm/kvm/mmu.c              |   57 +++++++++++++++++++++++++--------------
 3 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 7fcc412..555a6f1 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -31,9 +31,15 @@ struct kvm_vcpu;
 u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
 
 struct kvm_arch {
-	u32    vmid;	/* The VMID used for the virt. memory system */
-	pgd_t *pgd;	/* 1-level 2nd stage table */
-	u64    vttbr;	/* VTTBR value associated with above pgd and vmid */
+	/* The VMID used for the virt. memory system */
+	u32    vmid;
+
+	/* 1-level 2nd stage table and lock */
+	struct mutex pgd_mutex;
+	pgd_t *pgd;
+
+	/* VTTBR value associated with above pgd and vmid */
+	u64    vttbr;
 };
 
 #define EXCEPTION_NONE      0
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 9c5c38e..14ccc4d 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -119,6 +119,7 @@ int kvm_arch_init_vm(struct kvm *kvm)
 	ret = kvm_alloc_stage2_pgd(kvm);
 	if (ret)
 		goto out_fail_alloc;
+	mutex_init(&kvm->arch.pgd_mutex);
 
 	pgd_phys = virt_to_phys(kvm->arch.pgd);
 	kvm->arch.vttbr = pgd_phys & ((1LLU << 40) - 1) & ~((2 << VTTBR_X) - 1);
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 50c9571..baeb8a1 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -177,6 +177,9 @@ out:
  * Allocates the 1st level table only of size defined by PGD2_ORDER (can
  * support either full 40-bit input addresses or limited to 32-bit input
  * addresses). Clears the allocated pages.
+ *
+ * Note we don't need locking here as this is only called when the VM is
+ * destroyed, which can only be done once.
  */
 int kvm_alloc_stage2_pgd(struct kvm *kvm)
 {
@@ -204,6 +207,9 @@ int kvm_alloc_stage2_pgd(struct kvm *kvm)
  * Walks the level-1 page table pointed to by kvm->arch.pgd and frees all
  * underlying level-2 and level-3 tables before freeing the actual level-1 table
  * and setting the struct pointer to NULL.
+ *
+ * Note we don't need locking here as this is only called when the VM is
+ * destroyed, which can only be done once.
  */
 void kvm_free_stage2_pgd(struct kvm *kvm)
 {
@@ -239,49 +245,38 @@ void kvm_free_stage2_pgd(struct kvm *kvm)
 	kvm->arch.pgd = NULL;
 }
 
-static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
-			  gfn_t gfn, struct kvm_memory_slot *memslot)
+static int __user_mem_abort(struct kvm *kvm, phys_addr_t addr, pfn_t pfn)
 {
-	pfn_t pfn;
 	pgd_t *pgd;
 	pud_t *pud;
 	pmd_t *pmd;
 	pte_t *pte, new_pte;
 
-	pfn = gfn_to_pfn(vcpu->kvm, gfn);
-
-	if (is_error_pfn(pfn)) {
-		kvm_err(-EFAULT, "Guest gfn %u (0x%08lx) does not have "
-				"corresponding host mapping",
-				gfn, gfn << PAGE_SHIFT);
-		return -EFAULT;
-	}
-
 	/* Create 2nd stage page table mapping - Level 1 */
-	pgd = vcpu->kvm->arch.pgd + pgd_index(fault_ipa);
-	pud = pud_offset(pgd, fault_ipa);
+	pgd = kvm->arch.pgd + pgd_index(addr);
+	pud = pud_offset(pgd, addr);
 	if (pud_none(*pud)) {
-		pmd = pmd_alloc_one(NULL, fault_ipa);
+		pmd = pmd_alloc_one(NULL, addr);
 		if (!pmd) {
 			kvm_err(-ENOMEM, "Cannot allocate 2nd stage pmd");
 			return -ENOMEM;
 		}
 		pud_populate(NULL, pud, pmd);
-		pmd += pmd_index(fault_ipa);
+		pmd += pmd_index(addr);
 	} else
-		pmd = pmd_offset(pud, fault_ipa);
+		pmd = pmd_offset(pud, addr);
 
 	/* Create 2nd stage page table mapping - Level 2 */
 	if (pmd_none(*pmd)) {
-		pte = pte_alloc_one_kernel(NULL, fault_ipa);
+		pte = pte_alloc_one_kernel(NULL, addr);
 		if (!pte) {
 			kvm_err(-ENOMEM, "Cannot allocate 2nd stage pte");
 			return -ENOMEM;
 		}
 		pmd_populate_kernel(NULL, pmd, pte);
-		pte += pte_index(fault_ipa);
+		pte += pte_index(addr);
 	} else
-		pte = pte_offset_kernel(pmd, fault_ipa);
+		pte = pte_offset_kernel(pmd, addr);
 
 	/* Create 2nd stage page table mapping - Level 3 */
 	new_pte = pfn_pte(pfn, PAGE_KVM_GUEST);
@@ -290,6 +285,28 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	return 0;
 }
 
+static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
+			  gfn_t gfn, struct kvm_memory_slot *memslot)
+{
+	pfn_t pfn;
+	int ret;
+
+	pfn = gfn_to_pfn(vcpu->kvm, gfn);
+
+	if (is_error_pfn(pfn)) {
+		kvm_err(-EFAULT, "Guest gfn %u (0x%08lx) does not have "
+				"corresponding host mapping",
+				gfn, gfn << PAGE_SHIFT);
+		return -EFAULT;
+	}
+
+	mutex_lock(&vcpu->kvm->arch.pgd_mutex);
+	ret = __user_mem_abort(vcpu->kvm, fault_ipa, pfn);
+	mutex_unlock(&vcpu->kvm->arch.pgd_mutex);
+
+	return ret;
+}
+
 /**
  * kvm_handle_mmio_return -- Handle MMIO loads after user space emulation
  * @vcpu: The VCPU pointer


  parent reply	other threads:[~2011-12-11 10:25 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-11 10:24 [PATCH v5 00/13] KVM/ARM Implementation Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 01/13] ARM: KVM: Initial skeleton to compile KVM support Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 02/13] ARM: KVM: Hypervisor identity mapping Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 03/13] ARM: KVM: Add hypervisor inititalization Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 04/13] ARM: KVM: Memory virtualization setup Christoffer Dall
2011-12-12 14:40   ` Avi Kivity
2011-12-12 15:09     ` [Android-virt] " Christoffer Dall
2011-12-12 15:15       ` Avi Kivity
2011-12-12 15:25         ` Peter Maydell
2011-12-12 15:49           ` Avi Kivity
2011-12-12 17:40             ` Christoffer Dall
2011-12-13 17:10             ` Antonios Motakis
2011-12-13 17:13               ` Christoffer Dall
2011-12-11 10:24 ` [PATCH v5 05/13] ARM: KVM: Inject IRQs and FIQs from userspace Christoffer Dall
2011-12-11 15:18   ` Jan Kiszka
2011-12-11 16:03     ` Peter Maydell
2011-12-11 19:30       ` Christoffer Dall
2011-12-11 19:48         ` Peter Maydell
2011-12-11 20:07           ` [Android-virt] " Christoffer Dall
2011-12-11 20:25             ` Peter Maydell
2011-12-11 21:36               ` Christoffer Dall
2011-12-11 22:12                 ` Peter Maydell
2011-12-11 22:35                   ` Peter Maydell
2011-12-11 22:53                     ` Christoffer Dall
2011-12-11 23:01                       ` Jan Kiszka
2011-12-12 16:31                         ` Peter Maydell
2011-12-12 17:40                           ` Avi Kivity
2011-12-29  1:29                             ` Christoffer Dall
2012-02-09  1:15                             ` Peter Maydell
2011-12-12 11:06             ` Marc Zyngier
2011-12-12 12:54               ` Christoffer Dall
2011-12-12  6:35           ` Alexander Graf
2011-12-11 19:16     ` Christoffer Dall
2011-12-12 13:28   ` Avi Kivity
2011-12-12 14:38     ` [Android-virt] " Christoffer Dall
2011-12-12 14:50       ` Avi Kivity
2011-12-12 15:11         ` Christoffer Dall
2011-12-12 15:16           ` Avi Kivity
2011-12-11 10:24 ` [PATCH v5 06/13] ARM: KVM: World-switch implementation Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 07/13] ARM: KVM: Emulation framework and CP15 emulation Christoffer Dall
2011-12-12 13:44   ` Avi Kivity
2011-12-12 16:17     ` Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 08/13] ARM: KVM: Handle guest faults in KVM Christoffer Dall
2011-12-12 15:05   ` Avi Kivity
2011-12-12 19:53     ` Christoffer Dall
2011-12-13  9:45       ` Avi Kivity
2011-12-13 13:10         ` [Android-virt] " Christoffer Dall
2011-12-13 13:17           ` Marc Zyngier
2011-12-13 13:23           ` Avi Kivity
2011-12-13 13:44             ` Christoffer Dall
2011-12-13 14:27               ` Avi Kivity
2011-12-11 10:25 ` [PATCH v5 09/13] ARM: KVM: Handle I/O aborts Christoffer Dall
2011-12-12 13:54   ` Avi Kivity
2011-12-12 14:56     ` [Android-virt] " Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 10/13] ARM: KVM: Guest wait-for-interrupts (WFI) support Christoffer Dall
2011-12-12 14:12   ` Avi Kivity
2011-12-12 16:20     ` Christoffer Dall
2011-12-12 17:44       ` Avi Kivity
2011-12-12 19:21         ` [Android-virt] " Christoffer Dall
2011-12-13  9:41           ` Avi Kivity
2011-12-11 10:25 ` [PATCH v5 11/13] ARM: KVM: Support SMP hosts Christoffer Dall
2011-12-12 14:30   ` Avi Kivity
2011-12-12 17:37     ` Christoffer Dall
2011-12-12 17:56       ` Avi Kivity
2011-12-12 19:38         ` [Android-virt] " Christoffer Dall
     [not found]         ` <CAEDV+gJ=zeDpfp0kS2uBvmgRMyCpsV1LitjKR66R4W9Y3VGgWw@mail.gmail.com>
     [not found]           ` <4EE71CF1.5080705@redhat.com>
2011-12-13 13:36             ` Christoffer Dall
2011-12-13 14:17               ` Avi Kivity
2011-12-13 14:36                 ` Christoffer Dall
2011-12-13 14:17               ` Marc Zyngier
2011-12-19  6:15   ` Antonios Motakis
2011-12-19 14:57     ` [Android-virt] " Christoffer Dall
2011-12-19 15:19       ` Marc Zyngier
2011-12-19 15:30         ` Antonios Motakis
2011-12-19 15:37           ` Marc Zyngier
2011-12-19 15:40             ` Christoffer Dall
2011-12-19 15:42               ` Antonios Motakis
2011-12-19 15:45                 ` Marc Zyngier
     [not found]                   ` <CAEDV+gL929Hpa=PncVWeHRNAa5fBuorNNYFC=iix=PO+5aO2cg@mail.gmail.com>
2011-12-19 17:19                     ` Peter Maydell
2011-12-19 17:24                       ` Christoffer Dall
2011-12-19 17:36                         ` Peter Maydell
2011-12-19 17:40                           ` Christoffer Dall
2011-12-11 10:25 ` [PATCH v5 12/13] ARM: KVM: Fix guest view of MPIDR Christoffer Dall
2011-12-12 14:32   ` Avi Kivity
2011-12-12 17:39     ` Christoffer Dall
2011-12-12 17:44       ` Marc Zyngier
2011-12-12 19:43         ` Christoffer Dall
2011-12-13  9:46           ` Avi Kivity
2011-12-13 13:38             ` Christoffer Dall
2011-12-11 10:25 ` Christoffer Dall [this message]
2011-12-11 11:32 ` [PATCH v5 00/13] KVM/ARM Implementation Peter Maydell
2011-12-11 19:23   ` Christoffer Dall
2011-12-11 19:27     ` Peter Maydell
2012-01-11 16:48     ` Peter Maydell
2012-01-12  3:29       ` Christoffer Dall
2012-01-12  8:19         ` Peter Maydell
2012-01-12 16:15           ` [Android-virt] " Christoffer Dall
2012-01-20  2:59             ` Christoffer Dall
2012-01-30 22:46               ` Peter Maydell
2012-01-30 23:02                 ` Alexander Graf
2012-01-31 14:39                 ` Antonios Motakis
2012-02-01 12:11                 ` Marc Zyngier
2012-02-01 12:20                   ` Peter Maydell
2012-02-01 13:40                     ` Marc Zyngier
2012-02-01 13:57                       ` Peter Maydell
2012-02-01 13:59                       ` Christoffer Dall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111211102542.21693.39782.stgit@localhost \
    --to=c.dall@virtualopensystems.com \
    --cc=Marc.Zyngier@arm.com \
    --cc=android-virt@lists.cs.columbia.edu \
    --cc=avi@redhat.com \
    --cc=catalin.marinas@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=peter.maydell@linaro.org \
    --cc=tech@virtualopensystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).