From: Steven Sistare <steven.sistare@oracle.com>
To: Zheng Chuan <zhengchuan@huawei.com>,
Alex Williamson <alex.williamson@redhat.com>
Cc: "Daniel P. Berrange" <berrange@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Zeng" <jason.zeng@linux.intel.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Juan Quintela" <quintela@redhat.com>,
qemu-devel@nongnu.org, "Eric Blake" <eblake@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Xiexiangyou <xiexiangyou@huawei.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>
Subject: Re: [PATCH V6 19/27] vfio-pci: cpr part 1 (fd and dma)
Date: Tue, 30 Nov 2021 11:11:55 -0500 [thread overview]
Message-ID: <59e9f793-667d-5fe1-bccf-9afef791a00e@oracle.com> (raw)
In-Reply-To: <803a8bee-ec82-a41b-38ad-57d7ef572019@huawei.com>
On 11/10/2021 2:48 AM, Zheng Chuan wrote:
>
> Hi, steve
>
> On 2021/8/11 1:06, Alex Williamson wrote:
>> On Fri, 6 Aug 2021 14:43:53 -0700
>> Steve Sistare <steven.sistare@oracle.com> wrote:
>> [...]
>>> +static int
>>> +vfio_region_remap(MemoryRegionSection *section, void *handle, Error **errp)
>>> +{
>>> + MemoryRegion *mr = section->mr;
>>> + VFIOContainer *container = handle;
>>> + const char *name = memory_region_name(mr);
>>> + ram_addr_t size = int128_get64(section->size);
>>> + hwaddr offset, iova, roundup;
>>> + void *vaddr;
>>> +
>>> + if (vfio_listener_skipped_section(section) || memory_region_is_iommu(mr)) {
>>> + return 0;
>>> + }
>>> +
>>> + offset = section->offset_within_address_space;
>>> + iova = REAL_HOST_PAGE_ALIGN(offset);
> We should not do remap if it shares on host page with other structures.
> I think a judgement like int128_ge((int128_make64(iova), llend)) in vfio_listener_region_add() should be also added here to check it,
> otherwise it will remap no-exit dma which causes the live update failure.
> diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
> index 0981d31..d231841 100644
> --- a/hw/vfio/cpr.c
> +++ b/hw/vfio/cpr.c
> @@ -58,13 +58,21 @@ vfio_region_remap(MemoryRegionSection *section, void *handle, Error **errp)
> ram_addr_t size = int128_get64(section->size);
> hwaddr offset, iova, roundup;
> void *vaddr;
> -
> + Int128 llend;
> +
> if (vfio_listener_skipped_section(section) || memory_region_is_iommu(mr)) {
> return 0;
> }
>
> offset = section->offset_within_address_space;
> iova = REAL_HOST_PAGE_ALIGN(offset);
> + llend = int128_make64(section->offset_within_address_space);
> + llend = int128_add(llend, section->size);
> + llend = int128_and(llend, int128_exts64(qemu_real_host_page_mask));
> + if (int128_ge(int128_make64(iova), llend)) {
> + return 0;
> + }
> +
> roundup = iova - offset;
> size -= roundup;
> size = REAL_HOST_PAGE_ALIGN(size);
>
>>> + roundup = iova - offset;
>>> + size -= roundup;
>>> + size = REAL_HOST_PAGE_ALIGN(size);
>>> + vaddr = memory_region_get_ram_ptr(mr) +
>>> + section->offset_within_region + roundup;
>>> +
>>> + trace_vfio_region_remap(name, container->fd, iova, iova + size - 1, vaddr);
>>> + return vfio_dma_map_vaddr(container, iova, size, vaddr, errp);
>>> +}
Thank you Zheng. I intended to implement the logic you suggest, using 64-bit arithmetic,
but I botched it. This should do the trick:
diff --git a/hw/vfio/cpr.c b/hw/vfio/cpr.c
index df334d9..bbdeaea 100644
--- a/hw/vfio/cpr.c
+++ b/hw/vfio/cpr.c
@@ -66,8 +66,8 @@ vfio_region_remap(MemoryRegionSection *section, void *handle,
offset = section->offset_within_address_space;
iova = REAL_HOST_PAGE_ALIGN(offset);
roundup = iova - offset;
- size -= roundup;
- size = REAL_HOST_PAGE_ALIGN(size);
+ size -= roundup; /* adjust for starting alignment */
+ size &= qemu_real_host_page_mask; /* adjust for ending alignment */
end = iova + size;
if (iova >= end) {
return 0;
- Steve
next prev parent reply other threads:[~2021-11-30 16:13 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 21:43 [PATCH V6 00/27] Live Update Steve Sistare
2021-08-06 21:43 ` [PATCH V6 01/27] memory: qemu_check_ram_volatile Steve Sistare
2021-08-06 21:43 ` [PATCH V6 02/27] migration: fix populate_vfio_info Steve Sistare
2021-08-06 21:43 ` [PATCH V6 03/27] migration: qemu file wrappers Steve Sistare
2021-08-06 21:43 ` [PATCH V6 04/27] migration: simplify savevm Steve Sistare
2021-08-06 21:43 ` [PATCH V6 05/27] vl: start on wakeup request Steve Sistare
2021-08-06 21:43 ` [PATCH V6 06/27] cpr: reboot mode Steve Sistare
2021-08-06 21:43 ` [PATCH V6 07/27] cpr: reboot HMP interfaces Steve Sistare
2021-08-06 21:43 ` [PATCH V6 08/27] memory: flat section iterator Steve Sistare
2021-08-06 21:43 ` [PATCH V6 09/27] oslib: qemu_clear_cloexec Steve Sistare
2021-08-06 21:43 ` [PATCH V6 10/27] machine: memfd-alloc option Steve Sistare
2021-08-06 21:43 ` [PATCH V6 11/27] qapi: list utility functions Steve Sistare
2021-08-06 21:43 ` [PATCH V6 12/27] vl: helper to request re-exec Steve Sistare
2021-08-06 21:43 ` [PATCH V6 13/27] cpr: preserve extra state Steve Sistare
2021-08-06 21:43 ` [PATCH V6 14/27] cpr: restart mode Steve Sistare
2021-08-06 21:43 ` [PATCH V6 15/27] cpr: restart HMP interfaces Steve Sistare
2021-08-06 21:43 ` [PATCH V6 16/27] hostmem-memfd: cpr for memory-backend-memfd Steve Sistare
2021-08-06 21:43 ` [PATCH V6 17/27] pci: export functions for cpr Steve Sistare
2021-08-06 21:43 ` [PATCH V6 18/27] vfio-pci: refactor " Steve Sistare
2021-08-10 16:53 ` Alex Williamson
2021-08-23 16:52 ` Steven Sistare
2021-08-06 21:43 ` [PATCH V6 19/27] vfio-pci: cpr part 1 (fd and dma) Steve Sistare
2021-08-10 17:06 ` Alex Williamson
2021-08-23 19:43 ` Steven Sistare
2021-11-10 7:48 ` Zheng Chuan
2021-11-30 16:11 ` Steven Sistare [this message]
2021-08-06 21:43 ` [PATCH V6 20/27] vfio-pci: cpr part 2 (msi) Steve Sistare
2021-08-06 21:43 ` [PATCH V6 21/27] vfio-pci: cpr part 3 (intx) Steve Sistare
2022-03-29 11:03 ` Fam Zheng
2022-04-11 16:23 ` Steven Sistare
2022-04-12 11:01 ` Fam Zheng
2021-08-06 21:43 ` [PATCH V6 22/27] vhost: reset vhost devices for cpr Steve Sistare
2021-08-06 21:43 ` [PATCH V6 23/27] chardev: cpr framework Steve Sistare
2021-08-06 21:43 ` [PATCH V6 24/27] chardev: cpr for simple devices Steve Sistare
2021-08-06 21:43 ` [PATCH V6 25/27] chardev: cpr for pty Steve Sistare
2021-08-06 21:44 ` [PATCH V6 26/27] chardev: cpr for sockets Steve Sistare
2021-08-06 21:44 ` [PATCH V6 27/27] cpr: only-cpr-capable option Steve Sistare
2021-08-09 16:02 ` [PATCH V6 00/27] Live Update Steven Sistare
2021-08-21 8:54 ` Zheng Chuan
2021-08-23 21:36 ` Steven Sistare
2021-08-24 9:36 ` Zheng Chuan
2021-08-31 21:15 ` Steven Sistare
2021-10-27 6:16 ` Zheng Chuan
2021-10-27 12:25 ` Steven Sistare
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=59e9f793-667d-5fe1-bccf-9afef791a00e@oracle.com \
--to=steven.sistare@oracle.com \
--cc=alex.bennee@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=jason.zeng@linux.intel.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
--cc=xiexiangyou@huawei.com \
--cc=zhengchuan@huawei.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).