KVM: PPC: e500mc support
Subsystems (3)
cover KVM: PPC: e500mc support
This is Scott's e500mc RFC patch set rebased, berobbed of its pt_regs parts and fixed for bisectability. On top of them, I addressed all the comments that I had on the code and that came up in his code as FIXMEs.
I verified that this patch set works just fine on e500mc and doesn't break e500v2, so I would say it's good to go as it is, unless someone has strong objections to how things are done. Everything hereafter I would prefer to do based on a working upstream version rather than a downstream fork, as that way exposure is a lot higher.
Alex
Alexander Graf (15):
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 and e500mc mutually exclusive
KVM: PPC: booke: remove leftover debugging
KVM: PPC: booke: deliver program int on emulation failure
KVM: PPC: booke: call resched after every exit
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
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 | 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_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 | 22 +- arch/powerpc/include/asm/kvm_ppc.h | 8 + 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 | 15 +- arch/powerpc/kernel/cpu_setup_fsl_booke.S | 1 + arch/powerpc/kernel/head_44x.S | 23 +- arch/powerpc/kernel/head_booke.h | 69 ++- arch/powerpc/kernel/head_fsl_booke.S | 98 ++++- arch/powerpc/kvm/44x.c | 12 + arch/powerpc/kvm/Kconfig | 26 +- arch/powerpc/kvm/Makefile | 15 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 26 +- arch/powerpc/kvm/booke.c | 379 ++++++++++++++--- arch/powerpc/kvm/booke.h | 57 +++- arch/powerpc/kvm/booke_emulate.c | 23 +- arch/powerpc/kvm/bookehv_interrupts.S | 609 +++++++++++++++++++++++++++ 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/powerpc.c | 47 ++- arch/powerpc/kvm/timing.h | 6 + 36 files changed, 2717 insertions(+), 835 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/30 powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit
From: 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 2/30 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 3/30 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
@@ -808,6 +808,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 4/30 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 5/30 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 6/30 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 7/30 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 8/30 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 9/30 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 +114 -346
634 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 10/30 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
148 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 11/30 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 12/30 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 13/30 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
@@ -109,6 +109,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 14/30 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 15/30 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
@@ -230,7 +230,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 ;
@@ -638,7 +638,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 ];
@@ -715,7 +715,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 16/30 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/kvm/booke.c | 6 +++ arch/powerpc/kvm/e500_emulate.c | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 0 deletions(-)
arch/powerpc/kvm/booke.c +6 -0
@@ -326,6 +326,9 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, int_class =INT_CLASS_NONCRIT ;break ;case BOOKE_IRQPRIO_CRITICAL : +#ifdef CONFIG_KVM_E500MC +case BOOKE_IRQPRIO_DBELL_CRIT : +#endif allowed = vcpu->arch.shared->msr &MSR_CE ; allowed = allowed && !crit; msr_mask =MSR_GS |MSR_ME ;
@@ -342,6 +345,9 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, keep_irq = true;/* fall through */ case BOOKE_IRQPRIO_EXTERNAL : +#ifdef CONFIG_KVM_E500MC +case BOOKE_IRQPRIO_DBELL : +#endif 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 17/30 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,7 +322,7 @@ 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 :
@@ -331,13 +331,12 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,#endif 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 :
@@ -350,13 +349,13 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,#endif 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 18/30 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 19/30 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 + lwz r6,TI_PREEMPT(r8) + addi r7,r6,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 + stw r6,TI_PREEMPT(r8) stw r9, VCPU_LAST_INST(r4) .endif
Signature · 1 line
1.6.0.2
PATCH 20/30 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
@@ -766,7 +766,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
@@ -74,7 +74,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
@@ -230,7 +230,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 ;
@@ -638,7 +638,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 ];
@@ -715,7 +715,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 21/30 KVM: PPC: make e500v2 and e500mc mutually exclusive
In reply to Alexander GrafWe can't build e500v2 and e500mc (kvm) support inside the same kernel. 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
@@ -134,7 +134,7 @@ config KVM_E500V2 config KVM_E500MC bool "KVM support for PowerPC E500MC/E5500 processors" - depends on EXPERIMENTAL && PPC_E500MC + depends on EXPERIMENTAL && PPC_E500MC && !KVM_E500V2 select KVM select KVM_MMIO select KVM_BOOKE_HV
Signature · 1 line
1.6.0.2
PATCH 22/30 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
@@ -473,11 +473,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 23/30 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
@@ -549,13 +549,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 24/30 KVM: PPC: booke: call resched after every exit
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.
--- arch/powerpc/kvm/booke.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-)
arch/powerpc/kvm/booke.c +10 -5
@@ -572,6 +572,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, unsigned int exit_nr) {int r =RESUME_HOST ; +int resched_needed =1 ;/* update before a new last_exit_type is rewritten */ kvmppc_update_timing_stats (vcpu);
@@ -602,25 +603,21 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,switch (exit_nr) {case BOOKE_INTERRUPT_MACHINE_CHECK : -kvm_resched (vcpu); r =RESUME_GUEST ;break ;case BOOKE_INTERRUPT_EXTERNAL :kvmppc_account_exit (vcpu,EXT_INTR_EXITS ); -kvm_resched (vcpu); r =RESUME_GUEST ;break ;case BOOKE_INTERRUPT_DECREMENTER :kvmppc_account_exit (vcpu,DEC_EXITS ); -kvm_resched (vcpu); r =RESUME_GUEST ;break ;case BOOKE_INTERRUPT_DOORBELL :kvmppc_account_exit (vcpu,DBELL_EXITS ); -kvm_resched (vcpu); r =RESUME_GUEST ;break ;
@@ -869,8 +866,16 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,BUG (); } -local_irq_disable (); +/* make sure we reschedule if we need to */ +while (resched_needed) { +local_irq_disable (); + resched_needed =need_resched (); +if (resched_needed) { +local_irq_enable (); +cond_resched (); + } + }kvmppc_core_prepare_to_enter (vcpu);if (!(r &RESUME_HOST )) {
Signature · 1 line
1.6.0.2
PATCH 25/30 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
@@ -429,7 +429,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 26/30 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 27/30 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 28/30 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 29/30 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 30/30 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
Re: [PATCH 21/30] KVM: PPC: make e500v2 and e500mc mutually exclusive
In reply to Alexander GrafQuoted 4 lines · Alexander Graf
config
KVM_E500MC
bool "KVM support for PowerPC E500MC/E5500 processors"
- depends on EXPERIMENTAL &&PPC_E500MC
+ depends on EXPERIMENTAL &&PPC_E500MC&& !KVM_E500V2
There was a patch floating around that made a similar change to the platform support, so that you could either build an e500v2 kernel and enable support only for e500v2 board, or you could build an e500mc kernel and enable support only for e500mc boards. Last I heard, the patch wasn't quite working, but that was a while ago.
Is there a connection between this patch and that one?
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 21/30] KVM: PPC: make e500v2 and e500mc mutually exclusive
Quoted 7 lines · On 17.02.2012, at 23:32, Tabi Timur-B04825 wrote:
arch/powerpc/kvm/Kconfig config KVM_E500V2 · line 137
Quoted 4 lines · Alexander Graf
config
KVM_E500MC
bool "KVM support for PowerPC E500MC/E5500 processors"arch/powerpc/kvm/Kconfig +1
-1- depends on EXPERIMENTAL && PPC_E500MC + depends on EXPERIMENTAL && PPC_E500MC && !KVM_E500V2
Quoted 7 lines
There was a patch floating around that made a similar change to the platform support, so that you could either build an e500v2 kernel and enable support only for e500v2 board, or you could build an e500mc kernel and enable support only for e500mc boards. Last I heard, the patch wasn't quite working, but that was a while ago.
Is there a connection between this patch and that one?
No, and the code paths are quite orthogonal. While today it's impossible to build a kernel that can drive e500v2 and e500mc systems, it might be possible one day. That still doesn't buy us KVM compatibility between the two though. And vice versa. We could improve the KVM code to actually be versatile between the two platforms, but then you still couldn't run the same kernel on both ;).
Alex