All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Make the iommu driver no-snoop block feature consistent
@ 2022-04-05 16:15 ` Jason Gunthorpe
  0 siblings, 0 replies; 135+ messages in thread
From: Jason Gunthorpe via iommu @ 2022-04-05 16:15 UTC (permalink / raw)
  To: Alex Williamson, Lu Baolu, Christian Benvenuti, Cornelia Huck,
	David Woodhouse, Gerald Schaefer, iommu, Jason Wang,
	Joerg Roedel, kvm, linux-arm-kernel, linux-arm-msm, linux-rdma,
	linux-s390, Matthew Rosato, Michael S. Tsirkin, Nelson Escobar,
	netdev, Rob Clark, Robin Murphy, Suravee Suthikulpanit,
	virtualization, Will Deacon
  Cc: Tian, Kevin, Christoph Hellwig

PCIe defines a 'no-snoop' bit in each the TLP which is usually implemented
by a platform as bypassing elements in the DMA coherent CPU cache
hierarchy. A driver can command a device to set this bit on some of its
transactions as a micro-optimization.

However, the driver is now responsible to synchronize the CPU cache with
the DMA that bypassed it. On x86 this is done through the wbinvd
instruction, and the i915 GPU driver is the only Linux DMA driver that
calls it.

The problem comes that KVM on x86 will normally disable the wbinvd
instruction in the guest and render it a NOP. As the driver running in the
guest is not aware the wbinvd doesn't work it may still cause the device
to set the no-snoop bit and the platform will bypass the CPU cache.
Without a working wbinvd there is no way to re-synchronize the CPU cache
and the driver in the VM has data corruption.

Thus, we see a general direction on x86 that the IOMMU HW is able to block
the no-snoop bit in the TLP. This NOP's the optimization and allows KVM to
to NOP the wbinvd without causing any data corruption.

This control for Intel IOMMU was exposed by using IOMMU_CACHE and
IOMMU_CAP_CACHE_COHERENCY, however these two values now have multiple
meanings and usages beyond blocking no-snoop and the whole thing has
become confused.

Change it so that:
 - IOMMU_CACHE is only about the DMA coherence of normal DMAs from a
   device. It is used by the DMA API and set when the DMA API will not be
   doing manual cache coherency operations.

 - dev_is_dma_coherent() indicates if IOMMU_CACHE can be used with the
   device

 - The new optional domain op enforce_cache_coherency() will cause the
   entire domain to block no-snoop requests - ie there is no way for any
   device attached to the domain to opt out of the IOMMU_CACHE behavior.

An iommu driver should implement enforce_cache_coherency() so that by
default domains allow the no-snoop optimization. This leaves it available
to kernel drivers like i915. VFIO will call enforce_cache_coherency()
before establishing any mappings and the domain should then permanently
block no-snoop.

If enforce_cache_coherency() fails VFIO will communicate back through to
KVM into the arch code via kvm_arch_register_noncoherent_dma()
(only implemented by x86) which triggers a working wbinvd to be made
available to the VM.

While other arches are certainly welcome to implement
enforce_cache_coherency(), it is not clear there is any benefit in doing
so.

After this series there are only two calls left to iommu_capable() with a
bus argument which should help Robin's work here.

This is on github: https://github.com/jgunthorpe/linux/commits/intel_no_snoop

Cc: "Tian, Kevin" <kevin.tian@intel.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Jason Gunthorpe (5):
  iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with
    dev_is_dma_coherent()
  vfio: Require that devices support DMA cache coherence
  iommu: Introduce the domain op enforce_cache_coherency()
  vfio: Move the Intel no-snoop control off of IOMMU_CACHE
  iommu: Delete IOMMU_CAP_CACHE_COHERENCY

 drivers/infiniband/hw/usnic/usnic_uiom.c    | 16 +++++------
 drivers/iommu/amd/iommu.c                   |  9 +++++--
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |  2 --
 drivers/iommu/arm/arm-smmu/arm-smmu.c       |  6 -----
 drivers/iommu/arm/arm-smmu/qcom_iommu.c     |  6 -----
 drivers/iommu/fsl_pamu_domain.c             |  6 -----
 drivers/iommu/intel/iommu.c                 | 15 ++++++++---
 drivers/iommu/s390-iommu.c                  |  2 --
 drivers/vfio/vfio.c                         |  6 +++++
 drivers/vfio/vfio_iommu_type1.c             | 30 +++++++++++++--------
 drivers/vhost/vdpa.c                        |  3 ++-
 include/linux/intel-iommu.h                 |  1 +
 include/linux/iommu.h                       |  6 +++--
 13 files changed, 58 insertions(+), 50 deletions(-)


base-commit: 3123109284176b1532874591f7c81f3837bbdc17
-- 
2.35.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

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

end of thread, other threads:[~2022-04-07 22:39 UTC | newest]

Thread overview: 135+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 16:15 [PATCH 0/5] Make the iommu driver no-snoop block feature consistent Jason Gunthorpe via iommu
2022-04-05 16:15 ` Jason Gunthorpe
2022-04-05 16:15 ` Jason Gunthorpe
2022-04-05 16:16 ` [PATCH 1/5] iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with dev_is_dma_coherent() Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-06  5:30   ` Christoph Hellwig
2022-04-06  5:30     ` Christoph Hellwig
2022-04-06  5:30     ` Christoph Hellwig
2022-04-06  5:30     ` Christoph Hellwig
2022-04-06 12:07     ` Jason Gunthorpe via iommu
2022-04-06 12:07       ` Jason Gunthorpe
2022-04-06 12:07       ` Jason Gunthorpe
2022-04-06 13:51       ` Christoph Hellwig
2022-04-06 13:51         ` Christoph Hellwig
2022-04-06 13:51         ` Christoph Hellwig
2022-04-06 13:51         ` Christoph Hellwig
2022-04-06 14:14         ` Jason Gunthorpe via iommu
2022-04-06 14:14           ` Jason Gunthorpe
2022-04-06 14:14           ` Jason Gunthorpe
2022-04-06 15:47           ` Christoph Hellwig
2022-04-06 15:47             ` Christoph Hellwig
2022-04-06 15:47             ` Christoph Hellwig
2022-04-06 15:47             ` Christoph Hellwig
2022-04-06 15:48             ` Jason Gunthorpe via iommu
2022-04-06 15:48               ` Jason Gunthorpe
2022-04-06 15:48               ` Jason Gunthorpe
2022-04-06 15:48           ` Robin Murphy
2022-04-06 15:48             ` Robin Murphy
2022-04-06 15:48             ` Robin Murphy
2022-04-06 15:48             ` Robin Murphy
2022-04-06 13:56   ` Robin Murphy
2022-04-06 13:56     ` Robin Murphy
2022-04-06 13:56     ` Robin Murphy
2022-04-06 13:56     ` Robin Murphy
2022-04-06 14:24     ` Jason Gunthorpe via iommu
2022-04-06 14:24       ` Jason Gunthorpe
2022-04-06 14:24       ` Jason Gunthorpe
2022-04-06 15:18       ` Jason Gunthorpe via iommu
2022-04-06 15:18         ` Jason Gunthorpe
2022-04-06 15:18         ` Jason Gunthorpe
2022-04-06 15:50         ` Christoph Hellwig
2022-04-06 15:50           ` Christoph Hellwig
2022-04-06 15:50           ` Christoph Hellwig
2022-04-06 15:50           ` Christoph Hellwig
2022-04-06 16:06           ` Jason Gunthorpe via iommu
2022-04-06 16:06             ` Jason Gunthorpe
2022-04-06 16:06             ` Jason Gunthorpe
2022-04-06 16:10             ` Christoph Hellwig
2022-04-06 16:10               ` Christoph Hellwig
2022-04-06 16:10               ` Christoph Hellwig
2022-04-06 16:10               ` Christoph Hellwig
2022-04-06 17:17               ` Jason Gunthorpe via iommu
2022-04-06 17:17                 ` Jason Gunthorpe
2022-04-06 17:17                 ` Jason Gunthorpe
2022-04-07  7:18                 ` Tian, Kevin
2022-04-07  7:18                   ` Tian, Kevin
2022-04-07  7:18                   ` Tian, Kevin
2022-04-07  7:18                   ` Tian, Kevin
2022-04-07 13:59                   ` Jason Gunthorpe via iommu
2022-04-07 13:59                     ` Jason Gunthorpe
2022-04-07 13:59                     ` Jason Gunthorpe
2022-04-07 15:17                     ` Robin Murphy
2022-04-07 15:17                       ` Robin Murphy
2022-04-07 15:17                       ` Robin Murphy
2022-04-07 15:17                       ` Robin Murphy
2022-04-07 15:23                       ` Jason Gunthorpe
2022-04-07 15:23                         ` Jason Gunthorpe
2022-04-07 15:23                         ` Jason Gunthorpe via iommu
2022-04-07 22:37                         ` Alex Williamson
2022-04-07 22:37                           ` Alex Williamson
2022-04-07 22:37                           ` Alex Williamson
2022-04-07 22:37                           ` Alex Williamson
2022-04-07 15:31                       ` Christoph Hellwig
2022-04-07 15:31                         ` Christoph Hellwig
2022-04-07 15:31                         ` Christoph Hellwig
2022-04-07 15:31                         ` Christoph Hellwig
2022-04-07  8:53                 ` Niklas Schnelle
2022-04-07  8:53                   ` Niklas Schnelle
2022-04-07  8:53                   ` Niklas Schnelle
2022-04-05 16:16 ` [PATCH 2/5] vfio: Require that devices support DMA cache coherence Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 19:10   ` Alex Williamson
2022-04-05 19:10     ` Alex Williamson
2022-04-05 19:10     ` Alex Williamson
2022-04-05 19:10     ` Alex Williamson
2022-04-05 19:29     ` Jason Gunthorpe via iommu
2022-04-05 19:29       ` Jason Gunthorpe
2022-04-05 19:29       ` Jason Gunthorpe
2022-04-06  7:02       ` Tian, Kevin
2022-04-06  7:02         ` Tian, Kevin
2022-04-06  7:02         ` Tian, Kevin
2022-04-06  7:02         ` Tian, Kevin
2022-04-07 14:53         ` Jason Gunthorpe
2022-04-07 14:53           ` Jason Gunthorpe
2022-04-07 14:53           ` Jason Gunthorpe via iommu
2022-04-05 16:16 ` [PATCH 3/5] iommu: Introduce the domain op enforce_cache_coherency() Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 19:50   ` Alex Williamson
2022-04-05 19:50     ` Alex Williamson
2022-04-05 19:50     ` Alex Williamson
2022-04-05 19:50     ` Alex Williamson
2022-04-05 22:57     ` Jason Gunthorpe via iommu
2022-04-05 22:57       ` Jason Gunthorpe
2022-04-05 22:57       ` Jason Gunthorpe
2022-04-05 23:31       ` Tian, Kevin
2022-04-05 23:31         ` Tian, Kevin
2022-04-05 23:31         ` Tian, Kevin
2022-04-05 23:31         ` Tian, Kevin
2022-04-06  0:08       ` Tian, Kevin
2022-04-06  0:08         ` Tian, Kevin
2022-04-06  0:08         ` Tian, Kevin
2022-04-06  0:08         ` Tian, Kevin
2022-04-06  7:09   ` Tian, Kevin
2022-04-06  7:09     ` Tian, Kevin
2022-04-06  7:09     ` Tian, Kevin
2022-04-06  7:09     ` Tian, Kevin
2022-04-06 12:27     ` Jason Gunthorpe via iommu
2022-04-06 12:27       ` Jason Gunthorpe
2022-04-06 12:27       ` Jason Gunthorpe
2022-04-05 16:16 ` [PATCH 4/5] vfio: Move the Intel no-snoop control off of IOMMU_CACHE Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16 ` [PATCH 5/5] iommu: Delete IOMMU_CAP_CACHE_COHERENCY Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-06  6:52 ` [PATCH 0/5] Make the iommu driver no-snoop block feature consistent Tian, Kevin
2022-04-06  6:52   ` Tian, Kevin
2022-04-06  6:52   ` Tian, Kevin
2022-04-06  6:52   ` Tian, Kevin
2022-04-07 14:56   ` Jason Gunthorpe
2022-04-07 14:56     ` Jason Gunthorpe
2022-04-07 14:56     ` Jason Gunthorpe via iommu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.