From: Peter Zijlstra <peterz@infradead.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ruan Bonan <bonan.ruan@u.nus.edu>,
"mingo@redhat.com" <mingo@redhat.com>,
"will@kernel.org" <will@kernel.org>,
"longman@redhat.com" <longman@redhat.com>,
"boqun.feng@gmail.com" <boqun.feng@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"kpsingh@kernel.org" <kpsingh@kernel.org>,
"mattbobrowski@google.com" <mattbobrowski@google.com>,
"ast@kernel.org" <ast@kernel.org>,
"daniel@iogearbox.net" <daniel@iogearbox.net>,
"andrii@kernel.org" <andrii@kernel.org>,
"martin.lau@linux.dev" <martin.lau@linux.dev>,
"eddyz87@gmail.com" <eddyz87@gmail.com>,
"song@kernel.org" <song@kernel.org>,
"yonghong.song@linux.dev" <yonghong.song@linux.dev>,
"john.fastabend@gmail.com" <john.fastabend@gmail.com>,
"sdf@fomichev.me" <sdf@fomichev.me>,
"haoluo@google.com" <haoluo@google.com>,
"jolsa@kernel.org" <jolsa@kernel.org>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"mathieu.desnoyers@efficios.com" <mathieu.desnoyers@efficios.com>,
"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
"linux-trace-kernel@vger.kernel.org"
<linux-trace-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
Fu Yeqi <e1374359@u.nus.edu>,
akinobu.mita@gmail.com, tytso@mit.edu, Jason@zx2c4.com
Subject: Re: [BUG] possible deadlock in __schedule (with reproducer available)
Date: Fri, 29 Nov 2024 13:09:39 +0100 [thread overview]
Message-ID: <20241129120939.GG35539@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20241129173554.11e3b2b2f5126c2b72c6a78e@kernel.org>
On Fri, Nov 29, 2024 at 05:35:54PM +0900, Masami Hiramatsu wrote:
> On Sat, 23 Nov 2024 03:39:45 +0000
> Ruan Bonan <bonan.ruan@u.nus.edu> wrote:
>
> >
> > vprintk_emit+0x414/0xb90 kernel/printk/printk.c:2406
> > _printk+0x7a/0xa0 kernel/printk/printk.c:2432
> > fail_dump lib/fault-inject.c:46 [inline]
> > should_fail_ex+0x3be/0x570 lib/fault-inject.c:154
> > strncpy_from_user+0x36/0x230 lib/strncpy_from_user.c:118
> > strncpy_from_user_nofault+0x71/0x140 mm/maccess.c:186
> > bpf_probe_read_user_str_common kernel/trace/bpf_trace.c:215 [inline]
> > ____bpf_probe_read_user_str kernel/trace/bpf_trace.c:224 [inline]
>
> Hmm, this is a combination issue of BPF and fault injection.
>
> static void fail_dump(struct fault_attr *attr)
> {
> if (attr->verbose > 0 && __ratelimit(&attr->ratelimit_state)) {
> printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure.\n"
> "name %pd, interval %lu, probability %lu, "
> "space %d, times %d\n", attr->dname,
> attr->interval, attr->probability,
> atomic_read(&attr->space),
> atomic_read(&attr->times));
>
> This printk() acquires console lock under rq->lock has been acquired.
>
> This can happen if we use fault injection and trace event too because
> the fault injection caused printk warning.
Ah indeed. Same difference though, if you don't know the context, most
things are unsafe to do.
> I think this should be a bug of the fault injection, not tracing/BPF.
> And to solve this issue, we may be able to check the context and if
> it is tracing/NMI etc, fault injection should NOT make it failure.
Well, it should be okay to cause the failure, but it must be very
careful how it goes about doing that. Tripping printk() definitely is
out.
But there's a much bigger problem there, get_random*() is not wait-free,
in fact it takes a spinlock_t which makes that it is unusable from most
context, and it's definitely out for tracing.
Notably, this spinlock_t makes that it is unsafe to use from anything
that holds a raw_spinlock_t or is from hardirq context, or has
preempt_disable() -- which is a TON of code.
On this alone I would currently label the whole of fault-injection
broken. The should_fail() call itself is unsafe where many of its
callsites are otherwise perfectly fine -- eg. usercopy per the above.
Perhaps it should use a simple PRNG, a simple LFSR should be plenty good
enough to provide failure conditions.
And yeah, I would just completely rip out the printk. Trying to figure
out where and when it's safe to call printk() is non-trivial and just
not worth the effort imo.
next prev parent reply other threads:[~2024-11-29 12:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-23 3:39 [BUG] possible deadlock in __schedule (with reproducer available) Ruan Bonan
2024-11-23 20:27 ` Peter Zijlstra
2024-11-23 23:00 ` Steven Rostedt
2024-11-25 2:02 ` Alexei Starovoitov
2024-11-25 3:30 ` Steven Rostedt
2024-11-25 3:44 ` Steven Rostedt
2024-11-25 5:24 ` Ruan Bonan
2024-11-25 9:44 ` Peter Zijlstra
2024-11-26 21:15 ` Andrii Nakryiko
2024-11-27 23:03 ` Hillf Danton
2024-11-28 2:27 ` Alexei Starovoitov
2024-11-28 4:48 ` Hillf Danton
2024-11-29 8:35 ` Masami Hiramatsu
2024-11-29 12:09 ` Peter Zijlstra [this message]
2024-12-01 12:53 ` Akinobu Mita
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=20241129120939.GG35539@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Jason@zx2c4.com \
--cc=akinobu.mita@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bonan.ruan@u.nus.edu \
--cc=boqun.feng@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=e1374359@u.nus.edu \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mattbobrowski@google.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tytso@mit.edu \
--cc=will@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