From patchwork Tue Oct 8 15:18:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13826630 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 760D3CEFC21 for ; Tue, 8 Oct 2024 15:21:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Gt0h43Ami16S9HFQC1qfmI6Yb1Zj9E6y+zTm3TcdMkI=; b=RCx844HvCTXWlD1QotZiQDYtiF vrefqy4U/XAiUujbuYhpDO1zZ3Z+YxQO+mg+Coy5qKEDnu6RUZWHUcxDOhYxQl4E5TSce6jzJfewf I8n6zZTh0FycAAbRALVQu/wnG0m18n72hrNh2JfGzMKPUjkklPhBQajUU862N54zZeWpUJ8WPQBgz rUZL9rS57iiXJxDOPYbMC5FmBM0tsAyVlyyIb3BISiksiLyrWVdqjAE5qa5NXz8H7CKrTcDsFyXNn qFbBFuaH6+px3QwxnusvMDizNmmS/6Qj40Yztp9q2PYEwuOBv2xxw+xxk7DgFOdGRyBHvOGObHLrA ZGYzN9WQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syC1O-00000006Ll2-0p1I; Tue, 08 Oct 2024 15:21:10 +0000 Received: from mail-northeuropeazlp170130004.outbound.protection.outlook.com ([2a01:111:f403:c200::4] helo=DUZPR83CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syBzs-00000006LNl-1VWt for linux-i3c@lists.infradead.org; Tue, 08 Oct 2024 15:19:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TqwLvup6EdrLHRJ414dPRWhGjnhrA1AkGTRUGFkWl7aKQrql83+lbSVEKcZCRibe3ML4hq4RnMphLG7e3RvLXEOC7hMjFV0i3zlJDSzeEYy1ONXBpntMoVcHpPxCKhBRSDyGIrhLGoqnx35jEwJKYL+ymH8pE4kav9tjaXlLVtg0Tqgjg9BCiR6JYZxM9LetYUuMOp8RUNONtEg5hs23/0rtsTaWntAthsL5RCrp6n28ilk595JvbO8F+njMfEO/Pn1A6H0LL6RDu9VpFOjHqu5k5g1lcF+Pskdr3TEqrjryiZfTkP8lBd7RFzKlcUlUE8CIVBPeli4oSyxDZLM6+Q== 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=seUGrhq7525Aji8QqixFCyRDtakFX5/Xp2TzxWHsoBo=; b=ZspkfjTWVEsxMGBpUOgZkJv/KhTx8NswpCAUSXPGyWKOhT5KzBE113DOwW/wDuoAXEXKJsdGMQICODBf1xWpSzSkOknB5+6uriAf6nowi8v+hwXaeJLppXcpgoMsQaTFxivUsEbK8pZf24IQG3c7KfJD83r2OfvdqYEtEwSOPZSIgdKs+50J2CTc6wAMMgvxYyDeH5AOL2T+HDq4mnMLxgGQKkD0AIBmL4w2+b8BSVT/NiaLmOiMo/8KXxmEwRiajNZA9E1j4jVa1kAxLOB6SfxYkLYgJxrzxG2t2BScRXFQApuT2pTnWvjk8hYJFlNCkzIPx24P4Vf7q/AdqPmj9Q== 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=seUGrhq7525Aji8QqixFCyRDtakFX5/Xp2TzxWHsoBo=; b=cPuEWmBSz2OzFXF2vGAicNujW/AoF467Zg4+4IAYduv6Sx6SZ9/f0MJuyf5Bk5B+TaaOtBFSdso4l2RC9K2yeKFHaJRoCqrM10dtCllgMJTolvMyZ4v1N+k2h+YvwsPveFqE+IBfvMXgdlhRL8CktbrPYhmUQaHThB7SC9m+XR522sDLa5yverifAJ4Bz60KZTRobTh7JfXXj/WO1qmEg6qHtmF5NGXqjkgzV4C2HtN8Q7TeNmmLHT5uoHxOmsZzVf3BMjtKL8WWigK52oeULGzjZFWZwfON5NCqWzIYuy+ACIhoKCHwQqLlcTtMhDB0a5QcVBF4Ojl+smj66qkiiQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB9PR04MB9626.eurprd04.prod.outlook.com (2603:10a6:10:309::18) by GV1PR04MB9151.eurprd04.prod.outlook.com (2603:10a6:150:26::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.16; Tue, 8 Oct 2024 15:18:54 +0000 Received: from DB9PR04MB9626.eurprd04.prod.outlook.com ([fe80::e81:b393:ebc5:bc3d]) by DB9PR04MB9626.eurprd04.prod.outlook.com ([fe80::e81:b393:ebc5:bc3d%3]) with mapi id 15.20.8026.019; Tue, 8 Oct 2024 15:18:53 +0000 From: Frank Li Date: Tue, 08 Oct 2024 11:18:26 -0400 Subject: [PATCH v7 3/3] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20241008-i3c_dts_assign-v7-3-96ec93d1f34c@nxp.com> References: <20241008-i3c_dts_assign-v7-0-96ec93d1f34c@nxp.com> In-Reply-To: <20241008-i3c_dts_assign-v7-0-96ec93d1f34c@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=1728400720; l=3796; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=fYQXCdK74snyRv7MsUE/w/+rHiPoijiH/nm36eU6gIs=; b=fWsH4+cyiVF/9mzhKugs22BvUe9clSOdxCT1bXI5Bgz4y689aIN7eUb0FtFKIHI6be7lQrHO3 nuPZK+209xKCOPxfesfwwoMuXAU5Gr56ar5Dv4NqrtXME+t41GT0Rmr X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR11CA0101.namprd11.prod.outlook.com (2603:10b6:a03:f4::42) To DB9PR04MB9626.eurprd04.prod.outlook.com (2603:10a6:10:309::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR04MB9626:EE_|GV1PR04MB9151:EE_ X-MS-Office365-Filtering-Correlation-Id: 8985153a-0e14-4ddf-f2b1-08dce7ac8561 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|52116014|7416014|366016|376014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?HfnjiFm6iMjuddy3HjvnqFPZVTYTHfl?= =?utf-8?q?8Ypv0hH11GnMscrSdoTZZNobSvmiJKey7zs15jGfecou79CFQ7ZZQ/8DirFDOPtzf?= =?utf-8?q?7LeIOM+EKQAZcl8m2ZXRVXkjBOQ4i5gODDgR+HO7OrQioTFClOaKwNEd77pAGXnGz?= =?utf-8?q?LUoexc8p5/xL1xIHNz5itUCVU4fvyOWXFX3hU/lAtOIJbtJos50piwczkOJMTO2+n?= =?utf-8?q?MEnypY1fhRB8vGKO4czk8HcQGNr4/xd1OdBrQj755C87IQZYZslrezc7+17caTAgU?= =?utf-8?q?UkDAPqh3I6TGY6l0R6I+ssw+h3KHQW9GEpXy13U7gQnJL0j+uYw/NZc+FwcPRvang?= =?utf-8?q?3pfJW8J5l4JKzlpFKzJo9wDrUnARpNfmmGB/7DNSv4lqJovEPjXY7Q+SKLDUe1fkC?= =?utf-8?q?Xm3OA5/1u9bY8t9ik5d2mFLAQun31d8W/nA7Lpfic1L70VBwrCHW0SFNAKWwYByND?= =?utf-8?q?r4jbXK75ZWCDTCn4Rcwcdox2KB+CXUP2h4jy4oj6kNcQH34Brd8y2FHb7gJ+qzUPn?= =?utf-8?q?GXaMk26AaIMzXH056xiWogHpEV9Oqkpni/a/luugiM8cTXhw4+IO002VaSnsslW6y?= =?utf-8?q?uIitRLL2YXqfJkWavZTfwthyRUGKPOO+GcQUflP65jBEvevXL7V8ImQ5Wy3tSJqDc?= =?utf-8?q?Uhcdy+k3VLKbUsHS5S/BKUdl/IdMMfaABrsjLgo1dsyK9Vsk8hW+AsP7N6twWuxp7?= =?utf-8?q?t9Tvzv5L+hoJQHnMH3+ACo1kgzXZrig9H0/95WujZQj2kutDfHwwFlHzhFfdWmOXD?= =?utf-8?q?Lm0RUlpxqa3DTDzj6/pFCJ8Nnqj3hNVHwETrYekr+75Zldn4MZ+LwwwbqeH0TcVXi?= =?utf-8?q?MtcnG43R/Q8rZxL37Nw2Hz/KKvPHGoew1+KIcVmYr1dYtyFUpIQE5CpQT0MI08LTg?= =?utf-8?q?vE1qMwHGqChK5dW8T4NfKYF8YReAT27BbWFoPH266yYXycr1RabEG7ZDctoiZkBqP?= =?utf-8?q?wfTwWWfPt+t1UJtI8fRqMeCXGz1qOeCoyfWWaabqcjWwwO4K8IICdVvLqb/b8yuDK?= =?utf-8?q?BQqWgYyuRd80kO1ogfSqhb40/cQCXol0w3q45RGRYnGHlEv+h8tjhEjSFtfdhoiyb?= =?utf-8?q?VfhihV1bOYv5wmMtO3uotAGjHomBK3p98lBztO+Y8pUKmIulnEP+7ZIojrISLfRS1?= =?utf-8?q?n+xVBPwDdoV4dKJK5yjsfGXxgOSpAcR0wUluBCSnB3lxaItcU7MBZICfw1BQtn4nK?= =?utf-8?q?gDUBck4BRetbO+l13A2+XBQZRNdAuPcd2w7ZG2EC9m5sjTa0mjhS1hCWWYCxSkM5i?= =?utf-8?q?4vsi6AKQxvBloV8ioKt4L5333GcCisHKuEg=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR04MB9626.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(7416014)(366016)(376014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?k1Gg/FCDF9rgbz3XDzQCSSD6JjRx?= =?utf-8?q?n4l5ewNQ60yqrGfNGeBKO9o3wDE2H+kfAX1p4oOzlSELjQrtQC0gRiuXSBRfcdDVi?= =?utf-8?q?4tBjOCiBcWUZSy7K19TlQt4Ywp9LvksPcro+kjgYMsMoL+haS5mtim6b7RrTJFwBM?= =?utf-8?q?500kbOm3LcgL/Vxr10p4NfLqpwogWnqM4Hnjo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TmlyReHK6O2tCyxK?= =?utf-8?q?eZ6lAvMvxpx/RBUH8e0L30Oa5K+wpBNsD0CIZkI9x8rshbtnHz+aqrgoj2wdHGB/Z?= =?utf-8?q?wEK/GC69D2vuDbfdE820/V8xn2WzcrLjaBwstZ/2zxD++8b5KZIoeXqtKEs9NB4Ft?= =?utf-8?q?/j5GOHwJdRLCm+gnbBxsbkdKGHOFctApCIa6T8OrrgSWKv9AcDKLgUWNo3c8ii+aL?= =?utf-8?q?nGiyUB8RD4UXioIgDmH+Li4T+ONt9LjzjNj+S8q0qPE1r6QVntKh19yz3TcPUDQWx?= =?utf-8?q?N6IPw3OPyqkC6DalrnrGX+l0/qjGtfUzm6oJP5hF9pAmZDDpyjnMJ8Oo5EGkFzJL3?= =?utf-8?q?vCc/MkP/jM/ocMaWv5ZW3yEliDu8P52YezV2pj40BjAXRm77TzQKRcW6MuLHOC2vz?= =?utf-8?q?O672v8ekqOPTMl1P/IpiktU10m/ZZ5l/07GrRBOUmNPsuADGKxiKdOig=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8985153a-0e14-4ddf-f2b1-08dce7ac8561 X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB9626.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2024 15:18:53.9025 (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: 2373gy8CNq5op3mKurhu64q+HZIqSF9+0gg/9Kjlit+VnXWEvhSbzjWCw4tLQxl9DhytBQXWc7dikFF8SaBxUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9151 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241008_081936_443194_B46FEC3E X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-i3c@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-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Miquel Raynal --- Chagne v6 to v7 - none 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 e0962a17de7f0..9ccfabf849c42 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1548,16 +1548,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); @@ -1960,9 +1953,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); /* @@ -2126,7 +2120,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.