ppc patch queue 2012-03-15
Subsystems (3)
Hi Avi,
This is my current patch queue for ppc. Please pull.
Alex
The following changes since commit eb9ede961ffe8040e499f3bade88f38395610543:
Marcelo Tosatti (1):
KVM: fix kvm_vcpu_kick build failure on S390
are available in the git repository at:
git://github.com/agraf/linux-2.6.git for-upstream
Alexander Graf (31):
KVM: PPC: Book3s_32: Fix compile error
KVM: PPC: e500mc: Add doorbell emulation support
KVM: PPC: e500mc: implicitly set MSR_GS
KVM: PPC: e500mc: Move r1/r2 restoration very early
KVM: PPC: e500mc: add load inst fixup
KVM: PPC: rename CONFIG_KVM_E500 -> CONFIG_KVM_E500V2
KVM: PPC: make e500v2 kvm and e500mc cpu mutually exclusive
KVM: PPC: booke: remove leftover debugging
KVM: PPC: booke: deliver program int on emulation failure
KVM: PPC: booke: rework rescheduling checks
KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1
KVM: PPC: bookehv: fix exit timing
KVM: PPC: bookehv: remove negation for CONFIG_64BIT
KVM: PPC: bookehv: remove SET_VCPU
KVM: PPC: bookehv: disable MAS register updates early
KVM: PPC: bookehv: add comment about shadow_msr
KVM: PPC: booke: Readd debug abort code for machine check
KVM: PPC: booke: add GS documentation for program interrupt
KVM: PPC: bookehv: remove unused code
KVM: PPC: e500: fix typo in tlb code
KVM: PPC: booke: Support perfmon interrupts
KVM: PPC: booke: expose good state on irq reinject
KVM: PPC: booke: Reinject performance monitor interrupts
KVM: PPC: Booke: only prepare to enter when we enter
KVM: PPC: Save/Restore CR over vcpu_run
KVM: PPC: Pass EA to updating emulation ops
KVM: PPC: Book3S: Compile fix for ppc32 in HIOR
KVM: PPC: Emulate tw and td instructions
KVM: PPC: Book3s: PR: Add HV traps so we can run in HV=1 mode on p7
KVM: PPC: Book3S: PR: Fix preemption
KVM: PPC: Ignore unhalt request from kvm_vcpu_block
Benjamin Herrenschmidt (1):
powerpc/kvm: Fix magic page vs. 32-bit RTAS on ppc64
Bharat Bhushan (1):
Restore guest CR after exit timing calculation
Matt Evans (1):
KVM: PPC: Book3s: PR: Add SPAPR H_BULK_REMOVE support
Paul Mackerras (7):
KVM: PPC: Book3S HV: Fix kvm_alloc_linear in case where no linears exist
KVM: PPC: Book3S HV: Save and restore CR in __kvmppc_vcore_entry
KVM: PPC: Book3S HV: Make secondary threads more robust against stray IPIs
KVM: PPC: Book3S HV: Make virtual processor area registration more robust
KVM: PPC: Book3S HV: Report stolen time to guest through dispatch trace log
KVM: PPC: Book 3S: Fix compilation for !HV configs
KVM: PPC: Work around POWER7 DABR corruption problem
Scott Wood (15):
powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE
KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv
KVM: PPC: booke: add booke-level vcpu load/put
KVM: PPC: booke: Move vm core init/destroy out of booke.c
KVM: PPC: e500: rename e500_tlb.h to e500.h
KVM: PPC: e500: merge <asm/kvm_e500.h> into arch/powerpc/kvm/e500.h
KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h
KVM: PPC: e500: refactor core-specific TLB code
KVM: PPC: e500: Track TLB1 entries with a bitmap
KVM: PPC: e500: emulate tlbilx
powerpc/booke: Provide exception macros with interrupt name
KVM: PPC: booke: category E.HV (GS-mode) support
KVM: PPC: booke: standard PPC floating point support
KVM: PPC: e500mc support
arch/powerpc/include/asm/cputable.h | 21 +- arch/powerpc/include/asm/dbell.h | 3 + arch/powerpc/include/asm/hvcall.h | 10 + arch/powerpc/include/asm/hw_irq.h | 1 + arch/powerpc/include/asm/kvm.h | 1 + arch/powerpc/include/asm/kvm_asm.h | 8 + arch/powerpc/include/asm/kvm_book3s.h | 3 + arch/powerpc/include/asm/kvm_book3s_asm.h | 8 + arch/powerpc/include/asm/kvm_booke.h | 3 + arch/powerpc/include/asm/kvm_booke_hv_asm.h | 49 +++ arch/powerpc/include/asm/kvm_e500.h | 96 ----- arch/powerpc/include/asm/kvm_host.h | 54 ++- arch/powerpc/include/asm/kvm_ppc.h | 10 +- arch/powerpc/include/asm/mmu-book3e.h | 6 + arch/powerpc/include/asm/processor.h | 3 + arch/powerpc/include/asm/reg.h | 2 + arch/powerpc/include/asm/reg_booke.h | 34 ++ arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kernel/asm-offsets.c | 19 +- arch/powerpc/kernel/cpu_setup_fsl_booke.S | 1 + arch/powerpc/kernel/exceptions-64s.S | 12 +- arch/powerpc/kernel/head_44x.S | 23 +- arch/powerpc/kernel/head_booke.h | 69 ++- arch/powerpc/kernel/head_fsl_booke.S | 98 ++++- arch/powerpc/kernel/idle_power7.S | 7 + arch/powerpc/kvm/44x.c | 12 + arch/powerpc/kvm/Kconfig | 28 +- arch/powerpc/kvm/Makefile | 15 +- arch/powerpc/kvm/book3s.c | 7 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 31 +- arch/powerpc/kvm/book3s_hv.c | 322 +++++++++++---- arch/powerpc/kvm/book3s_hv_builtin.c | 9 +- arch/powerpc/kvm/book3s_hv_interrupts.S | 17 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 185 +++++---- arch/powerpc/kvm/book3s_interrupts.S | 7 + arch/powerpc/kvm/book3s_pr.c | 33 ++- arch/powerpc/kvm/book3s_pr_papr.c | 83 ++++- arch/powerpc/kvm/booke.c | 471 +++++++++++++++++---- arch/powerpc/kvm/booke.h | 57 +++- arch/powerpc/kvm/booke_emulate.c | 23 +- arch/powerpc/kvm/booke_interrupts.S | 7 +- arch/powerpc/kvm/bookehv_interrupts.S | 613 +++++++++++++++++++++++++++ arch/powerpc/kvm/e500.c | 372 ++++++++++++++--- arch/powerpc/kvm/e500.h | 302 +++++++++++++ arch/powerpc/kvm/e500_emulate.c | 110 +++++- arch/powerpc/kvm/e500_tlb.c | 588 +++++++++++--------------- arch/powerpc/kvm/e500_tlb.h | 174 -------- arch/powerpc/kvm/e500mc.c | 342 +++++++++++++++ arch/powerpc/kvm/emulate.c | 53 ++-- arch/powerpc/kvm/powerpc.c | 47 ++- arch/powerpc/kvm/timing.h | 6 + 51 files changed, 3397 insertions(+), 1059 deletions(-) create mode 100644 arch/powerpc/include/asm/kvm_booke_hv_asm.h delete mode 100644 arch/powerpc/include/asm/kvm_e500.h create mode 100644 arch/powerpc/kvm/bookehv_interrupts.S create mode 100644 arch/powerpc/kvm/e500.h delete mode 100644 arch/powerpc/kvm/e500_tlb.h create mode 100644 arch/powerpc/kvm/e500mc.c
PATCH 1/56 KVM: PPC: Book3s_32: Fix compile error
We were failing to compile on book3s_32 with the following errors:
arch/powerpc/kvm/book3s_pr.c:883:45: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast] arch/powerpc/kvm/book3s_pr.c:898:79: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
Fix this by explicity casting the u64 to long before we use it as a pointer.
--- arch/powerpc/kvm/book3s_pr.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_pr.c +4 -2
@@ -880,7 +880,8 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)switch (reg->id) {case KVM_REG_PPC_HIOR : - r =put_user (to_book3s (vcpu)->hior, (u64 __user *)reg->addr); + r =put_user (to_book3s (vcpu)->hior, + (u64 __user *)(long )reg->addr);break ;default :break ;
@@ -895,7 +896,8 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)switch (reg->id) {case KVM_REG_PPC_HIOR : - r =get_user (to_book3s (vcpu)->hior, (u64 __user *)reg->addr); + r =get_user (to_book3s (vcpu)->hior, + (u64 __user *)(long )reg->addr);if (!r)to_book3s (vcpu)->hior_explicit = true;break ;
Signature · 1 line
1.6.0.2
PATCH 2/56 powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Currently 32-bit only cares about this for choice of exception vector, which is done in core-specific code. However, KVM will want to distinguish as well.
--- arch/powerpc/include/asm/cputable.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/cputable.h +3 -2
@@ -376,7 +376,8 @@ extern const char *powerpc_base_platform;#define CPU_FTRS_47X (CPU_FTRS_440x6)#define CPU_FTRS_E200 (CPU_FTR_USE_TB | CPU_FTR_SPE_COMP | \ CPU_FTR_NODSISRALIGN | CPU_FTR_COHERENT_ICACHE | \ - CPU_FTR_UNIFIED_ID_CACHE | CPU_FTR_NOEXECUTE) + CPU_FTR_UNIFIED_ID_CACHE | CPU_FTR_NOEXECUTE | \ + CPU_FTR_DEBUG_LVL_EXC)#define CPU_FTRS_E500 (CPU_FTR_MAYBE_CAN_DOZE | CPU_FTR_USE_TB | \ CPU_FTR_SPE_COMP | CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_NODSISRALIGN | \ CPU_FTR_NOEXECUTE)
@@ -385,7 +386,7 @@ extern const char *powerpc_base_platform; CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE)#define CPU_FTRS_E500MC (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \ CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \ - CPU_FTR_DBELL) + CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC)#define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \ CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \ CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \
Signature · 1 line
1.6.0.2
PATCH 3/56 powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Split e500 (v1/v2) and e500mc/e5500 to allow optimization of feature checks that differ between the two.
--- arch/powerpc/include/asm/cputable.h | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/cputable.h +8 -4
@@ -483,8 +483,10 @@ enum { CPU_FTRS_E200 |#endif #ifdef CONFIG_E500 -CPU_FTRS_E500 |CPU_FTRS_E500_2 |CPU_FTRS_E500MC | -CPU_FTRS_E5500 | + CPU_FTRS_E500 | CPU_FTRS_E500_2 | +#endif +#ifdef CONFIG_PPC_E500MC +CPU_FTRS_E500MC |CPU_FTRS_E5500 | #endif 0, };
@@ -528,8 +530,10 @@ enum { CPU_FTRS_E200 &#endif #ifdef CONFIG_E500 -CPU_FTRS_E500 &CPU_FTRS_E500_2 &CPU_FTRS_E500MC & -CPU_FTRS_E5500 & + CPU_FTRS_E500 & CPU_FTRS_E500_2 & +#endif +#ifdef CONFIG_PPC_E500MC +CPU_FTRS_E500MC &CPU_FTRS_E5500 & #endif CPU_FTRS_POSSIBLE, };
Signature · 1 line
1.6.0.2
PATCH 4/56 KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
We'll use it on e500mc as well.
--- arch/powerpc/include/asm/kvm_book3s.h | 3 ++ arch/powerpc/include/asm/kvm_booke.h | 3 ++ arch/powerpc/include/asm/kvm_ppc.h | 5 ++++ arch/powerpc/kvm/book3s_64_mmu_hv.c | 26 +++++++++--------------- arch/powerpc/kvm/powerpc.c | 34 +++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 16 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +3 -0
@@ -452,4 +452,7 @@ static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)#define INS_DCBZ 0x7c0007ec +/* LPIDs we support with this build -- runtime limit may be lower */ +#define KVMPPC_NR_LPIDS (LPID_RSVD + 1) +#endif /* __ASM_KVM_BOOK3S_H__ */
arch/powerpc/include/asm/kvm_booke.h +3 -0
@@ -23,6 +23,9 @@#include <linux/types.h> #include <linux/kvm_host.h> +/* LPIDs we support with this build -- runtime limit may be lower */ +#define KVMPPC_NR_LPIDS 64 +static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) { vcpu->arch.gpr[num] = val;
arch/powerpc/include/asm/kvm_ppc.h +5 -0
@@ -204,4 +204,9 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,int kvm_vcpu_ioctl_dirty_tlb (struct kvm_vcpu *vcpu,struct kvm_dirty_tlb *cfg); +long kvmppc_alloc_lpid (void ); +void kvmppc_claim_lpid (long lpid); +void kvmppc_free_lpid (long lpid); +void kvmppc_init_lpid (unsigned long nr_lpids); +#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kvm/book3s_64_mmu_hv.c +10 -16
@@ -36,13 +36,11 @@/* POWER7 has 10-bit LPIDs, PPC970 has 6-bit LPIDs */ #define MAX_LPID_970 63 -#define NR_LPIDS (LPID_RSVD + 1) -unsigned long lpid_inuse[BITS_TO_LONGS (NR_LPIDS )];long kvmppc_alloc_hpt (struct kvm *kvm) {unsigned long hpt; -unsigned long lpid; +long lpid;struct revmap_entry *rev;struct kvmppc_linear_info *li;
@@ -72,14 +70,9 @@ long kvmppc_alloc_hpt(struct kvm *kvm) } kvm->arch.revmap = rev; -/* Allocate the guest's logical partition ID */ -do { - lpid =find_first_zero_bit (lpid_inuse,NR_LPIDS ); -if (lpid >=NR_LPIDS ) { -pr_err ("kvm_alloc_hpt: No LPIDs free\n" ); - goto out_freeboth; - } - }while (test_and_set_bit (lpid, lpid_inuse)); + lpid =kvmppc_alloc_lpid (); +if (lpid <0 ) + goto out_freeboth; kvm->arch.sdr1 =__pa (hpt) | (HPT_ORDER -18 ); kvm->arch.lpid = lpid;
@@ -96,7 +89,7 @@ long kvmppc_alloc_hpt(struct kvm *kvm)void kvmppc_free_hpt (struct kvm *kvm) { -clear_bit (kvm->arch.lpid, lpid_inuse); +kvmppc_free_lpid (kvm->arch.lpid);vfree (kvm->arch.revmap);if (kvm->arch.hpt_li)kvm_release_hpt (kvm->arch.hpt_li);
@@ -171,8 +164,7 @@ int kvmppc_mmu_hv_init(void)if (!cpu_has_feature (CPU_FTR_HVMODE ))return -EINVAL ; -memset (lpid_inuse,0 ,sizeof (lpid_inuse)); - +/* POWER7 has 10-bit LPIDs, PPC970 and e500mc have 6-bit LPIDs */ if (cpu_has_feature (CPU_FTR_ARCH_206 )) { host_lpid =mfspr (SPRN_LPID );/* POWER7 */ rsvd_lpid =LPID_RSVD ;
@@ -181,9 +173,11 @@ int kvmppc_mmu_hv_init(void) rsvd_lpid =MAX_LPID_970 ; } -set_bit (host_lpid, lpid_inuse); +kvmppc_init_lpid (rsvd_lpid +1 ); + +kvmppc_claim_lpid (host_lpid);/* rsvd_lpid is reserved for use in partition switching */ -set_bit (rsvd_lpid, lpid_inuse); +kvmppc_claim_lpid (rsvd_lpid);return 0 ; }
arch/powerpc/kvm/powerpc.c +34 -0
@@ -799,6 +799,40 @@ out:return r; } +static unsigned long lpid_inuse[BITS_TO_LONGS (KVMPPC_NR_LPIDS )]; +static unsigned long nr_lpids; + +long kvmppc_alloc_lpid (void ) +{ +long lpid; + +do { + lpid =find_first_zero_bit (lpid_inuse,KVMPPC_NR_LPIDS ); +if (lpid >= nr_lpids) { +pr_err ("%s: No LPIDs free\n" , __func__); +return -ENOMEM ; + } + }while (test_and_set_bit (lpid, lpid_inuse)); + +return lpid; +} + +void kvmppc_claim_lpid (long lpid) +{ +set_bit (lpid, lpid_inuse); +} + +void kvmppc_free_lpid (long lpid) +{ +clear_bit (lpid, lpid_inuse); +} + +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)); +} +int kvm_arch_init (void *opaque) {return 0 ;
Signature · 1 line
1.6.0.2
PATCH 5/56 KVM: PPC: booke: add booke-level vcpu load/put
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
This gives us a place to put load/put actions that correspond to code that is booke-specific but not specific to a particular core.
--- arch/powerpc/kvm/44x.c | 3 +++ arch/powerpc/kvm/booke.c | 8 ++++++++ arch/powerpc/kvm/booke.h | 3 +++ arch/powerpc/kvm/e500.c | 3 +++ 4 files changed, 17 insertions(+), 0 deletions(-)
arch/powerpc/kvm/44x.c +3 -0
@@ -29,15 +29,18 @@#include <asm/kvm_ppc.h> #include "44x_tlb.h" +#include "booke.h" void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { +kvmppc_booke_vcpu_load (vcpu, cpu);kvmppc_44x_tlb_load (vcpu); }void kvmppc_core_vcpu_put (struct kvm_vcpu *vcpu) {kvmppc_44x_tlb_put (vcpu); +kvmppc_booke_vcpu_put (vcpu); }int kvmppc_core_check_processor_compat (void )
arch/powerpc/kvm/booke.c +8 -0
@@ -968,6 +968,14 @@ void kvmppc_decrementer_func(unsigned long data)kvmppc_set_tsr_bits (vcpu,TSR_DIS ); } +void kvmppc_booke_vcpu_load (struct kvm_vcpu *vcpu,int cpu) +{ +} + +void kvmppc_booke_vcpu_put (struct kvm_vcpu *vcpu) +{ +} +int __init kvmppc_booke_init (void ) {unsigned long ivor[16 ];
arch/powerpc/kvm/booke.h +3 -0
@@ -71,4 +71,7 @@ void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);/* high-level function, manages flags, host state */ void kvmppc_vcpu_disable_spe (struct kvm_vcpu *vcpu); +void kvmppc_booke_vcpu_load (struct kvm_vcpu *vcpu,int cpu); +void kvmppc_booke_vcpu_put (struct kvm_vcpu *vcpu); +#endif /* __KVM_BOOKE_H__ */
arch/powerpc/kvm/e500.c +3 -0
@@ -36,6 +36,7 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { +kvmppc_booke_vcpu_load (vcpu, cpu);kvmppc_e500_tlb_load (vcpu, cpu); }
@@ -47,6 +48,8 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)if (vcpu->arch.shadow_msr &MSR_SPE )kvmppc_vcpu_disable_spe (vcpu);#endif + +kvmppc_booke_vcpu_put (vcpu); }int kvmppc_core_check_processor_compat (void )
Signature · 1 line
1.6.0.2
PATCH 6/56 KVM: PPC: booke: Move vm core init/destroy out of booke.c
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
e500mc will want to do lpid allocation/deallocation here.
--- arch/powerpc/kvm/44x.c | 9 +++++++++ arch/powerpc/kvm/booke.c | 9 --------- arch/powerpc/kvm/e500.c | 9 +++++++++ 3 files changed, 18 insertions(+), 9 deletions(-)
arch/powerpc/kvm/44x.c +9 -0
@@ -163,6 +163,15 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)kmem_cache_free (kvm_vcpu_cache, vcpu_44x); } +int kvmppc_core_init_vm (struct kvm *kvm) +{ +return 0 ; +} + +void kvmppc_core_destroy_vm (struct kvm *kvm) +{ +} +static int __init kvmppc_44x_init (void ) {int r;
arch/powerpc/kvm/booke.c +0 -9
@@ -932,15 +932,6 @@ void kvmppc_core_commit_memory_region(struct kvm *kvm, { } -int kvmppc_core_init_vm (struct kvm *kvm) -{ -return 0 ; -} - -void kvmppc_core_destroy_vm (struct kvm *kvm) -{ -} -void kvmppc_set_tcr (struct kvm_vcpu *vcpu,u32 new_tcr) { vcpu->arch.tcr = new_tcr;
arch/powerpc/kvm/e500.c +9 -0
@@ -226,6 +226,15 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)kmem_cache_free (kvm_vcpu_cache, vcpu_e500); } +int kvmppc_core_init_vm (struct kvm *kvm) +{ +return 0 ; +} + +void kvmppc_core_destroy_vm (struct kvm *kvm) +{ +} +static int __init kvmppc_e500_init (void ) {int r, i;
Signature · 1 line
1.6.0.2
PATCH 7/56 KVM: PPC: e500: rename e500_tlb.h to e500.h
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
This is in preparation for merging in the contents of arch/powerpc/include/asm/kvm_e500.h.
---
arch/powerpc/kvm/e500.c | 2 +-
arch/powerpc/kvm/{e500_tlb.h => e500.h} | 6 +++---
arch/powerpc/kvm/e500_emulate.c | 2 +-
arch/powerpc/kvm/e500_tlb.c | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
rename arch/powerpc/kvm/{e500_tlb.h => e500.h} (98%)arch/powerpc/kvm/e500.c +1 -1
@@ -24,7 +24,7 @@#include <asm/kvm_ppc.h> #include "booke.h" -#include "e500_tlb.h" +#include "e500.h" void kvmppc_core_load_host_debugstate (struct kvm_vcpu *vcpu) {
arch/powerpc/kvm/e500.h renamed from arch/powerpc/kvm/e500_tlb.h +3 -3
@@ -12,8 +12,8 @@* published by the Free Software Foundation. */ -#ifndef __KVM_E500_TLB_H__ -#define __KVM_E500_TLB_H__ +#ifndef KVM_E500_H +#define KVM_E500_H #include <linux/kvm_host.h> #include <asm/mmu-book3e.h>
@@ -171,4 +171,4 @@ static inline int tlbe_is_host_safe(const struct kvm_vcpu *vcpu, return 1; } -#endif /* __KVM_E500_TLB_H__ */ +#endif /* KVM_E500_H */
arch/powerpc/kvm/e500_emulate.c +1 -1
@@ -17,7 +17,7 @@#include <asm/kvm_e500.h> #include "booke.h" -#include "e500_tlb.h" +#include "e500.h" #define XOP_TLBIVAX 786#define XOP_TLBSX 914
arch/powerpc/kvm/e500_tlb.c +1 -1
@@ -29,7 +29,7 @@#include <asm/kvm_e500.h> #include "../mm/mmu_decl.h" -#include "e500_tlb.h" +#include "e500.h" #include "trace.h" #include "timing.h"
Signature · 1 line
1.6.0.2
PATCH 8/56 KVM: PPC: e500: merge <asm/kvm_e500.h> into arch/powerpc/kvm/e500.h
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Keeping two separate headers for e500-specific things was a pain, and wasn't even organized along any logical boundary.
There was TLB stuff in <asm/kvm_e500.h> despite the existence of arch/powerpc/kvm/e500_tlb.h, and nothing in <asm/kvm_e500.h> needed to be referenced from outside arch/powerpc/kvm.
--- arch/powerpc/include/asm/kvm_e500.h | 96 ----------------------------------- arch/powerpc/kvm/e500.c | 1 - arch/powerpc/kvm/e500.h | 82 ++++++++++++++++++++++++++++-- arch/powerpc/kvm/e500_emulate.c | 1 - arch/powerpc/kvm/e500_tlb.c | 1 - 5 files changed, 78 insertions(+), 103 deletions(-) delete mode 100644 arch/powerpc/include/asm/kvm_e500.h
arch/powerpc/include/asm/kvm_e500.h deleted +0 -96
@@ -1,96 +0,0 @@ -/* -* Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved. -* -* Author: Yu Liu, <[email protected]> -* -* Description: -* This file is derived from arch/powerpc/include/asm/kvm_44x.h, -* by Hollis Blanchard <[email protected]>. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License, version 2, as -* published by the Free Software Foundation. -*/ - -#ifndef __ASM_KVM_E500_H__ -#define __ASM_KVM_E500_H__ - -#include <linux/kvm_host.h> - -#define BOOKE_INTERRUPT_SIZE 36 - -#define E500_PID_NUM 3 -#define E500_TLB_NUM 2 - -#define E500_TLB_VALID 1 -#define E500_TLB_DIRTY 2 - -struct tlbe_ref { -pfn_t pfn; -unsigned int flags;/* E500_TLB_* */ -}; - -struct tlbe_priv { -struct tlbe_ref ref;/* TLB0 only -- TLB1 uses tlb_refs */ -}; - -struct vcpu_id_table ; - -struct kvmppc_e500_tlb_params { -int entries, ways, sets; -}; - -struct kvmppc_vcpu_e500 { -/* Unmodified copy of the guest's TLB -- shared with host userspace. */ -struct kvm_book3e_206_tlb_entry *gtlb_arch; - -/* Starting entry number in gtlb_arch[] */ -int gtlb_offset[E500_TLB_NUM ]; - -/* KVM internal information associated with each guest TLB entry */ -struct tlbe_priv *gtlb_priv[E500_TLB_NUM ]; - -struct kvmppc_e500_tlb_params gtlb_params[E500_TLB_NUM ]; - -unsigned int gtlb_nv[E500_TLB_NUM ]; - -/* -* information associated with each host TLB entry -- -* TLB1 only for now. If/when guest TLB1 entries can be -* mapped with host TLB0, this will be used for that too. -* -* We don't want to use this for guest TLB0 because then we'd -* have the overhead of doing the translation again even if -* the entry is still in the guest TLB (e.g. we swapped out -* and back, and our host TLB entries got evicted). -*/ -struct tlbe_ref *tlb_refs[E500_TLB_NUM ]; -unsigned int host_tlb1_nv; - -u32 host_pid[E500_PID_NUM ]; -u32 pid[E500_PID_NUM ]; -u32 svr; - -/* vcpu id table */ -struct vcpu_id_table *idt; - -u32 l1csr0; -u32 l1csr1; -u32 hid0; -u32 hid1; -u32 tlb0cfg; -u32 tlb1cfg; -u64 mcar; - -struct page **shared_tlb_pages; -int num_shared_tlb_pages; - -struct kvm_vcpu vcpu; -}; - -static inline struct kvmppc_vcpu_e500 *to_e500 (struct kvm_vcpu *vcpu) -{ - return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu); -} - -#endif /* __ASM_KVM_E500_H__ */
arch/powerpc/kvm/e500.c +0 -1
@@ -20,7 +20,6 @@#include <asm/reg.h> #include <asm/cputable.h> #include <asm/tlbflush.h> -#include <asm/kvm_e500.h> #include <asm/kvm_ppc.h> #include "booke.h"
arch/powerpc/kvm/e500.h +78 -4
96 lines not on this page · raw message
arch/powerpc/kvm/e500_emulate.c +0 -1
@@ -14,7 +14,6 @@#include <asm/kvm_ppc.h> #include <asm/disassemble.h> -#include <asm/kvm_e500.h> #include "booke.h" #include "e500.h"
arch/powerpc/kvm/e500_tlb.c +0 -1
@@ -26,7 +26,6 @@#include <linux/vmalloc.h> #include <linux/hugetlb.h> #include <asm/kvm_ppc.h> -#include <asm/kvm_e500.h> #include "../mm/mmu_decl.h" #include "e500.h"
Signature · 1 line
1.6.0.2
PATCH 9/56 KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Move vcpu to the beginning of vcpu_e500 to give it appropriate prominence, especially if more fields end up getting added to the end of vcpu_e500 (and vcpu ends up in the middle).
Remove gratuitous "extern" and add parameter names to prototypes.
--- arch/powerpc/kvm/e500.h | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)
arch/powerpc/kvm/e500.h +14 -11
@@ -42,6 +42,8 @@ struct kvmppc_e500_tlb_params { };struct kvmppc_vcpu_e500 { +struct kvm_vcpu vcpu; +/* Unmodified copy of the guest's TLB -- shared with host userspace. */ struct kvm_book3e_206_tlb_entry *gtlb_arch;
@@ -85,8 +87,6 @@ struct kvmppc_vcpu_e500 {struct page **shared_tlb_pages;int num_shared_tlb_pages; - -struct kvm_vcpu vcpu; };static inline struct kvmppc_vcpu_e500 *to_e500 (struct kvm_vcpu *vcpu)
@@ -113,19 +113,22 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu) (MAS3_U0 |MAS3_U1 |MAS3_U2 |MAS3_U3 \ | E500_TLB_USER_PERM_MASK | E500_TLB_SUPER_PERM_MASK) -extern void kvmppc_dump_tlbs (struct kvm_vcpu *); -extern int kvmppc_e500_emul_mt_mmucsr0 (struct kvmppc_vcpu_e500 *,ulong ); -extern int kvmppc_e500_emul_tlbwe (struct kvm_vcpu *); -extern int kvmppc_e500_emul_tlbre (struct kvm_vcpu *); -extern int kvmppc_e500_emul_tlbivax (struct kvm_vcpu *,int ,int ); -extern int kvmppc_e500_emul_tlbsx (struct kvm_vcpu *,int ); -extern int kvmppc_e500_tlb_search (struct kvm_vcpu *,gva_t ,unsigned int ,int );extern void kvmppc_e500_tlb_put (struct kvm_vcpu *);extern void kvmppc_e500_tlb_load (struct kvm_vcpu *,int ); -extern int kvmppc_e500_tlb_init (struct kvmppc_vcpu_e500 *); -extern void kvmppc_e500_tlb_uninit (struct kvmppc_vcpu_e500 *);extern void kvmppc_e500_tlb_setup (struct kvmppc_vcpu_e500 *);extern void kvmppc_e500_recalc_shadow_pid (struct kvmppc_vcpu_e500 *); +int kvmppc_e500_emul_mt_mmucsr0 (struct kvmppc_vcpu_e500 *vcpu_e500, +ulong value); +int kvmppc_e500_emul_tlbwe (struct kvm_vcpu *vcpu); +int kvmppc_e500_emul_tlbre (struct kvm_vcpu *vcpu); +int kvmppc_e500_emul_tlbivax (struct kvm_vcpu *vcpu,int ra,int rb); +int kvmppc_e500_emul_tlbsx (struct kvm_vcpu *vcpu,int rb); +int kvmppc_e500_tlb_search (struct kvm_vcpu *,gva_t ,unsigned int ,int ); +int kvmppc_e500_tlb_init (struct kvmppc_vcpu_e500 *vcpu_e500); +void kvmppc_e500_tlb_uninit (struct kvmppc_vcpu_e500 *vcpu_e500); + +void kvmppc_get_sregs_e500_tlb (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); +int kvmppc_set_sregs_e500_tlb (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs);/* TLB helper functions */ static inline unsigned int
Signature · 1 line
1.6.0.2
PATCH 10/56 KVM: PPC: e500: refactor core-specific TLB code
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
The PID handling is e500v1/v2-specific, and is moved to e500.c.
The MMU sregs code and kvmppc_core_vcpu_translate will be shared with e500mc, and is moved from e500.c to e500_tlb.c.
Partially based on patches from Liu Yu <[email protected]>.
--- arch/powerpc/include/asm/kvm_host.h | 2 + arch/powerpc/kvm/e500.c | 357 +++++++++++++++++++++++---- arch/powerpc/kvm/e500.h | 62 ++++- arch/powerpc/kvm/e500_emulate.c | 6 +- arch/powerpc/kvm/e500_tlb.c | 460 +++++++++-------------------------- 5 files changed, 473 insertions(+), 414 deletions(-)
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -426,6 +426,8 @@ struct kvm_vcpu_arch {ulong fault_esr;ulong queued_dear;ulong queued_esr; +u32 tlbcfg[4 ]; +u32 mmucfg;#endif gpa_t paddr_accessed;
arch/powerpc/kvm/e500.c +305 -52
432 lines not on this page · raw message
arch/powerpc/kvm/e500.h +49 -13
112 lines not on this page · raw message
arch/powerpc/kvm/e500_emulate.c +3 -3
@@ -174,9 +174,9 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)kvmppc_set_gpr (vcpu, rt, val);break ;case SPRN_TLB0CFG : -kvmppc_set_gpr (vcpu, rt, vcpu_e500->tlb0cfg);break ; +kvmppc_set_gpr (vcpu, rt, vcpu->arch.tlbcfg[0 ]);break ;case SPRN_TLB1CFG : -kvmppc_set_gpr (vcpu, rt, vcpu_e500->tlb1cfg);break ; +kvmppc_set_gpr (vcpu, rt, vcpu->arch.tlbcfg[1 ]);break ;case SPRN_L1CSR0 :kvmppc_set_gpr (vcpu, rt, vcpu_e500->l1csr0);break ;case SPRN_L1CSR1 :
@@ -192,7 +192,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)kvmppc_set_gpr (vcpu, rt,0 );break ;case SPRN_MMUCFG : -kvmppc_set_gpr (vcpu, rt,mfspr (SPRN_MMUCFG ));break ; +kvmppc_set_gpr (vcpu, rt, vcpu->arch.mmucfg);break ;/* extra exceptions */ case SPRN_IVOR32 :
arch/powerpc/kvm/e500_tlb.c +8 -255
303 lines not on this page · raw message
unsigned int eaddr, int as)
{
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
- unsigned int victim, pidsel, tsized;
+ unsigned int victim, tsized;
int tlbsel;
/* since we only have two TLBs, only lower bit is used. */ tlbsel = (vcpu->arch.shared->mas4 >> 28) & 0x1; victim = (tlbsel = 0) ? gtlb0_get_next_victim(vcpu_e500) : 0;
- pidsel = (vcpu->arch.shared->mas4 >> 16) & 0xf;
tsized = (vcpu->arch.shared->mas4 >> 7) & 0x1f;
vcpu->arch.shared->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(victim)
| MAS0_NV(vcpu_e500->gtlb_nv[tlbsel]);
vcpu->arch.shared->mas1 = MAS1_VALID | (as ? MAS1_TS : 0)
- | MAS1_TID(vcpu_e500->pid[pidsel]) + | MAS1_TID(get_tlbmiss_tid(vcpu)) | MAS1_TSIZE(tsized);
vcpu->arch.shared->mas2 = (eaddr & MAS2_EPN)
| (vcpu->arch.shared->mas4 & MAS2_ATTRIB_MASK);
@@ -585,23 +337,22 @@ static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu,
/* TID must be supplied by the caller */ static inline void kvmppc_e500_setup_stlbe(
- struct kvmppc_vcpu_e500 *vcpu_e500,
+ struct kvm_vcpu *vcpu,
struct kvm_book3e_206_tlb_entry *gtlbe, int tsize, struct tlbe_ref *ref, u64 gvaddr, struct kvm_book3e_206_tlb_entry *stlbe)
{
pfn_t pfn = ref->pfn;
+ u32 pr = vcpu->arch.shared->msr & MSR_PR;
BUG_ON(!(ref->flags & E500_TLB_VALID));
- /* Force TS=1 IPROT=0 for all guest mappings. */
- stlbe->mas1 = MAS1_TSIZE(tsize) | MAS1_TS | MAS1_VALID;
- stlbe->mas2 = (gvaddr & MAS2_EPN)
- | e500_shadow_mas2_attrib(gtlbe->mas2,
- vcpu_e500->vcpu.arch.shared->msr & MSR_PR);
- stlbe->mas7_3 = ((u64)pfn << PAGE_SHIFT)
- | e500_shadow_mas3_attrib(gtlbe->mas7_3,
- vcpu_e500->vcpu.arch.shared->msr & MSR_PR);
+ /* Force IPROT=0 for all guest mappings. */
+ stlbe->mas1 = MAS1_TSIZE(tsize) | get_tlb_sts(gtlbe) | MAS1_VALID;
+ stlbe->mas2 = (gvaddr & MAS2_EPN) |
+ e500_shadow_mas2_attrib(gtlbe->mas2, pr);
+ stlbe->mas7_3 = ((u64)pfn << PAGE_SHIFT) |
+ e500_shadow_mas3_attrib(gtlbe->mas7_3, pr);
}
static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
@@ -735,7 +486,8 @@ static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
kvmppc_e500_ref_release(ref);
kvmppc_e500_ref_setup(ref, gtlbe, pfn);
- kvmppc_e500_setup_stlbe(vcpu_e500, gtlbe, tsize, ref, gvaddr, stlbe);
+ kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize,
+ ref, gvaddr, stlbe);
}
/* XXX only map the one-one case, for now use TLB0 */
@@ -775,14 +527,6 @@ static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 *vcpu_e500,
return victim;
}
-void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr)
-{
- struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-
- /* Recalc shadow pid since MSR changes */
- kvmppc_e500_recalc_shadow_pid(vcpu_e500);
-}
-
static inline int kvmppc_e500_gtlbe_invalidate(
struct kvmppc_vcpu_e500 *vcpu_e500,
int tlbsel, int esel)
@@ -810,7 +554,7 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500, ulong value)
kvmppc_e500_gtlbe_invalidate(vcpu_e500, 1, esel);
/* Invalidate all vcpu id mappings */
- kvmppc_e500_id_table_reset_all(vcpu_e500);
+ kvmppc_e500_tlbil_all(vcpu_e500);
return EMULATE_DONE;
}
@@ -843,7 +587,7 @@ int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb)
}
/* Invalidate all vcpu id mappings */
- kvmppc_e500_id_table_reset_all(vcpu_e500);
+ kvmppc_e500_tlbil_all(vcpu_e500);
return EMULATE_DONE;
}
@@ -928,9 +672,7 @@ static void write_stlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
int stid;
preempt_disable();
- stid = kvmppc_e500_get_sid(vcpu_e500, get_tlb_ts(gtlbe),
- get_tlb_tid(gtlbe),
- get_cur_pr(&vcpu_e500->vcpu), 0);
+ stid = kvmppc_e500_get_tlb_stid(&vcpu_e500->vcpu, gtlbe);
stlbe->mas1 |= MAS1_TID(stid);
write_host_tlbe(vcpu_e500, stlbsel, sesel, stlbe);
@@ -940,8 +682,8 @@ static void write_stlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
{
struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
- struct kvm_book3e_206_tlb_entry *gtlbe;
- int tlbsel, esel;
+ struct kvm_book3e_206_tlb_entry *gtlbe, stlbe;
+ int tlbsel, esel, stlbsel, sesel;
tlbsel = get_tlb_tlbsel(vcpu);
esel = get_tlb_esel(vcpu, tlbsel);
@@ -960,8 +702,6 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
/* Invalidate shadow mappings for the about-to-be-clobbered TLBE. */ if (tlbe_is_host_safe(vcpu, gtlbe)) {
- struct kvm_book3e_206_tlb_entry stlbe;
- int stlbsel, sesel;
u64 eaddr;
u64 raddr;
@@ -988,7 +728,7 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
* are mapped on the fly. */
stlbsel = 1;
sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr,
- raddr >> PAGE_SHIFT, gtlbe, &stlbe);
+ raddr >> PAGE_SHIFT, gtlbe, &stlbe);
break;
default:
@@ -1002,6 +742,48 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
return EMULATE_DONE;
}
+static int kvmppc_e500_tlb_search(struct kvm_vcpu *vcpu,
+ gva_t eaddr, unsigned int pid, int as)
+{
+ struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
+ int esel, tlbsel;
+
+ for (tlbsel = 0; tlbsel < 2; tlbsel++) {
+ esel = kvmppc_e500_tlb_index(vcpu_e500, eaddr, tlbsel, pid, as);
+ if (esel >= 0)
+ return index_of(tlbsel, esel);
+ }
+
+ return -1;
+}
+
+/* 'linear_address' is actually an encoding of AS|PID|EADDR . */
+int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
+ struct kvm_translation *tr)
+{
+ int index;
+ gva_t eaddr;
+ u8 pid;
+ u8 as;
+
+ eaddr = tr->linear_address;
+ pid = (tr->linear_address >> 32) & 0xff;
+ as = (tr->linear_address >> 40) & 0x1;
+
+ index = kvmppc_e500_tlb_search(vcpu, eaddr, pid, as);
+ if (index < 0) {
+ tr->valid = 0;
+ return 0;
+ }
+
+ tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr);
+ /* XXX what does "writeable" and "usermode" even mean? */
+ tr->valid = 1;
+
+ return 0;
+}
+
+
int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr)
{
unsigned int as = !!(vcpu->arch.shared->msr & MSR_IS);
@@ -1065,7 +847,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
sesel = 0; /* unused */
priv = &vcpu_e500->gtlb_priv[tlbsel][esel];
- kvmppc_e500_setup_stlbe(vcpu_e500, gtlbe, BOOK3E_PAGESZ_4K,
+ kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K,
&priv->ref, eaddr, &stlbe);
break;
@@ -1086,48 +868,6 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
write_stlbe(vcpu_e500, gtlbe, &stlbe, stlbsel, sesel);
}
-int kvmppc_e500_tlb_search(struct kvm_vcpu *vcpu,
- gva_t eaddr, unsigned int pid, int as)
-{
- struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
- int esel, tlbsel;
-
- for (tlbsel = 0; tlbsel < 2; tlbsel++) {
- esel = kvmppc_e500_tlb_index(vcpu_e500, eaddr, tlbsel, pid, as);
- if (esel >= 0)
- return index_of(tlbsel, esel);
- }
-
- return -1;
-}
-
-void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid)
-{
- struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
-
- if (vcpu->arch.pid != pid) {
- vcpu_e500->pid[0] = vcpu->arch.pid = pid;
- kvmppc_e500_recalc_shadow_pid(vcpu_e500);
- }
-}
-
-void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *vcpu_e500)
-{
- struct kvm_book3e_206_tlb_entry *tlbe;
-
- /* Insert large initial mapping for guest. */
- tlbe = get_entry(vcpu_e500, 1, 0);
- tlbe->mas1 = MAS1_VALID | MAS1_TSIZE(BOOK3E_PAGESZ_256M);
- tlbe->mas2 = 0;
- tlbe->mas7_3 = E500_TLB_SUPER_PERM_MASK;
-
- /* 4K map for serial output. Used by kernel wrapper. */
- tlbe = get_entry(vcpu_e500, 1, 1);
- tlbe->mas1 = MAS1_VALID | MAS1_TSIZE(BOOK3E_PAGESZ_4K);
- tlbe->mas2 = (0xe0004500 & 0xFFFFF000) | MAS2_I | MAS2_G;
- tlbe->mas7_3 = (0xe0004500 & 0xFFFFF000) | E500_TLB_SUPER_PERM_MASK;
-}
-
static void free_gtlb(struct kvmppc_vcpu_e500 *vcpu_e500)
{
int i;
@@ -1154,6 +894,36 @@ static void free_gtlb(struct kvmppc_vcpu_e500 *vcpu_e500)
vcpu_e500->gtlb_arch = NULL;
}
+void kvmppc_get_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) +{
+ sregs->u.e.mas0 = vcpu->arch.shared->mas0;
+ sregs->u.e.mas1 = vcpu->arch.shared->mas1;
+ sregs->u.e.mas2 = vcpu->arch.shared->mas2;
+ sregs->u.e.mas7_3 = vcpu->arch.shared->mas7_3;
+ sregs->u.e.mas4 = vcpu->arch.shared->mas4;
+ sregs->u.e.mas6 = vcpu->arch.shared->mas6;
+
+ sregs->u.e.mmucfg = vcpu->arch.mmucfg;
+ sregs->u.e.tlbcfg[0] = vcpu->arch.tlbcfg[0];
+ sregs->u.e.tlbcfg[1] = vcpu->arch.tlbcfg[1];
+ sregs->u.e.tlbcfg[2] = 0;
+ sregs->u.e.tlbcfg[3] = 0;
+}
+
+int kvmppc_set_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) +{
+ if (sregs->u.e.features & KVM_SREGS_E_ARCH206_MMU) {
+ vcpu->arch.shared->mas0 = sregs->u.e.mas0;
+ vcpu->arch.shared->mas1 = sregs->u.e.mas1;
+ vcpu->arch.shared->mas2 = sregs->u.e.mas2;
+ vcpu->arch.shared->mas7_3 = sregs->u.e.mas7_3;
+ vcpu->arch.shared->mas4 = sregs->u.e.mas4;
+ vcpu->arch.shared->mas6 = sregs->u.e.mas6;
+ }
+
+ return 0;
+}
+
int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
struct kvm_config_tlb *cfg)
{
@@ -1237,14 +1007,16 @@ int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
vcpu_e500->gtlb_offset[0] = 0;
vcpu_e500->gtlb_offset[1] = params.tlb_sizes[0];
- vcpu_e500->tlb0cfg &= ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
+ vcpu->arch.mmucfg = mfspr(SPRN_MMUCFG) & ~MMUCFG_LPIDSIZE;
+
+ vcpu->arch.tlbcfg[0] &= ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
if (params.tlb_sizes[0] <= 2048)
- vcpu_e500->tlb0cfg |= params.tlb_sizes[0];
- vcpu_e500->tlb0cfg |= params.tlb_ways[0] << TLBnCFG_ASSOC_SHIFT;
+ vcpu->arch.tlbcfg[0] |= params.tlb_sizes[0];
+ vcpu->arch.tlbcfg[0] |= params.tlb_ways[0] << TLBnCFG_ASSOC_SHIFT;
- vcpu_e500->tlb1cfg &= ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
- vcpu_e500->tlb1cfg |= params.tlb_sizes[1];
- vcpu_e500->tlb1cfg |= params.tlb_ways[1] << TLBnCFG_ASSOC_SHIFT;
+ vcpu->arch.tlbcfg[1] &= ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
+ vcpu->arch.tlbcfg[1] |= params.tlb_sizes[1];
+ vcpu->arch.tlbcfg[1] |= params.tlb_ways[1] << TLBnCFG_ASSOC_SHIFT;
vcpu_e500->shared_tlb_pages = pages; vcpu_e500->num_shared_tlb_pages = num_pages;
@@ -1280,6 +1052,7 @@ int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500) {
+ struct kvm_vcpu *vcpu = &vcpu_e500->vcpu;
int entry_size = sizeof(struct kvm_book3e_206_tlb_entry); int entries = KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE;
@@ -1356,20 +1129,17 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
if (!vcpu_e500->gtlb_priv[1])
goto err;
- if (kvmppc_e500_id_table_alloc(vcpu_e500) = NULL)
- goto err;
-
/* Init TLB configuration register */
- vcpu_e500->tlb0cfg = mfspr(SPRN_TLB0CFG) &
+ vcpu->arch.tlbcfg[0] = mfspr(SPRN_TLB0CFG) &
~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
- vcpu_e500->tlb0cfg |= vcpu_e500->gtlb_params[0].entries;
- vcpu_e500->tlb0cfg |+ vcpu->arch.tlbcfg[0] |= vcpu_e500->gtlb_params[0].entries;
+ vcpu->arch.tlbcfg[0] | vcpu_e500->gtlb_params[0].ways << TLBnCFG_ASSOC_SHIFT;
- vcpu_e500->tlb1cfg = mfspr(SPRN_TLB1CFG) &
+ vcpu->arch.tlbcfg[1] = mfspr(SPRN_TLB1CFG) &
~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC);
- vcpu_e500->tlb0cfg |= vcpu_e500->gtlb_params[1].entries;
- vcpu_e500->tlb0cfg |+ vcpu->arch.tlbcfg[0] |= vcpu_e500->gtlb_params[1].entries;
+ vcpu->arch.tlbcfg[0] | vcpu_e500->gtlb_params[1].ways << TLBnCFG_ASSOC_SHIFT;
return 0;
@@ -1384,8 +1154,6 @@ err:
void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500) {
free_gtlb(vcpu_e500);
- kvmppc_e500_id_table_free(vcpu_e500);
-
kfree(vcpu_e500->tlb_refs[0]); kfree(vcpu_e500->tlb_refs[1]);
}
Signature · 1 line
1.6.0.2
PATCH 11/56 KVM: PPC: e500: Track TLB1 entries with a bitmap
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Rather than invalidate everything when a TLB1 entry needs to be taken down, keep track of which host TLB1 entries are used for a given guest TLB1 entry, and invalidate just those entries.
Based on code from Ashish Kalra <[email protected]> and Liu Yu <[email protected]>.
--- arch/powerpc/kvm/e500.h | 5 +++ arch/powerpc/kvm/e500_tlb.c | 72 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 5 deletions(-)
arch/powerpc/kvm/e500.h +5 -0
@@ -2,6 +2,7 @@* Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved. * * Author: Yu Liu <[email protected]> +* Ashish Kalra <[email protected]> * * Description: * This file is based on arch/powerpc/kvm/44x_tlb.h and
@@ -25,6 +26,7 @@#define E500_TLB_VALID 1#define E500_TLB_DIRTY 2 +#define E500_TLB_BITMAP 4struct tlbe_ref {pfn_t pfn;
@@ -82,6 +84,9 @@ struct kvmppc_vcpu_e500 {struct page **shared_tlb_pages;int num_shared_tlb_pages; +u64 *g2h_tlb1_map; +unsigned int *h2g_tlb1_rmap; +#ifdef CONFIG_KVM_E500 u32 pid[E500_PID_NUM ];
arch/powerpc/kvm/e500_tlb.c +67 -5
147 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 12/56 KVM: PPC: e500: emulate tlbilx
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
tlbilx is the new, preferred invalidation instruction. It is not found on e500 prior to e500mc, but there should be no harm in supporting it on all e500.
Based on code from Ashish Kalra <[email protected]>.
--- arch/powerpc/kvm/e500.h | 1 + arch/powerpc/kvm/e500_emulate.c | 9 ++++++ arch/powerpc/kvm/e500_tlb.c | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 0 deletions(-)
arch/powerpc/kvm/e500.h +1 -0
@@ -124,6 +124,7 @@ int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500,int kvmppc_e500_emul_tlbwe (struct kvm_vcpu *vcpu);int kvmppc_e500_emul_tlbre (struct kvm_vcpu *vcpu);int kvmppc_e500_emul_tlbivax (struct kvm_vcpu *vcpu,int ra,int rb); +int kvmppc_e500_emul_tlbilx (struct kvm_vcpu *vcpu,int rt,int ra,int rb);int kvmppc_e500_emul_tlbsx (struct kvm_vcpu *vcpu,int rb);int kvmppc_e500_tlb_init (struct kvmppc_vcpu_e500 *vcpu_e500);void kvmppc_e500_tlb_uninit (struct kvmppc_vcpu_e500 *vcpu_e500);
arch/powerpc/kvm/e500_emulate.c +9 -0
@@ -22,6 +22,7 @@#define XOP_TLBSX 914#define XOP_TLBRE 946#define XOP_TLBWE 978 +#define XOP_TLBILX 18int kvmppc_core_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int inst,int *advance)
@@ -29,6 +30,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,int emulated =EMULATE_DONE ;int ra;int rb; +int rt;switch (get_op (inst)) {case 31 :
@@ -47,6 +49,13 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, emulated =kvmppc_e500_emul_tlbsx (vcpu,rb);break ; +case XOP_TLBILX : + ra =get_ra (inst); + rb =get_rb (inst); + rt =get_rt (inst); + emulated =kvmppc_e500_emul_tlbilx (vcpu, rt, ra, rb); +break ; +case XOP_TLBIVAX : ra =get_ra (inst); rb =get_rb (inst);
arch/powerpc/kvm/e500_tlb.c +52 -0
58 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 13/56 powerpc/booke: Provide exception macros with interrupt name
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
DO_KVM will need to identify the particular exception type.
There is an existing set of arbitrary numbers that Linux passes, but it's an undocumented mess that sort of corresponds to server/classic exception vectors but not really.
--- arch/powerpc/kernel/head_44x.S | 23 +++++++++------ arch/powerpc/kernel/head_booke.h | 41 ++++++++++++++------------ arch/powerpc/kernel/head_fsl_booke.S | 52 +++++++++++++++++++++------------- 3 files changed, 68 insertions(+), 48 deletions(-)
arch/powerpc/kernel/head_44x.S +14 -9
@@ -248,10 +248,11 @@ _ENTRY(_start); interrupt_base: /* Critical Input Interrupt */ - CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) + CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception) /* Machine Check Interrupt */ - CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) + CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \ + machine_check_exception) MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) /* Data Storage Interrupt */
@@ -261,7 +262,8 @@ interrupt_base: INSTRUCTION_STORAGE_EXCEPTION /* External Input Interrupt */ - EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) + EXCEPTION(0x0500, BOOKE_INTERRUPT_EXTERNAL, ExternalInput, \ + do_IRQ, EXC_XFER_LITE) /* Alignment Interrupt */ ALIGNMENT_EXCEPTION
@@ -273,29 +275,32 @@ interrupt_base: #ifdef CONFIG_PPC_FPU FP_UNAVAILABLE_EXCEPTION #else - EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \ + FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) #endif /* System Call Interrupt */ START_EXCEPTION(SystemCall) - NORMAL_EXCEPTION_PROLOG + NORMAL_EXCEPTION_PROLOG(BOOKE_INTERRUPT_SYSCALL) EXC_XFER_EE_LITE(0x0c00, DoSyscall) /* Auxiliary Processor Unavailable Interrupt */ - EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \ + AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) /* Decrementer Interrupt */ DECREMENTER_EXCEPTION /* Fixed Internal Timer Interrupt */ /* TODO: Add FIT support */ - EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, \ + unknown_exception, EXC_XFER_EE) /* Watchdog Timer Interrupt */ /* TODO: Add watchdog support */ #ifdef CONFIG_BOOKE_WDT - CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) + CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException) #else - CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) + CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception) #endif /* Data TLB Error Interrupt */
arch/powerpc/kernel/head_booke.h +22 -19
119 lines not on this page · raw message
arch/powerpc/kernel/head_fsl_booke.S +32 -20
121 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 14/56 KVM: PPC: booke: category E.HV (GS-mode) support
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Chips such as e500mc that implement category E.HV in Power ISA 2.06 provide hardware virtualization features, including a new MSR mode for guest state. The guest OS can perform many operations without trapping into the hypervisor, including transitions to and from guest userspace.
Since we can use SRR1[GS] to reliably tell whether an exception came from guest state, instead of messing around with IVPR, we use DO_KVM similarly to book3s.
Current issues include:
- Machine checks from guest state are not routed to the host handler.
- The guest can cause a host oops by executing an emulated instruction in a page that lacks read permission. Existing e500/4xx support has the same problem.
Includes work by Ashish Kalra <[email protected]>, Varun Sethi <[email protected]>, and
Liu Yu <[email protected]>.
--- arch/powerpc/include/asm/dbell.h | 1 + arch/powerpc/include/asm/kvm_asm.h | 8 + arch/powerpc/include/asm/kvm_booke_hv_asm.h | 49 +++ arch/powerpc/include/asm/kvm_host.h | 19 +- arch/powerpc/include/asm/kvm_ppc.h | 3 + arch/powerpc/include/asm/mmu-book3e.h | 6 + arch/powerpc/include/asm/processor.h | 3 + arch/powerpc/include/asm/reg.h | 2 + arch/powerpc/include/asm/reg_booke.h | 34 ++ arch/powerpc/kernel/asm-offsets.c | 15 +- arch/powerpc/kernel/head_booke.h | 28 ++- arch/powerpc/kvm/Kconfig | 3 + arch/powerpc/kvm/booke.c | 309 ++++++++++++--- arch/powerpc/kvm/booke.h | 24 +- arch/powerpc/kvm/booke_emulate.c | 23 +- arch/powerpc/kvm/bookehv_interrupts.S | 587 +++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 5 + arch/powerpc/kvm/timing.h | 6 + 18 files changed, 1058 insertions(+), 67 deletions(-) create mode 100644 arch/powerpc/include/asm/kvm_booke_hv_asm.h create mode 100644 arch/powerpc/kvm/bookehv_interrupts.S
arch/powerpc/include/asm/dbell.h +1 -0
@@ -19,6 +19,7 @@#define PPC_DBELL_MSG_BRDCAST (0x04000000)#define PPC_DBELL_TYPE (x) (((x) & 0xf) << (63-36)) +#define PPC_DBELL_LPID (x) ((x) << (63 - 49))enum ppc_dbell {PPC_DBELL =0 ,/* doorbell */ PPC_DBELL_CRIT =1 ,/* critical doorbell */
arch/powerpc/include/asm/kvm_asm.h +8 -0
@@ -48,6 +48,14 @@#define BOOKE_INTERRUPT_SPE_FP_DATA 33#define BOOKE_INTERRUPT_SPE_FP_ROUND 34#define BOOKE_INTERRUPT_PERFORMANCE_MONITOR 35 +#define BOOKE_INTERRUPT_DOORBELL 36 +#define BOOKE_INTERRUPT_DOORBELL_CRITICAL 37 + +/* booke_hv */ +#define BOOKE_INTERRUPT_GUEST_DBELL 38 +#define BOOKE_INTERRUPT_GUEST_DBELL_CRIT 39 +#define BOOKE_INTERRUPT_HV_SYSCALL 40 +#define BOOKE_INTERRUPT_HV_PRIV 41/* book3s */
arch/powerpc/include/asm/kvm_booke_hv_asm.h new file +49 -0
49 lines not on this page · raw message
arch/powerpc/include/asm/kvm_host.h +18 -1
@@ -106,6 +106,8 @@ struct kvm_vcpu_stat {u32 dec_exits;u32 ext_intr_exits;u32 halt_wakeup; +u32 dbell_exits; +u32 gdbell_exits;#ifdef CONFIG_PPC_BOOK3S u32 pf_storage;u32 pf_instruc;
@@ -140,6 +142,7 @@ enum kvm_exit_types {EMULATED_TLBSX_EXITS ,EMULATED_TLBWE_EXITS ,EMULATED_RFI_EXITS , +EMULATED_RFCI_EXITS ,DEC_EXITS ,EXT_INTR_EXITS , HALT_WAKEUP,
@@ -147,6 +150,8 @@ enum kvm_exit_types {FP_UNAVAIL ,DEBUG_EXITS ,TIMEINGUEST , +DBELL_EXITS , +GDBELL_EXITS , __NUMBER_OF_KVM_EXIT_TYPES };
@@ -217,10 +222,10 @@ struct kvm_arch_memory_slot { };struct kvm_arch { +unsigned int lpid;#ifdef CONFIG_KVM_BOOK3S_64_HV unsigned long hpt_virt;struct revmap_entry *revmap; -unsigned int lpid;unsigned int host_lpid;unsigned long host_lpcr;unsigned long sdr1;
@@ -345,6 +350,17 @@ struct kvm_vcpu_arch {u64 vsr[64 ];#endif +#ifdef CONFIG_KVM_BOOKE_HV +u32 host_mas4; +u32 host_mas6; +u32 shadow_epcr; +u32 epcr; +u32 shadow_msrp; +u32 eplc; +u32 epsc; +u32 oldpir; +#endif +#ifdef CONFIG_PPC_BOOK3S /* For Gekko paired singles */ u32 qpr[32 ];
@@ -428,6 +444,7 @@ struct kvm_vcpu_arch {ulong queued_esr;u32 tlbcfg[4 ];u32 mmucfg; +u32 epr;#endif gpa_t paddr_accessed;
arch/powerpc/include/asm/kvm_ppc.h +3 -0
@@ -139,6 +139,9 @@ extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,extern void kvmppc_core_commit_memory_region (struct kvm *kvm,struct kvm_userspace_memory_region *mem); +extern int kvmppc_bookehv_init (void ); +extern void kvmppc_bookehv_exit (void ); +/* * Cuts out inst bits with ordering according to spec. * That means the leftmost bit is zero. All given bits are included.
arch/powerpc/include/asm/mmu-book3e.h +6 -0
@@ -104,6 +104,8 @@#define MAS4_TSIZED_MASK 0x00000f80/* Default TSIZE */ #define MAS4_TSIZED_SHIFT 7 +#define MAS5_SGS 0x80000000 +#define MAS6_SPID0 0x3FFF0000#define MAS6_SPID1 0x00007FFE#define MAS6_ISIZE (x) MAS1_TSIZE(x)
@@ -118,6 +120,10 @@#define MAS7_RPN 0xFFFFFFFF +#define MAS8_TGS 0x80000000/* Guest space */ +#define MAS8_VF 0x40000000/* Virtualization Fault */ +#define MAS8_TLPID 0x000000ff +/* Bit definitions for MMUCFG */ #define MMUCFG_MAVN 0x00000003/* MMU Architecture Version Number */ #define MMUCFG_MAVN_V1 0x00000000/* v1.0 */
arch/powerpc/include/asm/processor.h +3 -0
@@ -243,6 +243,9 @@ struct thread_struct {#ifdef CONFIG_KVM_BOOK3S_32_HANDLER void * kvm_shadow_vcpu;/* KVM internal data */ #endif /* CONFIG_KVM_BOOK3S_32_HANDLER */ +#if defined(CONFIG_KVM ) && defined(CONFIG_BOOKE ) +struct kvm_vcpu *kvm_vcpu; +#endif #ifdef CONFIG_PPC64 unsigned long dscr;int dscr_inherit;
arch/powerpc/include/asm/reg.h +2 -0
@@ -257,7 +257,9 @@#define LPCR_LPES_SH 2#define LPCR_RMI 0x00000002/* real mode is cache inhibit */ #define LPCR_HDICE 0x00000001/* Hyp Decr enable (HV,PR,EE) */ +#ifndef SPRN_LPID #define SPRN_LPID 0x13F/* Logical Partition Identifier */ +#endif #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 */
arch/powerpc/include/asm/reg_booke.h +34 -0
@@ -56,17 +56,29 @@#define SPRN_SPRG7W 0x117/* Special Purpose Register General 7 Write */ #define SPRN_EPCR 0x133/* Embedded Processor Control Register */ #define SPRN_DBCR2 0x136/* Debug Control Register 2 */ +#define SPRN_MSRP 0x137/* MSR Protect Register */ #define SPRN_IAC3 0x13A/* Instruction Address Compare 3 */ #define SPRN_IAC4 0x13B/* Instruction Address Compare 4 */ #define SPRN_DVC1 0x13E/* Data Value Compare Register 1 */ #define SPRN_DVC2 0x13F/* Data Value Compare Register 2 */ +#define SPRN_LPID 0x152/* Logical Partition ID */ #define SPRN_MAS8 0x155/* MMU Assist Register 8 */ #define SPRN_TLB0PS 0x158/* TLB 0 Page Size Register */ #define SPRN_MAS5_MAS6 0x15c/* MMU Assist Register 5 || 6 */ #define SPRN_MAS8_MAS1 0x15d/* MMU Assist Register 8 || 1 */ #define SPRN_EPTCFG 0x15e/* Embedded Page Table Config */ +#define SPRN_GSPRG0 0x170/* Guest SPRG0 */ +#define SPRN_GSPRG1 0x171/* Guest SPRG1 */ +#define SPRN_GSPRG2 0x172/* Guest SPRG2 */ +#define SPRN_GSPRG3 0x173/* Guest SPRG3 */ #define SPRN_MAS7_MAS3 0x174/* MMU Assist Register 7 || 3 */ #define SPRN_MAS0_MAS1 0x175/* MMU Assist Register 0 || 1 */ +#define SPRN_GSRR0 0x17A/* Guest SRR0 */ +#define SPRN_GSRR1 0x17B/* Guest SRR1 */ +#define SPRN_GEPR 0x17C/* Guest EPR */ +#define SPRN_GDEAR 0x17D/* Guest DEAR */ +#define SPRN_GPIR 0x17E/* Guest PIR */ +#define SPRN_GESR 0x17F/* Guest Exception Syndrome Register */ #define SPRN_IVOR0 0x190/* Interrupt Vector Offset Register 0 */ #define SPRN_IVOR1 0x191/* Interrupt Vector Offset Register 1 */ #define SPRN_IVOR2 0x192/* Interrupt Vector Offset Register 2 */
@@ -87,6 +99,13 @@#define SPRN_IVOR39 0x1B1/* Interrupt Vector Offset Register 39 */ #define SPRN_IVOR40 0x1B2/* Interrupt Vector Offset Register 40 */ #define SPRN_IVOR41 0x1B3/* Interrupt Vector Offset Register 41 */ +#define SPRN_GIVOR2 0x1B8/* Guest IVOR2 */ +#define SPRN_GIVOR3 0x1B9/* Guest IVOR3 */ +#define SPRN_GIVOR4 0x1BA/* Guest IVOR4 */ +#define SPRN_GIVOR8 0x1BB/* Guest IVOR8 */ +#define SPRN_GIVOR13 0x1BC/* Guest IVOR13 */ +#define SPRN_GIVOR14 0x1BD/* Guest IVOR14 */ +#define SPRN_GIVPR 0x1BF/* Guest IVPR */ #define SPRN_SPEFSCR 0x200/* SPE & Embedded FP Status & Control */ #define SPRN_BBEAR 0x201/* Branch Buffer Entry Address Register */ #define SPRN_BBTAR 0x202/* Branch Buffer Target Address Register */
@@ -239,6 +258,10 @@#define MCSR_LDG 0x00002000UL/* Guarded Load */ #define MCSR_TLBSYNC 0x00000002UL/* Multiple tlbsyncs detected */ #define MCSR_BSL2_ERR 0x00000001UL/* Backside L2 cache error */ + +#define MSRP_UCLEP 0x04000000/* Protect MSR[UCLE] */ +#define MSRP_DEP 0x00000200/* Protect MSR[DE] */ +#define MSRP_PMMP 0x00000004/* Protect MSR[PMM] */ #endif #ifdef CONFIG_E200
@@ -593,6 +616,17 @@#define SPRN_EPCR_DMIUH 0x00400000/* Disable MAS Interrupt updates * for hypervisor */ +/* Bit definitions for EPLC/EPSC */ +#define EPC_EPR 0x80000000/* 1 = user, 0 = kernel */ +#define EPC_EPR_SHIFT 31 +#define EPC_EAS 0x40000000/* Address Space */ +#define EPC_EAS_SHIFT 30 +#define EPC_EGS 0x20000000/* 1 = guest, 0 = hypervisor */ +#define EPC_EGS_SHIFT 29 +#define EPC_ELPID 0x00ff0000 +#define EPC_ELPID_SHIFT 16 +#define EPC_EPID 0x00003fff +#define EPC_EPID_SHIFT 0/* * The IBM-403 is an even more odd special case, as it is much
arch/powerpc/kernel/asm-offsets.c +13 -2
@@ -119,6 +119,9 @@ int main(void)#ifdef CONFIG_KVM_BOOK3S_32_HANDLER DEFINE (THREAD_KVM_SVCPU , offsetof(struct thread_struct , kvm_shadow_vcpu));#endif +#ifdef CONFIG_KVM_BOOKE_HV +DEFINE (THREAD_KVM_VCPU , offsetof(struct thread_struct , kvm_vcpu)); +#endif DEFINE (TI_FLAGS , offsetof(struct thread_info , flags));DEFINE (TI_LOCAL_FLAGS , offsetof(struct thread_info , local_flags));
@@ -401,6 +404,7 @@ int main(void)#ifdef CONFIG_KVM DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack)); DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid)); + DEFINE(VCPU_GUEST_PID, offsetof(struct kvm_vcpu, arch.pid)); DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr)); DEFINE(VCPU_VRSAVE, offsetof(struct kvm_vcpu, arch.vrsave)); DEFINE(VCPU_FPRS, offsetof(struct kvm_vcpu, arch.fpr));
@@ -443,9 +447,11 @@ int main(void)DEFINE (VCPU_SHARED_MAS4 , offsetof(struct kvm_vcpu_arch_shared , mas4));DEFINE (VCPU_SHARED_MAS6 , offsetof(struct kvm_vcpu_arch_shared , mas6)); +DEFINE (VCPU_KVM , offsetof(struct kvm_vcpu , kvm)); + DEFINE(KVM_LPID, offsetof(struct kvm, arch.lpid)); +/* book3s */ #ifdef CONFIG_KVM_BOOK3S_64_HV - DEFINE(KVM_LPID, offsetof(struct kvm, arch.lpid)); 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));
@@ -460,7 +466,6 @@ int main(void) DEFINE(VCPU_DAR, offsetof(struct kvm_vcpu, arch.shregs.dar));#endif #ifdef CONFIG_PPC_BOOK3S -DEFINE (VCPU_KVM , offsetof(struct kvm_vcpu , kvm));DEFINE (VCPU_VCPUID , offsetof(struct kvm_vcpu , vcpu_id)); DEFINE(VCPU_PURR, offsetof(struct kvm_vcpu, arch.purr)); DEFINE(VCPU_SPURR, offsetof(struct kvm_vcpu, arch.spurr));
@@ -611,6 +616,12 @@ int main(void) DEFINE(VCPU_HOST_SPEFSCR, offsetof(struct kvm_vcpu, arch.host_spefscr));#endif +#ifdef CONFIG_KVM_BOOKE_HV + DEFINE(VCPU_HOST_MAS4, offsetof(struct kvm_vcpu, arch.host_mas4)); + DEFINE(VCPU_HOST_MAS6, offsetof(struct kvm_vcpu, arch.host_mas6)); + DEFINE(VCPU_EPLC, offsetof(struct kvm_vcpu, arch.eplc)); +#endif +#ifdef CONFIG_KVM_EXIT_TIMING DEFINE (VCPU_TIMING_EXIT_TBU , offsetof(struct kvm_vcpu , arch.timing_exit.tv32.tbu));
arch/powerpc/kernel/head_booke.h +24 -4
@@ -3,6 +3,7 @@#include <asm/ptrace.h> /* for STACK_FRAME_REGS_MARKER */ #include <asm/kvm_asm.h> +#include <asm/kvm_booke_hv_asm.h> /* * Macros used for common Book-e exception handling
@@ -36,8 +37,9 @@ stw r11, THREAD_NORMSAVE(0)(r10); \ stw r13, THREAD_NORMSAVE(2)(r10); \mfcr r13;/* save CR in r13 for now */ \ -mfspr r11,SPRN_SRR1 ;/* check whether user or kernel */ \ - andi. r11,r11,MSR_PR ; \ +mfspr r11,SPRN_SRR1 ; \ + DO_KVM BOOKE_INTERRUPT_##intno SPRN_SRR1; \ + andi. r11, r11,MSR_PR ;/* check whether user or kernel */ \mr r11, r1; \ beq 1f; \/* if from user, start at top of this thread's kernel stack */ \
@@ -123,8 +125,9 @@stw r10,GPR10 (r8 ); \stw r11,GPR11 (r8 ); \stw r9,_CCR (r8 );/* save CR on stack */ \ -mfspr r10,exc_level_srr1;/* check whether user or kernel */ \ - andi. r10,r10,MSR_PR ; \ +mfspr r11,exc_level_srr1;/* check whether user or kernel */ \ + DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ + andi. r11,r11,MSR_PR ; \mfspr r11,SPRN_SPRG_THREAD ;/* if from user, start at top of */ \ lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\addi r11,r11,EXC_LVL_FRAME_OVERHEAD ;/* allocate stack frame */ \
@@ -173,6 +176,23 @@ SPRN_MCSRR0, SPRN_MCSRR1)/* +* Guest Doorbell -- this is a bit odd in that uses GSRR0/1 despite +* being delivered to the host. This exception can only happen +* inside a KVM guest -- so we just handle up to the DO_KVM rather +* than try to fit this into one of the existing prolog macros. +*/ +#define GUEST_DOORBELL_EXCEPTION \ + START_EXCEPTION(GuestDoorbell); \ + mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \ + mfspr r10, SPRN_SPRG_THREAD; \ + stw r11, THREAD_NORMSAVE(0)(r10); \ + mfspr r11, SPRN_SRR1; \ + stw r13, THREAD_NORMSAVE(2)(r10); \ + mfcr r13; /* save CR in r13 for now */\ +DO_KVM BOOKE_INTERRUPT_GUEST_DBELL SPRN_GSRR1; \ + trap + +/* * Exception vectors. */ #define START_EXCEPTION (label) \
arch/powerpc/kvm/Kconfig +3 -0
@@ -90,6 +90,9 @@ config KVM_BOOK3S_64_PR depends on KVM_BOOK3S_64 && !KVM_BOOK3S_64_HV select KVM_BOOK3S_PR +config KVM_BOOKE_HV + bool + config KVM_440 bool "KVM support for PowerPC 440 processors" depends on EXPERIMENTAL && 44x
arch/powerpc/kvm/booke.c +253 -56
483 lines not on this page · raw message
arch/powerpc/kvm/booke.h +23 -1
@@ -48,7 +48,20 @@#define BOOKE_IRQPRIO_PERFORMANCE_MONITOR 19/* Internal pseudo-irqprio for level triggered externals */ #define BOOKE_IRQPRIO_EXTERNAL_LEVEL 20 -#define BOOKE_IRQPRIO_MAX 20 +#define BOOKE_IRQPRIO_DBELL 21 +#define BOOKE_IRQPRIO_DBELL_CRIT 22 +#define BOOKE_IRQPRIO_MAX 23 + +#define BOOKE_IRQMASK_EE ((1 << BOOKE_IRQPRIO_EXTERNAL_LEVEL) | \ + (1 << BOOKE_IRQPRIO_PERFORMANCE_MONITOR) | \ + (1 << BOOKE_IRQPRIO_DBELL) | \ + (1 << BOOKE_IRQPRIO_DECREMENTER) | \ + (1 << BOOKE_IRQPRIO_FIT) | \ + (1 << BOOKE_IRQPRIO_EXTERNAL)) + +#define BOOKE_IRQMASK_CE ((1 << BOOKE_IRQPRIO_DBELL_CRIT) | \ + (1 << BOOKE_IRQPRIO_WATCHDOG) | \ + (1 << BOOKE_IRQPRIO_CRITICAL))extern unsigned long kvmppc_booke_handlers;
@@ -74,4 +87,13 @@ void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);void kvmppc_booke_vcpu_load (struct kvm_vcpu *vcpu,int cpu);void kvmppc_booke_vcpu_put (struct kvm_vcpu *vcpu); +enum int_class { +INT_CLASS_NONCRIT , +INT_CLASS_CRIT , +INT_CLASS_MC , +INT_CLASS_DBG , +}; + +void kvmppc_set_pending_interrupt (struct kvm_vcpu *vcpu,enum int_class type); +#endif /* __KVM_BOOKE_H__ */
arch/powerpc/kvm/booke_emulate.c +20 -3
@@ -99,6 +99,12 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,return emulated; } +/* +* NOTE: some of these registers are not emulated on BOOKE_HV (GS-mode). +* Their backing store is in real registers, and these functions +* will return the wrong result if called for them in another context +* (such as debugging). +*/ int kvmppc_booke_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs) {int emulated =EMULATE_DONE ;
@@ -122,9 +128,11 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)kvmppc_set_tcr (vcpu, spr_val);break ; -/* Note: SPRG4-7 are user-readable. These values are -* loaded into the real SPRGs when resuming the -* guest. */ +/* +* Note: SPRG4-7 are user-readable. +* These values are loaded into the real SPRGs when resuming the +* guest (PR-mode only). +*/ case SPRN_SPRG4 : vcpu->arch.shared->sprg4 = spr_val;break ;case SPRN_SPRG5 :
@@ -136,6 +144,9 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_IVPR : vcpu->arch.ivpr = spr_val; +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_GIVPR , spr_val); +#endif break ;case SPRN_IVOR0 : vcpu->arch.ivor[BOOKE_IRQPRIO_CRITICAL ] = spr_val;
@@ -145,6 +156,9 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)break ;case SPRN_IVOR2 : vcpu->arch.ivor[BOOKE_IRQPRIO_DATA_STORAGE ] = spr_val; +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_GIVOR2 , spr_val); +#endif break ;case SPRN_IVOR3 : vcpu->arch.ivor[BOOKE_IRQPRIO_INST_STORAGE ] = spr_val;
@@ -163,6 +177,9 @@ int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)break ;case SPRN_IVOR8 : vcpu->arch.ivor[BOOKE_IRQPRIO_SYSCALL ] = spr_val; +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_GIVOR8 , spr_val); +#endif break ;case SPRN_IVOR9 : vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL ] = spr_val;
arch/powerpc/kvm/bookehv_interrupts.S new file +587 -0
587 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +5 -0
@@ -114,6 +114,11 @@ int kvmppc_sanity_check(struct kvm_vcpu *vcpu) goto out;#endif +#ifdef CONFIG_KVM_BOOKE_HV +if (!cpu_has_feature (CPU_FTR_EMB_HV )) + goto out; +#endif + r = true; out:
arch/powerpc/kvm/timing.h +6 -0
@@ -93,6 +93,12 @@ static inline void kvmppc_account_exit_stat(struct kvm_vcpu *vcpu, int type)case SIGNAL_EXITS : vcpu->stat.signal_exits++;break ; +case DBELL_EXITS : + vcpu->stat.dbell_exits++; +break ; +case GDBELL_EXITS : + vcpu->stat.gdbell_exits++; +break ; } }
Signature · 1 line
1.6.0.2
PATCH 15/56 KVM: PPC: booke: standard PPC floating point support
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
e500mc has a normal PPC FPU, rather than SPE which is found on e500v1/v2.
Based on code from Liu Yu <[email protected]>.
--- arch/powerpc/include/asm/system.h | 1 + arch/powerpc/kvm/booke.c | 44 +++++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/booke.h | 30 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/system.h +1 -0
@@ -140,6 +140,7 @@ extern void via_cuda_init(void);extern void read_rtc_time (void );extern void pmac_find_display (void );extern void giveup_fpu (struct task_struct *); +extern void load_up_fpu (void );extern void disable_kernel_fp (void );extern void enable_kernel_fp (void );extern void flush_fp_to_thread (struct task_struct *);
arch/powerpc/kvm/booke.c +44 -0
57 lines not on this page · raw message
arch/powerpc/kvm/booke.h +30 -0
@@ -96,4 +96,34 @@ enum int_class {void kvmppc_set_pending_interrupt (struct kvm_vcpu *vcpu,enum int_class type); +/* +* Load up guest vcpu FP state if it's needed. +* It also set the MSR_FP in thread so that host know +* we're holding FPU, and then host can help to save +* guest vcpu FP state if other threads require to use FPU. +* This simulates an FP unavailable fault. +* +* It requires to be called with preemption disabled. +*/ +static inline void kvmppc_load_guest_fp (struct kvm_vcpu *vcpu) +{ +#ifdef CONFIG_PPC_FPU +if (vcpu->fpu_active && !(current->thread.regs->msr &MSR_FP )) { +load_up_fpu (); + current->thread.regs->msr |=MSR_FP ; + } +#endif +} + +/* +* Save guest vcpu FP state into thread. +* It requires to be called with preemption disabled. +*/ +static inline void kvmppc_save_guest_fp (struct kvm_vcpu *vcpu) +{ +#ifdef CONFIG_PPC_FPU +if (vcpu->fpu_active && (current->thread.regs->msr &MSR_FP )) +giveup_fpu (current); +#endif +}#endif /* __KVM_BOOKE_H__ */
Signature · 1 line
1.6.0.2
PATCH 16/56 KVM: PPC: e500mc support
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Add processor support for e500mc, using hardware virtualization support (GS-mode).
Current issues include:
- No support for external proxy (coreint) interrupt mode in the guest.
Includes work by Ashish Kalra <[email protected]>, Varun Sethi <[email protected]>, and
Liu Yu <[email protected]>.
--- arch/powerpc/include/asm/cputable.h | 6 +- arch/powerpc/include/asm/kvm.h | 1 + arch/powerpc/kernel/cpu_setup_fsl_booke.S | 1 + arch/powerpc/kernel/head_fsl_booke.S | 46 ++++ arch/powerpc/kvm/Kconfig | 17 ++- arch/powerpc/kvm/Makefile | 11 + arch/powerpc/kvm/e500.h | 13 +- arch/powerpc/kvm/e500_emulate.c | 24 ++- arch/powerpc/kvm/e500_tlb.c | 21 ++- arch/powerpc/kvm/e500mc.c | 342 +++++++++++++++++++++++++++++ arch/powerpc/kvm/powerpc.c | 6 +- 11 files changed, 476 insertions(+), 12 deletions(-) create mode 100644 arch/powerpc/kvm/e500mc.c
arch/powerpc/include/asm/cputable.h +4 -2
@@ -168,6 +168,7 @@ extern const char *powerpc_base_platform;#define CPU_FTR_LWSYNC ASM_CONST(0x0000000008000000)#define CPU_FTR_NOEXECUTE ASM_CONST(0x0000000010000000)#define CPU_FTR_INDEXED_DCR ASM_CONST(0x0000000020000000) +#define CPU_FTR_EMB_HV ASM_CONST(0x0000000040000000)/* * Add the 64-bit processor unique features in the top half of the word;
@@ -386,11 +387,11 @@ extern const char *powerpc_base_platform; CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE)#define CPU_FTRS_E500MC (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \ CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \ - CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC) + CPU_FTR_DBELL | CPU_FTR_DEBUG_LVL_EXC | CPU_FTR_EMB_HV)#define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \ CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \ CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \ - CPU_FTR_DEBUG_LVL_EXC) + CPU_FTR_DEBUG_LVL_EXC | CPU_FTR_EMB_HV)#define CPU_FTRS_GENERIC_32 (CPU_FTR_COMMON | CPU_FTR_NODSISRALIGN)/* 64-bit CPUs */
@@ -535,6 +536,7 @@ enum {#ifdef CONFIG_PPC_E500MC CPU_FTRS_E500MC &CPU_FTRS_E5500 & #endif + ~CPU_FTR_EMB_HV &/* can be removed at runtime */ CPU_FTRS_POSSIBLE, };#endif /* __powerpc64__ */
arch/powerpc/include/asm/kvm.h +1 -0
@@ -277,6 +277,7 @@ struct kvm_sync_regs {#define KVM_CPU_E500V2 2#define KVM_CPU_3S_32 3#define KVM_CPU_3S_64 4 +#define KVM_CPU_E500MC 5/* for KVM_CAP_SPAPR_TCE */ struct kvm_create_spapr_tce {
arch/powerpc/kernel/cpu_setup_fsl_booke.S +1 -0
@@ -73,6 +73,7 @@ _GLOBAL(__setup_cpu_e500v2) mtlr r4 blr _GLOBAL(__setup_cpu_e500mc) + mr r5, r4 mflr r4 bl __e500_icache_setup bl __e500_dcache_setup
arch/powerpc/kernel/head_fsl_booke.S +46 -0
80 lines not on this page · raw message
arch/powerpc/kvm/Kconfig +16 -1
@@ -109,7 +109,7 @@ config KVM_440 config KVM_EXIT_TIMING bool "Detailed exit timing" - depends on KVM_440 || KVM_E500 + depends on KVM_440 || KVM_E500 || KVM_E500MC ---help--- Calculate elapsed time for every exit/enter cycle. A per-vcpu report is available in debugfs kvm/vm#_vcpu#_timing.
@@ -132,6 +132,21 @@ config KVM_E500 If unsure, say N. +config KVM_E500MC + bool "KVM support for PowerPC E500MC/E5500 processors" + depends on EXPERIMENTAL && PPC_E500MC + select KVM + select KVM_MMIO + select KVM_BOOKE_HV + ---help--- + Support running unmodified E500MC/E5500 (32-bit) guest kernels in + virtual machines on E500MC/E5500 host processors. + + This module provides access to the hardware capabilities through + a character device node named /dev/kvm. + + If unsure, say N. + source drivers/vhost/Kconfig endif # VIRTUALIZATION
arch/powerpc/kvm/Makefile +11 -0
@@ -38,6 +38,16 @@ kvm-e500-objs := \ e500_emulate.o kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs) +kvm-e500mc-objs := \ + $(common-objs-y) \ + booke.o \ + booke_emulate.o \ + bookehv_interrupts.o \ + e500mc.o \ + e500_tlb.o \ + e500_emulate.o +kvm-objs-$(CONFIG_KVM_E500MC) := $(kvm-e500mc-objs) + kvm-book3s_64-objs-$(CONFIG_KVM_BOOK3S_64_PR) := \ ../../../virt/kvm/coalesced_mmio.o \ fpu.o \
@@ -89,6 +99,7 @@ kvm-objs := $(kvm-objs-m) $(kvm-objs-y) obj-$(CONFIG_KVM_440) += kvm.o obj-$(CONFIG_KVM_E500) += kvm.o +obj-$(CONFIG_KVM_E500MC) += kvm.o obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o
arch/powerpc/kvm/e500.h +11 -2
@@ -2,7 +2,9 @@* Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved. * * Author: Yu Liu <[email protected]> +* Scott Wood <[email protected]> * Ashish Kalra <[email protected]> +* Varun Sethi <[email protected]> * * Description: * This file is based on arch/powerpc/kvm/44x_tlb.h and
@@ -100,6 +102,7 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu) return container_of(vcpu, struct kvmppc_vcpu_e500, vcpu); } +/* This geometry is the legacy default -- can be overridden by userspace */ #define KVM_E500_TLB0_WAY_SIZE 128#define KVM_E500_TLB0_WAY_NUM 2
@@ -250,10 +253,12 @@ static inline int tlbe_is_host_safe(const struct kvm_vcpu *vcpu,if (!get_tlb_v (tlbe))return 0 ; +#ifndef CONFIG_KVM_BOOKE_HV /* Does it match current guest AS? */ /* XXX what about IS != DS? */ if (get_tlb_ts (tlbe) != !!(vcpu->arch.shared->msr &MSR_IS ))return 0 ; +#endif gpa =get_tlb_raddr (tlbe);if (!gfn_to_memslot (vcpu->kvm, gpa >>PAGE_SHIFT ))
@@ -274,7 +279,11 @@ void kvmppc_e500_tlbil_one(struct kvmppc_vcpu_e500 *vcpu_e500, struct kvm_book3e_206_tlb_entry *gtlbe);void kvmppc_e500_tlbil_all (struct kvmppc_vcpu_e500 *vcpu_e500); -#ifdef CONFIG_KVM_E500 +#ifdef CONFIG_KVM_BOOKE_HV +#define kvmppc_e500_get_tlb_stid (vcpu, gtlbe) get_tlb_tid(gtlbe) +#define get_tlbmiss_tid (vcpu) get_cur_pid(vcpu) +#define get_tlb_sts (gtlbe) (gtlbe->mas1 & MAS1_TS) +#else unsigned int kvmppc_e500_get_tlb_stid (struct kvm_vcpu *vcpu,struct kvm_book3e_206_tlb_entry *gtlbe);
@@ -288,6 +297,6 @@ static inline unsigned int get_tlbmiss_tid(struct kvm_vcpu *vcpu)/* Force TS=1 for all guest mappings. */ #define get_tlb_sts (gtlbe) (MAS1_TS) -#endif /* CONFIG_KVM_E500 */ +#endif /* !BOOKE_HV */ #endif /* KVM_E500_H */
arch/powerpc/kvm/e500_emulate.c +22 -2
@@ -85,6 +85,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)ulong spr_val =kvmppc_get_gpr (vcpu, rs);switch (sprn) { +#ifndef CONFIG_KVM_BOOKE_HV case SPRN_PID :kvmppc_set_pid (vcpu, spr_val);break ;
@@ -114,6 +115,7 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs) vcpu->arch.shared->mas7_3 &= (u64 )0xffffffff ; vcpu->arch.shared->mas7_3 |= (u64 )spr_val <<32 ;break ; +#endif case SPRN_L1CSR0 : vcpu_e500->l1csr0 = spr_val; vcpu_e500->l1csr0 &= ~(L1CSR0_DCFI |L1CSR0_CLFC );
@@ -143,7 +145,14 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)case SPRN_IVOR35 : vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR ] = spr_val;break ; - +#ifdef CONFIG_KVM_BOOKE_HV +case SPRN_IVOR36 : + vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL ] = spr_val; +break ; +case SPRN_IVOR37 : + vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT ] = spr_val; +break ; +#endif default : emulated =kvmppc_booke_emulate_mtspr (vcpu, sprn, rs); }
@@ -155,9 +164,11 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);int emulated =EMULATE_DONE ; -unsigned long val;switch (sprn) { +#ifndef CONFIG_KVM_BOOKE_HV +unsigned long val; +case SPRN_PID :kvmppc_set_gpr (vcpu, rt, vcpu_e500->pid[0 ]);break ;case SPRN_PID1 :
@@ -182,6 +193,7 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt) val = vcpu->arch.shared->mas7_3 >>32 ;kvmppc_set_gpr (vcpu, rt, val);break ; +#endif case SPRN_TLB0CFG :kvmppc_set_gpr (vcpu, rt, vcpu->arch.tlbcfg[0 ]);break ;case SPRN_TLB1CFG :
@@ -216,6 +228,14 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)case SPRN_IVOR35 :kvmppc_set_gpr (vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_PERFORMANCE_MONITOR ]);break ; +#ifdef CONFIG_KVM_BOOKE_HV +case SPRN_IVOR36 : +kvmppc_set_gpr (vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL ]); +break ; +case SPRN_IVOR37 : +kvmppc_set_gpr (vcpu, rt, vcpu->arch.ivor[BOOKE_IRQPRIO_DBELL_CRIT ]); +break ; +#endif default : emulated =kvmppc_booke_emulate_mfspr (vcpu, sprn, rt); }
arch/powerpc/kvm/e500_tlb.c +19 -2
@@ -2,7 +2,9 @@* Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved. * * Author: Yu Liu, [email protected] +* Scott Wood, [email protected] * Ashish Kalra, [email protected] +* Varun Sethi, [email protected] * * Description: * This file is based on arch/powerpc/kvm/44x_tlb.c,
@@ -64,6 +66,7 @@ static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode)/* Mask off reserved bits. */ mas3 &=MAS3_ATTRIB_MASK ; +#ifndef CONFIG_KVM_BOOKE_HV if (!usermode) {/* Guest is in supervisor mode, * so we need to translate guest
@@ -71,8 +74,9 @@ static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode) mas3 &= ~E500_TLB_USER_PERM_MASK ; mas3 |= (mas3 & E500_TLB_SUPER_PERM_MASK) << 1; } - -return mas3 |E500_TLB_SUPER_PERM_MASK ; + mas3 |=E500_TLB_SUPER_PERM_MASK ; +#endif +return mas3; }static inline u32 e500_shadow_mas2_attrib (u32 mas2,int usermode)
@@ -98,7 +102,16 @@ static inline void __write_host_tlbe(struct kvm_book3e_206_tlb_entry *stlbe,mtspr (SPRN_MAS2 , (unsigned long )stlbe->mas2);mtspr (SPRN_MAS3 , (u32 )stlbe->mas7_3);mtspr (SPRN_MAS7 , (u32)(stlbe->mas7_3 >>32 )); +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_MAS8 , stlbe->mas8); +#endif asmvolatile ("isync; tlbwe" : : :"memory" ); + +#ifdef CONFIG_KVM_BOOKE_HV +/* Must clear mas8 for other host tlbwe's */ +mtspr (SPRN_MAS8 ,0 ); +isync (); +#endif local_irq_restore (flags); trace_kvm_booke206_stlb_write(mas0, stlbe->mas8, stlbe->mas1,
@@ -384,6 +397,10 @@ static inline void kvmppc_e500_setup_stlbe(e500_shadow_mas2_attrib (gtlbe->mas2, pr); stlbe->mas7_3 = ((u64 )pfn <<PAGE_SHIFT ) |e500_shadow_mas3_attrib (gtlbe->mas7_3, pr); + +#ifdef CONFIG_KVM_BOOKE_HV + stlbe->mas8 =MAS8_TGS | vcpu->kvm->arch.lpid; +#endif } static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
arch/powerpc/kvm/e500mc.c new file +342 -0
342 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +3 -3
@@ -235,7 +235,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PPC_PAIRED_SINGLES :case KVM_CAP_PPC_OSI :case KVM_CAP_PPC_GET_PVINFO : -#ifdef CONFIG_KVM_E500 +#if defined(CONFIG_KVM_E500 ) || defined(CONFIG_KVM_E500MC )case KVM_CAP_SW_TLB :#endif r =1 ;
@@ -629,7 +629,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, r =0 ; vcpu->arch.papr_enabled = true;break ; -#ifdef CONFIG_KVM_E500 +#if defined(CONFIG_KVM_E500 ) || defined(CONFIG_KVM_E500MC )case KVM_CAP_SW_TLB : {struct kvm_config_tlb cfg;void __user *user_ptr = (void __user *)(uintptr_t )cap->args[0 ];
@@ -706,7 +706,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,break ; } -#ifdef CONFIG_KVM_E500 +#if defined(CONFIG_KVM_E500 ) || defined(CONFIG_KVM_E500MC )case KVM_DIRTY_TLB : {struct kvm_dirty_tlb dirty; r = -EFAULT ;
Signature · 1 line
1.6.0.2
PATCH 17/56 KVM: PPC: e500mc: Add doorbell emulation support
In reply to Alexander GrafWhen one vcpu wants to kick another, it can issue a special IPI instruction called msgsnd. This patch emulates this instruction, its clearing counterpart and the infrastructure required to actually trigger that interrupt inside a guest vcpu.
With this patch, SMP guests on e500mc work.
--- arch/powerpc/include/asm/dbell.h | 2 + arch/powerpc/kvm/booke.c | 2 + arch/powerpc/kvm/e500_emulate.c | 68 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/dbell.h +2 -0
@@ -19,7 +19,9 @@#define PPC_DBELL_MSG_BRDCAST (0x04000000)#define PPC_DBELL_TYPE (x) (((x) & 0xf) << (63-36)) +#define PPC_DBELL_TYPE_MASK PPC_DBELL_TYPE(0xf)#define PPC_DBELL_LPID (x) ((x) << (63 - 49)) +#define PPC_DBELL_PIR_MASK 0x3fffenum ppc_dbell {PPC_DBELL =0 ,/* doorbell */ PPC_DBELL_CRIT =1 ,/* critical doorbell */
arch/powerpc/kvm/booke.c +2 -0
@@ -326,6 +326,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, int_class =INT_CLASS_NONCRIT ;break ;case BOOKE_IRQPRIO_CRITICAL : +case BOOKE_IRQPRIO_DBELL_CRIT : allowed = vcpu->arch.shared->msr &MSR_CE ; allowed = allowed && !crit; msr_mask =MSR_GS |MSR_ME ;
@@ -342,6 +343,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, keep_irq = true;/* fall through */ case BOOKE_IRQPRIO_EXTERNAL : +case BOOKE_IRQPRIO_DBELL : allowed = vcpu->arch.shared->msr &MSR_EE ; allowed = allowed && !crit; msr_mask =MSR_GS |MSR_CE |MSR_ME |MSR_DE ;
arch/powerpc/kvm/e500_emulate.c +68 -0
90 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 18/56 KVM: PPC: e500mc: implicitly set MSR_GS
In reply to Alexander GrafWhen setting MSR for an e500mc guest, we implicitly always set MSR_GS to make sure the guest is in guest state. Since we have this implicit rule there, we don't need to explicitly pass MSR_GS to set_msr().
Remove all explicit setters of MSR_GS.
--- arch/powerpc/kvm/booke.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
arch/powerpc/kvm/booke.c +5 -6
@@ -280,7 +280,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority) {int allowed =0 ; -ulong uninitialized_var (msr_mask ); +ulong msr_mask =0 ;bool update_esr = false, update_dear = false;ulong crit_raw = vcpu->arch.shared->critical;ulong crit_r1 =kvmppc_get_gpr (vcpu,1 );
@@ -322,20 +322,19 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,case BOOKE_IRQPRIO_AP_UNAVAIL :case BOOKE_IRQPRIO_ALIGNMENT : allowed =1 ; - msr_mask =MSR_GS |MSR_CE |MSR_ME |MSR_DE ; + msr_mask =MSR_CE |MSR_ME |MSR_DE ; int_class =INT_CLASS_NONCRIT ;break ;case BOOKE_IRQPRIO_CRITICAL :case BOOKE_IRQPRIO_DBELL_CRIT : allowed = vcpu->arch.shared->msr &MSR_CE ; allowed = allowed && !crit; - msr_mask =MSR_GS |MSR_ME ; + msr_mask =MSR_ME ; int_class =INT_CLASS_CRIT ;break ;case BOOKE_IRQPRIO_MACHINE_CHECK : allowed = vcpu->arch.shared->msr &MSR_ME ; allowed = allowed && !crit; - msr_mask =MSR_GS ; int_class =INT_CLASS_MC ;break ;case BOOKE_IRQPRIO_DECREMENTER :
@@ -346,13 +345,13 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,case BOOKE_IRQPRIO_DBELL : allowed = vcpu->arch.shared->msr &MSR_EE ; allowed = allowed && !crit; - msr_mask =MSR_GS |MSR_CE |MSR_ME |MSR_DE ; + msr_mask =MSR_CE |MSR_ME |MSR_DE ; int_class =INT_CLASS_NONCRIT ;break ;case BOOKE_IRQPRIO_DEBUG : allowed = vcpu->arch.shared->msr &MSR_DE ; allowed = allowed && !crit; - msr_mask =MSR_GS |MSR_ME ; + msr_mask =MSR_ME ; int_class =INT_CLASS_CRIT ;break ; }
Signature · 1 line
1.6.0.2
PATCH 19/56 KVM: PPC: e500mc: Move r1/r2 restoration very early
In reply to Alexander GrafIf we hit any exception whatsoever in the restore path and r1/r2 aren't the host registers, we don't get a working oops. So it's always a good idea to restore them as early as possible.
This time, it actually has practical reasons to do so too, since we need to have the host page fault handler fix up our guest instruction read code. And for that to work we need r1/r2 restored.
--- arch/powerpc/kvm/bookehv_interrupts.S | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +6 -6
@@ -67,6 +67,12 @@ * saved in vcpu: cr, ctr, r3-r13 */ .macro kvm_handler_common intno, srr0, flags + /* Restore host stack pointer */ + PPC_STL r1, VCPU_GPR(r1)(r4) + PPC_STL r2, VCPU_GPR(r2)(r4) + PPC_LL r1, VCPU_HOST_STACK(r4) + PPC_LL r2, HOST_R2(r1) + mfspr r10, SPRN_PID lwz r8, VCPU_HOST_PID(r4) PPC_LL r11, VCPU_SHARED(r4)
@@ -290,10 +296,8 @@ _GLOBAL(kvmppc_resume_host) /* Save remaining volatile guest register state to vcpu. */ mfspr r3, SPRN_VRSAVE PPC_STL r0, VCPU_GPR(r0)(r4) - PPC_STL r1, VCPU_GPR(r1)(r4) mflr r5 mfspr r6, SPRN_SPRG4 - PPC_STL r2, VCPU_GPR(r2)(r4) PPC_STL r5, VCPU_LR(r4) mfspr r7, SPRN_SPRG5 PPC_STL r3, VCPU_VRSAVE(r4)
@@ -334,10 +338,6 @@ _GLOBAL(kvmppc_resume_host) mtspr SPRN_EPCR, r3 isync - /* Restore host stack pointer */ - PPC_LL r1, VCPU_HOST_STACK(r4) - PPC_LL r2, HOST_R2(r1) - /* Switch to kernel stack and jump to handler. */ PPC_LL r3, HOST_RUN(r1) mr r5, r14 /* intno */
Signature · 1 line
1.6.0.2
PATCH 20/56 KVM: PPC: e500mc: add load inst fixup
In reply to Alexander GrafThere's always a chance we're unable to read a guest instruction. The guest could have its TLB mapped execute-, but not readable, something odd happens and our TLB gets flushed. So it's a good idea to be prepared for that case and have a fallback that allows us to fix things up in that case.
Add fixup code that keeps guest code from potentially crashing our host kernel.
--- arch/powerpc/kvm/bookehv_interrupts.S | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +29 -1
@@ -28,6 +28,7 @@ #include <asm/asm-compat.h> #include <asm/asm-offsets.h> #include <asm/bitsperlong.h> +#include <asm/thread_info.h> #include "../kernel/head_booke.h" /* for THREAD_NORMSAVE() */
@@ -171,9 +172,36 @@ PPC_STL r30, VCPU_GPR(r30)(r4) PPC_STL r31, VCPU_GPR(r31)(r4) mtspr SPRN_EPLC, r8 + + /* disable preemption, so we are sure we hit the fixup handler */ +#ifdef CONFIG_PPC64 + clrrdi r8,r1,THREAD_SHIFT +#else + rlwinm r8,r1,0,0,31-THREAD_SHIFT /* current thread_info */ +#endif + li r7, 1 + stw r7, TI_PREEMPT(r8) + isync - lwepx r9, 0, r5 + + /* + * In case the read goes wrong, we catch it and write an invalid value + * in LAST_INST instead. + */ +1: lwepx r9, 0, r5 +2: +.section .fixup, "ax" +3: li r9, KVM_INST_FETCH_FAILED + b 2b +.previous +.section __ex_table,"a" + PPC_LONG_ALIGN + PPC_LONG 1b,3b +.previous + mtspr SPRN_EPLC, r3 + li r7, 0 + stw r7, TI_PREEMPT(r8) stw r9, VCPU_LAST_INST(r4) .endif
Signature · 1 line
1.6.0.2
PATCH 21/56 KVM: PPC: rename CONFIG_KVM_E500 -> CONFIG_KVM_E500V2
In reply to Alexander GrafThe CONFIG_KVM_E500 option really indicates that we're running on a V2 machine, not on a machine of the generic E500 class. So indicate that properly and change the config name accordingly.
--- arch/powerpc/kvm/Kconfig | 8 ++++---- arch/powerpc/kvm/Makefile | 4 ++-- arch/powerpc/kvm/booke.c | 2 +- arch/powerpc/kvm/e500.h | 6 +++--- arch/powerpc/kvm/e500_tlb.c | 2 +- arch/powerpc/kvm/powerpc.c | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-)
arch/powerpc/kvm/Kconfig +4 -4
@@ -109,7 +109,7 @@ config KVM_440 config KVM_EXIT_TIMING bool "Detailed exit timing" - depends on KVM_440 || KVM_E500 || KVM_E500MC + depends on KVM_440 || KVM_E500V2 || KVM_E500MC ---help--- Calculate elapsed time for every exit/enter cycle. A per-vcpu report is available in debugfs kvm/vm#_vcpu#_timing.
@@ -118,14 +118,14 @@ config KVM_EXIT_TIMING If unsure, say N. -config KVM_E500 - bool "KVM support for PowerPC E500 processors" +config KVM_E500V2 + bool "KVM support for PowerPC E500v2 processors" depends on EXPERIMENTAL && E500 select KVM select KVM_MMIO ---help--- Support running unmodified E500 guest kernels in virtual machines on - E500 host processors. + E500v2 host processors. This module provides access to the hardware capabilities through a character device node named /dev/kvm.
arch/powerpc/kvm/Makefile +2 -2
@@ -36,7 +36,7 @@ kvm-e500-objs := \ e500.o \ e500_tlb.o \ e500_emulate.o -kvm-objs-$(CONFIG_KVM_E500) := $(kvm-e500-objs) +kvm-objs-$(CONFIG_KVM_E500V2) := $(kvm-e500-objs) kvm-e500mc-objs := \ $(common-objs-y) \
@@ -98,7 +98,7 @@ kvm-objs-$(CONFIG_KVM_BOOK3S_32) := $(kvm-book3s_32-objs) kvm-objs := $(kvm-objs-m) $(kvm-objs-y) obj-$(CONFIG_KVM_440) += kvm.o -obj-$(CONFIG_KVM_E500) += kvm.o +obj-$(CONFIG_KVM_E500V2) += kvm.o obj-$(CONFIG_KVM_E500MC) += kvm.o obj-$(CONFIG_KVM_BOOK3S_64) += kvm.o obj-$(CONFIG_KVM_BOOK3S_32) += kvm.o
arch/powerpc/kvm/booke.c +1 -1
@@ -762,7 +762,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,gpa_t gpaddr;gfn_t gfn; -#ifdef CONFIG_KVM_E500 +#ifdef CONFIG_KVM_E500V2 if (!(vcpu->arch.shared->msr &MSR_PR ) && (eaddr &PAGE_MASK ) = vcpu->arch.magic_page_ea) {kvmppc_map_magic (vcpu);
arch/powerpc/kvm/e500.h +3 -3
@@ -39,7 +39,7 @@ struct tlbe_priv {struct tlbe_ref ref;/* TLB0 only -- TLB1 uses tlb_refs */ }; -#ifdef CONFIG_KVM_E500 +#ifdef CONFIG_KVM_E500V2 struct vcpu_id_table ;#endif
@@ -89,7 +89,7 @@ struct kvmppc_vcpu_e500 {u64 *g2h_tlb1_map;unsigned int *h2g_tlb1_rmap; -#ifdef CONFIG_KVM_E500 +#ifdef CONFIG_KVM_E500V2 u32 pid[E500_PID_NUM ];/* vcpu id table */
@@ -136,7 +136,7 @@ void kvmppc_get_sregs_e500_tlb(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);int kvmppc_set_sregs_e500_tlb (struct kvm_vcpu *vcpu,struct kvm_sregs *sregs); -#ifdef CONFIG_KVM_E500 +#ifdef CONFIG_KVM_E500V2 unsigned int kvmppc_e500_get_sid (struct kvmppc_vcpu_e500 *vcpu_e500,unsigned int as,unsigned int gid,unsigned int pr,int avoid_recursion);
arch/powerpc/kvm/e500_tlb.c +1 -1
@@ -156,7 +156,7 @@ static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500, } } -#ifdef CONFIG_KVM_E500 +#ifdef CONFIG_KVM_E500V2 void kvmppc_map_magic (struct kvm_vcpu *vcpu) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);
arch/powerpc/kvm/powerpc.c +4 -4
@@ -79,7 +79,7 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu) }case HC_VENDOR_KVM |KVM_HC_FEATURES : r =HC_EV_SUCCESS ; -#if defined(CONFIG_PPC_BOOK3S ) || defined(CONFIG_KVM_E500 ) +#if defined(CONFIG_PPC_BOOK3S ) || defined(CONFIG_KVM_E500V2 )/* XXX Missing magic page on 44x */ r2 |= (1 <<KVM_FEATURE_MAGIC_PAGE );#endif
@@ -235,7 +235,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_PPC_PAIRED_SINGLES :case KVM_CAP_PPC_OSI :case KVM_CAP_PPC_GET_PVINFO : -#if defined(CONFIG_KVM_E500 ) || defined(CONFIG_KVM_E500MC ) +#if defined(CONFIG_KVM_E500V2 ) || defined(CONFIG_KVM_E500MC )case KVM_CAP_SW_TLB :#endif r =1 ;
@@ -629,7 +629,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, r =0 ; vcpu->arch.papr_enabled = true;break ; -#if defined(CONFIG_KVM_E500 ) || defined(CONFIG_KVM_E500MC ) +#if defined(CONFIG_KVM_E500V2 ) || defined(CONFIG_KVM_E500MC )case KVM_CAP_SW_TLB : {struct kvm_config_tlb cfg;void __user *user_ptr = (void __user *)(uintptr_t )cap->args[0 ];
@@ -706,7 +706,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,break ; } -#if defined(CONFIG_KVM_E500 ) || defined(CONFIG_KVM_E500MC ) +#if defined(CONFIG_KVM_E500V2 ) || defined(CONFIG_KVM_E500MC )case KVM_DIRTY_TLB : {struct kvm_dirty_tlb dirty; r = -EFAULT ;
Signature · 1 line
1.6.0.2
PATCH 22/56 KVM: PPC: make e500v2 kvm and e500mc cpu mutually exclusive
In reply to Alexander GrafWe can't run e500v2 kvm on e500mc kernels, so indicate that by making the 2 options mutually exclusive in kconfig.
--- arch/powerpc/kvm/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/Kconfig +1 -1
@@ -120,7 +120,7 @@ config KVM_EXIT_TIMING config KVM_E500V2 bool "KVM support for PowerPC E500v2 processors" - depends on EXPERIMENTAL && E500 + depends on EXPERIMENTAL && E500 && !PPC_E500MC select KVM select KVM_MMIO ---help---
Signature · 1 line
1.6.0.2
PATCH 23/56 KVM: PPC: booke: remove leftover debugging
In reply to Alexander GrafThe e500mc patches left some debug code in that we don't need. Remove it.
--- arch/powerpc/kvm/booke.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
arch/powerpc/kvm/booke.c +0 -5
@@ -469,11 +469,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)return -EINVAL ; } -if (!current->thread.kvm_vcpu) { -WARN (1 ,"no vcpu\n" ); -return -EPERM ; - } -local_irq_disable ();kvmppc_core_prepare_to_enter (vcpu);
Signature · 1 line
1.6.0.2
PATCH 24/56 KVM: PPC: booke: deliver program int on emulation failure
In reply to Alexander GrafWhen we fail to emulate an instruction for the guest, we better go in and tell it that we failed to emulate it, by throwing an illegal instruction exception.
Please beware that we basically never get around to telling the guest that we failed thanks to the debugging code right above it. If user space however decides that it wants to ignore the debug, we would at least do "the right thing" afterwards.
--- arch/powerpc/kvm/booke.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/booke.c +1 -1
@@ -545,13 +545,13 @@ static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu)return RESUME_HOST ;case EMULATE_FAIL : -/* XXX Deliver Program interrupt to guest. */ printk (KERN_CRIT "%s: emulation at %lx failed (%08x)\n" , __func__, vcpu->arch.pc, vcpu->arch.last_inst);/* For debugging, encode the failing instruction and * report it to userspace. */ run->hw.hardware_exit_reason = ~0ULL <<32 ; run->hw.hardware_exit_reason |= vcpu->arch.last_inst; +kvmppc_core_queue_program (vcpu,ESR_PIL );return RESUME_HOST ;default :
Signature · 1 line
1.6.0.2
PATCH 25/56 KVM: PPC: booke: rework rescheduling checks
In reply to Alexander GrafInstead of checking whether we should reschedule only when we exited due to an interrupt, let's always check before entering the guest back again. This gets the target more in line with the other archs.
Also while at it, generalize the whole thing so that eventually we could have a single kvmppc_prepare_to_enter function for all ppc targets that does signal and reschedule checking for us.
--- arch/powerpc/include/asm/kvm_ppc.h | 2 +- arch/powerpc/kvm/book3s.c | 4 +- arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +1 -1
@@ -95,7 +95,7 @@ extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,extern void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu);extern void kvmppc_core_vcpu_put (struct kvm_vcpu *vcpu); -extern void kvmppc_core_prepare_to_enter (struct kvm_vcpu *vcpu); +extern int kvmppc_core_prepare_to_enter (struct kvm_vcpu *vcpu);extern int kvmppc_core_pending_dec (struct kvm_vcpu *vcpu);extern void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags);extern void kvmppc_core_queue_dec (struct kvm_vcpu *vcpu);
arch/powerpc/kvm/book3s.c +3 -1
@@ -258,7 +258,7 @@ static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned int priority)return true; } -void kvmppc_core_prepare_to_enter (struct kvm_vcpu *vcpu) +int kvmppc_core_prepare_to_enter (struct kvm_vcpu *vcpu) {unsigned long *pending = &vcpu->arch.pending_exceptions;unsigned long old_pending = vcpu->arch.pending_exceptions;
@@ -283,6 +283,8 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)/* Tell the guest about our interrupt status */ kvmppc_update_int_pending (vcpu, *pending, old_pending); + +return 0 ; }pfn_t kvmppc_gfn_to_pfn (struct kvm_vcpu *vcpu,gfn_t gfn)
arch/powerpc/kvm/booke.c +50 -22
120 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 26/56 KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1
In reply to Alexander GrafThe semantics of BOOKE_IRQPRIO_MAX changed to denote the highest available irqprio + 1, so let's reflect that in the code too.
--- arch/powerpc/kvm/booke.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/booke.c +1 -1
@@ -425,7 +425,7 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) } priority =__ffs (*pending); -while (priority <=BOOKE_IRQPRIO_MAX ) { +while (priority <BOOKE_IRQPRIO_MAX ) {if (kvmppc_booke_irqprio_deliver (vcpu, priority))break ;
Signature · 1 line
1.6.0.2
PATCH 27/56 KVM: PPC: bookehv: fix exit timing
In reply to Alexander GrafWhen using exit timing stats, we clobber r9 in the NEED_EMU case, so better move that part down a few lines and fix it that way.
--- arch/powerpc/kvm/bookehv_interrupts.S | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +4 -4
@@ -83,10 +83,6 @@ stw r10, VCPU_GUEST_PID(r4) mtspr SPRN_PID, r8 - .if \flags & NEED_EMU - lwz r9, VCPU_KVM(r4) - .endif - #ifdef CONFIG_KVM_EXIT_TIMING /* save exit time */ 1: mfspr r7, SPRN_TBRU
@@ -98,6 +94,10 @@ PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4) #endif + .if \flags & NEED_EMU + lwz r9, VCPU_KVM(r4) + .endif + oris r8, r6, MSR_CE@h #ifndef CONFIG_64BIT stw r6, (VCPU_SHARED_MSR + 4)(r11)
Signature · 1 line
1.6.0.2
PATCH 28/56 KVM: PPC: bookehv: remove negation for CONFIG_64BIT
In reply to Alexander GrafInstead if doing
#ifndef CONFIG_64BIT ... #else ... #endif
we should rather do
#ifdef CONFIG_64BIT ... #else ... #endif
which is a lot easier to read. Change the bookehv implementation to stick with this rule.
--- arch/powerpc/kvm/bookehv_interrupts.S | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +12 -12
@@ -99,10 +99,10 @@ .endif oris r8, r6, MSR_CE@h -#ifndef CONFIG_64BIT - stw r6, (VCPU_SHARED_MSR + 4)(r11) -#else +#ifdef CONFIG_64BIT std r6, (VCPU_SHARED_MSR)(r11) +#else + stw r6, (VCPU_SHARED_MSR + 4)(r11) #endif ori r8, r8, MSR_ME | MSR_RI PPC_STL r5, VCPU_PC(r4)
@@ -344,10 +344,10 @@ _GLOBAL(kvmppc_resume_host) stw r5, VCPU_SHARED_MAS0(r11) mfspr r7, SPRN_MAS2 stw r6, VCPU_SHARED_MAS1(r11) -#ifndef CONFIG_64BIT - stw r7, (VCPU_SHARED_MAS2 + 4)(r11) -#else +#ifdef CONFIG_64BIT std r7, (VCPU_SHARED_MAS2)(r11) +#else + stw r7, (VCPU_SHARED_MAS2 + 4)(r11) #endif mfspr r5, SPRN_MAS3 mfspr r6, SPRN_MAS4
@@ -530,10 +530,10 @@ lightweight_exit: stw r3, VCPU_HOST_MAS6(r4) lwz r3, VCPU_SHARED_MAS0(r11) lwz r5, VCPU_SHARED_MAS1(r11) -#ifndef CONFIG_64BIT - lwz r6, (VCPU_SHARED_MAS2 + 4)(r11) -#else +#ifdef CONFIG_64BIT ld r6, (VCPU_SHARED_MAS2)(r11) +#else + lwz r6, (VCPU_SHARED_MAS2 + 4)(r11) #endif lwz r7, VCPU_SHARED_MAS7_3+4(r11) lwz r8, VCPU_SHARED_MAS4(r11)
@@ -572,10 +572,10 @@ lightweight_exit: PPC_LL r6, VCPU_CTR(r4) PPC_LL r7, VCPU_CR(r4) PPC_LL r8, VCPU_PC(r4) -#ifndef CONFIG_64BIT - lwz r9, (VCPU_SHARED_MSR + 4)(r11) -#else +#ifdef CONFIG_64BIT ld r9, (VCPU_SHARED_MSR)(r11) +#else + lwz r9, (VCPU_SHARED_MSR + 4)(r11) #endif PPC_LL r0, VCPU_GPR(r0)(r4) PPC_LL r1, VCPU_GPR(r1)(r4)
Signature · 1 line
1.6.0.2
PATCH 29/56 KVM: PPC: bookehv: remove SET_VCPU
In reply to Alexander GrafThe SET_VCPU macro is a leftover from times when the vcpu struct wasn't stored in the thread on vcpu_load/put. It's not needed anymore. Remove it.
--- arch/powerpc/kvm/bookehv_interrupts.S | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +0 -8
@@ -35,9 +35,6 @@ #define GET_VCPU(vcpu, thread) \ PPC_LL vcpu, THREAD_KVM_VCPU(thread) -#define SET_VCPU(vcpu) \ - PPC_STL vcpu, (THREAD + THREAD_KVM_VCPU)(r2) - #define LONGBYTES (BITS_PER_LONG / 8) #define VCPU_GPR(n) (VCPU_GPRS + (n * LONGBYTES))
@@ -517,11 +514,6 @@ lightweight_exit: lwz r3, VCPU_GUEST_PID(r4) mtspr SPRN_PID, r3 - /* Save vcpu pointer for the exception handlers - * must be done before loading guest r2. - */ -// SET_VCPU(r4) - PPC_LL r11, VCPU_SHARED(r4) /* Save host mas4 and mas6 and load guest MAS registers */ mfspr r3, SPRN_MAS4
Signature · 1 line
1.6.0.2
PATCH 30/56 KVM: PPC: bookehv: disable MAS register updates early
In reply to Alexander GrafWe need to make sure that no MAS updates happen automatically while we have the guest MAS registers loaded. So move the disabling code a bit higher up so that it covers the full time we have guest values in MAS registers.
The race this patch fixes should never occur, but it makes the code a bit more logical to do it this way around.
--- arch/powerpc/kvm/bookehv_interrupts.S | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +6 -4
@@ -358,6 +358,7 @@ _GLOBAL(kvmppc_resume_host) mtspr SPRN_MAS4, r6 stw r5, VCPU_SHARED_MAS7_3+0(r11) mtspr SPRN_MAS6, r8 + /* Enable MAS register updates via exception */ mfspr r3, SPRN_EPCR rlwinm r3, r3, 0, ~SPRN_EPCR_DMIUH mtspr SPRN_EPCR, r3
@@ -515,6 +516,11 @@ lightweight_exit: mtspr SPRN_PID, r3 PPC_LL r11, VCPU_SHARED(r4) + /* Disable MAS register updates via exception */ + mfspr r3, SPRN_EPCR + oris r3, r3, SPRN_EPCR_DMIUH@h + mtspr SPRN_EPCR, r3 + isync /* Save host mas4 and mas6 and load guest MAS registers */ mfspr r3, SPRN_MAS4 stw r3, VCPU_HOST_MAS4(r4)
@@ -538,10 +544,6 @@ lightweight_exit: lwz r5, VCPU_SHARED_MAS7_3+0(r11) mtspr SPRN_MAS6, r3 mtspr SPRN_MAS7, r5 - /* Disable MAS register updates via exception */ - mfspr r3, SPRN_EPCR - oris r3, r3, SPRN_EPCR_DMIUH@h - mtspr SPRN_EPCR, r3 /* * Host interrupt handlers may have clobbered these guest-readable
Signature · 1 line
1.6.0.2
PATCH 31/56 KVM: PPC: bookehv: add comment about shadow_msr
In reply to Alexander GrafFor BookE HV the guest visible MSR is shared->msr and is identical to the MSR that is in use while the guest is running, because we can't trap reads from/to MSR.
So shadow_msr is unused there. Indicate that with a comment.
--- arch/powerpc/include/asm/kvm_host.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -386,6 +386,7 @@ struct kvm_vcpu_arch {#endif u32 vrsave;/* also USPRG0 */ u32 mmucr; +/* shadow_msr is unused for BookE HV */ ulong shadow_msr;ulong csrr0;ulong csrr1;
Signature · 1 line
1.6.0.2
PATCH 32/56 KVM: PPC: booke: Readd debug abort code for machine check
In reply to Alexander GrafWhen during guest execution we get a machine check interrupt, we don't know how to handle it yet. So let's add the error printing code back again that we dropped accidently earlier and tell user space that something went really wrong.
--- arch/powerpc/kvm/booke.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/powerpc/kvm/booke.c +6 -1
@@ -634,7 +634,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,switch (exit_nr) {case BOOKE_INTERRUPT_MACHINE_CHECK : - r =RESUME_GUEST ; +printk ("MACHINE CHECK: %lx\n" ,mfspr (SPRN_MCSR )); +kvmppc_dump_vcpu (vcpu); +/* For debugging, send invalid exit reason to user space */ + run->hw.hardware_exit_reason = ~1ULL <<32 ; + run->hw.hardware_exit_reason |=mfspr (SPRN_MCSR ); + r =RESUME_HOST ;break ;case BOOKE_INTERRUPT_EXTERNAL :
Signature · 1 line
1.6.0.2
PATCH 33/56 KVM: PPC: booke: add GS documentation for program interrupt
In reply to Alexander GrafThe comment for program interrupts triggered when using bookehv was misleading. Update it to mention why MSR_GS indicates that we have to inject an interrupt into the guest again, not emulate it.
--- arch/powerpc/kvm/booke.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
arch/powerpc/kvm/booke.c +8 -2
@@ -685,8 +685,14 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,case BOOKE_INTERRUPT_PROGRAM :if (vcpu->arch.shared->msr & (MSR_PR |MSR_GS )) { -/* Program traps generated by user-level software must be handled -* by the guest kernel. */ +/* +* Program traps generated by user-level software must +* be handled by the guest kernel. +* +* In GS mode, hypervisor privileged instructions trap +* on BOOKE_INTERRUPT_HV_PRIV, not here, so these are +* actual program interrupts, handled by the guest. +*/ kvmppc_core_queue_program (vcpu, vcpu->arch.fault_esr); r =RESUME_GUEST ;kvmppc_account_exit (vcpu,USR_PR_INST );
Signature · 1 line
1.6.0.2
PATCH 34/56 KVM: PPC: bookehv: remove unused code
In reply to Alexander GrafThere was some unused code in the exit code path that must have been a leftover from earlier iterations. While it did no harm, it's superfluous and thus should be removed.
--- arch/powerpc/kvm/bookehv_interrupts.S | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +0 -7
@@ -91,10 +91,6 @@ PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4) #endif - .if \flags & NEED_EMU - lwz r9, VCPU_KVM(r4) - .endif - oris r8, r6, MSR_CE@h #ifdef CONFIG_64BIT std r6, (VCPU_SHARED_MSR)(r11)
@@ -112,9 +108,6 @@ * appropriate for the exception type). */ cmpw r6, r8 - .if \flags & NEED_EMU - lwz r9, KVM_LPID(r9) - .endif beq 1f mfmsr r7 .if \srr0 != SPRN_MCSRR0 && \srr0 != SPRN_CSRR0
Signature · 1 line
1.6.0.2
PATCH 35/56 KVM: PPC: e500: fix typo in tlb code
In reply to Alexander GrafThe tlbncfg registers should be populated with their respective TLB's values. Fix the obvious typo.
--- arch/powerpc/kvm/e500_tlb.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/e500_tlb.c +2 -2
@@ -1268,8 +1268,8 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500) vcpu->arch.tlbcfg[1 ] =mfspr (SPRN_TLB1CFG ) & ~(TLBnCFG_N_ENTRY | TLBnCFG_ASSOC); - vcpu->arch.tlbcfg[0 ] |= vcpu_e500->gtlb_params[1 ].entries; - vcpu->arch.tlbcfg[0 ] |= + vcpu->arch.tlbcfg[1 ] |= vcpu_e500->gtlb_params[1 ].entries; + vcpu->arch.tlbcfg[1 ] |= vcpu_e500->gtlb_params[1 ].ways << TLBnCFG_ASSOC_SHIFT;return 0 ;
Signature · 1 line
1.6.0.2
PATCH 36/56 KVM: PPC: booke: Support perfmon interrupts
In reply to Alexander GrafWhen during guest context we get a performance monitor interrupt, we currently bail out and oops. Let's route it to its correct handler instead.
--- arch/powerpc/kvm/booke.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/kvm/booke.c +4 -0
@@ -679,6 +679,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, r =RESUME_GUEST ;break ; +case BOOKE_INTERRUPT_PERFORMANCE_MONITOR : + r =RESUME_GUEST ; +break ; +case BOOKE_INTERRUPT_HV_PRIV : r =emulation_exit (run, vcpu);break ;
Signature · 1 line
1.6.0.2
PATCH 37/56 KVM: PPC: booke: expose good state on irq reinject
In reply to Alexander GrafWhen reinjecting an interrupt into the host interrupt handler after we're back in host kernel land, we need to tell the kernel where the interrupt happened. We can't tell it that we were in guest state, because that might lead to random code walking host addresses. So instead, we tell it that we came from the interrupt reinject code.
This helps getting reasonable numbers out of perf.
--- arch/powerpc/kvm/booke.c | 56 +++++++++++++++++++++++++++++++++------------ 1 files changed, 41 insertions(+), 15 deletions(-)
arch/powerpc/kvm/booke.c +41 -15
@@ -595,37 +595,63 @@ static int emulation_exit(struct kvm_run *run, struct kvm_vcpu *vcpu) } } -/** -* kvmppc_handle_exit -* -* Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) -*/ -int kvmppc_handle_exit (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int exit_nr) +static void kvmppc_fill_pt_regs (struct pt_regs *regs) { -int r =RESUME_HOST ; +ulong r1, ip, msr, lr; + + asm("mr %0, 1" :"=r" (r1)); + asm("mflr %0" :"=r" (lr)); + asm("mfmsr %0" :"=r" (msr)); + asm("bl 1f; 1: mflr %0" :"=r" (ip)); + +memset (regs,0 ,sizeof (*regs)); + regs->gpr[1 ] = r1; + regs->nip = ip; + regs->msr = msr; + regs->link = lr; +} -/* update before a new last_exit_type is rewritten */ -kvmppc_update_timing_stats (vcpu); +static void kvmppc_restart_interrupt (struct kvm_vcpu *vcpu, +unsigned int exit_nr) +{ +struct pt_regs regs;switch (exit_nr) {case BOOKE_INTERRUPT_EXTERNAL : -do_IRQ (current->thread.regs); +kvmppc_fill_pt_regs (®s); +do_IRQ (®s);break ; -case BOOKE_INTERRUPT_DECREMENTER : -timer_interrupt (current->thread.regs); +kvmppc_fill_pt_regs (®s); +timer_interrupt (®s);break ; -#if defined(CONFIG_PPC_FSL_BOOK3E ) || defined(CONFIG_PPC_BOOK3E_64 )case BOOKE_INTERRUPT_DOORBELL : -doorbell_exception (current->thread.regs); +kvmppc_fill_pt_regs (®s); +doorbell_exception (®s);break ;#endif case BOOKE_INTERRUPT_MACHINE_CHECK :/* FIXME */ break ; } +} + +/** +* kvmppc_handle_exit +* +* Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) +*/ +int kvmppc_handle_exit (struct kvm_run *run,struct kvm_vcpu *vcpu, +unsigned int exit_nr) +{ +int r =RESUME_HOST ; + +/* update before a new last_exit_type is rewritten */ +kvmppc_update_timing_stats (vcpu); + +/* restart interrupts if they were meant for the host */ +kvmppc_restart_interrupt (vcpu, exit_nr);local_irq_enable ();
Signature · 1 line
1.6.0.2
PATCH 38/56 KVM: PPC: booke: Reinject performance monitor interrupts
In reply to Alexander GrafWhen we get a performance monitor interrupt, we need to make sure that the host receives it. So reinject it like we reinject the other host destined interrupts.
--- arch/powerpc/include/asm/hw_irq.h | 1 + arch/powerpc/kvm/booke.c | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/hw_irq.h +1 -0
@@ -12,6 +12,7 @@#include <asm/processor.h> extern void timer_interrupt (struct pt_regs *); +extern void performance_monitor_exception (struct pt_regs *regs);#ifdef CONFIG_PPC64 #include <asm/paca.h>
arch/powerpc/kvm/booke.c +4 -0
@@ -634,6 +634,10 @@ static void kvmppc_restart_interrupt(struct kvm_vcpu *vcpu,case BOOKE_INTERRUPT_MACHINE_CHECK :/* FIXME */ break ; +case BOOKE_INTERRUPT_PERFORMANCE_MONITOR : +kvmppc_fill_pt_regs (®s); +performance_monitor_exception (®s); +break ; } }
Signature · 1 line
1.6.0.2
PATCH 39/56 KVM: PPC: Booke: only prepare to enter when we enter
In reply to Alexander GrafSo far, we've always called prepare_to_enter even when all we did was return to the host. This patch changes that semantic to only call prepare_to_enter when we actually want to get back into the guest.
--- arch/powerpc/kvm/booke.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
arch/powerpc/kvm/booke.c +10 -8
@@ -464,7 +464,7 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)* * returns !0 if a signal is pending and check_signal is true */ -static int kvmppc_prepare_to_enter (struct kvm_vcpu *vcpu,bool check_signal) +static int kvmppc_prepare_to_enter (struct kvm_vcpu *vcpu) {int r =0 ;
@@ -477,7 +477,7 @@ static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu, bool check_signal)continue ; } -if (check_signal &&signal_pending (current)) { +if (signal_pending (current)) { r =1 ;break ; }
@@ -509,7 +509,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) }local_irq_disable (); -if (kvmppc_prepare_to_enter (vcpu, true)) { +if (kvmppc_prepare_to_enter (vcpu)) { kvm_run->exit_reason =KVM_EXIT_INTR ; ret = -EINTR ; goto out;
@@ -946,11 +946,13 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,* To avoid clobbering exit_reason, only check for signals if we * aren't already exiting to userspace for some other reason. */ -local_irq_disable (); -if (kvmppc_prepare_to_enter (vcpu, !(r &RESUME_HOST ))) { - run->exit_reason =KVM_EXIT_INTR ; - r = (-EINTR <<2 ) |RESUME_HOST | (r &RESUME_FLAG_NV ); -kvmppc_account_exit (vcpu,SIGNAL_EXITS ); +if (!(r &RESUME_HOST )) { +local_irq_disable (); +if (kvmppc_prepare_to_enter (vcpu)) { + run->exit_reason =KVM_EXIT_INTR ; + r = (-EINTR <<2 ) |RESUME_HOST | (r &RESUME_FLAG_NV ); +kvmppc_account_exit (vcpu,SIGNAL_EXITS ); + } }return r;
Signature · 1 line
1.6.0.2
PATCH 40/56 KVM: PPC: Book3s: PR: Add SPAPR H_BULK_REMOVE support
In reply to Alexander GrafFrom: Matt Evans <[email protected]>
SPAPR support includes various in-kernel hypercalls, improving performance by cutting out the exit to userspace. H_BULK_REMOVE is implemented in this patch.
--- arch/powerpc/kvm/book3s_pr_papr.c | 82 +++++++++++++++++++++++++++++++++++-- 1 files changed, 78 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_pr_papr.c +77 -4
@@ -98,6 +98,83 @@ static int kvmppc_h_pr_remove(struct kvm_vcpu *vcpu)return EMULATE_DONE ; } +/* Request defs for kvmppc_h_pr_bulk_remove() */ +#define H_BULK_REMOVE_TYPE 0xc000000000000000ULL +#define H_BULK_REMOVE_REQUEST 0x4000000000000000ULL +#define H_BULK_REMOVE_RESPONSE 0x8000000000000000ULL +#define H_BULK_REMOVE_END 0xc000000000000000ULL +#define H_BULK_REMOVE_CODE 0x3000000000000000ULL +#define H_BULK_REMOVE_SUCCESS 0x0000000000000000ULL +#define H_BULK_REMOVE_NOT_FOUND 0x1000000000000000ULL +#define H_BULK_REMOVE_PARM 0x2000000000000000ULL +#define H_BULK_REMOVE_HW 0x3000000000000000ULL +#define H_BULK_REMOVE_RC 0x0c00000000000000ULL +#define H_BULK_REMOVE_FLAGS 0x0300000000000000ULL +#define H_BULK_REMOVE_ABSOLUTE 0x0000000000000000ULL +#define H_BULK_REMOVE_ANDCOND 0x0100000000000000ULL +#define H_BULK_REMOVE_AVPN 0x0200000000000000ULL +#define H_BULK_REMOVE_PTEX 0x00ffffffffffffffULL +#define H_BULK_REMOVE_MAX_BATCH 4 + +static int kvmppc_h_pr_bulk_remove (struct kvm_vcpu *vcpu) +{ +int i; +int paramnr =4 ; +int ret =H_SUCCESS ; + +for (i =0 ; i <H_BULK_REMOVE_MAX_BATCH ; i++) { +unsigned long tsh =kvmppc_get_gpr (vcpu, paramnr+(2 *i)); +unsigned long tsl =kvmppc_get_gpr (vcpu, paramnr+(2 *i)+1 ); +unsigned long pteg, rb, flags; +unsigned long pte[2 ]; +unsigned long v =0 ; + +if ((tsh &H_BULK_REMOVE_TYPE ) =H_BULK_REMOVE_END ) { +break ;/* Exit success */ + } else if ((tsh & H_BULK_REMOVE_TYPE) !+ H_BULK_REMOVE_REQUEST) { + ret =H_PARAMETER ; +break ;/* Exit fail */ + } + + tsh &=H_BULK_REMOVE_PTEX |H_BULK_REMOVE_FLAGS ; + tsh |=H_BULK_REMOVE_RESPONSE ; + +if ((tsh &H_BULK_REMOVE_ANDCOND ) && + (tsh &H_BULK_REMOVE_AVPN )) { + tsh |=H_BULK_REMOVE_PARM ; +kvmppc_set_gpr (vcpu, paramnr+(2 *i), tsh); + ret =H_PARAMETER ; +break ;/* Exit fail */ + } + + pteg =get_pteg_addr (vcpu, tsh &H_BULK_REMOVE_PTEX ); +copy_from_user (pte, (void __user *)pteg,sizeof (pte)); + +/* tsl = AVPN */ + flags = (tsh &H_BULK_REMOVE_FLAGS ) >>26 ; + +if ((pte[0 ] &HPTE_V_VALID ) =0 || + ((flags &H_AVPN ) && (pte[0 ] & ~0x7fUL ) != tsl) || + ((flags &H_ANDCOND ) && (pte[0 ] & tsl) !=0 )) { + tsh |=H_BULK_REMOVE_NOT_FOUND ; + }else { +/* Splat the pteg in (userland) hpt */ +copy_to_user ((void __user *)pteg, &v,sizeof (v)); + + rb =compute_tlbie_rb (pte[0 ], pte[1 ], + tsh &H_BULK_REMOVE_PTEX ); + vcpu->arch.mmu.tlbie (vcpu, rb, rb &1 ? true : false); + tsh |=H_BULK_REMOVE_SUCCESS ; + tsh |= (pte[1 ] & (HPTE_R_C |HPTE_R_R )) <<43 ; + } +kvmppc_set_gpr (vcpu, paramnr+(2 *i), tsh); + } +kvmppc_set_gpr (vcpu,3 , ret); + +return EMULATE_DONE ; +} +static int kvmppc_h_pr_protect (struct kvm_vcpu *vcpu) {unsigned long flags =kvmppc_get_gpr (vcpu,4 );
@@ -144,10 +221,7 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)case H_PROTECT :return kvmppc_h_pr_protect (vcpu);case H_BULK_REMOVE : -/* We just flush all PTEs, so user space can -handle the HPT modifications */ -kvmppc_mmu_pte_flush (vcpu,0 ,0 ); -break ; +return kvmppc_h_pr_bulk_remove (vcpu);case H_CEDE :kvm_vcpu_block (vcpu); vcpu->stat.halt_wakeup++;
Signature · 1 line
1.6.0.2
PATCH 41/56 KVM: PPC: Book3S HV: Fix kvm_alloc_linear in case where no linears exist
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
In kvm_alloc_linear we were using and deferencing ri after the list_for_each_entry had come to the end of the list. In that situation, ri is not really defined and probably points to the list head. This will happen every time if the free_linears list is empty, for instance. This led to a NULL pointer dereference crash in memset on POWER7 while trying to allocate an HPT in the case where no HPTs were preallocated.
This fixes it by using a separate variable for the return value from the loop iterator.
--- arch/powerpc/kvm/book3s_hv_builtin.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_hv_builtin.c +5 -4
@@ -173,9 +173,9 @@ static void __init kvm_linear_init_one(ulong size, int count, int type)static struct kvmppc_linear_info *kvm_alloc_linear (int type) { -struct kvmppc_linear_info *ri; +struct kvmppc_linear_info *ri, *ret; - ri =NULL ; + ret =NULL ;spin_lock (&linear_lock);list_for_each_entry (ri, &free_linears, list) {if (ri->type != type)
@@ -183,11 +183,12 @@ static struct kvmppc_linear_info *kvm_alloc_linear(int type)list_del (&ri->list);atomic_inc (&ri->use_count); +memset (ri->base_virt,0 , ri->npages <<PAGE_SHIFT ); + ret = ri;break ; }spin_unlock (&linear_lock); -memset (ri->base_virt,0 , ri->npages <<PAGE_SHIFT ); -return ri; +return ret; }static void kvm_release_linear (struct kvmppc_linear_info *ri)
Signature · 1 line
1.6.0.2
PATCH 42/56 KVM: PPC: Book3S HV: Save and restore CR in __kvmppc_vcore_entry
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The ABI specifies that CR fields CR2--CR4 are nonvolatile across function calls. Currently __kvmppc_vcore_entry doesn't save and restore the CR, leading to CR2--CR4 getting corrupted with guest values, possibly leading to incorrect behaviour in its caller. This adds instructions to save and restore CR at the points where we save and restore the nonvolatile GPRs.
--- arch/powerpc/kvm/book3s_hv_interrupts.S | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_hv_interrupts.S +6 -2
@@ -46,8 +46,10 @@ _GLOBAL(__kvmppc_vcore_entry) /* Save host state to the stack */ stdu r1, -SWITCH_FRAME_SIZE(r1) - /* Save non-volatile registers (r14 - r31) */ + /* Save non-volatile registers (r14 - r31) and CR */ SAVE_NVGPRS(r1) + mfcr r3 + std r3, _CCR(r1) /* Save host DSCR */ BEGIN_FTR_SECTION
@@ -157,8 +159,10 @@ kvmppc_handler_highmem: * R13 = PACA */ - /* Restore non-volatile host registers (r14 - r31) */ + /* Restore non-volatile host registers (r14 - r31) and CR */ REST_NVGPRS(r1) + ld r4, _CCR(r1) + mtcr r4 addi r1, r1, SWITCH_FRAME_SIZE ld r0, PPC_LR_STKOFF(r1)
Signature · 1 line
1.6.0.2
PATCH 43/56 KVM: PPC: Save/Restore CR over vcpu_run
In reply to Alexander GrafOn PPC, CR2-CR4 are nonvolatile, thus have to be saved across function calls. We didn't respect that for any architecture until Paul spotted it in his patch for Book3S-HV. This patch saves/restores CR for all KVM capable PPC hosts.
--- arch/powerpc/kvm/book3s_interrupts.S | 7 +++++++ arch/powerpc/kvm/booke_interrupts.S | 7 ++++++- arch/powerpc/kvm/bookehv_interrupts.S | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_interrupts.S +7 -0
@@ -84,6 +84,10 @@ kvm_start_entry: /* Save non-volatile registers (r14 - r31) */ SAVE_NVGPRS(r1) + /* Save CR */ + mfcr r14 + stw r14, _CCR(r1) + /* Save LR */ PPC_STL r0, _LINK(r1)
@@ -165,6 +169,9 @@ kvm_exit_loop: PPC_LL r4, _LINK(r1) mtlr r4 + lwz r14, _CCR(r1) + mtcr r14 + /* Restore non-volatile host registers (r14 - r31) */ REST_NVGPRS(r1)
arch/powerpc/kvm/booke_interrupts.S +6 -1
@@ -34,7 +34,8 @@ /* r2 is special: it holds 'current', and it made nonvolatile in the * kernel with the -ffixed-r2 gcc option. */ #define HOST_R2 12 -#define HOST_NV_GPRS 16 +#define HOST_CR 16 +#define HOST_NV_GPRS 20 #define HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * 4)) #define HOST_MIN_STACK_SIZE (HOST_NV_GPR(31) + 4) #define HOST_STACK_SIZE (((HOST_MIN_STACK_SIZE + 15) / 16) * 16) /* Align. */
@@ -296,8 +297,10 @@ heavyweight_exit: /* Return to kvm_vcpu_run(). */ lwz r4, HOST_STACK_LR(r1) + lwz r5, HOST_CR(r1) addi r1, r1, HOST_STACK_SIZE mtlr r4 + mtcr r5 /* r3 still contains the return code from kvmppc_handle_exit(). */ blr
@@ -314,6 +317,8 @@ _GLOBAL(__kvmppc_vcpu_run) stw r3, HOST_RUN(r1) mflr r3 stw r3, HOST_STACK_LR(r1) + mfcr r5 + stw r5, HOST_CR(r1) /* Save host non-volatile register state to stack. */ stw r14, HOST_NV_GPR(r14)(r1)
arch/powerpc/kvm/bookehv_interrupts.S +7 -1
@@ -49,7 +49,8 @@ * kernel with the -ffixed-r2 gcc option. */ #define HOST_R2 (3 * LONGBYTES) -#define HOST_NV_GPRS (4 * LONGBYTES) +#define HOST_CR (4 * LONGBYTES) +#define HOST_NV_GPRS (5 * LONGBYTES) #define HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * LONGBYTES)) #define HOST_MIN_STACK_SIZE (HOST_NV_GPR(31) + LONGBYTES) #define HOST_STACK_SIZE ((HOST_MIN_STACK_SIZE + 15) & ~15) /* Align. */
@@ -396,6 +397,7 @@ skip_nv_load: heavyweight_exit: /* Not returning to guest. */ PPC_LL r5, HOST_STACK_LR(r1) + lwz r6, HOST_CR(r1) /* * We already saved guest volatile register state; now save the
@@ -442,6 +444,7 @@ heavyweight_exit: /* Return to kvm_vcpu_run(). */ mtlr r5 + mtcr r6 addi r1, r1, HOST_STACK_SIZE /* r3 still contains the return code from kvmppc_handle_exit(). */ blr
@@ -457,8 +460,11 @@ _GLOBAL(__kvmppc_vcpu_run) /* Save host state to stack. */ PPC_STL r3, HOST_RUN(r1) mflr r3 + mfcr r5 PPC_STL r3, HOST_STACK_LR(r1) + stw r5, HOST_CR(r1) + /* Save host non-volatile register state to stack. */ PPC_STL r14, HOST_NV_GPR(r14)(r1) PPC_STL r15, HOST_NV_GPR(r15)(r1)
Signature · 1 line
1.6.0.2
PATCH 44/56 KVM: PPC: Book3S HV: Make secondary threads more robust against stray IPIs
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently on POWER7, if we are running the guest on a core and we don't need all the hardware threads, we do nothing to ensure that the unused threads aren't executing in the kernel (other than checking that they are offline). We just assume they're napping and we don't do anything to stop them trying to enter the kernel while the guest is running. This means that a stray IPI can wake up the hardware thread and it will then try to enter the kernel, but since the core is in guest context, it will execute code from the guest in hypervisor mode once it turns the MMU on, which tends to lead to crashes or hangs in the host.
This fixes the problem by adding two new one-byte flags in the kvmppc_host_state structure in the PACA which are used to interlock between the primary thread and the unused secondary threads when entering the guest. With these flags, the primary thread can ensure that the unused secondaries are not already in kernel mode (i.e. handling a stray IPI) and then indicate that they should not try to enter the kernel if they do get woken for any reason. Instead they will go into KVM code, find that there is no vcpu to run, acknowledge and clear the IPI and go back to nap mode.
--- arch/powerpc/include/asm/kvm_book3s_asm.h | 8 +++ arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kernel/exceptions-64s.S | 12 ++-- arch/powerpc/kernel/idle_power7.S | 7 ++ arch/powerpc/kvm/book3s_hv.c | 49 ++++++++++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 92 +++++++++++++++++------------ 6 files changed, 124 insertions(+), 46 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +8 -0
@@ -79,6 +79,9 @@ struct kvmppc_host_state {u8 napping;#ifdef CONFIG_KVM_BOOK3S_64_HV +u8 hwthread_req; +u8 hwthread_state; +struct kvm_vcpu *kvm_vcpu;struct kvmppc_vcore *kvm_vcore;unsigned long xics_phys;
@@ -122,4 +125,9 @@ struct kvmppc_book3s_shadow_vcpu {#endif /*__ASSEMBLY__ */ +/* Values for kvm_state */ +#define KVM_HWTHREAD_IN_KERNEL 0 +#define KVM_HWTHREAD_IN_NAP 1 +#define KVM_HWTHREAD_IN_KVM 2 +#endif /* __ASM_KVM_BOOK3S_ASM_H__ */
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -554,6 +554,8 @@ int main(void)HSTATE_FIELD (HSTATE_IN_GUEST , in_guest);HSTATE_FIELD (HSTATE_RESTORE_HID5 , restore_hid5);HSTATE_FIELD (HSTATE_NAPPING , napping); +HSTATE_FIELD (HSTATE_HWTHREAD_REQ , hwthread_req); +HSTATE_FIELD (HSTATE_HWTHREAD_STATE , hwthread_state);#ifdef CONFIG_KVM_BOOK3S_64_HV HSTATE_FIELD (HSTATE_KVM_VCPU , kvm_vcpu);
arch/powerpc/kernel/exceptions-64s.S +7 -5
@@ -62,11 +62,13 @@ BEGIN_FTR_SECTION GET_PACA(r13) #ifdef CONFIG_KVM_BOOK3S_64_HV - lbz r0,PACAPROCSTART(r13) - cmpwi r0,0x80 - bne 1f - li r0,1 - stb r0,PACAPROCSTART(r13) + li r0,KVM_HWTHREAD_IN_KERNEL + stb r0,HSTATE_HWTHREAD_STATE(r13) + /* Order setting hwthread_state vs. testing hwthread_req */ + sync + lbz r0,HSTATE_HWTHREAD_REQ(r13) + cmpwi r0,0 + beq 1f b kvm_start_guest 1: #endif
arch/powerpc/kernel/idle_power7.S +7 -0
@@ -15,6 +15,7 @@ #include <asm/ppc_asm.h> #include <asm/asm-offsets.h> #include <asm/ppc-opcode.h> +#include <asm/kvm_book3s_asm.h> #undef DEBUG
@@ -64,6 +65,12 @@ _GLOBAL(power7_idle) std r9,_MSR(r1) std r1,PACAR1(r13) +#ifdef CONFIG_KVM_BOOK3S_64_HV + /* Tell KVM we're napping */ + li r4,KVM_HWTHREAD_IN_NAP + stb r4,HSTATE_HWTHREAD_STATE(r13) +#endif + /* Magic NAP mode enter sequence */ std r0,0(r1) ptesync
arch/powerpc/kvm/book3s_hv.c +46 -3
79 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +54 -38
138 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 45/56 KVM: PPC: Book3S HV: Make virtual processor area registration more robust
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The PAPR API allows three sorts of per-virtual-processor areas to be registered (VPA, SLB shadow buffer, and dispatch trace log), and furthermore, these can be registered and unregistered for another virtual CPU. Currently we just update the vcpu fields pointing to these areas at the time of registration or unregistration. If this is done on another vcpu, there is the possibility that the target vcpu is using those fields at the time and could end up using a bogus pointer and corrupting memory.
This fixes the race by making the target cpu itself do the update, so we can be sure that the update happens at a time when the fields aren't being used. Each area now has a struct kvmppc_vpa which is used to manage these updates. There is also a spinlock which protects access to all of the kvmppc_vpa structs, other than to the pinned_addr fields. (We could have just taken the spinlock when using the vpa, slb_shadow or dtl fields, but that would mean taking the spinlock on every guest entry and exit.)
This also changes 'struct dtl' (which was undefined) to 'struct dtl_entry', which is what the rest of the kernel uses.
Thanks to Michael Ellerman <[email protected]> for pointing out the need to initialize vcpu->arch.vpa_update_lock.
--- arch/powerpc/include/asm/hvcall.h | 10 ++ arch/powerpc/include/asm/kvm_host.h | 27 ++++- arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 227 ++++++++++++++++++++++++----------- 4 files changed, 190 insertions(+), 76 deletions(-)
arch/powerpc/include/asm/hvcall.h +10 -0
@@ -114,6 +114,16 @@#define H_PP1 (1UL<<(63-62))#define H_PP2 (1UL<<(63-63)) +/* Flags for H_REGISTER_VPA subfunction field */ +#define H_VPA_FUNC_SHIFT (63-18)/* Bit posn of subfunction code */ +#define H_VPA_FUNC_MASK 7UL +#define H_VPA_REG_VPA 1UL/* Register Virtual Processor Area */ +#define H_VPA_REG_DTL 2UL/* Register Dispatch Trace Log */ +#define H_VPA_REG_SLB 3UL/* Register SLB shadow buffer */ +#define H_VPA_DEREG_VPA 5UL/* Deregister Virtual Processor Area */ +#define H_VPA_DEREG_DTL 6UL/* Deregister Dispatch Trace Log */ +#define H_VPA_DEREG_SLB 7UL/* Deregister SLB shadow buffer */ +/* VASI States */ #define H_VASI_INVALID 0#define H_VASI_ENABLED 1
arch/powerpc/include/asm/kvm_host.h +21 -6
@@ -82,7 +82,7 @@ struct kvm_vcpu;struct lppaca ;struct slb_shadow ; -struct dtl ; +struct dtl_entry ;struct kvm_vm_stat {u32 remote_tlb_flush;
@@ -279,6 +279,19 @@ struct kvmppc_vcore {#define VCORE_EXITING 2#define VCORE_SLEEPING 3 +/* +* Struct used to manage memory for a virtual processor area +* registered by a PAPR guest. There are three types of area +* that a guest can register. +*/ +struct kvmppc_vpa { +void *pinned_addr;/* Address in kernel linear mapping */ +void *pinned_end;/* End of region */ +unsigned long next_gpa;/* Guest phys addr for update */ +unsigned long len;/* Number of bytes required */ +u8 update_pending;/* 1 => update pinned_addr from next_gpa */ +}; +struct kvmppc_pte {ulong eaddr;u64 vpage;
@@ -473,11 +486,6 @@ struct kvm_vcpu_arch {u8 prodded;u32 last_inst; -struct lppaca *vpa; -struct slb_shadow *slb_shadow; -struct dtl *dtl; -struct dtl *dtl_end; -wait_queue_head_t *wqp;struct kvmppc_vcore *vcore;int ret;
@@ -502,6 +510,13 @@ struct kvm_vcpu_arch {struct task_struct *run_task;struct kvm_run *kvm_run;pgd_t *pgdir; + +spinlock_t vpa_update_lock; +struct kvmppc_vpa vpa; +struct kvmppc_vpa dtl; +struct dtl_entry *dtl_ptr; +unsigned long dtl_index; +struct kvmppc_vpa slb_shadow;#endif };
arch/powerpc/kernel/asm-offsets.c +1 -1
@@ -480,7 +480,7 @@ int main(void) DEFINE(VCPU_PENDING_EXC, offsetof(struct kvm_vcpu, arch.pending_exceptions)); DEFINE(VCPU_CEDED, offsetof(struct kvm_vcpu, arch.ceded)); DEFINE(VCPU_PRODDED, offsetof(struct kvm_vcpu, arch.prodded)); - DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa)); + DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr)); 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_hv.c +158 -69
278 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 46/56 KVM: PPC: Book3S HV: Report stolen time to guest through dispatch trace log
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This adds code to measure "stolen" time per virtual core in units of timebase ticks, and to report the stolen time to the guest using the dispatch trace log (DTL). The guest can register an area of memory for the DTL for a given vcpu. The DTL is a ring buffer where KVM fills in one entry every time it enters the guest for that vcpu.
Stolen time is measured as time when the virtual core is not running, either because the vcore is not runnable (e.g. some of its vcpus are executing elsewhere in the kernel or in userspace), or when the vcpu thread that is running the vcore is preempted. This includes time when all the vcpus are idle (i.e. have executed the H_CEDE hypercall), which is OK because the guest accounts stolen time while idle as idle time.
Each vcpu keeps a record of how much stolen time has been reported to the guest for that vcpu so far. When we are about to enter the guest, we create a new DTL entry (if the guest vcpu has a DTL) and report the difference between total stolen time for the vcore and stolen time reported so far for the vcpu as the "enqueue to dispatch" time in the DTL entry.
--- arch/powerpc/include/asm/kvm_host.h | 4 +++ arch/powerpc/kvm/book3s_hv.c | 46 ++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm_host.h +4 -0
@@ -268,6 +268,9 @@ struct kvmppc_vcore {struct list_head runnable_threads;spinlock_t lock;wait_queue_head_t wq; +u64 stolen_tb; +u64 preempt_tb; +struct kvm_vcpu *runner; };#define VCORE_ENTRY_COUNT (vc) ((vc)->entry_exit_count & 0xff)
@@ -516,6 +519,7 @@ struct kvm_vcpu_arch {struct kvmppc_vpa dtl;struct dtl_entry *dtl_ptr;unsigned long dtl_index; +u64 stolen_logged;struct kvmppc_vpa slb_shadow;#endif };
arch/powerpc/kvm/book3s_hv.c +45 -1
105 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 47/56 Restore guest CR after exit timing calculation
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
No instruction which can change Condition Register (CR) should be executed after Guest CR is loaded. So the guest CR is restored after the Exit Timing in lightweight_exit executes cmpw, which can clobber CR.
--- arch/powerpc/kvm/bookehv_interrupts.S | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
arch/powerpc/kvm/bookehv_interrupts.S +8 -3
@@ -580,7 +580,6 @@ lightweight_exit: mtlr r3 mtxer r5 mtctr r6 - mtcr r7 mtsrr0 r8 mtsrr1 r9
@@ -588,14 +587,20 @@ lightweight_exit: /* save enter time */ 1: mfspr r6, SPRN_TBRU - mfspr r7, SPRN_TBRL + mfspr r9, SPRN_TBRL mfspr r8, SPRN_TBRU cmpw r8, r6 - PPC_STL r7, VCPU_TIMING_LAST_ENTER_TBL(r4) + PPC_STL r9, VCPU_TIMING_LAST_ENTER_TBL(r4) bne 1b PPC_STL r8, VCPU_TIMING_LAST_ENTER_TBU(r4) #endif + /* + * Don't execute any instruction which can change CR after + * below instruction. + */ + mtcr r7 + /* Finish loading guest volatiles and jump to guest. */ PPC_LL r5, VCPU_GPR(r5)(r4) PPC_LL r6, VCPU_GPR(r6)(r4)
Signature · 1 line
1.6.0.2
PATCH 48/56 KVM: PPC: Book 3S: Fix compilation for !HV configs
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Commits 2f5cdd5487 ("KVM: PPC: Book3S HV: Make secondary threads more robust against stray IPIs") and 1c2066b0f7 ("KVM: PPC: Book3S HV: Make virtual processor area registration more robust") added fields to struct kvm_vcpu_arch inside #ifdef CONFIG_KVM_BOOK3S_64_HV regions, and added lines to arch/powerpc/kernel/asm-offsets.c to generate assembler constants for their offsets. Unfortunately this led to compile errors on Book 3S machines for configs that had KVM enabled but not CONFIG_KVM_BOOK3S_64_HV. This fixes the problem by moving the offending lines inside #ifdef CONFIG_KVM_BOOK3S_64_HV regions.
--- arch/powerpc/kernel/asm-offsets.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kernel/asm-offsets.c +3 -3
@@ -464,6 +464,7 @@ int main(void) DEFINE(KVM_VRMA_SLB_V, offsetof(struct kvm, arch.vrma_slb_v)); DEFINE(VCPU_DSISR, offsetof(struct kvm_vcpu, arch.shregs.dsisr)); DEFINE(VCPU_DAR, offsetof(struct kvm_vcpu, arch.shregs.dar)); + DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr));#endif #ifdef CONFIG_PPC_BOOK3S DEFINE (VCPU_VCPUID , offsetof(struct kvm_vcpu , vcpu_id));
@@ -480,7 +481,6 @@ int main(void) DEFINE(VCPU_PENDING_EXC, offsetof(struct kvm_vcpu, arch.pending_exceptions)); DEFINE(VCPU_CEDED, offsetof(struct kvm_vcpu, arch.ceded)); DEFINE(VCPU_PRODDED, offsetof(struct kvm_vcpu, arch.prodded)); - DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr)); 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));
@@ -554,10 +554,10 @@ int main(void)HSTATE_FIELD (HSTATE_IN_GUEST , in_guest);HSTATE_FIELD (HSTATE_RESTORE_HID5 , restore_hid5);HSTATE_FIELD (HSTATE_NAPPING , napping); -HSTATE_FIELD (HSTATE_HWTHREAD_REQ , hwthread_req); -HSTATE_FIELD (HSTATE_HWTHREAD_STATE , hwthread_state);#ifdef CONFIG_KVM_BOOK3S_64_HV +HSTATE_FIELD (HSTATE_HWTHREAD_REQ , hwthread_req); +HSTATE_FIELD (HSTATE_HWTHREAD_STATE , hwthread_state);HSTATE_FIELD (HSTATE_KVM_VCPU , kvm_vcpu);HSTATE_FIELD (HSTATE_KVM_VCORE , kvm_vcore);HSTATE_FIELD (HSTATE_XICS_PHYS , xics_phys);
Signature · 1 line
1.6.0.2
PATCH 49/56 KVM: PPC: Work around POWER7 DABR corruption problem
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
It turns out that on POWER7, writing to the DABR can cause a corrupted value to be written if the PMU is active and updating SDAR in continuous sampling mode. To work around this, we make sure that the PMU is inactive and SDAR updates are disabled (via MMCRA) when we are context-switching DABR.
When the guest sets DABR via the H_SET_DABR hypercall, we use a slightly different workaround, which is to read back the DABR and write it again if it got corrupted.
While we are at it, make it consistent that the saving and restoring of the guest's non-volatile GPRs and the FPRs are done with the guest setup of the PMU active.
--- arch/powerpc/kvm/book3s_hv_interrupts.S | 9 ++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 93 ++++++++++++++++++------------- 2 files changed, 61 insertions(+), 41 deletions(-)
arch/powerpc/kvm/book3s_hv_interrupts.S +7 -2
@@ -68,19 +68,24 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) rotldi r10,r10,16 mtmsrd r10,1 - /* Save host PMU registers and load guest PMU registers */ + /* Save host PMU registers */ /* R4 is live here (vcpu pointer) but not r3 or r5 */ li r3, 1 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ mfspr r7, SPRN_MMCR0 /* save MMCR0 */ mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */ + mfspr r6, SPRN_MMCRA +BEGIN_FTR_SECTION + /* On P7, clear MMCRA in order to disable SDAR updates */ + li r5, 0 + mtspr SPRN_MMCRA, r5 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) isync ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */ lbz r5, LPPACA_PMCINUSE(r3) cmpwi r5, 0 beq 31f /* skip if not */ mfspr r5, SPRN_MMCR1 - mfspr r6, SPRN_MMCRA std r7, HSTATE_MMCR(r13) std r5, HSTATE_MMCR + 8(r13) std r6, HSTATE_MMCR + 16(r13)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +54 -39
166 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 50/56 KVM: PPC: Pass EA to updating emulation ops
In reply to Alexander GrafWhen emulating updating load/store instructions (lwzu, stwu, ...) we need to write the effective address of the load/store into a register.
Currently, we write the physical address in there, which is very wrong. So instead let's save off where the virtual fault was on MMIO and use that information as value to put into the register.
While at it, also move the XOP variants of the above instructions to the new scheme of using the already known vaddr instead of calculating it themselves.
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 5 ++- arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/booke.c | 1 + arch/powerpc/kvm/emulate.c | 39 +++++++++------------------------- 5 files changed, 17 insertions(+), 30 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -464,6 +464,7 @@ struct kvm_vcpu_arch {u32 epr;#endif gpa_t paddr_accessed; +gva_t vaddr_accessed;u8 io_gpr;/* GPR used as IO source/target */ u8 mmio_is_bigendian;
arch/powerpc/kvm/book3s_64_mmu_hv.c +3 -2
@@ -447,7 +447,7 @@ static int instruction_is_store(unsigned int instr) }static int kvmppc_hv_emulate_mmio (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned long gpa,int is_store) +unsigned long gpa,gva_t ea,int is_store) {int ret;u32 last_inst;
@@ -494,6 +494,7 @@ static int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu,*/ vcpu->arch.paddr_accessed = gpa; + vcpu->arch.vaddr_accessed = ea;return kvmppc_emulate_mmio (run, vcpu); }
@@ -547,7 +548,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,/* No memslot means it's an emulated MMIO region */ if (!memslot || (memslot->flags &KVM_MEMSLOT_INVALID )) {unsigned long gpa = (gfn <<PAGE_SHIFT ) | (ea & (psize -1 )); -return kvmppc_hv_emulate_mmio (run, vcpu, gpa, +return kvmppc_hv_emulate_mmio (run, vcpu, gpa, ea, dsisr &DSISR_ISSTORE ); }
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -350,6 +350,7 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu,/* MMIO */ vcpu->stat.mmio_exits++; vcpu->arch.paddr_accessed = pte.raddr; + vcpu->arch.vaddr_accessed = pte.eaddr; r =kvmppc_emulate_mmio (run, vcpu);if ( r ==RESUME_HOST_NV ) r =RESUME_HOST ;
arch/powerpc/kvm/booke.c +1 -0
@@ -875,6 +875,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,/* Guest has mapped and accessed a page which is not * actually RAM. */ vcpu->arch.paddr_accessed = gpaddr; + vcpu->arch.vaddr_accessed = eaddr; r =kvmppc_emulate_mmio (run, vcpu);kvmppc_account_exit (vcpu,MMIO_EXITS ); }
arch/powerpc/kvm/emulate.c +11 -28
@@ -141,7 +141,6 @@ u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb)int kvmppc_emulate_instruction (struct kvm_run *run,struct kvm_vcpu *vcpu) {u32 inst =kvmppc_get_last_inst (vcpu); -u32 ea;int ra;int rb;int rs;
@@ -185,12 +184,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rb =get_rb (inst); - ea =kvmppc_get_gpr (vcpu, rb); -if (ra) - ea +=kvmppc_get_gpr (vcpu, ra); - emulated =kvmppc_handle_load (run, vcpu, rt,1 ,1 ); -kvmppc_set_gpr (vcpu, ra, ea); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_31_XOP_STWX :
@@ -212,14 +207,10 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rb =get_rb (inst); - ea =kvmppc_get_gpr (vcpu, rb); -if (ra) - ea +=kvmppc_get_gpr (vcpu, ra); - emulated =kvmppc_handle_store (run, vcpu,kvmppc_get_gpr (vcpu, rs),1 ,1 ); -kvmppc_set_gpr (vcpu, rs, ea); +kvmppc_set_gpr (vcpu, rs, vcpu->arch.vaddr_accessed);break ;case OP_31_XOP_LHAX :
@@ -237,12 +228,8 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rb =get_rb (inst); - ea =kvmppc_get_gpr (vcpu, rb); -if (ra) - ea +=kvmppc_get_gpr (vcpu, ra); - emulated =kvmppc_handle_load (run, vcpu, rt,2 ,1 ); -kvmppc_set_gpr (vcpu, ra, ea); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_31_XOP_MFSPR :
@@ -318,14 +305,10 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rb =get_rb (inst); - ea =kvmppc_get_gpr (vcpu, rb); -if (ra) - ea +=kvmppc_get_gpr (vcpu, ra); - emulated =kvmppc_handle_store (run, vcpu,kvmppc_get_gpr (vcpu, rs),2 ,1 ); -kvmppc_set_gpr (vcpu, ra, ea); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_31_XOP_MTSPR :
@@ -429,7 +412,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rt =get_rt (inst); emulated =kvmppc_handle_load (run, vcpu, rt,4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_LBZ :
@@ -441,7 +424,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rt =get_rt (inst); emulated =kvmppc_handle_load (run, vcpu, rt,1 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_STW :
@@ -457,7 +440,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) emulated =kvmppc_handle_store (run, vcpu,kvmppc_get_gpr (vcpu, rs),4 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_STB :
@@ -473,7 +456,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) emulated =kvmppc_handle_store (run, vcpu,kvmppc_get_gpr (vcpu, rs),1 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_LHZ :
@@ -485,7 +468,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rt =get_rt (inst); emulated =kvmppc_handle_load (run, vcpu, rt,2 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_LHA :
@@ -497,7 +480,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) ra =get_ra (inst); rt =get_rt (inst); emulated =kvmppc_handle_loads (run, vcpu, rt,2 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;case OP_STH :
@@ -513,7 +496,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) emulated =kvmppc_handle_store (run, vcpu,kvmppc_get_gpr (vcpu, rs),2 ,1 ); -kvmppc_set_gpr (vcpu, ra, vcpu->arch.paddr_accessed); +kvmppc_set_gpr (vcpu, ra, vcpu->arch.vaddr_accessed);break ;default :
Signature · 1 line
1.6.0.2
PATCH 51/56 KVM: PPC: Book3S: Compile fix for ppc32 in HIOR
In reply to Alexander GrafOn PPC32 we can not use get_user/put_user for 64bit wide variables, as there is no single instruction that could load or store variables that big.
So instead, we have to use copy_from/to_user which works everywhere.
--- arch/powerpc/kvm/book3s_pr.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_pr.c +4 -4
@@ -881,8 +881,8 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)switch (reg->id) {case KVM_REG_PPC_HIOR : - r =put_user (to_book3s (vcpu)->hior, - (u64 __user *)(long )reg->addr); + r =copy_to_user ((u64 __user *)(long )reg->addr, + &to_book3s (vcpu)->hior,sizeof (u64));break ;default :break ;
@@ -897,8 +897,8 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)switch (reg->id) {case KVM_REG_PPC_HIOR : - r =get_user (to_book3s (vcpu)->hior, - (u64 __user *)(long )reg->addr); + r =copy_from_user (&to_book3s (vcpu)->hior, + (u64 __user *)(long )reg->addr,sizeof (u64));if (!r)to_book3s (vcpu)->hior_explicit = true;break ;
Signature · 1 line
1.6.0.2
PATCH 52/56 KVM: PPC: Emulate tw and td instructions
In reply to Alexander GrafThere are 4 conditional trapping instructions: tw, twi, td, tdi. The ones with an i take an immediate comparison, the others compare two registers. All of them arrive in the emulator when the condition to trap was successfully fulfilled.
Unfortunately, we were only implementing the i versions so far, so let's also add support for the other two.
This fixes kernel booting with recents book3s_32 guest kernels.
--- arch/powerpc/kvm/emulate.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
arch/powerpc/kvm/emulate.c +14 -0
@@ -35,7 +35,9 @@#define OP_TRAP 3#define OP_TRAP_64 2 +#define OP_31_XOP_TRAP 4#define OP_31_XOP_LWZX 23 +#define OP_31_XOP_TRAP_64 68#define OP_31_XOP_LBZX 87#define OP_31_XOP_STWX 151#define OP_31_XOP_STBX 215
@@ -169,6 +171,18 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)case 31 :switch (get_xop (inst)) { +case OP_31_XOP_TRAP : +#ifdef CONFIG_64BIT +case OP_31_XOP_TRAP_64 : +#endif +#ifdef CONFIG_PPC_BOOK3S +kvmppc_core_queue_program (vcpu,SRR1_PROGTRAP ); +#else +kvmppc_core_queue_program (vcpu, + vcpu->arch.shared->esr |ESR_PTR ); +#endif + advance =0 ; +break ;case OP_31_XOP_LWZX : rt =get_rt (inst); emulated =kvmppc_handle_load (run, vcpu, rt,4 ,1 );
Signature · 1 line
1.6.0.2
PATCH 53/56 KVM: PPC: Book3s: PR: Add HV traps so we can run in HV=1 mode on p7
In reply to Alexander GrafWhen running PR KVM on a p7 system in bare metal, we get HV exits instead of normal supervisor traps. Semantically they are identical though and the HSRR vs SRR difference is already taken care of in the exit code.
So all we need to do is handle them in addition to our normal exits.
--- arch/powerpc/kvm/book3s_pr.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_pr.c +4 -0
@@ -617,10 +617,13 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,break ;/* We're good on these - the host merely wanted to get our attention */ case BOOK3S_INTERRUPT_DECREMENTER : +case BOOK3S_INTERRUPT_HV_DECREMENTER : vcpu->stat.dec_exits++; r =RESUME_GUEST ;break ;case BOOK3S_INTERRUPT_EXTERNAL : +case BOOK3S_INTERRUPT_EXTERNAL_LEVEL : +case BOOK3S_INTERRUPT_EXTERNAL_HV : vcpu->stat.ext_intr_exits++; r =RESUME_GUEST ;break ;
@@ -628,6 +631,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, r =RESUME_GUEST ;break ;case BOOK3S_INTERRUPT_PROGRAM : +case BOOK3S_INTERRUPT_H_EMUL_ASSIST : {enum emulation_result er;struct kvmppc_book3s_shadow_vcpu *svcpu;
Signature · 1 line
1.6.0.2
PATCH 54/56 KVM: PPC: Book3S: PR: Fix preemption
In reply to Alexander GrafWe were leaking preemption counters. Fix the code to always toggle between preempt and non-preempt properly.
--- arch/powerpc/kvm/book3s_pr.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_pr.c +1 -2
@@ -781,6 +781,7 @@ program_interrupt: } } +preempt_disable ();if (!(r &RESUME_HOST )) {/* To avoid clobbering exit_reason, only check for signals if * we aren't already exiting to userspace for some other
@@ -802,8 +803,6 @@ program_interrupt: run->exit_reason =KVM_EXIT_INTR ; r = -EINTR ; }else { -preempt_disable (); -/* In case an interrupt came in that was triggered * from userspace (like DEC), we need to check what * to inject now! */
Signature · 1 line
1.6.0.2
PATCH 55/56 KVM: PPC: Ignore unhalt request from kvm_vcpu_block
In reply to Alexander GrafWhen running kvm_vcpu_block and it realizes that the CPU is actually good to run, we get a request bit set for KVM_REQ_UNHALT. Right now, there's nothing we can do with that bit, so let's unset it right after the call again so we don't get confused in our later checks for pending work.
--- arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/book3s_pr_papr.c | 1 + arch/powerpc/kvm/booke.c | 1 + 3 files changed, 3 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -119,6 +119,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr)if (msr &MSR_POW ) {if (!vcpu->arch.pending_exceptions) {kvm_vcpu_block (vcpu); +clear_bit (KVM_REQ_UNHALT , &vcpu->requests); vcpu->stat.halt_wakeup++;/* Unset POW bit after we woke up */
arch/powerpc/kvm/book3s_pr_papr.c +1 -0
@@ -224,6 +224,7 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)return kvmppc_h_pr_bulk_remove (vcpu);case H_CEDE :kvm_vcpu_block (vcpu); +clear_bit (KVM_REQ_UNHALT , &vcpu->requests); vcpu->stat.halt_wakeup++;return EMULATE_DONE ; }
arch/powerpc/kvm/booke.c +1 -0
@@ -449,6 +449,7 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)if (vcpu->arch.shared->msr &MSR_WE ) {local_irq_enable ();kvm_vcpu_block (vcpu); +clear_bit (KVM_REQ_UNHALT , &vcpu->requests);local_irq_disable ();kvmppc_set_exit_type (vcpu,EMULATED_MTMSRWE_EXITS );
Signature · 1 line
1.6.0.2
PATCH 56/56 powerpc/kvm: Fix magic page vs. 32-bit RTAS on ppc64
In reply to Alexander GrafFrom: Benjamin Herrenschmidt <[email protected]>
When the kernel calls into RTAS, it switches to 32-bit mode. The magic page was is longer accessible in that case, causing the patched instructions in the RTAS call wrapper to crash.
This fixes it by making available a 32-bit mapping of the magic page in that case. This mapping is flushed whenever we switch the kernel back to 64-bit mode.
--- arch/powerpc/kvm/book3s.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s.c +3 -0
@@ -291,6 +291,9 @@ pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn) { ulong mp_pa = vcpu->arch.magic_page_pa; + if (!(vcpu->arch.shared->msr & MSR_SF)) + mp_pa = (uint32_t)mp_pa; + /* Magic page override */ if (unlikely(mp_pa) && unlikely(((gfn << PAGE_SHIFT) & KVM_PAM) =
arch/powerpc/kvm/book3s_pr.c +18 -0
@@ -144,6 +144,21 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 msr) } } +/* +* When switching from 32 to 64-bit, we may have a stale 32-bit +* magic page around, we need to flush it. Typically 32-bit magic +* page will be instanciated when calling into RTAS. Note: We +* assume that such transition only happens while in kernel mode, +* ie, we never transition from user 32-bit to kernel 64-bit with +* a 32-bit magic page around. +*/ +if (vcpu->arch.magic_page_pa && + !(old_msr &MSR_PR ) && !(old_msr &MSR_SF ) && (msr &MSR_SF )) { +/* going from RTAS to normal kernel code */ +kvmppc_mmu_pte_flush (vcpu, (uint32_t )vcpu->arch.magic_page_pa, + ~0xFFFUL ); + } +/* Preload FPU if it's enabled */ if (vcpu->arch.shared->msr &MSR_FP )kvmppc_handle_ext (vcpu,BOOK3S_INTERRUPT_FP_UNAVAIL ,MSR_FP );
@@ -251,6 +266,9 @@ static int kvmppc_visible_gfn(struct kvm_vcpu *vcpu, gfn_t gfn) {ulong mp_pa = vcpu->arch.magic_page_pa; +if (!(vcpu->arch.shared->msr &MSR_SF )) + mp_pa = (uint32_t )mp_pa; +if (unlikely (mp_pa) &&unlikely ((mp_pa &KVM_PAM ) >>PAGE_SHIFT = gfn)) {return 1 ;
Signature · 1 line
1.6.0.2
Quoted 4 lines · Alexander Graf
Hi Avi,
This is my current patch queue for ppc. Please pull.
Pulled, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function