From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796228792; b=Pqc42GnbKXRkUsfU2NeyAfOL5PNUvO7p69Gm8PkhnZTxuRvfDBWtXVW+Q/AeXv5RQN14 v1IEHmc+ohFK65l8TwwA3AJmRR10umfFTlE/7G1Zj5Kz0JuxWFQK+EwpUx4wqqnSxWQX1 6yKQoSJbHjyKcyv5ZvYXjRl03kKK0pTE+ldPfIIVqPs+4k43bAY/v7HQoasg6JDppTgny a1GAvd4KxFkGdg15Zahwq6BXrDfou2c49poQQDV2xy68y3mARgLuouwqr62XhMvaIwohy INKeymPmEtzFACvZI4iC5Y0+YJ2S4GGrjV1jQfZSB/06paiQU4qLQ/tK8wyUg1tlwXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796228792; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=PbED3ecEmKsw8sf+j1BIgn+XHyTph0Vfaz/jGnZhDcc=; b=SgRr3G6yQ9eMfDzymAZFr+rqMrr0pWyNyurjlutjm2+FAz1c0+L76ARDMjfEFzNkwhwC Kw0y0qTO3pHV7/gyLhI2yhIHTvkz9ZDeEqNAVNS2UN6iF9+bkvQ+OfTsoHHnxjthyI33O l2KB/gKmhT28QxZe2YZpLBt897kHdQBhgemxoAPQB66PiduXcuYOe38rnYXNDaiYNPfKL n/yx1g27h0plfPLEgwe52Q0z0LSEFh6tde7cttE4FF6ERwEkwAd9758A5bKAMUsCpoE1H ZLZU78237QrhGyVygh7ycgpXoMovIi1ZAsrQ13rlDJRhOA65xfUMP+36wQ4G7SnmLwA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X5fnzW6d; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91296606A31A; Wed, 2 Dec 2026 16:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=X5fnzW6d Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DD801F00896; Wed, 2 Dec 2026 16:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796228791; bh=PbED3ecEmKsw8sf+j1BIgn+XHyTph0Vfaz/jGnZhDcc=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=X5fnzW6dP2YGKZMsXUll5ev1mYnWUtGJpJdp1ts4oQ3+rKTCQOwmMq+np4Ii4yk5g 9zmAV+E95NaRLxBIYR4OUSqxk69xxA5f4DAgpFwWtXh5QhPxj0M3hwCT7jtAnjXSCu VdxuwLWs2OEs7G3RoNP1Hy16bsOjLV4qS7/XAaUBYgw+QX122Ymk/3s2RGVqxhBf15 5Wlc827hxWMYKMirIoEoC+VLty+6bktukghb9J0Ux6K/qt6OJHk2wliPwn6OnSweSZ M9P2EjQCNfUPLeywYJ/WMayiBze9NLJzbX8wr5oWkQYN2wFybMhr9feeF2BPgo5a0g Moo6+PM0eVS+g== Content-Type: multipart/mixed; boundary="===============8390180443241473998==" X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: In-Reply-To: <20261202153739.57959-2-leon.hwang@linux.dev> References: <20261202153739.57959-2-leon.hwang@linux.dev> Subject: Re: [PATCH bpf-next 1/4] bpf: Add log support for perf link_create From: bot+bpf-ci@kernel.org To: leon.hwang@linux.dev,bpf@vger.kernel.org Cc: ast@kernel.org,daniel@iogearbox.net,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,john.fastabend@gmail.com,rostedt@goodmis.org,mhiramat@kernel.org,mathieu.desnoyers@efficios.com,peterz@infradead.org,mingo@redhat.com,acme@kernel.org,namhyung@kernel.org,mark.rutland@arm.com,alexander.shishkin@linux.intel.com,irogers@google.com,adrian.hunter@intel.com,james.clark@linaro.org,kpsingh@kernel.org,matt@bobrowski.net,shuah@kernel.org,leon.hwang@linux.dev,linux-kernel@vger.kernel.org,linux-trace-kernel@vger.kernel.org,linux-perf-users@vger.kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev Date: Wed, 2 Dec 2026 16:26:28 +0000 (UTC) --===============8390180443241473998== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > bpf: Add log support for perf link_create TL;DR: bpf_log() under bpf_event_mutex in perf_event_attach_bpf_prog() may fault on the user log buffer, possibly causing an ABBA deadlock with mmap_lock or stalling all perf BPF attaches; log after unlocking. > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c [ ... ] > mutex_lock(&bpf_event_mutex); > > - if (event->prog) > + if (event->prog) { > + bpf_log(log, "Target perf event already has a program attached.\n"); > goto unlock; > + } > > old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); > if (old_array && > bpf_prog_array_length(old_array) >= BPF_TRACE_MAX_PROGS) { > + bpf_log(log, "Too many programs (limit %d).\n", BPF_TRACE_MAX_PROGS); > ret = -E2BIG; > goto unlock; > } > > ret = bpf_prog_array_copy(old_array, NULL, prog, bpf_cookie, &new_array); > + if (ret == -EEXIST) > + bpf_log(log, "Program already attached to this trace event.\n"); > if (ret < 0) > goto unlock; Can these bpf_log() calls run safely under bpf_event_mutex? On the BPF_LINK_CREATE path the log is a user log, so bpf_log() ends up in bpf_verifier_vlog(), which calls copy_to_user() on log->ubuf. That can fault, and might_fault() tells lockdep about current->mm->mmap_lock. This records a bpf_event_mutex -> mmap_lock dependency. The opposite order already exists: perf_mmap_close() [mmap_lock held via remove_vma()] put_event() [last reference] _free_event() perf_event_free_bpf_prog() perf_event_detach_bpf_prog() mutex_lock(&bpf_event_mutex); Can this produce an ABBA deadlock between mmap_lock and bpf_event_mutex when the log page has to be faulted in? It looks like the same inversion that commit 3a38bb98d9ab ("bpf/tracing: fix a deadlock in perf_event_detach_bpf_prog") fixed by moving copy_to_user() out of bpf_event_mutex in perf_event_query_prog_array(), which still copies to user only after mutex_unlock(&bpf_event_mutex). The failing checks are easy to reach from userspace. Calling BPF_LINK_CREATE twice on the same tracepoint, kprobe or uprobe perf fd hits the event->prog branch, and attaching the same program through a second perf event on the same trace event returns -EEXIST from bpf_prog_array_copy(). Also, since bpf_event_mutex is global, could a slow or never-completing fault on the log buffer (for example a FUSE-backed mapping) block every perf-based BPF attach, detach and PERF_EVENT_IOC_QUERY_BPF on the system? The bpf_log() calls made under ctx->mutex in __perf_event_set_bpf_prog() and perf_event_set_bpf_handler(), and the kprobe_override message before mutex_lock(), look fine. Would it work to record the failure reason inside the critical section (for example in a const char *msg) and call bpf_log() after mutex_unlock(&bpf_event_mutex)? No later commit in the series changes perf_event_attach_bpf_prog(). --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46921726766 --===============8390180443241473998==--