From: Fam Zheng <famz@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Karl Rister <krister@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
borntraeger@de.ibm.com, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 3/4] util: Add VFIO helper library
Date: Thu, 22 Dec 2016 00:19:34 +0800 [thread overview]
Message-ID: <20161221161934.GA18068@lemon> (raw)
In-Reply-To: <405aa216-ab28-51e3-c81c-78a841605c01@redhat.com>
On Wed, 12/21 16:46, Paolo Bonzini wrote:
>
>
> On 20/12/2016 17:31, Fam Zheng wrote:
> > + hbitmap_iter_init(&iter, s->free_chunks, 1);
> > + if (contiguous) {
> > + while (true) {
> > + bool satisfy = true;
> > + next = hbitmap_iter_next(&iter);
> > + if (next < 0) {
> > + return NULL;
> > + }
> > + for (i = 1; i < chunks; i++) {
> > + if (!hbitmap_get(s->free_chunks, next + i)) {
> > + satisfy = false;
> > + break;
> > + }
> > + }
> > + if (satisfy) {
> > + break;
> > + }
> > + }
> > + hbitmap_reset(s->free_chunks, next, chunks);
> > + r = g_new(IOVARange, 1);
> > + r->iova = next * pages_per_chunk * getpagesize();
> > + r->nr_pages = pages;
> > + QSIMPLEQ_INSERT_TAIL(&m.iova_list, r, next);
> > + } else {
> > + next = hbitmap_iter_next(&iter);
> > + while (pages) {
> > + uint64_t chunk;
> > + if (next < 0) {
> > + hbitmap_iter_init(&iter, s->free_chunks, 1);
> > + next = hbitmap_iter_next(&iter);
> > + }
> > + assert(next >= 0);
> > + chunk = next;
> > + DPRINTF("using chunk %ld\n", chunk);
> > + next = hbitmap_iter_next(&iter);
> > + hbitmap_reset(s->free_chunks, chunk, 1);
> > + if (r && r->iova + r->nr_pages == chunk * pages_per_chunk) {
> > + r->nr_pages += MIN(pages, pages_per_chunk);
> > + } else {
> > + r = g_new(IOVARange, 1);
> > + r->iova = chunk * pages_per_chunk * getpagesize();
> > + r->nr_pages = MIN(pages, pages_per_chunk);
> > + QSIMPLEQ_INSERT_TAIL(&m.iova_list, r, next);
> > + }
> > + pages -= MIN(pages, pages_per_chunk);
> > + }
>
> I'm not sure HBitmap tracking is useful. If we exhaust the IOVA space,
> we can just throw everything away with a single VFIO_IOMMU_UNMAP_DMA.
> Then replay the RAMBlockNotifier mappings (we need to add this anyway
> for hotplug support) and keep on mapping lazily whatever comes later.
It's clever! It'd be a bit more complicated than that, though. Things like
queues etc in block/nvme.c have to be preserved, and if we already ensure that,
ram blocks can be preserved similarly, but indeed bounce buffers can be handled
that way. I still need to think about how to make sure none of the invalidated
IOVA addresses are in use by other requests.
Also I wonder how expensive the huge VFIO_IOMMU_UNMAP_DMA is. In the worst case
the "throwaway" IOVAs can be limited to a small range.
Fam
>
> Thanks,
>
> Paolo
next prev parent reply other threads:[~2016-12-21 16:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-20 16:31 [Qemu-devel] [PATCH 0/4] RFC: A VFIO based block driver for NVMe device Fam Zheng
2016-12-20 16:31 ` [Qemu-devel] [PATCH 1/4] ramblock-notifier: new Fam Zheng
2016-12-22 9:56 ` Paolo Bonzini
2017-01-11 5:38 ` Stefan Weil
2017-01-11 5:48 ` Stefan Weil
2017-01-11 6:41 ` Fam Zheng
2016-12-20 16:31 ` [Qemu-devel] [PATCH 2/4] util: Add a notifier list for qemu_vfree() Fam Zheng
2016-12-20 16:31 ` [Qemu-devel] [PATCH 3/4] util: Add VFIO helper library Fam Zheng
2016-12-21 15:46 ` Paolo Bonzini
2016-12-21 16:19 ` Fam Zheng [this message]
2016-12-21 17:02 ` Paolo Bonzini
2016-12-20 16:31 ` [Qemu-devel] [PATCH 4/4] block: Add VFIO based NVMe driver Fam Zheng
2016-12-20 16:39 ` Paolo Bonzini
2016-12-21 11:59 ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2016-12-21 14:05 ` Fam Zheng
2016-12-20 23:04 ` [Qemu-devel] [PATCH 0/4] RFC: A VFIO based block driver for NVMe device no-reply
2016-12-21 1:38 ` Fam Zheng
2016-12-21 0:48 ` no-reply
2016-12-29 4:09 ` Tian, Kevin
2016-12-30 0:46 ` Fam Zheng
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=20161221161934.GA18068@lemon \
--to=famz@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=krister@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.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).