net: annotate data-races around sk->sk_{rcv|snd}timeo
sk_getsockopt() runs without locks, we must add annotations to sk->sk_rcvtimeo and sk->sk_sndtimeo. In the future we might allow fetching these fields before we lock the socket in TCP fast path. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
e6d12bdb43
commit
285975dd67
@ -429,6 +429,7 @@ static int sock_set_timeout(long *timeo_p, sockptr_t optval, int optlen,
|
||||
{
|
||||
struct __kernel_sock_timeval tv;
|
||||
int err = sock_copy_user_timeval(&tv, optval, optlen, old_timeval);
|
||||
long val;
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
@ -439,7 +440,7 @@ static int sock_set_timeout(long *timeo_p, sockptr_t optval, int optlen,
|
||||
if (tv.tv_sec < 0) {
|
||||
static int warned __read_mostly;
|
||||
|
||||
*timeo_p = 0;
|
||||
WRITE_ONCE(*timeo_p, 0);
|
||||
if (warned < 10 && net_ratelimit()) {
|
||||
warned++;
|
||||
pr_info("%s: `%s' (pid %d) tries to set negative timeout\n",
|
||||
@ -447,11 +448,12 @@ static int sock_set_timeout(long *timeo_p, sockptr_t optval, int optlen,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*timeo_p = MAX_SCHEDULE_TIMEOUT;
|
||||
if (tv.tv_sec == 0 && tv.tv_usec == 0)
|
||||
return 0;
|
||||
if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1))
|
||||
*timeo_p = tv.tv_sec * HZ + DIV_ROUND_UP((unsigned long)tv.tv_usec, USEC_PER_SEC / HZ);
|
||||
val = MAX_SCHEDULE_TIMEOUT;
|
||||
if ((tv.tv_sec || tv.tv_usec) &&
|
||||
(tv.tv_sec < (MAX_SCHEDULE_TIMEOUT / HZ - 1)))
|
||||
val = tv.tv_sec * HZ + DIV_ROUND_UP((unsigned long)tv.tv_usec,
|
||||
USEC_PER_SEC / HZ);
|
||||
WRITE_ONCE(*timeo_p, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -813,9 +815,9 @@ void sock_set_sndtimeo(struct sock *sk, s64 secs)
|
||||
{
|
||||
lock_sock(sk);
|
||||
if (secs && secs < MAX_SCHEDULE_TIMEOUT / HZ - 1)
|
||||
sk->sk_sndtimeo = secs * HZ;
|
||||
WRITE_ONCE(sk->sk_sndtimeo, secs * HZ);
|
||||
else
|
||||
sk->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT;
|
||||
WRITE_ONCE(sk->sk_sndtimeo, MAX_SCHEDULE_TIMEOUT);
|
||||
release_sock(sk);
|
||||
}
|
||||
EXPORT_SYMBOL(sock_set_sndtimeo);
|
||||
@ -1721,12 +1723,14 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
|
||||
|
||||
case SO_RCVTIMEO_OLD:
|
||||
case SO_RCVTIMEO_NEW:
|
||||
lv = sock_get_timeout(sk->sk_rcvtimeo, &v, SO_RCVTIMEO_OLD == optname);
|
||||
lv = sock_get_timeout(READ_ONCE(sk->sk_rcvtimeo), &v,
|
||||
SO_RCVTIMEO_OLD == optname);
|
||||
break;
|
||||
|
||||
case SO_SNDTIMEO_OLD:
|
||||
case SO_SNDTIMEO_NEW:
|
||||
lv = sock_get_timeout(sk->sk_sndtimeo, &v, SO_SNDTIMEO_OLD == optname);
|
||||
lv = sock_get_timeout(READ_ONCE(sk->sk_sndtimeo), &v,
|
||||
SO_SNDTIMEO_OLD == optname);
|
||||
break;
|
||||
|
||||
case SO_RCVLOWAT:
|
||||
|
@ -568,7 +568,7 @@ META_COLLECTOR(int_sk_rcvtimeo)
|
||||
*err = -1;
|
||||
return;
|
||||
}
|
||||
dst->value = sk->sk_rcvtimeo / HZ;
|
||||
dst->value = READ_ONCE(sk->sk_rcvtimeo) / HZ;
|
||||
}
|
||||
|
||||
META_COLLECTOR(int_sk_sndtimeo)
|
||||
@ -579,7 +579,7 @@ META_COLLECTOR(int_sk_sndtimeo)
|
||||
*err = -1;
|
||||
return;
|
||||
}
|
||||
dst->value = sk->sk_sndtimeo / HZ;
|
||||
dst->value = READ_ONCE(sk->sk_sndtimeo) / HZ;
|
||||
}
|
||||
|
||||
META_COLLECTOR(int_sk_sendmsg_off)
|
||||
|
Loading…
Reference in New Issue
Block a user