Re: [PATCH v6 08/33] KVM: arm64: Use accessor functions for core regs
Marc Zyngier <[email protected]>
| Newsgroups | dev.linux.lists.kvmarm,org.infradead.lists.linux-arm-kernel,org.kernel.vger.kvm,org.kernel.vger.linux-kernel,org.kernel.vger.linux-s390 |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 12 Aug 2026 16:36:04 +0100, Steffen Eiden <[email protected]> wrote: > > Instead of accessing the value directly use assessor function that s/assessor function/accessors/ > abstract the actual location of the register values. Add a helper > function to reset fpsimd registers. Enable other KVM implementations to > reuse this code. to reuse this code by overloading the accessors. > > No functional changes. > > Signed-off-by: Steffen Eiden <[email protected]> > --- > arch/arm64/include/asm/kvm_emulate.h | 34 ++++++++++++++++++++++++++-- > arch/arm64/kvm/guest.c | 16 ++++++------- > 2 files changed, 40 insertions(+), 10 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h > index 8603766c1b4d..b31d50bdf59e 100644 > --- a/arch/arm64/include/asm/kvm_emulate.h > +++ b/arch/arm64/include/asm/kvm_emulate.h > @@ -141,6 +141,31 @@ static __always_inline unsigned long *vcpu_cpsr(const struct kvm_vcpu *vcpu) > return (unsigned long *)&vcpu->arch.ctxt.regs.pstate; > } > > +static __always_inline unsigned long *vcpu_sp_el0(struct kvm_vcpu *vcpu) > +{ > + return (unsigned long *)&vcpu->arch.ctxt.regs.sp; > +} > + > +static __always_inline u64 *vcpu_sp_el1(struct kvm_vcpu *vcpu) > +{ > + return __ctxt_sys_reg(&vcpu->arch.ctxt, SP_EL1); > +} > + > +static __always_inline __u128 *vcpu_vreg(struct kvm_vcpu *vcpu, int n) > +{ > + return &vcpu->arch.ctxt.fp_regs.vregs[n]; > +} > + > +static __always_inline __u32 *vcpu_fpsr(struct kvm_vcpu *vcpu) > +{ > + return &vcpu->arch.ctxt.fp_regs.fpsr; > +} > + > +static __always_inline __u32 *vcpu_fpcr(struct kvm_vcpu *vcpu) > +{ > + return &vcpu->arch.ctxt.fp_regs.fpcr; > +} > + > static __always_inline bool vcpu_mode_is_32bit(const struct kvm_vcpu *vcpu) > { > return !!(*vcpu_cpsr(vcpu) & PSR_MODE32_BIT); > @@ -737,6 +762,11 @@ static inline void vcpu_set_hcrx(struct kvm_vcpu *vcpu) > } > } > > +static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu) > +{ > + memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs)); > +} > + > /* Reset a vcpu's core registers. */ > static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) > { > @@ -752,8 +782,8 @@ static inline void kvm_reset_vcpu_core(struct kvm_vcpu *vcpu) > /* Reset core registers */ > memset(vcpu_gp_regs(vcpu), 0, sizeof(vcpu_gp_regs(vcpu))); > *vcpu_pc(vcpu) = 0; > - vcpu->arch.ctxt.regs.sp = 0; > - memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs)); > + *vcpu_sp_el0(vcpu) = 0; > + kvm_reset_fpsimd(vcpu); > vcpu->arch.ctxt.spsr_abt = 0; > vcpu->arch.ctxt.spsr_und = 0; > vcpu->arch.ctxt.spsr_irq = 0; > diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c > index b01d6622b872..773f6c8e5026 100644 > --- a/arch/arm64/kvm/guest.c > +++ b/arch/arm64/kvm/guest.c > @@ -134,19 +134,19 @@ static void *core_reg_addr(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) > KVM_REG_ARM_CORE_REG(regs.regs[30]): > off -= KVM_REG_ARM_CORE_REG(regs.regs[0]); > off /= 2; > - return &vcpu->arch.ctxt.regs.regs[off]; > + return &vcpu_gp_regs(vcpu)[off]; Doesn't this belong to the previous patch? Thanks, M. -- Without deviation from the norm, progress is not possible.