From: Leon Hwang <leon.hwang@linux.dev>
To: bot+bpf-ci@kernel.org, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev,
rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com, kpsingh@kernel.org,
matt@bobrowski.net, shuah@kernel.org,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
martin.lau@kernel.org, mason@kernel.org
Subject: Re: [PATCH bpf-next v3 4/9] bpf: Add log support for cgroup prog link_create
Date: Tue, 24 Nov 2026 14:27:03 +0800 [thread overview]
Message-ID: <fd8bf876-6e10-4183-96da-8778f8c4ca3f@linux.dev> (raw)
In-Reply-To: <ec5343ff7b660c9126b72574cd89cbd54772bd4291d4af16f1b9e39f16939398@mail.kernel.org>
On 24/11/26 00:04, bot+bpf-ci@kernel.org wrote:
>> bpf: Add log support for cgroup prog link_create
>
> TL;DR: The new bpf_log() calls in cgroup attach run under cgroup_mutex and
> cgroup_bpf_mutex, so a copy_to_user() fault on the user log buffer may stall
> other cgroup operations. Consider logging after unlock.
>
>> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
>> --- a/kernel/bpf/cgroup.c
>> +++ b/kernel/bpf/cgroup.c
>
> [ ... ]
>
>> @@ -1045,23 +1060,33 @@ static int __cgroup_bpf_attach(struct cgroup *cgrp,
>> atype = bpf_cgroup_atype_find(type, new_prog->aux->attach_btf_id);
>> if (atype < 0)
>> return -EINVAL;
>> - if (revision && revision != cgrp->bpf.revisions[atype])
>> + if (revision && revision != cgrp->bpf.revisions[atype]) {
>> + bpf_log(log, "Cgroup revision mismatch: expected %llu, actual %llu.\n",
>> + revision, cgrp->bpf.revisions[atype]);
>> return -ESTALE;
>> + }
>
> [ ... ]
>
>> @@ -1143,13 +1168,14 @@ static int cgroup_bpf_attach(struct cgroup *cgrp,
>> cgroup_bpf_lock_hierarchy();
>> ret = __cgroup_bpf_attach(cgrp, prog, replace_prog, link, type, flags,
>> - id_or_fd, revision);
>> + id_or_fd, revision, log);
>> cgroup_bpf_unlock_hierarchy();
>> return ret;
>
> Can these bpf_log() calls block other cgroup users while the locks are
> held?
>
> cgroup_bpf_attach() takes cgroup_mutex and cgroup_bpf_mutex through
> cgroup_bpf_lock_hierarchy() before calling __cgroup_bpf_attach(), and
> the new messages are emitted from inside it (and from get_prog_list()
> via insert_pl_to_hlist()):
>
> cgroup_bpf_attach()
> cgroup_bpf_lock_hierarchy()
> __cgroup_bpf_attach()
> bpf_log()
> bpf_verifier_vlog()
> copy_to_user(log->ubuf + ..., log->kbuf, ...)
>
> log->ubuf is the user supplied log_buf, so if that page is not resident
> (swapped out, or backed by FUSE or userfaultfd), copy_to_user() can sleep
> in the fault for as long as the caller chooses. While it sleeps,
> cgroup_mutex and cgroup_bpf_mutex remain held, so cgroup mkdir/rmdir,
> migration, BPF attach/detach, BPF_PROG_QUERY and the cgroup bpf release
> work would all wait.
>
> Commit 40aec6bab02e ("bpf, cgroup: Protect cgroup_bpf state with its own
> mutex") split these paths out from cgroup_mutex to avoid hung tasks, and
> before this patch the attach path did not touch user memory under these
> locks.
>
> This isn't a lock ordering problem, since cgroup_mutex -> mmap_lock
> already exists, but would it be better to record the message and emit it
> from cgroup_bpf_link_attach() after cgroup_bpf_unlock_hierarchy()?
I think it's okay to call bpf_log() inside those locks' critical
section, even though copy_to_user() could unlikely trigger page fault.
I didn't have good idea to address such concern. Probably, in
cgroup_bpf_attach(), prepare a local buffer before
cgroup_bpf_lock_hierarchy(), pass the buffer to __cgroup_bpf_attach() in
order to store the log messages, then call bpf_log() after
cgroup_bpf_unlock_hierarchy() if __cgroup_bpf_attach() returns error.
Thanks,
Leon
next prev parent reply other threads:[~2026-11-24 6:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:27 [PATCH bpf-next v3 0/9] bpf: Add log support for tracing link_create Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 1/9] " Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 2/9] bpf: Add log support for tracing_multi link_create Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 3/9] bpf: Add log support for iter link_create Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 4/9] bpf: Add log support for cgroup prog link_create Leon Hwang
2026-11-23 16:04 ` bot+bpf-ci
2026-11-24 6:27 ` Leon Hwang [this message]
2026-11-23 15:27 ` [PATCH bpf-next v3 5/9] libbpf: Add log_opts support for BPF_TRACE_ITER Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 6/9] selftests/bpf: Test tracing link_create logs Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 7/9] selftests/bpf: Test tracing_multi " Leon Hwang
2026-11-23 16:04 ` bot+bpf-ci
2026-11-23 22:04 ` Jiri Olsa
2026-11-23 15:27 ` [PATCH bpf-next v3 8/9] selftests/bpf: Verify iter " Leon Hwang
2026-11-23 15:27 ` [PATCH bpf-next v3 9/9] selftests/bpf: Verify cgroup prog " Leon Hwang
2026-11-24 0:12 ` [PATCH bpf-next v3 0/9] bpf: Add log support for tracing link_create Alexei Starovoitov
2026-11-24 6:25 ` Leon Hwang
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=fd8bf876-6e10-4183-96da-8778f8c4ca3f@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®