[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] arm/smmuv3: clean stream tables for non-coherent hardware


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Mykola Kvach <mykola_kvach@xxxxxxxx>
  • Date: Wed, 28 Oct 2026 01:53:35 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=byJ9sFmz24t4mtqdkmgsDp+GwT4BJiF9LkfjFfCoY0U=; b=vIZevLxj1kC9OX2a+z+j4mfrdMRDNF0TJsejHBwypw0wlPeYzwGHhMVIMgBvOWhakL1AAZarlqhIP4Xz1tuw8AwJcYwWPFBG6tflsF2iDIYLq9vPqEVMFxagQfaEhxteXFU0XSQjQDIAaFtaESHi85h1S+2qcYYtDD5JSyMBqqtJXMDXvw1+INDt2NYT7SQxhucsS92X6fXG/VO/mKo/qO2Qpadc5G5e+GsDSKhCEys6TUR9/xUqj7QzHEU8h/QJ/4bw0UJEA0guffXAA1VTksddTshOhhc9uHlpEWsfrP+e5h3bs7J26MpSGGZ+qtj/l5G9RkI7BoI5/lpjhpfEig==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PKdSEMFnBzO5OoVsZAr7NjGW5OD2qUOpDhtHmLaRFKffETwupQxHCRouuvYHE39Q/aJzRpk3XXjjFhCi6b5pPXTAbXNHoz+GSdWb6InHCyN2FUC368cWwgHZUqJK8mGp4dCM4oKbfOA67nUw/GBXAjHJMQUrYzYPpdMx7Lndu3nAKlT2w/zujy9x2Do4HDSRPKn3L19aot5lX3SHYCrI5UkhM4wj43fEUp6+Tx6haf8ek4HYccbbdQGUvs7sjfG4zqneib11aAAs2ZUQserCLF/NwS9DV6K0fQ36mTlh7BF7vFFWhXoLead5B4g7u9uvedrK40dYqgAE1Ki/sx4gSw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Bertrand Marquis <bertrand.marquis@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 27 Oct 2026 23:54:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Xen's dmam_alloc_coherent() returns cacheable memory. A non-coherent
SMMU cannot see writes that remain in the CPU cache.

On Orange Pi 5 (RK3588S), NVMe initialization failed with C_BAD_STREAMID
for SID 0x4100 while the CPU saw a populated L1 descriptor.

Clean new stream tables before use and updated STEs before the existing
configuration invalidations. Clean the L2 table before writing its L1
pointer, then clean the pointer. Skip these cache operations on coherent
SMMUs.

See Arm IHI 0070G.b, sections 3.15 and 3.21.3.1.

Fixes: 452ddbe3592b ("xen/arm: smmuv3: Add support for SMMUv3 driver")
Assisted-by: Codex:GPT-6.1
Signed-off-by: Mykola Kvach <mykola_kvach@xxxxxxxx>
---
 xen/drivers/passthrough/arm/smmu-v3.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index bf153227db..a396e2b9e0 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -637,6 +637,14 @@ static int arm_smmu_cmdq_issue_sync(struct arm_smmu_device 
*smmu)
 }
 
 /* Stream table manipulation functions */
+static void arm_smmu_clean_strtab(struct arm_smmu_device *smmu,
+                               const void *ptr, size_t size)
+{
+       /* Xen's dmam_alloc_coherent() returns cacheable memory. */
+       if (!(smmu->features & ARM_SMMU_FEAT_COHERENCY))
+               (void)clean_dcache_va_range(ptr, size);
+}
+
 static void
 arm_smmu_write_strtab_l1_desc(__le64 *dst, struct arm_smmu_strtab_l1_desc 
*desc)
 {
@@ -735,8 +743,11 @@ static void arm_smmu_write_strtab_ent(struct 
arm_smmu_master *master, u32 sid,
                 * The SMMU can perform negative caching, so we must sync
                 * the STE regardless of whether the old value was live.
                 */
-               if (smmu)
+               if (smmu) {
+                       arm_smmu_clean_strtab(smmu, dst,
+                                             STRTAB_STE_DWORDS * sizeof(*dst));
                        arm_smmu_sync_ste_for_sid(smmu, sid);
+               }
                return;
        }
 
@@ -762,8 +773,10 @@ static void arm_smmu_write_strtab_ent(struct 
arm_smmu_master *master, u32 sid,
                dst[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS,
                                                 STRTAB_STE_1_EATS_TRANS));
 
+       arm_smmu_clean_strtab(smmu, dst, STRTAB_STE_DWORDS * sizeof(*dst));
        arm_smmu_sync_ste_for_sid(smmu, sid);
        write_atomic(&dst[0], cpu_to_le64(val));
+       arm_smmu_clean_strtab(smmu, dst, sizeof(*dst));
        arm_smmu_sync_ste_for_sid(smmu, sid);
 
        /* It's likely that we'll want to use the new STE soon */
@@ -805,7 +818,11 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device 
*smmu, u32 sid)
        }
 
        arm_smmu_init_bypass_stes(desc->l2ptr, 1 << STRTAB_SPLIT);
+       /* Clean the L2 table before writing the L1 pointer. */
+       arm_smmu_clean_strtab(smmu, desc->l2ptr, size);
        arm_smmu_write_strtab_l1_desc(strtab, desc);
+       arm_smmu_clean_strtab(smmu, strtab,
+                             STRTAB_L1_DESC_DWORDS * sizeof(__le64));
        return 0;
 }
 
@@ -1700,6 +1717,9 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device 
*smmu)
                strtab += STRTAB_L1_DESC_DWORDS << 3;
        }
 
+       arm_smmu_clean_strtab(smmu, cfg->strtab,
+               cfg->num_l1_ents * STRTAB_L1_DESC_DWORDS * sizeof(__le64));
+
        return 0;
 }
 
@@ -1766,6 +1786,7 @@ static int arm_smmu_init_strtab_linear(struct 
arm_smmu_device *smmu)
        cfg->strtab_base_cfg = reg;
 
        arm_smmu_init_bypass_stes(strtab, cfg->num_l1_ents);
+       arm_smmu_clean_strtab(smmu, strtab, size);
        return 0;
 }
 
-- 
2.53.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.