On Sun, May 10, 2026 at 3:38 PM Manos Pitsidianakis
<[email protected]> wrote:
>
> Some internal kernel virtio API functions are inline macros, so define
> their symbols in a helper file.
>
> Signed-off-by: Manos Pitsidianakis <[email protected]>
> ---
>  MAINTAINERS            |  6 ++++++
>  rust/helpers/helpers.c |  1 +
>  rust/helpers/virtio.c  | 37 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 44 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 
> d1cc0e12fe1f004da89b1aa339116908f642e894..48c9c666d90b5a256ab6fae1f42508b789a0ce50
>  100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -27930,6 +27930,12 @@ F:     include/uapi/linux/virtio_*.h
>  F:     net/vmw_vsock/virtio*
>  F:     tools/virtio/
>
> +VIRTIO CORE API BINDINGS [RUST]
> +M:     Manos Pitsidianakis <[email protected]>
> +L:     [email protected]
> +S:     Maintained
> +F:     rust/helpers/virtio.c
> +
>  VIRTIO CRYPTO DRIVER
>  M:     Gonglei <[email protected]>
>  L:     [email protected]
> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
> index 
> a3c42e51f00a0990bea81ebce6e99bb397ce7533..5dc0d2f2ee6bd2ae8e6abfe4baa247c1963967f6
>  100644
> --- a/rust/helpers/helpers.c
> +++ b/rust/helpers/helpers.c
> @@ -61,6 +61,7 @@
>  #include "time.c"
>  #include "uaccess.c"
>  #include "usb.c"
> +#include "virtio.c"
>  #include "vmalloc.c"
>  #include "wait.c"
>  #include "workqueue.c"
> diff --git a/rust/helpers/virtio.c b/rust/helpers/virtio.c
> new file mode 100644
> index 
> 0000000000000000000000000000000000000000..46aeeb063158823e66477777b3cd4bd1525df330
> --- /dev/null
> +++ b/rust/helpers/virtio.c
> @@ -0,0 +1,37 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#ifdef CONFIG_VIRTIO
> +#include <linux/virtio_config.h>
> +
> +__rust_helper bool
> +rust_helper_virtio_has_feature(const struct virtio_device *vdev,
> +                              unsigned int fbit)
> +{
> +       return virtio_has_feature(vdev, fbit);
> +}
> +__rust_helper void rust_helper_virtio_get_features(struct virtio_device 
> *vdev,
> +                                                  u64 *features_out)
> +{
> +       return virtio_get_features(vdev, features_out);

As a suggestion, perhaps an API that allows getting feature bits > 64,
like VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO (65) or VIRTIO_NET_F_IPSEC (70)
could save the need to add more functions in the future.

> +}
> +
> +__rust_helper int rust_helper_virtio_find_vqs(struct virtio_device *vdev,
> +                                             unsigned int nvqs,
> +                                             struct virtqueue *vqs[],
> +                                             struct virtqueue_info 
> vqs_info[],
> +                                             struct irq_affinity *desc)
> +{
> +       return virtio_find_vqs(vdev, nvqs, vqs, vqs_info, desc);
> +}
> +
> +__rust_helper void rust_helper_virtio_device_ready(struct virtio_device *dev)
> +{
> +       return virtio_device_ready(dev);
> +}
> +
> +__rust_helper bool
> +rust_helper_virtio_is_little_endian(struct virtio_device *vdev)
> +{
> +       return virtio_is_little_endian(vdev);
> +}
> +#endif /* CONFIG_VIRTIO */
>
> --
> 2.47.3
>


Reply via email to