Skip to contentSkip to conversation

ALSA: virtio: trace control message lifecycles

RFC PATCH Superseded Joonho Lee 2 participants 3 messages Oct 17

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Joonho Lee

author
#0 lore raw

cover ALSA: virtio: trace control message lifecycles

Hi,

While investigating capture stalls, I needed to tell whether a control request had timed out, completed later, or been canceled during teardown. The existing timeout log gives the raw opcode, but repeated requests need an identifier to follow their lifetimes (or cycles).

This RFC adds one trace event to sound/virtio. Its enqueue, response, cancel and wait records share a per-send ID. Wait records describe the sender's outcome, response and cancel records describe queue completion. Therefore a timed-out wait can be followed by a response with the same identifier.

The patch applies directly to the mainline base listed below. PCM capture staging, split-ACK accounting, workqueue priority and application recovery changes are outside this RFC.

Validation of the exact source diff:
- ARM64 W=1 kernel/module builds with KASAN and lockdep; additional object builds with BPF events enabled and with event tracing disabled.
- Six QEMU cases compare baseline, trace-off and trace-on for a delayed PREPARE response and cancellation during unbind/rebind. Each checks subsequent capture and playback. No KASAN/lockdep diagnostics or trace loss were recorded. These tests use a patched synthetic QEMU backend.
- Eighteen QEMU performance trials, 9,000 timed open/start/drop/close cycles, use a 4,096-frame buffer. Enabled trials produce the expected enqueue/response/wait counts. Steady capture produces no control events.

The added message fields cost 24 bytes per request on the tested ARM64 configurations, even with tracing off. Module sections grew by 11,160 bytes in the debug build. Actual allocation depends on slab/page layout.

A further non-debug comparison used this exact candidate with QEMU 11.1.2 and HVF, sharing the same Image/config and differing only in virtio_snd.ko. Six balanced orders exercised 90,000 timed lifecycle cycles at 4,096 frames, followed by three 30-second synthetic captures. All functional checks passed, as each capture read 1,440,000 frames, with zero XRUNs or read errors. Each trace-on lifecycle trial recorded 90,000 events without loss. Steady capture recorded no control events.

Observed medians of six per-trial p95/p99 lifecycle times, in microseconds, were 201.105/349.729 for baseline, 254.146/334.416 for trace off, and 291.667/413.083 for trace on. Median process CPU time per lifecycle was 70.437, 70.532 and 77.300 microseconds, respectively. These measure the open/configure/prepare/start/drop/close sequence, rather than audio delivery latency.

Native VZ with the unpatched baseline and internal microphone completed 100 lifecycle cycles, but a 30-second capture returned EIO after 1,131,472 frames (23.57 seconds of audio). Native VZ steady-capture performance remains unverified. Earlier VZ integration results included experimental capture changes and a different port of the trace implementation, as they do not establish performance of this exact candidate.

Additional ARM64 QEMU fault injection exercises the real send and completion paths through a separate test-only caller. The backend returns status 0xdeadbeef and used lengths 0, 3 and 37 for a 36-byte response capacity. Blocking queue consumption fills 64 entries; the 65th send returns -ENOSPC. A held asynchronous request returns before its response, while SIGUSR1 interrupts a synchronous wait with kernel -ERESTARTSYS and userspace EINTR. Both requests complete later without another sender wait. Each fault is followed by a successful query, then the suite checks an additional-SG query, capture and capture reopen at 4,096 frames, plus playback.

The length faults deliberately write a complete response within the writable buffers and alter only the reported used length. Baseline and instrumented senders still return success in those cases. The event records the raw length with status_valid=0 and status=0; this patch does not change protocol validation. An unknown status with a valid length is recorded verbatim, with the existing sender path returning -EINVAL. Here status_valid describes coverage of the response header word. The raw used length remains available for opcode-specific payload checks.

Two fresh boots each of baseline, feature trace-off and feature trace-on passed all 42 fault scenarios with identical sender results. Each trace-on run contained 280 events with no trace loss. The original, unmodified production modules also passed six repeated timeout/reset regressions. Seven deliberately corrupted evidence sets were rejected by the oracle.

The fault caller and QEMU changes are local test fixtures, excluded from this patch. The production control implementation remains byte-for-byte the candidate tested above. The fixture modules were rebuilt with W=1; KASAN and lockdep remain enabled. These synthetic tests do not exercise physical microphone input or establish additional VZ compatibility.

Thanks,
Joonho

Joonho Lee (1):
ALSA: virtio: trace control message lifecycles

 sound/virtio/Makefile               |   2 +
 sound/virtio/virtio_ctl_msg.c       | 156 +++++++++++++++++++++++++++-
 sound/virtio/virtio_ctl_msg_trace.h | 107 +++++++++++++++++++
 3 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 sound/virtio/virtio_ctl_msg_trace.h

base-commit: 2f2f7eeef8b0a1a9b9ca998231419873ccae8d4e

author
#1 lore raw

RFC PATCH 1/1 ALSA: virtio: trace control message lifecycles

A timed-out control request can complete later or be canceled during teardown. The existing opcode-only timeout message does not identify the request or show when the queue gives it back, which makes it difficult to correlate control stalls with guest scheduling and device reset activity.

Add a virtio_snd_ctl_msg trace event with a per-send identifier and phases for enqueue, response, cancellation and the sender's wait outcome. Record PCM stream IDs where the request layout supplies one, the enqueue or wait result, and the device's used length and response status. Mark optional fields explicitly and check the writable response capacity before reading a status for the event.

Assign IDs only to requests sent while the event is enabled. Keep sender wait outcomes separate from queue completion so a timeout followed by a late response retains the same ID. Include neither audio data nor kernel addresses in the event.

Leave protocol results, request ownership and timeout handling unchanged. The added fields increase each control-message structure by 24 bytes on the tested ARM64 configurations, including when tracing is disabled. No events are added to PCM data completions.

Assisted-by LLM

---
Fault-injection validation uses a test-only caller and QEMU backend overlay, separate from this patch. It covers unknown status, used lengths below the header and above writable capacity, actual virtqueue -ENOSPC, asynchronous completion and a SIGUSR1-interrupted wait followed by a late response. Subsequent queries, capture/reopen at 4,096 frames, and playback recover. Two boots each of baseline, feature trace-off and feature trace-on passed 42 fault scenarios, with 280 events per trace-on run and no trace loss. KASAN and lockdep reported no diagnostics.

The malformed-length fixture safely writes a full success response before reporting the bad length. Existing send semantics return success; the event reports status_valid=0/status=0. This is diagnostic coverage, with no change to the driver's response-validation policy. Unknown status 0xdeadbeef is length-valid and appears unchanged in the event; the sender returns -EINVAL.

 sound/virtio/Makefile               |   2 +
 sound/virtio/virtio_ctl_msg.c       | 156 +++++++++++++++++++++++++++-
 sound/virtio/virtio_ctl_msg_trace.h | 107 +++++++++++++++++++
 3 files changed, 264 insertions(+), 1 deletion(-)
 create mode 100644 sound/virtio/virtio_ctl_msg_trace.h
sound/virtio/Makefile +2 -0
index 3ca41b3c8..3db8ad687 100644
@@ -2,6 +2,8 @@
 
 obj-$(CONFIG_SND_VIRTIO) += virtio_snd.o
 
+CFLAGS_virtio_ctl_msg.o := -I$(src)
+
 virtio_snd-y := \
 	virtio_card.o \
 	virtio_chmap.o \
sound/virtio/virtio_ctl_msg.c +155 -1

217 lines not on this page · raw message

sound/virtio/virtio_ctl_msg_trace.h new file +107 -0

107 lines not on this page · raw message

#2 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

A timed-out control request can complete later or be canceled during teardown. The existing opcode-only timeout message does not identify the request or show when the queue gives it back, which makes it difficult to correlate control stalls with guest scheduling and device reset activity.

Add a virtio_snd_ctl_msg trace event with a per-send identifier and phases for enqueue, response, cancellation and the sender's wait outcome. Record PCM stream IDs where the request layout supplies one, the enqueue or wait result, and the device's used length and response status. Mark optional fields explicitly and check the writable response capacity before reading a status for the event.

Assign IDs only to requests sent while the event is enabled. Keep sender wait outcomes separate from queue completion so a timeout followed by a late response retains the same ID. Include neither audio data nor kernel addresses in the event.

Quoted 7 lines

Leave protocol results, request ownership and timeout handling unchanged. The added fields increase each control-message structure by 24 bytes on the tested ARM64 configurations, including when tracing is disabled. No events are added to PCM data completions.

Assisted-by LLM

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1