KVM: PPC: Reduce races, fix code
Subsystems (3)
cover KVM: PPC: Reduce races, fix code
We've been a bit lax with how we use fields in the PACA so far. Most of the time we just overwrote random fields that another interrupt handler would have used as well.
That is racy.
We also jumped over to real mode from IR=1 using RFI. Unfortunately, we need 3 operations to do that transitions which need to be fully atomic, as any interrupt coming in between those instructions can possibly break us.
That is racy too.
So let's get rid of all the racy code and clean up some pieces along the way.
Alexander Graf (9):
KVM: PPC: Use accessor functions for GPR access
KVM: PPC: Add helpers for CR, XER
KVM: PPC: Use PACA backed shadow vcpu
KVM: PPC: Implement 'skip instruction' mode
KVM: PPC: Get rid of unnecessary RFI
KVM: PPC: Call SLB patching code in interrupt safe manner
KVM: PPC: Emulate trap SRR1 flags properly
KVM: PPC: Fix HID5 setting code
KVM: PPC: Pass program interrupt flags to the guest
arch/powerpc/include/asm/kvm_asm.h | 6 + arch/powerpc/include/asm/kvm_book3s.h | 4 + arch/powerpc/include/asm/kvm_book3s_64_asm.h | 18 ++ arch/powerpc/include/asm/kvm_host.h | 6 +- arch/powerpc/include/asm/kvm_ppc.h | 76 ++++++++- arch/powerpc/include/asm/paca.h | 5 + arch/powerpc/include/asm/reg.h | 4 + arch/powerpc/kernel/asm-offsets.c | 34 ++++- arch/powerpc/kvm/44x_emulate.c | 25 ++-- arch/powerpc/kvm/44x_tlb.c | 20 ++- arch/powerpc/kvm/book3s.c | 35 +++-- arch/powerpc/kvm/book3s_64_emulate.c | 77 +++++---- arch/powerpc/kvm/book3s_64_exports.c | 1 + arch/powerpc/kvm/book3s_64_interrupts.S | 242 +++++++++----------------- arch/powerpc/kvm/book3s_64_rmhandlers.S | 85 +++++++--- arch/powerpc/kvm/book3s_64_slb.S | 158 +++++++++++------- arch/powerpc/kvm/booke.c | 27 ++-- arch/powerpc/kvm/booke_emulate.c | 107 ++++++------ arch/powerpc/kvm/e500_emulate.c | 95 ++++++----- arch/powerpc/kvm/e500_tlb.c | 4 +- arch/powerpc/kvm/emulate.c | 112 +++++++------ arch/powerpc/kvm/powerpc.c | 21 ++- 22 files changed, 672 insertions(+), 490 deletions(-)
A message that is not in the archive (sent off-list or not yet received): 1262915889-11526-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org
PATCH 1/9 KVM: PPC: Use accessor functions for GPR access
All code in PPC KVM currently accesses gprs in the vcpu struct directly.
While there's nothing wrong with that wrt the current way gprs are stored and loaded, it doesn't suffice for the PACA acceleration that will follow in this patchset.
So let's just create little wrapper inline functions that we call whenever a GPR needs to be read from or written to. The compiled code shouldn't really change at all for now.
--- arch/powerpc/include/asm/kvm_ppc.h | 26 ++++++++ arch/powerpc/kvm/44x_emulate.c | 25 ++++---- arch/powerpc/kvm/44x_tlb.c | 14 ++-- arch/powerpc/kvm/book3s.c | 8 +- arch/powerpc/kvm/book3s_64_emulate.c | 77 +++++++++++++------------ arch/powerpc/kvm/booke.c | 16 +++--- arch/powerpc/kvm/booke_emulate.c | 107 +++++++++++++++++----------------- arch/powerpc/kvm/e500_emulate.c | 95 ++++++++++++++++-------------- arch/powerpc/kvm/e500_tlb.c | 4 +- arch/powerpc/kvm/emulate.c | 106 ++++++++++++++++++--------------- arch/powerpc/kvm/powerpc.c | 21 ++++--- 11 files changed, 274 insertions(+), 225 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +26 -0
@@ -96,4 +96,30 @@ extern void kvmppc_booke_exit(void);extern void kvmppc_core_destroy_mmu (struct kvm_vcpu *vcpu); +#ifdef CONFIG_PPC_BOOK3S + +static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) +{ + vcpu->arch.gpr[num] = val; +} + +static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) +{ +return vcpu->arch.gpr[num]; +} + +#else + +static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) +{ + vcpu->arch.gpr[num] = val; +} + +static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) +{ +return vcpu->arch.gpr[num]; +} + +#endif +#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kvm/44x_emulate.c +13 -12
@@ -65,13 +65,14 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,*/ switch (dcrn) {case DCRN_CPR0_CONFIG_ADDR : - vcpu->arch.gpr[rt] = vcpu->arch.cpr0_cfgaddr; +kvmppc_set_gpr (vcpu, rt, vcpu->arch.cpr0_cfgaddr);break ;case DCRN_CPR0_CONFIG_DATA :local_irq_disable ();mtdcr (DCRN_CPR0_CONFIG_ADDR , vcpu->arch.cpr0_cfgaddr); - vcpu->arch.gpr[rt] =mfdcr (DCRN_CPR0_CONFIG_DATA ); +kvmppc_set_gpr (vcpu, rt, +mfdcr (DCRN_CPR0_CONFIG_DATA ));local_irq_enable ();break ;default :
@@ -93,11 +94,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,/* emulate some access in kernel */ switch (dcrn) {case DCRN_CPR0_CONFIG_ADDR : - vcpu->arch.cpr0_cfgaddr = vcpu->arch.gpr[rs]; + vcpu->arch.cpr0_cfgaddr =kvmppc_get_gpr (vcpu, rs);break ;default : run->dcr.dcrn = dcrn; - run->dcr.data = vcpu->arch.gpr[rs]; + run->dcr.data =kvmppc_get_gpr (vcpu, rs); run->dcr.is_write =1 ; vcpu->arch.dcr_needed =1 ;kvmppc_account_exit (vcpu,DCR_EXITS );
@@ -146,13 +147,13 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)switch (sprn) {case SPRN_PID : -kvmppc_set_pid (vcpu, vcpu->arch.gpr[rs]);break ; +kvmppc_set_pid (vcpu,kvmppc_get_gpr (vcpu, rs));break ;case SPRN_MMUCR : - vcpu->arch.mmucr = vcpu->arch.gpr[rs];break ; + vcpu->arch.mmucr =kvmppc_get_gpr (vcpu, rs);break ;case SPRN_CCR0 : - vcpu->arch.ccr0 = vcpu->arch.gpr[rs];break ; + vcpu->arch.ccr0 =kvmppc_get_gpr (vcpu, rs);break ;case SPRN_CCR1 : - vcpu->arch.ccr1 = vcpu->arch.gpr[rs];break ; + vcpu->arch.ccr1 =kvmppc_get_gpr (vcpu, rs);break ;default : emulated =kvmppc_booke_emulate_mtspr (vcpu, sprn, rs); }
@@ -167,13 +168,13 @@ int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt)switch (sprn) {case SPRN_PID : - vcpu->arch.gpr[rt] = vcpu->arch.pid;break ; +kvmppc_get_gpr (vcpu, rt) = vcpu->arch.pid;break ;case SPRN_MMUCR : - vcpu->arch.gpr[rt] = vcpu->arch.mmucr;break ; +kvmppc_get_gpr (vcpu, rt) = vcpu->arch.mmucr;break ;case SPRN_CCR0 : - vcpu->arch.gpr[rt] = vcpu->arch.ccr0;break ; +kvmppc_get_gpr (vcpu, rt) = vcpu->arch.ccr0;break ;case SPRN_CCR1 : - vcpu->arch.gpr[rt] = vcpu->arch.ccr1;break ; +kvmppc_get_gpr (vcpu, rt) = vcpu->arch.ccr1;break ;default : emulated =kvmppc_booke_emulate_mfspr (vcpu, sprn, rt); }
arch/powerpc/kvm/44x_tlb.c +7 -7
@@ -439,7 +439,7 @@ int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws)struct kvmppc_44x_tlbe *tlbe;unsigned int gtlb_index; - gtlb_index = vcpu->arch.gpr[ra]; + gtlb_index =kvmppc_get_gpr (vcpu, ra);if (gtlb_index > KVM44x_GUEST_TLB_SIZE) {printk ("%s: index %d\n" , __func__, gtlb_index);kvmppc_dump_vcpu (vcpu);
@@ -455,15 +455,15 @@ int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 rs, u8 ws)switch (ws) {case PPC44x_TLB_PAGEID: tlbe->tid =get_mmucr_stid (vcpu); - tlbe->word0 = vcpu->arch.gpr[rs]; + tlbe->word0 =kvmppc_get_gpr (vcpu, rs);break ;case PPC44x_TLB_XLAT: - tlbe->word1 = vcpu->arch.gpr[rs]; + tlbe->word1 =kvmppc_get_gpr (vcpu, rs);break ;case PPC44x_TLB_ATTRIB: - tlbe->word2 = vcpu->arch.gpr[rs]; + tlbe->word2 =kvmppc_get_gpr (vcpu, rs);break ;default :
@@ -500,9 +500,9 @@ int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, u8 rc)unsigned int as =get_mmucr_sts (vcpu);unsigned int pid =get_mmucr_stid (vcpu); - ea = vcpu->arch.gpr[rb]; + ea =kvmppc_get_gpr (vcpu, rb);if (ra) - ea += vcpu->arch.gpr[ra]; + ea +=kvmppc_get_gpr (vcpu, ra); gtlb_index =kvmppc_44x_tlb_index (vcpu, ea, pid, as);if (rc) {
@@ -511,7 +511,7 @@ int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, u8 rc)else vcpu->arch.cr |=0x20000000 ; } - vcpu->arch.gpr[rt] = gtlb_index; +kvmppc_set_gpr (vcpu, rt, gtlb_index);kvmppc_set_exit_type (vcpu,EMULATED_TLBSX_EXITS );return EMULATE_DONE ;
arch/powerpc/kvm/book3s.c +4 -4
@@ -658,7 +658,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, }case BOOK3S_INTERRUPT_SYSCALL :#ifdef EXIT_DEBUG -printk (KERN_INFO "Syscall Nr %d\n" , (int )vcpu->arch.gpr[0 ]); +printk (KERN_INFO "Syscall Nr %d\n" , (int )kvmppc_get_gpr (vcpu,0 ));#endif vcpu->stat.syscall_exits++;kvmppc_book3s_queue_irqprio (vcpu, exit_nr);
@@ -734,7 +734,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) regs->sprg7 = vcpu->arch.sprg6;for (i =0 ; i <ARRAY_SIZE (regs->gpr); i++) - regs->gpr[i] = vcpu->arch.gpr[i]; + regs->gpr[i] =kvmppc_get_gpr (vcpu, i);return 0 ; }
@@ -759,8 +759,8 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) vcpu->arch.sprg6 = regs->sprg5; vcpu->arch.sprg7 = regs->sprg6; -for (i =0 ; i <ARRAY_SIZE (vcpu->arch.gpr); i++) - vcpu->arch.gpr[i] = regs->gpr[i]; +for (i =0 ; i <ARRAY_SIZE (regs->gpr); i++) +kvmppc_set_gpr (vcpu, i, regs->gpr[i]);return 0 ; }
arch/powerpc/kvm/book3s_64_emulate.c +40 -37
205 lines not on this page · raw message
arch/powerpc/kvm/booke.c +8 -8
@@ -69,10 +69,10 @@ void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu)for (i =0 ; i <32 ; i +=4 ) {printk ("gpr%02d: %08lx %08lx %08lx %08lx\n" , i, - vcpu->arch.gpr[i], - vcpu->arch.gpr[i+1 ], - vcpu->arch.gpr[i+2 ], - vcpu->arch.gpr[i+3 ]); +kvmppc_get_gpr (vcpu, i), +kvmppc_get_gpr (vcpu, i+1 ), +kvmppc_get_gpr (vcpu, i+2 ), +kvmppc_get_gpr (vcpu, i+3 )); } }
@@ -431,7 +431,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) { vcpu->arch.pc =0 ; vcpu->arch.msr =0 ; - vcpu->arch.gpr[1 ] = (16 <<20 ) -8 ;/* -8 for the callee-save LR slot */ +kvmppc_set_gpr (vcpu,1 , (16 <<20 ) -8 );/* -8 for the callee-save LR slot */ vcpu->arch.shadow_pid =1 ;
@@ -466,7 +466,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) regs->sprg7 = vcpu->arch.sprg6;for (i =0 ; i <ARRAY_SIZE (regs->gpr); i++) - regs->gpr[i] = vcpu->arch.gpr[i]; + regs->gpr[i] =kvmppc_get_gpr (vcpu, i);return 0 ; }
@@ -491,8 +491,8 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) vcpu->arch.sprg6 = regs->sprg5; vcpu->arch.sprg7 = regs->sprg6; -for (i =0 ; i <ARRAY_SIZE (vcpu->arch.gpr); i++) - vcpu->arch.gpr[i] = regs->gpr[i]; +for (i =0 ; i <ARRAY_SIZE (regs->gpr); i++) +kvmppc_set_gpr (vcpu, i, regs->gpr[i]);return 0 ; }
arch/powerpc/kvm/booke_emulate.c +54 -53
225 lines not on this page · raw message
arch/powerpc/kvm/e500_emulate.c +52 -43
169 lines not on this page · raw message
arch/powerpc/kvm/e500_tlb.c +2 -2
@@ -417,7 +417,7 @@ int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb)int esel, tlbsel;gva_t ea; - ea = ((ra) ? vcpu->arch.gpr[ra] :0 ) + vcpu->arch.gpr[rb]; + ea = ((ra) ?kvmppc_get_gpr (vcpu, ra) :0 ) +kvmppc_get_gpr (vcpu, rb); ia = (ea >>2 ) &0x1 ;
@@ -470,7 +470,7 @@ int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb)struct tlbe *gtlbe =NULL ;gva_t ea; - ea = vcpu->arch.gpr[rb]; + ea =kvmppc_get_gpr (vcpu, rb);for (tlbsel =0 ; tlbsel <2 ; tlbsel++) { esel =kvmppc_e500_tlb_index (vcpu_e500, ea, tlbsel, pid, as);
arch/powerpc/kvm/emulate.c +57 -49
269 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +11 -10
@@ -269,34 +269,35 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,static void kvmppc_complete_dcr_load (struct kvm_vcpu *vcpu,struct kvm_run *run) { -ulong *gpr = &vcpu->arch.gpr[vcpu->arch.io_gpr]; - *gpr = run->dcr.data; +kvmppc_set_gpr (vcpu, vcpu->arch.io_gpr, run->dcr.data); }static void kvmppc_complete_mmio_load (struct kvm_vcpu *vcpu,struct kvm_run *run) { -ulong *gpr = &vcpu->arch.gpr[vcpu->arch.io_gpr]; +ulong gpr; -if (run->mmio.len >sizeof (*gpr)) { +if (run->mmio.len >sizeof (gpr)) {printk (KERN_ERR "bad MMIO length: %d\n" , run->mmio.len);return ; }if (vcpu->arch.mmio_is_bigendian) {switch (run->mmio.len) { -case 4 : *gpr = *(u32 *)run->mmio.data;break ; -case 2 : *gpr = *(u16 *)run->mmio.data;break ; -case 1 : *gpr = *(u8 *)run->mmio.data;break ; +case 4 : gpr = *(u32 *)run->mmio.data;break ; +case 2 : gpr = *(u16 *)run->mmio.data;break ; +case 1 : gpr = *(u8 *)run->mmio.data;break ; } }else {/* Convert BE data from userland back to LE. */ switch (run->mmio.len) { -case 4 : *gpr =ld_le32 ((u32 *)run->mmio.data);break ; -case 2 : *gpr =ld_le16 ((u16 *)run->mmio.data);break ; -case 1 : *gpr = *(u8 *)run->mmio.data;break ; +case 4 : gpr =ld_le32 ((u32 *)run->mmio.data);break ; +case 2 : gpr =ld_le16 ((u16 *)run->mmio.data);break ; +case 1 : gpr = *(u8 *)run->mmio.data;break ; } } + +kvmppc_set_gpr (vcpu, vcpu->arch.io_gpr, gpr); } int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
Signature · 1 line
1.6.0.2
PATCH 3/9 KVM: PPC: Use PACA backed shadow vcpu
In reply to a message not in the archiveWe're being horribly racy right now. All the entry and exit code hijacks random fields from the PACA that could easily be used by different code in case we get interrupted, for example by a #MC or even page fault.
After discussing this with Ben, we figured it's best to reserve some more space in the PACA and just shove off some vcpu state to there.
That way we can drastically improve the readability of the code, make it less racy and less complex.
--- arch/powerpc/include/asm/kvm_book3s.h | 2 + arch/powerpc/include/asm/kvm_book3s_64_asm.h | 19 +++ arch/powerpc/include/asm/kvm_host.h | 5 +- arch/powerpc/include/asm/kvm_ppc.h | 20 ++- arch/powerpc/include/asm/paca.h | 5 + arch/powerpc/kernel/asm-offsets.c | 35 ++++- arch/powerpc/kvm/book3s.c | 4 + arch/powerpc/kvm/book3s_64_interrupts.S | 216 +++++++++----------------- arch/powerpc/kvm/book3s_64_rmhandlers.S | 32 +--- arch/powerpc/kvm/book3s_64_slb.S | 150 +++++++++++------- 10 files changed, 250 insertions(+), 238 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +2 -0
@@ -23,6 +23,7 @@#include <linux/types.h> #include <linux/kvm_host.h> #include <asm/kvm_ppc.h> +#include <asm/kvm_book3s_64_asm.h> struct kvmppc_slb {u64 esid;
@@ -69,6 +70,7 @@ struct kvmppc_sid_map {struct kvmppc_vcpu_book3s {struct kvm_vcpu vcpu; +struct kvmppc_book3s_shadow_vcpu shadow_vcpu;struct kvmppc_sid_map sid_map[SID_MAP_NUM ];struct kvmppc_slb slb[64 ];struct {
arch/powerpc/include/asm/kvm_book3s_64_asm.h +19 -0
@@ -20,6 +20,8 @@#ifndef __ASM_KVM_BOOK3S_ASM_H__#define __ASM_KVM_BOOK3S_ASM_H__ +#ifdef __ASSEMBLY__ +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER #include <asm/kvm_asm.h>
@@ -55,4 +57,21 @@ kvmppc_resume_\intno:#endif /* CONFIG_KVM_BOOK3S_64_HANDLER */ +#else /*__ASSEMBLY__ */ + +struct kvmppc_book3s_shadow_vcpu { +ulong gpr[14 ]; +u32 cr; +u32 xer; +ulong host_r1; +ulong host_r2; +ulong handler; +ulong scratch0; +ulong scratch1; +ulong vmhandler; +ulong rmhandler; +}; + +#endif /*__ASSEMBLY__ */ +#endif /* __ASM_KVM_BOOK3S_ASM_H__ */
arch/powerpc/include/asm/kvm_host.h +4 -1
@@ -175,10 +175,13 @@ struct kvm_vcpu_arch {ulong gpr[32 ];ulong pc; -u32 cr;ulong ctr;ulong lr; + +#ifdef CONFIG_BOOKE ulong xer; +u32 cr; +#endif ulong msr;#ifdef CONFIG_PPC64
arch/powerpc/include/asm/kvm_ppc.h +14 -6
@@ -98,34 +98,42 @@ extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu);#ifdef CONFIG_PPC_BOOK3S +/* We assume we're always acting on the current vcpu */ +static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val) { - vcpu->arch.gpr[num] = val; +if ( num <14 ) +get_paca ()->shadow_vcpu.gpr[num] = val; +else + vcpu->arch.gpr[num] = val; }static inline ulong kvmppc_get_gpr (struct kvm_vcpu *vcpu,int num) { -return vcpu->arch.gpr[num]; +if ( num <14 ) +return get_paca ()->shadow_vcpu.gpr[num]; +else +return vcpu->arch.gpr[num]; }static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val) { - vcpu->arch.cr = val; +get_paca ()->shadow_vcpu.cr = val; }static inline u32 kvmppc_get_cr (struct kvm_vcpu *vcpu) { -return vcpu->arch.cr; +return get_paca ()->shadow_vcpu.cr; }static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,u32 val) { - vcpu->arch.xer = val; +get_paca ()->shadow_vcpu.xer = val; }static inline u32 kvmppc_get_xer (struct kvm_vcpu *vcpu) { -return vcpu->arch.xer; +return get_paca ()->shadow_vcpu.xer; }#else
arch/powerpc/include/asm/paca.h +5 -0
@@ -19,6 +19,9 @@#include <asm/mmu.h> #include <asm/page.h> #include <asm/exception-64e.h> +#ifdef CONFIG_KVM_BOOK3S_64_HANDLER +#include <asm/kvm_book3s_64_asm.h> +#endif registerstruct paca_struct *local_paca asm("r13" );
@@ -135,6 +138,8 @@ struct paca_struct {u64 esid; u64 vsid; } kvm_slb[64 ];/* guest SLB */ +/* We use this to store guest state in */ +struct kvmppc_book3s_shadow_vcpu shadow_vcpu;u8 kvm_slb_max;/* highest used guest slb entry */ u8 kvm_in_guest;/* are we inside the guest? */ #endif
arch/powerpc/kernel/asm-offsets.c +31 -4
@@ -194,6 +194,32 @@ int main(void)DEFINE (PACA_KVM_IN_GUEST , offsetof(struct paca_struct , kvm_in_guest));DEFINE (PACA_KVM_SLB , offsetof(struct paca_struct , kvm_slb));DEFINE (PACA_KVM_SLB_MAX , offsetof(struct paca_struct , kvm_slb_max)); + DEFINE(PACA_KVM_CR, offsetof(struct paca_struct, shadow_vcpu.cr)); + DEFINE(PACA_KVM_XER, offsetof(struct paca_struct, shadow_vcpu.xer)); + DEFINE(PACA_KVM_R0, offsetof(struct paca_struct, shadow_vcpu.gpr[0])); + DEFINE(PACA_KVM_R1, offsetof(struct paca_struct, shadow_vcpu.gpr[1])); + DEFINE(PACA_KVM_R2, offsetof(struct paca_struct, shadow_vcpu.gpr[2])); + DEFINE(PACA_KVM_R3, offsetof(struct paca_struct, shadow_vcpu.gpr[3])); + DEFINE(PACA_KVM_R4, offsetof(struct paca_struct, shadow_vcpu.gpr[4])); + DEFINE(PACA_KVM_R5, offsetof(struct paca_struct, shadow_vcpu.gpr[5])); + DEFINE(PACA_KVM_R6, offsetof(struct paca_struct, shadow_vcpu.gpr[6])); + DEFINE(PACA_KVM_R7, offsetof(struct paca_struct, shadow_vcpu.gpr[7])); + DEFINE(PACA_KVM_R8, offsetof(struct paca_struct, shadow_vcpu.gpr[8])); + DEFINE(PACA_KVM_R9, offsetof(struct paca_struct, shadow_vcpu.gpr[9])); + DEFINE(PACA_KVM_R10, offsetof(struct paca_struct, shadow_vcpu.gpr[10])); + DEFINE(PACA_KVM_R11, offsetof(struct paca_struct, shadow_vcpu.gpr[11])); + DEFINE(PACA_KVM_R12, offsetof(struct paca_struct, shadow_vcpu.gpr[12])); + DEFINE(PACA_KVM_R13, offsetof(struct paca_struct, shadow_vcpu.gpr[13])); + DEFINE(PACA_KVM_HOST_R1, offsetof(struct paca_struct, shadow_vcpu.host_r1)); + DEFINE(PACA_KVM_HOST_R2, offsetof(struct paca_struct, shadow_vcpu.host_r2)); +DEFINE (PACA_KVM_VMHANDLER , offsetof(struct paca_struct , + shadow_vcpu.vmhandler)); +DEFINE (PACA_KVM_RMHANDLER , offsetof(struct paca_struct , + shadow_vcpu.rmhandler)); +DEFINE (PACA_KVM_SCRATCH0 , offsetof(struct paca_struct , + shadow_vcpu.scratch0)); +DEFINE (PACA_KVM_SCRATCH1 , offsetof(struct paca_struct , + shadow_vcpu.scratch1));#endif #endif /* CONFIG_PPC64 */
@@ -387,10 +413,7 @@ int main(void)#ifdef CONFIG_KVM DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack)); DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid)); - DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr)); DEFINE(VCPU_LR, offsetof(struct kvm_vcpu, arch.lr)); - DEFINE(VCPU_CR, offsetof(struct kvm_vcpu, arch.cr)); - DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); DEFINE(VCPU_CTR, offsetof(struct kvm_vcpu, arch.ctr)); DEFINE(VCPU_PC, offsetof(struct kvm_vcpu, arch.pc)); DEFINE(VCPU_MSR, offsetof(struct kvm_vcpu, arch.msr));
@@ -415,7 +438,11 @@ int main(void) DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, arch.trampoline_enter)); DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, arch.highmem_handler)); DEFINE(VCPU_HFLAGS, offsetof(struct kvm_vcpu, arch.hflags)); -#endif + DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr)); +#else + DEFINE(VCPU_CR, offsetof(struct kvm_vcpu, arch.cr)); + DEFINE(VCPU_XER, offsetof(struct kvm_vcpu, arch.xer)); +#endif /* CONFIG_PPC64 */ #endif #ifdef CONFIG_44xDEFINE (PGD_T_LOG2 ,PGD_T_LOG2 );
arch/powerpc/kvm/book3s.c +4 -0
@@ -66,12 +66,16 @@ void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) {memcpy (get_paca ()->kvm_slb,to_book3s (vcpu)->slb_shadow,sizeof (get_paca ()->kvm_slb)); +memcpy (&get_paca ()->shadow_vcpu, &to_book3s (vcpu)->shadow_vcpu, +sizeof (get_paca ()->shadow_vcpu));get_paca ()->kvm_slb_max =to_book3s (vcpu)->slb_shadow_max; }void kvmppc_core_vcpu_put (struct kvm_vcpu *vcpu) {memcpy (to_book3s (vcpu)->slb_shadow,get_paca ()->kvm_slb,sizeof (get_paca ()->kvm_slb)); +memcpy (&to_book3s (vcpu)->shadow_vcpu, &get_paca ()->shadow_vcpu, +sizeof (get_paca ()->shadow_vcpu));to_book3s (vcpu)->slb_shadow_max =get_paca ()->kvm_slb_max; }
arch/powerpc/kvm/book3s_64_interrupts.S +73 -143
301 lines not on this page · raw message
arch/powerpc/kvm/book3s_64_rmhandlers.S +8 -24
@@ -45,37 +45,21 @@ kvmppc_trampoline_\intno: * To distinguish, we check a magic byte in the PACA */ mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */ - std r12, (PACA_EXMC + EX_R12)(r13) + std r12, PACA_KVM_SCRATCH0(r13) mfcr r12 - stw r12, (PACA_EXMC + EX_CCR)(r13) + stw r12, PACA_KVM_SCRATCH1(r13) lbz r12, PACA_KVM_IN_GUEST(r13) cmpwi r12, 0 bne ..kvmppc_handler_hasmagic_\intno /* No KVM guest? Then jump back to the Linux handler! */ - lwz r12, (PACA_EXMC + EX_CCR)(r13) + lwz r12, PACA_KVM_SCRATCH1(r13) mtcr r12 - ld r12, (PACA_EXMC + EX_R12)(r13) + ld r12, PACA_KVM_SCRATCH0(r13) mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */ b kvmppc_resume_\intno /* Get back original handler */ /* Now we know we're handling a KVM guest */ ..kvmppc_handler_hasmagic_\intno: - /* Unset guest state */ - li r12, 0 - stb r12, PACA_KVM_IN_GUEST(r13) - - std r1, (PACA_EXMC+EX_R9)(r13) - std r10, (PACA_EXMC+EX_R10)(r13) - std r11, (PACA_EXMC+EX_R11)(r13) - std r2, (PACA_EXMC+EX_R13)(r13) - - mfsrr0 r10 - mfsrr1 r11 - - /* Restore R1/R2 so we can handle faults */ - ld r1, PACAR1(r13) - ld r2, (PACA_EXMC+EX_SRR0)(r13) - /* Let's store which interrupt we're handling */ li r12, \intno
@@ -106,16 +90,16 @@ INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX * * Input Registers: * - * R6 = SRR0 - * R7 = SRR1 + * R5 = SRR0 + * R6 = SRR1 * LR = real-mode IP * */ .global kvmppc_handler_lowmem_trampoline kvmppc_handler_lowmem_trampoline: - mtsrr0 r6 - mtsrr1 r7 + mtsrr0 r5 + mtsrr1 r6 blr kvmppc_handler_lowmem_trampoline_end:
arch/powerpc/kvm/book3s_64_slb.S +90 -60
198 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 4/9 KVM: PPC: Implement 'skip instruction' mode
In reply to a message not in the archiveTo fetch the last instruction we were interrupted on, we enable DR in early exit code, where we are still in a very transitional phase between guest and host state.
Most of the time this seemed to work, but another CPU can easily flush our TLB and HTAB which makes us go in the Linux page fault handler which totally breaks because we still use the guest's SLB entries.
To work around that, let's introduce a second KVM guest mode that defines that whenever we get a trap, we don't call the Linux handler or go into the KVM exit code, but just jump over the faulting instruction.
That way a potentially bad lwz doesn't trigger any faults and we can later on interpret the invalid instruction we fetched as "fetch didn't work".
--- arch/powerpc/include/asm/kvm_asm.h | 6 ++++ arch/powerpc/kvm/book3s_64_rmhandlers.S | 39 ++++++++++++++++++++++++++++++- arch/powerpc/kvm/book3s_64_slb.S | 16 ++++++++---- arch/powerpc/kvm/emulate.c | 4 +++ 4 files changed, 59 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/kvm_asm.h +6 -0
@@ -97,4 +97,10 @@#define RESUME_HOST RESUME_FLAG_HOST#define RESUME_HOST_NV (RESUME_FLAG_HOST|RESUME_FLAG_NV) +#define KVM_GUEST_MODE_NONE 0 +#define KVM_GUEST_MODE_GUEST 1 +#define KVM_GUEST_MODE_SKIP 2 + +#define KVM_INST_FETCH_FAILED -1 +#endif /* __POWERPC_KVM_ASM_H__ */
arch/powerpc/kvm/book3s_64_rmhandlers.S +38 -1
@@ -49,7 +49,7 @@ kvmppc_trampoline_\intno: mfcr r12 stw r12, PACA_KVM_SCRATCH1(r13) lbz r12, PACA_KVM_IN_GUEST(r13) - cmpwi r12, 0 + cmpwi r12, KVM_GUEST_MODE_NONE bne ..kvmppc_handler_hasmagic_\intno /* No KVM guest? Then jump back to the Linux handler! */ lwz r12, PACA_KVM_SCRATCH1(r13)
@@ -60,6 +60,11 @@ kvmppc_trampoline_\intno: /* Now we know we're handling a KVM guest */ ..kvmppc_handler_hasmagic_\intno: + + /* Should we just skip the faulting instruction? */ + cmpwi r12, KVM_GUEST_MODE_SKIP + beq kvmppc_handler_skip_ins + /* Let's store which interrupt we're handling */ li r12, \intno
@@ -86,6 +91,38 @@ INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX /* + * Bring us back to the faulting code, but skip the + * faulting instruction. + * + * This is a generic exit path from the interrupt + * trampolines above. + * + * Input Registers: + * + * R12 = free + * R13 = PACA + * PACA.KVM.SCRATCH0 = guest R12 + * PACA.KVM.SCRATCH1 = guest CR + * SPRG_SCRATCH0 = guest R13 + * + */ +kvmppc_handler_skip_ins: + + /* Patch the IP to the next instruction */ + mfsrr0 r12 + addi r12, r12, 4 + mtsrr0 r12 + + /* Clean up all state */ + lwz r12, PACA_KVM_SCRATCH1(r13) + mtcr r12 + ld r12, PACA_KVM_SCRATCH0(r13) + mfspr r13, SPRN_SPRG_SCRATCH0 + + /* And get back into the code */ + RFI + +/* * This trampoline brings us back to a real mode handler * * Input Registers:
arch/powerpc/kvm/book3s_64_slb.S +11 -5
@@ -212,10 +212,6 @@ kvmppc_handler_trampoline_exit: mfdar r5 mfdsisr r6 - /* Unset guest state */ - li r9, 0 - stb r9, PACA_KVM_IN_GUEST(r13) - /* * In order for us to easily get the last instruction, * we got the #vmexit at, we exploit the fact that the
@@ -233,18 +229,28 @@ kvmppc_handler_trampoline_exit: ld_last_inst: /* Save off the guest instruction we're at */ + + /* Set guest mode to 'jump over instruction' so if lwz faults + * we'll just continue at the next IP. */ + li r9, KVM_GUEST_MODE_SKIP + stb r9, PACA_KVM_IN_GUEST(r13) + /* 1) enable paging for data */ mfmsr r9 ori r11, r9, MSR_DR /* Enable paging for data */ mtmsr r11 /* 2) fetch the instruction */ - /* XXX implement PACA_KVM_IN_GUEST=2 path to safely jump over this */ + li r0, KVM_INST_FETCH_FAILED /* In case lwz faults */ lwz r0, 0(r3) /* 3) disable paging again */ mtmsr r9 no_ld_last_inst: + /* Unset guest mode */ + li r9, KVM_GUEST_MODE_NONE + stb r9, PACA_KVM_IN_GUEST(r13) + /* Restore bolted entries from the shadow and fix it along the way */ /* We don't store anything in entry 0, so we don't need to take care of it */
arch/powerpc/kvm/emulate.c +4 -0
@@ -143,6 +143,10 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)pr_debug (KERN_INFO "Emulating opcode %d / %d\n" ,get_op (inst),get_xop (inst)); +/* Try again next time */ +if (inst ==KVM_INST_FETCH_FAILED ) +return EMULATE_DONE ; +switch (get_op (inst)) {case OP_TRAP :#ifdef CONFIG_PPC64
Signature · 1 line
1.6.0.2
PATCH 5/9 KVM: PPC: Get rid of unnecessary RFI
In reply to a message not in the archiveUsing an RFI in IR=1 is dangerous. We need to set two SRRs and then do an RFI without getting interrupted at all, because every interrupt could potentially overwrite the SRR values.
Fortunately, we don't need to RFI in at least this particular case of the code, so we can just replace it with an mtmsr and b.
--- arch/powerpc/kvm/book3s_64_interrupts.S | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)
arch/powerpc/kvm/book3s_64_interrupts.S +11 -11
@@ -221,15 +221,8 @@ no_dcbz32_off: mflr r5 std r5, VCPU_LR(r7) - /* XXX convert to safe function call */ - /* Restore host msr -> SRR1 */ ld r6, VCPU_HOST_MSR(r7) - mtsrr1 r6 - - /* Restore host IP -> SRR0 */ - ld r5, VCPU_HOST_RETIP(r7) - mtsrr0 r5 /* * For some interrupts, we need to call the real Linux
@@ -246,8 +239,9 @@ no_dcbz32_off: cmpwi r12, BOOK3S_INTERRUPT_DECREMENTER beq call_linux_handler - /* Back to Interruptable Mode! (goto kvm_return_point) */ - RFI + /* Back to EE=1 */ + mtmsr r6 + b kvm_return_point call_linux_handler:
@@ -260,10 +254,16 @@ call_linux_handler: * interrupt handler! * * R3 still contains the exit code, - * R6 VCPU_HOST_RETIP and - * R7 VCPU_HOST_MSR + * R5 VCPU_HOST_RETIP and + * R6 VCPU_HOST_MSR */ + /* Restore host IP -> SRR0 */ + ld r5, VCPU_HOST_RETIP(r7) + + /* XXX Better move to a safe function? + * What if we get an HTAB flush in between mtsrr0 and mtsrr1? */ + mtlr r12 ld r4, VCPU_TRAMPOLINE_LOWMEM(r7)
Signature · 1 line
1.6.0.2
PATCH 8/9 KVM: PPC: Fix HID5 setting code
In reply to a message not in the archiveThe code to unset HID5.dcbz32 is broken.
This patch makes it do the right rotate magic.
--- arch/powerpc/kvm/book3s_64_interrupts.S | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/powerpc/kvm/book3s_64_interrupts.S +2 -1
@@ -177,8 +177,9 @@ kvmppc_handler_highmem: rldicl. r5, r5, 0, 63 /* CR = ((r5 & 1) == 0) */ beq no_dcbz32_off + li r4, 0 mfspr r5,SPRN_HID5 - rldimi r5,r5,6,56 + rldimi r5,r4,6,56 mtspr SPRN_HID5,r5 no_dcbz32_off:
Signature · 1 line
1.6.0.2
PATCH 9/9 KVM: PPC: Pass program interrupt flags to the guest
In reply to a message not in the archiveWhen we need to reinject a program interrupt into the guest, we also need to reinject the corresponding flags into the guest.
--- arch/powerpc/kvm/book3s.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s.c +5 -2
@@ -633,6 +633,9 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,case BOOK3S_INTERRUPT_PROGRAM : {enum emulation_result er; +ulong flags; + + flags = (vcpu->arch.shadow_msr &0x1f0000ull );if (vcpu->arch.msr &MSR_PR ) {#ifdef EXIT_DEBUG
@@ -640,7 +643,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,#endif if ((vcpu->arch.last_inst &0xff0007ff ) != (INS_DCBZ &0xfffffff7 )) { -kvmppc_book3s_queue_irqprio (vcpu, exit_nr); +kvmppc_core_queue_program (vcpu, flags); r =RESUME_GUEST ;break ; }
@@ -655,7 +658,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,case EMULATE_FAIL :printk (KERN_CRIT "%s: emulation at %lx failed (%08x)\n" , __func__, vcpu->arch.pc, vcpu->arch.last_inst); -kvmppc_book3s_queue_irqprio (vcpu, exit_nr); +kvmppc_core_queue_program (vcpu, flags); r =RESUME_GUEST ;break ;default :
Signature · 1 line
1.6.0.2
PATCH 2/9 KVM: PPC: Add helpers for CR, XER
In reply to Alexander GrafWe now have helpers for the GPRs, so let's also add some for CR and XER.
Having them in the PACA simplifies code a lot, as we don't need to care about where to store CC or not to overflow any integers.
--- arch/powerpc/include/asm/kvm_ppc.h | 40 ++++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/44x_tlb.c | 6 +++- arch/powerpc/kvm/book3s.c | 8 +++--- arch/powerpc/kvm/booke.c | 8 +++--- 4 files changed, 52 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +40 -0
@@ -108,6 +108,26 @@ static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num) return vcpu->arch.gpr[num]; } +static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val) +{ + vcpu->arch.cr = val; +} + +static inline u32 kvmppc_get_cr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.cr; +} + +static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,u32 val) +{ + vcpu->arch.xer = val; +} + +static inline u32 kvmppc_get_xer (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.xer; +} +#else static inline void kvmppc_set_gpr (struct kvm_vcpu *vcpu,int num,ulong val)
@@ -120,6 +140,26 @@ static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)return vcpu->arch.gpr[num]; } +static inline void kvmppc_set_cr (struct kvm_vcpu *vcpu,u32 val) +{ + vcpu->arch.cr = val; +} + +static inline u32 kvmppc_get_cr (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.cr; +} + +static inline void kvmppc_set_xer (struct kvm_vcpu *vcpu,u32 val) +{ + vcpu->arch.xer = val; +} + +static inline u32 kvmppc_get_xer (struct kvm_vcpu *vcpu) +{ +return vcpu->arch.xer; +} +#endif #endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kvm/44x_tlb.c +4 -2
@@ -506,10 +506,12 @@ int kvmppc_44x_emul_tlbsx(struct kvm_vcpu *vcpu, u8 rt, u8 ra, u8 rb, u8 rc) gtlb_index =kvmppc_44x_tlb_index (vcpu, ea, pid, as);if (rc) { +u32 cr =kvmppc_get_cr (vcpu); +if (gtlb_index <0 ) - vcpu->arch.cr &= ~0x20000000 ; +kvmppc_set_cr (vcpu, cr & ~0x20000000 );else - vcpu->arch.cr |=0x20000000 ; +kvmppc_set_cr (vcpu, cr |0x20000000 ); }kvmppc_set_gpr (vcpu, rt, gtlb_index);
arch/powerpc/kvm/book3s.c +4 -4
@@ -717,10 +717,10 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)int i; regs->pc = vcpu->arch.pc; - regs->cr = vcpu->arch.cr; + regs->cr =kvmppc_get_cr (vcpu); regs->ctr = vcpu->arch.ctr; regs->lr = vcpu->arch.lr; - regs->xer = vcpu->arch.xer; + regs->xer =kvmppc_get_xer (vcpu); regs->msr = vcpu->arch.msr; regs->srr0 = vcpu->arch.srr0; regs->srr1 = vcpu->arch.srr1;
@@ -744,10 +744,10 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)int i; vcpu->arch.pc = regs->pc; - vcpu->arch.cr = regs->cr; +kvmppc_set_cr (vcpu, regs->cr); vcpu->arch.ctr = regs->ctr; vcpu->arch.lr = regs->lr; - vcpu->arch.xer = regs->xer; +kvmppc_set_xer (vcpu, regs->xer);kvmppc_set_msr (vcpu, regs->msr); vcpu->arch.srr0 = regs->srr0; vcpu->arch.srr1 = regs->srr1;
arch/powerpc/kvm/booke.c +4 -4
@@ -449,10 +449,10 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)int i; regs->pc = vcpu->arch.pc; - regs->cr = vcpu->arch.cr; + regs->cr =kvmppc_get_cr (vcpu); regs->ctr = vcpu->arch.ctr; regs->lr = vcpu->arch.lr; - regs->xer = vcpu->arch.xer; + regs->xer =kvmppc_get_xer (vcpu); regs->msr = vcpu->arch.msr; regs->srr0 = vcpu->arch.srr0; regs->srr1 = vcpu->arch.srr1;
@@ -476,10 +476,10 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)int i; vcpu->arch.pc = regs->pc; - vcpu->arch.cr = regs->cr; +kvmppc_set_cr (vcpu, regs->cr); vcpu->arch.ctr = regs->ctr; vcpu->arch.lr = regs->lr; - vcpu->arch.xer = regs->xer; +kvmppc_set_xer (vcpu, regs->xer);kvmppc_set_msr (vcpu, regs->msr); vcpu->arch.srr0 = regs->srr0; vcpu->arch.srr1 = regs->srr1;
Signature · 1 line
1.6.0.2
PATCH 6/9 KVM: PPC: Call SLB patching code in interrupt safe manner
In reply to Alexander GrafCurrently we're racy when doing the transition from IR=1 to IR=0, from the module memory entry code to the real mode SLB switching code.
To work around that I took a look at the RTAS entry code which is faced with a similar problem and did the same thing:
A small helper in linear mapped memory that does mtmsr with IR=0 and then RFIs info the actual handler.
Thanks to that trick we can safely take page faults in the entry code and only need to be really wary of what to do as of the SLB switching part.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/include/asm/kvm_book3s_64_asm.h | 1 - arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 3 +-- arch/powerpc/kvm/book3s.c | 1 + arch/powerpc/kvm/book3s_64_exports.c | 1 + arch/powerpc/kvm/book3s_64_interrupts.S | 25 +++++++------------------ arch/powerpc/kvm/book3s_64_rmhandlers.S | 18 ++++++++++++++++++ arch/powerpc/kvm/book3s_64_slb.S | 4 ++++ 9 files changed, 34 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -121,6 +121,7 @@ extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,extern u32 kvmppc_trampoline_lowmem;extern u32 kvmppc_trampoline_enter; +extern void kvmppc_rmcall (ulong srr0,ulong srr1);static inline struct kvmppc_vcpu_book3s *to_book3s (struct kvm_vcpu *vcpu) {
arch/powerpc/include/asm/kvm_book3s_64_asm.h +0 -1
@@ -69,7 +69,6 @@ struct kvmppc_book3s_shadow_vcpu {ulong scratch0;ulong scratch1; ulong vmhandler; - ulong rmhandler; };#endif /*__ASSEMBLY__ */
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -167,6 +167,7 @@ struct kvm_vcpu_arch {ulong trampoline_lowmem;ulong trampoline_enter;ulong highmem_handler; +ulong rmcall;ulong host_paca_phys;struct kvmppc_mmu mmu;#endif
arch/powerpc/kernel/asm-offsets.c +1 -2
@@ -214,8 +214,6 @@ int main(void) DEFINE(PACA_KVM_HOST_R2, offsetof(struct paca_struct, shadow_vcpu.host_r2));DEFINE (PACA_KVM_VMHANDLER , offsetof(struct paca_struct , shadow_vcpu.vmhandler)); -DEFINE (PACA_KVM_RMHANDLER , offsetof(struct paca_struct , - shadow_vcpu.rmhandler));DEFINE (PACA_KVM_SCRATCH0 , offsetof(struct paca_struct , shadow_vcpu.scratch0)); DEFINE(PACA_KVM_SCRATCH1, offsetof(struct paca_struct,
@@ -437,6 +435,7 @@ int main(void) DEFINE(VCPU_TRAMPOLINE_LOWMEM, offsetof(struct kvm_vcpu, arch.trampoline_lowmem)); DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, arch.trampoline_enter)); DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, arch.highmem_handler)); + DEFINE(VCPU_RMCALL, offsetof(struct kvm_vcpu, arch.rmcall)); DEFINE(VCPU_HFLAGS, offsetof(struct kvm_vcpu, arch.hflags)); DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));#else
arch/powerpc/kvm/book3s.c +1 -0
@@ -919,6 +919,7 @@ struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id) vcpu->arch.trampoline_lowmem = kvmppc_trampoline_lowmem; vcpu->arch.trampoline_enter = kvmppc_trampoline_enter; vcpu->arch.highmem_handler = (ulong )kvmppc_handler_highmem; + vcpu->arch.rmcall = *(ulong *)kvmppc_rmcall; vcpu->arch.shadow_msr =MSR_USER64 ;
arch/powerpc/kvm/book3s_64_exports.c +1 -0
@@ -22,3 +22,4 @@EXPORT_SYMBOL_GPL (kvmppc_trampoline_enter);EXPORT_SYMBOL_GPL (kvmppc_trampoline_lowmem); +EXPORT_SYMBOL_GPL (kvmppc_rmcall);
arch/powerpc/kvm/book3s_64_interrupts.S +7 -18
@@ -95,17 +95,14 @@ kvm_start_entry: ld r3, VCPU_HIGHMEM_HANDLER(r4) std r3, PACA_KVM_VMHANDLER(r13) - ld r3, VCPU_TRAMPOLINE_ENTER(r4) - std r3, PACA_KVM_RMHANDLER(r13) - kvm_start_lightweight: ld r9, VCPU_PC(r4) /* r9 = vcpu->arch.pc */ ld r10, VCPU_SHADOW_MSR(r4) /* r10 = vcpu->arch.shadow_msr */ /* Load some guest state in the respective registers */ - ld r3, VCPU_CTR(r4) /* r3 = vcpu->arch.ctr */ - mtctr r3 /* CTR = r3 */ + ld r5, VCPU_CTR(r4) /* r5 = vcpu->arch.ctr */ + /* will be swapped in by rmcall */ ld r3, VCPU_LR(r4) /* r3 = vcpu->arch.lr */ mtlr r3 /* LR = r3 */
@@ -131,22 +128,14 @@ kvm_start_lightweight: no_dcbz32_on: - /* This sets the Magic value for the trampoline */ - - /* XXX this needs to move into a safe function, so we can - be sure we don't get any interrupts */ - - li r11, 1 - stb r11, PACA_KVM_IN_GUEST(r13) - - ld r3, PACA_KVM_RMHANDLER(r13) - mtsrr0 r3 + ld r6, VCPU_RMCALL(r4) + mtctr r6 - LOAD_REG_IMMEDIATE(r3, MSR_KERNEL & ~(MSR_IR | MSR_DR)) - mtsrr1 r3 + ld r3, VCPU_TRAMPOLINE_ENTER(r4) + LOAD_REG_IMMEDIATE(r4, MSR_KERNEL & ~(MSR_IR | MSR_DR)) /* Jump to SLB patching handlder and into our guest */ - RFI + bctr /* * This is the handler in module memory. It gets jumped at from the
arch/powerpc/kvm/book3s_64_rmhandlers.S +18 -0
@@ -140,6 +140,24 @@ kvmppc_handler_lowmem_trampoline: blr kvmppc_handler_lowmem_trampoline_end: +/* + * Call a function in real mode + * + * Input Registers: + * + * R3 = function + * R4 = MSR + * R5 = CTR + * + */ +_GLOBAL(kvmppc_rmcall) + mtmsr r4 /* Disable relocation, so mtsrr + doesn't get interrupted */ + mtctr r5 + mtsrr0 r3 + mtsrr1 r4 + RFI + .global kvmppc_trampoline_lowmem kvmppc_trampoline_lowmem: .long kvmppc_handler_lowmem_trampoline - _stext
arch/powerpc/kvm/book3s_64_slb.S +4 -0
@@ -63,6 +63,10 @@ kvmppc_handler_trampoline_enter: mtsrr0 r9 mtsrr1 r10 + /* Activate guest mode, so faults get handled by KVM */ + li r11, KVM_GUEST_MODE_GUEST + stb r11, PACA_KVM_IN_GUEST(r13) + /* Remove LPAR shadow entries */ #if SLB_NUM_BOLTED = 3
Signature · 1 line
1.6.0.2
PATCH 7/9 KVM: PPC: Emulate trap SRR1 flags properly
In reply to Alexander GrafBook3S needs some flags in SRR1 to get to know details about an interrupt.
One such example is the trap instruction. It tells the guest kernel that a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making WARN_ON behave like WARN_ON.
--- arch/powerpc/include/asm/kvm_book3s.h | 1 + arch/powerpc/include/asm/kvm_ppc.h | 2 +- arch/powerpc/include/asm/reg.h | 4 ++++ arch/powerpc/kvm/book3s.c | 7 +++++-- arch/powerpc/kvm/booke.c | 3 ++- arch/powerpc/kvm/emulate.c | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +1 -0
@@ -91,6 +91,7 @@ struct kvmppc_vcpu_book3s {u64 vsid_next;u64 vsid_max;int context_id; +ulong prog_flags;/* flags to inject when giving a 700 trap */ };#define CONTEXT_HOST 0
arch/powerpc/include/asm/kvm_ppc.h +1 -1
@@ -80,7 +80,7 @@ extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);extern void kvmppc_core_deliver_interrupts (struct kvm_vcpu *vcpu);extern int kvmppc_core_pending_dec (struct kvm_vcpu *vcpu); -extern void kvmppc_core_queue_program (struct kvm_vcpu *vcpu); +extern void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags);extern void kvmppc_core_queue_dec (struct kvm_vcpu *vcpu);extern void kvmppc_core_dequeue_dec (struct kvm_vcpu *vcpu); extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
arch/powerpc/include/asm/reg.h +4 -0
@@ -426,6 +426,10 @@#define SRR1_WAKEMT 0x00280000/* mtctrl */ #define SRR1_WAKEDEC 0x00180000/* Decrementer interrupt */ #define SRR1_WAKETHERM 0x00100000/* Thermal management interrupt */ +#define SRR1_PROGFPE 0x00100000/* Floating Point Enabled */ +#define SRR1_PROGPRIV 0x00040000/* Privileged instruction */ +#define SRR1_PROGTRAP 0x00020000/* Trap */ +#define SRR1_PROGADDR 0x00010000/* SRR0 contains subsequent addr */ #define SPRN_HSRR0 0x13A/* Save/Restore Register 0 */ #define SPRN_HSRR1 0x13B/* Save/Restore Register 1 */
arch/powerpc/kvm/book3s.c +5 -2
@@ -168,8 +168,9 @@ void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec) } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { +to_book3s (vcpu)->prog_flags = flags;kvmppc_book3s_queue_irqprio (vcpu,BOOK3S_INTERRUPT_PROGRAM ); }
@@ -198,6 +199,7 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority) {int deliver =1 ;int vec =0 ; +ulong flags =0ULL ;switch (priority) {case BOOK3S_IRQPRIO_DECREMENTER :
@@ -231,6 +233,7 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)break ;case BOOK3S_IRQPRIO_PROGRAM : vec =BOOK3S_INTERRUPT_PROGRAM ; + flags =to_book3s (vcpu)->prog_flags;break ;case BOOK3S_IRQPRIO_VSX : vec =BOOK3S_INTERRUPT_VSX ;
@@ -261,7 +264,7 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)#endif if (deliver) -kvmppc_inject_interrupt (vcpu, vec,0ULL ); +kvmppc_inject_interrupt (vcpu, vec, flags);return deliver; }
arch/powerpc/kvm/booke.c +2 -1
@@ -82,8 +82,9 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,set_bit (priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { +/* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_PROGRAM ); }
arch/powerpc/kvm/emulate.c +1 -1
@@ -154,7 +154,7 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)#else vcpu->arch.esr |=ESR_PTR ;#endif -kvmppc_core_queue_program (vcpu); +kvmppc_core_queue_program (vcpu,SRR1_PROGTRAP ); advance =0 ;break ;
Signature · 1 line
1.6.0.2
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 6 lines · Alexander Graf
Book3S needs some flags in SRR1 to get to know details about an interrupt.
One such example is the trap instruction. It tells the guest kernel that a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making
WARN_ONbehave likeWARN_ON.
... "for Book S". It already works properly for Book E, thankyouverymuch. ;)
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0
arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 9 lines
arch/powerpc/kvm/booke.c +2
-1@@ -82,8 +82,9 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, set_bit(priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { + /* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); }
Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Anyways, since we can't test changes at the moment (Yu, can you?), I'd settle for a comment to the effect that Book E code *should* do this, but doesn't (rather than the comment above that says it's ok).
-Hollis
A message that is not in the archive (sent off-list or not yet received): fb412d761001081129q26d7fdcj9d1a26184127d002-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 30 lines · Hollis Blanchard
Quoted 6 lines · Alexander Graf
Book3S needs some flags in SRR1 to get to know details about an interrupt.
One such example is the trap instruction. It tells the guest kernel that a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making
WARN_ONbehave likeWARN_ON.... "for Book S". It already works properly for Book E, thankyouverymuch. ;)
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 9 lines
arch/powerpc/kvm/booke.c +2
-1@@ -82,8 +82,9 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,set_bit (priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { +/* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_PROGRAM ); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Quoted 3 lines
Anyways, since we can't test changes at the moment (Yu, can you?), I'd settle for a comment to the effect that Book E code *should* do this, but doesn't (rather than the comment above that says it's ok).
Hm, can't you just write up a patch that removes the comment I put in, does the ESR setting in the function and do an #ifdef in emulate.c?
That way we can incrementally improve things. This series is really about Book3S. Improving BookE should go in a different patch.
Alex--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1FB2DDB0-F72E-437C-BEC5-8E1AEE5FBCC7-l3A5Bk7waGM@public.gmane.org
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 33 lines · Alexander Graf
Quoted 30 lines · Hollis Blanchard
Quoted 6 lines · Alexander Graf
Book3S needs some flags in SRR1 to get to know details about an interrupt.
One such example is the trap instruction. It tells the guest kernel that a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making
WARN_ONbehave likeWARN_ON.... "for Book S". It already works properly for Book E, thankyouverymuch. ;)
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 9 lines
arch/powerpc/kvm/booke.c +2
-1@@ -82,8 +82,9 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, set_bit(priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { + /* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Quoted 7 lines
Quoted 3 lines
Anyways, since we can't test changes at the moment (Yu, can you?), I'd settle for a comment to the effect that Book E code *should* do this, but doesn't (rather than the comment above that says it's ok).
Hm, can't you just write up a patch that removes the comment I put in, does the ESR setting in the function and do an #ifdef in
emulate.c?That way we can incrementally improve things. This series is really about Book3S. Improving BookE should go in a different patch.
Yes, but I'd rather minimize the behavioral changes as long as we can't test it.
-Hollis
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 38 lines · Hollis Blanchard
Quoted 37 lines · Alexander Graf
Quoted 33 lines · Hollis Blanchard
Quoted 6 lines · Alexander Graf
Book3S needs some flags in SRR1 to get to know details about an interrupt.
One such example is the trap instruction. It tells the guest kernel that a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making
WARN_ONbehave likeWARN_ON.... "for Book S". It already works properly for Book E, thankyouverymuch. ;)
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 9 lines
arch/powerpc/kvm/booke.c +2
-1@@ -82,8 +82,9 @@ static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,set_bit (priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { +/* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_PROGRAM ); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Anyways, since we can't test changes at the moment (Yu, can you?), I'd settle for a comment to the effect that Book E code *should* do this, but doesn't (rather than the comment above that says it's ok).
Quoted 5 lines
Quoted 3 lines
Hm, can't you just write up a patch that removes the comment I put in, does the ESR setting in the function and do an #ifdef in
emulate.c?That way we can incrementally improve things. This series is really about Book3S. Improving BookE should go in a different patch.
Yes, but I'd rather minimize the behavioral changes as long as we can't test it.
Right. That's why the semantics of "flags" are Book3S specific right now and as such the comment is correct.
The behavioral change we need to do later is to take the ESR setting into queue_program, but that should wait until after someone has a board to test things on again ;-). The reminder that we need to do this is hereby archived in the mails :).
Alex
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 7 lines · Alexander Graf
Quoted 3 lines
Yes, but I'd rather minimize the behavioral changes as long as we can't test it.
Right. That's why the semantics of "flags" are Book3S specific right now and as such the comment is correct.
The behavioral change we need to do later is to take the ESR setting into
queue_program, but that should wait until after someone has a board to test things on again ;-). The reminder that we need to do this is hereby archived in the mails :).
What's the conclusion here? Do we need a respin or is this good enough?
Signature · 1 line
error compiling committee.c: too many arguments to function
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 4 lines · Avi Kivity
Quoted 3 lines · Alexander Graf
Quoted 3 lines
Yes, but I'd rather minimize the behavioral changes as long as we can't test it.
Quoted 8 lines
Quoted 4 lines
Right. That's why the semantics of "flags" are Book3S specific right now and as such the comment is correct.
The behavioral change we need to do later is to take the ESR setting into
queue_program, but that should wait until after someone has a board to test things on again ;-). The reminder that we need to do this is hereby archived in the mails :).What's the conclusion here? Do we need a respin or is this good enough?
From my point of view this is good. Hollis and I were just both agreeing that it would be nice to move BookE to a similar concept. That really isn't in the scope of this series though.
Alex
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 5 lines · Alexander Graf
Quoted 3 lines
What's the conclusion here? Do we need a respin or is this good enough?
From my point of view this is good. Hollis and I were just both agreeing that it would be nice to move BookE to a similar concept. That really isn't in the scope of this series though.
Thanks. All applied.
Signature · 1 line
error compiling committee.c: too many arguments to function
RE: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
In reply to a message not in the archiveQuoted 19 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Saturday, January 09, 2010 3:30 AM
To: Alexander Graf
Cc: [email protected]; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properlyarch/powerpc/kvm/booke.c static void
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0@@ -82,8 +82,9 @@ static voidkvmppc_booke_queue_irqprio(struct
kvm_vcpu*vcpu,Quoted 3 lines
arch/powerpc/kvm/booke.c +0
-0set_bit(priority, &vcpu->arch.pending_exceptions); }
Quoted 12 lines
arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 6 lines
arch/powerpc/kvm/booke.c +2
-1-void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { + /* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
ESR is updated not only by program but by data_tlb, data_storage, etc. Should we rearrange them all?
Also DEAR has the same situation as ESR.
Should it be updated when we decide to inject interrupt to guest?
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 32 lines · On 21.01.2010, at 09:09, Liu Yu-B13201 wrote:
Quoted 19 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Saturday, January 09, 2010 3:30 AM
To: Alexander Graf
Cc: [email protected]; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properlyarch/powerpc/kvm/booke.c static void
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0@@ -82,8 +82,9 @@ static voidkvmppc_booke_queue_irqprio(struct
kvm_vcpu*vcpu,Quoted 3 lines
arch/powerpc/kvm/booke.c +0
-0set_bit (priority, &vcpu->arch.pending_exceptions); }Quoted 12 lines
arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 6 lines
arch/powerpc/kvm/booke.c +2
-1-void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { +/* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_PROGRAM ); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Quoted 4 lines
ESR is updated not only by program but by
data_tlb,data_storage, etc. Should we rearrange them all?
Also DEAR has the same situation as ESR.
Should it be updated when we decide to inject interrupt to guest?
If that's what the hardware does, then yes. I'm good with taking small steps though. So if you don't have the time to convert all of the handlers, you can easily start off with program interrupts.
Alex
RE: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
In reply to Hollis BlanchardQuoted 45 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Saturday, January 09, 2010 3:30 AM
To: Alexander Graf
Cc: [email protected]; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properlyQuoted 1 line · Alexander Graf
Book3S needs some flags in SRR1 to get to know details
about an interrupt.
Quoted 2 lines
One such example is the trap instruction. It tells the
guest kernel that
Quoted 3 lines
a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making
WARN_ONbehavelike
WARN_ON.... "for Book S". It already works properly for Book E, thankyouverymuch. ;)
arch/powerpc/kvm/booke.c static void
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0@@ -82,8 +82,9 @@ static voidkvmppc_booke_queue_irqprio(struct
kvm_vcpu*vcpu,arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 9 lines
arch/powerpc/kvm/booke.c +2
-1set_bit(priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { + /* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Quoted 4 lines
Anyways, since we can't test changes at the moment (Yu, can you?), I'd settle for a comment to the effect that Book E code *should* do this, but doesn't (rather than the comment above that says it's ok).
Sure.
You mean set the ESR at the moment we inject trap to guest? If it is not urgent, I'll do it later.
A message that is not in the archive (sent off-list or not yet received): 0A1FE637C2C7E148B9573BB60CC630E56C3F11-bKEhWGtIRUJ4Lp7cDGe+DVjVikpgYyvb5NbjCUgZEJk@public.gmane.org
Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 45 lines · On 11.01.2010, at 07:58, Liu Yu-B13201 wrote:
Quoted 45 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hollis Blanchard
Sent: Saturday, January 09, 2010 3:30 AM
To: Alexander Graf
Cc: [email protected]; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properlyQuoted 1 line · Alexander Graf
Book3S needs some flags in SRR1 to get to know details
about an interrupt.
Quoted 2 lines
One such example is the trap instruction. It tells the
guest kernel that
Quoted 3 lines
a program interrupt is due to a trap using a bit in SRR1.
This patch implements above behavior, making
WARN_ONbehavelike
WARN_ON.... "for Book S". It already works properly for Book E, thankyouverymuch. ;)
arch/powerpc/kvm/booke.c static void
Quoted 5 lines
arch/powerpc/kvm/booke.c +0
-0@@ -82,8 +82,9 @@ static voidkvmppc_booke_queue_irqprio(struct
kvm_vcpu*vcpu,arch/powerpc/kvm/booke.c static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, · line 89
Quoted 9 lines
arch/powerpc/kvm/booke.c +2
-1set_bit (priority, &vcpu->arch.pending_exceptions); } -void kvmppc_core_queue_program (struct kvm_vcpu *vcpu) +void kvmppc_core_queue_program (struct kvm_vcpu *vcpu,ulong flags) { +/* BookE does flags in ESR, so ignore those we get here */ kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_PROGRAM ); }Actually, I think Book E prematurely sets ESR, since it's done before the program interrupt is actually delivered. Architecturally, I'm not sure if it's a problem, but philosophically I've always wanted it to work the way you've just implemented for Book S.
Quoted 8 lines
Quoted 4 lines
Anyways, since we can't test changes at the moment (Yu, can you?), I'd settle for a comment to the effect that Book E code *should* do this, but doesn't (rather than the comment above that says it's ok).
Sure.
You mean set the ESR at the moment we inject trap to guest? If it is not urgent, I'll do it later.
It's definitely not urgent. In fact, If you could just test patches I send to you I can write it and have you test it :-).
Alex
A message that is not in the archive (sent off-list or not yet received): 375F3E96-79CD-4451-B984-7CC896C2FA5A-l3A5Bk7waGM@public.gmane.org
RE: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properly
Quoted 18 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Tuesday, January 12, 2010 8:08 AM
To: Liu Yu-B13201
Cc: Hollis Blanchard; [email protected]; kvm-ppc; Benjamin Herrenschmidt; Liu Yu
Subject: Re: [PATCH 7/9] KVM: PPC: Emulate trap SRR1 flags properlyQuoted 2 lines
Quoted 2 lines
Anyways, since we can't test changes at the moment (Yu,
can you?), I'd
Quoted 1 line
Quoted 1 line
settle for a comment to the effect that Book E code
*should* do this,
Quoted 3 lines
Quoted 2 lines
but doesn't (rather than the comment above that says it's ok).
Quoted 7 lines
Quoted 3 lines
Sure.
You mean set the ESR at the moment we inject trap to guest? If it is not urgent, I'll do it later.It's definitely not urgent. In fact, If you could just test patches I send to you I can write it and have you test it :-).
That would be nice.:-)
But last time I try the top tree, it seemed not work. Maybe I need to find out the reason and fix it first...