From: Koichiro Den <den@valinux.co.jp>
To: Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
Allen Hubbe <allenbh@gmail.com>, Frank Li <Frank.Li@kernel.org>,
Logan Gunthorpe <logang@deltatee.com>
Cc: fuyuanli <fuyuanli0722@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Nicholas Bellinger <nab@linux-iscsi.org>,
Joey Zhang <joey.zhang@microchip.com>,
ntb@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v3 15/15] NTB: ntb_transport: Remove clients before freeing transport resources
Date: Tue, 29 Sep 2026 00:25:50 +0900 [thread overview]
Message-ID: <20260928152550.3354675-16-den@valinux.co.jp> (raw)
In-Reply-To: <20260928152550.3354675-1-den@valinux.co.jp>
Unbinding ntb_transport can call ntb_transport_free() while ntb_netdev
is still bound. The transport frees MWs and QP resources before
unregistering the clients, so the netdev's transmit path and timer can
access freed memory. Its remove callback also calls
ntb_transport_free_queue() on a QP whose resources have already been
released. This teardown order is unsafe and somewhat unintuitive.
The crash can be reproduced with an intensive TX load, during which you
unbind the NTB device. The following is a KASAN report from my
VHOST/HOST setup using vNTB.
VHOST# sudo iperf3 -ub0 -c $HOST -l 100 -P 100 &
VHOST# echo $VHOST_NTB_DEV > /sys/bus/ntb/drivers/ntb_transport/unbind
==================================================================
BUG: KASAN: vmalloc-out-of-bounds in ntb_transport_tx_free_entry+0xf0
...
Call trace:
...
__asan_report_load4_noabort+0x1c/0x30
ntb_transport_tx_free_entry+0xf0/0x130 [ntb_transport]
ntb_netdev_tx_timer+0x78/0x260 [ntb_netdev]
...
Disable and drain transport link work first, then unregister the clients
so they stop using and release their QPs. After that, free any QPs left
over before running transport link cleanup. Disabling the work keeps
link events from restarting setup or cleanup during client removal.
Fixes: fce8a7bb5b4b ("PCI-Express Non-Transparent Bridge Support")
Cc: stable@vger.kernel.org
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Koichiro Den <den@valinux.co.jp>
---
Changes in v3:
- Add Reviewed-by tag. No code changes.
drivers/ntb/ntb_transport.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index af7f240479f4..eef3a214d91a 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -1484,9 +1484,11 @@ static void ntb_transport_free(struct ntb_client *self, struct ntb_dev *ndev)
debugfs_remove_recursive(nt->debugfs_node_dir);
- ntb_transport_link_cleanup(nt);
- cancel_work_sync(&nt->link_cleanup);
- cancel_delayed_work_sync(&nt->link_work);
+ /* Stop transport work before clients release their QPs. */
+ disable_delayed_work_sync(&nt->link_work);
+ disable_work_sync(&nt->link_cleanup);
+
+ ntb_bus_remove(nt);
qp_bitmap_alloc = nt->qp_bitmap & ~nt->qp_bitmap_free;
@@ -1497,11 +1499,10 @@ static void ntb_transport_free(struct ntb_client *self, struct ntb_dev *ndev)
ntb_transport_free_queue(qp);
}
+ ntb_transport_link_cleanup(nt);
ntb_link_disable(ndev);
ntb_clear_ctx(ndev);
- ntb_bus_remove(nt);
-
for (i = nt->mw_count; i--; ) {
ntb_free_mw(nt, i);
iounmap(nt->mw_vec[i].vbase);
--
2.51.0
prev parent reply other threads:[~2026-09-28 15:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 15:25 [PATCH v3 00/15] NTB: ntb_transport: Miscellaneous fixes Koichiro Den
2026-09-28 15:25 ` [PATCH v3 01/15] NTB: ntb_transport: Remove the device debugfs directory Koichiro Den
2026-09-28 15:25 ` [PATCH v3 02/15] NTB: ntb_transport: Start TX offload thread after queue setup Koichiro Den
2026-09-28 15:25 ` [PATCH v3 03/15] NTB: ntb_transport: Make link setup flags atomic Koichiro Den
2026-09-28 15:53 ` Logan Gunthorpe
2026-10-09 23:08 ` Dave Jiang
2026-09-28 15:25 ` [PATCH v3 04/15] NTB: ntb_transport: Avoid deadlock when cancelling link work Koichiro Den
2026-10-09 23:09 ` Dave Jiang
2026-09-28 15:25 ` [PATCH v3 05/15] NTB: ntb_transport: Publish link state after QP setup Koichiro Den
2026-09-28 15:25 ` [PATCH v3 06/15] NTB: ntb_transport: Avoid losing QP link-up requests Koichiro Den
2026-09-28 16:57 ` Logan Gunthorpe
2026-09-29 1:43 ` Koichiro Den
2026-10-09 23:11 ` Dave Jiang
2026-10-15 3:50 ` Koichiro Den
2026-10-27 15:03 ` Koichiro Den
2026-09-28 15:25 ` [PATCH v3 07/15] NTB: ntb_transport: Clear link state before QP cleanup Koichiro Den
2026-09-28 15:25 ` [PATCH v3 08/15] NTB: ntb_transport: Stop QP work before freeing a queue Koichiro Den
2026-10-09 23:11 ` Dave Jiang
2026-09-28 15:25 ` [PATCH v3 09/15] NTB: ntb_transport: Stop RX tasklet scheduling " Koichiro Den
2026-09-28 15:25 ` [PATCH v3 10/15] NTB: ntb_transport: Drain RX tasklets during link cleanup Koichiro Den
2026-09-28 15:25 ` [PATCH v3 11/15] NTB: ntb_transport: Wait for RX completions before resetting a QP Koichiro Den
2026-09-28 15:25 ` [PATCH v3 12/15] NTB: ntb_transport: Prepare remote RX info accesses for MW teardown Koichiro Den
2026-09-28 15:25 ` [PATCH v3 13/15] NTB: ntb_transport: Clear QP pointers when freeing an MW Koichiro Den
2026-09-28 15:25 ` [PATCH v3 14/15] NTB: ntb_transport: Abort link setup on QP MW allocation failure Koichiro Den
2026-09-28 15:25 ` Koichiro Den [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=20260928152550.3354675-16-den@valinux.co.jp \
--to=den@valinux.co.jp \
--cc=Frank.Li@kernel.org \
--cc=allenbh@gmail.com \
--cc=dave.jiang@intel.com \
--cc=fuyuanli0722@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jdmason@kudzu.us \
--cc=joey.zhang@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=nab@linux-iscsi.org \
--cc=ntb@lists.linux.dev \
--cc=stable@vger.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
all inboxes | Powered by JetHome®