From patchwork Thu Sep 9 09:53:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12482845 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=-7.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MIME_BASE64_TEXT,SPF_HELO_NONE,SPF_PASS,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 1CEF0C433EF for ; Thu, 9 Sep 2021 09:54:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0146B611C2 for ; Thu, 9 Sep 2021 09:54:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233353AbhIIJzJ (ORCPT ); Thu, 9 Sep 2021 05:55:09 -0400 Received: from mout.gmx.net ([212.227.17.21]:59647 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233181AbhIIJzH (ORCPT ); Thu, 9 Sep 2021 05:55:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1631181225; bh=TyajP3TQHWCSO51l7ROYmJ+J3jJ3UVz8VcrVa8pQORg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=MqqPi4cXk5xuygz7OEaR1/HLm5vz0ohwCR/hbiteIwo4vvt9pgmG/YnKPgCbDQQdA KrFmGjRRTD8Y8VE3hjzt3AlG8fBQzkk0SEbXf8Az3wkfbzIJhWXvbg36VPqGjQslko tVvLuKN1+o7nxeEarqoAP0IuVbka/zn7m+SdAvRo= 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 1N79u8-1n0ZaX0DeO-017Uwp; Thu, 09 Sep 2021 11:53:45 +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 0/3] Fix for KSZ DSA switch shutdown Date: Thu, 9 Sep 2021 11:53:21 +0200 Message-Id: <20210909095324.12978-1-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Provags-ID: V03:K1:hEctqTOBs7LoknwP+wrUDjHT7rIXAsnPX8ZNsFHTOJ0x7gOnybW wVjTrlD9IngF3bOVbU4O3ZKCWCG0QELQDfon0O0lBqpSfIHegVhy/Yskt3FTGRsPKaD8Qck Oqwmod6kD/wdM6v+H1SQKuzDu7jkryUV2ByyAXPvJQswDy1TdrtgC5pfPosOhGbLdF45nRT CxEDolLgXLnMhA9IPejMg== X-UI-Out-Filterresults: notjunk:1;V03:K0:bCXA2YNG7G8=:kikj125z90xM7GquRStpKL tBlgYF+Gl7pZDCFNzh+9I80ir6qDR1F6vhDVuwpnvM6URRsBP78bgCVk5S49+jvNvp8h8v7tP zg9kvFyUnGRYTKvDQrdtdUmHG98AfZ4DMI8tAMEJqhAC2NuulrOrbdC9Gs2WP47EDrXnlMAlV gQCaWaYeHYJcUYUi8T9tHZnQFOlptP2LqynvPXY5kdN7QkFXy586cEVxuARimtnFXuVFMWRUw hY5i3vR6WYF3bKN8FdOUWPqpoGT/Rk6tS2x3e8D9NOIn5MueGbujGJcYLTuDH6yxfugneQDOD BwpJ76pxVpmmNBujji9aGy2+LdLjUL9cRoui/NzF2eGJ9AYWrtsyePs0g7WO1N9r7uag7auka Qo0KeTW7tatYXHznnm9lEUWuT9msz5LxIjmPIBNPNGzNDrZD2+p39lpsjLaNx7s+RMAEdwTzG Aw7sGTmR6Q3FvgfFammvNMq1pqI7Njj92C++s0MnOoTi1FIyaaugvdFURFvtYm9g7P5bm8gi9 h924NJINgJHnOzjZStQY19E0y4tvTSEB+PimMFmyEwnb3NJTYePNQlOlB/7BsFIA8lLEfR0Td JCKKXnvSI880JWtUTPeamD2QXFzjX4oy0jYYei3ulchlW54nKWaK1vHpIU9VUjqXXU4/BN3fY beq5lpWex+XImcYvh+13UpCHTUNfTxCyj9lZWMgowsNlrlt1tQyFzYc0VN8nx6gKkbC/uPJOv 2uoDQs9ZEWo6jD9SCdnFEvtlStWk+ky+ZkICZv2M5WdbGaUPMf3z6i1W2nASLKedzUacZjxbz 7BeWPv28WPTOV8CpBR63zI9e7l8a91EnT7NLp+rkCDpeRXs/r2vH2Y6K43RYshFKQN524DpOJ EV9L+kY2IFq1JiIUp8Sx1x693f+/ccLQpzUwWAXV2aKSwo/oSEmTTmSpCPN0WZ1mxZk7JQT5K gpVfSKvlERnevbfFEZC78fesU89Qe35NoNoQHmoEDt4D++S125UA/4j9pvKFdbxJKgFnhF2xZ L1myNGN/492+RH4ZZPpJnv8H74fZoaJSU0URejN+gkJi0dkTgDwGrLkhF+5+uQsZBgHIpRPJX odHftVWAU0QTsc= Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch series fixes a system hang I got each time i tried to shutdown or reboot a system that uses a KSZ9897 as a DSA switch with a broadcom GENET network device as the DSA master device. At the time the system hangs the message "unregister_netdevice: waiting for eth0 to become free. Usage count = 2." is dumped periodically to the console. After some investigation I found the reason to be unreleased references to the master device which are still held by the slave devices at the time the system is shut down (I have two slave devices in use). While these references are supposed to be released in ksz_switch_remove() this function never gets the chance to be called due to the system hang at the master device deregistration which happens before ksz_switch_remove() is called. The fix is to make sure that the master device references are already released when the device is unregistered. For this reason PATCH1 provides a new function dsa_tree_shutdown() that can be called by DSA drivers to untear the DSA switch at shutdown. PATCH2 uses this function in a new helper function for KSZ switches to properly shutdown the KSZ switch. PATCH 3 uses the new helper function in the KSZ9477 shutdown handler. Theses patches have been tested on a Raspberry PI 5.10 kernel with a KSZ9897. The patches have been adjusted to apply against net-next and are compile tested with next-next. Lino Sanfilippo (3): net: dsa: introduce function dsa_tree_shutdown() net: dsa: microchip: provide the function ksz_switch_shutdown() net: dsa: microchip: tear down DSA tree at system shutdown drivers/net/dsa/microchip/ksz9477.c | 12 +++++++++++- drivers/net/dsa/microchip/ksz_common.c | 13 +++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 1 + include/net/dsa.h | 1 + net/dsa/dsa2.c | 8 ++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) base-commit: 626bf91a292e2035af5b9d9cce35c5c138dfe06d