kvm/e500: Map (vcpu,as,id) to core's shadow id.
Subsystems (2)
PATCH 2/3 kvm/e500: Map (vcpu,as,id) to core's shadow id.
The shadow id mappings is based on Hollis's idea.
We can benifit a lot from this trick:
1. Support AS=1 in guest.
So that OSes other than Linux can be expected to run in the guest.
2. Minimize the frequency of TLB flushes.
Signed-off-by Liu Yu <[email protected]>
--- arch/powerpc/include/asm/kvm_e500.h | 3 + arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kvm/booke.h | 4 + arch/powerpc/kvm/booke_interrupts.S | 11 +++ arch/powerpc/kvm/e500_emulate.c | 10 ++- arch/powerpc/kvm/e500_tlb.c | 146 +++++++++++++++++++++++++++++++++-- arch/powerpc/kvm/e500_tlb.h | 2 + 8 files changed, 167 insertions(+), 11 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +3 -0
@@ -43,6 +43,9 @@ struct kvmppc_vcpu_e500 {/* Pages which are referenced in the shadow TLB. */ struct kvmppc_e500_shadow_ref *shadow_refs[E500_TLB_NUM ]; +/* MMU id mapping */ +void *id_mapping; +unsigned int guest_tlb_size[E500_TLB_NUM ];unsigned int shadow_tlb_size[E500_TLB_NUM ];unsigned int guest_tlb_nv[E500_TLB_NUM ];
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -57,6 +57,7 @@ extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);extern void kvmppc_mmu_map (struct kvm_vcpu *vcpu,u64 gvaddr,gpa_t gpaddr,unsigned int gtlb_idx);extern void kvmppc_mmu_priv_switch (struct kvm_vcpu *vcpu,int usermode); +extern void kvmppc_mmu_as_switch (struct kvm_vcpu *vcpu,unsigned int as);extern void kvmppc_mmu_switch_pid (struct kvm_vcpu *vcpu,u32 pid);extern void kvmppc_mmu_destroy (struct kvm_vcpu *vcpu);extern int kvmppc_mmu_dtlb_index (struct kvm_vcpu *vcpu,gva_t eaddr);
arch/powerpc/kernel/asm-offsets.c +1 -0
@@ -379,6 +379,7 @@ int main(void) DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst)); DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear)); DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr)); + DEFINE(VCPU_SWAP_PID, offsetof(struct kvm_vcpu, arch.swap_pid));#endif #ifdef CONFIG_44xDEFINE (PGD_T_LOG2 ,PGD_T_LOG2 );
arch/powerpc/kvm/booke.h +3 -0
@@ -57,6 +57,10 @@ static inline void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)if ((new_msr &MSR_PR ) != (vcpu->arch.msr &MSR_PR ))kvmppc_mmu_priv_switch (vcpu, new_msr &MSR_PR ); + if ((new_msr & (MSR_IS | MSR_DS)) !+ (vcpu->arch.msr & (MSR_IS | MSR_DS))) +kvmppc_mmu_as_switch (vcpu, new_msr & (MSR_IS |MSR_DS )); + vcpu->arch.msr = new_msr;if (vcpu->arch.msr &MSR_WE ) {
arch/powerpc/kvm/booke_interrupts.S +11 -0
@@ -192,6 +192,12 @@ _GLOBAL(kvmppc_resume_host) lwz r3, VCPU_HOST_PID(r4) mtspr SPRN_PID, r3 +#ifdef CONFIG_E500 + /* we cheat and know Linux doesn't use PID1 which is always 0 */ + lis r3, 0 + mtspr SPRN_PID1, r3 +#endif + /* Restore host IVPR before re-enabling interrupts. We cheat and know * that Linux IVPR is always 0xc0000000. */ lis r3, 0xc000
@@ -350,6 +356,11 @@ lightweight_exit: lwz r3, VCPU_SHADOW_PID(r4) mtspr SPRN_PID, r3 +#ifdef CONFIG_E500 + lwz r3, VCPU_SWAP_PID(r4) + mtspr SPRN_PID1, r3 +#endif + #ifdef CONFIG_44x iccci 0, 0 /* XXX hack */ #endif
arch/powerpc/kvm/e500_emulate.c +7 -2
@@ -76,10 +76,14 @@ int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs)int emulated =EMULATE_DONE ;switch (sprn) { -case SPRN_PID : - vcpu_e500->pid[0 ] = vcpu->arch.shadow_pid - vcpu->arch.pid = vcpu->arch.gpr[rs]; +case SPRN_PID : { +unsigned int as = !!(vcpu->arch.msr & (MSR_IS |MSR_DS )); + + vcpu_e500->pid[0 ] = vcpu->arch.pid = vcpu->arch.gpr[rs]; + vcpu->arch.shadow_pid =kvmppc_e500_get_sid (vcpu_e500, as, +get_cur_pid (vcpu));break ; + }case SPRN_PID1 : vcpu_e500->pid[1 ] = vcpu->arch.gpr[rs];break ;case SPRN_PID2 :
arch/powerpc/kvm/e500_tlb.c +137 -8
218 lines not on this page · raw message
arch/powerpc/kvm/e500_tlb.h +2 -0
@@ -55,6 +55,8 @@ extern void kvmppc_e500_tlb_load(struct kvm_vcpu *, int);extern int kvmppc_e500_tlb_init (struct kvmppc_vcpu_e500 *);extern void kvmppc_e500_tlb_uninit (struct kvmppc_vcpu_e500 *);extern void kvmppc_e500_tlb_setup (struct kvmppc_vcpu_e500 *); +extern unsigned int kvmppc_e500_get_sid (struct kvmppc_vcpu_e500 *vcpu_e500, +int as,int gid);/* TLB helper functions */ static inline unsigned int get_tlb_size (const struct tlbe *tlbe)
Signature · 1 line
1.5.4