From: Peter Xu <peterx@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Michael Roth <michael.roth@amd.com>,
qemu-devel@nongnu.org, jmarcin@redhat.com, david@kernel.org,
pbonzini@redhat.com, chenyi.qiang@intel.com, farosas@suse.de,
aik@amd.com, xiaoyao.li@intel.com
Subject: Re: [PATCH v4 08/12] hostmem: Support fully shared guest memfd to back a VM
Date: Mon, 17 Aug 2026 09:01:43 -0400 [thread overview]
Message-ID: <aoMGNz9AdOnDQkKE@x1.local> (raw)
In-Reply-To: <an8yCp9qZ498aLu2@redhat.com>
On Fri, Aug 14, 2026 at 04:19:38PM +0100, Daniel P. Berrangé wrote:
> On Thu, Aug 13, 2026 at 10:06:17AM -0400, Peter Xu wrote:
> > On Thu, Aug 13, 2026 at 01:48:21PM +0100, Daniel P. Berrangé wrote:
> > > On Thu, Aug 13, 2026 at 08:28:24AM -0400, Peter Xu wrote:
> > > > On Thu, Aug 13, 2026 at 09:24:22AM +0100, Daniel P. Berrangé wrote:
> > > > > On Wed, Aug 12, 2026 at 03:16:46PM -0500, Michael Roth wrote:
> > > > > > From: Peter Xu <peterx@redhat.com>
> > > > > >
> > > > > > Host backends supports guest-memfd now by detecting whether it's a
> > > > > > confidential VM. There's no way to choose it yet from the memory level to
> > > > > > use it fully shared. If we use guest-memfd, it so far always implies we
> > > > > > need two layers of memory backends, while the guest-memfd only provides the
> > > > > > private set of pages.
> > > > > >
> > > > > > This patch introduces a way so that QEMU can consume guest memfd as the
> > > > > > only source of memory to back the object (aka, fully shared).
> > > > > >
> > > > > > To use the fully shared guest-memfd, one can add a memfd object with:
> > > > > >
> > > > > > -object memory-backend-memfd,guest-memfd=on,share=on
> > > > > >
> > > > > > Note that share=on is required with fully shared guest_memfd.
> > > > > >
> > > > > > PS: there's a trivial touch-up on fd<0 check, because the stub to create
> > > > > > guest-memfd may return negative but not -1.
> > > > > >
> > > > > > Signed-off-by: Peter Xu <peterx@redhat.com>
> > > > > > Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
> > > > > > Reviewed-by: Fabiano Rosas <farosas@suse.de>
> > > > > > Signed-off-by: Michael Roth <michael.roth@amd.com>
> > > > > > ---
> > > > > > backends/hostmem-memfd.c | 56 ++++++++++++++++++++++++++++++++++++----
> > > > > > qapi/qom.json | 6 ++++-
> > > > > > 2 files changed, 56 insertions(+), 6 deletions(-)
>
> snip
>
> > > > > "memory-backend-memfd,guest-memfd=on|off" is switching between two
> > > > > separate implementations of the class.
> > > > >
> > > > > This whole thing is just shouting "use a different class".
> > > > >
> > > > > There is no meaningful sharing of code here, and the sharing of the
> > > > > public interface is offering apps no value as the impl prevents them
> > > > > from choosing the value of the properties - they have to be set of
> > > > > certain values which are not introspectable.
> > > > >
> > > > > Please introduce a "memory-backend-guest-memfd" backend instead.
> > > >
> > > > This is indeed what Michael used to suggest, and we were discussing in
> > > > previous version on which is better,
> > > >
> > > > https://lore.kernel.org/r/rjqfiwh57gip3u3psqg33jhmo7ixaj2qwzupc7zdk7f3d26qnu@tglactz67ogk
> > > >
> > > > The hope is this is also easier for either libvirt or most users, but
> > > > please correct me if it's not the case, especially for libvirt. The plan
> > > > is when CoCo flags are provided, all things will automatically switch to a
> > > > CoCo-friendly implementation within QEMU.
> > > >
> > > > It also means here the guest-memfd= parameter shouldn't be needed in real
> > > > CoCo contexts because they'll simply be implied (no cmdline change needed
> > > > for the same "-object memory-backend-memfd" one used to use without CoCo).
> > > > It's only needed for only special use of guest-memfd, in this case
> > > > init-shared is the special case where CoCo doesn't use.
> > >
> > > Reading all this, IMHO reusing memory-backend-memfd for the current
> > > Coco support was a design mistake, it should have have a
> > > memory-backend-guest-memfd object from the start.
> > >
> > > Given that we need to be able to control memfd vs guest-memfd for
> > > the non-Coco case, it is still worth introducing the new object
> > > class today.
> > >
> > > Even if the two classes shared all their properties (which they
> > > don't given the comment about 'seal' being always on), then a
> > > "foo=on|off" that toggles two separate impls is still creating
> > > a pair of sub-classes by the backdoor.
> >
> > The idea of that, at least in my mind.. is an user shouldn't need to worry
> > about differences of guest-memfd and memfd, QEMU should just do it for the
> > users, based on the machine configurations. Memfd is a concept more widely
> > spread, the hope is anyone using guest-memfd should simply treat it as one
> > memfd, no matter it is shared, in-place converted, two-layer-backed, or
> > whatever is happening underneath.
> >
> > Now we do create guest-memfd via a separate ioctl, what if we can create it
> > via memfd_create() syscall too? Then do we need to do the separation from
> > QEMU layer?
>
> If QEMU automatically did "the right thing" choosing between traditional
> memfd and guest-memfd, then I wouldn't have even started this thread :-)
>
> The "guest-memfd=on|off" is the trigger that made me think the design
> was wrong from a public interface POV, as that explicitly says that the
> memfd vs guest-memfd distinction is not automatic - it requires the
> mgmt app to understand it and choose between them.
>
> > IMHO that is now an ioctl is not required; it really can be part of
> > memfd_create() syscall, it's just easier to manage, e.g. it's completely
> > KVM alone, and it also has attached to the KVM instance. The idea is still
> > similar, and we can see that from possibly shared properties here on huge
> > pages and so. I don't treat seal= a block just to introduce a new object
> > for that, and I expect as gmemfd evolves it will gradually get most
> > features memfd supports.. like folio migration and so.. but I could be
> > wrong.
> >
> > IMHO one major question to ask is, is it more convenient for libvirt to
> > have that new object? Please keep in mind that after we introduce this as
> > a new object, we may start to introduce even more *-guest-memfd in the
> > future, we roughly talked about DAX in the previous discussion. My goal is
> > to make it most convenient for either user or libvirt to maintain the
> > cmdlines for QEMU, but if you think that makes libvirt live harder instead,
> > I've no strong feeling to go back to what Michael initially suggested.
>
> It is no more or less difficult for libvirt to use different object
> types vs using different guest-memfd=bool values.
>
> What makes a difference for libvirt is understanding whether QEMU
> implements a given feature or not.
>
> If we have the situation with
>
> memory-backend-memfd,hugetlb=bool,guest-memfd=bool
>
> with this series, IIUC, libvirt can introspect to see the new
> guest-memfd property, but it has no way of knowing that it can't
> use the hugetlb proeprty when guest-memfd=on
>
> If the next QEMU release now permits hugetlb=on at the same time
> as guest-memfd=on, then libvirt has no way to know the restriction
> was relaxed.
>
> The QAPI introspection data for memory-backend-memfd is identical
> in both cases.
>
> To deal with this, you need to introduce a workaround to QAPI
> by declaring a feature flag like
>
> features: ['hugetlb-with-guest-memfd-works']
>
> that libvirt can probe for to determine the functional improvement
> in QEMU.
>
> By comparison, if we introduce a memory-backend-guest-memfd
> object today, then it will omit the hugetlb property entirely.
>
> If the next QEMU release adds a hugetlb property to the
> memory-backend-guest-memfd object, this change is now visible
> in the introspection data, and thus libvirt knows that combo
> is possible with QEMU
>
> (yes, there is the issue that this might have kernel dependancy
> that is not visible from QEMU's introspection, so not perfect,
> but at least libvirt can determine what QEMU is capable of)
Yes. Due to that, I was expecting Libvirt will always need to query host
capabilities on its own. In this case Libvirt, if preferred, should also
be able to probe standalone with KVM_CAP_GUEST_MEMFD_FLAGS.
It's also more involved for sure when hugetlb is involved, if it will share
the same hugetlb reservation with hugetlbfs, it'll also somehow need to
make sure there're available pages later for allocations. Also IIUC not
all default users are accessible to huge pages..
From QEMU's POV, personally I still prefer sticking with the memfd object
with guest-memfd=on, then expose the "features" in QAPI, that seems cleaner
to me.
>
>
> > For example, if libvirt wants to detect hugetlb supports for an object, it
> > can still pass in the parameters and test-boot a QEMU and then IIUC it'll
> > still correctly capture an error for gmemfd case. It might be that I
> > didn't really get what will make libvirt complex by reusing the object, but
> > I'll definitely follow your judgement on that.
>
> Trying parameters to see if they fail and then boot again with different
> options is not a viable approach. That is an indication that QEMU's
> design and/or introspection is flawed.
It'll be the same when introducing the new -guest-memfd object per above
complications, IMHO. I'm not sure how hugetlbfs pages were managed now
with Libvirt, maybe that can help us understand how guest-memfd (when
hugetlb pages will be supported) will affect Libvirt's mgmt. For now, it
doesn't seem to me that the new object will help in anyway, if we have
QEMU's "features" option.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2026-08-17 13:02 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 20:16 [PATCH v4 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends Michael Roth
2026-08-12 20:16 ` [PATCH v4 01/12] kvm: Decouple memory attribute check from kvm_guest_memfd_supported Michael Roth
2026-08-12 20:16 ` [PATCH v4 02/12] kvm: Detect guest-memfd flags supported Michael Roth
2026-08-12 20:16 ` [PATCH v4 03/12] kvm: Provide explicit error for kvm_create_guest_memfd() Michael Roth
2026-08-14 5:56 ` Philippe Mathieu-Daudé
2026-08-14 12:44 ` Peter Xu
2026-08-17 4:05 ` Philippe Mathieu-Daudé
2026-08-17 12:44 ` Peter Xu
2026-08-17 15:05 ` Philippe Mathieu-Daudé
2026-08-12 20:16 ` [PATCH v4 04/12] ramblock: Rename guest_memfd to guest_memfd_private Michael Roth
2026-08-12 20:16 ` [PATCH v4 05/12] memory: Rename RAM_GUEST_MEMFD to RAM_GUEST_MEMFD_PRIVATE Michael Roth
2026-08-12 20:16 ` [PATCH v4 06/12] memory: Rename memory_region_has_guest_memfd() to *_private() Michael Roth
2026-08-12 20:16 ` [PATCH v4 07/12] hostmem: Rename guest_memfd to guest_memfd_private Michael Roth
2026-08-12 20:16 ` [PATCH v4 08/12] hostmem: Support fully shared guest memfd to back a VM Michael Roth
2026-08-13 8:24 ` Daniel P. Berrangé
2026-08-13 12:28 ` Peter Xu
2026-08-13 12:48 ` Daniel P. Berrangé
2026-08-13 14:06 ` Peter Xu
2026-08-14 15:19 ` Daniel P. Berrangé
2026-08-17 13:01 ` Peter Xu [this message]
2026-08-13 22:10 ` Michael Roth via qemu development
2026-08-14 15:27 ` Daniel P. Berrangé
2026-08-17 13:43 ` Peter Xu
2026-08-12 20:16 ` [PATCH v4 09/12] machine: Rename machine_require_guest_memfd() to *_private() Michael Roth
2026-08-12 20:16 ` [PATCH v4 10/12] memory: Rename memory_region_init_ram_guest_memfd() " Michael Roth
2026-08-12 20:16 ` [PATCH v4 11/12] tests/migration-test: Support guest-memfd init shared mem type Michael Roth
2026-08-12 20:16 ` [PATCH v4 12/12] tests/migration-test: Add a precopy test for guest-memfd Michael Roth
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=aoMGNz9AdOnDQkKE@x1.local \
--to=peterx@redhat.com \
--cc=aik@amd.com \
--cc=berrange@redhat.com \
--cc=chenyi.qiang@intel.com \
--cc=david@kernel.org \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=michael.roth@amd.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 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.