From nobody Fri Sep 25 21:02:39 2026 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011005.outbound.protection.outlook.com [52.101.70.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A75EA48E0E7 for ; Mon, 21 Sep 2026 11:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.5 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789990281; cv=fail; b=h079x5DDlUnjxQGydMp2oMG15+2JiQFpor3dCQKTI96VuDe2Xn4q+kDDOtivygpT9s5KnltBlHMnHMO3eGwGP3deOLLGzq/3Az/nzgFw04jmSe3ypy37U1Du9dJ8Es2dELhXK2aKZkY55YHJgshyqxW1J1aAsAmmrTVHSWtTFFU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789990281; c=relaxed/simple; bh=w76LrviwoRXi1DOlKR7MnWMDfpZ4qGj3rLacMTnd53g=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=jNYaFSn46PqX+77Rg7OV13RZge8AmPpksMH71SS9JV2sN5LhzEad9eA7rmu1fcufYge+jNrD5OiROgdCp1wHWFSXhIrABwWvmXIvD+b5PrjUFZiH5vUPSwpIhGCli9cIBXBqI2vv7/j0R6UwDZikW+TfTshfHbzPvreLsa6nw/0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=JtzhnJ5Y; arc=fail smtp.client-ip=52.101.70.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="JtzhnJ5Y" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HgfGuraVCqFpUHUTAuekBbZqGkIctaBANUgLNI0U4ZdkgS/ghUIIYWOZyzji44w+tzl40W3Vba8S4LUVAB2kM3BOCYwevqjrZlp9YVWj+excIr4bBaMTt+1dOphUhVz6H429I5ygtDCpksPwQCZj/rJA8lPl6LftUJ9hTxIUzIwIMkYvmitvbPyHHeVlJpFGdYtBEYc7cx2qL3/Fw/yCanza/UHzYN3LnvaOPaq5C0gJbhCWLuystMLqInMSDHUzhdGhuhK47ytNArm7Y6NJe2gtBzRMtS4fQGaZJhqj+aOuLgNWfP5aZZ2/9O3MI0y/B8px270RSSvApE7NEGySHA== 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=lYR+CCfe7Nse5TyLdV8R6PaT5x5yrAjUFlHn+dCy7yU=; b=K1B8VFTMvu/8c80vmRnV8mnXyf8fB5YjSNMEh5uUWEirudhMH7S/GMhWM0hlgmGVzE9mDoBGXa2rZkCTKI63fP8v1dMlhV0VmrLfEB/4yUnIM/ODCU5lHr34HzHbew8tlsFGGc9J4BC5pd4vTwG2xGDk/xNVxlwcDhpKCXSGFfGCwj+4E+m50rS8hvRX70SNUC5HkvBWxXuxDaw/cjFrV6pbT7rPpK8XVC8GkR0w+fEV74wDlRoQ4tgEn+hVhPqVXUy3wn7ge2R/TdEilhXsGXV/nky9t0dN1n6+9pAp6KDXI5NT5fu9kTH7+GIMKHcQ08QO98TxbwXTrMmLmY6uaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lYR+CCfe7Nse5TyLdV8R6PaT5x5yrAjUFlHn+dCy7yU=; b=JtzhnJ5YpT41EUSmZoTz1P+MMuczpvwWT15MtwUzgi3dme2MXKguSJ+rFvkto8kSU0ij1+tTJVjerin95+zDju22PPnDc/xDxAWD7xpGjkcIj0N3B1VvOF8YeF65xVtkKgxxreSnNMRdih5wQbCgJJPjbDe7pq5DLZJEgxe28CJ1HA0zfjouyBwo8gC/v091HrSAkE9lzQ725IGpVhYI6NLwvoStb/OQLqEtojTwkipPVND0OaEveqPIh3js8Do1ekTroHz23Zwwv6NcSUPFDX8ToAWEK/hiWxTjCKxiYv+tSnvLlyRwzfDHR36N0jlSFUgoRFKVl/1jW9hwkEC6Ww== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) by VI0PR04MB10637.eurprd04.prod.outlook.com (2603:10a6:800:25f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.16; Mon, 21 Sep 2026 11:31:16 +0000 Received: from AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9]) by AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9%6]) with mapi id 15.21.0428.015; Mon, 21 Sep 2026 11:31:16 +0000 From: "Peng Fan (OSS)" Date: Mon, 21 Sep 2026 19:35:00 +0800 Subject: [PATCH RFC v2 1/4] iommu/arm-smmu-v3: Convert streams from RB tree to XArray Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-smmu-shared-sid-v2-1-4b656ce68178@nxp.com> References: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> In-Reply-To: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> To: Will Deacon , Robin Murphy , "Joerg Roedel (AMD)" , Jean-Philippe Brucker , Jason Gunthorpe Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Peng Fan X-Mailer: b4 0.16-dev-7bc12 X-ClientProxiedBy: MA5P287CA0043.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:175::6) To AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7874:EE_|VI0PR04MB10637:EE_ X-MS-Office365-Filtering-Correlation-Id: 67741980-5d52-4398-8060-08df17d3d955 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|376014|1800799024|366016|19092799006|10067099003|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: ijmPW31CZQO5l0bGL3MFCbE/hDecU3ictjC7ThYh96n23AUGJyOGd54L3dqeok4CxSA3u9iHB3gD484RIlL1lhNuDXdVLeIcWGKSB1rXlpa5RsWJmsHWB2prvBLcBf1FhK7DyY9c+WkjSMxHG+haW+QEfKo+gAaKtbvemQ++hrC6XzL6C1rvKZ6E1zfR2R+7pEGjHPFm4udjZgTTywHw/SRbmKSIdunsS+vtYXKVnFfAepRYj7r3DHU7OWm8SoOj2w7JoL8S4X2m7En9udOvW3xV+muA6amHKum0b6bSt5/PYrpudd9P9MUhcEM/wFwNPdAG6lALisgmz4n94lRy0653PDII9RJ9aH6CQTnO7F4I2p3UZy8tawLQ2BEOfvQ2M7uuQpvSuBTqYY8YSs8njPpocCdQKh9gP6rEVZWIUOtF/BnI6xzw3p7SpU6WuTZcTitAtrIRl9MpFaVxPZQpOZtUb6ypJax2y7obNqP28EkaMbsg+hlGahKygouD92s9HjuIJM34KM7XewR0llzauIvGGUozsVlsYPxejYdTc99cwujHtFjooaFoRvgssG6WO2xeuvTk2x85kVpCSUD6p7ZfdI3+1vwbVOMZ3lk2G8GDrmOZRZZ02qJozsggQsIWtxOna0izZknHYNtWii4kr+Ed2iOD5W7a1jv+GQgBmAo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7874.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(376014)(1800799024)(366016)(19092799006)(10067099003)(18002099003)(22082099003)(56012099006)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?THRtMndJZm9Yc2FqaWxQamVhNkdqT2lidFJ6dThZNHg1YVpzdUwyQ013VkZ6?= =?utf-8?B?cm1mUHVpVnh0cEJaYjEvN3hEczR1M05nRk94TkRpMGx2aDNFWEhUN3dvUEtk?= =?utf-8?B?NzJvT256SFZFcStDWU5vaVhlY1c5a2tLVGpxV202bW9sTVFvN0oxV2M4b3NT?= =?utf-8?B?QThXU1p2V2hIc0Q2WHVmbm40eHNOb2NZMEFpUHVQY0ZvQ2lkU0dTV0NITDJU?= =?utf-8?B?SlhyMkZDU3VGaW9tRXhlcWJ4VkcxdEt0cUVva0pmTnBydFo0K3ZxNGl5ek9D?= =?utf-8?B?S1dZekIxdzlOUzVEaThJSzRrR1JkTTJ0R1llUFFrWkNhdEt5WjJwVUdqQXBR?= =?utf-8?B?b2JZWEY1bzFSaFU1eHFK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kUmdK?= =?utf-8?B?OFhTdjVKMmRZK0RhSmdDeVI1dmt3RFljay9sNkVXaDViT3NrREJwQ2cwTzR0?= =?utf-8?B?ekpPQ09pU2NDd3YxK3EzNkpkcGdHZzZlZXZrUGRFUDY3MXNJV3lJUTlDckNO?= =?utf-8?B?djZ4eU83N2JVRHJRSUpTVWpMeGhtM1JvbmJadmsvN2s3WmkzbDJUa0p5V3h3?= =?utf-8?Q?hf8DVKARn4wPkYtIX4Akksx0rsRsY3cnjfJU6?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67741980-5d52-4398-8060-08df17d3d955 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7874.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2026 11:31:16.2764 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: N9f6ugbOgxlJTMoZoeYAVzvh9GlbVFleUk3mLed8gyzeMHrcc23pQ2DrOL8ONHQUCZREA87h4Z0WE8E6TY1+tyCGoKRj9BJ0WOd3ZgMnlf9G4jL3n42DLBOcn1n5/lGA X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR04MB10637 From: Peng Fan Replace the smmu->streams RB tree with an XArray for SID -> arm_smmu_stream lookups. The existing streams_mutex serialises all accesses (both xa_store/xa_erase and xa_load), protecting the lifetime of returned pointers against concurrent arm_smmu_remove_master() without requiring RCU grace periods. A mutex (rather than xa_lock) is needed because several paths sleep while the lock is held: dmam_alloc_coherent(GFP_KERNEL) in arm_smmu_init_sid_strtab(), and down_read() inside iommu_report_device_fault(). This removes the RB tree comparators, the rb_node from arm_smmu_stream, and simplifies duplicate-SID handling for bridged PCI devices. No behavioural change intended; preparation for shared-SID support. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Peng Fan --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 83 ++++++++++++++-----------= ---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 11 +++- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 5732f3ba0122d..65e448a69a019 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2024,37 +2024,17 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_= device *smmu, u32 sid) return 0; } =20 -static int arm_smmu_streams_cmp_key(const void *lhs, const struct rb_node = *rhs) -{ - struct arm_smmu_stream *stream_rhs =3D - rb_entry(rhs, struct arm_smmu_stream, node); - const u32 *sid_lhs =3D lhs; - - if (*sid_lhs < stream_rhs->id) - return -1; - if (*sid_lhs > stream_rhs->id) - return 1; - return 0; -} - -static int arm_smmu_streams_cmp_node(struct rb_node *lhs, - const struct rb_node *rhs) -{ - return arm_smmu_streams_cmp_key( - &rb_entry(lhs, struct arm_smmu_stream, node)->id, rhs); -} - static struct arm_smmu_master * arm_smmu_find_master(struct arm_smmu_device *smmu, u32 sid) { - struct rb_node *node; + struct arm_smmu_stream *stream; =20 lockdep_assert_held(&smmu->streams_mutex); =20 - node =3D rb_find(&sid, &smmu->streams, arm_smmu_streams_cmp_key); - if (!node) + stream =3D xa_load(&smmu->streams, sid); + if (!stream) return NULL; - return rb_entry(node, struct arm_smmu_stream, node)->master; + return stream->master; } =20 /* IRQ and event handlers */ @@ -4123,38 +4103,47 @@ static int arm_smmu_insert_master(struct arm_smmu_d= evice *smmu, NULL); =20 mutex_lock(&smmu->streams_mutex); - for (i =3D 0; i < fwspec->num_ids; i++) { + for (i =3D 0; i < master->num_streams; i++) { struct arm_smmu_stream *new_stream =3D &master->streams[i]; - struct rb_node *existing; + struct arm_smmu_stream *existing; u32 sid =3D new_stream->id; =20 ret =3D arm_smmu_init_sid_strtab(smmu, sid); if (ret) break; =20 - /* Insert into SID tree */ - existing =3D rb_find_add(&new_stream->node, &smmu->streams, - arm_smmu_streams_cmp_node); - if (existing) { - struct arm_smmu_master *existing_master =3D - rb_entry(existing, struct arm_smmu_stream, node) - ->master; - - /* Bridged PCI devices may end up with duplicated IDs */ - if (existing_master =3D=3D master) - continue; + /* Bridged PCI devices may end up with duplicated IDs */ + if (i > 0 && master->streams[i - 1].id =3D=3D sid) + continue; =20 + existing =3D xa_load(&smmu->streams, sid); + if (existing) { dev_warn(master->dev, "Aliasing StreamID 0x%x (from %s) unsupported, expect DMA to be broke= n\n", - sid, dev_name(existing_master->dev)); + sid, dev_name(existing->master->dev)); ret =3D -ENODEV; break; } + + /* + * xa_store() returns the old entry (void *) on success + * or an ERR_PTR on allocation failure. Use xa_err() to + * convert to a standard errno. + */ + ret =3D xa_err(xa_store(&smmu->streams, sid, new_stream, + GFP_KERNEL)); + if (ret) + break; } =20 if (ret) { - for (i--; i >=3D 0; i--) - rb_erase(&master->streams[i].node, &smmu->streams); + for (i--; i >=3D 0; i--) { + u32 sid =3D master->streams[i].id; + + if (i > 0 && master->streams[i - 1].id =3D=3D sid) + continue; + xa_erase(&smmu->streams, sid); + } kfree(master->streams); kfree(master->build_invs); } @@ -4167,14 +4156,19 @@ static void arm_smmu_remove_master(struct arm_smmu_= master *master) { int i; struct arm_smmu_device *smmu =3D master->smmu; - struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(master->dev); =20 if (!smmu || !master->streams) return; =20 mutex_lock(&smmu->streams_mutex); - for (i =3D 0; i < fwspec->num_ids; i++) - rb_erase(&master->streams[i].node, &smmu->streams); + for (i =3D 0; i < master->num_streams; i++) { + u32 sid =3D master->streams[i].id; + + /* Skip intra-master duplicate SIDs */ + if (i > 0 && master->streams[i - 1].id =3D=3D sid) + continue; + xa_erase(&smmu->streams, sid); + } mutex_unlock(&smmu->streams_mutex); =20 kfree(master->streams); @@ -4602,7 +4596,7 @@ static int arm_smmu_init_structures(struct arm_smmu_d= evice *smmu) int ret; =20 mutex_init(&smmu->streams_mutex); - smmu->streams =3D RB_ROOT; + xa_init(&smmu->streams); =20 ret =3D arm_smmu_init_queues(smmu); if (ret) @@ -5627,6 +5621,7 @@ static void arm_smmu_device_remove(struct platform_de= vice *pdev) =20 iommu_device_unregister(&smmu->iommu); iommu_device_sysfs_remove(&smmu->iommu); + xa_destroy(&smmu->streams); } =20 static void arm_smmu_device_shutdown(struct platform_device *pdev) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index dd2fee2f560e6..97dc97ac704d9 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -14,6 +14,7 @@ #include #include #include +#include =20 struct arm_smmu_device; struct arm_vsmmu; @@ -961,14 +962,20 @@ struct arm_smmu_device { /* IOMMU core code handle */ struct iommu_device iommu; =20 - struct rb_root streams; + /* + * XArray of arm_smmu_stream, indexed by SID. + * All accesses (reads and writes) are serialised by streams_mutex. + * The mutex is held across xa_load() and all subsequent uses of the + * returned pointer to prevent use-after-free from concurrent + * arm_smmu_remove_master(). + */ + struct xarray streams; struct mutex streams_mutex; }; =20 struct arm_smmu_stream { u32 id; struct arm_smmu_master *master; - struct rb_node node; }; =20 struct arm_smmu_vmaster { --=20 2.34.1 From nobody Fri Sep 25 21:02:39 2026 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011011.outbound.protection.outlook.com [52.101.70.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DA66498927 for ; Mon, 21 Sep 2026 12:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789994094; cv=fail; b=Smg+BrGkSqnnjeSQiwWzuNj4W3c08A/UGSgfWSZqYOBxMRHxzTjwzlJtenW4lX6YlRl085ZFLQCazDBkFKR38asAh/yo68R5fgWl3YWJRiMsgjWNcREcNs6Z/PDqAHjhKOYpIRqypcpHvaxMQvXDJTh/paahhA1lOUJsAa9NdW0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789994094; c=relaxed/simple; bh=nak7FVAxN8cQOLQ+DAJJzpH8R+4Ob2v4U3C3bNtEdBc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=dyriI4H9Mxxl1uwyiUB+4ybvMBF/lxR2G3htIX0QNpv4xuba6iron9kAEa9Jh0X1vWGdfQWpWRB2MLcyTihimQpTXD4OdgYshfmUlisTBL2dmjPT+yHCGRmCV4XqoLiF4TNIdQrDUALykp0NtNpv0kPoMP3fN2UtoH999+A0iyI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=qsaGG1lP; arc=fail smtp.client-ip=52.101.70.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="qsaGG1lP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tVmdju4Xad4hpu17IQLC3znT9DRbGN3jDVz+64mJIa9K+1cYQ8RW9aMr5pFBvlTGKzlJIsn6wOqxLDPyUQV+GNzoqrkQp8ekMMcE8V1BbZpJuHuq3hx63nusn+BTMkLnDHUe85jOTTuqcm+CREPPE3MBGPDRsaCEWihRoYMVZ5wONz2T5y6rd80EGY1Zbx6vzEb+ug7b0ipPtF60cZUSHydWJigJT+2xcCQhuQjyocFoy/OXAKplHpT6Pv59uFPcbIr+4Xbfhvu3AQ+5l6Ngt6SDKrbw59M0TmSbF5Xgxn1VorphRbczRZ1SXMdPSUOze0xrdx2eWZrAs20oMGpW2Q== 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=rEh8nJP0Bu9S+D5Xpz+LrHk0N2+O3O2q90oFsvUt/Z8=; b=l6WPUwSEvdI1jkMXZkYcnNH69lzYmUIzlnqg5r4xgSWmCWy4ptHajX6XOFCZacENkXYNlgFBjVoQ1lbO0PfcuQCFS9LDIi/PMxewm/Xltep8ZQQV/hFOTGW3ISV5QTVsw3soqkuMoTx2mJkJG2xRIPt3SxiocnrVl6mk0IVD3nooYdDLkGjg/ObqpCUZJ4BDQbOglTTjnMNZV1hUlC2dbUBo7KqtHIRddZDavDThoXPNCfxXo/oTnUFDpje+ET7RqMCg1c2XMSKKvqdJacXdFqP1Y4gwrLHzs9th6+B5xi4DTxg9skow07nNzmxgnFxBV++EA7lB9UMggTELz/4iCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rEh8nJP0Bu9S+D5Xpz+LrHk0N2+O3O2q90oFsvUt/Z8=; b=qsaGG1lPqlCTBHcuYx/crqS4+cpI5k5AXxaHfRmuqPsr0oafLk0sEKThABpKvRYJpZqzv2T8fuSLRQusiArtOH1T+XsAbo8IYnZm3ZStDXBraJlNKv8foFtUAzEbN/EjgbUC97f6HDUQEjYsljAqZVTAVVw9IEwl3jTQYci2x3LUjHJGI/6+TVD82884SpqYXXyeuYLmhn4uYWLgu/TcjbFWoWr9sTjrA3vUpC9B/r+htJC9qpfuha9FfCNytRwGE76JCy7fOz5KnmEiywkutOJfiIc601SQgTpQE/HjsKDimCYnRuG/uAiWlx64OKj6dAwsGuKKdDneqR179o/1Wg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) by PA1PR04MB10604.eurprd04.prod.outlook.com (2603:10a6:102:48e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.16; Mon, 21 Sep 2026 12:34:44 +0000 Received: from AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9]) by AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9%6]) with mapi id 15.21.0428.015; Mon, 21 Sep 2026 12:34:44 +0000 From: "Peng Fan (OSS)" To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, jpb@kernel.org, jgg@ziepe.ca Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, peng.fan@nxp.com Subject: [PATCH RFC v2 2/4] iommu/arm-smmu-v3: Support shared SIDs in insert/remove_master Date: Mon, 21 Sep 2026 20:38:46 +0800 Message-Id: <20260921123846.1663580-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> References: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI1PR02CA0004.apcprd02.prod.outlook.com (2603:1096:4:1f7::12) To AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7874:EE_|PA1PR04MB10604:EE_ X-MS-Office365-Filtering-Correlation-Id: 189fc34b-79ab-48f8-cbe2-08df17dcb735 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|19092799006|376014|1800799024|23010399003|10067099003|56012099006|18002099003|22082099003|11063799006; X-Microsoft-Antispam-Message-Info: a8E+pRAEv7eFNZ8EakQrJkBfDvJYN7b8bwwPXWPMUcVK75iIfxodvoudCfvr0SEYBeOuLn++esRTlJg2MhGht2f0mV4P6i9WQudLVJnH80YRX3zbAWhfgXPNZ5o4kmLxTO5y90KTChy/TvKocVqJ/bJCeeMuEGR2u3ctVyUQ7qrwu/anMhf+AkO9Bho86DGRhWcygFqrsS9jb0YGScLm3hEpgnJMyuXn1wM1kpbknPvN6pWrpsh88yNjKS5H69Fji5dYR12DYb6BNeY8L9DR18rKmBok598zii9TSVvQZyiL/x1xo5lceRp0lxGRxGXKmayGALeiMTTHn/y4kntorznoccntrFgLNrZzQsgcVtZMjMcrUETLMCHb30R+uALZBVANAZPcVImFOHMQ8uFMBJsZQar4tro17aupR1oJIsi/IatJO9YKQ/9CXyWw/mPcf5t7lavx18o8hJb6udd3Cvd+j+8AiUuBXBR4hHVECjzeknq6c7g1CxgC2M/62GomdiQ6I/YgclHXtEClWDkK/xen58+kyh+ZriHCjaMtnaCfsCK2GYI8AMTktwbpSIALzSKKTIpEqeFlzFuGHXRfF2kfctOueUQTHHo1efT1dQLEeEGhyIcX4W8OzD5PBjLNw4u699r4AVjkodcUgTB3xKrahJm3rFvNIayFJ5BAalc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7874.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(19092799006)(376014)(1800799024)(23010399003)(10067099003)(56012099006)(18002099003)(22082099003)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?e5me87vpBPH9J2aRN7Qgu1u8umZvt6fGYLgG0QqC5Ac56+UpFxKJNcYMORRW?= =?us-ascii?Q?XmOYwEZ+/SZKchPEAtr842+VK40dPzw06OKLUJsJ4uXPOZ2xSreVXdQsPTm3?= =?us-ascii?Q?PziBG8T7zjdI9JwmQFT+WDaU2Vo6eEP2yqw+9lY5hYn1IxYuS3Ow/PyGtXM7?= =?us-ascii?Q?KfTWQ1XGB6XrkO7U/noegxQmaFlhpKOtLnnX0v6ebREcyeD1hYS58NPLts+N?= =?us-ascii?Q?cnbta5YUl5b1vP9ZwuxCJbTeoUoMSpP7h/7UhvSHe/t/wtDG2Cmf1C/qtnWy?= =?us-ascii?Q?LlRYPawb4m6tq6s2hG0dlrLDSSGhbhHVis+rMoNj47Duz4RYgGfc4Qxsdkr+?= =?us-ascii?Q?vnk5qKFk7D9G/28RZ2q9TLPVJL2T7TiEnVNQb4QtwhqgDBzJWQ7Hbp9HyEYq?= =?us-ascii?Q?+Nw8ZGt6kYqDb+ft/PURaJ8MkEMeB3x8kaArMveWC1/ce0k600yQidYXSnLt?= =?us-ascii?Q?/B7eLDfirXQhG8kyfDa4IfrbuLWE1NHjdssLnxnWkCNZSlCSedAv47Ylk/cx?= =?us-ascii?Q?GNWx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t/L5ZLWbf4Z?= =?us-ascii?Q?PACi3l+Uj/9yfZDSZkk8jX60VpeGEIsEY1WuiW4xhS4Vmq+nZJw1EQj44tDe?= =?us-ascii?Q?T8bvIGDWSJuxK4TS6XQZMwF8NWujXB3Y8kyOEHhj766OoyRscapYZiKVmX2N?= =?us-ascii?Q?hbEEwGE9imzGuKrcIoTSRE6mIFuwCLvvaE0Wk6mheT8yHPTIu0y09kW/Sb1A?= =?us-ascii?Q?u0S7IbihVEk8X714nYRXjRcNAvhg7IiBQqnAFDW6vU42AwEFye43VUNysHEf?= =?us-ascii?Q?2l1wtuYVKalAI+KkAUM7Zll9WpYAghA3tbQwDFBGX6pxt5dLkPbNwCd6cQRo?= =?us-ascii?Q?Wmi2zPxfoMPexraCzeISuJKV5wY0fglMq+P3Yva5TQLPYxYgPWAy?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 189fc34b-79ab-48f8-cbe2-08df17dcb735 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7874.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2026 12:34:44.5284 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: w4wiW2JtFT0SWb+hE6qDgi3XEwQiv2RFnNkz9yge3ITDLHcQEVsKEApQ/oFEdyis5DffEkNPeZSMJ8c31zOvU4JRG+0uYN/5owyqGKk4lB7L4AHznKZC7XcaeWjXyL9z X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10604 Content-Type: text/plain; charset="utf-8" From: Peng Fan When arm_smmu_insert_master() encounters a SID already owned by a different master, instead of failing with -ENODEV, increment the canonical stream's ref_count and mark both masters as shared_sid. A per-SID shared_link list tracks all co-sharing streams so that ownership can be transferred when the canonical owner is removed. When arm_smmu_remove_master() removes a master: - Owning master with ref_count > 1: transfer the XArray entry to the next sharer via list_first_entry + xa_store, and clear shared_sid on the successor when ref_count drops to 1. - Owning master with ref_count =3D=3D 1: xa_erase (sole owner). - Non-owning sharer: list_del + ref_count--. Clear shared_sid on the canonical owner when ref_count drops to 1. New fields: - arm_smmu_stream: ref_count, ste_installed, shared_link (list_head) - arm_smmu_master: shared_sid (disables SVA, stall, IOPF) Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Peng Fan --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 88 +++++++++++++++++---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 23 ++++++ 2 files changed, 94 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 65e448a69a019..f53e1871426a5 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4095,6 +4095,7 @@ static int arm_smmu_insert_master(struct arm_smmu_dev= ice *smmu, =20 new_stream->id =3D fwspec->ids[i]; new_stream->master =3D master; + INIT_LIST_HEAD(&new_stream->shared_link); } =20 /* Put the ids into order for sorted to_merge/to_unref arrays */ @@ -4118,31 +4119,46 @@ static int arm_smmu_insert_master(struct arm_smmu_d= evice *smmu, =20 existing =3D xa_load(&smmu->streams, sid); if (existing) { - dev_warn(master->dev, - "Aliasing StreamID 0x%x (from %s) unsupported, expect DMA to be broke= n\n", - sid, dev_name(existing->master->dev)); - ret =3D -ENODEV; - break; + /* + * Another master already owns this SID. Bump the + * refcount, mark both masters as sharing, and link + * our stream so ownership can be transferred later. + */ + existing->ref_count++; + existing->master->shared_sid =3D true; + master->shared_sid =3D true; + list_add_tail(&new_stream->shared_link, + &existing->shared_link); + } else { + new_stream->ref_count =3D 1; + new_stream->ste_installed =3D false; + ret =3D xa_err(xa_store(&smmu->streams, sid, new_stream, + GFP_KERNEL)); + if (ret) + break; } - - /* - * xa_store() returns the old entry (void *) on success - * or an ERR_PTR on allocation failure. Use xa_err() to - * convert to a standard errno. - */ - ret =3D xa_err(xa_store(&smmu->streams, sid, new_stream, - GFP_KERNEL)); - if (ret) - break; } =20 if (ret) { + /* Undo any successful insertions / refcount bumps */ for (i--; i >=3D 0; i--) { + struct arm_smmu_stream *existing; u32 sid =3D master->streams[i].id; =20 if (i > 0 && master->streams[i - 1].id =3D=3D sid) continue; - xa_erase(&smmu->streams, sid); + + existing =3D xa_load(&smmu->streams, sid); + if (!existing) + continue; + if (existing->master =3D=3D master) { + xa_erase(&smmu->streams, sid); + } else { + list_del_init(&master->streams[i].shared_link); + existing->ref_count--; + if (existing->ref_count =3D=3D 1) + existing->master->shared_sid =3D false; + } } kfree(master->streams); kfree(master->build_invs); @@ -4163,11 +4179,49 @@ static void arm_smmu_remove_master(struct arm_smmu_= master *master) mutex_lock(&smmu->streams_mutex); for (i =3D 0; i < master->num_streams; i++) { u32 sid =3D master->streams[i].id; + struct arm_smmu_stream *stream; =20 /* Skip intra-master duplicate SIDs */ if (i > 0 && master->streams[i - 1].id =3D=3D sid) continue; - xa_erase(&smmu->streams, sid); + + stream =3D xa_load(&smmu->streams, sid); + if (!stream) + continue; + + if (stream->master =3D=3D master) { + /* + * This master owns the canonical XArray entry. + * Erase when the last reference drops; otherwise + * transfer ownership to the next sharer. + */ + stream->ref_count--; + if (stream->ref_count =3D=3D 0) { + xa_erase(&smmu->streams, sid); + } else { + struct arm_smmu_stream *next; + + next =3D list_first_entry(&stream->shared_link, + struct arm_smmu_stream, + shared_link); + list_del(&stream->shared_link); + next->ref_count =3D stream->ref_count; + next->ste_installed =3D stream->ste_installed; + xa_store(&smmu->streams, sid, next, + GFP_KERNEL); + if (next->ref_count =3D=3D 1) + next->master->shared_sid =3D false; + } + } else { + /* + * Non-owning sharer: unlink from the shared list + * and drop the refcount on the canonical entry. + */ + list_del_init(&master->streams[i].shared_link); + stream->ref_count--; + if (stream->ref_count =3D=3D 1) + stream->master->shared_sid =3D false; + } } mutex_unlock(&smmu->streams_mutex); =20 diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index 97dc97ac704d9..cf245b5de2bd2 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -976,6 +976,24 @@ struct arm_smmu_device { struct arm_smmu_stream { u32 id; struct arm_smmu_master *master; + /* + * ref_count > 1 means multiple masters share this SID. Protected by + * smmu->streams_mutex. + */ + unsigned int ref_count; + /* + * When ref_count > 1 the STE has already been written by the first + * master; subsequent masters must skip the write. + */ + bool ste_installed; + /* + * Links all arm_smmu_stream objects that share the same SID across + * different masters. The canonical (XArray-stored) entry is the list + * head; non-owning sharers are linked into it. Used to transfer + * XArray ownership when the current owner is removed. + * Protected by smmu->streams_mutex. + */ + struct list_head shared_link; }; =20 struct arm_smmu_vmaster { @@ -1024,6 +1042,11 @@ struct arm_smmu_master { bool ste_ats_enabled : 1; bool stall_enabled; bool ats_always_on; + /* + * True when at least one of this master's SIDs is shared with another + * master. SVA, stall and IOPF are disabled for such masters. + */ + bool shared_sid; unsigned int ssid_bits; unsigned int iopf_refcount; }; --=20 2.34.1 From nobody Fri Sep 25 21:02:39 2026 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013018.outbound.protection.outlook.com [52.101.72.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1F9949AA36 for ; Mon, 21 Sep 2026 12:36:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.72.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789994208; cv=fail; b=L9ZDBYvv7zmmHDIBFsmCGB42X8pQgMXrWKwaKuHk22/IxB70i7aPjwjBIifgiGHu9qp6rwZoNaropyH/xBSAsiJb4bXP4lmIB/i0masY6fcg1wDS6VoegWunSzrog5AmY+q/yq4we4Ri53tLgpEsktasSk2USavqIiFqKBtu0FA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789994208; c=relaxed/simple; bh=kPCHrfRWRxCV+0yr3XkTzgqUZgeLwbjN3rJORcVZi+o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=cA9K87odAzOjmqC5w8RmdYlP0DzoaoP9KnZtG5YyzSuxdFIq6JUgCMBPJjRtVGBG8PeVANV2UX/UdIGFV00EcSNxDbQtHpeJLXvn7lq6BTMPC+TXUvcgGIUMXr/a1u2LaGI/pi/TN/XMlQl3NeAu0kJBB8mDpwkMP/jlZ7SuY/s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=NLrL0oR7; arc=fail smtp.client-ip=52.101.72.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="NLrL0oR7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Khw0bfy65b1Yu2bGH50/kMh13rhg+6SOppXuv2Zh1FQQvSgyaTpveQRaTglVl+awddwZ1aImQ3QdRKl6BC7hdfZGeiPI6T5OisdE2aC7v3p280NzO8E+CROH55EonwnFCYPJH3L2W46oNNqHwGOoAmMVs9lKFUeLfVRiYD5WF3qcglrgvkI2fwQY0cc3DA3emIyCMjN1j5575MfaCuqnIjxDRHUkFazj2RRJXEbm3tuQDSEsMO5OaMDVuTxAelKQyfmjNztIughsK8LsQS8My5E33Vk6+kYmCEiu5LoMhYujnLmg5D2NfqNt89jQndGgS6S2KrxEuBs0TrPbI7gpGA== 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=crMJ5fwvhDLCfNoZh5OsD4lev7sJytrb8LKXxd6zrgQ=; b=mQNGfH3IPRPs3Fk5KJ7ADxLOtBQb6QuK6sSulKEPKrcjelLe+ehTN6U60xMEhxEet2KVfogDW6EwRorZca6YggBCJnn9x7elNGo8droPd2D4b7OpE/IpiwB4KKUlJPVX1sbm9ScnBwKg/O5BwbNq/rXf8zm3UrDsnFU2NvvJHRpHJCBMJuD+x1rXRTwlEYF9LlBs8fWn5ki5iUZDyDAbspLJf0bUM/wXW/w+vUGZDnLcKj+dhgLk6A9j31LAV+I873EcSN18dWkGSMROXJVDsEXQ49jnqcKQXnp8LmkiQkigBrvqSEu2N8A2h3B7RE3pukJ3SZiONsbgS93YBxt9Yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=crMJ5fwvhDLCfNoZh5OsD4lev7sJytrb8LKXxd6zrgQ=; b=NLrL0oR7XXJM6Yt3cX4vKDm2xlsw7RD2/Hu0eNaeqOQ6pziNN6cx2boGp4ymJ13mliAJr+Nfze7r5u4q6gyY+I5Hs/pVxzKslRzLIqiYGXCZLBSYDS5/pP7k4s+4xmLdXsBuPyMzblqJzq3XZVvTMS9lnya19NPu5QePuWxCOWqpHgzaat1w79Nogq/r1tsbYi7wifjU5eJssQKrJUgjvaOda5JRfuWnZsU+GvjYYe3GdgWmGm0KibSsXGuzcKIp0FHgIb+srVI6GO1+W6dMrhQkpQFZmUcsHWKTjBGuKBUuETFWSYm+a4BNGtmz+wHdgVKWSFcWMAyeV24Oru8r8A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) by AM8PR04MB7907.eurprd04.prod.outlook.com (2603:10a6:20b:237::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.16; Mon, 21 Sep 2026 12:36:37 +0000 Received: from AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9]) by AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9%6]) with mapi id 15.21.0428.015; Mon, 21 Sep 2026 12:36:37 +0000 From: "Peng Fan (OSS)" To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, jpb@kernel.org, jgg@ziepe.ca Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, peng.fan@nxp.com Subject: [PATCH RFC v2 3/4] iommu/arm-smmu-v3: Group aliasing devices into the same IOMMU group Date: Mon, 21 Sep 2026 20:40:57 +0800 Message-Id: <20260921124057.1664114-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> References: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI3PR01CA0014.apcprd01.prod.exchangelabs.com (2603:1096:4:296::10) To AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7874:EE_|AM8PR04MB7907:EE_ X-MS-Office365-Filtering-Correlation-Id: 3fc8eade-4760-42ab-7325-08df17dcfa1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|23010399003|376014|19092799006|6133799003|10067099003|11063799006|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: dW41/0f0/i2LIZ7EKawaW/5kNT1CvZVLFi4HlDbRplZ7HqBB88IKdxzaBnm39z9VSXpzcDnZ8yTR54k7V+WWu5+cu/8AY/D5tnJ5DyGOx1HXABajgjLPCNG8dxINxaK+d3goTRdGObB/vcUk9CVTQLo4cILRFBy+ygswDS2NfThqPZ1UUHa7DG2jYazvZxWOCk1yKZumnMIgJIgvz2lh4MMkHtrcHsaHw0qtXJPd7wQlNc4hZ8BcY62fX3hwS4FuO293UIBh7m6WFYY3Jbj6qfXHDM+sL19YfdaO2SYWMV1ZVBYrDN8+YMLVNDOuvR0BJpUxic7OuKxeOtWxm9J6Yc7IxFI47Wx+o8dB2CmbGKLexIDWCPa1N2bSh0qvT3chvl+U2LVIEKGAQDfOyD99xutfEQrxwGXFy7ZfDZJxzV6SZuYFV6wEnrcCmTbDYuuqmoztbV6+mNbHAtoyaqq1boAnFaLEIPfMkTikfhQ5Oxw+B5FhFTJixW9VNE2L+LTTt4IqK5CCRLEMSif+DsM5O8PekOX/8dGsHiYmYExqJ6r7Nm3HrKi8FmSlUdU4PKEWFf/H1iNG0cT09F3wHCz3k7d7XYt50WeBqFOJBscECxobby8Kl0S2yG7PSr5W8JWqIuBCchCzI/vP71GsTLhB8UJAcIOOOoa9bmn1Ud9EoZo= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7874.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(19092799006)(6133799003)(10067099003)(11063799006)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?K05xWDlBU0p4YXFwcVRPM3BhaGxMRCtNeCt1c1l0SlR2Z0hhMVNRNC9jTk5W?= =?utf-8?B?SU01ajh5WHVjd1JqZDRoYXJHdTNQaWFLZ3BtSUpqN09UU2tzbkJwU3Y1eXI1?= =?utf-8?B?dFRkRDgwd211dkxVUDNXS1NaN1A2eGxmay9OR0IzMTlXTEZtRjVZWnYrNUZl?= =?utf-8?B?c21PSER5NzU0eDFQRC9uZVlLVzZnZWNUK2JJNm5DQ2g5N3FGV0F0UDB1WjhO?= =?utf-8?B?blRYdXRqRFl6eXhWSWJGU24vWGNSS1ZwR3RKc2FEd2swREVwaEprRld4RUs4?= =?utf-8?B?eExjeEkzcTJaUEdlWkYwSUxlWCtGVE42aUlmZGFiOEFSdzJCQy85UE5IOUZN?= =?utf-8?B?VTA2ZVVuNUt5OG9ycEJ2eVBtL283T2twUjJHNkNTcUhFTjlJL21CTWJNb1FJ?= =?utf-8?B?bHhMbS9Ea2dNbkFqWlNaZlhNRU9lOTBhTjNjWGFFUllwY0VyNUFpYmVOWWVD?= =?utf-8?B?Tk1LKzNPRm5hZkRHb1VJUTViL0VKczNvanc2Z0M2ZGpqNnJNM3ZBalgxUXI0?= =?utf-8?B?bWxHRzltUUNzcEZhSFVZcGwyQmdnTUtDa1c4dDBOUVJ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dXevskApngNmnYZiENe3?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fc8eade-4760-42ab-7325-08df17dcfa1e X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7874.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2026 12:36:36.9942 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dx0R0OZ/IlUK62fntwiNxaoUpLoLS0xDaS4t7frU2EKMEJ89jKvf5qTfx5nxnOk6GvbL2izZHkZyyhEN1gEMDjd9gGpA4qyAyRltCpdtTeqUHm3Uda0iolhb2EiD7dka X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7907 From: Peng Fan arm_smmu_device_group() previously rejected SID aliasing with a comment saying it was impractical. Now that the XArray makes SID lookup O(1), detect aliasing at group-assignment time and place the new device into the same IOMMU group as the master that already owns the SID. This is a prerequisite for shared-SID support: devices sharing a SID must share a single IOMMU domain and therefore a single cd_table, because the STE can only point to one cd_table at a time. arm_smmu_device_group() is called before arm_smmu_insert_master() adds the current master's streams to the xarray, so any xarray hit here belongs to a different, already-probed master. streams_mutex is held to ensure the xarray is stable and the returned stream object is not freed concurrently. If a device has multiple SIDs that land in different existing groups, a warning is emitted. The IOMMU core has no group-merge API, so this cannot be fixed up and DMA isolation may be compromised. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Peng Fan --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 61 ++++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index f53e1871426a5..bb3ee25d10d6e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -4365,19 +4365,64 @@ static int arm_smmu_set_dirty_tracking(struct iommu= _domain *domain, =20 static struct iommu_group *arm_smmu_device_group(struct device *dev) { - struct iommu_group *group; + struct arm_smmu_master *master =3D dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu =3D master->smmu; + struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + struct iommu_group *group =3D NULL; + int i; =20 /* - * We don't support devices sharing stream IDs other than PCI RID - * aliases, since the necessary ID-to-device lookup becomes rather - * impractical given a potential sparse 32-bit stream ID space. + * If any of this device's SIDs are already owned by another master, + * place this device in the same IOMMU group as that master. This + * ensures that aliasing devices share a single domain and therefore + * a single cd_table, which is required because the STE can only + * point to one cd_table at a time. + * + * arm_smmu_device_group() is called before arm_smmu_insert_master() + * adds the current master's streams to the xarray, so any hit here + * belongs to a different, already-probed master. + * + * streams_mutex is held to ensure the xarray is stable and the + * returned stream object is not freed concurrently. */ + mutex_lock(&smmu->streams_mutex); + for (i =3D 0; i < fwspec->num_ids; i++) { + struct arm_smmu_stream *stream =3D + xa_load(&smmu->streams, fwspec->ids[i]); + struct iommu_group *existing; + + if (!stream) + continue; + + existing =3D iommu_group_get(stream->master->dev); + if (!group) { + group =3D existing; + } else if (group !=3D existing) { + /* + * This device has SIDs in two different groups. + * The IOMMU core has no group-merge API, so we + * cannot fix this up. Warn and keep the first + * group =E2=80=94 the mismatched SID will still be + * inserted into the XArray and shared, but DMA + * isolation is compromised. + */ + dev_warn(dev, + "SID 0x%x already in a different IOMMU group than SID 0x%x, expect br= oken isolation\n", + fwspec->ids[i], fwspec->ids[0]); + iommu_group_put(existing); + } else { + iommu_group_put(existing); + } + } + mutex_unlock(&smmu->streams_mutex); + + if (group) + return group; + if (dev_is_pci(dev)) - group =3D pci_device_group(dev); - else - group =3D generic_device_group(dev); + return pci_device_group(dev); =20 - return group; + return generic_device_group(dev); } =20 static int arm_smmu_of_xlate(struct device *dev, --=20 2.34.1 From nobody Fri Sep 25 21:02:39 2026 Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011060.outbound.protection.outlook.com [40.107.130.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAE4C421224 for ; Mon, 21 Sep 2026 12:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.130.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789994222; cv=fail; b=UBQRO8MwEe1f2XnJlhbJv5YjyXS2DGrO8ffUo9KaH7S9A56x7pNfrMAlVW+3yrMaErEw18XsnoFDqM6bH2XqJZJYjHwnznLCIAXK+mS5o36hW9sbIdhy0SoK87Z8dEFtXiAFCuxWcK7lNdNwgu+7QcD2h6pRD4HLDvtQiLd/PRQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789994222; c=relaxed/simple; bh=umXTb/1OOHTWKEpQtm9AR3N5YXms8K/tOA2z5ZHGSMA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=gmpODVY/KE2RuwCXHPW6uPo8YsuGESxvSr8s0t14uYpzg5exgw6XTnHMxznEA8cYZYFsZ1XPJSIXdOr9ya2TmHpMaKyIrFadomb/6dVh1j9bSiT6c7WL9thNrY2nXiUPjgTY7FZ9OdQewkemN+8A0zumSKEciCDpdXsla14fPFo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b=PEpe8Dg6; arc=fail smtp.client-ip=40.107.130.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="PEpe8Dg6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ap5+/sMN/kUP5b08POsqzSiFNXsOIJTxPp6/zxZt1BVEKGjT7IPat5Mh4gTAp8u5GrLEObELTYt4yMX22SfI0OBb4K90HVRyeNWEAkA7AB3uGVFaUGV/3pxWfvd+E/h+0j7PSpDqiGCtdgofeWi7GZPyd6m5oYacDFzaASBAJD6y9OuEAOecPbB9zwYVUed2CO3K/ppbiMsKPvtiBjtva89by2xzbbysLcLM7WMYnkAuNqEXO5kuO56nnHEtsrBI2XiAMOYNvVu2vvNSFsXSPfyZLzOeVCSmyLgJMw7vGeg6rVF8D+qJYVyKv8K6Qh9x3nirxdiG+yUjpbaExEt+Ew== 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=OBkujC1NXZxovgDMvI/zTLqcyC6O12+DyBcBm7tIcZw=; b=E1kJusHrbfn35lqdHWJqFGYD9+0BbyqTzVUJtGLmmodJYDkRbi68IjuDbIJaHdVNMFfNcHZ5Nuq8pkMUrFSE6nznR5/mIOG6MPBW0+CRQMqxGc44jhu2WprDt2gHAh8UJx4CTRI6/8I9E2ylskW+I0wqRU5EQVIHT7xvVgWhOT+N75khr7wpbCOdrhbZHNgvsVl00RO7eDIy1bHQGgGVRoaa0Gx13zn1jkuQmeSkGPLd7+dJ+XsxANxgZCwO78/nzmCoVUOFVrB9nosy/lG8ZSQGLyXPzvuhp73CB8EDkZ+1WnGu781xp9S6A7AayCuZd21jdhLnOS6bcHzTvID+QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OBkujC1NXZxovgDMvI/zTLqcyC6O12+DyBcBm7tIcZw=; b=PEpe8Dg6Lf9NSxN9lM6LxoxZFDj389/xIcvcN1r9DiE0BrvTc9FfKRXkTWdbPMB4mFNLrE4H2sioRmm3ZdplpPhmHtJJvys0BrRIqhqTGhW4QAD+e9eXTajbclefWMGXuiC1RvHzpAY/lsRGhZ0oo4oon5H4HDZL7wdYFweyWeMM+F2jloEB9GmaihrACLHlhSGYWOCDVeBcpANLQZ9gcKrwJgB+UBTrhEeD/1AuXZRYlg5fp+MTWE+QCq+owGpEDROcYwl8XUgILXGcwHn2f7bWv8SLm/SuoujqlGPr5H2HAmMBllgF/zGEAVk1CK3linRKYZvFagVGUPKF2o3Q3Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) by AM8PR04MB7907.eurprd04.prod.outlook.com (2603:10a6:20b:237::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.428.16; Mon, 21 Sep 2026 12:36:54 +0000 Received: from AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9]) by AM8PR04MB7874.eurprd04.prod.outlook.com ([fe80::ac38:1699:6f18:c5d9%6]) with mapi id 15.21.0428.015; Mon, 21 Sep 2026 12:36:54 +0000 From: "Peng Fan (OSS)" To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org, jpb@kernel.org, jgg@ziepe.ca Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, peng.fan@nxp.com Subject: [PATCH RFC v2 4/4] iommu/arm-smmu-v3: Wire up shared-SID STE ordering and feature gating Date: Mon, 21 Sep 2026 20:41:13 +0800 Message-Id: <20260921124113.1664326-1-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> References: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: MA5P287CA0073.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:1b3::6) To AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7874:EE_|AM8PR04MB7907:EE_ X-MS-Office365-Filtering-Correlation-Id: 22419541-643b-42f3-f47f-08df17dd0452 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|23010399003|376014|19092799006|6133799003|10067099003|11063799006|56012099006|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: RR+QwofzL0L81ZxfO0ybUdAeVtzTyr32g8wAv02OGgTuRjXHVLUU/DDPzq46nK2S8n63hUaIgscBGa7FI9UhTbzQd++lRBUBGZ57Z6N+rX7jDnP7t51UCtIBkRSh8ZlBcpnJ+xo1PzfpLVeyH/b1OWkFl33ECIMtE3nMX9UZXxRviR8TIRS1kjhFIj6EdlYSSLvjnUpCKqnpKKfQ4uyteaLmqGXATQYDFgh/ADfIR2YYlEV9X2AwZdctklMNrP3N8wov1NDhOwKZEkSpCf8zBnyYRPFm9KWXYY0uaEgrklrlRq7wSDqI+HCeq/0ggR/fLdVljMlflPIGesfw9Kzke/JBNU5w3qBpRR/oFQjrvG2cN14f8i145TSCDYyXAKdAb8Mz248L+lykViztWyZdi/ZMIcn3CsBAN/ZBgg8AD45xREFXEhjeRULW1ZKquOVgu1KlFhCe2+IobsNkZlEADEguujv9E//iv7JhaEdd2RlvgqKIPzu40YldTYw5eJf5vQ16zltmP1eXhapoMRqjuu31RgwkyCTZWHIPFCm6XGWgpesRJ2jqKnF9515F2P6hjTRsetaC5r2oVvizuQYIwb74SigZHj+0bv3ndQ+3Rj/t57BkDUU9ehY21aRw+oK8rR/8IcGtQt/rxQSS19U40UcoTxB7I/Sezt4CB2/vcPU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7874.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(23010399003)(376014)(19092799006)(6133799003)(10067099003)(11063799006)(56012099006)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?anIG1HqGhBZY/yT5VnE2EnIh7LWZhyoEYqciMtazGt9jDi+MZIuIqJNKDAmp?= =?us-ascii?Q?dW12bZiksVD8Jy8p918ZJF2lANlGLrfnFOJfFLEhuqU09LWzoTjQKSp9kDxM?= =?us-ascii?Q?uiUAsQmQNdm9MCJZNtAk1lA0Hma50ol1N5f4YfOyp7UJj75oz7krUe46cuBv?= =?us-ascii?Q?Ho2bqd/PEURix6NicAo8B+zE8kcNUi7mZDjqbb1sqUCvbIUtWZGp7snStbPs?= =?us-ascii?Q?bd1r4CHmGwPd1TxZgxFwBgT8gYAlmjAsF+pxlsOwZ7uVd4BvFz8mJ6fLW2d7?= =?us-ascii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Hl76hI35hAdZWn+?= =?us-ascii?Q?2n+OnB3I7z2smaVMhboYasbG8Er//bGiaS7JRnQ85HNIeHqSHzF5TkextuoU?= =?us-ascii?Q?bLwm0/Dpe+aTKEnrNdDu1q2YD8PfrQZz+gUKFle89St15wiBY+YyHEP4PVqg?= =?us-ascii?Q?NRuJjW0zauvFeGrhsPt+Yys3X1NcQnkd9hmYxA0/PxlwtMr84LwxcqHzJlbD?= =?us-ascii?Q?s3GCT5x89gzQ9cO+cgq1UoxH/EmQiA9NkcaqJ6/SJ36/NND8dooU6+2K43HN?= =?us-ascii?Q?tkIAXyIRC0n452oUuR4EpBZEQQUsUY2HfN5tukxdacdHvxRZvSZ/nUZ37tLg?= =?us-ascii?Q?J3mjaNi10ukSC+v35e2pF8FUv9afR7AM7/4Tf/RJuWsUOshQI8UscxGq3Fmv?= =?us-ascii?Q?/d8xNs1KFUTIGav/5xhxjsDAuwaBkq97F5A0KQurPkziQ7vmMytHKlgsRjKs?= =?us-ascii?Q?WYZt2QqfGq8h3PWOsk3Z8mkBIOWGYS/rUv2rDoZ8DbVM9db3IuEErB9LO+hA?= =?us-ascii?Q?MjmkQjlX2UQKrsX7Ri4d/M0zkqNhY6onj+KG2xVLoduUWpyRO7XMWIww9yMH?= =?us-ascii?Q?2cUmKlBsR5b3dwnBB2d4X1Bh5uI2E03Xq6vEvhyA7Gk/fAEcRFeS?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22419541-643b-42f3-f47f-08df17dd0452 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7874.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2026 12:36:54.0488 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kMe6bi42weT9wt+X4C9kL1Q6N6sNNuzf0Ep253sdzxUUbcRaGAeByoUYYGkhm+SQVebWuX8Zvq412JLaAKaBoWraEUB8BcFjaQ2wgxNCUan2oeiR4ZVI1t2Sj7LDJCg5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7907 Content-Type: text/plain; charset="utf-8" From: Peng Fan For shared SIDs, only the first master to attach writes the STE (tracked by ste_installed under streams_mutex); subsequent masters skip the write. On teardown, only the last master writes the ABORT STE (ref_count =3D=3D 1). This is handled by arm_smmu_skip_shared_ste(). Fault events on shared SIDs cannot be attributed to a specific master, so arm_smmu_find_master() returns NULL when ref_count > 1. Disable SVA, IOPF/stall, and vSMMU nesting for shared-SID masters since all three require unambiguous SID-to-device mapping. Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Peng Fan --- .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 4 +- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 7 +++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 59 +++++++++++++++++-- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/= iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c index ab1078a97d801..258ca42917f07 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c @@ -308,8 +308,10 @@ static int arm_vsmmu_vdevice_init(struct iommufd_vdevi= ce *vdev) /* * arm_vsmmu_vsid_to_sid() maps a vSID to master->streams[0] alone, so * more streams would leave the rest stale and none reads out of bounds. + * Shared SIDs are also unsupported for vSMMU since the STE is shared + * between multiple masters. */ - if (master->num_streams !=3D 1) + if (master->num_streams !=3D 1 || master->shared_sid) return -EOPNOTSUPP; return 0; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iomm= u/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 0a429c64fbf3e..43f8cc81bfdd1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -271,6 +271,13 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_dom= ain *domain, if (!(master->smmu->features & ARM_SMMU_FEAT_SVA)) return -EOPNOTSUPP; =20 + /* + * SVA requires stall-based fault handling which cannot be supported + * when multiple devices share a SID (fault routing is ambiguous). + */ + if (master->shared_sid) + return -EOPNOTSUPP; + /* Prevent arm_smmu_mm_release from being called while we are attaching */ if (!mmget_not_zero(domain->mm)) return -EINVAL; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index bb3ee25d10d6e..13968191b1452 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2034,6 +2034,13 @@ arm_smmu_find_master(struct arm_smmu_device *smmu, u= 32 sid) stream =3D xa_load(&smmu->streams, sid); if (!stream) return NULL; + /* + * For shared SIDs (ref_count > 1) we cannot determine which master + * triggered the fault, so return NULL to let the caller handle it + * as an unresolvable event. + */ + if (stream->ref_count > 1) + return NULL; return stream->master; } =20 @@ -2944,11 +2951,43 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *s= mmu, u32 sid) } } =20 +/* + * For shared SIDs, check whether this master should skip the STE write. + * + * Setup path: only the first master writes the STE; subsequent masters + * skip because ste_installed is already true. + * + * Teardown path (ABORT): skip while other masters still share the SID + * (ref_count > 1). Only the last remaining master writes the ABORT STE. + * + * Returns true if the STE write should be skipped for this SID. + */ +static bool arm_smmu_skip_shared_ste(struct arm_smmu_device *smmu, + u32 sid, bool is_abort) +{ + struct arm_smmu_stream *stream; + bool skip =3D false; + + mutex_lock(&smmu->streams_mutex); + stream =3D xa_load(&smmu->streams, sid); + if (stream) { + if (is_abort) + skip =3D stream->ref_count > 1; + else if (stream->ste_installed) + skip =3D true; + else + stream->ste_installed =3D true; + } + mutex_unlock(&smmu->streams_mutex); + return skip; +} + void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master, const struct arm_smmu_ste *target) { int i, j; struct arm_smmu_device *smmu =3D master->smmu; + bool is_abort; =20 master->cd_table.in_ste =3D FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) =3D=3D @@ -2957,10 +2996,12 @@ void arm_smmu_install_ste_for_dev(struct arm_smmu_m= aster *master, FIELD_GET(STRTAB_STE_1_EATS, le64_to_cpu(target->data[1])) =3D=3D STRTAB_STE_1_EATS_TRANS; =20 + is_abort =3D (FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target->data[0])) = =3D=3D + STRTAB_STE_0_CFG_ABORT); + for (i =3D 0; i < master->num_streams; ++i) { u32 sid =3D master->streams[i].id; - struct arm_smmu_ste *step =3D - arm_smmu_get_step_for_sid(smmu, sid); + struct arm_smmu_ste *step; =20 /* Bridged PCI devices may end up with duplicated IDs */ for (j =3D 0; j < i; j++) @@ -2969,6 +3010,11 @@ void arm_smmu_install_ste_for_dev(struct arm_smmu_ma= ster *master, if (j < i) continue; =20 + if (master->shared_sid && + arm_smmu_skip_shared_ste(smmu, sid, is_abort)) + continue; + + step =3D arm_smmu_get_step_for_sid(smmu, sid); arm_smmu_write_ste(master, sid, step, target); } } @@ -3116,8 +3162,13 @@ static int arm_smmu_enable_iopf(struct arm_smmu_mast= er *master, if (!master->stall_enabled) return 0; =20 - /* We're not keeping track of SIDs in fault events */ - if (master->num_streams !=3D 1) + /* + * We're not keeping track of SIDs in fault events, and stall/PRI + * cannot be supported when multiple devices share a SID because page + * fault responses are routed by RID/SID and we cannot distinguish + * which device triggered the fault. + */ + if (master->num_streams !=3D 1 || master->shared_sid) return -EOPNOTSUPP; =20 if (master->iopf_refcount) { --=20 2.34.1