[PATCH RFC 0/3] rust: snd: Introduce experimental ALSA rawmidi abstractions
From: Tristan de Cacqueray
Date: Sun Oct 11 2026 - 09:02:40 EST
Hi Takashi and the Rust for Linux maintainers.
I just noticed your mail about an early Rust prototype for the sound
subsystem right before I was about to submit this RFC!
https://lore.kernel.org/alsa-devel/878q48579z.wl-tiwai@xxxxxxx/
Nevertheless, please allow me to share what I had in mind through this
small proof of concept for the `rawmidi` API. I am looking for feedback on
the scope, coordination, and the ownership model rather than a detailed
review for merging.
My use case is a new hardware controller using a custom serial protocol.
While developing its Rust driver, I needed an interface to ALSA rawmidi.
I'm particularly interested in handling rawmidi substream safely to avoid
issues like the one fixed by
221253723dc5 ("ALSA: bcd2000: Fix race between rawmidi and disconnect")
So, I wrote some bindings to see how that would look like. This series adds
experimental snd_card and snd_rawmidi wrappers, input/output callback
traits, and a sample rawmidi faux device using delayed work to simulate
incoming MIDI data.
This is not merge-ready. In particular, the prototype does not yet enforce
the devres lifetime of the card or the lifetime of its rawmidi wrapper. The
substream helper also relies on the driver clearing it before close
returns.
Here are my questions:
1. Does this rawmidi experiment overlaps with your prototype?
If so, I would be happy to coordinate or adapt this experiment to it.
2. Is rawmidi a useful initial target for ALSA Rust abstraction?
3. Does your prototype mirror the C API 1:1, or for example, does it hide
the substream lifecycle? That's the design choice I'm least sure about.
Testing:
- build with CONFIG_RUST=y and CONFIG_SAMPLE_RUST_MIDI_DEVICE=m.
- Run amidi client to receive events from Rust:
amidi -l # to get the hw number
amidi -d -S "424344" -p hw:1,0
- Modprobe/rmmod works, but I haven't reproduced the race between
rawmidi substream and disconnect.
Base: rust-next at 2dee3d3adcad
This is my first contribution to the kernel, suggestions on routing or
RFC scope are welcome.
Thanks!
-Tristan
Signed-off-by: Tristan de Cacqueray <tristan@xxxxxxxxxxx>
---
Tristan de Cacqueray (3):
rust: snd: Add initial snd_card binding
rust: snd: Add snd_rawmidi binding
rust: snd: Add active rawmidi_substream helper
rust/bindings/bindings_helper.h | 2 +
rust/kernel/lib.rs | 2 +
rust/kernel/snd.rs | 403 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
samples/rust/Kconfig | 11 +++
samples/rust/Makefile | 1 +
samples/rust/rust_midi_device.rs | 159 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 578 insertions(+)
---
base-commit: 2dee3d3adcadcc57d62ba6608cd02f50b0c10264
change-id: 20261011-rust-snd-c5e596867624
Best regards,
--
Tristan de Cacqueray <tristan@xxxxxxxxxxx>