]> git.baikalelectronics.ru Git - kernel.git/commit
team: avoid race condition in scheduling delayed work
authorJoe Lawrence <Joe.Lawrence@stratus.com>
Fri, 3 Oct 2014 13:58:34 +0000 (09:58 -0400)
committerDavid S. Miller <davem@davemloft.net>
Sun, 5 Oct 2014 00:50:50 +0000 (20:50 -0400)
commita996c7dbe7df40dbe7656a9da5c82fd7df2e9077
tree28e33cbf979472878236ca81cd86771ae7ab9fa1
parentd509fa4321d03ee5b1a281df52317e940c520cdc
team: avoid race condition in scheduling delayed work

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: 05d961a5cebed21b5cad111 ("team: add peer notification")
Fixes: 4c74850fa685ec9904ee96e ("team: add support for sending multicast rejoins")
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/team/team.c