From patchwork Tue Oct 1 17:08:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818562 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 68D48CEACEC for ; Tue, 1 Oct 2024 17:09: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=wHQGvqa46IdNb02L4dJCCzIkVnRjOZv9RKBUOY5K18w=; b=e/dSPDaS8f2v0J11ftvnoZZkGV vL3mziJqoPvxTm6P4rL/RottHCbEezIPqdSjqdqX2VCSjz9RLJCFr5TV3PHkNhO6l6yH8BezReohj zSUvPslGg6G8SfzR+vLhE0hht9go+XNI11DQ8/5eCEehSZ3MHStdlogn+UrSk2x46s8wMIHvSDrkg 4SpQUlo92PqkF+RiZdw1vvoO5uSFBNgpu+e4QeSvngXNiy1txqIpod4kHXsWrbinO44tl1KwbAfI9 DcKCqw/wthxYImvQ0xqv6rL4cK4SzV9fCvLSi6mk+nhBFh+NtnZwMS85w7ZnbTQEZgcF3Fl1RKL5U YmwHBcEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svgN4-00000003d8H-0Vyn; Tue, 01 Oct 2024 17:09:10 +0000 Received: from mail-am7eur03on2052.outbound.protection.outlook.com ([40.107.105.52] helo=EUR03-AM7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svgN1-00000003d7R-1FoT for linux-i3c@lists.infradead.org; Tue, 01 Oct 2024 17:09:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iRsOgmo428s8hiWElJ6O+wa2xJ/r4bHfSNt67X/q5gnkwtjeQTaZqyLh15GHeSpivERfHmln1siKn1UNn1YA17RP+ecqp61P1qTGDIplKTmmsRAqXRpxHvySFkedrq1jl2KOtI3jSnqdw75RLUfecupKw0zWtVbD9tEDr6uG135t9O9gqC5DePnqE8zLjomkhK4bPJfsFjhqoiY6XERXLCzhhWaZJPk4NX4+yF56t15yGPj6DtVuSbb4EXdPVqM+Fq2qh1tFJbHrrfAeNRNY9j9YKkxACyRKXSUx1X0iEN9+oRrpxh+kEUBUA09JWwJk3jU0ccEtgxZy5wuu8EJYxg== 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=wq2uhNrumywxyGirPsCsUbtBLGtPk1U0mtxUjUUipPs=; b=XroeNa6uCB0EexIMH3FEzazI4qPxyxcqbJ22UsRaBOLxP8nvgBlT7fYyd1mH4PPTFO6qKdVxqXwvCkgWoaVDqXhQYzRWtL1vfIEUlvbJKwLLaDYudciFIGqjUBwuRPWe9UFKUk4IDEb2hFSzzNwTEqBCFJsbJkg/0jhvIeLxlTOxxpVqz1OK+/A4U10kZzaCqUfsnsPpmipDwZSi75uPqMPF0Ad+2jcxk3gG9O0i6CpjKkBPrCSKPtcq3TNu0pBcx63f2fwFEAWu2UvqB0SklmXkk6STfvQjVGugiq6bRKjIWr0E2qWpIfVs9Bc5YiUP9L1oYahi7q+TM/jl9aCZCA== 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=wq2uhNrumywxyGirPsCsUbtBLGtPk1U0mtxUjUUipPs=; b=b9QXGtMKwcjbzkmdG2m3Imw5Z4J+zvEMToWMkjZeCj9i/+BvEiFyWSBnWU1GGKH/Ym8jVNr1fj5lCcCvlkxhzmQ6DvEJScST6N9899D9bJdcyPtCNRhECMqUJV4+TIg4KnuyaO/he45ran0myVUZ9HoOVUhwvQI0vgtdxzNJUtqAU3FTpjAsEbNJO0wQgSP3Hlyu6oG/z91ZGtNgM47A3jebl4M9ePOh4PVUPS8CGAlUYTiJHKv8gekMeMejpof48B6BxDMWGYdYyhyQj27wX7oNwZU0IyzubYSKNosqpCcOeLqnFQZ4wRxwdaBTpvSt8N2Hzqli4imA42qNWrMi1Q== 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 VI1PR04MB9763.eurprd04.prod.outlook.com (2603:10a6:800:1d3::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Tue, 1 Oct 2024 17:09:00 +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.8005.024; Tue, 1 Oct 2024 17:08:59 +0000 From: Frank Li Date: Tue, 01 Oct 2024 13:08:22 -0400 Subject: [PATCH 3/3] i3c: master: Fix dynamic address leak when 'assigned-address' is present Message-Id: <20241001-i3c_dts_assign-v1-3-6ba83dc15eb8@nxp.com> References: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@nxp.com> In-Reply-To: <20241001-i3c_dts_assign-v1-0-6ba83dc15eb8@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=1727802526; l=3667; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=v9ysb37t9UYUAWV/t/laqr7J4MgebHgEF1/XTNH6RrI=; b=vx3zQzJECmDBokBXBNMawCmKn+M4q5bMYJRFCmxNi00KN6/hUifccsdHdL3tD4+LJYp571BjR j2vJl0n0e9RB21JlPD32VePEcKtWFrwGQdpiYs5T3CvwLYEdo82Du84 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0007.namprd03.prod.outlook.com (2603:10b6:a03:33a::12) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VI1PR04MB9763:EE_ X-MS-Office365-Filtering-Correlation-Id: 64464f56-528c-430b-e134-08dce23bbdf0 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|366016|376014|52116014|7416014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?us2EoMGKSMUiI0aYNBKg/YcFO/utwoi?= =?utf-8?q?LM57388zr3IPWh3otJqEGhqim6ucjPHxIOKRDWSKUKFBVIwEuapzdfrfuo9gjWuu6?= =?utf-8?q?dMJwveatJ+IN3WZ328qWg5n0QsSYuNKs/IBiDC/FX913bl5rfejfcoyybeRtLi0XN?= =?utf-8?q?0deQHuhDrnQRijZEs1fSNNPHULj4KXXTQFfKDVjoWpKlIJ1AuWwixpE89uuq+h1yc?= =?utf-8?q?hPKX7CwHlkodXxu1As7b0dbltfhfRxM7mx5D4ngWqxP3Br0goEvf6ui4nZU2fNTSH?= =?utf-8?q?pwznR4qDSzljWA28l6qvXDEN9BiRUfoQ0/712pO8auRBEmEENvHJ3WhSFwQPaeHU6?= =?utf-8?q?+nbbybyif3MlwXb2wi4vcyQxhVCHoYaO5HPyxzPqP4JEASNlBvd95MHfbu8aMT3cf?= =?utf-8?q?P3dwZEK9vsaey5X5Q0SDZuRAI5nmsUBAfvXMYC+If/y/X27Sdz43rEL6o/kguIrCp?= =?utf-8?q?dD2RGiVP4zhZvO884DL8NpXjlOKXYYB3SicuWFe6j+agFQ+EDoQ+KnYzDTaFftmyB?= =?utf-8?q?EkcqRnYwBK7m1tPQ1kV2ff5cBVdHxenlxi6tqvbYRbo9zCRjIh/MsjT6s4NDlvcTC?= =?utf-8?q?TZIj5oZDIMb/1mwJpyuoOb1YYD1PulcKSCcrFZVeiPtdZcFtkdtefkoA0rLoYlAU8?= =?utf-8?q?W/um/3dSbeDJ6DKx47u/kaw78hW9psrakl6kTROrK3o4qLI+C1DxkUenxjkz4mVrY?= =?utf-8?q?nFqonhEkyal3ow9Gzss+CqY+3Rq3pmNYF9rCOTmG/DZpxYHIQxyqG/+zhehqhvtOk?= =?utf-8?q?fKDAGk0IyXSccpUmOEmy1c5VxL4sN3s5LEXBZwEof7TwdGYBJoX4DGDa2U5x/5Ows?= =?utf-8?q?1ZxNoLvfWXJ8RVnKxN+I+9CAfpX2FxtM6T8YxNDpPm7noQpXu4nG24I0i6eei0Bmn?= =?utf-8?q?0iSk640a3VOFD/YNX11uPccRXjawlXzjG8UcqLJbMRrETdL0hCeEncR2SezkbCIuS?= =?utf-8?q?oFQc9KBXSBm7fcDfKYEqqbVAj3FUlTp2CtWvPS726arbF/PTojFVaLFifus0XIKrL?= =?utf-8?q?mBlobP4903hNnUp79E53ZaTiYgGtVa2Vw5ICoGkQrKR+qiV3nNA1CFBrXeZkGahUo?= =?utf-8?q?+s8hFxt5882ZeTL27vHz6wBUoTkj/iB8UCf30OdRvfN4UmpVhTdcBj+G21YLLEztI?= =?utf-8?q?dbvJHPblcBFjfo4D8XmD0Ze/uM0LWxTe2cl5SBsI+QUWoMtZRhQonCFVnT38qGuIO?= =?utf-8?q?vVqTA9J3NtGTM2PWppDsWhwNqvUgYpgZYQlWyGjkDJ1rR7SER4GqkJWGFb4KTZcDl?= =?utf-8?q?zd/YIYG//kQkSgM0b+APvktWY0yMJidl7A7tkv0iYFxnOIVpZkuCr/FG+Prv/fBmu?= =?utf-8?q?/b2HxtKM0sKkThK/x47pQjiXPieB8MIFDw=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)(366016)(376014)(52116014)(7416014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?PNR6aDbn6ItrhhfVPF2J1+k/9NlT?= =?utf-8?q?Ad/NWiXzTJHhp7AMXX21iRuZC/glt/D8MU3K657M0zSW742DkQPv/dHfOYVx6ud9d?= =?utf-8?q?bZHsIr2EeJyWGVm6v3uumwg2NpRcAHGajUPhbLf+8frsKvCTxUyXD2y2KhbETxkrc?= =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Xy3lzjiUCXsoCEti8y6fE2sN0DtGzIWnFRVSn5T6/OskChWiEZO?= =?utf-8?q?ipCfsQlamzpT18iggNcXl7151qq0GCyHFfse+GMCMFKuqWc883JX1mVyQgCdWSGYL?= =?utf-8?q?UxxaD6HBmMRV4T+7yVqbhBz597Q326C9ZdP/BOmQuNfpodYYzoaJE9mQ8XXKnslex?= =?utf-8?q?NsBNpk45M+5GcLy4reK3Reh1yaK4HJLKZYJAwLiXR2fXgB/LBta6ikPSG/XPkHuzQ?= =?utf-8?q?hqlhkcdgYZEK5SgK8UV8oeJE9B+mAHBkW7IGEfzBBSx5Qgo+XHRRdbhByfKINMs+X?= =?utf-8?q?vRwHVAtPw8u+vLOPQO2XO0KchmCyxOD5R+hb62BBamFHxtli5rJZFkocif1hSjprd?= =?utf-8?q?i1HkbPfl+zN6uk1baxZtF+IYqGjcxfpujd74U0j0BTD7C/CWzs4UBuWe37nzUUE6v?= =?utf-8?q?iZvnW/f1tKPHjSYupWHrqA9Y9VuXatadn+7MUoWDsbfLA1QigHUxkY5O/qeN3/itv?= =?utf-8?q?LxAEopHAwNyi?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64464f56-528c-430b-e134-08dce23bbdf0 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 17:08:59.8290 (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: GysygEz74+9CNS6PQsDB14H7DYIqpJH+dECNFJRHW2woNlDBfd4vWro/VDk2pKNla5rO7AOq8AoCcYkfEVCQwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB9763 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241001_100907_387061_68CEB5D6 X-CRM114-Status: GOOD ( 12.68 ) 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 --- 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 a56cb281e6b6d..eae7449f0dacb 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1556,16 +1556,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); @@ -1968,9 +1961,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_ext(&master->bus, i3cboardinfo->init_dyn_addr, - I3C_ADDR_SLOT_I3C_DEV | I3C_ADDR_SLOT_EXT_INIT); + I3C_ADDR_SLOT_EXT_INIT); /* * Only try to create/attach devices that have a static @@ -2133,7 +2127,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.