KVM: PPC: BOOK3S: PR: Add POWER8 support
Subsystems (3)
RFC PATCH 1/10 KVM: PPC: BOOK3S: PR: Add POWER8 support
Hello,
This patch series implements PR KVM support for POWER8 platform
-aneesh
RFC PATCH 1/10 KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation
We definitely don't need to emulate mtspr, because both the registers are hypervisor resource.
--- arch/powerpc/include/asm/kvm_book3s.h | 2 -- arch/powerpc/include/asm/kvm_host.h | 4 ++-- arch/powerpc/kvm/book3s_emulate.c | 16 ++++++++-------- arch/powerpc/kvm/book3s_pr.c | 10 ++++++++++ 4 files changed, 20 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -2
@@ -83,8 +83,6 @@ struct kvmppc_vcpu_book3s {u64 sdr1;u64 hior;u64 msr_mask; -u64 purr_offset; -u64 spurr_offset;#ifdef CONFIG_PPC_BOOK3S_32 u32 vsid_pool[VSID_POOL_SIZE ];u32 vsid_next;
arch/powerpc/include/asm/kvm_host.h +2 -2
@@ -506,8 +506,8 @@ struct kvm_vcpu_arch {#ifdef CONFIG_BOOKE u32 decar;#endif -u32 tbl; -u32 tbu; +/* Time base value when we entered the guest */ +u64 entry_tb;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];
arch/powerpc/kvm/book3s_emulate.c +8 -8
@@ -422,12 +422,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) (mfmsr() & MSR_HV)) vcpu->arch.hflags |=BOOK3S_HFLAG_DCBZ32 ;break ; -case SPRN_PURR : -to_book3s (vcpu)->purr_offset = spr_val -get_tb (); -break ; -case SPRN_SPURR : -to_book3s (vcpu)->spurr_offset = spr_val -get_tb (); -break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :
@@ -523,10 +517,16 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val *spr_val =0 ;break ;case SPRN_PURR : - *spr_val =get_tb () +to_book3s (vcpu)->purr_offset; +/* +* On exit we would have updated purr +*/ + *spr_val = vcpu->arch.purr;break ;case SPRN_SPURR : - *spr_val =get_tb () +to_book3s (vcpu)->purr_offset; +/* +* On exit we would have updated spurr +*/ + *spr_val = vcpu->arch.spurr;break ;case SPRN_GQR0 :case SPRN_GQR1 :
arch/powerpc/kvm/book3s_pr.c +10 -0
@@ -115,6 +115,11 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, svcpu->lr = vcpu->arch.lr; svcpu->pc = vcpu->arch.pc; svcpu->in_use = true; +/* +* Now also save the current time base value. We use this +* to find the guest purr and spurr value. +*/ + vcpu->arch.entry_tb =get_tb (); }/* Copy data touched by real-mode code from shadow vcpu back to vcpu */
@@ -161,6 +166,11 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu, out:preempt_enable (); +/* +* Update purr and spurr using time base +*/ + vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; + vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; }static int kvmppc_core_check_requests_pr (struct kvm_vcpu *vcpu)
Signature · 1 line
1.8.5.3
RFC PATCH 2/10 KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
In reply to Aneesh Kumar K.Vvirtual time base register is a per vm register and need to saved and restored on vm exit and entry. Writing to VTB is not allowed in the privileged mode.
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/reg.h | 7 +++++++ arch/powerpc/include/asm/time.h | 12 ++++++++++++ arch/powerpc/kvm/book3s_emulate.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 3 +++ 5 files changed, 26 insertions(+)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -508,6 +508,7 @@ struct kvm_vcpu_arch {#endif /* Time base value when we entered the guest */ u64 entry_tb; +u64 entry_vtb;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];
arch/powerpc/include/asm/reg.h +7 -0
@@ -1161,6 +1161,13 @@#define mtspr (rn, v) asm volatile("mtspr " __stringify(rn) ",%0" : \ : "r" ((unsigned long)(v)) \ : "memory") +#ifdef CONFIG_PPC_BOOK3S_64 +#define mfvtb () ({unsigned long rval; \ + asm volatile("mfspr %0, %1" : \ + "=r" (rval) : "i" (SPRN_VTB)); rval;}) +#else +#define mfvtb () BUG() +#endif #ifdef __powerpc64__#if defined(CONFIG_PPC_CELL ) || defined(CONFIG_PPC_FSL_BOOK3E )
arch/powerpc/include/asm/time.h +12 -0
@@ -101,6 +101,18 @@ static inline u64 get_rtc(void)return (u64 )hi *1000000000 + lo; } +#ifdef CONFIG_PPC_BOOK3S_64 +static inline u64 get_vtb (void ) +{ +return mfvtb (); +} +#else +static inline u64 get_vtb (void ) +{ +return 0 ; +} +#endif +#ifdef CONFIG_PPC64 static inline u64 get_tb (void ) {
arch/powerpc/kvm/book3s_emulate.c +3 -0
@@ -528,6 +528,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val*/ *spr_val = vcpu->arch.spurr;break ; +case SPRN_VTB : + *spr_val = vcpu->arch.vtb; +break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :
arch/powerpc/kvm/book3s_pr.c +3 -0
@@ -120,6 +120,8 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,* to find the guest purr and spurr value. */ vcpu->arch.entry_tb =get_tb (); + vcpu->arch.entry_vtb =get_vtb (); + }/* Copy data touched by real-mode code from shadow vcpu back to vcpu */
@@ -171,6 +173,7 @@ out:*/ vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; + vcpu->arch.vtb +=get_vtb () - vcpu->arch.entry_vtb; }static int kvmppc_core_check_requests_pr (struct kvm_vcpu *vcpu)
Signature · 1 line
1.8.5.3
RFC PATCH 6/10 KVM: PPC: BOOK3S: PR: Emulate DPDES register
In reply to Aneesh Kumar K.VSince we don't support SMT yet, we should always find zero in Directed privileged doorbell exception state register.
--- arch/powerpc/kvm/book3s_emulate.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/powerpc/kvm/book3s_emulate.c +6 -0
@@ -585,6 +585,12 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val*/ *spr_val =0 ;break ; +case SPRN_DPDES : +/* +* We don't have SMT support for PR yet, hence always return 0 +*/ + *spr_val =0 ; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);
Signature · 1 line
1.8.5.3
RFC PATCH 8/10 KVM: PPC: BOOK3S: PR: Add support for facility unavailable interrupt
In reply to Aneesh Kumar K.VAt this point we allow all the supported facilities except EBB. So forward the interrupt to guest as illegal instruction.
--- arch/powerpc/include/asm/kvm_asm.h | 4 +++- arch/powerpc/kvm/book3s.c | 4 ++++ arch/powerpc/kvm/book3s_emulate.c | 18 ++++++++++++++++++ arch/powerpc/kvm/book3s_pr.c | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_asm.h +3 -1
@@ -99,6 +99,7 @@#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40 +#define BOOK3S_INTERRUPT_FAC_UNAVAIL 0xf60#define BOOK3S_IRQPRIO_SYSTEM_RESET 0#define BOOK3S_IRQPRIO_DATA_SEGMENT 1
@@ -117,7 +118,8 @@#define BOOK3S_IRQPRIO_DECREMENTER 14#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR 15#define BOOK3S_IRQPRIO_EXTERNAL_LEVEL 16 -#define BOOK3S_IRQPRIO_MAX 17 +#define BOOK3S_IRQPRIO_FAC_UNAVAIL 17 +#define BOOK3S_IRQPRIO_MAX 18#define BOOK3S_HFLAG_DCBZ32 0x1#define BOOK3S_HFLAG_SLB 0x2
arch/powerpc/kvm/book3s.c +4 -0
@@ -143,6 +143,7 @@ static int kvmppc_book3s_vec2irqprio(unsigned int vec)case 0xd00 : prio =BOOK3S_IRQPRIO_DEBUG ;break ;case 0xf20 : prio =BOOK3S_IRQPRIO_ALTIVEC ;break ;case 0xf40 : prio =BOOK3S_IRQPRIO_VSX ;break ; +case 0xf60 : prio =BOOK3S_IRQPRIO_FAC_UNAVAIL ;break ;default : prio =BOOK3S_IRQPRIO_MAX ;break ; }
@@ -273,6 +274,9 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR : vec =BOOK3S_INTERRUPT_PERFMON ;break ; +case BOOK3S_IRQPRIO_FAC_UNAVAIL : + vec =BOOK3S_INTERRUPT_FAC_UNAVAIL ; +break ;default : deliver =0 ;printk (KERN_ERR "KVM: Unknown interrupt: 0x%x\n" , priority);
arch/powerpc/kvm/book3s_emulate.c +18 -0
@@ -481,6 +481,15 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) vcpu->arch.shadow_fscr = vcpu->arch.fscr & host_fscr;break ; } +case SPRN_EBBHR : + vcpu->arch.ebbhr = spr_val; +break ; +case SPRN_EBBRR : + vcpu->arch.ebbrr = spr_val; +break ; +case SPRN_BESCR : + vcpu->arch.bescr = spr_val; +break ; unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);
@@ -607,6 +616,15 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_FSCR : *spr_val = vcpu->arch.fscr;break ; +case SPRN_EBBHR : + *spr_val = vcpu->arch.ebbhr; +break ; +case SPRN_EBBRR : + *spr_val = vcpu->arch.ebbrr; +break ; +case SPRN_BESCR : + *spr_val = vcpu->arch.bescr; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);
arch/powerpc/kvm/book3s_pr.c +17 -0
@@ -900,6 +900,23 @@ int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,case BOOK3S_INTERRUPT_PERFMON : r =RESUME_GUEST ;break ; +case BOOK3S_INTERRUPT_FAC_UNAVAIL : + { +/* +* Check for the facility that need to be emulated +*/ +ulong fscr_ic = vcpu->arch.shadow_fscr >>56 ; +if (fscr_ic !=FSCR_EBB_LG ) { +/* +* We only disable EBB facility. +* So only emulate that. +*/ +kvmppc_book3s_queue_irqprio (vcpu, exit_nr); + r =RESUME_GUEST ; +break ; + } +/* Fall through */ + }case BOOK3S_INTERRUPT_PROGRAM :case BOOK3S_INTERRUPT_H_EMUL_ASSIST : {
Signature · 1 line
1.8.5.3
RFC PATCH 9/10 KVM: PPC: BOOK3S: PR: Ignore write to monitor mode control register
In reply to Aneesh Kumar K.VWe ignore write to these registers now
--- arch/powerpc/kvm/book3s_emulate.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/powerpc/kvm/book3s_emulate.c +10 -0
@@ -490,6 +490,16 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)case SPRN_BESCR : vcpu->arch.bescr = spr_val;break ; +case SPRN_MMCRS : +break ; +case SPRN_MMCRA : +break ; +case SPRN_MMCR0 : +break ; +case SPRN_MMCR1 : +break ; +case SPRN_MMCR2 : +break ; unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);
Signature · 1 line
1.8.5.3
RFC PATCH 10/10 PPC: BOOK3S: Disable/Enable TM looking at the ibm,pa-features device tree entry
In reply to Aneesh Kumar K.VRuntime disable transactional memory feature looking at pa-features device tree entry. We need to do this so that we can run a kernel built with TM config in PR mode. For PR guest we provide a device tree entry with TM feature disabled in pa-features
--- arch/powerpc/kernel/prom.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/powerpc/kernel/prom.c +5 -0
@@ -160,6 +160,11 @@ static struct ibm_pa_feature { {CPU_FTR_NODSISRALIGN, 0, 0, 1, 1, 1}, {0, MMU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, +/* +* We should use CPU_FTR_TM_COMP so that if we disable TM, it won't get +* enabled via device tree +*/ + {CPU_FTR_TM_COMP, 0, 0, 22, 0, 0}, }; static void __init scan_features(unsigned long node, unsigned char *ftrs,
Signature · 1 line
1.8.5.3
RFC PATCH 3/10 KVM: PPC: BOOK3S: PR: Emulate instruction counter
In reply to Aneesh Kumar K.VWriting to IC is not allowed in the privileged mode.
--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_emulate.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 2 ++ 3 files changed, 6 insertions(+)
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -509,6 +509,7 @@ struct kvm_vcpu_arch {/* Time base value when we entered the guest */ u64 entry_tb;u64 entry_vtb; +u64 entry_ic;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];
arch/powerpc/kvm/book3s_emulate.c +3 -0
@@ -531,6 +531,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_VTB : *spr_val = vcpu->arch.vtb;break ; +case SPRN_IC : + *spr_val = vcpu->arch.ic; +break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :
arch/powerpc/kvm/book3s_pr.c +2 -0
@@ -121,6 +121,7 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,*/ vcpu->arch.entry_tb =get_tb (); vcpu->arch.entry_vtb =get_vtb (); + vcpu->arch.entry_ic =mfspr (SPRN_IC ); }
@@ -174,6 +175,7 @@ out: vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.vtb +=get_vtb () - vcpu->arch.entry_vtb; + vcpu->arch.ic +=mfspr (SPRN_IC ) - vcpu->arch.entry_ic; }static int kvmppc_core_check_requests_pr (struct kvm_vcpu *vcpu)
Signature · 1 line
1.8.5.3
RFC PATCH 4/10 KVM: PPC: BOOK3S: PR: Emulate Thread identification register
In reply to Aneesh Kumar K.VSince PR KVM doesn't support SMT yet, we always return 0.
--- arch/powerpc/kvm/book3s_emulate.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/powerpc/kvm/book3s_emulate.c +6 -0
@@ -561,6 +561,12 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_DABR : *spr_val =0 ;break ; +case SPRN_TIR : +/* +* We don't have SMT support for PR yet, hence always return 0 +*/ + *spr_val =0 ; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);
Signature · 1 line
1.8.5.3
RFC PATCH 5/10 KVM: PPC: BOOK3S: PR: Doorbell support
In reply to Aneesh Kumar K.VWe don't have SMT support yet, hence we should not find a doorbell message generated
--- arch/powerpc/kvm/book3s_emulate.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
arch/powerpc/kvm/book3s_emulate.c +18 -0
@@ -28,7 +28,9 @@#define OP_19_XOP_RFI 50#define OP_31_XOP_MFMSR 83 +#define OP_31_XOP_MSGSNDP 142#define OP_31_XOP_MTMSR 146 +#define OP_31_XOP_MSGCLRP 174#define OP_31_XOP_MTMSRD 178#define OP_31_XOP_MTSR 210#define OP_31_XOP_MTSRIN 242
@@ -286,6 +288,22 @@ int kvmppc_core_emulate_op_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,break ; } +case OP_31_XOP_MSGSNDP : + { +/* +* PR KVM still don't support SMT mode. So we should +* not see a MSGSNDP/MSGCLRP used with PR KVM +*/ +pr_info ("KVM: MSGSNDP used in non SMT case\n" ); + emulated =EMULATE_FAIL ; +break ; + } +case OP_31_XOP_MSGCLRP : + { + pr_info"KVM: MSGCLRP used in non SMT case\n"); + emulated =EMULATE_FAIL ; +break ; + }default : emulated =EMULATE_FAIL ; }
Signature · 1 line
1.8.5.3
RFC PATCH 7/10 KVM: PPC: BOOK3S: PR: Emulate facility status and control register
In reply to Aneesh Kumar K.VWe allow priv-mode update of this. The guest value is saved in fscr, and the value actually used is saved in shadow_fscr. shadow_fscr only contains values that are allowed by the host. On facility unavailable interrupt, if the facility is allowed by fscr but disabled in shadow_fscr we need to emulate the support. Currently all but EBB is disabled. We still don't support performance monitoring in PR guest.
--- arch/powerpc/include/asm/kvm_book3s_asm.h | 1 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 2 ++ arch/powerpc/kvm/book3s_emulate.c | 16 ++++++++++++++++ arch/powerpc/kvm/book3s_interrupts.S | 25 ++++++++++++++++++++++--- 5 files changed, 42 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +1 -0
@@ -103,6 +103,7 @@ struct kvmppc_host_state {#ifdef CONFIG_PPC_BOOK3S_64 u64 cfar;u64 ppr; +u64 host_fscr;#endif };
arch/powerpc/include/asm/kvm_host.h +1 -0
@@ -478,6 +478,7 @@ struct kvm_vcpu_arch {ulong ppr;ulong pspb;ulong fscr; +ulong shadow_fscr;ulong tfhar;ulong tfiar;ulong texasr;
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -525,6 +525,7 @@ int main(void) 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_SHADOW_FSCR, offsetof(struct kvm_vcpu, arch.shadow_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));
@@ -626,6 +627,7 @@ int main(void)#ifdef CONFIG_PPC_BOOK3S_64 HSTATE_FIELD (HSTATE_CFAR , cfar);HSTATE_FIELD (HSTATE_PPR , ppr); +HSTATE_FIELD (HSTATE_FSCR , host_fscr);#endif /* CONFIG_PPC_BOOK3S_64 */ #else /* CONFIG_PPC_BOOK3S */
arch/powerpc/kvm/book3s_emulate.c +16 -0
@@ -468,6 +468,19 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)case SPRN_MSSSR0 :case SPRN_DABR :break ; +case SPRN_FSCR : + { +ulong host_fscr =mfspr (SPRN_FSCR ); +/* +* We disable FSCR_EBB for pr guest. TAR and DSCR are always +* enabled. +*/ +if (spr_val & ~(FSCR_TAR |FSCR_DSCR |FSCR_EBB )) +pr_info ("KVM: invalud FSCR value 0x%lx" , spr_val); + vcpu->arch.fscr = spr_val & (FSCR_TAR |FSCR_DSCR ); + vcpu->arch.shadow_fscr = vcpu->arch.fscr & host_fscr; +break ; + } unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);
@@ -591,6 +604,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val*/ *spr_val =0 ;break ; +case SPRN_FSCR : + *spr_val = vcpu->arch.fscr; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);
arch/powerpc/kvm/book3s_interrupts.S +22 -3
@@ -107,6 +107,14 @@ kvm_start_lightweight: ld r3, VCPU_SHARED(r4) ld r3, VCPU_SHARED_SPRG3(r3) mtspr SPRN_SPRG3, r3 + +BEGIN_FTR_SECTION + mfspr r3,SPRN_FSCR + PPC_STL r3, HSTATE_FSCR(r13) + + PPC_LL r3, VCPU_SHADOW_FSCR(r4) + mtspr SPRN_FSCR, r3 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) #endif /* CONFIG_PPC_BOOK3S_64 */ PPC_LL r4, VCPU_SHADOW_MSR(r4) /* get shadow_msr */
@@ -148,6 +156,9 @@ kvm_start_lightweight: bl FUNC(kvmppc_copy_from_svcpu) nop + /* R7 = vcpu */ + PPC_LL r7, GPR4(r1) + #ifdef CONFIG_PPC_BOOK3S_64 /* * Reload kernel SPRG3 value.
@@ -155,10 +166,18 @@ kvm_start_lightweight: */ ld r3, PACA_SPRG3(r13) mtspr SPRN_SPRG3, r3 -#endif /* CONFIG_PPC_BOOK3S_64 */ +BEGIN_FTR_SECTION + /* + * Save the current fscr in shadow fscr + */ + mfspr r3,SPRN_FSCR + PPC_STL r3, VCPU_SHADOW_FSCR(r7) - /* R7 = vcpu */ - PPC_LL r7, GPR4(r1) + PPC_LL r3, HSTATE_FSCR(r13) + mtspr SPRN_FSCR, r3 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) + +#endif /* CONFIG_PPC_BOOK3S_64 */ PPC_STL r14, VCPU_GPR(R14)(r7) PPC_STL r15, VCPU_GPR(R15)(r7)
Signature · 1 line
1.8.5.3
Re: [RFC PATCH 01/10] KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation
In reply to Aneesh Kumar K.VQuoted 2 lines · Aneesh Kumar K.V
We definitely don't need to emulate mtspr, because both the registers are hypervisor resource.
This patch description doesn't cover what the patch actually does. It changes the implementation from "always tell the guest it uses 100%" to "give the guest an accurate amount of cpu time spent inside guest context".
Also, I think we either go with full hyp semantics which means we also emulate the offset or we go with no hyp awareness in the guest at all which means we also don't emulate SPURR which is a hyp privileged register.
Otherwise I like the patch :).
Alex
Quoted 101 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_book3s.h | 2 -- arch/powerpc/include/asm/kvm_host.h | 4 ++-- arch/powerpc/kvm/book3s_emulate.c | 16 ++++++++-------- arch/powerpc/kvm/book3s_pr.c | 10 ++++++++++ 4 files changed, 20 insertions(+), 12 deletions(-)arch/powerpc/include/asm/kvm_book3s.h +0
-2@@ -83,8 +83,6 @@ struct kvmppc_vcpu_book3s {u64 sdr1;u64 hior;u64 msr_mask; -u64 purr_offset; -u64 spurr_offset;#ifdef CONFIG_PPC_BOOK3S_32 u32 vsid_pool[VSID_POOL_SIZE ];u32 vsid_next;arch/powerpc/include/asm/kvm_host.h +2
-2@@ -506,8 +506,8 @@ struct kvm_vcpu_arch {#ifdef CONFIG_BOOKE u32 decar;#endif -u32 tbl; -u32 tbu; +/* Time base value when we entered the guest */ +u64 entry_tb;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];arch/powerpc/kvm/book3s_emulate.c +8
-8@@ -422,12 +422,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) (mfmsr() & MSR_HV)) vcpu->arch.hflags |=BOOK3S_HFLAG_DCBZ32 ;break ; -case SPRN_PURR : -to_book3s (vcpu)->purr_offset = spr_val -get_tb (); -break ; -case SPRN_SPURR : -to_book3s (vcpu)->spurr_offset = spr_val -get_tb (); -break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :@@ -523,10 +517,16 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val *spr_val =0 ;break ;case SPRN_PURR : - *spr_val =get_tb () +to_book3s (vcpu)->purr_offset; +/* +* On exit we would have updated purr +*/ + *spr_val = vcpu->arch.purr;break ;case SPRN_SPURR : - *spr_val =get_tb () +to_book3s (vcpu)->purr_offset; +/* +* On exit we would have updated spurr +*/ + *spr_val = vcpu->arch.spurr;break ;case SPRN_GQR0 :case SPRN_GQR1 :arch/powerpc/kvm/book3s_pr.c +10
-0@@ -115,6 +115,11 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, svcpu->lr = vcpu->arch.lr; svcpu->pc = vcpu->arch.pc; svcpu->in_use = true; +/* +* Now also save the current time base value. We use this +* to find the guest purr and spurr value. +*/ + vcpu->arch.entry_tb =get_tb (); }/* Copy data touched by real-mode code from shadow vcpu back to vcpu */ @@ -161,6 +166,11 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu, out:preempt_enable (); +/* +* Update purr and spurr using time base +*/ + vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; + vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; }static int kvmppc_core_check_requests_pr (struct kvm_vcpu *vcpu)
Re: [RFC PATCH 02/10] KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
In reply to Aneesh Kumar K.VQuoted 30 lines · Aneesh Kumar K.V
virtual time base register is a per vm register and need to saved and restored on vm exit and entry. Writing to VTB is not allowed in the privileged mode.
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/include/asm/reg.h | 7 +++++++ arch/powerpc/include/asm/time.h | 12 ++++++++++++ arch/powerpc/kvm/book3s_emulate.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 3 +++ 5 files changed, 26 insertions(+)arch/powerpc/include/asm/kvm_host.h +1
-0@@ -508,6 +508,7 @@ struct kvm_vcpu_arch {#endif /* Time base value when we entered the guest */ u64 entry_tb; +u64 entry_vtb;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];arch/powerpc/include/asm/reg.h +0
-0
arch/powerpc/include/asm/reg.h line 1170
Quoted 10 lines
arch/powerpc/include/asm/reg.h +7
-0@@ -1161,6 +1161,13 @@#define mtspr (rn, v) asm volatile("mtspr " __stringify(rn) ",%0" : \ : "r" ((unsigned long)(v)) \ : "memory") +#ifdef CONFIG_PPC_BOOK3S_64 +#define mfvtb () ({unsigned long rval; \ + asm volatile("mfspr %0, %1" : \ + "=r" (rval) : "i" (SPRN_VTB)); rval;}) +#else +#define mfvtb () BUG() +#endif
static inline mfvtb(unsigned long)
{
#ifdef CONFIG_PPC_BOOK3S_64
return mfspr(SPRN_VTB);
#else
BUG();#endif
}
is a lot easier to read and get right. But reg.h is Ben's call.
Also could you please give me a pointer to the specification for it? I tried to look up vtb in the 2.06 ISA and couldn't find it. Is it a CPU specific register?
Quoted 12 lines
arch/powerpc/include/asm/reg.h +0
-0#ifdef __powerpc64__#if defined(CONFIG_PPC_CELL ) || defined(CONFIG_PPC_FSL_BOOK3E )arch/powerpc/include/asm/time.h +1
-0@@ -101,6 +101,18 @@ static inline u64 get_rtc(void)return (u64 )hi *1000000000 + lo; } +#ifdef CONFIG_PPC_BOOK3S_64
arch/powerpc/include/asm/time.h static inline u64 get_rtc(void) · line 114
Quoted 10 lines
arch/powerpc/include/asm/time.h +10
-0+static inline u64 get_vtb (void ) +{ +return mfvtb (); +} +#else +static inline u64 get_vtb (void ) +{ +return 0 ; +} +#endif
Just put the #ifdef inside the function body.
Quoted 32 lines
arch/powerpc/include/asm/time.h +1
-0+#ifdef CONFIG_PPC64 static inline u64 get_tb (void ) {arch/powerpc/kvm/book3s_emulate.c +3
-0@@ -528,6 +528,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val*/ *spr_val = vcpu->arch.spurr;break ; +case SPRN_VTB : + *spr_val = vcpu->arch.vtb; +break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :arch/powerpc/kvm/book3s_pr.c +2
-0@@ -120,6 +120,8 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,* to find the guest purr and spurr value. */ vcpu->arch.entry_tb =get_tb (); + vcpu->arch.entry_vtb =get_vtb (); + }/* Copy data touched by real-mode code from shadow vcpu back to vcpu */
arch/powerpc/kvm/book3s_pr.c out: · line 176
Quoted 4 lines
arch/powerpc/kvm/book3s_pr.c +1
-0@@ -171,6 +173,7 @@ out:*/ vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; + vcpu->arch.vtb +=get_vtb () - vcpu->arch.entry_vtb;
I thought it's per vm? That would contradict the per-vcpu logic you're implementing here. This way vtb scews with world switches on SMP guests.
Alex
Re: [RFC PATCH 03/10] KVM: PPC: BOOK3S: PR: Emulate instruction counter
In reply to Aneesh Kumar K.VQuoted 1 line · Aneesh Kumar K.V
Writing to IC is not allowed in the privileged mode.
This is not a patch description.
Quoted 39 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_emulate.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 2 ++ 3 files changed, 6 insertions(+)arch/powerpc/include/asm/kvm_host.h +1
-0@@ -509,6 +509,7 @@ struct kvm_vcpu_arch {/* Time base value when we entered the guest */ u64 entry_tb;u64 entry_vtb; +u64 entry_ic;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];arch/powerpc/kvm/book3s_emulate.c +3
-0@@ -531,6 +531,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_VTB : *spr_val = vcpu->arch.vtb;break ; +case SPRN_IC : + *spr_val = vcpu->arch.ic; +break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :arch/powerpc/kvm/book3s_pr.c +0
-0
arch/powerpc/kvm/book3s_pr.c void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, · line 124
Quoted 4 lines
arch/powerpc/kvm/book3s_pr.c +1
-0@@ -121,6 +121,7 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,*/ vcpu->arch.entry_tb =get_tb (); vcpu->arch.entry_vtb =get_vtb (); + vcpu->arch.entry_ic =mfspr (SPRN_IC );
Is this implemented on all systems?
arch/powerpc/kvm/book3s_pr.c out: · line 178
Quoted 8 lines
arch/powerpc/kvm/book3s_pr.c +1
-0}@@ -174,6 +175,7 @@ out: vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.vtb +=get_vtb () - vcpu->arch.entry_vtb; + vcpu->arch.ic +=mfspr (SPRN_IC ) - vcpu->arch.entry_ic;
This is getting quite convoluted. How about we act slightly more fuzzy and put all of this into vcpu_load/put?
Alex
Re: [RFC PATCH 07/10] KVM: PPC: BOOK3S: PR: Emulate facility status and control register
In reply to Aneesh Kumar K.VQuoted 68 lines · Aneesh Kumar K.V
We allow priv-mode update of this. The guest value is saved in fscr, and the value actually used is saved in
shadow_fscr.shadow_fscronly contains values that are allowed by the host. On facility unavailable interrupt, if the facility is allowed by fscr but disabled inshadow_fscrwe need to emulate the support. Currently all but EBB is disabled. We still don't support performance monitoring in PR guest.Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_book3s_asm.h | 1 + arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kernel/asm-offsets.c | 2 ++ arch/powerpc/kvm/book3s_emulate.c | 16 ++++++++++++++++ arch/powerpc/kvm/book3s_interrupts.S | 25 ++++++++++++++++++++++--- 5 files changed, 42 insertions(+), 3 deletions(-)arch/powerpc/include/asm/kvm_book3s_asm.h +1
-0@@ -103,6 +103,7 @@ struct kvmppc_host_state {#ifdef CONFIG_PPC_BOOK3S_64 u64 cfar;u64 ppr; +u64 host_fscr;#endif };arch/powerpc/include/asm/kvm_host.h +1
-0@@ -478,6 +478,7 @@ struct kvm_vcpu_arch {ulong ppr;ulong pspb;ulong fscr; +ulong shadow_fscr;ulong tfhar;ulong tfiar;ulong texasr;arch/powerpc/kernel/asm-offsets.c +2
-0@@ -525,6 +525,7 @@ int main(void) 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_SHADOW_FSCR, offsetof(struct kvm_vcpu, arch.shadow_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));@@ -626,6 +627,7 @@ int main(void)#ifdef CONFIG_PPC_BOOK3S_64 HSTATE_FIELD (HSTATE_CFAR , cfar);HSTATE_FIELD (HSTATE_PPR , ppr); +HSTATE_FIELD (HSTATE_FSCR , host_fscr);#endif /* CONFIG_PPC_BOOK3S_64 */ #else /* CONFIG_PPC_BOOK3S */ arch/powerpc/kvm/book3s_emulate.c +0
-0@@ -468,6 +468,19 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)case SPRN_MSSSR0 :case SPRN_DABR :
arch/powerpc/kvm/book3s_emulate.c int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) · line 479
Quoted 10 lines
arch/powerpc/kvm/book3s_emulate.c +9
-0break ; +case SPRN_FSCR : + { +ulong host_fscr =mfspr (SPRN_FSCR ); +/* +* We disable FSCR_EBB for pr guest. TAR and DSCR are always +* enabled. +*/ +if (spr_val & ~(FSCR_TAR |FSCR_DSCR |FSCR_EBB )) +pr_info ("KVM: invalud FSCR value 0x%lx" , spr_val);
Is this worth printing at all? If it is, it's probably more of a pr_debug(). Also s/invalud/invalid/.
Alex
Quoted 68 lines
arch/powerpc/kvm/book3s_emulate.c +7
-0+ vcpu->arch.fscr = spr_val & (FSCR_TAR |FSCR_DSCR ); + vcpu->arch.shadow_fscr = vcpu->arch.fscr & host_fscr; +break ; + } unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);@@ -591,6 +604,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val*/ *spr_val =0 ;break ; +case SPRN_FSCR : + *spr_val = vcpu->arch.fscr; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);arch/powerpc/kvm/book3s_interrupts.S +22
-3@@ -107,6 +107,14 @@ kvm_start_lightweight: ld r3, VCPU_SHARED(r4) ld r3, VCPU_SHARED_SPRG3(r3) mtspr SPRN_SPRG3, r3 + +BEGIN_FTR_SECTION + mfspr r3,SPRN_FSCR + PPC_STL r3, HSTATE_FSCR(r13) + + PPC_LL r3, VCPU_SHADOW_FSCR(r4) + mtspr SPRN_FSCR, r3 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) #endif /* CONFIG_PPC_BOOK3S_64 */ PPC_LL r4, VCPU_SHADOW_MSR(r4) /* get shadow_msr */@@ -148,6 +156,9 @@ kvm_start_lightweight: bl FUNC(kvmppc_copy_from_svcpu) nop + /* R7 = vcpu */ + PPC_LL r7, GPR4(r1) + #ifdef CONFIG_PPC_BOOK3S_64 /* * Reload kernel SPRG3 value.@@ -155,10 +166,18 @@ kvm_start_lightweight: */ ld r3, PACA_SPRG3(r13) mtspr SPRN_SPRG3, r3 -#endif /* CONFIG_PPC_BOOK3S_64 */ +BEGIN_FTR_SECTION + /* + * Save the current fscr in shadow fscr + */ + mfspr r3,SPRN_FSCR + PPC_STL r3, VCPU_SHADOW_FSCR(r7) - /* R7 = vcpu */ - PPC_LL r7, GPR4(r1) + PPC_LL r3, HSTATE_FSCR(r13) + mtspr SPRN_FSCR, r3 +END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) + +#endif /* CONFIG_PPC_BOOK3S_64 */ PPC_STL r14, VCPU_GPR(R14)(r7) PPC_STL r15, VCPU_GPR(R15)(r7)
Re: [RFC PATCH 08/10] KVM: PPC: BOOK3S: PR: Add support for facility unavailable interrupt
In reply to Aneesh Kumar K.VQuoted 99 lines · Aneesh Kumar K.V
At this point we allow all the supported facilities except EBB. So forward the interrupt to guest as illegal instruction.
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_asm.h | 4 +++- arch/powerpc/kvm/book3s.c | 4 ++++ arch/powerpc/kvm/book3s_emulate.c | 18 ++++++++++++++++++ arch/powerpc/kvm/book3s_pr.c | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)arch/powerpc/include/asm/kvm_asm.h +3
-1@@ -99,6 +99,7 @@#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40 +#define BOOK3S_INTERRUPT_FAC_UNAVAIL 0xf60#define BOOK3S_IRQPRIO_SYSTEM_RESET 0#define BOOK3S_IRQPRIO_DATA_SEGMENT 1@@ -117,7 +118,8 @@#define BOOK3S_IRQPRIO_DECREMENTER 14#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR 15#define BOOK3S_IRQPRIO_EXTERNAL_LEVEL 16 -#define BOOK3S_IRQPRIO_MAX 17 +#define BOOK3S_IRQPRIO_FAC_UNAVAIL 17 +#define BOOK3S_IRQPRIO_MAX 18#define BOOK3S_HFLAG_DCBZ32 0x1#define BOOK3S_HFLAG_SLB 0x2arch/powerpc/kvm/book3s.c +4
-0@@ -143,6 +143,7 @@ static int kvmppc_book3s_vec2irqprio(unsigned int vec)case 0xd00 : prio =BOOK3S_IRQPRIO_DEBUG ;break ;case 0xf20 : prio =BOOK3S_IRQPRIO_ALTIVEC ;break ;case 0xf40 : prio =BOOK3S_IRQPRIO_VSX ;break ; +case 0xf60 : prio =BOOK3S_IRQPRIO_FAC_UNAVAIL ;break ;default : prio =BOOK3S_IRQPRIO_MAX ;break ; }@@ -273,6 +274,9 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR : vec =BOOK3S_INTERRUPT_PERFMON ;break ; +case BOOK3S_IRQPRIO_FAC_UNAVAIL : + vec =BOOK3S_INTERRUPT_FAC_UNAVAIL ; +break ;default : deliver =0 ;printk (KERN_ERR "KVM: Unknown interrupt: 0x%x\n" , priority);arch/powerpc/kvm/book3s_emulate.c +18
-0@@ -481,6 +481,15 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) vcpu->arch.shadow_fscr = vcpu->arch.fscr & host_fscr;break ; } +case SPRN_EBBHR : + vcpu->arch.ebbhr = spr_val; +break ; +case SPRN_EBBRR : + vcpu->arch.ebbrr = spr_val; +break ; +case SPRN_BESCR : + vcpu->arch.bescr = spr_val; +break ; unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);@@ -607,6 +616,15 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_FSCR : *spr_val = vcpu->arch.fscr;break ; +case SPRN_EBBHR : + *spr_val = vcpu->arch.ebbhr; +break ; +case SPRN_EBBRR : + *spr_val = vcpu->arch.ebbrr; +break ; +case SPRN_BESCR : + *spr_val = vcpu->arch.bescr; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);arch/powerpc/kvm/book3s_pr.c +0
-0@@ -900,6 +900,23 @@ int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,case BOOK3S_INTERRUPT_PERFMON : r =RESUME_GUEST ;break ;
arch/powerpc/kvm/book3s_pr.c int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 912
Quoted 10 lines
arch/powerpc/kvm/book3s_pr.c +10
-0+case BOOK3S_INTERRUPT_FAC_UNAVAIL : + { +/* +* Check for the facility that need to be emulated +*/ +ulong fscr_ic = vcpu->arch.shadow_fscr >>56 ; +if (fscr_ic !=FSCR_EBB_LG ) { +/* +* We only disable EBB facility. +* So only emulate that.
I don't understand the comment. We emulate nothing at all here. We either
- hit an EBB unavailable in which case we send the guest an illegal
instruction interrupt or we
- hit another facility interrupt in which case we forward the
interrupt to the guest, but not the interrupt cause (fscr_ic).
I think the EBB case should be explicit:
/* We don't allow EBB inside the guest, so something must have gone
terribly wrong */
if (fscr_ic == FSCR_EBB_LG)
BUG();
vcpu->arch.fscr &= ~FSCR_IC_MASK; vcpu->arch.fscr |= vcpu->arch.shadow_fscr & FSCR_IC_MASK; kvmppc_book3s_queue_irqprio(vcpu, exit_nr); r = RESUME_GUEST; break;
Alex
Quoted 10 lines
arch/powerpc/kvm/book3s_pr.c +7
-0+*/ +kvmppc_book3s_queue_irqprio (vcpu, exit_nr); + r =RESUME_GUEST ; +break ; + } +/* Fall through */ + }case BOOK3S_INTERRUPT_PROGRAM :case BOOK3S_INTERRUPT_H_EMUL_ASSIST : {
Re: [RFC PATCH 10/10] PPC: BOOK3S: Disable/Enable TM looking at the ibm,pa-features device tree entry
In reply to Aneesh Kumar K.VQuoted 6 lines · Aneesh Kumar K.V
Runtime disable transactional memory feature looking at pa-features device tree entry. We need to do this so that we can run a kernel built with TM config in PR mode. For PR guest we provide a device tree entry with TM feature disabled in pa-features
Signed-off-by Aneesh Kumar K.V <[email protected]>
We need to be able to run kernels without this patch, so better fix TM for good - worst case by always aborting transactions.
Alex
Quoted 20 lines
--- arch/powerpc/kernel/prom.c | 5 +++++ 1 file changed, 5 insertions(+)arch/powerpc/kernel/prom.c +5
-0@@ -160,6 +160,11 @@ static struct ibm_pa_feature { {CPU_FTR_NODSISRALIGN, 0, 0, 1, 1, 1}, {0, MMU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, +/* +* We should use CPU_FTR_TM_COMP so that if we disable TM, it won't get +* enabled via device tree +*/ + {CPU_FTR_TM_COMP, 0, 0, 22, 0, 0}, }; static void __init scan_features(unsigned long node, unsigned char *ftrs,
Re: [RFC PATCH 02/10] KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
In reply to Alexander GrafQuoted 10 lines · Alexander Graf
static inline mfvtb(unsigned long)
{#ifdef CONFIG_PPC_BOOK3S_64 return mfspr(SPRN_VTB); #else BUG();#endif
}is a lot easier to read and get right. But
reg.his Ben's call.
Agreed.
Quoted 3 lines
Also could you please give me a pointer to the specification for it? I tried to look up vtb in the 2.06 ISA and couldn't find it. Is it a CPU specific register?
Re: [RFC PATCH 02/10] KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 9 lines · Alexander Graf
static inline mfvtb(unsigned long)
{#ifdef CONFIG_PPC_BOOK3S_64 return mfspr(SPRN_VTB); #else BUG();#endif
}
Quoted 3 lines
Quoted 1 line
is a lot easier to read and get right. But
reg.his Ben's call.Agreed.
I mean I agree with Alex, his version is nicer :-)
Cheers,
Ben.
Re: [RFC PATCH 02/10] KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
In reply to Aneesh Kumar K.VQuoted 3 lines · Aneesh Kumar K.V
virtual time base register is a per vm register and need to saved and restored on vm exit and entry. Writing to VTB is not allowed in the privileged mode.
...
arch/powerpc/include/asm/reg.h line 1167
Quoted 4 lines
arch/powerpc/include/asm/reg.h +4
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define mfvtb () ({unsigned long rval; \ + asm volatile("mfspr %0, %1" : \ + "=r" (rval) : "i" (SPRN_VTB)); rval;})
The mfspr will be a no-op on anything before POWER8, meaning the result will be whatever value was in the destination GPR before the mfspr. I suppose that may not matter if the result is only ever used when we're running on a POWER8 host, but I would feel more comfortable if we had explicit feature tests to make sure of that, rather than possibly doing computations with unpredictable values.
With your patch, a guest on a POWER7 or a PPC970 could do a read from VTB and get garbage -- first, there is nothing to stop userspace from requesting POWER8 emulation on an older machine, and secondly, even if the virtual machine is a PPC970 (say) you don't implement unimplemented SPR semantics for VTB (no-op if PR=0, illegal instruction interrupt if PR=1).
On the whole I think it is reasonable to reject an attempt to set the virtual PVR to a POWER8 PVR value if we are not running on a POWER8 host, because emulating all the new POWER8 features in software (particularly transactional memory) would not be feasible. Alex may disagree. :)
Paul.
Re: [RFC PATCH 07/10] KVM: PPC: BOOK3S: PR: Emulate facility status and control register
In reply to Aneesh Kumar K.VQuoted 7 lines · Aneesh Kumar K.V
We allow priv-mode update of this. The guest value is saved in fscr, and the value actually used is saved in
shadow_fscr.shadow_fscronly contains values that are allowed by the host. On facility unavailable interrupt, if the facility is allowed by fscr but disabled inshadow_fscrwe need to emulate the support. Currently all but EBB is disabled. We still don't support performance monitoring in PR guest.
...
arch/powerpc/kvm/book3s_interrupts.S kvm_start_lightweight: · line 174
Quoted 5 lines
arch/powerpc/kvm/book3s_interrupts.S +5
-0+ /* + * Save the current fscr in shadow fscr + */ + mfspr r3,SPRN_FSCR + PPC_STL r3, VCPU_SHADOW_FSCR(r7)
I don't think you need to do this. What could possibly have changed FSCR since we loaded it on the way into the guest?
Paul.
Re: [RFC PATCH 07/10] KVM: PPC: BOOK3S: PR: Emulate facility status and control register
Quoted 15 lines
Am 30.01.2014 um 07:00 schrieb Paul Mackerras <[email protected]>:
Quoted 8 lines · Aneesh Kumar K.V
We allow priv-mode update of this. The guest value is saved in fscr, and the value actually used is saved in
shadow_fscr.shadow_fscronly contains values that are allowed by the host. On facility unavailable interrupt, if the facility is allowed by fscr but disabled inshadow_fscrwe need to emulate the support. Currently all but EBB is disabled. We still don't support performance monitoring in PR guest....
Quoted 8 lines
arch/powerpc/kvm/book3s_interrupts.S kvm_start_lightweight: · line 174
Quoted 5 lines
arch/powerpc/kvm/book3s_interrupts.S +5
-0+ /* + * Save the current fscr in shadow fscr + */ + mfspr r3,SPRN_FSCR + PPC_STL r3, VCPU_SHADOW_FSCR(r7)I don't think you need to do this. What could possibly have changed FSCR since we loaded it on the way into the guest?
The interrupt cause is part of fscr. But yes, we only meed to store that on an fscr interrupt.
Do we use anything from fscr inside the kernel? Could we switch it lazily on vcpu_load/put?
Alex
Quoted 2 lines
Paul.
Re: [RFC PATCH 02/10] KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
In reply to Paul MackerrasQuoted 29 lines
Am 30.01.2014 um 06:49 schrieb Paul Mackerras <[email protected]>:
Quoted 4 lines · Aneesh Kumar K.V
virtual time base register is a per vm register and need to saved and restored on vm exit and entry. Writing to VTB is not allowed in the privileged mode.
...
arch/powerpc/include/asm/reg.h line 1167
Quoted 4 lines
arch/powerpc/include/asm/reg.h +4
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define mfvtb () ({unsigned long rval; \ + asm volatile("mfspr %0, %1" : \ + "=r" (rval) : "i" (SPRN_VTB)); rval;})The mfspr will be a no-op on anything before POWER8, meaning the result will be whatever value was in the destination GPR before the mfspr. I suppose that may not matter if the result is only ever used when we're running on a POWER8 host, but I would feel more comfortable if we had explicit feature tests to make sure of that, rather than possibly doing computations with unpredictable values.
With your patch, a guest on a POWER7 or a PPC970 could do a read from VTB and get garbage -- first, there is nothing to stop userspace from requesting POWER8 emulation on an older machine, and secondly, even if the virtual machine is a PPC970 (say) you don't implement unimplemented SPR semantics for VTB (no-op if PR=0, illegal instruction interrupt if PR=1).
Quoted 5 lines
On the whole I think it is reasonable to reject an attempt to set the virtual PVR to a POWER8 PVR value if we are not running on a POWER8 host, because emulating all the new POWER8 features in software (particularly transactional memory) would not be feasible. Alex may disagree. :)
We don't have a good feature flag indicator that tells kvm what the guest cpu is capable of. So yes, I think it's reasonable to just not expose p8 registers on p8 for now.
In theory it's of course possible to emulate a lot of p8 features on pre-p8 hardware, but I'm not sure it's worth the effort. If anyone wants to spend the time to work on it I'd be happy to tale patches though ;)
Alex
Quoted 2 lines
Paul.
Re: [RFC PATCH 01/10] KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation
In reply to Alexander GrafQuoted 8 lines · Alexander Graf
Quoted 2 lines · Aneesh Kumar K.V
We definitely don't need to emulate mtspr, because both the registers are hypervisor resource.
This patch description doesn't cover what the patch actually does. It changes the implementation from "always tell the guest it uses 100%" to "give the guest an accurate amount of cpu time spent inside guest context".
Will fix that
Quoted 5 lines
Also, I think we either go with full hyp semantics which means we also emulate the offset or we go with no hyp awareness in the guest at all which means we also don't emulate SPURR which is a hyp privileged register.
Can you clarify this ?
Quoted 3 lines
Otherwise I like the patch :).
-aneesh
Re: [RFC PATCH 01/10] KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation
Quoted 14 lines · Aneesh Kumar K.V
Quoted 8 lines · Alexander Graf
Quoted 2 lines · Aneesh Kumar K.V
We definitely don't need to emulate mtspr, because both the registers are hypervisor resource.
This patch description doesn't cover what the patch actually does. It changes the implementation from "always tell the guest it uses 100%" to "give the guest an accurate amount of cpu time spent inside guest context".
Will fix that
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Also, I think we either go with full hyp semantics which means we also emulate the offset or we go with no hyp awareness in the guest at all which means we also don't emulate SPURR which is a hyp privileged register.
Can you clarify this ?
In the 2.06 ISA SPURR is hypervisor privileged. That changed for 2.07 where it became supervisor privileged. So I suppose your patch is ok. When reviewing those patches I only had 2.06 around because power.org was broken.
Alex
Re: [RFC PATCH 02/10] KVM: PPC: BOOK3S: PR: Emulate virtual timebase register
In reply to Paul MackerrasQuoted 18 lines · Paul Mackerras
Quoted 3 lines · Aneesh Kumar K.V
virtual time base register is a per vm register and need to saved and restored on vm exit and entry. Writing to VTB is not allowed in the privileged mode.
...
arch/powerpc/include/asm/reg.h line 1167
Quoted 4 lines
arch/powerpc/include/asm/reg.h +4
-0+#ifdef CONFIG_PPC_BOOK3S_64 +#define mfvtb () ({unsigned long rval; \ + asm volatile("mfspr %0, %1" : \ + "=r" (rval) : "i" (SPRN_VTB)); rval;})The mfspr will be a no-op on anything before POWER8, meaning the result will be whatever value was in the destination GPR before the mfspr. I suppose that may not matter if the result is only ever used when we're running on a POWER8 host, but I would feel more comfortable if we had explicit feature tests to make sure of that, rather than possibly doing computations with unpredictable values.
Quoted 6 lines
With your patch, a guest on a POWER7 or a PPC970 could do a read from VTB and get garbage -- first, there is nothing to stop userspace from requesting POWER8 emulation on an older machine, and secondly, even if the virtual machine is a PPC970 (say) you don't implement unimplemented SPR semantics for VTB (no-op if PR=0, illegal instruction interrupt if PR=1).
Ok that means we need to do something like ?
struct cpu_spec *s = find_cpuspec(vcpu->arch.pvr);
if (s->cpu_features & CPU_FTR_ARCH_207S) {
}Quoted 6 lines
On the whole I think it is reasonable to reject an attempt to set the virtual PVR to a POWER8 PVR value if we are not running on a POWER8 host, because emulating all the new POWER8 features in software (particularly transactional memory) would not be feasible. Alex may disagree. :)
That would make it much simpler.
-aneesh
Re: [RFC PATCH 03/10] KVM: PPC: BOOK3S: PR: Emulate instruction counter
In reply to Alexander GrafQuoted 54 lines · Alexander Graf
Quoted 1 line · Aneesh Kumar K.V
Writing to IC is not allowed in the privileged mode.
This is not a patch description.
Quoted 39 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_emulate.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 2 ++ 3 files changed, 6 insertions(+)arch/powerpc/include/asm/kvm_host.h +1
-0@@ -509,6 +509,7 @@ struct kvm_vcpu_arch {/* Time base value when we entered the guest */ u64 entry_tb;u64 entry_vtb; +u64 entry_ic;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires ulong */ u32 ivor[64 ];arch/powerpc/kvm/book3s_emulate.c +3
-0@@ -531,6 +531,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_VTB : *spr_val = vcpu->arch.vtb;break ; +case SPRN_IC : + *spr_val = vcpu->arch.ic; +break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 :arch/powerpc/kvm/book3s_pr.c +0
-0arch/powerpc/kvm/book3s_pr.c void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, · line 124
Quoted 4 lines
arch/powerpc/kvm/book3s_pr.c +1
-0@@ -121,6 +121,7 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,*/ vcpu->arch.entry_tb =get_tb (); vcpu->arch.entry_vtb =get_vtb (); + vcpu->arch.entry_ic =mfspr (SPRN_IC );Is this implemented on all systems?
Quoted 3 lines
arch/powerpc/kvm/book3s_pr.c +0
-0}
Quoted 9 lines
arch/powerpc/kvm/book3s_pr.c out: · line 178
Quoted 5 lines
arch/powerpc/kvm/book3s_pr.c +1
-0@@ -174,6 +175,7 @@ out: vcpu->arch.purr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.spurr +=get_tb () - vcpu->arch.entry_tb; vcpu->arch.vtb +=get_vtb () - vcpu->arch.entry_vtb; + vcpu->arch.ic +=mfspr (SPRN_IC ) - vcpu->arch.entry_ic;This is getting quite convoluted. How about we act slightly more fuzzy and put all of this into vcpu_load/put?
I am not sure whether vcpu_load/put is too early/late to save these context ?
-aneesh
Re: [RFC PATCH 03/10] KVM: PPC: BOOK3S: PR: Emulate instruction counter
Quoted 7 lines · Aneesh Kumar K.V =
Alexander Graf <[email protected]> writes:
=20Quoted 5 lines · Aneesh Kumar K.V
Quoted 1 line
Writing to IC is not allowed in the privileged mode.
=20
This is not a patch description.
=20
Quoted 9 lines
Quoted 9 lines
=
Quoted 9 lines
=20
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_host.h | 1 + arch/powerpc/kvm/book3s_emulate.c | 3 +++ arch/powerpc/kvm/book3s_pr.c | 2 ++ 3 files changed, 6 insertions(+)=20
= renamed from arch/powerpc/include/asm/kvm_host.h +0
-0
b/arch/powerpc/include/asm/kvm_host.h
Quoted 10 lines
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h struct kvm_vcpu_arch { · line 514
Quoted 10 lines
index
9ebdd12e50a9..e0b13aca98e6100644arch/powerpc/include/asm/kvm_host.h +1
-0@@ -509,6 +509,7 @@ struct kvm_vcpu_arch {/* Time base value when we entered the guest */ u64 entry_tb;u64 entry_vtb; +u64 entry_ic;u32 tcr;ulong tsr;/* we need to perform set/clr_bits() which requires =
ulong */
Quoted 2 lines
Quoted 2 lines
=
Quoted 2 lines
arch/powerpc/include/asm/kvm_host.h +0
-0u32 ivor[64 ];= renamed from arch/powerpc/kvm/book3s_emulate.c +0
-0
b/arch/powerpc/kvm/book3s_emulate.c
Quoted 4 lines
Quoted 4 lines
arch/powerpc/kvm/book3s_emulate.c int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu =
Quoted 4 lines
index
4b58d8a90cb5..abe6f3057e5b100644arch/powerpc/kvm/book3s_emulate.c +0
-0@@ -531,6 +531,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu =
*vcpu, int sprn, ulong *spr_val
Quoted 10 lines
Quoted 10 lines
=
Quoted 10 lines
arch/powerpc/kvm/book3s_emulate.c +3
-0case SPRN_VTB : *spr_val =3D vcpu->arch.vtb;break ; +case SPRN_IC : + *spr_val =3D vcpu->arch.ic; +break ;case SPRN_GQR0 :case SPRN_GQR1 :case SPRN_GQR2 := renamed from arch/powerpc/kvm/book3s_pr.c +0
-0
b/arch/powerpc/kvm/book3s_pr.c
Quoted 4 lines
Quoted 4 lines
arch/powerpc/kvm/book3s_pr.c void kvmppc_copy_to_svcpu(struct =
Quoted 4 lines
index
b5598e9cdd09..51d469f8c9fd100644arch/powerpc/kvm/book3s_pr.c +0
-0@@ -121,6 +121,7 @@ void kvmppc_copy_to_svcpu(struct =
kvmppc_book3s_shadow_vcpu *svcpu,
Quoted 7 lines
Quoted 7 lines
arch/powerpc/kvm/book3s_pr.c void kvmppc_copy_to_svcpu(struct = · line 124
Quoted 4 lines
arch/powerpc/kvm/book3s_pr.c +1
-0*/ vcpu->arch.entry_tb =3D get_tb(); vcpu->arch.entry_vtb =3D get_vtb(); + vcpu->arch.entry_ic =3D mfspr(SPRN_IC);=20
Is this implemented on all systems?
=20
Quoted 10 lines
Quoted 10 lines
arch/powerpc/kvm/book3s_pr.c out: · line 178
Quoted 8 lines
=20
}
=20arch/powerpc/kvm/book3s_pr.c +1
-0@@ -174,6 +175,7 @@ out: vcpu->arch.purr +=3D get_tb() - vcpu->arch.entry_tb; vcpu->arch.spurr +=3D get_tb() - vcpu->arch.entry_tb; vcpu->arch.vtb +=3D get_vtb() - vcpu->arch.entry_vtb; + vcpu->arch.ic +=3D mfspr(SPRN_IC) - vcpu->arch.entry_ic;=20
This is getting quite convoluted. How about we act slightly more =
fuzzy=20
Quoted 5 lines
Quoted 2 lines
and put all of this into vcpu_load/put?
=20=20
I am not sure whether vcpu_load/put is too early/late to save these context ?
It'd mean we treat instruction emulation as part of guest overhead and = time, but we'd make the entry/exit path faster. Unlike with HV KVM, = guest entry/exit is pretty hot due to the massive amounts of instruction = emulation we need to do.
Alex
Re: [RFC PATCH 07/10] KVM: PPC: BOOK3S: PR: Emulate facility status and control register
In reply to Paul MackerrasQuoted 11 lines · Paul Mackerras
Quoted 7 lines · Aneesh Kumar K.V
We allow priv-mode update of this. The guest value is saved in fscr, and the value actually used is saved in
shadow_fscr.shadow_fscronly contains values that are allowed by the host. On facility unavailable interrupt, if the facility is allowed by fscr but disabled inshadow_fscrwe need to emulate the support. Currently all but EBB is disabled. We still don't support performance monitoring in PR guest....
Quoted 8 lines
arch/powerpc/kvm/book3s_interrupts.S kvm_start_lightweight: · line 174
Quoted 5 lines
arch/powerpc/kvm/book3s_interrupts.S +5
-0+ /* + * Save the current fscr in shadow fscr + */ + mfspr r3,SPRN_FSCR + PPC_STL r3, VCPU_SHADOW_FSCR(r7)I don't think you need to do this. What could possibly have changed FSCR since we loaded it on the way into the guest?
The reason for facility unavailable interrupt is encoded in FSCR right ?
-aneesh
Re: [RFC PATCH 08/10] KVM: PPC: BOOK3S: PR: Add support for facility unavailable interrupt
In reply to Alexander GrafQuoted 108 lines · Alexander Graf
Quoted 107 lines · Aneesh Kumar K.V
At this point we allow all the supported facilities except EBB. So forward the interrupt to guest as illegal instruction.
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_asm.h | 4 +++- arch/powerpc/kvm/book3s.c | 4 ++++ arch/powerpc/kvm/book3s_emulate.c | 18 ++++++++++++++++++ arch/powerpc/kvm/book3s_pr.c | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)arch/powerpc/include/asm/kvm_asm.h +3
-1@@ -99,6 +99,7 @@#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40 +#define BOOK3S_INTERRUPT_FAC_UNAVAIL 0xf60#define BOOK3S_IRQPRIO_SYSTEM_RESET 0#define BOOK3S_IRQPRIO_DATA_SEGMENT 1@@ -117,7 +118,8 @@#define BOOK3S_IRQPRIO_DECREMENTER 14#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR 15#define BOOK3S_IRQPRIO_EXTERNAL_LEVEL 16 -#define BOOK3S_IRQPRIO_MAX 17 +#define BOOK3S_IRQPRIO_FAC_UNAVAIL 17 +#define BOOK3S_IRQPRIO_MAX 18#define BOOK3S_HFLAG_DCBZ32 0x1#define BOOK3S_HFLAG_SLB 0x2arch/powerpc/kvm/book3s.c +4
-0@@ -143,6 +143,7 @@ static int kvmppc_book3s_vec2irqprio(unsigned int vec)case 0xd00 : prio =BOOK3S_IRQPRIO_DEBUG ;break ;case 0xf20 : prio =BOOK3S_IRQPRIO_ALTIVEC ;break ;case 0xf40 : prio =BOOK3S_IRQPRIO_VSX ;break ; +case 0xf60 : prio =BOOK3S_IRQPRIO_FAC_UNAVAIL ;break ;default : prio =BOOK3S_IRQPRIO_MAX ;break ; }@@ -273,6 +274,9 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR : vec =BOOK3S_INTERRUPT_PERFMON ;break ; +case BOOK3S_IRQPRIO_FAC_UNAVAIL : + vec =BOOK3S_INTERRUPT_FAC_UNAVAIL ; +break ;default : deliver =0 ;printk (KERN_ERR "KVM: Unknown interrupt: 0x%x\n" , priority);arch/powerpc/kvm/book3s_emulate.c +18
-0@@ -481,6 +481,15 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) vcpu->arch.shadow_fscr = vcpu->arch.fscr & host_fscr;break ; } +case SPRN_EBBHR : + vcpu->arch.ebbhr = spr_val; +break ; +case SPRN_EBBRR : + vcpu->arch.ebbrr = spr_val; +break ; +case SPRN_BESCR : + vcpu->arch.bescr = spr_val; +break ; unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);@@ -607,6 +616,15 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_FSCR : *spr_val = vcpu->arch.fscr;break ; +case SPRN_EBBHR : + *spr_val = vcpu->arch.ebbhr; +break ; +case SPRN_EBBRR : + *spr_val = vcpu->arch.ebbrr; +break ; +case SPRN_BESCR : + *spr_val = vcpu->arch.bescr; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);arch/powerpc/kvm/book3s_pr.c +8
-0@@ -900,6 +900,23 @@ int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,case BOOK3S_INTERRUPT_PERFMON : r =RESUME_GUEST ;break ; +case BOOK3S_INTERRUPT_FAC_UNAVAIL : + { +/* +* Check for the facility that need to be emulated +*/ +ulong fscr_ic = vcpu->arch.shadow_fscr >>56 ; +if (fscr_ic !=FSCR_EBB_LG ) { +/*
Quoted 9 lines
arch/powerpc/kvm/book3s_pr.c int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 912
Quoted 2 lines
arch/powerpc/kvm/book3s_pr.c +2
-0+* We only disable EBB facility. +* So only emulate that. I don't understand the comment. We emulate nothing at all here. We either
- hit an EBB unavailable in which case we send the guest an illegal
instruction interrupt or we
- hit another facility interrupt in which case we forward the
interrupt to the guest, but not the interrupt cause (fscr_ic).
What i wanted to achive was, enable both TAR and DSCR and disable EBB. The reason to disable EBB was, we are still not clear how to handle PMU details in PR. Now with FSCR carrying that value, we would get facility unavailable interrupt when we try to mfspr/mtspr few EBB related registers. The PR guest kernel do that on context switch (_switch). Now what we do here is to fallthrough and handle that via emulate mtspr/mfspr.
If we get facility unavailable interrupt due to any other reason, that means PR guest has explicitly disabled that facility. Hence we forward that as facility unavailable interrupt to guest allowing PR guest to handle that.
Quoted 7 lines
I think the EBB case should be explicit:
/* We don't allow EBB inside the guest, so something must have gone terribly wrong */ if (fscr_ic == FSCR_EBB_LG) BUG();
Instead of BUG, we do handle few mfspr/mtspr via emulate which we are mostly ignoring. For event based branch instruction, the emulation will fail and we will send 0x700(interrupt program) to PR guest right ?
Quoted 6 lines
vcpu->arch.fscr &= ~FSCR_IC_MASK; vcpu->arch.fscr |= vcpu->arch.shadow_fscr & FSCR_IC_MASK; kvmppc_book3s_queue_irqprio(vcpu, exit_nr); r = RESUME_GUEST; break;
-aneesh
Re: [RFC PATCH 08/10] KVM: PPC: BOOK3S: PR: Add support for facility unavailable interrupt
Quoted 128 lines · Aneesh Kumar K.V
Quoted 108 lines · Alexander Graf
Quoted 107 lines · Aneesh Kumar K.V
At this point we allow all the supported facilities except EBB. So forward the interrupt to guest as illegal instruction.
Signed-off-by Aneesh Kumar K.V <[email protected]>--- arch/powerpc/include/asm/kvm_asm.h | 4 +++- arch/powerpc/kvm/book3s.c | 4 ++++ arch/powerpc/kvm/book3s_emulate.c | 18 ++++++++++++++++++ arch/powerpc/kvm/book3s_pr.c | 17 +++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)arch/powerpc/include/asm/kvm_asm.h +3
-1@@ -99,6 +99,7 @@#define BOOK3S_INTERRUPT_PERFMON 0xf00#define BOOK3S_INTERRUPT_ALTIVEC 0xf20#define BOOK3S_INTERRUPT_VSX 0xf40 +#define BOOK3S_INTERRUPT_FAC_UNAVAIL 0xf60#define BOOK3S_IRQPRIO_SYSTEM_RESET 0#define BOOK3S_IRQPRIO_DATA_SEGMENT 1@@ -117,7 +118,8 @@#define BOOK3S_IRQPRIO_DECREMENTER 14#define BOOK3S_IRQPRIO_PERFORMANCE_MONITOR 15#define BOOK3S_IRQPRIO_EXTERNAL_LEVEL 16 -#define BOOK3S_IRQPRIO_MAX 17 +#define BOOK3S_IRQPRIO_FAC_UNAVAIL 17 +#define BOOK3S_IRQPRIO_MAX 18#define BOOK3S_HFLAG_DCBZ32 0x1#define BOOK3S_HFLAG_SLB 0x2arch/powerpc/kvm/book3s.c +4
-0@@ -143,6 +143,7 @@ static int kvmppc_book3s_vec2irqprio(unsigned int vec)case 0xd00 : prio =BOOK3S_IRQPRIO_DEBUG ;break ;case 0xf20 : prio =BOOK3S_IRQPRIO_ALTIVEC ;break ;case 0xf40 : prio =BOOK3S_IRQPRIO_VSX ;break ; +case 0xf60 : prio =BOOK3S_IRQPRIO_FAC_UNAVAIL ;break ;default : prio =BOOK3S_IRQPRIO_MAX ;break ; }@@ -273,6 +274,9 @@ int kvmppc_book3s_irqprio_deliver(struct kvm_vcpu *vcpu, unsigned int priority)case BOOK3S_IRQPRIO_PERFORMANCE_MONITOR : vec =BOOK3S_INTERRUPT_PERFMON ;break ; +case BOOK3S_IRQPRIO_FAC_UNAVAIL : + vec =BOOK3S_INTERRUPT_FAC_UNAVAIL ; +break ;default : deliver =0 ;printk (KERN_ERR "KVM: Unknown interrupt: 0x%x\n" , priority);arch/powerpc/kvm/book3s_emulate.c +18
-0@@ -481,6 +481,15 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val) vcpu->arch.shadow_fscr = vcpu->arch.fscr & host_fscr;break ; } +case SPRN_EBBHR : + vcpu->arch.ebbhr = spr_val; +break ; +case SPRN_EBBRR : + vcpu->arch.ebbrr = spr_val; +break ; +case SPRN_BESCR : + vcpu->arch.bescr = spr_val; +break ; unprivileged:default :printk (KERN_INFO "KVM: invalid SPR write: %d\n" , sprn);@@ -607,6 +616,15 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_valcase SPRN_FSCR : *spr_val = vcpu->arch.fscr;break ; +case SPRN_EBBHR : + *spr_val = vcpu->arch.ebbhr; +break ; +case SPRN_EBBRR : + *spr_val = vcpu->arch.ebbrr; +break ; +case SPRN_BESCR : + *spr_val = vcpu->arch.bescr; +break ;default : unprivileged:printk (KERN_INFO "KVM: invalid SPR read: %d\n" , sprn);arch/powerpc/kvm/book3s_pr.c +8
-0@@ -900,6 +900,23 @@ int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,case BOOK3S_INTERRUPT_PERFMON : r =RESUME_GUEST ;break ; +case BOOK3S_INTERRUPT_FAC_UNAVAIL : + { +/* +* Check for the facility that need to be emulated +*/ +ulong fscr_ic = vcpu->arch.shadow_fscr >>56 ; +if (fscr_ic !=FSCR_EBB_LG ) { +/* Quoted 9 lines
arch/powerpc/kvm/book3s_pr.c int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 912
Quoted 2 lines
arch/powerpc/kvm/book3s_pr.c +2
-0+* We only disable EBB facility. +* So only emulate that. I don't understand the comment. We emulate nothing at all here. We either
- hit an EBB unavailable in which case we send the guest an illegal
instruction interrupt or we
- hit another facility interrupt in which case we forward the
interrupt to the guest, but not the interrupt cause (fscr_ic).What i wanted to achive was, enable both TAR and DSCR and disable EBB. The reason to disable EBB was, we are still not clear how to handle PMU details in PR. Now with FSCR carrying that value, we would get facility unavailable interrupt when we try to mfspr/mtspr few EBB related registers. The PR guest kernel do that on context switch (
_switch). Now what we do here is to fallthrough and handle that via emulate mtspr/mfspr.
Quoted 4 lines
If we get facility unavailable interrupt due to any other reason, that means PR guest has explicitly disabled that facility. Hence we forward that as facility unavailable interrupt to guest allowing PR guest to handle that.
Please adjust the comment accordingly. From the code flow that is very unclear. "Disable" means we don't allow the guest to access EBB. You do want to allow the guest to use a fake version of EBB by emulating the facility unavailable interrupt.
if (fscr_ic == FSCR_EBB_LG) {
/*
* We filtered EBB out of FSCR so that we get traps whenever the guest is trying to
* access EBB registers. Thanks to that we can now emulate these instructions and
* expose a virtual (no-op) ebb facility to the guest
*/
<call instruction emulation>
} else {
/* forward interrupt to the guest */
}
Alex
Quoted 28 lines
Quoted 9 lines
I think the EBB case should be explicit:
/* We don't allow EBB inside the guest, so something must have gone
terribly wrong */
if (fscr_ic==FSCR_EBB_LG)BUG();Instead of BUG, we do handle few mfspr/mtspr via emulate which we are mostly ignoring. For event based branch instruction, the emulation will fail and we will send 0x700(interrupt program) to PR guest right ?
Quoted 6 lines
vcpu->arch.fscr &= ~FSCR_IC_MASK; vcpu->arch.fscr |= vcpu->arch.shadow_fscr & FSCR_IC_MASK; kvmppc_book3s_queue_irqprio(vcpu, exit_nr); r = RESUME_GUEST; break;-aneesh
--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH 01/10] KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation
In reply to Alexander GrafQuoted 17 lines · Alexander Graf
Quoted 14 lines · Aneesh Kumar K.V
Quoted 8 lines · Alexander Graf
Quoted 2 lines · Aneesh Kumar K.V
We definitely don't need to emulate mtspr, because both the registers are hypervisor resource.
This patch description doesn't cover what the patch actually does. It changes the implementation from "always tell the guest it uses 100%" to "give the guest an accurate amount of cpu time spent inside guest context".
Will fix that
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Also, I think we either go with full hyp semantics which means we also emulate the offset or we go with no hyp awareness in the guest at all which means we also don't emulate SPURR which is a hyp privileged register.
Can you clarify this ?
In the 2.06 ISA SPURR is hypervisor privileged. That changed for 2.07 where it became supervisor privileged. So I suppose your patch is ok. When reviewing those patches I only had 2.06 around because power.org was broken.
It's always been supervisor privilege for reading and hypervisor privilege for writing, ever since it was introduced in 2.05, and that hasn't changed. So I think what Aneesh is doing is correct.
Regards,
Paul.
Re: [RFC PATCH 01/10] KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation
Quoted 23 lines · Paul Mackerras
Quoted 22 lines · Alexander Graf
Quoted 19 lines · Aneesh Kumar K.V
Quoted 8 lines · Alexander Graf
Quoted 2 lines · Aneesh Kumar K.V
We definitely don't need to emulate mtspr, because both the registers are hypervisor resource.
This patch description doesn't cover what the patch actually does. It changes the implementation from "always tell the guest it uses 100%" to "give the guest an accurate amount of cpu time spent inside guest context".
Will fix that
Quoted 5 lines
Also, I think we either go with full hyp semantics which means we also emulate the offset or we go with no hyp awareness in the guest at all which means we also don't emulate SPURR which is a hyp privileged register.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Can you clarify this ?
In the 2.06 ISA SPURR is hypervisor privileged. That changed for 2.07 where it became supervisor privileged. So I suppose your patch is ok. When reviewing those patches I only had 2.06 around because power.org was broken.
It's always been supervisor privilege for reading and hypervisor privilege for writing, ever since it was introduced in 2.05, and that hasn't changed. So I think what Aneesh is doing is correct.
This is what ISA 2.06B says:
308 SPURR hypv hypv 64 S
309 PURR hypv yes 64 S
And this is ISA 2.07:
308 SPURR hypv yes 64 S
309 PURR hypv yes 64 S
So as you can see, from 2.06 to 2.07 SPURR became supervisor readable. Either the spec is wrong, the respective POWER CPUs don't implement the spec correctly or "hypv" doesn't mean "hypv" but means "may be hypv or yes".
I think in the context of this patch it's perfectly reasonable to treat SPURR as supervisor readable.
Alex