KVM: PPC: e500mc support v3
Subsystems (3)
cover KVM: PPC: e500mc support v3
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.
v1 -> v2:
- ESR -> GESR
- introduce and use constants for doorbell
- drop e500mc ifdefs for doorbell
- fix whitespace
- use explicit preempt counts in inst fixup
- rework e500v2 kconfig patch
- add patches 31-37
v2 -> v3:
- add patch 38
- check for signals earlier
- also remove "lwz r9, VCPU_KVM(r4)" which was as superfluous
- sync host state instead of guest state to pt_regs
- optimize reinject code path to get out fast when not reinjecting
Alexander Graf (23):
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
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/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_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 | 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 | 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 | 28 +- arch/powerpc/kvm/Makefile | 15 +- arch/powerpc/kvm/book3s.c | 4 +- arch/powerpc/kvm/book3s_64_mmu_hv.c | 26 +- arch/powerpc/kvm/booke.c | 469 +++++++++++++++++---- arch/powerpc/kvm/booke.h | 57 +++- arch/powerpc/kvm/booke_emulate.c | 23 +- arch/powerpc/kvm/bookehv_interrupts.S | 602 +++++++++++++++++++++++++++ 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 + 38 files changed, 2796 insertions(+), 850 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/38 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/38 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/38 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/38 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/38 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/38 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/38 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/38 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/38 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 10/38 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 11/38 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/38 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/38 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]>.
---
v1 -> v2:
- ESR -> GESR
--- 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/38 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/38 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 +338 -0
338 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/38 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.
---
v1 -> v2:
- introduce and use constants
- drop e500mc ifdefs
--- 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 17/38 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 18/38 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/38 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.
---
v1 -> v2:
- fix whitespace
- use explicit preempt counts
--- 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 20/38 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
@@ -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/38 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 22/38 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 23/38 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 24/38 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.
---
v2 -> v3:
- check for signals earlier
--- 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 25/38 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 26/38 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/38 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/38 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/38 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/38 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 31/38 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 32/38 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 33/38 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.
---
v2 -> v3:
- fix commit message
- also remove "lwz r9, VCPU_KVM(r4)" which was as superfluous
--- 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 34/38 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 35/38 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 36/38 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.
---
v2 -> v3:
- actually sync host state
- no need for vcpu in sync
--- 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 37/38 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.
---
v2 -> v3:
- call regs sync directly
--- 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 38/38 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
RE: [PATCH 13/38] KVM: PPC: booke: category E.HV (GS-mode) support
In reply to Alexander GrafQuoted 1,694 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Graf
Sent: Wednesday, February 29, 2012 5:40 AM
To: [email protected]
Cc: [email protected]; [email protected]; Wood Scott-B07421
Subject: [PATCH 13/38] KVM: PPC: booke: category E.HV (GS-mode) supportFrom: 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_KVMsimilarly 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]>.Signed-off-by Scott Wood <[email protected]>[agraf: remove pt_regs usage]Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- ESR -> GESR
--- 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.Sarch/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@@ -0,0 +1,49 @@ +/* +* Copyright 2010-2011 Freescale Semiconductor, Inc. +* +* 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_BOOKE_HV_ASM_H +#define ASM_KVM_BOOKE_HV_ASM_H + +#ifdef __ASSEMBLY__ + +/* +* All exceptions from guest state must go through KVM +* (except for those which are delivered directly to the guest) -- +* there are no exceptions for which we fall through directly to +* the normal host handler. +* +* Expected inputs (normal exceptions): +* SCRATCH0 = saved r10 +* r10 = thread struct +* r11 = appropriate SRR1 variant (currently used as scratch) +* r13 = saved CR +* *(r10 + THREAD_NORMSAVE(0)) = saved r11 +* *(r10 + THREAD_NORMSAVE(2)) = saved r13 +* +* Expected inputs (crit/mcheck/debug exceptions): +* appropriate SCRATCH = saved r8 +* r8 = exception level stack frame +* r9 = *(r8 + _CCR) = saved CR +* r11 = appropriate SRR1 variant (currently used as scratch) +* *(r8 + GPR9) = saved r9 +* *(r8 + GPR10) = saved r10 (r10 not yet clobbered) +* *(r8 + GPR11) = saved r11 +*/ +.macro DO_KVM intno srr1 +#ifdef CONFIG_KVM_BOOKE_HV +BEGIN_FTR_SECTION + mtocrf 0x80, r11 /* check MSR[GS] without clobbering reg */ + bf 3, kvmppc_resume_\intno\()_\srr1 + b kvmppc_handler_\intno\()_\srr1 +kvmppc_resume_\intno\()_\srr1: +END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) +#endif +.endm + +#endif /*__ASSEMBLY__ */ +#endif /* ASM_KVM_BOOKE_HV_ASM_H */ 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- renamed from arch/powerpc/kernel/asm-offsets.c +0
-0
offsets.c
index 8e0db0b..a24f2c0 100644arch/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 && 44xarch/powerpc/kvm/booke.c +81
-1@@ -17,6 +17,8 @@* * Authors: Hollis Blanchard <[email protected]> * Christian Ehrhardt <[email protected]> +* Scott Wood <[email protected]> +* Varun Sethi <[email protected]> */ #include <linux/errno.h> @@ -30,9 +32,12 @@#include <asm/cputable.h> #include <asm/uaccess.h> #include <asm/kvm_ppc.h> -#include "timing.h" #include <asm/cacheflush.h> +#include <asm/dbell.h> +#include <asm/hw_irq.h> +#include <asm/irq.h> +#include "timing.h" #include "booke.h" unsigned long kvmppc_booke_handlers;@@ -55,6 +60,8 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { { "dec", VCPU_STAT(dec_exits) }, { "ext_intr", VCPU_STAT(ext_intr_exits) }, { "halt_wakeup", VCPU_STAT(halt_wakeup) }, + { "doorbell", VCPU_STAT(dbell_exits) }, + { "guest doorbell", VCPU_STAT(gdbell_exits) }, { NULL } };@@ -121,6 +128,10 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) {u32 old_msr = vcpu->arch.shared->msr; +#ifdef CONFIG_KVM_BOOKE_HV + new_msr |=MSR_GS ; +#endif + vcpu->arch.shared->msr = new_msr;kvmppc_mmu_msr_notify (vcpu, old_msr);@@ -195,6 +206,75 @@ void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu,clear_bit (BOOKE_IRQPRIO_EXTERNAL_LEVEL , &vcpu->arch.pending_exceptions); } +static void set_guest_srr (struct kvm_vcpu *vcpu,unsigned long srr0,u32 srr1) +{ +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_GSRR0 , srr0); +mtspr (SPRN_GSRR1 , srr1); +#else + vcpu->arch.shared->srr0 = srr0; + vcpu->arch.shared->srr1 = srr1; +#endif +} + +static void set_guest_csrr (struct kvm_vcpu *vcpu,unsigned long srr0,u32 srr1) +{ + vcpu->arch.csrr0 = srr0; + vcpu->arch.csrr1 = srr1; +} + +static void set_guest_dsrr (struct kvm_vcpu *vcpu,unsigned long srr0,u32 srr1) +{ +if (cpu_has_feature (CPU_FTR_DEBUG_LVL_EXC )) { + vcpu->arch.dsrr0 = srr0; + vcpu->arch.dsrr1 = srr1; + }else { +set_guest_csrr (vcpu, srr0, srr1); + } +} + +static void set_guest_mcsrr (struct kvm_vcpu *vcpu,unsigned long srr0,u32 srr1) +{ + vcpu->arch.mcsrr0 = srr0; + vcpu->arch.mcsrr1 = srr1; +} + +static unsigned long get_guest_dear (struct kvm_vcpu *vcpu) +{ +#ifdef CONFIG_KVM_BOOKE_HV +return mfspr (SPRN_GDEAR ); +#else +return vcpu->arch.shared->dar; +#endif +} + +static void set_guest_dear (struct kvm_vcpu *vcpu,unsigned long dear) +{ +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_GDEAR , dear); +#else + vcpu->arch.shared->dar = dear; +#endif +} + +static unsigned long get_guest_esr (struct kvm_vcpu *vcpu) +{ +#ifdef CONFIG_KVM_BOOKE_HV +return mfspr (SPRN_GESR ); +#else +return vcpu->arch.shared->esr; +#endif +} + +static void set_guest_esr (struct kvm_vcpu *vcpu,u32 esr) +{ +#ifdef CONFIG_KVM_BOOKE_HV +mtspr (SPRN_GESR , esr); +#else + vcpu->arch.shared->esr = esr; +#endif +} +/* Deliver the interrupt of the corresponding priority, if possible. */ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,unsigned int priority)
arch/powerpc/kvm/booke.c +1
-0@@ -206,6 +286,7 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, ulong crit_r1 = kvmppc_get_gpr(vcpu, 1);bool crit;bool keep_irq = false; +enum int_class int_class;/* Truncate crit indicators in 32 bit mode */ arch/powerpc/kvm/booke.c +8
-4if (!(vcpu->arch.shared->msr &MSR_SF )) {@@ -241,16 +322,20 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, case BOOKE_IRQPRIO_AP_UNAVAIL:case BOOKE_IRQPRIO_ALIGNMENT : allowed =1 ; - msr_mask =MSR_CE |MSR_ME |MSR_DE ; + msr_mask =MSR_GS |MSR_CE |MSR_ME |MSR_DE ; + int_class =INT_CLASS_NONCRIT ;break ;case BOOKE_IRQPRIO_CRITICAL : -case BOOKE_IRQPRIO_WATCHDOG : allowed = vcpu->arch.shared->msr &MSR_CE ; - msr_mask =MSR_ME ; + allowed = allowed && !crit; + msr_mask =MSR_GS |MSR_ME ; + int_class =INT_CLASS_CRIT ;break ;case BOOKE_IRQPRIO_MACHINE_CHECK : allowed = vcpu->arch.shared->msr &MSR_ME ; - msr_mask =0 ; + allowed = allowed && !crit; + msr_mask =MSR_GS ; + int_class =INT_CLASS_MC ;break ;case BOOKE_IRQPRIO_DECREMENTER :arch/powerpc/kvm/booke.c +45
-6case BOOKE_IRQPRIO_FIT :@@ -259,28 +344,62 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, case BOOKE_IRQPRIO_EXTERNAL: allowed = vcpu->arch.shared->msr &MSR_EE ; allowed = allowed && !crit; - msr_mask =MSR_CE |MSR_ME |MSR_DE ; + msr_mask =MSR_GS |MSR_CE |MSR_ME |MSR_DE ; + int_class =INT_CLASS_NONCRIT ;break ;case BOOKE_IRQPRIO_DEBUG : allowed = vcpu->arch.shared->msr &MSR_DE ; - msr_mask =MSR_ME ; + allowed = allowed && !crit; + msr_mask =MSR_GS |MSR_ME ; + int_class =INT_CLASS_CRIT ;break ; }if (allowed) { - vcpu->arch.shared->srr0 = vcpu->arch.pc; - vcpu->arch.shared->srr1 = vcpu->arch.shared->msr; +switch (int_class) { +case INT_CLASS_NONCRIT : +set_guest_srr (vcpu, vcpu->arch.pc, + vcpu->arch.shared->msr); +break ; +case INT_CLASS_CRIT : +set_guest_csrr (vcpu, vcpu->arch.pc, + vcpu->arch.shared->msr); +break ; +case INT_CLASS_DBG : +set_guest_dsrr (vcpu, vcpu->arch.pc, + vcpu->arch.shared->msr); +break ; +case INT_CLASS_MC : +set_guest_mcsrr (vcpu, vcpu->arch.pc, + vcpu->arch.shared->msr); +break ; + } + vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority];if (update_esr == true) - vcpu->arch.shared->esr = vcpu->arch.queued_esr; +set_guest_esr (vcpu, vcpu->arch.queued_esr);if (update_dear == true) - vcpu->arch.shared->dar = vcpu->arch.queued_dear; +set_guest_dear (vcpu, vcpu->arch.queued_dear);kvmppc_set_msr (vcpu, vcpu->arch.shared->msr & msr_mask);if (!keep_irq)clear_bit (priority, &vcpu->arch.pending_exceptions); } +#ifdef CONFIG_KVM_BOOKE_HV +/* +* If an interrupt is pending but masked, raise a guest doorbell +* so that we are notified when the guest enables the relevant +* MSR bit. +*/ +if (vcpu->arch.pending_exceptions &BOOKE_IRQMASK_EE ) +kvmppc_set_pending_interrupt (vcpu,INT_CLASS_NONCRIT ); +if (vcpu->arch.pending_exceptions &BOOKE_IRQMASK_CE ) +kvmppc_set_pending_interrupt (vcpu,INT_CLASS_CRIT ); +if (vcpu->arch.pending_exceptions &BOOKE_IRQPRIO_MACHINE_CHECK ) +kvmppc_set_pending_interrupt (vcpu,INT_CLASS_MC ); +#endif +return allowed; }@@ -344,6 +463,11 @@ 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 ();arch/powerpc/kvm/booke.c +88
-12kvmppc_core_prepare_to_enter (vcpu);@@ -363,6 +487,38 @@ out:return ret; } +static int emulation_exit (struct kvm_run *run,struct kvm_vcpu *vcpu) +{ +enum emulation_result er; + + er =kvmppc_emulate_instruction (run, vcpu); +switch (er) { +case EMULATE_DONE : +/* don't overwrite subtypes, just account kvm_stats */ +kvmppc_account_exit_stat (vcpu,EMULATED_INST_EXITS ); +/* Future optimization: only reload non-volatiles if +* they were actually modified by emulation. */ +return RESUME_GUEST_NV ; + +case EMULATE_DO_DCR : + run->exit_reason =KVM_EXIT_DCR ; +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; +return RESUME_HOST ; + +default : +BUG (); + } +} +/** * kvmppc_handle_exit * @@ -371,12 +527,30 @@ out:int kvmppc_handle_exit (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int exit_nr) { -enum emulation_result er;int r =RESUME_HOST ;/* update before a new last_exit_type is rewritten */ kvmppc_update_timing_stats (vcpu); +switch (exit_nr) { +case BOOKE_INTERRUPT_EXTERNAL : +do_IRQ (current->thread.regs); +break ; + +case BOOKE_INTERRUPT_DECREMENTER : +timer_interrupt (current->thread.regs); +break ; + +#if defined(CONFIG_PPC_FSL_BOOK3E ) || defined(CONFIG_PPC_BOOK3E_64 ) +case BOOKE_INTERRUPT_DOORBELL : +doorbell_exception (current->thread.regs); +break ; +#endif +case BOOKE_INTERRUPT_MACHINE_CHECK : +/* FIXME */ +break ; + } +local_irq_enable (); run->exit_reason =KVM_EXIT_UNKNOWN ;@@ -384,30 +558,56 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, switch (exit_nr) {case BOOKE_INTERRUPT_MACHINE_CHECK : -printk ("MACHINE CHECK: %lx\n" ,mfspr (SPRN_MCSR )); -kvmppc_dump_vcpu (vcpu); - r =RESUME_HOST ; +kvm_resched (vcpu); + r =RESUME_GUEST ;break ;case BOOKE_INTERRUPT_EXTERNAL :kvmppc_account_exit (vcpu,EXT_INTR_EXITS ); -if (need_resched ()) -cond_resched (); +kvm_resched (vcpu); r =RESUME_GUEST ;break ;case BOOKE_INTERRUPT_DECREMENTER : -/* Since we switched IVPR back to the host's value, the host -* handled this interrupt the moment we enabled interrupts. -* Now we just offer it a chance to reschedule the guest. */ kvmppc_account_exit (vcpu,DEC_EXITS ); -if (need_resched ()) -cond_resched (); +kvm_resched (vcpu); r =RESUME_GUEST ;break ; +case BOOKE_INTERRUPT_DOORBELL : +kvmppc_account_exit (vcpu,DBELL_EXITS ); +kvm_resched (vcpu); + r =RESUME_GUEST ; +break ; + +case BOOKE_INTERRUPT_GUEST_DBELL_CRIT : +kvmppc_account_exit (vcpu,GDBELL_EXITS ); + +/* +* We are here because there is a pending guest interrupt +* which could not be delivered as MSR_CE or MSR_ME was not +* set. Once we break from here we will retry delivery. +*/ + r =RESUME_GUEST ; +break ; + +case BOOKE_INTERRUPT_GUEST_DBELL : +kvmppc_account_exit (vcpu,GDBELL_EXITS ); + +/* +* We are here because there is a pending guest interrupt +* which could not be delivered as MSR_EE was not set. Once +* we break from here we will retry delivery. +*/ + r =RESUME_GUEST ; +break ; + +case BOOKE_INTERRUPT_HV_PRIV : + r =emulation_exit (run, vcpu); +break ; +case BOOKE_INTERRUPT_PROGRAM : -if (vcpu->arch.shared->msr &MSR_PR ) { +if (vcpu->arch.shared->msr & (MSR_PR |MSR_GS )) {/* Program traps generated by user-level software must be handled
arch/powerpc/kvm/booke.c +1
-26* by the guest kernel. */ kvmppc_core_queue_program (vcpu, vcpu->arch.fault_esr);@@ -416,32 +616,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, break; } - er =kvmppc_emulate_instruction (run, vcpu); -switch (er) { -case EMULATE_DONE : -/* don't overwrite subtypes, just account kvm_stats */ -kvmppc_account_exit_stat (vcpu,EMULATED_INST_EXITS ); -/* Future optimization: only reload non-volatiles if -* they were actually modified by emulation. */ - r =RESUME_GUEST_NV ; -break ; -case EMULATE_DO_DCR : - run->exit_reason =KVM_EXIT_DCR ; - r =RESUME_HOST ; -break ; -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; - r =RESUME_HOST ; -break ; -default : -BUG (); - } + r =emulation_exit (run, vcpu);break ;arch/powerpc/kvm/booke.c +15
-0case BOOKE_INTERRUPT_FP_UNAVAIL :@@ -506,6 +681,21 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, r =RESUME_GUEST ;break ; +#ifdef CONFIG_KVM_BOOKE_HV +case BOOKE_INTERRUPT_HV_SYSCALL : +if (!(vcpu->arch.shared->msr &MSR_PR )) { +kvmppc_set_gpr (vcpu,3 ,kvmppc_kvm_pv (vcpu)); + }else { +/* +* hcall from guest userspace -- send privileged +* instruction program check. +*/ +kvmppc_core_queue_program (vcpu,ESR_PPR ); + } + + r =RESUME_GUEST ; +break ; +#else case BOOKE_INTERRUPT_SYSCALL : if (!(vcpu->arch.shared->msr & MSR_PR) &&arch/powerpc/kvm/booke.c +1
-0(((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) {@@ -519,6 +709,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,kvmppc_account_exit (vcpu,SYSCALL_EXITS ); r =RESUME_GUEST ;break ; +#endif case BOOKE_INTERRUPT_DTLB_MISS : {arch/powerpc/kvm/booke.c +5
-2unsigned long eaddr = vcpu->arch.fault_dear;@@ -659,12 +850,15 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)int r; vcpu->arch.pc =0 ; - vcpu->arch.shared->msr =0 ; - vcpu->arch.shadow_msr =MSR_USER |MSR_DE |MSR_IS |MSR_DS ; vcpu->arch.shared->pir = vcpu->vcpu_id;kvmppc_set_gpr (vcpu,1 , (16 <<20 ) -8 );/* -8 for the callee-save LR slot */ +kvmppc_set_msr (vcpu,0 ); +#ifndef CONFIG_KVM_BOOKE_HV + vcpu->arch.shadow_msr =MSR_USER |MSR_DE |MSR_IS |MSR_DS ; vcpu->arch.shadow_pid =1 ; + vcpu->arch.shared->msr =0 ; +#endif /* Eye-catching numbers so we know if the guest takes an interrupt arch/powerpc/kvm/booke.c +8
-5* before it's programmed its own IVPR/IVORs. */ @@ -745,8 +939,8 @@ static void get_sregs_base(struct kvm_vcpu *vcpu, sregs->u.e.csrr0 = vcpu->arch.csrr0; sregs->u.e.csrr1 = vcpu->arch.csrr1; sregs->u.e.mcsr = vcpu->arch.mcsr; - sregs->u.e.esr = vcpu->arch.shared->esr; - sregs->u.e.dear = vcpu->arch.shared->dar; + sregs->u.e.esr =get_guest_esr (vcpu); + sregs->u.e.dear =get_guest_dear (vcpu); sregs->u.e.tsr = vcpu->arch.tsr; sregs->u.e.tcr = vcpu->arch.tcr; sregs->u.e.dec =kvmppc_get_dec (vcpu, tb);@@ -763,8 +957,8 @@ static int set_sregs_base(struct kvm_vcpu *vcpu, vcpu->arch.csrr0 = sregs->u.e.csrr0; vcpu->arch.csrr1 = sregs->u.e.csrr1; vcpu->arch.mcsr = sregs->u.e.mcsr; - vcpu->arch.shared->esr = sregs->u.e.esr; - vcpu->arch.shared->dar = sregs->u.e.dear; +set_guest_esr (vcpu, sregs->u.e.esr); +set_guest_dear (vcpu, sregs->u.e.dear); vcpu->arch.vrsave = sregs->u.e.vrsave;kvmppc_set_tcr (vcpu, sregs->u.e.tcr);@@ -961,14 +1155,17 @@ void kvmppc_decrementer_func(unsigned long data)void kvmppc_booke_vcpu_load (struct kvm_vcpu *vcpu,int cpu) { + current->thread.kvm_vcpu = vcpu; }void kvmppc_booke_vcpu_put (struct kvm_vcpu *vcpu) { + current->thread.kvm_vcpu =NULL ; }int __init kvmppc_booke_init (void ) { +#ifndef CONFIG_KVM_BOOKE_HV unsigned long ivor[16 ];unsigned long max_ivor =0 ;int i;@@ -1011,7 +1208,7 @@ int __init kvmppc_booke_init(void) }flush_icache_range (kvmppc_booke_handlers, kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); - +#endif /* !BOOKE_HV */ return 0 ; }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 +6
-0@@ -99,6 +99,12 @@ int kvmppc_booke_emulate_op(struct kvm_run *run, structkvm_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) {arch/powerpc/kvm/booke_emulate.c +5
-3int 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 ;arch/powerpc/kvm/booke_emulate.c +3
-0case 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 :arch/powerpc/kvm/booke_emulate.c +3
-0vcpu->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 :arch/powerpc/kvm/booke_emulate.c +3
-0vcpu->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 :arch/powerpc/kvm/booke_emulate.c +0
-0vcpu->arch.ivor[BOOKE_IRQPRIO_AP_UNAVAIL ] = spr_val;arch/powerpc/kvm/bookehv_interrupts.S new file +58
-0@@ -0,0 +1,587 @@ +/* + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2010-2011 Freescale Semiconductor, Inc. + * + * Author: Varun Sethi <[email protected]> + * Author: Scott Wood <[email protected]> + * + * This file is derived from arch/powerpc/kvm/booke_interrupts.S + */ + +#include <asm/ppc_asm.h> +#include <asm/kvm_asm.h> +#include <asm/reg.h> +#include <asm/mmu-44x.h> +#include <asm/page.h> +#include <asm/asm-compat.h> +#include <asm/asm-offsets.h> +#include <asm/bitsperlong.h> + +#include "../kernel/head_booke.h" /* for THREAD_NORMSAVE() */ + +#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)) +#define VCPU_GUEST_SPRG(n) (VCPU_GUEST_SPRGS + (n * LONGBYTES)) + +/* The host stack layout: */ +#define HOST_R1 (0 * LONGBYTES) /* Implied by stwu. */ +#define HOST_CALLEE_LR (1 * LONGBYTES) +#define HOST_RUN (2 * LONGBYTES) /* struct kvm_run */ +/* + * r2 is special: it holds 'current', and it made nonvolatile in the + * kernel with the -ffixed-r2 gcc option. + */ +#define HOST_R2 (3 * LONGBYTES) +#define HOST_NV_GPRS (4 * 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. */ +#define HOST_STACK_LR (HOST_STACK_SIZE + LONGBYTES) /* In caller stack frame.*/
arch/powerpc/kvm/bookehv_interrupts.S new file +504
-0+ +#define NEED_EMU 0x00000001 /* emulation -- save nv regs */ +#define NEED_DEAR 0x00000002 /* save faulting DEAR */ +#define NEED_ESR 0x00000004 /* save faulting ESR */ + +/* + * On entry: + * r4 = vcpu, r5 = srr0, r6 = srr1 + * saved in vcpu: cr, ctr, r3-r13 + */ +.macro kvm_handler_common intno, srr0, flags + mfspr r10, SPRN_PID + lwz r8, VCPU_HOST_PID(r4) + PPC_LL r11, VCPU_SHARED(r4) + PPC_STL r14, VCPU_GPR(r14)(r4) /* We need a non-volatile GPR. */ + li r14, \intno + + 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 + mfspr r8, SPRN_TBRL + mfspr r9, SPRN_TBRU + cmpw r9, r7 + PPC_STL r8, VCPU_TIMING_EXIT_TBL(r4) + bne- 1b + PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4) +#endif + + oris r8, r6, MSR_CE@h +#ifndef CONFIG_64BIT + stw r6, (VCPU_SHARED_MSR + 4)(r11) +#else + std r6, (VCPU_SHARED_MSR)(r11) +#endif + ori r8, r8, MSR_ME | MSR_RI + PPC_STL r5, VCPU_PC(r4) + + /* + * Make sure CE/ME/RI are set (if appropriate for exception type) + * whether or not the guest had it set. Since mfmsr/mtmsr are + * somewhat expensive, skip in the common case where the guest + * had all these bits set (and thus they're still set if + * 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 + oris r7, r7, MSR_CE@h + .endif + .if \srr0 != SPRN_MCSRR0 + ori r7, r7, MSR_ME | MSR_RI + .endif + mtmsr r7 +1: + + .if \flags & NEED_EMU + /* + * This assumes you have external PID support. + * To support a bookehv CPU without external PID, you'll + * need to look up the TLB entry and create a temporary mapping. + * + * FIXME: we don't currently handle if the lwepx faults. PR-mode + * booke doesn't handle it either. Since Linux doesn't use + * broadcast tlbivax anymore, the only way this should happen is + * if the guest maps its memory execute-but-not-read, or if we + * somehow take a TLB miss in the middle of this entry code and + * evict the relevant entry. On e500mc, all kernel lowmem is + * bolted into TLB1 large page mappings, and we don't use + * broadcast invalidates, so we should not take a TLB miss here. + * + * Later we'll need to deal with faults here. Disallowing guest + * mappings that are execute-but-not-read could be an option on + * e500mc, but not on chips with an LRAT if it is used. + */ + + mfspr r3, SPRN_EPLC /* will already have correct ELPID and EGS */ + PPC_STL r15, VCPU_GPR(r15)(r4) + PPC_STL r16, VCPU_GPR(r16)(r4) + PPC_STL r17, VCPU_GPR(r17)(r4) + PPC_STL r18, VCPU_GPR(r18)(r4) + PPC_STL r19, VCPU_GPR(r19)(r4) + mr r8, r3 + PPC_STL r20, VCPU_GPR(r20)(r4) + rlwimi r8, r6, EPC_EAS_SHIFT - MSR_IR_LG, EPC_EAS + PPC_STL r21, VCPU_GPR(r21)(r4) + rlwimi r8, r6, EPC_EPR_SHIFT - MSR_PR_LG, EPC_EPR + PPC_STL r22, VCPU_GPR(r22)(r4) + rlwimi r8, r10, EPC_EPID_SHIFT, EPC_EPID + PPC_STL r23, VCPU_GPR(r23)(r4) + PPC_STL r24, VCPU_GPR(r24)(r4) + PPC_STL r25, VCPU_GPR(r25)(r4) + PPC_STL r26, VCPU_GPR(r26)(r4) + PPC_STL r27, VCPU_GPR(r27)(r4) + PPC_STL r28, VCPU_GPR(r28)(r4) + PPC_STL r29, VCPU_GPR(r29)(r4) + PPC_STL r30, VCPU_GPR(r30)(r4) + PPC_STL r31, VCPU_GPR(r31)(r4) + mtspr SPRN_EPLC, r8 + isync + lwepx r9, 0, r5 + mtspr SPRN_EPLC, r3 + stw r9, VCPU_LAST_INST(r4) + .endif + + .if \flags & NEED_ESR + mfspr r8, SPRN_ESR + PPC_STL r8, VCPU_FAULT_ESR(r4) + .endif + + .if \flags & NEED_DEAR + mfspr r9, SPRN_DEAR + PPC_STL r9, VCPU_FAULT_DEAR(r4) + .endif + + b kvmppc_resume_host +.endm + +/* + * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h + */ +.macro kvm_handler intno srr0, srr1, flags +_GLOBAL(kvmppc_handler_\intno\()_\srr1) + GET_VCPU(r11, r10) + PPC_STL r3, VCPU_GPR(r3)(r11) + mfspr r3, SPRN_SPRG_RSCRATCH0 + PPC_STL r4, VCPU_GPR(r4)(r11) + PPC_LL r4, THREAD_NORMSAVE(0)(r10) + PPC_STL r5, VCPU_GPR(r5)(r11) + PPC_STL r13, VCPU_CR(r11) + mfspr r5, \srr0 + PPC_STL r3, VCPU_GPR(r10)(r11) + PPC_LL r3, THREAD_NORMSAVE(2)(r10) + PPC_STL r6, VCPU_GPR(r6)(r11) + PPC_STL r4, VCPU_GPR(r11)(r11) + mfspr r6, \srr1 + PPC_STL r7, VCPU_GPR(r7)(r11) + PPC_STL r8, VCPU_GPR(r8)(r11) + PPC_STL r9, VCPU_GPR(r9)(r11) + PPC_STL r3, VCPU_GPR(r13)(r11) + mfctr r7 + PPC_STL r12, VCPU_GPR(r12)(r11) + PPC_STL r7, VCPU_CTR(r11) + mr r4, r11 + kvm_handler_common \intno, \srr0, \flags +.endm + +.macro kvm_lvl_handler intno scratch srr0, srr1, flags +_GLOBAL(kvmppc_handler_\intno\()_\srr1) + mfspr r10, SPRN_SPRG_THREAD + GET_VCPU(r11, r10) + PPC_STL r3, VCPU_GPR(r3)(r11) + mfspr r3, \scratch + PPC_STL r4, VCPU_GPR(r4)(r11) + PPC_LL r4, GPR9(r8) + PPC_STL r5, VCPU_GPR(r5)(r11) + PPC_STL r9, VCPU_CR(r11) + mfspr r5, \srr0 + PPC_STL r3, VCPU_GPR(r8)(r11) + PPC_LL r3, GPR10(r8) + PPC_STL r6, VCPU_GPR(r6)(r11) + PPC_STL r4, VCPU_GPR(r9)(r11) + mfspr r6, \srr1 + PPC_LL r4, GPR11(r8) + PPC_STL r7, VCPU_GPR(r7)(r11) + PPC_STL r8, VCPU_GPR(r8)(r11) + PPC_STL r3, VCPU_GPR(r10)(r11) + mfctr r7 + PPC_STL r12, VCPU_GPR(r12)(r11) + PPC_STL r4, VCPU_GPR(r11)(r11) + PPC_STL r7, VCPU_CTR(r11) + mr r4, r11 + kvm_handler_common \intno, \srr0, \flags +.endm + +kvm_lvl_handler BOOKE_INTERRUPT_CRITICAL, \ + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 +kvm_lvl_handler BOOKE_INTERRUPT_MACHINE_CHECK, \ + SPRN_SPRG_RSCRATCH_MC, SPRN_MCSRR0, SPRN_MCSRR1, 0 +kvm_handler BOOKE_INTERRUPT_DATA_STORAGE, \ + SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR) +kvm_handler BOOKE_INTERRUPT_INST_STORAGE, SPRN_SRR0, SPRN_SRR1, NEED_ESR +kvm_handler BOOKE_INTERRUPT_EXTERNAL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_ALIGNMENT, \ + SPRN_SRR0, SPRN_SRR1, (NEED_DEAR | NEED_ESR) +kvm_handler BOOKE_INTERRUPT_PROGRAM, SPRN_SRR0, SPRN_SRR1, NEED_ESR +kvm_handler BOOKE_INTERRUPT_FP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_SYSCALL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_AP_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_DECREMENTER, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_FIT, SPRN_SRR0, SPRN_SRR1, 0 +kvm_lvl_handler BOOKE_INTERRUPT_WATCHDOG, \ + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 +kvm_handler BOOKE_INTERRUPT_DTLB_MISS, \ + SPRN_SRR0, SPRN_SRR1, (NEED_EMU | NEED_DEAR | NEED_ESR) +kvm_handler BOOKE_INTERRUPT_ITLB_MISS, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_SPE_UNAVAIL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_SPE_FP_DATA, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_SPE_FP_ROUND, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_PERFORMANCE_MONITOR, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_DOORBELL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_lvl_handler BOOKE_INTERRUPT_DOORBELL_CRITICAL, \ + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 +kvm_handler BOOKE_INTERRUPT_HV_PRIV, SPRN_SRR0, SPRN_SRR1, NEED_EMU +kvm_handler BOOKE_INTERRUPT_HV_SYSCALL, SPRN_SRR0, SPRN_SRR1, 0 +kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, SPRN_GSRR0, SPRN_GSRR1, 0 +kvm_lvl_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, \ + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 +kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ + SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0 +kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \ + SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0 + + +/* Registers: + * SPRG_SCRATCH0: guest r10 + * r4: vcpu pointer + * r11: vcpu->arch.shared + * r14: KVM exit number + */ +_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) + PPC_STL r6, VCPU_SHARED_SPRG4(r11) + mfspr r8, SPRN_SPRG6 + PPC_STL r7, VCPU_SHARED_SPRG5(r11) + mfspr r9, SPRN_SPRG7 + PPC_STL r8, VCPU_SHARED_SPRG6(r11) + mfxer r3 + PPC_STL r9, VCPU_SHARED_SPRG7(r11) + + /* save guest MAS registers and restore host mas4 & mas6 */ + mfspr r5, SPRN_MAS0 + PPC_STL r3, VCPU_XER(r4) + mfspr r6, SPRN_MAS1 + 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 + std r7, (VCPU_SHARED_MAS2)(r11) +#endif + mfspr r5, SPRN_MAS3 + mfspr r6, SPRN_MAS4 + stw r5, VCPU_SHARED_MAS7_3+4(r11) + mfspr r7, SPRN_MAS6 + stw r6, VCPU_SHARED_MAS4(r11) + mfspr r5, SPRN_MAS7 + lwz r6, VCPU_HOST_MAS4(r4) + stw r7, VCPU_SHARED_MAS6(r11) + lwz r8, VCPU_HOST_MAS6(r4) + mtspr SPRN_MAS4, r6 + stw r5, VCPU_SHARED_MAS7_3+0(r11) + mtspr SPRN_MAS6, r8 + mfspr r3, SPRN_EPCR + rlwinm r3, r3, 0, ~SPRN_EPCR_DMIUH + 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 */ + mr r14, r4 /* Save vcpu pointer. */ + bl kvmppc_handle_exit + + /* Restore vcpu pointer and the nonvolatiles we used. */ + mr r4, r14 + PPC_LL r14, VCPU_GPR(r14)(r4) + + andi. r5, r3, RESUME_FLAG_NV + beq skip_nv_load + PPC_LL r15, VCPU_GPR(r15)(r4) + PPC_LL r16, VCPU_GPR(r16)(r4) + PPC_LL r17, VCPU_GPR(r17)(r4) + PPC_LL r18, VCPU_GPR(r18)(r4) + PPC_LL r19, VCPU_GPR(r19)(r4) + PPC_LL r20, VCPU_GPR(r20)(r4) + PPC_LL r21, VCPU_GPR(r21)(r4) + PPC_LL r22, VCPU_GPR(r22)(r4) + PPC_LL r23, VCPU_GPR(r23)(r4) + PPC_LL r24, VCPU_GPR(r24)(r4) + PPC_LL r25, VCPU_GPR(r25)(r4) + PPC_LL r26, VCPU_GPR(r26)(r4) + PPC_LL r27, VCPU_GPR(r27)(r4) + PPC_LL r28, VCPU_GPR(r28)(r4) + PPC_LL r29, VCPU_GPR(r29)(r4) + PPC_LL r30, VCPU_GPR(r30)(r4) + PPC_LL r31, VCPU_GPR(r31)(r4) +skip_nv_load: + /* Should we return to the guest? */ + andi. r5, r3, RESUME_FLAG_HOST + beq lightweight_exit + + srawi r3, r3, 2 /* Shift -ERR back down. */ + +heavyweight_exit: + /* Not returning to guest. */ + PPC_LL r5, HOST_STACK_LR(r1) + + /* + * We already saved guest volatile register state; now save the + * non-volatiles. + */ + + PPC_STL r15, VCPU_GPR(r15)(r4) + PPC_STL r16, VCPU_GPR(r16)(r4) + PPC_STL r17, VCPU_GPR(r17)(r4) + PPC_STL r18, VCPU_GPR(r18)(r4) + PPC_STL r19, VCPU_GPR(r19)(r4) + PPC_STL r20, VCPU_GPR(r20)(r4) + PPC_STL r21, VCPU_GPR(r21)(r4) + PPC_STL r22, VCPU_GPR(r22)(r4) + PPC_STL r23, VCPU_GPR(r23)(r4) + PPC_STL r24, VCPU_GPR(r24)(r4) + PPC_STL r25, VCPU_GPR(r25)(r4) + PPC_STL r26, VCPU_GPR(r26)(r4) + PPC_STL r27, VCPU_GPR(r27)(r4) + PPC_STL r28, VCPU_GPR(r28)(r4) + PPC_STL r29, VCPU_GPR(r29)(r4) + PPC_STL r30, VCPU_GPR(r30)(r4) + PPC_STL r31, VCPU_GPR(r31)(r4) + + /* Load host non-volatile register state from host stack. */ + PPC_LL r14, HOST_NV_GPR(r14)(r1) + PPC_LL r15, HOST_NV_GPR(r15)(r1) + PPC_LL r16, HOST_NV_GPR(r16)(r1) + PPC_LL r17, HOST_NV_GPR(r17)(r1) + PPC_LL r18, HOST_NV_GPR(r18)(r1) + PPC_LL r19, HOST_NV_GPR(r19)(r1) + PPC_LL r20, HOST_NV_GPR(r20)(r1) + PPC_LL r21, HOST_NV_GPR(r21)(r1) + PPC_LL r22, HOST_NV_GPR(r22)(r1) + PPC_LL r23, HOST_NV_GPR(r23)(r1) + PPC_LL r24, HOST_NV_GPR(r24)(r1) + PPC_LL r25, HOST_NV_GPR(r25)(r1) + PPC_LL r26, HOST_NV_GPR(r26)(r1) + PPC_LL r27, HOST_NV_GPR(r27)(r1) + PPC_LL r28, HOST_NV_GPR(r28)(r1) + PPC_LL r29, HOST_NV_GPR(r29)(r1) + PPC_LL r30, HOST_NV_GPR(r30)(r1) + PPC_LL r31, HOST_NV_GPR(r31)(r1) + + /* Return to kvm_vcpu_run(). */ + mtlr r5 + addi r1, r1, HOST_STACK_SIZE + /* r3 still contains the return code from kvmppc_handle_exit(). */ + blr + +/* Registers: + * r3: kvm_run pointer + * r4: vcpu pointer + */ +_GLOBAL(__kvmppc_vcpu_run) + stwu r1, -HOST_STACK_SIZE(r1) + PPC_STL r1, VCPU_HOST_STACK(r4) /* Save stack pointer to vcpu. */ + + /* Save host state to stack. */ + PPC_STL r3, HOST_RUN(r1) + mflr r3 + PPC_STL r3, HOST_STACK_LR(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) + PPC_STL r16, HOST_NV_GPR(r16)(r1) + PPC_STL r17, HOST_NV_GPR(r17)(r1) + PPC_STL r18, HOST_NV_GPR(r18)(r1) + PPC_STL r19, HOST_NV_GPR(r19)(r1) + PPC_STL r20, HOST_NV_GPR(r20)(r1) + PPC_STL r21, HOST_NV_GPR(r21)(r1) + PPC_STL r22, HOST_NV_GPR(r22)(r1) + PPC_STL r23, HOST_NV_GPR(r23)(r1) + PPC_STL r24, HOST_NV_GPR(r24)(r1) + PPC_STL r25, HOST_NV_GPR(r25)(r1) + PPC_STL r26, HOST_NV_GPR(r26)(r1) + PPC_STL r27, HOST_NV_GPR(r27)(r1) + PPC_STL r28, HOST_NV_GPR(r28)(r1) + PPC_STL r29, HOST_NV_GPR(r29)(r1) + PPC_STL r30, HOST_NV_GPR(r30)(r1) + PPC_STL r31, HOST_NV_GPR(r31)(r1) + + /* Load guest non-volatiles. */ + PPC_LL r14, VCPU_GPR(r14)(r4) + PPC_LL r15, VCPU_GPR(r15)(r4) + PPC_LL r16, VCPU_GPR(r16)(r4) + PPC_LL r17, VCPU_GPR(r17)(r4) + PPC_LL r18, VCPU_GPR(r18)(r4) + PPC_LL r19, VCPU_GPR(r19)(r4) + PPC_LL r20, VCPU_GPR(r20)(r4) + PPC_LL r21, VCPU_GPR(r21)(r4) + PPC_LL r22, VCPU_GPR(r22)(r4) + PPC_LL r23, VCPU_GPR(r23)(r4) + PPC_LL r24, VCPU_GPR(r24)(r4) + PPC_LL r25, VCPU_GPR(r25)(r4) + PPC_LL r26, VCPU_GPR(r26)(r4) + PPC_LL r27, VCPU_GPR(r27)(r4) + PPC_LL r28, VCPU_GPR(r28)(r4) + PPC_LL r29, VCPU_GPR(r29)(r4) + PPC_LL r30, VCPU_GPR(r30)(r4) + PPC_LL r31, VCPU_GPR(r31)(r4) + + +lightweight_exit: + PPC_STL r2, HOST_R2(r1) + + mfspr r3, SPRN_PID + stw r3, VCPU_HOST_PID(r4) + 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 + stw r3, VCPU_HOST_MAS4(r4) + mfspr r3, SPRN_MAS6 + 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 + ld r6, (VCPU_SHARED_MAS2)(r11) +#endif + lwz r7, VCPU_SHARED_MAS7_3+4(r11) + lwz r8, VCPU_SHARED_MAS4(r11) + mtspr SPRN_MAS0, r3 + mtspr SPRN_MAS1, r5 + mtspr SPRN_MAS2, r6 + mtspr SPRN_MAS3, r7 + mtspr SPRN_MAS4, r8 + lwz r3, VCPU_SHARED_MAS6(r11) + 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 + * SPRGs, so we need to reload them here with the guest's values. + */ + lwz r3, VCPU_VRSAVE(r4) + lwz r5, VCPU_SHARED_SPRG4(r11) + mtspr SPRN_VRSAVE, r3 + lwz r6, VCPU_SHARED_SPRG5(r11) + mtspr SPRN_SPRG4W, r5 + lwz r7, VCPU_SHARED_SPRG6(r11) + mtspr SPRN_SPRG5W, r6 + lwz r8, VCPU_SHARED_SPRG7(r11) + mtspr SPRN_SPRG6W, r7 + mtspr SPRN_SPRG7W, r8 + + /* Load some guest volatiles. */ + PPC_LL r3, VCPU_LR(r4) + PPC_LL r5, VCPU_XER(r4) + 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 + ld r9, (VCPU_SHARED_MSR)(r11) +#endif + PPC_LL r0, VCPU_GPR(r0)(r4) + PPC_LL r1, VCPU_GPR(r1)(r4) + PPC_LL r2, VCPU_GPR(r2)(r4) + PPC_LL r10, VCPU_GPR(r10)(r4) + PPC_LL r11, VCPU_GPR(r11)(r4) + PPC_LL r12, VCPU_GPR(r12)(r4) + PPC_LL r13, VCPU_GPR(r13)(r4) + mtlr r3 + mtxer r5 + mtctr r6 + mtcr r7
arch/powerpc/kvm/bookehv_interrupts.S line 572
Quoted 10 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +10
-0+ mtsrr0 r8 + mtsrr1 r9 + +#ifdef CONFIG_KVM_EXIT_TIMING + /* save enter time */ +1: + mfspr r6, SPRN_TBRU + mfspr r7, SPRN_TBRL + mfspr r8, SPRN_TBRU + cmpw r8, r6
Is not we should save guest CR after this otherwise this can corrupt it?
Thanks
-Bharat
Quoted 56 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +15
-0+ PPC_STL r7, VCPU_TIMING_LAST_ENTER_TBL(r4) + bne 1b + PPC_STL r8, VCPU_TIMING_LAST_ENTER_TBU(r4) +#endif + + /* Finish loading guest volatiles and jump to guest. */ + PPC_LL r5, VCPU_GPR(r5)(r4) + PPC_LL r6, VCPU_GPR(r6)(r4) + PPC_LL r7, VCPU_GPR(r7)(r4) + PPC_LL r8, VCPU_GPR(r8)(r4) + PPC_LL r9, VCPU_GPR(r9)(r4) + + PPC_LL r3, VCPU_GPR(r3)(r4) + PPC_LL r4, VCPU_GPR(r4)(r4) + rfiarch/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
-1@@ -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 ; } } --1.6.0.2
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 13/38] KVM: PPC: booke: category E.HV (GS-mode) support
Quoted 7 lines
Quoted 7 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +7
-0+ /* + * Host interrupt handlers may have clobbered these guest-readable + * SPRGs, so we need to reload them here with the guest's values. + */ + lwz r3, VCPU_VRSAVE(r4) + lwz r5, VCPU_SHARED_SPRG4(r11) + mtspr SPRN_VRSAVE, r3
Quoted 8 lines
arch/powerpc/kvm/bookehv_interrupts.S line 540
Quoted 8 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +8
-0+ lwz r6, VCPU_SHARED_SPRG5(r11) + mtspr SPRN_SPRG4W, r5 + lwz r7, VCPU_SHARED_SPRG6(r11) + mtspr SPRN_SPRG5W, r6 + lwz r8, VCPU_SHARED_SPRG7(r11) + mtspr SPRN_SPRG6W, r7 + mtspr SPRN_SPRG7W, r8 +
That should be here.
Quoted 26 lines
Quoted 26 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +26
-0+ /* Load some guest volatiles. */ + PPC_LL r3, VCPU_LR(r4) + PPC_LL r5, VCPU_XER(r4) + 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 + ld r9, (VCPU_SHARED_MSR)(r11) +#endif + PPC_LL r0, VCPU_GPR(r0)(r4) + PPC_LL r1, VCPU_GPR(r1)(r4) + PPC_LL r2, VCPU_GPR(r2)(r4) + PPC_LL r10, VCPU_GPR(r10)(r4) + PPC_LL r11, VCPU_GPR(r11)(r4) + PPC_LL r12, VCPU_GPR(r12)(r4) + PPC_LL r13, VCPU_GPR(r13)(r4) + mtlr r3 + mtxer r5 + mtctr r6 + mtcr r7 + mtsrr0 r8 + mtsrr1 r9 + +#ifdef CONFIG_KVM_EXIT_TIMING
Quoted 8 lines
arch/powerpc/kvm/bookehv_interrupts.S line 572
Quoted 6 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +6
-0+ /* save enter time */ +1: + mfspr r6, SPRN_TBRU + mfspr r7, SPRN_TBRL + mfspr r8, SPRN_TBRU + cmpw r8, r6Is not we should save guest CR after this otherwise this can corrupt it?
I think this should be a typo since in our previous kvm implementation, we always did collect kvm exit timing at the above location :)
Tiejun
Quoted 19 lines
Thanks
-BharatQuoted 15 lines
arch/powerpc/kvm/bookehv_interrupts.S new file +15
-0+ PPC_STL r7, VCPU_TIMING_LAST_ENTER_TBL(r4) + bne 1b + PPC_STL r8, VCPU_TIMING_LAST_ENTER_TBU(r4) +#endif + + /* Finish loading guest volatiles and jump to guest. */ + PPC_LL r5, VCPU_GPR(r5)(r4) + PPC_LL r6, VCPU_GPR(r6)(r4) + PPC_LL r7, VCPU_GPR(r7)(r4) + PPC_LL r8, VCPU_GPR(r8)(r4) + PPC_LL r9, VCPU_GPR(r9)(r4) + + PPC_LL r3, VCPU_GPR(r3)(r4) + PPC_LL r4, VCPU_GPR(r4)(r4) + rfi
Re: [PATCH 19/38] KVM: PPC: e500mc: add load inst fixup
In reply to Alexander GrafQuoted 7 lines · Alexander Graf
There'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.
Quoted 7 lines
Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- fix whitespace
Still broken.
Quoted 54 lines
- use explicit preempt counts
--- 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
PATCH 19/38 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.
---
v1 -> v2:
- fix whitespace
- use explicit preempt counts
v2 -> v3:
- fix whitespace (for real)
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
Re: [PATCH 12/38] powerpc/booke: Provide exception macros with interrupt name
In reply to Alexander GrafQuoted 7 lines · Alexander Graf
From: Scott Wood <[email protected]>
DO_KVMwill 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.
So what do the new names correspond to? What header is defining MACHINE_CHECK, BOOKE_INTERRUPT_EXTERNAL, etc (asm/kvm_asm.h)? If so we really should move these out of asm/kvm_asm.h and into something a bit more appropriate.
Quoted 346 lines
Signed-off-by Scott Wood <[email protected]>Signed-off-by Alexander Graf <[email protected]>---
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 +0
-0@@ -248,10 +248,11 @@ _ENTRY(_start);
interrupt_base:/* Critical Input Interrupt */arch/powerpc/kernel/head_44x.S +1
-1- CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) + CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)/* Machine Check Interrupt */arch/powerpc/kernel/head_44x.S +2
-1- 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 */arch/powerpc/kernel/head_44x.S +11
-7@@ -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@@ -2,6 +2,8 @@#define __HEAD_BOOKE_H__#include <asm/ptrace.h> /* for STACK_FRAME_REGS_MARKER */ +#include <asm/kvm_asm.h> +/* * Macros used for common Book-e exception handling */ @@ -28,7 +30,7 @@*/ #define THREAD_NORMSAVE (offset) (THREAD_NORMSAVES + (offset * 4)) -#define NORMAL_EXCEPTION_PROLOG \ +#define NORMAL_EXCEPTION_PROLOG(intno) \ mtspr SPRN_SPRG_WSCRATCH0, r10; /* save one register */ \ mfspr r10, SPRN_SPRG_THREAD; \ stw r11, THREAD_NORMSAVE(0)(r10); \@@ -113,7 +115,7 @@* registers as the normal prolog above. Instead we use a portion of the * critical/machine check exception stack at low physical addresses. */ -#define EXC_LEVEL_EXCEPTION_PROLOG (exc_level, exc_level_srr0, exc_level_srr1) \ +#define EXC_LEVEL_EXCEPTION_PROLOG (exc_level, intno, exc_level_srr0, exc_level_srr1) \ mtspr SPRN_SPRG_WSCRATCH_##exc_level,r8; \ BOOKE_LOAD_EXC_LEVEL_STACK(exc_level);/* r8 points to the exc_level stack*/ \stw r9,GPR9 (r8 );/* save various registers */ \@@ -162,12 +164,13 @@SAVE_4GPRS (3 , r11); \ SAVE_2GPRS(7, r11) -#define CRITICAL_EXCEPTION_PROLOG \ - EXC_LEVEL_EXCEPTION_PROLOG(CRIT, SPRN_CSRR0, SPRN_CSRR1) +#define CRITICAL_EXCEPTION_PROLOG (intno) \ + EXC_LEVEL_EXCEPTION_PROLOG(CRIT, intno, SPRN_CSRR0, SPRN_CSRR1)#define DEBUG_EXCEPTION_PROLOG \ - EXC_LEVEL_EXCEPTION_PROLOG(DBG, SPRN_DSRR0, SPRN_DSRR1) + EXC_LEVEL_EXCEPTION_PROLOG(DBG, DEBUG, SPRN_DSRR0, SPRN_DSRR1)#define MCHECK_EXCEPTION_PROLOG \ - EXC_LEVEL_EXCEPTION_PROLOG(MC, SPRN_MCSRR0, SPRN_MCSRR1) + EXC_LEVEL_EXCEPTION_PROLOG(MC, MACHINE_CHECK, \ + SPRN_MCSRR0, SPRN_MCSRR1)/* * Exception vectors. @@ -181,16 +184,16 @@ label: .long func; \ .long ret_from_except_full -#define EXCEPTION (n, label, hdlr, xfer) \ +#define EXCEPTION (n, intno, label, hdlr, xfer) \ START_EXCEPTION(label); \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(intno); \ addi r3,r1,STACK_FRAME_OVERHEAD; \ xfer(n, hdlr) -#define CRITICAL_EXCEPTION (n, label, hdlr) \ - START_EXCEPTION(label); \ - CRITICAL_EXCEPTION_PROLOG; \ - addi r3,r1,STACK_FRAME_OVERHEAD; \ +#define CRITICAL_EXCEPTION (n, intno, label, hdlr) \ + START_EXCEPTION(label); \ + CRITICAL_EXCEPTION_PROLOG(intno); \ + addi r3,r1,STACK_FRAME_OVERHEAD; \ EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \ NOCOPY, crit_transfer_to_handler, \ ret_from_crit_exc)@@ -302,7 +305,7 @@ label:#define DEBUG_CRIT_EXCEPTION \ START_EXCEPTION(DebugCrit); \ - CRITICAL_EXCEPTION_PROLOG; \ + CRITICAL_EXCEPTION_PROLOG(DEBUG); \ \/* \ * If there is a single step or branch-taken exception in an \ @@ -355,7 +358,7 @@ label:#define DATA_STORAGE_EXCEPTION \ START_EXCEPTION(DataStorage) \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(DATA_STORAGE); \ mfspr r5,SPRN_ESR;/* Grab the ESR and save it */ \stw r5,_ESR (r11 ); \mfspr r4,SPRN_DEAR ;/* Grab the DEAR */ \@@ -363,7 +366,7 @@ label:#define INSTRUCTION_STORAGE_EXCEPTION \ START_EXCEPTION(InstructionStorage) \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(INST_STORAGE); \ mfspr r5,SPRN_ESR;/* Grab the ESR and save it */ \stw r5,_ESR (r11 ); \mr r4,r12;/* Pass SRR0 as arg2 */ \@@ -372,7 +375,7 @@ label:#define ALIGNMENT_EXCEPTION \ START_EXCEPTION(Alignment) \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(ALIGNMENT); \ mfspr r4,SPRN_DEAR;/* Grab the DEAR and save it */ \stw r4,_DEAR (r11 ); \addi r3,r1,STACK_FRAME_OVERHEAD ; \@@ -380,7 +383,7 @@ label:#define PROGRAM_EXCEPTION \ START_EXCEPTION(Program) \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(PROGRAM); \ mfspr r4,SPRN_ESR;/* Grab the ESR and save it */ \stw r4,_ESR (r11 ); \addi r3,r1,STACK_FRAME_OVERHEAD ; \@@ -388,7 +391,7 @@ label:#define DECREMENTER_EXCEPTION \ START_EXCEPTION(Decrementer) \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(DECREMENTER); \ lis r0,TSR_DIS@h;/* Setup the DEC interrupt mask */ \mtspr SPRN_TSR ,r0;/* Clear the DEC interrupt */ \addi r3,r1,STACK_FRAME_OVERHEAD ; \@@ -396,7 +399,7 @@ label:#define FP_UNAVAILABLE_EXCEPTION \ START_EXCEPTION(FloatingPointUnavailable) \ - NORMAL_EXCEPTION_PROLOG; \ + NORMAL_EXCEPTION_PROLOG(FP_UNAVAIL); \ beq 1f; \ bl load_up_fpu;/* if from user, just load it up */ \b fast_exception_return; \arch/powerpc/kernel/head_fsl_booke.S +0
-0@@ -301,19 +301,20 @@ _ENTRY(__early_start)
interrupt_base:/* Critical Input Interrupt */arch/powerpc/kernel/head_fsl_booke.S +1
-1- CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) + CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)/* Machine Check Interrupt */ #ifdef CONFIG_E200 /* no RFMCI, MCSRRs on E200 */arch/powerpc/kernel/head_fsl_booke.S +2
-1- CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) + CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \ + machine_check_exception)#else MCHECK_EXCEPTION(0x0200, MachineCheck, machine_check_exception)#endif
/* Data Storage Interrupt */ START_EXCEPTION(DataStorage)arch/powerpc/kernel/head_fsl_booke.S +1
-1- NORMAL_EXCEPTION_PROLOG + NORMAL_EXCEPTION_PROLOG(DATA_STORAGE)mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */
stw r5,_ESR(r11)
mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */arch/powerpc/kernel/head_fsl_booke.S +28
-17@@ -328,7 +329,7 @@ interrupt_base: INSTRUCTION_STORAGE_EXCEPTION /* External Input Interrupt */ - EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) + EXCEPTION(0x0500, EXTERNAL, ExternalInput, do_IRQ, EXC_XFER_LITE) /* Alignment Interrupt */ ALIGNMENT_EXCEPTION@@ -342,32 +343,36 @@ interrupt_base: #else #ifdef CONFIG_E200 /* E200 treats 'normal' floating point instructions as FP Unavail exception */ - EXCEPTION(0x0800, FloatingPointUnavailable, program_check_exception, EXC_XFER_EE) + EXCEPTION(0x0800, FP_UNAVAIL, FloatingPointUnavailable, \ + program_check_exception, EXC_XFER_EE) #else - EXCEPTION(0x0800, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x0800, FP_UNAVAIL, FloatingPointUnavailable, \ + unknown_exception, EXC_XFER_EE) #endif #endif /* System Call Interrupt */ START_EXCEPTION(SystemCall) - NORMAL_EXCEPTION_PROLOG + NORMAL_EXCEPTION_PROLOG(SYSCALL) EXC_XFER_EE_LITE(0x0c00, DoSyscall) /* Auxiliary Processor Unavailable Interrupt */ - EXCEPTION(0x2900, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x2900, AP_UNAVAIL, AuxillaryProcessorUnavailable, \ + unknown_exception, EXC_XFER_EE) /* Decrementer Interrupt */ DECREMENTER_EXCEPTION /* Fixed Internal Timer Interrupt */ /* TODO: Add FIT support */ - EXCEPTION(0x3100, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x3100, FIT, FixedIntervalTimer, \ + unknown_exception, EXC_XFER_EE) /* Watchdog Timer Interrupt */ #ifdef CONFIG_BOOKE_WDT - CRITICAL_EXCEPTION(0x3200, WatchdogTimer, WatchdogException) + CRITICAL_EXCEPTION(0x3200, WATCHDOG, WatchdogTimer, WatchdogException) #else - CRITICAL_EXCEPTION(0x3200, WatchdogTimer, unknown_exception) + CRITICAL_EXCEPTION(0x3200, WATCHDOG, WatchdogTimer, unknown_exception) #endif /* Data TLB Error Interrupt */@@ -538,31 +543,38 @@ interrupt_base: #ifdef CONFIG_SPE /* SPE Unavailable */ START_EXCEPTION(SPEUnavailable) - NORMAL_EXCEPTION_PROLOG + NORMAL_EXCEPTION_PROLOG(SPE_UNAVAIL) bne load_up_spe addi r3,r1,STACK_FRAME_OVERHEAD EXC_XFER_EE_LITE(0x2010, KernelSPE) #else - EXCEPTION(0x2020, SPEUnavailable, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x2020, SPE_UNAVAIL, SPEUnavailable, \ + unknown_exception, EXC_XFER_EE) #endif /* CONFIG_SPE */ /* SPE Floating Point Data */ #ifdef CONFIG_SPE - EXCEPTION(0x2030, SPEFloatingPointData, SPEFloatingPointException, EXC_XFER_EE); + EXCEPTION(0x2030, SPE_FP_DATA, SPEFloatingPointData, \ + SPEFloatingPointException, EXC_XFER_EE); /* SPE Floating Point Round */ - EXCEPTION(0x2050, SPEFloatingPointRound, SPEFloatingPointRoundException, EXC_XFER_EE) + EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \ + SPEFloatingPointRoundException, EXC_XFER_EE) #else - EXCEPTION(0x2040, SPEFloatingPointData, unknown_exception, EXC_XFER_EE) - EXCEPTION(0x2050, SPEFloatingPointRound, unknown_exception, EXC_XFER_EE) + EXCEPTION(0x2040, SPE_FP_DATA, SPEFloatingPointData, \ + unknown_exception, EXC_XFER_EE) + EXCEPTION(0x2050, SPE_FP_ROUND, SPEFloatingPointRound, \ + unknown_exception, EXC_XFER_EE) #endif /* CONFIG_SPE */ /* Performance Monitor */ - EXCEPTION(0x2060, PerformanceMonitor, performance_monitor_exception, EXC_XFER_STD) + EXCEPTION(0x2060, PERFORMANCE_MONITOR, PerformanceMonitor, \ + performance_monitor_exception, EXC_XFER_STD) - EXCEPTION(0x2070, Doorbell, doorbell_exception, EXC_XFER_STD) + EXCEPTION(0x2070, DOORBELL, Doorbell, doorbell_exception, EXC_XFER_STD) - CRITICAL_EXCEPTION(0x2080, CriticalDoorbell, unknown_exception) + CRITICAL_EXCEPTION(0x2080, DOORBELL_CRITICAL, \ + CriticalDoorbell, unknown_exception) /* Debug Interrupt */ DEBUG_DEBUG_EXCEPTIONSignature · 6 lines
1.6.0.2 -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 12/38] powerpc/booke: Provide exception macros with interrupt name
Quoted 5 lines · Kumar Gala
Quoted 2 lines · Alexander Graf
From: Scott Wood <[email protected]>
Quoted 7 lines
Quoted 5 lines
DO_KVMwill 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.
So what do the new names correspond to?
The names are Linux-defined. The values are IVOR numbers.
Quoted 2 lines
What header is defining
MACHINE_CHECK,BOOKE_INTERRUPT_EXTERNAL, etc (asm/kvm_asm.h)?
Yes, it's asm/kvm_asm.h at the moment.
It's actually BOOKE_INTERRUPT_MACHINE_CHECK, etc. The exception macros paste on BOOKE_INTERRUPT_ when they use it, to keep the macro users from having to wrap lines even more often.
Quoted 2 lines
If so we really should move these out of
asm/kvm_asm.hand into something a bit more appropriate.
Yes, that was one of the things I had been planning to fix post-RFC. Any preference what header it should be in? asm/reg_booke.h seems to be the least bad option of the existing headers -- or perhaps move head_booke.h to arch/powerpc/include/asm.
Long-term it would also be nice for this to replace, rather than supplement, the current numbers, though as Ben pointed out there are a number of places throughout the code that will have to be fixed for that to happen.
-Scott
Re: [PATCH 12/38] powerpc/booke: Provide exception macros with interrupt name
Quoted 25 lines · Scott Wood
Quoted 5 lines · Kumar Gala
Quoted 2 lines · Alexander Graf
From: Scott Wood <[email protected]>
Quoted 7 lines
Quoted 5 lines
DO_KVMwill 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.
So what do the new names correspond to?
The names are Linux-defined. The values are IVOR numbers.
Quoted 2 lines
What header is defining
MACHINE_CHECK,BOOKE_INTERRUPT_EXTERNAL, etc (asm/kvm_asm.h)?Yes, it's
asm/kvm_asm.hat the moment.It's actually
BOOKE_INTERRUPT_MACHINE_CHECK, etc. The exception macros paste onBOOKE_INTERRUPT_when they use it, to keep the macro users from having to wrap lines even more often.
Quoted 7 lines
Quoted 2 lines
If so we really should move these out of
asm/kvm_asm.hand into something a bit more appropriate.Yes, that was one of the things I had been planning to fix post-RFC. Any preference what header it should be in?
asm/reg_booke.hseems to be the least bad option of the existing headers -- or perhaps movehead_booke.htoarch/powerpc/include/asm.
asm/reg_booke.h seems the least painful right now. head_booke.h is only used on 32-bit so that's not the best choice at this point. We could create an <asm/head_booke.h> in addition to the one in arch/powerpc/kernel/
Quoted 4 lines
Long-term it would also be nice for this to replace, rather than supplement, the current numbers, though as Ben pointed out there are a number of places throughout the code that will have to be fixed for that to happen.
Yeah, not too worried about that. More just wanting it to be clear what one has to 'update' if adding support for a new exception.
- k