From: Peter Xu <peterx@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org, Juraj Marcin <jmarcin@redhat.com>,
David Hildenbrand <david@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Chenyi Qiang <chenyi.qiang@intel.com>,
Alexey Kardashevskiy <aik@amd.com>,
Li Xiaoyao <xiaoyao.li@intel.com>
Subject: Re: [PATCH v3 01/12] kvm: Decouple memory attribute check from kvm_guest_memfd_supported
Date: Tue, 23 Dec 2025 12:02:55 -0500 [thread overview]
Message-ID: <aUrLP3i-SWftPpWA@x1.local> (raw)
In-Reply-To: <87345a354v.fsf@suse.de>
On Tue, Dec 16, 2025 at 10:53:04AM -0300, Fabiano Rosas wrote:
> Peter Xu <peterx@redhat.com> writes:
>
> > From: Xiaoyao Li <xiaoyao.li@intel.com>
> >
> > With the mmap support of guest memfd, KVM allows usersapce to create
> > guest memfd serving as normal non-private memory for X86 DEFEAULT VM.
> > However, KVM doesn't support private memory attriute for X86 DEFAULT
> > VM.
> >
> > Make kvm_guest_memfd_supported not rely on KVM_MEMORY_ATTRIBUTE_PRIVATE
> > and check KVM_MEMORY_ATTRIBUTE_PRIVATE separately when the machine
> > requires guest_memfd to serve as private memory.
> >
> > This allows QMEU to create guest memfd with mmap to serve as the memory
> > backend for X86 DEFAULT VM.
> >
> > Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > include/system/kvm.h | 1 +
> > accel/kvm/kvm-all.c | 8 ++++++--
> > accel/stubs/kvm-stub.c | 5 +++++
> > system/physmem.c | 8 ++++++++
> > 4 files changed, 20 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/system/kvm.h b/include/system/kvm.h
> > index 8f9eecf044..b5811c90f1 100644
> > --- a/include/system/kvm.h
> > +++ b/include/system/kvm.h
> > @@ -561,6 +561,7 @@ int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp);
> >
> > int kvm_set_memory_attributes_private(hwaddr start, uint64_t size);
> > int kvm_set_memory_attributes_shared(hwaddr start, uint64_t size);
> > +bool kvm_private_memory_attribute_supported(void);
> >
> > int kvm_convert_memory(hwaddr start, hwaddr size, bool to_private);
> >
> > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> > index 28006d73c5..59836ebdff 100644
> > --- a/accel/kvm/kvm-all.c
> > +++ b/accel/kvm/kvm-all.c
> > @@ -1501,6 +1501,11 @@ int kvm_set_memory_attributes_shared(hwaddr start, uint64_t size)
> > return kvm_set_memory_attributes(start, size, 0);
> > }
> >
> > +bool kvm_private_memory_attribute_supported(void)
> > +{
> > + return !!(kvm_supported_memory_attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE);
> > +}
> > +
> > /* Called with KVMMemoryListener.slots_lock held */
> > static void kvm_set_phys_mem(KVMMemoryListener *kml,
> > MemoryRegionSection *section, bool add)
> > @@ -2781,8 +2786,7 @@ static int kvm_init(AccelState *as, MachineState *ms)
> > kvm_supported_memory_attributes = kvm_vm_check_extension(s, KVM_CAP_MEMORY_ATTRIBUTES);
> > kvm_guest_memfd_supported =
> > kvm_vm_check_extension(s, KVM_CAP_GUEST_MEMFD) &&
> > - kvm_vm_check_extension(s, KVM_CAP_USER_MEMORY2) &&
> > - (kvm_supported_memory_attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE);
> > + kvm_vm_check_extension(s, KVM_CAP_USER_MEMORY2);
> > kvm_pre_fault_memory_supported = kvm_vm_check_extension(s, KVM_CAP_PRE_FAULT_MEMORY);
> >
> > if (s->kernel_irqchip_split == ON_OFF_AUTO_AUTO) {
> > diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c
> > index 68cd33ba97..73f04eb589 100644
> > --- a/accel/stubs/kvm-stub.c
> > +++ b/accel/stubs/kvm-stub.c
> > @@ -125,3 +125,8 @@ int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp)
> > {
> > return -ENOSYS;
> > }
> > +
> > +bool kvm_private_memory_attribute_supported(void)
> > +{
> > + return false;
> > +}
> > diff --git a/system/physmem.c b/system/physmem.c
> > index c9869e4049..3555d2f6f7 100644
> > --- a/system/physmem.c
> > +++ b/system/physmem.c
> > @@ -2211,6 +2211,14 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
> > object_get_typename(OBJECT(current_machine->cgs)));
> > goto out_free;
> > }
> > +
> > + if (!kvm_private_memory_attribute_supported()) {
> > + error_setg(errp, "cannot set up private guest memory for %s: "
> > + " KVM does not support private memory attribute",
> > + object_get_typename(OBJECT(current_machine->cgs)));
> > + goto out_free;
> > + }
>
> Hm, it took me a while to understand why this is under (new_block->flags
> & RAM_GUEST_MEMFD) but checking for private memory support. If it's at
> all feasible I would just squash all those patches doing
> s/guest_memfd/guest_memfd_private/ to avoid having intermediate patches
> where the terminology is not aligned.
Yeah, the hope is it'll stop being confusing after this series applied.
Keeping them separate is logically more sensible, not only to make review
easier, but the rule that each commit should be self contained and also
minimum..
>
> Anyway, up to you. For this one:
>
> Reviewed-by: Fabiano Rosas <farosas@suse.de>
Thanks!
--
Peter Xu
next prev parent reply other threads:[~2025-12-23 17:04 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-15 20:51 [PATCH v3 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends Peter Xu
2025-12-15 20:51 ` [PATCH v3 01/12] kvm: Decouple memory attribute check from kvm_guest_memfd_supported Peter Xu
2025-12-16 12:41 ` Xiaoyao Li
2025-12-23 16:56 ` Peter Xu
2025-12-16 13:53 ` Fabiano Rosas
2025-12-23 17:02 ` Peter Xu [this message]
2026-06-02 1:10 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 02/12] kvm: Detect guest-memfd flags supported Peter Xu
2025-12-16 13:54 ` Fabiano Rosas
2026-06-02 1:29 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 03/12] kvm: Provide explicit error for kvm_create_guest_memfd() Peter Xu
2025-12-16 4:03 ` Xiaoyao Li
2025-12-16 13:55 ` Fabiano Rosas
2026-06-02 1:31 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 04/12] ramblock: Rename guest_memfd to guest_memfd_private Peter Xu
2026-06-02 1:37 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 05/12] memory: Rename RAM_GUEST_MEMFD to RAM_GUEST_MEMFD_PRIVATE Peter Xu
2025-12-16 5:49 ` Xiaoyao Li
2025-12-23 17:04 ` Peter Xu
2026-06-02 1:39 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 06/12] memory: Rename memory_region_has_guest_memfd() to *_private() Peter Xu
2026-06-02 1:40 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 07/12] hostmem: Rename guest_memfd to guest_memfd_private Peter Xu
2025-12-16 5:54 ` Xiaoyao Li
2026-06-02 18:56 ` Michael Roth
2025-12-15 20:51 ` [PATCH v3 08/12] hostmem: Support fully shared guest memfd to back a VM Peter Xu
2025-12-16 6:54 ` Xiaoyao Li
2025-12-16 14:02 ` Fabiano Rosas
2026-06-02 21:40 ` Michael Roth
2026-06-05 7:23 ` David Hildenbrand (Arm)
2026-06-05 11:23 ` David Hildenbrand (Arm)
2025-12-15 20:52 ` [PATCH v3 09/12] machine: Rename machine_require_guest_memfd() to *_private() Peter Xu
2025-12-16 6:55 ` Xiaoyao Li
2026-06-02 21:46 ` Michael Roth
2025-12-15 20:52 ` [PATCH v3 10/12] memory: Rename memory_region_init_ram_guest_memfd() " Peter Xu
2025-12-16 6:56 ` Xiaoyao Li
2026-06-02 21:49 ` Michael Roth
2025-12-15 20:52 ` [PATCH v3 11/12] tests/migration-test: Support guest-memfd init shared mem type Peter Xu
2025-12-16 14:18 ` Fabiano Rosas
2025-12-23 17:09 ` Peter Xu
2025-12-15 20:52 ` [PATCH v3 12/12] tests/migration-test: Add a precopy test for guest-memfd Peter Xu
2025-12-16 14:20 ` Fabiano Rosas
2026-06-02 22:02 ` [PATCH v3 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends Michael Roth
2026-06-03 19:27 ` Peter Xu
2026-06-04 22:36 ` Michael Roth
2026-06-05 14:57 ` Peter Xu
2026-06-08 17:59 ` 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=aUrLP3i-SWftPpWA@x1.local \
--to=peterx@redhat.com \
--cc=aik@amd.com \
--cc=chenyi.qiang@intel.com \
--cc=david@kernel.org \
--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 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.