From: Koichiro Den <den@valinux.co.jp>
To: Manivannan Sadhasivam <mani@kernel.org>, Frank Li <Frank.Li@kernel.org>
Cc: "Jon Mason" <jdmason@kudzu.us>,
"Dave Jiang" <dave.jiang@intel.com>,
"Allen Hubbe" <allenbh@gmail.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
ntb@lists.linux.dev, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v6 0/2] PCI: endpoint: pci-epf-*ntb: Harden vNTB resource management
Date: Tue, 1 Sep 2026 15:32:36 +0900 [thread overview]
Message-ID: <20260901063238.631166-1-den@valinux.co.jp> (raw)
Hi,
This is a follow-up to v5:
https://lore.kernel.org/r/20260226084142.2226875-1-den@valinux.co.jp/
Patches 1-3 from v5 were applied. This v6 addresses the remaining
lifetime issue. Mani, sorry for the delay.
Before this series:
bind: EPC resources -> virtual PCI bus -> ntb_dev -> NTB clients
unbind: EPC resources freed
virtual PCI hierarchy, ntb_dev, and NTB clients left behind
(The bus returned by pci_scan_bus() was not retained, and
pci-vntb had no .remove callback.)
After this series:
bind: EPC resources -> virtual PCI root bus -> ntb_dev -> NTB clients
unbind: NTB clients -> ntb_dev -> virtual PCI root bus -> EPC resources
Testing
=======
I ran the following script on R-Car S4. It only checks removal and
re-creation of the local virtual PCI and NTB devices. No peer or PCIe
link is needed.
#!/bin/bash
set -eu
modprobe ntb_transport
modprobe pci_epf_vntb
cd /sys/kernel/config/pci_ep
F=functions/pci_epf_vntb/func0
V=$F/pci_epf_vntb.0
C=e65d0000.pcie-ep
mkdir "$F"
echo 0x1957 > "$F/vendorid"
echo 0x0809 > "$F/deviceid"
echo 16 > "$V/db_count"
echo 128 > "$V/spad_count"
echo 1 > "$V/num_mws"
echo 0x100000 > "$V/mw1"
echo 0x1957 > "$V/vntb_vid"
echo 0x080a > "$V/vntb_pid"
echo 0x10 > "$V/vbus_number"
echo 0 > "$V/ctrl_bar"
echo 2 > "$V/mw1_bar"
ln -s "controllers/$C" "$F/primary/"
modprobe ntb_netdev
unlink "$F/primary/$C"
rmmod ntb_netdev
rmmod ntb_transport
test ! -e /sys/bus/pci/devices/0001:10:00.0
test ! -e /sys/class/pci_bus/0001:10
test ! -e /sys/bus/ntb/devices/0001:10:00.0
ln -s "controllers/$C" "$F/primary/"
modprobe ntb_transport
modprobe ntb_netdev
test -e /sys/bus/pci/devices/0001:10:00.0
test -e /sys/class/pci_bus/0001:10
test -e /sys/bus/ntb/devices/0001:10:00.0
echo PASSED
Before this series, removing ntb_transport after the EPF unlink
panicked:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000040
pc : vntb_epf_get_dma_dev+0x10/0x20 [pci_epf_vntb]
lr : ntb_free_mw+0x38/0xd0 [ntb_transport]
...
ntb_transport_free+0x2c/0x1c8 [ntb_transport]
ntb_remove+0x2c/0x48 [ntb]
...
ntb_unregister_client+0x14/0x28 [ntb]
ntb_transport_exit+0x18/0xb70 [ntb_transport]
...
Kernel panic - not syncing: Oops: Fatal exception
Unlinking the EPF freed endpoint resources and cleared epf->epc, but
left the NTB device registered, Removing ntb_transport later
dereferenced the NULL pointer.
After this series, unlinking the EPF removed both the virtual PCI bus
and the NTB device. The same EPF could then be linked again, and the
script printed:
PASSED
Best regards,
Koichiro
---
Changes in v6:
- Add the missing PCI rescan/remove lock noted during review of v5
patch 4.
- Rework v5 patch 5.
- Drop v5 patch 4, as f7245901de89 fixed the NULL-parent bug it worked
around.
v5: https://lore.kernel.org/r/20260226084142.2226875-1-den@valinux.co.jp/
Koichiro Den (2):
PCI: endpoint: pci-epf-vntb: Serialize virtual PCI bus scan
PCI: endpoint: pci-epf-vntb: Manage virtual NTB and PCI bus lifetime
drivers/pci/endpoint/functions/pci-epf-vntb.c | 90 +++++++++++++++----
1 file changed, 75 insertions(+), 15 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
prerequisite-patch-id: 0000000000000000000000000000000000000000
--
2.51.0
next reply other threads:[~2026-09-01 6:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 6:32 Koichiro Den [this message]
2026-09-01 6:32 ` [PATCH v6 1/2] PCI: endpoint: pci-epf-vntb: Serialize virtual PCI bus scan Koichiro Den
2026-09-01 6:47 ` sashiko-bot
2026-09-01 19:00 ` Frank Li
2026-09-01 6:32 ` [PATCH v6 2/2] PCI: endpoint: pci-epf-vntb: Manage virtual NTB and PCI bus lifetime Koichiro Den
2026-09-01 6:45 ` sashiko-bot
2026-09-01 19:05 ` Frank Li
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=20260901063238.631166-1-den@valinux.co.jp \
--to=den@valinux.co.jp \
--cc=Frank.Li@kernel.org \
--cc=allenbh@gmail.com \
--cc=bhelgaas@google.com \
--cc=dave.jiang@intel.com \
--cc=jdmason@kudzu.us \
--cc=kishon@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mani@kernel.org \
--cc=ntb@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