Skip to contentSkip to conversation

test-runner: Add support for PCIe passthrough

PATCH Applied Luiz Augusto von Dentz 3 participants 6 messages Aug 27 – Sep 4

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/4 test-runner: Add support for PCIe passthrough

From: Luiz Augusto von Dentz <[email protected]>

Add a -P/--pcie option which passes the given QEMU device arguments through to QEMU, in the same way -U/--usb does for USB devices, so a host controller can be handed to the guest:

  $ tools/test-runner -P "vfio-pci,host=0000:00:14.3" \
        -d -k /pathto/bzImage -- /bin/bash

The device does not have to be prepared by hand: the BDF is taken from the host= argument and bound to vfio-pci, and the driver it was bound to before is restored once the guest exits. As VFIO can only pass through a device if the rest of its IOMMU group is unbound or already handled by VFIO, the group is checked before the device is taken away from its driver, so a group that cannot be used is reported instead of leaving the device behind on vfio-pci.

Restoring the driver means QEMU can no longer simply replace this process, so with -P it is started as a child and SIGINT, SIGTERM and SIGHUP are forwarded to it, leaving this process to restore the driver once QEMU is reaped.

Since vfio-pci requires ACPI for device enumeration and an APIC for MSI delivery, the guest command line drops "acpi=off pci=noacpi noapic" when -P is given. All other modes keep the previous command line and are still exec'ed directly.

Tested by passing a PCIe card reader through to the guest, checking that it is bound to vfio-pci while the guest runs and bound back to its own driver afterwards.

The model drafted the option handling, the vfio binding, the command line change and the documentation section; all of it was reviewed and tested by the author.

Assisted-by Claude:claude-opus-5
---
 doc/test-runner.rst |  28 ++++
 tools/test-runner.c | 317 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 337 insertions(+), 8 deletions(-)
doc/test-runner.rst +28 -0
index a650c6fae571..6787507c3f40 100644
@@ -23,6 +23,7 @@ OPTIONS
 :-A/-audio[=path]: Start audio server
 :-u/--unix[=path]: Provide serial device
 :-U/--usb=<qemu_args>: Provide USB device
+:-P/--pcie=<qemu_args>: Provide PCIe device
 :-q/--qemu=<path>: QEMU binary
 :-k/--kernel=<image>: Kernel image (bzImage)
 :-h/--help: Show help options
@@ -230,3 +231,30 @@ In addition the above kernel config option the following is required:
 
 	$ tools/test-runner -U "usb-host,vendorid=<0xxxxx>,productid=<0xxxxx>" \
 	-d -k /pathto/bzImage -- /bin/bash
+
+Running shell with host controller PCIe-passthrough
+---------------------------------------------------
+
+In addition the above kernel config option the following is required:
+
+.. code-block::
+
+	CONFIG_PCI=y
+	CONFIG_PCI_MSI=y
+	CONFIG_ACPI=y
+	CONFIG_BT_HCIBTINTEL_PCIE=y
+
+On the host, an IOMMU must be enabled in the firmware and on the host kernel
+command line (``intel_iommu=on`` or ``amd_iommu=on``). The controller itself
+does not need any manual preparation: test-runner unbinds it from its current
+driver, binds it to vfio-pci, and restores the original driver once the guest
+exits.
+
+.. code-block::
+
+	$ tools/test-runner -P "vfio-pci,host=0000:00:14.3" \
+	-d -k /pathto/bzImage -- /bin/bash
+
+Note that unlike the other modes, PCIe-passthrough boots the guest with ACPI
+and APIC enabled, as these are required for device enumeration and MSI
+interrupt delivery.
tools/test-runner.c +309 -8

394 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 2/4 monitor: Add latency standard deviation

From: Luiz Augusto von Dentz <[email protected]>

The latency range and moving average alone do not tell a link that is consistently slow apart from one that is unstable. A high average with a low deviation points at the scheduling or the interval configuration, while a low average with a high deviation points at interference, retransmissions or controller buffer stalls.

Track the sample count along with the sum and the sum of the squares in struct packet_latency, and report the resulting standard deviation on the latency lines of both the live decoding and the analyze mode.

The samples are squared in usec and only scaled down to msec^2 afterwards, so that the sub-msec resolution is not lost while the running sum stays clear of an overflow.

The model derived the accumulator layout and the scaling, which the author reviewed and verified against an independently computed deviation.

Assisted-by opencode:claude-opus-5
---
 Makefile.tools    |  2 +-
 monitor/analyze.c |  6 ++++--
 monitor/packet.c  | 41 +++++++++++++++++++++++++++++++++++++++--
 monitor/packet.h  |  4 ++++
 4 files changed, 48 insertions(+), 5 deletions(-)
Makefile.tools +1 -1
index b3ef4ae1c3df..8f9ffe97cbf0 100644
@@ -62,7 +62,7 @@ monitor_btmon_SOURCES = monitor/main.c monitor/bt.h \
 				src/settings.h src/settings.c
 monitor_btmon_LDADD = lib/libbluetooth-internal.la \
 				src/libshared-mainloop.la \
-				$(GLIB_LIBS) $(UDEV_LIBS) -ldl
+				$(GLIB_LIBS) $(UDEV_LIBS) -ldl -lm
 
 if MANPAGES
 man_MANS += doc/btmon.1
monitor/analyze.c +4 -2
index de9c23603a21..b349887716da 100644
@@ -155,10 +155,12 @@ static void print_stats(struct hci_stats *stats, const char *label)
 		return;
 
 	print_field("%s packets: %zu/%zu", label, stats->num, stats->num_comp);
-	print_field("%s Latency: %lld-%lld msec (~%lld msec)", label,
+	print_field("%s Latency: %lld-%lld msec (~%lld msec +/- %lld msec)",
+			label,
 			TV_MSEC(stats->latency.min),
 			TV_MSEC(stats->latency.max),
-			TV_MSEC(stats->latency.med));
+			TV_MSEC(stats->latency.med),
+			packet_latency_stddev(&stats->latency));
 	print_field("%s size: %u-%u octets (~%zd octets)", label,
 			stats->min, stats->max, stats->bytes / stats->num);
 
monitor/packet.c +39 -2

69 lines not on this page · raw message

monitor/packet.h +4 -0
index 73a86f64b242..6b792c0e420c 100644
@@ -31,6 +31,9 @@ struct packet_latency {
 	struct timeval min;
 	struct timeval max;
 	struct timeval med;
+	uint64_t count;
+	uint64_t sum_usec;	/* Sum of samples, in usec */
+	uint64_t sum_sq_msec;	/* Sum of squared samples, in msec^2 */
 };
 
 struct packet_frame {
@@ -69,6 +72,7 @@ struct packet_conn_data {
 
 struct packet_conn_data *packet_get_conn_data(uint16_t handle);
 void packet_latency_add(struct packet_latency *latency, struct timeval *delta);
+long long packet_latency_stddev(const struct packet_latency *latency);
 
 bool packet_has_filter(unsigned long filter);
 void packet_set_filter(unsigned long filter);
Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH 3/4 monitor: Add ISO packet loss counters

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Isochronous streams are the one place where HCI hands the host enough information to tell whether data actually arrived: the ISO data packet header carries an SDU sequence number and a packet status flag.

Track both per connection and report them during the live decoding and in the analyze mode. Gaps in the sequence number are counted as lost SDUs, a packet status flag of 2 is counted as dropped and a flag of 1 as possibly invalid. Duplicates and reordered sequence numbers are not counted as loss.

During the live decoding the counters are only printed on the packet where a discontinuity is detected, so a clean stream produces no extra output.

The model wrote the sequence number accounting and the ISO header walking, which the author reviewed and verified against a trace with known gaps.

Assisted-by opencode:claude-opus-5
---
 monitor/analyze.c | 39 ++++++++++++++++++++++++++++++++++
 monitor/packet.c  | 53 ++++++++++++++++++++++++++++++++++++++++++++---
 monitor/packet.h  | 11 ++++++++++
 3 files changed, 100 insertions(+), 3 deletions(-)
monitor/analyze.c +39 -0
index b349887716da..9742981ec21a 100644
@@ -32,6 +32,12 @@
 #define TIMEVAL_MSEC(_tv) \
 	(long long)((_tv)->tv_sec * 1000 + (_tv)->tv_usec / 1000)
 
+/* Same layout as the ISO handle/flags fields decoded in packet.c */
+#define ISO_FLAGS(_h)		((_h) >> 12)
+#define ISO_FLAGS_PB(_f)	((_f) & 0x0003)
+#define ISO_FLAGS_TS(_f)	(((_f) >> 2) & 0x0001)
+#define ISO_DATA_FLAGS(_h)	((_h) >> 14)
+
 struct hci_dev {
 	uint16_t index;
 	uint8_t type;
@@ -87,6 +93,7 @@ struct hci_conn {
 	struct queue *chan_list;
 	struct hci_stats rx;
 	struct hci_stats tx;
+	struct packet_loss rx_loss;
 };
 
 struct hci_conn_tx {
@@ -357,6 +364,15 @@ static void conn_destroy(void *data)
 	print_stats(&conn->rx, "RX");
 	print_stats(&conn->tx, "TX");
 
+	if (conn->rx_loss.total)
+		print_field("RX loss: %zu/%zu (%zu.%02zu%%) "
+				"dropped %zu invalid %zu",
+				conn->rx_loss.lost, conn->rx_loss.total,
+				conn->rx_loss.lost * 100 / conn->rx_loss.total,
+				(conn->rx_loss.lost * 10000 /
+					conn->rx_loss.total) % 100,
+				conn->rx_loss.dropped, conn->rx_loss.invalid);
+
 	if (conn->setup_seen) {
 		print_field("Connected: #%lu", conn->frame_connected);
 		if (conn->terminated) {
@@ -1338,8 +1354,11 @@ static void iso_pkt(struct timeval *tv, uint16_t index, bool out,
 					const void *data, uint16_t size)
 {
 	const struct bt_hci_iso_hdr *hdr = data;
+	struct iovec iov = { .iov_base = (void *)data, .iov_len = size };
 	struct hci_conn *conn;
 	struct hci_dev *dev;
+	uint16_t handle;
+	uint8_t flags, pb_flag;
 
 	dev = dev_lookup(index);
 	if (!dev)
@@ -1357,6 +1376,26 @@ static void iso_pkt(struct timeval *tv, uint16_t index, bool out,
 			return;
 	}
 
+	handle = le16_to_cpu(hdr->handle);
+	flags = ISO_FLAGS(handle);
+	pb_flag = ISO_FLAGS_PB(flags);
+
+	/* Only the first fragment of an SDU carries the sequence number */
+	if (!out && (pb_flag == 0x00 || pb_flag == 0x02)) {
+		const struct bt_hci_iso_data_start *start;
+
+		util_iov_pull_mem(&iov, sizeof(*hdr));
+
+		/* Skip the timestamp when present */
+		if (ISO_FLAGS_TS(flags))
+			util_iov_pull_mem(&iov, sizeof(uint32_t));
+
+		start = util_iov_pull_mem(&iov, sizeof(*start));
+		if (start)
+			packet_loss_add(&conn->rx_loss, le16_to_cpu(start->sn),
+				ISO_DATA_FLAGS(le16_to_cpu(start->slen)));
+	}
+
 	if (out) {
 		conn_pkt_tx(conn, tv, size - sizeof(*hdr), NULL);
 	} else {
monitor/packet.c +50 -3

92 lines not on this page · raw message

monitor/packet.h +11 -0
index 6b792c0e420c..9d1efdf45258 100644
@@ -36,6 +36,15 @@ struct packet_latency {
 	uint64_t sum_sq_msec;	/* Sum of squared samples, in msec^2 */
 };
 
+struct packet_loss {
+	uint16_t last_sn;
+	bool have_sn;
+	size_t lost;		/* Samples missing from the SN sequence */
+	size_t invalid;		/* Samples flagged possibly invalid */
+	size_t dropped;		/* Samples flagged as lost data */
+	size_t total;		/* Samples seen, including the lost ones */
+};
+
 struct packet_frame {
 	struct timeval tv;
 	size_t num;
@@ -66,6 +75,7 @@ struct packet_conn_data {
 	struct queue *tx_q;
 	struct queue *chan_q;
 	struct packet_latency tx_l;
+	struct packet_loss rx_loss;
 	void     *data;
 	void     (*destroy)(struct packet_conn_data *conn, void *data);
 };
@@ -73,6 +83,7 @@ struct packet_conn_data {
 struct packet_conn_data *packet_get_conn_data(uint16_t handle);
 void packet_latency_add(struct packet_latency *latency, struct timeval *delta);
 long long packet_latency_stddev(const struct packet_latency *latency);
+void packet_loss_add(struct packet_loss *loss, uint16_t sn, uint8_t sflags);
 
 bool packet_has_filter(unsigned long filter);
 void packet_set_filter(unsigned long filter);
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH 4/4 doc/btmon: Document the deviation and loss counters

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Describe how to read the latency standard deviation and each of the ISO packet loss counters, and correct the description of the moving average, which was documented as a median even though it has always been computed as a moving average.

The model drafted the text, which the author reviewed against the actual output.

Assisted-by opencode:claude-opus-5
---
 doc/btmon.rst | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)
doc/btmon.rst +51 -1
index f701454e598e..adb2c9881f97 100644
@@ -561,9 +561,11 @@ Analyze mode reports, for each controller found in the trace:
   - Connection type (BR-ACL, LE-ACL, BR-SCO, BR-ESCO, LE-ISO)
   - Device address
   - TX and RX packet counts and completion counts
-  - Latency statistics (min, max, median) in milliseconds
+  - Latency statistics (min, max, moving average and standard
+    deviation) in milliseconds
   - Packet size statistics (min, max, average) in octets
   - Throughput estimate in Kb/s
+  - Packet loss statistics, for isochronous connections
 
 - **Per-channel statistics**: For each L2CAP channel within a
   connection, the same packet/latency/size statistics.
@@ -571,6 +573,54 @@ Analyze mode reports, for each controller found in the trace:
 - **Latency plots**: If ``gnuplot`` is installed, ASCII-art latency
    distribution plots are rendered in the terminal.
 
+Latency Standard Deviation
+--------------------------
+
+Latency is reported as::
+
+   TX Latency: 5-300 msec (~91 msec +/- 104 msec)
+
+The range is the minimum and maximum observed latency, ``~`` is a
+moving average and ``+/-`` is the standard deviation over all samples.
+
+The standard deviation is what distinguishes a link that is merely slow
+from one that is unstable. A high average with a low deviation means
+consistent latency, which is usually a scheduling or interval
+configuration issue. A low average with a high deviation means most
+packets are fast but some are heavily delayed, which typically points at
+interference, retransmissions or controller buffer stalls. Comparing the
+maximum against ``average + deviation`` shows whether the worst case is
+representative or a one-off outlier.
+
+Packet Loss
+-----------
+
+Packet loss is tracked for isochronous (CIS/BIS) connections, where the
+ISO data packet header carries an SDU sequence number and a packet
+status flag. It is reported as::
+
+   RX loss: 13/21 (61.90%) dropped 1 invalid 1
+
+The counters are:
+
+- **loss**: SDUs missing from the received sequence, derived from gaps
+  in the sequence number. The denominator is the number of SDUs that
+  should have been received, that is the ones actually seen plus the
+  ones detected as missing.
+
+- **dropped**: SDUs the controller delivered with a packet status flag
+  of ``2`` (lost data), meaning the controller knows the payload did not
+  arrive.
+
+- **invalid**: SDUs delivered with a packet status flag of ``1``
+  (possibly invalid), meaning the payload arrived but may be corrupt.
+
+Duplicate and reordered sequence numbers are not counted as loss.
+
+Loss counters are also shown during live decoding, on the ISO data
+packet where a discontinuity is detected. The line is only emitted once
+a loss has occurred, so a clean stream produces no extra output.
+
 PROTOCOL ERROR CODES
 =====================
 
Signature · 1 line
2.54.0
#4 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1152755

---Test result---

Test Summary:

CheckPatch                    FAIL      2.19 seconds
GitLint                       PASS      1.31 seconds
BuildEll                      PASS      19.97 seconds
BluezMake                     PASS      541.80 seconds
MakeCheck                     PASS      19.49 seconds
MakeDistcheck                 PASS      152.15 seconds
CheckValgrind                 PASS      220.65 seconds
CheckSmatch                   WARNING   294.22 seconds
bluezmakeextell               PASS      95.10 seconds
IncrementalBuild              PASS      590.14 seconds
ScanBuild                     PASS      866.71 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,vRFC,1/4] test-runner: Add support for PCIe passthrough WARNING:BAD_SIGN_OFF: Non-standard signature: Assisted-by:
#130:

Assisted-by Claude:claude-opus-5

ERROR:BAD_SIGN_OFF: Unrecognized email address: 'Claude:claude-opus-5' #130:

Assisted-by Claude:claude-opus-5

/github/workspace/src/patch/14771785.patch total: 1 errors, 1 warnings, 431 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14771785.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,vRFC,2/4] monitor: Add latency standard deviation WARNING:BAD_SIGN_OFF: Non-standard signature: Assisted-by:
#119:

Assisted-by opencode:claude-opus-5

ERROR:BAD_SIGN_OFF: Unrecognized email address: 'opencode:claude-opus-5' #119:

Assisted-by opencode:claude-opus-5

/github/workspace/src/patch/14771786.patch total: 1 errors, 1 warnings, 107 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14771786.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,vRFC,3/4] monitor: Add ISO packet loss counters WARNING:BAD_SIGN_OFF: Non-standard signature: Assisted-by:
#119:

Assisted-by opencode:claude-opus-5

ERROR:BAD_SIGN_OFF: Unrecognized email address: 'opencode:claude-opus-5' #119:

Assisted-by opencode:claude-opus-5

/github/workspace/src/patch/14771787.patch total: 1 errors, 1 warnings, 192 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14771787.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,vRFC,4/4] doc/btmon: Document the deviation and loss counters WARNING:BAD_SIGN_OFF: Non-standard signature: Assisted-by:
#110:

Assisted-by opencode:claude-opus-5

ERROR:BAD_SIGN_OFF: Unrecognized email address: 'opencode:claude-opus-5' #110:

Assisted-by opencode:claude-opus-5

/github/workspace/src/patch/14771788.patch total: 1 errors, 1 warnings, 66 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14771788.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
monitor/packet.c:2003:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3924:52: warning: array of flexible structuresmonitor/bt.h:3912:40: warning: array of flexible structuresmonitor/packet.c:2003:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3924:52: warning: array of flexible structuresmonitor/bt.h:3912:40: warning: array of flexible structures

https://github.com/bluez/bluez/pull/2444

---
Regards,
Linux Bluetooth

#5 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Thu, 27 Aug 2026 12:53:23 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

Add a -P/--pcie option which passes the given QEMU device arguments through to QEMU, in the same way -U/--usb does for USB devices, so a host controller can be handed to the guest:

  $ tools/test-runner -P "vfio-pci,host=0000:00:14.3" \
        -d -k /pathto/bzImage -- /bin/bash

[...]

Here is the summary with links:
- [BlueZ,vRFC,1/4] test-runner: Add support for PCIe passthrough

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5ef24e77a642
  - [BlueZ,vRFC,2/4] monitor: Add latency standard deviation
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=24a46bbd3b78
  - [BlueZ,vRFC,3/4] monitor: Add ISO packet loss counters
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7bcf6c42721e
  - [BlueZ,vRFC,4/4] doc/btmon: Document the deviation and loss counters
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4b92dddc8e54

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html