mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: iav@iav.lv
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, tglx@kernel.org, linux-pm@vger.kernel.org,
	maxime.chevallier@bootlin.com, lukas@wunner.de,
	rafael.j.wysocki@intel.com, wei.fang@nxp.com,
	niklas.soderlund@ragnatech.se, paul@pbarker.dev,
	florian.fainelli@broadcom.com, opendmb@gmail.com,
	Thangaraj.S@microchip.com, shenwei.wang@nxp.com,
	Haoning.CHENG@cn.bosch.com, willemb@google.com,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v9 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line
Date: Tue, 01 Dec 2026 07:30:46 +0000	[thread overview]
Message-ID: <179611024612.3146.9721290308822470504@kernel.org> (raw)
In-Reply-To: <20261130-b4-phylib-mac-pm-irq-v3-v9-2-7b9c3c9ac9f7@iav.lv>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 (2) · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Stale irq_rerun on a shared PHY interrupt line.

Pre-existing issues:
- [Medium] Concern: in mdio_bus_phy_suspend(), irq_suspended is set and
  phy_suspend()'s error is returned without undoing the postponing.
- [Medium] Concern: mdio_bus_phy_resume_irq() replays the postponed
  interrupt with irq_wake_thread().

--

net: phy: fix three paths that unbalance a postponed PHY interrupt line

With this patch, only the postponed phy_interrupt() run that sets irq_rerun
disables the line, and the patch records which line that run disabled.
phy_free_interrupt() and phy_request_interrupt() now clear irq_rerun when
the line has no users. The patch also adds irq_pm_lock and moves the
postpone and rerun logic into mdio_bus_phy_suspend_irq() and
mdio_bus_phy_resume_irq().

> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 9af303d60bd6b..b917238678928 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c

[ ... ]

> @@ -1430,8 +1430,12 @@ static irqreturn_t phy_interrupt(int irq, void *phy_dat)
>  				pm_wakeup_dev_event(parent, 0, true);
>  		}
>  
> -		phydev->irq_rerun = true;
> -		disable_irq_nosync(irq);
> +		/* Disable the line only once: an edge can rerun the thread. */
> +		if (!phydev->irq_rerun) {
> +			phydev->irq_rerun_line = irq;
> +			phydev->irq_rerun = true;
> +			disable_irq_nosync(irq);
> +		}
>  		return IRQ_HANDLED;
>  	}
>  
> @@ -1480,6 +1484,12 @@ void phy_request_interrupt(struct phy_device *phydev)
>  {
>  	int err;
>  
> +	/* 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 = false;
> +	mutex_unlock(&phydev->irq_pm_lock);
> +
>  	err = 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 (phydev->irq_rerun && !irq_has_action(phydev->irq_rerun_line))
> +		phydev->irq_rerun = false;
> +	mutex_unlock(&phydev->irq_pm_lock);
>  }
>  EXPORT_SYMBOL(phy_free_interrupt);

[Severity: Medium]
Can irq_rerun go stale on a shared line?

irq_rerun is a per-PHY bool, but the disable it stands for is counted in
the depth of the shared irq_desc. Both irq_has_action() checks run under
the per-PHY irq_pm_lock, and that lock does not serialize against the
other users of the line.

For example, take PHY A and user B sharing line L. A postpones an
interrupt, so L is at depth 1:

  A: phy_free_interrupt()
       free_irq()                   /* B still holds L */
       irq_has_action() == true     /* irq_rerun kept */
  B: free_irq()                     /* irq_shutdown() */
  B: request_irq()                  /* irq_startup(): desc->depth = 0 */
  A: phy_request_interrupt()
       irq_has_action() == true     /* irq_rerun kept */
       request_threaded_irq()

Two windows lead to the same state. One is between free_irq() and the
irq_has_action() check in phy_free_interrupt(). The other is between the
irq_has_action() check and request_threaded_irq() in
phy_request_interrupt().

>From then on, while A is still postponed, the new guard in phy_interrupt()
skips the disable:

	if (!phydev->irq_rerun) {
		...
		disable_irq_nosync(irq);
	}

Take a level-triggered PHY interrupt whose status cannot be read. The
handler returns IRQ_HANDLED, the ONESHOT completion unmasks the line, and
the interrupt fires again right away.

Would the IRQ thread then spin until mdio_bus_phy_resume_irq() runs? Before
this patch, every postponed run masked the line.

After that, mdio_bus_phy_resume_irq() calls
enable_irq(phydev->irq_rerun_line) unconditionally. Would that hit the
"Unbalanced enable for IRQ %d" WARN in __enable_irq(), or cancel a
disable_irq() that another driver on the line still holds?

The commit message lists these cases:

  "Three cases on a shared line stay unbalanced ... until then a postponed
  interrupt does not disable the line again, so a level-triggered one keeps
  firing."

However, the repeated firing of a level-triggered line comes from the new
guard in phy_interrupt(). The later patches in the series do not change
this code; they only add irq_requested and irq_wake_enabled handling.

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 1791d578f4dde..f2e2370b4be7c 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c

[ ... ]

> +/* 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 *phydev)
> +{
> +	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 = false;
> +		enable_irq(phydev->irq_rerun_line);
> +		if (phydev->irq == phydev->irq_rerun_line)
> +			irq_wake_thread(phydev->irq, phydev);

[Severity: Medium]
This is a pre-existing issue, but does irq_wake_thread() do anything on a
nested-threaded line, such as a PHY interrupt behind an I2C or SPI GPIO
expander? On such a line action->thread is NULL, so the postponed PHY event
would be lost. The old mdio_bus_phy_resume() used irq_wake_thread() the
same way.

This seems to be addressed later in the series by "net: phy: run a
postponed PHY interrupt handler directly on resume". That patch calls
phydev->drv->handle_interrupt() under phydev->lock instead.

> +	}
> +	mutex_unlock(&phydev->irq_pm_lock);
> +}

[ ... ]

> @@ -393,19 +419,7 @@ static __maybe_unused int mdio_bus_phy_resume(struct device *dev)
>  	if (ret < 0)
>  		return ret;
>  no_resume:

[Severity: Medium]
This isn't a bug introduced by this patch, but the early returns after a
phy_init_hw() or phy_resume() failure skip mdio_bus_phy_resume_irq(). Would
irq_suspended then stay set, along with the postponed line, including the
other users of a shared line, staying disabled?

mdio_bus_phy_suspend() has a similar path at this commit. It sets
irq_suspended through mdio_bus_phy_suspend_irq() and then returns the
result of phy_suspend() without undoing the postponing:

	phydev->suspended_by_mdio_bus = 1;

	return phy_suspend(phydev);

The suspend half is addressed later in the series by "net: phy: stop
postponing PHY interrupts when phy_suspend() fails". That patch calls
mdio_bus_phy_resume_irq() and phy_start_machine() on failure.

The same later commit keeps the resume error returns on purpose: "Undoing
the postponing there would run the handler, from the next interrupt on,
on a PHY that did not resume".

> -	if (phy_interrupt_is_valid(phydev)) {
> -		phydev->irq_suspended = 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 = false;
> -			enable_irq(phydev->irq);
> -			irq_wake_thread(phydev->irq, phydev);
> -		}
> -	}
> +	mdio_bus_phy_resume_irq(phydev);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-b4-phylib-mac-pm-irq-v3-v9-0-7b9c3c9ac9f7%40iav.lv

  reply	other threads:[~2026-12-01  7:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  7:04 [PATCH net v9 0/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-11-30  7:04 ` [PATCH net v9 1/5] net: phy: move irq_suspended and irq_rerun out of the bitfield Igor Velkov via B4 Relay
2026-11-30  7:04 ` [PATCH net v9 2/5] net: phy: fix three paths that unbalance a postponed PHY interrupt line Igor Velkov via B4 Relay
2026-12-01  7:30   ` netdev-bot+sashiko [this message]
2026-11-30  7:04 ` [PATCH net v9 3/5] net: phy: stop postponing PHY interrupts when phy_suspend() fails Igor Velkov via B4 Relay
2026-12-01  7:30   ` netdev-bot+sashiko
2026-11-30  7:04 ` [PATCH net v9 4/5] net: phy: run a postponed PHY interrupt handler directly on resume Igor Velkov via B4 Relay
2026-11-30  7:04 ` [PATCH net v9 5/5] net: phy: postpone PHY interrupts during sleep with MAC-managed PM Igor Velkov via B4 Relay
2026-12-01  7:30   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179611024612.3146.9721290308822470504@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Haoning.CHENG@cn.bosch.com \
    --cc=Thangaraj.S@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=hkallweit1@gmail.com \
    --cc=iav@iav.lv \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=lukas@wunner.de \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=paul@pbarker.dev \
    --cc=rafael.j.wysocki@intel.com \
    --cc=shenwei.wang@nxp.com \
    --cc=tglx@kernel.org \
    --cc=wei.fang@nxp.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®