semaphore: might_lock(->pi_lock) in up()
PATCH 1/1 semaphore: might_lock(->pi_lock) in up()
In one of our bugs we very rarely see a lockdep splat on boot-up. The locking loop only happens when the console_sem semaphore is contended in a specific path, which doesn't happen all too often. Help out lockdep a bit with a might_lock annotation.
For reference, the full splat:
WARNING: CPU: 0 PID: 216 at lib/debugobjects.c:291 debug_print_object+0x67/0x80 ---[ end trace 1dcad5e101ee43df ]---
======================================================
WARNING: possible circular locking dependency detected 4.16.0-rc5-g178cfb9373cc-drmtip_2+ #1 Not tainted
------------------------------------------------------
systemd-udevd/216 is trying to acquire lock:
((console_sem).lock){..-.}, at: [<0000000073293a25>] down_trylock+0xa/0x30
but task is already holding lock:
(&obj_hash[i].lock){-.-.}, at: [<00000000023c4e37>] debug_check_no_obj_freed+0xa4/0x230
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #3 (&obj_hash[i].lock){-.-.}:
__debug_object_init+0x5f/0x430
hrtimer_init+0x1b/0x150
init_dl_task_timer+0x17/0x30
__sched_fork.isra.16+0xa7/0x100
init_idle+0x53/0x270
sched_init+0x42f/0x4a5
start_kernel+0x20e/0x3f0
secondary_startup_64+0xa5/0xb0-> #2 (&rq->lock){-.-.}:
task_fork_fair+0x36/0x120
sched_fork+0x12f/0x2a0
copy_process.part.7+0x5e4/0x1d90
_do_fork+0xc0/0x6b0
kernel_thread+0x20/0x30
rest_init+0x1d/0x220
start_kernel+0x3e8/0x3f0
secondary_startup_64+0xa5/0xb0-> #1 (&p->pi_lock){-.-.}:
try_to_wake_up+0x27/0x610
up+0x3b/0x50
__up_console_sem+0x2e/0x50
console_unlock+0x31f/0x650
do_con_write.part.12+0x6fd/0x9a0
con_write+0x4d/0x60
do_output_char+0x168/0x1d0
n_tty_write+0x1f8/0x450
tty_write+0x1b6/0x2e0
do_iter_write+0x140/0x180
vfs_writev+0x84/0xf0
do_writev+0x4c/0xd0
do_syscall_64+0x65/0x1a0
entry_SYSCALL_64_after_hwframe+0x42/0xb7-> #0 ((console_sem).lock){..-.}:
_raw_spin_lock_irqsave+0x33/0x50
down_trylock+0xa/0x30
__down_trylock_console_sem+0x20/0x80
console_trylock+0xe/0x60
vprintk_emit+0x24f/0x4f0
printk+0x3e/0x46
__warn_printk+0x37/0x70
debug_print_object+0x67/0x80
debug_check_no_obj_freed+0x1ef/0x230
__vunmap+0x5b/0x110
load_module+0x2347/0x2dc0
SyS_finit_module+0xa5/0xe0
do_syscall_64+0x65/0x1a0
entry_SYSCALL_64_after_hwframe+0x42/0xb7other info that might help us debug this:
Chain exists of: (console_sem).lock --> &rq->lock --> &obj_hash[i].lock Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&obj_hash[i].lock);
lock(&rq->lock);
lock(&obj_hash[i].lock);lock((console_sem).lock);
*** DEADLOCK ***
1 lock held by systemd-udevd/216:
#0: (&obj_hash[i].lock){-.-.}, at: [<00000000023c4e37>] debug_check_no_obj_freed+0xa4/0x230
stack backtrace: CPU: 0 PID: 216 Comm: systemd-udevd Not tainted 4.16.0-rc5-g178cfb9373cc-drmtip_2+ #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.10.1-0-g8891697-prebuilt.qemu-project.org 04/01/2014 Call Trace: dump_stack+0x5f/0x86 print_circular_bug.isra.18+0x1d0/0x2c0 __lock_acquire+0x14ae/0x1b60 ? lock_acquire+0xaf/0x200 lock_acquire+0xaf/0x200 ? down_trylock+0xa/0x30 ? vprintk_emit+0x24f/0x4f0 _raw_spin_lock_irqsave+0x33/0x50 ? down_trylock+0xa/0x30 down_trylock+0xa/0x30 __down_trylock_console_sem+0x20/0x80 console_trylock+0xe/0x60 vprintk_emit+0x24f/0x4f0 printk+0x3e/0x46 ? clock_was_set_work+0x20/0x20 __warn_printk+0x37/0x70 ? debug_check_no_obj_freed+0xa4/0x230 ? clock_was_set_work+0x20/0x20 debug_print_object+0x67/0x80 debug_check_no_obj_freed+0x1ef/0x230 __vunmap+0x5b/0x110 load_module+0x2347/0x2dc0 ? show_coresize+0x20/0x20 ? vfs_read+0x126/0x150 ? SyS_finit_module+0xa5/0xe0 SyS_finit_module+0xa5/0xe0 do_syscall_64+0x65/0x1a0 entry_SYSCALL_64_after_hwframe+0x42/0xb7 RIP: 0033:0x7f5037e42839 RSP: 002b:00007fff88b69df8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 RAX: ffffffffffffffda RBX: 00005599ad713550 RCX: 00007f5037e42839 RDX: 0000000000000000 RSI: 00007f5037b210e5 RDI: 000000000000000f RBP: 00007f5037b210e5 R08: 0000000000000000 R09: 00007fff88b69f10 R10: 000000000000000f R11: 0000000000000246 R12: 0000000000000000 R13: 00005599ad707370 R14: 0000000000020000 R15: 00005599ad713550
References: https://bugs.freedesktop.org/show_bug.cgi?id=105600
---
For now this is just a quick test patch for CI. I'll resubmit once we gathered some data.
-Daniel
--- kernel/locking/semaphore.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/locking/semaphore.c +3 -0
@@ -181,6 +181,9 @@ void up(struct semaphore *sem)unsigned long flags;raw_spin_lock_irqsave (&sem->lock, flags); +/* if we wake up a task we need its ->pi_lock, just pretend to take ours +* for the lockdep accounting. */ +might_lock (¤t->pi_lock);if (likely (list_empty (&sem->wait_list))) sem->count++;else
Signature · 6 lines
2.16.2 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Fi.CI.CHECKPATCH: warning for semaphore: might_lock(->pi_lock) in up()
== Series Details ==
== Series Details ==
Series: semaphore: might_lock(->pi_lock) in up()
URL : https://patchwork.freedesktop.org/series/40256/
State : warning
== Summary ==
$ dim checkpatch origin/drm-tip
757a703afe1d semaphore: might_lock(->pi_lock) in up()
-:24: WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line)
#24:
(&obj_hash[i].lock){-.-.}, at: [<00000000023c4e37>] debug_check_no_obj_freed+0xa4/0x230-:153: WARNING:BLOCK_COMMENT_STYLE: Block comments use a trailing */ on a separate line #153: FILE: kernel/locking/semaphore.c:185:
+ * for the lockdep accounting. */
total: 0 errors, 2 warnings, 0 checks, 9 lines checked
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.BAT: success for semaphore: might_lock(->pi_lock) in up()
In reply to Daniel Vetter== Series Details ==
== Series Details ==
Series: semaphore: might_lock(->pi_lock) in up()
URL : https://patchwork.freedesktop.org/series/40256/
State : success
== Summary ==
Series 40256v1 semaphore: might_lock(->pi_lock) in up()
https://patchwork.freedesktop.org/api/1.0/series/40256/revisions/1/mbox/
---- Known issues:
Test gem_mmap_gtt:
Subgroup basic-small-bo-tiledx:
fail -> PASS (fi-gdg-551) fdo#102575
Test kms_pipe_crc_basic:
Subgroup suspend-read-crc-pipe-b:
incomplete -> PASS (fi-snb-2520m) fdo#103713fdo#102575 https://bugs.freedesktop.org/show_bug.cgi?id=102575
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
fi-bdw-5557u total:285 pass:264 dwarn:0 dfail:0 fail:0 skip:21 time:432s fi-bdw-gvtdvm total:285 pass:261 dwarn:0 dfail:0 fail:0 skip:24 time:445s fi-blb-e6850 total:285 pass:220 dwarn:1 dfail:0 fail:0 skip:64 time:384s fi-bsw-n3050 total:285 pass:239 dwarn:0 dfail:0 fail:0 skip:46 time:536s fi-bwr-2160 total:285 pass:180 dwarn:0 dfail:0 fail:0 skip:105 time:298s fi-bxt-dsi total:285 pass:255 dwarn:0 dfail:0 fail:0 skip:30 time:514s fi-bxt-j4205 total:285 pass:256 dwarn:0 dfail:0 fail:0 skip:29 time:510s fi-byt-j1900 total:285 pass:250 dwarn:0 dfail:0 fail:0 skip:35 time:514s fi-byt-n2820 total:285 pass:246 dwarn:0 dfail:0 fail:0 skip:39 time:503s fi-cfl-8700k total:285 pass:257 dwarn:0 dfail:0 fail:0 skip:28 time:411s fi-cfl-s2 total:285 pass:259 dwarn:0 dfail:0 fail:0 skip:26 time:579s fi-cfl-u total:285 pass:259 dwarn:0 dfail:0 fail:0 skip:26 time:509s fi-cnl-drrs total:285 pass:254 dwarn:3 dfail:0 fail:0 skip:28 time:524s fi-elk-e7500 total:285 pass:225 dwarn:1 dfail:0 fail:0 skip:59 time:425s fi-gdg-551 total:285 pass:177 dwarn:0 dfail:0 fail:0 skip:108 time:320s fi-hsw-4770 total:285 pass:258 dwarn:0 dfail:0 fail:0 skip:27 time:402s fi-ilk-650 total:285 pass:225 dwarn:0 dfail:0 fail:0 skip:60 time:418s fi-ivb-3520m total:285 pass:256 dwarn:0 dfail:0 fail:0 skip:29 time:470s fi-ivb-3770 total:285 pass:252 dwarn:0 dfail:0 fail:0 skip:33 time:430s fi-kbl-7500u total:285 pass:260 dwarn:1 dfail:0 fail:0 skip:24 time:473s fi-kbl-7567u total:285 pass:265 dwarn:0 dfail:0 fail:0 skip:20 time:465s fi-kbl-r total:285 pass:258 dwarn:0 dfail:0 fail:0 skip:27 time:521s fi-pnv-d510 total:285 pass:219 dwarn:1 dfail:0 fail:0 skip:65 time:656s fi-skl-6260u total:285 pass:265 dwarn:0 dfail:0 fail:0 skip:20 time:435s fi-skl-6600u total:285 pass:258 dwarn:0 dfail:0 fail:0 skip:27 time:538s fi-skl-6700hq total:285 pass:259 dwarn:0 dfail:0 fail:0 skip:26 time:540s fi-skl-6700k2 total:285 pass:261 dwarn:0 dfail:0 fail:0 skip:24 time:508s fi-skl-6770hq total:285 pass:265 dwarn:0 dfail:0 fail:0 skip:20 time:487s fi-skl-guc total:285 pass:257 dwarn:0 dfail:0 fail:0 skip:28 time:426s fi-skl-gvtdvm total:285 pass:262 dwarn:0 dfail:0 fail:0 skip:23 time:441s fi-snb-2520m total:285 pass:245 dwarn:0 dfail:0 fail:0 skip:40 time:573s fi-snb-2600 total:285 pass:245 dwarn:0 dfail:0 fail:0 skip:40 time:401s
141def2a45f4a3ad7c7e9144cd26e97bb1298397 drm-tip: 2018y-03m-19d-23h-48m-43s UTC integration manifest 757a703afe1d semaphore: might_lock(->pi_lock) in up()
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_8409/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✓ Fi.CI.IGT: success for semaphore: might_lock(->pi_lock) in up()
In reply to Daniel Vetter== Series Details ==
== Series Details ==
Series: semaphore: might_lock(->pi_lock) in up()
URL : https://patchwork.freedesktop.org/series/40256/
State : success
== Summary ==
---- Known issues:
Test kms_cursor_legacy:
Subgroup 2x-long-flip-vs-cursor-legacy:
incomplete -> PASS (shard-hsw) fdo#104873
Test kms_flip:
Subgroup 2x-flip-vs-expired-vblank-interruptible:
pass -> FAIL (shard-hsw) fdo#102887
Subgroup dpms-vs-vblank-race:
fail -> PASS (shard-hsw) fdo#103060
Subgroup flip-vs-absolute-wf_vblank:
fail -> PASS (shard-hsw) fdo#100368
Test kms_flip_tiling:
Subgroup flip-x-tiled:
fail -> PASS (shard-apl) fdo#103822
Test kms_pipe_crc_basic:
Subgroup suspend-read-crc-pipe-a:
skip -> PASS (shard-snb) fdo#103375 +1
Test kms_plane:
Subgroup plane-position-hole-pipe-c-planes:
fail -> PASS (shard-apl) fdo#103166fdo#104873 https://bugs.freedesktop.org/show_bug.cgi?id=104873
fdo#102887 https://bugs.freedesktop.org/show_bug.cgi?id=102887
fdo#103060 https://bugs.freedesktop.org/show_bug.cgi?id=103060
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#103822 https://bugs.freedesktop.org/show_bug.cgi?id=103822
fdo#103375 https://bugs.freedesktop.org/show_bug.cgi?id=103375
fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166
shard-apl total:3478 pass:1814 dwarn:1 dfail:0 fail:7 skip:1655 time:12993s shard-hsw total:3478 pass:1767 dwarn:1 dfail:0 fail:2 skip:1707 time:11779s shard-snb total:3478 pass:1357 dwarn:1 dfail:0 fail:2 skip:2118 time:7146s
Blacklisted hosts:
shard-kbl total:3478 pass:1939 dwarn:1 dfail:1 fail:9 skip:1528 time:9858s
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_8409/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx