Hypervisor-mode KVM on POWER7
Subsystems (4)
v2 cover Hypervisor-mode KVM on POWER7
The following series of patches enable KVM to exploit the hardware hypervisor mode on 64-bit Power ISA Book3S machines. At present only POWER7 is supported, but it would be easy to add other processors.
Running the KVM host in hypervisor mode means that the guest can use both supervisor mode and user mode. That means that the guest can execute supervisor-privilege instructions and access supervisor- privilege registers. In addition the hardware directs most exceptions to the guest. Thus we don't need to emulate any instructions in the host. Generally, the only times we need to exit the guest are when it does a hypercall or when an external interrupt or host timer (decrementer) interrupt occurs.
The focus of this KVM implementation is to run guests that use the PAPR (Power Architecture Platform Requirements) paravirtualization interface, which is the interface supplied by PowerVM on IBM pSeries machines. Currently the "pseries" machine type in qemu is only supported by book3s_hv KVM, and book3s_hv KVM only supports the "pseries" machine type. That will hopefully change in future.
These patches are against Linus' v3.0-rc1 tree.
Paul.
PATCH v2 1/12 kvm/powerpc: Move fields between struct kvm_vcpu_arch and kvmppc_vcpu_book3s
This moves the slb field, which represents the state of the emulated SLB, from the kvmppc_vcpu_book3s struct to the kvm_vcpu_arch, and the hpte_hash_[v]pte[_long] fields from kvm_vcpu_arch to kvmppc_vcpu_book3s. This is in accord with the principle that the kvm_vcpu_arch struct represents the state of the emulated CPU, and the kvmppc_vcpu_book3s struct holds the auxiliary data structures used in the emulation.
--- arch/powerpc/include/asm/kvm_book3s.h | 35 +++++++++------- arch/powerpc/include/asm/kvm_host.h | 34 +++++++--------- arch/powerpc/kvm/book3s.c | 9 ++-- arch/powerpc/kvm/book3s_64_mmu.c | 54 +++++++++++------------- arch/powerpc/kvm/book3s_mmu_hpte.c | 71 +++++++++++++++++++------------- arch/powerpc/kvm/trace.h | 2 +- 6 files changed, 107 insertions(+), 98 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +19 -16
@@ -24,20 +24,6 @@#include <linux/kvm_host.h> #include <asm/kvm_book3s_asm.h> -struct kvmppc_slb { -u64 esid; -u64 vsid; -u64 orige; -u64 origv; -bool valid :1 ; -bool Ks :1 ; -bool Kp :1 ; -bool nx :1 ; -bool large :1 ;/* PTEs are 16MB */ -bool tb :1 ;/* 1TB segment */ -bool class :1 ; -}; -struct kvmppc_bat {u64 raw;u32 bepi;
@@ -67,11 +53,22 @@ struct kvmppc_sid_map {#define VSID_POOL_SIZE (SID_CONTEXTS * 16)#endif +struct hpte_cache { +struct hlist_node list_pte; +struct hlist_node list_pte_long; +struct hlist_node list_vpte; +struct hlist_node list_vpte_long; +struct rcu_head rcu_head; +u64 host_va; +u64 pfn; +ulong slot; +struct kvmppc_pte pte; +}; +struct kvmppc_vcpu_book3s {struct kvm_vcpu vcpu;struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;struct kvmppc_sid_map sid_map[SID_MAP_NUM ]; -struct kvmppc_slb slb[64 ];struct {u64 esid;u64 vsid;
@@ -81,7 +78,6 @@ struct kvmppc_vcpu_book3s {struct kvmppc_bat dbat[8 ];u64 hid[6 ];u64 gqr[8 ]; -int slb_nr;u64 sdr1;u64 hior;u64 msr_mask;
@@ -94,6 +90,13 @@ struct kvmppc_vcpu_book3s {#endif int context_id[SID_CONTEXTS ];ulong prog_flags;/* flags to inject when giving a 700 trap */ + +struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE ]; +struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG ]; +struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE ]; +struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG ]; +int hpte_cache_count; +spinlock_t mmu_lock; };#define CONTEXT_HOST 0
arch/powerpc/include/asm/kvm_host.h +15 -19
@@ -163,16 +163,18 @@ struct kvmppc_mmu {bool (*is_dcbz32)(struct kvm_vcpu *vcpu); }; -struct hpte_cache { -struct hlist_node list_pte; -struct hlist_node list_pte_long; -struct hlist_node list_vpte; -struct hlist_node list_vpte_long; -struct rcu_head rcu_head; -u64 host_va; -u64 pfn; -ulong slot; -struct kvmppc_pte pte; +struct kvmppc_slb { +u64 esid; +u64 vsid; +u64 orige; +u64 origv; +bool valid :1 ; +bool Ks :1 ; +bool Kp :1 ; +bool nx :1 ; +bool large :1 ;/* PTEs are 16MB */ +bool tb :1 ;/* 1TB segment */ +bool class :1 ; };struct kvm_vcpu_arch {
@@ -187,6 +189,9 @@ struct kvm_vcpu_arch {ulong highmem_handler;ulong rmcall;ulong host_paca_phys; +struct kvmppc_slb slb[64 ]; +int slb_max;/* # valid entries in slb[] */ +int slb_nr;/* total number of entries in SLB */ struct kvmppc_mmu mmu;#endif
@@ -298,15 +303,6 @@ struct kvm_vcpu_arch {struct kvm_vcpu_arch_shared *shared;unsigned long magic_page_pa;/* phys addr to map the magic page to */ unsigned long magic_page_ea; /* effect. addr to map the magic page to */ - -#ifdef CONFIG_PPC_BOOK3S -struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE ]; -struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG ]; -struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE ]; -struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG ]; -int hpte_cache_count; -spinlock_t mmu_lock; -#endif };#endif /* __POWERPC_KVM_HOST_H__ */
arch/powerpc/kvm/book3s.c +5 -4
@@ -17,7 +17,6 @@#include <linux/kvm_host.h> #include <linux/err.h> #include <linux/slab.h> -#include "trace.h" #include <asm/reg.h> #include <asm/cputable.h>
@@ -33,6 +32,8 @@#include <linux/vmalloc.h> #include <linux/highmem.h> +#include "trace.h" +#define VCPU_STAT (x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU/* #define EXIT_DEBUG */
@@ -1190,8 +1191,8 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, sregs->u.s.sdr1 =to_book3s (vcpu)->sdr1;if (vcpu->arch.hflags &BOOK3S_HFLAG_SLB ) {for (i =0 ; i <64 ; i++) { - sregs->u.s.ppc64.slb[i].slbe = vcpu3s->slb[i].orige | i; - sregs->u.s.ppc64.slb[i].slbv = vcpu3s->slb[i].origv; + sregs->u.s.ppc64.slb[i].slbe = vcpu->arch.slb[i].orige | i; + sregs->u.s.ppc64.slb[i].slbv = vcpu->arch.slb[i].origv; } }else {for (i =0 ; i <16 ; i++)
@@ -1339,7 +1340,7 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) vcpu->arch.pvr =0x84202 ;#endif kvmppc_set_pvr (vcpu, vcpu->arch.pvr); - vcpu_book3s->slb_nr =64 ; + vcpu->arch.slb_nr =64 ;/* remember where some real-mode handlers are */ vcpu->arch.trampoline_lowmem = kvmppc_trampoline_lowmem;
arch/powerpc/kvm/book3s_64_mmu.c +25 -29
143 lines not on this page · raw message
arch/powerpc/kvm/book3s_mmu_hpte.c +42 -29
212 lines not on this page · raw message
arch/powerpc/kvm/trace.h +1 -1
@@ -252,7 +252,7 @@ TRACE_EVENT(kvm_book3s_mmu_flush, ),TP_fast_assign ( - __entry->count = vcpu->arch.hpte_cache_count; + __entry->count = to_book3s(vcpu)->hpte_cache_count; __entry->p1 = p1; __entry->p2 = p2; __entry->type = type;
Signature · 1 line
1.7.5.3
PATCH v2 2/12 kvm/powerpc: Split out code from book3s.c into book3s_pr.c
In reply to Paul MackerrasIn preparation for adding code to enable KVM to use hypervisor mode on 64-bit Book 3S processors, this splits book3s.c into two files, book3s.c and book3s_pr.c, where book3s_pr.c contains the code that is specific to running the guest in problem state (user mode) and book3s.c contains code which should apply to all Book 3S processors.
In doing this, we abstract some details, namely the interrupt offset, updating the interrupt pending flag, and detecting if the guest is in a critical section. These are all things that will be different when we use hypervisor mode.
--- arch/powerpc/include/asm/kvm_book3s.h | 35 ++ arch/powerpc/kvm/Makefile | 2 + arch/powerpc/kvm/book3s.c | 995 +-------------------------------- arch/powerpc/kvm/book3s_pr.c | 1009 +++++++++++++++++++++++++++++++++ 4 files changed, 1053 insertions(+), 988 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_pr.c
arch/powerpc/include/asm/kvm_book3s.h +35 -0
@@ -113,6 +113,7 @@ extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask)extern void kvmppc_mmu_pte_vflush (struct kvm_vcpu *vcpu,u64 vp,u64 vp_mask);extern void kvmppc_mmu_pte_pflush (struct kvm_vcpu *vcpu,ulong pa_start,ulong pa_end);extern void kvmppc_set_msr (struct kvm_vcpu *vcpu,u64 new_msr); +extern void kvmppc_set_pvr (struct kvm_vcpu *vcpu,u32 pvr);extern void kvmppc_mmu_book3s_64_init (struct kvm_vcpu *vcpu);extern void kvmppc_mmu_book3s_32_init (struct kvm_vcpu *vcpu);extern int kvmppc_mmu_map_page (struct kvm_vcpu *vcpu,struct kvmppc_pte *pte);
@@ -150,6 +151,20 @@ static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); } +static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) +{ +return to_book3s (vcpu)->hior; +} + +static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu, +unsigned long pending_now,unsigned long old_pending) +{ +if (pending_now) + vcpu->arch.shared->int_pending =1 ; +else if (old_pending) + vcpu->arch.shared->int_pending =0 ; +} +static inline ulong dsisr (void ) {ulong r;
@@ -247,6 +262,26 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)return to_svcpu (vcpu)->fault_dar; } +static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu) +{ +ulong crit_raw = vcpu->arch.shared->critical; +ulong crit_r1 =kvmppc_get_gpr (vcpu,1 ); +bool crit; + +/* Truncate crit indicators in 32 bit mode */ +if (!(vcpu->arch.shared->msr &MSR_SF )) { + crit_raw &=0xffffffff ; + crit_r1 &=0xffffffff ; + } + +/* Critical section when crit == r1 */ + crit = (crit_raw == crit_r1); +/* ... and we're in supervisor mode */ + crit = crit && !(vcpu->arch.shared->msr &MSR_PR ); + +return crit; +} +/* Magic register values loaded into r3 and r4 before the 'sc' assembly * instruction for the OSI hypercalls */ #define OSI_SC_MAGIC_R3 0x113724FA
arch/powerpc/kvm/Makefile +2 -0
@@ -43,6 +43,7 @@ kvm-book3s_64-objs := \ fpu.o \ book3s_paired_singles.o \ book3s.o \ + book3s_pr.o \ book3s_emulate.o \ book3s_interrupts.o \ book3s_mmu_hpte.o \
@@ -56,6 +57,7 @@ kvm-book3s_32-objs := \ fpu.o \ book3s_paired_singles.o \ book3s.o \ + book3s_pr.o \ book3s_emulate.o \ book3s_interrupts.o \ book3s_mmu_hpte.o \
arch/powerpc/kvm/book3s.c +7 -988
1,053 lines not on this page · raw message
arch/powerpc/kvm/book3s_pr.c new file +1009 -0
1,009 lines not on this page · raw message
Signature · 1 line
1.7.5.3
PATCH v2 3/12 powerpc, kvm: Rework KVM checks in first-level interrupt handlers
In reply to Paul MackerrasInstead of branching out-of-line with the DO_KVM macro to check if we are in a KVM guest at the time of an interrupt, this moves the KVM check inline in the first-level interrupt handlers. This speeds up the non-KVM case and makes sure that none of the interrupt handlers are missing the check.
Because the first-level interrupt handlers are now larger, some things had to be move out of line in exceptions-64s.S.
This all necessitated some minor changes to the interrupt entry code in KVM. This also streamlines the book3s_32 KVM test.
--- arch/powerpc/include/asm/exception-64s.h | 121 ++++++++++++------ arch/powerpc/kernel/exceptions-64s.S | 189 +++++++++++++++++----------- arch/powerpc/kvm/book3s_rmhandlers.S | 78 ++++++------ arch/powerpc/kvm/book3s_segment.S | 7 + arch/powerpc/platforms/iseries/exception.S | 2 +- arch/powerpc/platforms/iseries/exception.h | 4 +- 6 files changed, 247 insertions(+), 154 deletions(-)
arch/powerpc/include/asm/exception-64s.h +81 -40
@@ -61,19 +61,22 @@#define EXC_HV H#define EXC_STD -#define EXCEPTION_PROLOG_1(area) \ +#define __EXCEPTION_PROLOG_1(area, extra, vec) \ GET_PACA(r13); \ std r9,area+EX_R9(r13); /* save r9 - r12 */ \ std r10,area+EX_R10(r13); \ - std r11,area+EX_R11(r13); \ - std r12,area+EX_R12(r13); \ BEGIN_FTR_SECTION_NESTED(66); \ mfspr r10,SPRN_CFAR; \ std r10,area+EX_CFAR(r13); \ END_FTR_SECTION_NESTED(CPU_FTR_CFAR, CPU_FTR_CFAR, 66); \ - GET_SCRATCH0(r9); \ - std r9,area+EX_R13(r13); \ - mfcr r9 + mfcr r9; \ + extra(vec); \ + std r11,area+EX_R11(r13); \ + std r12,area+EX_R12(r13); \ + GET_SCRATCH0(r10); \ + std r10,area+EX_R13(r13) +#define EXCEPTION_PROLOG_1 (area, extra, vec) \ + __EXCEPTION_PROLOG_1(area, extra, vec)#define __EXCEPTION_PROLOG_PSERIES_1 (label, h) \ ld r12,PACAKBASE(r13);/* get high part of &label */ \
@@ -85,13 +88,54 @@ mtspr SPRN_##h##SRR1,r10; \ h##rfid; \ b ./* prevent speculative execution */ -#define EXCEPTION_PROLOG_PSERIES_1 (label, h) \ +#define EXCEPTION_PROLOG_PSERIES_1 (label, h) \ __EXCEPTION_PROLOG_PSERIES_1(label, h) -#define EXCEPTION_PROLOG_PSERIES (area, label, h) \ - EXCEPTION_PROLOG_1(area); \ +#define EXCEPTION_PROLOG_PSERIES (area, label, h, extra, vec) \ + EXCEPTION_PROLOG_1(area, extra, vec); \ EXCEPTION_PROLOG_PSERIES_1(label, h); +#define __KVMTEST (n) \ + lbz r10,PACA_KVM_SVCPU+SVCPU_IN_GUEST(r13); \ + cmpwi r10,0; \ + bne do_kvm_##n + +#define __KVM_HANDLER (area, h, n) \ +do_kvm_##n: \ + ld r10,area+EX_R10(r13); \ + stw r9,PACA_KVM_SVCPU+SVCPU_SCRATCH1(r13); \ + ld r9,area+EX_R9(r13); \ + std r12,PACA_KVM_SVCPU+SVCPU_SCRATCH0(r13); \ + li r12,n; \ + b kvmppc_interrupt + +#define __KVM_HANDLER_SKIP (area, h, n) \ +do_kvm_##n: \ + cmpwi r10,KVM_GUEST_MODE_SKIP; \ + ld r10,area+EX_R10(r13); \ + beq 89f; \ + stw r9,PACA_KVM_SVCPU+SVCPU_SCRATCH1(r13); \ + ld r9,area+EX_R9(r13); \ + std r12,PACA_KVM_SVCPU+SVCPU_SCRATCH0(r13); \ + li r12,n; \ + b kvmppc_interrupt; \ +89: mtocrf 0x80,r9; \ + ld r9,area+EX_R9(r13); \ + b kvmppc_skip_##h##interrupt + +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER +#define KVMTEST (n) __KVMTEST(n) +#define KVM_HANDLER (area, h, n) __KVM_HANDLER(area, h, n) +#define KVM_HANDLER_SKIP (area, h, n) __KVM_HANDLER_SKIP(area, h, n) + +#else +#define KVMTEST (n) +#define KVM_HANDLER (area, h, n) +#define KVM_HANDLER_SKIP (area, h, n) +#endif + +#define NOTEST (n) +/* * The common exception prolog is used for all except a few exceptions * such as a segment miss on a kernel address. We have to be prepared
@@ -164,57 +208,54 @@ .globl label##_pSeries; \ label##_pSeries: \HMT_MEDIUM ; \ -DO_KVM vec; \SET_SCRATCH0 (r13);/* save r13 */ \ - EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, EXC_STD) + EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ + EXC_STD, KVMTEST, vec)#define STD_EXCEPTION_HV (loc, vec, label) \ . = loc; \ .globl label##_hv; \ label##_hv: \ HMT_MEDIUM; \ - DO_KVM vec; \ - SET_SCRATCH0(r13);/* save r13 */ \ - EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, EXC_HV) + SET_SCRATCH0(r13);/* save r13 */ \ + EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ + EXC_HV, KVMTEST, vec) -#define __MASKABLE_EXCEPTION_PSERIES (vec, label, h) \ - HMT_MEDIUM; \ - DO_KVM vec; \ - SET_SCRATCH0(r13);/* save r13 */ \ -GET_PACA (r13); \ - std r9,PACA_EXGEN+EX_R9(r13); /* save r9, r10 */ \ - std r10,PACA_EXGEN+EX_R10(r13); \ +#define __SOFTEN_TEST (h) \ lbz r10,PACASOFTIRQEN(r13); \ -mfcr r9; \ cmpwi r10,0; \ - beq masked_##h##interrupt; \ - GET_SCRATCH0(r10); \ - std r10,PACA_EXGEN+EX_R13(r13); \ - std r11,PACA_EXGEN+EX_R11(r13); \ - std r12,PACA_EXGEN+EX_R12(r13); \ - ld r12,PACAKBASE(r13);/* get high part of &label */ \ -ld r10,PACAKMSR (r13 );/* get MSR value for kernel */ \ - mfspr r11,SPRN_##h##SRR0; /* save SRR0 */ \ - LOAD_HANDLER(r12,label##_common) \ - mtspr SPRN_##h##SRR0,r12; \ - mfspr r12,SPRN_##h##SRR1; /* and SRR1 */ \ - mtspr SPRN_##h##SRR1,r10; \ - h##rfid; \ - b ./* prevent speculative execution */ -#define _MASKABLE_EXCEPTION_PSERIES (vec, label, h) \ - __MASKABLE_EXCEPTION_PSERIES(vec, label, h) + beq masked_##h##interrupt +#define _SOFTEN_TEST (h) __SOFTEN_TEST(h) + +#define SOFTEN_TEST (vec) \ + KVMTEST(vec); \ + _SOFTEN_TEST(EXC_STD) + +#define SOFTEN_TEST_HV (vec) \ + KVMTEST(vec); \ + _SOFTEN_TEST(EXC_HV) + +#define __MASKABLE_EXCEPTION_PSERIES (vec, label, h, extra) \ + HMT_MEDIUM; \ + SET_SCRATCH0(r13);/* save r13 */ \ +__EXCEPTION_PROLOG_1 (PACA_EXGEN , extra, vec); \ + EXCEPTION_PROLOG_PSERIES_1(label##_common, h); +#define _MASKABLE_EXCEPTION_PSERIES (vec, label, h, extra) \ + __MASKABLE_EXCEPTION_PSERIES(vec, label, h, extra)#define MASKABLE_EXCEPTION_PSERIES (loc, vec, label) \ . = loc; \ .globl label##_pSeries; \ label##_pSeries: \ - _MASKABLE_EXCEPTION_PSERIES(vec, label, EXC_STD) + _MASKABLE_EXCEPTION_PSERIES(vec, label, \ + EXC_STD, SOFTEN_TEST)#define MASKABLE_EXCEPTION_HV (loc, vec, label) \ . = loc; \ .globl label##_hv; \ label##_hv: \ - _MASKABLE_EXCEPTION_PSERIES(vec, label, EXC_HV) + _MASKABLE_EXCEPTION_PSERIES(vec, label, \ + EXC_HV, SOFTEN_TEST_HV)#ifdef CONFIG_PPC_ISERIES #define DISABLE_INTS \
arch/powerpc/kernel/exceptions-64s.S +115 -74
309 lines not on this page · raw message
arch/powerpc/kvm/book3s_rmhandlers.S +41 -37
126 lines not on this page · raw message
arch/powerpc/kvm/book3s_segment.S +7 -0
@@ -125,6 +125,9 @@ kvmppc_handler_trampoline_enter_end: .global kvmppc_handler_trampoline_exit kvmppc_handler_trampoline_exit: +.global kvmppc_interrupt +kvmppc_interrupt: + /* Register usage at this point: * * SPRG_SCRATCH0 = guest R13
@@ -155,12 +158,16 @@ kvmppc_handler_trampoline_exit: PPC_LL r2, (SHADOW_VCPU_OFF + SVCPU_HOST_R2)(r13) /* Save guest PC and MSR */ +#ifdef CONFIG_PPC64 +BEGIN_FTR_SECTION andi. r0,r12,0x2 beq 1f mfspr r3,SPRN_HSRR0 mfspr r4,SPRN_HSRR1 andi. r12,r12,0x3ffd b 2f +END_FTR_SECTION_IFSET(CPU_FTR_HVMODE_206) +#endif 1: mfsrr0 r3 mfsrr1 r4 2:
arch/powerpc/platforms/iseries/exception.S +1 -1
@@ -167,7 +167,7 @@ BEGIN_FTR_SECTION std r12,PACA_EXGEN+EX_R13(r13) EXCEPTION_PROLOG_ISERIES_1 FTR_SECTION_ELSE - EXCEPTION_PROLOG_1(PACA_EXGEN) + EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0) EXCEPTION_PROLOG_ISERIES_1 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_SLB) b data_access_common
arch/powerpc/platforms/iseries/exception.h +2 -2
@@ -39,7 +39,7 @@ label##_iSeries: \HMT_MEDIUM ; \mtspr SPRN_SPRG_SCRATCH0 ,r13;/* save r13 */ \ -EXCEPTION_PROLOG_1 (area); \ +EXCEPTION_PROLOG_1 (area,NOTEST ,0 ); \EXCEPTION_PROLOG_ISERIES_1 ; \ b label##_common
@@ -48,7 +48,7 @@ label##_iSeries: \ label##_iSeries: \HMT_MEDIUM ; \mtspr SPRN_SPRG_SCRATCH0 ,r13;/* save r13 */ \ -EXCEPTION_PROLOG_1 (PACA_EXGEN ); \ +EXCEPTION_PROLOG_1 (PACA_EXGEN ,NOTEST ,0 ); \lbz r10,PACASOFTIRQEN (r13 ); \ cmpwi 0,r10,0; \ beq- label##_iSeries_masked; \
Signature · 1 line
1.7.5.3
PATCH v2 4/12 kvm/powerpc: Deliver program interrupts right away instead of queueing them
In reply to Paul MackerrasDoing so means that we don't have to save the flags anywhere and gets rid of the last reference to to_book3s(vcpu) in arch/powerpc/kvm/book3s.c.
Doing so is OK because a program interrupt won't be generated at the same time as any other synchronous interrupt. If a program interrupt and an asynchronous interrupt (external or decrementer) are generated at the same time, the program interrupt will be delivered, which is correct because it has a higher priority, and then the asynchronous interrupt will be masked.
We don't ever generate system reset or machine check interrupts to the guest, but if we did, then we would need to make sure they got delivered rather than the program interrupt. The current code would be wrong in this situation anyway since it would deliver the program interrupt as well as the reset/machine check interrupt.
--- arch/powerpc/kvm/book3s.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s.c +3 -5
@@ -128,8 +128,8 @@ void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { -to_book3s (vcpu)->prog_flags = flags; -kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_PROGRAM ); +/* might as well deliver this straight away */ +kvmppc_inject_interrupt (vcpu,BOOK3S_INTERRUPT_PROGRAM , flags); }void kvmppc_core_queue_dec (struct kvm_vcpu *vcpu)
@@ -169,7 +169,6 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority) {int deliver =1 ;int vec =0 ; -ulong flags =0ULL ;bool crit =kvmppc_critical_section (vcpu);switch (priority) {
@@ -205,7 +204,6 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)break ;case BOOK3S_IRQPRIO_PROGRAM : vec =BOOK3S_INTERRUPT_PROGRAM ; - flags =to_book3s (vcpu)->prog_flags;break ;case BOOK3S_IRQPRIO_VSX : vec =BOOK3S_INTERRUPT_VSX ;
@@ -236,7 +234,7 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)#endif if (deliver) -kvmppc_inject_interrupt (vcpu, vec, flags); +kvmppc_inject_interrupt (vcpu, vec,0 );return deliver; }
Signature · 1 line
1.7.5.3
PATCH v2 5/12 kvm/powerpc: Pass init/destroy vm and prepare/commit memory region ops down
In reply to Paul MackerrasThis arranges for the top-level arch/powerpc/kvm/powerpc.c file to pass down some of the calls it gets to the lower-level subarchitecture specific code. The lower-level implementations (in booke.c and book3s.c) are no-ops. The coming book3s_hv.c will need this.
--- arch/powerpc/include/asm/kvm_ppc.h | 7 +++++++ arch/powerpc/kvm/book3s_pr.c | 20 ++++++++++++++++++++ arch/powerpc/kvm/booke.c | 20 ++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 9 ++++++--- 4 files changed, 53 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +7 -0
@@ -110,6 +110,13 @@ extern void kvmppc_booke_exit(void);extern void kvmppc_core_destroy_mmu (struct kvm_vcpu *vcpu);extern int kvmppc_kvm_pv (struct kvm_vcpu *vcpu); +extern int kvmppc_core_init_vm (struct kvm *kvm); +extern void kvmppc_core_destroy_vm (struct kvm *kvm); +extern int kvmppc_core_prepare_memory_region (struct kvm *kvm, +struct kvm_userspace_memory_region *mem); +extern void kvmppc_core_commit_memory_region (struct kvm *kvm, +struct kvm_userspace_memory_region *mem); +/* * Cuts out inst bits with ordering according to spec. * That means the leftmost bit is zero. All given bits are included.
arch/powerpc/kvm/book3s_pr.c +20 -0
@@ -984,6 +984,26 @@ int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)return ret; } +int kvmppc_core_prepare_memory_region (struct kvm *kvm, +struct kvm_userspace_memory_region *mem) +{ +return 0 ; +} + +void kvmppc_core_commit_memory_region (struct kvm *kvm, +struct kvm_userspace_memory_region *mem) +{ +} + +int kvmppc_core_init_vm (struct kvm *kvm) +{ +return 0 ; +} + +void kvmppc_core_destroy_vm (struct kvm *kvm) +{ +} +static int kvmppc_book3s_init (void ) {int r;
arch/powerpc/kvm/booke.c +20 -0
@@ -770,6 +770,26 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)return -ENOTSUPP ; } +int kvmppc_core_prepare_memory_region (struct kvm *kvm, +struct kvm_userspace_memory_region *mem) +{ +return 0 ; +} + +void kvmppc_core_commit_memory_region (struct kvm *kvm, +struct kvm_userspace_memory_region *mem) +{ +} + +int kvmppc_core_init_vm (struct kvm *kvm) +{ +return 0 ; +} + +void kvmppc_core_destroy_vm (struct kvm *kvm) +{ +} +int __init kvmppc_booke_init (void ) {unsigned long ivor[16 ];
arch/powerpc/kvm/powerpc.c +6 -3
@@ -147,7 +147,7 @@ void kvm_arch_check_processor_compat(void *rtn)int kvm_arch_init_vm (struct kvm *kvm) { -return 0 ; +return kvmppc_core_init_vm (kvm); }void kvm_arch_destroy_vm (struct kvm *kvm)
@@ -163,6 +163,9 @@ void kvm_arch_destroy_vm(struct kvm *kvm) kvm->vcpus[i] =NULL ;atomic_set (&kvm->online_vcpus,0 ); + +kvmppc_core_destroy_vm (kvm); +mutex_unlock (&kvm->lock); }
@@ -211,7 +214,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,struct kvm_userspace_memory_region *mem, int user_alloc) { -return 0 ; + return kvmppc_core_prepare_memory_region(kvm, mem); } void kvm_arch_commit_memory_region(struct kvm *kvm,
@@ -219,7 +222,7 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,struct kvm_memory_slot old, int user_alloc) { -return ; +kvmppc_core_commit_memory_region (kvm ,mem ); }
Signature · 1 line
1.7.5.3
PATCH v2 6/12 kvm/powerpc: Move guest enter/exit down into subarch-specific code
In reply to Paul MackerrasInstead of doing the kvm_guest_enter/exit() and local_irq_dis/enable() calls in powerpc.c, this moves them down into the subarch-specific book3s_pr.c and booke.c. This eliminates an extra local_irq_enable() call in book3s_pr.c, and will be needed for when we do SMT4 guest support in the book3s hypervisor mode code.
--- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/book3s_interrupts.S | 2 +- arch/powerpc/kvm/book3s_pr.c | 12 ++++++------ arch/powerpc/kvm/booke.c | 13 +++++++++++++ arch/powerpc/kvm/powerpc.c | 6 +----- 5 files changed, 22 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -42,6 +42,7 @@ enum emulation_result { EMULATE_AGAIN, /* something went wrong. go again */ }; +extern int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);extern int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);extern char kvmppc_handlers_start[];extern unsigned long kvmppc_handler_len;
arch/powerpc/kvm/book3s_interrupts.S +1 -1
@@ -85,7 +85,7 @@ * r3: kvm_run pointer * r4: vcpu pointer */ -_GLOBAL(__kvmppc_vcpu_entry) +_GLOBAL(__kvmppc_vcpu_run) kvm_start_entry: /* Write correct stack frame */
arch/powerpc/kvm/book3s_pr.c +6 -6
@@ -891,8 +891,7 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)vfree (vcpu_book3s); } -extern int __kvmppc_vcpu_entry (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu); -int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) +int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) {int ret;double fpr[32 ][TS_FPRWIDTH ];
@@ -944,14 +943,15 @@ int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)/* Remember the MSR with disabled extensions */ ext_msr = current->thread.regs->msr; -/* XXX we get called with irq disabled - change that! */ -local_irq_enable (); -/* Preload FPU if it's enabled */ if (vcpu->arch.shared->msr &MSR_FP )kvmppc_handle_ext (vcpu,BOOK3S_INTERRUPT_FP_UNAVAIL ,MSR_FP ); - ret =__kvmppc_vcpu_entry (kvm_run, vcpu); +kvm_guest_enter (); + + ret =__kvmppc_vcpu_run (kvm_run, vcpu); + +kvm_guest_exit ();local_irq_disable ();
arch/powerpc/kvm/booke.c +13 -0
@@ -257,6 +257,19 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu) vcpu->arch.shared->int_pending =0 ; } +int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) +{ +int ret; + +local_irq_disable (); +kvm_guest_enter (); + ret =__kvmppc_vcpu_run (kvm_run, vcpu); +kvm_guest_exit (); +local_irq_enable (); + +return ret; +} +/** * kvmppc_handle_exit *
arch/powerpc/kvm/powerpc.c +1 -5
@@ -499,11 +499,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)kvmppc_core_deliver_interrupts (vcpu); -local_irq_disable (); -kvm_guest_enter (); - r =__kvmppc_vcpu_run (run, vcpu); -kvm_guest_exit (); -local_irq_enable (); + r =kvmppc_vcpu_run (run, vcpu);if (vcpu->sigset_active)sigprocmask (SIG_SETMASK , &sigsaved,NULL );
Signature · 1 line
1.7.5.3
PATCH v2 7/12 powerpc: Set up LPCR for running guest partitions
In reply to Paul MackerrasIn hypervisor mode, the LPCR controls several aspects of guest partitions, including virtual partition memory mode, and also controls whether the hypervisor decrementer interrupts are enabled. This sets up LPCR at boot time so that guest partitions will use a virtual real memory area (VRMA) composed of 16MB large pages, and hypervisor decrementer interrupts are disabled.
--- arch/powerpc/include/asm/reg.h | 4 ++++ arch/powerpc/kernel/cpu_setup_power7.S | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/reg.h +4 -0
@@ -232,10 +232,12 @@#define LPCR_VPM0 (1ul << (63-0))#define LPCR_VPM1 (1ul << (63-1))#define LPCR_ISL (1ul << (63-2)) +#define LPCR_VC_SH (63-2)#define LPCR_DPFD_SH (63-11)#define LPCR_VRMA_L (1ul << (63-12))#define LPCR_VRMA_LP0 (1ul << (63-15))#define LPCR_VRMA_LP1 (1ul << (63-16)) +#define LPCR_VRMASD_SH (63-16)#define LPCR_RMLS 0x1C000000/* impl dependent rmo limit sel */ #define LPCR_ILE 0x02000000/* !HV irqs set MSR:LE */ #define LPCR_PECE 0x00007000/* powersave exit cause enable */
@@ -243,8 +245,10 @@#define LPCR_PECE1 0x00002000/* decrementer can cause exit */ #define LPCR_PECE2 0x00001000/* machine check etc can cause exit */ #define LPCR_MER 0x00000800/* Mediated External Exception */ +#define LPCR_LPES 0x0000000c#define LPCR_LPES0 0x00000008/* LPAR Env selector 0 */ #define LPCR_LPES1 0x00000004/* LPAR Env selector 1 */ +#define LPCR_LPES_SH 2#define LPCR_RMI 0x00000002/* real mode is cache inhibit */ #define LPCR_HDICE 0x00000001/* Hyp Decr enable (HV,PR,EE) */ #define SPRN_LPID 0x13F/* Logical Partition Identifier */
arch/powerpc/kernel/cpu_setup_power7.S +11 -7
@@ -61,19 +61,23 @@ __init_LPCR: * LPES = 0b01 (HSRR0/1 used for 0x500) * PECE = 0b111 * DPFD = 4 + * HDICE = 0 + * VC = 0b100 (VPM0=1, VPM1=0, ISL=0) + * VRMASD = 0b10000 (L=1, LP=00) * * Other bits untouched for now */ mfspr r3,SPRN_LPCR - ori r3,r3,(LPCR_LPES0|LPCR_LPES1) - xori r3,r3, LPCR_LPES0 + li r5,1 + rldimi r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2 ori r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2) - li r5,7 - sldi r5,r5,LPCR_DPFD_SH - andc r3,r3,r5 li r5,4 - sldi r5,r5,LPCR_DPFD_SH - or r3,r3,r5 + rldimi r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3 + clrrdi r3,r3,1 /* clear HDICE */ + li r5,4 + rldimi r3,r5, LPCR_VC_SH, 0 + li r5,0x10 + rldimi r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5 mtspr SPRN_LPCR,r3 isync blr
Signature · 1 line
1.7.5.3
PATCH v2 8/12 kvm/powerpc: Split host-state fields out of kvmppc_book3s_shadow_vcpu
In reply to Paul MackerrasThere are several fields in struct kvmppc_book3s_shadow_vcpu that temporarily store bits of host state while a guest is running, rather than anything relating to the particular guest or vcpu. This splits them out into a new kvmppc_host_state structure and modifies the definitions in asm-offsets.c to suit.
On 32-bit, we have a kvmppc_host_state structure inside the kvmppc_book3s_shadow_vcpu since the assembly code needs to be able to get to them both with one pointer. On 64-bit they are separate fields in the PACA. This means that on 64-bit we don't need to copy the kvmppc_host_state in and out on vcpu load/unload, and in future will mean that the book3s_hv code doesn't need a shadow_vcpu struct in the PACA at all.
--- arch/powerpc/include/asm/exception-64s.h | 10 ++-- arch/powerpc/include/asm/kvm_book3s_asm.h | 27 ++++++--- arch/powerpc/include/asm/paca.h | 1 + arch/powerpc/kernel/asm-offsets.c | 94 ++++++++++++++-------------- arch/powerpc/kvm/book3s_interrupts.S | 17 +++--- arch/powerpc/kvm/book3s_rmhandlers.S | 18 +++--- arch/powerpc/kvm/book3s_segment.S | 72 +++++++++++----------- 7 files changed, 124 insertions(+), 115 deletions(-)
arch/powerpc/include/asm/exception-64s.h +5 -5
@@ -96,16 +96,16 @@EXCEPTION_PROLOG_PSERIES_1 (label, h);#define __KVMTEST (n) \ - lbz r10,PACA_KVM_SVCPU+SVCPU_IN_GUEST(r13); \ + lbz r10,HSTATE_IN_GUEST(r13); \ cmpwi r10,0; \ bne do_kvm_##n#define __KVM_HANDLER (area, h, n) \ do_kvm_##n: \ ld r10,area+EX_R10(r13); \ - stw r9,PACA_KVM_SVCPU+SVCPU_SCRATCH1(r13); \ + stw r9,HSTATE_SCRATCH1(r13); \ ld r9,area+EX_R9(r13); \ - std r12,PACA_KVM_SVCPU+SVCPU_SCRATCH0(r13); \ + std r12,HSTATE_SCRATCH0(r13); \ li r12,n; \ b kvmppc_interrupt
@@ -114,9 +114,9 @@ do_kvm_##n: \cmpwi r10,KVM_GUEST_MODE_SKIP ; \ ld r10,area+EX_R10(r13); \ beq 89f; \ - stw r9,PACA_KVM_SVCPU+SVCPU_SCRATCH1(r13); \ +stw r9,HSTATE_SCRATCH1 (r13 ); \ ld r9,area+EX_R9(r13); \ - std r12,PACA_KVM_SVCPU+SVCPU_SCRATCH0(r13); \ +std r12,HSTATE_SCRATCH0 (r13 ); \li r12,n; \b kvmppc_interrupt; \ 89: mtocrf 0x80,r9; \
arch/powerpc/include/asm/kvm_book3s_asm.h +19 -8
@@ -60,6 +60,22 @@ kvmppc_resume_\intno: #else /*__ASSEMBLY__ */ +/* + * This struct goes in the PACA on 64-bit processors. It is used + * to store host state that needs to be saved when we enter a guest + * and restored when we exit, but isn't specific to any particular + * guest or vcpu. It also has some scratch fields used by the guest + * exit code. + */ +struct kvmppc_host_state { + ulong host_r1; + ulong host_r2; + ulong vmhandler; + ulong scratch0; + ulong scratch1; + u8 in_guest; +}; + struct kvmppc_book3s_shadow_vcpu { ulong gpr[14]; u32 cr;
@@ -73,17 +89,12 @@ struct kvmppc_book3s_shadow_vcpu {ulong shadow_srr1;ulong fault_dar; -ulong host_r1; -ulong host_r2; -ulong handler; -ulong scratch0; -ulong scratch1; -ulong vmhandler; -u8 in_guest; -#ifdef CONFIG_PPC_BOOK3S_32 u32 sr[16 ];/* Guest SRs */ + +struct kvmppc_host_state hstate;#endif + #ifdef CONFIG_PPC_BOOK3S_64 u8 slb_max; /* highest used guest slb entry */ struct {
arch/powerpc/include/asm/paca.h +1 -0
@@ -149,6 +149,7 @@ struct paca_struct {#ifdef CONFIG_KVM_BOOK3S_HANDLER /* We use this to store guest state in */ struct kvmppc_book3s_shadow_vcpu shadow_vcpu; +struct kvmppc_host_state kvm_hstate;#endif };
arch/powerpc/kernel/asm-offsets.c +47 -47
114 lines not on this page · raw message
arch/powerpc/kvm/book3s_interrupts.S +8 -9
@@ -29,8 +29,7 @@ #define ULONG_SIZE 8 #define FUNC(name) GLUE(.,name) -#define GET_SHADOW_VCPU(reg) \ - addi reg, r13, PACA_KVM_SVCPU +#define GET_SHADOW_VCPU_R13 #define DISABLE_INTERRUPTS \ mfmsr r0; \
@@ -43,8 +42,8 @@ #define ULONG_SIZE 4 #define FUNC(name) name -#define GET_SHADOW_VCPU(reg) \ - lwz reg, (THREAD + THREAD_KVM_SVCPU)(r2) +#define GET_SHADOW_VCPU_R13 \ + lwz r13, (THREAD + THREAD_KVM_SVCPU)(r2) #define DISABLE_INTERRUPTS \ mfmsr r0; \
@@ -107,15 +106,15 @@ kvm_start_entry: /* Load non-volatile guest state from the vcpu */ VCPU_LOAD_NVGPRS(r4) - GET_SHADOW_VCPU(r5) + GET_SHADOW_VCPU_R13 - /* Save R1/R2 in the PACA */ - PPC_STL r1, SVCPU_HOST_R1(r5) - PPC_STL r2, SVCPU_HOST_R2(r5) + /* Save R1/R2 in the PACA (64-bit) or shadow_vcpu (32-bit) */ + PPC_STL r1, HSTATE_HOST_R1(r13) + PPC_STL r2, HSTATE_HOST_R2(r13) /* XXX swap in/out on load? */ PPC_LL r3, VCPU_HIGHMEM_HANDLER(r4) - PPC_STL r3, SVCPU_VMHANDLER(r5) + PPC_STL r3, HSTATE_VMHANDLER(r13) kvm_start_lightweight:
arch/powerpc/kvm/book3s_rmhandlers.S +8 -10
@@ -36,7 +36,6 @@ #if defined(CONFIG_PPC_BOOK3S_64) #define LOAD_SHADOW_VCPU(reg) GET_PACA(reg) -#define SHADOW_VCPU_OFF PACA_KVM_SVCPU #define MSR_NOIRQ MSR_KERNEL & ~(MSR_IR | MSR_DR) #define FUNC(name) GLUE(.,name)
@@ -66,7 +65,6 @@ kvmppc_skip_Hinterrupt: #elif defined(CONFIG_PPC_BOOK3S_32) -#define SHADOW_VCPU_OFF 0 #define MSR_NOIRQ MSR_KERNEL #define FUNC(name) name
@@ -96,14 +94,14 @@ kvmppc_trampoline_\intno: b kvmppc_resume_\intno /* Get back original handler */ 1: tophys(r13, r13) - stw r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) + stw r12, HSTATE_SCRATCH1(r13) mfspr r12, SPRN_SPRG_SCRATCH1 - stw r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH0)(r13) - lbz r12, (SHADOW_VCPU_OFF + SVCPU_IN_GUEST)(r13) + stw r12, HSTATE_SCRATCH0(r13) + lbz r12, HSTATE_IN_GUEST(r13) cmpwi r12, KVM_GUEST_MODE_NONE bne ..kvmppc_handler_hasmagic_\intno /* No KVM guest? Then jump back to the Linux handler! */ - lwz r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) + lwz r12, HSTATE_SCRATCH1(r13) b 2b /* Now we know we're handling a KVM guest */
@@ -146,8 +144,8 @@ INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC * * R12 = free * R13 = Shadow VCPU (PACA) - * SVCPU.SCRATCH0 = guest R12 - * SVCPU.SCRATCH1 = guest CR + * HSTATE.SCRATCH0 = guest R12 + * HSTATE.SCRATCH1 = guest CR * SPRG_SCRATCH0 = guest R13 * */
@@ -159,9 +157,9 @@ kvmppc_handler_skip_ins: mtsrr0 r12 /* Clean up all state */ - lwz r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) + lwz r12, HSTATE_SCRATCH1(r13) mtcr r12 - PPC_LL r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH0)(r13) + PPC_LL r12, HSTATE_SCRATCH0(r13) GET_SCRATCH0(r13) /* And get back into the code */
arch/powerpc/kvm/book3s_segment.S +36 -36
142 lines not on this page · raw message
Signature · 1 line
1.7.5.3
PATCH v2 9/12 kvm/powerpc: Add support for Book3S processors in hypervisor mode
In reply to Paul MackerrasThis adds support for KVM running on 64-bit Book 3S processors, specifically POWER7, in hypervisor mode. Using hypervisor mode means that the guest can use the processor's supervisor mode. That means that the guest can execute privileged instructions and access privileged registers itself without trapping to the host. This gives excellent performance, but does mean that KVM cannot emulate a processor architecture other than the one that the hardware implements.
This code assumes that the guest is running paravirtualized using the PAPR (Power Architecture Platform Requirements) interface, which is the interface that IBM's PowerVM hypervisor uses. That means that existing Linux distributions that run on IBM pSeries machines will also run under KVM without modification. In order to communicate the PAPR hypercalls to qemu, this adds a new KVM_EXIT_PAPR_HCALL exit code to include/linux/kvm.h.
Currently the choice between book3s_hv support and book3s_pr support (i.e. the existing code, which runs the guest in user mode) has to be made at kernel configuration time, so a given kernel binary can only do one or the other.
This new book3s_hv code doesn't support MMIO emulation at present. Since we are running paravirtualized guests, this isn't a serious restriction.
With the guest running in supervisor mode, most exceptions go straight to the guest. We will never get data or instruction storage or segment interrupts, alignment interrupts, decrementer interrupts, program interrupts, single-step interrupts, etc., coming to the hypervisor from the guest. Therefore this introduces a new KVMTEST_NONHV macro for the exception entry path so that we don't have to do the KVM test on entry to those exception handlers.
We do however get hypervisor decrementer, hypervisor data storage, hypervisor instruction storage, and hypervisor emulation assist interrupts, so we have to handle those.
In hypervisor mode, real-mode accesses can access all of RAM, not just a limited amount. Therefore we put all the guest state in the vcpu.arch and use the shadow_vcpu in the PACA only for temporary scratch space. We allocate the vcpu with kzalloc rather than vzalloc, and we don't use anything in the kvmppc_vcpu_book3s struct, so we don't allocate it. We don't have a shared page with the guest, but we still need a kvm_vcpu_arch_shared struct to store the values of various registers, so we include one in the vcpu_arch struct.
The POWER7 processor has a restriction that all threads in a core have to be in the same partition. MMU-on kernel code counts as a partition (partition 0), so we have to do a partition switch on every entry to and exit from the guest. At present we require the host and guest to run in single-thread mode because of this hardware restriction.
This code allocates a hashed page table for the guest and initializes it with HPTEs for the guest's Virtual Real Memory Area (VRMA). We require that the guest memory is allocated using 16MB huge pages, in order to simplify the low-level memory management. This also means that we can get away without tracking paging activity in the host for now, since huge pages can't be paged or swapped.
--- Documentation/virtual/kvm/api.txt | 17 + arch/powerpc/include/asm/exception-64s.h | 19 +- arch/powerpc/include/asm/kvm_asm.h | 4 + arch/powerpc/include/asm/kvm_book3s.h | 136 +++++- arch/powerpc/include/asm/kvm_book3s_64.h | 2 + arch/powerpc/include/asm/kvm_book3s_asm.h | 11 + arch/powerpc/include/asm/kvm_booke.h | 4 + arch/powerpc/include/asm/kvm_host.h | 53 ++- arch/powerpc/include/asm/kvm_ppc.h | 6 + arch/powerpc/include/asm/mmu-hash64.h | 10 +- arch/powerpc/include/asm/paca.h | 2 + arch/powerpc/include/asm/reg.h | 4 + arch/powerpc/kernel/asm-offsets.c | 78 ++++ arch/powerpc/kernel/exceptions-64s.S | 60 ++-- arch/powerpc/kvm/Kconfig | 41 ++- arch/powerpc/kvm/Makefile | 16 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 258 +++++++++++ arch/powerpc/kvm/book3s_hv.c | 430 +++++++++++++++++++ arch/powerpc/kvm/book3s_hv_interrupts.S | 325 ++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 667 +++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_segment.S | 34 +- arch/powerpc/kvm/powerpc.c | 22 +- arch/powerpc/kvm/trace.h | 2 +- include/linux/kvm.h | 6 + 24 files changed, 2125 insertions(+), 82 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_mmu_hv.c create mode 100644 arch/powerpc/kvm/book3s_hv.c create mode 100644 arch/powerpc/kvm/book3s_hv_interrupts.S create mode 100644 arch/powerpc/kvm/book3s_hv_rmhandlers.S
Documentation/virtual/kvm/api.txt +17 -0
@@ -1473,6 +1473,23 @@ Userspace can now handle the hypercall and when it's done modify the gprs as necessary. Upon guest entry all guest GPRs will then be replaced by the values in this struct. + /* KVM_EXIT_PAPR_HCALL */ + struct { + __u64 nr; + __u64 ret; + __u64 args[9]; + } papr_hcall; + +This is used on 64-bit PowerPC when emulating a pSeries partition, +e.g. with the 'pseries' machine type in qemu. It occurs when the +guest does a hypercall using the 'sc 1' instruction. The 'nr' field +contains the hypercall number (from the guest R3), and 'args' contains +the arguments (from the guest R4 - R12). Userspace should put the +return code in 'ret' and any extra returned values in args[]. +The possible hypercalls are defined in the Power Architecture Platform +Requirements (PAPR) document available from www.power.org (free +developer registration required to access it). + /* Fix the size of the union. */ char padding[256]; };
arch/powerpc/include/asm/exception-64s.h +15 -4
@@ -134,6 +134,17 @@ do_kvm_##n: \#define KVM_HANDLER_SKIP (area, h, n)#endif +#ifdef CONFIG_KVM_BOOK3S_PR +#define KVMTEST_PR (n) __KVMTEST(n) +#define KVM_HANDLER_PR (area, h, n) __KVM_HANDLER(area, h, n) +#define KVM_HANDLER_PR_SKIP (area, h, n) __KVM_HANDLER_SKIP(area, h, n) + +#else +#define KVMTEST_PR (n) +#define KVM_HANDLER_PR (area, h, n) +#define KVM_HANDLER_PR_SKIP (area, h, n) +#endif +#define NOTEST (n)/*
@@ -210,7 +221,7 @@ label##_pSeries: \HMT_MEDIUM ; \SET_SCRATCH0 (r13);/* save r13 */ \ EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common, \ - EXC_STD, KVMTEST, vec) + EXC_STD, KVMTEST_PR, vec)#define STD_EXCEPTION_HV (loc, vec, label) \ . = loc; \
@@ -227,8 +238,8 @@ label##_hv: \ beq masked_##h##interrupt#define _SOFTEN_TEST (h) __SOFTEN_TEST(h) -#define SOFTEN_TEST (vec) \ - KVMTEST(vec); \ +#define SOFTEN_TEST_PR (vec) \ + KVMTEST_PR(vec); \ _SOFTEN_TEST(EXC_STD)#define SOFTEN_TEST_HV (vec) \
@@ -248,7 +259,7 @@ label##_hv: \ .globl label##_pSeries; \ label##_pSeries: \ _MASKABLE_EXCEPTION_PSERIES(vec, label, \ - EXC_STD, SOFTEN_TEST) + EXC_STD, SOFTEN_TEST_PR)#define MASKABLE_EXCEPTION_HV (loc, vec, label) \ . = loc; \
arch/powerpc/include/asm/kvm_asm.h +4 -0
@@ -64,8 +64,12 @@#define BOOK3S_INTERRUPT_PROGRAM 0x700#define BOOK3S_INTERRUPT_FP_UNAVAIL 0x800#define BOOK3S_INTERRUPT_DECREMENTER 0x900 +#define BOOK3S_INTERRUPT_HV_DECREMENTER 0x980#define BOOK3S_INTERRUPT_SYSCALL 0xc00#define BOOK3S_INTERRUPT_TRACE 0xd00 +#define BOOK3S_INTERRUPT_H_DATA_STORAGE 0xe00 +#define BOOK3S_INTERRUPT_H_INST_STORAGE 0xe20 +#define BOOK3S_INTERRUPT_H_EMUL_ASSIST 0xe40#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40
arch/powerpc/include/asm/kvm_book3s.h +118 -18
174 lines not on this page · raw message
arch/powerpc/include/asm/kvm_book3s_64.h +2 -0
@@ -20,9 +20,11 @@#ifndef __ASM_KVM_BOOK3S_64_H__#define __ASM_KVM_BOOK3S_64_H__ +#ifdef CONFIG_KVM_BOOK3S_PR static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu (struct kvm_vcpu *vcpu) {return &get_paca ()->shadow_vcpu; } +#endif #endif /* __ASM_KVM_BOOK3S_64_H__ */
arch/powerpc/include/asm/kvm_book3s_asm.h +11 -0
@@ -74,6 +74,17 @@ struct kvmppc_host_state {ulong scratch0;ulong scratch1;u8 in_guest; + +#ifdef CONFIG_KVM_BOOK3S_64_HV +struct kvm_vcpu *kvm_vcpu; +u64 dabr; +u64 host_mmcr[3 ]; +u32 host_pmc[6 ]; +u64 host_purr; +u64 host_spurr; +u64 host_dscr; +u64 dec_expires; +#endif };struct kvmppc_book3s_shadow_vcpu {
arch/powerpc/include/asm/kvm_booke.h +4 -0
@@ -93,4 +93,8 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) return vcpu->arch.fault_dear; } +static inline ulong kvmppc_get_msr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.shared->msr; +}#endif /* __ASM_KVM_BOOKE_H__ */
arch/powerpc/include/asm/kvm_host.h +48 -5
125 lines not on this page · raw message
arch/powerpc/include/asm/kvm_ppc.h +6 -0
@@ -111,6 +111,12 @@ extern void kvmppc_booke_exit(void);extern void kvmppc_core_destroy_mmu (struct kvm_vcpu *vcpu);extern int kvmppc_kvm_pv (struct kvm_vcpu *vcpu); +extern long kvmppc_alloc_hpt (struct kvm *kvm); +extern void kvmppc_free_hpt (struct kvm *kvm); +extern long kvmppc_prepare_vrma (struct kvm *kvm, +struct kvm_userspace_memory_region *mem); +extern void kvmppc_map_vrma (struct kvm *kvm, +struct kvm_userspace_memory_region *mem);extern int kvmppc_core_init_vm (struct kvm *kvm);extern void kvmppc_core_destroy_vm (struct kvm *kvm); extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
arch/powerpc/include/asm/mmu-hash64.h +8 -2
@@ -90,13 +90,19 @@ extern char initial_stab[];#define HPTE_R_PP0 ASM_CONST(0x8000000000000000)#define HPTE_R_TS ASM_CONST(0x4000000000000000) +#define HPTE_R_KEY_HI ASM_CONST(0x3000000000000000)#define HPTE_R_RPN_SHIFT 12 -#define HPTE_R_RPN ASM_CONST(0x3ffffffffffff000) -#define HPTE_R_FLAGS ASM_CONST(0x00000000000003ff) +#define HPTE_R_RPN ASM_CONST(0x0ffffffffffff000)#define HPTE_R_PP ASM_CONST(0x0000000000000003)#define HPTE_R_N ASM_CONST(0x0000000000000004) +#define HPTE_R_G ASM_CONST(0x0000000000000008) +#define HPTE_R_M ASM_CONST(0x0000000000000010) +#define HPTE_R_I ASM_CONST(0x0000000000000020) +#define HPTE_R_W ASM_CONST(0x0000000000000040) +#define HPTE_R_WIMG ASM_CONST(0x0000000000000078)#define HPTE_R_C ASM_CONST(0x0000000000000080)#define HPTE_R_R ASM_CONST(0x0000000000000100) +#define HPTE_R_KEY_LO ASM_CONST(0x0000000000000e00)#define HPTE_V_1TB_SEG ASM_CONST(0x4000000000000000)#define HPTE_V_VRMA_MASK ASM_CONST(0x4001ffffff000000)
arch/powerpc/include/asm/paca.h +2 -0
@@ -147,8 +147,10 @@ struct paca_struct {struct dtl_entry *dtl_curr;/* pointer corresponding to dtl_ridx */ #ifdef CONFIG_KVM_BOOK3S_HANDLER +#ifdef CONFIG_KVM_BOOK3S_PR /* We use this to store guest state in */ struct kvmppc_book3s_shadow_vcpu shadow_vcpu; +#endif struct kvmppc_host_state kvm_hstate;#endif };
arch/powerpc/include/asm/reg.h +4 -0
@@ -189,6 +189,9 @@#define SPRN_CTR 0x009/* Count Register */ #define SPRN_DSCR 0x11#define SPRN_CFAR 0x1c/* Come From Address Register */ +#define SPRN_AMR 0x1d/* Authority Mask Register */ +#define SPRN_UAMOR 0x9d/* User Authority Mask Override Register */ +#define SPRN_AMOR 0x15d/* Authority Mask Override Register */ #define SPRN_ACOP 0x1F/* Available Coprocessor Register */ #define SPRN_CTRLF 0x088#define SPRN_CTRLT 0x098
@@ -252,6 +255,7 @@#define LPCR_RMI 0x00000002/* real mode is cache inhibit */ #define LPCR_HDICE 0x00000001/* Hyp Decr enable (HV,PR,EE) */ #define SPRN_LPID 0x13F/* Logical Partition Identifier */ +#define LPID_RSVD 0x3ff/* Reserved LPID for partn switching */ #define SPRN_HMER 0x150/* Hardware m? error recovery */ #define SPRN_HMEER 0x151/* Hardware m? enable error recovery */ #define SPRN_HEIR 0x153/* Hypervisor Emulated Instruction Register */
arch/powerpc/kernel/asm-offsets.c +78 -0
114 lines not on this page · raw message
arch/powerpc/kernel/exceptions-64s.S +32 -28
151 lines not on this page · raw message
arch/powerpc/kvm/Kconfig +38 -3
83 lines not on this page · raw message
arch/powerpc/kvm/Makefile +13 -3
@@ -14,7 +14,7 @@ CFLAGS_emulate.o := -I. common-objs-y += powerpc.o emulate.o obj-$(CONFIG_KVM_EXIT_TIMING) += timing.o -obj-$(CONFIG_KVM_BOOK3S_HANDLER) += book3s_exports.o +obj-$(CONFIG_KVM_BOOK3S_PR) += book3s_exports.o AFLAGS_booke_interrupts.o := -I$(obj)
@@ -38,7 +38,7 @@ kvm-e500-objs := \ e500_emulate.o kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs) -kvm-book3s_64-objs := \ +kvm-book3s_64_pr-objs := \ $(common-objs-y) \ fpu.o \ book3s_paired_singles.o \
@@ -50,7 +50,17 @@ kvm-book3s_64-objs := \ book3s_64_mmu_host.o \ book3s_64_mmu.o \ book3s_32_mmu.o -kvm-objs-$(CONFIG_KVM_BOOK3S_64) := $(kvm-book3s_64-objs) +kvm-objs-$(CONFIG_KVM_BOOK3S_64_PR) := $(kvm-book3s_64_pr-objs) + +kvm-book3s_64_hv-objs := \ + ../../../virt/kvm/kvm_main.o \ + powerpc.o \ + emulate.o \ + book3s.o \ + book3s_hv.o \ + book3s_hv_interrupts.o \ + book3s_64_mmu_hv.o +kvm-objs-$(CONFIG_KVM_BOOK3S_64_HV) := $(kvm-book3s_64_hv-objs) kvm-book3s_32-objs := \ $(common-objs-y) \
arch/powerpc/kvm/book3s_64_mmu_hv.c new file +258 -0
258 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c new file +430 -0
430 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_interrupts.S new file +325 -0
325 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S new file +667 -0
667 lines not on this page · raw message
arch/powerpc/kvm/book3s_segment.S +17 -17
@@ -85,29 +85,29 @@ kvmppc_handler_trampoline_enter: /* Enter guest */ - PPC_LL r4, (SVCPU_CTR)(r3) - PPC_LL r5, (SVCPU_LR)(r3) - lwz r6, (SVCPU_CR)(r3) - lwz r7, (SVCPU_XER)(r3) + PPC_LL r4, SVCPU_CTR(r3) + PPC_LL r5, SVCPU_LR(r3) + lwz r6, SVCPU_CR(r3) + lwz r7, SVCPU_XER(r3) mtctr r4 mtlr r5 mtcr r6 mtxer r7 - PPC_LL r0, (SVCPU_R0)(r3) - PPC_LL r1, (SVCPU_R1)(r3) - PPC_LL r2, (SVCPU_R2)(r3) - PPC_LL r4, (SVCPU_R4)(r3) - PPC_LL r5, (SVCPU_R5)(r3) - PPC_LL r6, (SVCPU_R6)(r3) - PPC_LL r7, (SVCPU_R7)(r3) - PPC_LL r8, (SVCPU_R8)(r3) - PPC_LL r9, (SVCPU_R9)(r3) - PPC_LL r10, (SVCPU_R10)(r3) - PPC_LL r11, (SVCPU_R11)(r3) - PPC_LL r12, (SVCPU_R12)(r3) - PPC_LL r13, (SVCPU_R13)(r3) + PPC_LL r0, SVCPU_R0(r3) + PPC_LL r1, SVCPU_R1(r3) + PPC_LL r2, SVCPU_R2(r3) + PPC_LL r4, SVCPU_R4(r3) + PPC_LL r5, SVCPU_R5(r3) + PPC_LL r6, SVCPU_R6(r3) + PPC_LL r7, SVCPU_R7(r3) + PPC_LL r8, SVCPU_R8(r3) + PPC_LL r9, SVCPU_R9(r3) + PPC_LL r10, SVCPU_R10(r3) + PPC_LL r11, SVCPU_R11(r3) + PPC_LL r12, SVCPU_R12(r3) + PPC_LL r13, SVCPU_R13(r3) PPC_LL r3, (SVCPU_R3)(r3)
arch/powerpc/kvm/powerpc.c +21 -1
@@ -38,8 +38,12 @@int kvm_arch_vcpu_runnable (struct kvm_vcpu *v) { +#ifndef CONFIG_KVM_BOOK3S_64_HV return !(v->arch.shared->msr &MSR_WE ) || !!(v->arch.pending_exceptions); +#else +return 1 ; +#endif }int kvmppc_kvm_pv (struct kvm_vcpu *vcpu)
@@ -183,10 +187,13 @@ int kvm_dev_ioctl_check_extension(long ext)#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 :case KVM_CAP_ENABLE_CAP : + r =1 ; +break ; +#ifndef CONFIG_KVM_BOOK3S_64_HV +case KVM_CAP_PPC_PAIRED_SINGLES :case KVM_CAP_PPC_OSI :case KVM_CAP_PPC_GET_PVINFO : r =1 ;
@@ -194,6 +201,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_COALESCED_MMIO : r =KVM_COALESCED_MMIO_PAGE_OFFSET ;break ; +#endif default : r =0 ;break ;
@@ -290,6 +298,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)hrtimer_init (&vcpu->arch.dec_timer,CLOCK_REALTIME ,HRTIMER_MODE_ABS );tasklet_init (&vcpu->arch.tasklet, kvmppc_decrementer_func, (ulong )vcpu); vcpu->arch.dec_timer.function = kvmppc_decrementer_wakeup; + vcpu->arch.dec_expires = ~(u64 )0 ;#ifdef CONFIG_KVM_EXIT_TIMING mutex_init (&vcpu->arch.exit_timing_lock);
@@ -316,6 +325,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)mtspr (SPRN_VRSAVE , vcpu->arch.vrsave);#endif kvmppc_core_vcpu_load (vcpu, cpu); + vcpu->cpu =smp_processor_id (); }void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu)
@@ -324,6 +334,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)#ifdef CONFIG_BOOKE vcpu->arch.vrsave =mfspr (SPRN_VRSAVE );#endif + vcpu->cpu =-1 ; } int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
@@ -495,6 +506,13 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)for (i =0 ; i <32 ; i++)kvmppc_set_gpr (vcpu, i, gprs[i]); vcpu->arch.osi_needed =0 ; + }else if (vcpu->arch.hcall_needed) { +int i; + +kvmppc_set_gpr (vcpu,3 , run->papr_hcall.ret); +for (i =0 ; i <9 ; ++i) +kvmppc_set_gpr (vcpu,4 + i, run->papr_hcall.args[i]); + vcpu->arch.hcall_needed =0 ; }kvmppc_core_deliver_interrupts (vcpu);
@@ -517,6 +535,8 @@ int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)if (waitqueue_active (&vcpu->wq)) {wake_up_interruptible (&vcpu->wq); vcpu->stat.halt_wakeup++; + }else if (vcpu->cpu !=-1 ) { +smp_send_reschedule (vcpu->cpu); }return 0 ;
arch/powerpc/kvm/trace.h +1 -1
@@ -103,7 +103,7 @@ TRACE_EVENT(kvm_gtlb_write,* Book3S trace points * *************************************************************************/ -#ifdef CONFIG_PPC_BOOK3S +#ifdef CONFIG_KVM_BOOK3S_PR TRACE_EVENT(kvm_book3s_exit, TP_PROTO(unsigned int exit_nr, struct kvm_vcpu *vcpu),
include/linux/kvm.h +6 -0
@@ -161,6 +161,7 @@ struct kvm_pit_config {#define KVM_EXIT_NMI 16#define KVM_EXIT_INTERNAL_ERROR 17#define KVM_EXIT_OSI 18 +#define KVM_EXIT_PAPR_HCALL 19/* For KVM_EXIT_INTERNAL_ERROR */ #define KVM_INTERNAL_ERROR_EMULATION 1
@@ -264,6 +265,11 @@ struct kvm_run {struct {__u64 gprs[32 ]; } osi; +struct { +__u64 nr; +__u64 ret; +__u64 args[9 ]; + } papr_hcall;/* Fix the size of the union. */ char padding[256 ]; };
Signature · 1 line
1.7.5.3
PATCH v2 10/12 kvm/powerpc: Handle some PAPR hcalls in the kernel
In reply to Paul MackerrasThis adds the infrastructure for handling PAPR hcalls in the kernel, either early in the guest exit path while we are still in real mode, or later once the MMU has been turned back on and we are in the full kernel context. The advantage of handling hcalls in real mode if possible is that we avoid two partition switches -- and this will become more important when we support SMT4 guests, since a partition switch means we have to pull all of the threads in the core out of the guest. The disadvantage is that we can only access the kernel linear mapping, not anything vmalloced or ioremapped, since the MMU is off.
This also adds code to handle the following hcalls in real mode:
H_ENTER Add an HPTE to the hashed page table H_REMOVE Remove an HPTE from the hashed page table H_READ Read HPTEs from the hashed page table H_PROTECT Change the protection bits in an HPTE
H_BULK_REMOVE Remove up to 4 HPTEs from the hashed page tableH_SET_DABR Set the data address breakpoint register
Plus code to handle the following hcalls in the kernel:
H_CEDE Idle the vcpu until an interrupt or H_PROD hcall arrivesH_PROD Wake up a ceded vcpuH_REGISTER_VPA Register a virtual processor area (VPA)
--- arch/powerpc/include/asm/hvcall.h | 5 + arch/powerpc/include/asm/kvm_host.h | 11 + arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 342 +++++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv.c | 170 +++++++++++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 156 ++++++++++++++- arch/powerpc/kvm/powerpc.c | 2 +- 8 files changed, 685 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/hvcall.h +5 -0
@@ -29,6 +29,10 @@#define H_LONG_BUSY_ORDER_100_SEC 9905/* Long busy, hint that 100sec \ is a good time to retry */ #define H_LONG_BUSY_END_RANGE 9905/* End of long busy range */ + +/* Internal value used in book3s_hv kvm support; not returned to guests */ +#define H_TOO_HARD 9999 +#define H_HARDWARE -1/* Hardware error */ #define H_FUNCTION -2/* Function not supported */ #define H_PRIVILEGE -3/* Caller not privileged */
@@ -100,6 +104,7 @@#define H_PAGE_SET_ACTIVE H_PAGE_STATE_CHANGE#define H_AVPN (1UL<<(63-32))/* An avpn is provided as a sanity test */ #define H_ANDCOND (1UL<<(63-33)) +#define H_LOCAL (1UL<<(63-35))#define H_ICACHE_INVALIDATE (1UL<<(63-40))/* icbi, etc. (ignored for IO pages) */ #define H_ICACHE_SYNCHRONIZE (1UL<<(63-41))/* dcbst, icbi, etc (ignored for IO pages */ #define H_COALESCE_CAND (1UL<<(63-42))/* page is a good candidate for coalescing */
arch/powerpc/include/asm/kvm_host.h +11 -0
@@ -59,6 +59,10 @@ struct kvm;struct kvm_run ;struct kvm_vcpu ; +struct lppaca ; +struct slb_shadow ; +struct dtl ; +struct kvm_vm_stat {u32 remote_tlb_flush; };
@@ -337,7 +341,14 @@ struct kvm_vcpu_arch {u64 dec_expires;unsigned long pending_exceptions;u16 last_cpu; +u8 ceded; +u8 prodded;u32 last_inst; + +struct lppaca *vpa; +struct slb_shadow *slb_shadow; +struct dtl *dtl; +struct dtl *dtl_end;int trap;struct kvm_vcpu_arch_shared *shared;unsigned long magic_page_pa;/* phys addr to map the magic page to */
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -117,6 +117,7 @@ extern long kvmppc_prepare_vrma(struct kvm *kvm, struct kvm_userspace_memory_region *mem);extern void kvmppc_map_vrma (struct kvm *kvm,struct kvm_userspace_memory_region *mem); +extern int kvmppc_pseries_do_hcall (struct kvm_vcpu *vcpu);extern int kvmppc_core_init_vm (struct kvm *kvm);extern void kvmppc_core_destroy_vm (struct kvm *kvm); extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -189,6 +189,7 @@ int main(void) DEFINE(LPPACADECRINT, offsetof(struct lppaca, int_dword.fields.decr_int));DEFINE (LPPACA_PMCINUSE , offsetof(struct lppaca , pmcregs_in_use));DEFINE (LPPACA_DTLIDX , offsetof(struct lppaca , dtl_idx)); +DEFINE (LPPACA_YIELDCOUNT , offsetof(struct lppaca , yield_count));DEFINE (PACA_DTL_RIDX , offsetof(struct paca_struct , dtl_ridx));#endif /* CONFIG_PPC_STD_MMU_64 */ DEFINE (PACAEMERGSP , offsetof(struct paca_struct , emergency_sp));
@@ -458,6 +459,7 @@ int main(void) DEFINE(VCPU_DEC, offsetof(struct kvm_vcpu, arch.dec)); DEFINE(VCPU_DEC_EXPIRES, offsetof(struct kvm_vcpu, arch.dec_expires)); DEFINE(VCPU_LPCR, offsetof(struct kvm_vcpu, arch.lpcr)); + DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa)); DEFINE(VCPU_MMCR, offsetof(struct kvm_vcpu, arch.mmcr)); DEFINE(VCPU_PMC, offsetof(struct kvm_vcpu, arch.pmc)); DEFINE(VCPU_SLB, offsetof(struct kvm_vcpu, arch.slb));
arch/powerpc/kvm/book3s_64_mmu_hv.c +342 -0
348 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c +169 -1
188 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +154 -2
188 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +1 -1
@@ -42,7 +42,7 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)return !(v->arch.shared->msr &MSR_WE ) || !!(v->arch.pending_exceptions);#else -return 1 ; +return !(v->arch.ceded) || !!(v->arch.pending_exceptions);#endif }
Signature · 1 line
1.7.5.3
PATCH v2 11/12 kvm/powerpc: Accelerate H_PUT_TCE by implementing it in real mode
In reply to Paul MackerrasFrom: David Gibson <[email protected]>
This improves I/O performance for guests using the PAPR paravirtualization interface by making the H_PUT_TCE hcall faster, by implementing it in real mode. H_PUT_TCE is used for updating virtual IOMMU tables, and is used both for virtual I/O and for real I/O in the PAPR interface.
Since this moves the IOMMU tables into the kernel, we define a new KVM_CREATE_SPAPR_TCE ioctl to allow qemu to create the tables. The ioctl returns a file descriptor which can be used to mmap the newly created table. The qemu driver models use them in the same way as userspace managed tables, but they can be updated directly by the guest with a real-mode H_PUT_TCE implementation, reducing the number of host/guest context switches during guest IO.
There are certain circumstances where it is useful for userland qemu to write to the TCE table even if the kernel H_PUT_TCE path is used most of the time. Specifically, allowing this will avoid awkwardness when we need to reset the table. More importantly, we will in the future need to write the table in order to restore its state after a checkpoint resume or migration.
--- Documentation/virtual/kvm/api.txt | 35 +++++++++ arch/powerpc/include/asm/kvm.h | 9 +++ arch/powerpc/include/asm/kvm_book3s_64.h | 2 + arch/powerpc/include/asm/kvm_host.h | 9 +++ arch/powerpc/include/asm/kvm_ppc.h | 2 + arch/powerpc/kvm/Makefile | 3 +- arch/powerpc/kvm/book3s_64_vio_hv.c | 73 +++++++++++++++++++ arch/powerpc/kvm/book3s_hv.c | 116 +++++++++++++++++++++++++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 2 +- arch/powerpc/kvm/powerpc.c | 18 +++++ include/linux/kvm.h | 3 + 11 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/kvm/book3s_64_vio_hv.c
Documentation/virtual/kvm/api.txt +35 -0
@@ -1291,6 +1291,41 @@ Returns the tsc frequency of the guest. The unit of the return value is KHz. If the host has unstable tsc this ioctl returns -EIO instead as an error. +4.56 KVM_CREATE_SPAPR_TCE + +Capability: KVM_CAP_SPAPR_TCE +Architectures: powerpc +Type: vm ioctl +Parameters: struct kvm_create_spapr_tce (in) +Returns: file descriptor for manipulating the created TCE table + +This creates a virtual TCE (translation control entry) table, which +is an IOMMU for PAPR-style virtual I/O. It is used to translate +logical addresses used in virtual I/O into guest physical addresses, +and provides a scatter/gather capability for PAPR virtual I/O. + +/* for KVM_CAP_SPAPR_TCE */ +struct kvm_create_spapr_tce { + __u64 liobn; + __u32 window_size; +}; + +The liobn field gives the logical IO bus number for which to create a +TCE table. The window_size field specifies the size of the DMA window +which this TCE table will translate - the table will contain one 64 +bit TCE entry for every 4kiB of the DMA window. + +When the guest issues an H_PUT_TCE hcall on a liobn for which a TCE +table has been created using this ioctl(), the kernel will handle it +in real mode, updating the TCE table. H_PUT_TCE calls for other +liobns will cause a vm exit and must be handled by userspace. + +The return value is a file descriptor which can be passed to mmap(2) +to map the created TCE table into userspace. This lets userspace read +the entries written by kernel-handled H_PUT_TCE calls, and also lets +userspace update the TCE table directly which is useful in some +circumstances. + 5. The kvm_run structure Application code obtains a pointer to the kvm_run structure by
arch/powerpc/include/asm/kvm.h +9 -0
@@ -22,6 +22,9 @@#include <linux/types.h> +/* Select powerpc specific features in <linux/kvm.h> */ +#define __KVM_HAVE_SPAPR_TCE +struct kvm_regs {__u64 pc;__u64 cr;
@@ -272,4 +275,10 @@ struct kvm_guest_debug_arch {#define KVM_INTERRUPT_UNSET -2U#define KVM_INTERRUPT_SET_LEVEL -3U +/* for KVM_CAP_SPAPR_TCE */ +struct kvm_create_spapr_tce { +__u64 liobn; +__u32 window_size; +}; +#endif /* __LINUX_KVM_POWERPC_H */
arch/powerpc/include/asm/kvm_book3s_64.h +2 -0
@@ -27,4 +27,6 @@ static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu(struct kvm_vcpu *vcpu) }#endif +#define SPAPR_TCE_SHIFT 12 +#endif /* __ASM_KVM_BOOK3S_64_H__ */
arch/powerpc/include/asm/kvm_host.h +9 -0
@@ -144,6 +144,14 @@ struct kvmppc_pginfo {atomic_t refcnt; }; +struct kvmppc_spapr_tce_table { +struct list_head list; +struct kvm *kvm; +u64 liobn; +u32 window_size; +struct page *pages[0 ]; +}; +struct kvm_arch {#ifdef CONFIG_KVM_BOOK3S_64_HV unsigned long hpt_virt;
@@ -157,6 +165,7 @@ struct kvm_arch {unsigned long sdr1;unsigned long host_sdr1;int tlbie_lock; +struct list_head spapr_tce_tables;unsigned short last_vcpu[NR_CPUS ];#endif /* CONFIG_KVM_BOOK3S_64_HV */ };
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -118,6 +118,8 @@ extern long kvmppc_prepare_vrma(struct kvm *kvm,extern void kvmppc_map_vrma (struct kvm *kvm,struct kvm_userspace_memory_region *mem);extern int kvmppc_pseries_do_hcall (struct kvm_vcpu *vcpu); +extern long kvm_vm_ioctl_create_spapr_tce (struct kvm *kvm, +struct kvm_create_spapr_tce *args);extern int kvmppc_core_init_vm (struct kvm *kvm);extern void kvmppc_core_destroy_vm (struct kvm *kvm); extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
arch/powerpc/kvm/Makefile +2 -1
@@ -59,7 +59,8 @@ kvm-book3s_64_hv-objs := \ book3s.o \ book3s_hv.o \ book3s_hv_interrupts.o \ - book3s_64_mmu_hv.o + book3s_64_mmu_hv.o \ + book3s_64_vio_hv.o kvm-objs-$(CONFIG_KVM_BOOK3S_64_HV) := $(kvm-book3s_64_hv-objs) kvm-book3s_32-objs := \
arch/powerpc/kvm/book3s_64_vio_hv.c new file +73 -0
73 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c +115 -1
134 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +1 -1
@@ -732,7 +732,7 @@ hcall_real_table: .long 0 /* 0x14 - H_CLEAR_REF */ .long .kvmppc_h_protect - hcall_real_table .long 0 /* 0x1c - H_GET_TCE */ - .long 0 /* 0x20 - H_SET_TCE */ + .long .kvmppc_h_put_tce - hcall_real_table .long 0 /* 0x24 - H_SET_SPRG0 */ .long .kvmppc_h_set_dabr - hcall_real_table .long 0 /* 0x2c */
arch/powerpc/kvm/powerpc.c +18 -0
@@ -202,6 +202,11 @@ int kvm_dev_ioctl_check_extension(long ext) r =KVM_COALESCED_MMIO_PAGE_OFFSET ;break ;#endif +#ifdef CONFIG_KVM_BOOK3S_64_HV +case KVM_CAP_SPAPR_TCE : + r =1 ; +break ; +#endif default : r =0 ;break ;
@@ -652,6 +657,19 @@ long kvm_arch_vm_ioctl(struct file *filp,break ; } +#ifdef CONFIG_KVM_BOOK3S_64_HV +case KVM_CREATE_SPAPR_TCE : { +struct kvm_create_spapr_tce create_tce; +struct kvm *kvm = filp->private_data; + + r = -EFAULT ; +if (copy_from_user (&create_tce, argp,sizeof (create_tce))) + goto out; + r =kvm_vm_ioctl_create_spapr_tce (kvm, &create_tce); + goto out; + } +#endif /* CONFIG_KVM_BOOK3S_64_HV */ +default : r = -ENOTTY ; }
include/linux/kvm.h +3 -0
@@ -550,6 +550,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_TSC_CONTROL 60#define KVM_CAP_GET_TSC_KHZ 61#define KVM_CAP_PPC_BOOKE_SREGS 62 +#define KVM_CAP_SPAPR_TCE 63#ifdef KVM_CAP_IRQ_ROUTING
@@ -752,6 +753,8 @@ struct kvm_clock_data {/* Available with KVM_CAP_XCRS */ #define KVM_GET_XCRS _IOR(KVMIO, 0xa6, struct kvm_xcrs)#define KVM_SET_XCRS _IOW(KVMIO, 0xa7, struct kvm_xcrs) +/* Available with KVM_CAP_SPAPR_TCE */ +#define KVM_CREATE_SPAPR_TCE _IOW(KVMIO, 0xa8, struct kvm_create_spapr_tce)#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
Signature · 1 line
1.7.5.3
PATCH v2 12/12 kvm/powerpc: Allow book3s_hv guests to use SMT processor modes
In reply to Paul MackerrasThis lifts the restriction that book3s_hv guests can only run one hardware thread per core, and allows them to use up to 4 threads per core on POWER7. The host still has to run single-threaded.
This capability is advertised to qemu through a new KVM_CAP_PPC_SMT capability. The return value of the ioctl querying this capability is the number of vcpus per virtual CPU core (vcore), currently 4.
To use this, the host kernel should be booted with all threads active, and then all the secondary threads should be offlined. This will put the secondary threads into nap mode. KVM will then wake them from nap mode and use them for running guest code (while they are still offline). To wake the secondary threads, we send them an IPI using a new xics_wake_cpu() function, implemented in arch/powerpc/sysdev/xics/icp-native.c. In other words, at this stage we assume that the platform has a XICS interrupt controller and we are using icp-native.c to drive it. Since the woken thread will need to acknowledge and clear the IPI, we also export the base physical address of the XICS registers using kvmppc_set_xics_phys() for use in the low-level KVM book3s code.
When a vcpu is created, it is assigned to a virtual CPU core. The vcore number is obtained by dividing the vcpu number by 4, since we assume at most 4 threads per core. Thus, if qemu wishes to run the guest in single-threaded mode, it should make all vcpu numbers be multiples of 4.
We distinguish three states of a vcpu: runnable (i.e., ready to execute the guest), blocked (that is, idle), and busy in host. We currently implement a policy that the vcore can run only when all its threads are runnable or blocked. This way, if a vcpu needs to execute elsewhere in the kernel or in qemu, it can do so without being starved of CPU by the other vcpus.
When a vcore starts to run, it executes in the context of one of the vcpu threads. The other vcpu threads all go to sleep and stay asleep until something happens requiring the vcpu thread to return to qemu, or to wake up to run the vcore (this can happen when another vcpu thread goes from busy in host state to blocked).
It can happen that a vcpu goes from blocked to runnable state (e.g. because of an interrupt), and the vcore it belongs to is already running. In that case it can start to run immediately as long as the none of the vcpus in the vcore have started to exit the guest. We send the next free thread in the vcore an IPI to get it to start to execute the guest. It synchronizes with the other threads via the vcore->entry_exit_count field to make sure that it doesn't go into the guest if the other vcpus are exiting by the time that it is ready to actually enter the guest.
Note that there is no fixed relationship between the hardware thread number and the vcpu number. Hardware threads are assigned to vcpus as they become runnable, so we will always use the lower-numbered hardware threads in preference to higher-numbered threads if not all the vcpus in the vcore are runnable, regardless of which vcpus are runnable.
--- Documentation/virtual/kvm/api.txt | 13 ++ arch/powerpc/include/asm/kvm.h | 1 + arch/powerpc/include/asm/kvm_book3s_asm.h | 2 + arch/powerpc/include/asm/kvm_host.h | 45 +++++- arch/powerpc/include/asm/kvm_ppc.h | 13 ++ arch/powerpc/kernel/asm-offsets.c | 6 + arch/powerpc/kernel/exceptions-64s.S | 31 +++- arch/powerpc/kernel/idle_power7.S | 2 - arch/powerpc/kvm/Kconfig | 2 +- arch/powerpc/kvm/book3s_hv.c | 265 +++++++++++++++++++++++++++-- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 168 ++++++++++++++++++- arch/powerpc/kvm/powerpc.c | 3 + arch/powerpc/sysdev/xics/icp-native.c | 7 + include/linux/kvm.h | 1 + 14 files changed, 529 insertions(+), 30 deletions(-)
Documentation/virtual/kvm/api.txt +13 -0
@@ -180,6 +180,19 @@ KVM_CHECK_EXTENSION ioctl() to determine the value for max_vcpus at run-time. If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4 cpus max. +On powerpc using book3s_hv mode, the vcpus are mapped onto virtual +threads in one or more virtual CPU cores. (This is because the +hardware requires all the hardware threads in a CPU core to be in the +same partition.) The KVM_CAP_PPC_SMT capability indicates the number +of vcpus per virtual core (vcore). The vcore id is obtained by +dividing the vcpu id by the number of vcpus per vcore. The vcpus in a +given vcore will always be in the same physical core as each other +(though that might be a different physical core from time to time). +Userspace can control the threading (SMT) mode of the guest by its +allocation of vcpu ids. For example, if userspace wants +single-threaded guest vcpus, it should make all vcpu ids be a multiple +of the number of vcpus per vcore. + 4.8 KVM_GET_DIRTY_LOG (vm ioctl) Capability: basic
arch/powerpc/include/asm/kvm.h +1 -0
@@ -24,6 +24,7 @@/* Select powerpc specific features in <linux/kvm.h> */ #define __KVM_HAVE_SPAPR_TCE +#define __KVM_HAVE_PPC_SMTstruct kvm_regs {__u64 pc;
arch/powerpc/include/asm/kvm_book3s_asm.h +2 -0
@@ -77,6 +77,8 @@ struct kvmppc_host_state {#ifdef CONFIG_KVM_BOOK3S_64_HV struct kvm_vcpu *kvm_vcpu; +struct kvmppc_vcore *kvm_vcore; +unsigned long xics_phys;u64 dabr;u64 host_mmcr[3 ];u32 host_pmc[6 ];
arch/powerpc/include/asm/kvm_host.h +44 -1
74 lines not on this page · raw message
arch/powerpc/include/asm/kvm_ppc.h +13 -0
@@ -33,6 +33,9 @@#else #include <asm/kvm_booke.h> #endif +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER +#include <asm/paca.h> +#endif enum emulation_result {EMULATE_DONE ,/* no further processing */
@@ -168,4 +171,14 @@ int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);void kvmppc_set_pid (struct kvm_vcpu *vcpu,u32 pid); +#ifdef CONFIG_KVM_BOOK3S_64_HV +static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) +{ + paca[cpu].kvm_hstate.xics_phys = addr; +} +#else +static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) +{} +#endif +#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kernel/asm-offsets.c +6 -0
@@ -470,6 +470,10 @@ int main(void) DEFINE(VCPU_FAULT_DAR, offsetof(struct kvm_vcpu, arch.fault_dar)); DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); DEFINE(VCPU_TRAP, offsetof(struct kvm_vcpu, arch.trap)); + DEFINE(VCPU_PTID, offsetof(struct kvm_vcpu, arch.ptid)); +DEFINE (VCORE_ENTRY_EXIT , offsetof(struct kvmppc_vcore , entry_exit_count)); +DEFINE (VCORE_NAP_COUNT , offsetof(struct kvmppc_vcore , nap_count)); +DEFINE (VCORE_IN_GUEST , offsetof(struct kvmppc_vcore , in_guest));DEFINE (VCPU_SVCPU , offsetof(struct kvmppc_vcpu_book3s , shadow_vcpu) - offsetof(struct kvmppc_vcpu_book3s , vcpu));DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));
@@ -528,6 +532,8 @@ int main(void)#ifdef CONFIG_KVM_BOOK3S_64_HV HSTATE_FIELD (HSTATE_KVM_VCPU , kvm_vcpu); +HSTATE_FIELD (HSTATE_KVM_VCORE , kvm_vcore); +HSTATE_FIELD (HSTATE_XICS_PHYS , xics_phys);HSTATE_FIELD (HSTATE_MMCR , host_mmcr);HSTATE_FIELD (HSTATE_PMC , host_pmc);HSTATE_FIELD (HSTATE_PURR , host_purr);
arch/powerpc/kernel/exceptions-64s.S +22 -9
@@ -49,19 +49,32 @@ BEGIN_FTR_SECTION * state loss at this time. */ mfspr r13,SPRN_SRR1 - rlwinm r13,r13,47-31,30,31 - cmpwi cr0,r13,1 - bne 1f - b .power7_wakeup_noloss -1: cmpwi cr0,r13,2 - bne 1f - b .power7_wakeup_loss + rlwinm. r13,r13,47-31,30,31 + beq 9f + + /* waking up from powersave (nap) state */ + cmpwi cr1,r13,2 /* Total loss of HV state is fatal, we could try to use the * PIR to locate a PACA, then use an emergency stack etc... * but for now, let's just stay stuck here */ -1: cmpwi cr0,r13,3 - beq . + bgt cr1,. + GET_PACA(r13) + +#ifdef CONFIG_KVM_BOOK3S_64_HV + lbz r0,PACAPROCSTART(r13) + cmpwi r0,0x80 + bne 1f + li r0,0 + stb r0,PACAPROCSTART(r13) + b kvm_start_guest +1: +#endif + + beq cr1,2f + b .power7_wakeup_noloss +2: b .power7_wakeup_loss +9: END_FTR_SECTION_IFSET(CPU_FTR_HVMODE_206) #endif /* CONFIG_PPC_P7_NAP */ EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common, EXC_STD,
arch/powerpc/kernel/idle_power7.S +0 -2
@@ -73,7 +73,6 @@ _GLOBAL(power7_idle) b . _GLOBAL(power7_wakeup_loss) - GET_PACA(r13) ld r1,PACAR1(r13) REST_NVGPRS(r1) REST_GPR(2, r1)
@@ -87,7 +86,6 @@ _GLOBAL(power7_wakeup_loss) rfid _GLOBAL(power7_wakeup_noloss) - GET_PACA(r13) ld r1,PACAR1(r13) ld r4,_MSR(r1) ld r5,_NIP(r1)
arch/powerpc/kvm/Kconfig +1 -1
@@ -58,7 +58,7 @@ config KVM_BOOK3S_64 config KVM_BOOK3S_64_HV bool "KVM support for POWER7 using hypervisor mode in host" - depends on EXPERIMENTAL && PPC_BOOK3S_64 + depends on EXPERIMENTAL && PPC_BOOK3S_64 && (PPC_PSERIES || PPC_POWERNV) select KVM select KVM_BOOK3S_64 ---help---
arch/powerpc/kvm/book3s_hv.c +254 -11
326 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +162 -6
227 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +3 -0
@@ -206,6 +206,9 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_SPAPR_TCE : r =1 ;break ; +case KVM_CAP_PPC_SMT : + r =KVM_THREADS_PER_CORE ; +break ;#endif default : r =0 ;
arch/powerpc/sysdev/xics/icp-native.c +7 -0
@@ -24,6 +24,7 @@#include <asm/irq.h> #include <asm/errno.h> #include <asm/xics.h> +#include <asm/kvm_ppc.h> struct icp_ipl { union {
@@ -139,6 +140,11 @@ static void icp_native_cause_ipi(int cpu, unsigned long data)icp_native_set_qirr (cpu,IPI_PRIORITY ); } +void xics_wake_cpu (int cpu) +{ +icp_native_set_qirr (cpu,IPI_PRIORITY ); +} +static irqreturn_t icp_native_ipi_action (int irq,void *dev_id) {int cpu =smp_processor_id ();
@@ -185,6 +191,7 @@ static int __init icp_native_map_one_cpu(int hw_id, unsigned long addr, } icp_native_regs[cpu] =ioremap (addr, size); +kvmppc_set_xics_phys (cpu, addr);if (!icp_native_regs[cpu]) { pr_warning("icp_native: Failed ioremap for CPU %d, " "interrupt server #0x%x, addr %#lx\n",
include/linux/kvm.h +1 -0
@@ -551,6 +551,7 @@ struct kvm_ppc_pvinfo {#define KVM_CAP_GET_TSC_KHZ 61#define KVM_CAP_PPC_BOOKE_SREGS 62#define KVM_CAP_SPAPR_TCE 63 +#define KVM_CAP_PPC_SMT 64#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.7.5.3
Quoted 13 lines · Paul Mackerras
The following series of patches enable KVM to exploit the hardware hypervisor mode on 64-bit Power ISA Book3S machines. At present only POWER7 is supported, but it would be easy to add other processors.
Running the KVM host in hypervisor mode means that the guest can use both supervisor mode and user mode. That means that the guest can execute supervisor-privilege instructions and access supervisor- privilege registers. In addition the hardware directs most exceptions to the guest. Thus we don't need to emulate any instructions in the host. Generally, the only times we need to exit the guest are when it does a hypercall or when an external interrupt or host timer (decrementer) interrupt occurs.
Quoted 8 lines
The focus of this KVM implementation is to run guests that use the PAPR (Power Architecture Platform Requirements) paravirtualization interface, which is the interface supplied by PowerVM on IBM pSeries machines. Currently the "pseries" machine type in qemu is only supported by
book3s_hvKVM, andbook3s_hvKVM only supports the "pseries" machine type. That will hopefully change in future.These patches are against Linus' v3.0-rc1 tree.
Thinking about the testability of this a bit more ... how much effort would it be to get this code running on a 970MP with SLOF? There should only be a few POWER7 specific pieces, right?
Alex
Quoted 3 lines · Alexander Graf
Thinking about the testability of this a bit more ... how much effort would it be to get this code running on a 970MP with SLOF? There should only be a few POWER7 specific pieces, right?
Do you have a 970MP that has a usable hypervisor mode, i.e. not an Apple machine? The 970s in Apple machines have the HV hard-wired to 1, which means they do have a hypervisor mode but it isn't any use.
If you do have such a machine, then we would have to look at some details like the instruction sequence for the partition switch, and make sure we don't try to use SMT4 mode. Also, I believe we will have to flush the TLB on partition switches, since Power processors prior to POWER7 didn't tag the TLB entries with the partition ID.
So it should be quite feasible if you have a non-Apple machine. I will check whether the 970MP machines that Terrasoft were distributing would be suitable. We have one of them in the lab.
Regards,
Paul.
Quoted 16 lines · Paul Mackerras
Quoted 3 lines · Alexander Graf
Thinking about the testability of this a bit more ... how much effort would it be to get this code running on a 970MP with SLOF? There should only be a few POWER7 specific pieces, right?
Do you have a 970MP that has a usable hypervisor mode, i.e. not an Apple machine? The 970s in Apple machines have the HV hard-wired to 1, which means they do have a hypervisor mode but it isn't any use.
If you do have such a machine, then we would have to look at some details like the instruction sequence for the partition switch, and make sure we don't try to use SMT4 mode. Also, I believe we will have to flush the TLB on partition switches, since Power processors prior to POWER7 didn't tag the TLB entries with the partition ID.
Quoted 3 lines
So it should be quite feasible if you have a non-Apple machine. I will check whether the 970MP machines that Terrasoft were distributing would be suitable. We have one of them in the lab.
That's the one I was thinking of and yes, I have one available. That way I could test 99% of your code, you don't have to release hardware, and everyone's happy :).
Alex
Quoted 19 lines · Alexander Graf
Quoted 16 lines · Paul Mackerras
Quoted 3 lines · Alexander Graf
Thinking about the testability of this a bit more ... how much effort would it be to get this code running on a 970MP with SLOF? There should only be a few POWER7 specific pieces, right?
Do you have a 970MP that has a usable hypervisor mode, i.e. not an Apple machine? The 970s in Apple machines have the HV hard-wired to 1, which means they do have a hypervisor mode but it isn't any use.
If you do have such a machine, then we would have to look at some details like the instruction sequence for the partition switch, and make sure we don't try to use SMT4 mode. Also, I believe we will have to flush the TLB on partition switches, since Power processors prior to POWER7 didn't tag the TLB entries with the partition ID.
Quoted 6 lines
Quoted 3 lines
So it should be quite feasible if you have a non-Apple machine. I will check whether the 970MP machines that Terrasoft were distributing would be suitable. We have one of them in the lab.
That's the one I was thinking of and yes, I have one available. That way I could test 99% of your code, you don't have to release hardware, and everyone's happy :).
Be aware that on 970s (off the top of my head):
- did not have the LPCR architected so you'll have to access individual HID registers.
- old style RMOR is supported, not VRMA
- no MEDiated interrupt
-jx
Quoted 7 lines
Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 19 lines · Alexander Graf
Quoted 16 lines · Paul Mackerras
Quoted 3 lines · Alexander Graf
Thinking about the testability of this a bit more ... how much effort would it be to get this code running on a 970MP with SLOF? There should only be a few POWER7 specific pieces, right?
Do you have a 970MP that has a usable hypervisor mode, i.e. not an Apple machine? The 970s in Apple machines have the HV hard-wired to 1, which means they do have a hypervisor mode but it isn't any use.
If you do have such a machine, then we would have to look at some details like the instruction sequence for the partition switch, and make sure we don't try to use SMT4 mode. Also, I believe we will have to flush the TLB on partition switches, since Power processors prior to POWER7 didn't tag the TLB entries with the partition ID.
Quoted 7 lines
Quoted 3 lines
So it should be quite feasible if you have a non-Apple machine. I will check whether the 970MP machines that Terrasoft were distributing would be suitable. We have one of them in the lab.
That's the one I was thinking of and yes, I have one available. That way I could test 99% of your code, you don't have to release hardware, and everyone's happy :).
I checked our YDL PowerStation and it does appear to have a usable hypervisor mode. :)
As Jimi X pointed out, there are a few things that POWER7 has that 970 doesn't. In particular the lack of VRMA mode means that we will have to find 64MB of physically contiguous memory, aligned on a 64MB address boundary, for the real mode area (RMO) for the guest. 64MB is the smallest RMO size that the 970 supports; it also supports 128MB, 256MB, 1GB, 16GB and 256GB. I think we'll have to reserve some memory at boot. We may get away with bumping up CONFIG_FORCE_MAX_ZONEORDER, but relying on allocating a physically contiguous 64MB at runtime seems somewhat fragile. Also, we'll need some qemu changes since it won't be able to allocate the RMO itself.
The other thing is that we have to flush the TLB on every partitions switch, plus make sure that we're not switching the partition ID while any other cpu in the same partition is doing a tlbie or tlbsync. Still, it should all be doable.
Paul.
Quoted 16 lines · Paul Mackerras
Quoted 3 lines · Alexander Graf
Thinking about the testability of this a bit more ... how much effort would it be to get this code running on a 970MP with SLOF? There should only be a few POWER7 specific pieces, right?
Do you have a 970MP that has a usable hypervisor mode, i.e. not an Apple machine? The 970s in Apple machines have the HV hard-wired to 1, which means they do have a hypervisor mode but it isn't any use.
If you do have such a machine, then we would have to look at some details like the instruction sequence for the partition switch, and make sure we don't try to use SMT4 mode. Also, I believe we will have to flush the TLB on partition switches, since Power processors prior to POWER7 didn't tag the TLB entries with the partition ID.
Quoted 3 lines
So it should be quite feasible if you have a non-Apple machine. I will check whether the 970MP machines that Terrasoft were distributing would be suitable. We have one of them in the lab.
PA6T is closer to power7 than 970 when it comes to hypervisor features (i.e. VRMA, LPCR, mediated interrupts are all available there). I can try to find some old hardware if there's any interest from anyone to use it.
Of course, there isn't much of a roadmap. But 970 isn't really going anywhere either. :)
-Olof