RBP: 00007f6078a121d0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000002
R13: 00007ffc8500ee5f R14: 00007f6078a12300 R15: 0000000000022000
======================================================
WARNING: possible circular locking dependency detected
5.10.123 #1 Not tainted
------------------------------------------------------
syz-executor.4/18315 is trying to acquire lock:
ffffffff84d0b5c0 (console_owner){-.-.}-{0:0}, at: console_unlock+0x2e1/0xb30 kernel/printk/printk.c:2507

but task is already holding lock:
ffff88800fc3c958 (&port->lock){-.-.}-{2:2}, at: pty_write+0xf4/0x1f0 drivers/tty/pty.c:120

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&port->lock){-.-.}-{2:2}:
       __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
       _raw_spin_lock_irqsave+0x36/0x50 kernel/locking/spinlock.c:159
       tty_port_tty_get+0x1f/0x100 drivers/tty/tty_port.c:288
       tty_port_default_wakeup+0x11/0x40 drivers/tty/tty_port.c:47
       serial8250_tx_chars+0x516/0xa90 drivers/tty/serial/8250/8250_port.c:1861
       serial8250_handle_irq.part.0+0x3f1/0x4c0 drivers/tty/serial/8250/8250_port.c:1948
       serial8250_handle_irq drivers/tty/serial/8250/8250_port.c:1921 [inline]
       serial8250_default_handle_irq+0xb8/0x230 drivers/tty/serial/8250/8250_port.c:1964
       serial8250_interrupt+0xf4/0x1a0 drivers/tty/serial/8250/8250_core.c:126
       __handle_irq_event_percpu+0x2ef/0x820 kernel/irq/handle.c:156
       handle_irq_event_percpu kernel/irq/handle.c:196 [inline]
       handle_irq_event+0xff/0x280 kernel/irq/handle.c:213
       handle_edge_irq+0x249/0xd00 kernel/irq/chip.c:822
       asm_call_irq_on_stack+0x12/0x20
       __run_irq_on_irqstack arch/x86/include/asm/irq_stack.h:48 [inline]
       run_irq_on_irqstack_cond arch/x86/include/asm/irq_stack.h:101 [inline]
       handle_irq arch/x86/kernel/irq.c:230 [inline]
       __common_interrupt arch/x86/kernel/irq.c:249 [inline]
       common_interrupt+0xdd/0x190 arch/x86/kernel/irq.c:239
       asm_common_interrupt+0x1e/0x40 arch/x86/include/asm/idtentry.h:626
       native_restore_fl arch/x86/include/asm/irqflags.h:41 [inline]
       arch_local_irq_restore arch/x86/include/asm/irqflags.h:84 [inline]
       __raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:160 [inline]
       _raw_spin_unlock_irqrestore+0x25/0x40 kernel/locking/spinlock.c:191
       spin_unlock_irqrestore include/linux/spinlock.h:409 [inline]
       uart_write+0x304/0x580 drivers/tty/serial/serial_core.c:622
       do_output_char+0x5e4/0x860 drivers/tty/n_tty.c:442
       process_output drivers/tty/n_tty.c:509 [inline]
       n_tty_write+0x487/0xf90 drivers/tty/n_tty.c:2395
       do_tty_write drivers/tty/tty_io.c:1028 [inline]
       file_tty_write.constprop.0+0x4f8/0x8d0 drivers/tty/tty_io.c:1118
       redirected_tty_write+0xa1/0xc0 drivers/tty/tty_io.c:1125
       call_write_iter include/linux/fs.h:1903 [inline]
       do_iter_readv_writev+0x476/0x750 fs/read_write.c:740
       do_iter_write+0x18d/0x670 fs/read_write.c:866
       vfs_writev+0x1aa/0x5e0 fs/read_write.c:939
       do_writev+0x139/0x300 fs/read_write.c:982
       do_syscall_64+0x33/0x40 arch/x86/entry/common.c:46
       entry_SYSCALL_64_after_hwframe+0x44/0xa9

-> #1 (&port_lock_key){-.-.}-{2:2}:
       __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
       _raw_spin_lock_irqsave+0x36/0x50 kernel/locking/spinlock.c:159
       serial8250_console_write+0x90b/0xb60 drivers/tty/serial/8250/8250_port.c:3340
       call_console_drivers kernel/printk/printk.c:1911 [inline]
       console_unlock+0x826/0xb30 kernel/printk/printk.c:2532
       register_console kernel/printk/printk.c:2873 [inline]
       register_console+0x53d/0x800 kernel/printk/printk.c:2763
       univ8250_console_init+0x3a/0x46 drivers/tty/serial/8250/8250_core.c:690
       console_init+0x361/0x4fa kernel/printk/printk.c:2983
       start_kernel+0x2e1/0x48a init/main.c:982
       secondary_startup_64_no_verify+0xc2/0xcb

-> #0 (console_owner){-.-.}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:2988 [inline]
       check_prevs_add kernel/locking/lockdep.c:3113 [inline]
       validate_chain kernel/locking/lockdep.c:3728 [inline]
       __lock_acquire+0x29e3/0x5b00 kernel/locking/lockdep.c:4954
       lock_acquire kernel/locking/lockdep.c:5564 [inline]
       lock_acquire+0x197/0x490 kernel/locking/lockdep.c:5529
       console_lock_spinning_enable kernel/printk/printk.c:1763 [inline]
       console_unlock+0x360/0xb30 kernel/printk/printk.c:2529
       vprintk_emit+0x1da/0x4d0 kernel/printk/printk.c:2054
       vprintk_func+0x8b/0x140 kernel/printk/printk_safe.c:401
       printk+0xba/0xed kernel/printk/printk.c:2102
       fail_dump lib/fault-inject.c:45 [inline]
       should_fail+0x472/0x5a0 lib/fault-inject.c:146
       should_failslab+0x5/0x10 mm/slab_common.c:1193
       slab_pre_alloc_hook mm/slab.h:515 [inline]
       slab_alloc_node mm/slub.c:2821 [inline]
       slab_alloc mm/slub.c:2904 [inline]
       __kmalloc+0x72/0x3e0 mm/slub.c:3967
       kmalloc include/linux/slab.h:557 [inline]
       tty_buffer_alloc+0x23f/0x2a0 drivers/tty/tty_buffer.c:175
       __tty_buffer_request_room+0x156/0x2a0 drivers/tty/tty_buffer.c:274
       tty_insert_flip_string_fixed_flag+0x91/0x250 drivers/tty/tty_buffer.c:319
       tty_insert_flip_string include/linux/tty_flip.h:37 [inline]
       pty_write+0x126/0x1f0 drivers/tty/pty.c:122
       n_tty_write+0xa44/0xf90 drivers/tty/n_tty.c:2406
       do_tty_write drivers/tty/tty_io.c:1028 [inline]
       file_tty_write.constprop.0+0x4f8/0x8d0 drivers/tty/tty_io.c:1118
       call_write_iter include/linux/fs.h:1903 [inline]
       do_iter_readv_writev+0x476/0x750 fs/read_write.c:740
       do_iter_write+0x18d/0x670 fs/read_write.c:866
       vfs_iter_write+0x70/0xa0 fs/read_write.c:907
       iter_file_splice_write+0x71d/0xbe0 fs/splice.c:686
       do_splice_from fs/splice.c:764 [inline]
       direct_splice_actor+0x10f/0x170 fs/splice.c:933
       splice_direct_to_actor+0x387/0x980 fs/splice.c:888
       do_splice_direct+0x1c4/0x290 fs/splice.c:976
       do_sendfile+0x54f/0x1040 fs/read_write.c:1257
       __do_sys_sendfile64 fs/read_write.c:1318 [inline]
       __se_sys_sendfile64 fs/read_write.c:1304 [inline]
       __x64_sys_sendfile64+0x1cd/0x210 fs/read_write.c:1304
       do_syscall_64+0x33/0x40 arch/x86/entry/common.c:46
       entry_SYSCALL_64_after_hwframe+0x44/0xa9

other info that might help us debug this:

Chain exists of:
  console_owner --> &port_lock_key --> &port->lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&port->lock);
                               lock(&port_lock_key);
                               lock(&port->lock);
  lock(console_owner);

 *** DEADLOCK ***

6 locks held by syz-executor.4/18315:
 #0: ffff88804fc4a098 (&tty->ldisc_sem){++++}-{0:0}, at: tty_ldisc_ref_wait+0x22/0x80 drivers/tty/tty_ldisc.c:266
 #1: ffff88804fc4a130 (&tty->atomic_write_lock){+.+.}-{3:3}, at: tty_write_lock drivers/tty/tty_io.c:952 [inline]
 #1: ffff88804fc4a130 (&tty->atomic_write_lock){+.+.}-{3:3}, at: do_tty_write drivers/tty/tty_io.c:975 [inline]
 #1: ffff88804fc4a130 (&tty->atomic_write_lock){+.+.}-{3:3}, at: file_tty_write.constprop.0+0x29d/0x8d0 drivers/tty/tty_io.c:1118
 #2: ffff88804fc4a2e8 (&tty->termios_rwsem){++++}-{3:3}, at: n_tty_write+0x1bf/0xf90 drivers/tty/n_tty.c:2366
 #3: ffffc9000f64a378 (&ldata->output_lock){+.+.}-{3:3}, at: n_tty_write+0xa0b/0xf90 drivers/tty/n_tty.c:2405
 #4: ffff88800fc3c958 (&port->lock){-.-.}-{2:2}, at: pty_write+0xf4/0x1f0 drivers/tty/pty.c:120
 #5: ffffffff84deb940 (console_lock){+.+.}-{0:0}, at: vprintk_func+0x8b/0x140 kernel/printk/printk_safe.c:401

stack backtrace:
CPU: 1 PID: 18315 Comm: syz-executor.4 Not tainted 5.10.123 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x107/0x163 lib/dump_stack.c:118
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2123
 check_prev_add kernel/locking/lockdep.c:2988 [inline]
 check_prevs_add kernel/locking/lockdep.c:3113 [inline]
 validate_chain kernel/locking/lockdep.c:3728 [inline]
 __lock_acquire+0x29e3/0x5b00 kernel/locking/lockdep.c:4954
 lock_acquire kernel/locking/lockdep.c:5564 [inline]
 lock_acquire+0x197/0x490 kernel/locking/lockdep.c:5529
 console_lock_spinning_enable kernel/printk/printk.c:1763 [inline]
 console_unlock+0x360/0xb30 kernel/printk/printk.c:2529
 vprintk_emit+0x1da/0x4d0 kernel/printk/printk.c:2054
 vprintk_func+0x8b/0x140 kernel/printk/printk_safe.c:401
 printk+0xba/0xed kernel/printk/printk.c:2102
 fail_dump lib/fault-inject.c:45 [inline]
 should_fail+0x472/0x5a0 lib/fault-inject.c:146
 should_failslab+0x5/0x10 mm/slab_common.c:1193
 slab_pre_alloc_hook mm/slab.h:515 [inline]
 slab_alloc_node mm/slub.c:2821 [inline]
 slab_alloc mm/slub.c:2904 [inline]
 __kmalloc+0x72/0x3e0 mm/slub.c:3967
 kmalloc include/linux/slab.h:557 [inline]
 tty_buffer_alloc+0x23f/0x2a0 drivers/tty/tty_buffer.c:175
 __tty_buffer_request_room+0x156/0x2a0 drivers/tty/tty_buffer.c:274
 tty_insert_flip_string_fixed_flag+0x91/0x250 drivers/tty/tty_buffer.c:319
 tty_insert_flip_string include/linux/tty_flip.h:37 [inline]
 pty_write+0x126/0x1f0 drivers/tty/pty.c:122
 n_tty_write+0xa44/0xf90 drivers/tty/n_tty.c:2406
 do_tty_write drivers/tty/tty_io.c:1028 [inline]
 file_tty_write.constprop.0+0x4f8/0x8d0 drivers/tty/tty_io.c:1118
 call_write_iter include/linux/fs.h:1903 [inline]
 do_iter_readv_writev+0x476/0x750 fs/read_write.c:740
 do_iter_write+0x18d/0x670 fs/read_write.c:866
 vfs_iter_write+0x70/0xa0 fs/read_write.c:907
 iter_file_splice_write+0x71d/0xbe0 fs/splice.c:686
 do_splice_from fs/splice.c:764 [inline]
 direct_splice_actor+0x10f/0x170 fs/splice.c:933
 splice_direct_to_actor+0x387/0x980 fs/splice.c:888
 do_splice_direct+0x1c4/0x290 fs/splice.c:976
 do_sendfile+0x54f/0x1040 fs/read_write.c:1257
 __do_sys_sendfile64 fs/read_write.c:1318 [inline]
 __se_sys_sendfile64 fs/read_write.c:1304 [inline]
 __x64_sys_sendfile64+0x1cd/0x210 fs/read_write.c:1304
 do_syscall_64+0x33/0x40 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7f607b49cb19
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f6078a12188 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f607b5aff60 RCX: 00007f607b49cb19
RDX: 0000000000000000 RSI: 0000000000000003 RDI: 0000000000000004
RBP: 00007f6078a121d0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000002
R13: 00007ffc8500ee5f R14: 00007f6078a12300 R15: 0000000000022000