KVM: PPC: BOOK3S: PR: Fix PURR and SPURR emulation

We use time base for PURR and SPURR emulation with PR KVM since we
are emulating a single threaded core. When using time base
we need to make sure that we don't accumulate time spent in the host
in PURR and SPURR value.

Also we don't need to emulate mtspr because both the registers are
hypervisor resource.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
Aneesh Kumar K.V 2014-06-04 16:47:55 +05:30 committed by Alexander Graf
parent 9f6226a762
commit 3cd60e3118
4 changed files with 21 additions and 12 deletions

View File

@ -83,8 +83,6 @@ struct kvmppc_vcpu_book3s {
u64 sdr1; u64 sdr1;
u64 hior; u64 hior;
u64 msr_mask; u64 msr_mask;
u64 purr_offset;
u64 spurr_offset;
#ifdef CONFIG_PPC_BOOK3S_32 #ifdef CONFIG_PPC_BOOK3S_32
u32 vsid_pool[VSID_POOL_SIZE]; u32 vsid_pool[VSID_POOL_SIZE];
u32 vsid_next; u32 vsid_next;

View File

@ -503,8 +503,8 @@ struct kvm_vcpu_arch {
#ifdef CONFIG_BOOKE #ifdef CONFIG_BOOKE
u32 decar; u32 decar;
#endif #endif
u32 tbl; /* Time base value when we entered the guest */
u32 tbu; u64 entry_tb;
u32 tcr; u32 tcr;
ulong tsr; /* we need to perform set/clr_bits() which requires ulong */ ulong tsr; /* we need to perform set/clr_bits() which requires ulong */
u32 ivor[64]; u32 ivor[64];

View File

@ -439,12 +439,6 @@ int kvmppc_core_emulate_mtspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
(mfmsr() & MSR_HV)) (mfmsr() & MSR_HV))
vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32; vcpu->arch.hflags |= BOOK3S_HFLAG_DCBZ32;
break; 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_GQR0:
case SPRN_GQR1: case SPRN_GQR1:
case SPRN_GQR2: case SPRN_GQR2:
@ -572,10 +566,16 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
*spr_val = 0; *spr_val = 0;
break; break;
case SPRN_PURR: 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; break;
case SPRN_SPURR: 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; break;
case SPRN_GQR0: case SPRN_GQR0:
case SPRN_GQR1: case SPRN_GQR1:

View File

@ -120,6 +120,11 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,
#ifdef CONFIG_PPC_BOOK3S_64 #ifdef CONFIG_PPC_BOOK3S_64
svcpu->shadow_fscr = vcpu->arch.shadow_fscr; svcpu->shadow_fscr = vcpu->arch.shadow_fscr;
#endif #endif
/*
* 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();
svcpu->in_use = true; svcpu->in_use = true;
} }
@ -166,6 +171,12 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu,
#ifdef CONFIG_PPC_BOOK3S_64 #ifdef CONFIG_PPC_BOOK3S_64
vcpu->arch.shadow_fscr = svcpu->shadow_fscr; vcpu->arch.shadow_fscr = svcpu->shadow_fscr;
#endif #endif
/*
* Update purr and spurr using time base on exit.
*/
vcpu->arch.purr += get_tb() - vcpu->arch.entry_tb;
vcpu->arch.spurr += get_tb() - vcpu->arch.entry_tb;
svcpu->in_use = false; svcpu->in_use = false;
out: out: