casaroli opened a new pull request, #21913:
URL: https://github.com/apache/nuttx/pull/21913
## Summary
`virtqueue_add_buffer()` of OpenAMP checks the number of free descriptors
only with `VQUEUE_DEBUG` (`CONFIG_OPENAMP_DEBUG`). Without it, a buffer added
to a full queue walks past the end of the free list: it overwrites descriptors
that the device still owns, and the free count wraps. QEMU then stops the
device ("Guest says index 32768 is available"). In virtio-snd each audio buffer
uses 2 descriptors, but the number of buffers comes from the application
(`AUDIOIOC_ALLOCBUFFER` and `AUDIOIOC_ENQUEUEBUFFER`), not from the queue: the
period count of `AUDIOIOC_GETBUFFERINFO` is only a hint, and
`virtio_snd_send_pcm()` only logs an error when more buffers are queued. This
PR makes `virtio_snd_send_pcm()` return `-ENOSPC` when the queue has not enough
free descriptors. It can run in the completion interrupt (the upper half
enqueues the next buffer there), so it does not wait: the caller keeps the
buffer. `AUDIOIOC_ENQUEUEBUFFER` returns the error to the application, and in
the shared-bu
ffer mode the upper half tries the buffer again after the next completion.
## Impact
`drivers/virtio/virtio-snd.c` only. An application that enqueues more
buffers than the queue holds gets `ENOSPC` for the extra buffers, instead of a
stopped device. Nothing changes while the queue has room (a player that uses
the count of `AUDIOIOC_GETBUFFERINFO`, as nxplayer does, never fills it). No
API change except this new error of `AUDIOIOC_ENQUEUEBUFFER`. A second commit
says it in Documentation/os/audio (private buffers: use the count of
`AUDIOIOC_GETBUFFERINFO`; virtio-snd returns `-ENOSPC` on a full queue). The
same code in flat, protected and kernel builds.
## Testing
- Test program `sndfull.c`: open `/dev/audio/pcm0p`, configure 48 kHz stereo
16-bit, allocate and enqueue 12 buffers of 25 ms, start, play 1 s, stop, close.
qemu-armv8a:nsh_smp (flat build, 2 CPUs, arm64, QEMU with HVF) with
`CONFIG_AUDIO`, `CONFIG_DRIVERS_VIRTIO_SOUND`,
`CONFIG_DRIVERS_VIRTIO_MMIO_QUEUE_LEN=16` (8 buffers) and a QEMU virtio-sound
device. master: QEMU stops the device ("Guest says index 32768 is available")
and the program never ends, FAIL. This PR: PASS, 8 buffers enqueued, 4 get
`ENOSPC`, no device error, the shell answers.
- ostest: qemu-armv8a:knsh (kernel build) exit 0, qemu-armv8a:nsh (flat
build) exit 0, with `CONFIG_AUDIO` and `CONFIG_DRIVERS_VIRTIO_SOUND`, arm64,
QEMU with HVF.
- rv-virt:nsh64 (flat build, riscv64) with the driver: `virtio-snd.c`
compiles without warnings; the link fails in libmetal (a flat risc-v build has
no `up_addrenv_va_to_pa` or `up_addrenv_pa_to_va`, on master too), not changed
here.
- checkpatch: `tools/checkpatch.sh -c -u -m -g` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]