From: Fuad Tabba <tabba@google.com>
To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org
Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au,
anup@brainfault.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com,
viro@zeniv.linux.org.uk, brauner@kernel.org,
willy@infradead.org, akpm@linux-foundation.org,
xiaoyao.li@intel.com, yilun.xu@intel.com,
chao.p.peng@linux.intel.com, jarkko@kernel.org,
amoorthy@google.com, dmatlack@google.com,
isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz,
vannapurve@google.com, ackerleytng@google.com,
mail@maciej.szmigiero.name, david@redhat.com,
michael.roth@amd.com, wei.w.wang@intel.com,
liam.merwick@oracle.com, isaku.yamahata@gmail.com,
kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com,
steven.price@arm.com, quic_eberman@quicinc.com,
quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com,
quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com,
quic_pderrin@quicinc.com, quic_pheragu@quicinc.com,
catalin.marinas@arm.com, james.morse@arm.com,
yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org,
will@kernel.org, qperret@google.com, keirf@google.com,
roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org,
jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com,
fvdl@google.com, hughd@google.com, jthoughton@google.com,
peterx@redhat.com, pankaj.gupta@amd.com, ira.weiny@intel.com,
tabba@google.com
Subject: [PATCH v10 15/16] KVM: Introduce the KVM capability KVM_CAP_GMEM_SHARED_MEM
Date: Tue, 27 May 2025 19:02:44 +0100 [thread overview]
Message-ID: <20250527180245.1413463-16-tabba@google.com> (raw)
In-Reply-To: <20250527180245.1413463-1-tabba@google.com>
This patch introduces the KVM capability KVM_CAP_GMEM_SHARED_MEM, which
indicates that guest_memfd supports shared memory (when enabled by the
flag). This support is limited to certain VM types, determined per
architecture.
This patch also updates the KVM documentation with details on the new
capability, flag, and other information about support for shared memory
in guest_memfd.
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Fuad Tabba <tabba@google.com>
---
Documentation/virt/kvm/api.rst | 9 +++++++++
include/uapi/linux/kvm.h | 1 +
virt/kvm/kvm_main.c | 4 ++++
3 files changed, 14 insertions(+)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 47c7c3f92314..59f994a99481 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -6390,6 +6390,15 @@ most one mapping per page, i.e. binding multiple memory regions to a single
guest_memfd range is not allowed (any number of memory regions can be bound to
a single guest_memfd file, but the bound ranges must not overlap).
+When the capability KVM_CAP_GMEM_SHARED_MEM is supported, the 'flags' field
+supports GUEST_MEMFD_FLAG_SUPPORT_SHARED. Setting this flag on guest_memfd
+creation enables mmap() and faulting of guest_memfd memory to host userspace.
+
+When the KVM MMU performs a PFN lookup to service a guest fault and the backing
+guest_memfd has the GUEST_MEMFD_FLAG_SUPPORT_SHARED set, then the fault will
+always be consumed from guest_memfd, regardless of whether it is a shared or a
+private fault.
+
See KVM_SET_USER_MEMORY_REGION2 for additional details.
4.143 KVM_PRE_FAULT_MEMORY
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index c2714c9d1a0e..5aa85d34a29a 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -930,6 +930,7 @@ struct kvm_enable_cap {
#define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237
#define KVM_CAP_X86_GUEST_MODE 238
#define KVM_CAP_ARM_WRITABLE_IMP_ID_REGS 239
+#define KVM_CAP_GMEM_SHARED_MEM 240
struct kvm_irq_routing_irqchip {
__u32 irqchip;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 6289ea1685dd..64ed4da70d2f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4845,6 +4845,10 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
#ifdef CONFIG_KVM_GMEM
case KVM_CAP_GUEST_MEMFD:
return !kvm || kvm_arch_supports_gmem(kvm);
+#endif
+#ifdef CONFIG_KVM_GMEM_SHARED_MEM
+ case KVM_CAP_GMEM_SHARED_MEM:
+ return !kvm || kvm_arch_supports_gmem_shared_mem(kvm);
#endif
default:
break;
--
2.49.0.1164.gab81da1b16-goog
next prev parent reply other threads:[~2025-05-27 18:03 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 18:02 [PATCH v10 00/16] KVM: Mapping guest_memfd backed memory at the host for software protected VMs Fuad Tabba
2025-05-27 18:02 ` [PATCH v10 01/16] KVM: Rename CONFIG_KVM_PRIVATE_MEM to CONFIG_KVM_GMEM Fuad Tabba
2025-05-31 19:05 ` Shivank Garg
2025-06-05 8:19 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 02/16] KVM: Rename CONFIG_KVM_GENERIC_PRIVATE_MEM to CONFIG_KVM_GENERIC_GMEM_POPULATE Fuad Tabba
2025-05-31 19:07 ` Shivank Garg
2025-06-05 8:19 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 03/16] KVM: Rename kvm_arch_has_private_mem() to kvm_arch_supports_gmem() Fuad Tabba
2025-05-31 19:12 ` Shivank Garg
2025-06-05 8:20 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 04/16] KVM: x86: Rename kvm->arch.has_private_mem to kvm->arch.supports_gmem Fuad Tabba
2025-05-31 19:13 ` Shivank Garg
2025-06-05 8:21 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 05/16] KVM: Rename kvm_slot_can_be_private() to kvm_slot_has_gmem() Fuad Tabba
2025-05-31 19:13 ` Shivank Garg
2025-06-05 8:22 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 06/16] KVM: Fix comments that refer to slots_lock Fuad Tabba
2025-05-31 19:14 ` Shivank Garg
2025-06-05 8:22 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 07/16] KVM: Fix comment that refers to kvm uapi header path Fuad Tabba
2025-05-31 19:19 ` Shivank Garg
2025-06-02 10:10 ` Fuad Tabba
2025-06-02 10:23 ` David Hildenbrand
2025-06-04 9:00 ` Gavin Shan
2025-06-05 8:22 ` Vlastimil Babka
2025-05-27 18:02 ` [PATCH v10 08/16] KVM: guest_memfd: Allow host to map guest_memfd pages Fuad Tabba
2025-05-28 23:17 ` kernel test robot
2025-06-02 10:05 ` Fuad Tabba
2025-06-02 10:43 ` Shivank Garg
2025-06-02 11:13 ` Fuad Tabba
2025-06-04 6:02 ` Gavin Shan
2025-06-04 8:37 ` Fuad Tabba
2025-06-04 12:26 ` David Hildenbrand
2025-06-04 12:32 ` Fuad Tabba
2025-06-04 13:02 ` David Hildenbrand
2025-06-05 6:40 ` Gavin Shan
2025-06-05 8:25 ` Fuad Tabba
2025-06-05 9:53 ` Gavin Shan
2025-06-05 8:28 ` Vlastimil Babka
2025-06-05 8:44 ` Fuad Tabba
2025-05-27 18:02 ` [PATCH v10 09/16] KVM: guest_memfd: Track shared memory support in memslot Fuad Tabba
2025-06-04 12:25 ` David Hildenbrand
2025-06-04 12:31 ` Fuad Tabba
2025-05-27 18:02 ` [PATCH v10 10/16] KVM: x86/mmu: Handle guest page faults for guest_memfd with shared memory Fuad Tabba
2025-05-27 18:02 ` [PATCH v10 11/16] KVM: x86: Compute max_mapping_level with input from guest_memfd Fuad Tabba
2025-06-04 13:09 ` David Hildenbrand
2025-05-27 18:02 ` [PATCH v10 12/16] KVM: arm64: Refactor user_mem_abort() calculation of force_pte Fuad Tabba
2025-06-04 6:05 ` Gavin Shan
2025-05-27 18:02 ` [PATCH v10 13/16] KVM: arm64: Handle guest_memfd-backed guest page faults Fuad Tabba
2025-06-04 13:17 ` David Hildenbrand
2025-06-04 13:30 ` Fuad Tabba
2025-06-04 13:33 ` David Hildenbrand
2025-05-27 18:02 ` [PATCH v10 14/16] KVM: arm64: Enable mapping guest_memfd in arm64 Fuad Tabba
2025-06-04 13:17 ` David Hildenbrand
2025-06-04 13:31 ` Fuad Tabba
2025-05-27 18:02 ` Fuad Tabba [this message]
2025-06-05 9:59 ` [PATCH v10 15/16] KVM: Introduce the KVM capability KVM_CAP_GMEM_SHARED_MEM Gavin Shan
2025-05-27 18:02 ` [PATCH v10 16/16] KVM: selftests: guest_memfd mmap() test when mapping is allowed Fuad Tabba
2025-06-04 9:19 ` Gavin Shan
2025-06-04 9:48 ` Fuad Tabba
2025-06-04 10:05 ` Gavin Shan
2025-06-04 10:25 ` Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250527180245.1413463-16-tabba@google.com \
--to=tabba@google.com \
--cc=ackerleytng@google.com \
--cc=akpm@linux-foundation.org \
--cc=amoorthy@google.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=brauner@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=chao.p.peng@linux.intel.com \
--cc=chenhuacai@kernel.org \
--cc=david@redhat.com \
--cc=dmatlack@google.com \
--cc=fvdl@google.com \
--cc=hch@infradead.org \
--cc=hughd@google.com \
--cc=ira.weiny@intel.com \
--cc=isaku.yamahata@gmail.com \
--cc=isaku.yamahata@intel.com \
--cc=james.morse@arm.com \
--cc=jarkko@kernel.org \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=jthoughton@google.com \
--cc=keirf@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mail@maciej.szmigiero.name \
--cc=maz@kernel.org \
--cc=mic@digikod.net \
--cc=michael.roth@amd.com \
--cc=mpe@ellerman.id.au \
--cc=oliver.upton@linux.dev \
--cc=palmer@dabbelt.com \
--cc=pankaj.gupta@amd.com \
--cc=paul.walmsley@sifive.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qperret@google.com \
--cc=quic_cvanscha@quicinc.com \
--cc=quic_eberman@quicinc.com \
--cc=quic_mnalajal@quicinc.com \
--cc=quic_pderrin@quicinc.com \
--cc=quic_pheragu@quicinc.com \
--cc=quic_svaddagi@quicinc.com \
--cc=quic_tsoni@quicinc.com \
--cc=rientjes@google.com \
--cc=roypat@amazon.co.uk \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=steven.price@arm.com \
--cc=suzuki.poulose@arm.com \
--cc=vannapurve@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=wei.w.wang@intel.com \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=xiaoyao.li@intel.com \
--cc=yilun.xu@intel.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).