Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2183959pxb; Mon, 18 Jan 2021 10:22:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAG1vSEGxMUt8iGaq+OWF6hOog+/+F5nDM/lChMgHFK4h7MBmULkNQ4S9XnowuEemLQiT+ X-Received: by 2002:a05:6402:3116:: with SMTP id dc22mr534053edb.325.1610994120090; Mon, 18 Jan 2021 10:22:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610994120; cv=none; d=google.com; s=arc-20160816; b=SKJY3I0CbcAwhdDP74E0bU0OKHYe/fnXFdPMGYN58MwF8wda+LZqeVUWHv/CRY0v30 qcnvDllYrMomEnlpPg1VlZFbS24oRuUFJH195ObOujLaCeBo2IFdu8XBVucQXFZ6Z2Eo 9JuFb0i4qakVGu6M3zSxKbdfdK93RVrojxdWJ2uJNueJKLSDwgtUktGpLti5Ws+bm+qd Sh6kTiBny/gN3vjO06Wy6b8gsI7ILWK173T4ImpO7aChUJwSP4X/gGhLSKMNL68ozCpt 0YMoDuBGMw8V6ccVmoTx4ky+CfoZWA9FWv75uXSee1Y5JCVlEaRlytWCwrhVKx2MNEkf S4Jw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=XyPj4fpCKq7Kf34W6VB83/dQjJztz//caDgn5EKYgu8=; b=uwJ1351uErFbXzKMgKHt7jB/08mkprkwAYvTZF29+l2O3zk4V3A43dJR1l1rcDpyIq IH3voLWCM1W81sLlSIzYO2T4ACYywErcNXUxMl+qm5n5J9zrnllTRIX5gg/EWIsoj151 XpClothlXp1WXf+T/vkwpJJr4td675hhCDxXmfsRj9WToL5LSd0ZEiRrvx1a62ufbs4q v+yAs8ucxNoEUQuadpHOEDoBvxDlhhEYyuqM/q+YSyd5CggCTkyyH1u7Oz8euV3ZYIZE 3QN8FPkNrAn328Q8jMS+9RasDfsT1s8ewoW/VY6lHhgZoQRylDdOESemDbMJoJ1Lq3LR SqMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i1si7975862edy.450.2021.01.18.10.21.36; Mon, 18 Jan 2021 10:22:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407455AbhARSTg (ORCPT + 99 others); Mon, 18 Jan 2021 13:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393198AbhARPIm (ORCPT ); Mon, 18 Jan 2021 10:08:42 -0500 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FEE9C0613D6 for ; Mon, 18 Jan 2021 07:07:03 -0800 (PST) Received: from ramsan.of.borg ([84.195.186.194]) by laurent.telenet-ops.be with bizsmtp id JF6z2400Q4C55Sk01F6z0a; Mon, 18 Jan 2021 16:07:02 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1l1W7O-004cpa-RE; Mon, 18 Jan 2021 16:06:58 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1l1W7N-003LF3-L3; Mon, 18 Jan 2021 16:06:57 +0100 From: Geert Uytterhoeven To: Sergei Shtylyov , "David S . Miller" , Jakub Kicinski , Andrew Lunn , Heiner Kallweit , Florian Fainelli , Russell King , Ioana Ciornei , Wolfram Sang Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH net v2 2/2] sh_eth: Make PHY access aware of Runtime PM to fix reboot crash Date: Mon, 18 Jan 2021 16:06:56 +0100 Message-Id: <20210118150656.796584-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210118150656.796584-1-geert+renesas@glider.be> References: <20210118150656.796584-1-geert+renesas@glider.be> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wolfram reports that his R-Car H2-based Lager board can no longer be rebooted in v5.11-rc1, as it crashes with an imprecise external abort. The issue can be reproduced on other boards (e.g. Koelsch with R-Car M2-W) too, if CONFIG_IP_PNP is disabled, and the Ethernet interface is down at reboot time: Unhandled fault: imprecise external abort (0x1406) at 0x00000000 pgd = (ptrval) [00000000] *pgd=422b6835, *pte=00000000, *ppte=00000000 Internal error: : 1406 [#1] ARM Modules linked in: CPU: 0 PID: 1105 Comm: init Tainted: G W 5.10.0-rc1-00402-ge2f016cf7751 #1048 Hardware name: Generic R-Car Gen2 (Flattened Device Tree) PC is at sh_mdio_ctrl+0x44/0x60 LR is at sh_mmd_ctrl+0x20/0x24 ... Backtrace: [] (sh_mdio_ctrl) from [] (sh_mmd_ctrl+0x20/0x24) r7:0000001f r6:00000020 r5:00000002 r4:c22a1dc4 [] (sh_mmd_ctrl) from [] (mdiobb_cmd+0x38/0xa8) [] (mdiobb_cmd) from [] (mdiobb_read+0x58/0xdc) r9:c229f844 r8:c0c329dc r7:c221e000 r6:00000001 r5:c22a1dc4 r4:00000001 [] (mdiobb_read) from [] (__mdiobus_read+0x74/0xe0) r7:0000001f r6:00000001 r5:c221e000 r4:c221e000 [] (__mdiobus_read) from [] (mdiobus_read+0x40/0x54) r7:0000001f r6:00000001 r5:c221e000 r4:c221e458 [] (mdiobus_read) from [] (phy_read+0x1c/0x20) r7:ffffe000 r6:c221e470 r5:00000200 r4:c229f800 [] (phy_read) from [] (kszphy_config_intr+0x44/0x80) [] (kszphy_config_intr) from [] (phy_disable_interrupts+0x44/0x50) r5:c229f800 r4:c229f800 [] (phy_disable_interrupts) from [] (phy_shutdown+0x18/0x1c) r5:c229f800 r4:c229f804 [] (phy_shutdown) from [] (device_shutdown+0x168/0x1f8) [] (device_shutdown) from [] (kernel_restart_prepare+0x3c/0x48) r9:c22d2000 r8:c0100264 r7:c0b0d034 r6:00000000 r5:4321fedc r4:00000000 [] (kernel_restart_prepare) from [] (kernel_restart+0x1c/0x60) [] (kernel_restart) from [] (__do_sys_reboot+0x168/0x208) r5:4321fedc r4:01234567 [] (__do_sys_reboot) from [] (sys_reboot+0x18/0x1c) r7:00000058 r6:00000000 r5:00000000 r4:00000000 [] (sys_reboot) from [] (ret_fast_syscall+0x0/0x54) As of commit e2f016cf775129c0 ("net: phy: add a shutdown procedure"), system reboot calls phy_disable_interrupts() during shutdown. As this happens unconditionally, the PHY registers may be accessed while the device is suspended, causing undefined behavior, which may crash the system. Fix this by wrapping the PHY bitbang accessors in the sh_eth driver by wrappers that take care of Runtime PM, to resume the device when needed. Reported-by: Wolfram Sang Suggested-by: Andrew Lunn Signed-off-by: Geert Uytterhoeven --- v2: - Call mdiobb_{read,write}() now they are exported, - Use mii_bus.parent to avoid bb_info.dev copy, - Drop RFC state. --- drivers/net/ethernet/renesas/sh_eth.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c index c633046329352601..9b52d350e21a9f2b 100644 --- a/drivers/net/ethernet/renesas/sh_eth.c +++ b/drivers/net/ethernet/renesas/sh_eth.c @@ -3034,6 +3034,28 @@ static int sh_mdio_release(struct sh_eth_private *mdp) return 0; } +static int sh_mdiobb_read(struct mii_bus *bus, int phy, int reg) +{ + int res; + + pm_runtime_get_sync(bus->parent); + res = mdiobb_read(bus, phy, reg); + pm_runtime_put(bus->parent); + + return res; +} + +static int sh_mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val) +{ + int res; + + pm_runtime_get_sync(bus->parent); + res = mdiobb_write(bus, phy, reg, val); + pm_runtime_put(bus->parent); + + return res; +} + /* MDIO bus init function */ static int sh_mdio_init(struct sh_eth_private *mdp, struct sh_eth_plat_data *pd) @@ -3058,6 +3080,10 @@ static int sh_mdio_init(struct sh_eth_private *mdp, if (!mdp->mii_bus) return -ENOMEM; + /* Wrap accessors with Runtime PM-aware ops */ + mdp->mii_bus->read = sh_mdiobb_read; + mdp->mii_bus->write = sh_mdiobb_write; + /* Hook up MII support for ethtool */ mdp->mii_bus->name = "sh_mii"; mdp->mii_bus->parent = dev; -- 2.25.1