Message ID | 20230611104019.33793-1-maxime.chevallier@bootlin.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1969218vqr; Sun, 11 Jun 2023 03:49:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WT3anazxT9eEQxN/8wnQI8l8robBPR13+S5rrRrkrD3RwP+nglwtr2lMk5qTPKfS6+V5o X-Received: by 2002:a05:6402:412:b0:514:9497:1bf6 with SMTP id q18-20020a056402041200b0051494971bf6mr3072015edv.2.1686480587681; Sun, 11 Jun 2023 03:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686480587; cv=none; d=google.com; s=arc-20160816; b=ZQ0LqY3aH/JxFeUZRDGc4L+kBS2fXJLWLI4rmcFAExRLzRU2ysud75NQIkhkHq0m9z sRgVp2mw7oK3MIT2WlIqdSvC1PbsYUnYKL03WhEouiSRo6c/ppISun2DIQiJxVQT5gnx JuTomNU4Mo1kZCaNP5c/DI0dPwkUJ52swcvM/ul3RvDqRfBzk/5aEqWynLAPgwgS45ND dwDkW7XUqIzSVqNThmHUCgZHh3uUgACyz3q0src6t3xDqSxyoDNstbI1BQvVkacL/WBU Xsr/o2pnSsfWiHMSw/90Xzk4XNZ91ey8eTnIZt3b8qYrsgBhwdAjkU+HNlTEkTZBdfbf UmeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=C55nMeIDtiQJBRlRcKRFLbxtCKPrKUT5Uj3r1tMKd3M=; b=jXPRO6SnUpulAVbhjkSkmabNKmfanvvgEGJVZ0aIvE+tBsbSyq9GywsSAxGGUsXjEE 84SRfVWqIRa+/xzcECeJaY/UsLO8t+doexRbsoHBnnxWf8ys80337UEBvqdcArPBuDL2 z1g+jn5HjVJ1trDipMMX0nSrDL87peAuvjB1T0sGk09MDMS9ylTMN7LMt5oMNhBhQ7dH rFQ6GTonp+rwI+0JdNzzKlP5SCnZvlxj+kWKS7qTrtrZudOPPo0fqj6rUswG920SJe+8 5FwxBR8HvH3EBRc/5RRKTjnnQvNW0b4gY+t+sMYIUnhnxl/fC+O7hSNvkGJdXBKV/jPK qDcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=VXXXJ0gr; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a056402038f00b0050bc8f33385si4439182edv.285.2023.06.11.03.49.14; Sun, 11 Jun 2023 03:49:47 -0700 (PDT) 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=@bootlin.com header.s=gm1 header.b=VXXXJ0gr; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232851AbjFKKke (ORCPT <rfc822;liningstudo@gmail.com> + 99 others); Sun, 11 Jun 2023 06:40:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbjFKKkc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 11 Jun 2023 06:40:32 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34FD21B1; Sun, 11 Jun 2023 03:40:30 -0700 (PDT) X-GND-Sasl: maxime.chevallier@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686480028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=C55nMeIDtiQJBRlRcKRFLbxtCKPrKUT5Uj3r1tMKd3M=; b=VXXXJ0grXoG5uje5MHKFDs6efk0qeKbQwieCwCx1NG18jdG2FVSZbbIgIc1EVxgz77GB5B z5CX0xzDjrD4UlwcZBINJG767DR2N66m3UsH/4JfAB4qstQoTJtzDISUYKHyG9NN3FJ2Wm iIQ8G0X3dKsUjZlYSGtWMV9ucCYNP7e3rrdWILpUff+zkvTzi999Iv0YH3mCWVaY3HduBp vXDUy9xkuCN0I7xIP+9m/ePEKU29Z31OleAhZ1t5haUF4Q5c9dkkwqjUVk3TSKGCgfhqkA ePdhX1KFqcgLphRumZGInKA6ixbzzM1Nza+1TeFtA3i15lPAse6bz+FB4g3w2g== X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com X-GND-Sasl: maxime.chevallier@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 8A424FF80A; Sun, 11 Jun 2023 10:40:24 +0000 (UTC) From: Maxime Chevallier <maxime.chevallier@bootlin.com> To: davem@davemloft.net Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn <andrew@lunn.ch>, Jakub Kicinski <kuba@kernel.org>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, Russell King <linux@armlinux.org.uk>, linux-arm-kernel@lists.infradead.org, Simon Horman <simon.horman@corigine.com>, alexis.lothore@bootlin.com Subject: [PATCH net-next] net: altera_tse: fix init sequence to avoid races with register_netdev Date: Sun, 11 Jun 2023 12:40:19 +0200 Message-Id: <20230611104019.33793-1-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768403068393493175?= X-GMAIL-MSGID: =?utf-8?q?1768403068393493175?= |
Series |
[net-next] net: altera_tse: fix init sequence to avoid races with register_netdev
|
|
Commit Message
Maxime Chevallier
June 11, 2023, 10:40 a.m. UTC
As reported here[1], the init sequence in altera_tse can be racy should
any operation on the registered netdev happen after netdev registration
but before phylink initialization.
Fix the registering order to avoid such races by making register_netdev
the last step of the probing sequence.
[1]: https://lore.kernel.org/netdev/ZH9XK5yEGyoDMIs%2F@shell.armlinux.org.uk/
Fixes: fef2998203e1 ("net: altera: tse: convert to phylink")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
This patch targets net-next as it fixes a commit that is in net-next
too.
drivers/net/ethernet/altera/altera_tse_main.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
Comments
On Sun, Jun 11, 2023 at 12:40:19PM +0200, Maxime Chevallier wrote: > As reported here[1], the init sequence in altera_tse can be racy should > any operation on the registered netdev happen after netdev registration > but before phylink initialization. > > Fix the registering order to avoid such races by making register_netdev > the last step of the probing sequence. > > [1]: https://lore.kernel.org/netdev/ZH9XK5yEGyoDMIs%2F@shell.armlinux.org.uk/ > > Fixes: fef2998203e1 ("net: altera: tse: convert to phylink") > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> > --- > This patch targets net-next as it fixes a commit that is in net-next > too. While it fixes the order in which stuff is registered, it introduces a new bug - register_netdev() is what atomically allocated a netdev name, and you use the netdev name when creating the PCS MII bus: snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name); This needs to change, because this will end up being "eth%d-pcs-mii". I am at a loss why you didn't realise this (or in fact recognise that there are other issues) given that I sent you three patches fixing this mess.
Hi, On Sun, 11 Jun 2023 16:42:26 +0100 "Russell King (Oracle)" <linux@armlinux.org.uk> wrote: > On Sun, Jun 11, 2023 at 12:40:19PM +0200, Maxime Chevallier wrote: > > As reported here[1], the init sequence in altera_tse can be racy should > > any operation on the registered netdev happen after netdev registration > > but before phylink initialization. > > > > Fix the registering order to avoid such races by making register_netdev > > the last step of the probing sequence. > > > > [1]: https://lore.kernel.org/netdev/ZH9XK5yEGyoDMIs%2F@shell.armlinux.org.uk/ > > > > Fixes: fef2998203e1 ("net: altera: tse: convert to phylink") > > Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> > > --- > > This patch targets net-next as it fixes a commit that is in net-next > > too. > > While it fixes the order in which stuff is registered, it introduces > a new bug - register_netdev() is what atomically allocated a netdev > name, and you use the netdev name when creating the PCS MII bus: > > snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name); > > This needs to change, because this will end up being "eth%d-pcs-mii". > > I am at a loss why you didn't realise this (or in fact recognise that > there are other issues) given that I sent you three patches fixing > this mess. > Hmpf your patches went un-noticed, sorry... I'll base later work on that. I will also followup with a similar series for dwmac-socfpga Best regards, Maxime
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c index 2e15800e5310..54f1b5ad84ce 100644 --- a/drivers/net/ethernet/altera/altera_tse_main.c +++ b/drivers/net/ethernet/altera/altera_tse_main.c @@ -1395,12 +1395,6 @@ static int altera_tse_probe(struct platform_device *pdev) spin_lock_init(&priv->rxdma_irq_lock); netif_carrier_off(ndev); - ret = register_netdev(ndev); - if (ret) { - dev_err(&pdev->dev, "failed to register TSE net device\n"); - goto err_register_netdev; - } - platform_set_drvdata(pdev, ndev); priv->revision = ioread32(&priv->mac_dev->megacore_revision); @@ -1449,12 +1443,16 @@ static int altera_tse_probe(struct platform_device *pdev) goto err_init_phylink; } + ret = register_netdev(ndev); + if (ret) { + dev_err(&pdev->dev, "failed to register TSE net device\n"); + return ret; + } + return 0; err_init_phylink: lynx_pcs_destroy(priv->pcs); err_init_pcs: - unregister_netdev(ndev); -err_register_netdev: netif_napi_del(&priv->napi); altera_tse_mdio_destroy(ndev); err_free_netdev: