Skip to contentSkip to conversation

RFC: x86/smp: use printk_deferred in native_smp_send_reschedule

PATCH In review Daniel Vetter 3 participants 10 messages May 7, 2019 – May 8, 2019 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: x86/smp: use printk_deferred in native_smp_send_reschedule

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.

This is fix attempt number 3, we've already tried to:

- make the console_trylock trylock also the spinlock. This works in the limited case of the console_lock use-case, but doesn't fix the same semaphore.lock acquisition in the up() path in console_unlock, which we can't avoid with a trylock.

- move the wake_up_process in up() out from under the semaphore.lock spinlock critical section. Again this works for the limited case of the console_lock, and does fully break the cycle for this lock. Unfortunately there's still plenty of scheduler related locks that wake_up_process needs, so the loop is still there, just with a few less locks involved.

Hence now third attempt, trying to fix this by using printk_deferred() instead of the normal printk that WARN() uses. native_smp_send_reschedule is only called from scheduler related code, which has to use printk_deferred due to this locking recursion, so this seems consistent.

It has the unfortunate downside that we're losing the backtrace though (I didn't find a printk_deferred version of WARN, and I'm not sure it's a bright idea to dump that much using printk_deferred.)

Keeping all the people from the console_lock/printk related attempts on cc as fyi.

Note: We can only hit this in our CI, with a very low reproduction rate. And right now the lockdep splat and a few other things crowd out what actually happens in the little bit of dmesg we recover, so no idea yet why exactly we're hitting that WARN().

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]>
Cc Nicolai Stange <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/smp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/smp.c +2 -1
index 04adc8d60aed..f19782786669 100644
@@ -125,7 +125,8 @@ static bool smp_no_nmi_ipi = false;
 static void native_smp_send_reschedule(int cpu)
 {
 	if (unlikely(cpu_is_offline(cpu))) {
-		WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
+		printk_deferred(KERN_WARNING
+				"sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
 		return;
 	}
 	apic->send_IPI(cpu, RESCHEDULE_VECTOR);
Signature · 1 line
2.20.1
#1 lore raw

✗ Fi.CI.CHECKPATCH: warning for RFC: x86/smp: use printk_deferred in native_smp_send_reschedule

== Series Details ==

== Series Details ==

Series: RFC: x86/smp: use printk_deferred in native_smp_send_reschedule
URL : https://patchwork.freedesktop.org/series/60384/
State : warning

== Summary ==

$ dim checkpatch origin/drm-tip
79bd449b8e2d RFC: x86/smp: use printk_deferred in native_smp_send_reschedule
-:93: WARNING:UNNECESSARY_KERN_LEVEL: Possible unnecessary KERN_WARNING
#93: FILE: arch/x86/kernel/smp.c:128:
+		printk_deferred(KERN_WARNING

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

total: 0 errors, 2 warnings, 0 checks, 9 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: x86/smp: use printk_deferred in native_smp_send_reschedule

In reply to Daniel Vetter
== Series Details ==

== Series Details ==

Series: RFC: x86/smp: use printk_deferred in native_smp_send_reschedule
URL : https://patchwork.freedesktop.org/series/60384/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6061 -> Patchwork_12981
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

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

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

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live_contexts:
- fi-bdw-gvtdvm: [PASS][1] -> [DMESG-FAIL][2] ([fdo#110235])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/fi-bdw-gvtdvm/igt@i915_selftest@live_contexts.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/fi-bdw-gvtdvm/igt@i915_selftest@live_contexts.html

* igt@i915_selftest@live_hangcheck:
- fi-skl-iommu: [PASS][3] -> [INCOMPLETE][4] ([fdo#108602] / [fdo#108744])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/fi-skl-iommu/igt@i915_selftest@live_hangcheck.html
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/fi-skl-iommu/igt@i915_selftest@live_hangcheck.html

#### Possible fixes ####

* igt@gem_exec_suspend@basic-s3:
- fi-blb-e6850: [INCOMPLETE][5] ([fdo#107718]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/fi-blb-e6850/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/fi-blb-e6850/igt@[email protected]

* igt@i915_selftest@live_hangcheck:
- {fi-icl-y}: [INCOMPLETE][7] ([fdo#107713] / [fdo#108569]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/fi-icl-y/igt@i915_selftest@live_hangcheck.html
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/fi-icl-y/igt@i915_selftest@live_hangcheck.html

* igt@kms_busy@basic-flip-c:
- fi-skl-6770hq: [SKIP][9] ([fdo#109271] / [fdo#109278]) -> [PASS][10] +2 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/fi-skl-6770hq/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/fi-skl-6770hq/igt@[email protected]

* igt@kms_flip@basic-flip-vs-dpms:
- fi-skl-6770hq: [SKIP][11] ([fdo#109271]) -> [PASS][12] +23 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/fi-skl-6770hq/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/fi-skl-6770hq/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#107718]: https://bugs.freedesktop.org/show_bug.cgi?id=107718
[fdo#108569]: https://bugs.freedesktop.org/show_bug.cgi?id=108569
[fdo#108602]: https://bugs.freedesktop.org/show_bug.cgi?id=108602
[fdo#108744]: https://bugs.freedesktop.org/show_bug.cgi?id=108744
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109278]: https://bugs.freedesktop.org/show_bug.cgi?id=109278
[fdo#110235]: https://bugs.freedesktop.org/show_bug.cgi?id=110235

Participating hosts (49 -> 45)
------------------------------

Additional (4): fi-byt-j1900 fi-icl-u2 fi-icl-u3 fi-snb-2600
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_6061 -> Patchwork_12981

CI_DRM_6061: 2a3ab645af902ecea7c0b89a4ca40dd194bccfd6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4972: f052e49a43cc9704ea5f240df15dd9d3dfed68ab @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12981: 79bd449b8e2dd37f018f106a347a4a5cdbbbbd32 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

79bd449b8e2d RFC: x86/smp: use printk_deferred in native_smp_send_reschedule

== Logs ==

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

#3 lore raw

✓ Fi.CI.IGT: success for RFC: x86/smp: use printk_deferred in native_smp_send_reschedule

In reply to Daniel Vetter
== Series Details ==

== Series Details ==

Series: RFC: x86/smp: use printk_deferred in native_smp_send_reschedule
URL : https://patchwork.freedesktop.org/series/60384/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6061_full -> Patchwork_12981_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

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

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

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_basic@readonly-blt:
- shard-apl: [PASS][1] -> [INCOMPLETE][2] ([fdo#103927])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-apl6/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-apl4/igt@[email protected]

* igt@i915_pm_rpm@i2c:
- shard-iclb: [PASS][3] -> [FAIL][4] ([fdo#104097])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb6/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb3/igt@[email protected]

* igt@kms_flip@dpms-vs-vblank-race-interruptible:
- shard-skl: [PASS][5] -> [FAIL][6] ([fdo#103060])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-skl8/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-skl3/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-suspend:
- shard-apl: [PASS][7] -> [DMESG-WARN][8] ([fdo#108566]) +6 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-apl4/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-apl3/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-render:
- shard-iclb: [PASS][9] -> [FAIL][10] ([fdo#103167]) +1 similar issue
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb8/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-render.html
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb1/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-shrfb-draw-render.html

* igt@kms_plane_lowres@pipe-a-tiling-y:
- shard-iclb: [PASS][11] -> [FAIL][12] ([fdo#103166])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb4/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb4/igt@[email protected]

* igt@kms_psr@psr2_basic:
- shard-iclb: [PASS][13] -> [SKIP][14] ([fdo#109441]) +2 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb2/igt@kms_psr@psr2_basic.html
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb1/igt@kms_psr@psr2_basic.html

* igt@kms_setmode@basic:
- shard-apl: [PASS][15] -> [FAIL][16] ([fdo#99912])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-apl7/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-apl3/igt@[email protected]

#### Possible fixes ####

* igt@gem_eio@reset-stress:
- shard-snb: [FAIL][17] ([fdo#109661]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-snb6/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-snb5/igt@[email protected]

* igt@gem_workarounds@suspend-resume:
- shard-apl: [DMESG-WARN][19] ([fdo#108566]) -> [PASS][20] +3 similar issues
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-apl5/igt@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-apl7/igt@[email protected]

* igt@gem_workarounds@suspend-resume-context:
- shard-kbl: [DMESG-WARN][21] ([fdo#103313]) -> [PASS][22]
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-kbl4/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-kbl1/igt@[email protected]

* igt@kms_draw_crc@draw-method-xrgb8888-render-xtiled:
- shard-skl: [FAIL][23] ([fdo#103184] / [fdo#103232]) -> [PASS][24]
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-skl10/igt@[email protected]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-skl10/igt@[email protected]

* igt@kms_flip@2x-plain-flip-fb-recreate:
- shard-glk: [FAIL][25] ([fdo#100368]) -> [PASS][26]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-glk7/igt@[email protected]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-glk1/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-pri-indfb-multidraw:
- shard-iclb: [FAIL][27] ([fdo#103167]) -> [PASS][28] +2 similar issues
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb2/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb1/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
- shard-skl: [INCOMPLETE][29] ([fdo#104108]) -> [PASS][30]
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-skl10/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-skl2/igt@[email protected]

* igt@kms_plane@pixel-format-pipe-b-planes:
- shard-glk: [SKIP][31] ([fdo#109271]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-glk5/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-glk9/igt@[email protected]

* igt@kms_plane@plane-position-hole-dpms-pipe-b-planes:
- shard-snb: [SKIP][33] ([fdo#109271]) -> [PASS][34] +1 similar issue
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-snb4/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-snb1/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-a-constant-alpha-min:
- shard-skl: [FAIL][35] ([fdo#108145]) -> [PASS][36]
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-skl2/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-skl6/igt@[email protected]

* igt@kms_plane_lowres@pipe-a-tiling-x:
- shard-iclb: [FAIL][37] ([fdo#103166]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb6/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb3/igt@[email protected]

* igt@kms_psr@psr2_cursor_plane_onoff:
- shard-iclb: [SKIP][39] ([fdo#109441]) -> [PASS][40] +3 similar issues
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-iclb7/igt@kms_psr@psr2_cursor_plane_onoff.html
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-iclb2/igt@kms_psr@psr2_cursor_plane_onoff.html

#### Warnings ####

* igt@kms_atomic_transition@3x-modeset-transitions:
- shard-snb: [SKIP][41] ([fdo#109271]) -> [SKIP][42] ([fdo#109271] / [fdo#109278])
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-snb4/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-snb1/igt@[email protected]

* igt@kms_cursor_crc@cursor-512x170-sliding:
- shard-glk: [INCOMPLETE][43] ([fdo#103359] / [k.org#198133]) -> [SKIP][44] ([fdo#109271])
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6061/shard-glk3/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_12981/shard-glk8/igt@[email protected]

[fdo#100368]: https://bugs.freedesktop.org/show_bug.cgi?id=100368
[fdo#103060]: https://bugs.freedesktop.org/show_bug.cgi?id=103060
[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#103313]: https://bugs.freedesktop.org/show_bug.cgi?id=103313
[fdo#103359]: https://bugs.freedesktop.org/show_bug.cgi?id=103359
[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#104097]: https://bugs.freedesktop.org/show_bug.cgi?id=104097
[fdo#104108]: https://bugs.freedesktop.org/show_bug.cgi?id=104108
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[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#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#109661]: https://bugs.freedesktop.org/show_bug.cgi?id=109661
[fdo#99912]: https://bugs.freedesktop.org/show_bug.cgi?id=99912
[k.org#198133]: https://bugzilla.kernel.org/show_bug.cgi?id=198133

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

Missing (1): pig-snb-2600

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

* Linux: CI_DRM_6061 -> Patchwork_12981

CI_DRM_6061: 2a3ab645af902ecea7c0b89a4ca40dd194bccfd6 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4972: f052e49a43cc9704ea5f240df15dd9d3dfed68ab @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_12981: 79bd449b8e2dd37f018f106a347a4a5cdbbbbd32 @ 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_12981/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
In reply to Daniel Vetter

On (05/07/19 19:33), Daniel Vetter wrote:
[..]

Quoted 18 lines

- make the console_trylock trylock also the spinlock. This works in the limited case of the console_lock use-case, but doesn't fix the same semaphore.lock acquisition in the up() path in console_unlock, which we can't avoid with a trylock.

- move the wake_up_process in up() out from under the semaphore.lock spinlock critical section. Again this works for the limited case of the console_lock, and does fully break the cycle for this lock. Unfortunately there's still plenty of scheduler related locks that wake_up_process needs, so the loop is still there, just with a few less locks involved.

Hence now third attempt, trying to fix this by using printk_deferred() instead of the normal printk that WARN() uses. native_smp_send_reschedule is only called from scheduler related code, which has to use printk_deferred due to this locking recursion, so this seems consistent.

Quoted 3 lines

It has the unfortunate downside that we're losing the backtrace though (I didn't find a printk_deferred version of WARN, and I'm not sure it's a bright idea to dump that much using printk_deferred.)

I'm catching up with the emails now (was offline for almost 2 weeks), so I haven't seen [yet] all of the previous patches/discussions.

[..]

arch/x86/kernel/smp.c static bool smp_no_nmi_ipi = false; · line 132

Quoted 9 lines

static void native_smp_send_reschedule(int cpu)
{

arch/x86/kernel/smp.c +2 -1
 	if (unlikely(cpu_is_offline(cpu))) {
-		WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
+		printk_deferred(KERN_WARNING
+				"sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
 		return;
 	}
 	apic->send_IPI(cpu, RESCHEDULE_VECTOR);

Hmm,
One thing to notice here is that the CPU in question is offline-ed, and printk_deferred() is a per-CPU type of deferred printk(). So the following thing

	__this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
	irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));

might not print anything at all. In this particular case we always need another CPU to do console_unlock(), since this_cpu() is not really expected to do wake_up_klogd_work_func()->console_unlock().

	-ss
#5 lore raw
Quoted 16 lines · Sergey Senozhatsky

[..]

arch/x86/kernel/smp.c static bool smp_no_nmi_ipi = false; · line 132

Quoted 9 lines

static void native_smp_send_reschedule(int cpu)
{

arch/x86/kernel/smp.c +2 -1
 	if (unlikely(cpu_is_offline(cpu))) {
-		WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
+		printk_deferred(KERN_WARNING
+				"sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
 		return;
 	}
 	apic->send_IPI(cpu, RESCHEDULE_VECTOR);

Hmm,
One thing to notice here is that the CPU in question is offline-ed, and printk_deferred() is a per-CPU type of deferred printk(). So the following thing

Quoted 6 lines
	__this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
	irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));

might not print anything at all. In this particular case we always need another CPU to do console_unlock(), since this_cpu() is not really expected to do wake_up_klogd_work_func()->console_unlock().

D'oh... It's remote CPU which is offline, not this_cpu(). Sorry, my bad!

Any printk-related patch in this area will make PeterZ really-really angry :)

printk_deferred(), just like prinkt_safe(), depends on IRQ work; printk_safe(), however, can redirect multiple lines, unlike printk_deferred(). So if you want to keep the backtrace, you may do something like

	if (unlikely(cpu_is_offline(cpu))) {
		printk_safe_enter(...);
		WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n",
			 cpu);
		printk_safe_exit(...);
		return;
	}

I think, in this case John's reworked-printk can do better than printk_safe/printk_deferred.

	-ss
#6 lore raw
Quoted 21 lines · Sergey Senozhatsky
Quoted 19 lines · Sergey Senozhatsky

[..]

arch/x86/kernel/smp.c static bool smp_no_nmi_ipi = false; · line 132

Quoted 9 lines

static void native_smp_send_reschedule(int cpu)

 {
    if (unlikely(cpu_is_offline(cpu))) {
arch/x86/kernel/smp.c +2 -1
-           WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
+           printk_deferred(KERN_WARNING
+                           "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
            return;
    }
    apic->send_IPI(cpu, RESCHEDULE_VECTOR);

Hmm,
One thing to notice here is that the CPU in question is offline-ed, and printk_deferred() is a per-CPU type of deferred printk(). So the following thing

      __this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
      irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));
Quoted 6 lines
Quoted 3 lines

might not print anything at all. In this particular case we always need another CPU to do console_unlock(), since this_cpu() is not really expected to do wake_up_klogd_work_func()->console_unlock().

D'oh... It's remote CPU which is offline, not this_cpu(). Sorry, my bad!

Well I started reading, then freaked out about the WARN_ON in irq_work_queue_on until I realized that's not the one we're calling either :-)

Quoted 2 lines

Any printk-related patch in this area will make PeterZ really-really angry :)

Hm any more context for someone with no clue about this? Just that the dependencies are already terribly complex and it's not going to get better, or something more specific?

Quoted 13 lines

printk_deferred(), just like prinkt_safe(), depends on IRQ work; printk_safe(), however, can redirect multiple lines, unlike printk_deferred(). So if you want to keep the backtrace, you may do something like

        if (unlikely(cpu_is_offline(cpu))) {
                printk_safe_enter(...);
                WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n",
                         cpu);
                printk_safe_exit(...);
                return;
        }
Quoted 2 lines

I think, in this case John's reworked-printk can do better than printk_safe/printk_deferred.

Hm I think this is what Petr was suggesting, but somehow I didn't find the printk_safe_* functions and didn't connect the dots. Needs the _irqsave variants I guess, I'll respin a v2 of this. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#7 lore raw

On (05/08/19 10:06), Daniel Vetter wrote:
[..]

Quoted 6 lines
Quoted 2 lines

Any printk-related patch in this area will make PeterZ really-really angry :)

Hm any more context for someone with no clue about this? Just that the dependencies are already terribly complex and it's not going to get better, or something more specific?

The main problem is that it's a deferred error-reporting, so such a report has chances to never be reported. It's not like 'normal' printk() is always guaranteed to immediately start printing; sometimes it will, sometimes it won't, and sometimes it never will, for instance when console_sem was locked by offline-ed CPU.

An example of PeterZ's opinion on printk_deferred()
/* message ID: [email protected] */

| No, printk_deferred() is a disease, it needs to be eradicated, not | spread around.

Quoted 13 lines
Quoted 13 lines

printk_deferred(), just like prinkt_safe(), depends on IRQ work; printk_safe(), however, can redirect multiple lines, unlike printk_deferred(). So if you want to keep the backtrace, you may do something like

        if (unlikely(cpu_is_offline(cpu))) {
                printk_safe_enter(...);
                WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n",
                         cpu);
                printk_safe_exit(...);
                return;
        }
Quoted 5 lines
Quoted 2 lines

I think, in this case John's reworked-printk can do better than printk_safe/printk_deferred.

Hm I think this is what Petr was suggesting, but somehow I didn't find the printk_safe_* functions and didn't connect the dots.

These are in kernel/printk/printk_safe.c as of now.

Quoted 1 line

Needs the _irqsave variants I guess, I'll respin a v2 of this.

Let's wait a bit before respin.

	-ss
#8 lore raw
In reply to Sergey Senozhatsky
Quoted 44 lines · Sergey Senozhatsky
Quoted 16 lines · Sergey Senozhatsky

[..]

arch/x86/kernel/smp.c static bool smp_no_nmi_ipi = false; · line 132

Quoted 9 lines

static void native_smp_send_reschedule(int cpu)

 {
    if (unlikely(cpu_is_offline(cpu))) {
arch/x86/kernel/smp.c +2 -1
-           WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
+           printk_deferred(KERN_WARNING
+                           "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
            return;
    }
    apic->send_IPI(cpu, RESCHEDULE_VECTOR);

Hmm,
One thing to notice here is that the CPU in question is offline-ed, and printk_deferred() is a per-CPU type of deferred printk(). So the following thing

Quoted 6 lines
      __this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
      irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));

might not print anything at all. In this particular case we always need another CPU to do console_unlock(), since this_cpu() is not really expected to do wake_up_klogd_work_func()->console_unlock().

D'oh... It's remote CPU which is offline, not this_cpu(). Sorry, my bad!

Any printk-related patch in this area will make PeterZ really-really angry :)

printk_deferred(), just like prinkt_safe(), depends on IRQ work; printk_safe(), however, can redirect multiple lines, unlike printk_deferred(). So if you want to keep the backtrace, you may do something like

        if (unlikely(cpu_is_offline(cpu))) {
                printk_safe_enter(...);
                WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n",
                         cpu);
                printk_safe_exit(...);
                return;
        }
Quoted 2 lines

I think, in this case John's reworked-printk can do better than printk_safe/printk_deferred.

[coffee slowly kicking in it seems]

Locking at __up_console_sem in printk.c, we already do this. I get a bit a feeling that the 2nd attempt in this saga (pulling the wake_up_process out from under semaphore.lock spinlock of the console_lock) is all we really need, since the more direct recursion that Petr pointed out is already handled with printk_safe_enter/exit around the up().

https://patchwork.kernel.org/patch/10930673/ for reference that approach, in case it's lost in your inbox.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#9 lore raw
In reply to Sergey Senozhatsky
Quoted 44 lines · Sergey Senozhatsky

On (05/07/19 19:33), Daniel Vetter wrote:
[..]

Quoted 18 lines

- make the console_trylock trylock also the spinlock. This works in the limited case of the console_lock use-case, but doesn't fix the same semaphore.lock acquisition in the up() path in console_unlock, which we can't avoid with a trylock.

- move the wake_up_process in up() out from under the semaphore.lock spinlock critical section. Again this works for the limited case of the console_lock, and does fully break the cycle for this lock. Unfortunately there's still plenty of scheduler related locks that wake_up_process needs, so the loop is still there, just with a few less locks involved.

Hence now third attempt, trying to fix this by using printk_deferred() instead of the normal printk that WARN() uses. native_smp_send_reschedule is only called from scheduler related code, which has to use printk_deferred due to this locking recursion, so this seems consistent.

Quoted 3 lines

It has the unfortunate downside that we're losing the backtrace though (I didn't find a printk_deferred version of WARN, and I'm not sure it's a bright idea to dump that much using printk_deferred.)

I'm catching up with the emails now (was offline for almost 2 weeks), so I haven't seen [yet] all of the previous patches/discussions.

[..]

arch/x86/kernel/smp.c static bool smp_no_nmi_ipi = false; · line 132

Quoted 9 lines

static void native_smp_send_reschedule(int cpu)

 {
      if (unlikely(cpu_is_offline(cpu))) {
arch/x86/kernel/smp.c +2 -1
-             WARN(1, "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
+             printk_deferred(KERN_WARNING
+                             "sched: Unexpected reschedule of offline CPU#%d!\n", cpu);
              return;
      }
      apic->send_IPI(cpu, RESCHEDULE_VECTOR);

Hmm,
One thing to notice here is that the CPU in question is offline-ed, and printk_deferred() is a per-CPU type of deferred printk(). So the following thing

Quoted 6 lines
        __this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
        irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));

might not print anything at all. In this particular case we always need another CPU to do console_unlock(), since this_cpu() is not really expected to do wake_up_klogd_work_func()->console_unlock().

Hm right, I was happy enough when Petr pointed out the printk_deferred infrastructure that I didn't look too deeply into how it works. From a quick loo

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch