[PATCH 1/3] kvmtool: Abstract KVM_VM_TYPE into a weak function

Andre Przywara andre.przywara at arm.com
Thu Mar 18 10:20:38 GMT 2021


On Tue,  9 Mar 2021 16:39:07 +0000
Marc Zyngier <maz at kernel.org> wrote:

> Most architectures pass a fixed value for their VM type. However,
> arm64 uses it as a parameter describing the size of the guest's
> physical address space.
> 
> In order to support this, introduce a kvm__get_vm_type() helper
> that only returns KVM_VM_TYPE for now.
> 
> Signed-off-by: Marc Zyngier <maz at kernel.org>

Reviewed-by: Andre Przywara <andre.przywara at arm.com>

Cheers,
Andre

> ---
>  include/kvm/kvm.h | 1 +
>  kvm.c             | 7 ++++++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h
> index 53373b0..72a42e8 100644
> --- a/include/kvm/kvm.h
> +++ b/include/kvm/kvm.h
> @@ -100,6 +100,7 @@ int kvm__init(struct kvm *kvm);
>  struct kvm *kvm__new(void);
>  int kvm__recommended_cpus(struct kvm *kvm);
>  int kvm__max_cpus(struct kvm *kvm);
> +int kvm__get_vm_type(struct kvm *kvm);
>  void kvm__init_ram(struct kvm *kvm);
>  int kvm__exit(struct kvm *kvm);
>  bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename);
> diff --git a/kvm.c b/kvm.c
> index e327541..5bc66c8 100644
> --- a/kvm.c
> +++ b/kvm.c
> @@ -428,6 +428,11 @@ int kvm__max_cpus(struct kvm *kvm)
>  	return ret;
>  }
>  
> +int __attribute__((weak)) kvm__get_vm_type(struct kvm *kvm)
> +{
> +	return KVM_VM_TYPE;
> +}
> +
>  int kvm__init(struct kvm *kvm)
>  {
>  	int ret;
> @@ -461,7 +466,7 @@ int kvm__init(struct kvm *kvm)
>  		goto err_sys_fd;
>  	}
>  
> -	kvm->vm_fd = ioctl(kvm->sys_fd, KVM_CREATE_VM, KVM_VM_TYPE);
> +	kvm->vm_fd = ioctl(kvm->sys_fd, KVM_CREATE_VM, kvm__get_vm_type(kvm));
>  	if (kvm->vm_fd < 0) {
>  		pr_err("KVM_CREATE_VM ioctl");
>  		ret = kvm->vm_fd;




More information about the linux-arm-kernel mailing list