[PATCH v6 0/2] PCI: endpoint: pci-epf-*ntb: Harden vNTB resource management
From: Koichiro Den
Date: Tue Sep 01 2026 - 02:34:30 EST
Hi,
This is a follow-up to v5:
https://lore.kernel.org/r/20260226084142.2226875-1-den@xxxxxxxxxxxxx/
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@xxxxxxxxxxxxx/
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