From patchwork Thu Sep 9 09:53:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 509115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D9F0C433FE for ; Thu, 9 Sep 2021 09:54:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64815611C2 for ; Thu, 9 Sep 2021 09:54:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233720AbhIIJzM (ORCPT ); Thu, 9 Sep 2021 05:55:12 -0400 Received: from mout.gmx.net ([212.227.17.22]:53389 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233436AbhIIJzI (ORCPT ); Thu, 9 Sep 2021 05:55:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1631181226; bh=iAMRA7J7B75qAx18nV5A5l4I0o/uKALUFm0ZoKS/HHg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=cXAyqhcJyiqOIZsACbKqoinbmnr/7VmWILgGOkAg/JcAMRhT9LrLWIxdVzEDbBi6U pAt/tTzHtbO1tzX/Erk71p15XOaia5BG/eRmhPBvIH/yL+2oicH+d66eHZv1HeBWhW K5+8GlQ+N0af7tVTbrE4A9+rMfx9QOPutBVcIWiU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.119.124]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MVvPJ-1mXrXb1RCP-00RoLG; Thu, 09 Sep 2021 11:53:46 +0200 From: Lino Sanfilippo To: olteanv@gmail.com Cc: p.rosenberger@kunbus.com, woojung.huh@microchip.com, UNGLinuxDriver@microchip.com, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lino Sanfilippo Subject: [PATCH 3/3] net: dsa: microchip: tear down DSA tree at system shutdown Date: Thu, 9 Sep 2021 11:53:24 +0200 Message-Id: <20210909095324.12978-4-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210909095324.12978-1-LinoSanfilippo@gmx.de> References: <20210909095324.12978-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:UbZPGZWtRgdxY+0Xbb+EY2aJRkm0/k/LthL4CtHbi2KZq/rfe0g Fw6SC7V+pEtF72erFJ9lBzjd4I4d6qlrM6r5T7OozRS0MmwIxLBXKd6hLP2ybcG8l/hghZk 9X0KZrHSOTQENyoXrNKalfn10SG+IfAb5tANNhuU/WhkuvZWbtAgwQNFwCZ1Inkx20NmKee ai9frIHEigrqU+9cb3l1w== X-UI-Out-Filterresults: notjunk:1; V03:K0:2B41uqs+kGA=:axrewgqKY8dNNzqw4KXZrU TOfdgrq5sJ5MmsARhKW7OYPoVrF/zBrdqQx3bPrI9/mpr/+uWMxU4Bh151t2Jb+TmkOJd62lu uo3hWF+mhABAVcRhwPtdt1Q/OZ5MgTB3WfcZYtKMxv1rWnpVemVtWREyf7hrjUq9+FRJTkoII Yj8YkRTTGd2NKICe6hBHfhihRB4WES9M01oCHG7UMKhQ0K1XmtLAz8Pmw0fWj3uqXjomVvx11 rtNCQb8AgJ0OtuapliDJh1K8qKTyprQxlZcY94ZLpQUE85gduwZaLmqVOh5Uy7Z/RdSvZ/fbe Vvkf+3MQeYuBpdlqpULtxGuzjKS8UPDHoKMHOciDhyleKur5z+m6ufsMkeQbVg1UV86/nzBbd MeW6PvrM5zlDT/loPyiGSfj2zdDI/zMMHcOCmXOtnooi8saoSQKV9fm9dF+qi6B6tTTuFTmG/ EDUSBfg8Go05YqDh/mJrHSH0LG3s2D7N13cpRZGFxvMp0IqppQiE6VTPGgi431bmeHHmV0DUg K7G5jp/J1Op6Si+c0vpAWzrXZmtadF6pLCu1t2Vdw6y++eDzsj64EaFvW54H4NTg1tmWaB7n9 +J0SRD0l56M0Bhf2t25z6wT2937lB7SVueH2ilQ3j5xMNC41/aWk/2DJFxcNP2Io5CbWkheVe lj2fbwyagb6H5wqRJaiqXT0Ft+6U32aR60+h/A+wYHCsKlJR5LurVzB2+41PaZahaRsfv4BTF w6h7QRv2PJIhEWTtGZt7TRJPGGxYrSki9N7gC6TLKvyat1od24Lj+kkxDhtshGYCGLlDyGG73 p0no8uI5erZk2hRPg6Dxd4fnCKXu5yyd2LqdsTQftr6pZgfo3sYYg8DZxEGlepcu5Fs0EdMvt 6Tu3yGvQkPTOkMJv54EPO2eOkA1K2h7UyFpn7MzrM5vNfz4n3/5qjsHhLh/UdW6r73oxsuKvE bTYTFw+jpAJZinIZ51MyUKHoR9fMDKUy7KyobsAwFD2qNJJVE6NPACk9CeV4s8qoTmv1e1qy8 FRjJtRkMS4pkltM7bzEa+5Wll1MjUx/VgLoeWpMlykxEUqBK1erZXR9dN4mAuAvC6+SpMIDua vE/Vy92+x9fzIY= Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Shutting down the system with registered KSZ9477 slave devices results in a system hang. Additionally the message "unregister_netdevice: waiting for ETH to become free. Usage count = X" is dumped into the kernel log (with ETH being the DSA master device and X the number of registered slave devices). The reason for this issue are pending references to the DSA master device which are still held by the slave devices at the time master device is unregistered. While these references are supposed to be released in ksz_switch_remove() this function never gets the chance to be called due to the earlier system hang at the master device deregistration. Fix this deadlock situation by deregistering the switch (and thus releasing the master device references) in the KSZ9477 shutdown handler. Since this handler is called before the master device deregistration all references to the master device are released at the time of deregistration and thus the deadlock does not occur. Signed-off-by: Lino Sanfilippo --- drivers/net/dsa/microchip/ksz9477.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 854e25f43fa7..5db82898b737 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -229,6 +229,16 @@ static int ksz9477_reset_switch(struct ksz_device *dev) return 0; } +static int ksz9477_shutdown(struct ksz_device *dev) +{ + int ret; + + ret = ksz9477_reset_switch(dev); + ksz_switch_shutdown(dev); + + return ret; +} + static void ksz9477_r_mib_cnt(struct ksz_device *dev, int port, u16 addr, u64 *cnt) { @@ -1601,7 +1611,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .r_mib_pkt = ksz9477_r_mib_pkt, .freeze_mib = ksz9477_freeze_mib, .port_init_cnt = ksz9477_port_init_cnt, - .shutdown = ksz9477_reset_switch, + .shutdown = ksz9477_shutdown, .detect = ksz9477_switch_detect, .init = ksz9477_switch_init, .exit = ksz9477_switch_exit,