aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp_metrics.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/tcp_metrics.c')
-rw-r--r--net/ipv4/tcp_metrics.c20
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
155static struct tcp_metrics_block *tcpm_new(struct dst_entry *dst, 158static 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
1049static void tcp_metrics_flush_all(struct net *net) 1046static 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)) {