Re: "PM / wakeup: Show wakeup sources stats in sysfs" causes boot warnings

From: Qian Cai
Date: Wed Aug 14 2019 - 09:18:40 EST


On Tue, 2019-08-13 at 15:35 -0700, Stephen Boyd wrote:
> Quoting Qian Cai (2019-08-13 14:32:56)
> > The linux-next commit "PM / wakeup: Show wakeup sources stats in sysfs" [1]
> > introduced some baddies during boot on several x86 servers. Reverted the
> > commit
> > fixed the issue.
> >
> > [1] https://lore.kernel.org/lkml/20190807014846.143949-4-trong@xxxxxxxxxxx/
> >
> > [ÂÂÂ39.195053][ÂÂÂÂT1] serio: i8042 KBD port at 0x60,0x64 irq 1
> > [ÂÂÂ39.197347][ÂÂÂÂT1] kobject_add_internal failed for wakeup (error: -2
> > parent:
> > serio0)
> > [ÂÂÂ39.199845][ÂÂÂÂT1] INFO: trying to register non-static key.
> > [ÂÂÂ39.201582][ÂÂÂÂT1] the code is fine but needs lockdep annotation.
> > [ÂÂÂ39.203477][ÂÂÂÂT1] turning off the locking correctness validator.
> > [ÂÂÂ39.205399][ÂÂÂÂT1] CPU: 12 PID: 1 Comm: swapper/0 Not tainted 5.3.0-rc4-
> > next-20190813 #3
> > [ÂÂÂ39.207938][ÂÂÂÂT1] Hardware name: HP ProLiant XL420 Gen9/ProLiant XL420
> > Gen9, BIOS U19 12/27/2015
> > [ÂÂÂ39.210606][ÂÂÂÂT1] Call Trace:
> > [ÂÂÂ39.210606][ÂÂÂÂT1]ÂÂdump_stack+0x62/0x9a
> > [ÂÂÂ39.210606][ÂÂÂÂT1]ÂÂregister_lock_class+0x95a/0x960
> > [ÂÂÂ39.210606][ÂÂÂÂT1]ÂÂ? __platform_driver_probe+0xcd/0x230
> > [ÂÂÂ39.210606][ÂÂÂÂT1]ÂÂ? __platform_create_bundle+0xc0/0xe0
> > [ÂÂÂ39.210606][ÂÂÂÂT1]ÂÂ? i8042_init+0x4ec/0x578
> > [ÂÂÂ39.210606][ÂÂÂÂT1]ÂÂ? do_one_initcall+0xfe/0x45a
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ? kernel_init_freeable+0x614/0x6a7
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ? kernel_init+0x11/0x138
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ? ret_from_fork+0x35/0x40
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ? is_dynamic_key+0xf0/0xf0
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ? rwlock_bug.part.0+0x60/0x60
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ? __debug_check_no_obj_freed+0x8e/0x250
> > [ÂÂÂ39.219571][ÂÂÂÂT1]ÂÂ__lock_acquire.isra.13+0x5f/0x830
> > [ÂÂÂ39.229491][ÂÂÂÂT1]ÂÂ? __debug_check_no_obj_freed+0x152/0x250
> > [ÂÂÂ39.229491][ÂÂÂÂT1]ÂÂlock_acquire+0x107/0x220
> > [ÂÂÂ39.229491][ÂÂÂÂT1]ÂÂ? __pm_relax.part.2+0x21/0xa0
> > [ÂÂÂ39.229491][ÂÂÂÂT1]ÂÂ_raw_spin_lock_irqsave+0x35/0x50
> > [ÂÂÂ39.229491][ÂÂÂÂT1]ÂÂ? __pm_relax.part.2+0x21/0xa0
> > [ÂÂÂ39.229491][ÂÂÂÂT1]ÂÂ__pm_relax.part.2+0x21/0xa0
> > [ÂÂÂ39.239588][ÂÂÂÂT1]ÂÂwakeup_source_destroy.part.3+0x18/0x190
> > [ÂÂÂ39.239588][ÂÂÂÂT1]ÂÂwakeup_source_register+0x43/0x50
>
> We shouldn't call wakeup_source_destroy() from the error path in
> wakeup_source_register() because that calls __pm_relax() and that takes
> a lock that isn't initialized until wakeup_source_add() is called. Can
> you try this patch?

It works fine which takes care of the lockdep issue.

>
> ----8<----
> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> index 3a7f5803aa81..f7925820b5ca 100644
> --- a/drivers/base/power/wakeup.c
> +++ b/drivers/base/power/wakeup.c
> @@ -137,6 +137,13 @@ static void wakeup_source_record(struct wakeup_source
> *ws)
> Â spin_unlock_irqrestore(&deleted_ws.lock, flags);
> Â}
> Â
> +static void wakeup_source_free(struct wakeup_source *ws)
> +{
> + ida_free(&wakeup_ida, ws->id);
> + kfree_const(ws->name);
> + kfree(ws);
> +}
> +
> Â/**
> Â * wakeup_source_destroy - Destroy a struct wakeup_source object.
> Â * @ws: Wakeup source to destroy.
> @@ -150,9 +157,7 @@ void wakeup_source_destroy(struct wakeup_source *ws)
> Â
> Â __pm_relax(ws);
> Â wakeup_source_record(ws);
> - ida_free(&wakeup_ida, ws->id);
> - kfree_const(ws->name);
> - kfree(ws);
> + wakeup_source_free(ws);
> Â}
> ÂEXPORT_SYMBOL_GPL(wakeup_source_destroy);
> Â
> @@ -217,7 +222,7 @@ struct wakeup_source *wakeup_source_register(struct device
> *dev,
> Â if (ws) {
> Â ret = wakeup_source_sysfs_add(dev, ws);
> Â if (ret) {
> - wakeup_source_destroy(ws);
> + wakeup_source_free(ws);
> Â return NULL;
> Â }
> Â wakeup_source_add(ws);