All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Make the iommu driver no-snoop block feature consistent
@ 2022-04-07 15:23 ` Jason Gunthorpe via iommu
  0 siblings, 0 replies; 84+ messages in thread
From: Jason Gunthorpe @ 2022-04-07 15:23 UTC (permalink / raw)
  To: Alex Williamson, Lu Baolu, Cornelia Huck, David Woodhouse, iommu,
	Joerg Roedel, kvm, Suravee Suthikulpanit, Will Deacon
  Cc: Christoph Hellwig, Tian, Kevin, Robin Murphy

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 may be 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. AMD IOMMU has the same feature and same IOPTE bits
however it unconditionally blocks no-snoop.

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/VFIO/etc when the user of the
   iommu_domain will not be doing manual cache coherency operations.

 - IOMMU_CAP_CACHE_COHERENCY 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.
   This is permanent on the domain and must apply to any future devices
   attached to it.

Ideally an iommu driver should implement enforce_cache_coherency() so that
by DMA API 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 iommu drivers are certainly welcome to implement
enforce_cache_coherency(), it is not clear there is any benefit in doing
so right now.

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

v2:
 - Abandon removing IOMMU_CAP_CACHE_COHERENCY - instead make it the cap
   flag that indicates IOMMU_CACHE is supported
 - Put the VFIO tests for IOMMU_CACHE at VFIO device registration
 - In the Intel driver remove the domain->iommu_snooping value, this is
   global not per-domain
v1: https://lore.kernel.org/r/0-v1-ef02c60ddb76+12ca2-intel_no_snoop_jgg@nvidia.com

Jason Gunthorpe (4):
  iommu: Introduce the domain op enforce_cache_coherency()
  vfio: Move the Intel no-snoop control off of IOMMU_CACHE
  iommu: Redefine IOMMU_CAP_CACHE_COHERENCY as the cap flag for
    IOMMU_CACHE
  vfio: Require that devices support DMA cache coherence

 drivers/iommu/amd/iommu.c       |  7 +++++++
 drivers/iommu/intel/iommu.c     | 17 +++++++++++++----
 drivers/vfio/vfio.c             |  7 +++++++
 drivers/vfio/vfio_iommu_type1.c | 30 +++++++++++++++++++-----------
 include/linux/intel-iommu.h     |  2 +-
 include/linux/iommu.h           |  7 +++++--
 6 files changed, 52 insertions(+), 18 deletions(-)


base-commit: 3123109284176b1532874591f7c81f3837bbdc17
-- 
2.35.1


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

end of thread, other threads:[~2022-07-01  6:24 UTC | newest]

Thread overview: 84+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 15:23 [PATCH v2 0/4] Make the iommu driver no-snoop block feature consistent Jason Gunthorpe
2022-04-07 15:23 ` Jason Gunthorpe via iommu
2022-04-07 15:23 ` [PATCH v2 1/4] iommu: Introduce the domain op enforce_cache_coherency() Jason Gunthorpe
2022-04-07 15:23   ` Jason Gunthorpe via iommu
2022-04-08  8:05   ` Tian, Kevin
2022-04-08  8:05     ` Tian, Kevin
2022-04-09 12:44     ` Lu Baolu
2022-04-09 12:44       ` Lu Baolu
2022-04-11 14:11     ` Jason Gunthorpe
2022-04-11 14:11       ` Jason Gunthorpe via iommu
2022-04-08  8:27   ` Tian, Kevin
2022-04-08  8:27     ` Tian, Kevin
2022-04-07 15:23 ` [PATCH v2 2/4] vfio: Move the Intel no-snoop control off of IOMMU_CACHE Jason Gunthorpe
2022-04-07 15:23   ` Jason Gunthorpe via iommu
2022-04-08  8:16   ` Tian, Kevin
2022-04-08  8:16     ` Tian, Kevin
2022-04-09 12:50     ` Lu Baolu
2022-04-09 12:50       ` Lu Baolu
2022-04-12  7:44       ` Tian, Kevin
2022-04-12  7:44         ` Tian, Kevin
2022-04-12 13:13         ` Lu Baolu
2022-04-12 13:13           ` Lu Baolu
2022-04-12 13:20           ` Jason Gunthorpe via iommu
2022-04-12 13:20             ` Jason Gunthorpe
2022-04-12 23:04             ` Tian, Kevin
2022-04-12 23:04               ` Tian, Kevin
2022-04-13 11:37               ` Lu Baolu
2022-04-13 11:37                 ` Lu Baolu
2022-04-08 15:47   ` Alex Williamson
2022-04-08 15:47     ` Alex Williamson
2022-04-11 14:13     ` Jason Gunthorpe
2022-04-11 14:13       ` Jason Gunthorpe via iommu
2022-04-07 15:23 ` [PATCH v2 3/4] iommu: Redefine IOMMU_CAP_CACHE_COHERENCY as the cap flag for IOMMU_CACHE Jason Gunthorpe
2022-04-07 15:23   ` Jason Gunthorpe via iommu
2022-04-08  8:21   ` Tian, Kevin
2022-04-08  8:21     ` Tian, Kevin
2022-04-08 12:21     ` Jason Gunthorpe
2022-04-08 12:21       ` Jason Gunthorpe via iommu
2022-04-09 12:51   ` Lu Baolu
2022-04-09 12:51     ` Lu Baolu
2022-04-07 15:23 ` [PATCH v2 4/4] vfio: Require that devices support DMA cache coherence Jason Gunthorpe
2022-04-07 15:23   ` Jason Gunthorpe via iommu
2022-04-08  8:26   ` Tian, Kevin
2022-04-08  8:26     ` Tian, Kevin
2022-04-08 12:22     ` Jason Gunthorpe via iommu
2022-04-08 12:22       ` Jason Gunthorpe
2022-04-08 13:28       ` Robin Murphy
2022-04-08 13:28         ` Robin Murphy
2022-04-08 13:37         ` Jason Gunthorpe
2022-04-08 13:37           ` Jason Gunthorpe via iommu
2022-04-08 15:48   ` Alex Williamson
2022-04-08 15:48     ` Alex Williamson
2022-07-01  4:57   ` Alexey Kardashevskiy
2022-07-01  4:57     ` Alexey Kardashevskiy
2022-07-01  6:07     ` Tian, Kevin
2022-07-01  6:07       ` Tian, Kevin
2022-07-01  6:24       ` Alexey Kardashevskiy
2022-07-01  6:24         ` Alexey Kardashevskiy
2022-04-07 17:03 ` [PATCH v2 0/4] Make the iommu driver no-snoop block feature consistent Robin Murphy
2022-04-07 17:03   ` Robin Murphy
2022-04-07 17:43   ` Jason Gunthorpe
2022-04-07 17:43     ` Jason Gunthorpe via iommu
2022-04-07 18:02     ` Robin Murphy
2022-04-07 18:02       ` Robin Murphy
2022-04-07 19:08       ` Jason Gunthorpe
2022-04-07 19:08         ` Jason Gunthorpe via iommu
2022-04-07 19:27         ` Robin Murphy
2022-04-07 19:27           ` Robin Murphy
2022-04-08 12:18           ` Jason Gunthorpe
2022-04-08 12:18             ` Jason Gunthorpe via iommu
2022-04-08 13:11             ` Robin Murphy
2022-04-08 13:11               ` Robin Murphy
2022-04-08 13:35               ` Jason Gunthorpe
2022-04-08 13:35                 ` Jason Gunthorpe via iommu
2022-04-08 17:44                 ` Robin Murphy
2022-04-08 17:44                   ` Robin Murphy
2022-04-12  2:51                   ` Tian, Kevin
2022-04-12  2:51                     ` Tian, Kevin
2022-04-08  9:08         ` Tian, Kevin
2022-04-08  9:08           ` Tian, Kevin
2022-04-08 10:11           ` Robin Murphy
2022-04-08 10:11             ` Robin Murphy
2022-04-12  2:49             ` Tian, Kevin
2022-04-12  2:49               ` Tian, Kevin

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.