Re: [PATCH v2 02/10] KVM: Add KVM_MAP_MEMORY vcpu ioctl to pre-populate guest memory

From: Edgecombe, Rick P
Date: Tue Apr 16 2024 - 10:23:08 EST


On Wed, 2024-04-10 at 15:07 -0700, isaku.yamahata@xxxxxxxxx wrote:
> From: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
>
> Add a new ioctl KVM_MAP_MEMORY in the KVM common code. It iterates on the
> memory range and calls the arch-specific function.  Add stub arch function
> as a weak symbol.
>
> Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>

But one comment below.
> ---
> v2:
> - Drop need_resched(). (David, Sean, Kai)
> - Move cond_resched() at the end of loop. (Kai)
> - Drop added check. (David)
> - Use EINTR instead of ERESTART. (David, Sean)
> - Fix srcu lock leak. (Kai, Sean)
> - Add comment above copy_to_user().
> - Drop pointless comment. (Sean)
> - Drop kvm_arch_vcpu_pre_map_memory(). (Sean)
> - Don't overwrite error code. (Sean, David)
> - Make the parameter in bytes, not pages. (Michael)
> - Drop source member in struct kvm_memory_mapping. (Sean, Michael)
> ---
>  include/linux/kvm_host.h |  3 +++
>  include/uapi/linux/kvm.h |  9 +++++++
>  virt/kvm/kvm_main.c      | 54 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 66 insertions(+)
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 48f31dcd318a..e56a0c7e5b42 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -2445,4 +2445,7 @@ static inline int kvm_gmem_get_pfn(struct kvm *kvm,
>  }
>  #endif /* CONFIG_KVM_PRIVATE_MEM */
>  
> +int kvm_arch_vcpu_map_memory(struct kvm_vcpu *vcpu,
> +                            struct kvm_memory_mapping *mapping);
> +
>  #endif
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index 2190adbe3002..972aa9e054d3 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -917,6 +917,7 @@ struct kvm_enable_cap {
>  #define KVM_CAP_MEMORY_ATTRIBUTES 233
>  #define KVM_CAP_GUEST_MEMFD 234
>  #define KVM_CAP_VM_TYPES 235
> +#define KVM_CAP_MAP_MEMORY 236

This can go in a later patch.