diff options
author | Eric Dumazet <edumazet@google.com> | 2015-03-16 10:14:34 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-16 16:32:23 -0400 |
commit | 9f1ab18672bee992b6169bbfa2b5ae86b42e88a8 (patch) | |
tree | eb41d9d508745c09bde7dd2b56dc83f6c9d0b0d6 /net/ipv4/tcp_metrics.c | |
parent | bd76a116707bd2381da36cf7c3183df11293f1d6 (diff) |
tcp_metrics: fix wrong lockdep annotations
Changes in tcp_metric hash table are protected by tcp_metrics_lock
only, not by genl_mutex
While we are at it use deref_locked() instead of rcu_dereference()
in tcp_new() to avoid unnecessary barrier, as we hold tcp_metrics_lock
as well.
Reported-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Fixes: 098a697b497e ("tcp_metrics: Use a single hash table for all network namespaces.")
Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_metrics.c')
-rw-r--r-- | net/ipv4/tcp_metrics.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/net/ipv4/tcp_metrics.c b/net/ipv4/tcp_metrics.c index 366728cbee4a..5bef3513af77 100644 --- a/net/ipv4/tcp_metrics.c +++ b/net/ipv4/tcp_metrics.c | |||
@@ -152,6 +152,9 @@ static void tcpm_check_stamp(struct tcp_metrics_block *tm, struct dst_entry *dst | |||
152 | #define TCP_METRICS_RECLAIM_DEPTH 5 | 152 | #define TCP_METRICS_RECLAIM_DEPTH 5 |
153 | #define TCP_METRICS_RECLAIM_PTR (struct tcp_metrics_block *) 0x1UL | 153 | #define TCP_METRICS_RECLAIM_PTR (struct tcp_metrics_block *) 0x1UL |
154 | 154 | ||
155 | #define deref_locked(p) \ | ||
156 | rcu_dereference_protected(p, lockdep_is_held(&tcp_metrics_lock)) | ||
157 | |||
155 | static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, | 158 | static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, |
156 | struct inetpeer_addr *saddr, | 159 | struct inetpeer_addr *saddr, |
157 | struct inetpeer_addr *daddr, | 160 | struct inetpeer_addr *daddr, |
@@ -180,9 +183,9 @@ static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, | |||
180 | if (unlikely(reclaim)) { | 183 | if (unlikely(reclaim)) { |
181 | struct tcp_metrics_block *oldest; | 184 | struct tcp_metrics_block *oldest; |
182 | 185 | ||
183 | oldest = rcu_dereference(tcp_metrics_hash[hash].chain); | 186 | oldest = deref_locked(tcp_metrics_hash[hash].chain); |
184 | for (tm = rcu_dereference(oldest->tcpm_next); tm; | 187 | for (tm = deref_locked(oldest->tcpm_next); tm; |
185 | tm = rcu_dereference(tm->tcpm_next)) { | 188 | tm = deref_locked(tm->tcpm_next)) { |
186 | if (time_before(tm->tcpm_stamp, oldest->tcpm_stamp)) | 189 | if (time_before(tm->tcpm_stamp, oldest->tcpm_stamp)) |
187 | oldest = tm; | 190 | oldest = tm; |
188 | } | 191 | } |
@@ -1040,12 +1043,6 @@ out_free: | |||
1040 | return ret; | 1043 | return ret; |
1041 | } | 1044 | } |
1042 | 1045 | ||
1043 | #define deref_locked_genl(p) \ | ||
1044 | rcu_dereference_protected(p, lockdep_genl_is_held() && \ | ||
1045 | lockdep_is_held(&tcp_metrics_lock)) | ||
1046 | |||
1047 | #define deref_genl(p) rcu_dereference_protected(p, lockdep_genl_is_held()) | ||
1048 | |||
1049 | static void tcp_metrics_flush_all(struct net *net) | 1046 | static void tcp_metrics_flush_all(struct net *net) |
1050 | { | 1047 | { |
1051 | unsigned int max_rows = 1U << tcp_metrics_hash_log; | 1048 | unsigned int max_rows = 1U << tcp_metrics_hash_log; |
@@ -1057,8 +1054,7 @@ static void tcp_metrics_flush_all(struct net *net) | |||
1057 | struct tcp_metrics_block __rcu **pp; | 1054 | struct tcp_metrics_block __rcu **pp; |
1058 | spin_lock_bh(&tcp_metrics_lock); | 1055 | spin_lock_bh(&tcp_metrics_lock); |
1059 | pp = &hb->chain; | 1056 | pp = &hb->chain; |
1060 | for (tm = deref_locked_genl(*pp); tm; | 1057 | for (tm = deref_locked(*pp); tm; tm = deref_locked(*pp)) { |
1061 | tm = deref_locked_genl(*pp)) { | ||
1062 | if (net_eq(tm_net(tm), net)) { | 1058 | if (net_eq(tm_net(tm), net)) { |
1063 | *pp = tm->tcpm_next; | 1059 | *pp = tm->tcpm_next; |
1064 | kfree_rcu(tm, rcu_head); | 1060 | kfree_rcu(tm, rcu_head); |
@@ -1097,7 +1093,7 @@ static int tcp_metrics_nl_cmd_del(struct sk_buff *skb, struct genl_info *info) | |||
1097 | hb = tcp_metrics_hash + hash; | 1093 | hb = tcp_metrics_hash + hash; |
1098 | pp = &hb->chain; | 1094 | pp = &hb->chain; |
1099 | spin_lock_bh(&tcp_metrics_lock); | 1095 | spin_lock_bh(&tcp_metrics_lock); |
1100 | for (tm = deref_locked_genl(*pp); tm; tm = deref_locked_genl(*pp)) { | 1096 | for (tm = deref_locked(*pp); tm; tm = deref_locked(*pp)) { |
1101 | if (addr_same(&tm->tcpm_daddr, &daddr) && | 1097 | if (addr_same(&tm->tcpm_daddr, &daddr) && |
1102 | (!src || addr_same(&tm->tcpm_saddr, &saddr)) && | 1098 | (!src || addr_same(&tm->tcpm_saddr, &saddr)) && |
1103 | net_eq(tm_net(tm), net)) { | 1099 | net_eq(tm_net(tm), net)) { |