From nobody Tue Nov 24 12:36:17 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795394793; b=B3UMaqh8zn4ixpuJXO92Q+S449jgxZx/gIEAXEZQrzomUn6tjX256GEGRu1GFULthZ4W 10czId4J5oNWdik7I7OSwXYU2GLqXxAfQB5lRd+1hrc1KuN02GZBiTjXvBZ3V4/VkvKDN oTc2qVb4uGElFl8Wd17GUThryjUkQ/FoQJlKOI7I1dEep/UtUbRHMJ1/tBYAbDeleEUdo b9EVD3fW4rPJ7OzcAMqc3rGWeautJQtzaEyDAUBTKjUxH5hf6qkflr2gspZm+pG7Fjz3x t9AxzS9OK7wTMFsBM0FCK+Knn3jE6jfL3M2SMHcgCK5ntDfcEWuIMdQaBJpGrRq8ZXw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795394793; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cwtYdg7Ff/aGghpLaQ6sVil8yrw30S9ZwzKbTVNyIbs=; b=5hZnh74MQD+C2kLNvDzZPaRBPEuv3STENWpLzSCJXO0aTTwI36Dt2V9TvyvJAwYVGu/q 2T9nH8LWTez4QybRNUOV/CmTXSDeUj1b0CmakfSxpMqnmRbAui4fsPyb5fT/W7pzh4j3i rMgB3TqE8j4Wj05OIM3WiC3K63ImwbdDkiVXY0X2mbg8bqL96zMGlEgiTizv5udlJlvee qag2dD+gPlJmeQ89YT3KFPExQ8qp7UB1aIope62n1YBM+ZJODboQkfX7awi7J4kjbhbEm AJElZcwZoJ2+rcdKpl8zpQ7yLBqbVqlgy7/pSCSH0jlgmiWr+F1F8FMVp4BRh81Unig== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lEYA2aED; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D12A8606A6B4; Mon, 23 Nov 2026 00:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lEYA2aED Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795394793; b=1rWInvMIkd0Cm9N8UranfPJk0O1MTRuX56zJp6lVL4VOQkyX2d1tPA6WruI0IDTHZFP3 t7P1DlXX4dBUV/PDnct+00o8+zURWPL8ZuT1ws640kQoh+qegPhKnXAksKMZhuOzOelZY uagBKECcZ/bKEdrWDz0dC/GC26dtO6gbyddTONrCdRoXIVHvUBwQpWAqW0orRXrZ+bdsO szRu3n9ROnwpjR7bKl9B3cvPrn2XzIAKLRoZAsCVShnAKR3liqgexRad8jFWFJeDqeUzZ gTN0b8WhMArIlsvhjpDHkT6SjRpa5FnesqZiKVfDEsQio9Uk6hMAPABLi6XLxojdUBg== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795394793; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cwtYdg7Ff/aGghpLaQ6sVil8yrw30S9ZwzKbTVNyIbs=; b=cBVr0jU7sBkp5lDggSG1416hgqkdMvIhAqiljnYyZhA8hl8wcGD7P5N/jXF4wSdZB9vg HOu68fyvxSB1xCFTnHZGWowAR4/TI/sFlUwPaeyv0ShfQuxS7+Kg+pb1YCKeZBXkXF0JB P2HYa6rWSqifiBaOii605Su1YAmJCsHxT5LTouFJFJCi9qWEz1kxlntyvXj55k6BIK3Pa Hu/Sa9ui/H/H26GP7X0wLgmbsJivMSTadbnVRxsj8pOfWZgMrR8LTROOqbRPDv5MQoG3k rDw1mo78O8rk+xXJ2y17rDhiYFDWfzokrzT8CdFm24SBIgA9EWsTUtx34FHrf0RarHg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id CA3111F000D1; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795394793; bh=cwtYdg7Ff/aGghpLaQ6sVil8yrw30S9ZwzKbTVNyIbs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=lEYA2aED4l+8+lLkXoVdvsmdZDeso0ZgAYlP8Z6aILUYUTWNMEjyERFRyZiTKEEaQ VNioBWrGZe3O9o3IOiL9ZVQBzUI5dlyRcCdJ62thFpaORAnmbDRRCoBDk/T03r6qz+ AMRqnMVAt8QBeko6Ax0Mc3uqbLY6aepIX/qo/AhlYvi1omIOZbPUfXKZlieOhQr37E oZFiWo+HrEPoiyjPuc5jaJMyvxqWacuiZC47FpQZqjXqG40PG9yFX6NCtOGwyoDOmH /Q0ZCcI0p1I/sR0wS8Z/zJav8PERiFJpOo6DHVYr8xlHm0NV4AcAMMs5RsQDLY6LGs adIapMlLBghBQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 5AD434C27C; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) From: Igor Velkov via B4 Relay Date: Mon, 23 Nov 2026 00:46:13 +0000 Subject: [PATCH net v8 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261123-b4-phylib-mac-pm-irq-v3-v8-1-e9f706e79614@iav.lv> References: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> In-Reply-To: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Thomas Gleixner , linux-pm@vger.kernel.org, Maxime Chevallier , Lukas Wunner , "Rafael J. Wysocki" , Wei Fang , =?utf-8?q?Niklas_S=C3=B6derlund?= , Paul Barker , Florian Fainelli , Doug Berger , Thangaraj Samynathan , Shenwei Wang , Haoning Cheng , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Igor Velkov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3375; i=iav@iav.lv; h=from:subject:message-id; bh=Qlv4+bRQfcVjpy/H1IULOONZkAOElJ21mxexa2OAmIQ=; b=owGbwMvMwCVmNH1q96v4SmbG02pJDNnMPTdE2as3+Wz1+snBbVkw3d149aXaP6y310zd4fZb6 8PplCMdHaUsDGJcDLJiiiwTDmncylhy9a+/h/kDmDmsTCBDGLg4BeAiXYwMPe86jaxZMwWt7kaY KDy6Kndg4sdes84CicKb0w6kiWWxMPwPSeXYYC8f/ik+yHjeQWcOu1fHFwetX+1hcb3IfHrIi0u sAA== X-Developer-Key: i=iav@iav.lv; a=openpgp; fpr=90C228DA68A4D5FD4F4837E03297958BEA5F7903 X-Endpoint-Received: by B4 Relay for iav@iav.lv/default with auth_id=1060 X-Original-From: Igor Velkov Reply-To: iav@iav.lv Content-Transfer-Encoding: quoted-printable From: Igor Velkov irq_suspended and irq_rerun share a word with link, autoneg_complete and interrupts. phy_interrupt() sets irq_rerun from the IRQ thread without phydev->lock, while the state machine writes link and autoneg_complete under it and phy_request_interrupt()/ phy_free_interrupt() write interrupts, so one read-modify-write can undo another. A lost irq_rerun leaves the PHY interrupt disabled after resume, as phy_interrupt() has already disabled the line. The last patch of this series sets irq_suspended for PHYs whose MAC driver manages PHY PM; with stmmac that happens before the MAC stops the PHY, which widens the window. Taking phydev->lock in phy_interrupt() alone does not close it: phy_suspend() stores suspended in the same word and cannot hold the lock across phy_may_wakeup(), which may take it, and phy_init_hw() and mdio_bus_phy_suspend() write the word unlocked too. Locking every writer, MAC drivers included, is a wide audit, and one missed now or added later reopens the race. Make both flags bools. Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspen= d") Tested-by: Haoning Cheng Signed-off-by: Igor Velkov --- drivers/net/phy/phy.c | 2 +- drivers/net/phy/phy_device.c | 6 +++--- include/linux/phy.h | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index fce9bc7be330..9af303d60bd6 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1430,7 +1430,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_d= at) pm_wakeup_dev_event(parent, 0, true); } =20 - phydev->irq_rerun =3D 1; + phydev->irq_rerun =3D true; disable_irq_nosync(irq); return IRQ_HANDLED; } diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b39e945cebd7..1791d578f4dd 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -344,7 +344,7 @@ static __maybe_unused int mdio_bus_phy_suspend(struct d= evice *dev) * has resumed. Wait for concurrent interrupt handler to complete. */ if (phy_interrupt_is_valid(phydev)) { - phydev->irq_suspended =3D 1; + phydev->irq_suspended =3D true; synchronize_irq(phydev->irq); } =20 @@ -394,14 +394,14 @@ static __maybe_unused int mdio_bus_phy_resume(struct = device *dev) return ret; no_resume: if (phy_interrupt_is_valid(phydev)) { - phydev->irq_suspended =3D 0; + phydev->irq_suspended =3D false; synchronize_irq(phydev->irq); =20 /* Rerun interrupts which were postponed by phy_interrupt() * because they occurred during the system sleep transition. */ if (phydev->irq_rerun) { - phydev->irq_rerun =3D 0; + phydev->irq_rerun =3D false; enable_irq(phydev->irq); irq_wake_thread(phydev->irq, phydev); } diff --git a/include/linux/phy.h b/include/linux/phy.h index 21afc2082b17..59c75296d535 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -726,8 +726,11 @@ struct phy_device { =20 /* Interrupts are enabled */ unsigned interrupts:1; - unsigned irq_suspended:1; - unsigned irq_rerun:1; + /* Not bitfields: phy_interrupt() and the PM callbacks write them + * without phydev->lock + */ + bool irq_suspended; + bool irq_rerun; =20 unsigned default_timestamp:1; =20 --=20 2.43.0 From nobody Tue Nov 24 12:36:17 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795394791; b=4UCWkP08CgualoyBUq2EAnGg9nUMi1gazzZ5HpwpMHgwUQR81okj54XF8rU52zhq/OZa LXAzyu/SlkM+2x/npuKYUiwnWCArK/d1LbzJlzxWIuAkAd/hC5iGaAF2RdTaw5iqr+BiR 3wfBT6O6k37wLrIw2x8VE7C45lQNFxfuQ1V8wBTSsBgGwU3hQqd/ESZikvSsqrwsU1gTv Dl/wHcUJpmQoxskHa7FAAu76NS++p3l81nxT1MFI1qXGGWk8DNwPHLaI5FUDSOCnL57ve 1bJAriqoDu9D66rGDIFjQHSjpzxF74iH5TKuJSWz+hK3DxtHyYryqfKdYyVNeqfgv6g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795394791; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cA/N3p8I7gIJ0F5ljZHX+T5KEJi4WKSf5rP+621uci4=; b=dRD2H10SB5UyEhfjmh0jdC8uwbP4xoZ6vmhk1ZGFtMYrNw9+47289zMIKjQ75uKzQLj6 sfpN4f9dR+wm7ayw3EM+4b8wVva4kMuhxie/396LfHtG1RC45k6fTU5MziVmNBZvLeWTs WSWaHk6xekFNp9c1pRUq918JJpBsvHjOHipteg5ZFtI5Co4wNBgltqZLwdlJ6ZfPWk3su 9+/b/5aJIduH493PFwyf78XRtlm5pyWFcbPgpar+4AyxO4/YI/RIO9znZVcUO/SndCjlH QyzHWU3f6aR6779cqQMgSfiZsmfNQfCQWrlp70lGtKix1M/KBc+KbHP3fnXpbEa9N3Q== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QytJFNaf; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1DE606A31E; Mon, 23 Nov 2026 00:46:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QytJFNaf Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795394791; b=pjT87CQoyiV67Fh83bVk8tmC5SRaYTcJ4kfaS2KzvcWIRaKKg+4XgMNwC/zWRmIWpNsx Q88GHe2ss6qPVbiAF5Gg7urPYDzwc4Zd02baRAUUshWL1tExm+BrRQdKVQAQheSMj6BWB 1hUBaeASkLXPPdZ441/fI5ksG752XOlFF/xOC5mgkmOkkHRh+soZ1U6PPc3ZjX5wUdaZS a+qhc/+nUEkzrtyQvT+FSe+xMINRMS+iCjHasiBuR1KcAH9jLexBo2rMlptySXoXjVyeB AjtDdC8I1fSkXn7FDAitOgsnE/YZ/NTHC2HtZ+eOVnMoPHe60iWyXbqffWKzfPL26Lw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795394791; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cA/N3p8I7gIJ0F5ljZHX+T5KEJi4WKSf5rP+621uci4=; b=b/iP8ws5uOgjoWPxCEtmoB0y1BEIJIyW03LYTFVEt5b1SXkRUQ582CX8BHYAFauYfcPa ZAkc+3ZP01x6onJPj0t+stzWvVL6nY1U/nUbTKdbCiO43ALBdhytUFMVuorViH0Vd4Hjc m7nz/AyRjAdiUCwvu/iY974OjLNjt/6hlNjyy9mpydcTHNePs+JIveBAWLR8D7nyAQFnR vPSZda/ZNLg4S3JyHGyXm7Pcu/KytWZ3FhIn+/n42iCWu0p2yWDInEKJuJ9RWJdOadohZ P8dOL8qfEIObYfya9+/TLIcS2B+mnTEsPd+7xRKUr/7voc2l/EfQEDLY/hLT+VqN1mA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id E97B91F000D2; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795394791; bh=cA/N3p8I7gIJ0F5ljZHX+T5KEJi4WKSf5rP+621uci4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=QytJFNafGq8dAbUOEQ5vkAnejYblvZBqeaBfSHvf1RfFAgZfkGM0dR0sUpKoGTkQs pQT/DsJl0ymbuXmISNFgQni6yfGamc18T6NqmA8gA2UC+WWeXNe5We/76ZBkvlKOfV TPZIxCwh3MJys9Ru/0rlu4d8kXABYYPWNbDHAIh/dmZ4V7+d9XscOBPR6ySpO1Dt0O yuLBEgWxZ9p/TDBfs+ylocjKcrcnV1a87C2zmthImNGJrACxKAQCsM0P4Hzrn+AXdA ID1kbDkmqGjfEuFa/5mIODmPuwdnxyip8B1ZUvgHQe1jE9V9LIs9PkkrXaHvWM9CuK GzuIrJTID3yuQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 79B384C282; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) From: Igor Velkov via B4 Relay Date: Mon, 23 Nov 2026 00:46:14 +0000 Subject: [PATCH net v8 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261123-b4-phylib-mac-pm-irq-v3-v8-2-e9f706e79614@iav.lv> References: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> In-Reply-To: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Thomas Gleixner , linux-pm@vger.kernel.org, Maxime Chevallier , Lukas Wunner , "Rafael J. Wysocki" , Wei Fang , =?utf-8?q?Niklas_S=C3=B6derlund?= , Paul Barker , Florian Fainelli , Doug Berger , Thangaraj Samynathan , Shenwei Wang , Haoning Cheng , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Igor Velkov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=11424; i=iav@iav.lv; h=from:subject:message-id; bh=w00LTI1p+eM+1x7ZRAmQjTjEZhBtoli35Tub5EEx2ho=; b=owGbwMvMwCVmNH1q96v4SmbG02pJDNnMPTe2C7lsy/ZrW5y0or9+fmbl6zdCVUbap849XXSCx eP7Ve/WjlIWBjEuBlkxRZYJhzRuZSy5+tffw/wBzBxWJpAhDFycAjCRV9yMDCeEFxvMa9/d7z/b o+7d9/cHgrUiW2fONXZy+LuJocRn7RSGvwLzV14U9dqx6eG/p1u9OoPUmbxWftkyT1JrS1Toq9C rt7kA X-Developer-Key: i=iav@iav.lv; a=openpgp; fpr=90C228DA68A4D5FD4F4837E03297958BEA5F7903 X-Endpoint-Received: by B4 Relay for iav@iav.lv/default with auth_id=1060 X-Original-From: Igor Velkov Reply-To: iav@iav.lv Content-Transfer-Encoding: quoted-printable From: Igor Velkov phy_interrupt() postpones interrupts during a system sleep transition: it sets irq_rerun and disables the line, and mdio_bus_phy_resume() re-enables the line once and reruns the handler. Three paths leave the line unbalanced: - On an edge-triggered line the IRQ core does not mask a ONESHOT interrupt, so an edge that arrives before disable_irq_nosync() runs the thread again. That second run disables the line again, and the line stays disabled after resume. - phy_free_interrupt() can run between the postponed interrupt and mdio_bus_phy_resume() and leaves irq_rerun set. Once the line has no users, free_irq() shuts it down and a new request starts it at depth 0, so the enable_irq() in mdio_bus_phy_resume() is unbalanced. On a shared line this can happen once the other users free it too, as with the two PHYs of dra72-evm-revc behind cpsw. - If phy_request_interrupt() then leaves the PHY polling, mdio_bus_phy_resume() returns before enable_irq(), and the other users of a shared line stay disabled. MAC drivers that close the interface in their suspend callback, such as cpsw, and ravb with Wake-on-LAN off, reach phy_free_interrupt() through phy_disconnect(), and so does dev_close() in a kernel-internal reset of the MAC such as stmmac_reset_subtask(), whose workqueue does not freeze. These drivers set mac_managed_pm, which a later patch brings under postponing. Let only the run that sets irq_rerun disable the line, and record the line it disabled. Clear irq_rerun where the line starts again at depth 0: in phy_free_interrupt() when free_irq() leaves the line without users, and in phy_request_interrupt() when the line has no users. Otherwise mdio_bus_phy_resume() enables the recorded line, also for a PHY that fell back to polling, and reruns the handler only if the PHY still uses that line. Enabling the line in phy_free_interrupt() instead would unmask a source that phy_disable_interrupts() failed to clear, and inside the noirq phase it would unbalance a wakeup line that suspend_device_irqs() enabled (IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND). Add irq_pm_lock, so that requesting and freeing the interrupt do not change irq_rerun between the check and the enable_irq() of the rerun after resume, and move the postponing and the rerun into helpers. phy_interrupt() never takes the lock, so synchronize_irq() and free_irq() can wait for the handler under it. irq_rerun and irq_rerun_line are plain fields: one thread runs the handler, and the other paths access them only under the lock, after free_irq() or synchronize_irq(), or before this PHY has requested the line. Mark the irq_suspended accesses with READ_ONCE() and WRITE_ONCE(): the handler reads it while the PM callbacks write it. Three cases on a shared line stay unbalanced: after all users have freed the line, another user requests it first, so it has users when this PHY requests it; another user requests it between free_irq() and the irq_has_action() check in phy_free_interrupt(); or the last other user frees it between the irq_has_action() check and request_threaded_irq() in phy_request_interrupt(). irq_rerun then stays, and the enable after resume is unbalanced or reaches a line without users; until then a postponed interrupt does not disable the line again, so a level-triggered one keeps firing. This does not keep close and open off the MDIO bus: on close, phy_disconnect() calls phy_stop(), phy_free_interrupt() with its phy_disable_interrupts() and, in phy_detach(), phy_suspend(); on open, phy_attach_direct() calls phy_init_hw() and phy_request_interrupt() calls phy_enable_interrupts(). A MAC driver that powers its MDIO bus down during sleep must not close or open the interface until the bus is back. Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspen= d") Signed-off-by: Igor Velkov --- Haoning Cheng's Tested-by on v5 is not carried: phy_free_interrupt() no longer enables a shared line. --- drivers/net/phy/phy.c | 24 ++++++++++++++++--- drivers/net/phy/phy_device.c | 57 ++++++++++++++++++++++++++++------------= ---- include/linux/phy.h | 12 ++++++++-- 3 files changed, 67 insertions(+), 26 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 9af303d60bd6..92ee4651bdbc 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1416,7 +1416,7 @@ static irqreturn_t phy_interrupt(int irq, void *phy_d= at) /* Wakeup interrupts may occur during a system sleep transition. * Postpone handling until the PHY has resumed. */ - if (IS_ENABLED(CONFIG_PM_SLEEP) && phydev->irq_suspended) { + if (IS_ENABLED(CONFIG_PM_SLEEP) && READ_ONCE(phydev->irq_suspended)) { struct net_device *netdev =3D phydev->attached_dev; =20 if (netdev) { @@ -1430,8 +1430,12 @@ static irqreturn_t phy_interrupt(int irq, void *phy_= dat) pm_wakeup_dev_event(parent, 0, true); } =20 - phydev->irq_rerun =3D true; - disable_irq_nosync(irq); + /* Disable the line only once: an edge can rerun the thread. */ + if (!phydev->irq_rerun) { + phydev->irq_rerun_line =3D irq; + phydev->irq_rerun =3D true; + disable_irq_nosync(irq); + } return IRQ_HANDLED; } =20 @@ -1480,6 +1484,12 @@ void phy_request_interrupt(struct phy_device *phydev) { int err; =20 + /* A line without users restarts at depth 0, so our disable is gone */ + mutex_lock(&phydev->irq_pm_lock); + if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line)) + phydev->irq_rerun =3D false; + mutex_unlock(&phydev->irq_pm_lock); + err =3D request_threaded_irq(phydev->irq, NULL, phy_interrupt, IRQF_ONESHOT | IRQF_SHARED, phydev_name(phydev), phydev); @@ -1507,7 +1517,15 @@ EXPORT_SYMBOL(phy_request_interrupt); void phy_free_interrupt(struct phy_device *phydev) { phy_disable_interrupts(phydev); + + mutex_lock(&phydev->irq_pm_lock); free_irq(phydev->irq, phydev); + /* free_irq() shuts down a line left without users and the next request + * resets its depth; mdio_bus_phy_resume_irq() enables a shared line. + */ + if (!irq_has_action(phydev->irq)) + phydev->irq_rerun =3D false; + mutex_unlock(&phydev->irq_pm_lock); } EXPORT_SYMBOL(phy_free_interrupt); =20 diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1791d578f4dd..f2e2370b4be7 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -332,6 +332,39 @@ static bool mdio_bus_phy_may_suspend(struct phy_device= *phydev) return !phydev->suspended; } =20 +/* Wakeup interrupts may occur during the system sleep transition when + * the PHY is inaccessible. Set flag to postpone handling until the PHY + * has resumed. Wait for concurrent interrupt handler to complete. + */ +static __maybe_unused void mdio_bus_phy_suspend_irq(struct phy_device *phy= dev) +{ + if (!phy_interrupt_is_valid(phydev)) + return; + + WRITE_ONCE(phydev->irq_suspended, true); + synchronize_irq(phydev->irq); +} + +/* Rerun interrupts which were postponed by phy_interrupt() + * because they occurred during the system sleep transition. + */ +static __maybe_unused void mdio_bus_phy_resume_irq(struct phy_device *phyd= ev) +{ + WRITE_ONCE(phydev->irq_suspended, false); + + mutex_lock(&phydev->irq_pm_lock); + if (phy_interrupt_is_valid(phydev)) + synchronize_irq(phydev->irq); + /* The PHY may have fallen back to polling since it disabled the line */ + if (phydev->irq_rerun) { + phydev->irq_rerun =3D false; + enable_irq(phydev->irq_rerun_line); + if (phydev->irq =3D=3D phydev->irq_rerun_line) + irq_wake_thread(phydev->irq, phydev); + } + mutex_unlock(&phydev->irq_pm_lock); +} + static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) { struct phy_device *phydev =3D to_phy_device(dev); @@ -339,14 +372,7 @@ static __maybe_unused int mdio_bus_phy_suspend(struct = device *dev) if (phydev->mac_managed_pm) return 0; =20 - /* Wakeup interrupts may occur during the system sleep transition when - * the PHY is inaccessible. Set flag to postpone handling until the PHY - * has resumed. Wait for concurrent interrupt handler to complete. - */ - if (phy_interrupt_is_valid(phydev)) { - phydev->irq_suspended =3D true; - synchronize_irq(phydev->irq); - } + mdio_bus_phy_suspend_irq(phydev); =20 /* We must stop the state machine manually, otherwise it stops out of * control, possibly with the phydev->lock held. Upon resume, netdev @@ -393,19 +419,7 @@ static __maybe_unused int mdio_bus_phy_resume(struct d= evice *dev) if (ret < 0) return ret; no_resume: - if (phy_interrupt_is_valid(phydev)) { - phydev->irq_suspended =3D false; - synchronize_irq(phydev->irq); - - /* Rerun interrupts which were postponed by phy_interrupt() - * because they occurred during the system sleep transition. - */ - if (phydev->irq_rerun) { - phydev->irq_rerun =3D false; - enable_irq(phydev->irq); - irq_wake_thread(phydev->irq, phydev); - } - } + mdio_bus_phy_resume_irq(phydev); =20 if (phy_uses_state_machine(phydev)) phy_start_machine(phydev); @@ -711,6 +725,7 @@ struct phy_device *phy_device_create(struct mii_bus *bu= s, int addr, u32 phy_id, dev->max_n_ports =3D 1; =20 mutex_init(&dev->lock); + mutex_init(&dev->irq_pm_lock); INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); =20 /* Request the appropriate module unconditionally; don't diff --git a/include/linux/phy.h b/include/linux/phy.h index 59c75296d535..d84f7d8bc9df 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -651,8 +651,8 @@ struct phy_oatc14_sqi_capability { * @interrupts: Flag interrupts have been enabled * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt * handling shall be postponed until PHY has resumed - * @irq_rerun: Flag indicating interrupts occurred while PHY was suspended, - * requiring a rerun of the interrupt handler after resume + * @irq_rerun: Set by the postponed interrupt that disabled the line + * @irq_rerun_line: The line the postponed interrupt disabled * @default_timestamp: Flag indicating whether we are using the phy * timestamp as the default one * @interface: enum phy_interface_t value @@ -675,6 +675,9 @@ struct phy_oatc14_sqi_capability { * @n_ports: Number of ports currently attached to the PHY * @max_n_ports: Max number of ports this PHY can expose * @lock: Mutex for serialization access to PHY + * @irq_pm_lock: Held by the PM callbacks, and by the requesting and freei= ng + * of the interrupt where they test and clear @irq_rerun; + * phy_interrupt() never takes it * @state_queue: Work queue for state machine * @link_down_events: Number of times link was lost * @shared: Pointer to private data shared by phys in one package @@ -731,6 +734,7 @@ struct phy_device { */ bool irq_suspended; bool irq_rerun; + int irq_rerun_line; =20 unsigned default_timestamp:1; =20 @@ -808,6 +812,10 @@ struct phy_device { struct delayed_work state_queue; =20 struct mutex lock; + /* Held where the PM callbacks and the requesting and freeing of the + * interrupt test and clear irq_rerun + */ + struct mutex irq_pm_lock; =20 /* This may be modified under the rtnl lock */ bool sfp_bus_attached; --=20 2.43.0 From nobody Tue Nov 24 12:36:17 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795394792; b=hdO+79/afftPiFQqq7I3dY6cVBsVoyO54KXMRgkapuaRAaxRLY4qd6zt4GmzAxPhBrIv QztK0qi9xlnlMg6mjNKDF5vdyCjB3Z0VuTBiPtYQty+M/txvkAKyT0Dj5OD13TdePjWkh RSV4xLRRpHAiCf7o1yUcm0Uwn0xDI8/gLeDDbKgXJX34jGswaGLYxPaNLQY8ChLXpS0MS F31NAOp7sOJ66kAgXmWfzNjzcuyLut2jEIudSm2BRkYlDtvwQiRpPPcc1/eRhcQvIiPPl k2PpZC6fAkoDAFfLUKXB6Z2wr80wV8AXgTm62kFoQymfhFbdpHkrOCOc+Q5FTnNgXoQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795394792; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=FN3Bbbst5D0sGRM0932dqc0PNYvsp0yyVthhcry7hX4=; b=1uyWAtTc07+bRG+DHZ7gQ2+dtfLqUDp4PCgrl7cemNdO417s4cz+yB0eXR7OTGpbKfKM Z2+2C2ikiGFJeTgpdkRmfAD40+B+hxbl8CwDPTjtX9fdoMHAopbzVqqHbcV7OqBWRCMLu SnW8P5nt1qhEwftZuY/57dbtsv6hBvVSMOn57o+EA5I04bLVnaFb0+hpvD88uGSiKbJtE sJ0tCLe1FZpUaXdN6Nu1r+OMsEjNCtuFgqVKx74yn9sO4xZDFvu0n8JC/5fea8NwoxrXz 9jIMeCBxLIBUNcB/RXmZrBtd7JkQDdPCi7jP90w6SFeirRdVMwEzG36t7BFwQVYJW/g== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lHFPByGf; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BEE360A2606; Mon, 23 Nov 2026 00:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lHFPByGf Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795394792; b=yptY7uAb93MVJJFc5VeLgvj+XxQCbkZIQR6274cjaxk3BQ40GO4uah7qhEZXaWyhDbeE zcDhLtA9WV0wteUF5L1WwcZs2x8GcgD0FIR5aL/vMnI7NTqcrU3VcNmJ7ApD9/ieohe6p COF9kuhee3Hm0mkCG6VGN1zEIBIJxVjgVt+0IR56hmah/GaSuenmKXz4oMuFATtLg2Qxl wvpKCvAEJrIStyd180KIVU92ar3+SIzke+jgL19Ucc55EfKj41H42zleIxuarNrPLXjqQ TfZST9LzLommRhr9vtNgNHzTULzsVVogMB5mtl3Fdlc98vauhLUrSx1/JqLVLE6MXxA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795394792; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=FN3Bbbst5D0sGRM0932dqc0PNYvsp0yyVthhcry7hX4=; b=croIgxelQWqLOdJq1naxm7RqdThBTNaGJYzx0cIkKyVJtCamgTdOkA3ZyXgD5JbASQYW Y2O0754BDLl+JCBLcLB2aEIGdbrCNBPakD6yckXDpZDk90ALRXK6MyRLrkGeIgb6TEgtE FQOx2BT0yC7o51a+jqLkDd26tYV4VRby6mVguLtsZNe/frq0sn3fyLMz9qUu2LleNxmqd RxjaBjh3+DjwD+hje+o7UlMrj1Enwgj4hdp2riLea41OTjhtTkTvyXsKgt4KrxfRpXDdJ 9h/+CHICb8A0wZCNr76Y+KVSHgsmWyNKR9SNYwDw9rn+eFMAuyi+jwRnfj6Ks3ZXpbQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 135871F000D3; Mon, 23 Nov 2026 00:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795394792; bh=FN3Bbbst5D0sGRM0932dqc0PNYvsp0yyVthhcry7hX4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=lHFPByGfWvtPMngvhAQTXd5gXRh/T2z6+Zzh3Pk2Bve+97yw/TJIKu0vsI138LGEi 5p4uaal1x8ZeMD30FZvrAVoByhP+TPRxVgwD/plu3u1baucMK2COALbq1Z/yo1sTYX ZJSzmx+X5tUjysv29wDACFQ+zn81A8T7zMP/v/ohE3WV2gw0cq7yctzFti9IZsS+qE TpbmPphzAytWSbx9iBiUSPtMM49xN883h64YaSD8Z7L9JTW9VvVa2Nj3oez8rJjUIv X+1XniOOkl0yTVLrfRWGpNc1nsKHujM0RJNOmGgzgd7aDMyvEIjwZnpGVABClVFQ11 ODkyChF2iYXgA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 977114C286; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) From: Igor Velkov via B4 Relay Date: Mon, 23 Nov 2026 00:46:15 +0000 Subject: [PATCH net v8 3/5] net: phy: stop postponing PHY interrupts when phy_suspend() fails X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261123-b4-phylib-mac-pm-irq-v3-v8-3-e9f706e79614@iav.lv> References: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> In-Reply-To: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Thomas Gleixner , linux-pm@vger.kernel.org, Maxime Chevallier , Lukas Wunner , "Rafael J. Wysocki" , Wei Fang , =?utf-8?q?Niklas_S=C3=B6derlund?= , Paul Barker , Florian Fainelli , Doug Berger , Thangaraj Samynathan , Shenwei Wang , Haoning Cheng , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Igor Velkov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2342; i=iav@iav.lv; h=from:subject:message-id; bh=uRMMA0Q2puJNX3mPj5NSRgKeAYrUSBenrydqXPVYlvM=; b=owGbwMvMwCVmNH1q96v4SmbG02pJDNnMPTcunbzVGP1OpeTbgvawfYxi57IlgpU/MQg4/Two6 XRPVXB7RykLgxgXg6yYIsuEQxq3MpZc/evvYf4AZg4rE8gQBi5OAZiI5GyG/8Er+nccNVhetqpN yupD+yHR8gMWbvE3ApMnTtGfw/rywU6G3yweXLbbD9j+VhK/FrBpk49ugWSyqsuTJkGlO3ru06x iuAA= X-Developer-Key: i=iav@iav.lv; a=openpgp; fpr=90C228DA68A4D5FD4F4837E03297958BEA5F7903 X-Endpoint-Received: by B4 Relay for iav@iav.lv/default with auth_id=1060 X-Original-From: Igor Velkov Reply-To: iav@iav.lv Content-Transfer-Encoding: quoted-printable From: Igor Velkov When phy_suspend() fails in mdio_bus_phy_suspend(), irq_suspended stays set and the state machine stays stopped: the PM core does not resume a device whose suspend callback failed, and the next PHY interrupt disables the line until the next resume. Undo the postponing and restart the state machine when phy_suspend() fails. Set suspended_by_mdio_bus only after phy_suspend() succeeds. Set before it, the flag outlived a failed suspend, and in a later cycle where mdio_bus_phy_may_suspend() returns false, mdio_bus_phy_resume() ran phy_init_hw() and phy_resume() on a PHY that the MDIO bus had not suspended. The error returns of mdio_bus_phy_resume(), after phy_init_hw() or phy_resume() failed, stay as they are: the postponing goes on, and a line that a postponed interrupt disabled stays disabled. Undoing the postponing there would run the handler, from the next interrupt on, on a PHY that did not resume. Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspen= d") Signed-off-by: Igor Velkov --- Haoning Cheng's Tested-by on v5 is not carried: this patch no longer changes the resume error path. --- drivers/net/phy/phy_device.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f2e2370b4be7..2d2058c29f30 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -368,6 +368,7 @@ static __maybe_unused void mdio_bus_phy_resume_irq(stru= ct phy_device *phydev) static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) { struct phy_device *phydev =3D to_phy_device(dev); + int ret; =20 if (phydev->mac_managed_pm) return 0; @@ -385,9 +386,20 @@ static __maybe_unused int mdio_bus_phy_suspend(struct = device *dev) if (!mdio_bus_phy_may_suspend(phydev)) return 0; =20 + ret =3D phy_suspend(phydev); + if (ret) { + /* The PM core skips the resume callback of a device whose + * suspend callback failed. + */ + mdio_bus_phy_resume_irq(phydev); + if (phy_uses_state_machine(phydev)) + phy_start_machine(phydev); + return ret; + } + phydev->suspended_by_mdio_bus =3D 1; =20 - return phy_suspend(phydev); + return 0; } =20 static __maybe_unused int mdio_bus_phy_resume(struct device *dev) --=20 2.43.0 From nobody Tue Nov 24 12:36:17 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795394786; b=bZrN6POMy+CPmssUs6tv1GBAxTMESHPVTtgh6Gm+N3BlHGVMI4bgMfX0q+J6e4PzezUS OWSAFh6AnkShQlGuXufa8E3//ZAHhOMz9Y4yjG6Q1b2xullWxMaOX/QZ5LNghSHwc0j/l b2y2AxupWclqfxCoeKOA45T9/39PEBPmjez8qkhBExZWyHMWDrtHySQTw8YKosjeJw8pF 29OqJeDKyt3K7aFrzMLZ+XDvMKhO7pvrcYHOB3JJFcqdo+m5udcTKPc+nqjf9VnUCSi39 uxB9SpJzLabPqOTFaz/UEGBXevE1egZyhTg6bGH8LpOoBWOXLjRx1D5kUHdISiSkdMg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795394786; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=30Qu+ur/6/c1t3EoSrJtgPyjUR8t9B2zrfD9U5zhs40=; b=D8IJwalrQycV+eEFWju0l+R5fxWQ1ZkLIWCBpL/RlnJJvJrg799H5KxCdUlK0XICI8vO ynK9f6xT4G0CqSBs2p2s+6UOBYFC1d4ySBQg6LtM5ZMg5pnIBvX5/6B/WQQJGC2TMeVCL RovXruNqfnbPsCX8gpqOgQhkUCgE4qLLUEgHkHmcW2qQba03EXyOfVeANVgSEDG8DQ9HY pDAMG7hyBYTyxZd9cINDRXW55VLGbcYhI0gaTNxldKZyt12/ouc/rMb4vRU6BRJuIEnEd hHJ+O5OV9PDmiQ523ncXK1j7uhqILUYoMvdLCL8m5jspmXPRq2wAcH4i/gbzS/NBDbg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TSiZUDA7; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDC92606A320; Mon, 23 Nov 2026 00:46:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TSiZUDA7 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795394786; b=pYuCjOFFEG37yigxNJlTuxs/BsWPXvlcsc/A69ulkZpB5fZW1BNHahQ/eIaGcXRUTFxm scUAHULEm/gG9fqAOu7nXvr0Ik/XMy1xdayHqkMkGKE5l3ml6E0VhqEGtPVs7J/Nz+XUI UweiWLFQ3u+HmRVvD0mHQv6E6fziOtAp7VPD3Lr9LQiLfRQyj+wNqwMPqpUaxQtGCZ+/g RbA0gRwzSJqPAkc3P84kPC5SFLgc6DiPOHKVWp5Nty4UHwhfRBs0HUKowi05+L7yB9pIt B3w8CYfnBrWvUgx85CIRWeS57EEStqztiE3ykEowURHMrKFK9+1FvzTEoP2C+UESJuQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795394786; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=30Qu+ur/6/c1t3EoSrJtgPyjUR8t9B2zrfD9U5zhs40=; b=Yn99m87b/pH+wnFK3mZfeJTVa6cy28azrX0RbLAD+wDUM/IZSVW2B+EcQlUZ4oUajO8W /6wa0dd+NKuQTO2+zFD/yc8y0IoZSg5Su/qvFvxl8cnfo0s9ifpD9+S4k/OgyIRPhqUm0 3uPEWhZrKwCaQ5vNdCSryo7Pe6TGxw17z+zV2OEOmdvCwjYvXYwF/8dU4W6YQ9pjLF3oN ++iTymJxdYJQ0ZJVBpQQEADtvc/8eZ3InRqrNHWGkVVOpckKX+zYV00wlbNo3DdjbqhdA FRyGv7yYoskMhul+QOVnRBuEN/EE0hbG43HN7KbVhfJ0BR8FzYFK5nHGFr+qRtpY4Kg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 2EFA81F000D4; Mon, 23 Nov 2026 00:46:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795394785; bh=30Qu+ur/6/c1t3EoSrJtgPyjUR8t9B2zrfD9U5zhs40=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=TSiZUDA7nhQGKLHC/2/yKYZWqq9CqTzeQU8ph13qkI4iqkJfdl2nlO0EHYu39Kgpk kezVVXpNITlgpWAmP++H0MSgwO4WKU9SMSw+P99h9rrzuEIUuNllFOncylZI7BGMuc 4UHKUxK9vHmlvgY+vGBaOFVgukcTFReOIsUytysrFAM5/eVaIEv72Bo5B2/b+G7Sji jBAwvhn2kp+qdozXp6g6cQT2FsmO9WYzwXvWVtwsQgmaYBgPjb5+A80PQr86wxEnLa s9k65B86rS8qn3aGo4I074p8aM3VuY9/Sycskd9VOn4+ohoD3xLMh6EKBd99lVtnXJ OnmDiCTgpN4Aw== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id B2E944C28A; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) From: Igor Velkov via B4 Relay Date: Mon, 23 Nov 2026 00:46:16 +0000 Subject: [PATCH net v8 4/5] net: phy: run a postponed PHY interrupt handler directly on resume X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261123-b4-phylib-mac-pm-irq-v3-v8-4-e9f706e79614@iav.lv> References: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> In-Reply-To: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Thomas Gleixner , linux-pm@vger.kernel.org, Maxime Chevallier , Lukas Wunner , "Rafael J. Wysocki" , Wei Fang , =?utf-8?q?Niklas_S=C3=B6derlund?= , Paul Barker , Florian Fainelli , Doug Berger , Thangaraj Samynathan , Shenwei Wang , Haoning Cheng , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Igor Velkov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3946; i=iav@iav.lv; h=from:subject:message-id; bh=4J/4xMe32fdh9YgOph9KgzVmf4XWY5UGbdamA1eJyLE=; b=owGbwMvMwCVmNH1q96v4SmbG02pJDNnMPTf/OdhNSeT4xMyypuQtj8LJnPTHPI1Wxec1la5xR ofYLpHtKGVhEONikBVTZJlwSONWxpKrf/09zB/AzGFlAhnCwMUpABPxWsXI8Pj8p53GuTZlMlKh Ezncl7D/5otT/bDKIbeqhLtB7bj3bIb/TjPN/2fFtC+XvP1PZjXbz4j6WUwOPxQTjRMP3A3SYFb jBwA= X-Developer-Key: i=iav@iav.lv; a=openpgp; fpr=90C228DA68A4D5FD4F4837E03297958BEA5F7903 X-Endpoint-Received: by B4 Relay for iav@iav.lv/default with auth_id=1060 X-Original-From: Igor Velkov Reply-To: iav@iav.lv Content-Transfer-Encoding: quoted-printable From: Igor Velkov mdio_bus_phy_resume_irq() reruns a postponed interrupt with irq_wake_thread(). A PHY interrupt behind a nested threaded interrupt controller, such as an I2C or SPI GPIO expander, has no interrupt thread, so irq_wake_thread() does nothing and the postponed interrupt is lost: the PHY keeps its status latched and its INT line asserted. For a PHY that the MDIO bus suspended, mdio_bus_phy_resume() calls phy_init_hw() before the rerun, and config_intr() there acknowledges the latched status in drivers such as realtek. A PHY that the bus did not suspend, as with Wake-on-LAN enabled, gets no phy_init_hw() and loses the interrupt today. A later patch brings PHYs with MAC-managed PM under postponing, and stmmac, for one, does not call phy_init_hw() on resume. Call the PHY driver's handler from mdio_bus_phy_resume_irq(), as phy_interrupt() does, unless the PHY has its interrupts disabled, as after phy_free_interrupt(): on a shared line irq_rerun outlives the free, and the handler would run on a PHY that no longer uses the line. Hold irq_pm_lock across the call and around phy_disable_interrupts() in phy_free_interrupt(), so that the free waits for the handler, as free_irq() waits for the thread. Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspen= d") Signed-off-by: Igor Velkov --- drivers/net/phy/phy.c | 3 +-- drivers/net/phy/phy_device.c | 13 ++++++++++--- include/linux/phy.h | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 92ee4651bdbc..6cc94b525e09 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1516,9 +1516,8 @@ EXPORT_SYMBOL(phy_request_interrupt); */ void phy_free_interrupt(struct phy_device *phydev) { - phy_disable_interrupts(phydev); - mutex_lock(&phydev->irq_pm_lock); + phy_disable_interrupts(phydev); free_irq(phydev->irq, phydev); /* free_irq() shuts down a line left without users and the next request * resets its depth; mdio_bus_phy_resume_irq() enables a shared line. diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2d2058c29f30..8bc394ff7d2d 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -355,12 +355,19 @@ static __maybe_unused void mdio_bus_phy_resume_irq(st= ruct phy_device *phydev) mutex_lock(&phydev->irq_pm_lock); if (phy_interrupt_is_valid(phydev)) synchronize_irq(phydev->irq); - /* The PHY may have fallen back to polling since it disabled the line */ + /* The PHY may have fallen back to polling since it disabled the line, + * or freed its interrupt while another user keeps the line. + */ if (phydev->irq_rerun) { phydev->irq_rerun =3D false; enable_irq(phydev->irq_rerun_line); - if (phydev->irq =3D=3D phydev->irq_rerun_line) - irq_wake_thread(phydev->irq, phydev); + /* A nested threaded line has no thread; we run the handler */ + if (phydev->irq =3D=3D phydev->irq_rerun_line && + phydev->interrupts) { + mutex_lock(&phydev->lock); + phydev->drv->handle_interrupt(phydev); + mutex_unlock(&phydev->lock); + } } mutex_unlock(&phydev->irq_pm_lock); } diff --git a/include/linux/phy.h b/include/linux/phy.h index d84f7d8bc9df..9253a07e84be 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -677,7 +677,7 @@ struct phy_oatc14_sqi_capability { * @lock: Mutex for serialization access to PHY * @irq_pm_lock: Held by the PM callbacks, and by the requesting and freei= ng * of the interrupt where they test and clear @irq_rerun; - * phy_interrupt() never takes it + * taken before @lock; phy_interrupt() never takes it * @state_queue: Work queue for state machine * @link_down_events: Number of times link was lost * @shared: Pointer to private data shared by phys in one package --=20 2.43.0 From nobody Tue Nov 24 12:36:17 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795394798; b=ZV11D2W3YYHchD1wHQIqDbdQ9XerhknEbexg6jyOSfjSDw8DIBc83lL12WowRbSuUrbF QtYA+Er6A9L7/RiLHHiW6CUTSJPFSAST9PF+pLkcujivJCGs7cJxTj78OVd9GLs+8ThtR dJT1mBE0UhKFS1+yKO9l2NGm/R9apNgjClOv+15mts4Vech4SaVqIm8YTyn101YBuqyR2 FHvh4KFR09taGvhwuQTB2OQXuiFZDIZ4rn/7Q17+2zXPZZNwIZvVs2UCEHVEuBTO2Mage IwWYrI4t9Whot+vE8ySGF1eImUlFuu+X9nbASLVIPkx6/CXfvxsh8noECWPYvptHDCg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795394798; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=kxGGhR/P1EpVrGtRyUb20WvpccAqTJevEP1rssKg7Yo=; b=s+0Y359W0Bcxn2Z5Heyscblv2qxKj4zRrkksrxFwgCplVO2Tz/oNok5difkZO5X6iDFv dMnc8joKI3WSrpAhrmBrzPJ42WHqboO7GhCza1w8W/ndohgWWMLPIG7UrspnODaItHN94 XwdR5wstROdVESYYyXwYto9mmvcTLnGeKTwpKbQUEyhgQT25Bcz0Zv1m3OEQZME9Vy0PZ 7owFMNeu5yGYTDFMIhAtp2e4hYjWUCITxB+rnmVfu4oipZgDqiPSxSRnkjaPMHlNCYdDN 8S0hF1MMGvQS6guMYWuPgr/HwlKaH2H3hllsvgCW7Sf6IrohoIPwkKn0mJXKi3leQuQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gujkP6jO; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37F0F606A31E; Mon, 23 Nov 2026 00:46:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gujkP6jO Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795394797; b=3KCpvCs9Rs1RrH4ErBSxg31bOE661oa5SYWi+32Y/jnBSrPUB++bJxX6nmTGNQrkjSnq C55vFQA3pgl0EsUQVx8cG5etgpwT/XX9oGKoXvOjfLmvgLchF5dlL+HR5YGTg0fuI9Ldg LgUschGae75+v7AaIe1AeJDKG8/RQ4eHpaVNZDYnzZJO4rwPgqZJfyykJlUg0KmdKtGf7 q5DxInEPmnt3QgYJTtz8snMPaLW0WTvzzBsywnr7+83qadPpZNzF9B29mOupwgwXuYaix R/wzBeKi3ZT3x4NDCDuJ18GTLSbQnB2r7KenSoYqRbZ9juUgdAA1oK6keA6oTOyMw1w== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795394797; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=kxGGhR/P1EpVrGtRyUb20WvpccAqTJevEP1rssKg7Yo=; b=iQl+x1W84zjyKhJ8MaYDztMyRTJzLNlg5EAWQe8il+T62U5Mbbj+rb/j5/r4/Ut6CSLr R3os2U10MUFQLcn5+WuBw5+FG8tvha1A0Kz2gXNQtjw+i+udqTuz5mUzVSOseSPCmucLA TIU2QBr7qHXK2zgVXm+XywN9w1ncfp/RR1bn/SKHDk3PgiDjlIBJROoxvIpocT8DwR2ms cTtOvGb6OzE1HpSfoQKYgDgGQUvNwhSI+cwD+mfXgb4qHAxTA9yxbD7cM5ULI0ShXbh6Y ju2lqXTra/rgMphdiGT4R8TKncKFo+61Z2e5lRnKIAWzf6zBwxTLNOWj6M4dhM7++rA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 05D9E1F000ED; Mon, 23 Nov 2026 00:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795394797; bh=kxGGhR/P1EpVrGtRyUb20WvpccAqTJevEP1rssKg7Yo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=gujkP6jOwbAyd6fHwik7d4mgYXYaM1KJGnStxnhzLpyDK+WdjQD62PITjflF1HD6B 7ZxuBWXtp52y3/QR0Y7017mHkZaD+sheZW9TWQlv1TwXXEi4zGgdocy1vkz1BRxLd8 RmHD5z6A6WiZvL9qoBMV1L1GcWMi9bi/PnlcDZHnKXoImNU5/n8uFmgdKPJS7V5cYc Ayeq6VSNP87wmiRBnGBi9sk6qhA7UbP2r9OX4SsWbdaXw1tFB2j+3KcKY4kursC2fh FuBHl9PokKvNtypcUdfRg3LlJEL72+2r8Evt1EIHpn6fglrLC8Fqe4BPbGb0j/tGAX zSojzVWzdWUzg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id CDE114C28E; Mon, 23 Nov 2026 00:46:19 +0000 (UTC) From: Igor Velkov via B4 Relay Date: Mon, 23 Nov 2026 00:46:17 +0000 Subject: [PATCH net v8 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261123-b4-phylib-mac-pm-irq-v3-v8-5-e9f706e79614@iav.lv> References: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> In-Reply-To: <20261123-b4-phylib-mac-pm-irq-v3-v8-0-e9f706e79614@iav.lv> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Thomas Gleixner , linux-pm@vger.kernel.org, Maxime Chevallier , Lukas Wunner , "Rafael J. Wysocki" , Wei Fang , =?utf-8?q?Niklas_S=C3=B6derlund?= , Paul Barker , Florian Fainelli , Doug Berger , Thangaraj Samynathan , Shenwei Wang , Haoning Cheng , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Igor Velkov X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=13942; i=iav@iav.lv; h=from:subject:message-id; bh=/2w9XPVi3IQJ1MGUV9hFU/N44O2waJYWgwEwJd+EKc0=; b=owGbwMvMwCVmNH1q96v4SmbG02pJDNnMPTdfvT15c+brO3cnbH23d8pEn2zd42k2sWkfErM6n U/ev9Y+r6OUhUGMi0FWTJFlwiGNWxlLrv719zB/ADOHlQlkCAMXpwBMRP4kI8Pre2drcqQcrBkW JbSyitQe1IuZeUA35rkGF/tGvsNlnqsZGfaFinzwCp/aMV1Vc/KG6JcFBo+d2auFf6w/XCd1em2 DOAsA X-Developer-Key: i=iav@iav.lv; a=openpgp; fpr=90C228DA68A4D5FD4F4837E03297958BEA5F7903 X-Endpoint-Received: by B4 Relay for iav@iav.lv/default with auth_id=1060 X-Original-From: Igor Velkov Reply-To: iav@iav.lv Content-Transfer-Encoding: quoted-printable From: Igor Velkov mdio_bus_phy_suspend() and mdio_bus_phy_resume() return early when the MAC driver manages PHY PM, so the PHY never gets irq_suspended and phy_interrupt() runs the PHY driver's handler at any point of the sleep transition. If the MAC driver powers the MDIO bus down, the MDIO access in that handler can stall the CPU. This happens on both sides: - suspend: the MAC's suspend callback stops the PHY, the link goes down, and the handler runs while the MAC powers down; - resume: resume_device_irqs() re-enables a pending interrupt before the MAC resumes. On Helios64 (dwmac-rk, RTL8211F with its interrupt line described in DT) both hang the board: the handler reads INSR while the GMAC clocks are off, after rk_gmac_suspend() or before rk_gmac_resume(). The commit in the Fixes tag added the postponing after the early return for MAC-managed PHY PM, and stmmac has set mac_managed_pm since commit f151c147b3af ("net: stmmac: Enable mac_managed_pm phylink config"). Postpone the interrupts of these PHYs too, and start in the prepare callback. The PM core calls prepare for all devices before the first suspend callback, so irq_suspended is set before any MAC driver suspends. The system still runs between prepare and the suspend callbacks, and for hibernation it allocates the image memory there: a link change of such a PHY in that window is handled only after resume or complete. mdio_bus_phy_suspend() is too late when the PHY sits on an MDIO bus the MAC does not own: phy_attach_direct() links the MAC as a consumer of the PHY, and the MAC suspends first. ODROID-HC4 (stmmac, RTL8211F behind mdio-mux-meson-g12a) takes this path. There, without this series, a magic packet that arrived after stmmac_suspend() ran the handler, which acknowledged the PME; the RTL8211F raises PME once per arming, and the board slept through the packets that followed. PHYs without MAC-managed PM still start postponing in mdio_bus_phy_suspend(). The PM core skips the resume callback of a device whose suspend callback it did not call, so the complete callback stops the postponing when the transition aborted before mdio_bus_phy_suspend(). The PHY device is a child of its MDIO bus, so mdio_bus_phy_resume() runs after the resume callbacks of the bus and its parents (with stmmac, the MAC) and replays the postponed interrupt then. The PM core resumes children of a device whose resume callback failed, and phylib cannot tell: if the MAC fails to power the bus up, the replay still reaches the bus. Behind the device link the PHY resumes before the MAC, so there the replay still runs before the MAC resumes, as the handler did from resume_device_irqs() before this change. phy_suspend(), phy_resume() and the state machine stay with the MAC driver, and no MAC driver needs a change. Doing this in phylink_suspend() instead would miss macb, which sets mac_managed_pm but suspends with phylink_stop(). A postponed interrupt cannot read the PHY, so it cannot tell Wake-on-LAN from a link change. A PHY without MAC-managed PM reports what phy_interrupt() reports today. A PHY with MAC-managed PM reports no wakeup from the postponed interrupt: the MAC can change the link in its suspend callback, as stmmac lowers the link speed through phylink_suspend() when the PHY may wake the system. A postponed interrupt leaves its line disabled. suspend_device_irqs() runs before the noirq callbacks: it arms a wakeup line and leaves a disabled one disabled unless the irqchip has IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND, so a PHY whose interrupt line is also its wake IRQ would sleep through a wakeup. Enable the line a postponed interrupt disabled in the noirq suspend callback while it is still disabled and armed for wakeup, and disable it again in the noirq resume callback, before resume_device_irqs(). The irq core turns an interrupt on an armed line into a wakeup without running the handler, and clears the armed state before it disables the line, so a line that already woke the system is left alone, and so is a line that is no longer disabled. An edge the postponed interrupt consumed does not repeat, so on an edge-triggered line a magic packet that arrives during the transition does not abort it. The next one wakes the system if the PHY raises another edge for it; the RTL8211F, which raises PME once per arming, does not. On a level-triggered line, a PHY that keeps a link interrupt asserted, such as the one from the speed change above, aborts every suspend with Wake-on-LAN enabled: its driver has to restrict the interrupt to Wake-on-LAN in its suspend callback, as rtl8211f_suspend() does; with Wake-on-LAN enabled, phy_suspend() calls that callback only for a driver that sets PHY_ALWAYS_CALL_SUSPEND. The noirq callbacks also run as freeze_noirq and thaw_noirq, so all of this holds while a hibernation image is created. Tested with 7.4-rc3 and this series, s2idle with the link up. Helios64: - no Wake-on-LAN, GMAC clocks off in suspend: 7 of 7 cycles suspended and resumed; on 7.3 without this series the same test hung or reset the board after the link went down 10 of 10 times; - MAC power/wakeup enabled, no Wake-on-LAN: 3 of 3 slept; - Wake-on-LAN in the PHY, so phylink_suspend() also drops the link speed: a magic packet woke the board 2 of 2 times, no suspend aborted; - the same under a flood of magic packets: a packet after rtl8211f_suspend() was postponed and disabled the line, the noirq callback enabled it, and the wakeup aborted the suspend 5 of 5 times (traced). ODROID-HC4: - Wake-on-LAN in the PHY under a flood of magic packets: a packet after stmmac_suspend() was postponed, and the wakeup aborted the suspend 6 of 6 times (5 traced); without this series the board slept until the RTC alarm 5 of 5 times; - Wake-on-LAN in the PHY, no packets: 5 of 5 slept until the RTC alarm, with no PHY interrupt. Fixes: 1758bde2e4aa ("net: phy: Don't trigger state machine while in suspen= d") Signed-off-by: Igor Velkov --- Haoning Cheng's Tested-by on v5 is not carried: MAC-managed PHYs no longer report a wakeup. --- drivers/net/phy/phy.c | 13 ++++++-- drivers/net/phy/phy_device.c | 79 ++++++++++++++++++++++++++++++++++++++++= ++-- include/linux/phy.h | 17 +++++++--- 3 files changed, 98 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 6cc94b525e09..45891570a56e 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1419,7 +1419,10 @@ static irqreturn_t phy_interrupt(int irq, void *phy_= dat) if (IS_ENABLED(CONFIG_PM_SLEEP) && READ_ONCE(phydev->irq_suspended)) { struct net_device *netdev =3D phydev->attached_dev; =20 - if (netdev) { + /* With MAC-managed PM, a postponed interrupt cannot tell + * Wake-on-LAN from a link change the MAC causes. + */ + if (netdev && !phydev->mac_managed_pm) { struct device *parent =3D netdev->dev.parent; =20 if (netdev->ethtool->wol_enabled) @@ -1486,8 +1489,10 @@ void phy_request_interrupt(struct phy_device *phydev) =20 /* A line without users restarts at depth 0, so our disable is gone */ mutex_lock(&phydev->irq_pm_lock); - if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line)) + if (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line)) { phydev->irq_rerun =3D false; + phydev->irq_wake_enabled =3D false; + } mutex_unlock(&phydev->irq_pm_lock); =20 err =3D request_threaded_irq(phydev->irq, NULL, phy_interrupt, @@ -1522,8 +1527,10 @@ void phy_free_interrupt(struct phy_device *phydev) /* free_irq() shuts down a line left without users and the next request * resets its depth; mdio_bus_phy_resume_irq() enables a shared line. */ - if (!irq_has_action(phydev->irq)) + if (!irq_has_action(phydev->irq)) { phydev->irq_rerun =3D false; + phydev->irq_wake_enabled =3D false; + } mutex_unlock(&phydev->irq_pm_lock); } EXPORT_SYMBOL(phy_free_interrupt); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8bc394ff7d2d..082ae31c2234 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -372,11 +373,41 @@ static __maybe_unused void mdio_bus_phy_resume_irq(st= ruct phy_device *phydev) mutex_unlock(&phydev->irq_pm_lock); } =20 +static __maybe_unused int mdio_bus_phy_prepare(struct device *dev) +{ + struct phy_device *phydev =3D to_phy_device(dev); + + /* The MAC can suspend the PHY or power the MDIO bus down before our + * suspend callback runs, so we postpone interrupts from here on. + */ + if (phydev->mac_managed_pm) { + mdio_bus_phy_suspend_irq(phydev); + phydev->irq_prepared =3D true; + } + + return 0; +} + +static __maybe_unused void mdio_bus_phy_complete(struct device *dev) +{ + struct phy_device *phydev =3D to_phy_device(dev); + + /* The PM core skips our resume callback if the transition aborted + * before our suspend callback. + */ + if (phydev->irq_prepared) { + phydev->irq_prepared =3D false; + mdio_bus_phy_resume_irq(phydev); + } +} + static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) { struct phy_device *phydev =3D to_phy_device(dev); int ret; =20 + phydev->irq_prepared =3D false; + if (phydev->mac_managed_pm) return 0; =20 @@ -414,8 +445,10 @@ static __maybe_unused int mdio_bus_phy_resume(struct d= evice *dev) struct phy_device *phydev =3D to_phy_device(dev); int ret; =20 - if (phydev->mac_managed_pm) + if (phydev->mac_managed_pm) { + mdio_bus_phy_resume_irq(phydev); return 0; + } =20 if (!phydev->suspended_by_mdio_bus) goto no_resume; @@ -446,8 +479,48 @@ static __maybe_unused int mdio_bus_phy_resume(struct d= evice *dev) return 0; } =20 -static SIMPLE_DEV_PM_OPS(mdio_bus_phy_pm_ops, mdio_bus_phy_suspend, - mdio_bus_phy_resume); +static __maybe_unused int mdio_bus_phy_suspend_noirq(struct device *dev) +{ + struct phy_device *phydev =3D to_phy_device(dev); + struct irq_data *d; + + mutex_lock(&phydev->irq_pm_lock); + /* We enable the line a postponed interrupt disabled if the irq core + * armed it for wakeup, so that it wakes the system. + */ + if (phydev->irq_rerun) { + d =3D irq_get_irq_data(phydev->irq_rerun_line); + if (d && irqd_irq_disabled(d) && irqd_is_wakeup_armed(d)) { + enable_irq(phydev->irq_rerun_line); + phydev->irq_wake_enabled =3D true; + } + } + mutex_unlock(&phydev->irq_pm_lock); + + return 0; +} + +static __maybe_unused int mdio_bus_phy_resume_noirq(struct device *dev) +{ + struct phy_device *phydev =3D to_phy_device(dev); + + mutex_lock(&phydev->irq_pm_lock); + if (phydev->irq_wake_enabled) { + phydev->irq_wake_enabled =3D false; + disable_irq_nosync(phydev->irq_rerun_line); + } + mutex_unlock(&phydev->irq_pm_lock); + + return 0; +} + +static const struct dev_pm_ops mdio_bus_phy_pm_ops =3D { + .prepare =3D pm_sleep_ptr(mdio_bus_phy_prepare), + .complete =3D pm_sleep_ptr(mdio_bus_phy_complete), + SET_SYSTEM_SLEEP_PM_OPS(mdio_bus_phy_suspend, mdio_bus_phy_resume) + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mdio_bus_phy_suspend_noirq, + mdio_bus_phy_resume_noirq) +}; =20 /** * genphy_match_phy_device - match a PHY device with a PHY driver diff --git a/include/linux/phy.h b/include/linux/phy.h index 9253a07e84be..048f6b743099 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -649,10 +649,14 @@ struct phy_oatc14_sqi_capability { * @mdix_ctrl: User setting of crossover * @pma_extable: Cached value of PMA/PMD Extended Abilities Register * @interrupts: Flag interrupts have been enabled - * @irq_suspended: Flag indicating PHY is suspended and therefore interrupt - * handling shall be postponed until PHY has resumed + * @irq_suspended: Flag indicating a system sleep transition, so interrupt + * handling shall be postponed until the PHY has resumed * @irq_rerun: Set by the postponed interrupt that disabled the line * @irq_rerun_line: The line the postponed interrupt disabled + * @irq_wake_enabled: Set while @irq_rerun_line is enabled for the noirq + * phase, as it wakes the system + * @irq_prepared: Set for a PHY with MAC-managed PM from the prepare callb= ack + * until the suspend callback runs * @default_timestamp: Flag indicating whether we are using the phy * timestamp as the default one * @interface: enum phy_interface_t value @@ -676,8 +680,9 @@ struct phy_oatc14_sqi_capability { * @max_n_ports: Max number of ports this PHY can expose * @lock: Mutex for serialization access to PHY * @irq_pm_lock: Held by the PM callbacks, and by the requesting and freei= ng - * of the interrupt where they test and clear @irq_rerun; - * taken before @lock; phy_interrupt() never takes it + * of the interrupt where they test and clear @irq_rerun and + * @irq_wake_enabled; taken before @lock; phy_interrupt() + * never takes it * @state_queue: Work queue for state machine * @link_down_events: Number of times link was lost * @shared: Pointer to private data shared by phys in one package @@ -735,6 +740,8 @@ struct phy_device { bool irq_suspended; bool irq_rerun; int irq_rerun_line; + bool irq_wake_enabled; + bool irq_prepared; =20 unsigned default_timestamp:1; =20 @@ -813,7 +820,7 @@ struct phy_device { =20 struct mutex lock; /* Held where the PM callbacks and the requesting and freeing of the - * interrupt test and clear irq_rerun + * interrupt test and clear irq_rerun and irq_wake_enabled */ struct mutex irq_pm_lock; =20 --=20 2.43.0