Re: [PATCH v2 2/2] tty: Fix race against tty_open() in tty_register_device_attr()

kernel test robot
2025-06-03T08:49:45Z

Hello,

kernel test robot noticed "WARNING:possible_circular_locking_dependency_detected" on:

commit: c3184e841ee2a1585b89e4bbd90cacb41063871f ("[PATCH v2 2/2] tty: Fix race against tty_open() in tty_register_device_attr()")
url: https://github.com/intel-lab-lkp/linux/commits/Max-Staudt/tty-Fix-race-against-tty_open-in-tty_register_device_attr/20250528-213024
base: https://git.kernel.org/cgit/linux/kernel/git/gregkh/tty.git tty-testing
patch link: https://lore.kernel.org/all/20250528132816.11433-2-max@enpas.org/
patch subject: [PATCH v2 2/2] tty: Fix race against tty_open() in tty_register_device_attr()

in testcase: boot

config: x86_64-randconfig-001-20250530
compiler: gcc-12
test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G

(please refer to attached dmesg/kmsg for entire log/backtrace)

+-------------------------------------------------------------------------------------------------------------------------------------------------------+------------+------------+
| | 44db64e370 | c3184e841e |
+-------------------------------------------------------------------------------------------------------------------------------------------------------+------------+------------+
| WARNING:possible_circular_locking_dependency_detected | 0 | 6 |
| WARNING:possible_circular_locking_dependency_detected_swapper_is_trying_to_acquire_lock:at:tty_port_open_but_task_is_already_holding_lock:at:tty_lock | 0 | 6 |
+-------------------------------------------------------------------------------------------------------------------------------------------------------+------------+------------+

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Closes: https://lore.kernel.org/oe-lkp/202506031638.a5c78088-lkp@intel.com

[ 22.678060][ T1] WARNING: possible circular locking dependency detected
[ 22.678860][ T1] 6.15.0-rc4-00108-gc3184e841ee2 #1 Tainted: G T
[ 22.679596][ T1] ------------------------------------------------------
[ 22.680280][ T1] swapper/1 is trying to acquire lock:
[ 22.680750][ T1] ffff888101cf02d0 (&port->mutex){+.+.}-{4:4}, at: tty_port_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_port.c:761)
[ 22.681597][ T1]
[ 22.681597][ T1] but task is already holding lock:
[ 22.682232][ T1] ffff8881084f91e0 (&tty->legacy_mutex){+.+.}-{4:4}, at: tty_lock (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_mutex.c:19)
[ 22.683067][ T1]
[ 22.683067][ T1] which lock already depends on the new lock.
[ 22.683067][ T1]
[ 22.683981][ T1]
[ 22.683981][ T1] the existing dependency chain (in reverse order) is:
[ 22.684732][ T1]
[ 22.684732][ T1] -> #2 (&tty->legacy_mutex){+.+.}-{4:4}:
[ 22.685465][ T1] validate_chain (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3286 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3909)
[ 22.685990][ T1] __lock_acquire (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5235)
[ 22.688240][ T1] lock_acquire (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:472 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5868 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5823)
[ 22.688677][ T1] __mutex_lock (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:603 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:746)
[ 22.689128][ T1] mutex_lock_nested (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:799)
[ 22.689636][ T1] tty_lock (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_mutex.c:19)
[ 22.690065][ T1] tty_init_dev (kbuild/obj/consumer/x86_64-randconfig-001-20250530/include/linux/module.h:730)
[ 22.690553][ T1] tty_init_dev (kbuild/obj/consumer/x86_64-randconfig-001-20250530/include/linux/module.h:730)
[ 22.691065][ T1] tty_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_io.c:2073 kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_io.c:2120)
[ 22.691582][ T1] chrdev_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/char_dev.c:414)
[ 22.692010][ T1] do_dentry_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:956)
[ 22.692506][ T1] vfs_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:1087)
[ 22.692910][ T1] do_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/namei.c:3881)
[ 22.693344][ T1] path_openat (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/namei.c:4039)
[ 22.693796][ T1] do_filp_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/namei.c:4067)
[ 22.694218][ T1] file_open_name (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:1374)
[ 22.694669][ T1] filp_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:1394)
[ 22.695063][ T1] console_on_rootfs (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1528)
[ 22.695624][ T1] kernel_init_freeable (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1578)
[ 22.696135][ T1] kernel_init (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1459)
[ 22.696554][ T1] ret_from_fork (kbuild/obj/consumer/x86_64-randconfig-001-20250530/arch/x86/kernel/process.c:159)
[ 22.697060][ T1] ret_from_fork_asm (kbuild/obj/consumer/x86_64-randconfig-001-20250530/arch/x86/entry/entry_64.S:258)
[ 22.697516][ T1]
[ 22.697516][ T1] -> #1 (tty_mutex){+.+.}-{4:4}:
[ 22.698166][ T1] validate_chain (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3286 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3909)
[ 22.698652][ T1] __lock_acquire (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5235)
[ 22.699158][ T1] lock_acquire (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:472 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5868 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5823)
[ 22.699577][ T1] __mutex_lock (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:603 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:746)
[ 22.700113][ T1] mutex_lock_nested (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:799)
[ 22.700564][ T1] tty_register_device_attr (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_io.c:3250)
[ 22.701135][ T1] tty_port_register_device_attr_serdev (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_port.c:199)
[ 22.701722][ T1] serial_core_add_one_port (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/serial_core.c:3184)
[ 22.702255][ T1] serial_core_register_port (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/serial_core.c:3388)
[ 22.702868][ T1] serial_ctrl_register_port (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/serial_ctrl.c:42)
[ 22.703443][ T1] uart_add_one_port (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/serial_port.c:144)
[ 22.703888][ T1] serial8250_register_8250_port (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/8250/8250_core.c:822)
[ 22.704473][ T1] serial_pnp_probe (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/8250/8250_pnp.c:480)
[ 22.704935][ T1] pnp_device_probe (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/pnp/driver.c:113)
[ 22.705438][ T1] really_probe (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:579 kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:657)
[ 22.705882][ T1] __driver_probe_device (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:799)
[ 22.706388][ T1] driver_probe_device (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:829)
[ 22.706886][ T1] __driver_attach (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:1216 kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:1155)
[ 22.707345][ T1] bus_for_each_dev (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/bus.c:369)
[ 22.707854][ T1] driver_attach (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/dd.c:1234)
[ 22.708343][ T1] bus_add_driver (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/bus.c:678)
[ 22.708788][ T1] driver_register (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/base/driver.c:249)
[ 22.709313][ T1] pnp_register_driver (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/pnp/driver.c:281)
[ 22.709779][ T1] serial8250_pnp_init (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/8250/8250_pnp.c:531)
[ 22.710314][ T1] serial8250_init (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/8250/8250_platform.c:315)
[ 22.710850][ T1] do_one_initcall (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1257)
[ 22.711331][ T1] do_initcalls (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1318 kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1335)
[ 22.711819][ T1] kernel_init_freeable (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1569)
[ 22.712320][ T1] kernel_init (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1459)
[ 22.712739][ T1] ret_from_fork (kbuild/obj/consumer/x86_64-randconfig-001-20250530/arch/x86/kernel/process.c:159)
[ 22.713196][ T1] ret_from_fork_asm (kbuild/obj/consumer/x86_64-randconfig-001-20250530/arch/x86/entry/entry_64.S:258)
[ 22.713650][ T1]
[ 22.713650][ T1] -> #0 (&port->mutex){+.+.}-{4:4}:
[ 22.714356][ T1] check_noncircular (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:2215)
[ 22.714826][ T1] check_prev_add (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3167)
[ 22.715274][ T1] validate_chain (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3286 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:3909)
[ 22.715793][ T1] __lock_acquire (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5235)
[ 22.716237][ T1] lock_acquire (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:472 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5868 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/lockdep.c:5823)
[ 22.716741][ T1] __mutex_lock (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:603 kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:746)
[ 22.717172][ T1] mutex_lock_nested (kbuild/obj/consumer/x86_64-randconfig-001-20250530/kernel/locking/mutex.c:799)
[ 22.717631][ T1] tty_port_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_port.c:761)
[ 22.718106][ T1] uart_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/serial/serial_core.c:1974)
[ 22.718642][ T1] tty_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/drivers/tty/tty_io.c:2140)
[ 22.719094][ T1] chrdev_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/char_dev.c:414)
[ 22.719514][ T1] do_dentry_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:956)
[ 22.719966][ T1] vfs_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:1087)
[ 22.720411][ T1] do_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/namei.c:3881)
[ 22.720873][ T1] path_openat (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/namei.c:4039)
[ 22.721298][ T1] do_filp_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/namei.c:4067)
[ 22.721848][ T1] file_open_name (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:1374)
[ 22.722280][ T1] filp_open (kbuild/obj/consumer/x86_64-randconfig-001-20250530/fs/open.c:1394)
[ 22.722739][ T1] console_on_rootfs (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1528)
[ 22.723194][ T1] kernel_init_freeable (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1578)
[ 22.723695][ T1] kernel_init (kbuild/obj/consumer/x86_64-randconfig-001-20250530/init/main.c:1459)
[ 22.724200][ T1] ret_from_fork (kbuild/obj/consumer/x86_64-randconfig-001-20250530/arch/x86/kernel/process.c:159)
[ 22.724709][ T1] ret_from_fork_asm (kbuild/obj/consumer/x86_64-randconfig-001-20250530/arch/x86/entry/entry_64.S:258)
[ 22.725164][ T1]
[ 22.725164][ T1] other info that might help us debug this:
[ 22.725164][ T1]
[ 22.726026][ T1] Chain exists of:
[ 22.726026][ T1] &port->mutex --> tty_mutex --> &tty->legacy_mutex
[ 22.726026][ T1]

The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20250603/202506031638.a5c78088-lkp@intel.com

--
0-DAY CI Kernel Test Service