qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: "Albert Esteve" <aesteve@redhat.com>,
	qemu-devel@nongnu.org, stefanha@redhat.com,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Fabiano Rosas" <farosas@suse.de>,
	pbonzini@redhat.com, "Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [RFC v2] memory.c: improve refcounting for RAM vs MMIO regions
Date: Wed, 6 Aug 2025 16:56:35 -0400	[thread overview]
Message-ID: <aJPBg2WBlfU5Rp21@x1.local> (raw)
In-Reply-To: <6c254144-a5ee-4536-b0a1-844fb5281b7d@redhat.com>

On Wed, Aug 06, 2025 at 10:36:33PM +0200, David Hildenbrand wrote:
> On 06.08.25 22:15, Peter Xu wrote:
> > On Tue, Aug 05, 2025 at 10:11:23AM +0200, Albert Esteve wrote:
> > > v1->v2:
> > > - Added documentation
> > > - Explained the reasoning in the commit message
> > > 
> > > In the last version of the SHMEM MAP/UNMAP [1] Stefan
> > > raised a concern [2] about dynamically creating and
> > > destroying memory regions and their lifecycle [3].
> > > 
> > > After some discussion, David Hildenbrand proposed
> > > to detect RAM regions and handle refcounting differently.
> > > I tried to extend the reasoning in the commit message
> > > below. If I wrote any innacuracies, please keep me
> > > honest. I hope we can gather some feedback with
> > > this RFC patch before sending it for inclusion.
> > 
> > This seems working.  Looks like so far all RAM MRs are fine with it, but
> > I'm not strongly confident it's true or it'll trivially keep true in the
> > future too.
> > 
> > Besides, this still adds some trivial complexity to memory_region_ref() on
> > treating RAM/MMIO MRs differently.
> > > It also sounds like a pure "accident" that the shmem objects to be
> mapped
> > from the vhost-user devices are RAMs.  I wonder what happens if we want to
> > also support dynmaic MMIO regions.
> 
> Is this use case realistic?

Nop. :) It's a sincere wish that if such a feature to be introduced, it
could work for MMIOs too.  Or better if no need to introduce it.

> 
> If there is a reasonable way to prepare for such hypothetical use cases them
> while solving Albert's immediate use case, I'm all for it.
> 
> > 
> > Would this work even without changing QEMU memory core?
> > 
> > For example, have you thought about creating a VhostUserShmemObject for
> > each of the VHOST_USER_BACKEND_SHMEM_MAP request?
> 
> You mean, adding an intermediate object that remains the parent of these
> MemoryRegion?
> 
> Could work. To free a MemoryRegion, I guess we would unparent that
> intermediate object, and that object would then free the memory region --
> unless something still references that intermediate object. Not sure if the
> memory region might keep the intermediate object still alive (no idea).

It should, as long as memory_region_ref() will boost the tempobj's refcount
properly.

Thanks,

> 
> Certainly something to explore, Albert, can you look into that?
> 
> -- 
> Cheers,
> 
> David / dhildenb
> 

-- 
Peter Xu



  reply	other threads:[~2025-08-06 20:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05  8:11 [RFC v2] memory.c: improve refcounting for RAM vs MMIO regions Albert Esteve
2025-08-06 20:15 ` Peter Xu
2025-08-06 20:36   ` David Hildenbrand
2025-08-06 20:56     ` Peter Xu [this message]
2025-08-07  7:22     ` Albert Esteve
2025-08-14  8:47       ` Albert Esteve

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=aJPBg2WBlfU5Rp21@x1.local \
    --to=peterx@redhat.com \
    --cc=aesteve@redhat.com \
    --cc=david@redhat.com \
    --cc=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).