* [PATCH] team: avoid race condition in scheduling delayed work
@ 2014-10-03 13:58 Joe Lawrence
2014-10-05 0:51 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Joe Lawrence @ 2014-10-03 13:58 UTC (permalink / raw)
To: netdev; +Cc: Jiri Pirko, Joe Lawrence
When team_notify_peers and team_mcast_rejoin are called, they both reset
their respective .count_pending atomic variable. Then when the actual
worker function is executed, the variable is atomically decremented.
This pattern introduces a potential race condition where the
.count_pending rolls over and the worker function keeps rescheduling
until .count_pending decrements to zero again:
THREAD 1 THREAD 2
======== ========
team_notify_peers(teamX)
atomic_set count_pending = 1
schedule_delayed_work
team_notify_peers(teamX)
atomic_set count_pending = 1
team_notify_peers_work
atomic_dec_and_test
count_pending = 0
(return)
schedule_delayed_work
team_notify_peers_work
atomic_dec_and_test
count_pending = -1
schedule_delayed_work
(repeat until count_pending = 0)
Instead of assigning a new value to .count_pending, use atomic_add to
tack-on the additional desired worker function invocations.
Signed-off-by: Joe Lawrence <joe.lawrence@stratus.com>
Acked-by: Jiri Pirko <jiri@resnulli.us>
Fixes: fc423ff00df3a19554414ee ("team: add peer notification")
Fixes: 492b200efdd20b8fcfdac87 ("team: add support for sending multicast rejoins")
---
drivers/net/team/team.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index d46df38..2b87e3f 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -647,7 +647,7 @@ static void team_notify_peers(struct team *team)
{
if (!team->notify_peers.count || !netif_running(team->dev))
return;
- atomic_set(&team->notify_peers.count_pending, team->notify_peers.count);
+ atomic_add(team->notify_peers.count, &team->notify_peers.count_pending);
schedule_delayed_work(&team->notify_peers.dw, 0);
}
@@ -687,7 +687,7 @@ static void team_mcast_rejoin(struct team *team)
{
if (!team->mcast_rejoin.count || !netif_running(team->dev))
return;
- atomic_set(&team->mcast_rejoin.count_pending, team->mcast_rejoin.count);
+ atomic_add(team->mcast_rejoin.count, &team->mcast_rejoin.count_pending);
schedule_delayed_work(&team->mcast_rejoin.dw, 0);
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] team: avoid race condition in scheduling delayed work
2014-10-03 13:58 [PATCH] team: avoid race condition in scheduling delayed work Joe Lawrence
@ 2014-10-05 0:51 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-10-05 0:51 UTC (permalink / raw)
To: joe.lawrence; +Cc: netdev, jiri
From: Joe Lawrence <joe.lawrence@stratus.com>
Date: Fri, 3 Oct 2014 09:58:34 -0400
> When team_notify_peers and team_mcast_rejoin are called, they both reset
> their respective .count_pending atomic variable. Then when the actual
> worker function is executed, the variable is atomically decremented.
> This pattern introduces a potential race condition where the
> .count_pending rolls over and the worker function keeps rescheduling
> until .count_pending decrements to zero again:
...
> Instead of assigning a new value to .count_pending, use atomic_add to
> tack-on the additional desired worker function invocations.
>
> Signed-off-by: Joe Lawrence <joe.lawrence@stratus.com>
> Acked-by: Jiri Pirko <jiri@resnulli.us>
> Fixes: fc423ff00df3a19554414ee ("team: add peer notification")
> Fixes: 492b200efdd20b8fcfdac87 ("team: add support for sending multicast rejoins")
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-05 0:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-03 13:58 [PATCH] team: avoid race condition in scheduling delayed work Joe Lawrence
2014-10-05 0:51 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).