diff options
Diffstat (limited to 'include/net/sock.h')
| -rw-r--r-- | include/net/sock.h | 29 | 
1 files changed, 19 insertions, 10 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index 11d503417591..b770261fbdaf 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1053,6 +1053,12 @@ static inline void sk_wmem_queued_add(struct sock *sk, int val)  	WRITE_ONCE(sk->sk_wmem_queued, sk->sk_wmem_queued + val);  } +static inline void sk_forward_alloc_add(struct sock *sk, int val) +{ +	/* Paired with lockless reads of sk->sk_forward_alloc */ +	WRITE_ONCE(sk->sk_forward_alloc, sk->sk_forward_alloc + val); +} +  void sk_stream_write_space(struct sock *sk);  /* OOB backlog add */ @@ -1377,7 +1383,7 @@ static inline int sk_forward_alloc_get(const struct sock *sk)  	if (sk->sk_prot->forward_alloc_get)  		return sk->sk_prot->forward_alloc_get(sk);  #endif -	return sk->sk_forward_alloc; +	return READ_ONCE(sk->sk_forward_alloc);  }  static inline bool __sk_stream_memory_free(const struct sock *sk, int wake) @@ -1673,14 +1679,14 @@ static inline void sk_mem_charge(struct sock *sk, int size)  {  	if (!sk_has_account(sk))  		return; -	sk->sk_forward_alloc -= size; +	sk_forward_alloc_add(sk, -size);  }  static inline void sk_mem_uncharge(struct sock *sk, int size)  {  	if (!sk_has_account(sk))  		return; -	sk->sk_forward_alloc += size; +	sk_forward_alloc_add(sk, size);  	sk_mem_reclaim(sk);  } @@ -1900,7 +1906,9 @@ struct sockcm_cookie {  static inline void sockcm_init(struct sockcm_cookie *sockc,  			       const struct sock *sk)  { -	*sockc = (struct sockcm_cookie) { .tsflags = sk->sk_tsflags }; +	*sockc = (struct sockcm_cookie) { +		.tsflags = READ_ONCE(sk->sk_tsflags) +	};  }  int __sock_cmsg_send(struct sock *sk, struct cmsghdr *cmsg, @@ -2695,9 +2703,9 @@ void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,  static inline void  sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)  { -	ktime_t kt = skb->tstamp;  	struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb); - +	u32 tsflags = READ_ONCE(sk->sk_tsflags); +	ktime_t kt = skb->tstamp;  	/*  	 * generate control messages if  	 * - receive time stamping in software requested @@ -2705,10 +2713,10 @@ sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)  	 * - hardware time stamps available and wanted  	 */  	if (sock_flag(sk, SOCK_RCVTSTAMP) || -	    (sk->sk_tsflags & SOF_TIMESTAMPING_RX_SOFTWARE) || -	    (kt && sk->sk_tsflags & SOF_TIMESTAMPING_SOFTWARE) || +	    (tsflags & SOF_TIMESTAMPING_RX_SOFTWARE) || +	    (kt && tsflags & SOF_TIMESTAMPING_SOFTWARE) ||  	    (hwtstamps->hwtstamp && -	     (sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE))) +	     (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE)))  		__sock_recv_timestamp(msg, sk, skb);  	else  		sock_write_timestamp(sk, kt); @@ -2730,7 +2738,8 @@ static inline void sock_recv_cmsgs(struct msghdr *msg, struct sock *sk,  #define TSFLAGS_ANY	  (SOF_TIMESTAMPING_SOFTWARE			| \  			   SOF_TIMESTAMPING_RAW_HARDWARE) -	if (sk->sk_flags & FLAGS_RECV_CMSGS || sk->sk_tsflags & TSFLAGS_ANY) +	if (sk->sk_flags & FLAGS_RECV_CMSGS || +	    READ_ONCE(sk->sk_tsflags) & TSFLAGS_ANY)  		__sock_recv_cmsgs(msg, sk, skb);  	else if (unlikely(sock_flag(sk, SOCK_TIMESTAMP)))  		sock_write_timestamp(sk, skb->tstamp);  |