From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
To: "Jakub Sitnicki" <jakub@cloudflare.com>
Cc: bpf@vger.kernel.org, "John Fastabend" <john.fastabend@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Neal Cardwell" <ncardwell@google.com>,
"Kuniyuki Iwashima" <kuniyu@google.com>,
"David Ahern" <dsahern@kernel.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Shuah Khan" <shuah@kernel.org>, "Michal Luczaj" <mhal@rbox.co>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Cong Wang" <cong.wang@bytedance.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 1/3] bpf, sockmap: Fix incorrect copied_seq calculation
Date: Thu, 20 Nov 2025 14:03:46 +0000 [thread overview]
Message-ID: <b6c033deb75243e285fa6b028ee666f874b75eb8@linux.dev> (raw)
In-Reply-To: <87tsyo6ets.fsf@cloudflare.com>
November 20, 2025 at 20:58, "Jakub Sitnicki" <jakub@cloudflare.com mailto:jakub@cloudflare.com?to=%22Jakub%20Sitnicki%22%20%3Cjakub%40cloudflare.com%3E > wrote:
>
> On Thu, Nov 20, 2025 at 02:49 AM GMT, Jiayuan Chen wrote:
>
> >
> > November 20, 2025 at 03:53, "Jakub Sitnicki" <jakub@cloudflare.com mailto:jakub@cloudflare.com?to=%22Jakub%20Sitnicki%22%20%3Cjakub%40cloudflare.com%3E > wrote:
> >
> > [...]
> >
> > >
> > > > +/* The BPF program sets BPF_F_INGRESS on sk_msg to indicate data needs to be
> > > > + * redirected to the ingress queue of a specified socket. Since BPF_F_INGRESS is
> > > > + * defined in UAPI so that we can't extend this enum for our internal flags. We
> > > > + * define some internal flags here while inheriting BPF_F_INGRESS.
> > > > + */
> > > > +enum {
> > > > + SK_MSG_F_INGRESS = BPF_F_INGRESS, /* (1ULL << 0) */
> > > > + /* internal flag */
> > > > + SK_MSG_F_INGRESS_SELF = (1ULL << 1)
> > > > +};
> > > > +
> > > >
> > > I'm wondering if we need additional state to track this.
> > > Can we track sk_msg's construted from skb's that were not redirected by
> > > setting `sk_msg.sk = sk` to indicate that the source socket is us in
> > > sk_psock_skb_ingress_self()?
> > >
> > Functionally, that would work. However, in that case, we would have to hold
> > a reference to sk until the sk_msg is read, which would delay the release of
> > sk. One concern is that if there is a bug in the read-side application, sk
> > might never be released.
> >
> We don't need to grab a reference to sk if we're talking about setting
> it only in sk_psock_skb_ingress_self(). psock already holds a ref for
> psock->sk, and we purge psock->ingress_msg queue when destroying the
> psock before releasing the sock ref in sk_psock_destroy().
I see. When it's an ingress to self redirection, the msg.sk would point to
the same socket as psock->sk (the socket itself), not to another socket, so
indeed no additional reference grab is needed.
> While there's nothing wrong with an internal flaag, I'm trying to see if
> we make things somewhat consistent so as a result sk_msg state is easier
> to reason about.
>
> My thinking here is that we already set sk_msg.sk to source socket in
> sk_psock_msg_verdict() on sendmsg() path, so we know that this is the
> purpose of that field. We could mimic this on recvmsg() path.
>
next prev parent reply other threads:[~2025-11-20 14:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-17 11:07 [PATCH bpf-next v1 0/3] bpf: Fix FIONREAD and copied_seq issues Jiayuan Chen
2025-11-17 11:07 ` [PATCH bpf-next v1 1/3] bpf, sockmap: Fix incorrect copied_seq calculation Jiayuan Chen
2025-11-19 19:53 ` Jakub Sitnicki
2025-11-20 2:49 ` Jiayuan Chen
2025-11-20 12:58 ` Jakub Sitnicki
2025-11-20 14:03 ` Jiayuan Chen [this message]
2025-11-17 11:07 ` [PATCH bpf-next v1 2/3] bpf, sockmap: Fix FIONREAD for sockmap Jiayuan Chen
2025-11-17 11:07 ` [PATCH bpf-next v1 3/3] bpf, selftest: Add tests for FIONREAD and copied_seq Jiayuan Chen
2025-11-21 19:12 ` [syzbot ci] Re: bpf: Fix FIONREAD and copied_seq issues syzbot ci
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=b6c033deb75243e285fa6b028ee666f874b75eb8@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=horms@kernel.org \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mhal@rbox.co \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).