From: Leon Hwang <leon.hwang@linux.dev>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Amery Hung <ameryhung@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-patches-bot@fb.com
Subject: Re: [PATCH bpf-next v4 3/4] bpf: Free special fields when update local storage maps with BPF_F_LOCK
Date: Mon, 3 Nov 2025 13:17:56 +0800 [thread overview]
Message-ID: <22f12031-7a19-4824-a9cc-459fb63a5e0e@linux.dev> (raw)
In-Reply-To: <CAADnVQLib8ebe8cmGRj98YZiArendX8u=dSKNUrUFz6NGq7LRg@mail.gmail.com>
On 31/10/25 06:35, Alexei Starovoitov wrote:
> On Thu, Oct 30, 2025 at 8:25 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>>
[...]
>> @@ -641,6 +642,7 @@ bpf_local_storage_update(void *owner, struct bpf_local_storage_map *smap,
>> if (old_sdata && (map_flags & BPF_F_LOCK)) {
>> copy_map_value_locked(&smap->map, old_sdata->data, value,
>> false);
>> + bpf_obj_free_fields(smap->map.record, old_sdata->data);
>> selem = SELEM(old_sdata);
>> goto unlock;
>> }
>
> Even with rqspinlock I feel this is a can of worms and
> recursion issues.
>
> I think it's better to disallow special fields and BPF_F_LOCK combination.
> We already do that for uptr:
> if ((map_flags & BPF_F_LOCK) &&
> btf_record_has_field(map->record, BPF_UPTR))
> return -EOPNOTSUPP;
>
> let's do it for all special types.
> So patches 2 and 3 will change to -EOPNOTSUPP.
>
Do you mean disallowing the combination of BPF_F_LOCK with other special
fields (except for BPF_SPIN_LOCK) on the UAPI side — for example, in
lookup_elem() and update_elem()?
If so, I'd like to send a separate patch set to implement that after the
series
“bpf: Introduce BPF_F_CPU and BPF_F_ALL_CPUS flags for percpu maps” is
applied.
After that, we can easily add the check in bpf_map_check_op_flags() for
the UAPI side, like this:
static inline int bpf_map_check_op_flags(...)
{
if ((flags & BPF_F_LOCK) && !btf_record_has_field(map->record,
BPF_SPIN_LOCK))
return -EINVAL;
if ((flags & BPF_F_LOCK) && btf_record_has_field(map->record,
~BPF_SPIN_LOCK))
return -EOPNOTSUPP;
}
Then we can clean up some code, including the bpf_obj_free_fields()
calls that follow copy_map_value_locked(), as well as the existing UPTR
check.
Thanks,
Leon
next prev parent reply other threads:[~2025-11-03 5:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 15:24 [PATCH bpf-next v4 0/4] bpf: Free special fields when update hash and local storage maps Leon Hwang
2025-10-30 15:24 ` [PATCH bpf-next v4 1/4] bpf: Free special fields when update [lru_,]percpu_hash maps Leon Hwang
2025-10-30 15:24 ` [PATCH bpf-next v4 2/4] bpf: Free special fields when update hash maps with BPF_F_LOCK Leon Hwang
2025-10-30 15:24 ` [PATCH bpf-next v4 3/4] bpf: Free special fields when update local storage " Leon Hwang
2025-10-30 22:35 ` Alexei Starovoitov
2025-11-03 5:17 ` Leon Hwang [this message]
2025-11-03 17:24 ` Alexei Starovoitov
2025-10-30 15:24 ` [PATCH bpf-next v4 4/4] selftests/bpf: Add tests to verify freeing the special fields when update hash and local storage maps Leon Hwang
2025-11-04 17:30 ` Yonghong Song
2025-11-05 2:14 ` Leon Hwang
2025-11-05 3:35 ` Yonghong Song
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=22f12031-7a19-4824-a9cc-459fb63a5e0e@linux.dev \
--to=leon.hwang@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-patches-bot@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=sdf@fomichev.me \
--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 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.