[PATCH v3 16/18] KVM: arm64: nVHE: Migrate hyp interface to SMCCC

Andrew Scull ascull at google.com
Wed Sep 9 04:30:39 EDT 2020


On Tue, Sep 08, 2020 at 12:02:22PM +0100, Andrew Scull wrote:
> On Mon, Sep 07, 2020 at 03:20:07PM +0100, Marc Zyngier wrote:
> > On Thu, 03 Sep 2020 14:53:05 +0100,
> > Andrew Scull <ascull at google.com> wrote:
> > > 
> > > Rather than passing arbitrary function pointers to run at hyp, define
> > > and equivalent set of SMCCC functions.
> > > 
> > > Since the SMCCC functions are strongly tied to the original function
> > > prototypes, it is not expected for the host to ever call an invalid ID
> > > but a warning is raised if this does ever occur.
> > > 
> > > As __kvm_vcpu_run is used for every switch between the host and a guest,
> > > it is explicitly singled out to be identified before the other function
> > > IDs to improve the performance of the hot path.
> > > 
> > > Signed-off-by: Andrew Scull <ascull at google.com>
> > > Signed-off-by: David Brazdil <dbrazdil at google.com>
> > > ---
> > >  arch/arm64/include/asm/kvm_asm.h   |  24 ++++++
> > >  arch/arm64/include/asm/kvm_host.h  |  25 ++++---
> > >  arch/arm64/kvm/arm.c               |   2 +-
> > >  arch/arm64/kvm/hyp.S               |  24 ++----
> > >  arch/arm64/kvm/hyp/nvhe/hyp-main.c | 113 +++++++++++++++++++++++++----
> > >  5 files changed, 145 insertions(+), 43 deletions(-)
> > > 
> > > diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
> > > index 4bbde3d3989c..4a73f1349151 100644
> > > --- a/arch/arm64/include/asm/kvm_asm.h
> > > +++ b/arch/arm64/include/asm/kvm_asm.h
> > > @@ -38,6 +38,30 @@
> > >  
> > >  #define __SMCCC_WORKAROUND_1_SMC_SZ 36
> > >  
> > > +#define KVM_HOST_SMCCC_ID(id)						\
> > > +	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
> > > +			   ARM_SMCCC_SMC_64,				\
> > > +			   ARM_SMCCC_OWNER_STANDARD_HYP,		\
> > > +			   (id))
> > > +
> > > +#define KVM_HOST_SMCCC_FUNC(name) KVM_HOST_SMCCC_ID(__KVM_HOST_SMCCC_FUNC_##name)
> > > +
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_hyp_init			0
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_flush_vm_context		1
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_ipa		2
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid		3
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_local_vmid	4
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_timer_set_cntvoff		5
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_vcpu_run			6
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_enable_ssbs			7
> > > +#define __KVM_HOST_SMCCC_FUNC___vgic_v3_get_ich_vtr_el2		8
> > > +#define __KVM_HOST_SMCCC_FUNC___vgic_v3_read_vmcr		9
> > > +#define __KVM_HOST_SMCCC_FUNC___vgic_v3_write_vmcr		10
> > > +#define __KVM_HOST_SMCCC_FUNC___vgic_v3_init_lrs		11
> > > +#define __KVM_HOST_SMCCC_FUNC___kvm_get_mdcr_el2		12
> > > +#define __KVM_HOST_SMCCC_FUNC___vgic_v3_save_aprs		13
> > > +#define __KVM_HOST_SMCCC_FUNC___vgic_v3_restore_aprs		14
> > 
> > Wait. This looks broken. How do you distinguish between these and the
> > stubs?
> 
> The __KVM_HOST_SMCCC_FUNC_* definitions are just the function ID part of
> the SMCCC x0 argument. KVM_HOST_SMCCC_ID builds it into a 64-bit
> fastcall owner by the hypervisor. The stubs fall into the legacy region
> so these don't conflict.

Looking again made me realize that I was using the service call region
for hypervisor standards rather than vendor hypervisors so I'll be
defining the vendor hyp region in arm-smccc.h to make use of here.



More information about the linux-arm-kernel mailing list