Skip to content

Commit

Permalink
net: annotate data-races around sk->sk_bind_phc
Browse files Browse the repository at this point in the history
[ Upstream commit 251cd40 ]

sk->sk_bind_phc is read locklessly. Add corresponding annotations.

Fixes: d463126 ("net: sock: extend SO_TIMESTAMPING for PHC binding")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Eric Dumazet authored and gregkh committed Sep 19, 2023
1 parent b352717 commit 5f4836e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions net/core/sock.c
Expand Up @@ -894,7 +894,7 @@ static int sock_timestamping_bind_phc(struct sock *sk, int phc_index)
if (!match)
return -EINVAL;

sk->sk_bind_phc = phc_index;
WRITE_ONCE(sk->sk_bind_phc, phc_index);

return 0;
}
Expand Down Expand Up @@ -1719,7 +1719,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
case SO_TIMESTAMPING_OLD:
lv = sizeof(v.timestamping);
v.timestamping.flags = READ_ONCE(sk->sk_tsflags);
v.timestamping.bind_phc = sk->sk_bind_phc;
v.timestamping.bind_phc = READ_ONCE(sk->sk_bind_phc);
break;

case SO_RCVTIMEO_OLD:
Expand Down
2 changes: 1 addition & 1 deletion net/socket.c
Expand Up @@ -935,7 +935,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,

if (tsflags & SOF_TIMESTAMPING_BIND_PHC)
hwtstamp = ptp_convert_timestamp(&hwtstamp,
sk->sk_bind_phc);
READ_ONCE(sk->sk_bind_phc));

if (ktime_to_timespec64_cond(hwtstamp, tss.ts + 2)) {
empty = 0;
Expand Down

0 comments on commit 5f4836e

Please sign in to comment.