Message ID | 20210610144411.1414221-1-eric.dumazet@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | b71eaed8c04f72a919a9c44e83e4ee254e69e7f3 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] inet: annotate date races around sk->sk_txhash | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | fail | Series targets non-next tree, but doesn't contain any Fixes tags |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | success | CCed 3 of 3 maintainers |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 3301 this patch: 3301 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | warning | WARNING: Possible repeated word: 'Google' |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 3400 this patch: 3400 |
netdev/header_inline | success | Link |
Hello: This patch was applied to netdev/net.git (refs/heads/master): On Thu, 10 Jun 2021 07:44:11 -0700 you wrote: > From: Eric Dumazet <edumazet@google.com> > > UDP sendmsg() path can be lockless, it is possible for another > thread to re-connect an change sk->sk_txhash under us. > > There is no serious impact, but we can use READ_ONCE()/WRITE_ONCE() > pair to document the race. > > [...] Here is the summary with links: - [net] inet: annotate date races around sk->sk_txhash https://git.kernel.org/netdev/net/c/b71eaed8c04f You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
diff --git a/include/net/sock.h b/include/net/sock.h index 2fc513aa114c0f4bd7554ca08655d0daf63f4544..7a7058f4f265c3e6aaad75b507ccb808bf110c65 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1934,7 +1934,8 @@ static inline u32 net_tx_rndhash(void) static inline void sk_set_txhash(struct sock *sk) { - sk->sk_txhash = net_tx_rndhash(); + /* This pairs with READ_ONCE() in skb_set_hash_from_sk() */ + WRITE_ONCE(sk->sk_txhash, net_tx_rndhash()); } static inline bool sk_rethink_txhash(struct sock *sk) @@ -2206,9 +2207,12 @@ static inline void sock_poll_wait(struct file *filp, struct socket *sock, static inline void skb_set_hash_from_sk(struct sk_buff *skb, struct sock *sk) { - if (sk->sk_txhash) { + /* This pairs with WRITE_ONCE() in sk_set_txhash() */ + u32 txhash = READ_ONCE(sk->sk_txhash); + + if (txhash) { skb->l4_hash = 1; - skb->hash = sk->sk_txhash; + skb->hash = txhash; } }