public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iommu/amd: Avoid setting C-bit for MMIO addresses
@ 2025-11-03 14:00 Wei Wang
  2025-11-03 14:00 ` [PATCH v2 1/2] iommu/amd: Add IOMMU_PROT_IE flag for memory encryption Wei Wang
  2025-11-03 14:00 ` [PATCH v2 2/2] vfio/type1: Set IOMMU_MMIO in dma->prot for MMIO-backed addresses Wei Wang
  0 siblings, 2 replies; 20+ messages in thread
From: Wei Wang @ 2025-11-03 14:00 UTC (permalink / raw)
  To: alex, jgg, suravee.suthikulpanit, thomas.lendacky, joro
  Cc: kevin.tian, wei.w.wang, linux-kernel, iommu

When SME is enabled, iommu_v1_map_pages() currently sets the C-bit for
all physical addresses. This is correct for system RAM, since the C-bit is
required by SME to indicate encrypted memory and ensure proper
encryption/decryption.

However, applying the C-bit to MMIO addresses is incorrect. Devices and
PCIe switches do not interpret the C-bit currently, and doing so can break
PCIe peer-to-peer communication. To prevent this, avoid setting the C-bit
when the physical address is backed by MMIO.

Note: this patchset only updates vfio_iommu_type1. Corresponding changes
to iommufd to pass the IOMMU_MMIO prot flag will be added if this approach
is accepted.

v1->v2 changes:
- 1 used page_is_ram() in the AMD IOMMU driver to detect non-RAM
  addresses, avoiding changes to upper-layer callers (vfio and iommufd).
  v2 instead lets upper layers explicitly indicate MMIO mappings via the
  IOMMU_MMIO prot flag. This avoids the potential overhead of
  page_is_ram(). (suggested by Jason Gunthorpe) 
  v1 link: https://lkml.org/lkml/2025/10/23/1211

Wei Wang (2):
  iommu/amd: Add IOMMU_PROT_IE flag for memory encryption
  vfio/type1: Set IOMMU_MMIO in dma->prot for MMIO-backed addresses

 drivers/iommu/amd/amd_iommu_types.h |  3 ++-
 drivers/iommu/amd/io_pgtable.c      |  7 +++++--
 drivers/iommu/amd/iommu.c           |  2 ++
 drivers/vfio/vfio_iommu_type1.c     | 14 +++++++++-----
 4 files changed, 18 insertions(+), 8 deletions(-)

-- 
2.51.1


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

end of thread, other threads:[~2025-11-18 14:37 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03 14:00 [PATCH v2 0/2] iommu/amd: Avoid setting C-bit for MMIO addresses Wei Wang
2025-11-03 14:00 ` [PATCH v2 1/2] iommu/amd: Add IOMMU_PROT_IE flag for memory encryption Wei Wang
2025-11-07  1:02   ` Jason Gunthorpe
2025-11-07  2:39     ` Wei Wang
2025-11-10  9:55   ` Vasant Hegde
2025-11-11  1:18     ` Wei Wang
2025-11-11  4:44       ` Vasant Hegde
2025-11-03 14:00 ` [PATCH v2 2/2] vfio/type1: Set IOMMU_MMIO in dma->prot for MMIO-backed addresses Wei Wang
2025-11-07  1:03   ` Jason Gunthorpe
2025-11-07  2:38     ` Wei Wang
2025-11-07 14:16       ` Jason Gunthorpe
     [not found]         ` <SI2PR01MB4393E04163E5AC9FD45D56EFDCC3A@SI2PR01MB4393.apcprd01.prod.exchangelabs.com>
2025-11-07 15:57           ` Jason Gunthorpe
2025-11-07 16:19             ` Wei Wang
2025-11-07 16:36               ` Jason Gunthorpe
2025-11-07 17:56                 ` Tom Lendacky
2025-11-07 18:32                   ` Jason Gunthorpe
2025-11-07 19:59                     ` Tom Lendacky
2025-11-10  6:28                       ` Wei Wang
2025-11-10  9:55                       ` Vasant Hegde
2025-11-18 14:36                       ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox