[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b75bbc3f-85fd-4209-9ce1-3bf685ba62ff@rbox.co>
Date: Wed, 11 Feb 2026 11:02:27 +0100
From: Michal Luczaj <mhal@...x.co>
To: Martin KaFai Lau <martin.lau@...ux.dev>,
Kuniyuki Iwashima <kuniyu@...gle.com>
Cc: John Fastabend <john.fastabend@...il.com>,
Jakub Sitnicki <jakub@...udflare.com>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
Willem de Bruijn <willemb@...gle.com>, Cong Wang <cong.wang@...edance.com>,
Alexei Starovoitov <ast@...nel.org>, Yonghong Song <yhs@...com>,
Andrii Nakryiko <andrii@...nel.org>, Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>,
KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
Shuah Khan <shuah@...nel.org>, netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH bpf v2 3/4] bpf, sockmap: Adapt for the af_unix-specific
lock
On 2/9/26 21:17, Martin KaFai Lau wrote:
> On 2/8/26 9:14 AM, Michal Luczaj wrote:
>> On 2/7/26 23:00, Kuniyuki Iwashima wrote:
>>> On Sat, Feb 7, 2026 at 6:35 AM Michal Luczaj <mhal@...x.co> wrote:
>>>> This patch also happens to fix a deadlock that may occur when
>>>> bpf_iter_unix_seq_show()'s lock_sock_fast() takes the fast path and the
>>>> iter prog attempts to update a sockmap. Which ends up spinning at
>>>> sock_map_update_elem()'s bh_lock_sock():
>>>
>>> Hmm.. this seems to be a more general problem for
>>> bpf iter vs sockmap. bpf_iter_{tcp,udp}_seq_show() also
>>> hold lock_sock(), where this patch's solution does not help.
>>> We need to resolve this regardless of socket family.
>>
>> I don't see any deadlocks there. Note that I've mentioned lock_sock_fast()
>> fast path was a problem, not lock_sock().
>
> For the tcp/udp, I think the bpf_iter should be fine: lock_sock() in
> seq_show and bh_lock_sock() in map_update. It seems redundant though.
I wasn't sure what exactly you suspect of being redundant, so I did some
digging:
lock_sock() in tcp/udp iter is expected (among others?) by kfunc
bpf_sock_destroy(). Relevant commit 4ddbcb886268 ("bpf: Add
bpf_sock_destroy kfunc"),
https://lore.kernel.org/all/20230519225157.760788-8-aditi.ghag@isovalent.com/
In short: lock must be taken for synchronization of proto::diag_destroy().
Reasons for bh_lock_sock() during bpf sockmap update are explained in
commit 0126240f448d ("bpf: sockmap: Allow update from BPF"),
https://lore.kernel.org/bpf/20200821102948.21918-6-lmb@cloudflare.com/
In short: socket shouldn't be allowed to change its state during the
update. BH lock because bpf can't sleep.
> From looking at may_update_sockmap(), other bpf progs (e.g., tc) can do
> map_update also. On those paths, I am not sure why
> sock_map_update_elem() does not need to check "!sock_owned_by_user(sk)".
> If it is indeed an issue, it probably needs to be addressed separately.
Since sockmap update can happen in a tracing prog, can you really expect a
socket to be always owned?
> It should also be helpful to be consistent with tcp/udp iter and use
> lock_sock() instead of lock_sock_fast() in bpf_iter_unix_seq_show().
OK, I'll tweak that in v3.
Powered by blists - more mailing lists