Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: tulip: use mod_timer() in t21142_lnk_change()
@ 2026-09-04 12:36 Magnus Lindholm
  2026-09-05 14:07 ` Francois Romieu
  0 siblings, 1 reply; 3+ messages in thread
From: Magnus Lindholm @ 2026-09-04 12:36 UTC (permalink / raw)
  To: andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-parisc, linux-kernel, linux-alpha, Magnus Lindholm,
	stable

t21142_lnk_change() is called from tulip_interrupt(), i.e. in hardirq
context. On a link-fail or NWay renegotiation event it calls
timer_delete_sync(&tp->timer) before rescheduling the timer, which is
exactly what

  WARN_ON(in_hardirq() && !(timer->flags & TIMER_IRQSAFE));

in __timer_delete_sync() exists to catch, since tp->timer is not
TIMER_IRQSAFE:

  WARNING: kernel/time/timer.c:1611 at __timer_delete_sync+0x13c/0x150
  ...
  [<...>] t21142_lnk_change+...
  [<...>] tulip_interrupt+...

This isn't teardown, it's just rescheduling the media timer, which is
exactly what mod_timer() is for. mod_timer(timer, expires) is
documented as equivalent to timer_delete(); timer->expires = expires;
add_timer(), and as the only safe way to change the timeout when a
timer has multiple unserialized concurrent users. That is the case
here: t21142_media_task(), scheduled by this same timer's callback,
already ends with its own mod_timer() call on tp->timer, with a
comment noting it synchronizes against add_timer() calls from
interrupts. Using mod_timer() in t21142_lnk_change() as well, instead
of an unprotected timer_delete()+add_timer() pair, matches that
existing concurrency model instead of racing against it.

Update the comment in tulip_interrupt() accordingly. pnic2_lnk_change()
still calls timer_delete_sync() from the same hardirq path, but its timer
callback re-arms the timer directly with mod_timer(), so fixing that path
requires separate consideration of the callback/reschedule race.

The warning was reproduced during a link-state change at boot on an
Alpha UP2000+ running v7.3-rc1 with:

  0001:02:08.0 Ethernet controller: Digital Equipment Corporation
  DECchip 21142/43 (rev 30)

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 drivers/net/ethernet/dec/tulip/21142.c     | 8 ++------
 drivers/net/ethernet/dec/tulip/interrupt.c | 5 ++---
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/dec/tulip/21142.c b/drivers/net/ethernet/dec/tulip/21142.c
index 76767dec216d..da701f325783 100644
--- a/drivers/net/ethernet/dec/tulip/21142.c
+++ b/drivers/net/ethernet/dec/tulip/21142.c
@@ -216,20 +216,16 @@ void t21142_lnk_change(struct net_device *dev, int csr5)
 		    (csr12 & 2) == 2) ||
 		   (tp->nway && (csr5 & (TPLnkFail)))) {
 		/* Link blew? Maybe restart NWay. */
-		timer_delete_sync(&tp->timer);
 		t21142_start_nway(dev);
-		tp->timer.expires = RUN_AT(3*HZ);
-		add_timer(&tp->timer);
+		mod_timer(&tp->timer, RUN_AT(3 * HZ));
 	} else if (dev->if_port == 3  ||  dev->if_port == 5) {
 		if (tulip_debug > 1)
 			dev_info(&dev->dev, "21143 %s link beat %s\n",
 				 medianame[dev->if_port],
 				 (csr12 & 2) ? "failed" : "good");
 		if ((csr12 & 2)  &&  ! tp->medialock) {
-			timer_delete_sync(&tp->timer);
 			t21142_start_nway(dev);
-			tp->timer.expires = RUN_AT(3*HZ);
-			add_timer(&tp->timer);
+			mod_timer(&tp->timer, RUN_AT(3 * HZ));
 		} else if (dev->if_port == 5)
 			iowrite32(csr14 & ~0x080, ioaddr + CSR14);
 	} else if (dev->if_port == 0  ||  dev->if_port == 4) {
diff --git a/drivers/net/ethernet/dec/tulip/interrupt.c b/drivers/net/ethernet/dec/tulip/interrupt.c
index 0a12cb9b3ba7..6ed4b68ad86c 100644
--- a/drivers/net/ethernet/dec/tulip/interrupt.c
+++ b/drivers/net/ethernet/dec/tulip/interrupt.c
@@ -698,9 +698,8 @@ irqreturn_t tulip_interrupt(int irq, void *dev_instance)
 				dev->stats.rx_errors++;
 				tulip_start_rxtx(tp);
 			}
-			/*
-			 * NB: t21142_lnk_change() does a timer_delete_sync(), so be careful
-			 * if this call is ever done under the spinlock
+			/* NB: pnic2_lnk_change() does a timer_delete_sync(), so be careful
+			 * if this call is ever done under the spinlock.
 			 */
 			if (csr5 & (TPLnkPass | TPLnkFail | 0x08000000)) {
 				if (tp->link_change)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: tulip: use mod_timer() in t21142_lnk_change()
  2026-09-04 12:36 [PATCH] net: tulip: use mod_timer() in t21142_lnk_change() Magnus Lindholm
@ 2026-09-05 14:07 ` Francois Romieu
  2026-09-05 19:25   ` Magnus Lindholm
  0 siblings, 1 reply; 3+ messages in thread
From: Francois Romieu @ 2026-09-05 14:07 UTC (permalink / raw)
  To: Magnus Lindholm
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-parisc, linux-kernel, linux-alpha, stable

Magnus Lindholm <linmag7@gmail.com> :
> t21142_lnk_change() is called from tulip_interrupt(), i.e. in hardirq
> context. On a link-fail or NWay renegotiation event it calls
> timer_delete_sync(&tp->timer) before rescheduling the timer, which is
> exactly what
> 
>   WARN_ON(in_hardirq() && !(timer->flags & TIMER_IRQSAFE));
> 
> in __timer_delete_sync() exists to catch, since tp->timer is not
> TIMER_IRQSAFE:
> 
>   WARNING: kernel/time/timer.c:1611 at __timer_delete_sync+0x13c/0x150
>   ...
>   [<...>] t21142_lnk_change+...
>   [<...>] tulip_interrupt+...
> 
> This isn't teardown, it's just rescheduling the media timer, which is
> exactly what mod_timer() is for. mod_timer(timer, expires) is
> documented as equivalent to timer_delete(); timer->expires = expires;
> add_timer(), and as the only safe way to change the timeout when a
> timer has multiple unserialized concurrent users. That is the case
> here: t21142_media_task(), scheduled by this same timer's callback,
> already ends with its own mod_timer() call on tp->timer, with a
> comment noting it synchronizes against add_timer() calls from
> interrupts. Using mod_timer() in t21142_lnk_change() as well, instead
> of an unprotected timer_delete()+add_timer() pair, matches that
> existing concurrency model instead of racing against it.
> 
> Update the comment in tulip_interrupt() accordingly. pnic2_lnk_change()
> still calls timer_delete_sync() from the same hardirq path, but its timer
> callback re-arms the timer directly with mod_timer(), so fixing that path
> requires separate consideration of the callback/reschedule race.
> 
> The warning was reproduced during a link-state change at boot on an
> Alpha UP2000+ running v7.3-rc1 with:
> 
>   0001:02:08.0 Ethernet controller: Digital Equipment Corporation
>   DECchip 21142/43 (rev 30)
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
> ---

The current code may avoid concurrent run (#1) of t21142_start_nway and
t21142_media_task. It may also deadlock (#2) as you have noticed.

As far as I understand the code, current users - if any - may experience
#1 (avoid concurrent run) or #2 (deadlock) alone as well as #1 and #2

Users of modified code won't experience #2 but they may fail more often
at #1.

It may deserve a minor comment explaining either the choice or why it is
not an issue.

-- 
Ueimor

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: tulip: use mod_timer() in t21142_lnk_change()
  2026-09-05 14:07 ` Francois Romieu
@ 2026-09-05 19:25   ` Magnus Lindholm
  0 siblings, 0 replies; 3+ messages in thread
From: Magnus Lindholm @ 2026-09-05 19:25 UTC (permalink / raw)
  To: Francois Romieu
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
	linux-parisc, linux-kernel, linux-alpha, stable

Hi Francois,

On Sat, Sep 5, 2026 at 4:08 PM Francois Romieu <romieu@fr.zoreil.com> wrote:

>
> The current code may avoid concurrent run (#1) of t21142_start_nway and
> t21142_media_task. It may also deadlock (#2) as you have noticed.
>
> As far as I understand the code, current users - if any - may experience
> #1 (avoid concurrent run) or #2 (deadlock) alone as well as #1 and #2
>
> Users of modified code won't experience #2 but they may fail more often
> at #1.
>
> It may deserve a minor comment explaining either the choice or why it is
> not an issue.
>

Thanks for catching that, you're right that swapping to mod_timer()
alone loses the pending-timer protection timer_delete_sync() gave for
free. I'll put out a v2 reorders to mod_timer() before
t21142_start_nway(), which
should restore it for the pending case; I don't think anything short
of cancel_work_sync() on media_work covers the already-queued case,
which the old code didn't either.

Magnus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-05 19:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 12:36 [PATCH] net: tulip: use mod_timer() in t21142_lnk_change() Magnus Lindholm
2026-09-05 14:07 ` Francois Romieu
2026-09-05 19:25   ` Magnus Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox