[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 04/15] KVM: Extend the memslot to support fd-based private mem
From: |
Chao Peng |
Subject: |
[PATCH v3 04/15] KVM: Extend the memslot to support fd-based private memory |
Date: |
Tue, 21 Dec 2021 23:11:14 +0800 |
Extend the memslot definition to provide fd-based private memory support
by adding two new fields(fd/ofs). The memslot then can maintain memory
for both shared and private pages in a single memslot. Shared pages are
provided in the existing way by using userspace_addr(hva) field and
get_user_pages() while private pages are provided through the new
fields(fd/ofs). Since there is no 'hva' concept anymore for private
memory we cannot call get_user_pages() to get a pfn, instead we rely on
the newly introduced MEMFD_OPS callbacks to do 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>
---
include/linux/kvm_host.h | 9 +++++++++
include/uapi/linux/kvm.h | 12 ++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 865a677baf52..96e46b288ecd 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -433,8 +433,17 @@ struct kvm_memory_slot {
u32 flags;
short id;
u16 as_id;
+ struct file *file;
+ u64 file_ofs;
};
+static inline bool kvm_slot_is_private(const struct kvm_memory_slot *slot)
+{
+ if (slot && (slot->flags & KVM_MEM_PRIVATE))
+ return true;
+ return false;
+}
+
static inline bool kvm_slot_dirty_track_enabled(struct kvm_memory_slot *slot)
{
return slot->flags & KVM_MEM_LOG_DIRTY_PAGES;
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index e3706e574bd2..a2c1fb8c9843 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -103,6 +103,17 @@ struct kvm_userspace_memory_region {
__u64 userspace_addr; /* start of the userspace allocated memory */
};
+struct kvm_userspace_memory_region_ext {
+ __u32 slot;
+ __u32 flags;
+ __u64 guest_phys_addr;
+ __u64 memory_size; /* bytes */
+ __u64 userspace_addr; /* hva */
+ __u64 ofs; /* offset into fd */
+ __u32 fd;
+ __u32 padding[5];
+};
+
/*
* The bit 0 ~ bit 15 of kvm_memory_region::flags are visible for userspace,
* other bits are reserved for kvm internal use which are defined in
@@ -110,6 +121,7 @@ struct kvm_userspace_memory_region {
*/
#define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)
#define KVM_MEM_READONLY (1UL << 1)
+#define KVM_MEM_PRIVATE (1UL << 2)
/* for KVM_IRQ_LINE */
struct kvm_irq_level {
--
2.17.1
- [PATCH v3 00/15] KVM: mm: fd-based approach for supporting KVM guest private memory, Chao Peng, 2021/12/21
- [PATCH v3 01/15] mm/shmem: Introduce F_SEAL_INACCESSIBLE, Chao Peng, 2021/12/21
- [PATCH v3 02/15] mm/memfd: Introduce MFD_INACCESSIBLE flag, Chao Peng, 2021/12/21
- [PATCH v3 03/15] mm/memfd: Introduce MEMFD_OPS, Chao Peng, 2021/12/21
- [PATCH v3 04/15] KVM: Extend the memslot to support fd-based private memory,
Chao Peng <=
- [PATCH v3 05/15] KVM: Implement fd-based memory using MEMFD_OPS interfaces, Chao Peng, 2021/12/21
- [PATCH v3 06/15] KVM: Refactor hva based memory invalidation code, Chao Peng, 2021/12/21
- [PATCH v3 07/15] KVM: Special handling for fd-based memory invalidation, Chao Peng, 2021/12/21
- [PATCH v3 08/15] KVM: Split out common memory invalidation code, Chao Peng, 2021/12/21
- [PATCH v3 09/15] KVM: Implement fd-based memory invalidation, Chao Peng, 2021/12/21
- [PATCH v3 12/15] KVM: Add KVM_EXIT_MEMORY_ERROR exit, Chao Peng, 2021/12/21
- [PATCH v3 13/15] KVM: Handle page fault for private memory, Chao Peng, 2021/12/21
- [PATCH v3 14/15] KVM: Use kvm_userspace_memory_region_ext, Chao Peng, 2021/12/21
- [PATCH v3 10/15] KVM: Add kvm_map_gfn_range, Chao Peng, 2021/12/21
- [PATCH v3 15/15] KVM: Register/unregister private memory slot to memfd, Chao Peng, 2021/12/21