Skip to contentSkip to conversation

kvmppc: Add e500 support

PATCH In review Liu Yu 2 participants 4 messages Dec 3, 2008 – Dec 5, 2008

Subsystems (2)
lore
Share & tools
lore

Liu Yu

author
#0 lore raw

PATCH 2/3 kvmppc: Add e500 support

Mainly include tlb and instruction emulation.

---
 arch/powerpc/include/asm/kvm_e500.h |   67 ++++
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/kernel/asm-offsets.c   |   17 +-
 arch/powerpc/kvm/44x.c              |   22 +--
 arch/powerpc/kvm/Kconfig            |   13 +
 arch/powerpc/kvm/Makefile           |    8 +
 arch/powerpc/kvm/booke.c            |    2 +-
 arch/powerpc/kvm/booke_interrupts.h |   23 ++
 arch/powerpc/kvm/e500.c             |  172 ++++++++++
 arch/powerpc/kvm/e500_emulate.c     |  359 ++++++++++++++++++++
 arch/powerpc/kvm/e500_tlb.c         |  628 +++++++++++++++++++++++++++++++++++
 arch/powerpc/kvm/e500_tlb.h         |  290 ++++++++++++++++
 12 files changed, 1577 insertions(+), 25 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_e500.h
 create mode 100644 arch/powerpc/kvm/e500.c
 create mode 100644 arch/powerpc/kvm/e500_emulate.c
 create mode 100644 arch/powerpc/kvm/e500_tlb.c
 create mode 100644 arch/powerpc/kvm/e500_tlb.h
arch/powerpc/include/asm/kvm_e500.h new file +67 -0
new file mode 100644
index 0000000..9d497ce
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Yu Liu, <[email protected]>
+ *
+ * Description:
+ * This file is derived from arch/powerpc/include/asm/kvm_44x.h,
+ * by Hollis Blanchard <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_KVM_E500_H__
+#define __ASM_KVM_E500_H__
+
+#include <linux/kvm_host.h>
+
+#define BOOKE_INTERRUPT_SIZE 36
+
+#define E500_PID_NUM   3
+#define E500_TLB_NUM   2
+
+struct tlbe{
+	u32 mas1;
+	u32 mas2;
+	u32 mas3;
+	u32 mas7;
+};
+
+struct kvmppc_vcpu_e500 {
+	/* Unmodified copy of the guest's TLB. */
+	struct tlbe *guest_tlb[E500_TLB_NUM];
+	/* TLB that's actually used when the guest is running. */
+	struct tlbe *shadow_tlb[E500_TLB_NUM];
+	/* Pages which are referenced in the shadow TLB. */
+	struct page **shadow_pages[E500_TLB_NUM];
+
+	unsigned int guest_tlb_size[E500_TLB_NUM];
+	unsigned int shadow_tlb_size[E500_TLB_NUM];
+	unsigned int guest_tlb_nv[E500_TLB_NUM];
+
+	u32 host_pid[E500_PID_NUM];
+	u32 pid[E500_PID_NUM];
+
+	u32 mas0;
+	u32 mas1;
+	u32 mas2;
+	u32 mas3;
+	u32 mas4;
+	u32 mas5;
+	u32 mas6;
+	u32 mas7;
+	u32 l1csr1;
+	u32 hid0;
+	u32 hid1;
+
+	struct kvm_vcpu vcpu;
+};
+
+static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)
+{
+	return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu);
+}
+
+#endif /* __ASM_KVM_E500_H__ */
arch/powerpc/include/asm/kvm_host.h +1 -0
index 2b1a31a..d9018ed 100644
@@ -122,6 +122,7 @@ struct kvm_vcpu_arch {
 	u32 ccr1;
 	u32 dbcr0;
 	u32 dbcr1;
+	u32 dbsr;
 
 	u32 last_inst;
 	ulong fault_dear;
arch/powerpc/kernel/asm-offsets.c +14 -3
index b6367e8..a863487 100644
@@ -49,8 +49,13 @@
 #include <asm/iseries/alpaca.h>
 #endif
 #ifdef CONFIG_KVM
+#ifdef CONFIG_44x
 #include <asm/kvm_44x.h>
 #endif
+#ifdef CONFIG_FSL_BOOKE
+#include <asm/kvm_e500.h>
+#endif
+#endif
 
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
 #include "head_booke.h"
@@ -355,6 +360,7 @@ int main(void)
 	DEFINE(PTE_SIZE, sizeof(pte_t));
 
 #ifdef CONFIG_KVM
+#ifdef CONFIG_44x
 	DEFINE(TLBE_BYTES, sizeof(struct kvmppc_44x_tlbe));
 
 	DEFINE(VCPU_TO_44X, offsetof(struct kvmppc_vcpu_44x, vcpu));
@@ -362,9 +368,15 @@ int main(void)
 	       offsetof(struct kvmppc_vcpu_44x, shadow_tlb));
 	DEFINE(VCPU44x_SHADOW_MOD,
 	       offsetof(struct kvmppc_vcpu_44x, shadow_tlb_mod));
-
-	DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
 	DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
+	DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
+#endif
+#ifdef CONFIG_FSL_BOOKE
+	DEFINE(VCPU_TO_E500, offsetof(struct kvmppc_vcpu_e500, vcpu));
+	DEFINE(VCPU_HOST_PID, offsetof(struct kvmppc_vcpu_e500, host_pid));
+	DEFINE(VCPU_SHADOW_PID, offsetof(struct kvmppc_vcpu_e500, pid));
+#endif
+	DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
 	DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
 	DEFINE(VCPU_LR, offsetof(struct kvm_vcpu, arch.lr));
 	DEFINE(VCPU_CR, offsetof(struct kvm_vcpu, arch.cr));
@@ -376,7 +388,6 @@ int main(void)
 	DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
 	DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
 	DEFINE(VCPU_SPRG7, offsetof(struct kvm_vcpu, arch.sprg7));
-	DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
 
 	DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
 	DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
arch/powerpc/kvm/44x.c +1 -21
index 6d72c9d..22054b1 100644
@@ -216,29 +216,9 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
 
 static int kvmppc_44x_init(void)
 {
-	unsigned long ivor[BOOKE_INTERRUPT_SIZE];
 	int r;
 
-	/* Copy our interrupt handlers to match host IVORs. That way we don't
-	 * have to swap the IVORs on every guest/host transition. */
-	ivor[0] = mfspr(SPRN_IVOR0);
-	ivor[1] = mfspr(SPRN_IVOR1);
-	ivor[2] = mfspr(SPRN_IVOR2);
-	ivor[3] = mfspr(SPRN_IVOR3);
-	ivor[4] = mfspr(SPRN_IVOR4);
-	ivor[5] = mfspr(SPRN_IVOR5);
-	ivor[6] = mfspr(SPRN_IVOR6);
-	ivor[7] = mfspr(SPRN_IVOR7);
-	ivor[8] = mfspr(SPRN_IVOR8);
-	ivor[9] = mfspr(SPRN_IVOR9);
-	ivor[10] = mfspr(SPRN_IVOR10);
-	ivor[11] = mfspr(SPRN_IVOR11);
-	ivor[12] = mfspr(SPRN_IVOR12);
-	ivor[13] = mfspr(SPRN_IVOR13);
-	ivor[14] = mfspr(SPRN_IVOR14);
-	ivor[15] = mfspr(SPRN_IVOR15);
-
-	r = kvmppc_booke_init(ivor, sizeof(ivor)/sizeof(ivor[0]));
+	r = kvmppc_booke_init();
 	if (r)
 		return r;
 
arch/powerpc/kvm/Kconfig +13 -0
index e4ab1c7..426f666 100644
@@ -32,6 +32,19 @@ config KVM_440
 
 	  If unsure, say N.
 
+config KVM_E500
+	bool "KVM support for PowerPC E500 processors"
+	depends on EXPERIMENTAL && E500
+	select KVM
+	---help---
+	  Support running unmodified E500 guest kernels in virtual machines on
+	  E500 host processors.
+
+	  This module provides access to the hardware capabilities through
+	  a character device node named /dev/kvm.
+
+	  If unsure, say N.
+
 config KVM_TRACE
 	bool "KVM trace support"
 	depends on KVM && MARKERS && SYSFS
arch/powerpc/kvm/Makefile +8 -0
index f045fad..90421a4 100644
@@ -20,3 +20,11 @@ kvm-440-objs := \
 	44x_tlb.o \
 	44x_emulate.o
 obj-$(CONFIG_KVM_440) += kvm-440.o
+
+kvm-e500-objs := \
+	booke.o \
+	booke_interrupts.o \
+	e500.o \
+	e500_tlb.o \
+	e500_emulate.o
+obj-$(CONFIG_KVM_E500) += kvm-e500.o
arch/powerpc/kvm/booke.c +1 -1
index d96f793..8dcfb74 100644
@@ -424,7 +424,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
 	regs->msr = vcpu->arch.msr;
 	regs->srr0 = vcpu->arch.srr0;
 	regs->srr1 = vcpu->arch.srr1;
-	regs->pid = vcpu->arch.pid;
+	regs->pid = get_cur_pid(vcpu);
 	regs->sprg0 = vcpu->arch.sprg0;
 	regs->sprg1 = vcpu->arch.sprg1;
 	regs->sprg2 = vcpu->arch.sprg2;
arch/powerpc/kvm/booke_interrupts.h +23 -0
index bbd10fd..c8ef553 100644
@@ -1,6 +1,8 @@
 #ifndef __KVMPPC_BOOKE_INTERRUPT_H__
 #define __KVMPPC_BOOKE_INTERRUPT_H__
 
+#include <asm/asm-offsets.h>
+
 #ifdef CONFIG_44x
 #include <asm/mmu-44x.h>
 
@@ -51,4 +53,25 @@
 
 #endif
 
+
+#ifdef CONFIG_FSL_BOOKE
+#define LOAD_PID(addr)					\
+	lwz     r3, (addr - VCPU_TO_E500)(r4);		\
+	mtspr   SPRN_PID, r3;				\
+	lwz     r3, (addr - VCPU_TO_E500 + 4)(r4);	\
+	mtspr   SPRN_PID1, r3;				\
+	lwz     r3, (addr - VCPU_TO_E500 + 8)(r4);	\
+	mtspr   SPRN_PID2, r3
+
+#define SAVE_PID(addr)					\
+	mfspr   r3, SPRN_PID;				\
+	stw     r3, (addr - VCPU_TO_E500)(r4);		\
+	mfspr   r3, SPRN_PID1;				\
+	stw     r3, (addr - VCPU_TO_E500 + 4)(r4);	\
+	mfspr   r3, SPRN_PID2;				\
+	stw     r3, (addr - VCPU_TO_E500 + 8)(r4)
+
+#define LOAD_GUEST_TLB
+#endif
+
 #endif /* __KVMPPC_BOOKE_INTERRUPT_H__ */
arch/powerpc/kvm/e500.c new file +172 -0

172 lines not on this page · raw message

arch/powerpc/kvm/e500_emulate.c new file +359 -0

359 lines not on this page · raw message

arch/powerpc/kvm/e500_tlb.c new file +624 -0

624 lines not on this page · raw message

arch/powerpc/kvm/e500_tlb.h new file +289 -0

289 lines not on this page · raw message

Signature · 1 line
1.5.4
author
#1 lore raw
Quoted 9 lines

-----Original Message-----
From: Liu Yu-B13201
Sent: Wednesday, December 03, 2008 5:29 PM
To: [email protected]
Cc: [email protected]; Liu Yu-B13201
Subject: [PATCH 2/3] kvmppc: Add e500 support

Quoted 8 lines

Mainly include tlb and instruction emulation.

---
 arch/powerpc/include/asm/kvm_e500.h |   67 ++++
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/kernel/asm-offsets.c   |   17 +-
 arch/powerpc/kvm/44x.c              |   22 +--

Sorry. diff about this file 44x.c is a regression. Due to wrong operation.
Will fixed in next version. Please ignore it.

Quoted 16 lines
 arch/powerpc/kvm/Kconfig            |   13 +
 arch/powerpc/kvm/Makefile           |    8 +
 arch/powerpc/kvm/booke.c            |    2 +-
 arch/powerpc/kvm/booke_interrupts.h |   23 ++
 arch/powerpc/kvm/e500.c             |  172 ++++++++++
 arch/powerpc/kvm/e500_emulate.c     |  359 ++++++++++++++++++++
 arch/powerpc/kvm/e500_tlb.c         |  628 
+++++++++++++++++++++++++++++++++++
 arch/powerpc/kvm/e500_tlb.h         |  290 ++++++++++++++++
 12 files changed, 1577 insertions(+), 25 deletions(-)
 create mode 100644 arch/powerpc/include/asm/kvm_e500.h
 create mode 100644 arch/powerpc/kvm/e500.c
 create mode 100644 arch/powerpc/kvm/e500_emulate.c
 create mode 100644 arch/powerpc/kvm/e500_tlb.c
 create mode 100644 arch/powerpc/kvm/e500_tlb.h
#2 lore raw
In reply to Liu Yu

I haven't gone through this all (since it won't apply/build now), but just a couple quick comments:

Quoted 19 lines · Liu Yu
arch/powerpc/kvm/e500_tlb.h new file +13 -0
new file mode 100644
index 0000000..6adda39
@@ -0,0 +1,290 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
+ *
+ * Author: Yu Liu, [email protected], Aug, 2008
+ *
+ * Description:
+ * This file is based on arch/powerpc/kvm/44x_tlb.h,
+ * by Hollis Blanchard <[email protected]>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation.
+ */

arch/powerpc/kvm/e500_tlb.h line 23

Quoted 10 lines
arch/powerpc/kvm/e500_tlb.h new file +10 -0
+
+#ifndef __KVM_E500_TLB_H__
+#define __KVM_E500_TLB_H__
+
+#include <linux/kvm_host.h>
+#include <asm/mmu-fsl-booke.h>
+#include <asm/tlb.h>
+#include <asm/kvm_e500.h>
+
+#define KVM_E500_TLB0_ENABLE   /* Enable it to utilize TLB0 */

Just remove this ifdef completely.

arch/powerpc/kvm/e500_tlb.h line 31

Quoted 7 lines
arch/powerpc/kvm/e500_tlb.h new file +7 -0
+#define KVM_E500_TLB0_WAY_SIZE_BIT     7       /* Fixed */
+#define KVM_E500_TLB0_WAY_SIZE         (1UL << KVM_E500_TLB0_WAY_SIZE_BIT)
+#define KVM_E500_TLB0_WAY_SIZE_MASK    (KVM_E500_TLB0_WAY_SIZE - 1)
+
+#define KVM_E500_TLB0_WAY_NUM_BIT      1       /* No greater than 7 */
+#define KVM_E500_TLB0_WAY_NUM          (1UL << KVM_E500_TLB0_WAY_NUM_BIT)
+#define KVM_E500_TLB0_WAY_NUM_MASK     (KVM_E500_TLB0_WAY_NUM - 1)

Are these really KVM constants, or e500 in general? If general e500, you should put them in a general e500 header.

arch/powerpc/kvm/e500_tlb.h line 34

Quoted 2 lines
arch/powerpc/kvm/e500_tlb.h new file +2 -0
+#define KVM_E500_TLB0_SIZE  (KVM_E500_TLB0_WAY_SIZE * KVM_E500_TLB0_WAY_NUM)
+#define KVM_E500_TLB1_SIZE  16

You probably want to distinguish between hardware TLB size and guest TLB size, since TLBnCFG allows you to trivially expose a larger virtual TLB to the guest than the hardware really supports.

arch/powerpc/kvm/e500_tlb.h line 39

Quoted 4 lines
arch/powerpc/kvm/e500_tlb.h new file +4 -0
+#define index_of(tlbsel, esel) (((tlbsel) << 16) | ((esel) & 0xFFFF))
+#define tlbsel_of(index)       ((index) >> 16)
+#define esel_of(index)         ((index) & 0xFFFF)
+#define to_htlb1_esel(esel) (num_tlbcam_entries - (esel) - 1)

I don't really like these names, but they're completely local so it's not too big a deal.

arch/powerpc/kvm/e500_tlb.h line 61

Quoted 2 lines
arch/powerpc/kvm/e500_tlb.h new file +2 -0
+extern unsigned int tlbcam_index;
+extern unsigned int num_tlbcam_entries;

You should put these externs somewhere in a generic e500 header, since they are generic e500 globals. They should probably also be renamed to reflect that...

Either way it's something you should submit, as a small separate patch, to the e500 maintainer to get their ack.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
author
#3 lore raw
In reply to Liu Yu
Quoted 11 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Friday, December 05, 2008 7:12 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH 2/3] kvmppc: Add e500 support

I haven't gone through this all (since it won't apply/build now), but just a couple quick comments:

Thanks.

Quoted 23 lines · Liu Yu

Review

Quoted 1 line
(quoted diff) +0 -0

b/arch/powerpc/kvm/e500_tlb.h

arch/powerpc/kvm/e500_tlb.h line 2

Quoted 7 lines

new file mode 100644
index 0000000..6adda39

arch/powerpc/kvm/e500_tlb.h new file +2 -0
@@ -0,0 +1,290 @@
+/*
+ * Copyright (C) 2008 Freescale Semiconductor, Inc. All 

rights reserved.

arch/powerpc/kvm/e500_tlb.h

Quoted 8 lines
arch/powerpc/kvm/e500_tlb.h new file +8 -0
+ *
+ * Author: Yu Liu, [email protected], Aug, 2008
+ *
+ * Description:
+ * This file is based on arch/powerpc/kvm/44x_tlb.h,
+ * by Hollis Blanchard <[email protected]>.
+ *
+ * This program is free software; you can redistribute it 

and/or modify

arch/powerpc/kvm/e500_tlb.h line 11

Quoted 1 line
arch/powerpc/kvm/e500_tlb.h new file +1 -0
+ * it under the terms of the GNU General Public License, 

version 2, as

Quoted 14 lines

arch/powerpc/kvm/e500_tlb.h line 23

Quoted 12 lines
arch/powerpc/kvm/e500_tlb.h new file +12 -0
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __KVM_E500_TLB_H__
+#define __KVM_E500_TLB_H__
+
+#include <linux/kvm_host.h>
+#include <asm/mmu-fsl-booke.h>
+#include <asm/tlb.h>
+#include <asm/kvm_e500.h>
+
+#define KVM_E500_TLB0_ENABLE   /* Enable it to utilize TLB0 */

Just remove this ifdef completely.

Fixed.

Quoted 8 lines

arch/powerpc/kvm/e500_tlb.h line 25

Quoted 3 lines
arch/powerpc/kvm/e500_tlb.h new file +2 -0
+#define KVM_E500_TLB0_WAY_SIZE_BIT     7       /* Fixed */
+#define KVM_E500_TLB0_WAY_SIZE         (1UL << 

KVM_E500_TLB0_WAY_SIZE_BIT)

arch/powerpc/kvm/e500_tlb.h

Quoted 3 lines
arch/powerpc/kvm/e500_tlb.h new file +3 -0
+#define KVM_E500_TLB0_WAY_SIZE_MASK    (KVM_E500_TLB0_WAY_SIZE - 1)
+
+#define KVM_E500_TLB0_WAY_NUM_BIT      1       /* No 

greater than 7 */

Quoted 7 lines

arch/powerpc/kvm/e500_tlb.h line 29

Quoted 1 line
arch/powerpc/kvm/e500_tlb.h new file +1 -0
+#define KVM_E500_TLB0_WAY_NUM          (1UL << 

KVM_E500_TLB0_WAY_NUM_BIT)

arch/powerpc/kvm/e500_tlb.h line 31

Quoted 1 line
arch/powerpc/kvm/e500_tlb.h new file +1 -0
+#define KVM_E500_TLB0_WAY_NUM_MASK     (KVM_E500_TLB0_WAY_NUM - 1)

Are these really KVM constants, or e500 in general? If general e500, you
should put them in a general e500 header.

They are used to describe TLB0 physical structure.
Maintain its logical structure can avoid illogical TLB0 size and can provide correct content when guest read appointed entry. (TLB0 also provide a way to read a certain entry)
But kernel now doesn't concern its structure, its size or even content of a certain entry,
it only use the auto-update mechanism to update TLB0....
So they're unnecessary for linux now, but I think they can avoid possible problem.

Quoted 10 lines

arch/powerpc/kvm/e500_tlb.h line 31

Quoted 2 lines
arch/powerpc/kvm/e500_tlb.h new file +1 -0
+#define KVM_E500_TLB0_SIZE  (KVM_E500_TLB0_WAY_SIZE * 

KVM_E500_TLB0_WAY_NUM)

arch/powerpc/kvm/e500_tlb.h line 34

Quoted 1 line
arch/powerpc/kvm/e500_tlb.h new file +1 -0
+#define KVM_E500_TLB1_SIZE  16

You probably want to distinguish between hardware TLB size and guest TLB
size, since TLBnCFG allows you to trivially expose a larger virtual TLB
to the guest than the hardware really supports.

Right. But kernel doesn't concern it now...

Quoted 9 lines

arch/powerpc/kvm/e500_tlb.h line 33

Quoted 2 lines
arch/powerpc/kvm/e500_tlb.h new file +1 -0
+#define index_of(tlbsel, esel) (((tlbsel) << 16) | ((esel) 

& 0xFFFF))

arch/powerpc/kvm/e500_tlb.h line 39

Quoted 3 lines
arch/powerpc/kvm/e500_tlb.h new file +3 -0
+#define tlbsel_of(index)       ((index) >> 16)
+#define esel_of(index)         ((index) & 0xFFFF)
+#define to_htlb1_esel(esel) (num_tlbcam_entries - (esel) - 1)

I don't really like these names, but they're completely local so it's not too big a deal.

Yes. In fact, I don't like them either.
Suggestions are always welcomed. :-)

Quoted 11 lines

arch/powerpc/kvm/e500_tlb.h line 61

Quoted 3 lines
arch/powerpc/kvm/e500_tlb.h new file +2 -0
+extern unsigned int tlbcam_index;
+extern unsigned int num_tlbcam_entries;

You should put these externs somewhere in a generic e500 header, since they are generic e500 globals. They should probably also be renamed to reflect that...

Either way it's something you should submit, as a small separate patch,
to the e500 maintainer to get their ack.

I'll think about it. Thanks.