tipc: introduce new spinlock to protect struct link_req
authorYing Xue <ying.xue@windriver.com>
Tue, 7 Jan 2014 22:02:43 +0000 (17:02 -0500)
committerDavid S. Miller <davem@davemloft.net>
Tue, 7 Jan 2014 23:44:25 +0000 (18:44 -0500)
commitf9a2c80b8b7366748a1c3975df07f4a34aa80538
tree9c3c627d0feeedd82eb8cad56e90657a3fe0f3a0
parentb9d4c33935bb5673fa9f721ecf85e5029c847f08
tipc: introduce new spinlock to protect struct link_req

Currently, only 'bearer_lock' is used to protect struct link_req in
the function disc_timeout(). This is unsafe, since the member fields
'num_nodes' and 'timer_intv' might be accessed by below three different
threads simultaneously, none of them grabbing bearer_lock in the
critical region:

link_activate()
  tipc_bearer_add_dest()
    tipc_disc_add_dest()
      req->num_nodes++;

tipc_link_reset()
  tipc_bearer_remove_dest()
    tipc_disc_remove_dest()
      req->num_nodes--
      disc_update()
        read req->num_nodes
write req->timer_intv

disc_timeout()
  read req->num_nodes
  read/write req->timer_intv

Without lock protection, the only symptom of a race is that discovery
messages occasionally may not be sent out. This is not fatal, since such
messages are best-effort anyway. On the other hand, since discovery
messages are not time critical, adding a protecting lock brings no
serious overhead either. So we add a new, dedicated spinlock in
order to guarantee absolute data consistency in link_req objects.
This also helps reduce the overall role of the bearer_lock, which
we want to remove completely in a later commit series.

Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tipc/discover.c