From 9434be947f3036a81f04de763aef90efdbedef74 Mon Sep 17 00:00:00 2001 From: YangWencheng Date: Tue, 14 Oct 2025 12:17:58 +0800 Subject: [PATCH] anolis: drivers/iommu/amd: Clear IOMMU page table entry C bit if IOMMU_PROT_MMIO is set in prot ANBZ: #26161 It makes no sence to set SME bit on IOMMU page table entry if the phyical address is PFN rather than DRAM, it even causes device P2P access fail, as device can't recognize SME bit, only memory controller can hanle SME bit properly. Signed-off-by: YangWencheng --- drivers/iommu/amd/amd_iommu_types.h | 3 ++- drivers/iommu/amd/io_pgtable.c | 2 ++ drivers/iommu/amd/iommu.c | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index ccbab3a4811a..208b0f180b39 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -441,9 +441,10 @@ #define IOMMU_PTE_PAGE(pte) (iommu_phys_to_virt((pte) & IOMMU_PAGE_MASK)) #define IOMMU_PTE_MODE(pte) (((pte) >> 9) & 0x07) -#define IOMMU_PROT_MASK 0x03 +#define IOMMU_PROT_MASK 0x07 #define IOMMU_PROT_IR 0x01 #define IOMMU_PROT_IW 0x02 +#define IOMMU_PROT_MMIO 0x04 #define IOMMU_UNITY_MAP_FLAG_EXCL_RANGE (1 << 2) diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c index 4d308c071134..8b4d406d49db 100644 --- a/drivers/iommu/amd/io_pgtable.c +++ b/drivers/iommu/amd/io_pgtable.c @@ -361,6 +361,8 @@ static int iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova, __pte |= IOMMU_PTE_IR; if (prot & IOMMU_PROT_IW) __pte |= IOMMU_PTE_IW; + if (prot & IOMMU_PROT_MMIO) + __pte = __sme_clr(__pte); for (i = 0; i < count; ++i) pte[i] = __pte; diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 83a29a61fa08..c9bd2700f86c 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2764,6 +2764,8 @@ static int amd_iommu_map_pages(struct iommu_domain *dom, unsigned long iova, prot |= IOMMU_PROT_IR; if (iommu_prot & IOMMU_WRITE) prot |= IOMMU_PROT_IW; + if (iommu_prot & IOMMU_MMIO) + prot |= IOMMU_PROT_MMIO; if (ops->map_pages) { ret = ops->map_pages(ops, iova, paddr, pgsize, -- Gitee