All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
	<daniel@iogearbox.net>, <andrii@kernel.org>, <eddyz87@gmail.com>,
	<memxor@gmail.com>, <john.fastabend@gmail.com>,
	<jakub@cloudflare.com>, <jiayuan.chen@linux.dev>,
	<davem@davemloft.net>, <edumazet@kernel.org>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <horms@kernel.org>, <kuniyu@google.com>,
	<willemb@google.com>, <matttbe@kernel.org>,
	<mptcp@lists.linux.dev>, <mason@kernel.org>,
	<josef@toxicpanda.com>
Subject: Re: [PATCH bpf v2 14/15] bpf, sockmap: Keep the rest of the cork after a redirect
Date: Wed, 04 Nov 2026 00:30:22 +0000	[thread overview]
Message-ID: <DMM03F7F8IDM.VMOKC4RWW2LV@gmail.com> (raw)
In-Reply-To: <179374188416.488855.8465787275984951547@kernel.org>

On Tue, Nov 03, 2026 at 01:38 PM netdev-bot+sashiko@kernel.org <netdev-bot+sashiko@kernel.org> wrote:
>>  			if (!cork)
>>  				*copied -= free;
>>  		}
>
> Should the cork case also subtract the freed bytes from *copied and keep
> the error?

No. That's deliberate, and the commit log says that it stays. See
commit fec51d40ea65 ("bpf: sockmap, zero sg_size on error when buffer is
released"). A cork has data of earlier sendmsg() calls. An error for
that data doesn't go to the current caller.

>> +		if (cork && msg->sg.size && !psock->cork) {
>
> Is this case meant to stay out of scope, or should *copied at least be
> reduced by the freed tail?

Out of scope. It's already explained in the commit log.
A smaller *copied alone is wrong. ret is 0 and tcp_bpf_sendmsg()
continues with the next bytes of the user buffer. Then the return value
doesn't tell which bytes are lost.

> This isn't a bug introduced by this patch, but putting the tail back here
> adds a new way into a race that already exists in the SK_PASS branch. Can
> a restored cork be freed while tcp_bpf_push() is still using it?

yeah. It's an old bug, not from this patch.
Each SK_PASS on a cork has this window, with or without a redirect
before it.

> Would it fix this to detach psock->cork in the SK_PASS branch before any
> push that can drop the lock, and attach it again under the lock afterwards,
> as the SK_REDIRECT branch does?

For this case, yes. Jiayuan proposed to serialize the senders in the
reply to patch 13. That covers this case and the new cork above.

> Non-cork messages already have the same accounting problem. Should
> sk_msg_apply_bytes() be charged with the bytes actually sent rather than
> tosend?

No. The verdict has to end before release_sock(). See
commit cd9733f5d75c ("tcp_bpf: Fix one concurrency problem in the
tcp_bpf_send_verdict function"). A refund after lock_sock() can land on
the verdict of another sender.
The prog runs again on the rest. Without this patch the kernel frees it.

> Could a test be added that checks how many bytes the peer receives?

Right. test_sockmap doesn't catch it. It can be a follow up.

  reply	other threads:[~2026-11-04  0:30 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:20 [PATCH bpf v2 00/15] bpf, sockmap: Fixes for verdicts, redirects, corks and recvmsg() Alexei Starovoitov
2026-11-02  7:20 ` [PATCH bpf v2 01/15] bpf, sockmap: Write sg.start when recvmsg() faults Alexei Starovoitov
2026-11-02  8:32   ` Jiayuan Chen
2026-11-02  7:20 ` [PATCH bpf v2 02/15] bpf, sockmap: Don't let an SK_DROP verdict stick Alexei Starovoitov
2026-11-02  8:45   ` Jiayuan Chen
2026-11-02 18:47   ` John Fastabend
2026-11-02  7:21 ` [PATCH bpf v2 03/15] bpf, sockmap: Don't let an SK_PASS verdict cover the next message Alexei Starovoitov
2026-11-02 18:51   ` John Fastabend
2026-11-02 22:44     ` Alexei Starovoitov
2026-11-03 21:37   ` netdev-bot+sashiko
2026-11-04  0:28     ` Alexei Starovoitov
2026-11-04  1:32       ` Jiayuan Chen
2026-11-04  2:04         ` Alexei Starovoitov
2026-11-02  7:21 ` [PATCH bpf v2 04/15] bpf, sockmap: Subtract all dropped bytes from the return value Alexei Starovoitov
2026-11-02 11:19   ` Jiayuan Chen
2026-11-02 19:12   ` John Fastabend
2026-11-02  7:21 ` [PATCH bpf v2 05/15] bpf, sockmap: Clear the resume state of a stopped psock Alexei Starovoitov
2026-11-02 11:40   ` Jiayuan Chen
2026-11-02 19:16     ` John Fastabend
2026-11-02  7:21 ` [PATCH bpf v2 06/15] bpf, sockmap: Give no progs to a TCP listener Alexei Starovoitov
2026-11-02 12:00   ` Jiayuan Chen
2026-11-02 19:31   ` John Fastabend
2026-11-03 21:37   ` netdev-bot+sashiko
2026-11-04  0:29     ` Alexei Starovoitov
2026-11-02  7:21 ` [PATCH bpf v2 07/15] bpf, sockmap: Check the target of an egress redirect before each send Alexei Starovoitov
2026-11-02 12:32   ` Jiayuan Chen
2026-11-02 16:18     ` Alexei Starovoitov
2026-11-02 19:36   ` John Fastabend
2026-11-03 21:38   ` netdev-bot+sashiko
2026-11-04  0:29     ` Alexei Starovoitov
2026-11-02  7:21 ` [PATCH bpf v2 08/15] net: Leave sk_stream_wait_memory() once the socket is dead Alexei Starovoitov
2026-11-02 12:54   ` Jiayuan Chen
2026-11-04  5:23   ` Eric Dumazet
2026-11-04 18:32     ` Alexei Starovoitov
2026-11-02  7:21 ` [PATCH bpf v2 09/15] bpf, sockmap: Check the TCP state in recvmsg() Alexei Starovoitov
2026-11-02 15:15   ` Jiayuan Chen
2026-11-02 16:57   ` Matthieu Baerts
2026-11-03 21:38   ` netdev-bot+sashiko
2026-11-04  0:29     ` Alexei Starovoitov
2026-11-02  7:21 ` [PATCH bpf v2 10/15] bpf, sockmap: Reset the copy position when corking Alexei Starovoitov
2026-11-03  1:39   ` Jiayuan Chen
2026-11-02  7:21 ` [PATCH bpf v2 11/15] bpf, sockmap: Don't copy 0 bytes into a full cork Alexei Starovoitov
2026-11-03  1:41   ` Jiayuan Chen
2026-11-02  7:21 ` [PATCH bpf v2 12/15] bpf, sockmap: Clear the redirect target before the sk_msg prog runs Alexei Starovoitov
2026-11-03  1:58   ` Jiayuan Chen
2026-11-02  7:21 ` [PATCH bpf v2 13/15] bpf, sockmap: Check that the redirected message is the cork Alexei Starovoitov
2026-11-03  2:07   ` Jiayuan Chen
2026-11-02  7:21 ` [PATCH bpf v2 14/15] bpf, sockmap: Keep the rest of the cork after a redirect Alexei Starovoitov
2026-11-03  2:25   ` Jiayuan Chen
2026-11-03 21:38   ` netdev-bot+sashiko
2026-11-04  0:30     ` Alexei Starovoitov [this message]
2026-11-02  7:21 ` [PATCH bpf v2 15/15] bpf, sockmap: Clear the end mark of elements added by push and pop Alexei Starovoitov
2026-11-03  2:51   ` Jiayuan Chen
2026-11-02  9:29 ` [PATCH bpf v2 00/15] bpf, sockmap: Fixes for verdicts, redirects, corks and recvmsg() MPTCP CI
2026-11-02 20:11 ` John Fastabend
2026-11-04  5:24   ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DMM03F7F8IDM.VMOKC4RWW2LV@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=josef@toxicpanda.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=mason@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.