ppc patch queue 2014-01-29
Subsystems (5)
Hi Paolo & Gleb,
This is my current patch queue for ppc. Please pull.
Highlights in this release are:
- automatic module loading
- book3s hv: little endian guest support
- booke: use proper caching attributes for non-ram
- minor optimizations / bug fixes
- book3s hv: first part of POWER8 support
Alex
The following changes since commit 8a3caa6d74597c2a083f7c87f866891a0b12540b:
KVM: kvm_clear_guest_page(): fix empty_zero_page usage (2013-11-21 11:19:32 +0200)
are available in the git repository at:
git://github.com/agraf/linux-2.6.git kvm-ppc-next
for you to fetch changes up to 4068890931f62752abc3591e7b3736e7537c6dcb:
KVM: PPC: Book3S PR: Cope with doorbell interrupts (2014-01-27 16:01:23 +0100)
----------------------------------------------------------------
Alexander Graf (2):
KVM: PPC: Add devname:kvm aliases for modules
KVM: PPC: Unify kvmppc_get_last_inst and sc
Andreas Schwab (1):
KVM: PPC: Book3S HV: use xics_wake_cpu only when defined
Anton Blanchard (1):
KVM: PPC: Book3S HV: Basic little-endian guest support
Bharat Bhushan (6):
kvm/powerpc: rename kvm_hypercall() to epapr_hypercall() kvm/powerpc: move kvm_hypercall0() and friends to epapr_hypercall0()
kvm: booke: clear host tlb reference flag on guest tlb invalidation
kvm: book3s: rename lookup_linux_pte() to lookup_linux_pte_and_update()
kvm: powerpc: define a linux pte lookup function
kvm: powerpc: use caching attributes as per linux pte
Cédric Le Goater (1):
KVM: PPC: Book3S: MMIO emulation support for little endian guests
Gleb Natapov (1):
KVM: PPC: fix couple of memory leaks in MPIC/XICS devices
Liu Ping Fan (1):
powerpc: kvm: optimize "sc 1" as fast return
Michael Ellerman (1):
KVM: PPC: Book3S HV: Add handler for HV facility unavailable
Michael Neuling (5):
KVM: PPC: Book3S HV: Don't set DABR on POWER8
KVM: PPC: Book3S HV: Context-switch new POWER8 SPRs powerpc/Kconfig: Make TM select VSX and VMX
KVM: PPC: Book3S HV: Add new state for transactional memory
KVM: PPC: Book3S HV: Add software abort codes for transactional memory
Mihai Caraman (1):
KVM: PPC: e500: Fix bad address type in deliver_tlb_misss()
Paul Mackerras (13):
KVM: PPC: Use load_fp/vr_state rather than load_up_fpu/altivec
KVM: PPC: Store FP/VSX/VMX state in thread_fp/vr_state structures
KVM: PPC: Load/save FP/VMX/VSX state directly to/from vcpu struct
KVM: PPC: Book3S HV: Use load/store_fp_state functions in HV guest entry/exit
KVM: PPC: Book3S HV: Align physical and virtual CPU thread numbers
KVM: PPC: Book3S HV: Flush the correct number of TLB sets on POWER8
KVM: PPC: Book3S HV: Implement architecture compatibility modes for POWER8
KVM: PPC: Book3S HV: Consolidate code that checks reason for wake from nap
KVM: PPC: Book3S HV: Handle guest using doorbells for IPIs
KVM: PPC: Book3S HV: Handle new LPCR bits on POWER8
KVM: PPC: Book3S HV: Prepare for host using hypervisor doorbells
KVM: PPC: Book3S HV: Add support for DABRX register on POWER7
KVM: PPC: Book3S PR: Cope with doorbell interrupts
Scott Wood (1):
kvm/ppc: IRQ disabling cleanup
Tiejun Chen (1):
KVM: PPC: Book3E HV: call RECONCILE_IRQ_STATE to sync the software state
Zhouyi Zhou (1):
KVM: PPC: NULL return of kvmppc_mmu_hpte_cache_next should be handled
Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/epapr_hcalls.h | 111 +++ arch/powerpc/include/asm/kvm_asm.h | 3 + arch/powerpc/include/asm/kvm_book3s.h | 27 +- arch/powerpc/include/asm/kvm_book3s_asm.h | 1 + arch/powerpc/include/asm/kvm_booke.h | 6 + arch/powerpc/include/asm/kvm_host.h | 61 +- arch/powerpc/include/asm/kvm_para.h | 80 +- arch/powerpc/include/asm/kvm_ppc.h | 13 +- arch/powerpc/include/asm/pgtable.h | 21 + arch/powerpc/include/asm/reg.h | 43 +- arch/powerpc/include/asm/switch_to.h | 2 - arch/powerpc/include/uapi/asm/kvm.h | 3 + arch/powerpc/include/uapi/asm/tm.h | 2 + arch/powerpc/kernel/asm-offsets.c | 50 +- arch/powerpc/kernel/kvm.c | 41 +- arch/powerpc/kvm/44x.c | 4 + arch/powerpc/kvm/book3s.c | 46 +- arch/powerpc/kvm/book3s_32_mmu_host.c | 5 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 4 +- arch/powerpc/kvm/book3s_exports.c | 4 - arch/powerpc/kvm/book3s_hv.c | 319 ++++++-- arch/powerpc/kvm/book3s_hv_interrupts.S | 8 +- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 1213 ++++++++++++++++++----------- arch/powerpc/kvm/book3s_paired_singles.c | 169 ++-- arch/powerpc/kvm/book3s_pr.c | 155 +--- arch/powerpc/kvm/book3s_rmhandlers.S | 47 -- arch/powerpc/kvm/book3s_segment.S | 2 + arch/powerpc/kvm/book3s_xics.c | 4 +- arch/powerpc/kvm/booke.c | 44 +- arch/powerpc/kvm/booke.h | 5 +- arch/powerpc/kvm/bookehv_interrupts.S | 11 + arch/powerpc/kvm/e500.c | 4 + arch/powerpc/kvm/e500.h | 8 +- arch/powerpc/kvm/e500_mmu.c | 2 +- arch/powerpc/kvm/e500_mmu_host.c | 59 +- arch/powerpc/kvm/e500mc.c | 4 + arch/powerpc/kvm/emulate.c | 1 - arch/powerpc/kvm/mpic.c | 1 + arch/powerpc/kvm/powerpc.c | 58 +- 42 files changed, 1575 insertions(+), 1077 deletions(-)
[PULL 01/36] powerpc: kvm: optimize "sc 1" as fast return
From: Liu Ping Fan <[email protected]>
In some scene, e.g openstack CI, PR guest can trigger "sc 1" frequently, this patch optimizes the path by directly delivering BOOK3S_INTERRUPT_SYSCALL to HV guest, so powernv can return to HV guest without heavy exit, i.e, no need to swap TLB, HTAB,.. etc
--- arch/powerpc/kvm/book3s_hv.c | 10 ++++------ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-)
arch/powerpc/kvm/book3s_hv.c +4 -6
@@ -669,12 +669,10 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,/* hcall - punt to userspace */ int i; -if (vcpu->arch.shregs.msr &MSR_PR ) { -/* sc 1 from userspace - reflect to guest syscall */ -kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_SYSCALL ); - r =RESUME_GUEST ; -break ; - } +/* hypercall with MSR_PR has already been handled in rmode, +* and never reaches here. +*/ + run->papr_hcall.nr =kvmppc_get_gpr (vcpu,3 );for (i =0 ; i <9 ; ++i) run->papr_hcall.args[i] =kvmppc_get_gpr (vcpu,4 + i);
arch/powerpc/kvm/book3s_hv_rmhandlers.S +18 -1
@@ -686,6 +686,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) 5: mtspr SPRN_SRR0, r6 mtspr SPRN_SRR1, r7 +/* + * Required state: + * R4 = vcpu + * R10: value for HSRR0 + * R11: value for HSRR1 + * R13 = PACA + */ fast_guest_return: li r0,0 stb r0,VCPU_CEDED(r4) /* cancel cede */
@@ -1471,7 +1478,8 @@ kvmppc_hisi: hcall_try_real_mode: ld r3,VCPU_GPR(R3)(r9) andi. r0,r11,MSR_PR - bne guest_exit_cont + /* sc 1 from userspace - reflect to guest syscall */ + bne sc_1_fast_return clrrdi r3,r3,2 cmpldi r3,hcall_real_table_end - hcall_real_table bge guest_exit_cont
@@ -1492,6 +1500,15 @@ hcall_try_real_mode: ld r11,VCPU_MSR(r4) b fast_guest_return +sc_1_fast_return: + mtspr SPRN_SRR0,r10 + mtspr SPRN_SRR1,r11 + li r10, BOOK3S_INTERRUPT_SYSCALL + li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ + rotldi r11, r11, 63 + mr r4,r9 + b fast_guest_return + /* We've attempted a real mode hcall, but it's punted it back * to userspace. We need to restore some clobbered volatiles * before resuming the pass-it-to-qemu path */
Signature · 1 line
1.8.1.4
[PULL 02/36] KVM: PPC: Add devname:kvm aliases for modules
In reply to Alexander GrafSystems that support automatic loading of kernel modules through device aliases should try and automatically load kvm when /dev/kvm gets opened.
Add code to support that magic for all PPC kvm targets, even the ones that don't support modules yet.
--- arch/powerpc/kvm/44x.c | 4 ++++ arch/powerpc/kvm/book3s.c | 8 ++++++++ arch/powerpc/kvm/book3s_hv.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 3 +++ arch/powerpc/kvm/e500.c | 4 ++++ arch/powerpc/kvm/e500mc.c | 4 ++++ 6 files changed, 26 insertions(+)
arch/powerpc/kvm/44x.c +4 -0
@@ -21,6 +21,8 @@#include <linux/slab.h> #include <linux/err.h> #include <linux/export.h> +#include <linux/module.h> +#include <linux/miscdevice.h> #include <asm/reg.h> #include <asm/cputable.h>
@@ -231,3 +233,5 @@ static void __exit kvmppc_44x_exit(void)module_init (kvmppc_44x_init);module_exit (kvmppc_44x_exit); +MODULE_ALIAS_MISCDEV (KVM_MINOR ); +MODULE_ALIAS ("devname:kvm" );
arch/powerpc/kvm/book3s.c +8 -0
@@ -18,6 +18,8 @@#include <linux/err.h> #include <linux/export.h> #include <linux/slab.h> +#include <linux/module.h> +#include <linux/miscdevice.h> #include <asm/reg.h> #include <asm/cputable.h>
@@ -879,3 +881,9 @@ static void kvmppc_book3s_exit(void)module_init (kvmppc_book3s_init);module_exit (kvmppc_book3s_exit); + +/* On 32bit this is our one and only kernel module */ +#ifdef CONFIG_KVM_BOOK3S_32 +MODULE_ALIAS_MISCDEV (KVM_MINOR ); +MODULE_ALIAS ("devname:kvm" ); +#endif
arch/powerpc/kvm/book3s_hv.c +3 -0
@@ -31,6 +31,7 @@#include <linux/spinlock.h> #include <linux/page-flags.h> #include <linux/srcu.h> +#include <linux/miscdevice.h> #include <asm/reg.h> #include <asm/cputable.h>
@@ -2216,3 +2217,5 @@ static void kvmppc_book3s_exit_hv(void)module_init (kvmppc_book3s_init_hv);module_exit (kvmppc_book3s_exit_hv);MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_MISCDEV (KVM_MINOR ); +MODULE_ALIAS ("devname:kvm" );
arch/powerpc/kvm/book3s_pr.c +3 -0
@@ -41,6 +41,7 @@#include <linux/vmalloc.h> #include <linux/highmem.h> #include <linux/module.h> +#include <linux/miscdevice.h> #include "book3s.h"
@@ -1584,4 +1585,6 @@ module_init(kvmppc_book3s_init_pr);module_exit (kvmppc_book3s_exit_pr);MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_MISCDEV (KVM_MINOR ); +MODULE_ALIAS ("devname:kvm" );#endif
arch/powerpc/kvm/e500.c +4 -0
@@ -16,6 +16,8 @@#include <linux/slab.h> #include <linux/err.h> #include <linux/export.h> +#include <linux/module.h> +#include <linux/miscdevice.h> #include <asm/reg.h> #include <asm/cputable.h>
@@ -573,3 +575,5 @@ static void __exit kvmppc_e500_exit(void)module_init (kvmppc_e500_init);module_exit (kvmppc_e500_exit); +MODULE_ALIAS_MISCDEV (KVM_MINOR ); +MODULE_ALIAS ("devname:kvm" );
arch/powerpc/kvm/e500mc.c +4 -0
@@ -16,6 +16,8 @@#include <linux/slab.h> #include <linux/err.h> #include <linux/export.h> +#include <linux/miscdevice.h> +#include <linux/module.h> #include <asm/reg.h> #include <asm/cputable.h>
@@ -391,3 +393,5 @@ static void __exit kvmppc_e500mc_exit(void)module_init (kvmppc_e500mc_init);module_exit (kvmppc_e500mc_exit); +MODULE_ALIAS_MISCDEV (KVM_MINOR ); +MODULE_ALIAS ("devname:kvm" );
Signature · 1 line
1.8.1.4
[PULL 03/36] KVM: PPC: fix couple of memory leaks in MPIC/XICS devices
In reply to Alexander GrafFrom: Gleb Natapov <[email protected]>
XICS failed to free xics structure on error path. MPIC destroy handler forgot to delete kvm_device structure.
--- arch/powerpc/kvm/book3s_xics.c | 4 +++- arch/powerpc/kvm/mpic.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_xics.c +3 -1
@@ -1246,8 +1246,10 @@ static int kvmppc_xics_create(struct kvm_device *dev, u32 type) kvm->arch.xics = xics;mutex_unlock (&kvm->lock); -if (ret) +if (ret) { +kfree (xics);return ret; + }xics_debugfs_init (xics);
arch/powerpc/kvm/mpic.c +1 -0
@@ -1635,6 +1635,7 @@ static void mpic_destroy(struct kvm_device *dev) dev->kvm->arch.mpic =NULL ;kfree (opp); +kfree (dev); }static int mpic_set_default_irq_routing (struct openpic *opp)
Signature · 1 line
1.8.1.4
[PULL 04/36] kvm/powerpc: rename kvm_hypercall() to epapr_hypercall()
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
kvm_hypercall() have nothing KVM specific, so renamed to epapr_hypercall(). Also this in moved to arch/powerpc/include/asm/epapr_hcalls.h
--- arch/powerpc/include/asm/epapr_hcalls.h | 46 +++++++++++++++++++++++++++++++++ arch/powerpc/include/asm/kvm_para.h | 23 +++++------------ arch/powerpc/kernel/kvm.c | 41 ++--------------------------- 3 files changed, 54 insertions(+), 56 deletions(-)
arch/powerpc/include/asm/epapr_hcalls.h +46 -0
@@ -460,5 +460,51 @@ static inline unsigned int ev_idle(void)return r3; } + +#ifdef CONFIG_EPAPR_PARAVIRT +static inline unsigned long epapr_hypercall (unsigned long *in, +unsigned long *out, +unsigned long nr) +{ +unsigned long register r0 asm("r0" ); + unsigned long register r3 asm("r3") = in[0]; + unsigned long register r4 asm("r4") = in[1]; + unsigned long register r5 asm("r5") = in[2]; + unsigned long register r6 asm("r6") = in[3]; + unsigned long register r7 asm("r7") = in[4]; + unsigned long register r8 asm("r8") = in[5]; + unsigned long register r9 asm("r9") = in[6]; + unsigned long register r10 asm("r10") = in[7]; + unsigned long register r11 asm("r11") = nr; +unsigned long register r12 asm("r12" ); + + asmvolatile ("bl epapr_hypercall_start" + :"=r" (r0),"=r" (r3),"=r" (r4),"=r" (r5),"=r" (r6), +"=r" (r7),"=r" (r8),"=r" (r9),"=r" (r10),"=r" (r11), +"=r" (r12) + :"r" (r3),"r" (r4),"r" (r5),"r" (r6),"r" (r7),"r" (r8), +"r" (r9),"r" (r10),"r" (r11) + :"memory" ,"cc" ,"xer" ,"ctr" ,"lr" ); + + out[0 ] = r4; + out[1 ] = r5; + out[2 ] = r6; + out[3 ] = r7; + out[4 ] = r8; + out[5 ] = r9; + out[6 ] = r10; + out[7 ] = r11; + +return r3; +} +#else +static unsigned long epapr_hypercall (unsigned long *in, +unsigned long *out, +unsigned long nr) +{ +return EV_UNIMPLEMENTED ; +} +#endif +#endif /* !__ASSEMBLY__ */ #endif /* _EPAPR_HCALLS_H */
arch/powerpc/include/asm/kvm_para.h +6 -17
@@ -39,10 +39,6 @@ static inline int kvm_para_available(void) return 1; } -extern unsigned long kvm_hypercall (unsigned long *in, -unsigned long *out, -unsigned long nr); -#else static inline int kvm_para_available (void )
@@ -50,13 +46,6 @@ static inline int kvm_para_available(void) return 0; } -static unsigned long kvm_hypercall (unsigned long *in, -unsigned long *out, -unsigned long nr) -{ -return EV_UNIMPLEMENTED ; -} -#endif static inline long kvm_hypercall0_1 (unsigned int nr,unsigned long *r2)
@@ -65,7 +54,7 @@ static inline long kvm_hypercall0_1(unsigned int nr, unsigned long *r2)unsigned long out[8 ];unsigned long r; - r =kvm_hypercall (in, out,KVM_HCALL_TOKEN (nr)); + r =epapr_hypercall (in, out,KVM_HCALL_TOKEN (nr)); *r2 = out[0 ];return r;
@@ -76,7 +65,7 @@ static inline long kvm_hypercall0(unsigned int nr)unsigned long in[8 ];unsigned long out[8 ]; -return kvm_hypercall (in, out,KVM_HCALL_TOKEN (nr)); +return epapr_hypercall (in, out,KVM_HCALL_TOKEN (nr)); }static inline long kvm_hypercall1 (unsigned int nr,unsigned long p1)
@@ -85,7 +74,7 @@ static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)unsigned long out[8 ]; in[0 ] = p1; -return kvm_hypercall (in, out,KVM_HCALL_TOKEN (nr)); +return epapr_hypercall (in, out,KVM_HCALL_TOKEN (nr)); } static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
@@ -96,7 +85,7 @@ static inline long kvm_hypercall2(unsigned int nr, unsigned long p1, in[0 ] = p1; in[1 ] = p2; -return kvm_hypercall (in, out,KVM_HCALL_TOKEN (nr)); +return epapr_hypercall (in, out,KVM_HCALL_TOKEN (nr)); } static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
@@ -108,7 +97,7 @@ static inline long kvm_hypercall3(unsigned int nr, unsigned long p1, in[0 ] = p1; in[1 ] = p2; in[2 ] = p3; -return kvm_hypercall (in, out,KVM_HCALL_TOKEN (nr)); +return epapr_hypercall (in, out,KVM_HCALL_TOKEN (nr)); } static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
@@ -122,7 +111,7 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, in[1 ] = p2; in[2 ] = p3; in[3 ] = p4; -return kvm_hypercall (in, out,KVM_HCALL_TOKEN (nr)); +return epapr_hypercall (in, out,KVM_HCALL_TOKEN (nr)); }
arch/powerpc/kernel/kvm.c +2 -39
58 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 05/36] kvm/powerpc: move kvm_hypercall0() and friends to epapr_hypercall0()
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
kvm_hypercall0() and friends have nothing KVM specific so moved to epapr_hypercall0() and friends. Also they are moved from arch/powerpc/include/asm/kvm_para.h to arch/powerpc/include/asm/epapr_hcalls.h
--- arch/powerpc/include/asm/epapr_hcalls.h | 65 +++++++++++++++++++++++++++++++ arch/powerpc/include/asm/kvm_para.h | 69 +-------------------------------- 2 files changed, 66 insertions(+), 68 deletions(-)
arch/powerpc/include/asm/epapr_hcalls.h +65 -0
@@ -506,5 +506,70 @@ static unsigned long epapr_hypercall(unsigned long *in, }#endif +static inline long epapr_hypercall0_1 (unsigned int nr,unsigned long *r2) +{ +unsigned long in[8 ]; +unsigned long out[8 ]; +unsigned long r; + + r =epapr_hypercall (in, out, nr); + *r2 = out[0 ]; + +return r; +} + +static inline long epapr_hypercall0 (unsigned int nr) +{ +unsigned long in[8 ]; +unsigned long out[8 ]; + +return epapr_hypercall (in, out, nr); +} + +static inline long epapr_hypercall1 (unsigned int nr,unsigned long p1) +{ +unsigned long in[8 ]; +unsigned long out[8 ]; + + in[0 ] = p1; +return epapr_hypercall (in, out, nr); +} + +static inline long epapr_hypercall2 (unsigned int nr,unsigned long p1, +unsigned long p2) +{ +unsigned long in[8 ]; +unsigned long out[8 ]; + + in[0 ] = p1; + in[1 ] = p2; +return epapr_hypercall (in, out, nr); +} + +static inline long epapr_hypercall3 (unsigned int nr,unsigned long p1, +unsigned long p2,unsigned long p3) +{ +unsigned long in[8 ]; +unsigned long out[8 ]; + + in[0 ] = p1; + in[1 ] = p2; + in[2 ] = p3; +return epapr_hypercall (in, out, nr); +} + +static inline long epapr_hypercall4 (unsigned int nr,unsigned long p1, +unsigned long p2,unsigned long p3, +unsigned long p4) +{ +unsigned long in[8 ]; +unsigned long out[8 ]; + + in[0 ] = p1; + in[1 ] = p2; + in[2 ] = p3; + in[3 ] = p4; +return epapr_hypercall (in, out, nr); +}#endif /* !__ASSEMBLY__ */ #endif /* _EPAPR_HCALLS_H */
arch/powerpc/include/asm/kvm_para.h +1 -68
81 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 06/36] KVM: PPC: Use load_fp/vr_state rather than load_up_fpu/altivec
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The load_up_fpu and load_up_altivec functions were never intended to be called from C, and do things like modifying the MSR value in their callers' stack frames, which are assumed to be interrupt frames. In addition, on 32-bit Book S they require the MMU to be off.
This makes KVM use the new load_fp_state() and load_vr_state() functions instead of load_up_fpu/altivec. This means we can remove the assembler glue in book3s_rmhandlers.S, and potentially fixes a bug on Book E, where load_up_fpu was called directly from C.
--- arch/powerpc/include/asm/kvm_book3s.h | 3 --- arch/powerpc/include/asm/switch_to.h | 2 -- arch/powerpc/kvm/book3s_exports.c | 4 --- arch/powerpc/kvm/book3s_pr.c | 18 +++++++++----- arch/powerpc/kvm/book3s_rmhandlers.S | 47 ----------------------------------- arch/powerpc/kvm/booke.h | 3 ++- 6 files changed, 14 insertions(+), 63 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -3
@@ -186,9 +186,6 @@ extern void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr,extern void kvmppc_entry_trampoline (void );extern void kvmppc_hv_entry_trampoline (void ); -extern void kvmppc_load_up_fpu (void ); -extern void kvmppc_load_up_altivec (void ); -extern void kvmppc_load_up_vsx (void );extern u32 kvmppc_alignment_dsisr (struct kvm_vcpu *vcpu,unsigned int inst);extern ulong kvmppc_alignment_dar (struct kvm_vcpu *vcpu,unsigned int inst);extern int kvmppc_h_pr (struct kvm_vcpu *vcpu,unsigned long cmd);
arch/powerpc/include/asm/switch_to.h +0 -2
@@ -25,10 +25,8 @@ static inline void save_tar(struct thread_struct *prev)static inline void save_tar (struct thread_struct *prev) {}#endif -extern void load_up_fpu (void );extern void enable_kernel_fp (void );extern void enable_kernel_altivec (void ); -extern void load_up_altivec (struct task_struct *);extern int emulate_altivec (struct pt_regs *);extern void __giveup_vsx (struct task_struct *);extern void giveup_vsx (struct task_struct *);
arch/powerpc/kvm/book3s_exports.c +0 -4
@@ -25,9 +25,5 @@ EXPORT_SYMBOL_GPL(kvmppc_hv_entry_trampoline);#endif #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE EXPORT_SYMBOL_GPL (kvmppc_entry_trampoline); -EXPORT_SYMBOL_GPL (kvmppc_load_up_fpu); -#ifdef CONFIG_ALTIVEC -EXPORT_SYMBOL_GPL (kvmppc_load_up_altivec); -#endif #endif
arch/powerpc/kvm/book3s_pr.c +12 -6
@@ -691,7 +691,8 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,#endif t->fp_state.fpscr = vcpu->arch.fpscr; t->fpexc_mode =0 ; -kvmppc_load_up_fpu (); +enable_kernel_fp (); +load_fp_state (&t->fp_state); }if (msr &MSR_VEC ) {
@@ -699,7 +700,8 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,memcpy (t->vr_state.vr, vcpu->arch.vr,sizeof (vcpu->arch.vr)); t->vr_state.vscr = vcpu->arch.vscr; t->vrsave =-1 ; -kvmppc_load_up_altivec (); +enable_kernel_altivec (); +load_vr_state (&t->vr_state);#endif }
@@ -722,11 +724,15 @@ static void kvmppc_handle_lost_ext(struct kvm_vcpu *vcpu)if (!lost_ext)return ; -if (lost_ext &MSR_FP ) -kvmppc_load_up_fpu (); +if (lost_ext &MSR_FP ) { +enable_kernel_fp (); +load_fp_state (¤t->thread.fp_state); + }#ifdef CONFIG_ALTIVEC -if (lost_ext &MSR_VEC ) -kvmppc_load_up_altivec (); +if (lost_ext &MSR_VEC ) { +enable_kernel_altivec (); +load_vr_state (¤t->thread.vr_state); + }#endif current->thread.regs->msr |= lost_ext; }
arch/powerpc/kvm/book3s_rmhandlers.S +0 -47
51 lines not on this page · raw message
arch/powerpc/kvm/booke.h +2 -1
@@ -136,7 +136,8 @@ 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 (); +enable_kernel_fp (); +load_fp_state (¤t->thread.fp_state); current->thread.regs->msr |=MSR_FP ; }#endif
Signature · 1 line
1.8.1.4
[PULL 07/36] KVM: PPC: Store FP/VSX/VMX state in thread_fp/vr_state structures
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This uses struct thread_fp_state and struct thread_vr_state to store the floating-point, VMX/Altivec and VSX state, rather than flat arrays. This makes transferring the state to/from the thread_struct simpler and allows us to unify the get/set_one_reg implementations for the VSX registers.
--- arch/powerpc/include/asm/kvm_host.h | 12 +-- arch/powerpc/kernel/asm-offsets.c | 11 +- arch/powerpc/kvm/book3s.c | 38 +++++-- arch/powerpc/kvm/book3s_hv.c | 42 -------- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 +- arch/powerpc/kvm/book3s_paired_singles.c | 169 +++++++++++++++---------------- arch/powerpc/kvm/book3s_pr.c | 63 +----------- arch/powerpc/kvm/booke.c | 8 +- arch/powerpc/kvm/powerpc.c | 4 +- 9 files changed, 131 insertions(+), 220 deletions(-)
arch/powerpc/include/asm/kvm_host.h +4 -8
@@ -410,8 +410,7 @@ struct kvm_vcpu_arch {ulong gpr[32 ]; -u64 fpr[32 ]; -u64 fpscr; +struct thread_fp_state fp;#ifdef CONFIG_SPE ulong evr[32 ];
@@ -420,12 +419,7 @@ struct kvm_vcpu_arch {u64 acc;#endif #ifdef CONFIG_ALTIVEC -vector128 vr[32 ]; -vector128 vscr; -#endif - -#ifdef CONFIG_VSX -u64 vsr[64 ]; +struct thread_vr_state vr;#endif #ifdef CONFIG_KVM_BOOKE_HV
@@ -619,6 +613,8 @@ struct kvm_vcpu_arch {#endif }; +#define VCPU_FPR (vcpu, i) (vcpu)->arch.fp.fpr[i][TS_FPROFFSET] +/* Values for vcpu->arch.state */ #define KVMPPC_VCPU_NOTREADY 0#define KVMPPC_VCPU_RUNNABLE 1
arch/powerpc/kernel/asm-offsets.c +4 -7
@@ -425,14 +425,11 @@ int main(void) 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)); - DEFINE(VCPU_FPSCR, offsetof(struct kvm_vcpu, arch.fpscr)); + DEFINE(VCPU_FPRS, offsetof(struct kvm_vcpu, arch.fp.fpr)); + DEFINE(VCPU_FPSCR, offsetof(struct kvm_vcpu, arch.fp.fpscr));#ifdef CONFIG_ALTIVEC - DEFINE(VCPU_VRS, offsetof(struct kvm_vcpu, arch.vr)); - DEFINE(VCPU_VSCR, offsetof(struct kvm_vcpu, arch.vscr)); -#endif -#ifdef CONFIG_VSX - DEFINE(VCPU_VSRS, offsetof(struct kvm_vcpu, arch.vsr)); + DEFINE(VCPU_VRS, offsetof(struct kvm_vcpu, arch.vr.vr)); + DEFINE(VCPU_VSCR, offsetof(struct kvm_vcpu, arch.vr.vscr));#endif DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr));
arch/powerpc/kvm/book3s.c +30 -8
@@ -577,10 +577,10 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)break ; case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: i = reg->id -KVM_REG_PPC_FPR0 ; - val =get_reg_val (reg->id, vcpu->arch.fpr[i]); + val =get_reg_val (reg->id,VCPU_FPR (vcpu, i));break ;case KVM_REG_PPC_FPSCR : - val =get_reg_val (reg->id, vcpu->arch.fpscr); + val =get_reg_val (reg->id, vcpu->arch.fp.fpscr);break ;#ifdef CONFIG_ALTIVEC case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
@@ -588,19 +588,30 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) r = -ENXIO ;break ; } - val.vval = vcpu->arch.vr[reg->id -KVM_REG_PPC_VR0 ]; + val.vval = vcpu->arch.vr.vr[reg->id -KVM_REG_PPC_VR0 ];break ;case KVM_REG_PPC_VSCR :if (!cpu_has_feature (CPU_FTR_ALTIVEC )) { r = -ENXIO ;break ; } - val =get_reg_val (reg->id, vcpu->arch.vscr.u[3 ]); + val =get_reg_val (reg->id, vcpu->arch.vr.vscr.u[3 ]);break ;case KVM_REG_PPC_VRSAVE : val =get_reg_val (reg->id, vcpu->arch.vrsave);break ;#endif /* CONFIG_ALTIVEC */ +#ifdef CONFIG_VSX + case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: +if (cpu_has_feature (CPU_FTR_VSX )) { +long int i = reg->id -KVM_REG_PPC_VSR0 ; + val.vsxval[0 ] = vcpu->arch.fp.fpr[i][0 ]; + val.vsxval[1 ] = vcpu->arch.fp.fpr[i][1 ]; + }else { + r = -ENXIO ; + } +break ; +#endif /* CONFIG_VSX */ case KVM_REG_PPC_DEBUG_INST : {u32 opcode =INS_TW ; r = copy_to_user((u32 __user *)(long)reg->addr,
@@ -656,10 +667,10 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)break ; case KVM_REG_PPC_FPR0 ... KVM_REG_PPC_FPR31: i = reg->id -KVM_REG_PPC_FPR0 ; - vcpu->arch.fpr[i] =set_reg_val (reg->id, val); +VCPU_FPR (vcpu, i) =set_reg_val (reg->id, val);break ;case KVM_REG_PPC_FPSCR : - vcpu->arch.fpscr =set_reg_val (reg->id, val); + vcpu->arch.fp.fpscr =set_reg_val (reg->id, val);break ;#ifdef CONFIG_ALTIVEC case KVM_REG_PPC_VR0 ... KVM_REG_PPC_VR31:
@@ -667,14 +678,14 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) r = -ENXIO ;break ; } - vcpu->arch.vr[reg->id -KVM_REG_PPC_VR0 ] = val.vval; + vcpu->arch.vr.vr[reg->id -KVM_REG_PPC_VR0 ] = val.vval;break ;case KVM_REG_PPC_VSCR :if (!cpu_has_feature (CPU_FTR_ALTIVEC )) { r = -ENXIO ;break ; } - vcpu->arch.vscr.u[3 ] =set_reg_val (reg->id, val); + vcpu->arch.vr.vscr.u[3 ] =set_reg_val (reg->id, val);break ;case KVM_REG_PPC_VRSAVE :if (!cpu_has_feature (CPU_FTR_ALTIVEC )) {
@@ -684,6 +695,17 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) vcpu->arch.vrsave =set_reg_val (reg->id, val);break ;#endif /* CONFIG_ALTIVEC */ +#ifdef CONFIG_VSX + case KVM_REG_PPC_VSR0 ... KVM_REG_PPC_VSR31: +if (cpu_has_feature (CPU_FTR_VSX )) { +long int i = reg->id -KVM_REG_PPC_VSR0 ; + vcpu->arch.fp.fpr[i][0 ] = val.vsxval[0 ]; + vcpu->arch.fp.fpr[i][1 ] = val.vsxval[1 ]; + }else { + r = -ENXIO ; + } +break ; +#endif /* CONFIG_VSX */ #ifdef CONFIG_KVM_XICS case KVM_REG_PPC_ICP_STATE :if (!vcpu->arch.icp) {
arch/powerpc/kvm/book3s_hv.c +0 -42
54 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +2 -2
@@ -1889,7 +1889,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) BEGIN_FTR_SECTION reg = 0 .rept 32 - li r6,reg*16+VCPU_VSRS + li r6,reg*16+VCPU_FPRS STXVD2X(reg,R6,R3) reg = reg + 1 .endr
@@ -1951,7 +1951,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) BEGIN_FTR_SECTION reg = 0 .rept 32 - li r7,reg*16+VCPU_VSRS + li r7,reg*16+VCPU_FPRS LXVD2X(reg,R7,R4) reg = reg + 1 .endr
arch/powerpc/kvm/book3s_paired_singles.c +83 -86
455 lines not on this page · raw message
arch/powerpc/kvm/book3s_pr.c +4 -59
111 lines not on this page · raw message
arch/powerpc/kvm/booke.c +2 -6
@@ -707,9 +707,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) fpexc_mode = current->thread.fpexc_mode;/* Restore guest FPU state to thread */ -memcpy (current->thread.fp_state.fpr, vcpu->arch.fpr, -sizeof (vcpu->arch.fpr)); - current->thread.fp_state.fpscr = vcpu->arch.fpscr; + current->thread.fp_state = vcpu->arch.fp;/* * Since we can't trap on MSR_FP in GS-mode, we consider the guest
@@ -745,9 +743,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) vcpu->fpu_active =0 ;/* Save guest FPU state from thread */ -memcpy (vcpu->arch.fpr, current->thread.fp_state.fpr, -sizeof (vcpu->arch.fpr)); - vcpu->arch.fpscr = current->thread.fp_state.fpscr; + vcpu->arch.fp = current->thread.fp_state;/* Restore userspace FPU state from stack */ current->thread.fp_state = fp;
arch/powerpc/kvm/powerpc.c +2 -2
@@ -656,14 +656,14 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu,kvmppc_set_gpr (vcpu, vcpu->arch.io_gpr, gpr);break ;case KVM_MMIO_REG_FPR : - vcpu->arch.fpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr; +VCPU_FPR (vcpu, vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ) = gpr;break ;#ifdef CONFIG_PPC_BOOK3S case KVM_MMIO_REG_QPR : vcpu->arch.qpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr;break ;case KVM_MMIO_REG_FQPR : - vcpu->arch.fpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr; +VCPU_FPR (vcpu, vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ) = gpr; vcpu->arch.qpr[vcpu->arch.io_gpr &KVM_MMIO_REG_MASK ] = gpr;break ;#endif
Signature · 1 line
1.8.1.4
[PULL 08/36] KVM: PPC: Load/save FP/VMX/VSX state directly to/from vcpu struct
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Now that we have the vcpu floating-point and vector state stored in the same type of struct as the main kernel uses, we can load that state directly from the vcpu struct instead of having extra copies to/from the thread_struct. Similarly, when the guest state needs to be saved, we can have it saved it directly to the vcpu struct by setting the current->thread.fp_save_area and current->thread.vr_save_area pointers. That also means that we don't need to back up and restore userspace's FP/vector state. This all makes the code simpler and faster.
Note that it's not necessary to save or modify current->thread.fpexc_mode, since nothing in KVM uses or is affected by its value. Nor is it necessary to touch used_vr or used_vsr.
--- arch/powerpc/kvm/book3s_pr.c | 72 ++++++++++---------------------------------- arch/powerpc/kvm/booke.c | 16 ---------- arch/powerpc/kvm/booke.h | 4 ++- 3 files changed, 19 insertions(+), 73 deletions(-)
arch/powerpc/kvm/book3s_pr.c +16 -56
@@ -567,16 +567,16 @@ void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr)* both the traditional FP registers and the added VSX * registers into thread.fp_state.fpr[]. */ -if (current->thread.regs->msr &MSR_FP ) +if (t->regs->msr &MSR_FP )giveup_fpu (current); - vcpu->arch.fp = t->fp_state; + t->fp_save_area =NULL ; }#ifdef CONFIG_ALTIVEC if (msr &MSR_VEC ) {if (current->thread.regs->msr &MSR_VEC )giveup_altivec (current); - vcpu->arch.vr = t->vr_state; + t->vr_save_area =NULL ; }#endif
@@ -661,22 +661,20 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,#endif if (msr &MSR_FP ) { - t->fp_state = vcpu->arch.fp; - t->fpexc_mode =0 ;enable_kernel_fp (); -load_fp_state (&t->fp_state); +load_fp_state (&vcpu->arch.fp); + t->fp_save_area = &vcpu->arch.fp; }if (msr &MSR_VEC ) {#ifdef CONFIG_ALTIVEC - t->vr_state = vcpu->arch.vr; - t->vrsave =-1 ;enable_kernel_altivec (); -load_vr_state (&t->vr_state); +load_vr_state (&vcpu->arch.vr); + t->vr_save_area = &vcpu->arch.vr;#endif } - current->thread.regs->msr |= msr; + t->regs->msr |= msr; vcpu->arch.guest_owned_ext |= msr;kvmppc_recalc_shadow_msr (vcpu);
@@ -697,12 +695,12 @@ static void kvmppc_handle_lost_ext(struct kvm_vcpu *vcpu)if (lost_ext &MSR_FP ) {enable_kernel_fp (); -load_fp_state (¤t->thread.fp_state); +load_fp_state (&vcpu->arch.fp); }#ifdef CONFIG_ALTIVEC if (lost_ext &MSR_VEC ) {enable_kernel_altivec (); -load_vr_state (¤t->thread.vr_state); +load_vr_state (&vcpu->arch.vr); }#endif current->thread.regs->msr |= lost_ext;
@@ -1204,17 +1202,9 @@ static void kvmppc_core_vcpu_free_pr(struct kvm_vcpu *vcpu)static int kvmppc_vcpu_run_pr (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) {int ret; -struct thread_fp_state fp; -int fpexc_mode;#ifdef CONFIG_ALTIVEC -struct thread_vr_state vr;unsigned long uninitialized_var (vrsave ); -int used_vr;#endif -#ifdef CONFIG_VSX -int used_vsr; -#endif -ulong ext_msr;/* Check if we can run the vcpu at all */ if (!vcpu->arch.sane) {
@@ -1236,33 +1226,22 @@ static int kvmppc_vcpu_run_pr(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) goto out; } -/* Save FPU state in stack */ +/* Save FPU state in thread_struct */ if (current->thread.regs->msr &MSR_FP )giveup_fpu (current); - fp = current->thread.fp_state; - fpexc_mode = current->thread.fpexc_mode;#ifdef CONFIG_ALTIVEC -/* Save Altivec state in stack */ - used_vr = current->thread.used_vr; -if (used_vr) { -if (current->thread.regs->msr &MSR_VEC ) -giveup_altivec (current); - vr = current->thread.vr_state; - vrsave = current->thread.vrsave; - } +/* Save Altivec state in thread_struct */ +if (current->thread.regs->msr &MSR_VEC ) +giveup_altivec (current);#endif #ifdef CONFIG_VSX -/* Save VSX state in stack */ - used_vsr = current->thread.used_vsr; -if (used_vsr && (current->thread.regs->msr &MSR_VSX )) +/* Save VSX state in thread_struct */ +if (current->thread.regs->msr &MSR_VSX )__giveup_vsx (current);#endif -/* Remember the MSR with disabled extensions */ - ext_msr = current->thread.regs->msr; -/* Preload FPU if it's enabled */ if (vcpu->arch.shared->msr &MSR_FP )kvmppc_handle_ext (vcpu,BOOK3S_INTERRUPT_FP_UNAVAIL ,MSR_FP );
@@ -1277,25 +1256,6 @@ static int kvmppc_vcpu_run_pr(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)/* Make sure we save the guest FPU/Altivec/VSX state */ kvmppc_giveup_ext (vcpu,MSR_FP |MSR_VEC |MSR_VSX ); - current->thread.regs->msr = ext_msr; - -/* Restore FPU/VSX state from stack */ - current->thread.fp_state = fp; - current->thread.fpexc_mode = fpexc_mode; - -#ifdef CONFIG_ALTIVEC -/* Restore Altivec state from stack */ -if (used_vr && current->thread.used_vr) { - current->thread.vr_state = vr; - current->thread.vrsave = vrsave; - } - current->thread.used_vr = used_vr; -#endif - -#ifdef CONFIG_VSX - current->thread.used_vsr = used_vsr; -#endif - out: vcpu->mode =OUTSIDE_GUEST_MODE ;return ret;
arch/powerpc/kvm/booke.c +0 -16
@@ -682,10 +682,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) {int ret, s;struct thread_struct thread; -#ifdef CONFIG_PPC_FPU -struct thread_fp_state fp; -int fpexc_mode; -#endif if (!vcpu->arch.sane) { kvm_run->exit_reason =KVM_EXIT_INTERNAL_ERROR ;
@@ -703,11 +699,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)#ifdef CONFIG_PPC_FPU /* Save userspace FPU state in stack */ enable_kernel_fp (); - fp = current->thread.fp_state; - fpexc_mode = current->thread.fpexc_mode; - -/* Restore guest FPU state to thread */ - current->thread.fp_state = vcpu->arch.fp;/* * Since we can't trap on MSR_FP in GS-mode, we consider the guest
@@ -741,13 +732,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)kvmppc_save_guest_fp (vcpu); vcpu->fpu_active =0 ; - -/* Save guest FPU state from thread */ - vcpu->arch.fp = current->thread.fp_state; - -/* Restore userspace FPU state from stack */ - current->thread.fp_state = fp; - current->thread.fpexc_mode = fpexc_mode;#endif out:
arch/powerpc/kvm/booke.h +3 -1
@@ -137,7 +137,8 @@ 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 )) {enable_kernel_fp (); -load_fp_state (¤t->thread.fp_state); +load_fp_state (&vcpu->arch.fp); + current->thread.fp_save_area = &vcpu->arch.fp; current->thread.regs->msr |=MSR_FP ; }#endif
@@ -152,6 +153,7 @@ 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); + current->thread.fp_save_area =NULL ;#endif }
Signature · 1 line
1.8.1.4
[PULL 09/36] KVM: PPC: Book3S HV: Use load/store_fp_state functions in HV guest entry/exit
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This modifies kvmppc_load_fp and kvmppc_save_fp to use the generic FP/VSX and VMX load/store functions instead of open-coding the FP/VSX/VMX load/store instructions. Since kvmppc_load/save_fp don't follow C calling conventions, we make them private symbols within book3s_hv_rmhandlers.S.
--- arch/powerpc/kernel/asm-offsets.c | 2 - arch/powerpc/kvm/book3s_hv_rmhandlers.S | 86 +++++++++------------------------ 2 files changed, 22 insertions(+), 66 deletions(-)
arch/powerpc/kernel/asm-offsets.c +0 -2
@@ -426,10 +426,8 @@ int main(void) 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.fp.fpr)); - DEFINE(VCPU_FPSCR, offsetof(struct kvm_vcpu, arch.fp.fpscr));#ifdef CONFIG_ALTIVEC DEFINE(VCPU_VRS, offsetof(struct kvm_vcpu, arch.vr.vr)); - DEFINE(VCPU_VSCR, offsetof(struct kvm_vcpu, arch.vr.vscr));#endif DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr));
arch/powerpc/kvm/book3s_hv_rmhandlers.S +22 -64
137 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 10/36] kvm: booke: clear host tlb reference flag on guest tlb invalidation
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
On booke, "struct tlbe_ref" contains host tlb mapping information (pfn: for guest-pfn to pfn, flags: attribute associated with this mapping) for a guest tlb entry. So when a guest creates a TLB entry then "struct tlbe_ref" is set to point to valid "pfn" and set attributes in "flags" field of the above said structure. When a guest TLB entry is invalidated then flags field of corresponding "struct tlbe_ref" is updated to point that this is no more valid, also we selectively clear some other attribute bits, example: if E500_TLB_BITMAP was set then we clear E500_TLB_BITMAP, if E500_TLB_TLB0 is set then we clear this.
Ideally we should clear complete "flags" as this entry is invalid and does not have anything to re-used. The other part of the problem is that when we use the same entry again then also we do not clear (started doing or-ing etc).
So far it was working because the selectively clearing mentioned above actually clears "flags" what was set during TLB mapping. But the problem starts coming when we add more attributes to this then we need to selectively clear them and which is not needed.
--- arch/powerpc/kvm/e500_mmu_host.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/powerpc/kvm/e500_mmu_host.c +8 -8
@@ -231,15 +231,15 @@ void inval_gtlbe_on_host(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel, ref->flags &= ~(E500_TLB_TLB0 |E500_TLB_VALID ); } -/* Already invalidated in between */ -if (!(ref->flags &E500_TLB_VALID )) -return ; - -/* Guest tlbe is backed by at most one host tlbe per shadow pid. */ -kvmppc_e500_tlbil_one (vcpu_e500, gtlbe); +/* +* If TLB entry is still valid then it's a TLB0 entry, and thus +* backed by at most one host tlbe per shadow pid +*/ +if (ref->flags &E500_TLB_VALID ) +kvmppc_e500_tlbil_one (vcpu_e500, gtlbe);/* Mark the TLB as not backed by the host anymore */ - ref->flags &= ~E500_TLB_VALID ; + ref->flags =0 ; }static inline int tlbe_is_writable (struct kvm_book3e_206_tlb_entry *tlbe)
@@ -252,7 +252,7 @@ static inline void kvmppc_e500_ref_setup(struct tlbe_ref *ref, pfn_t pfn) { ref->pfn = pfn; - ref->flags |=E500_TLB_VALID ; + ref->flags =E500_TLB_VALID ;/* Mark the page accessed */ kvm_set_pfn_accessed (pfn);
Signature · 1 line
1.8.1.4
[PULL 11/36] kvm: book3s: rename lookup_linux_pte() to lookup_linux_pte_and_update()
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
lookup_linux_pte() is doing more than lookup, updating the pte, so for clarity it is renamed to lookup_linux_pte_and_update()
--- arch/powerpc/kvm/book3s_hv_rm_mmu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv_rm_mmu.c +5 -3
@@ -134,7 +134,7 @@ static void remove_revmap_chain(struct kvm *kvm, long pte_index,unlock_rmap (rmap); } -static pte_t lookup_linux_pte (pgd_t *pgdir,unsigned long hva, +static pte_t lookup_linux_pte_and_update (pgd_t *pgdir,unsigned long hva,int writing,unsigned long *pte_sizep) {pte_t *ptep;
@@ -231,7 +231,8 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,/* Look up the Linux PTE for the backing page */ pte_size = psize; - pte =lookup_linux_pte (pgdir, hva, writing, &pte_size); + pte =lookup_linux_pte_and_update (pgdir, hva, writing, + &pte_size);if (pte_present (pte)) {if (writing && !pte_write (pte))/* make the actual HPTE be read-only */
@@ -671,7 +672,8 @@ long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags, memslot =__gfn_to_memslot (kvm_memslots (kvm), gfn);if (memslot) { hva =__gfn_to_hva_memslot (memslot, gfn); - pte =lookup_linux_pte (pgdir, hva,1 , &psize); + pte =lookup_linux_pte_and_update (pgdir, hva, +1 , &psize);if (pte_present (pte) && !pte_write (pte)) r =hpte_make_readonly (r); }
Signature · 1 line
1.8.1.4
[PULL 12/36] kvm: powerpc: define a linux pte lookup function
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
We need to search linux "pte" to get "pte" attributes for setting TLB in KVM. This patch defines a lookup_linux_ptep() function which returns pte pointer.
--- arch/powerpc/include/asm/pgtable.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/powerpc/include/asm/pgtable.h +21 -0
@@ -223,6 +223,27 @@ extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,#endif pte_t *find_linux_pte_or_hugepte (pgd_t *pgdir,unsigned long ea,unsigned *shift); + +static inline pte_t *lookup_linux_ptep (pgd_t *pgdir,unsigned long hva, +unsigned long *pte_sizep) +{ +pte_t *ptep; +unsigned long ps = *pte_sizep; +unsigned int shift; + + ptep =find_linux_pte_or_hugepte (pgdir, hva, &shift); +if (!ptep) +return NULL ; +if (shift) + *pte_sizep =1ul << shift; +else + *pte_sizep =PAGE_SIZE ; + +if (ps > *pte_sizep) +return NULL ; + +return ptep; +}#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */
Signature · 1 line
1.8.1.4
[PULL 13/36] kvm: powerpc: use caching attributes as per linux pte
In reply to Alexander GrafFrom: Bharat Bhushan <[email protected]>
KVM uses same WIM tlb attributes as the corresponding qemu pte. For this we now search the linux pte for the requested page and get these cache caching/coherency attributes from pte.
--- arch/powerpc/include/asm/kvm_host.h | 2 +- arch/powerpc/kvm/booke.c | 1 + arch/powerpc/kvm/e500.h | 8 ++++--- arch/powerpc/kvm/e500_mmu_host.c | 43 ++++++++++++++++++++++--------------- 4 files changed, 33 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -1
@@ -540,6 +540,7 @@ struct kvm_vcpu_arch {#endif gpa_t paddr_accessed;gva_t vaddr_accessed; +pgd_t *pgdir;u8 io_gpr;/* GPR used as IO source/target */ u8 mmio_is_bigendian;
@@ -597,7 +598,6 @@ struct kvm_vcpu_arch {struct list_head run_list;struct task_struct *run_task;struct kvm_run *kvm_run; -pgd_t *pgdir;spinlock_t vpa_update_lock;struct kvmppc_vpa vpa;
arch/powerpc/kvm/booke.c +1 -0
@@ -717,6 +717,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) thread.debug = current->thread.debug; current->thread.debug = vcpu->arch.shadow_dbg_reg; + vcpu->arch.pgdir = current->mm->pgd;kvmppc_fix_ee_before_entry (); ret =__kvmppc_vcpu_run (kvm_run, vcpu);
arch/powerpc/kvm/e500.h +5 -3
@@ -31,11 +31,13 @@ enum vcpu_ftr {#define E500_TLB_NUM 2/* entry is mapped somewhere in host TLB */ -#define E500_TLB_VALID (1 << 0) +#define E500_TLB_VALID (1 << 31)/* TLB1 entry is mapped by host TLB1, tracked by bitmaps */ -#define E500_TLB_BITMAP (1 << 1) +#define E500_TLB_BITMAP (1 << 30)/* TLB1 entry is mapped by host TLB0 */ -#define E500_TLB_TLB0 (1 << 2) +#define E500_TLB_TLB0 (1 << 29) +/* bits [6-5] MAS2_X1 and MAS2_X0 and [4-0] bits for WIMGE */ +#define E500_TLB_MAS2_ATTR (0x7f)struct tlbe_ref {pfn_t pfn;/* valid only for TLB0, except briefly */
arch/powerpc/kvm/e500_mmu_host.c +26 -17
91 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 14/36] KVM: PPC: Book3E HV: call RECONCILE_IRQ_STATE to sync the software state
In reply to Alexander GrafFrom: Tiejun Chen <[email protected]>
Rather than calling hard_irq_disable() when we're back in C code we can just call RECONCILE_IRQ_STATE to soft disable IRQs while we're already in hard disabled state.
This should be functionally equivalent to the code before, but cleaner and faster.
--- arch/powerpc/kvm/booke.c | 11 ----------- arch/powerpc/kvm/bookehv_interrupts.S | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-)
arch/powerpc/kvm/booke.c +0 -11
@@ -879,17 +879,6 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,int s;int idx; -#ifdef CONFIG_PPC64 -WARN_ON (local_paca->irq_happened !=0 ); -#endif - -/* -* We enter with interrupts disabled in hardware, but -* we need to call hard_irq_disable anyway to ensure that -* the software state is kept in sync. -*/ -hard_irq_disable (); -/* update before a new last_exit_type is rewritten */ kvmppc_update_timing_stats (vcpu);
arch/powerpc/kvm/bookehv_interrupts.S +11 -0
@@ -33,6 +33,8 @@ #ifdef CONFIG_64BIT #include <asm/exception-64e.h> +#include <asm/hw_irq.h> +#include <asm/irqflags.h> #else #include "../kernel/head_booke.h" /* for THREAD_NORMSAVE() */ #endif
@@ -465,6 +467,15 @@ _GLOBAL(kvmppc_resume_host) mtspr SPRN_EPCR, r3 isync +#ifdef CONFIG_64BIT + /* + * We enter with interrupts disabled in hardware, but + * we need to call RECONCILE_IRQ_STATE to ensure + * that the software state is kept in sync. + */ + RECONCILE_IRQ_STATE(r3,r5) +#endif + /* Switch to kernel stack and jump to handler. */ PPC_LL r3, HOST_RUN(r1) mr r5, r14 /* intno */
Signature · 1 line
1.8.1.4
[PULL 15/36] KVM: PPC: NULL return of kvmppc_mmu_hpte_cache_next should be handled
In reply to Alexander GrafFrom: Zhouyi Zhou <[email protected]>
NULL return of kvmppc_mmu_hpte_cache_next should be handled
--- arch/powerpc/kvm/book3s_32_mmu_host.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/powerpc/kvm/book3s_32_mmu_host.c +5 -0
@@ -243,6 +243,11 @@ next_pteg:/* Now tell our Shadow PTE code about the new page */ pte =kvmppc_mmu_hpte_cache_next (vcpu); +if (!pte) { +kvm_release_pfn_clean (hpaddr >>PAGE_SHIFT ); + r = -EAGAIN ; + goto out; + } dprintk_mmu("KVM: %c%c Map 0x%llx: [%lx] 0x%llx (0x%llx) -> %lx\n", orig_pte->may_write ? 'w' : '-',
Signature · 1 line
1.8.1.4
[PULL 16/36] KVM: PPC: Unify kvmppc_get_last_inst and sc
In reply to Alexander GrafWe had code duplication between the inline functions to get our last instruction on normal interrupts and system call interrupts. Unify both helper functions towards a single implementation.
--- arch/powerpc/include/asm/kvm_book3s.h | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +7 -11
@@ -264,10 +264,8 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)return vcpu->arch.pc; } -static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu) +static inline u32 kvmppc_get_last_inst_internal (struct kvm_vcpu *vcpu,ulong pc) { -ulong pc =kvmppc_get_pc (vcpu); -/* Load the instruction manually if it failed to do so in the * exit path */ if (vcpu->arch.last_inst =KVM_INST_FETCH_FAILED )
@@ -276,6 +274,11 @@ static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)return vcpu->arch.last_inst; } +static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu) +{ +return kvmppc_get_last_inst_internal (vcpu,kvmppc_get_pc (vcpu)); +} +/* * Like kvmppc_get_last_inst(), but for fetching a sc instruction. * Because the sc instruction sets SRR0 to point to the following
@@ -283,14 +286,7 @@ static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)*/ static inline u32 kvmppc_get_last_sc (struct kvm_vcpu *vcpu) { -ulong pc =kvmppc_get_pc (vcpu) -4 ; - -/* Load the instruction manually if it failed to do so in the -* exit path */ -if (vcpu->arch.last_inst =KVM_INST_FETCH_FAILED ) -kvmppc_ld (vcpu, &pc,sizeof (u32), &vcpu->arch.last_inst, false); - -return vcpu->arch.last_inst; +return kvmppc_get_last_inst_internal (vcpu,kvmppc_get_pc (vcpu) -4 ); }static inline ulong kvmppc_get_fault_dar (struct kvm_vcpu *vcpu)
Signature · 1 line
1.8.1.4
[PULL 17/36] KVM: PPC: Book3S: MMIO emulation support for little endian guests
In reply to Alexander GrafFrom: Cédric Le Goater <[email protected]>
MMIO emulation reads the last instruction executed by the guest and then emulates. If the guest is running in Little Endian order, or more generally in a different endian order of the host, the instruction needs to be byte-swapped before being emulated.
This patch adds a helper routine which tests the endian order of the host and the guest in order to decide whether a byteswap is needed or not. It is then used to byteswap the last instruction of the guest in the endian order of the host before MMIO emulation is performed.
Finally, kvmppc_handle_load() of kvmppc_handle_store() are modified to reverse the endianness of the MMIO if required.
--- arch/powerpc/include/asm/kvm_book3s.h | 8 +++++++- arch/powerpc/include/asm/kvm_booke.h | 6 ++++++ arch/powerpc/include/asm/kvm_ppc.h | 7 ++++--- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/emulate.c | 1 - arch/powerpc/kvm/powerpc.c | 28 ++++++++++++++++++++++++---- 6 files changed, 42 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +7 -1
@@ -264,6 +264,11 @@ static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)return vcpu->arch.pc; } +static inline bool kvmppc_need_byteswap (struct kvm_vcpu *vcpu) +{ +return (vcpu->arch.shared->msr &MSR_LE ) != (MSR_KERNEL &MSR_LE ); +} +static inline u32 kvmppc_get_last_inst_internal (struct kvm_vcpu *vcpu,ulong pc) {/* Load the instruction manually if it failed to do so in the
@@ -271,7 +276,8 @@ static inline u32 kvmppc_get_last_inst_internal(struct kvm_vcpu *vcpu, ulong pc)if (vcpu->arch.last_inst =KVM_INST_FETCH_FAILED )kvmppc_ld (vcpu, &pc,sizeof (u32), &vcpu->arch.last_inst, false); -return vcpu->arch.last_inst; +return kvmppc_need_byteswap (vcpu) ?swab32 (vcpu->arch.last_inst) : + vcpu->arch.last_inst; }static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu)
arch/powerpc/include/asm/kvm_booke.h +6 -0
@@ -63,6 +63,12 @@ static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)return vcpu->arch.xer; } +static inline bool kvmppc_need_byteswap (struct kvm_vcpu *vcpu) +{ +/* XXX Would need to check TLB entry */ +return false; +} +static inline u32 kvmppc_get_last_inst (struct kvm_vcpu *vcpu) {return vcpu->arch.last_inst;
arch/powerpc/include/asm/kvm_ppc.h +4 -3
@@ -54,12 +54,13 @@ extern void kvmppc_handler_highmem(void);extern void kvmppc_dump_vcpu (struct kvm_vcpu *vcpu);extern int kvmppc_handle_load (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int rt,unsigned int bytes, -int is_bigendian); +int is_default_endian);extern int kvmppc_handle_loads (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int rt,unsigned int bytes, -int is_bigendian); +int is_default_endian);extern int kvmppc_handle_store (struct kvm_run *run,struct kvm_vcpu *vcpu, -u64 val,unsigned int bytes,int is_bigendian); +u64 val,unsigned int bytes, +int is_default_endian);extern int kvmppc_emulate_instruction (struct kvm_run *run,struct kvm_vcpu *vcpu);
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -558,7 +558,7 @@ static int kvmppc_hv_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu,* we just return and retry the instruction. */ -if (instruction_is_store (vcpu->arch.last_inst) != !!is_store) +if (instruction_is_store (kvmppc_get_last_inst (vcpu)) != !!is_store)return RESUME_GUEST ;/*
arch/powerpc/kvm/emulate.c +0 -1
@@ -219,7 +219,6 @@ static int kvmppc_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)* lmw * stmw * -* XXX is_bigendian should depend on MMU mapping or MSR[LE] */ /* XXX Should probably auto-generate instruction decoding for a particular core * from opcode tables in the future. */
arch/powerpc/kvm/powerpc.c +24 -4
@@ -673,9 +673,19 @@ static void kvmppc_complete_mmio_load(struct kvm_vcpu *vcpu, }int kvmppc_handle_load (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int rt,unsigned int bytes,int is_bigendian) +unsigned int rt,unsigned int bytes, +int is_default_endian) {int idx, ret; +int is_bigendian; + +if (kvmppc_need_byteswap (vcpu)) { +/* Default endianness is "little endian". */ + is_bigendian = !is_default_endian; + }else { +/* Default endianness is "big endian". */ + is_bigendian = is_default_endian; + }if (bytes >sizeof (run->mmio.data)) { printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
@@ -711,21 +721,31 @@ EXPORT_SYMBOL_GPL(kvmppc_handle_load);/* Same as above, but sign extends */ int kvmppc_handle_loads (struct kvm_run *run,struct kvm_vcpu *vcpu, -unsigned int rt,unsigned int bytes,int is_bigendian) +unsigned int rt,unsigned int bytes, +int is_default_endian) {int r; vcpu->arch.mmio_sign_extend =1 ; - r =kvmppc_handle_load (run, vcpu, rt, bytes, is_bigendian); + r =kvmppc_handle_load (run, vcpu, rt, bytes, is_default_endian);return r; }int kvmppc_handle_store (struct kvm_run *run,struct kvm_vcpu *vcpu, -u64 val,unsigned int bytes,int is_bigendian) +u64 val,unsigned int bytes,int is_default_endian) {void *data = run->mmio.data;int idx, ret; +int is_bigendian; + +if (kvmppc_need_byteswap (vcpu)) { +/* Default endianness is "little endian". */ + is_bigendian = !is_default_endian; + }else { +/* Default endianness is "big endian". */ + is_bigendian = is_default_endian; + }if (bytes >sizeof (run->mmio.data)) { printk(KERN_ERR "%s: bad MMIO length: %d\n", __func__,
Signature · 1 line
1.8.1.4
[PULL 18/36] KVM: PPC: Book3S HV: use xics_wake_cpu only when defined
In reply to Alexander GrafFrom: Andreas Schwab <[email protected]>
--- arch/powerpc/kvm/book3s_hv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv.c +6 -1
@@ -86,10 +86,13 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)/* CPU points to the first thread of the core */ if (cpu != me && cpu >=0 && cpu < nr_cpu_ids) { +#ifdef CONFIG_KVM_XICS int real_cpu = cpu + vcpu->arch.ptid;if (paca[real_cpu].kvm_hstate.xics_phys)xics_wake_cpu (real_cpu); -else if (cpu_online (cpu)) + else +#endif +if (cpu_online (cpu))smp_send_reschedule (cpu); }put_cpu ();
@@ -1142,7 +1145,9 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu)smp_wmb ();#if defined(CONFIG_PPC_ICP_NATIVE ) && defined(CONFIG_SMP )if (vcpu->arch.ptid) { +#ifdef CONFIG_KVM_XICS xics_wake_cpu (cpu); +#endif ++vc->n_woken; }#endif
Signature · 1 line
1.8.1.4
[PULL 19/36] KVM: PPC: e500: Fix bad address type in deliver_tlb_misss()
In reply to Alexander GrafFrom: Mihai Caraman <[email protected]>
Use gva_t instead of unsigned int for eaddr in deliver_tlb_miss().
--- arch/powerpc/kvm/e500_mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kvm/e500_mmu.c +1 -1
@@ -127,7 +127,7 @@ static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 *vcpu_e500, }static inline void kvmppc_e500_deliver_tlb_miss (struct kvm_vcpu *vcpu, -unsigned int eaddr,int as) +gva_t eaddr,int as) {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);unsigned int victim, tsized;
Signature · 1 line
1.8.1.4
[PULL 20/36] kvm/ppc: IRQ disabling cleanup
In reply to Alexander GrafFrom: Scott Wood <[email protected]>
Simplify the handling of lazy EE by going directly from fully-enabled to hard-disabled. This replaces the lazy_irq_pending() check (including its misplaced kvm_guest_exit() call).
As suggested by Tiejun Chen, move the interrupt disabling into kvmppc_prepare_to_enter() rather than have each caller do it. Also move the IRQ enabling on heavyweight exit into kvmppc_prepare_to_enter().
--- arch/powerpc/include/asm/kvm_ppc.h | 6 ++++++ arch/powerpc/kvm/book3s_pr.c | 14 ++++++-------- arch/powerpc/kvm/booke.c | 12 +++++------- arch/powerpc/kvm/powerpc.c | 26 +++++++++----------------- 4 files changed, 26 insertions(+), 32 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +6 -0
@@ -456,6 +456,12 @@ static inline void kvmppc_fix_ee_before_entry(void)trace_hardirqs_on ();#ifdef CONFIG_PPC64 +/* +* To avoid races, the caller must have gone directly from having +* interrupts fully-enabled to hard-disabled. +*/ +WARN_ON (local_paca->irq_happened !=PACA_IRQ_HARD_DIS ); +/* Only need to enable IRQs by hard enabling them after this */ local_paca->irq_happened =0 ; local_paca->soft_enabled =1 ;
arch/powerpc/kvm/book3s_pr.c +6 -8
@@ -999,14 +999,14 @@ program_interrupt:* and if we really did time things so badly, then we just exit * again due to a host external interrupt. */ -local_irq_disable (); s =kvmppc_prepare_to_enter (vcpu); -if (s <=0 ) { -local_irq_enable (); +if (s <=0 ) r = s; - }else { +else { +/* interrupts now hard-disabled */ kvmppc_fix_ee_before_entry (); } +kvmppc_handle_lost_ext (vcpu); }
@@ -1219,12 +1219,10 @@ static int kvmppc_vcpu_run_pr(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)* really did time things so badly, then we just exit again due to * a host external interrupt. */ -local_irq_disable (); ret =kvmppc_prepare_to_enter (vcpu); -if (ret <=0 ) { -local_irq_enable (); +if (ret <=0 ) goto out; - } +/* interrupts now hard-disabled */ /* Save FPU state in thread_struct */ if (current->thread.regs->msr &MSR_FP )
arch/powerpc/kvm/booke.c +5 -7
@@ -643,7 +643,7 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)local_irq_enable ();kvm_vcpu_block (vcpu);clear_bit (KVM_REQ_UNHALT , &vcpu->requests); -local_irq_disable (); +hard_irq_disable ();kvmppc_set_exit_type (vcpu,EMULATED_MTMSRWE_EXITS ); r =1 ;
@@ -688,13 +688,12 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)return -EINVAL ; } -local_irq_disable (); s =kvmppc_prepare_to_enter (vcpu);if (s <=0 ) { -local_irq_enable (); ret = s; goto out; } +/* interrupts now hard-disabled */ #ifdef CONFIG_PPC_FPU /* Save userspace FPU state in stack */
@@ -1187,12 +1186,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,* aren't already exiting to userspace for some other reason. */ if (!(r &RESUME_HOST )) { -local_irq_disable (); s =kvmppc_prepare_to_enter (vcpu); -if (s <=0 ) { -local_irq_enable (); +if (s <=0 ) r = (s <<2 ) |RESUME_HOST | (r &RESUME_FLAG_NV ); - }else { +else { +/* interrupts now hard-disabled */ kvmppc_fix_ee_before_entry (); } }
arch/powerpc/kvm/powerpc.c +9 -17
@@ -68,14 +68,16 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)*/ int kvmppc_prepare_to_enter (struct kvm_vcpu *vcpu) { -int r =1 ; +int r; + +WARN_ON (irqs_disabled ()); +hard_irq_disable (); -WARN_ON_ONCE (!irqs_disabled ());while (true) {if (need_resched ()) {local_irq_enable ();cond_resched (); -local_irq_disable (); +hard_irq_disable ();continue ; }
@@ -101,7 +103,7 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)local_irq_enable ();trace_kvm_check_requests (vcpu); r =kvmppc_core_check_requests (vcpu); -local_irq_disable (); +hard_irq_disable ();if (r >0 )continue ;break ;
@@ -113,22 +115,12 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)continue ; } -#ifdef CONFIG_PPC64 -/* lazy EE magic */ -hard_irq_disable (); -if (lazy_irq_pending ()) { -/* Got an interrupt in between, try again */ -local_irq_enable (); -local_irq_disable (); -kvm_guest_exit (); -continue ; - } -#endif -kvm_guest_enter (); -break ; +return 1 ; } +/* return to host */ +local_irq_enable ();return r; }EXPORT_SYMBOL_GPL (kvmppc_prepare_to_enter);
Signature · 1 line
1.8.1.4
[PULL 21/36] KVM: PPC: Book3S HV: Don't set DABR on POWER8
In reply to Alexander GrafFrom: Michael Neuling <[email protected]>
POWER8 doesn't have the DABR and DABRX registers; instead it has new DAWR/DAWRX registers, which will be handled in a later patch.
--- arch/powerpc/kvm/book3s_hv_interrupts.S | 2 ++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s_hv_interrupts.S +2 -0
@@ -57,9 +57,11 @@ BEGIN_FTR_SECTION std r3, HSTATE_DSCR(r13) END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) +BEGIN_FTR_SECTION /* Save host DABR */ mfspr r3, SPRN_DABR std r3, HSTATE_DABR(r13) +END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) /* Hard-disable interrupts */ mfmsr r10
arch/powerpc/kvm/book3s_hv_rmhandlers.S +10 -3
@@ -61,11 +61,13 @@ kvmppc_call_hv_entry: /* Back from guest - restore host state and return to caller */ +BEGIN_FTR_SECTION /* Restore host DABR and DABRX */ ld r5,HSTATE_DABR(r13) li r6,7 mtspr SPRN_DABR,r5 mtspr SPRN_DABRX,r6 +END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) /* Restore SPRG3 */ ld r3,PACA_SPRG3(r13)
@@ -284,15 +286,17 @@ kvmppc_hv_entry: std r0, PPC_LR_STKOFF(r1) stdu r1, -112(r1) +BEGIN_FTR_SECTION /* Set partition DABR */ /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */ li r5,3 ld r6,VCPU_DABR(r4) mtspr SPRN_DABRX,r5 mtspr SPRN_DABR,r6 -BEGIN_FTR_SECTION + BEGIN_FTR_SECTION_NESTED(89) isync -END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) + END_FTR_SECTION_NESTED(CPU_FTR_ARCH_206, CPU_FTR_ARCH_206, 89) +END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) /* Load guest PMU registers */ /* R4 is live here (vcpu pointer) */
@@ -1609,6 +1613,9 @@ ignore_hdec: b fast_guest_return _GLOBAL(kvmppc_h_set_dabr) +BEGIN_FTR_SECTION + b 2f +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) std r4,VCPU_DABR(r3) /* Work around P7 bug where DABR can get corrupted on mtspr */ 1: mtspr SPRN_DABR,r4
@@ -1616,7 +1623,7 @@ _GLOBAL(kvmppc_h_set_dabr) cmpd r4, r5 bne 1b isync - li r3,0 +2: li r3,0 blr _GLOBAL(kvmppc_h_cede)
Signature · 1 line
1.8.1.4
[PULL 22/36] KVM: PPC: Book3S HV: Align physical and virtual CPU thread numbers
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
On a threaded processor such as POWER7, we group VCPUs into virtual cores and arrange that the VCPUs in a virtual core run on the same physical core. Currently we don't enforce any correspondence between virtual thread numbers within a virtual core and physical thread numbers. Physical threads are allocated starting at 0 on a first-come first-served basis to runnable virtual threads (VCPUs).
POWER8 implements a new "msgsndp" instruction which guest kernels can use to interrupt other threads in the same core or sub-core. Since the instruction takes the destination physical thread ID as a parameter, it becomes necessary to align the physical thread IDs with the virtual thread IDs, that is, to make sure virtual thread N within a virtual core always runs on physical thread N.
This means that it's possible that thread 0, which is where we call __kvmppc_vcore_entry, may end up running some other vcpu than the one whose task called kvmppc_run_core(), or it may end up running no vcpu at all, if for example thread 0 of the virtual core is currently executing in userspace. However, we do need thread 0 to be responsible for switching the MMU -- a previous version of this patch that had other threads switching the MMU was found to be responsible for occasional memory corruption and machine check interrupts in the guest on POWER7 machines.
To accommodate this, we no longer pass the vcpu pointer to __kvmppc_vcore_entry, but instead let the assembly code load it from the PACA. Since the assembly code will need to know the kvm pointer and the thread ID for threads which don't have a vcpu, we move the thread ID into the PACA and we add a kvm pointer to the virtual core structure.
In the case where thread 0 has no vcpu to run, it still calls into kvmppc_hv_entry in order to do the MMU switch, and then naps until either its vcpu is ready to run in the guest, or some other thread needs to exit the guest. In the latter case, thread 0 jumps to the code that switches the MMU back to the host. This control flow means that now we switch the MMU before loading any guest vcpu state. Similarly, on guest exit we now save all the guest vcpu state before switching the MMU back to the host. This has required substantial code movement, making the diff rather large.
--- arch/powerpc/include/asm/kvm_book3s_asm.h | 1 + arch/powerpc/include/asm/kvm_host.h | 2 + arch/powerpc/kernel/asm-offsets.c | 3 +- arch/powerpc/kvm/book3s_hv.c | 46 +- arch/powerpc/kvm/book3s_hv_interrupts.S | 6 +- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 676 +++++++++++++++++------------- 6 files changed, 397 insertions(+), 337 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -0
@@ -87,6 +87,7 @@ struct kvmppc_host_state {u8 hwthread_req;u8 hwthread_state;u8 host_ipi; +u8 ptid;struct kvm_vcpu *kvm_vcpu;struct kvmppc_vcore *kvm_vcore;unsigned long xics_phys;
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -288,6 +288,7 @@ struct kvmppc_vcore {int n_woken;int nap_count;int napping_threads; +int first_vcpuid;u16 pcpu;u16 last_cpu;u8 vcore_state;
@@ -298,6 +299,7 @@ struct kvmppc_vcore {u64 stolen_tb;u64 preempt_tb;struct kvm_vcpu *runner; +struct kvm *kvm;u64 tb_offset;/* guest timebase - host timebase */ ulong lpcr;u32 arch_compat;
arch/powerpc/kernel/asm-offsets.c +2 -1
@@ -506,7 +506,6 @@ int main(void) DEFINE(VCPU_FAULT_DAR, offsetof(struct kvm_vcpu, arch.fault_dar)); DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); DEFINE(VCPU_TRAP, offsetof(struct kvm_vcpu, arch.trap)); - DEFINE(VCPU_PTID, offsetof(struct kvm_vcpu, arch.ptid)); DEFINE(VCPU_CFAR, offsetof(struct kvm_vcpu, arch.cfar)); DEFINE(VCPU_PPR, offsetof(struct kvm_vcpu, arch.ppr)); DEFINE(VCPU_SHADOW_SRR1, offsetof(struct kvm_vcpu, arch.shadow_srr1));
@@ -514,6 +513,7 @@ int main(void)DEFINE (VCORE_NAP_COUNT , offsetof(struct kvmppc_vcore , nap_count));DEFINE (VCORE_IN_GUEST , offsetof(struct kvmppc_vcore , in_guest));DEFINE (VCORE_NAPPING_THREADS , offsetof(struct kvmppc_vcore , napping_threads)); +DEFINE (VCORE_KVM , offsetof(struct kvmppc_vcore , kvm));DEFINE (VCORE_TB_OFFSET , offsetof(struct kvmppc_vcore , tb_offset));DEFINE (VCORE_LPCR , offsetof(struct kvmppc_vcore , lpcr));DEFINE (VCORE_PCR , offsetof(struct kvmppc_vcore , pcr));
@@ -583,6 +583,7 @@ int main(void)HSTATE_FIELD (HSTATE_XICS_PHYS , xics_phys);HSTATE_FIELD (HSTATE_SAVED_XIRR , saved_xirr);HSTATE_FIELD (HSTATE_HOST_IPI , host_ipi); +HSTATE_FIELD (HSTATE_PTID , ptid);HSTATE_FIELD (HSTATE_MMCR , host_mmcr);HSTATE_FIELD (HSTATE_PMC , host_pmc);HSTATE_FIELD (HSTATE_PURR , host_purr);
arch/powerpc/kvm/book3s_hv.c +17 -29
115 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_interrupts.S +2 -4
@@ -35,7 +35,7 @@ ****************************************************************************/ /* Registers: - * r4: vcpu pointer + * none */ _GLOBAL(__kvmppc_vcore_entry)
@@ -71,7 +71,6 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) mtmsrd r10,1 /* Save host PMU registers */ - /* R4 is live here (vcpu pointer) but not r3 or r5 */ li r3, 1 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ mfspr r7, SPRN_MMCR0 /* save MMCR0 */
@@ -136,16 +135,15 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) * enters the guest with interrupts enabled. */ BEGIN_FTR_SECTION + ld r4, HSTATE_KVM_VCPU(r13) ld r0, VCPU_PENDING_EXC(r4) li r7, (1 << BOOK3S_IRQPRIO_EXTERNAL) oris r7, r7, (1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h and. r0, r0, r7 beq 32f - mr r31, r4 lhz r3, PACAPACAINDEX(r13) bl smp_send_reschedule nop - mr r4, r31 32: END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) #endif /* CONFIG_SMP */
arch/powerpc/kvm/book3s_hv_rmhandlers.S +373 -303
859 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 23/36] KVM: PPC: Book3S HV: Context-switch new POWER8 SPRs
In reply to Alexander GrafFrom: Michael Neuling <[email protected]>
This adds fields to the struct kvm_vcpu_arch to store the new guest-accessible SPRs on POWER8, adds code to the get/set_one_reg functions to allow userspace to access this state, and adds code to the guest entry and exit to context-switch these SPRs between host and guest.
Note that DPDES (Directed Privileged Doorbell Exception State) is shared between threads on a core; hence we store it in struct kvmppc_vcore and have the master thread save and restore it.
--- arch/powerpc/include/asm/kvm_host.h | 25 +++++- arch/powerpc/include/asm/reg.h | 17 ++++ arch/powerpc/include/uapi/asm/kvm.h | 1 + arch/powerpc/kernel/asm-offsets.c | 23 +++++ arch/powerpc/kvm/book3s_hv.c | 153 +++++++++++++++++++++++++++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 145 ++++++++++++++++++++++++++++++ 6 files changed, 361 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_host.h +24 -1
@@ -304,6 +304,7 @@ struct kvmppc_vcore {ulong lpcr;u32 arch_compat;ulong pcr; +ulong dpdes;/* doorbell state (POWER8) */ };#define VCORE_ENTRY_COUNT (vc) ((vc)->entry_exit_count & 0xff)
@@ -448,6 +449,7 @@ struct kvm_vcpu_arch {ulong pc;ulong ctr;ulong lr; +ulong tar;ulong xer;u32 cr;
@@ -457,13 +459,32 @@ struct kvm_vcpu_arch {ulong guest_owned_ext;ulong purr;ulong spurr; +ulong ic; +ulong vtb;ulong dscr;ulong amr;ulong uamor; +ulong iamr;u32 ctrl;ulong dabr; +ulong dawr; +ulong dawrx; +ulong ciabr;ulong cfar;ulong ppr; +ulong pspb; +ulong fscr; +ulong tfhar; +ulong tfiar; +ulong texasr; +ulong ebbhr; +ulong ebbrr; +ulong bescr; +ulong csigr; +ulong tacr; +ulong tcscr; +ulong acop; +ulong wort;ulong shadow_srr1;#endif u32 vrsave;/* also USPRG0 */
@@ -498,10 +519,12 @@ struct kvm_vcpu_arch {u32 ccr1;u32 dbsr; -u64 mmcr[3 ]; +u64 mmcr[5 ];u32 pmc[8 ]; +u32 spmc[2 ];u64 siar;u64 sdar; +u64 sier;#ifdef CONFIG_KVM_EXIT_TIMING struct mutex exit_timing_lock;
arch/powerpc/include/asm/reg.h +17 -0
@@ -223,6 +223,11 @@#define CTRL_TE 0x00c00000/* thread enable */ #define CTRL_RUNLATCH 0x1#define SPRN_DAWR 0xB4 +#define SPRN_CIABR 0xBB +#define CIABR_PRIV 0x3 +#define CIABR_PRIV_USER 1 +#define CIABR_PRIV_SUPER 2 +#define CIABR_PRIV_HYPER 3#define SPRN_DAWRX 0xBC#define DAWRX_USER (1UL << 0)#define DAWRX_KERNEL (1UL << 1)
@@ -260,6 +265,8 @@#define SPRN_HRMOR 0x139/* Real mode offset register */ #define SPRN_HSRR0 0x13A/* Hypervisor Save/Restore 0 */ #define SPRN_HSRR1 0x13B/* Hypervisor Save/Restore 1 */ +#define SPRN_IC 0x350/* Virtual Instruction Count */ +#define SPRN_VTB 0x351/* Virtual Time Base */ /* HFSCR and FSCR bit numbers are the same */ #define FSCR_TAR_LG 8/* Enable Target Address Register */ #define FSCR_EBB_LG 7/* Enable Event Based Branching */
@@ -368,6 +375,8 @@#define DER_EBRKE 0x00000002/* External Breakpoint Interrupt */ #define DER_DPIE 0x00000001/* Dev. Port Nonmaskable Request */ #define SPRN_DMISS 0x3D0/* Data TLB Miss Register */ +#define SPRN_DHDES 0x0B1/* Directed Hyp. Doorbell Exc. State */ +#define SPRN_DPDES 0x0B0/* Directed Priv. Doorbell Exc. State */ #define SPRN_EAR 0x11A/* External Address Register */ #define SPRN_HASH1 0x3D2/* Primary Hash Address Register */ #define SPRN_HASH2 0x3D3/* Secondary Hash Address Resgister */
@@ -427,6 +436,7 @@#define SPRN_IABR 0x3F2/* Instruction Address Breakpoint Register */ #define SPRN_IABR2 0x3FA/* 83xx */ #define SPRN_IBCR 0x135/* 83xx Insn Breakpoint Control Reg */ +#define SPRN_IAMR 0x03D/* Instr. Authority Mask Reg */ #define SPRN_HID4 0x3F4/* 970 HID4 */ #define HID4_LPES0 (1ul << (63-0))/* LPAR env. sel. bit 0 */ #define HID4_RMLS2_SH (63 - 2)/* Real mode limit bottom 2 bits */
@@ -541,6 +551,7 @@#define SPRN_PIR 0x3FF/* Processor Identification Register */ #endif #define SPRN_TIR 0x1BE/* Thread Identification Register */ +#define SPRN_PSPB 0x09F/* Problem State Priority Boost reg */ #define SPRN_PTEHI 0x3D5/* 981 7450 PTE HI word (S/W TLB load) */ #define SPRN_PTELO 0x3D6/* 982 7450 PTE LO word (S/W TLB load) */ #define SPRN_PURR 0x135/* Processor Utilization of Resources Reg */
@@ -682,6 +693,7 @@#define SPRN_EBBHR 804/* Event based branch handler register */ #define SPRN_EBBRR 805/* Event based branch return register */ #define SPRN_BESCR 806/* Branch event status and control register */ +#define SPRN_WORT 895/* Workload optimization register - thread */ #define SPRN_PMC1 787#define SPRN_PMC2 788
@@ -698,6 +710,11 @@#define SIER_SIHV 0x1000000/* Sampled MSR_HV */ #define SIER_SIAR_VALID 0x0400000/* SIAR contents valid */ #define SIER_SDAR_VALID 0x0200000/* SDAR contents valid */ +#define SPRN_TACR 888 +#define SPRN_TCSCR 889 +#define SPRN_CSIGR 890 +#define SPRN_SPMC1 892 +#define SPRN_SPMC2 893/* When EBB is enabled, some of MMCR0/MMCR2/SIER are user accessible */ #define MMCR0_USER_MASK (MMCR0_FC | MMCR0_PMXE | MMCR0_PMAO)
arch/powerpc/include/uapi/asm/kvm.h +1 -0
@@ -545,6 +545,7 @@ struct kvm_get_htab_header {#define KVM_REG_PPC_TCSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb1)#define KVM_REG_PPC_PID (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb2)#define KVM_REG_PPC_ACOP (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb3) +#define KVM_REG_PPC_WORT (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb4)#define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4)#define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5)
arch/powerpc/kernel/asm-offsets.c +23 -0
@@ -432,6 +432,7 @@ int main(void) DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr)); DEFINE(VCPU_LR, offsetof(struct kvm_vcpu, arch.lr)); + DEFINE(VCPU_TAR, offsetof(struct kvm_vcpu, arch.tar)); DEFINE(VCPU_CR, offsetof(struct kvm_vcpu, arch.cr)); DEFINE(VCPU_PC, offsetof(struct kvm_vcpu, arch.pc));#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
@@ -484,11 +485,17 @@ int main(void)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)); + DEFINE(VCPU_IC, offsetof(struct kvm_vcpu, arch.ic)); + DEFINE(VCPU_VTB, offsetof(struct kvm_vcpu, arch.vtb)); DEFINE(VCPU_DSCR, offsetof(struct kvm_vcpu, arch.dscr)); DEFINE(VCPU_AMR, offsetof(struct kvm_vcpu, arch.amr)); DEFINE(VCPU_UAMOR, offsetof(struct kvm_vcpu, arch.uamor)); + DEFINE(VCPU_IAMR, offsetof(struct kvm_vcpu, arch.iamr)); DEFINE(VCPU_CTRL, offsetof(struct kvm_vcpu, arch.ctrl)); DEFINE(VCPU_DABR, offsetof(struct kvm_vcpu, arch.dabr)); + DEFINE(VCPU_DAWR, offsetof(struct kvm_vcpu, arch.dawr)); + DEFINE(VCPU_DAWRX, offsetof(struct kvm_vcpu, arch.dawrx)); + DEFINE(VCPU_CIABR, offsetof(struct kvm_vcpu, arch.ciabr)); DEFINE(VCPU_HFLAGS, offsetof(struct kvm_vcpu, arch.hflags)); DEFINE(VCPU_DEC, offsetof(struct kvm_vcpu, arch.dec)); DEFINE(VCPU_DEC_EXPIRES, offsetof(struct kvm_vcpu, arch.dec_expires));
@@ -497,8 +504,10 @@ int main(void) DEFINE(VCPU_PRODDED, offsetof(struct kvm_vcpu, arch.prodded)); DEFINE(VCPU_MMCR, offsetof(struct kvm_vcpu, arch.mmcr)); DEFINE(VCPU_PMC, offsetof(struct kvm_vcpu, arch.pmc)); + DEFINE(VCPU_SPMC, offsetof(struct kvm_vcpu, arch.spmc)); DEFINE(VCPU_SIAR, offsetof(struct kvm_vcpu, arch.siar)); DEFINE(VCPU_SDAR, offsetof(struct kvm_vcpu, arch.sdar)); + DEFINE(VCPU_SIER, offsetof(struct kvm_vcpu, arch.sier)); DEFINE(VCPU_SLB, offsetof(struct kvm_vcpu, arch.slb)); DEFINE(VCPU_SLB_MAX, offsetof(struct kvm_vcpu, arch.slb_max)); DEFINE(VCPU_SLB_NR, offsetof(struct kvm_vcpu, arch.slb_nr));
@@ -508,6 +517,19 @@ int main(void) DEFINE(VCPU_TRAP, offsetof(struct kvm_vcpu, arch.trap)); DEFINE(VCPU_CFAR, offsetof(struct kvm_vcpu, arch.cfar)); DEFINE(VCPU_PPR, offsetof(struct kvm_vcpu, arch.ppr)); + DEFINE(VCPU_FSCR, offsetof(struct kvm_vcpu, arch.fscr)); + DEFINE(VCPU_PSPB, offsetof(struct kvm_vcpu, arch.pspb)); + DEFINE(VCPU_TFHAR, offsetof(struct kvm_vcpu, arch.tfhar)); + DEFINE(VCPU_TFIAR, offsetof(struct kvm_vcpu, arch.tfiar)); + DEFINE(VCPU_TEXASR, offsetof(struct kvm_vcpu, arch.texasr)); + DEFINE(VCPU_EBBHR, offsetof(struct kvm_vcpu, arch.ebbhr)); + DEFINE(VCPU_EBBRR, offsetof(struct kvm_vcpu, arch.ebbrr)); + DEFINE(VCPU_BESCR, offsetof(struct kvm_vcpu, arch.bescr)); + DEFINE(VCPU_CSIGR, offsetof(struct kvm_vcpu, arch.csigr)); + DEFINE(VCPU_TACR, offsetof(struct kvm_vcpu, arch.tacr)); + DEFINE(VCPU_TCSCR, offsetof(struct kvm_vcpu, arch.tcscr)); + DEFINE(VCPU_ACOP, offsetof(struct kvm_vcpu, arch.acop)); + DEFINE(VCPU_WORT, offsetof(struct kvm_vcpu, arch.wort)); DEFINE(VCPU_SHADOW_SRR1, offsetof(struct kvm_vcpu, arch.shadow_srr1));DEFINE (VCORE_ENTRY_EXIT , offsetof(struct kvmppc_vcore , entry_exit_count));DEFINE (VCORE_NAP_COUNT , offsetof(struct kvmppc_vcore , nap_count));
@@ -517,6 +539,7 @@ int main(void)DEFINE (VCORE_TB_OFFSET , offsetof(struct kvmppc_vcore , tb_offset));DEFINE (VCORE_LPCR , offsetof(struct kvmppc_vcore , lpcr));DEFINE (VCORE_PCR , offsetof(struct kvmppc_vcore , pcr)); +DEFINE (VCORE_DPDES , offsetof(struct kvmppc_vcore , dpdes));DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));DEFINE (VCPU_SLB_V , offsetof(struct kvmppc_slb , origv));DEFINE (VCPU_SLB_SIZE ,sizeof (struct kvmppc_slb ));
arch/powerpc/kvm/book3s_hv.c +151 -2
189 lines not on this page · raw message
arch/powerpc/kvm/book3s_hv_rmhandlers.S +145 -0
181 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 24/36] KVM: PPC: Book3S HV: Flush the correct number of TLB sets on POWER8
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
POWER8 has 512 sets in the TLB, compared to 128 for POWER7, so we need to do more tlbiel instructions when flushing the TLB on POWER8.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +7 -1
@@ -430,7 +430,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201) andc r7,r7,r0 stdcx. r7,0,r6 bne 23b - li r6,128 /* and flush the TLB */ + /* Flush the TLB of any entries for this LPID */ + /* use arch 2.07S as a proxy for POWER8 */ +BEGIN_FTR_SECTION + li r6,512 /* POWER8 has 512 sets */ +FTR_SECTION_ELSE + li r6,128 /* POWER7 has 128 sets */ +ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_207S) mtctr r6 li r7,0x800 /* IS field = 0b10 */ ptesync
Signature · 1 line
1.8.1.4
[PULL 25/36] KVM: PPC: Book3S HV: Add handler for HV facility unavailable
In reply to Alexander GrafFrom: Michael Ellerman <[email protected]>
At present this should never happen, since the host kernel sets HFSCR to allow access to all facilities. It's better to be prepared to handle it cleanly if it does ever happen, though.
--- arch/powerpc/include/asm/kvm_asm.h | 1 + arch/powerpc/kvm/book3s_hv.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_asm.h +1 -0
@@ -99,6 +99,7 @@#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40 +#define BOOK3S_INTERRUPT_H_FAC_UNAVAIL 0xf80#define BOOK3S_IRQPRIO_SYSTEM_RESET 0#define BOOK3S_IRQPRIO_DATA_SEGMENT 1
arch/powerpc/kvm/book3s_hv.c +10 -1
@@ -706,7 +706,16 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,* we don't emulate any guest instructions at this stage. */ case BOOK3S_INTERRUPT_H_EMUL_ASSIST : -kvmppc_core_queue_program (vcpu,0x80000 ); +kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); + r =RESUME_GUEST ; +break ; +/* +* This occurs if the guest (kernel or userspace), does something that +* is prohibited by HFSCR. We just generate a program interrupt to +* the guest. +*/ +case BOOK3S_INTERRUPT_H_FAC_UNAVAIL : +kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); r =RESUME_GUEST ;break ;default :
Signature · 1 line
1.8.1.4
[PULL 26/36] KVM: PPC: Book3S HV: Implement architecture compatibility modes for POWER8
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
This allows us to select architecture 2.05 (POWER6) or 2.06 (POWER7) compatibility modes on a POWER8 processor. (Note that transactional memory is disabled for usermode if either or both of the PCR_TM_DIS and PCR_ARCH_206 bits are set.)
--- arch/powerpc/include/asm/reg.h | 2 ++ arch/powerpc/kvm/book3s_hv.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/reg.h +2 -0
@@ -329,6 +329,8 @@#define SPRN_PCR 0x152/* Processor compatibility register */ #define PCR_VEC_DIS (1ul << (63-0))/* Vec. disable (bit NA since POWER8) */ #define PCR_VSX_DIS (1ul << (63-1))/* VSX disable (bit NA since POWER8) */ +#define PCR_TM_DIS (1ul << (63-2))/* Trans. memory disable (POWER8) */ +#define PCR_ARCH_206 0x4/* Architecture 2.06 */ #define PCR_ARCH_205 0x2/* Architecture 2.05 */ #define SPRN_HEIR 0x153/* Hypervisor Emulated Instruction Register */ #define SPRN_TLBINDEXR 0x154/* P7 TLB control register */
arch/powerpc/kvm/book3s_hv.c +15 -1
@@ -184,14 +184,28 @@ int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)switch (arch_compat) {case PVR_ARCH_205 : - pcr =PCR_ARCH_205 ; +/* +* If an arch bit is set in PCR, all the defined +* higher-order arch bits also have to be set. +*/ + pcr =PCR_ARCH_206 |PCR_ARCH_205 ;break ;case PVR_ARCH_206 :case PVR_ARCH_206p: + pcr =PCR_ARCH_206 ; +break ; +case PVR_ARCH_207 :break ;default :return -EINVAL ; } + +if (!cpu_has_feature (CPU_FTR_ARCH_207S )) { +/* POWER7 can't emulate POWER8 */ +if (!(pcr &PCR_ARCH_206 )) +return -EINVAL ; + pcr &= ~PCR_ARCH_206 ; + } }spin_lock (&vc->lock);
Signature · 1 line
1.8.1.4
[PULL 27/36] KVM: PPC: Book3S HV: Consolidate code that checks reason for wake from nap
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
Currently in book3s_hv_rmhandlers.S we have three places where we have woken up from nap mode and we check the reason field in SRR1 to see what event woke us up. This consolidates them into a new function, kvmppc_check_wake_reason. It looks at the wake reason field in SRR1, and if it indicates that an external interrupt caused the wakeup, calls kvmppc_read_intr to check what sort of interrupt it was.
This also consolidates the two places where we synthesize an external interrupt (0x500 vector) for the guest. Now, if the guest exit code finds that there was an external interrupt which has been handled (i.e. it was an IPI indicating that there is now an interrupt pending for the guest), it jumps to deliver_guest_interrupt, which is in the last part of the guest entry code, where we synthesize guest external and decrementer interrupts. That code has been streamlined a little and now clears LPCR[MER] when appropriate as well as setting it.
The extra clearing of any pending IPI on a secondary, offline CPU thread before going back to nap mode has been removed. It is no longer necessary now that we have code to read and acknowledge IPIs in the guest exit path.
This fixes a minor bug in the H_CEDE real-mode handling - previously, if we found that other threads were already exiting the guest when we were about to go to nap mode, we would branch to the cede wakeup path and end up looking in SRR1 for a wakeup reason. Now we branch to a point after we have checked the wakeup reason.
This also fixes a minor bug in kvmppc_read_intr - previously it could return 0xff rather than 1, in the case where we find that a host IPI is pending after we have cleared the IPI. Now it returns 1.
--- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 192 +++++++++++++------------------- 1 file changed, 77 insertions(+), 115 deletions(-)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +77 -115
@@ -193,8 +193,10 @@ kvm_novcpu_wakeup: stb r0, HSTATE_NAPPING(r13) stb r0, HSTATE_HWTHREAD_REQ(r13) + /* check the wake reason */ + bl kvmppc_check_wake_reason + /* see if any other thread is already exiting */ - li r12, 0 lwz r0, VCORE_ENTRY_EXIT(r5) cmpwi r0, 0x100 bge kvm_novcpu_exit
@@ -204,23 +206,14 @@ kvm_novcpu_wakeup: li r0, 1 sld r0, r0, r7 addi r6, r5, VCORE_NAPPING_THREADS -4: lwarx r3, 0, r6 - andc r3, r3, r0 - stwcx. r3, 0, r6 +4: lwarx r7, 0, r6 + andc r7, r7, r0 + stwcx. r7, 0, r6 bne 4b - /* Check the wake reason in SRR1 to see why we got here */ - mfspr r3, SPRN_SRR1 - rlwinm r3, r3, 44-31, 0x7 /* extract wake reason field */ - cmpwi r3, 4 /* was it an external interrupt? */ - bne kvm_novcpu_exit /* if not, exit the guest */ - - /* extern interrupt - read and handle it */ - li r12, BOOK3S_INTERRUPT_EXTERNAL - bl kvmppc_read_intr + /* See if the wake reason means we need to exit */ cmpdi r3, 0 bge kvm_novcpu_exit - li r12, 0 /* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */ ld r4, HSTATE_KVM_VCPU(r13)
@@ -264,40 +257,16 @@ kvm_start_guest: */ /* Check the wake reason in SRR1 to see why we got here */ - mfspr r3,SPRN_SRR1 - rlwinm r3,r3,44-31,0x7 /* extract wake reason field */ - cmpwi r3,4 /* was it an external interrupt? */ - bne 27f /* if not */ - ld r5,HSTATE_XICS_PHYS(r13) - li r7,XICS_XIRR /* if it was an external interrupt, */ - lwzcix r8,r5,r7 /* get and ack the interrupt */ - sync - clrldi. r9,r8,40 /* get interrupt source ID. */ - beq 28f /* none there? */ - cmpwi r9,XICS_IPI /* was it an IPI? */ - bne 29f - li r0,0xff - li r6,XICS_MFRR - stbcix r0,r5,r6 /* clear IPI */ - stwcix r8,r5,r7 /* EOI the interrupt */ - sync /* order loading of vcpu after that */ + bl kvmppc_check_wake_reason + cmpdi r3, 0 + bge kvm_no_guest /* get vcpu pointer, NULL if we have no vcpu to run */ ld r4,HSTATE_KVM_VCPU(r13) cmpdi r4,0 /* if we have no vcpu to run, go back to sleep */ beq kvm_no_guest - b 30f -27: /* XXX should handle hypervisor maintenance interrupts etc. here */ - b kvm_no_guest -28: /* SRR1 said external but ICP said nope?? */ - b kvm_no_guest -29: /* External non-IPI interrupt to offline secondary thread? help?? */ - stw r8,HSTATE_SAVED_XIRR(r13) - b kvm_no_guest - -30: /* Set HSTATE_DSCR(r13) to something sensible */ LOAD_REG_ADDR(r6, dscr_default) ld r6, 0(r6)
@@ -310,18 +279,6 @@ kvm_start_guest: li r0, 0 std r0, HSTATE_KVM_VCPU(r13) lwsync - /* Clear any pending IPI - we're an offline thread */ - ld r5, HSTATE_XICS_PHYS(r13) - li r7, XICS_XIRR - lwzcix r3, r5, r7 /* ack any pending interrupt */ - rlwinm. r0, r3, 0, 0xffffff /* any pending? */ - beq 37f - sync - li r0, 0xff - li r6, XICS_MFRR - stbcix r0, r5, r6 /* clear the IPI */ - stwcix r3, r5, r7 /* EOI it */ -37: sync /* increment the nap count and then go to nap mode */ ld r4, HSTATE_KVM_VCORE(r13)
@@ -818,47 +775,46 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) mtctr r6 mtxer r7 +kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */ ld r10, VCPU_PC(r4) ld r11, VCPU_MSR(r4) -kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */ ld r6, VCPU_SRR0(r4) ld r7, VCPU_SRR1(r4) + mtspr SPRN_SRR0, r6 + mtspr SPRN_SRR1, r7 +deliver_guest_interrupt: /* r11 = vcpu->arch.msr & ~MSR_HV */ rldicl r11, r11, 63 - MSR_HV_LG, 1 rotldi r11, r11, 1 + MSR_HV_LG ori r11, r11, MSR_ME /* Check if we can deliver an external or decrementer interrupt now */ - ld r0,VCPU_PENDING_EXC(r4) - lis r8,(1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h - and r0,r0,r8 - cmpdi cr1,r0,0 - andi. r0,r11,MSR_EE - beq cr1,11f + ld r0, VCPU_PENDING_EXC(r4) + rldicl r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63 + cmpdi cr1, r0, 0 + andi. r8, r11, MSR_EE BEGIN_FTR_SECTION - mfspr r8,SPRN_LPCR - ori r8,r8,LPCR_MER - mtspr SPRN_LPCR,r8 + mfspr r8, SPRN_LPCR + /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */ + rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH + mtspr SPRN_LPCR, r8 isync END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) beq 5f - li r0,BOOK3S_INTERRUPT_EXTERNAL -12: mr r6,r10 + li r0, BOOK3S_INTERRUPT_EXTERNAL + bne cr1, 12f + mfspr r0, SPRN_DEC + cmpwi r0, 0 + li r0, BOOK3S_INTERRUPT_DECREMENTER + bge 5f + +12: mtspr SPRN_SRR0, r10 mr r10,r0 - mr r7,r11 + mtspr SPRN_SRR1, r11 li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ rotldi r11,r11,63 - b 5f -11: beq 5f - mfspr r0,SPRN_DEC - cmpwi r0,0 - li r0,BOOK3S_INTERRUPT_DECREMENTER - blt 12b - - /* Move SRR0 and SRR1 into the respective regs */ -5: mtspr SPRN_SRR0, r6 - mtspr SPRN_SRR1, r7 +5: /* * Required state:
@@ -1047,39 +1003,19 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) /* External interrupt, first check for host_ipi. If this is * set, we know the host wants us out so let's do it now */ -do_ext_interrupt: bl kvmppc_read_intr cmpdi r3, 0 bgt ext_interrupt_to_host - /* Allright, looks like an IPI for the guest, we need to set MER */ /* Check if any CPU is heading out to the host, if so head out too */ ld r5, HSTATE_KVM_VCORE(r13) lwz r0, VCORE_ENTRY_EXIT(r5) cmpwi r0, 0x100 bge ext_interrupt_to_host - /* See if there is a pending interrupt for the guest */ - mfspr r8, SPRN_LPCR - ld r0, VCPU_PENDING_EXC(r9) - /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */ - rldicl. r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63 - rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH - beq 2f - - /* And if the guest EE is set, we can deliver immediately, else - * we return to the guest with MER set - */ - andi. r0, r11, MSR_EE - beq 2f - mtspr SPRN_SRR0, r10 - mtspr SPRN_SRR1, r11 - li r10, BOOK3S_INTERRUPT_EXTERNAL - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 -2: mr r4, r9 - mtspr SPRN_LPCR, r8 - b fast_guest_return + /* Return to guest after delivering any pending interrupt */ + mr r4, r9 + b deliver_guest_interrupt ext_interrupt_to_host:
@@ -1887,7 +1823,6 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) stb r0,HSTATE_NAPPING(r13) /* order napping_threads update vs testing entry_exit_count */ lwsync - mr r4,r3 lwz r7,VCORE_ENTRY_EXIT(r5) cmpwi r7,0x100 bge 33f /* another thread already exiting */
@@ -1940,6 +1875,11 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) nap b . +33: mr r4, r3 + li r3, 0 + li r12, 0 + b 34f + kvm_end_cede: /* get vcpu pointer */ ld r4, HSTATE_KVM_VCPU(r13)
@@ -1969,12 +1909,15 @@ kvm_end_cede: ld r29, VCPU_GPR(R29)(r4) ld r30, VCPU_GPR(R30)(r4) ld r31, VCPU_GPR(R31)(r4) + + /* Check the wake reason in SRR1 to see why we got here */ + bl kvmppc_check_wake_reason /* clear our bit in vcore->napping_threads */ -33: ld r5,HSTATE_KVM_VCORE(r13) - lbz r3,HSTATE_PTID(r13) +34: ld r5,HSTATE_KVM_VCORE(r13) + lbz r7,HSTATE_PTID(r13) li r0,1 - sld r0,r0,r3 + sld r0,r0,r7 addi r6,r5,VCORE_NAPPING_THREADS 32: lwarx r7,0,r6 andc r7,r7,r0
@@ -1983,23 +1926,18 @@ kvm_end_cede: li r0,0 stb r0,HSTATE_NAPPING(r13) - /* Check the wake reason in SRR1 to see why we got here */ - mfspr r3, SPRN_SRR1 - rlwinm r3, r3, 44-31, 0x7 /* extract wake reason field */ - cmpwi r3, 4 /* was it an external interrupt? */ - li r12, BOOK3S_INTERRUPT_EXTERNAL + /* See if the wake reason means we need to exit */ + stw r12, VCPU_TRAP(r4) mr r9, r4 - ld r10, VCPU_PC(r9) - ld r11, VCPU_MSR(r9) - beq do_ext_interrupt /* if so */ + cmpdi r3, 0 + bgt guest_exit_cont /* see if any other thread is already exiting */ lwz r0,VCORE_ENTRY_EXIT(r5) cmpwi r0,0x100 - blt kvmppc_cede_reentry /* if not go back to guest */ + bge guest_exit_cont - /* some threads are exiting, so go to the guest exit path */ - b hcall_real_fallback + b kvmppc_cede_reentry /* if not go back to guest */ /* cede when already previously prodded case */ kvm_cede_prodded:
@@ -2030,6 +1968,29 @@ machine_check_realmode: b fast_interrupt_c_return /* + * Check the reason we woke from nap, and take appropriate action. + * Returns: + * 0 if nothing needs to be done + * 1 if something happened that needs to be handled by the host + * -1 if there was a guest wakeup (IPI) + * + * Also sets r12 to the interrupt vector for any interrupt that needs + * to be handled now by the host (0x500 for external interrupt), or zero. + */ +kvmppc_check_wake_reason: + mfspr r6, SPRN_SRR1 + rlwinm r6, r6, 44-31, 0x7 /* extract wake reason field */ + cmpwi r6, 4 /* was it an external interrupt? */ + li r12, BOOK3S_INTERRUPT_EXTERNAL + beq kvmppc_read_intr /* if so, see what it was */ + li r3, 0 + li r12, 0 + cmpwi r6, 6 /* was it the decrementer? */ + beq 0f + li r3, 1 /* anything else, return 1 */ +0: blr + +/* * Determine what sort of external interrupt is pending (if any). * Returns: * 0 if no interrupt is pending
@@ -2060,7 +2021,6 @@ kvmppc_read_intr: * interrupts directly to the guest */ cmpwi r3, XICS_IPI /* if there is, is it an IPI? */ - li r3, 1 bne 42f /* It's an IPI, clear the MFRR and EOI it */
@@ -2086,12 +2046,14 @@ kvmppc_read_intr: * before exit, it will be picked up by the host ICP driver */ stw r0, HSTATE_SAVED_XIRR(r13) + li r3, 1 b 1b 43: /* We raced with the host, we need to resend that IPI, bummer */ li r0, IPI_PRIORITY stbcix r0, r6, r8 /* set the IPI */ sync + li r3, 1 b 1b /*
Signature · 1 line
1.8.1.4
[PULL 28/36] KVM: PPC: Book3S HV: Handle guest using doorbells for IPIs
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
* SRR1 wake reason field for system reset interrupt on wakeup from nap is now a 4-bit field on P8, compared to 3 bits on P7.
* Set PECEDP in LPCR when napping because of H_CEDE so guest doorbells will wake us up.
* Waking up from nap because of a guest doorbell interrupt is not a reason to exit the guest.
--- arch/powerpc/include/asm/reg.h | 4 +++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/reg.h +3 -1
@@ -307,7 +307,9 @@#define LPCR_ILE 0x02000000/* !HV irqs set MSR:LE */ #define LPCR_AIL_0 0x00000000/* MMU off exception offset 0x0 */ #define LPCR_AIL_3 0x01800000/* MMU on exception offset 0xc00...4xxx */ -#define LPCR_PECE 0x00007000/* powersave exit cause enable */ +#define LPCR_PECE 0x0001f000/* powersave exit cause enable */ +#define LPCR_PECEDP 0x00010000/* directed priv dbells cause exit */ +#define LPCR_PECEDH 0x00008000/* directed hyp dbells cause exit */ #define LPCR_PECE0 0x00004000/* ext. exceptions can cause exit */ #define LPCR_PECE1 0x00002000/* decrementer can cause exit */ #define LPCR_PECE2 0x00001000/* machine check etc can cause exit */
arch/powerpc/kvm/book3s_hv_rmhandlers.S +15 -4
@@ -1857,13 +1857,16 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_206) bl kvmppc_save_fp /* - * Take a nap until a decrementer or external interrupt occurs, - * with PECE1 (wake on decr) and PECE0 (wake on external) set in LPCR + * Take a nap until a decrementer or external or doobell interrupt + * occurs, with PECE1, PECE0 and PECEDP set in LPCR */ li r0,1 stb r0,HSTATE_HWTHREAD_REQ(r13) mfspr r5,SPRN_LPCR ori r5,r5,LPCR_PECE0 | LPCR_PECE1 +BEGIN_FTR_SECTION + oris r5,r5,LPCR_PECEDP@h +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) mtspr SPRN_LPCR,r5 isync li r0, 0
@@ -1979,14 +1982,22 @@ machine_check_realmode: */ kvmppc_check_wake_reason: mfspr r6, SPRN_SRR1 - rlwinm r6, r6, 44-31, 0x7 /* extract wake reason field */ - cmpwi r6, 4 /* was it an external interrupt? */ +BEGIN_FTR_SECTION + rlwinm r6, r6, 45-31, 0xf /* extract wake reason field (P8) */ +FTR_SECTION_ELSE + rlwinm r6, r6, 45-31, 0xe /* P7 wake reason field is 3 bits */ +ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_207S) + cmpwi r6, 8 /* was it an external interrupt? */ li r12, BOOK3S_INTERRUPT_EXTERNAL beq kvmppc_read_intr /* if so, see what it was */ li r3, 0 li r12, 0 cmpwi r6, 6 /* was it the decrementer? */ beq 0f +BEGIN_FTR_SECTION + cmpwi r6, 5 /* privileged doorbell? */ + beq 0f +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) li r3, 1 /* anything else, return 1 */ 0: blr
Signature · 1 line
1.8.1.4
[PULL 29/36] KVM: PPC: Book3S HV: Handle new LPCR bits on POWER8
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
POWER8 has a bit in the LPCR to enable or disable the PURR and SPURR registers to count when in the guest. Set this bit.
POWER8 has a field in the LPCR called AIL (Alternate Interrupt Location) which is used to enable relocation-on interrupts. Allow userspace to set this field.
--- arch/powerpc/include/asm/reg.h | 2 ++ arch/powerpc/kvm/book3s_hv.c | 6 ++++++ 2 files changed, 8 insertions(+)
arch/powerpc/include/asm/reg.h +2 -0
@@ -305,8 +305,10 @@#define LPCR_RMLS 0x1C000000/* impl dependent rmo limit sel */ #define LPCR_RMLS_SH (63-37)#define LPCR_ILE 0x02000000/* !HV irqs set MSR:LE */ +#define LPCR_AIL 0x01800000/* Alternate interrupt location */ #define LPCR_AIL_0 0x00000000/* MMU off exception offset 0x0 */ #define LPCR_AIL_3 0x01800000/* MMU on exception offset 0xc00...4xxx */ +#define LPCR_ONL 0x00040000/* online - PURR/SPURR count */ #define LPCR_PECE 0x0001f000/* powersave exit cause enable */ #define LPCR_PECEDP 0x00010000/* directed priv dbells cause exit */ #define LPCR_PECEDH 0x00008000/* directed hyp dbells cause exit */
arch/powerpc/kvm/book3s_hv.c +6 -0
@@ -789,8 +789,11 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr)/* * Userspace can only modify DPFD (default prefetch depth), * ILE (interrupt little-endian) and TC (translation control). +* On POWER8 userspace can also modify AIL (alt. interrupt loc.) */ mask =LPCR_DPFD |LPCR_ILE |LPCR_TC ; +if (cpu_has_feature (CPU_FTR_ARCH_207S )) + mask |=LPCR_AIL ; vc->lpcr = (vc->lpcr & ~mask) | (new_lpcr & mask);spin_unlock (&vc->lock); }
@@ -2166,6 +2169,9 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)LPCR_VPM0 |LPCR_VPM1 ; kvm->arch.vrma_slb_v =SLB_VSID_B_1T | (VRMA_VSID <<SLB_VSID_SHIFT_1T ); +/* On POWER8 turn on online bit to enable PURR/SPURR */ +if (cpu_has_feature (CPU_FTR_ARCH_207S )) + lpcr |=LPCR_ONL ; } kvm->arch.lpcr = lpcr;
Signature · 1 line
1.8.1.4
[PULL 30/36] KVM: PPC: Book3S HV: Prepare for host using hypervisor doorbells
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
POWER8 has support for hypervisor doorbell interrupts. Though the kernel doesn't use them for IPIs on the powernv platform yet, it probably will in future, so this makes KVM cope gracefully if a hypervisor doorbell interrupt arrives while in a guest.
--- arch/powerpc/include/asm/kvm_asm.h | 1 + arch/powerpc/kvm/book3s_hv.c | 1 + arch/powerpc/kvm/book3s_hv_rmhandlers.S | 7 +++++++ 3 files changed, 9 insertions(+)
arch/powerpc/include/asm/kvm_asm.h +1 -0
@@ -96,6 +96,7 @@#define BOOK3S_INTERRUPT_H_DATA_STORAGE 0xe00#define BOOK3S_INTERRUPT_H_INST_STORAGE 0xe20#define BOOK3S_INTERRUPT_H_EMUL_ASSIST 0xe40 +#define BOOK3S_INTERRUPT_H_DOORBELL 0xe80#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40
arch/powerpc/kvm/book3s_hv.c +1 -0
@@ -651,6 +651,7 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, r =RESUME_GUEST ;break ;case BOOK3S_INTERRUPT_EXTERNAL : +case BOOK3S_INTERRUPT_H_DOORBELL : vcpu->stat.ext_intr_exits++; r =RESUME_GUEST ;break ;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +7 -0
@@ -1997,10 +1997,17 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_207S) BEGIN_FTR_SECTION cmpwi r6, 5 /* privileged doorbell? */ beq 0f + cmpwi r6, 3 /* hypervisor doorbell? */ + beq 3f END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) li r3, 1 /* anything else, return 1 */ 0: blr + /* hypervisor doorbell */ +3: li r12, BOOK3S_INTERRUPT_H_DOORBELL + li r3, 1 + blr + /* * Determine what sort of external interrupt is pending (if any). * Returns:
Signature · 1 line
1.8.1.4
[PULL 31/36] KVM: PPC: Book3S HV: Add support for DABRX register on POWER7
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
The DABRX (DABR extension) register on POWER7 processors provides finer control over which accesses cause a data breakpoint interrupt. It contains 3 bits which indicate whether to enable accesses in user, kernel and hypervisor modes respectively to cause data breakpoint interrupts, plus one bit that enables both real mode and virtual mode accesses to cause interrupts. Currently, KVM sets DABRX to allow both kernel and user accesses to cause interrupts while in the guest.
This adds support for the guest to specify other values for DABRX. PAPR defines a H_SET_XDABR hcall to allow the guest to set both DABR and DABRX with one call. This adds a real-mode implementation of H_SET_XDABR, which shares most of its code with the existing H_SET_DABR implementation. To support this, we add a per-vcpu field to store the DABRX value plus code to get and set it via the ONE_REG interface.
For Linux guests to use this new hcall, userspace needs to add "hcall-xdabr" to the set of strings in the /chosen/hypertas-functions property in the device tree. If userspace does this and then migrates the guest to a host where the kernel doesn't include this patch, then userspace will need to implement H_SET_XDABR by writing the specified DABR value to the DABR using the ONE_REG interface. In that case, the old kernel will set DABRX to DABRX_USER | DABRX_KERNEL. That should still work correctly, at least for Linux guests, since Linux guests cope with getting data breakpoint interrupts in modes that weren't requested by just ignoring the interrupt, and Linux guests never set DABRX_BTI.
The other thing this does is to make H_SET_DABR and H_SET_XDABR work on POWER8, which has the DAWR and DAWRX instead of DABR/X. Guests that know about POWER8 should use H_SET_MODE rather than H_SET_[X]DABR, but guests running in POWER7 compatibility mode will still use H_SET_[X]DABR. For them, this adds the logic to convert DABR/X values into DAWR/X values on POWER8.
--- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/reg.h | 18 +++++++++++------- arch/powerpc/include/uapi/asm/kvm.h | 2 ++ arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_hv.c | 6 ++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 32 ++++++++++++++++++++++++++++++-- 7 files changed, 52 insertions(+), 9 deletions(-)
Documentation/virtual/kvm/api.txt +1 -0
@@ -1838,6 +1838,7 @@ registers, find a list below: PPC | KVM_REG_PPC_LPCR | 64 PPC | KVM_REG_PPC_PPR | 64 PPC | KVM_REG_PPC_ARCH_COMPAT 32 + PPC | KVM_REG_PPC_DABRX | 32 PPC | KVM_REG_PPC_TM_GPR0 | 64 ... PPC | KVM_REG_PPC_TM_GPR31 | 64
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -466,6 +466,7 @@ struct kvm_vcpu_arch {ulong uamor;ulong iamr;u32 ctrl; +u32 dabrx;ulong dabr;ulong dawr;ulong dawrx;
arch/powerpc/include/asm/reg.h +11 -7
@@ -229,16 +229,20 @@#define CIABR_PRIV_SUPER 2#define CIABR_PRIV_HYPER 3#define SPRN_DAWRX 0xBC -#define DAWRX_USER (1UL << 0) -#define DAWRX_KERNEL (1UL << 1) -#define DAWRX_HYP (1UL << 2) +#define DAWRX_USER __MASK(0) +#define DAWRX_KERNEL __MASK(1) +#define DAWRX_HYP __MASK(2) +#define DAWRX_WTI __MASK(3) +#define DAWRX_WT __MASK(4) +#define DAWRX_DR __MASK(5) +#define DAWRX_DW __MASK(6)#define SPRN_DABR 0x3F5/* Data Address Breakpoint Register */ #define SPRN_DABR2 0x13D/* e300 */ #define SPRN_DABRX 0x3F7/* Data Address Breakpoint Register Extension */ -#define DABRX_USER (1UL << 0) -#define DABRX_KERNEL (1UL << 1) -#define DABRX_HYP (1UL << 2) -#define DABRX_BTI (1UL << 3) +#define DABRX_USER __MASK(0) +#define DABRX_KERNEL __MASK(1) +#define DABRX_HYP __MASK(2) +#define DABRX_BTI __MASK(3)#define DABRX_ALL (DABRX_BTI | DABRX_HYP | DABRX_KERNEL | DABRX_USER)#define SPRN_DAR 0x013/* Data Address Register */ #define SPRN_DBCR 0x136/* e300 Data Breakpoint Control Reg */
arch/powerpc/include/uapi/asm/kvm.h +2 -0
@@ -554,6 +554,8 @@ struct kvm_get_htab_header {/* Architecture compatibility level */ #define KVM_REG_PPC_ARCH_COMPAT (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb7) +#define KVM_REG_PPC_DABRX (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb8) +/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -493,6 +493,7 @@ int main(void) DEFINE(VCPU_IAMR, offsetof(struct kvm_vcpu, arch.iamr)); DEFINE(VCPU_CTRL, offsetof(struct kvm_vcpu, arch.ctrl)); DEFINE(VCPU_DABR, offsetof(struct kvm_vcpu, arch.dabr)); + DEFINE(VCPU_DABRX, offsetof(struct kvm_vcpu, arch.dabrx)); DEFINE(VCPU_DAWR, offsetof(struct kvm_vcpu, arch.dawr)); DEFINE(VCPU_DAWRX, offsetof(struct kvm_vcpu, arch.dawrx)); DEFINE(VCPU_CIABR, offsetof(struct kvm_vcpu, arch.ciabr));
arch/powerpc/kvm/book3s_hv.c +6 -0
@@ -812,6 +812,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_DABR : *val =get_reg_val (id, vcpu->arch.dabr);break ; +case KVM_REG_PPC_DABRX : + *val =get_reg_val (id, vcpu->arch.dabrx); +break ;case KVM_REG_PPC_DSCR : *val =get_reg_val (id, vcpu->arch.dscr);break ;
@@ -967,6 +970,9 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_DABR : vcpu->arch.dabr =set_reg_val (id, *val);break ; +case KVM_REG_PPC_DABRX : + vcpu->arch.dabrx =set_reg_val (id, *val) & ~DABRX_HYP ; +break ;case KVM_REG_PPC_DSCR : vcpu->arch.dscr =set_reg_val (id, *val);break ;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +30 -2
@@ -585,7 +585,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) BEGIN_FTR_SECTION /* Set partition DABR */ /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */ - li r5,3 + lwz r5,VCPU_DABRX(r4) ld r6,VCPU_DABR(r4) mtspr SPRN_DABRX,r5 mtspr SPRN_DABR,r6
@@ -1763,24 +1763,52 @@ hcall_real_table: .long 0 /* 0x11c */ .long 0 /* 0x120 */ .long .kvmppc_h_bulk_remove - hcall_real_table + .long 0 /* 0x128 */ + .long 0 /* 0x12c */ + .long 0 /* 0x130 */ + .long .kvmppc_h_set_xdabr - hcall_real_table hcall_real_table_end: ignore_hdec: mr r4,r9 b fast_guest_return +_GLOBAL(kvmppc_h_set_xdabr) + andi. r0, r5, DABRX_USER | DABRX_KERNEL + beq 6f + li r0, DABRX_USER | DABRX_KERNEL | DABRX_BTI + andc. r0, r5, r0 + beq 3f +6: li r3, H_PARAMETER + blr + _GLOBAL(kvmppc_h_set_dabr) + li r5, DABRX_USER | DABRX_KERNEL +3: BEGIN_FTR_SECTION b 2f END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) std r4,VCPU_DABR(r3) + stw r5, VCPU_DABRX(r3) + mtspr SPRN_DABRX, r5 /* Work around P7 bug where DABR can get corrupted on mtspr */ 1: mtspr SPRN_DABR,r4 mfspr r5, SPRN_DABR cmpd r4, r5 bne 1b isync -2: li r3,0 + li r3,0 + blr + + /* Emulate H_SET_DABR/X on P8 for the sake of compat mode guests */ +2: rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW + rlwimi r5, r4, 1, DAWRX_WT + clrrdi r4, r4, 3 + std r4, VCPU_DAWR(r3) + std r5, VCPU_DAWRX(r3) + mtspr SPRN_DAWR, r4 + mtspr SPRN_DAWRX, r5 + li r3, 0 blr _GLOBAL(kvmppc_h_cede)
Signature · 1 line
1.8.1.4
[PULL 32/36] KVM: PPC: Book3S HV: Basic little-endian guest support
In reply to Alexander GrafFrom: Anton Blanchard <[email protected]>
We create a guest MSR from scratch when delivering exceptions in a few places. Instead of extracting LPCR[ILE] and inserting it into MSR_LE each time, we simply create a new variable intr_msr which contains the entire MSR to use. For a little-endian guest, userspace needs to set the ILE (interrupt little-endian) bit in the LPCR for each vcpu (or at least one vcpu in each virtual core).
[[email protected] - removed H_SET_MODE implementation from original version of the patch, and made kvmppc_set_lpcr update vcpu->arch.intr_msr.]
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 22 ++++++++++++++++++++++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 15 +++++---------- 5 files changed, 30 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -636,6 +636,7 @@ struct kvm_vcpu_arch {spinlock_t tbacct_lock;u64 busy_stolen;u64 busy_preempt; +unsigned long intr_msr;#endif };
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -480,6 +480,7 @@ int main(void) DEFINE(VCPU_DAR, offsetof(struct kvm_vcpu, arch.shregs.dar)); DEFINE(VCPU_VPA, offsetof(struct kvm_vcpu, arch.vpa.pinned_addr)); DEFINE(VCPU_VPA_DIRTY, offsetof(struct kvm_vcpu, arch.vpa.dirty)); + DEFINE(VCPU_INTR_MSR, offsetof(struct kvm_vcpu, arch.intr_msr));#endif #ifdef CONFIG_PPC_BOOK3S DEFINE (VCPU_VCPUID , offsetof(struct kvm_vcpu , vcpu_id));
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -262,7 +262,7 @@ int kvmppc_mmu_hv_init(void)static void kvmppc_mmu_book3s_64_hv_reset_msr (struct kvm_vcpu *vcpu) { -kvmppc_set_msr (vcpu,MSR_SF |MSR_ME ); +kvmppc_set_msr (vcpu, vcpu->arch.intr_msr); }/*
arch/powerpc/kvm/book3s_hv.c +22 -0
@@ -788,6 +788,27 @@ static void kvmppc_set_lpcr(struct kvm_vcpu *vcpu, u64 new_lpcr)spin_lock (&vc->lock);/* +* If ILE (interrupt little-endian) has changed, update the +* MSR_LE bit in the intr_msr for each vcpu in this vcore. +*/ +if ((new_lpcr &LPCR_ILE ) != (vc->lpcr &LPCR_ILE )) { +struct kvm *kvm = vcpu->kvm; +struct kvm_vcpu *vcpu; +int i; + +mutex_lock (&kvm->lock); +kvm_for_each_vcpu (i, vcpu, kvm) { +if (vcpu->arch.vcore != vc) +continue ; +if (new_lpcr &LPCR_ILE ) + vcpu->arch.intr_msr |=MSR_LE ; +else + vcpu->arch.intr_msr &= ~MSR_LE ; + } +mutex_unlock (&kvm->lock); + } + +/* * Userspace can only modify DPFD (default prefetch depth), * ILE (interrupt little-endian) and TC (translation control). * On POWER8 userspace can also modify AIL (alt. interrupt loc.)
@@ -1155,6 +1176,7 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_hv(struct kvm *kvm,spin_lock_init (&vcpu->arch.vpa_update_lock);spin_lock_init (&vcpu->arch.tbacct_lock); vcpu->arch.busy_preempt =TB_NIL ; + vcpu->arch.intr_msr =MSR_SF |MSR_ME ;kvmppc_mmu_book3s_hv_init (vcpu);
arch/powerpc/kvm/book3s_hv_rmhandlers.S +5 -10
@@ -812,8 +812,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206) 12: mtspr SPRN_SRR0, r10 mr r10,r0 mtspr SPRN_SRR1, r11 - li r11,(MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11,r11,63 + ld r11, VCPU_INTR_MSR(r4) 5: /*
@@ -1551,8 +1550,7 @@ kvmppc_hdsi: mtspr SPRN_SRR0, r10 mtspr SPRN_SRR1, r11 li r10, BOOK3S_INTERRUPT_DATA_STORAGE - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11, VCPU_INTR_MSR(r9) fast_interrupt_c_return: 6: ld r7, VCPU_CTR(r9) lwz r8, VCPU_XER(r9)
@@ -1621,8 +1619,7 @@ kvmppc_hisi: 1: mtspr SPRN_SRR0, r10 mtspr SPRN_SRR1, r11 li r10, BOOK3S_INTERRUPT_INST_STORAGE - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11, VCPU_INTR_MSR(r9) b fast_interrupt_c_return 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */
@@ -1665,8 +1662,7 @@ sc_1_fast_return: mtspr SPRN_SRR0,r10 mtspr SPRN_SRR1,r11 li r10, BOOK3S_INTERRUPT_SYSCALL - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11, VCPU_INTR_MSR(r9) mr r4,r9 b fast_guest_return
@@ -1994,8 +1990,7 @@ machine_check_realmode: beq mc_cont /* If not, deliver a machine check. SRR0/1 are already set */ li r10, BOOK3S_INTERRUPT_MACHINE_CHECK - li r11, (MSR_ME << 1) | 1 /* synthesize MSR_SF | MSR_ME */ - rotldi r11, r11, 63 + ld r11, VCPU_INTR_MSR(r9) b fast_interrupt_c_return /*
Signature · 1 line
1.8.1.4
[PULL 33/36] powerpc/Kconfig: Make TM select VSX and VMX
In reply to Alexander GrafFrom: Michael Neuling <[email protected]>
There are no processors in existence that have TM but no VMX or VSX. So let's makes CONFIG_PPC_TRANSACTIONAL_MEM select both CONFIG_VSX and CONFIG_ALTIVEC. This makes the code a lot simpler by removing the need for a bunch of #ifdefs.
--- arch/powerpc/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/Kconfig +2 -0
@@ -338,6 +338,8 @@ config PPC_TRANSACTIONAL_MEM bool "Transactional Memory support for POWERPC" depends on PPC_BOOK3S_64 depends on SMP + select ALTIVEC + select VSX default n ---help--- Support user-mode Transactional Memory on POWERPC.
Signature · 1 line
1.8.1.4
[PULL 34/36] KVM: PPC: Book3S HV: Add new state for transactional memory
In reply to Alexander GrafFrom: Michael Neuling <[email protected]>
Add new state for transactional memory (TM) to kvm_vcpu_arch. Also add asm-offset bits that are going to be required.
This also moves the existing TFHAR, TFIAR and TEXASR SPRs into a CONFIG_PPC_TRANSACTIONAL_MEM section. This requires some code changes to ensure we still compile with CONFIG_PPC_TRANSACTIONAL_MEM=N. Much of the added the added #ifdefs are removed in a later patch when the bulk of the TM code is added.
--- arch/powerpc/include/asm/kvm_host.h | 24 +++++++++-- arch/powerpc/kernel/asm-offsets.c | 19 +++++++-- arch/powerpc/kvm/book3s_hv.c | 4 ++ arch/powerpc/kvm/book3s_hv_rmhandlers.S | 75 ++++++++++++++++++++++++++++++++- 4 files changed, 114 insertions(+), 8 deletions(-)
arch/powerpc/include/asm/kvm_host.h +21 -3
@@ -475,9 +475,6 @@ struct kvm_vcpu_arch {ulong ppr;ulong pspb;ulong fscr; -ulong tfhar; -ulong tfiar; -ulong texasr;ulong ebbhr;ulong ebbrr;ulong bescr;
@@ -526,6 +523,27 @@ struct kvm_vcpu_arch {u64 siar;u64 sdar;u64 sier; +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +u64 tfhar; +u64 texasr; +u64 tfiar; + +u32 cr_tm; +u64 lr_tm; +u64 ctr_tm; +u64 amr_tm; +u64 ppr_tm; +u64 dscr_tm; +u64 tar_tm; + +ulong gpr_tm[32 ]; + +struct thread_fp_state fp_tm; + +struct thread_vr_state vr_tm; +u32 vrsave_tm;/* also USPRG0 */ + +#endif #ifdef CONFIG_KVM_EXIT_TIMING struct mutex exit_timing_lock;
arch/powerpc/kernel/asm-offsets.c +16 -3
@@ -521,9 +521,6 @@ int main(void) DEFINE(VCPU_PPR, offsetof(struct kvm_vcpu, arch.ppr)); DEFINE(VCPU_FSCR, offsetof(struct kvm_vcpu, arch.fscr)); DEFINE(VCPU_PSPB, offsetof(struct kvm_vcpu, arch.pspb)); - DEFINE(VCPU_TFHAR, offsetof(struct kvm_vcpu, arch.tfhar)); - DEFINE(VCPU_TFIAR, offsetof(struct kvm_vcpu, arch.tfiar)); - DEFINE(VCPU_TEXASR, offsetof(struct kvm_vcpu, arch.texasr)); DEFINE(VCPU_EBBHR, offsetof(struct kvm_vcpu, arch.ebbhr)); DEFINE(VCPU_EBBRR, offsetof(struct kvm_vcpu, arch.ebbrr)); DEFINE(VCPU_BESCR, offsetof(struct kvm_vcpu, arch.bescr));
@@ -545,6 +542,22 @@ int main(void)DEFINE (VCPU_SLB_E , offsetof(struct kvmppc_slb , orige));DEFINE (VCPU_SLB_V , offsetof(struct kvmppc_slb , origv));DEFINE (VCPU_SLB_SIZE ,sizeof (struct kvmppc_slb )); +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + DEFINE(VCPU_TFHAR, offsetof(struct kvm_vcpu, arch.tfhar)); + DEFINE(VCPU_TFIAR, offsetof(struct kvm_vcpu, arch.tfiar)); + DEFINE(VCPU_TEXASR, offsetof(struct kvm_vcpu, arch.texasr)); + DEFINE(VCPU_GPR_TM, offsetof(struct kvm_vcpu, arch.gpr_tm)); + DEFINE(VCPU_FPRS_TM, offsetof(struct kvm_vcpu, arch.fp_tm.fpr)); + DEFINE(VCPU_VRS_TM, offsetof(struct kvm_vcpu, arch.vr_tm.vr)); + DEFINE(VCPU_VRSAVE_TM, offsetof(struct kvm_vcpu, arch.vrsave_tm)); + DEFINE(VCPU_CR_TM, offsetof(struct kvm_vcpu, arch.cr_tm)); + DEFINE(VCPU_LR_TM, offsetof(struct kvm_vcpu, arch.lr_tm)); + DEFINE(VCPU_CTR_TM, offsetof(struct kvm_vcpu, arch.ctr_tm)); + DEFINE(VCPU_AMR_TM, offsetof(struct kvm_vcpu, arch.amr_tm)); + DEFINE(VCPU_PPR_TM, offsetof(struct kvm_vcpu, arch.ppr_tm)); + DEFINE(VCPU_DSCR_TM, offsetof(struct kvm_vcpu, arch.dscr_tm)); + DEFINE(VCPU_TAR_TM, offsetof(struct kvm_vcpu, arch.tar_tm)); +#endif #ifdef CONFIG_PPC_BOOK3S_64 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
arch/powerpc/kvm/book3s_hv.c +4 -0
@@ -875,6 +875,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_IAMR : *val =get_reg_val (id, vcpu->arch.iamr);break ; +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM case KVM_REG_PPC_TFHAR : *val =get_reg_val (id, vcpu->arch.tfhar);break ;
@@ -884,6 +885,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_TEXASR : *val =get_reg_val (id, vcpu->arch.texasr);break ; +#endif case KVM_REG_PPC_FSCR : *val =get_reg_val (id, vcpu->arch.fscr);break ;
@@ -1033,6 +1035,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_IAMR : vcpu->arch.iamr =set_reg_val (id, *val);break ; +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM case KVM_REG_PPC_TFHAR : vcpu->arch.tfhar =set_reg_val (id, *val);break ;
@@ -1042,6 +1045,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,case KVM_REG_PPC_TEXASR : vcpu->arch.texasr =set_reg_val (id, *val);break ; +#endif case KVM_REG_PPC_FSCR : vcpu->arch.fscr =set_reg_val (id, *val);break ;
arch/powerpc/kvm/book3s_hv_rmhandlers.S +73 -2
105 lines not on this page · raw message
Signature · 1 line
1.8.1.4
[PULL 35/36] KVM: PPC: Book3S HV: Add software abort codes for transactional memory
In reply to Alexander GrafFrom: Michael Neuling <[email protected]>
This adds the software abort code defines for transactional memory (TM). These values are from PAPR.
--- arch/powerpc/include/uapi/asm/tm.h | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/include/uapi/asm/tm.h +2 -0
@@ -6,6 +6,8 @@* the failure is persistent. PAPR saves 0xff-0xe0 for the hypervisor. */ #define TM_CAUSE_PERSISTENT 0x01 +#define TM_CAUSE_KVM_RESCHED 0xe0/* From PAPR */ +#define TM_CAUSE_KVM_FAC_UNAV 0xe2/* From PAPR */ #define TM_CAUSE_RESCHED 0xde#define TM_CAUSE_TLBI 0xdc#define TM_CAUSE_FAC_UNAV 0xda
Signature · 1 line
1.8.1.4
[PULL 36/36] KVM: PPC: Book3S PR: Cope with doorbell interrupts
In reply to Alexander GrafFrom: Paul Mackerras <[email protected]>
When the PR host is running on a POWER8 machine in POWER8 mode, it will use doorbell interrupts for IPIs. If one of them arrives while we are in the guest, we pop out of the guest with trap number 0xA00, which isn't handled by kvmppc_handle_exit_pr, leading to the following BUG_ON:
[ 331.436215] exit_nr=0xa00 | pc=0x1d2c | msr=0x800000000000d032 [ 331.437522] ------------[ cut here ]------------ [ 331.438296] kernel BUG at arch/powerpc/kvm/book3s_pr.c:982! [ 331.439063] Oops: Exception in kernel mode, sig: 5 [#2] [ 331.439819] SMP NR_CPUS=1024 NUMA pSeries [ 331.440552] Modules linked in: tun nf_conntrack_netbios_ns nf_conntrack_broadcast ipt_MASQUERADE ip6t_REJECT xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw virtio_net kvm binfmt_misc ibmvscsi scsi_transport_srp scsi_tgt virtio_blk [ 331.447614] CPU: 11 PID: 1296 Comm: qemu-system-ppc Tainted: G D 3.11.7-200.2.fc19.ppc64p7 #1 [ 331.448920] task: c0000003bdc8c000 ti: c0000003bd32c000 task.ti: c0000003bd32c000 [ 331.450088] NIP: d0000000025d6b9c LR: d0000000025d6b98 CTR: c0000000004cfdd0 [ 331.451042] REGS: c0000003bd32f420 TRAP: 0700 Tainted: G D (3.11.7-200.2.fc19.ppc64p7) [ 331.452331] MSR: 800000000282b032 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI> CR: 28004824 XER: 20000000 [ 331.454616] SOFTE: 1 [ 331.455106] CFAR: c000000000848bb8 [ 331.455726]
GPR00: d0000000025d6b98 c0000003bd32f6a0 d0000000026017b8 0000000000000032
GPR04: c0000000018627f8 c000000001873208 320d0a3030303030 3030303030643033
GPR08: c000000000c490a8 0000000000000000 0000000000000000 0000000000000002
GPR12: 0000000028004822 c00000000fdc6300 0000000000000000 00000100076ec310
GPR16: 000000002ae343b8 00003ffffd397398 0000000000000000 0000000000000000
GPR20: 00000100076f16f4 00000100076ebe60 0000000000000008 ffffffffffffffff
GPR24: 0000000000000000 0000008001041e60 0000000000000000 0000008001040ce8
GPR28: c0000003a2d80000 0000000000000a00 0000000000000001 c0000003a2681810
[ 331.466504] NIP [d0000000025d6b9c] .kvmppc_handle_exit_pr+0x75c/0xa80 [kvm] [ 331.466999] LR [d0000000025d6b98] .kvmppc_handle_exit_pr+0x758/0xa80 [kvm] [ 331.467517] Call Trace: [ 331.467909] [c0000003bd32f6a0] [d0000000025d6b98] .kvmppc_handle_exit_pr+0x758/0xa80 [kvm] (unreliable) [ 331.468553] [c0000003bd32f750] [d0000000025d98f0] kvm_start_lightweight+0xb4/0xc4 [kvm] [ 331.469189] [c0000003bd32f920] [d0000000025d7648] .kvmppc_vcpu_run_pr+0xd8/0x270 [kvm] [ 331.469838] [c0000003bd32f9c0] [d0000000025cf748] .kvmppc_vcpu_run+0xc8/0xf0 [kvm] [ 331.470790] [c0000003bd32fa50] [d0000000025cc19c] .kvm_arch_vcpu_ioctl_run+0x5c/0x1b0 [kvm] [ 331.471401] [c0000003bd32fae0] [d0000000025c4888] .kvm_vcpu_ioctl+0x478/0x730 [kvm] [ 331.472026] [c0000003bd32fc90] [c00000000026192c] .do_vfs_ioctl+0x4dc/0x7a0 [ 331.472561] [c0000003bd32fd80] [c000000000261cc4] .SyS_ioctl+0xd4/0xf0 [ 331.473095] [c0000003bd32fe30] [c000000000009ed8] syscall_exit+0x0/0x98 [ 331.473633] Instruction dump: [ 331.473766] 4bfff9b4 2b9d0800 419efc18 60000000 60420000 3d220000 e8bf11a0 e8df12a8 [ 331.474733] 7fa4eb78 e8698660 48015165 e8410028 <0fe00000> 813f00e4 3ba00000 39290001 [ 331.475386] ---[ end trace 49fc47d994c1f8f2 ]--- [ 331.479817]
This fixes the problem by making kvmppc_handle_exit_pr() recognize the interrupt. We also need to jump to the doorbell interrupt handler in book3s_segment.S to handle the interrupt on the way out of the guest. Having done that, there's nothing further to be done in kvmppc_handle_exit_pr().
--- arch/powerpc/include/asm/kvm_asm.h | 1 + arch/powerpc/kvm/book3s_pr.c | 1 + arch/powerpc/kvm/book3s_segment.S | 2 ++ 3 files changed, 4 insertions(+)
arch/powerpc/include/asm/kvm_asm.h +1 -0
@@ -91,6 +91,7 @@#define BOOK3S_INTERRUPT_FP_UNAVAIL 0x800#define BOOK3S_INTERRUPT_DECREMENTER 0x900#define BOOK3S_INTERRUPT_HV_DECREMENTER 0x980 +#define BOOK3S_INTERRUPT_DOORBELL 0xa00#define BOOK3S_INTERRUPT_SYSCALL 0xc00#define BOOK3S_INTERRUPT_TRACE 0xd00#define BOOK3S_INTERRUPT_H_DATA_STORAGE 0xe00
arch/powerpc/kvm/book3s_pr.c +1 -0
@@ -827,6 +827,7 @@ int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,/* We're good on these - the host merely wanted to get our attention */ case BOOK3S_INTERRUPT_DECREMENTER :case BOOK3S_INTERRUPT_HV_DECREMENTER : +case BOOK3S_INTERRUPT_DOORBELL : vcpu->stat.dec_exits++; r =RESUME_GUEST ;break ;
arch/powerpc/kvm/book3s_segment.S +2 -0
@@ -361,6 +361,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE) beqa BOOK3S_INTERRUPT_DECREMENTER cmpwi r12, BOOK3S_INTERRUPT_PERFMON beqa BOOK3S_INTERRUPT_PERFMON + cmpwi r12, BOOK3S_INTERRUPT_DOORBELL + beqa BOOK3S_INTERRUPT_DOORBELL RFI kvmppc_handler_trampoline_exit_end:
Signature · 1 line
1.8.1.4
Paolo Bonzini
maintainerIl 29/01/2014 17:12, Alexander Graf ha scritto:
Quoted 1 line
git://github.com/agraf/linux-2.6.gitkvm-ppc-next
Pulled. There were a couple of conflicts, but I didn't have to scratch my head too long. :)
Thanks,
Paolo