🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by bot+bpf-ci Fri, 30 Oct 2026 12:45
Re: [PATCH bpf-next 2/2] bpf, sockmap: Fix psock update-side data races on sk->sk_prot and progs
#8907
Author: bot+bpf-ci
Date: Fri, 30 Oct 2026 12:45
77 lines
11176 bytes
--===============5168075361254505390==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

> bpf, sockmap: Fix psock update-side data races on sk->sk_prot and progs

TL;DR: Commit message only: the first bullet says the saved_data_ready gating
was dropped in sock_map_link(), but the diff drops it in sock_map_del_link(),
duplicating the second bullet.

>     bpf, sockmap: Fix psock update-side data races on sk->sk_prot and progs
>
>     The update side of the sockmap psock lifecycle has several unsynchronized
>     accesses to sk->sk_prot and psock prog state that KCSAN flags when the
>     new update-vs-delete race selftest runs. The fix comes from Alexei [1]:
>
>     * sock_map_link() installed psock programs and called sock_map_init_proto()
>       before taking sk->sk_callback_lock, racing a concurrent teardown's
>       tcp_bpf_update_proto() write of sk->sk_prot. Take the write_lock early,
>       before psock_set_prog() and sock_map_init_proto(), and drop the
>       psock->saved_data_ready gating from prog detection (it is re-checked
>       under the lock before stopping progs).
>
>     * sock_map_del_link() read psock->saved_data_ready outside the lock. Move
>       the saved_data_ready check under write_lock_bh(&sk->sk_callback_lock)
>       so prog teardown is serialized against the proto restore.
>
>     * sock_map_psock_get_checked() and sock_map_sk_is_suitable() did plain
>       sk->sk_prot reads. Convert to READ_ONCE() to mark the intentional racy
>       read against the WRITE_ONCE() swap in sock_replace_proto().
>
>     With these changes the sock_map_link/psock_set_prog side of the reported
>     KCSAN splats is silenced; the remaining teardown-vs-core-TCP pairings
>     are the separate read-side annotation problem.
>
>     [1] https://lore.kernel.org/bpf/DMBHB0TQOV1L.38MECMYFGUS5B@gmail.com
>
>     Suggested-by: Alexei Starovoitov <ast@kernel.org>
>     Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>

The first bullet says sock_map_link() drops the psock->saved_data_ready
gating from prog detection, which is "re-checked under the lock before
stopping progs".  Is that sentence describing the right function?

The diff doesn't change sock_map_link() that way.  Its only change is
moving write_lock_bh(&sk->sk_callback_lock) above the psock_set_prog()
calls, plus the matching unlock on the sock_map_init_proto() error path.
sock_map_link() still gates on !psock->saved_data_ready:

    if (stream_parser && stream_verdict && !psock->saved_data_ready) {

The gating that was dropped is in sock_map_del_link():

    -	if (psock->saved_data_ready && progs->stream_parser)
    +	if (progs->stream_parser)
     		strp_stop = true;
    ...
    +	write_lock_bh(&sk->sk_callback_lock);
    +	if (psock->saved_data_ready) {

The second bullet already covers the sock_map_del_link() lock and
saved_data_ready change, so the sentence in the first bullet looks both
misplaced and repeated.

Could it be moved to (or merged with) the sock_map_del_link() bullet, so
that a reader doesn't conclude the saved_data_ready checks were removed
from sock_map_link()?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41053761520
--===============5168075361254505390==--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads