From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D769C98302 for ; Tue, 22 Sep 2026 14:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To: Content-Type:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qwNAof3a5RtKqZApzhvqoO+or4coDp6jtiej3iFk3iQ=; b=biAv17kO1CY/IdzC6kjCspP1o+ Bb2Qwe3H7A1RSIWI5Ca9Q+JyAXHW2dcIhJqyMb0P1wMTZhM6BgWeXHtxfGeD3/QIjn6e5kq/Cn5SH YrfOFu5txIPKzMjQsZTsZVoOvaKGUeroAFN7I6gBE4adCaot4HVS3+zHCaIkcx97sysEdRpmWzdJd exZgRKXV1sxmS6+5rVNLOUyRP7xYmUrV/0F5te75kPZTpd389wR4aQXoZqj7w4ORaODDOJr6evgK/ QZ72f6LHsDm/r2//eiBMK+AFwHgbzbRFzxdtk7JSmXLVydQRlRaia29h06+bzkd0oM1cGggz9T33Y gqvxZ4RA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x912t-00000005cTY-0GpK; Tue, 22 Sep 2026 14:00:31 +0000 Received: from mail-francecentralazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c20a::7] helo=PA4PR04CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x912p-00000005cSV-0iTC for linux-arm-kernel@lists.infradead.org; Tue, 22 Sep 2026 14:00:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Oy1upvUNouFx/CICNWQ4GAgYO2FDtiDXVHBv8tpIDxcm9bC7BoXA1+50C9bA94FCb9DHAbL5+YHdyBrtBa7cOGSHusZOhfBVWqD3dMTzqYYtugLBEH1GnD4dgWDL5ezNyX5nclErALv92AmpdYhnH0tGD/34HgbRbhgQYye3GpPOSIWaLgAxe3O75bpjcBY/wHcM53Zzo5EAxyW08IU/+bZmCUWrSC4n7mSi3e04w5C3uOWTPNefQsrdx6AN/xSXRQs6o+nUsLavsSobhUbX9X0ECbXrxH2d2aACTraI57+xH0OUFWcRWfs368iLOVhAuxFUdxzsjSeJYolfJMzCHQ== 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=qwNAof3a5RtKqZApzhvqoO+or4coDp6jtiej3iFk3iQ=; b=CiDVBIuIzaUm3Uv1HlMZNbSRK7RNGs/tp/t3Gc2b52W9ui1iW4ve2mcWVtMhkLyaajxhLEgPs9UfNgmtYPUEOx4kZMKOaw95xrtZHA3/0KkCyaTbLajwlaxq05rX7WQhriXJgluYezpDgN79a3vIKvXXWSL3A2Ti8F9bXK2c3CguC9Gm0doLIw3OEEjNtI4CMUygWoxCxyEMs1PhmExHvMgcCfcEr2z9r6bHCL82o4hwqmqDFOnQrGz3ae+++VRNtiaanulZd4qxE1/ACYSVkB+F8BbBum4CKR7gn5TQnGVI5yK3RqltZNFHYZ+0LddunSepqzMQ420lBteQKiAE2Q== 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=qwNAof3a5RtKqZApzhvqoO+or4coDp6jtiej3iFk3iQ=; b=On9jUdmZiX7FdY8+yF3LJ/vAnDcVNcxUf2KY9hPYSfiJkluCeLasxv4GybXOiGsUb+tkFa567jqo8gi9K8TH+A8Gpe5gzRAPAgoGDyK3HEAVEvxuwQoTKfhZfmxYq40yuZsMUt76Rt4zPq8pEcMFZPZhnAX54xRDTgvy/Qly9egr/9JNgfBeykxNELRZ364I7ADKY4SCesOIIVJ9wbjwLGZnkfRQHKLDr3NGiDAFyUAUjjG71JGHbHy2oYnXH/ppSZPmeg8To1YPIKDZmMxJugHCVNetiQsGZtHINVmO3aBorn/j7PGvSKu3lQHlKkLscEqql+HB7ONOSOWRZxgUDQ== 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 VI1PR04MB7104.eurprd04.prod.outlook.com (2603:10a6:800:126::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.451.13; Tue, 22 Sep 2026 14:00:18 +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; Tue, 22 Sep 2026 14:00:18 +0000 Date: Tue, 22 Sep 2026 22:04:39 +0800 From: Peng Fan To: Nicolin Chen Cc: Will Deacon , Robin Murphy , "Joerg Roedel (AMD)" , Jean-Philippe Brucker , Jason Gunthorpe , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Peng Fan Subject: Re: [PATCH RFC v2 1/4] iommu/arm-smmu-v3: Convert streams from RB tree to XArray Message-ID: References: <20260921-smmu-shared-sid-v2-0-4b656ce68178@nxp.com> <20260921-smmu-shared-sid-v2-1-4b656ce68178@nxp.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: SI3PR02CA0008.apcprd02.prod.outlook.com (2603:1096:4:295::16) To AM8PR04MB7874.eurprd04.prod.outlook.com (2603:10a6:20b:24d::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM8PR04MB7874:EE_|VI1PR04MB7104:EE_ X-MS-Office365-Filtering-Correlation-Id: dadc246e-e27a-4f9d-15ae-08df18b1d558 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|19092799006|366016|23010399003|6133799003|18002099003|22082099003|11063799006|10067099003|4143699003|56012099006; X-Microsoft-Antispam-Message-Info: nrG3hoG+avmxud02RZAhK1CQ0WjziXD83jBbYZ6RXdOCtRZ/LB31ox3s6idcaN8ao34iffqLIT58KLN00ooz3fd0RgspWucGE+QSML/TVTQEJBdFCzNqvpKOCdCybJ6Vp/n+fP143FdiEpYxleTcvIYHcDgMOr7PChGi2eEtRp27v46rQt+lJRIQmpKmVRC5MWNGGSQj8UjkIeVgk0TlhMLWtDOndRd/C+XSQEgK3Fa247wKKIqYMeQY9bPUMMgMJcZKOMplO0PT/UOFgJyJ4qzMx8DvLOvL1bNMWboZWo/wcsz3yY5V3Hj05mhSeNoEh7uZqen1T8Gl24zzZb4ZUgWtypPEcUiLUXzjWYij5tnCMryWSSLDi9pb8crQrkJ+hZ/+bToT49Qc6LhTDUeC1cMeb9rjU1gncwcFa7/y4AAWSCFz1SceT9DlJYwP2mOTePcs2eywqBCTGZerMrgdpF7fKF3IdCb/JT6hCkOyGm6VwlY4l7k6LOWQ+6Qlm4TijOOG6FhW8Kin0FTM+ZWI1DrXYC5iJZvo1s0FMPvWP1J1th/Pdj7WL27q3sBstJk54a3QtBMjzgoR5jNLRY0SaU6Jdl8xh/qc4Z1RhDzRZ5CvQXtlg14zqhWZpMNN1raS 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)(376014)(19092799006)(366016)(23010399003)(6133799003)(18002099003)(22082099003)(11063799006)(10067099003)(4143699003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zA84f1UmI+sH16jOKAxILpDkeM+dfPnrnzt4iF8ZyaOR1hvkxC9zyOim6wlG?= =?us-ascii?Q?qxLjPzrBj6fdY6Xw3L78skkk5RNuMbIQ2VcPauClBSNn6Xz5frCyQqM3nAWG?= =?us-ascii?Q?Zef4pSXAdMHBgPQ/xTbsEpXC0HiTh2gftsVExfwQHn2cgdJvjtc1fSBHl25u?= =?us-ascii?Q?cfagAotmv2XVVcssxmXbWFggQbYgMI6/dTqPlGUIPdUXwFauprnZUC3L7e+w?= =?us-ascii?Q?jcQk/+NS7Xd0mcc8eaOqv07q0AvJk+m86vXXMsgLOX0Ll8eZq2F1Zs4dDSuu?= =?us-ascii?Q?972648NduDdpGpU7jtKBCLhHWJR1+NzKbMw3DuVGmuTnp730QfW6iXdk6fPR?= =?us-ascii?Q?qB/pBQs+gsT4Z+aou1642sHVVdZOu4gWTktstybYEM83tCEj+iEpCcmODPBo?= =?us-ascii?Q?SCH0lMxDVWyC4OWAQv/eWbphnEuilM58XG1WECwhY4wc6Jv3T7FmtyfqwnAB?= =?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6iJ80+aytBfanCKLHqYUu?= =?us-ascii?Q?k69CGWhjql9k4vysXRMMHoWN10LUz71ZSdr8rhTINn3DMMr7/dRRwV7u0oGP?= =?us-ascii?Q?FdCd8NVetU/urYJxkzytLlHWGXf6BqbzH8YE5+/Ch4X1pIE76z4VktplUGRB?= =?us-ascii?Q?tDM4qpK7w4UH+i8iXwb7o196bqguNTU9klgynaNHOaywoI8a6Ty2MM+GPdwX?= =?us-ascii?Q?IveilYEHEtODgLGX+K/0ndPwAnjBoJ1hOzp7wc8P94gUtKGz+FyjXg4uOSJq?= =?us-ascii?Q?ljlxI4pJPpei/C0GEv203hjDQaPE32/oHdh3yEBsWrhFqjD+oDhtUHYx7w9z?= =?us-ascii?Q?spoKkqLwp/J0ejeNRFeBd85N4kMMVrvvZaCuh9+6OPOy5j9YxYqOp4LqWC9I?= =?us-ascii?Q?69EixSNc+lvTfku/tA5ygC/25UUbFJmWaF6gm/7arc6iRhHlS2x3?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dadc246e-e27a-4f9d-15ae-08df18b1d558 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7874.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2026 14:00:17.8991 (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: +NNVHs/sQBOdVDsHB0qK46HRXoPLOSczkoefUznyPNlTQG3oGy9HgMOHWN5OihnOQpcf8vLPzisk9/e/NXjJ2EEP+WT/N/IJy+ykLEFs+5HzhJ4ofV1rJbBystwgHCww X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7104 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260922_070027_216893_1C3BB990 X-CRM114-Status: GOOD ( 14.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Nicolin, Thanks for reviewing. On Mon, Sep 21, 2026 at 12:24:13PM -0700, Nicolin Chen wrote: >On Mon, Sep 21, 2026 at 07:35:00PM +0800, Peng Fan (OSS) wrote: >> 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(). > >The commit message reads very unconvincing. > >The first paragraph starts with an action "replace" without giving >a clear reason for the action. > >> This removes the RB tree comparators, the rb_node from > >Then the second paragraph repeats the action... > >> arm_smmu_stream, and simplifies duplicate-SID handling for bridged PCI >> devices. > >... and slightly mentions "simplifies". Maybe it should write about >why this is necessary and how xarray would simplify vs RB tree? Jean had a comment that "maybe simplify the driver first by moving to a xarray", see [1] [2]. [1] https://lore.kernel.org/linux-iommu/20230518130459.GA2587493@myrica/ [2] https://lore.kernel.org/linux-iommu/ecb3725c-27c4-944b-b42c-f4e293521f94@arm.com/#t Does below commit message looks good to you? iommu/arm-smmu-v3: Convert streams from RB tree to XArray As suggested by Jean-Philippe Brucker [1], convert the smmu->streams RB tree to an XArray as a preparatory simplification for shared-SID support. A subsequent patch needs to look up an existing stream by SID and then decide to share it rather than reject it - two separate operations. The RB tree's rb_find_add() fuses lookup and insertion atomically: it either inserts or returns the collision, making "find, then conditionally share" impossible without restructuring. XArray's xa_load() and xa_store() are independent operations that naturally support this pattern. Eliminates the two comparator functions (arm_smmu_streams_cmp_key/node), the per-stream rb_node field. The existing streams_mutex continues to serialise all accesses. 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(). No behavioural change. [1] https://lore.kernel.org/linux-iommu/20230518130459.GA2587493@myrica/#t Thanks, Peng > >Nicolin >