Re: [RFC PATCH] thunderbolt: cancel pending DP bandwidth requests on teardown
From: Mika Westerberg
Date: Mon Nov 23 2026 - 00:45:33 EST
Hi,
On Thu, Nov 19, 2026 at 10:35:58AM +0800, Yaohan Li wrote:
> tb_queue_dp_bandwidth_request() queues its delayed work and keeps no
> record of it. The retry path in tb_handle_dp_bandwidth_request() queues
> the work again with a 50 ms delay, and tb_deinit() only cancels the
> bandwidth group release works. The flush_workqueue() in
> tb_domain_remove() runs before tb_deinit() but it does not cover a
> delayed work whose timer has not expired yet, so a request that is
> waiting for its retry can run after the domain has been removed and the
> tb structure has been freed.
>
> Record the queued requests in tb_cm and cancel the remaining ones in
> tb_deinit(), which runs after the workqueue has been flushed and before
> the domain device is unregistered. A request is recorded and queued
> while holding dp_bandwidth_lock, so tb_deinit() either sees it and
> cancels it or the request is rejected before it is queued at all. A
> work item that is already running hands the ownership of its request
> back to tb_deinit() through the canceled flag.
>
> This covers the list and the delayed work, not the lifetime of @tb.
> dp_bandwidth_closed keeps new work from being queued, but it is not a
> reference on @tb. Both in-tree callers are reached from the DP
> bandwidth handling in tb.c - one from the bandwidth work that runs on
> tb->wq, one from the control channel event path that tb_ctl_stop()
> stops - and tb_deinit() runs after both have been drained.
>
> Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>
>
> ---
> Prepared against v7.4-rc1-1969-g666539eecdf4.
>
> Compile tested only: arm64 with aarch64-linux-gnu-gcc 11.4
> and CONFIG_USB4=m. The affected hardware was not
> available, so the teardown path was not exercised and no fault or
> race injection was run.
For complex fixes like this, I would definitely want a real hardware repro,
and also a proof that your change actually fix it and does not cause any
unexpected "side effects".