Allow PR and HV KVM to coexist in one kernel
Subsystems (10)
cover Allow PR and HV KVM to coexist in one kernel
Hi All,
This patch series support enabling HV and PR KVM together in the same kernel. We extend machine property with new property "kvm_type". A value of "HV" will force HV KVM and "PR" PR KVM. If we don't specify kvm_type we will select the fastest KVM mode. ie, HV if that is supported otherwise PR.
With Qemu command line having
-machine pseries,accel=kvm,kvm_type=HV
[root@llmp24l02 qemu]# bash ../qemu
failed to initialize KVM: Invalid argument
[root@llmp24l02 qemu]# modprobe kvm-pr
[root@llmp24l02 qemu]# bash ../qemu
failed to initialize KVM: Invalid argument
[root@llmp24l02 qemu]# modprobe kvm-hv
[root@llmp24l02 qemu]# bash ../qemu
now with
-machine pseries,accel=kvm,kvm_type=PR
[root@llmp24l02 qemu]# rmmod kvm-pr
[root@llmp24l02 qemu]# bash ../qemu
failed to initialize KVM: Invalid argument
[root@llmp24l02 qemu]#
[root@llmp24l02 qemu]# modprobe kvm-pr
[root@llmp24l02 qemu]# bash ../qemu
Changes from V1:
* Build fixes for BOOKE (only compile tested)
* Address review feedback
-aneesh
PATCH 1/14 kvm: powerpc: book3s: remove kvmppc_handler_highmem label
From: Paul Mackerras <[email protected]>
This label is not used now.
--- arch/powerpc/kvm/book3s_hv_interrupts.S | 3 --- arch/powerpc/kvm/book3s_interrupts.S | 3 --- 2 files changed, 6 deletions(-)
arch/powerpc/kvm/book3s_hv_interrupts.S +0 -3
@@ -158,9 +158,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) * Interrupts are enabled again at this point. */ -.global kvmppc_handler_highmem -kvmppc_handler_highmem: - /* * Register usage at this point: *
arch/powerpc/kvm/book3s_interrupts.S +0 -3
@@ -121,9 +121,6 @@ kvm_start_lightweight: * */ -.global kvmppc_handler_highmem -kvmppc_handler_highmem: - /* * Register usage at this point: *
Signature · 1 line
1.8.1.2
PATCH 2/14 kvm: powerpc: book3s: move book3s_64_vio_hv.c into the main kernel binary
In reply to Aneesh Kumar K.VFrom: Paul Mackerras <[email protected]>
Since the code in book3s_64_vio_hv.c is called from real mode with HV KVM, and therefore has to be built into the main kernel binary, this makes it always built-in rather than part of the KVM module. It gets called from the KVM module by PR KVM, so this adds an EXPORT_SYMBOL_GPL().
--- arch/powerpc/kvm/Makefile | 12 ++++++++---- arch/powerpc/kvm/book3s_64_vio_hv.c | 1 + 2 files changed, 9 insertions(+), 4 deletions(-)
arch/powerpc/kvm/Makefile +8 -4
@@ -53,32 +53,36 @@ kvm-e500mc-objs := \ e500_emulate.o kvm-objs-$(CONFIG_KVM_E500MC) := $(kvm-e500mc-objs) +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) := \ + book3s_64_vio_hv.o + kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ $(KVM)/coalesced_mmio.o \ fpu.o \ book3s_paired_singles.o \ book3s_pr.o \ book3s_pr_papr.o \ - book3s_64_vio_hv.o \ book3s_emulate.o \ book3s_interrupts.o \ book3s_mmu_hpte.o \ book3s_64_mmu_host.o \ book3s_64_mmu.o \ book3s_32_mmu.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ + +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) += \ book3s_rmhandlers.o kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ book3s_hv.o \ book3s_hv_interrupts.o \ book3s_64_mmu_hv.o + kvm-book3s_64-builtin-xics-objs-$(CONFIG_KVM_XICS) := \ book3s_hv_rm_xics.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ + +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ book3s_hv_rmhandlers.o \ book3s_hv_rm_mmu.o \ - book3s_64_vio_hv.o \ book3s_hv_ras.o \ book3s_hv_builtin.o \ book3s_hv_cma.o \
arch/powerpc/kvm/book3s_64_vio_hv.c +1 -0
@@ -74,3 +74,4 @@ long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,/* Didn't find the liobn, punt it to userspace */ return H_TOO_HARD ; } +EXPORT_SYMBOL_GPL (kvmppc_h_put_tce);
Signature · 1 line
1.8.1.2
PATCH 3/14 kvm: powerpc: book3s: pr: Rename KVM_BOOK3S_PR to KVM_BOOK3S_PR_POSSIBLE
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
With later patches supporting PR kvm as a kernel module, the changes that has to be built into the main kernel binary to enable PR KVM module is now selected via KVM_BOOK3S_PR_POSSIBLE
--- arch/powerpc/include/asm/exception-64s.h | 2 +- arch/powerpc/include/asm/kvm_book3s.h | 4 ++-- arch/powerpc/include/asm/kvm_book3s_64.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 2 +- arch/powerpc/include/asm/paca.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/kvm/Kconfig | 6 +++--- arch/powerpc/kvm/trace.h | 10 +++++----- 9 files changed, 16 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/exception-64s.h +1 -1
@@ -243,7 +243,7 @@ do_kvm_##n: \#define KVM_HANDLER_SKIP (area, h, n)#endif -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE #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)
arch/powerpc/include/asm/kvm_book3s.h +2 -2
@@ -304,7 +304,7 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)return vcpu->arch.fault_dar; } -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) {
@@ -339,7 +339,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) return crit; } -#else /* CONFIG_KVM_BOOK3S_PR */ +#else /* CONFIG_KVM_BOOK3S_PR_POSSIBLE */ static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) {
arch/powerpc/include/asm/kvm_book3s_64.h +1 -1
@@ -20,7 +20,7 @@ #ifndef __ASM_KVM_BOOK3S_64_H__ #define __ASM_KVM_BOOK3S_64_H__ -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE static inline struct kvmppc_book3s_shadow_vcpu *svcpu_get(struct kvm_vcpu *vcpu) { preempt_disable();
arch/powerpc/include/asm/kvm_host.h +1 -1
@@ -262,7 +262,7 @@ struct kvm_arch {struct kvmppc_vcore *vcores[KVM_MAX_VCORES ];int hpt_cma_alloc;#endif /* CONFIG_KVM_BOOK3S_64_HV */ -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE struct mutex hpt_mutex;#endif #ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/include/asm/paca.h +1 -1
@@ -161,7 +161,7 @@ struct paca_struct {struct dtl_entry *dtl_curr;/* pointer corresponding to dtl_ridx */ #ifdef CONFIG_KVM_BOOK3S_HANDLER -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE /* We use this to store guest state in */ struct kvmppc_book3s_shadow_vcpu shadow_vcpu;#endif
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -530,7 +530,7 @@ int main(void)DEFINE (VCPU_SLB_SIZE ,sizeof (struct kvmppc_slb ));#ifdef CONFIG_PPC_BOOK3S_64 -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE DEFINE (PACA_SVCPU , offsetof(struct paca_struct , shadow_vcpu));# define SVCPU_FIELD (x, f) DEFINE(x, offsetof(struct paca_struct, shadow_vcpu.f))#else
arch/powerpc/kernel/exceptions-64s.S +1 -1
@@ -424,7 +424,7 @@ data_access_check_stab: mfspr r9,SPRN_DSISR srdi r10,r10,60 rlwimi r10,r9,16,0x20 -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE lbz r9,HSTATE_IN_GUEST(r13) rlwimi r10,r9,8,0x300 #endif
arch/powerpc/kvm/Kconfig +3 -3
@@ -34,7 +34,7 @@ config KVM_BOOK3S_64_HANDLER bool select KVM_BOOK3S_HANDLER -config KVM_BOOK3S_PR +config KVM_BOOK3S_PR_POSSIBLE bool select KVM_MMIO select MMU_NOTIFIER
@@ -44,7 +44,7 @@ config KVM_BOOK3S_32 depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT select KVM select KVM_BOOK3S_32_HANDLER - select KVM_BOOK3S_PR + select KVM_BOOK3S_PR_POSSIBLE ---help--- Support running unmodified book3s_32 guest kernels in virtual machines on book3s_32 host processors.
@@ -91,7 +91,7 @@ config KVM_BOOK3S_64_HV config KVM_BOOK3S_64_PR def_bool y depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV - select KVM_BOOK3S_PR + select KVM_BOOK3S_PR_POSSIBLE config KVM_BOOKE_HV bool
arch/powerpc/kvm/trace.h +5 -5
@@ -94,7 +94,7 @@ TRACE_EVENT(kvm_exit, __field( unsigned long, pc ) __field( unsigned long, msr ) __field( unsigned long, dar ) -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE __field( unsigned long, srr1 ) #endif__field (unsigned long , last_inst )
@@ -105,7 +105,7 @@ TRACE_EVENT(kvm_exit, __entry->pc =kvmppc_get_pc (vcpu); __entry->dar =kvmppc_get_fault_dar (vcpu); __entry->msr = vcpu->arch.shared->msr; -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE __entry->srr1 = vcpu->arch.shadow_srr1;#endif __entry->last_inst = vcpu->arch.last_inst;
@@ -115,7 +115,7 @@ TRACE_EVENT(kvm_exit, " | pc=0x%lx" " | msr=0x%lx" " | dar=0x%lx" -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE " | srr1=0x%lx" #endif" | last_inst=0x%lx"
@@ -124,7 +124,7 @@ TRACE_EVENT(kvm_exit, __entry->pc, __entry->msr, __entry->dar, -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE __entry->srr1, #endif __entry->last_inst
@@ -236,7 +236,7 @@ TRACE_EVENT(kvm_check_requests,* Book3S trace points * *************************************************************************/ -#ifdef CONFIG_KVM_BOOK3S_PR +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE TRACE_EVENT(kvm_book3s_reenter, TP_PROTO(int r, struct kvm_vcpu *vcpu),
Signature · 1 line
1.8.1.2
PATCH 4/14 kvm: powerpc: book3s: Add a new config variable CONFIG_KVM_BOOK3S_HV_POSSIBLE
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This help ups to select the relevant code in the kernel code when we later move HV and PR bits as seperate modules. The patch also makes the config options for PR KVM selectable
--- arch/powerpc/include/asm/kvm_book3s.h | 2 -- arch/powerpc/include/asm/kvm_book3s_64.h | 6 +++--- arch/powerpc/include/asm/kvm_book3s_asm.h | 2 +- arch/powerpc/include/asm/kvm_host.h | 10 +++++----- arch/powerpc/include/asm/kvm_ppc.h | 2 +- arch/powerpc/kernel/asm-offsets.c | 8 ++++---- arch/powerpc/kernel/idle_power7.S | 2 +- arch/powerpc/kvm/Kconfig | 18 +++++++++++++++++- arch/powerpc/kvm/Makefile | 12 ++++++++---- arch/powerpc/kvm/book3s_exports.c | 5 +++-- 10 files changed, 43 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -2
@@ -199,8 +199,6 @@ static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)return vcpu->arch.book3s; } -extern void kvm_return_point (void ); -/* Also add subarch specific defines */ #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
arch/powerpc/include/asm/kvm_book3s_64.h +3 -3
@@ -35,7 +35,7 @@ static inline void svcpu_put(struct kvmppc_book3s_shadow_vcpu *svcpu)#define SPAPR_TCE_SHIFT 12 -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE #define KVM_DEFAULT_HPT_ORDER 24/* 16MB HPT by default */ extern unsigned long kvm_rma_pages;#endif
@@ -278,7 +278,7 @@ static inline int is_vrma_hpte(unsigned long hpte_v) (HPTE_V_1TB_SEG | (VRMA_VSID << (40 -16 ))); } -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE /* * Note modification of an HPTE; set the HPTE modified bit * if anyone is interested.
@@ -289,6 +289,6 @@ static inline void note_hpte_modification(struct kvm *kvm,if (atomic_read (&kvm->arch.hpte_mod_interest)) rev->guest_rpte |=HPTE_GR_MODIFIED ; } -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #endif /* __ASM_KVM_BOOK3S_64_H__ */
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -1
@@ -83,7 +83,7 @@ struct kvmppc_host_state {u8 restore_hid5;u8 napping; -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE u8 hwthread_req;u8 hwthread_state;u8 host_ipi;
arch/powerpc/include/asm/kvm_host.h +5 -5
@@ -229,15 +229,15 @@ struct revmap_entry {#define KVMPPC_GOT_PAGE 0x80struct kvm_arch_memory_slot { -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE unsigned long *rmap;unsigned long *slot_phys; -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ };struct kvm_arch {unsigned int lpid; -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE unsigned long hpt_virt;struct revmap_entry *revmap;unsigned int host_lpid;
@@ -261,7 +261,7 @@ struct kvm_arch {cpumask_t need_tlb_flush;struct kvmppc_vcore *vcores[KVM_MAX_VCORES ];int hpt_cma_alloc; -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE struct mutex hpt_mutex;#endif
@@ -597,7 +597,7 @@ struct kvm_vcpu_arch {struct kvmppc_icp *icp;/* XICS presentation controller */ #endif -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE struct kvm_vcpu_arch_shared shregs;unsigned long pgfault_addr;
arch/powerpc/include/asm/kvm_ppc.h +1 -1
@@ -260,7 +260,7 @@ void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);struct openpic ; -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE extern void kvm_cma_reserve (void )__init ;static inline void kvmppc_set_xics_phys (int cpu,unsigned long addr) {
arch/powerpc/kernel/asm-offsets.c +4 -4
@@ -442,7 +442,7 @@ int main(void) DEFINE(VCPU_LR, offsetof(struct kvm_vcpu, arch.lr)); DEFINE(VCPU_CR, offsetof(struct kvm_vcpu, arch.cr)); DEFINE(VCPU_PC, offsetof(struct kvm_vcpu, arch.pc)); -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE DEFINE(VCPU_MSR, offsetof(struct kvm_vcpu, arch.shregs.msr)); DEFINE(VCPU_SRR0, offsetof(struct kvm_vcpu, arch.shregs.srr0)); DEFINE(VCPU_SRR1, offsetof(struct kvm_vcpu, arch.shregs.srr1));
@@ -473,7 +473,7 @@ int main(void) DEFINE(KVM_LPID, offsetof(struct kvm, arch.lpid));/* book3s */ -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE DEFINE(KVM_SDR1, offsetof(struct kvm, arch.sdr1)); DEFINE(KVM_HOST_LPID, offsetof(struct kvm, arch.host_lpid)); DEFINE(KVM_HOST_LPCR, offsetof(struct kvm, arch.host_lpcr));
@@ -583,7 +583,7 @@ int main(void)HSTATE_FIELD (HSTATE_RESTORE_HID5 , restore_hid5);HSTATE_FIELD (HSTATE_NAPPING , napping); -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE HSTATE_FIELD (HSTATE_HWTHREAD_REQ , hwthread_req);HSTATE_FIELD (HSTATE_HWTHREAD_STATE , hwthread_state);HSTATE_FIELD (HSTATE_KVM_VCPU , kvm_vcpu);
@@ -599,7 +599,7 @@ int main(void)HSTATE_FIELD (HSTATE_DABR , dabr);HSTATE_FIELD (HSTATE_DECEXP , dec_expires);DEFINE (IPI_PRIORITY ,IPI_PRIORITY ); -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_PPC_BOOK3S_64 HSTATE_FIELD (HSTATE_CFAR , cfar);
arch/powerpc/kernel/idle_power7.S +1 -1
@@ -84,7 +84,7 @@ _GLOBAL(power7_nap) std r9,_MSR(r1) std r1,PACAR1(r13) -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE /* Tell KVM we're napping */ li r4,KVM_HWTHREAD_IN_NAP stb r4,HSTATE_HWTHREAD_STATE(r13)
arch/powerpc/kvm/Kconfig +17 -1
@@ -39,6 +39,9 @@ config KVM_BOOK3S_PR_POSSIBLE select KVM_MMIO select MMU_NOTIFIER +config KVM_BOOK3S_HV_POSSIBLE + bool + config KVM_BOOK3S_32 tristate "KVM support for PowerPC book3s_32 processors" depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT
@@ -59,6 +62,7 @@ config KVM_BOOK3S_64 depends on PPC_BOOK3S_64 select KVM_BOOK3S_64_HANDLER select KVM + select KVM_BOOK3S_PR_POSSIBLE if !KVM_BOOK3S_HV_POSSIBLE ---help--- Support running unmodified book3s_64 and book3s_32 guest kernels in virtual machines on book3s_64 host processors.
@@ -71,6 +75,7 @@ config KVM_BOOK3S_64 config KVM_BOOK3S_64_HV bool "KVM support for POWER7 and PPC970 using hypervisor mode in host" depends on KVM_BOOK3S_64 + select KVM_BOOK3S_HV_POSSIBLE select MMU_NOTIFIER select CMA ---help---
@@ -89,9 +94,20 @@ config KVM_BOOK3S_64_HV If unsure, say N. config KVM_BOOK3S_64_PR - def_bool y + bool "KVM support without using hypervisor mode in host" depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV select KVM_BOOK3S_PR_POSSIBLE + ---help--- + Support running guest kernels in virtual machines on processors + without using hypervisor mode in the host, by running the + guest in user mode (problem state) and emulating all + privileged instructions and registers. + + This is not as fast as using hypervisor mode, but works on + machines where hypervisor mode is not available or not usable, + and can emulate processors that are different from the host + processor, including emulating 32-bit processors on a 64-bit + host. config KVM_BOOKE_HV bool
arch/powerpc/kvm/Makefile +8 -4
@@ -57,7 +57,6 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) := \ book3s_64_vio_hv.o kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ - $(KVM)/coalesced_mmio.o \ fpu.o \ book3s_paired_singles.o \ book3s_pr.o \
@@ -69,10 +68,15 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ book3s_64_mmu.o \ book3s_32_mmu.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_PR) += \ +ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE +kvm-book3s_64-module-objs := \ + $(KVM)/coalesced_mmio.o + +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o +endif -kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) := \ +kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ book3s_hv.o \ book3s_hv_interrupts.o \ book3s_64_mmu_hv.o
@@ -91,7 +95,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \ book3s_xics.o -kvm-book3s_64-module-objs := \ +kvm-book3s_64-module-objs += \ $(KVM)/kvm_main.o \ $(KVM)/eventfd.o \ powerpc.o \
arch/powerpc/kvm/book3s_exports.c +3 -2
@@ -20,9 +20,10 @@#include <linux/export.h> #include <asm/kvm_book3s.h> -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE EXPORT_SYMBOL_GPL (kvmppc_hv_entry_trampoline); -#else +#endif +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE EXPORT_SYMBOL_GPL (kvmppc_entry_trampoline);EXPORT_SYMBOL_GPL (kvmppc_load_up_fpu);#ifdef CONFIG_ALTIVEC
Signature · 1 line
1.8.1.2
PATCH 5/14 kvm: powerpc: book3s: Add kvmppc_ops callback
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This patch add a new callback kvmppc_ops. This will help us in enabling both HV and PR KVM together in the same kernel. The actual change to enable them together is done in the later patch in the series.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 - arch/powerpc/include/asm/kvm_ppc.h | 85 +++++++++---- arch/powerpc/kernel/exceptions-64s.S | 2 +- arch/powerpc/kvm/book3s.c | 145 +++++++++++++++++++++- arch/powerpc/kvm/book3s.h | 32 +++++ arch/powerpc/kvm/book3s_32_mmu_host.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_host.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 17 ++- arch/powerpc/kvm/book3s_emulate.c | 8 +- arch/powerpc/kvm/book3s_hv.c | 220 ++++++++++++++++++++++++---------- arch/powerpc/kvm/book3s_interrupts.S | 2 +- arch/powerpc/kvm/book3s_pr.c | 194 +++++++++++++++++++----------- arch/powerpc/kvm/book3s_xics.c | 4 +- arch/powerpc/kvm/emulate.c | 6 +- arch/powerpc/kvm/powerpc.c | 58 +++------ 15 files changed, 554 insertions(+), 224 deletions(-) create mode 100644 arch/powerpc/kvm/book3s.h
arch/powerpc/include/asm/kvm_book3s.h +0 -1
@@ -124,7 +124,6 @@ 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 void kvmppc_mmu_book3s_hv_init (struct kvm_vcpu *vcpu);
arch/powerpc/include/asm/kvm_ppc.h +64 -21
115 lines not on this page · raw message
arch/powerpc/kernel/exceptions-64s.S +1 -1
@@ -126,7 +126,7 @@ BEGIN_FTR_SECTION bgt cr1,. GET_PACA(r13) -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE li r0,KVM_HWTHREAD_IN_KERNEL stb r0,HSTATE_HWTHREAD_STATE(r13) /* Order setting hwthread_state vs. testing hwthread_req */
arch/powerpc/kvm/book3s.c +141 -4
172 lines not on this page · raw message
arch/powerpc/kvm/book3s.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright IBM Corporation, 2013 +* Author Aneesh Kumar K.V <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of the +* License or (at your optional) any later version of the license. +* +*/ + +#ifndef __POWERPC_KVM_BOOK3S_H__ +#define __POWERPC_KVM_BOOK3S_H__ + +extern void kvmppc_core_flush_memslot_hv (struct kvm *kvm, +struct kvm_memory_slot *memslot); +extern int kvm_unmap_hva_hv (struct kvm *kvm,unsigned long hva); +extern int kvm_unmap_hva_range_hv (struct kvm *kvm,unsigned long start, +unsigned long end); +extern int kvm_age_hva_hv (struct kvm *kvm,unsigned long hva); +extern int kvm_test_age_hva_hv (struct kvm *kvm,unsigned long hva); +extern void kvm_set_spte_hva_hv (struct kvm *kvm,unsigned long hva,pte_t pte); + +extern void kvmppc_mmu_destroy_pr (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_pr (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_pr (struct kvm_vcpu *vcpu, +int sprn,ulong spr_val); +extern int kvmppc_core_emulate_mfspr_pr (struct kvm_vcpu *vcpu, +int sprn,ulong *spr_val); + +#endif
arch/powerpc/kvm/book3s_32_mmu_host.c +1 -1
@@ -349,7 +349,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)svcpu_put (svcpu); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_pr (struct kvm_vcpu *vcpu) {int i;
arch/powerpc/kvm/book3s_64_mmu_host.c +1 -1
@@ -378,7 +378,7 @@ void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)svcpu_put (svcpu); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_pr (struct kvm_vcpu *vcpu) {kvmppc_mmu_hpte_destroy (vcpu);__destroy_context (to_book3s (vcpu)->context_id[0 ]);
arch/powerpc/kvm/book3s_64_mmu_hv.c +7 -10
@@ -260,10 +260,6 @@ int kvmppc_mmu_hv_init(void)return 0 ; } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) -{ -} -static void kvmppc_mmu_book3s_64_hv_reset_msr (struct kvm_vcpu *vcpu) {kvmppc_set_msr (vcpu,MSR_SF |MSR_ME );
@@ -906,21 +902,22 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,return 0 ; } -int kvm_unmap_hva (struct kvm *kvm,unsigned long hva) +int kvm_unmap_hva_hv (struct kvm *kvm,unsigned long hva) {if (kvm->arch.using_mmu_notifiers)kvm_handle_hva (kvm, hva, kvm_unmap_rmapp);return 0 ; } -int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end) +int kvm_unmap_hva_range_hv (struct kvm *kvm,unsigned long start,unsigned long end) {if (kvm->arch.using_mmu_notifiers)kvm_handle_hva_range (kvm, start, end, kvm_unmap_rmapp);return 0 ; } -void kvmppc_core_flush_memslot (struct kvm *kvm,struct kvm_memory_slot *memslot) +void kvmppc_core_flush_memslot_hv (struct kvm *kvm, +struct kvm_memory_slot *memslot) {unsigned long *rmapp;unsigned long gfn;
@@ -994,7 +991,7 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp,return ret; } -int kvm_age_hva (struct kvm *kvm,unsigned long hva) +int kvm_age_hva_hv (struct kvm *kvm,unsigned long hva) {if (!kvm->arch.using_mmu_notifiers)return 0 ;
@@ -1032,14 +1029,14 @@ static int kvm_test_age_rmapp(struct kvm *kvm, unsigned long *rmapp,return ret; } -int kvm_test_age_hva (struct kvm *kvm,unsigned long hva) +int kvm_test_age_hva_hv (struct kvm *kvm,unsigned long hva) {if (!kvm->arch.using_mmu_notifiers)return 0 ;return kvm_handle_hva (kvm, hva, kvm_test_age_rmapp); } -void kvm_set_spte_hva (struct kvm *kvm,unsigned long hva,pte_t pte) +void kvm_set_spte_hva_hv (struct kvm *kvm,unsigned long hva,pte_t pte) {if (!kvm->arch.using_mmu_notifiers)return ;
arch/powerpc/kvm/book3s_emulate.c +4 -4
@@ -86,8 +86,8 @@ static bool spr_allowed(struct kvm_vcpu *vcpu, enum priv_level level)return true; } -int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int inst,int *advance) +int kvmppc_core_emulate_op_pr (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) {int emulated =EMULATE_DONE ;int rt =get_rt (inst);
@@ -345,7 +345,7 @@ static struct kvmppc_bat *kvmppc_find_bat(struct kvm_vcpu *vcpu, int sprn)return bat; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) +int kvmppc_core_emulate_mtspr_pr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {int emulated =EMULATE_DONE ;
@@ -468,7 +468,7 @@ unprivileged:return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) +int kvmppc_core_emulate_mfspr_pr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {int emulated =EMULATE_DONE ;
arch/powerpc/kvm/book3s_hv.c +158 -62
423 lines not on this page · raw message
arch/powerpc/kvm/book3s_interrupts.S +1 -1
@@ -181,7 +181,7 @@ kvm_start_lightweight: /* Restore r3 (kvm_run) and r4 (vcpu) */ REST_2GPRS(3, r1) - bl FUNC(kvmppc_handle_exit) + bl FUNC(kvmppc_handle_exit_pr) /* If RESUME_GUEST, get back in the loop */ cmpwi r3, RESUME_GUEST
arch/powerpc/kvm/book3s_pr.c +125 -69
365 lines not on this page · raw message
arch/powerpc/kvm/book3s_xics.c +2 -2
@@ -1250,13 +1250,13 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type)xics_debugfs_init (xics); -#ifdef CONFIG_KVM_BOOK3S_64_HV +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE if (cpu_has_feature (CPU_FTR_ARCH_206 )) {/* Enable real mode support */ xics->real_mode =ENABLE_REALMODE ; xics->real_mode_dbg =DEBUG_REALMODE ; } -#endif /* CONFIG_KVM_BOOK3S_64_HV */ +#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ return 0 ; }
arch/powerpc/kvm/emulate.c +3 -3
@@ -173,7 +173,7 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_PIR :break ;default : - emulated =kvmppc_core_emulate_mtspr (vcpu, sprn, + emulated = kvmppc_ops->emulate_mtspr (vcpu, sprn, spr_val);if (emulated ==EMULATE_FAIL ) printk(KERN_INFO "mtspr: unknown spr "
@@ -234,7 +234,7 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) spr_val =kvmppc_get_dec (vcpu,get_tb ());break ;default : - emulated =kvmppc_core_emulate_mfspr (vcpu, sprn, + emulated = kvmppc_ops->emulate_mfspr (vcpu, sprn, &spr_val);if (unlikely (emulated ==EMULATE_FAIL )) { printk(KERN_INFO "mfspr: unknown spr "
@@ -507,7 +507,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) }if (emulated ==EMULATE_FAIL ) { - emulated =kvmppc_core_emulate_op (run, vcpu, inst, &advance); + emulated = kvmppc_ops->emulate_op (run, vcpu, inst, &advance);if (emulated ==EMULATE_AGAIN ) { advance =0 ; }else if (emulated ==EMULATE_FAIL ) {
arch/powerpc/kvm/powerpc.c +14 -44
92 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 6/14 kvm: powerpc: booke: Convert BOOKE to use kvmppc_ops callbacks
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
Make required changes to get BOOKE configs to build with the introduction of kvmppc_ops callback
--- arch/powerpc/include/asm/kvm_ppc.h | 4 +-- arch/powerpc/kvm/44x.c | 55 +++++++++++++++++++++++++++----------- arch/powerpc/kvm/44x_emulate.c | 8 +++--- arch/powerpc/kvm/44x_tlb.c | 2 +- arch/powerpc/kvm/booke.c | 47 +++++++++++++++++++++++++++----- arch/powerpc/kvm/booke.h | 24 +++++++++++++++++ arch/powerpc/kvm/e500.c | 53 +++++++++++++++++++++++++----------- arch/powerpc/kvm/e500_emulate.c | 8 +++--- arch/powerpc/kvm/e500_mmu.c | 2 +- arch/powerpc/kvm/e500mc.c | 54 ++++++++++++++++++++++++++----------- 10 files changed, 194 insertions(+), 63 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +2 -2
@@ -285,10 +285,10 @@ static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value) __v; \ }) -void kvmppc_core_get_sregs (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); +int kvmppc_core_get_sregs (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int kvmppc_core_set_sregs (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); -void kvmppc_get_sregs_ivor (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); +int kvmppc_get_sregs_ivor (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int kvmppc_set_sregs_ivor (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int kvm_vcpu_ioctl_get_one_reg (struct kvm_vcpu *vcpu,struct kvm_one_reg *reg);
arch/powerpc/kvm/44x.c +40 -15
113 lines not on this page · raw message
arch/powerpc/kvm/44x_emulate.c +4 -4
@@ -91,8 +91,8 @@ static int emulate_mfdcr(struct kvm_vcpu *vcpu, int rt, int dcrn)return EMULATE_DONE ; } -int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int inst,int *advance) +int kvmppc_core_emulate_op_44x (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) {int emulated =EMULATE_DONE ;int dcrn =get_dcrn (inst);
@@ -152,7 +152,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) +int kvmppc_core_emulate_mtspr_44x (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {int emulated =EMULATE_DONE ;
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) +int kvmppc_core_emulate_mfspr_44x (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {int emulated =EMULATE_DONE ;
arch/powerpc/kvm/44x_tlb.c +1 -1
@@ -268,7 +268,7 @@ static void kvmppc_44x_shadow_release(struct kvmppc_vcpu_44x *vcpu_44x,trace_kvm_stlb_inval (stlb_index); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_44x (struct kvm_vcpu *vcpu) {struct kvmppc_vcpu_44x *vcpu_44x =to_44x (vcpu);int i;
arch/powerpc/kvm/booke.c +41 -6
89 lines not on this page · raw message
arch/powerpc/kvm/booke.h +24 -0
@@ -99,6 +99,30 @@ enum int_class {void kvmppc_set_pending_interrupt (struct kvm_vcpu *vcpu,enum int_class type); +extern void kvmppc_mmu_destroy_44x (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_44x (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_44x (struct kvm_vcpu *vcpu,int sprn, +ulong spr_val); +extern int kvmppc_core_emulate_mfspr_44x (struct kvm_vcpu *vcpu,int sprn, +ulong *spr_val); +extern void kvmppc_mmu_destroy_e500 (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_e500 (struct kvm_run *run, +struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong spr_val); +extern int kvmppc_core_emulate_mfspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong *spr_val); +extern void kvmppc_mmu_destroy_e500 (struct kvm_vcpu *vcpu); +extern int kvmppc_core_emulate_op_e500 (struct kvm_run *run, +struct kvm_vcpu *vcpu, +unsigned int inst,int *advance); +extern int kvmppc_core_emulate_mtspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong spr_val); +extern int kvmppc_core_emulate_mfspr_e500 (struct kvm_vcpu *vcpu,int sprn, +ulong *spr_val); +/* * Load up guest vcpu FP state if it's needed. * It also set the MSR_FP in thread so that host know
arch/powerpc/kvm/e500.c +38 -15
129 lines not on this page · raw message
arch/powerpc/kvm/e500_emulate.c +4 -4
@@ -103,8 +103,8 @@ static int kvmppc_e500_emul_ehpriv(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int inst,int *advance) +int kvmppc_core_emulate_op_e500 (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int inst,int *advance) {int emulated =EMULATE_DONE ;int ra =get_ra (inst);
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } -int kvmppc_core_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) +int kvmppc_core_emulate_mtspr_e500 (struct kvm_vcpu *vcpu,int sprn,ulong spr_val) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);int emulated =EMULATE_DONE ;
@@ -263,7 +263,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)return emulated; } -int kvmppc_core_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) +int kvmppc_core_emulate_mfspr_e500 (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);int emulated =EMULATE_DONE ;
arch/powerpc/kvm/e500_mmu.c +1 -1
@@ -536,7 +536,7 @@ gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int index,return get_tlb_raddr (gtlbe) | (eaddr & pgmask); } -void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) +void kvmppc_mmu_destroy_e500 (struct kvm_vcpu *vcpu) { }
arch/powerpc/kvm/e500mc.c +39 -15
128 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Re: [PATCH -V2 06/14] kvm: powerpc: booke: Convert BOOKE to use kvmppc_ops callbacks
Quoted 6 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
Make required changes to get BOOKE configs to build with the introduction of
kvmppc_opscallbackSigned-off-by Aneesh Kumar K.V <[email protected]>
This can not be a separate commit, as you're breaking bisectability for booke this way.
I've squashed this in with the previous commit.
Alex
Re: [PATCH -V2 06/14] kvm: powerpc: booke: Convert BOOKE to use kvmppc_ops callbacks
Quoted 11 lines · Alexander Graf
Quoted 6 lines · Aneesh Kumar K.V
From: "Aneesh Kumar K.V" <[email protected]>
Make required changes to get BOOKE configs to build with the introduction of
kvmppc_opscallbackSigned-off-by Aneesh Kumar K.V <[email protected]>This can not be a separate commit, as you're breaking bisectability for booke this way.
The only reason I split that into two was to make review easy. But yes when merging to your tree we should fold.
Quoted 2 lines
I've squashed this in with the previous commit.
Ok.
-aneesh
PATCH 7/14 kvm: powerpc: book3s: Cleanup interrupt handling code
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
With this patch if HV is included, interrupts come in to the HV version of the kvmppc_interrupt code, which then jumps to the PR handler, renamed to kvmppc_interrupt_pr, if the guest is a PR guest. This helps in enabling both HV and PR, which we do in later patch
--- arch/powerpc/include/asm/exception-64s.h | 11 +++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 9 +++++++-- arch/powerpc/kvm/book3s_segment.S | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/exception-64s.h +11 -0
@@ -197,6 +197,17 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) cmpwi r10,0; \ bne do_kvm_##n +#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +/* +* If hv is possible, interrupts come into to the hv version +* of the kvmppc_interrupt code, which then jumps to the PR handler, +* kvmppc_interrupt_pr, if the guest is a PR guest. +*/ +#define kvmppc_interrupt kvmppc_interrupt_hv +#else +#define kvmppc_interrupt kvmppc_interrupt_pr +#endif +#define __KVM_HANDLER (area, h, n) \ do_kvm_##n: \ BEGIN_FTR_SECTION_NESTED(947) \
arch/powerpc/kvm/book3s_hv_rmhandlers.S +7 -2
@@ -734,8 +734,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) /* * We come here from the first-level interrupt handlers. */ - .globl kvmppc_interrupt -kvmppc_interrupt: + .globl kvmppc_interrupt_hv +kvmppc_interrupt_hv: /* * Register contents: * R12 = interrupt vector
@@ -749,6 +749,11 @@ kvmppc_interrupt: lbz r9, HSTATE_IN_GUEST(r13) cmpwi r9, KVM_GUEST_MODE_HOST_HV beq kvmppc_bad_host_intr +#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE + cmpwi r9, KVM_GUEST_MODE_GUEST + ld r9, HSTATE_HOST_R2(r13) + beq kvmppc_interrupt_pr +#endif /* We're now back in the host but in guest MMU context */ li r9, KVM_GUEST_MODE_HOST_HV stb r9, HSTATE_IN_GUEST(r13)
arch/powerpc/kvm/book3s_segment.S +2 -2
@@ -161,8 +161,8 @@ kvmppc_handler_trampoline_enter_end: .global kvmppc_handler_trampoline_exit kvmppc_handler_trampoline_exit: -.global kvmppc_interrupt -kvmppc_interrupt: +.global kvmppc_interrupt_pr +kvmppc_interrupt_pr: /* Register usage at this point: *
Signature · 1 line
1.8.1.2
PATCH 8/14 kvm: powerpc: book3s: Add is_hv_enabled to kvmppc_ops
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This help us to identify whether we are running with hypervisor mode KVM enabled. The change is needed so that we can have both HV and PR kvm enabled in the same kernel.
If both HV and PR KVM are included, interrupts come in to the HV version of the kvmppc_interrupt code, which then jumps to the PR handler, renamed to kvmppc_interrupt_pr, if the guest is a PR guest.
Allowing both PR and HV in the same kernel required some changes to kvm_dev_ioctl_check_extension(), since the values returned now can't be selected with #ifdefs as much as previously. We look at is_hv_enabled to return the right value when checking for capabilities.For capabilities that are only provided by HV KVM, we return the HV value only if is_hv_enabled is true. For capabilities provided by PR KVM but not HV, we return the PR value only if is_hv_enabled is false.
NOTE: in later patch we replace is_hv_enabled with a static inline function comparing kvm_ppc_ops
--- arch/powerpc/include/asm/kvm_book3s.h | 53 ---------------------------------- arch/powerpc/include/asm/kvm_ppc.h | 5 ++-- arch/powerpc/kvm/book3s.c | 44 ++++++++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv.c | 1 + arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/kvm/powerpc.c | 54 +++++++++++++++++++---------------- 7 files changed, 79 insertions(+), 81 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -53
@@ -301,59 +301,6 @@ static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)return vcpu->arch.fault_dar; } -#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE - -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 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; -} -#else /* CONFIG_KVM_BOOK3S_PR_POSSIBLE */ - -static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) -{ -return 0 ; -} - -static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu, -unsigned long pending_now,unsigned long old_pending) -{ -} - -static inline bool kvmppc_critical_section (struct kvm_vcpu *vcpu) -{ -return false; -} -#endif -/* 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/include/asm/kvm_ppc.h +3 -2
@@ -180,6 +180,7 @@ union kvmppc_one_reg { };struct kvmppc_ops { +bool is_hv_enabled;int (*get_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int (*set_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
@@ -309,10 +310,10 @@ static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)static inline u32 kvmppc_get_xics_latch (void ) { -u32 xirr =get_paca ()->kvm_hstate.saved_xirr; +u32 xirr; + xirr =get_paca ()->kvm_hstate.saved_xirr;get_paca ()->kvm_hstate.saved_xirr =0 ; -return xirr; }
arch/powerpc/kvm/book3s.c +44 -0
50 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv.c +1 -0
@@ -2159,6 +2159,7 @@ static long kvm_arch_vm_ioctl_hv(struct file *filp, }static struct kvmppc_ops kvmppc_hv_ops = { + .is_hv_enabled = true, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, .get_one_reg = kvmppc_get_one_reg_hv,
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -1523,6 +1523,7 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp, }static struct kvmppc_ops kvmppc_pr_ops = { + .is_hv_enabled = false, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr, .get_one_reg = kvmppc_get_one_reg_pr,
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -818,7 +818,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req) }/* Check for real mode returning too hard */ -if (xics->real_mode) +if (xics->real_mode && kvmppc_ops->is_hv_enabled)return kvmppc_xics_rm_complete (vcpu, req);switch (req) {
arch/powerpc/kvm/powerpc.c +29 -25
119 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 9/14 kvm: powerpc: book3s: pr: move PR related tracepoints to a separate header
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This patch moves PR related tracepoints to a separate header. This enables in converting PR to a kernel module which will be done in later patches
--- arch/powerpc/kvm/book3s_64_mmu_host.c | 2 +- arch/powerpc/kvm/book3s_mmu_hpte.c | 2 +- arch/powerpc/kvm/book3s_pr.c | 4 +- arch/powerpc/kvm/trace.h | 234 +-------------------------- arch/powerpc/kvm/trace_pr.h | 297 ++++++++++++++++++++++++++++++++++ 5 files changed, 309 insertions(+), 230 deletions(-) create mode 100644 arch/powerpc/kvm/trace_pr.h
arch/powerpc/kvm/book3s_64_mmu_host.c +1 -1
@@ -27,7 +27,7 @@#include <asm/machdep.h> #include <asm/mmu_context.h> #include <asm/hw_irq.h> -#include "trace.h" +#include "trace_pr.h" #define PTE_SIZE 12
arch/powerpc/kvm/book3s_mmu_hpte.c +1 -1
@@ -28,7 +28,7 @@#include <asm/mmu_context.h> #include <asm/hw_irq.h> -#include "trace.h" +#include "trace_pr.h" #define PTE_SIZE 12
arch/powerpc/kvm/book3s_pr.c +3 -1
@@ -42,7 +42,9 @@#include <linux/highmem.h> #include "book3s.h" -#include "trace.h" + +#define CREATE_TRACE_POINTS +#include "trace_pr.h" /* #define EXIT_DEBUG */ /* #define DEBUG_EXT */
arch/powerpc/kvm/trace.h +7 -227
276 lines not on this page · raw message
arch/powerpc/kvm/trace_pr.h new file +297 -0
297 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 10/14 kvm: powerpc: booke: Move booke related tracepoints to separate header
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/kvm/booke.c | 4 +- arch/powerpc/kvm/e500_mmu.c | 2 +- arch/powerpc/kvm/e500_mmu_host.c | 3 +- arch/powerpc/kvm/trace.h | 204 --------------------------------------- arch/powerpc/kvm/trace_booke.h | 177 +++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 207 deletions(-) create mode 100644 arch/powerpc/kvm/trace_booke.h
arch/powerpc/kvm/booke.c +3 -1
@@ -40,7 +40,9 @@#include "timing.h" #include "booke.h" -#include "trace.h" + +#define CREATE_TRACE_POINTS +#include "trace_booke.h" unsigned long kvmppc_booke_handlers;
arch/powerpc/kvm/e500_mmu.c +1 -1
@@ -32,7 +32,7 @@#include <asm/kvm_ppc.h> #include "e500.h" -#include "trace.h" +#include "trace_booke.h" #include "timing.h" #include "e500_mmu_host.h"
arch/powerpc/kvm/e500_mmu_host.c +2 -1
@@ -32,10 +32,11 @@#include <asm/kvm_ppc.h> #include "e500.h" -#include "trace.h" #include "timing.h" #include "e500_mmu_host.h" +#include "trace_booke.h" +#define to_htlb1_esel (esel) (host_tlb_params[1].entries - (esel) - 1)static struct kvmppc_e500_tlb_params host_tlb_params[E500_TLB_NUM ];
arch/powerpc/kvm/trace.h +0 -204
216 lines not on this page · raw message
arch/powerpc/kvm/trace_booke.h new file +177 -0
177 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 11/14 kvm: powerpc: book3s: Support building HV and PR KVM as module
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
--- arch/powerpc/kvm/Kconfig | 6 +++--- arch/powerpc/kvm/Makefile | 11 ++++++++--- arch/powerpc/kvm/book3s.c | 12 +++++++++++- arch/powerpc/kvm/book3s_emulate.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 2 ++ arch/powerpc/kvm/book3s_pr.c | 5 ++++- arch/powerpc/kvm/book3s_rtas.c | 1 + arch/powerpc/kvm/emulate.c | 1 + arch/powerpc/kvm/powerpc.c | 10 ++++++++++ virt/kvm/kvm_main.c | 4 ++++ 10 files changed, 45 insertions(+), 9 deletions(-)
arch/powerpc/kvm/Kconfig +3 -3
@@ -73,7 +73,7 @@ config KVM_BOOK3S_64 If unsure, say N. config KVM_BOOK3S_64_HV - bool "KVM support for POWER7 and PPC970 using hypervisor mode in host" + tristate "KVM support for POWER7 and PPC970 using hypervisor mode in host" depends on KVM_BOOK3S_64 select KVM_BOOK3S_HV_POSSIBLE select MMU_NOTIFIER
@@ -94,8 +94,8 @@ config KVM_BOOK3S_64_HV If unsure, say N. config KVM_BOOK3S_64_PR - bool "KVM support without using hypervisor mode in host" - depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV + tristate "KVM support without using hypervisor mode in host" + depends on KVM_BOOK3S_64 select KVM_BOOK3S_PR_POSSIBLE ---help--- Support running guest kernels in virtual machines on processors
arch/powerpc/kvm/Makefile +8 -3
@@ -56,7 +56,7 @@ kvm-objs-$(CONFIG_KVM_E500MC) := $(kvm-e500mc-objs) kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) := \ book3s_64_vio_hv.o -kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ +kvm-pr-y := \ fpu.o \ book3s_paired_singles.o \ book3s_pr.o \
@@ -76,7 +76,7 @@ kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_rmhandlers.o endif -kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ +kvm-hv-y += \ book3s_hv.o \ book3s_hv_interrupts.o \ book3s_64_mmu_hv.o
@@ -84,13 +84,15 @@ kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ kvm-book3s_64-builtin-xics-objs-$(CONFIG_KVM_XICS) := \ book3s_hv_rm_xics.o -kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HV) += \ +ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE +kvm-book3s_64-builtin-objs-$(CONFIG_KVM_BOOK3S_64_HANDLER) += \ book3s_hv_rmhandlers.o \ book3s_hv_rm_mmu.o \ book3s_hv_ras.o \ book3s_hv_builtin.o \ book3s_hv_cma.o \ $(kvm-book3s_64-builtin-xics-objs-y) +endif kvm-book3s_64-objs-$(CONFIG_KVM_XICS) += \ book3s_xics.o
@@ -131,4 +133,7 @@ obj-$(CONFIG_KVM_E500MC) += kvm.o obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o +obj-$(CONFIG_KVM_BOOK3S_64_PR) += kvm-pr.o +obj-$(CONFIG_KVM_BOOK3S_64_HV) += kvm-hv.o + obj-y += $(kvm-book3s_64-builtin-objs-y)
arch/powerpc/kvm/book3s.c +11 -1
@@ -170,28 +170,32 @@ void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)printk (KERN_INFO "Queueing interrupt %x\n" , vec);#endif } - +EXPORT_SYMBOL_GPL (kvmppc_book3s_queue_irqprio);void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) {/* might as well deliver this straight away */ kvmppc_inject_interrupt (vcpu,BOOK3S_INTERRUPT_PROGRAM , flags); } +EXPORT_SYMBOL_GPL (kvmppc_core_queue_program);void kvmppc_core_queue_dec (struct kvm_vcpu *vcpu) {kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_DECREMENTER ); } +EXPORT_SYMBOL_GPL (kvmppc_core_queue_dec);int kvmppc_core_pending_dec (struct kvm_vcpu *vcpu) {return test_bit (BOOK3S_IRQPRIO_DECREMENTER , &vcpu->arch.pending_exceptions); } +EXPORT_SYMBOL_GPL (kvmppc_core_pending_dec);void kvmppc_core_dequeue_dec (struct kvm_vcpu *vcpu) {kvmppc_book3s_dequeue_irqprio (vcpu,BOOK3S_INTERRUPT_DECREMENTER ); } +EXPORT_SYMBOL_GPL (kvmppc_core_dequeue_dec);void kvmppc_core_queue_external (struct kvm_vcpu *vcpu,struct kvm_interrupt *irq)
@@ -329,6 +333,7 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)return 0 ; } +EXPORT_SYMBOL_GPL (kvmppc_core_prepare_to_enter);pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn,bool writing,bool *writable)
@@ -354,6 +359,7 @@ pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing,return gfn_to_pfn_prot (vcpu->kvm, gfn, writing, writable); } +EXPORT_SYMBOL_GPL (kvmppc_gfn_to_pfn);static int kvmppc_xlate (struct kvm_vcpu *vcpu,ulong eaddr,bool data,bool iswrite,struct kvmppc_pte *pte)
@@ -421,6 +427,7 @@ int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,return EMULATE_DONE ; } +EXPORT_SYMBOL_GPL (kvmppc_st);int kvmppc_ld (struct kvm_vcpu *vcpu,ulong *eaddr,int size,void *ptr,bool data)
@@ -451,6 +458,7 @@ nopte: mmio:return EMULATE_DO_MMIO ; } +EXPORT_SYMBOL_GPL (kvmppc_ld);int kvm_arch_vcpu_setup (struct kvm_vcpu *vcpu) {
@@ -706,6 +714,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) { kvmppc_ops->set_msr (vcpu, msr); } +EXPORT_SYMBOL_GPL (kvmppc_set_msr);int kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) {
@@ -787,6 +796,7 @@ int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) {return kvmppc_ops->unmap_hva (kvm, hva); } +EXPORT_SYMBOL_GPL (kvm_unmap_hva);int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end) {
arch/powerpc/kvm/book3s_emulate.c +1 -1
@@ -172,7 +172,7 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, vcpu->arch.mmu.tlbie (vcpu, addr, large);break ; } -#ifdef CONFIG_KVM_BOOK3S_64_PR +#ifdef CONFIG_PPC_BOOK3S_64 case OP_31_XOP_FAKE_SC1 : {/* SC 1 papr hypercalls */
arch/powerpc/kvm/book3s_hv.c +2 -0
@@ -52,6 +52,7 @@#include <linux/vmalloc.h> #include <linux/highmem.h> #include <linux/hugetlb.h> +#include <linux/module.h> #include "book3s.h"
@@ -2215,3 +2216,4 @@ static void kvmppc_book3s_exit_hv(void)module_init (kvmppc_book3s_init_hv);module_exit (kvmppc_book3s_exit_hv); +MODULE_LICENSE ("GPL" );
arch/powerpc/kvm/book3s_pr.c +4 -1
@@ -40,6 +40,7 @@#include <linux/sched.h> #include <linux/vmalloc.h> #include <linux/highmem.h> +#include <linux/module.h> #include "book3s.h"
@@ -918,7 +919,7 @@ program_interrupt:ulong cmd =kvmppc_get_gpr (vcpu,3 );int i; -#ifdef CONFIG_KVM_BOOK3S_64_PR +#ifdef CONFIG_PPC_BOOK3S_64 if (kvmppc_h_pr (vcpu, cmd) ==EMULATE_DONE ) { r =RESUME_GUEST ;break ;
@@ -1582,3 +1583,5 @@ static void kvmppc_book3s_exit_pr(void)module_init (kvmppc_book3s_init_pr);module_exit (kvmppc_book3s_exit_pr); + +MODULE_LICENSE ("GPL" );
arch/powerpc/kvm/book3s_rtas.c +1 -0
@@ -260,6 +260,7 @@ fail:*/ return rc; } +EXPORT_SYMBOL_GPL (kvmppc_rtas_hcall);void kvmppc_rtas_tokens_free (struct kvm *kvm) {
arch/powerpc/kvm/emulate.c +1 -0
@@ -526,3 +526,4 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)return emulated; } +EXPORT_SYMBOL_GPL (kvmppc_emulate_instruction);
arch/powerpc/kvm/powerpc.c +10 -0
@@ -126,6 +126,7 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)return r; } +EXPORT_SYMBOL_GPL (kvmppc_prepare_to_enter);int kvmppc_kvm_pv (struct kvm_vcpu *vcpu) {
@@ -179,6 +180,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)return r; } +EXPORT_SYMBOL_GPL (kvmppc_kvm_pv);int kvmppc_sanity_check (struct kvm_vcpu *vcpu) {
@@ -207,6 +209,7 @@ out: vcpu->arch.sane = r;return r ?0 : -EINVAL ; } +EXPORT_SYMBOL_GPL (kvmppc_sanity_check);int kvmppc_emulate_mmio (struct kvm_run *run,struct kvm_vcpu *vcpu) {
@@ -241,6 +244,7 @@ int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu)return r; } +EXPORT_SYMBOL_GPL (kvmppc_emulate_mmio);int kvm_arch_hardware_enable (void *garbage) {
@@ -665,6 +669,7 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,return EMULATE_DO_MMIO ; } +EXPORT_SYMBOL_GPL (kvmppc_handle_load);/* Same as above, but sign extends */ int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
@@ -726,6 +731,7 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,return EMULATE_DO_MMIO ; } +EXPORT_SYMBOL_GPL (kvmppc_handle_store);int kvm_arch_vcpu_ioctl_run (struct kvm_vcpu *vcpu,struct kvm_run *run) {
@@ -1074,22 +1080,26 @@ long kvmppc_alloc_lpid(void)return lpid; } +EXPORT_SYMBOL_GPL (kvmppc_alloc_lpid);void kvmppc_claim_lpid (long lpid) {set_bit (lpid, lpid_inuse); } +EXPORT_SYMBOL_GPL (kvmppc_claim_lpid);void kvmppc_free_lpid (long lpid) {clear_bit (lpid, lpid_inuse); } +EXPORT_SYMBOL_GPL (kvmppc_free_lpid);void kvmppc_init_lpid (unsigned long nr_lpids_param) { nr_lpids = min_t(unsigned long, KVMPPC_NR_LPIDS, nr_lpids_param);memset (lpid_inuse,0 ,sizeof (lpid_inuse)); } +EXPORT_SYMBOL_GPL (kvmppc_init_lpid);int kvm_arch_init (void *opaque) {
virt/kvm/kvm_main.c +4 -0
@@ -186,6 +186,7 @@ void kvm_flush_remote_tlbs(struct kvm *kvm) ++kvm->stat.remote_tlb_flush;cmpxchg (&kvm->tlbs_dirty, dirty_count,0 ); } +EXPORT_SYMBOL_GPL (kvm_flush_remote_tlbs);void kvm_reload_remote_mmus (struct kvm *kvm) {
@@ -964,6 +965,7 @@ int kvm_get_dirty_log(struct kvm *kvm, out:return r; } +EXPORT_SYMBOL_GPL (kvm_get_dirty_log);bool kvm_largepages_enabled (void ) {
@@ -1648,6 +1650,7 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn) memslot =gfn_to_memslot (kvm, gfn);mark_page_dirty_in_slot (kvm, memslot, gfn); } +EXPORT_SYMBOL_GPL (mark_page_dirty);/* * The vCPU has executed a HLT instruction with in-kernel mode enabled.
@@ -1673,6 +1676,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)finish_wait (&vcpu->wq, &wait); } +EXPORT_SYMBOL_GPL (kvm_vcpu_block);#ifndef CONFIG_S390 /*
Signature · 1 line
1.8.1.2
Re: [PATCH -V2 11/14] kvm: powerpc: book3s: Support building HV and PR KVM as module
The below patch fix a compile issue with KVM_XICS. Please fold
arch/powerpc/kvm/book3s_xics.c +1 -0
@@ -840,6 +840,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req)return rc; } +EXPORT_SYMBOL_GPL (kvmppc_xics_hcall);/* -- Initialisation code etc. -- */
PATCH 12/14 kvm: Add struct kvm arg to memslot APIs
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
We will use that in the later patch to find the kvm ops handler
--- arch/arm/kvm/arm.c | 5 +++-- arch/ia64/kvm/kvm-ia64.c | 5 +++-- arch/mips/kvm/kvm_mips.c | 5 +++-- arch/powerpc/include/asm/kvm_ppc.h | 6 ++++-- arch/powerpc/kvm/book3s.c | 4 ++-- arch/powerpc/kvm/booke.c | 4 ++-- arch/powerpc/kvm/powerpc.c | 9 +++++---- arch/s390/kvm/kvm-s390.c | 5 +++-- arch/x86/kvm/x86.c | 5 +++-- include/linux/kvm_host.h | 5 +++-- virt/kvm/kvm_main.c | 12 ++++++------ 11 files changed, 37 insertions(+), 28 deletions(-)
arch/arm/kvm/arm.c +3 -2
@@ -152,12 +152,13 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/ia64/kvm/kvm-ia64.c +3 -2
@@ -1550,12 +1550,13 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/mips/kvm/kvm_mips.c +3 -2
@@ -198,12 +198,13 @@ kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)return -ENOIOCTLCMD ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/powerpc/include/asm/kvm_ppc.h +4 -2
@@ -134,9 +134,11 @@ extern struct page *kvm_alloc_hpt(unsigned long nr_pages);extern void kvm_release_hpt (struct page *page,unsigned long nr_pages);extern int kvmppc_core_init_vm (struct kvm *kvm);extern void kvmppc_core_destroy_vm (struct kvm *kvm); -extern void kvmppc_core_free_memslot (struct kvm_memory_slot *free, +extern void kvmppc_core_free_memslot (struct kvm *kvm, +struct kvm_memory_slot *free,struct kvm_memory_slot *dont); -extern int kvmppc_core_create_memslot (struct kvm_memory_slot *slot, +extern int kvmppc_core_create_memslot (struct kvm *kvm, +struct kvm_memory_slot *slot,unsigned long npages); extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot,
arch/powerpc/kvm/book3s.c +2 -2
@@ -761,13 +761,13 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)return kvmppc_ops->get_dirty_log (kvm, log); } -void kvmppc_core_free_memslot (struct kvm_memory_slot *free, +void kvmppc_core_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { kvmppc_ops->free_memslot (free, dont); } -int kvmppc_core_create_memslot (struct kvm_memory_slot *slot, +int kvmppc_core_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned long npages) {return kvmppc_ops->create_memslot (slot, npages);
arch/powerpc/kvm/booke.c +2 -2
@@ -1662,12 +1662,12 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)return -ENOTSUPP ; } -void kvmppc_core_free_memslot (struct kvm_memory_slot *free, +void kvmppc_core_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvmppc_core_create_memslot (struct kvm_memory_slot *slot, +int kvmppc_core_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned long npages) {return 0 ;
arch/powerpc/kvm/powerpc.c +5 -4
@@ -417,15 +417,16 @@ long kvm_arch_dev_ioctl(struct file *filp,return -EINVAL ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { -kvmppc_core_free_memslot (free, dont); +kvmppc_core_free_memslot (kvm, free, dont); } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) { -return kvmppc_core_create_memslot (slot, npages); +return kvmppc_core_create_memslot (kvm, slot, npages); }void kvm_arch_memslots_updated (struct kvm *kvm)
arch/s390/kvm/kvm-s390.c +3 -2
@@ -1053,12 +1053,13 @@ int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)return VM_FAULT_SIGBUS ; } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) { } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {return 0 ; }
arch/x86/kvm/x86.c +3 -2
@@ -7065,7 +7065,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kfree (rcu_dereference_check (kvm->arch.apic_map,1 )); } -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) {int i;
@@ -7086,7 +7086,8 @@ void kvm_arch_free_memslot(struct kvm_memory_slot *free, } } -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages) +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages) {int i;
include/linux/kvm_host.h +3 -2
@@ -508,9 +508,10 @@ int kvm_set_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem);int __kvm_set_memory_region (struct kvm *kvm,struct kvm_userspace_memory_region *mem); -void kvm_arch_free_memslot (struct kvm_memory_slot *free, +void kvm_arch_free_memslot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont); -int kvm_arch_create_memslot (struct kvm_memory_slot *slot,unsigned long npages); +int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot, +unsigned long npages);void kvm_arch_memslots_updated (struct kvm *kvm); int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot,
virt/kvm/kvm_main.c +6 -6
@@ -541,13 +541,13 @@ static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot)/* * Free any memory in @free but not in @dont. */ -static void kvm_free_physmem_slot (struct kvm_memory_slot *free, +static void kvm_free_physmem_slot (struct kvm *kvm,struct kvm_memory_slot *free,struct kvm_memory_slot *dont) {if (!dont || free->dirty_bitmap != dont->dirty_bitmap)kvm_destroy_dirty_bitmap (free); -kvm_arch_free_memslot (free, dont); +kvm_arch_free_memslot (kvm, free, dont); free->npages =0 ; }
@@ -558,7 +558,7 @@ void kvm_free_physmem(struct kvm *kvm)struct kvm_memory_slot *memslot;kvm_for_each_memslot (memslot, slots) -kvm_free_physmem_slot (memslot,NULL ); +kvm_free_physmem_slot (kvm, memslot,NULL );kfree (kvm->memslots); }
@@ -822,7 +822,7 @@ int __kvm_set_memory_region(struct kvm *kvm,if (change ==KVM_MR_CREATE ) { new.userspace_addr = mem->userspace_addr; -if (kvm_arch_create_memslot (&new, npages)) +if (kvm_arch_create_memslot (kvm, &new, npages)) goto out_free; }
@@ -898,7 +898,7 @@ int __kvm_set_memory_region(struct kvm *kvm,kvm_arch_commit_memory_region (kvm, mem, &old, change); -kvm_free_physmem_slot (&old, &new); +kvm_free_physmem_slot (kvm, &old, &new);kfree (old_memslots);return 0 ;
@@ -906,7 +906,7 @@ int __kvm_set_memory_region(struct kvm *kvm, out_slots:kfree (slots); out_free: -kvm_free_physmem_slot (&new, &old); +kvm_free_physmem_slot (kvm, &new, &old); out:return r; }
Signature · 1 line
1.8.1.2
PATCH 13/14 kvm: powerpc: book3s: Allow the HV and PR selection per virtual machine
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
This moves the kvmppc_ops callbacks to be a per VM entity. This enables us to select HV and PR mode when creating a VM. We also allow both kvm-hv and kvm-pr kernel module to be loaded. To achieve this we move /dev/kvm ownership to kvm.ko module. Depending on which KVM mode we select during VM creation we take a reference count on respective module
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/kvm_ppc.h | 7 +-- arch/powerpc/kvm/44x.c | 7 ++- arch/powerpc/kvm/book3s.c | 89 +++++++++++++++++++++++++------------ arch/powerpc/kvm/book3s.h | 2 + arch/powerpc/kvm/book3s_hv.c | 18 ++++---- arch/powerpc/kvm/book3s_pr.c | 25 +++++++---- arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/kvm/booke.c | 22 ++++----- arch/powerpc/kvm/e500.c | 8 +++- arch/powerpc/kvm/e500mc.c | 6 ++- arch/powerpc/kvm/emulate.c | 11 ++--- arch/powerpc/kvm/powerpc.c | 76 ++++++++++++++++++++++--------- include/uapi/linux/kvm.h | 4 ++ 14 files changed, 187 insertions(+), 91 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -275,6 +275,7 @@ struct kvm_arch {#ifdef CONFIG_KVM_XICS struct kvmppc_xics *xics;#endif +struct kvmppc_ops *kvm_ops; };/*
arch/powerpc/include/asm/kvm_ppc.h +4 -3
@@ -182,6 +182,7 @@ union kvmppc_one_reg { };struct kvmppc_ops { +struct module *owner;bool is_hv_enabled;int (*get_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int (*set_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);
@@ -217,7 +218,6 @@ struct kvmppc_ops { unsigned long npages);int (*init_vm)(struct kvm *kvm);void (*destroy_vm)(struct kvm *kvm); -int (*check_processor_compat)(void );int (*get_smmu_info)(struct kvm *kvm,struct kvm_ppc_smmu_info *info);int (*emulate_op)(struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int inst,int *advance);
@@ -229,7 +229,8 @@ struct kvmppc_ops { }; -extern struct kvmppc_ops *kvmppc_ops; +extern struct kvmppc_ops *kvmppc_hv_ops; +extern struct kvmppc_ops *kvmppc_pr_ops;/* * Cuts out inst bits with ordering according to spec.
@@ -326,7 +327,7 @@ static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)static inline void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu) { - kvmppc_ops->fast_vcpu_kick (vcpu); + vcpu->kvm->arch.kvm_ops->fast_vcpu_kick (vcpu); }#else
arch/powerpc/kvm/44x.c +5 -2
@@ -213,16 +213,19 @@ static int __init kvmppc_44x_init(void)if (r) goto err_out; - r =kvm_init (&kvm_ops_44x,sizeof (struct kvmppc_vcpu_44x ), -0 ,THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_44x ),0 ,THIS_MODULE );if (r) goto err_out; + kvm_ops_44x.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_44x; + err_out:return r; } static void __exit kvmppc_44x_exit(void) { + kvmppc_pr_ops =NULL ;kvmppc_booke_exit (); }
arch/powerpc/kvm/book3s.c +60 -29
238 lines not on this page · raw message
arch/powerpc/kvm/book3s.h +2 -0
@@ -28,5 +28,7 @@ extern int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);extern int kvmppc_core_emulate_mfspr_pr (struct kvm_vcpu *vcpu,int sprn,ulong *spr_val); +extern int kvmppc_book3s_init_pr (void ); +extern void kvmppc_book3s_exit_pr (void );#endif
arch/powerpc/kvm/book3s_hv.c +10 -8
@@ -2159,7 +2159,7 @@ static long kvm_arch_vm_ioctl_hv(struct file *filp,return r; } -static struct kvmppc_ops kvmppc_hv_ops = { +static struct kvmppc_ops kvm_ops_hv = { .is_hv_enabled = true, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,
@@ -2186,7 +2186,6 @@ static struct kvmppc_ops kvmppc_hv_ops = { .create_memslot = kvmppc_core_create_memslot_hv, .init_vm = kvmppc_core_init_vm_hv, .destroy_vm = kvmppc_core_destroy_vm_hv, - .check_processor_compat = kvmppc_core_check_processor_compat_hv, .get_smmu_info = kvm_vm_ioctl_get_smmu_info_hv, .emulate_op = kvmppc_core_emulate_op_hv, .emulate_mtspr = kvmppc_core_emulate_mtspr_hv,
@@ -2198,20 +2197,23 @@ static struct kvmppc_ops kvmppc_hv_ops = {static int kvmppc_book3s_init_hv (void ) {int r; - - r =kvm_init (&kvmppc_hv_ops,sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); - -if (r) +/* +* FIXME!! Do we need to check on all cpus ? +*/ + r =kvmppc_core_check_processor_compat_hv (); +if (r <0 )return r; - r =kvmppc_mmu_hv_init (); + kvm_ops_hv.owner =THIS_MODULE ; + kvmppc_hv_ops = &kvm_ops_hv; + r =kvmppc_mmu_hv_init ();return r; }static void kvmppc_book3s_exit_hv (void ) { -kvm_exit (); + kvmppc_hv_ops =NULL ; }module_init (kvmppc_book3s_init_hv);
arch/powerpc/kvm/book3s_pr.c +16 -9
@@ -1525,7 +1525,7 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp,return -ENOTTY ; } -static struct kvmppc_ops kvmppc_pr_ops = { +static struct kvmppc_ops kvm_ops_pr = { .is_hv_enabled = false, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr,
@@ -1552,7 +1552,6 @@ static struct kvmppc_ops kvmppc_pr_ops = { .create_memslot = kvmppc_core_create_memslot_pr, .init_vm = kvmppc_core_init_vm_pr, .destroy_vm = kvmppc_core_destroy_vm_pr, - .check_processor_compat = kvmppc_core_check_processor_compat_pr, .get_smmu_info = kvm_vm_ioctl_get_smmu_info_pr, .emulate_op = kvmppc_core_emulate_op_pr, .emulate_mtspr = kvmppc_core_emulate_mtspr_pr,
@@ -1561,27 +1560,35 @@ static struct kvmppc_ops kvmppc_pr_ops = { .arch_vm_ioctl = kvm_arch_vm_ioctl_pr, }; -static int kvmppc_book3s_init_pr (void ) + +int kvmppc_book3s_init_pr (void ) {int r; - r =kvm_init (&kvmppc_pr_ops,sizeof (struct kvm_vcpu ),0 ,THIS_MODULE ); - -if (r) + r =kvmppc_core_check_processor_compat_pr (); +if (r <0 )return r; - r =kvmppc_mmu_hpte_sysinit (); + kvm_ops_pr.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_pr; + r =kvmppc_mmu_hpte_sysinit ();return r; } -static void kvmppc_book3s_exit_pr (void ) +void kvmppc_book3s_exit_pr (void ) { + kvmppc_pr_ops =NULL ;kvmppc_mmu_hpte_sysexit (); -kvm_exit (); } +/* +* We only support separate modules for book3s 64 +*/ +#ifdef CONFIG_PPC_BOOK3S_64 +module_init (kvmppc_book3s_init_pr);module_exit (kvmppc_book3s_exit_pr);MODULE_LICENSE ("GPL" ); +#endif
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -818,7 +818,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req) }/* Check for real mode returning too hard */ -if (xics->real_mode && kvmppc_ops->is_hv_enabled) +if (xics->real_mode && vcpu->kvm->arch.kvm_ops->is_hv_enabled)return kvmppc_xics_rm_complete (vcpu, req);switch (req) {
arch/powerpc/kvm/booke.c +11 -11
@@ -1472,7 +1472,7 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,get_sregs_base (vcpu, sregs);get_sregs_arch206 (vcpu, sregs); -return kvmppc_ops->get_sregs (vcpu, sregs); +return vcpu->kvm->arch.kvm_ops->get_sregs (vcpu, sregs); } int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
@@ -1491,7 +1491,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,if (ret <0 )return ret; -return kvmppc_ops->set_sregs (vcpu, sregs); +return vcpu->kvm->arch.kvm_ops->set_sregs (vcpu, sregs); }int kvm_vcpu_ioctl_get_one_reg (struct kvm_vcpu *vcpu,struct kvm_one_reg *reg)
@@ -1548,7 +1548,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) val =get_reg_val (reg->id, vcpu->arch.vrsave);break ;default : - r = kvmppc_ops->get_one_reg (vcpu, reg->id, &val); + r = vcpu->kvm->arch.kvm_ops->get_one_reg (vcpu, reg->id, &val);break ; }
@@ -1631,7 +1631,7 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) vcpu->arch.vrsave =set_reg_val (reg->id, val);break ;default : - r = kvmppc_ops->set_one_reg (vcpu, reg->id, &val); + r = vcpu->kvm->arch.kvm_ops->set_one_reg (vcpu, reg->id, &val);break ; }
@@ -1911,37 +1911,37 @@ void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu)void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu) { - kvmppc_ops->mmu_destroy (vcpu); + vcpu->kvm->arch.kvm_ops->mmu_destroy (vcpu); }int kvmppc_core_init_vm (struct kvm *kvm) { -return kvmppc_ops->init_vm (kvm); +return kvm->arch.kvm_ops->init_vm (kvm); }struct kvm_vcpu *kvmppc_core_vcpu_create (struct kvm *kvm,unsigned int id) { -return kvmppc_ops->vcpu_create (kvm, id); +return kvm->arch.kvm_ops->vcpu_create (kvm, id); }void kvmppc_core_vcpu_free (struct kvm_vcpu *vcpu) { - kvmppc_ops->vcpu_free (vcpu); + vcpu->kvm->arch.kvm_ops->vcpu_free (vcpu); }void kvmppc_core_destroy_vm (struct kvm *kvm) { - kvmppc_ops->destroy_vm (kvm); + kvm->arch.kvm_ops->destroy_vm (kvm); }void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { - kvmppc_ops->vcpu_load (vcpu, cpu); + vcpu->kvm->arch.kvm_ops->vcpu_load (vcpu, cpu); }void kvmppc_core_vcpu_put (struct kvm_vcpu *vcpu) { - kvmppc_ops->vcpu_put (vcpu); + vcpu->kvm->arch.kvm_ops->vcpu_put (vcpu); }int __init kvmppc_booke_init (void )
arch/powerpc/kvm/e500.c +7 -1
@@ -555,13 +555,19 @@ static int __init kvmppc_e500_init(void)flush_icache_range (kvmppc_booke_handlers, kvmppc_booke_handlers + ivor[max_ivor] + handler_len); - r =kvm_init (&kvm_ops_e500,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE ); +if (r) + goto err_out; + kvm_ops_e500.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_e500; + err_out:return r; } static void __exit kvmppc_e500_exit(void) { + kvmppc_pr_ops =NULL ;kvmppc_booke_exit (); }
arch/powerpc/kvm/e500mc.c +5 -1
@@ -373,15 +373,19 @@ static int __init kvmppc_e500mc_init(void)kvmppc_init_lpid (64 );kvmppc_claim_lpid (0 );/* host */ - r =kvm_init (&kvm_ops_e500mc,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE ); + r =kvm_init (NULL ,sizeof (struct kvmppc_vcpu_e500 ),0 ,THIS_MODULE );if (r) goto err_out; + kvm_ops_e500mc.owner =THIS_MODULE ; + kvmppc_pr_ops = &kvm_ops_e500mc; + err_out:return r; } static void __exit kvmppc_e500mc_exit(void) { + kvmppc_pr_ops =NULL ;kvmppc_booke_exit (); }
arch/powerpc/kvm/emulate.c +6 -5
@@ -173,8 +173,8 @@ static int kvmppc_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_PIR :break ;default : - emulated = kvmppc_ops->emulate_mtspr (vcpu, sprn, - spr_val); + emulated = vcpu->kvm->arch.kvm_ops->emulate_mtspr (vcpu, sprn, + spr_val);if (emulated ==EMULATE_FAIL )printk (KERN_INFO "mtspr: unknown spr " "0x%x\n" , sprn);
@@ -234,8 +234,8 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) spr_val =kvmppc_get_dec (vcpu,get_tb ());break ;default : - emulated = kvmppc_ops->emulate_mfspr (vcpu, sprn, - &spr_val); + emulated = vcpu->kvm->arch.kvm_ops->emulate_mfspr (vcpu, sprn, + &spr_val);if (unlikely (emulated ==EMULATE_FAIL )) {printk (KERN_INFO "mfspr: unknown spr " "0x%x\n" , sprn);
@@ -507,7 +507,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) }if (emulated ==EMULATE_FAIL ) { - emulated = kvmppc_ops->emulate_op (run, vcpu, inst, &advance); + emulated = vcpu->kvm->arch.kvm_ops->emulate_op (run, vcpu, inst, + &advance);if (emulated ==EMULATE_AGAIN ) { advance =0 ; }else if (emulated ==EMULATE_FAIL ) {
arch/powerpc/kvm/powerpc.c +55 -21
171 lines not on this page · raw message
include/uapi/linux/kvm.h +4 -0
@@ -518,6 +518,10 @@ struct kvm_ppc_smmu_info {/* machine type bits, to be used as argument to KVM_CREATE_VM */ #define KVM_VM_S390_UCONTROL 1 +/* on ppc, 0 indicate default, 1 should force HV and 2 PR */ +#define KVM_VM_PPC_HV 1 +#define KVM_VM_PPC_PR 2 +#define KVM_S390_SIE_PAGE_OFFSET 1/*
Signature · 1 line
1.8.1.2
PATCH 14/14 kvm: powerpc: book3s: drop is_hv_enabled
In reply to Aneesh Kumar K.VFrom: "Aneesh Kumar K.V" <[email protected]>
drop is_hv_enabled, because that should not be a callback property
--- arch/powerpc/include/asm/kvm_ppc.h | 6 +++++- arch/powerpc/kvm/book3s.c | 6 +++--- arch/powerpc/kvm/book3s_hv.c | 1 - arch/powerpc/kvm/book3s_pr.c | 1 - arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/kvm/powerpc.c | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +5 -1
@@ -183,7 +183,6 @@ union kvmppc_one_reg {struct kvmppc_ops {struct module *owner; -bool is_hv_enabled;int (*get_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);int (*set_sregs)(struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
@@ -232,6 +231,11 @@ struct kvmppc_ops {extern struct kvmppc_ops *kvmppc_hv_ops;extern struct kvmppc_ops *kvmppc_pr_ops; +static inline bool is_kvmppc_hv_enabled (struct kvm *kvm) +{ +return kvm->arch.kvm_ops == kvmppc_hv_ops; +} +/* * 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.c +3 -3
@@ -72,7 +72,7 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)static inline unsigned long kvmppc_interrupt_offset (struct kvm_vcpu *vcpu) { -if (!vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (!is_kvmppc_hv_enabled (vcpu->kvm))return to_book3s (vcpu)->hior;return 0 ; }
@@ -80,7 +80,7 @@ static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu)static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu,unsigned long pending_now,unsigned long old_pending) { -if (vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (is_kvmppc_hv_enabled (vcpu->kvm))return ;if (pending_now) vcpu->arch.shared->int_pending =1 ;
@@ -94,7 +94,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)ulong crit_r1;bool crit; -if (vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (is_kvmppc_hv_enabled (vcpu->kvm))return false; crit_raw = vcpu->arch.shared->critical;
arch/powerpc/kvm/book3s_hv.c +0 -1
@@ -2160,7 +2160,6 @@ static long kvm_arch_vm_ioctl_hv(struct file *filp, }static struct kvmppc_ops kvm_ops_hv = { - .is_hv_enabled = true, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv, .get_one_reg = kvmppc_get_one_reg_hv,
arch/powerpc/kvm/book3s_pr.c +0 -1
@@ -1526,7 +1526,6 @@ static long kvm_arch_vm_ioctl_pr(struct file *filp, }static struct kvmppc_ops kvm_ops_pr = { - .is_hv_enabled = false, .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_pr, .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_pr, .get_one_reg = kvmppc_get_one_reg_pr,
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -818,7 +818,7 @@ int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 req) }/* Check for real mode returning too hard */ -if (xics->real_mode && vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (xics->real_mode &&is_kvmppc_hv_enabled (vcpu->kvm))return kvmppc_xics_rm_complete (vcpu, req);switch (req) {
arch/powerpc/kvm/powerpc.c +1 -1
@@ -200,7 +200,7 @@ int kvmppc_sanity_check(struct kvm_vcpu *vcpu) goto out;/* HV KVM can only do PAPR mode for now */ -if (!vcpu->arch.papr_enabled && vcpu->kvm->arch.kvm_ops->is_hv_enabled) +if (!vcpu->arch.papr_enabled &&is_kvmppc_hv_enabled (vcpu->kvm)) goto out;#ifdef CONFIG_KVM_BOOKE_HV
Signature · 1 line
1.8.1.2
Hi Alex,
Any update on this ?
-aneesh
Quoted 40 lines · Aneesh Kumar K.V
Hi All,
This patch series support enabling HV and PR KVM together in the same kernel. We extend machine property with new property "
kvm_type". A value of "HV" will force HV KVM and "PR" PR KVM. If we don't specifykvm_typewe will select the fastest KVM mode. ie, HV if that is supported otherwise PR.With Qemu command line having
-machine pseries,accel=kvm,kvm_type=HV
[root@llmp24l02 qemu]# bash ../qemu
failed to initialize KVM: Invalid argument
[root@llmp24l02 qemu]# modprobe kvm-pr
[root@llmp24l02 qemu]# bash ../qemu
failed to initialize KVM: Invalid argument
[root@llmp24l02 qemu]# modprobe kvm-hv
[root@llmp24l02 qemu]# bash ../qemunow with
-machine pseries,accel=kvm,kvm_type=PR
[root@llmp24l02 qemu]# rmmod kvm-pr
[root@llmp24l02 qemu]# bash ../qemu
failed to initialize KVM: Invalid argument
[root@llmp24l02 qemu]#
[root@llmp24l02 qemu]# modprobe kvm-pr
[root@llmp24l02 qemu]# bash ../qemuChanges from V1:
* Build fixes for BOOKE (only compile tested)
* Address review feedback-aneesh
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Alexander Graf
AppliedQuoted 6 lines · Aneesh Kumar K.V
Hi All,
This patch series support enabling HV and PR KVM together in the same kernel. We extend machine property with new property "
kvm_type". A value of "HV" will force HV KVM and "PR" PR KVM. If we don't specifykvm_typewe will select the fastest KVM mode. ie, HV if that is supported otherwise PR.
Thanks, applied all to kvm-ppc-queue.
Alex