From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: ntb@lists.linux.dev
Subject: Re: [PATCH v2 03/14] NTB: ntb_transport: Avoid deadlock when cancelling link work
Date: Thu, 10 Sep 2026 04:23:32 +0000 [thread overview]
Message-ID: <20260910042332.892FA1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260910040836.3792333-4-den@valinux.co.jp>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Dropping `link_event_lock` around `cancel_delayed_work_sync()` introduces a race condition that can permanently tear down a successfully established link.
Pre-existing issues:
- [High] Separate work items for link-up and link-down events can execute out of order, leading to a permanent link failure.
--
commit d67dbc659b034b7a703fc35d72b81082c61a2ecd
Author: Koichiro Den <den@valinux.co.jp>
NTB: ntb_transport: Avoid deadlock when cancelling link work
This commit changes ntb_transport_link_cleanup() to cancel the link_work
delayed work item outside of the link_event_lock. This avoids a deadlock
where a retry in link_work blocks on the lock held by the cleanup function.
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 55a20ae9a85e6..c77b173dca01f 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -960,6 +960,15 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt)
> struct ntb_transport_qp *qp;
> u64 qp_bitmap_alloc;
> unsigned int i, count;
> + bool cancel_link_work;
> +
> + scoped_guard(mutex, &nt->link_event_lock)
> + cancel_link_work = !nt->link_is_up;
> +
> + if (cancel_link_work)
> + cancel_delayed_work_sync(&nt->link_work);
> +
> + guard(mutex)(&nt->link_event_lock);
[Severity: High]
Does dropping the link_event_lock around cancel_delayed_work_sync() create a
race condition that could permanently tear down the link?
If a hardware link flap occurs, ntb_transport_event_callback() can queue both
link_work and link_cleanup. If link_cleanup executes, it evaluates
!nt->link_is_up under the scoped_guard, drops the lock, and calls
cancel_delayed_work_sync().
During this unlocked window, a pending link_work can acquire the lock,
successfully establish the NTB link, set nt->link_is_up = true, and complete.
When link_cleanup reacquires the lock, it unconditionally destroys the QPs
and MWs that were just successfully established, without re-evaluating the
link state.
Can we re-check the link state after reacquiring the lock to prevent this
permanent link failure?
[ ... ]
As an additional observation regarding the event handling:
drivers/ntb/ntb_transport.c:ntb_transport_event_callback() {
...
if (ntb_link_is_up(nt->ndev, NULL, NULL) == 1)
schedule_delayed_work(&nt->link_work, 0);
else
schedule_work(&nt->link_cleanup);
...
}
[Severity: High]
This isn't a bug introduced by this patch, but does using separate work items
for link-up and link-down events allow them to execute out of order?
Since link_work and link_cleanup are queued to the global workqueue as
distinct work items, rapid hardware flapping (DOWN then UP) can queue both
simultaneously.
If they execute out of order, or if link_cleanup executes last and cancels an
un-run link_work, the software state could be torn down permanently even
though the physical hardware state is UP.
Could a single work item or a state machine handle both events to enforce
ordering?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910040836.3792333-1-den@valinux.co.jp?part=3
next prev parent reply other threads:[~2026-09-10 4:23 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 4:08 [PATCH v2 00/14] NTB: ntb_transport: Miscellaneous fixes Koichiro Den
2026-09-10 4:08 ` [PATCH v2 01/14] NTB: ntb_transport: Remove the device debugfs directory Koichiro Den
2026-09-10 4:20 ` sashiko-bot
2026-09-10 18:41 ` Frank Li
2026-09-10 4:08 ` [PATCH v2 02/14] NTB: ntb_transport: Start TX offload thread after queue setup Koichiro Den
2026-09-11 16:13 ` Frank Li
2026-09-10 4:08 ` [PATCH v2 03/14] NTB: ntb_transport: Avoid deadlock when cancelling link work Koichiro Den
2026-09-10 4:23 ` sashiko-bot [this message]
2026-09-11 16:21 ` Frank Li
2026-09-11 17:41 ` Koichiro Den
2026-09-10 4:08 ` [PATCH v2 04/14] NTB: ntb_transport: Publish link state after QP setup Koichiro Den
2026-09-11 16:39 ` Frank Li
2026-09-10 4:08 ` [PATCH v2 05/14] NTB: ntb_transport: Avoid losing QP link-up requests Koichiro Den
2026-09-10 4:26 ` sashiko-bot
2026-09-11 16:53 ` Frank Li
2026-09-11 18:04 ` Koichiro Den
2026-09-11 18:21 ` Koichiro Den
2026-09-12 3:20 ` Frank Li
2026-09-12 14:52 ` Koichiro Den
2026-09-10 4:08 ` [PATCH v2 06/14] NTB: ntb_transport: Clear link state before QP cleanup Koichiro Den
2026-09-10 4:27 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 07/14] NTB: ntb_transport: Stop QP work before freeing a queue Koichiro Den
2026-09-10 4:23 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 08/14] NTB: ntb_transport: Stop RX tasklet scheduling " Koichiro Den
2026-09-10 4:08 ` [PATCH v2 09/14] NTB: ntb_transport: Drain RX tasklets during link cleanup Koichiro Den
2026-09-10 4:23 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 10/14] NTB: ntb_transport: Wait for RX completions before resetting a QP Koichiro Den
2026-09-10 4:24 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 11/14] NTB: ntb_transport: Prepare remote RX info accesses for MW teardown Koichiro Den
2026-09-10 4:31 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 12/14] NTB: ntb_transport: Clear QP pointers when freeing an MW Koichiro Den
2026-09-10 4:32 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 13/14] NTB: ntb_transport: Abort link setup on QP MW allocation failure Koichiro Den
2026-09-10 4:40 ` sashiko-bot
2026-09-10 4:08 ` [PATCH v2 14/14] NTB: ntb_transport: Remove clients before freeing transport resources Koichiro Den
2026-09-10 4:36 ` sashiko-bot
2026-09-10 8:48 ` Koichiro Den
2026-09-11 15:49 ` Dave Jiang
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=20260910042332.892FA1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=den@valinux.co.jp \
--cc=ntb@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.