From: Peter Xu <peterx@redhat.com>
To: Xu Yilun <yilun.xu@linux.intel.com>
Cc: "Alexey Kardashevskiy" <aik@amd.com>,
"Chenyi Qiang" <chenyi.qiang@intel.com>,
"David Hildenbrand" <david@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Michael Roth" <michael.roth@amd.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org,
"Williams Dan J" <dan.j.williams@intel.com>,
"Peng Chao P" <chao.p.peng@intel.com>,
"Gao Chao" <chao.gao@intel.com>, "Xu Yilun" <yilun.xu@intel.com>
Subject: Re: [PATCH 2/7] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager
Date: Thu, 23 Jan 2025 11:47:17 -0500 [thread overview]
Message-ID: <Z5Jylb73kDJ6HTEZ@x1n> (raw)
In-Reply-To: <Z5INAQjxyYhwyc+1@yilunxu-OptiPlex-7050>
On Thu, Jan 23, 2025 at 05:33:53PM +0800, Xu Yilun wrote:
> On Wed, Jan 22, 2025 at 11:43:01AM -0500, Peter Xu wrote:
> > On Wed, Jan 22, 2025 at 05:41:31PM +0800, Xu Yilun wrote:
> > > On Wed, Jan 22, 2025 at 03:30:05PM +1100, Alexey Kardashevskiy wrote:
> > > >
> > > >
> > > > On 22/1/25 02:18, Peter Xu wrote:
> > > > > On Tue, Jun 25, 2024 at 12:31:13AM +0800, Xu Yilun wrote:
> > > > > > On Mon, Jan 20, 2025 at 03:46:15PM -0500, Peter Xu wrote:
> > > > > > > On Mon, Jan 20, 2025 at 09:22:50PM +1100, Alexey Kardashevskiy wrote:
> > > > > > > > > It is still uncertain how to implement the private MMIO. Our assumption
> > > > > > > > > is the private MMIO would also create a memory region with
> > > > > > > > > guest_memfd-like backend. Its mr->ram is true and should be managed by
> > > > > > > > > RamdDiscardManager which can skip doing DMA_MAP in VFIO's region_add
> > > > > > > > > listener.
> > > > > > > >
> > > > > > > > My current working approach is to leave it as is in QEMU and VFIO.
> > > > > > >
> > > > > > > Agreed. Setting ram=true to even private MMIO sounds hackish, at least
> > > > > >
> > > > > > The private MMIO refers to assigned MMIO, not emulated MMIO. IIUC,
> > > > > > normal assigned MMIO is always set ram=true,
> > > > > >
> > > > > > void memory_region_init_ram_device_ptr(MemoryRegion *mr,
> > > > > > Object *owner,
> > > > > > const char *name,
> > > > > > uint64_t size,
> > > > > > void *ptr)
> >
> > [1]
> >
> > > > > > {
> > > > > > memory_region_init(mr, owner, name, size);
> > > > > > mr->ram = true;
> > > > > >
> > > > > >
> > > > > > So I don't think ram=true is a problem here.
> > > > >
> > > > > I see. If there's always a host pointer then it looks valid. So it means
> > > > > the device private MMIOs are always mappable since the start?
> > > >
> > > > Yes. VFIO owns the mapping and does not treat shared/private MMIO any
> > > > different at the moment. Thanks,
> > >
> > > mm.. I'm actually expecting private MMIO not have a host pointer, just
> > > as private memory do.
> > >
> > > But I'm not sure why having host pointer correlates mr->ram == true.
> >
> > If there is no host pointer, what would you pass into "ptr" as referenced
> > at [1] above when creating the private MMIO memory region?
>
> Sorry for confusion. I mean existing MMIO region use set mr->ram = true,
> and unmappable region (gmem) also set mr->ram = true. So don't know why
> mr->ram = true for private MMIO is hackish.
That's exactly what I had on the question in the previous email - please
have a look at what QEMU does right now with memory_access_is_direct().
I'm not 100% sure it'll work if the host pointer doesn't exist.
Let's take one user of it to be explicit: flatview_write_continue_step()
will try to access the ram pointer if it's direct:
if (!memory_access_is_direct(mr, true)) {
...
} else {
/* RAM case */
uint8_t *ram_ptr = qemu_ram_ptr_length(mr->ram_block, mr_addr, l,
false, true);
memmove(ram_ptr, buf, *l);
invalidate_and_set_dirty(mr, mr_addr, *l);
return MEMTX_OK;
}
I don't see how QEMU could work yet if one MR set ram=true but without a
host pointer..
As discussed previously, IMHO it's okay that the pointer is not accessible,
but still I assume QEMU assumes the pointer at least existed for a ram=on
MR. I don't know whether it's suitable to set ram=on if the pointer
doesn't ever exist.
>
> I think We could add another helper to create memory region for private
> MMIO.
>
> >
> > OTOH, IIUC guest private memory finally can also have a host pointer (aka,
> > mmap()-able), it's just that even if it exists, accessing it may crash QEMU
> > if it's private.
>
> Not sure if I get it correct: when memory will be converted to private, QEMU
> should firstly unmap the host ptr, which means host ptr doesn't alway exist.
At least current QEMU doesn't unmap it?
kvm_convert_memory() does ram_block_discard_range() indeed, but that's hole
punches, not unmap. So the host pointer can always be there.
Even if we could have in-place gmemfd conversions in the future for guest
mem, we should also need the host pointer to be around, in which case (per
my current understand) it will even avoid hole punching but instead make
the page accessible (by being able to be faulted in).
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2025-01-23 16:47 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 7:08 [PATCH 0/7] Enable shared device assignment Chenyi Qiang
2024-12-13 7:08 ` [PATCH 1/7] memory: Export a helper to get intersection of a MemoryRegionSection with a given range Chenyi Qiang
2024-12-18 12:33 ` David Hildenbrand
2025-01-08 4:47 ` Alexey Kardashevskiy
2025-01-08 6:41 ` Chenyi Qiang
2024-12-13 7:08 ` [PATCH 2/7] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager Chenyi Qiang
2024-12-18 6:45 ` Chenyi Qiang
2025-01-08 4:48 ` Alexey Kardashevskiy
2025-01-08 10:56 ` Chenyi Qiang
2025-01-08 11:20 ` Alexey Kardashevskiy
2025-01-09 2:11 ` Chenyi Qiang
2025-01-09 2:55 ` Alexey Kardashevskiy
2025-01-09 4:29 ` Chenyi Qiang
2025-01-10 0:58 ` Alexey Kardashevskiy
2025-01-10 6:38 ` Chenyi Qiang
2025-01-09 21:00 ` Xu Yilun
2025-01-09 21:50 ` Xu Yilun
2025-01-13 3:34 ` Chenyi Qiang
2025-01-12 22:23 ` Xu Yilun
2025-01-14 1:14 ` Chenyi Qiang
2025-01-15 4:06 ` Alexey Kardashevskiy
2025-01-15 6:15 ` Chenyi Qiang
[not found] ` <2b2730f3-6e1a-4def-b126-078cf6249759@amd.com>
2025-01-20 20:46 ` Peter Xu
2024-06-24 16:31 ` Xu Yilun
2025-01-21 15:18 ` Peter Xu
2025-01-22 4:30 ` Alexey Kardashevskiy
2025-01-22 9:41 ` Xu Yilun
2025-01-22 16:43 ` Peter Xu
2025-01-23 9:33 ` Xu Yilun
2025-01-23 16:47 ` Peter Xu [this message]
2025-01-24 9:47 ` Xu Yilun
2025-01-24 15:55 ` Peter Xu
2025-01-24 18:17 ` David Hildenbrand
2025-01-26 3:34 ` Xu Yilun
2025-01-30 16:28 ` Peter Xu
2025-01-30 16:51 ` David Hildenbrand
2025-02-06 10:41 ` Xu Yilun
2025-02-06 20:03 ` Peter Xu
2025-01-14 6:45 ` Chenyi Qiang
2025-01-13 10:54 ` David Hildenbrand
2025-01-14 1:10 ` Chenyi Qiang
2025-01-15 4:05 ` Alexey Kardashevskiy
[not found] ` <f3aaffe7-7045-4288-8675-349115a867ce@redhat.com>
2025-01-20 17:21 ` Peter Xu
2025-01-20 17:54 ` David Hildenbrand
2025-01-20 18:33 ` Peter Xu
2025-01-20 18:47 ` David Hildenbrand
2025-01-20 20:19 ` Peter Xu
2025-01-20 20:25 ` David Hildenbrand
2025-01-20 20:43 ` Peter Xu
2025-01-21 1:35 ` Chenyi Qiang
2025-01-21 16:35 ` Peter Xu
2025-01-22 3:28 ` Chenyi Qiang
2025-01-22 5:38 ` Xiaoyao Li
2025-01-24 0:15 ` Alexey Kardashevskiy
2025-01-24 3:09 ` Chenyi Qiang
2025-01-24 5:56 ` Alexey Kardashevskiy
2025-01-24 16:12 ` Peter Xu
2025-01-20 18:09 ` Peter Xu
2025-01-21 9:00 ` Chenyi Qiang
2025-01-21 9:26 ` David Hildenbrand
2025-01-21 10:16 ` Chenyi Qiang
2025-01-21 10:26 ` David Hildenbrand
2025-01-22 6:43 ` Chenyi Qiang
2025-01-21 15:38 ` Peter Xu
2025-01-24 3:40 ` Chenyi Qiang
2024-12-13 7:08 ` [PATCH 3/7] guest_memfd: Introduce a callback to notify the shared/private state change Chenyi Qiang
2024-12-13 7:08 ` [PATCH 4/7] KVM: Notify the state change event during shared/private conversion Chenyi Qiang
2024-12-13 7:08 ` [PATCH 5/7] memory: Register the RamDiscardManager instance upon guest_memfd creation Chenyi Qiang
2025-01-08 4:47 ` Alexey Kardashevskiy
2025-01-09 5:34 ` Chenyi Qiang
2025-01-09 9:32 ` Alexey Kardashevskiy
2025-01-10 5:13 ` Chenyi Qiang
[not found] ` <59bd0e82-f269-4567-8f75-a32c9c997ca9@redhat.com>
2025-01-24 3:27 ` Alexey Kardashevskiy
2025-01-24 5:36 ` Chenyi Qiang
2025-01-09 8:14 ` Zhao Liu
2025-01-09 8:17 ` Chenyi Qiang
2024-12-13 7:08 ` [PATCH 6/7] RAMBlock: make guest_memfd require coordinate discard Chenyi Qiang
2025-01-13 10:56 ` David Hildenbrand
2025-01-14 1:38 ` Chenyi Qiang
[not found] ` <e1141052-1dec-435b-8635-a41881fedd4c@redhat.com>
2025-01-21 6:26 ` Chenyi Qiang
2025-01-21 8:05 ` David Hildenbrand
2024-12-13 7:08 ` [RFC PATCH 7/7] memory: Add a new argument to indicate the request attribute in RamDismcardManager helpers Chenyi Qiang
2025-01-08 4:47 ` [PATCH 0/7] Enable shared device assignment Alexey Kardashevskiy
2025-01-08 6:28 ` Chenyi Qiang
2025-01-08 11:38 ` Alexey Kardashevskiy
2025-01-09 7:52 ` Chenyi Qiang
2025-01-09 8:18 ` Alexey Kardashevskiy
2025-01-09 8:49 ` Chenyi Qiang
2025-01-10 1:42 ` Alexey Kardashevskiy
2025-01-10 7:06 ` Chenyi Qiang
2025-01-10 8:26 ` David Hildenbrand
2025-01-10 13:20 ` Jason Gunthorpe
2025-01-10 13:45 ` David Hildenbrand
2025-01-10 14:14 ` Jason Gunthorpe
2025-01-10 14:50 ` David Hildenbrand
2025-01-15 3:39 ` Alexey Kardashevskiy
2025-01-15 12:49 ` Jason Gunthorpe
[not found] ` <cc3428b1-22b7-432a-9c74-12b7e36b6cc6@redhat.com>
2025-01-20 18:39 ` Jason Gunthorpe
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=Z5Jylb73kDJ6HTEZ@x1n \
--to=peterx@redhat.com \
--cc=aik@amd.com \
--cc=chao.gao@intel.com \
--cc=chao.p.peng@intel.com \
--cc=chenyi.qiang@intel.com \
--cc=dan.j.williams@intel.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=yilun.xu@intel.com \
--cc=yilun.xu@linux.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).