mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Niklas Schnelle <schnelle@linux.ibm.com>
To: Jean-Philippe Brucker <jean-philippe@linaro.org>
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	Christoph Hellwig <hch@infradead.org>
Subject: Re: [RFC] iommu/virtio: Use single flush queue (EXPERIMENTAL)
Date: Fri, 25 Aug 2023 14:22:38 +0200	[thread overview]
Message-ID: <9d7819fd165a1e87ea1dd66f9d0d841f45012264.camel@linux.ibm.com> (raw)
In-Reply-To: <20230802123612.GA6142@myrica>

On Wed, 2023-08-02 at 13:36 +0100, Jean-Philippe Brucker wrote:
> Hi Niklas,
> 
> On Wed, Jul 26, 2023 at 01:14:33PM +0200, Niklas Schnelle wrote:
> > Just like on paged s390 guests with their virtual IOMMU, syncing
> > mappings via virtio-iommu is quite expensive. It can thus benefit from
> > queueing unmapped IOVAs and flushing them in batches but less so from
> > parallel flushes which is what the shadow_on_flush flag introduced for
> > s390 tunes dma-iommu to do.
> > 
> > For this to work .flush_iotlb_all is implemented. Furthermore
> > .iotlb_sync_map is also implemented and used to pull the sync out of the
> > mapping operation for some additional batching and performance gain.
> > 
> > In a basic test with NVMe pass-through to a KVM guest on a Ryzen 3900X
> > these changes together lead to about 19% more IOPS in a fio test and
> > slightly more bandwidth too.
> 
> Nice, thank you for testing this. I played with a NVMe on an Intel desktop
> and can confirm similar results. With "sq" meaning single flush queue and
> "mq" percpu flush queue, "+map" is with .iotlb_sync_map() enabled.
> 
> Multithread block randwrite job [1]:
> 
>                          BW compared to host    Confidence
>                           (higher better)
>               host           100.0%               ±0.0%
>           noviommu            99.9                 0.0
>     viommu lazy sq +map       99.9                 0.1
>     viommu lazy mq +map       99.9                 0.1
>     viommu lazy sq            92.2                 0.9
>     viommu lazy mq            91.5                 0.9
>      viommu strict +map       92.7                 0.9
>      viommu strict            81.3                 1.0
> 
> 
> Single page randrw:
> 
>                         Latency compared to host    Confidence
>                            (lower better)
>               host            x1.00                   ±.04
>           noviommu             1.23                    .04
>     viommu lazy sq +map        7.09                    .05
>     viommu lazy mq +map        7.07                    .07
>     viommu lazy sq             7.15                    .04
>     viommu lazy mq             7.11                    .05
>      viommu strict +map        8.82                    .05
>      viommu strict             8.82                    .04
> 
> So with lazy+map we get the maximum bandwidth reachable on this disk
> (2.5GiB/s) even with a heavy iommu_map/unmap usage, which is cool.
> Random access latency also improves with lazy mode.
> 
> The difference between single and percpu flush queue isn't really
> measurable in my multithread test. There is a difference between Lazy sq
> and mq but the variation between samples outweighs it.

Interesting that there is no advantage when using a single large queue.
Maybe virtio-iommu does handle the per-CPU flushing well because of a
stronger CPU affinity than on s390x or maybe it has to do with the sync
being just a queue drain making only some syncs slow.

> 
> > 
> > Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> > ---
> > Note:
> > The idea of using the single flush queue scheme from my series "iommu/dma: s390
> > DMA API conversion and optimized IOTLB flushing"[0] for virtio-iommu was already
> > mentioned in the cover letter. I now wanted to explore this with this patch
> > which may also serve as a test vehicle for the single flush queue scheme usable
> > on non-s390.
> > 
> > Besides limited testing, this is marked experimental mainly because the use of
> > queuing needs to be a concious decision as it allows continued access to
> > unmapped pages for up to a second with the currently proposed single flush
> > queue mechanism.
> 
> It fits with the iommu.strict=0 / CONFIG_IOMMU_DEFAULT_DMA_LAZY setting,
> which selects DMA_FQ domains. That option allows a misbehaving device to
> access memory that has been freed/reallocated, which is what we're
> enabling here. I believe the risk is pretty much the same for deferred
> UNMAP as for deferred TLBI, since mappings that we're removing were likely
> cached in the TLB. Increasing the timeout does make it easier to exploit,
> but I don't think that changes the policy from an admin's perspective:
> only enable lazy mode if you trust device and driver.

I'm with Jason here. I think for non-CoCo hypervisor's
the hypervisor is trusted so may just forward the trust level of the
relevant device. This may of course be different for CoCo VMs but then
the VM knows and could e.g. default to iommu.strict=1 or it needs to
use swiotlb anyway.

> 
> On bare metal, we disable DMA_FQ for devices that can be easily hotplugged
> into unattended machines (through external-facing ports like thunderbolt).
> On VMs, the concern isn't really about external devices, since they don't
> automatically get plugged into a VM without user intervention. Here I
> guess the devices we don't trust will be virtual devices implemented by
> other VMs. We don't have any method to identify them yet, so
> iommu.strict=1 and CONFIG_IOMMU_DEFAULT_DMA_STRICT is the best we can do
> at the moment.
> 
> I'm not so sure about enabling shadow_on_flush by default, since the
> performance difference was too small in my tests. Maybe a module parameter
> for dma-iommu could configure the flush queue?
> 
> > Also it might make sense to split this patch to do the
> > introduction and use of .iotlb_sync_map separately but as a test vehicle
> > I found it easier to consume as a single patch.
> 
> Yes, both changes are useful but should be in two patches
> 
> Thanks,
> Jean
> 

After sending v12 of my series[0] I'm now looking into sending this
separately. Rebasing on v6.5-rc7 however I noticed that without my
patch "iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM
return" we not only get a conflict with my series but also potentially
miss errors on map since just like on s390x virtio-iommu's
.iotlb_sync_map can fail. So I think it makes most sense to send this
based on my series. I hope that's okay for you.

[0]
https://lore.kernel.org/lkml/20230825-dma_iommu-v12-0-4134455994a7@linux.ibm.com/

  parent reply	other threads:[~2023-08-25 13:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-17 11:00 [PATCH v11 0/6] iommu/dma: s390 DMA API conversion and optimized IOTLB flushing Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 1/6] iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM return Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 2/6] s390/pci: prepare is_passed_through() for dma-iommu Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 3/6] s390/pci: Use dma-iommu layer Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 4/6] iommu/s390: Force ISM devices to use IOMMU_DOMAIN_DMA Niklas Schnelle
2023-07-19 12:56   ` Matthew Rosato
2023-08-18 19:10   ` Robin Murphy
2023-08-23 10:53     ` Niklas Schnelle
2023-07-17 11:00 ` [PATCH v11 5/6] iommu/dma: Allow a single FQ in addition to per-CPU FQs Niklas Schnelle
2023-08-18 18:16   ` Robin Murphy
2023-08-23 14:21     ` Niklas Schnelle
2023-08-29 15:39       ` Robin Murphy
2023-07-17 11:00 ` [PATCH v11 6/6] iommu/dma: Use a large flush queue and timeout for shadow_on_flush Niklas Schnelle
2023-08-18 19:06   ` Robin Murphy
2023-07-26 11:14 ` [RFC] iommu/virtio: Use single flush queue (EXPERIMENTAL) Niklas Schnelle
2023-08-02 12:36   ` Jean-Philippe Brucker
2023-08-02 13:44     ` Jason Gunthorpe
2023-08-25 12:22     ` Niklas Schnelle [this message]
2023-08-18 16:51 ` [PATCH v11 0/6] iommu/dma: s390 DMA API conversion and optimized IOTLB flushing 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=9d7819fd165a1e87ea1dd66f9d0d841f45012264.camel@linux.ibm.com \
    --to=schnelle@linux.ibm.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=hch@infradead.org \
    --cc=jean-philippe@linaro.org \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=robin.murphy@arm.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=will@kernel.org \
    /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

all inboxes | Powered by JetHome®