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

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


  • To: Mykola Kvach <mykola_kvach@xxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Tue, 24 Nov 2026 17:42:31 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=epam.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=8Yn1VKXsfCjSXLVsfyDKydpn/WbjucjwTc+yAGL2zY8=; b=u+Jck6V82RfskFaXFpq9YohIAv76uDYaAuUPOSl673aBR8UcZ4esjqS/iWoWJCd7K1IGoAYpX+cyHwtrzQfMN6Kf/YNOgdlmHrSuoAZk9t2tHzbnphAsdYlXaqp/yECpn+EIXhlVrxk/Hv6d+B6cvxbiDzkmu+qgyAPW95Szif18BBuWRz5fyq0mA22jxWefZ/W13afx4Ux/bcBY9D/atyppyoGEyCC3dsOJj3gM9ZgvRBAKDN8BVDM8KzXyrErz4qiDC1xXivn87M3o5lQYA5YVve9cd/68VwVDwIMSuYjkBZ0PHEBE+Jdv4LRVCnzrsR0aRzO66KdIcPNtCryL+g==
  • 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=8Yn1VKXsfCjSXLVsfyDKydpn/WbjucjwTc+yAGL2zY8=; b=yshiWzu6EGJdKC+93rx1Ovq8/VsZCQBrOndzOzid76RqgCUlJ82/UE5X1xPVu3aDNXkqCWO96+tOrRbFUkmrjYo+C+fsI11ho8Qf/ZSOgplJbzJdPBV/k5ETto2fqTLVINwI3jjigCzyHikNy3h98ijILW5eM7FGMAstwFdWuDK6RXT5JPeSZxeS0Z4ilS7hF/un5IJLpDqOw9g0y3tF8FSe37nYfp4Mdbnk3gJx9yQL8Jyh2O5nLLEOL4SgpiqQhBg8t9K0MCk3JxJg+uRyHqXadTCbhx0x2T9ZWk1GGGQagErZIzaPXLeaslZc3R0yAbFKmK06sNxUL27sbSqSlg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=bFjaniMB7Uwrr5WdcBvCtpF/ZuXyOc/aFc50PlVSBbn0LNPSgHgwCvrzlg5F74s+Gi3+dlyqLwPlCZEjS62Yb5uZoj9fsZhmP5I9TTx5vjEJa9Qvq67TesuBbZBaQruINjKxLKrbzKN3ysi5PkDfxKPeWnC+fWleBpv6wKz/CouByra7VhtflVpQ0lDwRqFX+XdWAiuaOWoP7YesKnC5ue+4+e3ZIuojalEgMRrVx7HBj6Hm/X3/BqJ6EbMtNX/QQ2Z8oaGla2TCQJJR4WqZllFQZPlAkQPIll4ISuNw2Q664i/uHPM1e2+f1wgq1So7j/wJ72+F6aXBq80hZNiDyg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Uuj9r/97/mcLu329NOrTogclbImxBlv26bC9e3eFZ3QfCmCIUb7Xyt0uFoeSvLJSs/lzWfNXHOrn5epXhpKdVoiIqa9y8Vipu2ujviDoukj5alcWpZY2B+D9mFTHoCrnnzTOnN2gvsx5nHhm8O/JDEMFU+bDcW7svuvpn9Z+EYCyI7jmRhlmZvDsDswTvO+Onx1gXiJuSUU9Mo2HmO/b3Az5wuve47KrPyBLsvgY0x0lOiI70maoWg4p9InKZi2BYhmQ6l/ha3Hyo4Ym3wUDvCOoCnPwHZJRWGIjFVusNrgVFSP2AYkRM0yZZd9RARjx/BqBSfZU8WHq5PPvC0cfQA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results-original: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, 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, 24 Nov 2026 17:43:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHddcA7KSg86rXuDUWg7Tm+9FjlvLc9is4A
  • Thread-topic: [PATCH v2] arm/smmuv3: clean stream tables for non-coherent hardware

Hi Mykola,

On 16 Nov 2026, at 11:47, Mykola Kvach <mykola_kvach@xxxxxxxx> wrote:

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>
---
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 | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthrough/arm/smmu-v3.c
index 232df2421c..945a18a7a1 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);

I think there is a case we need to handle here. arm_smmu_add_device()
reaches this path after the SMMU is enabled.

- The SMMU may already have cached the inactive L1 descriptor.
- The CPU cache clean makes the updated descriptor visible in memory.
- The later leaf CFGI_STE can leave the inactive L1 descriptor cached,
  so DMA can still fail with C_BAD_STREAMID.

IHI 0070 section 5.1 requires a non-leaf invalidation when an inactive
L1 descriptor becomes active. We should issue a non-leaf CFGI_STE
followed by CMD_SYNC after publishing the updated descriptor.

There is a corresponding fix proposed for Linux [1].

I realise this issue predates the patch. Would you mind handling it
in the next version, or would you prefer to do it in a follow-up?

The rest of the patch looks good to me with the changes you agreed
with Oleksandr.

Cheers,
Bertrand




 


Rackspace

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