Re: [PATCH 0/9] TRACE_IRQFLAGS wreckage

From: Marco Elver
Date: Thu Aug 20 2020 - 13:21:31 EST


On Thu, Aug 20, 2020 at 04:58PM +0200, peterz@xxxxxxxxxxxxx wrote:
> On Thu, Aug 20, 2020 at 10:36:43AM -0400, Steven Rostedt wrote:
> >
> > I tested this series on top of tip/master and triggered the below
> > warning when running the irqsoff tracer boot up test (config attached).
> >
> > -- Steve
> >
> > Testing tracer irqsoff:
> >
> > =============================
> > WARNING: suspicious RCU usage
> > 5.9.0-rc1-test+ #92 Not tainted
> > -----------------------------
> > include/trace/events/lock.h:13 suspicious rcu_dereference_check() usage!
...
>
> Shiny, I think that wants something like the below, but let me go frob
> my config and test it.
>
> ---
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
...

With that applied (manually, due to conflicts), I still get warnings for
certain call locations with KCSAN on (that is with my fix from the other
email):

| =============================
| WARNING: suspicious RCU usage
| 5.9.0-rc1+ #23 Tainted: G W
| -----------------------------
| include/trace/events/random.h:310 suspicious rcu_dereference_check() usage!
|
| other info that might help us debug this:
|
|
| rcu_scheduler_active = 2, debug_locks = 0
| RCU used illegally from extended quiescent state!
| no locks held by swapper/1/0.
|
| stack backtrace:
| CPU: 1 PID: 0 Comm: swapper/1 Tainted: G W 5.9.0-rc1+ #23
| Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014
| Call Trace:
| __dump_stack lib/dump_stack.c:77 [inline]
| dump_stack+0xf1/0x14d lib/dump_stack.c:118
| trace_prandom_u32 include/trace/events/random.h:310 [inline]
| prandom_u32+0x1ee/0x200 lib/random32.c:86
| prandom_u32_max include/linux/prandom.h:46 [inline]
| reset_kcsan_skip kernel/kcsan/core.c:277 [inline]
| kcsan_setup_watchpoint+0x9b/0x600 kernel/kcsan/core.c:424
| is_idle_task+0xd/0x20 include/linux/sched.h:1671 <==== inline, but not noinstr
| irqentry_enter+0x17/0x50 kernel/entry/common.c:293 <==== noinstr function

We can fix that with the patch below.

That leaves me with this, still due to prandom_u32(). :-/

| ------------[ cut here ]------------
| DEBUG_LOCKS_WARN_ON(lockdep_hardirqs_enabled())
| WARNING: CPU: 4 PID: 1861 at kernel/locking/lockdep.c:4875 check_flags.part.0+0x157/0x160 kernel/locking/lockdep.c:4875
| Modules linked in:
| CPU: 4 PID: 1861 Comm: kworker/u16:4 Not tainted 5.9.0-rc1+ #24
| Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014
| RIP: 0010:check_flags.part.0+0x157/0x160 kernel/locking/lockdep.c:4875
| Code: c0 0f 84 70 5d 00 00 44 8b 0d fd 11 5f 06 45 85 c9 0f 85 60 5d 00 00 48 c7 c6 3e d0 f4 86 48 c7 c7 b2 49 f3 86 e8 8d 49 f6 ff <0f> 0b e9 46 5d 00 00 66 90 41 57 41 56 49 89 fe 41 55 41 89 d5 41
| RSP: 0000:ffffc900034bfcb0 EFLAGS: 00010082
| RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8136161c
| RDX: ffff88881a9dcb00 RSI: ffffffff81363835 RDI: 0000000000000006
| RBP: ffffc900034bfd00 R08: 0000000000000000 R09: 0000ffffffffffff
| R10: 0000000000000104 R11: 0000ffff874efd6b R12: ffffffff874f26c0
| R13: 0000000000000244 R14: 0000000000000000 R15: 0000000000000046
| FS: 0000000000000000(0000) GS:ffff88881fc00000(0000) knlGS:0000000000000000
| CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
| CR2: 0000000000000000 CR3: 0000000007489001 CR4: 0000000000770ee0
| DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
| DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
| PKRU: 55555554
| Call Trace:
| check_flags kernel/locking/lockdep.c:4871 [inline]
| lock_is_held_type+0x42/0x100 kernel/locking/lockdep.c:5042
| lock_is_held include/linux/lockdep.h:267 [inline]
| rcu_read_lock_sched_held+0x41/0x80 kernel/rcu/update.c:136
| trace_prandom_u32 include/trace/events/random.h:310 [inline]
| prandom_u32+0x1bb/0x200 lib/random32.c:86
| prandom_u32_max include/linux/prandom.h:46 [inline]
| reset_kcsan_skip kernel/kcsan/core.c:277 [inline]
| kcsan_setup_watchpoint+0x9b/0x600 kernel/kcsan/core.c:424
| perf_lock_task_context+0x5e3/0x6e0 kernel/events/core.c:1491
| perf_pin_task_context kernel/events/core.c:1506 [inline]
| perf_event_exit_task_context kernel/events/core.c:12284 [inline]
| perf_event_exit_task+0x1e2/0x910 kernel/events/core.c:12364
| do_exit+0x70e/0x18b0 kernel/exit.c:815
| call_usermodehelper_exec_async+0x2e2/0x2f0 kernel/umh.c:114
| ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:294
| irq event stamp: 107
| hardirqs last enabled at (107): [<ffffffff815532ab>] perf_lock_task_context+0x5db/0x6e0 kernel/events/core.c:1491
| hardirqs last disabled at (106): [<ffffffff81552f12>] perf_lock_task_context+0x242/0x6e0 kernel/events/core.c:1459
| softirqs last enabled at (0): [<ffffffff8129b95e>] copy_process+0xe9e/0x3970 kernel/fork.c:2004
| softirqs last disabled at (0): [<0000000000000000>] 0x0
| ---[ end trace a3058d9b157af5c4 ]---
| possible reason: unannotated irqs-off.
| irq event stamp: 107
| hardirqs last enabled at (107): [<ffffffff815532ab>] perf_lock_task_context+0x5db/0x6e0 kernel/events/core.c:1491
| hardirqs last disabled at (106): [<ffffffff81552f12>] perf_lock_task_context+0x242/0x6e0 kernel/events/core.c:1459
| softirqs last enabled at (0): [<ffffffff8129b95e>] copy_process+0xe9e/0x3970 kernel/fork.c:2004
| softirqs last disabled at (0): [<0000000000000000>] 0x0

Suggestions?

Thanks,
-- Marco

------ >8 ------

From 4ec9dd472c978e1eba622fb22bc04e4357f10421 Mon Sep 17 00:00:00 2001
From: Marco Elver <elver@xxxxxxxxxx>
Date: Thu, 20 Aug 2020 19:06:09 +0200
Subject: [PATCH] sched: Turn inline into __always_inline due to noinstr use

is_idle_task() may be used from noinstr functions such as
irqentry_enter(). Since the compiler is free to not inline regular
inline functions, switch to using __always_inline.

Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
---
include/linux/sched.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 93ecd930efd3..afe01e232935 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1666,7 +1666,7 @@ extern struct task_struct *idle_task(int cpu);
*
* Return: 1 if @p is an idle task. 0 otherwise.
*/
-static inline bool is_idle_task(const struct task_struct *p)
+static __always_inline bool is_idle_task(const struct task_struct *p)
{
return !!(p->flags & PF_IDLE);
}
--
2.28.0.297.g1956fa8f8d-goog