All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Roth <michael.roth@amd.com>
To: <qemu-devel@nongnu.org>
Cc: <pbonzini@redhat.com>, <berrange@redhat.com>, <armbru@redhat.com>,
	<pankaj.gupta@amd.com>, <isaku.yamahata@intel.com>,
	<xiaoyao.li@intel.com>, <chao.p.peng@linux.intel.com>,
	<david@kernel.org>, Peter Xu <peterx@redhat.com>,
	Fabiano Rosas <farosas@suse.de>
Subject: [PATCH v5 02/12] kvm: Detect guest-memfd flags supported
Date: Tue, 8 Sep 2026 08:30:52 -0500	[thread overview]
Message-ID: <20260908133151.836685-3-michael.roth@amd.com> (raw)
In-Reply-To: <20260908133151.836685-1-michael.roth@amd.com>

From: Peter Xu <peterx@redhat.com>

Detect supported guest-memfd flags by the current kernel, and reject
creations of guest-memfd using invalid flags.  When the cap isn't
available, then no flag is supported.

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
 accel/kvm/kvm-all.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index cdc7554082..120cab1e22 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -107,6 +107,7 @@ bool kvm_pre_fault_memory_supported;
 static bool kvm_immediate_exit;
 static uint64_t kvm_supported_memory_attributes;
 static bool kvm_guest_memfd_supported;
+static uint64_t kvm_guest_memfd_flags_supported;
 static hwaddr kvm_max_slot_size = ~0;
 
 static const KVMCapabilityInfo kvm_required_capabilities[] = {
@@ -3065,6 +3066,8 @@ static int kvm_init(AccelState *as, MachineState *ms)
         kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD) &&
         kvm_vm_check_extension(s, KVM_CAP_USER_MEMORY2);
     kvm_pre_fault_memory_supported = kvm_vm_check_extension(s, KVM_CAP_PRE_FAULT_MEMORY);
+    kvm_guest_memfd_flags_supported =
+        kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD_FLAGS);
 
     if (s->kernel_irqchip_split == ON_OFF_AUTO_AUTO) {
         s->kernel_irqchip_split = mc->default_kernel_irqchip_split ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
@@ -4760,6 +4763,13 @@ int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp)
         return -1;
     }
 
+    if (flags & ~kvm_guest_memfd_flags_supported) {
+        error_setg(errp, "Current KVM instance does not support "
+                   "guest-memfd flag: 0x%"PRIx64,
+                   flags & ~kvm_guest_memfd_flags_supported);
+        return -1;
+    }
+
     fd = kvm_vm_ioctl(kvm_state, KVM_CREATE_GUEST_MEMFD, &guest_memfd);
     if (fd < 0) {
         error_setg_errno(errp, errno, "Error creating KVM guest_memfd");
-- 
2.43.0



  parent reply	other threads:[~2026-09-08 13:34 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 13:30 [PATCH v5 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends Michael Roth
2026-09-08 13:30 ` [PATCH v5 01/12] kvm: Decouple memory attribute check from kvm_guest_memfd_supported Michael Roth
2026-09-10  8:47   ` David Hildenbrand
2026-09-08 13:30 ` Michael Roth [this message]
2026-09-08 13:30 ` [PATCH v5 03/12] kvm: Provide explicit error for kvm_create_guest_memfd() Michael Roth
2026-09-10  8:48   ` David Hildenbrand
2026-09-08 13:30 ` [PATCH v5 04/12] ramblock: Rename guest_memfd to guest_memfd_private Michael Roth
2026-09-10  8:49   ` David Hildenbrand
2026-09-08 13:30 ` [PATCH v5 05/12] memory: Rename RAM_GUEST_MEMFD to RAM_GUEST_MEMFD_PRIVATE Michael Roth
2026-09-10  8:50   ` David Hildenbrand
2026-09-08 13:30 ` [PATCH v5 06/12] memory: Rename memory_region_has_guest_memfd() to *_private() Michael Roth
2026-09-10  8:50   ` David Hildenbrand
2026-09-08 13:30 ` [PATCH v5 07/12] hostmem: Rename guest_memfd to guest_memfd_private Michael Roth
2026-09-10  8:51   ` David Hildenbrand
2026-09-08 13:30 ` [PATCH v5 08/12] hostmem: Support fully shared guest memfd to back a VM Michael Roth
2026-09-08 14:03   ` Markus Armbruster
2026-09-10 22:58     ` Michael Roth
2026-09-11  5:56       ` Markus Armbruster
2026-09-11 19:22         ` Michael Roth
2026-09-10  8:54   ` David Hildenbrand
2026-09-10 23:00     ` Michael Roth
2026-09-11 12:06       ` Peter Xu
2026-09-11 16:00         ` David Hildenbrand (Arm)
2026-09-08 13:30 ` [PATCH v5 09/12] machine: Rename machine_require_guest_memfd() to *_private() Michael Roth
2026-09-10  8:55   ` David Hildenbrand
2026-09-10 23:08     ` Michael Roth
2026-09-11 10:48       ` David Hildenbrand (Arm)
2026-09-11 19:27         ` Michael Roth
2026-09-08 13:31 ` [PATCH v5 10/12] memory: Rename memory_region_init_ram_guest_memfd() " Michael Roth
2026-09-10  8:56   ` David Hildenbrand
2026-09-08 13:31 ` [PATCH v5 11/12] tests/migration-test: Support guest-memfd init shared mem type Michael Roth
2026-09-08 13:31 ` [PATCH v5 12/12] tests/migration-test: Add a precopy test for guest-memfd Michael Roth
2026-09-10  8:45 ` [PATCH v5 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends David Hildenbrand

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=20260908133151.836685-3-michael.roth@amd.com \
    --to=michael.roth@amd.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=chao.p.peng@linux.intel.com \
    --cc=david@kernel.org \
    --cc=farosas@suse.de \
    --cc=isaku.yamahata@intel.com \
    --cc=pankaj.gupta@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xiaoyao.li@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.