[PATCH 14/18] selftests/liveupdate: pci: Add a test with an endpoint below a switch

From: David Matlack

Date: Tue Dec 01 2026 - 19:40:56 EST


Add a PCI Live Update test that preserves an endpoint below a PCIe
switch, next to a control endpoint below another downstream port of the
same switch. The root port and the switch's upstream port are shared
between the preserved and the control endpoint, and so must be
preserved.

Add pci_switch to build switches, and pci_topology_switch for this
topology, which later tests reuse.

Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
.../liveupdate/pci/pci_vmtest_lib.sh | 29 +++++++++++++++++++
.../selftests/liveupdate/pci/switch.vmtest.sh | 8 +++++
2 files changed, 37 insertions(+)
create mode 100644 tools/testing/selftests/liveupdate/pci/switch.vmtest.sh

diff --git a/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh b/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh
index 5babeb19fbc1..3038cc4ca53f 100644
--- a/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh
+++ b/tools/testing/selftests/liveupdate/pci/pci_vmtest_lib.sh
@@ -47,6 +47,22 @@ function pci_root_port() {
TEST_QEMU_ARGS+=(-device "pcie-root-port,id=$1,bus=pcie.0,addr=$2,chassis=$PCI_CHASSIS")
}

+# pci_switch <id> <bus> <downstream_id>...
+# Add a switch below <bus>, with one downstream port per <downstream_id>. The
+# downstream ports are devices 0, 1, ... on the switch's internal bus.
+function pci_switch() {
+ local id=$1 bus=$2 i=0 dsp
+ shift 2
+
+ TEST_QEMU_ARGS+=(-device "x3130-upstream,id=$id,bus=$bus,addr=0")
+ for dsp in "$@"; do
+ PCI_CHASSIS=$((PCI_CHASSIS + 1))
+ TEST_QEMU_ARGS+=(-device
+ "xio3130-downstream,id=$dsp,bus=$id,addr=$i,chassis=$PCI_CHASSIS,slot=0")
+ i=$((i + 1))
+ done
+}
+
# pci_igb <id> <bus> [<addr>]
# Add an IGB endpoint at device <addr> (default 0) on <bus>.
function pci_igb() {
@@ -80,6 +96,19 @@ function pci_topology_root_ports() {
pci_control 0000:00:03.0/00.0
}

+# pci_topology_switch
+# A switch below a root port, with an endpoint to preserve and a control
+# endpoint below different downstream ports.
+function pci_topology_switch() {
+ pci_root_port rp1 0x2
+ pci_switch sw1 rp1 dsp1 dsp2
+ pci_igb igb1 dsp1
+ pci_igb igb2 dsp2
+
+ pci_preserve 0000:00:02.0/00.0/00.0/00.0
+ pci_control 0000:00:02.0/00.0/01.0/00.0
+}
+
function test_check() {
python3 "$test_dir/pci/check_cfg_trace.py" \
--serial "$workspace_dir/qemu.serial" --trace "$PCI_TRACE"
diff --git a/tools/testing/selftests/liveupdate/pci/switch.vmtest.sh b/tools/testing/selftests/liveupdate/pci/switch.vmtest.sh
new file mode 100644
index 000000000000..5b851ddf0b2b
--- /dev/null
+++ b/tools/testing/selftests/liveupdate/pci/switch.vmtest.sh
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Preserve an endpoint below a switch, next to a control endpoint below another
+# downstream port of the same switch.
+
+source "$test_dir/pci/pci_vmtest_lib.sh"
+
+pci_topology_switch
--
2.56.1.911.g883d8bcb20-goog