linux-sunxi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH v9 0/6] iommu/dma: s390 DMA API conversion and optimized IOTLB flushing
@ 2023-05-15  9:15 Niklas Schnelle
  2023-05-15  9:15 ` [PATCH v9 1/6] s390/ism: Set DMA coherent mask Niklas Schnelle
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Niklas Schnelle @ 2023-05-15  9:15 UTC (permalink / raw)
  To: Joerg Roedel, Matthew Rosato, Will Deacon, Wenjia Zhang,
	Robin Murphy, Jason Gunthorpe
  Cc: Gerd Bayer, Julian Ruess, Pierre Morel, Alexandra Winter,
	Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Christian Borntraeger, Sven Schnelle, Suravee Suthikulpanit,
	Hector Martin, Sven Peter, Alyssa Rosenzweig, David Woodhouse,
	Lu Baolu, Andy Gross, Bjorn Andersson, Konrad Dybcio, Yong Wu,
	Matthias Brugger, AngeloGioacchino Del Regno, Gerald Schaefer,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland, Thierry Reding, Krishna Reddy,
	Jonathan Hunter, Niklas Schnelle, Jonathan Corbet, linux-s390,
	netdev, linux-kernel, iommu, asahi, linux-arm-kernel,
	linux-arm-msm, linux-mediatek, linux-sunxi, linux-tegra,
	linux-doc

Hi All,

This patch series converts s390's PCI support from its platform specific DMA
API implementation in arch/s390/pci/pci_dma.c to the common DMA IOMMU layer.
The conversion itself is done in patches 3-4 with patch 2 providing the final
necessary IOMMU driver improvement to handle s390's special IOTLB flush
out-of-resource indication in virtualized environments. Patches 1-2 may be
applied independently. The conversion itself only touches the s390 IOMMU driver
and s390 arch code moving over remaining functions from the s390 DMA API
implementation. No changes to common code are necessary.

After patch 4 the basic conversion is done and on our partitioning machine
hypervisor LPAR performance matches or exceeds the existing code. When running
under z/VM or KVM however, performance plummets to about half of the existing
code due to a much higher rate of IOTLB flushes for unmapped pages. Due to the
hypervisors use of IOTLB flushes to synchronize their shadow tables these are
very expensive and minimizing them is key for regaining the performance loss.

To this end patches 5-6 add a new, single queue, IOTLB flushing scheme as
an alternative to the existing per-CPU flush queues. Introducing an alternative
scheme was also suggested by Robin Murphy[1]. In the previous RFC of this
conversion Robin suggested reusing more of the existing queuing logic which
I incorporated since v2. The single queue mode is introduced in patch
5 together with a new dma_iommu_options struct and tune_dma_iommu callback in
IOMMU ops which allows IOMMU drivers to switch to a single flush queue.

Then patch 6 enables variable queue sizes using power of 2 queue sizes and
shift/mask to keep performance as close to the existing code as possible. The
variable queue size and a variable timeout are added to the dma_iommu_options
struct and utilized by s390 in the z/VM and KVM guest cases. As it is
implemented in common code the single queue IOTLB flushing scheme can of course
be used by other platforms with expensive IOTLB flushes. Particularly
virtio-iommu may be a candidate.

In a previous version I verified that the new scheme does work on my x86_64
Ryzen workstation by locally modifying iommu_subsys_init() to default to the
single queue mode and verifying its use via "/sys/.../iommu_group/type". I did
not find problems with an AMD GPU, Intel NIC (with SR-IOV and KVM
pass-through), NVMes or any on board peripherals.

This code is also available in the b4/dma_iommu topic branch of my
git.kernel.org repository[3] with tags the version sent.

NOTE: Due to the large drop in performance I think we should not merge the DMA
API conversion (patch 4) until we have a more suited IOVA flushing scheme
with similar improvements as the proposed changes.

Best regards,
Niklas

[0] https://lore.kernel.org/linux-iommu/20221109142903.4080275-1-schnelle@linux.ibm.com/
[1] https://lore.kernel.org/linux-iommu/3e402947-61f9-b7e8-1414-fde006257b6f@arm.com/
[2] https://lore.kernel.org/linux-iommu/a8e778da-7b41-a6ba-83c3-c366a426c3da@arm.com/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/niks/linux.git/

---
Changes in v9:
- Rebased on v6.4-rc2
- Re-ordered iommu_group_store_type() to allow passing the device to
  iommu_dma_init_fq()
- Link to v8: https://lore.kernel.org/r/20230310-dma_iommu-v8-0-2347dfbed7af@linux.ibm.com

---
Niklas Schnelle (6):
      s390/ism: Set DMA coherent mask
      iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM return
      s390/pci: prepare is_passed_through() for dma-iommu
      s390/pci: Use dma-iommu layer
      iommu/dma: Allow a single FQ in addition to per-CPU FQs
      iommu/dma: Make flush queue sizes and timeout driver configurable

 Documentation/admin-guide/kernel-parameters.txt |   9 +-
 arch/s390/include/asm/pci.h                     |   7 -
 arch/s390/include/asm/pci_clp.h                 |   3 +
 arch/s390/include/asm/pci_dma.h                 | 119 +---
 arch/s390/pci/Makefile                          |   2 +-
 arch/s390/pci/pci.c                             |  22 +-
 arch/s390/pci/pci_bus.c                         |   5 -
 arch/s390/pci/pci_debug.c                       |  12 +-
 arch/s390/pci/pci_dma.c                         | 735 ------------------------
 arch/s390/pci/pci_event.c                       |  17 +-
 arch/s390/pci/pci_sysfs.c                       |  19 +-
 drivers/iommu/Kconfig                           |   4 +-
 drivers/iommu/amd/iommu.c                       |   5 +-
 drivers/iommu/apple-dart.c                      |   5 +-
 drivers/iommu/dma-iommu.c                       | 191 ++++--
 drivers/iommu/dma-iommu.h                       |   4 +-
 drivers/iommu/intel/iommu.c                     |   5 +-
 drivers/iommu/iommu.c                           |  38 +-
 drivers/iommu/msm_iommu.c                       |   5 +-
 drivers/iommu/mtk_iommu.c                       |   5 +-
 drivers/iommu/s390-iommu.c                      | 435 +++++++++++++-
 drivers/iommu/sprd-iommu.c                      |   5 +-
 drivers/iommu/sun50i-iommu.c                    |   4 +-
 drivers/iommu/tegra-gart.c                      |   5 +-
 drivers/s390/net/ism_drv.c                      |   2 +-
 include/linux/iommu.h                           |  29 +-
 26 files changed, 682 insertions(+), 1010 deletions(-)
---
base-commit: f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6
change-id: 20230310-dma_iommu-5e048c538647

Best regards,
-- 
Niklas Schnelle
Linux on Z Development

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement - https://www.ibm.com/privacy 


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-05-23 13:37 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15  9:15 [PATCH v9 0/6] iommu/dma: s390 DMA API conversion and optimized IOTLB flushing Niklas Schnelle
2023-05-15  9:15 ` [PATCH v9 1/6] s390/ism: Set DMA coherent mask Niklas Schnelle
2023-05-16  7:39   ` Pierre Morel
2023-05-16  7:58   ` Petr Tesařík
2023-05-15  9:15 ` [PATCH v9 2/6] iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM return Niklas Schnelle
2023-05-15  9:15 ` [PATCH v9 3/6] s390/pci: prepare is_passed_through() for dma-iommu Niklas Schnelle
2023-05-15  9:15 ` [PATCH v9 4/6] s390/pci: Use dma-iommu layer Niklas Schnelle
2023-05-15  9:15 ` [PATCH v9 5/6] iommu/dma: Allow a single FQ in addition to per-CPU FQs Niklas Schnelle
2023-05-15 13:07   ` Jason Gunthorpe
2023-05-15 14:42     ` Niklas Schnelle
2023-05-22 16:26   ` Robin Murphy
2023-05-23 12:02     ` Niklas Schnelle
2023-05-23 12:16       ` Robin Murphy
2023-05-23 13:35     ` Niklas Schnelle
2023-05-15  9:15 ` [PATCH v9 6/6] iommu/dma: Make flush queue sizes and timeout driver configurable Niklas Schnelle
2023-05-22 16:10   ` Joerg Roedel
2023-05-23 12:20     ` Niklas Schnelle

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).