From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
To: "Cong Wang" <xiyou.wangcong@gmail.com>
Cc: bpf@vger.kernel.org, mrpre@163.com,
"Boris Pismenny" <borisp@nvidia.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@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>,
"Mykola Lysenko" <mykolal@fb.com>,
"Shuah Khan" <shuah@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 1/2] ktls, sockmap: Fix missing uncharge operation
Date: Tue, 29 Apr 2025 01:55:53 +0000 [thread overview]
Message-ID: <048b968d1993ca84e3442da936bc8e4be07d98f4@linux.dev> (raw)
In-Reply-To: <aBAZ/p0Yj2kFGHhg@pop-os.localdomain>
2025/4/29 08:14, "Cong Wang" <xiyou.wangcong@gmail.com> wrote:
>
> On Fri, Apr 25, 2025 at 01:59:57PM +0800, Jiayuan Chen wrote:
>
> >
> > net/tls/tls_sw.c | 7 +++++++
> >
> > 1 file changed, 7 insertions(+)
> >
> >
> >
> > diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> >
> > index f3d7d19482da..fc88e34b7f33 100644
> >
> > --- a/net/tls/tls_sw.c
> >
> > +++ b/net/tls/tls_sw.c
> >
> > @@ -908,6 +908,13 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
> >
> > &msg_redir, send, flags);
> >
> > lock_sock(sk);
> >
> > if (err < 0) {
> >
> > + /* Regardless of whether the data represented by
> >
> > + * msg_redir is sent successfully, we have already
> >
> > + * uncharged it via sk_msg_return_zero(). The
> >
> > + * msg->sg.size represents the remaining unprocessed
> >
> > + * data, which needs to be uncharged here.
> >
> > + */
> >
> > + sk_mem_uncharge(sk, msg->sg.size);
> >
> > *copied -= sk_msg_free_nocharge(sk, &msg_redir);
> >
>
> Equivalent to sk_msg_free() ?
>
> Thanks.
>
Before calling tcp_bpf_sendmsg_redir(), we have already uncharged some
memory using sk_msg_return_zero(). If we perform sk_msg_free(msg_redir),
it will cause the duplicate uncharge of this part of data. If we perform
sk_msg_free(msg), since tcp_bpf_sendmsg_redir() may not have sent any data
and msg->sg.start no longer points to this part of data, it will lead to
memoryleak.
So, directly calling sk_msg_free is not a good idea.
next prev parent reply other threads:[~2025-04-29 1:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 5:59 [PATCH bpf-next v1 0/2] ktls, sockmap: Fix missing uncharge operation and add selfttest Jiayuan Chen
2025-04-25 5:59 ` [PATCH bpf-next v1 1/2] ktls, sockmap: Fix missing uncharge operation Jiayuan Chen
2025-04-29 0:14 ` Cong Wang
2025-04-29 1:55 ` Jiayuan Chen [this message]
2025-05-04 20:19 ` Cong Wang
2025-04-25 5:59 ` [PATCH bpf-next v1 2/2] selftests/bpf: Add test to cover sockmap with ktls Jiayuan Chen
2025-05-02 5:26 ` [PATCH bpf-next v1 0/2] ktls, sockmap: Fix missing uncharge operation and add selfttest John Fastabend
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=048b968d1993ca84e3442da936bc8e4be07d98f4@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=borisp@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mrpre@163.com \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=xiyou.wangcong@gmail.com \
--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).