mirror of
https://github.com/torvalds/linux.git
synced 2024-11-26 22:21:42 +00:00
KVM: PPC: Use accessors for VCPU registers
Introduce accessor generator macros for VCPU registers. Use the accessor functions to replace direct accesses to this registers. This will be important later for Nested APIv2 support which requires additional functionality for accessing and modifying VCPU state. Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20230914030600.16993-5-jniethe5@gmail.com
This commit is contained in:
parent
2a64bc6731
commit
7028ac8d17
@ -458,10 +458,45 @@ static inline void kvmppc_set_vscr(struct kvm_vcpu *vcpu, u32 val)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define KVMPPC_BOOK3S_VCPU_ACCESSOR_SET(reg, size) \
|
||||
static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \
|
||||
{ \
|
||||
\
|
||||
vcpu->arch.reg = val; \
|
||||
}
|
||||
|
||||
#define KVMPPC_BOOK3S_VCPU_ACCESSOR_GET(reg, size) \
|
||||
static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
|
||||
{ \
|
||||
return vcpu->arch.reg; \
|
||||
}
|
||||
|
||||
#define KVMPPC_BOOK3S_VCPU_ACCESSOR(reg, size) \
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR_SET(reg, size) \
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR_GET(reg, size) \
|
||||
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(pid, 32)
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(tar, 64)
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(ebbhr, 64)
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(ebbrr, 64)
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(bescr, 64)
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(ic, 64)
|
||||
KVMPPC_BOOK3S_VCPU_ACCESSOR(vrsave, 64)
|
||||
|
||||
static inline u64 kvmppc_get_dec_expires(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
return vcpu->arch.dec_expires;
|
||||
}
|
||||
|
||||
static inline void kvmppc_set_dec_expires(struct kvm_vcpu *vcpu, u64 val)
|
||||
{
|
||||
vcpu->arch.dec_expires = val;
|
||||
}
|
||||
|
||||
/* Expiry time of vcpu DEC relative to host TB */
|
||||
static inline u64 kvmppc_dec_expires_host_tb(struct kvm_vcpu *vcpu)
|
||||
{
|
||||
return vcpu->arch.dec_expires - vcpu->arch.vcore->tb_offset;
|
||||
return kvmppc_get_dec_expires(vcpu) - vcpu->arch.vcore->tb_offset;
|
||||
}
|
||||
|
||||
static inline bool is_kvmppc_resume_guest(int r)
|
||||
|
@ -565,7 +565,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
|
||||
regs->msr = kvmppc_get_msr(vcpu);
|
||||
regs->srr0 = kvmppc_get_srr0(vcpu);
|
||||
regs->srr1 = kvmppc_get_srr1(vcpu);
|
||||
regs->pid = vcpu->arch.pid;
|
||||
regs->pid = kvmppc_get_pid(vcpu);
|
||||
regs->sprg0 = kvmppc_get_sprg0(vcpu);
|
||||
regs->sprg1 = kvmppc_get_sprg1(vcpu);
|
||||
regs->sprg2 = kvmppc_get_sprg2(vcpu);
|
||||
@ -683,19 +683,19 @@ int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id,
|
||||
*val = get_reg_val(id, vcpu->arch.fscr);
|
||||
break;
|
||||
case KVM_REG_PPC_TAR:
|
||||
*val = get_reg_val(id, vcpu->arch.tar);
|
||||
*val = get_reg_val(id, kvmppc_get_tar(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_EBBHR:
|
||||
*val = get_reg_val(id, vcpu->arch.ebbhr);
|
||||
*val = get_reg_val(id, kvmppc_get_ebbhr(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_EBBRR:
|
||||
*val = get_reg_val(id, vcpu->arch.ebbrr);
|
||||
*val = get_reg_val(id, kvmppc_get_ebbrr(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_BESCR:
|
||||
*val = get_reg_val(id, vcpu->arch.bescr);
|
||||
*val = get_reg_val(id, kvmppc_get_bescr(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_IC:
|
||||
*val = get_reg_val(id, vcpu->arch.ic);
|
||||
*val = get_reg_val(id, kvmppc_get_ic(vcpu));
|
||||
break;
|
||||
default:
|
||||
r = -EINVAL;
|
||||
@ -768,19 +768,19 @@ int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id,
|
||||
kvmppc_set_fpscr(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_TAR:
|
||||
vcpu->arch.tar = set_reg_val(id, *val);
|
||||
kvmppc_set_tar(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_EBBHR:
|
||||
vcpu->arch.ebbhr = set_reg_val(id, *val);
|
||||
kvmppc_set_ebbhr(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_EBBRR:
|
||||
vcpu->arch.ebbrr = set_reg_val(id, *val);
|
||||
kvmppc_set_ebbrr(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_BESCR:
|
||||
vcpu->arch.bescr = set_reg_val(id, *val);
|
||||
kvmppc_set_bescr(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_IC:
|
||||
vcpu->arch.ic = set_reg_val(id, *val);
|
||||
kvmppc_set_ic(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
default:
|
||||
r = -EINVAL;
|
||||
|
@ -96,7 +96,7 @@ static long kvmhv_copy_tofrom_guest_radix(struct kvm_vcpu *vcpu, gva_t eaddr,
|
||||
void *to, void *from, unsigned long n)
|
||||
{
|
||||
int lpid = vcpu->kvm->arch.lpid;
|
||||
int pid = vcpu->arch.pid;
|
||||
int pid = kvmppc_get_pid(vcpu);
|
||||
|
||||
/* This would cause a data segment intr so don't allow the access */
|
||||
if (eaddr & (0x3FFUL << 52))
|
||||
@ -270,7 +270,7 @@ int kvmppc_mmu_radix_xlate(struct kvm_vcpu *vcpu, gva_t eaddr,
|
||||
/* Work out effective PID */
|
||||
switch (eaddr >> 62) {
|
||||
case 0:
|
||||
pid = vcpu->arch.pid;
|
||||
pid = kvmppc_get_pid(vcpu);
|
||||
break;
|
||||
case 3:
|
||||
pid = 0;
|
||||
|
@ -2310,7 +2310,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
|
||||
*val = get_reg_val(id, vcpu->arch.tcscr);
|
||||
break;
|
||||
case KVM_REG_PPC_PID:
|
||||
*val = get_reg_val(id, vcpu->arch.pid);
|
||||
*val = get_reg_val(id, kvmppc_get_pid(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_ACOP:
|
||||
*val = get_reg_val(id, vcpu->arch.acop);
|
||||
@ -2421,7 +2421,7 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
|
||||
*val = get_reg_val(id, vcpu->arch.vcore->arch_compat);
|
||||
break;
|
||||
case KVM_REG_PPC_DEC_EXPIRY:
|
||||
*val = get_reg_val(id, vcpu->arch.dec_expires);
|
||||
*val = get_reg_val(id, kvmppc_get_dec_expires(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_ONLINE:
|
||||
*val = get_reg_val(id, vcpu->arch.online);
|
||||
@ -2553,7 +2553,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
|
||||
vcpu->arch.tcscr = set_reg_val(id, *val);
|
||||
break;
|
||||
case KVM_REG_PPC_PID:
|
||||
vcpu->arch.pid = set_reg_val(id, *val);
|
||||
kvmppc_set_pid(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_ACOP:
|
||||
vcpu->arch.acop = set_reg_val(id, *val);
|
||||
@ -2606,8 +2606,8 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
|
||||
* decrementer, which is better than a large one that
|
||||
* causes a hang.
|
||||
*/
|
||||
if (!vcpu->arch.dec_expires && tb_offset)
|
||||
vcpu->arch.dec_expires = get_tb() + tb_offset;
|
||||
if (!kvmppc_get_dec_expires(vcpu) && tb_offset)
|
||||
kvmppc_set_dec_expires(vcpu, get_tb() + tb_offset);
|
||||
|
||||
vcpu->arch.vcore->tb_offset = tb_offset;
|
||||
break;
|
||||
@ -2690,7 +2690,7 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
|
||||
r = kvmppc_set_arch_compat(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_DEC_EXPIRY:
|
||||
vcpu->arch.dec_expires = set_reg_val(id, *val);
|
||||
kvmppc_set_dec_expires(vcpu, set_reg_val(id, *val));
|
||||
break;
|
||||
case KVM_REG_PPC_ONLINE:
|
||||
i = set_reg_val(id, *val);
|
||||
|
@ -305,7 +305,7 @@ static void switch_mmu_to_guest_radix(struct kvm *kvm, struct kvm_vcpu *vcpu, u6
|
||||
u32 pid;
|
||||
|
||||
lpid = nested ? nested->shadow_lpid : kvm->arch.lpid;
|
||||
pid = vcpu->arch.pid;
|
||||
pid = kvmppc_get_pid(vcpu);
|
||||
|
||||
/*
|
||||
* Prior memory accesses to host PID Q3 must be completed before we
|
||||
@ -330,7 +330,7 @@ static void switch_mmu_to_guest_hpt(struct kvm *kvm, struct kvm_vcpu *vcpu, u64
|
||||
int i;
|
||||
|
||||
lpid = kvm->arch.lpid;
|
||||
pid = vcpu->arch.pid;
|
||||
pid = kvmppc_get_pid(vcpu);
|
||||
|
||||
/*
|
||||
* See switch_mmu_to_guest_radix. ptesync should not be required here
|
||||
|
@ -1729,7 +1729,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
|
||||
val = get_reg_val(reg->id, kvmppc_get_vscr(vcpu));
|
||||
break;
|
||||
case KVM_REG_PPC_VRSAVE:
|
||||
val = get_reg_val(reg->id, vcpu->arch.vrsave);
|
||||
val = get_reg_val(reg->id, kvmppc_get_vrsave(vcpu));
|
||||
break;
|
||||
#endif /* CONFIG_ALTIVEC */
|
||||
default:
|
||||
@ -1784,7 +1784,7 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
|
||||
r = -ENXIO;
|
||||
break;
|
||||
}
|
||||
vcpu->arch.vrsave = set_reg_val(reg->id, val);
|
||||
kvmppc_set_vrsave(vcpu, set_reg_val(reg->id, val));
|
||||
break;
|
||||
#endif /* CONFIG_ALTIVEC */
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user