Linux-PM Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] PM / wakeup: Fix sysfs registration error path
@ 2019-08-14  0:40 Stephen Boyd
  2019-08-14  9:34 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Boyd @ 2019-08-14  0:40 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: linux-kernel, linux-pm, Qian Cai, Tri Vo, Peter Zijlstra,
	Greg Kroah-Hartman

We shouldn't call wakeup_source_destroy() from the error path in
wakeup_source_register() because that calls __pm_relax() which takes a
lock that isn't initialized until wakeup_source_add() is called. Add a
new function, wakeup_source_free(), that just does the bare minimum to
free a wakeup source that was created but hasn't been added yet and use
it from the two places it's needed. This fixes the following problem
seen on various x86 server boxes:

 INFO: trying to register non-static key.
 the code is fine but needs lockdep annotation.
 turning off the locking correctness validator.
 CPU: 12 PID: 1 Comm: swapper/0 Not tainted 5.3.0-rc4-
 Hardware name: HP ProLiant XL420 Gen9/ProLiant XL420 Gen9, BIOS U19 12/27/2015
 Call Trace:
  dump_stack+0x62/0x9a
  register_lock_class+0x95a/0x960
  ? __platform_driver_probe+0xcd/0x230
  ? __platform_create_bundle+0xc0/0xe0
  ? i8042_init+0x4ec/0x578
  ? do_one_initcall+0xfe/0x45a
  ? kernel_init_freeable+0x614/0x6a7
  ? kernel_init+0x11/0x138
  ? ret_from_fork+0x35/0x40
  ? is_dynamic_key+0xf0/0xf0
  ? rwlock_bug.part.0+0x60/0x60
  ? __debug_check_no_obj_freed+0x8e/0x250
  __lock_acquire.isra.13+0x5f/0x830
  ? __debug_check_no_obj_freed+0x152/0x250
  lock_acquire+0x107/0x220
  ? __pm_relax.part.2+0x21/0xa0
  _raw_spin_lock_irqsave+0x35/0x50
  ? __pm_relax.part.2+0x21/0xa0
  __pm_relax.part.2+0x21/0xa0
  wakeup_source_destroy.part.3+0x18/0x190
  wakeup_source_register+0x43/0x50

Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
Reported-by: Qian Cai <cai@lca.pw>
Cc: Qian Cai <cai@lca.pw>
Cc: Tri Vo <trong@android.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/base/power/wakeup.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

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);
-- 
Sent by a computer through tubes


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PM / wakeup: Fix sysfs registration error path
  2019-08-14  0:40 [PATCH] PM / wakeup: Fix sysfs registration error path Stephen Boyd
@ 2019-08-14  9:34 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2019-08-14  9:34 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Rafael J. Wysocki, Linux Kernel Mailing List, Linux PM, Qian Cai,
	Tri Vo, Peter Zijlstra, Greg Kroah-Hartman

On Wed, Aug 14, 2019 at 2:40 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> We shouldn't call wakeup_source_destroy() from the error path in
> wakeup_source_register() because that calls __pm_relax() which takes a
> lock that isn't initialized until wakeup_source_add() is called. Add a
> new function, wakeup_source_free(), that just does the bare minimum to
> free a wakeup source that was created but hasn't been added yet and use
> it from the two places it's needed. This fixes the following problem
> seen on various x86 server boxes:
>
>  INFO: trying to register non-static key.
>  the code is fine but needs lockdep annotation.
>  turning off the locking correctness validator.
>  CPU: 12 PID: 1 Comm: swapper/0 Not tainted 5.3.0-rc4-
>  Hardware name: HP ProLiant XL420 Gen9/ProLiant XL420 Gen9, BIOS U19 12/27/2015
>  Call Trace:
>   dump_stack+0x62/0x9a
>   register_lock_class+0x95a/0x960
>   ? __platform_driver_probe+0xcd/0x230
>   ? __platform_create_bundle+0xc0/0xe0
>   ? i8042_init+0x4ec/0x578
>   ? do_one_initcall+0xfe/0x45a
>   ? kernel_init_freeable+0x614/0x6a7
>   ? kernel_init+0x11/0x138
>   ? ret_from_fork+0x35/0x40
>   ? is_dynamic_key+0xf0/0xf0
>   ? rwlock_bug.part.0+0x60/0x60
>   ? __debug_check_no_obj_freed+0x8e/0x250
>   __lock_acquire.isra.13+0x5f/0x830
>   ? __debug_check_no_obj_freed+0x152/0x250
>   lock_acquire+0x107/0x220
>   ? __pm_relax.part.2+0x21/0xa0
>   _raw_spin_lock_irqsave+0x35/0x50
>   ? __pm_relax.part.2+0x21/0xa0
>   __pm_relax.part.2+0x21/0xa0
>   wakeup_source_destroy.part.3+0x18/0x190
>   wakeup_source_register+0x43/0x50
>
> Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
> Reported-by: Qian Cai <cai@lca.pw>
> Cc: Qian Cai <cai@lca.pw>
> Cc: Tri Vo <trong@android.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  drivers/base/power/wakeup.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> 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);
> --

Applied, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-14  0:40 [PATCH] PM / wakeup: Fix sysfs registration error path Stephen Boyd
2019-08-14  9:34 ` Rafael J. Wysocki

Linux-PM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pm/0 linux-pm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pm linux-pm/ https://lore.kernel.org/linux-pm \
		linux-pm@vger.kernel.org linux-pm@archiver.kernel.org
	public-inbox-index linux-pm


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pm


AGPL code for this site: git clone https://public-inbox.org/ public-inbox