Skip to content

libkrunfw: Add virtio-media driver support - #139

Open
dorindabassey wants to merge 1 commit into
libkrun:mainfrom
dorindabassey:vhost-media
Open

libkrunfw: Add virtio-media driver support#139
dorindabassey wants to merge 1 commit into
libkrun:mainfrom
dorindabassey:vhost-media

Conversation

@dorindabassey

@dorindabassey dorindabassey commented Aug 11, 2026

Copy link
Copy Markdown

Add virtio-media driver patches v4 from upstream kernel mailing list to enable vhost-user media device support in libkrun. The driver proxies V4L2 operations between guest userspace and the virtio host backend, supporting MMAP buffer sharing through a shared memory region.

Changes:

  • Add patches 0031-0038 from [PATCH v4 0/8] media: Add virtio-media driver (lore.kernel.org/linux-media)
  • Enable media kernel configs (CONFIG_MEDIA_SUPPORT, CONFIG_MEDIA_CAMERA_SUPPORT, CONFIG_VIDEO_DEV, CONFIG_MEDIA_VIRTIO)

Fixes (kernel 6.12 backport):

  • UAPI header types: use __u32/__u64 instead of u32/u64 in
    include/uapi/linux/virtio_media.h for userspace compatibility
  • UAPI header includes: add #include <linux/types.h> for __u32/__u64
    definitions
  • UAPI header guard: use /* */ instead of // for #endif comment
  • videodev2.h: add #include <linux/time_types.h> for struct timespec definition
    (fixes aarch64/riscv64 headers_check failure)
  • v4l2_fh_add()/v4l2_fh_del() signature: drop second argument
    (mainline changed to 2-arg in 6.13+)
  • kzalloc_obj() does not exist in 6.12: replace with
    kzalloc(sizeof(*session), GFP_KERNEL)
  • file_to_v4l2_fh() does not exist in 6.12: add compat macro
    in virtio_media.h

Note: The UAPI header fixes address issues present in upstream v7
patches that would fail make headers_check. The videodev2.h fix
addresses a kernel 6.12 issue where struct timespec is incomplete
during headers_check on aarch64/riscv64. All issues discovered
during CI builds.

The driver has been tested with rust-vmm vhost-device-media backend and a webcam, capturing video through the full SHMEM MMAP path.

Upstream patch authors:

Alexandre Courbot gnurou@gmail.com
Brian Daniels briandaniels@google.com

@aesteve-rh

Copy link
Copy Markdown

The VIRTIO_ID_MEDIA patch is available in https://lore.kernel.org/all/20260310-virtio-media-id-v1-1-be211bcf682b@redhat.com/

@dorindabassey

Copy link
Copy Markdown
Author

Thanks Albert! I could pick it up and drop the local patch.

@slp

slp commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

@dorindabassey Any idea why is it failing on aarch64?

@dorindabassey
dorindabassey force-pushed the vhost-media branch 6 times, most recently from d246b39 to 8356d57 Compare August 25, 2026 09:48
Add virtio-media driver patches v7 from upstream kernel mailing
list to enable vhost-user media device support in libkrun.
Also add the VIRTIO_ID_MEDIA preparatory patch and a fix for
videodev2.h UAPI header. The driver proxies V4L2 operations
between guest userspace and the virtio host backend, supporting
MMAP buffer sharing through a shared memory region.

Changes:

- Add patch 0031 to fix videodev2.h struct timespec issue
  on aarch64/riscv64 headers_check
- Add patches 0032-0036 from [PATCH v7 0/4] media: Add
  virtio-media driver (lore.kernel.org/linux-media)
- Enable media kernel configs (CONFIG_MEDIA_SUPPORT,
  CONFIG_MEDIA_CAMERA_SUPPORT, CONFIG_VIDEO_DEV,
  CONFIG_MEDIA_VIRTIO)

Fixes (kernel 6.12 backport):

- UAPI header types: use __u32/__u64 instead of u32/u64 in
  include/uapi/linux/virtio_media.h for userspace compatibility
- UAPI header includes: add #include <linux/types.h> for __u32/__u64
  definitions
- UAPI header guard: use /* */ instead of // for #endif comment
- videodev2.h: add #include <time.h> for struct timespec definition
  (fixes aarch64/riscv64 headers_check failure)
- v4l2_fh_add()/v4l2_fh_del() signature: drop second argument
  (mainline changed to 2-arg in 6.13+)
- kzalloc_obj() does not exist in 6.12: replace with
  kzalloc(sizeof(*session), GFP_KERNEL)
- file_to_v4l2_fh() does not exist in 6.12: add compat macro
  in virtio_media.h

Note: The UAPI header fixes address issues present in upstream v7
patches that would fail `make headers_check`. The videodev2.h fix
addresses a kernel 6.12 issue where struct timespec is incomplete
during headers_check on aarch64/riscv64. All issues discovered
during CI builds.

The driver has been tested with rust-vmm vhost-device-media
backend and a webcam, capturing video through the full
SHMEM MMAP path.

Upstream patch authors:

Alexandre Courbot <gnurou@gmail.com>
Brian Daniels <briandaniels@google.com>
Albert Esteve <aesteve@redhat.com>

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
@dorindabassey

Copy link
Copy Markdown
Author

@dorindabassey Any idea why is it failing on aarch64?

There were two separate issues:

  1. virtio_media.h UAPI header bugs (all architectures):
    The v7 patches had UAPI header issues:
  • Used u32/u64 instead of __u32/__u64
  • Missing #include <linux/types.h>
  • C++-style comments in header guards

These was failing make headers_check on all architectures. I've fixed them in the backport (patch 0032) and will send upstream review.

  1. videodev2.h struct timespec issue (aarch64/riscv64 only):
    This one was not a virtio-media bug - it's a kernel 6.12 videodev2.h issue that only manifested on aarch64/riscv64. During headers_check, struct timespec was incomplete because <sys/time.h> doesn't provide it on those architectures. I've added a workaround patch (0031) using __kernel_old_timespec as fallback.

CI is passing now with both fixes applied.

@aesteve-rh

Copy link
Copy Markdown

Btw, it changes nothing, but the commit has made its way upstream: torvalds/linux@2187be2

In case you want to remove the patch here.

@dorindabassey

Copy link
Copy Markdown
Author

about that patch, I'd still leave it here, we're on an older kernel, but we can drop the patch if we update the kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants