Skip to contentSkip to conversation

Patch: Make linkwatch more robust against rtnl holders

PATCH Stefan Rompf 3 participants 4 messages Feb 15, 2004 – Feb 20, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi David,

the attached patch updates the linkwatch code so that it backs off and retries whenever it cannot get the rtnl semaphore.

This makes it more robust against unrelated processes calling flush_scheduled_work() while holding the rtnl lock. This problem was reported on netdev for the sungem driver.

I preferred rescheduling every 1/10 second against creating a kernel thread as the code is shorter, and the situation should not happen anyway.

Stefan

core/link_watch.c renamed from core/link_watch.c.old +9 -2
@@ -84,6 +84,8 @@
 
 static void linkwatch_event(void *dummy)
 {
+	if (rtnl_shlock_nowait()) goto out_err1;
+	if (rtnl_exlock_nowait()) goto out_err2;
 	/* Limit the number of linkwatch events to one
 	 * per second so that a runaway driver does not
 	 * cause a storm of messages on the netlink
@@ -92,11 +94,16 @@
 	linkwatch_nextevent = jiffies + HZ;
 	clear_bit(LW_RUNNING, &linkwatch_flags);
 
-	rtnl_shlock();
-	rtnl_exlock();
 	linkwatch_run_queue();
 	rtnl_exunlock();
 	rtnl_shunlock();
+
+	return;
+
+out_err2:
+	rtnl_shunlock();
+out_err1:
+	schedule_delayed_work(&linkwatch_work, HZ / 10);
 }
 
 
#1 lore raw
Quoted 2 lines · On Sun, 15 Feb 2004 15:11:47 +0100 Stefan Rompf <[email protected]> wrote:

the attached patch updates the linkwatch code so that it backs off and retries whenever it cannot get the rtnl semaphore.

I think we should fix locking conflicts created by things like what the sungem driver is doing instead.

#2 lore raw
Quoted 9 lines · David S. Miller
Quoted 1 line · On Sun, 15 Feb 2004 15:11:47 +0100 Stefan Rompf <[email protected]> wrote:

the attached patch updates the linkwatch code so that it backs off and retries whenever it cannot get the rtnl semaphore.

I think we should fix locking conflicts created by things like what the sungem driver is doing instead.

Agreed.

Jeff

#3 lore raw
In reply to David S. Miller

Hi David,

Quoted 5 lines
Quoted 2 lines

the attached patch updates the linkwatch code so that it backs off and retries whenever it cannot get the rtnl semaphore.

I think we should fix locking conflicts created by things like what the sungem driver is doing instead.

On the other hand, I'm not aware of any convention when flush_scheduled_work() is allowed to be called. As long as anyone inside kernel space is can schedule work and anyone else can wait for completion, it does not hurt to make a schedule task less vulnerable to deadlocks.

Stefan