Commit 8f42ab27 authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Alexander Graf

KVM: PPC: BOOK3S: PR: Emulate virtual timebase register

virtual time base register is a per VM, per cpu register that needs
to be saved and restored on vm exit and entry. Writing to VTB is not
allowed in the privileged mode.
Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
[agraf: fix compile error]
Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
parent 3cd60e31
...@@ -505,6 +505,7 @@ struct kvm_vcpu_arch { ...@@ -505,6 +505,7 @@ struct kvm_vcpu_arch {
#endif #endif
/* Time base value when we entered the guest */ /* Time base value when we entered the guest */
u64 entry_tb; u64 entry_tb;
u64 entry_vtb;
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];
......
...@@ -1203,6 +1203,15 @@ ...@@ -1203,6 +1203,15 @@
: "r" ((unsigned long)(v)) \ : "r" ((unsigned long)(v)) \
: "memory") : "memory")
static inline unsigned long mfvtb (void)
{
#ifdef CONFIG_PPC_BOOK3S_64
if (cpu_has_feature(CPU_FTR_ARCH_207S))
return mfspr(SPRN_VTB);
#endif
return 0;
}
#ifdef __powerpc64__ #ifdef __powerpc64__
#if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E) #if defined(CONFIG_PPC_CELL) || defined(CONFIG_PPC_FSL_BOOK3E)
#define mftb() ({unsigned long rval; \ #define mftb() ({unsigned long rval; \
......
...@@ -102,6 +102,15 @@ static inline u64 get_rtc(void) ...@@ -102,6 +102,15 @@ static inline u64 get_rtc(void)
return (u64)hi * 1000000000 + lo; return (u64)hi * 1000000000 + lo;
} }
static inline u64 get_vtb(void)
{
#ifdef CONFIG_PPC_BOOK3S_64
if (cpu_has_feature(CPU_FTR_ARCH_207S))
return mfvtb();
#endif
return 0;
}
#ifdef CONFIG_PPC64 #ifdef CONFIG_PPC64
static inline u64 get_tb(void) static inline u64 get_tb(void)
{ {
......
...@@ -646,6 +646,9 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) ...@@ -646,6 +646,9 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
case KVM_REG_PPC_BESCR: case KVM_REG_PPC_BESCR:
val = get_reg_val(reg->id, vcpu->arch.bescr); val = get_reg_val(reg->id, vcpu->arch.bescr);
break; break;
case KVM_REG_PPC_VTB:
val = get_reg_val(reg->id, vcpu->arch.vtb);
break;
default: default:
r = -EINVAL; r = -EINVAL;
break; break;
...@@ -750,6 +753,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg) ...@@ -750,6 +753,9 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
case KVM_REG_PPC_BESCR: case KVM_REG_PPC_BESCR:
vcpu->arch.bescr = set_reg_val(reg->id, val); vcpu->arch.bescr = set_reg_val(reg->id, val);
break; break;
case KVM_REG_PPC_VTB:
vcpu->arch.vtb = set_reg_val(reg->id, val);
break;
default: default:
r = -EINVAL; r = -EINVAL;
break; break;
......
...@@ -577,6 +577,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val ...@@ -577,6 +577,9 @@ int kvmppc_core_emulate_mfspr_pr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val
*/ */
*spr_val = vcpu->arch.spurr; *spr_val = vcpu->arch.spurr;
break; break;
case SPRN_VTB:
*spr_val = vcpu->arch.vtb;
break;
case SPRN_GQR0: case SPRN_GQR0:
case SPRN_GQR1: case SPRN_GQR1:
case SPRN_GQR2: case SPRN_GQR2:
......
...@@ -897,9 +897,6 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, ...@@ -897,9 +897,6 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
case KVM_REG_PPC_IC: case KVM_REG_PPC_IC:
*val = get_reg_val(id, vcpu->arch.ic); *val = get_reg_val(id, vcpu->arch.ic);
break; break;
case KVM_REG_PPC_VTB:
*val = get_reg_val(id, vcpu->arch.vtb);
break;
case KVM_REG_PPC_CSIGR: case KVM_REG_PPC_CSIGR:
*val = get_reg_val(id, vcpu->arch.csigr); *val = get_reg_val(id, vcpu->arch.csigr);
break; break;
...@@ -1097,9 +1094,6 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id, ...@@ -1097,9 +1094,6 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
case KVM_REG_PPC_IC: case KVM_REG_PPC_IC:
vcpu->arch.ic = set_reg_val(id, *val); vcpu->arch.ic = set_reg_val(id, *val);
break; break;
case KVM_REG_PPC_VTB:
vcpu->arch.vtb = set_reg_val(id, *val);
break;
case KVM_REG_PPC_CSIGR: case KVM_REG_PPC_CSIGR:
vcpu->arch.csigr = set_reg_val(id, *val); vcpu->arch.csigr = set_reg_val(id, *val);
break; break;
......
...@@ -125,6 +125,7 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, ...@@ -125,6 +125,7 @@ void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu,
* to find the guest purr and spurr value. * to find the guest purr and spurr value.
*/ */
vcpu->arch.entry_tb = get_tb(); vcpu->arch.entry_tb = get_tb();
vcpu->arch.entry_vtb = get_vtb();
svcpu->in_use = true; svcpu->in_use = true;
} }
...@@ -176,7 +177,7 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu, ...@@ -176,7 +177,7 @@ void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu,
*/ */
vcpu->arch.purr += get_tb() - vcpu->arch.entry_tb; vcpu->arch.purr += get_tb() - vcpu->arch.entry_tb;
vcpu->arch.spurr += get_tb() - vcpu->arch.entry_tb; vcpu->arch.spurr += get_tb() - vcpu->arch.entry_tb;
vcpu->arch.vtb += get_vtb() - vcpu->arch.entry_vtb;
svcpu->in_use = false; svcpu->in_use = false;
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment