Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Oguzhan KAYNAK" <kaynak.oguzhan0@gmail.com>
Cc: ntb@lists.linux.dev
Subject: Re: [RFC PATCH 1/3] NTB: ntb_transport: Run a pending link cleanup before the next link setup
Date: Sun, 06 Dec 2026 07:33:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-252247@kernel.org> (raw)
In-Reply-To: <20261206070959.8519-2-kaynak.oguzhan0@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ntb_transport: unsynchronized link_up check causes spurious
  link teardown
--

commit ff41587a6452a6a2bd40eda8955de637cc27dd31
Author: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>

NTB: ntb_transport: Run a pending link cleanup before the next link setup

This commit adds a link_down_pending flag so that ntb_transport_link_work()
defers link setup until a pending ntb_transport_link_cleanup() completes, and
has ntb_transport_link_cleanup_work() reschedule link_work if the hardware
link is up.

> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 3cf2d778bf925..31c214d147c4c 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c

[ ... ]

> @@ -1057,17 +1068,27 @@ static void ntb_transport_link_cleanup_work(struct work_struct *work)
>  	struct ntb_transport_ctx *nt =
>  		container_of(work, struct ntb_transport_ctx, link_cleanup);
>  
> -	ntb_transport_link_cleanup(nt);
> +	ntb_transport_link_cleanup(nt, true);
> +
> +	/*
> +	 * ntb_transport_link_work() does nothing while a cleanup is pending,
> +	 * and the cleanup may have cancelled it: set the link up now if the
> +	 * link came back.
> +	 */
> +	if (ntb_link_is_up(nt->ndev, NULL, NULL) == 1)
> +		schedule_delayed_work(&nt->link_work, 0);
>  }
>  
>  static void ntb_transport_event_callback(void *data)
>  {
>  	struct ntb_transport_ctx *nt = data;
>  
> -	if (ntb_link_is_up(nt->ndev, NULL, NULL) == 1)
> +	if (ntb_link_is_up(nt->ndev, NULL, NULL) == 1) {
>  		schedule_delayed_work(&nt->link_work, 0);
> -	else
> +	} else {
> +		atomic_set(&nt->link_down_pending, 1);
>  		schedule_work(&nt->link_cleanup);
> +	}
>  }

[Severity: Medium]
Can a delayed ntb_transport_event_callback() set link_down_pending after the
link has already come up, tearing down a live link?

ntb_link_event() only holds ntb->ctx_lock around
ntb_transport_event_callback(), which the link work items never take.  If
CPU0 is delayed between reading ntb_link_is_up() == 0 and setting
link_down_pending while an earlier cleanup finishes:

CPU0                              CPU1
ntb_transport_event_callback()    ntb_transport_link_cleanup_work()
  ntb_link_is_up() == 0             ntb_transport_link_cleanup(nt, true)
  /* delayed */                       atomic_xchg(&link_down_pending, 0)
                                      ...
                                  /* hardware link comes up */
                                    ntb_link_is_up() == 1
                                    schedule_delayed_work(&link_work, 0)
                                  ntb_transport_link_work()
                                    link_down_pending == 0, link_is_up == 0
                                    /* completes handshake with peer */
                                    atomic_set_release(&link_is_up, true)
  atomic_set(&link_down_pending, 1)
  schedule_work(&link_cleanup)    ntb_transport_link_cleanup_work()
                                    ntb_transport_link_cleanup(nt, true)
                                      /* tears down QPs/MWs, zeroes spads */
                                        <-- spurious link teardown

The second cleanup zeroes the local scratchpads and reschedules link_work,
which then reads VERSION == 0 and retries indefinitely while the peer still
considers the link up and does not rewrite the scratchpads.  The transport
link stays wedged until another hardware link-down occurs.

Serializing the ntb_link_is_up() check and link_down_pending update against
ntb_transport_link_cleanup_work() and ntb_transport_link_work() would close
this race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206070959.8519-1-kaynak.oguzhan0@gmail.com?part=1

  reply	other threads:[~2026-12-06  7:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  7:09 [RFC PATCH 0/3] NTB: ntb_transport: Lost link-up after a late link cleanup Oguzhan KAYNAK
2026-12-06  7:09 ` [RFC PATCH 1/3] NTB: ntb_transport: Run a pending link cleanup before the next link setup Oguzhan KAYNAK
2026-12-06  7:33   ` sashiko-bot [this message]
2026-12-06  7:09 ` [RFC PATCH 2/3] NTB: ntb_transport: Retry link setup on a zero peer MW size Oguzhan KAYNAK
2026-12-06  7:32   ` sashiko-bot
2026-12-06  7:09 ` [RFC PATCH 3/3] NTB: ntb_transport: Keep scratchpads in a cleanup before first link-up Oguzhan KAYNAK
2026-12-06  7:35   ` sashiko-bot

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=sashiko-outbox-252247@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kaynak.oguzhan0@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox