From: Yonghong Song <yonghong.song@linux.dev>
To: Eduard Zingerman <eddyz87@gmail.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jakub Sitnicki <jakub@cloudflare.com>,
John Fastabend <john.fastabend@gmail.com>,
kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v6 1/5] bpf: Add bpf_link support for sk_msg and sk_skb progs
Date: Tue, 9 Apr 2024 08:28:29 -0700 [thread overview]
Message-ID: <54361423-20a4-43fb-997b-ec0ef064c218@linux.dev> (raw)
In-Reply-To: <b5df14d028562c863e65c27af82250c14395f513.camel@gmail.com>
On 4/9/24 2:52 AM, Eduard Zingerman wrote:
> On Mon, 2024-04-08 at 08:24 -0700, Yonghong Song wrote:
>
> [...]
>
>
>> +/* Handle the following two cases:
>> + * case 1: link != NULL, prog != NULL, old != NULL
>> + * case 2: link != NULL, prog != NULL, old == NULL
>> + */
>> +static int sock_map_link_update_prog(struct bpf_link *link,
>> + struct bpf_prog *prog,
>> + struct bpf_prog *old)
>> +{
>> + const struct sockmap_link *sockmap_link = container_of(link, struct sockmap_link, link);
>> + struct bpf_prog **pprog, *old_link_prog;
>> + struct bpf_link **plink;
>> + int ret = 0;
>> +
>> + mutex_lock(&sockmap_mutex);
>> +
>> + /* If old prog is not NULL, ensure old prog is the same as link->prog. */
>> + if (old && link->prog != old) {
>> + ret = -EPERM;
>> + goto out;
>> + }
>> + /* Ensure link->prog has the same type/attach_type as the new prog. */
>> + if (link->prog->type != prog->type ||
>> + link->prog->expected_attach_type != prog->expected_attach_type) {
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>> + ret = sock_map_prog_link_lookup(sockmap_link->map, &pprog, &plink,
>> + sockmap_link->attach_type);
>> + if (ret)
>> + goto out;
>> +
>> + /* return error if the stored bpf_link does not match the incoming bpf_link. */
>> + if (link != *plink)
>> + return -EBUSY;
> Hi Yonghong,
>
> Sorry, this was a mistake on my side,
> this needs a 'goto out' in order to unlock the mutex.
It is my fault as well since I missed it too. Will send a revision later today
just in case there are more comments.
>
> Thanks,
> Eduard
>
>> +
>> + if (old) {
>> + ret = psock_replace_prog(pprog, prog, old);
>> + if (ret)
>> + goto out;
>> + } else {
>> + psock_set_prog(pprog, prog);
>> + }
>> +
>> + bpf_prog_inc(prog);
>> + old_link_prog = xchg(&link->prog, prog);
>> + bpf_prog_put(old_link_prog);
>> +
>> +out:
>> + mutex_unlock(&sockmap_mutex);
>> + return ret;
>> +}
next prev parent reply other threads:[~2024-04-09 15:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 15:24 [PATCH bpf-next v6 0/5] bpf: Add bpf_link support for sk_msg and sk_skb progs Yonghong Song
2024-04-08 15:24 ` [PATCH bpf-next v6 1/5] " Yonghong Song
2024-04-09 9:52 ` Eduard Zingerman
2024-04-09 15:28 ` Yonghong Song [this message]
2024-04-08 15:24 ` [PATCH bpf-next v6 2/5] libbpf: Add bpf_link support for BPF_PROG_TYPE_SOCKMAP Yonghong Song
2024-04-08 15:24 ` [PATCH bpf-next v6 3/5] bpftool: Add link dump support for BPF_LINK_TYPE_SOCKMAP Yonghong Song
2024-04-08 15:24 ` [PATCH bpf-next v6 4/5] selftests/bpf: Refactor out helper functions for a few tests Yonghong Song
2024-04-08 15:24 ` [PATCH bpf-next v6 5/5] selftests/bpf: Add some tests with new bpf_program__attach_sockmap() APIs Yonghong Song
2024-04-09 7:55 ` Eduard Zingerman
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=54361423-20a4-43fb-997b-ec0ef064c218@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@kernel.org \
/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