From: Kui-Feng Lee <sinquersw@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Kui-Feng Lee <thinker.li@gmail.com>, bpf <bpf@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>, Song Liu <song@kernel.org>,
Kernel Team <kernel-team@meta.com>,
Andrii Nakryiko <andrii@kernel.org>,
Kui-Feng Lee <kuifeng@meta.com>
Subject: Re: [PATCH bpf-next 3/6] bpf: provide a function to unregister struct_ops objects from consumers.
Date: Fri, 3 May 2024 11:09:28 -0700 [thread overview]
Message-ID: <80a59f2c-e82b-427a-88eb-568301437b95@gmail.com> (raw)
In-Reply-To: <CAADnVQK6NqyFrjW29m-02GuS0jFyxyWWNySp+82N2+oaVZNg8A@mail.gmail.com>
On 5/3/24 09:19, Alexei Starovoitov wrote:
> On Thu, May 2, 2024 at 5:41 PM Kui-Feng Lee <sinquersw@gmail.com> wrote:
>>
>>
>>>>> + prev_state = cmpxchg(&st_map->kvalue.common.state,
>>>>> + BPF_STRUCT_OPS_STATE_INUSE,
>>>>> + BPF_STRUCT_OPS_STATE_TOBEFREE);
>
> All the uses of cmpxchg mean that there are races.
> I know there is already a case for it in the existing code
> and maybe it's justified.
> But I would very much prefer the whole code converted to
> clean locks without cmpxchg tricks.
>
>
>>>>> + if (prev_state == BPF_STRUCT_OPS_STATE_INUSE) {
>>>>> + st_map->st_ops_desc->st_ops->unreg(data);
>>>>> + /* Pair with bpf_map_inc() for reg() */
>>>>> + bpf_map_put(&st_map->map);
>>>>> + /* Pair with bpf_map_inc_not_zero() above */
>>>>> + bpf_map_put(&st_map->map);
>>>>> + return true;
>
> I haven't tried to follow the logic, but double bpf_map_put
> on the same map screams that this is broken.
> Do proper locks everywhere.
> inc_not_zero and cmpxchg shouldn't be needed.
> keep it simple.
Got it!
next prev parent reply other threads:[~2024-05-03 18:09 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 21:36 [PATCH bpf-next 0/6] Notify user space when a struct_ops object is detached/unregisterd Kui-Feng Lee
2024-04-29 21:36 ` [PATCH bpf-next 1/6] bpf: add a pointer of the attached link to bpf_struct_ops_map Kui-Feng Lee
2024-05-01 17:01 ` Andrii Nakryiko
2024-05-01 22:15 ` Kui-Feng Lee
2024-04-29 21:36 ` [PATCH bpf-next 2/6] bpf: export bpf_link_inc_not_zero() Kui-Feng Lee
2024-04-29 21:36 ` [PATCH bpf-next 3/6] bpf: provide a function to unregister struct_ops objects from consumers Kui-Feng Lee
2024-05-01 18:48 ` Martin KaFai Lau
2024-05-01 22:15 ` Kui-Feng Lee
2024-05-01 23:06 ` Martin KaFai Lau
2024-05-02 17:56 ` Martin KaFai Lau
2024-05-02 18:29 ` Martin KaFai Lau
2024-05-03 0:41 ` Kui-Feng Lee
2024-05-03 16:19 ` Alexei Starovoitov
2024-05-03 18:09 ` Kui-Feng Lee [this message]
2024-05-03 17:17 ` Martin KaFai Lau
2024-04-29 21:36 ` [PATCH bpf-next 4/6] bpf: detach a bpf_struct_ops_map from a link Kui-Feng Lee
2024-04-29 21:36 ` [PATCH bpf-next 5/6] bpf: support epoll from bpf struct_ops links Kui-Feng Lee
2024-05-01 17:03 ` Andrii Nakryiko
2024-05-01 22:16 ` Kui-Feng Lee
2024-04-29 21:36 ` [PATCH bpf-next 6/6] selftests/bpf: test detaching " Kui-Feng Lee
2024-05-01 17:05 ` Andrii Nakryiko
2024-05-01 22:17 ` Kui-Feng Lee
2024-05-02 18:15 ` Martin KaFai Lau
2024-05-03 18:34 ` Kui-Feng Lee
2024-05-03 19:15 ` Martin KaFai Lau
2024-05-03 21:34 ` Kui-Feng Lee
2024-05-03 21:59 ` Martin KaFai Lau
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=80a59f2c-e82b-427a-88eb-568301437b95@gmail.com \
--to=sinquersw@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--cc=song@kernel.org \
--cc=thinker.li@gmail.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 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).