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 12/13] ARM: KVM: Fix guest view of MPIDR
Date: Sun, 11 Dec 2011 05:25:36 -0500	[thread overview]
Message-ID: <20111211102536.21693.48826.stgit@localhost> (raw)
In-Reply-To: <20111211102403.21693.6887.stgit@localhost>

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

A guest may need to know which CPU it has booted on (and Linux does).
Now that we can run KVM on a SMP host, QEMU may be running on any
CPU. In that case, directly reading MPIDR will give an inconsistent
view on the guest CPU number (among other problems).

The solution is to use the VMPIDR register, which is computed by
using the host MPIDR and overriding the low bits with KVM vcpu_id.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/arm/include/asm/kvm_host.h |    1 +
 arch/arm/kernel/asm-offsets.c   |    1 +
 arch/arm/kvm/arm.c              |    4 ++++
 arch/arm/kvm/interrupts.S       |    8 ++++++++
 4 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index a0ffbe8..7fcc412 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -63,6 +63,7 @@ struct kvm_vcpu_arch {
 	/* System control coprocessor (cp15) */
 	struct {
 		u32 c0_MIDR;		/* Main ID Register */
+		u32 c0_MPIDR;		/* MultiProcessor ID Register */
 		u32 c1_SCTLR;		/* System Control Register */
 		u32 c1_ACTLR;		/* Auxilliary Control Register */
 		u32 c1_CPACR;		/* Coprocessor Access Control */
diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c
index c126cfb..1c6e2ee 100644
--- a/arch/arm/kernel/asm-offsets.c
+++ b/arch/arm/kernel/asm-offsets.c
@@ -148,6 +148,7 @@ int main(void)
 #ifdef CONFIG_KVM_ARM_HOST
   DEFINE(VCPU_KVM,		offsetof(struct kvm_vcpu, kvm));
   DEFINE(VCPU_MIDR,		offsetof(struct kvm_vcpu, arch.cp15.c0_MIDR));
+  DEFINE(VCPU_MPIDR,		offsetof(struct kvm_vcpu, arch.cp15.c0_MPIDR));
   DEFINE(VCPU_SCTLR,		offsetof(struct kvm_vcpu, arch.cp15.c1_SCTLR));
   DEFINE(VCPU_CPACR,		offsetof(struct kvm_vcpu, arch.cp15.c1_CPACR));
   DEFINE(VCPU_TTBR0,		offsetof(struct kvm_vcpu, arch.cp15.c2_TTBR0));
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 6e384e2..9c5c38e 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -32,6 +32,7 @@
 #include <asm/ptrace.h>
 #include <asm/mman.h>
 #include <asm/tlbflush.h>
+#include <asm/cputype.h>
 #include <asm/kvm_arm.h>
 #include <asm/kvm_asm.h>
 #include <asm/kvm_mmu.h>
@@ -270,6 +271,9 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
 			[sctlr] "=r" (sctlr));
 	vcpu->arch.cp15.c1_SCTLR = sctlr & ~1U;
 
+	/* Compute guest MPIDR */
+	vcpu->arch.cp15.c0_MPIDR = (read_cpuid_mpidr() & ~0xff) | vcpu->vcpu_id;
+
 	return 0;
 }
 
diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S
index d516bf4..fbc26ca 100644
--- a/arch/arm/kvm/interrupts.S
+++ b/arch/arm/kvm/interrupts.S
@@ -245,6 +245,10 @@ ENTRY(__kvm_vcpu_run)
 	ldr	r1, [r0, #VCPU_MIDR]
 	mcr	p15, 4, r1, c0, c0, 0
 
+	@ Write guest view of MPIDR into VMPIDR
+	ldr	r1, [r0, #VCPU_MPIDR]
+	mcr	p15, 4, r1, c0, c0, 5
+
 	@ Load guest registers
 	add	r0, r0, #(VCPU_USR_SP)
 	load_mode_state r0, usr
@@ -291,6 +295,10 @@ __kvm_vcpu_return:
 	mrc	p15, 0, r2, c0, c0, 0
 	mcr	p15, 4, r2, c0, c0, 0
 
+	@ Back to hardware MPIDR
+	mrc	p15, 0, r2, c0, c0, 5
+	mcr	p15, 4, r2, c0, c0, 5
+
 	@ Set VMID == 0
 	mov	r2, #0
 	mov	r3, #0


  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 ` Christoffer Dall [this message]
2011-12-12 14:32   ` [PATCH v5 12/13] ARM: KVM: Fix guest view of MPIDR 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 ` [PATCH v5 13/13] ARM: KVM: Support SMP guests Christoffer Dall
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=20111211102536.21693.48826.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).