From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Bin Luo <luob87709@gmail.com>
Cc: linux-usb@vger.kernel.org, andreas.noever@gmail.com,
westeri@kernel.org, YehezkelShB@gmail.com
Subject: Re: [BUG] thunderbolt: request work may outlive control channel teardown
Date: Wed, 25 Nov 2026 15:04:50 +0100 [thread overview]
Message-ID: <20261125140450.GF191152@black.igk.intel.com> (raw)
In-Reply-To: <20261125130000.475-1-luob87709@gmail.com>
Hi,
On Wed, Nov 25, 2026 at 09:00:00PM +0800, Bin Luo wrote:
> Hi,
>
> I found a possible lifetime issue between asynchronous XDomain response work
> and control-channel teardown. The source path below is from Linux v7.4-rc1,
> commit 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4.
>
> Source path
> -----------
>
> An incoming XDomain request is scheduled by `tb_xdp_schedule_request()` in
> `drivers/thunderbolt/xdomain.c`; its worker is `tb_xdp_handle_request()` at
> line 762. For example, the `LINK_STATE_CHANGE_REQUEST` case at lines 896-906
> calls `tb_xdp_link_state_change_response()`, which sends the response through
> `__tb_xdomain_response()` (line 608).
>
> `__tb_xdomain_response()` allocates a `tb_cfg_request` and calls
> `tb_cfg_request()` with no response buffer. In `drivers/thunderbolt/ctl.c`,
> `tb_cfg_request()` schedules `req->work` on the system workqueue at line 570.
> `tb_cfg_request_work()` at line 527 invokes the callback, then calls
> `tb_cfg_request_dequeue()` at line 534. Dequeue reads the raw `req->ctl`
> pointer and locks `ctl->request_queue_lock` at line 161.
>
> The teardown path is separate. `tb_domain_remove()` in
> `drivers/thunderbolt/domain.c:501` calls `tb_ctl_stop()` (`ctl.c:750`), which
> stops the rings, warns if requests remain, and reinitializes the request-list
> head. It does not cancel or synchronously drain every request work item on the
> system workqueue. `tb_domain_remove()` flushes `tb->wq` (`domain.c:510`), but
> the request worker uses the system workqueue. The domain release handler later
> calls `tb_ctl_free()` (`domain.c:317-322`, `ctl.c:704`), freeing the control
> channel. The host NHI PCI remove path reaches `tb_domain_remove()` through
> `nhi_pci_do_remove()` in `drivers/thunderbolt/pci.c:594-619`.
>
> The request kref protects `req`; I do not see a request-held reference that
> pins `req->ctl` through dequeue. A delayed work item could therefore lock a
> freed control-channel mutex. The `ctl.c` and `domain.c` blobs at this baseline
> match upstream comparison snapshot
> 4dce97c6c265544342e716e62fd24bbb232590c5.
>
> Reproduction
> ------------
>
> The attached `thunderbolt_test_injection.patch` adds a test-only built-in hook.
> It creates a minimal `tb_ctl` and `tb_cfg_request` with the real allocator and
> enqueue helper, reinitializes the request-list head, optionally frees `ctl`,
> then directly invokes the real `tb_cfg_request_work()`. This forces the
> lifetime order; it does not call `tb_ctl_stop()` or `tb_domain_remove()`, queue
> the worker through the real system workqueue, send an XDomain packet, or use a
> physical Thunderbolt/USB4 controller.
>
> The attached `config.selected` is the complete x86_64 configuration used; it
> has `CONFIG_USB4=y`, `CONFIG_KASAN=y`, and `CONFIG_KASAN_GENERIC=y`. With the
> attached patch and config, the build and QEMU steps are:
Thank you for the report!
Can you provide the exact steps we can run on real hardware to reproduce
this?
Like:
1. Boot the system, nothing connected.
2. Connect device router X to port Y.
3. Verify USB4 link via ..
...
prev parent reply other threads:[~2026-11-25 14:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 13:00 [BUG] thunderbolt: request work may outlive control channel teardown Bin Luo
2026-11-25 13:06 ` Bin Luo
2026-11-25 14:04 ` Mika Westerberg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125140450.GF191152@black.igk.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=luob87709@gmail.com \
--cc=westeri@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox