Rust for Linux List
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Manos Pitsidianakis <manos@pitsidianak.is>,
	 Matteo Giugni <m.giugni1@studenti.unipi.it>,
	German Maglione <gmaglione@redhat.com>,
	 Leonardo Giovannoni <leonardo.giovannoni@ing.unipi.it>,
	Giuseppe Lettieri <giuseppe.lettieri@unipi.it>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Peter Hilber" <peter.hilber@oss.qualcomm.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Viresh Kumar" <viresh.kumar@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	rust-for-linux@vger.kernel.org,
	"Jason Wang" <jasowang@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RFC v3 0/6] Add Rust virtio bindings and sample device
Date: Fri, 7 Aug 2026 16:30:31 +0200	[thread overview]
Message-ID: <anXnRcX65PnfMe9W@sgarzare-redhat> (raw)
In-Reply-To: <20260510-rust-virtio-v3-0-1427f14d67e1@pitsidianak.is>

On Sun, May 10, 2026 at 04:38:13PM +0300, Manos Pitsidianakis wrote:
>Hi all, this RFC series adds Rust bindings for Virtio drivers
>(frontends in virtio parlance).
>
>As a PoC, it also adds a sample virtio-rtc driver which performs
>capability discovery through the virtqueue without registering any clock.
>
>Before I send a cleaned-up non-RFC I would like some initial feedback
>(i.e. is it something the upstream wants?)

I had a quick look, I commented something, but maybe you already planned 
to fix some of them in the final version.

That said, overall it seems a great starting point, and I can help with 
the effort of maintaining it.

I had some issues building the rust virtio rtc driver, it seems bindgen 
0.71.1 I had installed have some issues with clang 22, upgrading bindgen 
to 0.72 fixed all the issues.

>
>This was tested with the rust-vmm vhost-device-rtc device backend that I
>wrote[^0]:
>
>[^0]: 
>https://github.com/rust-vmm/vhost-device/tree/main/vhost-device-rtc
>
>Instructions:
>
>  Run the daemon in a separate terminal:
>
>  $ cargo run --bin vhost-device-rtc -- -s /tmp/rtc.sock
>
>  Then run the VM:
>
>  $ qemu-system-aarch64 \
>    -machine type=virt,virtualization=off,acpi=on \
>    -cpu host \
>    -smp 8 \
>    -accel kvm \
>    -drive if=virtio,format=qcow2,file=./debian-13-nocloud-arm64-daily.qcow2 \
>    -device virtio-net-pci,netdev=unet \
>    -device virtio-scsi-pci \
>    -serial mon:stdio \
>    -m 8192 \
>    -object memory-backend-memfd,id=mem,size=8G,share=on \
>    -numa node,memdev=mem \
>    -display none \
>    -vga none \
>    -kernel /path/to/linux/build/arch/arm64/boot/Image \
>    -device vhost-user-test-device,chardev=rtc,id=rtc,virtio-id=17,num_vqs=2,vq_size=1024 \
>    -chardev socket,path=/tmp/rtc.sock,id=rtc \
>    ...
>
>  Example output:
>    [    1.105238] rust_virtio_rtc: Probe Rust virtio driver sample.
>    [    1.105645] rust_virtio_rtc: Found 1 vqs.
>    [    1.136050] rust_virtio_rtc: process_requestq got buf 16 bytes
>    [    1.136125] rust_virtio_rtc: Got response! Ok(RespCfg { head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, num_clocks: Le16(3), reserved: [0, 0, 0, 0, 0, 0] })
>    [    1.136701] rust_virtio_rtc: Got response! Ok(RespClockCap { 
>    head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, 
>    clock_type: 3, leap_second_smearing: 0, flags: 0, reserved: [0, 0, 
>    0, 0, 0] })
>    [    1.136724] rust_virtio_rtc virtio0: cannot expose clock 0 (type 3, variant 0, flags 0) to userspace
>    [    1.137259] rust_virtio_rtc: Got response! Ok(RespRead { head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, clock_reading: Le64(1777890485031060388) })
>    [    1.137277] rust_virtio_rtc: #0 clock reading = 
>    1777890485031060388
>    [    1.137749] rust_virtio_rtc: Got response! Ok(RespClockCap { head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, clock_type: 1, leap_second_smearing: 0, flags: 0, reserved: [0, 0, 0, 0, 0] })
>    [    1.137769] rust_virtio_rtc virtio0: cannot expose clock 1 (type 1, variant 0, flags 0) to userspace
>    [    1.138247] rust_virtio_rtc: Got response! Ok(RespRead { head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, clock_reading: Le64(1777890485032086075) })
>    [    1.138264] rust_virtio_rtc: #1 clock reading = 1777890485032086075
>    [    1.138730] rust_virtio_rtc: Got response! Ok(RespClockCap { head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, clock_type: 2, leap_second_smearing: 0, flags: 0, reserved: [0, 0, 0, 0, 0] })
>    [    1.138751] rust_virtio_rtc virtio0: cannot expose clock 2 (type 2, variant 0, flags 0) to userspace
>    [    1.139253] rust_virtio_rtc: Got response! Ok(RespRead { head: ReqHead { msg_type: Le16(0), reserved: [0, 0, 0, 0, 0, 0] }, clock_reading: Le64(338567896865557) })
>    [    1.139270] rust_virtio_rtc: #2 clock reading = 338567896865557
>
>Concerns - Notes - TODOs
>========================
>
>- Virtqueue lifetimes don't neatly apply to Rust as expected, so a lot
>  of times we have to go through unsafe pointer dereferences (though
>  which are guaranteed by Virtio subsystem to be valid, for example 
>  when
>  a callback is called with the vq argument). There's a potential for
>  misuse and definitely could use better thinking.

Yeah, I see, I guess we can work on this as next step.
I'm CCing Matteo, German, Giuseppe, and Leonardo.

We are mentoring Matteo who is working on his Master thesis at University 
of Pisa. His main effort is to provide crates for virtio drivers (e.g.  
virtqueue, driver-specific request/reply processing, etc.) that can be 
generic enough to be used in different OSes, providing the right 
abstraction.

We pointed out to this series and he would like to collaborate.
Matteo and others can add more on this of course :-)

Feel free to continue in-list or off-list for sync.

>- `struct virtio_device` is not reference-counted like other implemented
>  device types in rust/kernel. Maybe we need to change C API first to
>  make them reference counted, assuming this doesn't break anything?

Good point.

>- The sample driver obviously conflicts with the C implementation, so
>  this would either need to move out of samples/ or figure out some way
>  to handle this in kbuild.

I think we need to discuss this with MST, but IMO we should try the path 
of replacing the C version with this (when we feel confident).

>- kernel::virtio module and its types need a few rustdoc examples that I
>  will add in followup series

Agree.

Thanks,
Stefano


      parent reply	other threads:[~2026-08-07 14:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-10 13:38 [PATCH RFC v3 0/6] Add Rust virtio bindings and sample device Manos Pitsidianakis
2026-05-10 13:38 ` [PATCH RFC v3 1/6] rust/bindings: generate virtio bindings Manos Pitsidianakis
2026-05-10 13:38 ` [PATCH RFC v3 2/6] rust/helpers: add virtio.c Manos Pitsidianakis
2026-05-21  9:03   ` Eugenio Perez Martin
2026-05-25  7:51     ` Manos Pitsidianakis
2026-05-10 13:38 ` [PATCH RFC v3 3/6] rust/kernel/device: return parent at same context Manos Pitsidianakis
2026-05-10 13:38 ` [PATCH RFC v3 4/6] rust: add virtio module Manos Pitsidianakis
2026-08-07 14:09   ` Stefano Garzarella
2026-05-10 13:38 ` [PATCH RFC v3 5/6] rust: impl interruptible waits for Completion Manos Pitsidianakis
2026-05-10 13:38 ` [PATCH RFC v3 6/6] samples/rust: Add sample virtio-rtc driver [WIP] Manos Pitsidianakis
2026-08-07 14:09   ` Stefano Garzarella
2026-07-21  6:21 ` [PATCH RFC v3 0/6] Add Rust virtio bindings and sample device Manos Pitsidianakis
2026-07-21  7:46   ` Stefano Garzarella
2026-07-22  8:49   ` Eugenio Perez Martin
2026-07-22  8:55     ` Manos Pitsidianakis
2026-07-22  9:31       ` Eugenio Perez Martin
2026-07-22  9:55         ` Manos Pitsidianakis
2026-08-07 14:30 ` Stefano Garzarella [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anXnRcX65PnfMe9W@sgarzare-redhat \
    --to=sgarzare@redhat.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=eperezma@redhat.com \
    --cc=gary@garyguo.net \
    --cc=giuseppe.lettieri@unipi.it \
    --cc=gmaglione@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=leonardo.giovannoni@ing.unipi.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=m.giugni1@studenti.unipi.it \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=manos@pitsidianak.is \
    --cc=mst@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peter.hilber@oss.qualcomm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=stefanha@redhat.com \
    --cc=tmgross@umich.edu \
    --cc=viresh.kumar@linaro.org \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox