[PATCH 2/3] kvmtool: arm64: Use the maximum supported IPA size when creating the VM

Marc Zyngier maz at kernel.org
Thu Mar 18 14:06:59 GMT 2021


On Thu, 18 Mar 2021 10:21:25 +0000,
Andre Przywara <andre.przywara at arm.com> wrote:
> 
> On Tue,  9 Mar 2021 16:39:08 +0000
> Marc Zyngier <maz at kernel.org> wrote:
> 
> Hi,
> 
> > Instead of just asking the the default VM size, request the maximum
> > IPA size to the kernel, and use this at VM creation time.
> > 
> > The IPA space is parametrized accordingly.
> > 
> > Signed-off-by: Marc Zyngier <maz at kernel.org>
> > ---
> >  arm/aarch64/include/kvm/kvm-arch.h | 19 ++++++++++++++++---
> >  arm/aarch64/kvm.c                  | 15 +++++++++++++++
> >  2 files changed, 31 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arm/aarch64/include/kvm/kvm-arch.h b/arm/aarch64/include/kvm/kvm-arch.h
> > index 55ef8ed..159567b 100644
> > --- a/arm/aarch64/include/kvm/kvm-arch.h
> > +++ b/arm/aarch64/include/kvm/kvm-arch.h
> > @@ -3,10 +3,23 @@
> >  
> >  struct kvm;
> >  unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd);
> > +int kvm__arch_get_ipa_limit(struct kvm *kvm);
> >  
> > -#define ARM_MAX_MEMORY(kvm)	((kvm)->cfg.arch.aarch32_guest	?	\
> > -				ARM_LOMAP_MAX_MEMORY		:	\
> > -				ARM_HIMAP_MAX_MEMORY)
> > +#define ARM_MAX_MEMORY(kvm)	({					\
> > +	u64 max_ram;							\
> > +									\
> > +	if ((kvm)->cfg.arch.aarch32_guest) {				\
> > +		max_ram = ARM_LOMAP_MAX_MEMORY;				\
> > +	} else {							\
> > +		int ipabits = kvm__arch_get_ipa_limit(kvm);		\
> > +		if (ipabits <= 0)					\
> > +			max_ram = ARM_HIMAP_MAX_MEMORY;			\
> > +		else							\
> > +			max_ram = (1ULL << ipabits) - ARM_MEMORY_AREA;	\
> > +	}								\
> > +									\
> > +	max_ram;							\
> > +})
> >  
> >  #include "arm-common/kvm-arch.h"
> >  
> > diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c
> > index 49e1dd3..c4f81d0 100644
> > --- a/arm/aarch64/kvm.c
> > +++ b/arm/aarch64/kvm.c
> > @@ -46,3 +46,18 @@ fail:
> >  	return 0x80000;
> >  }
> >  
> > +int kvm__arch_get_ipa_limit(struct kvm *kvm)
> > +{
> > +	int ret;
> > +
> > +	ret = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_ARM_VM_IPA_SIZE);
> > +	if (ret <= 0)
> > +		ret = 0;
> > +
> > +	return ret;
> > +}
> > +
> > +int kvm__get_vm_type(struct kvm *kvm)
> > +{
> > +	return kvm__arch_get_ipa_limit(kvm);
> 
> Shouldn't that be funnelled through KVM_VM_TYPE_ARM_IPA_SIZE()?
> Granted, that doesn't really do anything, but if I understand the
> api.rst directly, it's logically needed to convert the IPA size into a
> VM type.

It wouldn't do anything indeed, until we get the magic extension that
bumps the IPA space beyond 255 bits. Doesn't hurt, I guess...

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list