From patchwork Tue Nov 29 14:12:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 27261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp362898wrr; Tue, 29 Nov 2022 06:16:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Uutek1efIdZArvMGvNeOjDw1Y6h52stKgvT811V/qT1euc/xzB+KinbVdMhuiVELcF46a X-Received: by 2002:a17:906:ca2:b0:7b9:eef3:4435 with SMTP id k2-20020a1709060ca200b007b9eef34435mr304068ejh.696.1669731367699; Tue, 29 Nov 2022 06:16:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669731367; cv=pass; d=google.com; s=arc-20160816; b=rCTxfBGtQb1Tonm4sEjQLWlnE/O8NWBiOkx50f0GtHKPigbXN9tsd4SBRoj2kru3yU Ex77JmC+jv1UKW0Eu95TukpkqbPcSEPi0xRHr1gpF0YWDQd5WgvSLO4pp/Nj+KldofUD bfYdLbgBZoCAArS4PEaLRwuXejsDnF0rR/Bk4Kj844nmostPVpDjEFDol0PkwJ6gJJxY pbgMeck7OsUMWQARlXpDjhcNH362lDIA1kP4FuT4GQmKQ0t5Z8B3X6tJktnZ+qS2uUOb gRIZSJbX1g1S3PpBwU5rxZGhm0K0kvYFnYWS2Vr10tcfBL2GuxNyKgEjTWdnnntlLPKP yBFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OL7cN229WgYN1n34DlcBKSHuHNhmJvQ06ZayZTOX02s=; b=iF2H3NwXhcEhnKIlRFuVQbIreelWwqJGNGRhf+vJMAhtUU0Q7MbK4jAiHdyKoUDSlS allyHp3ZME+WMJi4NZUnsWxLXenn+5Xm0y4qbGBRoEdaOGGvUiNjOwhiqtXG9hsGi0ZX QjNsG7RLGfrvlPpnMRzTryYB9/hrN98DD2UMb4iyoQAPeZBlWbrBxYwmo1WW581Z7TuM v2WyVPbU4LvvOkAE5fJqSt/Y2LQ6FXVEAAiOkidheEx76WjLJeC91Ziz+I4x4LTEKghe cp+3DQOEYEItNdTrNCsnmHByVZOPr5s6jK22XtcKBKgS4UqP0Dx/6f/wQaLIyh/EBzAv 8oCg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=qr9n3JUG; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170906974900b0078223ff2756si13234591ejy.244.2022.11.29.06.15.43; Tue, 29 Nov 2022 06:16:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=qr9n3JUG; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235511AbiK2OOR (ORCPT + 99 others); Tue, 29 Nov 2022 09:14:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbiK2ONg (ORCPT ); Tue, 29 Nov 2022 09:13:36 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on060d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1f::60d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 154BF62057; Tue, 29 Nov 2022 06:13:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bDATt6u9kPXerY8IC4eAS6hR+MPICxQY6p3uNaa6XjrmifuMwiYppn0MhWo93MGmaHahNSPuj8ktR/OrvtamDezfnroC4X0wkJut3Jf9kVsY0vLpfJVKNjUlp5xxNv5KSN47NIZeSC1r71WMbOPUwOKLmRGHk4s5hIqdSch+YiVTkx8wmFy6QtN7iNvJqzvILznb6OlAnRZ1RnS12VRYsVNmE304d9gAImi/hqDUBR8FQU9lNVzhjxP5bE0hho4mZDR/5o/D1YgmCfGJ3DzBvfugPQAl+l9MrBSXo2RvSFgCQo5QgtgOVpqlfI1fjcLK2gIkTmu3OprFawvUUm9uWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=OL7cN229WgYN1n34DlcBKSHuHNhmJvQ06ZayZTOX02s=; b=XJrlF98BNq6FBPsXe2Mv9CB5UWAAIU/oS0wFR542pj6H3XhOu0C3OQ7SLtZJRTVl2UvPxmzWb9Ls9WxBbc8dMLKHmbtIfX4vfidGh+7uo9RYpL5mnhgbVsTMI5FlO+34m3Y6RIDMRb0XCpbBeUHsGgRwThBIZYJy9DU9B7s/f9EMJyYOdmWX0XKsSbar+pGA+Bik6WUqoHWlYFIrlxmviNquVxbPHhnv4PR68VY4B0qpObs1O9cMjcqhRr2roNSLQ21ncD0Ntef4vSLV09YeGVh0hYh9Fv9E/a6uLGK04GWZF7/lmcN5Xm4s1aF+iaFEe+WyiKARLPbj/mxHC+t6Aw== 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=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OL7cN229WgYN1n34DlcBKSHuHNhmJvQ06ZayZTOX02s=; b=qr9n3JUGT4vbI1JpF/4ybjkDxFUrrVZZOSMAHxqa9mZ8F/6dar02HEX7cvez/alN6FVE0WzcFJpfb2VzyfiRN4Xf57gEsJFpL1yTI7E56y24sXBzLBnBMGHAtsAPfkqu0lE1rN1/JKqen2HxdMfq3Vapa6L1nNZDA49MkM1wEZg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by AS8PR04MB8724.eurprd04.prod.outlook.com (2603:10a6:20b:42b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5857.19; Tue, 29 Nov 2022 14:12:39 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::9317:77dc:9be2:63b%7]) with mapi id 15.20.5857.023; Tue, 29 Nov 2022 14:12:38 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Ioana Ciornei , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Russell King , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 05/12] net: dpaa2-eth: assign priv->mac after dpaa2_mac_connect() call Date: Tue, 29 Nov 2022 16:12:14 +0200 Message-Id: <20221129141221.872653-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221129141221.872653-1-vladimir.oltean@nxp.com> References: <20221129141221.872653-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR0701CA0029.eurprd07.prod.outlook.com (2603:10a6:800:90::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|AS8PR04MB8724:EE_ X-MS-Office365-Filtering-Correlation-Id: e33fb400-03e8-46ee-f2f8-08dad213c4ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8i9sQ7H3YS7AXnt7D/WVNoZvNh9d00iZ9oLddJ6M34aWv94vyy25FY70nya3MJr4dr63T874VquRdV9Cy+PAmUENd/xur/u8xS2I7hXtciPdlRAjrOO35dVbah4ZOSlETH2r/PhowYHixDq+wWEnRGA0mUqpW2lWqgK0P6TSx6eSisrEx9dhY9dOQiQfV9w7Enz8sTVTZawH0OyVF+mpcPD4CDqQPXS3cstj2n3/YQ8579AflzNrqvsIdB3yBoUxDcQGIS9oEEOwO6T3cKOcSOJKh+NNoYkXGNNXXEWkzydrJ51nDu+AaZTyD2uEAQc9IAQGqZ8LexodRztSovRl7QLB4gQpVrhfDZO3+u6lzixTx8ItYrIhAZiYA850KsIDoQm7e06XSmp1qtj90OMSQKD/5uuWQjjjsVq7zvua1iDS7frY/ogrWJ/MfnrWS18sY1QODwo/8QA2zDqMcDSRiEFmMNvloaRZsn2XHPGb9/6zpkWOAdQU2Ou+Az2sAf25S63bSgtTN8cPfBfTVInE2QfJJr7Mykq/Q59Euc2lEOBGhkICiDDfBvBcyJ/uJGSdM+aghxF/9WccLPwh/t676gQyS6jo7zMoFQ1rCp4Cdroia+0/o9Fjg9aRupk4LNiybW38AODvALNl/9PyXkFDfRoUR5bj2r7VW+kRvYlPts6UXag/IpsTEy4ARxHM+NYNE3LXjzI3gFtObW/AQK0jAg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(39860400002)(396003)(366004)(346002)(451199015)(6666004)(6506007)(6486002)(478600001)(66476007)(1076003)(36756003)(186003)(66556008)(2616005)(66946007)(8676002)(4326008)(6512007)(52116002)(5660300002)(26005)(316002)(54906003)(6916009)(86362001)(2906002)(83380400001)(41300700001)(44832011)(38350700002)(8936002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1gWZjMvs84Wa+j6FRH8T9HdAi16VotA6emdxrf3i9VPeA4eCHhCeQ7TS/m3bretMkzsy9CYvWvwqpeufs+UYkrpOFoaYACb8/HwZea+dngqFYGobupHFZSYkA23yecDDBExpH7PMfb/l0od7R4OaZKPvVNwiyy2IGXNlGgtieRUjL6DkkV/IJukGnW7rUDcuzcIRsu9xXrGFPaplubHCwcW4EZiU2Fjo/I421lC69jRTVseQup9agKL/UsRazN8LshfZJP4Nd1nZ3Jrx+uM9J20UdxhOMvy7GFczyt4KtI4jVy8vNMbSjvARhFSdYzVReES7zXSzCPocvGe5YlAmG8JrgBuD4hryeWgFQzLLz39/XIBYoNpzgoNVJY+SX/1sZzVW6a3mCzvYc/3V4s3UkeKkMbO51haVWnO9SZMCKJdGW6Co7RSmMtdjof3lTkXwHKn001slk7vg0aB4y8xjMfrNw0LmGGPaRtLdSUkQ4KeUJQznnMz2cidakbPemG+QXC8FWCgL7Tx+FCmI+/SHg583L6VnC9J3pBXQQLAJYFtZRxNvHO0tP4tK2/nOrJlQx43TJpQSh0JA7T403i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46ee-f2f8-08dad213c4ab X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Nov 2022 14:12:37.3567 (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: WaId8kosgqSVZsHplNVGHWSAfD2CtN6u5xGuFjjfjLu9S38wlTgxdKbBXC0FDwppIFkYl9S1ItJcKtry1lt51w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8724 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO,SPF_HELO_PASS, T_SPF_PERMERROR autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750840238852494120?= X-GMAIL-MSGID: =?utf-8?q?1750840238852494120?= There are 2 requirements for correct code: - Any time the driver accesses the priv->mac pointer at runtime, it either holds NULL to indicate a DPNI-DPNI connection (or unconnected DPNI), or a struct dpaa2_mac whose phylink instance was fully initialized (created and connected to the PHY). No changes are made to priv->mac while it is being used. Currently, rtnl_lock() watches over the call to dpaa2_eth_connect_mac(), so it serves the purpose of serializing this with all readers of priv->mac. - dpaa2_mac_connect() should run unlocked, because inside it are 2 phylink calls with incompatible locking requirements: phylink_create() requires that the rtnl_mutex isn't held, and phylink_fwnode_phy_connect() requires that the rtnl_mutex is held. The only way to solve those contradictory requirements is to let dpaa2_mac_connect() take rtnl_lock() when it needs to. To solve both requirements, we need to identify the writer side of the priv->mac pointer, which can be wrapped in a mutex private to the driver in a future patch. The dpaa2_mac_connect() cannot be part of the writer side critical section, because of an AB/BA deadlock with rtnl_lock(). So the strategy needs to be that where we prepare the DPMAC by calling dpaa2_mac_connect(), and only make priv->mac point to it once it's fully prepared. This ensures that the writer side critical section has the absolute minimum surface it can. The reverse strategy is adopted in the dpaa2_eth_disconnect_mac() code path. This makes sure that priv->mac is NULL when we start tearing down the DPMAC that we disconnected from, and concurrent code will simply not see it. No locking changes in this patch (concurrent code is still blocked by the rtnl_mutex). Signed-off-by: Vladimir Oltean --- .../net/ethernet/freescale/dpaa2/dpaa2-eth.c | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c index 8896a3198bd2..4dbf8a1651cd 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c @@ -4624,9 +4624,8 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) err = dpaa2_mac_open(mac); if (err) goto err_free_mac; - priv->mac = mac; - if (dpaa2_eth_is_type_phy(priv)) { + if (dpaa2_mac_is_type_phy(mac)) { err = dpaa2_mac_connect(mac); if (err) { if (err == -EPROBE_DEFER) @@ -4640,11 +4639,12 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) } } + priv->mac = mac; + return 0; err_close_mac: dpaa2_mac_close(mac); - priv->mac = NULL; err_free_mac: kfree(mac); return err; @@ -4652,15 +4652,18 @@ static int dpaa2_eth_connect_mac(struct dpaa2_eth_priv *priv) static void dpaa2_eth_disconnect_mac(struct dpaa2_eth_priv *priv) { - if (dpaa2_eth_is_type_phy(priv)) - dpaa2_mac_disconnect(priv->mac); + struct dpaa2_mac *mac = priv->mac; - if (!dpaa2_eth_has_mac(priv)) + priv->mac = NULL; + + if (!mac) return; - dpaa2_mac_close(priv->mac); - kfree(priv->mac); - priv->mac = NULL; + if (dpaa2_mac_is_type_phy(mac)) + dpaa2_mac_disconnect(mac); + + dpaa2_mac_close(mac); + kfree(mac); } static irqreturn_t dpni_irq0_handler_thread(int irq_num, void *arg)