Re: [PATCH v4 2/8] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code
From: Fuad Tabba
Date: Tue Jul 14 2026 - 02:42:20 EST
On Tue, 14 Jul 2026 at 01:30, Oliver Upton <oupton@xxxxxxxxxx> wrote:
>
> Hi Fuad,
>
> On Mon, Jul 06, 2026 at 10:59:21AM +0100, Fuad Tabba wrote:
> > The vcpu_{read,write}_sys_reg() accessors are host-only, so helpers
> > built on them such as kvm_vcpu_set_be()/kvm_vcpu_is_be() cannot be
> > shared with hyp code. exception.c already wraps them in
> > __vcpu_{read,write}_sys_reg(), which pick the host- or hyp-side accessor
> > via has_vhe() and so are valid in any context.
> >
> > Move those wrappers to kvm_emulate.h as kvm_vcpu_{read,write}_sys_reg()
> > and switch the callers over, so a follow-up series can share that
> > emulation code at EL2.
> >
> > No functional change intended.
> >
> > Reviewed-by: Vincent Donnefort <vdonnefort@xxxxxxxxxx>
> > Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
> > ---
> > arch/arm64/include/asm/kvm_emulate.h | 22 +++++++++++++++---
> > arch/arm64/kvm/hyp/exception.c | 34 ++++++++--------------------
> > 2 files changed, 28 insertions(+), 28 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> > index 5bf3d7e1d92c7..80b30fead3d16 100644
> > --- a/arch/arm64/include/asm/kvm_emulate.h
> > +++ b/arch/arm64/include/asm/kvm_emulate.h
> > @@ -506,6 +506,22 @@ static inline unsigned long kvm_vcpu_get_mpidr_aff(struct kvm_vcpu *vcpu)
> > return __vcpu_sys_reg(vcpu, MPIDR_EL1) & MPIDR_HWID_BITMASK;
> > }
> >
> > +static inline u64 kvm_vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg)
> > +{
> > + if (has_vhe())
> > + return vcpu_read_sys_reg(vcpu, reg);
> > +
> > + return __vcpu_sys_reg(vcpu, reg);
> > +}
> > +
> > +static inline void kvm_vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg)
> > +{
> > + if (has_vhe())
> > + vcpu_write_sys_reg(vcpu, val, reg);
> > + else
> > + __vcpu_assign_sys_reg(vcpu, reg, val);
> > +}
> > +
>
> Can you instead name the wrappers vcpu_{read,write}_sys_reg() and rename
> the current implementations, like __vcpu_{read,write}_sysreg_vhe()?
>
> Just want to avoid confusion between kvm_vcpu_ and vcpu_
Will do, thanks!
/fuad
>
> Thanks,
> Oliver