[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v5 05/13] KVM: Extend the memslot to support fd-based private
From: |
Sean Christopherson |
Subject: |
Re: [PATCH v5 05/13] KVM: Extend the memslot to support fd-based private memory |
Date: |
Mon, 28 Mar 2022 21:56:33 +0000 |
On Thu, Mar 10, 2022, Chao Peng wrote:
> Extend the memslot definition to provide fd-based private memory support
> by adding two new fields (private_fd/private_offset). The memslot then
> can maintain memory for both shared pages and private pages in a single
> memslot. Shared pages are provided by existing userspace_addr(hva) field
> and private pages are provided through the new private_fd/private_offset
> fields.
>
> Since there is no 'hva' concept anymore for private memory so we cannot
> rely on get_user_pages() to get a pfn, instead we use the newly added
> memfile_notifier to complete the same job.
>
> This new extension is indicated by a new flag KVM_MEM_PRIVATE.
>
> Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
> Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
> ---
> Documentation/virt/kvm/api.rst | 37 +++++++++++++++++++++++++++-------
> include/linux/kvm_host.h | 7 +++++++
> include/uapi/linux/kvm.h | 8 ++++++++
> 3 files changed, 45 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
> index 3acbf4d263a5..f76ac598606c 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -1307,7 +1307,7 @@ yet and must be cleared on entry.
> :Capability: KVM_CAP_USER_MEMORY
> :Architectures: all
> :Type: vm ioctl
> -:Parameters: struct kvm_userspace_memory_region (in)
> +:Parameters: struct kvm_userspace_memory_region(_ext) (in)
> :Returns: 0 on success, -1 on error
>
> ::
> @@ -1320,9 +1320,17 @@ yet and must be cleared on entry.
> __u64 userspace_addr; /* start of the userspace allocated memory */
> };
>
> + struct kvm_userspace_memory_region_ext {
> + struct kvm_userspace_memory_region region;
Peeking ahead, the partial switch to the _ext variant is rather gross. I would
prefer that KVM use an entirely different, but binary compatible, struct
internally.
And once the kernel supports C11[*], I'm pretty sure we can make the "region" in
_ext an anonymous struct, and make KVM's internal struct a #define of _ext.
That
should minimize the churn (no need to get the embedded "region" field), reduce
line lengths, and avoid confusion due to some flows taking the _ext but others
dealing with only the "base" struct.
Maybe kvm_user_memory_region or kvm_user_mem_region? Though it's tempting to be
evil and usurp the old kvm_memory_region :-)
E.g. pre-C11 do
struct kvm_userspace_memory_region_ext {
struct kvm_userspace_memory_region region;
__u64 private_offset;
__u32 private_fd;
__u32 padding[5];
};
#ifdef __KERNEL__
struct kvm_user_mem_region {
__u32 slot;
__u32 flags;
__u64 guest_phys_addr;
__u64 memory_size; /* bytes */
__u64 userspace_addr; /* start of the userspace allocated memory */
__u64 private_offset;
__u32 private_fd;
__u32 padding[5];
};
#endif
and then post-C11 do
struct kvm_userspace_memory_region_ext {
#ifdef __KERNEL__
struct kvm_userspace_memory_region region;
#else
struct kvm_userspace_memory_region;
#endif
__u64 private_offset;
__u32 private_fd;
__u32 padding[5];
};
#ifdef __KERNEL__
#define kvm_user_mem_region kvm_userspace_memory_region_ext
#endif
[*] https://lore.kernel.org/all/20220301145233.3689119-1-arnd@kernel.org
> + __u64 private_offset;
> + __u32 private_fd;
> + __u32 padding[5];
> +};
- [PATCH v5 00/13] KVM: mm: fd-based approach for supporting KVM guest private memory, Chao Peng, 2022/03/10
- [PATCH v5 01/13] mm/memfd: Introduce MFD_INACCESSIBLE flag, Chao Peng, 2022/03/10
- [PATCH v5 02/13] mm: Introduce memfile_notifier, Chao Peng, 2022/03/10
- [PATCH v5 03/13] mm/shmem: Support memfile_notifier, Chao Peng, 2022/03/10
- [PATCH v5 04/13] mm/shmem: Restrict MFD_INACCESSIBLE memory against RLIMIT_MEMLOCK, Chao Peng, 2022/03/10
- [PATCH v5 05/13] KVM: Extend the memslot to support fd-based private memory, Chao Peng, 2022/03/10
- [PATCH v5 06/13] KVM: Use kvm_userspace_memory_region_ext, Chao Peng, 2022/03/10
- [PATCH v5 07/13] KVM: Add KVM_EXIT_MEMORY_ERROR exit, Chao Peng, 2022/03/10
- [PATCH v5 08/13] KVM: Use memfile_pfn_ops to obtain pfn for private pages, Chao Peng, 2022/03/10
- [PATCH v5 10/13] KVM: Register private memslot to memory backing store, Chao Peng, 2022/03/10
- [PATCH v5 09/13] KVM: Handle page fault for private memory, Chao Peng, 2022/03/10