qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Xiaoyao Li <xiaoyao.li@intel.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	David Hildenbrand <david@redhat.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Chenyi Qiang <chenyi.qiang@intel.com>,
	Juraj Marcin <jmarcin@redhat.com>,
	Fabiano Rosas <farosas@suse.de>
Subject: Re: [PATCH v2 2/9] kvm: Detect guest-memfd flags supported
Date: Fri, 12 Dec 2025 12:23:18 -0500	[thread overview]
Message-ID: <aTxPhhvS2FiW3cgK@x1.local> (raw)
In-Reply-To: <a958f847-78fc-4743-80bb-49aae5f37bcf@intel.com>

On Fri, Dec 12, 2025 at 11:10:23AM +0800, Xiaoyao Li wrote:
> On 11/20/2025 1:29 AM, Peter Xu wrote:
> > 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.
> > 
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >   accel/kvm/kvm-all.c | 11 +++++++++++
> >   1 file changed, 11 insertions(+)
> > 
> > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> > index 96c194ce54..f477014126 100644
> > --- a/accel/kvm/kvm-all.c
> > +++ b/accel/kvm/kvm-all.c
> > @@ -108,6 +108,7 @@ static int kvm_sstep_flags;
> >   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_capabilites[] = {
> > @@ -2787,6 +2788,10 @@ static int kvm_init(AccelState *as, MachineState *ms)
> >       kvm_guest_memfd_supported =
> >           kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD) &&
> >           kvm_vm_check_extension(s, KVM_CAP_USER_MEMORY2);
> > +
> > +    ret = kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD_FLAGS);
> > +    kvm_guest_memfd_flags_supported = ret > 0 ? ret : 0;
> > +
> >       kvm_pre_fault_memory_supported = kvm_vm_check_extension(s, KVM_CAP_PRE_FAULT_MEMORY);
> >       if (s->kernel_irqchip_split == ON_OFF_AUTO_AUTO) {
> > @@ -4492,6 +4497,12 @@ 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, "KVM does not support guest-memfd flag: 0x%"PRIx64,
> 
> I'm thinking if need to add "for current VM" like:
> 
> 	KVM does not support guest-memfd flag: xxx for current VM
> 
> because kvm_guest_memfd_flags_supported is got from VM-scope CAP and varies
> for different VM types.

Sure I can amend it.  Though I plan to change the sentence slightly:

     if (flags & ~kvm_guest_memfd_flags_supported) {
-        error_setg(errp, "KVM does not support guest-memfd flag: 0x%"PRIx64,
+        error_setg(errp, "Current KVM instance does not support "
+                   "guest-memfd flag: 0x%"PRIx64,
                    flags & ~kvm_guest_memfd_flags_supported);
         return -1;
     }

Thanks,

> 
> > +                   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");
> 

-- 
Peter Xu



  reply	other threads:[~2025-12-12 17:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-19 17:29 [PATCH v2 0/9] KVM/hostmem: Support init-shared guest-memfd as VM backends Peter Xu
2025-11-19 17:29 ` [PATCH v2 1/9] kvm: Decouple memory attribute check from kvm_guest_memfd_supported Peter Xu
2025-11-19 17:29 ` [PATCH v2 2/9] kvm: Detect guest-memfd flags supported Peter Xu
2025-12-11  6:56   ` Xiaoyao Li
2025-12-12  3:10   ` Xiaoyao Li
2025-12-12 17:23     ` Peter Xu [this message]
2025-11-19 17:29 ` [PATCH v2 3/9] memory: Rename RAM_GUEST_MEMFD to RAM_GUEST_MEMFD_PRIVATE Peter Xu
2025-12-11  7:05   ` Xiaoyao Li
2025-11-19 17:29 ` [PATCH v2 4/9] memory: Rename memory_region_has_guest_memfd() to *_private() Peter Xu
2025-12-11  7:10   ` Xiaoyao Li
2025-12-11 15:45     ` Peter Xu
2025-11-19 17:29 ` [PATCH v2 5/9] ramblock: Rename guest_memfd to guest_memfd_private Peter Xu
2025-12-11  7:10   ` Xiaoyao Li
2025-11-19 17:29 ` [PATCH v2 6/9] hostmem: " Peter Xu
2025-12-11  7:16   ` Xiaoyao Li
2025-12-11 16:15     ` Peter Xu
2025-11-19 17:29 ` [PATCH v2 7/9] hostmem: Support in-place guest memfd to back a VM Peter Xu
2025-12-11  7:41   ` Xiaoyao Li
2025-12-11 16:27     ` Peter Xu
2025-12-12  3:05       ` Xiaoyao Li
2025-12-12 17:41         ` Peter Xu
2025-11-19 17:29 ` [PATCH v2 8/9] tests/migration-test: Support guest-memfd init shared mem type Peter Xu
2025-11-19 17:29 ` [PATCH v2 9/9] tests/migration-test: Add a precopy test for guest-memfd Peter Xu

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=aTxPhhvS2FiW3cgK@x1.local \
    --to=peterx@redhat.com \
    --cc=aik@amd.com \
    --cc=chenyi.qiang@intel.com \
    --cc=david@redhat.com \
    --cc=farosas@suse.de \
    --cc=jmarcin@redhat.com \
    --cc=pbonzini@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 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).