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

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


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykola Kvach <Mykola_Kvach@xxxxxxxx>
  • Date: Thu, 3 Dec 2026 14:40:14 +0000
  • Accept-language: en-US, uk-UA
  • 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=4IEUYyE7+17jEsTC9HGGfnUYA9I7DAUp1XCkowZ28lQ=; b=IJeJhx/h5Fbndt/7LzPujcXLJP3XnQ5h2w1Ly6Kq/p/EWSnVVleEq/ZDhx1Mr+oZlfA0x3hYE7MGeeWte5LERdUh94RKyjlRELygpO+rtTGuv5gOiW4Mdaim6WDawHLRLTixsBjcm8QkW8i72Hj2F/lH9CqCN62sZyN39ZEd8D2WUbA5pEL1EKvRoCHHEb/t0kDh5TQHefXpOWXJn0fFk9gS9cFtaFsoeMNN36F9tX/GIXQraIV2WAZus3BCzLfQrbTIMzJge/ll/3z78OJWwaJtpp2BuHskLvPnUipIS7utOVCihgyueGQxmHFLZOE72Ui1h9AZBDpomRz07F012g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u41Pt9GKnMrwH9ZhnNA1IalkHUO0+tpohOmI/LgpnBaEj+EnW+3/tPfyXmlRVBediGJAwjuxYagBh9couR7z4CuEWAX7JXy3S7nH4IuiIZ+8hrC/d0ByriKWawVJI5eQ0x1bXPa4Oh3QIRPV2SBAnKVRNdrGjTe60PM955KiNdHmDGmAxzCJWK6W1DUkg5DFgZMkO/FdFlP5xiaD37KvvGK92BZkilr0HwfLIC+Hx01oAgADDhYnPwww2PsnDIwdj558EZq8yrPwTRhYc7biFpsf2AcFxH0+V0W9Rre5R6FFNs2JYE7T26U9OvXSHqvzXO1EumAe5QJrATFKCO0EyQ==
  • 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>, Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>
  • Delivery-date: Thu, 03 Dec 2026 14:40:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdgzQ1vuJGlfBptEy6U9vhdiiBPg==
  • Thread-topic: [PATCH v3] arm/smmuv3: clean stream tables for non-coherent hardware

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. Clean updated STE data in
arm_smmu_sync_ste_for_sid() before issuing CFGI_STE and CMD_SYNC.
Keep both sync points around the dst[0] update.

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>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
---
Changes in v3:
- Reuse l1size in arm_smmu_init_strtab_2lvl() to clean the L1 table
  after arm_smmu_init_l1_strtab() succeeds.

Changes in v2:
- Rename arm_smmu_clean_strtab() to arm_smmu_clean_dcache().
- Pass the STE pointer and clean size to arm_smmu_sync_ste_for_sid().
  Clean the given range there before CFGI_STE and CMD_SYNC. Keep the
  original clean ranges, both sync points around dst[0], and the
  explicit cleaning during table initialisation.
---
 xen/drivers/passthrough/arm/smmu-v3.c | 30 ++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index 232df2421c..472dd96ada 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_dcache(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)
 {
@@ -649,7 +657,8 @@ arm_smmu_write_strtab_l1_desc(__le64 *dst, struct 
arm_smmu_strtab_l1_desc *desc)
        write_atomic(dst, cpu_to_le64(val));
 }
 
-static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid)
+static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid,
+                                     const __le64 *dst, size_t size)
 {
        struct arm_smmu_cmdq_ent cmd = {
                .opcode = CMDQ_OP_CFGI_STE,
@@ -659,6 +668,7 @@ static void arm_smmu_sync_ste_for_sid(struct 
arm_smmu_device *smmu, u32 sid)
                },
        };
 
+       arm_smmu_clean_dcache(smmu, dst, size);
        arm_smmu_cmdq_issue_cmd(smmu, &cmd);
        arm_smmu_cmdq_issue_sync(smmu);
 }
@@ -736,7 +746,8 @@ static void arm_smmu_write_strtab_ent(struct 
arm_smmu_master *master, u32 sid,
                 * the STE regardless of whether the old value was live.
                 */
                if (smmu)
-                       arm_smmu_sync_ste_for_sid(smmu, sid);
+                       arm_smmu_sync_ste_for_sid(smmu, sid, dst,
+                                                 STRTAB_STE_DWORDS << 3);
                return;
        }
 
@@ -762,9 +773,9 @@ 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_sync_ste_for_sid(smmu, sid);
+       arm_smmu_sync_ste_for_sid(smmu, sid, dst, STRTAB_STE_DWORDS << 3);
        write_atomic(&dst[0], cpu_to_le64(val));
-       arm_smmu_sync_ste_for_sid(smmu, sid);
+       arm_smmu_sync_ste_for_sid(smmu, sid, dst, sizeof(*dst));
 
        /* It's likely that we'll want to use the new STE soon */
        if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH))
@@ -805,7 +816,10 @@ 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_dcache(smmu, desc->l2ptr, size);
        arm_smmu_write_strtab_l1_desc(strtab, desc);
+       arm_smmu_clean_dcache(smmu, strtab, STRTAB_L1_DESC_DWORDS << 3);
        return 0;
 }
 
@@ -1765,6 +1779,7 @@ static int arm_smmu_init_strtab_2lvl(struct 
arm_smmu_device *smmu)
        void *strtab;
        u64 reg;
        u32 size, l1size;
+       int ret;
        struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
 
        /* Calculate the L1 size, capped to the SIDSIZE. */
@@ -1795,7 +1810,11 @@ static int arm_smmu_init_strtab_2lvl(struct 
arm_smmu_device *smmu)
        reg |= FIELD_PREP(STRTAB_BASE_CFG_SPLIT, STRTAB_SPLIT);
        cfg->strtab_base_cfg = reg;
 
-       return arm_smmu_init_l1_strtab(smmu);
+       ret = arm_smmu_init_l1_strtab(smmu);
+       if (!ret)
+               arm_smmu_clean_dcache(smmu, strtab, l1size);
+
+       return ret;
 }
 
 static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)
@@ -1823,6 +1842,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_dcache(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®.