From patchwork Thu Oct 3 20:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13821546 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010052.outbound.protection.outlook.com [52.101.69.52]) (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 8CFDC4C8F for ; Thu, 3 Oct 2024 20:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727986497; cv=fail; b=t4mcI6s8HZ0DOSl9pM9toaIOx+NL2HA9/6MOgXerBwTue8IKHmnpsiOE1F+cf7U4FkZbXq1fGiqme9+cFApMrEh44U6TNFEeQXPb+/CiHUmLhKRkqcJ437gquVJnkKFYMwbPAuMB6f1ZPNCcjk068CXRjtbp1W6xpbx/Ym8xZCI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727986497; c=relaxed/simple; bh=Yb5+glUNRPlFHl6jLjq7YLk0v1GoaUIekn5edA0U3j4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=CVyoHm4FfVShj/swI+BZlo2qz/PCXCUy524GJT0n2wYf93MXkKFpaEfnPWN71c+HJnL9kWobdvWACg0+JHbaCI+pLIMnew3Tl0pVRWK4K0ip8ahKFUL1VsiaWbZBFQtU6uR32/xUA7f/DxUnkuAVZ5Wey63DOW3HRVqs+R0dheI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=ZtBOLyJe; arc=fail smtp.client-ip=52.101.69.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="ZtBOLyJe" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c1c83FSXWtwL3gNL37mEDlLKSfcLcKNEZtJVsbeUp0o+6awlU0HpCQDx1giXiNu5NS9yAKNHtOZqDoGCxB91pyu4Y72eopb9alrniZJxVc0AkRf0L/uC86IJBFJ0tuXVGqOk0TNUbzyS7uOBKt6q4qj6gLEKIJchdbA+RxKZ4HwiS0Vh9IBSCAe6BMDgTObst06BT8L63M7CpNpS364Vr5Zy8Ik8Mv3OWlU+jTM4vS0QdML8UMG33249vbjqDLNWfwKkbmqAhBDz1+VzVx19Ly7B0+zZd+9ZMdvc4qFfEHNdasGjN65GDcsthMpLv0Xq9XTqGF1BPIt/d48z3rSefA== 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=0if/ydm24wIbbYdZueK9zG2st0g0wGo5taHXKt9KGfI=; b=hW9fUyC/r09Mnt6GG2L9Lo467qc/b6H3A5VUnPym5ay01s7qIqiHrWUke5sTogeUays2mMckLnOrev0NSESynlZc5DnAjB1eAYYoR0KMrSREgOCmpp+jk94YQMdwv5MCSZYTnbFwtAGmt1aNsN3SWjVRilACArmh1gDGyyzrB2z9/C8Xzj67zcVjjY9F24AS13Z6oy9V7JLoWUZxe4i5K3N+P6RD2yK8WGUBafvQsdqhvdlpJTQylTsHpACjvyMcP9kRJboU1TPVR5J3DZvgVGznU8SlRqhPMafd2PUYBO3ZgE+S/aHJHtffTQcoSe1OmmcvSdvQdPPl6fzCm48vdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0if/ydm24wIbbYdZueK9zG2st0g0wGo5taHXKt9KGfI=; b=ZtBOLyJecUzODAFwknZE2zr+1ZJPkFt2U1DAuqVrIwi+fX2qdPkTGfTEzVygwaBbL+K5HL7jDCVj5bOzwy1wprqCk3wbnvbA95Ol3/tS/VfMdMngl5bIOzvzs67ZylnDulENJWo9YAMgC5RAOEHyfaYp6mVXNgPamGDzzW2Zpd/hDgtDmIst9E/gsy372fyf9MIrANVpg3rZHhVLsdVRz5OOJ7WjYk70MY7R29RY5TGb5QvdZRubwcnAqJdXo4aAcpIsC2QDmrbqxVvy2vwwrziywxK4ufYN4devC9Pp+dzrm8X+SvYyoQ7L9Wyi/dUgBpr8txJmd6Hq8xmSmUDvFw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PR3PR04MB7481.eurprd04.prod.outlook.com (2603:10a6:102:87::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Thu, 3 Oct 2024 20:14:52 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8026.016; Thu, 3 Oct 2024 20:14:52 +0000 From: Frank Li Date: Thu, 03 Oct 2024 16:14:21 -0400 Subject: [PATCH v6 3/3] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20241003-i3c_dts_assign-v6-3-eae2569c92ca@nxp.com> References: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> In-Reply-To: <20241003-i3c_dts_assign-v6-0-eae2569c92ca@nxp.com> To: Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, bbrezillon@kernel.org, boris.brezillon@collabora.com, conor.culhane@silvaco.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, miquel.raynal@bootlin.com, pthombar@cadence.com, ravindra.yashvant.shinde@nxp.com, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727986479; l=3769; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=Yb5+glUNRPlFHl6jLjq7YLk0v1GoaUIekn5edA0U3j4=; b=EiWoxD2VbobWJQpPxlrQ2U8mFYbrEU/I/ns6W1eQl9ac8bLf/0xgx6EY/pFbtZyPzJ2JDjEZw fWWUSlb+1tUCS60vhhhFSP9mUGdAqXsEKMzZFeiqDgylkopLXu9pjde X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BY1P220CA0008.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:59d::16) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PR3PR04MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b006c73-d064-42c0-cc31-08dce3e80a4f X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?jkuYgvHtZw8xsoA4+4UQWN4b4uyjmyk?= =?utf-8?q?ocHigbZffHGtaJvP/zLBb/lMKCZfiWovXH9omQ3svMokiWf6Itthg2r/tNMWWB+/l?= =?utf-8?q?X10mLcHRst51bymZOvdotahndhV17rWUottldDxdaNzq5hbk8ItQ3oGIG3VFMCyn4?= =?utf-8?q?5J6H/mWG+vFbe/fj/JxT6V0Y0+VOnMafOQVvE69MSx3WQ+cIycMHJt9OdPaNNkpdY?= =?utf-8?q?RVvA0SrW/ujDqNkco3mHvLoSsOpiX6SX26vVncmaDHwH9Msssjqtqg4zyAPGJNikp?= =?utf-8?q?vh3595r4Oo1Si9/aaPQZLd2ywfzWP6gGV9nJ1LRYOozKikv/UEEYayX9+1OjuyKLO?= =?utf-8?q?BG8/EGO350R2svfnjoo1jb5IY6o8HxJ3xdVniL/q6sEwyPy6ZN3J1VyukefKou9jB?= =?utf-8?q?lIhS55vTadjl0D0i0bZGITJiLKrrcSEZ8nMzESP7iIofNDCXuMS+W1Hrf3lKajcc4?= =?utf-8?q?JiN/5/xP7Q5a/q5+2FLnZEJK0eghtsc5gw2IdocClFhXP4NBbFNNgY4B1A/naCD7e?= =?utf-8?q?EPi7l2AOAZrgrDxINu3n6bUd/oL2pfByvo/mCPS2GZJd4x6HPqTEC487SwVfFdLqs?= =?utf-8?q?h1AFoZB9Os0qMzwlxcVcpRnN7vtwIuvyMpsTzXssM3xXABG21tmlxWTkT0Cf6yw51?= =?utf-8?q?Fm+rAvy3r4qMRLNYwr0lQr5zOGl08s7ShMQAc91hVBvrwUv+u0Amnith0d0qO9x4G?= =?utf-8?q?4Hsi4oxQVEGIrSzYpo/WdYsnfaNp3t+kPeL4JRy71pgg7fnoveKNXk2uzl9tmjlNu?= =?utf-8?q?2Onxaq7AL/4WnjAhqm9DUx59u9QfRbrs5Fbd2+4SzVsjR3hkSIKnJw7tN+bHcoxWQ?= =?utf-8?q?W9uzesEsFVpy36jDvynybF/bHzWYaGUFb0BMYruH5F+Ak8xPxEasvRz7yaqc3D7DX?= =?utf-8?q?wZOp3SSbVC3vjHcmA+OvjjAfvgCdxokypBp3VicJd9FImkvx28wRS1XtMqcqRzJ6K?= =?utf-8?q?cidJC8OA7p3GVhUXz+HIJommWDDo5EnCZPCh5fhvW1D1JPex/ja6ZMT3BTGCTIQfg?= =?utf-8?q?WFCQJcHuaN7MtsLDuInKzYfSdM8Nzce/WFoq7X2Cx9riQty3W1W3m60YLNxX9b3sU?= =?utf-8?q?7sGCOoVdrZukW4zgCFzkIT9o9eyHVU5B6fazOrYMVY2joYbeSULM9NcKdUolIleaG?= =?utf-8?q?PKdEKZy7OMQiqtR5YByEr5N3Xs6s6kOT/Lo3QZ3yM4I1LFBlCYwISZJTXWmntToHt?= =?utf-8?q?uNviAjUR1Pzs5q0jVrzH33oYG9v5IHdjebA2yftaVqx/2529tBsJUbPfoTbkaH4Bj?= =?utf-8?q?Txu8ZMEGtwOVetjpU8kk6ksO+/L4TGnUvmg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Y1u1l84OTGxaWyh4RvOPdiqszNEr?= =?utf-8?q?E6kTiPtNYkaPu+KOIMI2zWdwDvh+ekhP2/AbDbD4Yh1XmBaNm66lEwIkugg27rJTv?= =?utf-8?q?bLATHLtIup40w0NCV/RDMqOU2dwLFKbNc1YktgI/Hc/9H7Szv9668EETKOSv8XRVN?= =?utf-8?q?YRV1rd1yjz4LCNV/B/qWmGzx3z4TzKMwZ+Mg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qnSlD/vdj+9ec/N7?= =?utf-8?q?HPKiqd//ezsQ2+JqdnBTbKRSaFC9oCWN6+MMIe/2F3/8i8WuCs5r9z1qwS9/QWdTE?= =?utf-8?q?FWUERi9VcajgtlCLWj45V3SzeNNZ9PKbuyDTBFzzi7AoKhxT7DuDZyrZWRQYwejyu?= =?utf-8?q?tSTuZlB6M+u5x6TOfg3s7GFlKKTJ8vMLKeXYX9n1T5m2xRY8ad5SHqkCnx2047CvR?= =?utf-8?q?vQ91SAIUDqgOEA2aoGyUe7nN7rT6aNmu3dDNbXVPrudH8xUlO6yGlgr3Bu9zpl5vM?= =?utf-8?q?/gumH5fT/LFfvIvkkXUyQpcTvwg2nuqqmKMYMmx4ky+B+PFe1P+qOdbfvb9DZZ9A5?= =?utf-8?q?Hii1VnvntayMXSNXunGTYvUFP8WYvVo/cVUCaRkIFH2jkJLO/2/QcQSl+o+EdGfzJ?= =?utf-8?q?TD+s9RJUezA6XV8OWaQZhzOiJbIcMhnuO4P5lhNfXl8AC0hPrg7RnI5o=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b006c73-d064-42c0-cc31-08dce3e80a4f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2024 20:14:52.5704 (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: xdFY5mw48Em1/shn/mHPwrLpXSHPvbGPtKKWdsePYy9CpS/RazgKtTXu30g+KDbGZv0J1xHsh8A1pqBBJwhCIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7481 If the DTS contains 'assigned-address', a dynamic address leak occurs during hotjoin events. Assume a device have assigned-address 0xb. - Device issue Hotjoin - Call i3c_master_do_daa() - Call driver xxx_do_daa() - Call i3c_master_get_free_addr() to get dynamic address 0x9 - i3c_master_add_i3c_dev_locked(0x9) - expected_dyn_addr = newdev->boardinfo->init_dyn_addr (0xb); - i3c_master_reattach_i3c_dev(newdev(0xb), old_dyn_addr(0x9)); - if (dev->info.dyn_addr != old_dyn_addr && ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0x9 -> TRUE (!dev->boardinfo || ^^^^^^^^^^^^^^^ -> FALSE dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 0xb != 0xb -> FALSE ... i3c_bus_set_addr_slot_status(&master->bus, old_dyn_addr, I3C_ADDR_SLOT_FREE); ^^^ This will be skipped. So old_dyn_addr never free } - i3c_master_get_free_addr() will return increased sequence number. Remove dev->info.dyn_addr != dev->boardinfo->init_dyn_addr condition check. dev->info.dyn_addr should be checked before calling this function because i3c_master_setnewda_locked() has already been called and the target device has already accepted dyn_addr. It is too late to check if dyn_addr is free in i3c_master_reattach_i3c_dev(). Add check to ensure expected_dyn_addr is free before i3c_master_setnewda_locked(). Fixes: cc3a392d69b6 ("i3c: master: fix for SETDASA and DAA process") Cc: stable@kernel.org Signed-off-by: Frank Li --- Chagne v5 to v6 - fixed version number to v5 - fix merge conflict because change function name and macro name. Change v3 to v4 - none --- drivers/i3c/master.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 68411f1cf80d6..42f610636fb7c 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1547,16 +1547,9 @@ static int i3c_master_reattach_i3c_dev(struct i3c_dev_desc *dev, u8 old_dyn_addr) { struct i3c_master_controller *master = i3c_dev_get_master(dev); - enum i3c_addr_slot_status status; int ret; - if (dev->info.dyn_addr != old_dyn_addr && - (!dev->boardinfo || - dev->info.dyn_addr != dev->boardinfo->init_dyn_addr)) { - status = i3c_bus_get_addr_slot_status(&master->bus, - dev->info.dyn_addr); - if (status != I3C_ADDR_SLOT_FREE) - return -EBUSY; + if (dev->info.dyn_addr != old_dyn_addr) { i3c_bus_set_addr_slot_status(&master->bus, dev->info.dyn_addr, I3C_ADDR_SLOT_I3C_DEV); @@ -1959,9 +1952,10 @@ static int i3c_master_bus_init(struct i3c_master_controller *master) goto err_rstdaa; } + /* Not mark as occupied until real device exist in bus */ i3c_bus_set_addr_slot_status_mask(&master->bus, i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_DESIRED, + I3C_ADDR_SLOT_EXT_DESIRED, I3C_ADDR_SLOT_EXT_STATUS_MASK); /* @@ -2125,7 +2119,8 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, else expected_dyn_addr = newdev->info.dyn_addr; - if (newdev->info.dyn_addr != expected_dyn_addr) { + if (newdev->info.dyn_addr != expected_dyn_addr && + i3c_bus_get_addr_slot_status(&master->bus, expected_dyn_addr) == I3C_ADDR_SLOT_FREE) { /* * Try to apply the expected dynamic address. If it fails, keep * the address assigned by the master.