Skip to content

Comments

Migrate to rutabaga_gfx v0.1.76-libkrun.0 from crates.io#560

Draft
dorindabassey wants to merge 3 commits intocontainers:mainfrom
dorindabassey:fixkrun
Draft

Migrate to rutabaga_gfx v0.1.76-libkrun.0 from crates.io#560
dorindabassey wants to merge 3 commits intocontainers:mainfrom
dorindabassey:fixkrun

Conversation

@dorindabassey
Copy link
Collaborator

As part of the efforts to remove vendored rutabaga_gfx and use upstream Rutabaga_gfx, we are adopting the new RutabagaBuilder API with capset_mask, Add temporary workaround for VirtioFsKey not being publicly exported(marking as draft pending magma-gpu/rutabaga_gfx#43 merge).

Dorinda Bassey added 3 commits February 23, 2026 13:53
Migrate from the old RutabagaBuilder API that used explicit
virgl_flags to the new capset_mask-based API.

  Key changes:
  - Replace RutabagaBuilder::new(component, virgl_flags, capset_mask)
    with new(capset_mask, fence_handler) signature
  - Explicitly set EGL flag via set_use_egl(true) to match old behavior
  - Rename RutabagaChannel to RutabagaPath (API change)
  - Update handle type constants (e.g. RUTABAGA_MEM_HANDLE_TYPE_* to
    RUTABAGA_HANDLE_TYPE_MEM_*)
  - Plumb export_table through RutabagaBuilder for cross-domain fd
    sharing between virtio-fs and virtio-gpu

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
VirtioFsKey is not publicly exported from
rutabaga_gfx v0.1.76-libkrun.0. Define local
VirtioFsKey and temporarily disable
export_table feature.

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
Using rutabaga_gfx from crates.io version 0.1.76-libkrun.0
instead of vendored source.

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @dorindabassey, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the project's GPU virtualization stack by migrating to an upstream version of the rutabaga_gfx crate. This change removes a significant amount of vendored code, simplifies the build process, and aligns the project with the latest RutabagaBuilder API. A temporary workaround ensures continued functionality for GPU-related file system operations while awaiting upstream rutabaga_gfx improvements.

Highlights

  • Dependency Update: The rutabaga_gfx dependency has been updated to version 0.1.76-libkrun.0 from crates.io, replacing the previously vendored version.
  • RutabagaBuilder API Adoption: The code now utilizes the new RutabagaBuilder API, specifically incorporating the capset_mask for more flexible GPU component initialization.
  • Vendored Crate Removal: The entire vendored rutabaga_gfx crate, including its FFI bindings, generated code, and internal modules, has been removed from the repository.
  • VirtioFsKey Workaround: A temporary local definition for VirtioFsKey has been added in src/devices/src/virtio/fs/filesystem.rs to address its lack of public export in the new rutabaga_gfx version, ensuring compatibility for GPU-enabled builds.
  • GPU Device Refactoring: The Gpu and Worker structs in src/devices/src/virtio/gpu have been refactored to remove the virgl_flags parameter, streamlining the GPU device initialization process with the new RutabagaBuilder.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Cargo.lock
    • Added mesa3d_util package with version 0.1.76-libkrun.0 and its dependencies.
    • Updated rutabaga_gfx package version from 0.1.2 to 0.1.76-libkrun.0 and adjusted its dependencies to include mesa3d_util, serde, and serde_json, while removing anyhow, nix, vmm-sys-util, and winapi.
  • src/devices/Cargo.toml
    • Updated rutabaga_gfx dependency to use version 0.1.76-libkrun.0 from crates.io instead of a local path, and modified its features for both general and Linux-specific targets.
  • src/devices/src/virtio/fs/filesystem.rs
    • Added a conditional public struct VirtioFsKey and a conditional type alias ExportTable to provide a temporary workaround for VirtioFsKey not being publicly exported in the new rutabaga_gfx version when the gpu feature is enabled.
  • src/devices/src/virtio/fs/linux/passthrough.rs
    • Imported the new VirtioFsKey struct conditionally for GPU builds.
    • Modified remove and insert operations on the ExportTable to conditionally use the new VirtioFsKey struct when the gpu feature is enabled, otherwise falling back to the (u64, u64) tuple.
  • src/devices/src/virtio/gpu/device.rs
    • Removed the virgl_flags field from the Gpu struct.
    • Removed the virgl_flags parameter from the Gpu::new constructor and the VirtioDevice::activate method.
  • src/devices/src/virtio/gpu/virtio_gpu.rs
    • Updated std::os::fd::AsRawFd import to std::os::unix::io::{AsFd, AsRawFd}.
    • Updated rutabaga_gfx imports to reflect changes in constants and types (e.g., RUTABAGA_MEM_HANDLE_TYPE_APPLE to RUTABAGA_HANDLE_TYPE_MEM_APPLE, RutabagaChannel to RutabagaPath).
    • Removed the virgl_flags parameter from VirtioGpu::new_rutabaga and VirtioGpu::new methods.
    • Refactored rutabaga_paths initialization to use RutabagaPath instead of RutabagaChannel.
    • Updated RutabagaBuilder::new call to use capset_mask and set_default_component, set_use_egl, set_use_gles, and set_rutabaga_paths methods.
    • Commented out the set_export_table call in RutabagaBuilder due to the VirtioFsKey public export issue.
    • Modified result_from_query to call rutabaga.resource3d_info instead of rutabaga.query.
    • Updated transfer_write call to include an additional None parameter.
    • Modified export_blob and resource_map logic to use export.as_mesa_handle() and mesa_handle.os_handle.as_fd().as_raw_fd() for handle access.
  • src/devices/src/virtio/gpu/worker.rs
    • Removed the virgl_flags field from the Worker struct.
    • Removed the virgl_flags parameter from the Worker::new constructor and the Worker::run method.
    • Updated Transfer3D::new_2d call to include the info.offset parameter.
  • src/rutabaga_gfx/Cargo.toml
    • Removed the entire file, indicating the removal of the vendored rutabaga_gfx crate.
  • src/rutabaga_gfx/LICENSE
    • Removed the entire file, as the vendored rutabaga_gfx license is no longer needed.
  • src/rutabaga_gfx/build.rs
    • Removed the entire file, as the vendored rutabaga_gfx build script is no longer needed.
  • src/rutabaga_gfx/ffi/Cargo.toml
    • Removed the entire file, indicating the removal of the FFI bindings for the vendored rutabaga_gfx.
  • src/rutabaga_gfx/ffi/LICENSE
    • Removed the entire file, as the FFI bindings license is no longer needed.
  • src/rutabaga_gfx/ffi/Makefile
    • Removed the entire file, as the FFI bindings Makefile is no longer needed.
  • src/rutabaga_gfx/ffi/build.rs
    • Removed the entire file, as the FFI bindings build script is no longer needed.
  • src/rutabaga_gfx/ffi/src/.clang-format
    • Removed the entire file, as the FFI bindings clang-format configuration is no longer needed.
  • src/rutabaga_gfx/ffi/src/include/rutabaga_gfx_ffi.h
    • Removed the entire file, as the FFI bindings header is no longer needed.
  • src/rutabaga_gfx/ffi/src/lib.rs
    • Removed the entire file, as the FFI bindings library is no longer needed.
  • src/rutabaga_gfx/ffi/src/tests/Makefile
    • Removed the entire file, as the FFI bindings test Makefile is no longer needed.
  • src/rutabaga_gfx/ffi/src/tests/rutabaga_test.c
    • Removed the entire file, as the FFI bindings test C file is no longer needed.
  • src/rutabaga_gfx/ffi/src/tests/virtgpu_cross_domain_protocol.h
    • Removed the entire file, as the FFI bindings cross-domain protocol header is no longer needed.
  • src/rutabaga_gfx/src/cross_domain/cross_domain_protocol.rs
    • Removed the entire file, as the vendored cross-domain protocol is no longer needed.
  • src/rutabaga_gfx/src/cross_domain/mod.rs
    • Removed the entire file, as the vendored cross-domain module is no longer needed.
  • src/rutabaga_gfx/src/cross_domain/sys/epoll_internal.rs
    • Removed the entire file, as the vendored epoll internal module is no longer needed.
  • src/rutabaga_gfx/src/cross_domain/sys/mod.rs
    • Removed the entire file, as the vendored cross-domain sys module is no longer needed.
  • src/rutabaga_gfx/src/cross_domain/sys/stub.rs
    • Removed the entire file, as the vendored cross-domain sys stub is no longer needed.
  • src/rutabaga_gfx/src/cross_domain/sys/unix.rs
    • Removed the entire file, as the vendored cross-domain sys unix module is no longer needed.
  • src/rutabaga_gfx/src/generated/generate
    • Removed the entire file, as the vendored generated script is no longer needed.
  • src/rutabaga_gfx/src/generated/generate.py
    • Removed the entire file, as the vendored generated script is no longer needed.
  • src/rutabaga_gfx/src/generated/mod.rs
    • Removed the entire file, as the vendored generated module is no longer needed.
  • src/rutabaga_gfx/src/generated/virgl_debug_callback_bindings.rs
    • Removed the entire file, as the vendored virgl debug callback bindings are no longer needed.
  • src/rutabaga_gfx/src/generated/virgl_renderer_bindings.rs
    • Removed the entire file, as the vendored virgl renderer bindings are no longer needed.
  • src/rutabaga_gfx/src/gfxstream.rs
    • Removed the entire file, as the vendored gfxstream module is no longer needed.
  • src/rutabaga_gfx/src/gfxstream_stub.rs
    • Removed the entire file, as the vendored gfxstream stub module is no longer needed.
  • src/rutabaga_gfx/src/lib.rs
    • Removed the entire file, as the vendored rutabaga_gfx library is no longer needed.
  • src/rutabaga_gfx/src/macros.rs
    • Removed the entire file, as the vendored macros are no longer needed.
  • src/rutabaga_gfx/src/renderer_utils.rs
    • Removed the entire file, as the vendored renderer utilities are no longer needed.
  • src/rutabaga_gfx/src/rutabaga_2d.rs
    • Removed the entire file, as the vendored rutabaga 2D module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_core.rs
    • Removed the entire file, as the vendored rutabaga core module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/formats.rs
    • Removed the entire file, as the vendored gralloc formats module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/gralloc.rs
    • Removed the entire file, as the vendored gralloc module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/minigbm.rs
    • Removed the entire file, as the vendored minigbm module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/minigbm_bindings.rs
    • Removed the entire file, as the vendored minigbm bindings are no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/mod.rs
    • Removed the entire file, as the vendored gralloc module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/rendernode.rs
    • Removed the entire file, as the vendored rendernode module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/system_gralloc.rs
    • Removed the entire file, as the vendored system gralloc module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc.rs
    • Removed the entire file, as the vendored vulkano gralloc module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys.rs
    • Removed the entire file, as the vendored vulkano gralloc sys module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys/unix.rs
    • Removed the entire file, as the vendored vulkano gralloc sys unix module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_gralloc/vulkano_gralloc/sys/windows.rs
    • Removed the entire file, as the vendored vulkano gralloc sys windows module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/descriptor.rs
    • Removed the entire file, as the vendored OS descriptor module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/memory_mapping.rs
    • Removed the entire file, as the vendored OS memory mapping module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/mod.rs
    • Removed the entire file, as the vendored OS module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/shm.rs
    • Removed the entire file, as the vendored OS shared memory module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/stub/descriptor.rs
    • Removed the entire file, as the vendored OS sys stub descriptor module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/stub/memory_mapping.rs
    • Removed the entire file, as the vendored OS sys stub memory mapping module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/stub/mod.rs
    • Removed the entire file, as the vendored OS sys stub module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/stub/shm.rs
    • Removed the entire file, as the vendored OS sys stub shared memory module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/unix/descriptor.rs
    • Removed the entire file, as the vendored OS sys unix descriptor module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/unix/memory_mapping.rs
    • Removed the entire file, as the vendored OS sys unix memory mapping module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/unix/mod.rs
    • Removed the entire file, as the vendored OS sys unix module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/unix/shm.rs
    • Removed the entire file, as the vendored OS sys unix shared memory module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/windows/descriptor.rs
    • Removed the entire file, as the vendored OS sys windows descriptor module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/windows/memory_mapping.rs
    • Removed the entire file, as the vendored OS sys windows memory mapping module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/windows/mod.rs
    • Removed the entire file, as the vendored OS sys windows module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_os/sys/windows/shm.rs
    • Removed the entire file, as the vendored OS sys windows shared memory module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_snapshot.rs
    • Removed the entire file, as the vendored rutabaga snapshot module is no longer needed.
  • src/rutabaga_gfx/src/rutabaga_utils.rs
    • Removed the entire file, as the vendored rutabaga utilities module is no longer needed.
  • src/rutabaga_gfx/src/virgl_renderer.rs
    • Removed the entire file, as the vendored virgl renderer module is no longer needed.
  • src/vmm/src/builder.rs
    • Modified the build_microvm function to conditionally check for vm_resources.gpu_virgl_flags presence.
    • Removed the virgl_flags parameter from the devices::virtio::Gpu::new call within build_microvm.
    • Removed the virgl_flags parameter from the attach_gpu_device function signature and its call to devices::virtio::Gpu::new.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request migrates rutabaga_gfx to version 0.1.76-libkrun.0 from crates.io and removes the vendored version. It correctly adopts the new RutabagaBuilder API and updates resource mapping and transfer calls to match the upstream changes. However, there are two significant issues: the capset_mask is hardcoded to 0, which will likely prevent the guest from discovering 3D capabilities, and the export_table functionality is currently disabled due to type mismatch issues with the VirtioFsKey workaround, resulting in a regression for VirtioFS/GPU resource sharing.


// Initialize VirglRenderer - use capset_mask=0 to register all available capsets
// and explicitly set VirglRenderer as the default component
let capset_mask = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The capset_mask is hardcoded to 0. In rutabaga_gfx, this mask determines which capability sets are advertised to the guest. Hardcoding it to 0 will likely cause the guest driver to fail to discover 3D acceleration features (like Virgl), even if the VirglRenderer component is initialized. The comment suggests this registers all available capsets, but typically a bitmask of 0 indicates no capsets are enabled. This should likely be derived from the desired features or set to include relevant capsets like RUTABAGA_CAPSET_VIRGL and RUTABAGA_CAPSET_VIRGL2.

Comment on lines +274 to +282
// TODO: Re-enable once rutabaga_gfx exports VirtioFsKey publicly
// The export_table feature requires VirtioFsKey which is defined in
// rutabaga_gfx::rutabaga_core but not re-exported in the public API.
// Our local VirtioFsKey definition matches the layout but causes type
// mismatch errors when passed to rutabaga.
// if let Some(export_table) = export_table {
// builder = builder.set_export_table(export_table);
// }
let _ = export_table; // Suppress unused variable warning

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The export_table functionality is currently disabled and the variable is suppressed. This is a regression that prevents sharing resources between VirtioFS and the GPU (e.g., for mapping host files into GPU memory). While the TODO indicates this is a temporary workaround for the non-exported VirtioFsKey type in rutabaga_gfx, this feature is critical for certain use cases and should be re-enabled as soon as possible.

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.

1 participant