Skip to contentSkip to conversation

RFC: console: hack up console_trylock more

PATCH In review Daniel Vetter 6 participants 20 messages May 2, 2019 – May 9, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: console: hack up console_trylock more

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0
  pollwake+0x6f/0x90
  credit_entropy_bits+0x204/0x310
  add_interrupt_randomness+0x18f/0x210
  handle_irq+0x67/0x160
  do_IRQ+0x5e/0x130
  common_interrupt+0xf/0xf
  </IRQ>

This alone isn't a problem, but the spinlock in the semaphore is also still held while waking up waiters (up() -> __up() -> try_to_wake_up() callchain), which then closes the runqueue vs. semaphore.lock loop, and upsets lockdep, which issues a circular locking splat to dmesg. Worse it upsets developers, since we don't want to spam dmesg with clutter when the machine is dying already.

Fix this by creating a __down_trylock which only trylocks the semaphore.lock. This isn't correct in full generality, but good enough for console_lock:

- there's only ever one console_lock holder, we won't fail spuriously because someone is doing a down() or up() while there's still room (unlike other semaphores with count > 1).

- console_unlock() has one massive retry loop, which will catch anyone who races the trylock against the up(). This makes sure that no printk lines will get lost. Making the trylock more racy therefore has no further impact.

Also cc'ing John Ogness since perhaps his printk rework fixes this all properly.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc John Ogness <[email protected]>
---
 include/linux/semaphore.h  |  1 +
 kernel/locking/semaphore.c | 33 +++++++++++++++++++++++++++++++++
 kernel/printk/printk.c     |  2 +-
 3 files changed, 35 insertions(+), 1 deletion(-)
include/linux/semaphore.h +1 -0
index 11c86fbfeb98..82f6db6121c3 100644
@@ -40,6 +40,7 @@ extern void down(struct semaphore *sem);
 extern int __must_check down_interruptible(struct semaphore *sem);
 extern int __must_check down_killable(struct semaphore *sem);
 extern int __must_check down_trylock(struct semaphore *sem);
+extern int __must_check __down_trylock(struct semaphore *sem);
 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
 extern void up(struct semaphore *sem);
 
kernel/locking/semaphore.c +33 -0
index 561acdd39960..345123336019 100644
@@ -143,6 +143,39 @@ int down_trylock(struct semaphore *sem)
 }
 EXPORT_SYMBOL(down_trylock);
 
+/**
+ * __down_trylock - try to acquire the semaphore, without any locking
+ * @sem: the semaphore to be acquired
+ *
+ * Try to acquire the semaphore atomically.  Returns 0 if the semaphore has
+ * been acquired successfully or 1 if it it cannot be acquired.
+ *
+ * NOTE: This return value is inverted from both spin_trylock and
+ * mutex_trylock!  Be careful about this when converting code.
+ *
+ * Unlike mutex_trylock, this function can be used from interrupt context,
+ * and the semaphore can be released by any task or interrupt.
+ *
+ * WARNING: Unlike down_trylock this function doesn't guarantee that that the
+ * semaphore will be acquired if it could, it's best effort only. Use for
+ * down_trylock_console_sem only.
+ */
+int __down_trylock(struct semaphore *sem)
+{
+	unsigned long flags;
+	int count;
+
+	if (!raw_spin_trylock_irqsave(&sem->lock, flags))
+		return 1;
+	count = sem->count - 1;
+	if (likely(count >= 0))
+		sem->count = count;
+	raw_spin_unlock_irqrestore(&sem->lock, flags);
+
+	return (count < 0);
+}
+EXPORT_SYMBOL(__down_trylock);
+
 /**
  * down_timeout - acquire the semaphore within a specified time
  * @sem: the semaphore to be acquired
kernel/printk/printk.c +1 -1
index 02ca827b8fac..5293803eec1f 100644
@@ -217,7 +217,7 @@ static int __down_trylock_console_sem(unsigned long ip)
 	 * deadlock in printk()->down_trylock_console_sem() otherwise.
 	 */
 	printk_safe_enter_irqsave(flags);
-	lock_failed = down_trylock(&console_sem);
+	lock_failed = __down_trylock(&console_sem);
 	printk_safe_exit_irqrestore(flags);
 
 	if (lock_failed)
Signature · 1 line
2.20.1
#1 lore raw

✗ Fi.CI.CHECKPATCH: warning for RFC: console: hack up console_trylock more

== Series Details ==

== Series Details ==

Series: RFC: console: hack up console_trylock more
URL : https://patchwork.freedesktop.org/series/60212/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
5a15dd2f624b RFC: console: hack up console_trylock more
-:73: CHECK:AVOID_EXTERNS: extern prototypes should be avoided in .h files
#73: FILE: include/linux/semaphore.h:43:
+extern int __must_check __down_trylock(struct semaphore *sem);

-:133: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <[email protected]>'

total: 0 errors, 1 warnings, 1 checks, 54 lines checked

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

✓ Fi.CI.BAT: success for RFC: console: hack up console_trylock more

In reply to Daniel Vetter
== Series Details ==

== Series Details ==

Series: RFC: console: hack up console_trylock more
URL : https://patchwork.freedesktop.org/series/60212/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6028 -> Patchwork_12941
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/60212/revisions/1/mbox/

Known issues
------------

Here are the changes found in Patchwork_12941 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live_contexts:
- fi-icl-y: [PASS][1] -> [INCOMPLETE][2] ([fdo#107713] / [fdo#108569] / [fdo#110581])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/fi-icl-y/igt@i915_selftest@live_contexts.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/fi-icl-y/igt@i915_selftest@live_contexts.html

#### Possible fixes ####

* igt@gem_exec_suspend@basic-s3:
- fi-blb-e6850: [INCOMPLETE][3] ([fdo#107718] / [fdo#110581]) -> [PASS][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/fi-blb-e6850/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/fi-blb-e6850/igt@[email protected]

* igt@i915_pm_rpm@module-reload:
- fi-skl-6770hq: [FAIL][5] ([fdo#108511]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/fi-skl-6770hq/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/fi-skl-6770hq/igt@[email protected]

[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#108511]: https://bugs.freedesktop.org/show_bug.cgi?id=108511
[fdo#108569]: https://bugs.freedesktop.org/show_bug.cgi?id=108569
[fdo#110581]: https://bugs.freedesktop.org/show_bug.cgi?id=110581

Participating hosts (54 -> 46)
------------------------------

Missing (8): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-clapper fi-bdw-samus

Build changes
-------------

* Linux: CI_DRM_6028 -> Patchwork_12941

CI_DRM_6028: dbaec229490d7a786375739370f757b7e70d0251 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4972: f052e49a43cc9704ea5f240df15dd9d3dfed68ab @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12941: 5a15dd2f624bd37232f5e349e4b3416ebad9845d @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

5a15dd2f624b RFC: console: hack up console_trylock more

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

✓ Fi.CI.IGT: success for RFC: console: hack up console_trylock more

In reply to Daniel Vetter
== Series Details ==

== Series Details ==

Series: RFC: console: hack up console_trylock more
URL : https://patchwork.freedesktop.org/series/60212/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6028_full -> Patchwork_12941_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

Known issues
------------

Here are the changes found in Patchwork_12941_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_ctx_isolation@vecs0-s3:
- shard-skl: [PASS][1] -> [INCOMPLETE][2] ([fdo#104108] / [fdo#107773] / [fdo#110581])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl2/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl6/igt@[email protected]

* igt@i915_pm_rpm@gem-execbuf:
- shard-skl: [PASS][3] -> [INCOMPLETE][4] ([fdo#107803] / [fdo#107807] / [fdo#110581])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl6/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl5/igt@[email protected]

* igt@i915_suspend@fence-restore-untiled:
- shard-apl: [PASS][5] -> [DMESG-WARN][6] ([fdo#108566]) +6 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-apl8/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-apl7/igt@[email protected]

* igt@kms_cursor_legacy@cursor-vs-flip-atomic-transitions:
- shard-hsw: [PASS][7] -> [FAIL][8] ([fdo#103355])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-hsw2/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-hsw6/igt@[email protected]

* igt@kms_flip@flip-vs-expired-vblank:
- shard-apl: [PASS][9] -> [FAIL][10] ([fdo#102887] / [fdo#105363])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-apl1/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-apl8/igt@[email protected]

* igt@kms_flip@flip-vs-suspend-interruptible:
- shard-skl: [PASS][11] -> [INCOMPLETE][12] ([fdo#107773] / [fdo#109507] / [fdo#110581])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl4/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl9/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-move:
- shard-iclb: [PASS][13] -> [FAIL][14] ([fdo#103167]) +4 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb7/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb2/igt@[email protected]

* igt@kms_plane_lowres@pipe-a-tiling-x:
- shard-iclb: [PASS][15] -> [FAIL][16] ([fdo#103166])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb3/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb5/igt@[email protected]

* igt@kms_psr2_su@page_flip:
- shard-iclb: [PASS][17] -> [SKIP][18] ([fdo#109642])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb2/igt@kms_psr2_su@page_flip.html
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb1/igt@kms_psr2_su@page_flip.html

* igt@kms_psr@no_drrs:
- shard-iclb: [PASS][19] -> [FAIL][20] ([fdo#108341])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb2/igt@kms_psr@no_drrs.html
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb1/igt@kms_psr@no_drrs.html

* igt@kms_psr@psr2_no_drrs:
- shard-iclb: [PASS][21] -> [SKIP][22] ([fdo#109441]) +1 similar issue
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb2/igt@kms_psr@psr2_no_drrs.html
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb7/igt@kms_psr@psr2_no_drrs.html

* igt@kms_sysfs_edid_timing:
- shard-iclb: [PASS][23] -> [FAIL][24] ([fdo#100047])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb1/igt@kms_sysfs_edid_timing.html
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb3/igt@kms_sysfs_edid_timing.html

* igt@tools_test@tools_test:
- shard-iclb: [PASS][25] -> [SKIP][26] ([fdo#109352])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb8/igt@tools_test@tools_test.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb1/igt@tools_test@tools_test.html

#### Possible fixes ####

* igt@gem_workarounds@suspend-resume:
- shard-apl: [DMESG-WARN][27] ([fdo#108566]) -> [PASS][28] +4 similar issues
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-apl6/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-apl4/igt@[email protected]

* igt@i915_pm_rpm@gem-evict-pwrite:
- shard-skl: [INCOMPLETE][29] ([fdo#107807] / [fdo#110581]) -> [PASS][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl6/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl4/igt@[email protected]

* igt@i915_suspend@fence-restore-untiled:
- shard-kbl: [DMESG-WARN][31] ([fdo#108566]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-kbl3/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-kbl4/igt@[email protected]

* igt@kms_dp_dsc@basic-dsc-enable-edp:
- shard-iclb: [SKIP][33] ([fdo#109349]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb7/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb2/igt@[email protected]

* igt@kms_draw_crc@draw-method-xrgb8888-render-xtiled:
- shard-skl: [FAIL][35] ([fdo#103184] / [fdo#103232]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl8/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl5/igt@[email protected]

* igt@kms_flip@flip-vs-suspend:
- shard-glk: [INCOMPLETE][37] ([fdo#103359] / [fdo#110581] / [k.org#198133]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-glk6/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-glk2/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-rgb101010-draw-mmap-cpu:
- shard-skl: [FAIL][39] ([fdo#103167] / [fdo#110379]) -> [PASS][40]
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl8/igt@[email protected]
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl5/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render:
- shard-iclb: [FAIL][41] ([fdo#103167]) -> [PASS][42] +2 similar issues
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb8/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render.html
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb1/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-cur-indfb-draw-render.html

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-mmap-gtt:
- shard-skl: [FAIL][43] ([fdo#108040]) -> [PASS][44]
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl8/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-mmap-gtt.html
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl5/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-mmap-gtt.html

* igt@kms_plane@pixel-format-pipe-b-planes-source-clamping:
- shard-glk: [SKIP][45] ([fdo#109271]) -> [PASS][46]
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-glk4/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-glk9/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-coverage-7efc:
- shard-skl: [FAIL][47] ([fdo#108145] / [fdo#110403]) -> [PASS][48]
[47]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-skl7/igt@[email protected]
[48]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-skl6/igt@[email protected]

* igt@kms_plane_scaling@pipe-a-scaler-with-clipping-clamping:
- shard-glk: [SKIP][49] ([fdo#109271] / [fdo#109278]) -> [PASS][50]
[49]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-glk7/igt@[email protected]
[50]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-glk9/igt@[email protected]

* igt@kms_psr@psr2_sprite_mmap_gtt:
- shard-iclb: [SKIP][51] ([fdo#109441]) -> [PASS][52] +3 similar issues
[51]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-iclb7/igt@kms_psr@psr2_sprite_mmap_gtt.html
[52]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-iclb2/igt@kms_psr@psr2_sprite_mmap_gtt.html

* igt@perf_pmu@init-busy-bcs0:
- shard-apl: [INCOMPLETE][53] ([fdo#103927] / [fdo#110581]) -> [PASS][54]
[53]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6028/shard-apl4/igt@[email protected]
[54]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/shard-apl2/igt@[email protected]

[fdo#100047]: https://bugs.freedesktop.org/show_bug.cgi?id=100047
[fdo#102887]: https://bugs.freedesktop.org/show_bug.cgi?id=102887
[fdo#103166]: https://bugs.freedesktop.org/show_bug.cgi?id=103166
[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103184]: https://bugs.freedesktop.org/show_bug.cgi?id=103184
[fdo#103232]: https://bugs.freedesktop.org/show_bug.cgi?id=103232
[fdo#103355]: https://bugs.freedesktop.org/show_bug.cgi?id=103355
[fdo#103359]: https://bugs.freedesktop.org/show_bug.cgi?id=103359
[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
[fdo#105363]: https://bugs.freedesktop.org/show_bug.cgi?id=105363
[fdo#107773]: https://bugs.freedesktop.org/show_bug.cgi?id=107773
[fdo#107803]: https://bugs.freedesktop.org/show_bug.cgi?id=107803
[fdo#107807]: https://bugs.freedesktop.org/show_bug.cgi?id=107807
[fdo#108040]: https://bugs.freedesktop.org/show_bug.cgi?id=108040
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#108341]: https://bugs.freedesktop.org/show_bug.cgi?id=108341
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
[fdo#109349]: https://bugs.freedesktop.org/show_bug.cgi?id=109349
[fdo#109352]: https://bugs.freedesktop.org/show_bug.cgi?id=109352
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109507]: https://bugs.freedesktop.org/show_bug.cgi?id=109507
[fdo#109642]: https://bugs.freedesktop.org/show_bug.cgi?id=109642
[fdo#110379]: https://bugs.freedesktop.org/show_bug.cgi?id=110379
[fdo#110403]: https://bugs.freedesktop.org/show_bug.cgi?id=110403
[fdo#110581]: https://bugs.freedesktop.org/show_bug.cgi?id=110581
[k.org#198133]: https://bugzilla.kernel.org/show_bug.cgi?id=198133

Participating hosts (10 -> 10)
------------------------------

No changes in participating hosts

Build changes
-------------

* Linux: CI_DRM_6028 -> Patchwork_12941

CI_DRM_6028: dbaec229490d7a786375739370f757b7e70d0251 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4972: f052e49a43cc9704ea5f240df15dd9d3dfed68ab @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12941: 5a15dd2f624bd37232f5e349e4b3416ebad9845d @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12941/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

maintainer
#4 lore raw
In reply to Daniel Vetter
Quoted 36 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0
  pollwake+0x6f/0x90
  credit_entropy_bits+0x204/0x310
  add_interrupt_randomness+0x18f/0x210
  handle_irq+0x67/0x160
  do_IRQ+0x5e/0x130
  common_interrupt+0xf/0xf
  </IRQ>

This alone isn't a problem, but the spinlock in the semaphore is also still held while waking up waiters (up() -> __up() -> try_to_wake_up() callchain), which then closes the runqueue vs. semaphore.lock loop, and upsets lockdep, which issues a circular locking splat to dmesg. Worse it upsets developers, since we don't want to spam dmesg with clutter when the machine is dying already.

Fix this by creating a __down_trylock which only trylocks the semaphore.lock. This isn't correct in full generality, but good enough for console_lock:

Quoted 8 lines

- there's only ever one console_lock holder, we won't fail spuriously because someone is doing a down() or up() while there's still room (unlike other semaphores with count > 1).

- console_unlock() has one massive retry loop, which will catch anyone who races the trylock against the up(). This makes sure that no printk lines will get lost. Making the trylock more racy therefore has no further impact.

To be honest, I do not see how this could solve the problem.

The circular dependency is still there. If the new __down_trylock() succeeds then console_unlock() will get called in the same context and it will still need to call up() -> try_to_wake_up().

Note that there are many other console_lock() callers that might happen in parallel and might appear in the wait queue.

Best Regards,
Petr

#5 lore raw
Quoted 46 lines · Petr Mladek
Quoted 36 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0
  pollwake+0x6f/0x90
  credit_entropy_bits+0x204/0x310
  add_interrupt_randomness+0x18f/0x210
  handle_irq+0x67/0x160
  do_IRQ+0x5e/0x130
  common_interrupt+0xf/0xf
  </IRQ>

This alone isn't a problem, but the spinlock in the semaphore is also still held while waking up waiters (up() -> __up() -> try_to_wake_up() callchain), which then closes the runqueue vs. semaphore.lock loop, and upsets lockdep, which issues a circular locking splat to dmesg. Worse it upsets developers, since we don't want to spam dmesg with clutter when the machine is dying already.

Fix this by creating a __down_trylock which only trylocks the semaphore.lock. This isn't correct in full generality, but good enough for console_lock:

Quoted 8 lines

- there's only ever one console_lock holder, we won't fail spuriously because someone is doing a down() or up() while there's still room (unlike other semaphores with count > 1).

- console_unlock() has one massive retry loop, which will catch anyone who races the trylock against the up(). This makes sure that no printk lines will get lost. Making the trylock more racy therefore has no further impact.

Quoted 8 lines

To be honest, I do not see how this could solve the problem.

The circular dependency is still there. If the new __down_trylock() succeeds then console_unlock() will get called in the same context and it will still need to call up() -> try_to_wake_up().

Note that there are many other console_lock() callers that might happen in parallel and might appear in the wait queue.

Hm right. It's very rare we hit this in our CI and I don't know how to repro otherwise, so just threw this out at the wall to see if it sticks. I'll try and come up with a new trick then.

Thanks, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
maintainer
#6 lore raw
Quoted 53 lines · Daniel Vetter
Quoted 52 lines · Petr Mladek
Quoted 36 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0
  pollwake+0x6f/0x90
  credit_entropy_bits+0x204/0x310
  add_interrupt_randomness+0x18f/0x210
  handle_irq+0x67/0x160
  do_IRQ+0x5e/0x130
  common_interrupt+0xf/0xf
  </IRQ>

This alone isn't a problem, but the spinlock in the semaphore is also still held while waking up waiters (up() -> __up() -> try_to_wake_up() callchain), which then closes the runqueue vs. semaphore.lock loop, and upsets lockdep, which issues a circular locking splat to dmesg. Worse it upsets developers, since we don't want to spam dmesg with clutter when the machine is dying already.

Fix this by creating a __down_trylock which only trylocks the semaphore.lock. This isn't correct in full generality, but good enough for console_lock:

Quoted 8 lines

- there's only ever one console_lock holder, we won't fail spuriously because someone is doing a down() or up() while there's still room (unlike other semaphores with count > 1).

- console_unlock() has one massive retry loop, which will catch anyone who races the trylock against the up(). This makes sure that no printk lines will get lost. Making the trylock more racy therefore has no further impact.

To be honest, I do not see how this could solve the problem.

The circular dependency is still there. If the new __down_trylock() succeeds then console_unlock() will get called in the same context and it will still need to call up() -> try_to_wake_up().

Quoted 6 lines
Quoted 2 lines

Note that there are many other console_lock() callers that might happen in parallel and might appear in the wait queue.

Hm right. It's very rare we hit this in our CI and I don't know how to repro otherwise, so just threw this out at the wall to see if it sticks. I'll try and come up with a new trick then.

Single messages are printed from scheduler via printk_deferred(). WARN() might be solved by introducing printk deferred context, see the per-cpu variable printk_context.

Best Regards,
Petr
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw
Quoted 57 lines · Petr Mladek
Quoted 56 lines · Daniel Vetter
Quoted 54 lines · Petr Mladek
Quoted 36 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0
  pollwake+0x6f/0x90
  credit_entropy_bits+0x204/0x310
  add_interrupt_randomness+0x18f/0x210
  handle_irq+0x67/0x160
  do_IRQ+0x5e/0x130
  common_interrupt+0xf/0xf
  </IRQ>

This alone isn't a problem, but the spinlock in the semaphore is also still held while waking up waiters (up() -> __up() -> try_to_wake_up() callchain), which then closes the runqueue vs. semaphore.lock loop, and upsets lockdep, which issues a circular locking splat to dmesg. Worse it upsets developers, since we don't want to spam dmesg with clutter when the machine is dying already.

Fix this by creating a __down_trylock which only trylocks the semaphore.lock. This isn't correct in full generality, but good enough for console_lock:

Quoted 8 lines

- there's only ever one console_lock holder, we won't fail spuriously because someone is doing a down() or up() while there's still room (unlike other semaphores with count > 1).

- console_unlock() has one massive retry loop, which will catch anyone who races the trylock against the up(). This makes sure that no printk lines will get lost. Making the trylock more racy therefore has no further impact.

To be honest, I do not see how this could solve the problem.

The circular dependency is still there. If the new __down_trylock() succeeds then console_unlock() will get called in the same context and it will still need to call up() -> try_to_wake_up().

Note that there are many other console_lock() callers that might happen in parallel and might appear in the wait queue.

Quoted 7 lines
Quoted 3 lines

Hm right. It's very rare we hit this in our CI and I don't know how to repro otherwise, so just threw this out at the wall to see if it sticks. I'll try and come up with a new trick then.

Single messages are printed from scheduler via printk_deferred(). WARN() might be solved by introducing printk deferred context, see the per-cpu variable printk_context.

I convinced myself that I can take the wake_up_process out from under the spinlock, for the limited case of the console lock. I think that's a cleaner and more robust fix than leaking printk_context trickery into the console_unlock code.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

PATCH 1/1 RFC: console: hack up console_lock more v2

In reply to Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0
  pollwake+0x6f/0x90
  credit_entropy_bits+0x204/0x310
  add_interrupt_randomness+0x18f/0x210
  handle_irq+0x67/0x160
  do_IRQ+0x5e/0x130
  common_interrupt+0xf/0xf
  </IRQ>

This alone isn't a problem, but the spinlock in the semaphore is also still held while waking up waiters (up() -> __up() -> try_to_wake_up() callchain), which then closes the runqueue vs. semaphore.lock loop, and upsets lockdep, which issues a circular locking splat to dmesg. Worse it upsets developers, since we don't want to spam dmesg with clutter when the machine is dying already.

Fix this by creating a prinkt_safe_up() which calls wake_up_process outside of the spinlock. This isn't correct in full generality, but good enough for console_lock:

- console_lock doesn't use interruptible or killable or timeout down() calls, hence an up() is the only thing that can wake up a process. Hence the process can't get woken and killed and reaped while we try to wake it up too.

- semaphore.c always updates the waiter list while under the spinlock, so there's no other races. Specifically another process that races with a quick console_lock/unlock while we've dropped the spinlock already won't see our own waiter.

Also cc'ing John Ogness since perhaps his printk rework fixes this all properly.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc John Ogness <[email protected]>

---
v2: My first attempt at patching down_trylock didn't work (thanks to Petr for pointing out), now try to have a special up() that breaks the cycle.
-Daniel

---
 include/linux/semaphore.h  |  1 +
 kernel/locking/semaphore.c | 31 +++++++++++++++++++++++++++++++
 kernel/printk/printk.c     |  2 +-
 3 files changed, 33 insertions(+), 1 deletion(-)
include/linux/semaphore.h +1 -0
index 11c86fbfeb98..7e839c72809d 100644
@@ -41,6 +41,7 @@ extern int __must_check down_interruptible(struct semaphore *sem);
 extern int __must_check down_killable(struct semaphore *sem);
 extern int __must_check down_trylock(struct semaphore *sem);
 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
+extern void printk_safe_up(struct semaphore *sem);
 extern void up(struct semaphore *sem);
 
 #endif /* __LINUX_SEMAPHORE_H */
kernel/locking/semaphore.c +31 -0
index 561acdd39960..84675993dc59 100644
@@ -197,6 +197,37 @@ struct semaphore_waiter {
 	bool up;
 };
 
+/**
+ * printk_safe_up - release the semaphore in console_unlock
+ * @sem: the semaphore to release
+ *
+ * Release the semaphore.  Unlike mutexes, up() may be called from any
+ * context and even by tasks which have never called down().
+ *
+ * NOTE: This is a special version of up() for console_unlock only. It is only
+ * safe if there are no killable, interruptible or timing out down() calls.
+ */
+void printk_safe_up(struct semaphore *sem)
+{
+	unsigned long flags;
+	struct semaphore_waiter *waiter = NULL;
+
+	raw_spin_lock_irqsave(&sem->lock, flags);
+	if (likely(list_empty(&sem->wait_list))) {
+		sem->count++;
+	} else {
+		waiter = list_first_entry(&sem->wait_list,
+					  struct semaphore_waiter, list);
+		list_del(&waiter->list);
+		waiter->up = true;
+	}
+	raw_spin_unlock_irqrestore(&sem->lock, flags);
+
+	if (waiter)
+		wake_up_process(waiter->task);
+}
+EXPORT_SYMBOL(printk_safe_up);
+
 /*
  * Because this function is inlined, the 'state' parameter will be
  * constant, and thus optimised away by the compiler.  Likewise the
kernel/printk/printk.c +1 -1
index 02ca827b8fac..62303929afda 100644
@@ -234,7 +234,7 @@ static void __up_console_sem(unsigned long ip)
 	mutex_release(&console_lock_dep_map, 1, ip);
 
 	printk_safe_enter_irqsave(flags);
-	up(&console_sem);
+	printk_safe_up(&console_sem);
 	printk_safe_exit_irqrestore(flags);
 }
 #define up_console_sem() __up_console_sem(_RET_IP_)
Signature · 6 lines
2.20.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
maintainer
#9 lore raw

Re: [PATCH] RFC: console: hack up console_lock more v2

Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Best Regards,
Petr

maintainer
#10 lore raw

Re: [PATCH] RFC: console: hack up console_lock more v2

Quoted 22 lines · Petr Mladek
Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

Quoted 7 lines

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Ah, I was too fast and did the same mistake. This won't help because it would still call try_to_wake_up() recursively.

We need to call all printk's that can be called under locks taken in try_to_wake_up() path in printk deferred context. Unfortunately it is whack a mole approach.

Best Regards,
Petr

#11 lore raw

Re: [PATCH] RFC: console: hack up console_lock more v2

Quoted 26 lines · Petr Mladek
Quoted 25 lines · Petr Mladek
Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

Quoted 7 lines
Quoted 4 lines

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Ah, I was too fast and did the same mistake. This won't help because it would still call try_to_wake_up() recursively.

Uh :-/

Quoted 3 lines

We need to call all printk's that can be called under locks taken in try_to_wake_up() path in printk deferred context. Unfortunately it is whack a mole approach.

Hm since it's whack-a-mole anyway, what about converting the WARN_ON into a prinkt_deferred, like all the other scheduler related code? Feels a notch more consistent to me than leaking the printk_context into areas it wasn't really meant built for. Scheduler code already fully subscribed to the whack-a-mole approach after all.

This would mean we drop the backtrace from the native_smp_send_reschedule, or maybe we need a printk_deferred_backtrace()?
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
maintainer
#12 lore raw

Re: [PATCH] RFC: console: hack up console_lock more v2

Quoted 41 lines · Daniel Vetter
Quoted 26 lines · Petr Mladek
Quoted 25 lines · Petr Mladek
Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

Quoted 7 lines
Quoted 4 lines

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Ah, I was too fast and did the same mistake. This won't help because it would still call try_to_wake_up() recursively.

Uh :-/

Quoted 3 lines

We need to call all printk's that can be called under locks taken in try_to_wake_up() path in printk deferred context. Unfortunately it is whack a mole approach.

Quoted 5 lines

Hm since it's whack-a-mole anyway, what about converting the WARN_ON into a prinkt_deferred, like all the other scheduler related code? Feels a notch more consistent to me than leaking the printk_context into areas it wasn't really meant built for. Scheduler code already fully subscribed to the whack-a-mole approach after all.

I am not sure how exactly you mean the conversion.

Anyway, we do not want to use printk_deferred() treewide. It reduces the chance that the messages reach consoles. Scheduler is an exception because of the possible deadlocks.

A solution would be to define WARN_ON_DEFERRED() that would call normal WARN_ON() in printk deferred context and use in scheduler.

Best Regards,
Petr

#13 lore raw

Re: [Intel-gfx] [PATCH] RFC: console: hack up console_lock more v2

Quoted 50 lines · Petr Mladek
Quoted 41 lines · Daniel Vetter
Quoted 26 lines · Petr Mladek
Quoted 25 lines · Petr Mladek
Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

Quoted 7 lines
Quoted 4 lines

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Ah, I was too fast and did the same mistake. This won't help because it would still call try_to_wake_up() recursively.

Uh :-/

Quoted 3 lines

We need to call all printk's that can be called under locks taken in try_to_wake_up() path in printk deferred context. Unfortunately it is whack a mole approach.

Quoted 5 lines

Hm since it's whack-a-mole anyway, what about converting the WARN_ON into a prinkt_deferred, like all the other scheduler related code? Feels a notch more consistent to me than leaking the printk_context into areas it wasn't really meant built for. Scheduler code already fully subscribed to the whack-a-mole approach after all.

I am not sure how exactly you mean the conversion.

Quoted 7 lines

Anyway, we do not want to use printk_deferred() treewide. It reduces the chance that the messages reach consoles. Scheduler is an exception because of the possible deadlocks.

A solution would be to define WARN_ON_DEFERRED() that would call normal WARN_ON() in printk deferred context and use in scheduler.

Sent it out, and then Sergey pointed out printk_safe_enter/exit (which I guess is what you meant, and which I missed), but we're doing this already around the up() call in __up_console_sem.

So I think these further recursions you're pointed out are already handled correctly, and all we need to do is to break the loop involving semaphore.lock of the console_lock semaphore only. Which I think this patch here achieves.

Thoughts? Or are we again missing something here?

Thanks, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
maintainer
#14 lore raw

Re: [Intel-gfx] [PATCH] RFC: console: hack up console_lock more v2

Quoted 55 lines · Daniel Vetter
Quoted 54 lines · Petr Mladek
Quoted 41 lines · Daniel Vetter
Quoted 26 lines · Petr Mladek
Quoted 25 lines · Petr Mladek
Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

Quoted 7 lines
Quoted 4 lines

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Ah, I was too fast and did the same mistake. This won't help because it would still call try_to_wake_up() recursively.

Uh :-/

Quoted 3 lines

We need to call all printk's that can be called under locks taken in try_to_wake_up() path in printk deferred context. Unfortunately it is whack a mole approach.

Quoted 5 lines

Hm since it's whack-a-mole anyway, what about converting the WARN_ON into a prinkt_deferred, like all the other scheduler related code? Feels a notch more consistent to me than leaking the printk_context into areas it wasn't really meant built for. Scheduler code already fully subscribed to the whack-a-mole approach after all.

I am not sure how exactly you mean the conversion.

Anyway, we do not want to use printk_deferred() treewide. It reduces the chance that the messages reach consoles. Scheduler is an exception because of the possible deadlocks.

Quoted 6 lines
Quoted 3 lines

A solution would be to define WARN_ON_DEFERRED() that would call normal WARN_ON() in printk deferred context and use in scheduler.

Sent it out, and then Sergey pointed out printk_safe_enter/exit (which I guess is what you meant, and which I missed)

No, I meant introducing a deferred printk context that would behave like printk_deferred().

printk safe context is more limiting. It prevents deadlock on logbuf_lock by temporary saving the messages into per-CPU buffers.

In scheduler, we could store the messages directly into the main log buffer. We just need to deffer the console handling to avoid deadlock on the scheduler locks.

Quoted 7 lines

, but we're doing this already around the up() call in __up_console_sem.

So I think these further recursions you're pointed out are already handled correctly, and all we need to do is to break the loop involving semaphore.lock of the console_lock semaphore only. Which I think this patch here achieves.

printk safe context would help only when try_to_wake_up() and all other functions using the same locks _all over the system_ are called printk safe (or deferred) context.

By other words, printk safe context solves only printk() recursion. It does not solve recursion of the scheduler operations.

Best Regards,
Petr

maintainer
#15 lore raw

Re: [PATCH] RFC: console: hack up console_lock more v2

In reply to Daniel Vetter
Quoted 7 lines · Daniel Vetter

console_trylock, called from within printk, can be called from pretty much anywhere. Including try_to_wake_up. Note that this isn't common, usually the box is in pretty bad shape at that point already. But it really doesn't help when then lockdep jumps in and spams the logs, potentially obscuring the real backtrace we're really interested in. One case I've seen (slightly simplified backtrace):

Quoted 10 lines
 Call Trace:
  <IRQ>
  console_trylock+0xe/0x60
  vprintk_emit+0xf1/0x320
  printk+0x4d/0x69
  __warn_printk+0x46/0x90
  native_smp_send_reschedule+0x2f/0x40
  check_preempt_curr+0x81/0xa0
  ttwu_do_wakeup+0x14/0x220
  try_to_wake_up+0x218/0x5f0

try_to_wake_up() takes p->pi_lock. It could deadlock because it can get called recursively from printk_safe_up().

And there are more locks taken from try_to_wake_up(), for example, __task_rq_lock() taken from ttwu_remote().

IMHO, the most reliable solution would be do call the entire up_console_sem() from printk deferred context. We could assign few bytes for this context in the per-CPU printk_deferred variable.

Best Regards,
Petr
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

Re: [Intel-gfx] [PATCH] RFC: console: hack up console_lock more v2

In reply to Daniel Vetter

Quoting Daniel Vetter (2019-05-06 08:45:53)

Quoted 29 lines
kernel/locking/semaphore.c +28 -0
+/**
+ * printk_safe_up - release the semaphore in console_unlock
+ * @sem: the semaphore to release
+ *
+ * Release the semaphore.  Unlike mutexes, up() may be called from any
+ * context and even by tasks which have never called down().
+ *
+ * NOTE: This is a special version of up() for console_unlock only. It is only
+ * safe if there are no killable, interruptible or timing out down() calls.
+ */
+void printk_safe_up(struct semaphore *sem)
+{
+       unsigned long flags;
+       struct semaphore_waiter *waiter = NULL;
+
+       raw_spin_lock_irqsave(&sem->lock, flags);
+       if (likely(list_empty(&sem->wait_list))) {
+               sem->count++;
+       } else {
+               waiter = list_first_entry(&sem->wait_list,
+                                         struct semaphore_waiter, list);
+               list_del(&waiter->list);
+               waiter->up = true;
+       }
+       raw_spin_unlock_irqrestore(&sem->lock, flags);
+
+       if (waiter)
+               wake_up_process(waiter->task);
Quoted 1 line

From comparing against __down_common() there's a risk here that as soon

as waiter->up == true, the waiter may complete and make the onstack struct semaphore_waiter invalid. If you store waiter->task locally under the spinlock that problem is resolved.

Then there is the issue of an unprotected dereference of the task in wake_up_process() -- I think you can wrap this function with rcu_read_lock() to keep that safe, and wake_up_process() should be a no-op if it races against process termination.
-Chris

maintainer
#17 lore raw

Re: [Intel-gfx] [PATCH] RFC: console: hack up console_lock more v2

Quoted 35 lines · Chris Wilson

Quoting Daniel Vetter (2019-05-06 08:45:53)

Quoted 18 lines
kernel/locking/semaphore.c +18 -0
+/**
+ * printk_safe_up - release the semaphore in console_unlock
+ * @sem: the semaphore to release
+ *
+ * Release the semaphore.  Unlike mutexes, up() may be called from any
+ * context and even by tasks which have never called down().
+ *
+ * NOTE: This is a special version of up() for console_unlock only. It is only
+ * safe if there are no killable, interruptible or timing out down() calls.
+ */
+void printk_safe_up(struct semaphore *sem)
+{
+       unsigned long flags;
+       struct semaphore_waiter *waiter = NULL;
+
+       raw_spin_lock_irqsave(&sem->lock, flags);
+       if (likely(list_empty(&sem->wait_list))) {
+               sem->count++;

kernel/locking/semaphore.c struct semaphore_waiter { · line 227

Quoted 10 lines
kernel/locking/semaphore.c +10 -0
+       } else {
+               waiter = list_first_entry(&sem->wait_list,
+                                         struct semaphore_waiter, list);
+               list_del(&waiter->list);
+               waiter->up = true;
+       }
+       raw_spin_unlock_irqrestore(&sem->lock, flags);
+
+       if (waiter)
+               wake_up_process(waiter->task);

From comparing against __down_common() there's a risk here that as soon as waiter->up == true, the waiter may complete and make the onstack struct semaphore_waiter invalid. If you store waiter->task locally under the spinlock that problem is resolved.

Quoted 4 lines

Then there is the issue of an unprotected dereference of the task in wake_up_process() -- I think you can wrap this function with rcu_read_lock() to keep that safe, and wake_up_process() should be a no-op if it races against process termination.

task_struct is not RCU protected, see task_rcu_dereference() for magic.
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw

✗ Fi.CI.CHECKPATCH: warning for RFC: console: hack up console_trylock more (rev2)

In reply to Daniel Vetter
== Series Details ==

== Series Details ==

Series: RFC: console: hack up console_trylock more (rev2)
URL : https://patchwork.freedesktop.org/series/60212/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
679d117ff9c3 RFC: console: hack up console_lock more v2
-:74: CHECK:AVOID_EXTERNS: extern prototypes should be avoided in .h files
#74: FILE: include/linux/semaphore.h:44:
+extern void printk_safe_up(struct semaphore *sem);

-:132: WARNING:NO_AUTHOR_SIGN_OFF: Missing Signed-off-by: line by nominal patch author 'Daniel Vetter <[email protected]>'

total: 0 errors, 1 warnings, 1 checks, 52 lines checked

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#19 lore raw

✗ Fi.CI.BAT: failure for RFC: console: hack up console_trylock more (rev2)

In reply to Daniel Vetter
== Series Details ==

== Series Details ==

Series: RFC: console: hack up console_trylock more (rev2)
URL : https://patchwork.freedesktop.org/series/60212/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_6048 -> Patchwork_12968
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_12968 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_12968, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_12968:

### IGT changes ###

#### Possible regressions ####

* igt@i915_selftest@live_hangcheck:
- fi-apl-guc: [PASS][1] -> [DMESG-FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6048/fi-apl-guc/igt@i915_selftest@live_hangcheck.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/fi-apl-guc/igt@i915_selftest@live_hangcheck.html

#### Warnings ####

* igt@runner@aborted:
- fi-apl-guc: [FAIL][3] ([fdo#108622] / [fdo#109720]) -> [FAIL][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6048/fi-apl-guc/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/fi-apl-guc/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_12968 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live_workarounds:
- fi-icl-y: [PASS][5] -> [INCOMPLETE][6] ([fdo#107713] / [fdo#110581])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6048/fi-icl-y/igt@i915_selftest@live_workarounds.html
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/fi-icl-y/igt@i915_selftest@live_workarounds.html

#### Possible fixes ####

* igt@i915_selftest@live_execlists:
- fi-apl-guc: [INCOMPLETE][7] ([fdo#103927] / [fdo#109720] / [fdo#110581]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6048/fi-apl-guc/igt@i915_selftest@live_execlists.html
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/fi-apl-guc/igt@i915_selftest@live_execlists.html

* igt@kms_flip@basic-flip-vs-wf_vblank:
- fi-bwr-2160: [FAIL][9] ([fdo#100368]) -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6048/fi-bwr-2160/igt@kms_flip@basic-flip-vs-wf_vblank.html
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/fi-bwr-2160/igt@kms_flip@basic-flip-vs-wf_vblank.html

[fdo#100368]: https://bugs.freedesktop.org/show_bug.cgi?id=100368
[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#108622]: https://bugs.freedesktop.org/show_bug.cgi?id=108622
[fdo#109720]: https://bugs.freedesktop.org/show_bug.cgi?id=109720
[fdo#110581]: https://bugs.freedesktop.org/show_bug.cgi?id=110581

Participating hosts (52 -> 45)
------------------------------

Additional (1): fi-bsw-n3050
Missing (8): fi-kbl-soraka fi-ilk-m540 fi-hsw-4200u fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-byt-clapper fi-bdw-samus

Build changes
-------------

* Linux: CI_DRM_6048 -> Patchwork_12968

CI_DRM_6048: 896b156d0aa15d20a798e528ff7e5d529fbf26ae @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4972: f052e49a43cc9704ea5f240df15dd9d3dfed68ab @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12968: 679d117ff9c33340493d143534e192ce490943dc @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

679d117ff9c3 RFC: console: hack up console_lock more v2

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12968/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx