Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From fc57b8c1deda99bc1e64d45dd7f97a1b9259d16e Mon Sep 17 00:00:00 2001
From 000264f8823f76fb6cf91dc40ace84a29a0fa089 Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:27 +0100
Subject: [PATCH 01/45] KVM: Rename CONFIG_KVM_PRIVATE_MEM to CONFIG_KVM_GMEM
Date: Tue, 15 Jul 2025 10:33:30 +0100
Subject: [PATCH 01/46] KVM: Rename CONFIG_KVM_PRIVATE_MEM to CONFIG_KVM_GMEM

Rename the Kconfig option CONFIG_KVM_PRIVATE_MEM to CONFIG_KVM_GMEM. The
original name implied that the feature only supported "private" memory.
Expand Down Expand Up @@ -32,10 +32,10 @@ Signed-off-by: Fuad Tabba <[email protected]>
6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 639d9bcee842..66bdd0759d27 100644
index f7af967aa16f..acb25f935d84 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -2269,7 +2269,7 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,
@@ -2275,7 +2275,7 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,
int tdp_max_root_level, int tdp_huge_page_level);


Expand Down Expand Up @@ -137,10 +137,10 @@ index 724c89af78af..8d00918d4c8b 100644
-kvm-$(CONFIG_KVM_PRIVATE_MEM) += $(KVM)/guest_memfd.o
+kvm-$(CONFIG_KVM_GMEM) += $(KVM)/guest_memfd.o
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index eec82775c5bf..898c3d5a7ba8 100644
index 222f0e894a0c..d5f0ec2d321f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4910,7 +4910,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
@@ -4913,7 +4913,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
case KVM_CAP_MEMORY_ATTRIBUTES:
return kvm_supported_mem_attributes(kvm);
#endif
Expand All @@ -149,7 +149,7 @@ index eec82775c5bf..898c3d5a7ba8 100644
case KVM_CAP_GUEST_MEMFD:
return !kvm || kvm_arch_has_private_mem(kvm);
#endif
@@ -5344,7 +5344,7 @@ static long kvm_vm_ioctl(struct file *filp,
@@ -5347,7 +5347,7 @@ static long kvm_vm_ioctl(struct file *filp,
case KVM_GET_STATS_FD:
r = kvm_vm_ioctl_get_stats_fd(kvm);
break;
Expand Down Expand Up @@ -180,5 +180,5 @@ index acef3f5c582a..ec311c0d6718 100644

#endif /* __KVM_MM_H__ */
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 2ce4cc59bb3e067e019842870824d7a459d140f0 Mon Sep 17 00:00:00 2001
From 05cf45cc4528079db3c40c021947ae0cc28eec82 Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:28 +0100
Subject: [PATCH 02/45] KVM: Rename CONFIG_KVM_GENERIC_PRIVATE_MEM to
Date: Tue, 15 Jul 2025 10:33:31 +0100
Subject: [PATCH 02/46] KVM: Rename CONFIG_KVM_GENERIC_PRIVATE_MEM to
CONFIG_KVM_GENERIC_GMEM_POPULATE

The original name was vague regarding its functionality. This Kconfig
Expand Down Expand Up @@ -99,5 +99,5 @@ index b2aa6bf24d3a..befea51bbc75 100644
kvm_gmem_populate_cb post_populate, void *opaque)
{
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 85b1525e138e76dd43f58e8b5cfd2f0f861ae6a6 Mon Sep 17 00:00:00 2001
From fd6bbab2fcae663ac196e4c68c8bcd8393b99d6a Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:29 +0100
Subject: [PATCH 03/45] KVM: Introduce kvm_arch_supports_gmem()
Date: Tue, 15 Jul 2025 10:33:32 +0100
Subject: [PATCH 03/46] KVM: Introduce kvm_arch_supports_gmem()

Introduce kvm_arch_supports_gmem() to explicitly indicate whether an
architecture supports guest_memfd.
Expand Down Expand Up @@ -30,10 +30,10 @@ Signed-off-by: Fuad Tabba <[email protected]>
3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 66bdd0759d27..09f4f6240d9d 100644
index acb25f935d84..bde811b2d303 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -2271,8 +2271,10 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,
@@ -2277,8 +2277,10 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,

#ifdef CONFIG_KVM_GMEM
#define kvm_arch_has_private_mem(kvm) ((kvm)->arch.has_private_mem)
Expand All @@ -44,7 +44,7 @@ index 66bdd0759d27..09f4f6240d9d 100644
#endif

#define kvm_arch_has_readonly_mem(kvm) (!(kvm)->arch.has_protected_state)
@@ -2325,7 +2327,7 @@ enum {
@@ -2331,7 +2333,7 @@ enum {
#define HF_SMM_INSIDE_NMI_MASK (1 << 2)

# define KVM_MAX_NR_ADDRESS_SPACES 2
Expand Down Expand Up @@ -76,7 +76,7 @@ index 359baaae5e9f..ab1bde048034 100644
static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm)
{
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 898c3d5a7ba8..afbc025ce4d3 100644
index d5f0ec2d321f..162e2a69cc49 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1588,7 +1588,7 @@ static int check_memory_region_flags(struct kvm *kvm,
Expand All @@ -88,7 +88,7 @@ index 898c3d5a7ba8..afbc025ce4d3 100644
valid_flags |= KVM_MEM_GUEST_MEMFD;

/* Dirty logging private memory is not currently supported. */
@@ -4912,7 +4912,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
@@ -4915,7 +4915,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
#endif
#ifdef CONFIG_KVM_GMEM
case KVM_CAP_GUEST_MEMFD:
Expand All @@ -98,5 +98,5 @@ index 898c3d5a7ba8..afbc025ce4d3 100644
default:
break;
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 50a700bdda054eaa3f86c79a1510a1d60325f2be Mon Sep 17 00:00:00 2001
From 76851fca367e2d7666c3e709eab8cc016406f91b Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:30 +0100
Subject: [PATCH 04/45] KVM: x86: Introduce kvm->arch.supports_gmem
Date: Tue, 15 Jul 2025 10:33:33 +0100
Subject: [PATCH 04/46] KVM: x86: Introduce kvm->arch.supports_gmem

Introduce a new boolean member, supports_gmem, to kvm->arch.

Expand Down Expand Up @@ -31,18 +31,18 @@ Signed-off-by: Fuad Tabba <[email protected]>
4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 09f4f6240d9d..ebddedf0a1f2 100644
index bde811b2d303..938b5be03d33 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1342,6 +1342,7 @@ struct kvm_arch {
@@ -1348,6 +1348,7 @@ struct kvm_arch {
u8 mmu_valid_gen;
u8 vm_type;
bool has_private_mem;
+ bool supports_gmem;
bool has_protected_state;
bool pre_fault_allowed;
struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
@@ -2271,7 +2272,7 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,
@@ -2277,7 +2278,7 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level,

#ifdef CONFIG_KVM_GMEM
#define kvm_arch_has_private_mem(kvm) ((kvm)->arch.has_private_mem)
Expand All @@ -64,10 +64,10 @@ index ab9b947dbf4f..d1c484eaa8ad 100644
}

diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 1ad20c273f3b..c227516e6a02 100644
index f31ccdeb905b..a3db6df245ee 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -625,6 +625,7 @@ int tdx_vm_init(struct kvm *kvm)
@@ -632,6 +632,7 @@ int tdx_vm_init(struct kvm *kvm)

kvm->arch.has_protected_state = true;
kvm->arch.has_private_mem = true;
Expand All @@ -76,10 +76,10 @@ index 1ad20c273f3b..c227516e6a02 100644

/*
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a9d992d5652f..b34236029383 100644
index 357b9e3a6cef..adbdc2cc97d4 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -12778,8 +12778,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
@@ -12780,8 +12780,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
return -EINVAL;

kvm->arch.vm_type = type;
Expand All @@ -91,5 +91,5 @@ index a9d992d5652f..b34236029383 100644
kvm->arch.pre_fault_allowed =
type == KVM_X86_DEFAULT_VM || type == KVM_X86_SW_PROTECTED_VM;
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From c16d4a48f6fbad7bdb9024c1c91c38b6d9bdc4e8 Mon Sep 17 00:00:00 2001
From a56ba2f9a2ec7436126f23997e502543e0e4bbe0 Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:31 +0100
Subject: [PATCH 05/45] KVM: Rename kvm_slot_can_be_private() to
Date: Tue, 15 Jul 2025 10:33:34 +0100
Subject: [PATCH 05/46] KVM: Rename kvm_slot_can_be_private() to
kvm_slot_has_gmem()

Rename kvm_slot_can_be_private() to kvm_slot_has_gmem() to improve
Expand Down Expand Up @@ -54,10 +54,10 @@ index 4e06e2e89a8f..213904daf1e5 100644
return -EFAULT;
}
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 459c3b791fd4..ade7a5b36c68 100644
index b201f77fcd49..687392c5bf5d 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2319,7 +2319,7 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
@@ -2323,7 +2323,7 @@ static int snp_launch_update(struct kvm *kvm, struct kvm_sev_cmd *argp)
mutex_lock(&kvm->slots_lock);

memslot = gfn_to_memslot(kvm, params.gfn_start);
Expand All @@ -66,7 +66,7 @@ index 459c3b791fd4..ade7a5b36c68 100644
ret = -EINVAL;
goto out;
}
@@ -4670,7 +4670,7 @@ void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code)
@@ -4678,7 +4678,7 @@ void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code)
}

slot = gfn_to_memslot(kvm, gfn);
Expand Down Expand Up @@ -102,5 +102,5 @@ index befea51bbc75..6db515833f61 100644

file = kvm_gmem_get_file(slot);
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 4e0120bc233422b398683f708873242163972916 Mon Sep 17 00:00:00 2001
From ffbe742826fa64c4af474398ce274b58338f3e48 Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:32 +0100
Subject: [PATCH 06/45] KVM: Fix comments that refer to slots_lock
Date: Tue, 15 Jul 2025 10:33:35 +0100
Subject: [PATCH 06/46] KVM: Fix comments that refer to slots_lock

Fix comments so that they refer to slots_lock instead of slots_locks
(remove trailing s).
Expand Down Expand Up @@ -31,7 +31,7 @@ index ed00c2b40e4b..9c654dfb6dce 100644
#endif
char stats_id[KVM_STATS_NAME_SIZE];
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index afbc025ce4d3..81bb18fa8655 100644
index 162e2a69cc49..46bddac1dacd 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -331,7 +331,7 @@ void kvm_flush_remote_tlbs_memslot(struct kvm *kvm,
Expand All @@ -44,5 +44,5 @@ index afbc025ce4d3..81bb18fa8655 100644
*/
lockdep_assert_held(&kvm->slots_lock);
--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From b9cc809ebdf2e73ebdd42300d3d1b0702aed3d21 Mon Sep 17 00:00:00 2001
From 2b0fd6a86bfa830aee045aaab2cd21616ee2df7d Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:33 +0100
Subject: [PATCH 07/45] KVM: Fix comment that refers to kvm uapi header path
Date: Tue, 15 Jul 2025 10:33:36 +0100
Subject: [PATCH 07/46] KVM: Fix comment that refers to kvm uapi header path

The comment that points to the path where the user-visible memslot flags
are refers to an outdated path and has a typo.
Expand Down Expand Up @@ -31,5 +31,5 @@ index 9c654dfb6dce..1ec71648824c 100644
#define KVM_MEMSLOT_INVALID (1UL << 16)

--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 58c6400113b15dce2c25f61927c0572e85c497c4 Mon Sep 17 00:00:00 2001
From 86e455716787a2e9361fb48458d38f5731e8666c Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:34 +0100
Subject: [PATCH 08/45] KVM: guest_memfd: Allow host to map guest_memfd pages
Date: Tue, 15 Jul 2025 10:33:37 +0100
Subject: [PATCH 08/46] KVM: guest_memfd: Allow host to map guest_memfd pages

Introduce the core infrastructure to enable host userspace to mmap()
guest_memfd-backed memory. This is needed for several evolving KVM use
Expand Down Expand Up @@ -96,10 +96,10 @@ index 1ec71648824c..9ac21985f3b5 100644
static inline bool kvm_arch_has_readonly_mem(struct kvm *kvm)
{
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 37891580d05d..c71348db818f 100644
index 7a4c35ff03fe..3beafbf306af 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -1592,6 +1592,7 @@ struct kvm_memory_attributes {
@@ -1596,6 +1596,7 @@ struct kvm_memory_attributes {
#define KVM_MEMORY_ATTRIBUTE_PRIVATE (1ULL << 3)

#define KVM_CREATE_GUEST_MEMFD _IOWR(KVMIO, 0xd4, struct kvm_create_guest_memfd)
Expand Down Expand Up @@ -212,5 +212,5 @@ index 6db515833f61..07a4b165471d 100644
return -EINVAL;

--
2.49.0
2.50.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e841f1cf86506f567df73da1a9429fe8586f90a5 Mon Sep 17 00:00:00 2001
From 09759854a3fbd70fc5c8c1f44da8c11c12cd3ac2 Mon Sep 17 00:00:00 2001
From: Fuad Tabba <[email protected]>
Date: Wed, 9 Jul 2025 11:59:35 +0100
Subject: [PATCH 09/45] KVM: guest_memfd: Track guest_memfd mmap support in
Date: Tue, 15 Jul 2025 10:33:38 +0100
Subject: [PATCH 09/46] KVM: guest_memfd: Track guest_memfd mmap support in
memslot

Add a new internal flag, KVM_MEMSLOT_GMEM_ONLY, to the top half of
Expand All @@ -16,6 +16,7 @@ information directly in the memslot, we reduce overhead and simplify the
logic involved in handling guest_memfd-backed pages for host mappings.

Reviewed-by: Gavin Shan <[email protected]>
Reviewed-by: Shivank Garg <[email protected]>
Acked-by: David Hildenbrand <[email protected]>
Suggested-by: David Hildenbrand <[email protected]>
Signed-off-by: Fuad Tabba <[email protected]>
Expand Down Expand Up @@ -67,5 +68,5 @@ index 07a4b165471d..2b00f8796a15 100644
xa_store_range(&gmem->bindings, start, end - 1, slot, GFP_KERNEL);
filemap_invalidate_unlock(inode->i_mapping);
--
2.49.0
2.50.1

Loading