diff options
author | Reshetova, Elena <elena.reshetova@intel.com> | 2017-06-30 06:08:01 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-07-01 10:39:08 -0400 |
commit | 41c6d650f6537e55a1b53438c646fbc3f49176bf (patch) | |
tree | d7fb3d5a2f1b3fb0fe76fa010141be563488d36b | |
parent | 14afee4b6092fde451ee17604e5f5c89da33e71e (diff) |
net: convert sock.sk_refcnt from atomic_t to refcount_t
refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
This patch uses refcount_inc_not_zero() instead of
atomic_inc_not_zero_hint() due to absense of a _hint()
version of refcount API. If the hint() version must
be used, we might need to revisit API.
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David Windsor <dwindsor@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
35 files changed, 70 insertions, 69 deletions
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c index 8af664f7d27c..be117495eb43 100644 --- a/crypto/algif_aead.c +++ b/crypto/algif_aead.c | |||
@@ -877,7 +877,7 @@ static void aead_sock_destruct(struct sock *sk) | |||
877 | unsigned int ivlen = crypto_aead_ivsize( | 877 | unsigned int ivlen = crypto_aead_ivsize( |
878 | crypto_aead_reqtfm(&ctx->aead_req)); | 878 | crypto_aead_reqtfm(&ctx->aead_req)); |
879 | 879 | ||
880 | WARN_ON(atomic_read(&sk->sk_refcnt) != 0); | 880 | WARN_ON(refcount_read(&sk->sk_refcnt) != 0); |
881 | aead_put_sgl(sk); | 881 | aead_put_sgl(sk); |
882 | sock_kzfree_s(sk, ctx->iv, ivlen); | 882 | sock_kzfree_s(sk, ctx->iv, ivlen); |
883 | sock_kfree_s(sk, ctx, ctx->len); | 883 | sock_kfree_s(sk, ctx, ctx->len); |
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 1178931288cb..b9e6e0e1f55c 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <net/tcp_states.h> | 32 | #include <net/tcp_states.h> |
33 | #include <net/netns/hash.h> | 33 | #include <net/netns/hash.h> |
34 | 34 | ||
35 | #include <linux/atomic.h> | 35 | #include <linux/refcount.h> |
36 | #include <asm/byteorder.h> | 36 | #include <asm/byteorder.h> |
37 | 37 | ||
38 | /* This is for all connections with a full identity, no wildcards. | 38 | /* This is for all connections with a full identity, no wildcards. |
@@ -334,7 +334,7 @@ static inline struct sock *inet_lookup(struct net *net, | |||
334 | sk = __inet_lookup(net, hashinfo, skb, doff, saddr, sport, daddr, | 334 | sk = __inet_lookup(net, hashinfo, skb, doff, saddr, sport, daddr, |
335 | dport, dif, &refcounted); | 335 | dport, dif, &refcounted); |
336 | 336 | ||
337 | if (sk && !refcounted && !atomic_inc_not_zero(&sk->sk_refcnt)) | 337 | if (sk && !refcounted && !refcount_inc_not_zero(&sk->sk_refcnt)) |
338 | sk = NULL; | 338 | sk = NULL; |
339 | return sk; | 339 | return sk; |
340 | } | 340 | } |
diff --git a/include/net/request_sock.h b/include/net/request_sock.h index 53ced67c4ae9..23e22054aa60 100644 --- a/include/net/request_sock.h +++ b/include/net/request_sock.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/spinlock.h> | 19 | #include <linux/spinlock.h> |
20 | #include <linux/types.h> | 20 | #include <linux/types.h> |
21 | #include <linux/bug.h> | 21 | #include <linux/bug.h> |
22 | #include <linux/refcount.h> | ||
22 | 23 | ||
23 | #include <net/sock.h> | 24 | #include <net/sock.h> |
24 | 25 | ||
@@ -89,7 +90,7 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener, | |||
89 | return NULL; | 90 | return NULL; |
90 | req->rsk_listener = NULL; | 91 | req->rsk_listener = NULL; |
91 | if (attach_listener) { | 92 | if (attach_listener) { |
92 | if (unlikely(!atomic_inc_not_zero(&sk_listener->sk_refcnt))) { | 93 | if (unlikely(!refcount_inc_not_zero(&sk_listener->sk_refcnt))) { |
93 | kmem_cache_free(ops->slab, req); | 94 | kmem_cache_free(ops->slab, req); |
94 | return NULL; | 95 | return NULL; |
95 | } | 96 | } |
@@ -100,7 +101,7 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener, | |||
100 | sk_node_init(&req_to_sk(req)->sk_node); | 101 | sk_node_init(&req_to_sk(req)->sk_node); |
101 | sk_tx_queue_clear(req_to_sk(req)); | 102 | sk_tx_queue_clear(req_to_sk(req)); |
102 | req->saved_syn = NULL; | 103 | req->saved_syn = NULL; |
103 | atomic_set(&req->rsk_refcnt, 0); | 104 | refcount_set(&req->rsk_refcnt, 0); |
104 | 105 | ||
105 | return req; | 106 | return req; |
106 | } | 107 | } |
@@ -108,7 +109,7 @@ reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener, | |||
108 | static inline void reqsk_free(struct request_sock *req) | 109 | static inline void reqsk_free(struct request_sock *req) |
109 | { | 110 | { |
110 | /* temporary debugging */ | 111 | /* temporary debugging */ |
111 | WARN_ON_ONCE(atomic_read(&req->rsk_refcnt) != 0); | 112 | WARN_ON_ONCE(refcount_read(&req->rsk_refcnt) != 0); |
112 | 113 | ||
113 | req->rsk_ops->destructor(req); | 114 | req->rsk_ops->destructor(req); |
114 | if (req->rsk_listener) | 115 | if (req->rsk_listener) |
@@ -119,7 +120,7 @@ static inline void reqsk_free(struct request_sock *req) | |||
119 | 120 | ||
120 | static inline void reqsk_put(struct request_sock *req) | 121 | static inline void reqsk_put(struct request_sock *req) |
121 | { | 122 | { |
122 | if (atomic_dec_and_test(&req->rsk_refcnt)) | 123 | if (refcount_dec_and_test(&req->rsk_refcnt)) |
123 | reqsk_free(req); | 124 | reqsk_free(req); |
124 | } | 125 | } |
125 | 126 | ||
diff --git a/include/net/sock.h b/include/net/sock.h index 5284e50fc81a..60200f4f4028 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -66,6 +66,7 @@ | |||
66 | #include <linux/poll.h> | 66 | #include <linux/poll.h> |
67 | 67 | ||
68 | #include <linux/atomic.h> | 68 | #include <linux/atomic.h> |
69 | #include <linux/refcount.h> | ||
69 | #include <net/dst.h> | 70 | #include <net/dst.h> |
70 | #include <net/checksum.h> | 71 | #include <net/checksum.h> |
71 | #include <net/tcp_states.h> | 72 | #include <net/tcp_states.h> |
@@ -219,7 +220,7 @@ struct sock_common { | |||
219 | u32 skc_tw_rcv_nxt; /* struct tcp_timewait_sock */ | 220 | u32 skc_tw_rcv_nxt; /* struct tcp_timewait_sock */ |
220 | }; | 221 | }; |
221 | 222 | ||
222 | atomic_t skc_refcnt; | 223 | refcount_t skc_refcnt; |
223 | /* private: */ | 224 | /* private: */ |
224 | int skc_dontcopy_end[0]; | 225 | int skc_dontcopy_end[0]; |
225 | union { | 226 | union { |
@@ -611,7 +612,7 @@ static inline bool __sk_del_node_init(struct sock *sk) | |||
611 | 612 | ||
612 | static __always_inline void sock_hold(struct sock *sk) | 613 | static __always_inline void sock_hold(struct sock *sk) |
613 | { | 614 | { |
614 | atomic_inc(&sk->sk_refcnt); | 615 | refcount_inc(&sk->sk_refcnt); |
615 | } | 616 | } |
616 | 617 | ||
617 | /* Ungrab socket in the context, which assumes that socket refcnt | 618 | /* Ungrab socket in the context, which assumes that socket refcnt |
@@ -619,7 +620,7 @@ static __always_inline void sock_hold(struct sock *sk) | |||
619 | */ | 620 | */ |
620 | static __always_inline void __sock_put(struct sock *sk) | 621 | static __always_inline void __sock_put(struct sock *sk) |
621 | { | 622 | { |
622 | atomic_dec(&sk->sk_refcnt); | 623 | refcount_dec(&sk->sk_refcnt); |
623 | } | 624 | } |
624 | 625 | ||
625 | static inline bool sk_del_node_init(struct sock *sk) | 626 | static inline bool sk_del_node_init(struct sock *sk) |
@@ -628,7 +629,7 @@ static inline bool sk_del_node_init(struct sock *sk) | |||
628 | 629 | ||
629 | if (rc) { | 630 | if (rc) { |
630 | /* paranoid for a while -acme */ | 631 | /* paranoid for a while -acme */ |
631 | WARN_ON(atomic_read(&sk->sk_refcnt) == 1); | 632 | WARN_ON(refcount_read(&sk->sk_refcnt) == 1); |
632 | __sock_put(sk); | 633 | __sock_put(sk); |
633 | } | 634 | } |
634 | return rc; | 635 | return rc; |
@@ -650,7 +651,7 @@ static inline bool sk_nulls_del_node_init_rcu(struct sock *sk) | |||
650 | 651 | ||
651 | if (rc) { | 652 | if (rc) { |
652 | /* paranoid for a while -acme */ | 653 | /* paranoid for a while -acme */ |
653 | WARN_ON(atomic_read(&sk->sk_refcnt) == 1); | 654 | WARN_ON(refcount_read(&sk->sk_refcnt) == 1); |
654 | __sock_put(sk); | 655 | __sock_put(sk); |
655 | } | 656 | } |
656 | return rc; | 657 | return rc; |
@@ -1144,9 +1145,9 @@ static inline void sk_refcnt_debug_dec(struct sock *sk) | |||
1144 | 1145 | ||
1145 | static inline void sk_refcnt_debug_release(const struct sock *sk) | 1146 | static inline void sk_refcnt_debug_release(const struct sock *sk) |
1146 | { | 1147 | { |
1147 | if (atomic_read(&sk->sk_refcnt) != 1) | 1148 | if (refcount_read(&sk->sk_refcnt) != 1) |
1148 | printk(KERN_DEBUG "Destruction of the %s socket %p delayed, refcnt=%d\n", | 1149 | printk(KERN_DEBUG "Destruction of the %s socket %p delayed, refcnt=%d\n", |
1149 | sk->sk_prot->name, sk, atomic_read(&sk->sk_refcnt)); | 1150 | sk->sk_prot->name, sk, refcount_read(&sk->sk_refcnt)); |
1150 | } | 1151 | } |
1151 | #else /* SOCK_REFCNT_DEBUG */ | 1152 | #else /* SOCK_REFCNT_DEBUG */ |
1152 | #define sk_refcnt_debug_inc(sk) do { } while (0) | 1153 | #define sk_refcnt_debug_inc(sk) do { } while (0) |
@@ -1636,7 +1637,7 @@ void sock_init_data(struct socket *sock, struct sock *sk); | |||
1636 | /* Ungrab socket and destroy it, if it was the last reference. */ | 1637 | /* Ungrab socket and destroy it, if it was the last reference. */ |
1637 | static inline void sock_put(struct sock *sk) | 1638 | static inline void sock_put(struct sock *sk) |
1638 | { | 1639 | { |
1639 | if (atomic_dec_and_test(&sk->sk_refcnt)) | 1640 | if (refcount_dec_and_test(&sk->sk_refcnt)) |
1640 | sk_free(sk); | 1641 | sk_free(sk); |
1641 | } | 1642 | } |
1642 | /* Generic version of sock_put(), dealing with all sockets | 1643 | /* Generic version of sock_put(), dealing with all sockets |
diff --git a/net/atm/proc.c b/net/atm/proc.c index bbb6461a4b7f..27c9c01c537d 100644 --- a/net/atm/proc.c +++ b/net/atm/proc.c | |||
@@ -211,7 +211,7 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc) | |||
211 | vcc->flags, sk->sk_err, | 211 | vcc->flags, sk->sk_err, |
212 | sk_wmem_alloc_get(sk), sk->sk_sndbuf, | 212 | sk_wmem_alloc_get(sk), sk->sk_sndbuf, |
213 | sk_rmem_alloc_get(sk), sk->sk_rcvbuf, | 213 | sk_rmem_alloc_get(sk), sk->sk_rcvbuf, |
214 | atomic_read(&sk->sk_refcnt)); | 214 | refcount_read(&sk->sk_refcnt)); |
215 | } | 215 | } |
216 | 216 | ||
217 | static void svc_info(struct seq_file *seq, struct atm_vcc *vcc) | 217 | static void svc_info(struct seq_file *seq, struct atm_vcc *vcc) |
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index 8a8f77a247e6..91e3ba280706 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c | |||
@@ -657,7 +657,7 @@ static int bt_seq_show(struct seq_file *seq, void *v) | |||
657 | seq_printf(seq, | 657 | seq_printf(seq, |
658 | "%pK %-6d %-6u %-6u %-6u %-6lu %-6lu", | 658 | "%pK %-6d %-6u %-6u %-6u %-6lu %-6lu", |
659 | sk, | 659 | sk, |
660 | atomic_read(&sk->sk_refcnt), | 660 | refcount_read(&sk->sk_refcnt), |
661 | sk_rmem_alloc_get(sk), | 661 | sk_rmem_alloc_get(sk), |
662 | sk_wmem_alloc_get(sk), | 662 | sk_wmem_alloc_get(sk), |
663 | from_kuid(seq_user_ns(seq), sock_i_uid(sk)), | 663 | from_kuid(seq_user_ns(seq), sock_i_uid(sk)), |
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index ac3c650cb234..2172ae509cf1 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c | |||
@@ -197,7 +197,7 @@ static void rfcomm_sock_kill(struct sock *sk) | |||
197 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) | 197 | if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) |
198 | return; | 198 | return; |
199 | 199 | ||
200 | BT_DBG("sk %p state %d refcnt %d", sk, sk->sk_state, atomic_read(&sk->sk_refcnt)); | 200 | BT_DBG("sk %p state %d refcnt %d", sk, sk->sk_state, refcount_read(&sk->sk_refcnt)); |
201 | 201 | ||
202 | /* Kill poor orphan */ | 202 | /* Kill poor orphan */ |
203 | bt_sock_unlink(&rfcomm_sk_list, sk); | 203 | bt_sock_unlink(&rfcomm_sk_list, sk); |
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c267713cd383..8b11341ed69a 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -3844,7 +3844,7 @@ struct sk_buff *skb_clone_sk(struct sk_buff *skb) | |||
3844 | struct sock *sk = skb->sk; | 3844 | struct sock *sk = skb->sk; |
3845 | struct sk_buff *clone; | 3845 | struct sk_buff *clone; |
3846 | 3846 | ||
3847 | if (!sk || !atomic_inc_not_zero(&sk->sk_refcnt)) | 3847 | if (!sk || !refcount_inc_not_zero(&sk->sk_refcnt)) |
3848 | return NULL; | 3848 | return NULL; |
3849 | 3849 | ||
3850 | clone = skb_clone(skb, GFP_ATOMIC); | 3850 | clone = skb_clone(skb, GFP_ATOMIC); |
@@ -3915,7 +3915,7 @@ void skb_complete_tx_timestamp(struct sk_buff *skb, | |||
3915 | /* Take a reference to prevent skb_orphan() from freeing the socket, | 3915 | /* Take a reference to prevent skb_orphan() from freeing the socket, |
3916 | * but only if the socket refcount is not zero. | 3916 | * but only if the socket refcount is not zero. |
3917 | */ | 3917 | */ |
3918 | if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) { | 3918 | if (likely(refcount_inc_not_zero(&sk->sk_refcnt))) { |
3919 | *skb_hwtstamps(skb) = *hwtstamps; | 3919 | *skb_hwtstamps(skb) = *hwtstamps; |
3920 | __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND, false); | 3920 | __skb_complete_tx_timestamp(skb, sk, SCM_TSTAMP_SND, false); |
3921 | sock_put(sk); | 3921 | sock_put(sk); |
@@ -3997,7 +3997,7 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked) | |||
3997 | /* Take a reference to prevent skb_orphan() from freeing the socket, | 3997 | /* Take a reference to prevent skb_orphan() from freeing the socket, |
3998 | * but only if the socket refcount is not zero. | 3998 | * but only if the socket refcount is not zero. |
3999 | */ | 3999 | */ |
4000 | if (likely(atomic_inc_not_zero(&sk->sk_refcnt))) { | 4000 | if (likely(refcount_inc_not_zero(&sk->sk_refcnt))) { |
4001 | err = sock_queue_err_skb(sk, skb); | 4001 | err = sock_queue_err_skb(sk, skb); |
4002 | sock_put(sk); | 4002 | sock_put(sk); |
4003 | } | 4003 | } |
diff --git a/net/core/sock.c b/net/core/sock.c index 0866d59489cb..ba0ef6a7dbaf 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -1708,7 +1708,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority) | |||
1708 | * (Documentation/RCU/rculist_nulls.txt for details) | 1708 | * (Documentation/RCU/rculist_nulls.txt for details) |
1709 | */ | 1709 | */ |
1710 | smp_wmb(); | 1710 | smp_wmb(); |
1711 | atomic_set(&newsk->sk_refcnt, 2); | 1711 | refcount_set(&newsk->sk_refcnt, 2); |
1712 | 1712 | ||
1713 | /* | 1713 | /* |
1714 | * Increment the counter in the same struct proto as the master | 1714 | * Increment the counter in the same struct proto as the master |
@@ -1851,7 +1851,7 @@ void skb_orphan_partial(struct sk_buff *skb) | |||
1851 | ) { | 1851 | ) { |
1852 | struct sock *sk = skb->sk; | 1852 | struct sock *sk = skb->sk; |
1853 | 1853 | ||
1854 | if (atomic_inc_not_zero(&sk->sk_refcnt)) { | 1854 | if (refcount_inc_not_zero(&sk->sk_refcnt)) { |
1855 | WARN_ON(refcount_sub_and_test(skb->truesize, &sk->sk_wmem_alloc)); | 1855 | WARN_ON(refcount_sub_and_test(skb->truesize, &sk->sk_wmem_alloc)); |
1856 | skb->destructor = sock_efree; | 1856 | skb->destructor = sock_efree; |
1857 | } | 1857 | } |
@@ -2687,7 +2687,7 @@ void sock_init_data(struct socket *sock, struct sock *sk) | |||
2687 | * (Documentation/RCU/rculist_nulls.txt for details) | 2687 | * (Documentation/RCU/rculist_nulls.txt for details) |
2688 | */ | 2688 | */ |
2689 | smp_wmb(); | 2689 | smp_wmb(); |
2690 | atomic_set(&sk->sk_refcnt, 1); | 2690 | refcount_set(&sk->sk_refcnt, 1); |
2691 | atomic_set(&sk->sk_drops, 0); | 2691 | atomic_set(&sk->sk_drops, 0); |
2692 | } | 2692 | } |
2693 | EXPORT_SYMBOL(sock_init_data); | 2693 | EXPORT_SYMBOL(sock_init_data); |
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index a3fa1a5b6d98..4089c013cb03 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c | |||
@@ -756,7 +756,7 @@ static void reqsk_queue_hash_req(struct request_sock *req, | |||
756 | * are committed to memory and refcnt initialized. | 756 | * are committed to memory and refcnt initialized. |
757 | */ | 757 | */ |
758 | smp_wmb(); | 758 | smp_wmb(); |
759 | atomic_set(&req->rsk_refcnt, 2 + 1); | 759 | refcount_set(&req->rsk_refcnt, 2 + 1); |
760 | } | 760 | } |
761 | 761 | ||
762 | void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, | 762 | void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req, |
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index e9a59d2d91d4..a4be2c1cb688 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c | |||
@@ -246,7 +246,7 @@ EXPORT_SYMBOL_GPL(__inet_lookup_listener); | |||
246 | /* All sockets share common refcount, but have different destructors */ | 246 | /* All sockets share common refcount, but have different destructors */ |
247 | void sock_gen_put(struct sock *sk) | 247 | void sock_gen_put(struct sock *sk) |
248 | { | 248 | { |
249 | if (!atomic_dec_and_test(&sk->sk_refcnt)) | 249 | if (!refcount_dec_and_test(&sk->sk_refcnt)) |
250 | return; | 250 | return; |
251 | 251 | ||
252 | if (sk->sk_state == TCP_TIME_WAIT) | 252 | if (sk->sk_state == TCP_TIME_WAIT) |
@@ -287,7 +287,7 @@ begin: | |||
287 | continue; | 287 | continue; |
288 | if (likely(INET_MATCH(sk, net, acookie, | 288 | if (likely(INET_MATCH(sk, net, acookie, |
289 | saddr, daddr, ports, dif))) { | 289 | saddr, daddr, ports, dif))) { |
290 | if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt))) | 290 | if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) |
291 | goto out; | 291 | goto out; |
292 | if (unlikely(!INET_MATCH(sk, net, acookie, | 292 | if (unlikely(!INET_MATCH(sk, net, acookie, |
293 | saddr, daddr, ports, dif))) { | 293 | saddr, daddr, ports, dif))) { |
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index f8aff2c71cde..5b039159e67a 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c | |||
@@ -76,7 +76,7 @@ void inet_twsk_free(struct inet_timewait_sock *tw) | |||
76 | 76 | ||
77 | void inet_twsk_put(struct inet_timewait_sock *tw) | 77 | void inet_twsk_put(struct inet_timewait_sock *tw) |
78 | { | 78 | { |
79 | if (atomic_dec_and_test(&tw->tw_refcnt)) | 79 | if (refcount_dec_and_test(&tw->tw_refcnt)) |
80 | inet_twsk_free(tw); | 80 | inet_twsk_free(tw); |
81 | } | 81 | } |
82 | EXPORT_SYMBOL_GPL(inet_twsk_put); | 82 | EXPORT_SYMBOL_GPL(inet_twsk_put); |
@@ -131,7 +131,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, | |||
131 | * We can use atomic_set() because prior spin_lock()/spin_unlock() | 131 | * We can use atomic_set() because prior spin_lock()/spin_unlock() |
132 | * committed into memory all tw fields. | 132 | * committed into memory all tw fields. |
133 | */ | 133 | */ |
134 | atomic_set(&tw->tw_refcnt, 4); | 134 | refcount_set(&tw->tw_refcnt, 4); |
135 | inet_twsk_add_node_rcu(tw, &ehead->chain); | 135 | inet_twsk_add_node_rcu(tw, &ehead->chain); |
136 | 136 | ||
137 | /* Step 3: Remove SK from hash chain */ | 137 | /* Step 3: Remove SK from hash chain */ |
@@ -195,7 +195,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, | |||
195 | * to a non null value before everything is setup for this | 195 | * to a non null value before everything is setup for this |
196 | * timewait socket. | 196 | * timewait socket. |
197 | */ | 197 | */ |
198 | atomic_set(&tw->tw_refcnt, 0); | 198 | refcount_set(&tw->tw_refcnt, 0); |
199 | 199 | ||
200 | __module_get(tw->tw_prot->owner); | 200 | __module_get(tw->tw_prot->owner); |
201 | } | 201 | } |
@@ -278,7 +278,7 @@ restart: | |||
278 | atomic_read(&twsk_net(tw)->count)) | 278 | atomic_read(&twsk_net(tw)->count)) |
279 | continue; | 279 | continue; |
280 | 280 | ||
281 | if (unlikely(!atomic_inc_not_zero(&tw->tw_refcnt))) | 281 | if (unlikely(!refcount_inc_not_zero(&tw->tw_refcnt))) |
282 | continue; | 282 | continue; |
283 | 283 | ||
284 | if (unlikely((tw->tw_family != family) || | 284 | if (unlikely((tw->tw_family != family) || |
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index ccfbce13a633..b8f0db54b197 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c | |||
@@ -290,7 +290,7 @@ void ping_close(struct sock *sk, long timeout) | |||
290 | { | 290 | { |
291 | pr_debug("ping_close(sk=%p,sk->num=%u)\n", | 291 | pr_debug("ping_close(sk=%p,sk->num=%u)\n", |
292 | inet_sk(sk), inet_sk(sk)->inet_num); | 292 | inet_sk(sk), inet_sk(sk)->inet_num); |
293 | pr_debug("isk->refcnt = %d\n", sk->sk_refcnt.counter); | 293 | pr_debug("isk->refcnt = %d\n", refcount_read(&sk->sk_refcnt)); |
294 | 294 | ||
295 | sk_common_release(sk); | 295 | sk_common_release(sk); |
296 | } | 296 | } |
@@ -1127,7 +1127,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f, | |||
1127 | 0, 0L, 0, | 1127 | 0, 0L, 0, |
1128 | from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)), | 1128 | from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)), |
1129 | 0, sock_i_ino(sp), | 1129 | 0, sock_i_ino(sp), |
1130 | atomic_read(&sp->sk_refcnt), sp, | 1130 | refcount_read(&sp->sk_refcnt), sp, |
1131 | atomic_read(&sp->sk_drops)); | 1131 | atomic_read(&sp->sk_drops)); |
1132 | } | 1132 | } |
1133 | 1133 | ||
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index bdffad875691..b0bb5d0a30bd 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -1063,7 +1063,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i) | |||
1063 | 0, 0L, 0, | 1063 | 0, 0L, 0, |
1064 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), | 1064 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), |
1065 | 0, sock_i_ino(sp), | 1065 | 0, sock_i_ino(sp), |
1066 | atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops)); | 1066 | refcount_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops)); |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | static int raw_seq_show(struct seq_file *seq, void *v) | 1069 | static int raw_seq_show(struct seq_file *seq, void *v) |
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 7835bb4a1fab..0905cf04c2a4 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c | |||
@@ -213,7 +213,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb, | |||
213 | child = icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst, | 213 | child = icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst, |
214 | NULL, &own_req); | 214 | NULL, &own_req); |
215 | if (child) { | 215 | if (child) { |
216 | atomic_set(&req->rsk_refcnt, 1); | 216 | refcount_set(&req->rsk_refcnt, 1); |
217 | tcp_sk(child)->tsoffset = tsoff; | 217 | tcp_sk(child)->tsoffset = tsoff; |
218 | sock_rps_save_rxhash(child, skb); | 218 | sock_rps_save_rxhash(child, skb); |
219 | inet_csk_reqsk_queue_add(sk, req, child); | 219 | inet_csk_reqsk_queue_add(sk, req, child); |
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 4af82b914dd4..8b1539efaf38 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c | |||
@@ -214,7 +214,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk, | |||
214 | inet_csk_reset_xmit_timer(child, ICSK_TIME_RETRANS, | 214 | inet_csk_reset_xmit_timer(child, ICSK_TIME_RETRANS, |
215 | TCP_TIMEOUT_INIT, TCP_RTO_MAX); | 215 | TCP_TIMEOUT_INIT, TCP_RTO_MAX); |
216 | 216 | ||
217 | atomic_set(&req->rsk_refcnt, 2); | 217 | refcount_set(&req->rsk_refcnt, 2); |
218 | 218 | ||
219 | /* Now finish processing the fastopen child socket. */ | 219 | /* Now finish processing the fastopen child socket. */ |
220 | inet_csk(child)->icsk_af_ops->rebuild_header(child); | 220 | inet_csk(child)->icsk_af_ops->rebuild_header(child); |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index d774bcd9a54b..6ec6900eb300 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -2323,7 +2323,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i) | |||
2323 | from_kuid_munged(seq_user_ns(f), sock_i_uid(sk)), | 2323 | from_kuid_munged(seq_user_ns(f), sock_i_uid(sk)), |
2324 | icsk->icsk_probes_out, | 2324 | icsk->icsk_probes_out, |
2325 | sock_i_ino(sk), | 2325 | sock_i_ino(sk), |
2326 | atomic_read(&sk->sk_refcnt), sk, | 2326 | refcount_read(&sk->sk_refcnt), sk, |
2327 | jiffies_to_clock_t(icsk->icsk_rto), | 2327 | jiffies_to_clock_t(icsk->icsk_rto), |
2328 | jiffies_to_clock_t(icsk->icsk_ack.ato), | 2328 | jiffies_to_clock_t(icsk->icsk_ack.ato), |
2329 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, | 2329 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, |
@@ -2349,7 +2349,7 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw, | |||
2349 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK", | 2349 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK", |
2350 | i, src, srcp, dest, destp, tw->tw_substate, 0, 0, | 2350 | i, src, srcp, dest, destp, tw->tw_substate, 0, 0, |
2351 | 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, | 2351 | 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, |
2352 | atomic_read(&tw->tw_refcnt), tw); | 2352 | refcount_read(&tw->tw_refcnt), tw); |
2353 | } | 2353 | } |
2354 | 2354 | ||
2355 | #define TMPSZ 150 | 2355 | #define TMPSZ 150 |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 86fad2a14ac4..25294d43e147 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -577,7 +577,7 @@ struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport, | |||
577 | 577 | ||
578 | sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport, | 578 | sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport, |
579 | dif, &udp_table, NULL); | 579 | dif, &udp_table, NULL); |
580 | if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) | 580 | if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) |
581 | sk = NULL; | 581 | sk = NULL; |
582 | return sk; | 582 | return sk; |
583 | } | 583 | } |
@@ -2242,7 +2242,7 @@ void udp_v4_early_demux(struct sk_buff *skb) | |||
2242 | uh->source, iph->saddr, dif); | 2242 | uh->source, iph->saddr, dif); |
2243 | } | 2243 | } |
2244 | 2244 | ||
2245 | if (!sk || !atomic_inc_not_zero_hint(&sk->sk_refcnt, 2)) | 2245 | if (!sk || !refcount_inc_not_zero(&sk->sk_refcnt)) |
2246 | return; | 2246 | return; |
2247 | 2247 | ||
2248 | skb->sk = sk; | 2248 | skb->sk = sk; |
@@ -2691,7 +2691,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f, | |||
2691 | 0, 0L, 0, | 2691 | 0, 0L, 0, |
2692 | from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)), | 2692 | from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)), |
2693 | 0, sock_i_ino(sp), | 2693 | 0, sock_i_ino(sp), |
2694 | atomic_read(&sp->sk_refcnt), sp, | 2694 | refcount_read(&sp->sk_refcnt), sp, |
2695 | atomic_read(&sp->sk_drops)); | 2695 | atomic_read(&sp->sk_drops)); |
2696 | } | 2696 | } |
2697 | 2697 | ||
diff --git a/net/ipv4/udp_diag.c b/net/ipv4/udp_diag.c index 9a89c10a55f0..4515836d2a3a 100644 --- a/net/ipv4/udp_diag.c +++ b/net/ipv4/udp_diag.c | |||
@@ -55,7 +55,7 @@ static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb, | |||
55 | req->id.idiag_dport, | 55 | req->id.idiag_dport, |
56 | req->id.idiag_if, tbl, NULL); | 56 | req->id.idiag_if, tbl, NULL); |
57 | #endif | 57 | #endif |
58 | if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) | 58 | if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) |
59 | sk = NULL; | 59 | sk = NULL; |
60 | rcu_read_unlock(); | 60 | rcu_read_unlock(); |
61 | err = -ENOENT; | 61 | err = -ENOENT; |
@@ -206,7 +206,7 @@ static int __udp_diag_destroy(struct sk_buff *in_skb, | |||
206 | return -EINVAL; | 206 | return -EINVAL; |
207 | } | 207 | } |
208 | 208 | ||
209 | if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) | 209 | if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) |
210 | sk = NULL; | 210 | sk = NULL; |
211 | 211 | ||
212 | rcu_read_unlock(); | 212 | rcu_read_unlock(); |
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c index 5c786f5ab961..a1f918713006 100644 --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c | |||
@@ -1041,6 +1041,6 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp, | |||
1041 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), | 1041 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), |
1042 | 0, | 1042 | 0, |
1043 | sock_i_ino(sp), | 1043 | sock_i_ino(sp), |
1044 | atomic_read(&sp->sk_refcnt), sp, | 1044 | refcount_read(&sp->sk_refcnt), sp, |
1045 | atomic_read(&sp->sk_drops)); | 1045 | atomic_read(&sp->sk_drops)); |
1046 | } | 1046 | } |
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index d0900918a19e..b13b8f93079d 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c | |||
@@ -75,7 +75,7 @@ begin: | |||
75 | continue; | 75 | continue; |
76 | if (!INET6_MATCH(sk, net, saddr, daddr, ports, dif)) | 76 | if (!INET6_MATCH(sk, net, saddr, daddr, ports, dif)) |
77 | continue; | 77 | continue; |
78 | if (unlikely(!atomic_inc_not_zero(&sk->sk_refcnt))) | 78 | if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt))) |
79 | goto out; | 79 | goto out; |
80 | 80 | ||
81 | if (unlikely(!INET6_MATCH(sk, net, saddr, daddr, ports, dif))) { | 81 | if (unlikely(!INET6_MATCH(sk, net, saddr, daddr, ports, dif))) { |
@@ -172,7 +172,7 @@ struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo, | |||
172 | 172 | ||
173 | sk = __inet6_lookup(net, hashinfo, skb, doff, saddr, sport, daddr, | 173 | sk = __inet6_lookup(net, hashinfo, skb, doff, saddr, sport, daddr, |
174 | ntohs(dport), dif, &refcounted); | 174 | ntohs(dport), dif, &refcounted); |
175 | if (sk && !refcounted && !atomic_inc_not_zero(&sk->sk_refcnt)) | 175 | if (sk && !refcounted && !refcount_inc_not_zero(&sk->sk_refcnt)) |
176 | sk = NULL; | 176 | sk = NULL; |
177 | return sk; | 177 | return sk; |
178 | } | 178 | } |
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index f1a4881d9835..2521690d62d6 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
@@ -1809,7 +1809,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i) | |||
1809 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), | 1809 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)), |
1810 | icsk->icsk_probes_out, | 1810 | icsk->icsk_probes_out, |
1811 | sock_i_ino(sp), | 1811 | sock_i_ino(sp), |
1812 | atomic_read(&sp->sk_refcnt), sp, | 1812 | refcount_read(&sp->sk_refcnt), sp, |
1813 | jiffies_to_clock_t(icsk->icsk_rto), | 1813 | jiffies_to_clock_t(icsk->icsk_rto), |
1814 | jiffies_to_clock_t(icsk->icsk_ack.ato), | 1814 | jiffies_to_clock_t(icsk->icsk_ack.ato), |
1815 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, | 1815 | (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, |
@@ -1842,7 +1842,7 @@ static void get_timewait6_sock(struct seq_file *seq, | |||
1842 | dest->s6_addr32[2], dest->s6_addr32[3], destp, | 1842 | dest->s6_addr32[2], dest->s6_addr32[3], destp, |
1843 | tw->tw_substate, 0, 0, | 1843 | tw->tw_substate, 0, 0, |
1844 | 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, | 1844 | 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, |
1845 | atomic_read(&tw->tw_refcnt), tw); | 1845 | refcount_read(&tw->tw_refcnt), tw); |
1846 | } | 1846 | } |
1847 | 1847 | ||
1848 | static int tcp6_seq_show(struct seq_file *seq, void *v) | 1848 | static int tcp6_seq_show(struct seq_file *seq, void *v) |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 319aa8ed9cf8..4a3e65626e8b 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -325,7 +325,7 @@ struct sock *udp6_lib_lookup(struct net *net, const struct in6_addr *saddr, __be | |||
325 | 325 | ||
326 | sk = __udp6_lib_lookup(net, saddr, sport, daddr, dport, | 326 | sk = __udp6_lib_lookup(net, saddr, sport, daddr, dport, |
327 | dif, &udp_table, NULL); | 327 | dif, &udp_table, NULL); |
328 | if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) | 328 | if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) |
329 | sk = NULL; | 329 | sk = NULL; |
330 | return sk; | 330 | return sk; |
331 | } | 331 | } |
@@ -916,7 +916,7 @@ static void udp_v6_early_demux(struct sk_buff *skb) | |||
916 | else | 916 | else |
917 | return; | 917 | return; |
918 | 918 | ||
919 | if (!sk || !atomic_inc_not_zero_hint(&sk->sk_refcnt, 2)) | 919 | if (!sk || !refcount_inc_not_zero(&sk->sk_refcnt)) |
920 | return; | 920 | return; |
921 | 921 | ||
922 | skb->sk = sk; | 922 | skb->sk = sk; |
diff --git a/net/key/af_key.c b/net/key/af_key.c index e466579c18fa..edcf1d0f82c8 100644 --- a/net/key/af_key.c +++ b/net/key/af_key.c | |||
@@ -3739,7 +3739,7 @@ static int pfkey_seq_show(struct seq_file *f, void *v) | |||
3739 | else | 3739 | else |
3740 | seq_printf(f, "%pK %-6d %-6u %-6u %-6u %-6lu\n", | 3740 | seq_printf(f, "%pK %-6d %-6u %-6u %-6u %-6lu\n", |
3741 | s, | 3741 | s, |
3742 | atomic_read(&s->sk_refcnt), | 3742 | refcount_read(&s->sk_refcnt), |
3743 | sk_rmem_alloc_get(s), | 3743 | sk_rmem_alloc_get(s), |
3744 | sk_wmem_alloc_get(s), | 3744 | sk_wmem_alloc_get(s), |
3745 | from_kuid_munged(seq_user_ns(f), sock_i_uid(s)), | 3745 | from_kuid_munged(seq_user_ns(f), sock_i_uid(s)), |
diff --git a/net/l2tp/l2tp_debugfs.c b/net/l2tp/l2tp_debugfs.c index d100aed3d06f..98a005d0d04a 100644 --- a/net/l2tp/l2tp_debugfs.c +++ b/net/l2tp/l2tp_debugfs.c | |||
@@ -144,9 +144,8 @@ static void l2tp_dfs_seq_tunnel_show(struct seq_file *m, void *v) | |||
144 | tunnel->encap == L2TP_ENCAPTYPE_IP ? "IP" : | 144 | tunnel->encap == L2TP_ENCAPTYPE_IP ? "IP" : |
145 | ""); | 145 | ""); |
146 | seq_printf(m, " %d sessions, refcnt %d/%d\n", session_count, | 146 | seq_printf(m, " %d sessions, refcnt %d/%d\n", session_count, |
147 | tunnel->sock ? atomic_read(&tunnel->sock->sk_refcnt) : 0, | 147 | tunnel->sock ? refcount_read(&tunnel->sock->sk_refcnt) : 0, |
148 | atomic_read(&tunnel->ref_count)); | 148 | atomic_read(&tunnel->ref_count)); |
149 | |||
150 | seq_printf(m, " %08x rx %ld/%ld/%ld rx %ld/%ld/%ld\n", | 149 | seq_printf(m, " %08x rx %ld/%ld/%ld rx %ld/%ld/%ld\n", |
151 | tunnel->debug, | 150 | tunnel->debug, |
152 | atomic_long_read(&tunnel->stats.tx_packets), | 151 | atomic_long_read(&tunnel->stats.tx_packets), |
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c index 9b02c13d258b..5e91b47f0d2a 100644 --- a/net/llc/llc_conn.c +++ b/net/llc/llc_conn.c | |||
@@ -507,7 +507,7 @@ again: | |||
507 | sk_nulls_for_each_rcu(rc, node, laddr_hb) { | 507 | sk_nulls_for_each_rcu(rc, node, laddr_hb) { |
508 | if (llc_estab_match(sap, daddr, laddr, rc)) { | 508 | if (llc_estab_match(sap, daddr, laddr, rc)) { |
509 | /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ | 509 | /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ |
510 | if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt))) | 510 | if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt))) |
511 | goto again; | 511 | goto again; |
512 | if (unlikely(llc_sk(rc)->sap != sap || | 512 | if (unlikely(llc_sk(rc)->sap != sap || |
513 | !llc_estab_match(sap, daddr, laddr, rc))) { | 513 | !llc_estab_match(sap, daddr, laddr, rc))) { |
@@ -566,7 +566,7 @@ again: | |||
566 | sk_nulls_for_each_rcu(rc, node, laddr_hb) { | 566 | sk_nulls_for_each_rcu(rc, node, laddr_hb) { |
567 | if (llc_listener_match(sap, laddr, rc)) { | 567 | if (llc_listener_match(sap, laddr, rc)) { |
568 | /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ | 568 | /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ |
569 | if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt))) | 569 | if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt))) |
570 | goto again; | 570 | goto again; |
571 | if (unlikely(llc_sk(rc)->sap != sap || | 571 | if (unlikely(llc_sk(rc)->sap != sap || |
572 | !llc_listener_match(sap, laddr, rc))) { | 572 | !llc_listener_match(sap, laddr, rc))) { |
@@ -973,9 +973,9 @@ void llc_sk_free(struct sock *sk) | |||
973 | skb_queue_purge(&sk->sk_write_queue); | 973 | skb_queue_purge(&sk->sk_write_queue); |
974 | skb_queue_purge(&llc->pdu_unack_q); | 974 | skb_queue_purge(&llc->pdu_unack_q); |
975 | #ifdef LLC_REFCNT_DEBUG | 975 | #ifdef LLC_REFCNT_DEBUG |
976 | if (atomic_read(&sk->sk_refcnt) != 1) { | 976 | if (refcount_read(&sk->sk_refcnt) != 1) { |
977 | printk(KERN_DEBUG "Destruction of LLC sock %p delayed in %s, cnt=%d\n", | 977 | printk(KERN_DEBUG "Destruction of LLC sock %p delayed in %s, cnt=%d\n", |
978 | sk, __func__, atomic_read(&sk->sk_refcnt)); | 978 | sk, __func__, refcount_read(&sk->sk_refcnt)); |
979 | printk(KERN_DEBUG "%d LLC sockets are still alive\n", | 979 | printk(KERN_DEBUG "%d LLC sockets are still alive\n", |
980 | atomic_read(&llc_sock_nr)); | 980 | atomic_read(&llc_sock_nr)); |
981 | } else { | 981 | } else { |
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c index 63b6ab056370..d90928f50226 100644 --- a/net/llc/llc_sap.c +++ b/net/llc/llc_sap.c | |||
@@ -329,7 +329,7 @@ again: | |||
329 | sk_nulls_for_each_rcu(rc, node, laddr_hb) { | 329 | sk_nulls_for_each_rcu(rc, node, laddr_hb) { |
330 | if (llc_dgram_match(sap, laddr, rc)) { | 330 | if (llc_dgram_match(sap, laddr, rc)) { |
331 | /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ | 331 | /* Extra checks required by SLAB_TYPESAFE_BY_RCU */ |
332 | if (unlikely(!atomic_inc_not_zero(&rc->sk_refcnt))) | 332 | if (unlikely(!refcount_inc_not_zero(&rc->sk_refcnt))) |
333 | goto again; | 333 | goto again; |
334 | if (unlikely(llc_sk(rc)->sap != sap || | 334 | if (unlikely(llc_sk(rc)->sap != sap || |
335 | !llc_dgram_match(sap, laddr, rc))) { | 335 | !llc_dgram_match(sap, laddr, rc))) { |
diff --git a/net/netfilter/xt_TPROXY.c b/net/netfilter/xt_TPROXY.c index df7f1df00330..d767e35fff6b 100644 --- a/net/netfilter/xt_TPROXY.c +++ b/net/netfilter/xt_TPROXY.c | |||
@@ -127,7 +127,7 @@ nf_tproxy_get_sock_v4(struct net *net, struct sk_buff *skb, void *hp, | |||
127 | daddr, dport, | 127 | daddr, dport, |
128 | in->ifindex); | 128 | in->ifindex); |
129 | 129 | ||
130 | if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) | 130 | if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) |
131 | sk = NULL; | 131 | sk = NULL; |
132 | /* NOTE: we return listeners even if bound to | 132 | /* NOTE: we return listeners even if bound to |
133 | * 0.0.0.0, those are filtered out in | 133 | * 0.0.0.0, those are filtered out in |
@@ -197,7 +197,7 @@ nf_tproxy_get_sock_v6(struct net *net, struct sk_buff *skb, int thoff, void *hp, | |||
197 | daddr, ntohs(dport), | 197 | daddr, ntohs(dport), |
198 | in->ifindex); | 198 | in->ifindex); |
199 | 199 | ||
200 | if (sk && !atomic_inc_not_zero(&sk->sk_refcnt)) | 200 | if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) |
201 | sk = NULL; | 201 | sk = NULL; |
202 | /* NOTE: we return listeners even if bound to | 202 | /* NOTE: we return listeners even if bound to |
203 | * 0.0.0.0, those are filtered out in | 203 | * 0.0.0.0, those are filtered out in |
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 8ced52e91181..5acee49db90b 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -575,7 +575,7 @@ static void netlink_remove(struct sock *sk) | |||
575 | table = &nl_table[sk->sk_protocol]; | 575 | table = &nl_table[sk->sk_protocol]; |
576 | if (!rhashtable_remove_fast(&table->hash, &nlk_sk(sk)->node, | 576 | if (!rhashtable_remove_fast(&table->hash, &nlk_sk(sk)->node, |
577 | netlink_rhashtable_params)) { | 577 | netlink_rhashtable_params)) { |
578 | WARN_ON(atomic_read(&sk->sk_refcnt) == 1); | 578 | WARN_ON(refcount_read(&sk->sk_refcnt) == 1); |
579 | __sock_put(sk); | 579 | __sock_put(sk); |
580 | } | 580 | } |
581 | 581 | ||
@@ -691,7 +691,7 @@ static void deferred_put_nlk_sk(struct rcu_head *head) | |||
691 | struct netlink_sock *nlk = container_of(head, struct netlink_sock, rcu); | 691 | struct netlink_sock *nlk = container_of(head, struct netlink_sock, rcu); |
692 | struct sock *sk = &nlk->sk; | 692 | struct sock *sk = &nlk->sk; |
693 | 693 | ||
694 | if (!atomic_dec_and_test(&sk->sk_refcnt)) | 694 | if (!refcount_dec_and_test(&sk->sk_refcnt)) |
695 | return; | 695 | return; |
696 | 696 | ||
697 | if (nlk->cb_running && nlk->cb.done) { | 697 | if (nlk->cb_running && nlk->cb.done) { |
@@ -2568,7 +2568,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v) | |||
2568 | sk_rmem_alloc_get(s), | 2568 | sk_rmem_alloc_get(s), |
2569 | sk_wmem_alloc_get(s), | 2569 | sk_wmem_alloc_get(s), |
2570 | nlk->cb_running, | 2570 | nlk->cb_running, |
2571 | atomic_read(&s->sk_refcnt), | 2571 | refcount_read(&s->sk_refcnt), |
2572 | atomic_read(&s->sk_drops), | 2572 | atomic_read(&s->sk_drops), |
2573 | sock_i_ino(s) | 2573 | sock_i_ino(s) |
2574 | ); | 2574 | ); |
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 90fd38d5c458..643302b37b48 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c | |||
@@ -4495,7 +4495,7 @@ static int packet_seq_show(struct seq_file *seq, void *v) | |||
4495 | seq_printf(seq, | 4495 | seq_printf(seq, |
4496 | "%pK %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n", | 4496 | "%pK %-6d %-4d %04x %-5d %1d %-6u %-6u %-6lu\n", |
4497 | s, | 4497 | s, |
4498 | atomic_read(&s->sk_refcnt), | 4498 | refcount_read(&s->sk_refcnt), |
4499 | s->sk_type, | 4499 | s->sk_type, |
4500 | ntohs(po->num), | 4500 | ntohs(po->num), |
4501 | po->ifindex, | 4501 | po->ifindex, |
diff --git a/net/phonet/socket.c b/net/phonet/socket.c index 29c7f754c70d..1b050dd17393 100644 --- a/net/phonet/socket.c +++ b/net/phonet/socket.c | |||
@@ -614,7 +614,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v) | |||
614 | sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk), | 614 | sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk), |
615 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)), | 615 | from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)), |
616 | sock_i_ino(sk), | 616 | sock_i_ino(sk), |
617 | atomic_read(&sk->sk_refcnt), sk, | 617 | refcount_read(&sk->sk_refcnt), sk, |
618 | atomic_read(&sk->sk_drops)); | 618 | atomic_read(&sk->sk_drops)); |
619 | } | 619 | } |
620 | seq_pad(seq, '\n'); | 620 | seq_pad(seq, '\n'); |
diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c index f1299f54627a..a2ad4482376f 100644 --- a/net/rxrpc/af_rxrpc.c +++ b/net/rxrpc/af_rxrpc.c | |||
@@ -747,7 +747,7 @@ static int rxrpc_release_sock(struct sock *sk) | |||
747 | { | 747 | { |
748 | struct rxrpc_sock *rx = rxrpc_sk(sk); | 748 | struct rxrpc_sock *rx = rxrpc_sk(sk); |
749 | 749 | ||
750 | _enter("%p{%d,%d}", sk, sk->sk_state, atomic_read(&sk->sk_refcnt)); | 750 | _enter("%p{%d,%d}", sk, sk->sk_state, refcount_read(&sk->sk_refcnt)); |
751 | 751 | ||
752 | /* declare the socket closed for business */ | 752 | /* declare the socket closed for business */ |
753 | sock_orphan(sk); | 753 | sock_orphan(sk); |
diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index eb0e9bab54c1..d6e97115500b 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c | |||
@@ -340,7 +340,7 @@ META_COLLECTOR(int_sk_refcnt) | |||
340 | *err = -1; | 340 | *err = -1; |
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | dst->value = atomic_read(&skb->sk->sk_refcnt); | 343 | dst->value = refcount_read(&skb->sk->sk_refcnt); |
344 | } | 344 | } |
345 | 345 | ||
346 | META_COLLECTOR(int_sk_rcvbuf) | 346 | META_COLLECTOR(int_sk_rcvbuf) |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 1b92b72e812f..101e3597338f 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -2313,7 +2313,7 @@ static void tipc_sk_remove(struct tipc_sock *tsk) | |||
2313 | struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id); | 2313 | struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id); |
2314 | 2314 | ||
2315 | if (!rhashtable_remove_fast(&tn->sk_rht, &tsk->node, tsk_rht_params)) { | 2315 | if (!rhashtable_remove_fast(&tn->sk_rht, &tsk->node, tsk_rht_params)) { |
2316 | WARN_ON(atomic_read(&sk->sk_refcnt) == 1); | 2316 | WARN_ON(refcount_read(&sk->sk_refcnt) == 1); |
2317 | __sock_put(sk); | 2317 | __sock_put(sk); |
2318 | } | 2318 | } |
2319 | } | 2319 | } |
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 7c2e21ebbedc..c88525403d2e 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -2847,7 +2847,7 @@ static int unix_seq_show(struct seq_file *seq, void *v) | |||
2847 | 2847 | ||
2848 | seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu", | 2848 | seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu", |
2849 | s, | 2849 | s, |
2850 | atomic_read(&s->sk_refcnt), | 2850 | refcount_read(&s->sk_refcnt), |
2851 | 0, | 2851 | 0, |
2852 | s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0, | 2852 | s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0, |
2853 | s->sk_type, | 2853 | s->sk_type, |