QEMU-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.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 03/12] kvm: Provide explicit error for kvm_create_guest_memfd()
Date: Fri, 14 Aug 2026 08:44:15 -0400	[thread overview]
Message-ID: <an8Nn5cb52ev4MF2@x1.local> (raw)
In-Reply-To: <cc83a207-c89f-4ec7-864a-db0115c4f641@oss.qualcomm.com>

On Fri, Aug 14, 2026 at 07:56:42AM +0200, Philippe Mathieu-Daudé wrote:
> Hi Peter, Michael,
> 
> On 12/8/26 22:16, Michael Roth wrote:
> > From: Peter Xu <peterx@redhat.com>
> > 
> > So that there will be a verbal string returned when kvm not enabled, or
> > kvm not compiled.
> > 
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.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    | 5 +++++
> >   accel/stubs/kvm-stub.c | 1 +
> >   2 files changed, 6 insertions(+)
> > 
> > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> > index 120cab1e22..bda2e25a66 100644
> > --- a/accel/kvm/kvm-all.c
> > +++ b/accel/kvm/kvm-all.c
> > @@ -4758,6 +4758,11 @@ int kvm_create_guest_memfd(uint64_t size, uint64_t flags, Error **errp)
> >           .flags = flags,
> >       };
> > +    if (!kvm_enabled()) {
> > +        error_setg(errp, "guest-memfd requires KVM accelerator");
> > +        return -1;
> 
> This doesn't sound right withing a KVM-specific method. We want to
> assert() here.
> 
> The call in ram_block_add() is already protected:
> 
> 2147 static void ram_block_add(RAMBlock *new_block, Error **errp)
> 2148 {
> ...
> 2185     if (new_block->flags & RAM_GUEST_MEMFD) {
> 2188         if (!kvm_enabled()) {
> 2189             error_setg(errp, "cannot set up private guest memory for
> %s: KVM required",
> 2190 object_get_typename(OBJECT(current_machine->cgs)));
> 2191             goto out_free;
> 2192         }
> ...
> 2203         new_block->guest_memfd =
> kvm_create_guest_memfd(new_block->max_length,
> 2204                                                         0, errp);
> 
> The other one is:
> 
> 2823 int ram_block_rebind(Error **errp)
> 2824 {
> ...
> 2829     RAMBLOCK_FOREACH(block) {
> ...
> 2834             block->guest_memfd =
> kvm_create_guest_memfd(block->max_length,
> 2835                                                         0, errp);
> 
> which is only called from KVM:
> 
> 2776 static int kvm_reset_vmfd(MachineState *ms)
> 2777 {
> ...
> 2827     /* rebind memory to new vm fd */
> 2828     ret = ram_block_rebind(&err);
> 
> So maybe what we want is:
> 
> -- >8 --
> diff --git a/system/physmem.c b/system/physmem.c
> index b97016b1303..66ff74541aa 100644
> --- a/system/physmem.c
> +++ b/system/physmem.c
> @@ -2824,6 +2824,8 @@ int ram_block_rebind(Error **errp)
>  {
>      RAMBlock *block;
> 
> +    assert(kvm_enabled()); /* Only supported by KVM so far */
> +
>      qemu_mutex_lock_ramlist();
> 
>      RAMBLOCK_FOREACH(block) {
> ---
> 
> Or less aggressive:
> 
> -- >8 --
> diff --git a/system/physmem.c b/system/physmem.c
> index b97016b1303..2988d1dd6c9 100644
> --- a/system/physmem.c
> +++ b/system/physmem.c
> @@ -2824,6 +2824,11 @@ int ram_block_rebind(Error **errp)
>  {
>      RAMBlock *block;
> 
> +    if (!kvm_enabled()) {
> +        error_setg(errp, "guest-memfd requires KVM accelerator");
> +        return -1;
> +    }
> +
>      qemu_mutex_lock_ramlist();
> 
>      RAMBLOCK_FOREACH(block) {
> ---
> 
> WDYT?

Fine by me.

IMHO it's normally more of an issue the other way round, if we used an
assert() where we should use error_setg() (hence, user triggerable
assert()s).  Here we expect it to never happen, so either way should not
happen..

If so, we could also assert() in ram_block_rebind(), as it's only used in
kvm_reset_vmfd() only, so I don't see how it can be reached if KVM is not
enabled first..

Thanks,

-- 
Peter Xu



  reply	other threads:[~2026-08-14 12:45 UTC|newest]

Thread overview: 34+ 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 [this message]
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
2026-08-23 15:33               ` Michael Roth via qemu development
2026-08-24 12:58                 ` Peter Xu
2026-08-25  2:04                   ` Michael Roth
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
2026-08-21 14:18 ` [PATCH v4 00/12] KVM/hostmem: Support init-shared guest-memfd as VM backends Peter Xu
2026-08-23 15:52   ` Michael Roth
2026-08-24 13:17     ` Peter Xu
2026-08-25  2:20       ` 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=an8Nn5cb52ev4MF2@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=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@oss.qualcomm.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