Skip to contentSkip to conversation

PPC KVM patches

GIT PULL New Alexander Graf 1 participant 6 messages May 4, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi Marcelo / Avi,

This is my current PPC KVM patch queue. Please pull.

Alex

The following changes since commit 40f4a244a3687d390e97f8e5240f5a701e630ccc:
Avi Kivity (1):
KVM: VMX: Cache vmcs segment fields

are available in the git repository at:

git://github.com/agraf/linux-2.6.git kvm-ppc-next

Scott Wood (4):
KVM: PPC: e500: emulate SVR
KVM: PPC: fix exit accounting for SPRs, tlbwe, tlbsx
KVM: PPC: booke: save/restore VRSAVE (a.k.a. USPRG0)
KVM: PPC: booke: add sregs support

Stuart Yoder (1):
KVM: PPC: use ticks, not usecs, for exit timing

 Documentation/kvm/api.txt           |    6 +-
 arch/powerpc/include/asm/kvm.h      |  184 +++++++++++++++++++++++++++++++++++
 arch/powerpc/include/asm/kvm_44x.h  |    1 -
 arch/powerpc/include/asm/kvm_e500.h |    2 +
 arch/powerpc/include/asm/kvm_host.h |    4 +
 arch/powerpc/include/asm/kvm_ppc.h  |    9 ++
 arch/powerpc/kernel/asm-offsets.c   |    1 +
 arch/powerpc/kvm/44x.c              |   10 ++
 arch/powerpc/kvm/44x_emulate.c      |    2 -
 arch/powerpc/kvm/booke.c            |  154 +++++++++++++++++++++++++++++-
 arch/powerpc/kvm/booke_interrupts.S |    1 -
 arch/powerpc/kvm/e500.c             |   76 ++++++++++++++
 arch/powerpc/kvm/e500_emulate.c     |    7 +-
 arch/powerpc/kvm/e500_tlb.c         |   13 +++-
 arch/powerpc/kvm/emulate.c          |   15 ++-
 arch/powerpc/kvm/powerpc.c          |   17 +++
 arch/powerpc/kvm/timing.c           |   21 +++-
 include/linux/kvm.h                 |    1 +
 18 files changed, 503 insertions(+), 21 deletions(-)
#1 lore raw

PATCH 1/5 KVM: PPC: e500: emulate SVR

From: Scott Wood <[email protected]>

Return the actual host SVR for now, as we already do for PVR. Eventually we may support Qemu overriding PVR/SVR if the situation is appropriate, once we implement KVM_SET_SREGS on e500.

---
 arch/powerpc/include/asm/kvm_e500.h |    1 +
 arch/powerpc/kvm/e500.c             |    1 +
 arch/powerpc/kvm/e500_emulate.c     |    2 ++
 3 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +1 -0
index 7fea26f..bb2a089 100644
@@ -43,6 +43,7 @@ struct kvmppc_vcpu_e500 {
 
 	u32 host_pid[E500_PID_NUM];
 	u32 pid[E500_PID_NUM];
+	u32 svr;
 
 	u32 mas0;
 	u32 mas1;
arch/powerpc/kvm/e500.c +1 -0
index e3768ee..0c1af12 100644
@@ -63,6 +63,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 
 	/* Registers init */
 	vcpu->arch.pvr = mfspr(SPRN_PVR);
+	vcpu_e500->svr = mfspr(SPRN_SVR);
 
 	/* Since booke kvm only support one core, update all vcpus' PIR to 0 */
 	vcpu->vcpu_id = 0;
arch/powerpc/kvm/e500_emulate.c +2 -0
index 8e3edfb..e2fb47f 100644
@@ -175,6 +175,8 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
 		kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid0); break;
 	case SPRN_HID1:
 		kvmppc_set_gpr(vcpu, rt, vcpu_e500->hid1); break;
+	case SPRN_SVR:
+		kvmppc_set_gpr(vcpu, rt, vcpu_e500->svr); break;
 
 	case SPRN_MMUCSR0:
 		kvmppc_set_gpr(vcpu, rt, 0); break;
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/5 KVM: PPC: fix exit accounting for SPRs, tlbwe, tlbsx

In reply to Alexander Graf

From: Scott Wood <[email protected]>

The exit type setting for mfspr/mtspr is moved from 44x to toplevel SPR emulation. This enables it on e500, and makes sure that all SPRs are covered.

Exit accounting for tlbwe and tlbsx is added to e500.

---
 arch/powerpc/kvm/44x_emulate.c |    2 --
 arch/powerpc/kvm/e500_tlb.c    |    5 ++++-
 arch/powerpc/kvm/emulate.c     |    2 ++
 3 files changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/kvm/44x_emulate.c +0 -2
index 65ea083..549bb2c 100644
@@ -158,7 +158,6 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
 		emulated = kvmppc_booke_emulate_mtspr(vcpu, sprn, rs);
 	}
 
-	kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS);
 	return emulated;
 }
 
@@ -179,7 +178,6 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)
 		emulated = kvmppc_booke_emulate_mfspr(vcpu, sprn, rt);
 	}
 
-	kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS);
 	return emulated;
 }
 
arch/powerpc/kvm/e500_tlb.c +4 -1
index d6d6d47..56ac452 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, [email protected]
  *
@@ -24,6 +24,7 @@
 #include "../mm/mmu_decl.h"
 #include "e500_tlb.h"
 #include "trace.h"
+#include "timing.h"
 
 #define to_htlb1_esel(esel) (tlb1_entry_num - (esel) - 1)
 
@@ -506,6 +507,7 @@ int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb)
 		vcpu_e500->mas7 = 0;
 	}
 
+	kvmppc_set_exit_type(vcpu, EMULATED_TLBSX_EXITS);
 	return EMULATE_DONE;
 }
 
@@ -571,6 +573,7 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
 		write_host_tlbe(vcpu_e500, stlbsel, sesel);
 	}
 
+	kvmppc_set_exit_type(vcpu, EMULATED_TLBWE_EXITS);
 	return EMULATE_DONE;
 }
 
arch/powerpc/kvm/emulate.c +2 -0
index c64fd29..8f7a3aa 100644
@@ -294,6 +294,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 				}
 				break;
 			}
+			kvmppc_set_exit_type(vcpu, EMULATED_MFSPR_EXITS);
 			break;
 
 		case OP_31_XOP_STHX:
@@ -363,6 +364,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 					printk("mtspr: unknown spr %x\n", sprn);
 				break;
 			}
+			kvmppc_set_exit_type(vcpu, EMULATED_MTSPR_EXITS);
 			break;
 
 		case OP_31_XOP_DCBI:
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/5 KVM: PPC: use ticks, not usecs, for exit timing

In reply to Alexander Graf

From: Stuart Yoder <[email protected]>

Convert to microseconds when displaying
(with fix from Bharat Bhushan <[email protected]>).

This reduces rounding error with large quantities of short exits.

---
 arch/powerpc/kvm/timing.c |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
arch/powerpc/kvm/timing.c +17 -4
index 18f40fd..319177d 100644
@@ -151,17 +151,30 @@ static int kvmppc_exit_timing_show(struct seq_file *m, void *private)
 {
 	struct kvm_vcpu *vcpu = m->private;
 	int i;
+	u64 min, max, sum, sum_quad;
 
 	seq_printf(m, "%s", "type	count	min	max	sum	sum_squared\n");
 
+
 	for (i = 0; i < __NUMBER_OF_KVM_EXIT_TYPES; i++) {
+
+		min = vcpu->arch.timing_min_duration[i];
+		do_div(min, tb_ticks_per_usec);
+		max = vcpu->arch.timing_max_duration[i];
+		do_div(max, tb_ticks_per_usec);
+		sum = vcpu->arch.timing_sum_duration[i];
+		do_div(sum, tb_ticks_per_usec);
+		sum_quad = vcpu->arch.timing_sum_quad_duration[i];
+		do_div(sum_quad, tb_ticks_per_usec);
+
 		seq_printf(m, "%12s	%10d	%10lld	%10lld	%20lld	%20lld\n",
 			kvm_exit_names[i],
 			vcpu->arch.timing_count_type[i],
-			vcpu->arch.timing_min_duration[i],
-			vcpu->arch.timing_max_duration[i],
-			vcpu->arch.timing_sum_duration[i],
-			vcpu->arch.timing_sum_quad_duration[i]);
+			min,
+			max,
+			sum,
+			sum_quad);
+
 	}
 	return 0;
 }
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/5 KVM: PPC: booke: save/restore VRSAVE (a.k.a. USPRG0)

In reply to Alexander Graf

From: Scott Wood <[email protected]>

Linux doesn't use USPRG0 (now renamed VRSAVE in the architecture, even when Altivec isn't involved), but a guest might.

---
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/kernel/asm-offsets.c   |    1 +
 arch/powerpc/kvm/booke_interrupts.S |    1 -
 arch/powerpc/kvm/powerpc.c          |   13 +++++++++++++
 4 files changed, 15 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
index 890897c..a168043 100644
@@ -223,6 +223,7 @@ struct kvm_vcpu_arch {
 	ulong hflags;
 	ulong guest_owned_ext;
 #endif
+	u32 vrsave; /* also USPRG0 */
 	u32 mmucr;
 	ulong sprg4;
 	ulong sprg5;
arch/powerpc/kernel/asm-offsets.c +1 -0
index 23e6a93..cf0d822 100644
@@ -395,6 +395,7 @@ int main(void)
 	DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
 	DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
 	DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
+	DEFINE(VCPU_VRSAVE, offsetof(struct kvm_vcpu, arch.vrsave));
 	DEFINE(VCPU_SPRG4, offsetof(struct kvm_vcpu, arch.sprg4));
 	DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
 	DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
arch/powerpc/kvm/booke_interrupts.S +0 -1
index 1cc471f..b58ccae 100644
@@ -380,7 +380,6 @@ lightweight_exit:
 	 * because host interrupt handlers would get confused. */
 	lwz	r1, VCPU_GPR(r1)(r4)
 
-	/* XXX handle USPRG0 */
 	/* Host interrupt handlers may have clobbered these guest-readable
 	 * SPRGs, so we need to reload them here with the guest's values. */
 	lwz	r3, VCPU_SPRG4(r4)
arch/powerpc/kvm/powerpc.c +13 -0
index ec3d2e7..9e6aa8b 100644
@@ -298,12 +298,25 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
 
 void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
+#ifdef CONFIG_BOOKE
+	/*
+	 * vrsave (formerly usprg0) isn't used by Linux, but may
+	 * be used by the guest.
+	 *
+	 * On non-booke this is associated with Altivec and
+	 * is handled by code in book3s.c.
+	 */
+	mtspr(SPRN_VRSAVE, vcpu->arch.vrsave);
+#endif
 	kvmppc_core_vcpu_load(vcpu, cpu);
 }
 
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 {
 	kvmppc_core_vcpu_put(vcpu);
+#ifdef CONFIG_BOOKE
+	vcpu->arch.vrsave = mfspr(SPRN_VRSAVE);
+#endif
 }
 
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/5 KVM: PPC: booke: add sregs support

In reply to Alexander Graf

From: Scott Wood <[email protected]>

---
 Documentation/kvm/api.txt           |    6 +-
 arch/powerpc/include/asm/kvm.h      |  184 +++++++++++++++++++++++++++++++++++
 arch/powerpc/include/asm/kvm_44x.h  |    1 -
 arch/powerpc/include/asm/kvm_e500.h |    1 +
 arch/powerpc/include/asm/kvm_host.h |    3 +
 arch/powerpc/include/asm/kvm_ppc.h  |    9 ++
 arch/powerpc/kvm/44x.c              |   10 ++
 arch/powerpc/kvm/booke.c            |  154 +++++++++++++++++++++++++++++-
 arch/powerpc/kvm/e500.c             |   75 ++++++++++++++
 arch/powerpc/kvm/e500_emulate.c     |    5 +-
 arch/powerpc/kvm/e500_tlb.c         |    8 ++
 arch/powerpc/kvm/emulate.c          |   13 ++-
 arch/powerpc/kvm/powerpc.c          |    4 +
 include/linux/kvm.h                 |    1 +
 14 files changed, 461 insertions(+), 13 deletions(-)
Documentation/kvm/api.txt +4 -2
index 1b9eaa7..f64c41f 100644
@@ -261,7 +261,7 @@ See KVM_GET_REGS for the data structure.
 4.13 KVM_GET_SREGS
 
 Capability: basic
-Architectures: x86
+Architectures: x86, ppc
 Type: vcpu ioctl
 Parameters: struct kvm_sregs (out)
 Returns: 0 on success, -1 on error
@@ -279,6 +279,8 @@ struct kvm_sregs {
 	__u64 interrupt_bitmap[(KVM_NR_INTERRUPTS + 63) / 64];
 };
 
+/* ppc -- see arch/powerpc/include/asm/kvm.h */
+
 interrupt_bitmap is a bitmap of pending external interrupts.  At most
 one bit may be set.  This interrupt has been acknowledged by the APIC
 but not yet injected into the cpu core.
@@ -286,7 +288,7 @@ but not yet injected into the cpu core.
 4.14 KVM_SET_SREGS
 
 Capability: basic
-Architectures: x86
+Architectures: x86, ppc
 Type: vcpu ioctl
 Parameters: struct kvm_sregs (in)
 Returns: 0 on success, -1 on error
arch/powerpc/include/asm/kvm.h +184 -0

196 lines not on this page · raw message

arch/powerpc/include/asm/kvm_44x.h +0 -1
index d22d399..a0e5761 100644
@@ -61,7 +61,6 @@ static inline struct kvmppc_vcpu_44x *to_44x(struct kvm_vcpu *vcpu)
 	return container_of(vcpu, struct kvmppc_vcpu_44x, vcpu);
 }
 
-void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 new_pid);
 void kvmppc_44x_tlb_put(struct kvm_vcpu *vcpu);
 void kvmppc_44x_tlb_load(struct kvm_vcpu *vcpu);
 
arch/powerpc/include/asm/kvm_e500.h +1 -0
index bb2a089..7a2a565 100644
@@ -59,6 +59,7 @@ struct kvmppc_vcpu_e500 {
 	u32 hid1;
 	u32 tlb0cfg;
 	u32 tlb1cfg;
+	u64 mcar;
 
 	struct kvm_vcpu vcpu;
 };
arch/powerpc/include/asm/kvm_host.h +3 -0
index a168043..186f150 100644
@@ -233,6 +233,9 @@ struct kvm_vcpu_arch {
 	ulong csrr1;
 	ulong dsrr0;
 	ulong dsrr1;
+	ulong mcsrr0;
+	ulong mcsrr1;
+	ulong mcsr;
 	ulong esr;
 	u32 dec;
 	u32 decar;
arch/powerpc/include/asm/kvm_ppc.h +9 -0
index ecb3bc7..9345238 100644
@@ -61,6 +61,7 @@ extern int kvmppc_emulate_instruction(struct kvm_run *run,
                                       struct kvm_vcpu *vcpu);
 extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
 extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
+extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
 
 /* Core-specific hooks */
 
@@ -142,4 +143,12 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
 	return r;
 }
 
+void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+
+void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
+
+void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
+
 #endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kvm/44x.c +10 -0
index 74d0e74..da3a122 100644
@@ -107,6 +107,16 @@ int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
 	return 0;
 }
 
+void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
+{
+	kvmppc_get_sregs_ivor(vcpu, sregs);
+}
+
+int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
+{
+	return kvmppc_set_sregs_ivor(vcpu, sregs);
+}
+
 struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
 {
 	struct kvmppc_vcpu_44x *vcpu_44x;
arch/powerpc/kvm/booke.c +152 -2

174 lines not on this page · raw message

arch/powerpc/kvm/e500.c +75 -0

81 lines not on this page · raw message

arch/powerpc/kvm/e500_emulate.c +2 -3
index e2fb47f..69cd665 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
  *
  * Author: Yu Liu, <[email protected]>
  *
@@ -78,8 +78,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)
 
 	switch (sprn) {
 	case SPRN_PID:
-		vcpu_e500->pid[0] = vcpu->arch.shadow_pid =
-			vcpu->arch.pid = spr_val;
+		kvmppc_set_pid(vcpu, spr_val);
 		break;
 	case SPRN_PID1:
 		vcpu_e500->pid[1] = spr_val; break;
arch/powerpc/kvm/e500_tlb.c +8 -0
index 56ac452..b18fe35 100644
@@ -675,6 +675,14 @@ int kvmppc_e500_tlb_search(struct kvm_vcpu *vcpu,
 	return -1;
 }
 
+void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid)
+{
+	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+
+	vcpu_e500->pid[0] = vcpu->arch.shadow_pid =
+		vcpu->arch.pid = pid;
+}
+
 void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *vcpu_e500)
 {
 	struct tlbe *tlbe;
arch/powerpc/kvm/emulate.c +8 -5
index 8f7a3aa..141dce3 100644
@@ -114,6 +114,12 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
 	}
 }
 
+u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb)
+{
+	u64 jd = tb - vcpu->arch.dec_jiffies;
+	return vcpu->arch.dec - jd;
+}
+
 /* XXX to do:
  * lhax
  * lhaux
@@ -279,11 +285,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 
 			case SPRN_DEC:
 			{
-				u64 jd = get_tb() - vcpu->arch.dec_jiffies;
-				kvmppc_set_gpr(vcpu, rt, vcpu->arch.dec - jd);
-				pr_debug("mfDEC: %x - %llx = %lx\n",
-					 vcpu->arch.dec, jd,
-					 kvmppc_get_gpr(vcpu, rt));
+				kvmppc_set_gpr(vcpu, rt,
+					       kvmppc_get_dec(vcpu, get_tb()));
 				break;
 			}
 			default:
arch/powerpc/kvm/powerpc.c +4 -0
index 9e6aa8b..616dd51 100644
@@ -175,7 +175,11 @@ int kvm_dev_ioctl_check_extension(long ext)
 	int r;
 
 	switch (ext) {
+#ifdef CONFIG_BOOKE
+	case KVM_CAP_PPC_BOOKE_SREGS:
+#else
 	case KVM_CAP_PPC_SEGSTATE:
+#endif
 	case KVM_CAP_PPC_PAIRED_SINGLES:
 	case KVM_CAP_PPC_UNSET_IRQ:
 	case KVM_CAP_PPC_IRQ_LEVEL:
include/linux/kvm.h +1 -0
index 2f63ebe..55ef181 100644
@@ -543,6 +543,7 @@ struct kvm_ppc_pvinfo {
 #define KVM_CAP_ASYNC_PF 59
 #define KVM_CAP_TSC_CONTROL 60
 #define KVM_CAP_GET_TSC_KHZ 61
+#define KVM_CAP_PPC_BOOKE_SREGS 62
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
Signature · 1 line
1.6.0.2