diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2010-02-22 20:04:49 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-02-25 03:41:03 -0500 |
commit | a898def29e4119bc01ebe7ca97423181f4c0ea2d (patch) | |
tree | e6f89d4f4a91fd24507ad600ebb9ad620ec9d9a8 /net/core | |
parent | 3120438ad68601f341e61e7cb1323b0e1a6ca367 (diff) |
net: Add checking to rcu_dereference() primitives
Update rcu_dereference() primitives to use new lockdep-based
checking. The rcu_dereference() in __in6_dev_get() may be
protected either by rcu_read_lock() or RTNL, per Eric Dumazet.
The rcu_dereference() in __sk_free() is protected by the fact
that it is never reached if an update could change it. Check
for this by using rcu_dereference_check() to verify that the
struct sock's ->sk_wmem_alloc counter is zero.
Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: laijs@cn.fujitsu.com
Cc: dipankar@in.ibm.com
Cc: mathieu.desnoyers@polymtl.ca
Cc: josh@joshtriplett.org
Cc: dvhltc@us.ibm.com
Cc: niv@us.ibm.com
Cc: peterz@infradead.org
Cc: rostedt@goodmis.org
Cc: Valdis.Kletnieks@vt.edu
Cc: dhowells@redhat.com
LKML-Reference: <1266887105-1528-5-git-send-email-paulmck@linux.vnet.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/dev.c | 2 | ||||
-rw-r--r-- | net/core/filter.c | 6 | ||||
-rw-r--r-- | net/core/rtnetlink.c | 8 | ||||
-rw-r--r-- | net/core/sock.c | 3 |
4 files changed, 14 insertions, 5 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index ec874218b206..bb1f1da2b8a7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -2041,7 +2041,7 @@ gso: | |||
2041 | rcu_read_lock_bh(); | 2041 | rcu_read_lock_bh(); |
2042 | 2042 | ||
2043 | txq = dev_pick_tx(dev, skb); | 2043 | txq = dev_pick_tx(dev, skb); |
2044 | q = rcu_dereference(txq->qdisc); | 2044 | q = rcu_dereference_bh(txq->qdisc); |
2045 | 2045 | ||
2046 | #ifdef CONFIG_NET_CLS_ACT | 2046 | #ifdef CONFIG_NET_CLS_ACT |
2047 | skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); | 2047 | skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); |
diff --git a/net/core/filter.c b/net/core/filter.c index 08db7b9143a3..3541aa48d21d 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
@@ -86,7 +86,7 @@ int sk_filter(struct sock *sk, struct sk_buff *skb) | |||
86 | return err; | 86 | return err; |
87 | 87 | ||
88 | rcu_read_lock_bh(); | 88 | rcu_read_lock_bh(); |
89 | filter = rcu_dereference(sk->sk_filter); | 89 | filter = rcu_dereference_bh(sk->sk_filter); |
90 | if (filter) { | 90 | if (filter) { |
91 | unsigned int pkt_len = sk_run_filter(skb, filter->insns, | 91 | unsigned int pkt_len = sk_run_filter(skb, filter->insns, |
92 | filter->len); | 92 | filter->len); |
@@ -521,7 +521,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk) | |||
521 | } | 521 | } |
522 | 522 | ||
523 | rcu_read_lock_bh(); | 523 | rcu_read_lock_bh(); |
524 | old_fp = rcu_dereference(sk->sk_filter); | 524 | old_fp = rcu_dereference_bh(sk->sk_filter); |
525 | rcu_assign_pointer(sk->sk_filter, fp); | 525 | rcu_assign_pointer(sk->sk_filter, fp); |
526 | rcu_read_unlock_bh(); | 526 | rcu_read_unlock_bh(); |
527 | 527 | ||
@@ -536,7 +536,7 @@ int sk_detach_filter(struct sock *sk) | |||
536 | struct sk_filter *filter; | 536 | struct sk_filter *filter; |
537 | 537 | ||
538 | rcu_read_lock_bh(); | 538 | rcu_read_lock_bh(); |
539 | filter = rcu_dereference(sk->sk_filter); | 539 | filter = rcu_dereference_bh(sk->sk_filter); |
540 | if (filter) { | 540 | if (filter) { |
541 | rcu_assign_pointer(sk->sk_filter, NULL); | 541 | rcu_assign_pointer(sk->sk_filter, NULL); |
542 | sk_filter_delayed_uncharge(sk, filter); | 542 | sk_filter_delayed_uncharge(sk, filter); |
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 794bcb897ff0..4c7d3f635ba7 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c | |||
@@ -89,6 +89,14 @@ int rtnl_is_locked(void) | |||
89 | } | 89 | } |
90 | EXPORT_SYMBOL(rtnl_is_locked); | 90 | EXPORT_SYMBOL(rtnl_is_locked); |
91 | 91 | ||
92 | #ifdef CONFIG_PROVE_LOCKING | ||
93 | int lockdep_rtnl_is_held(void) | ||
94 | { | ||
95 | return lockdep_is_held(&rtnl_mutex); | ||
96 | } | ||
97 | EXPORT_SYMBOL(lockdep_rtnl_is_held); | ||
98 | #endif /* #ifdef CONFIG_PROVE_LOCKING */ | ||
99 | |||
92 | static struct rtnl_link *rtnl_msg_handlers[NPROTO]; | 100 | static struct rtnl_link *rtnl_msg_handlers[NPROTO]; |
93 | 101 | ||
94 | static inline int rtm_msgindex(int msgtype) | 102 | static inline int rtm_msgindex(int msgtype) |
diff --git a/net/core/sock.c b/net/core/sock.c index e1f6f225f012..305cba401ae6 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -1073,7 +1073,8 @@ static void __sk_free(struct sock *sk) | |||
1073 | if (sk->sk_destruct) | 1073 | if (sk->sk_destruct) |
1074 | sk->sk_destruct(sk); | 1074 | sk->sk_destruct(sk); |
1075 | 1075 | ||
1076 | filter = rcu_dereference(sk->sk_filter); | 1076 | filter = rcu_dereference_check(sk->sk_filter, |
1077 | atomic_read(&sk->sk_wmem_alloc) == 0); | ||
1077 | if (filter) { | 1078 | if (filter) { |
1078 | sk_filter_uncharge(sk, filter); | 1079 | sk_filter_uncharge(sk, filter); |
1079 | rcu_assign_pointer(sk->sk_filter, NULL); | 1080 | rcu_assign_pointer(sk->sk_filter, NULL); |