Skip to content

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

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

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).

@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.

@mtjhrc
Copy link
Collaborator

mtjhrc commented Feb 25, 2026

To continue on the discussion from #558

Personally I also think we need to continue to accept important changes to rutabaga until we use the upstream. Actually this will help us close the gap (but the things we merge should also go upstream!).
Also, I think it's entirely possible to switch to upstream on libkrun 1.x too, but we need feature parity, packaging and test that everything works. If that is something we want to work on depends on the timeline of libkrun 2.0 (we can also discuss this on the next libkrun sync).

@valpackett
Copy link
Contributor

Finally testing this since I needed to test magma-gpu/rutabaga_gfx#42 and also maybe avoid contributing D-Bus support into the fork when we're so close to unforking… :)

Other than the flags/capset control issue above, one thing missing compared to before is gbm (referenced in the discussion in magma-gpu/rutabaga_gfx#40), I ported over the upstream gbm support hacks from the vendored fork but might've screwed something up since software-rendered apps crash the proxy with that enabled (investigating). But without the gbm feature they work fine. (FWIW this gbm gralloc thing seems to only be an optimization, to make sure the SHM copy-out in the guest proxy goes directly to GPU-managed memory)

@dorindabassey dorindabassey force-pushed the fixkrun branch 3 times, most recently from 7d945d6 to 88cff0a Compare March 3, 2026 09:50
@dorindabassey
Copy link
Collaborator Author

Finally testing this since I needed to test magma-gpu/rutabaga_gfx#42 and also maybe avoid contributing D-Bus support into the fork when we're so close to unforking… :)

+1

Other than the flags/capset control issue above, one thing missing compared to before is gbm (referenced in the discussion in magma-gpu/rutabaga_gfx#40), I ported over the upstream gbm support hacks from the vendored fork but might've screwed something up since software-rendered apps crash the proxy with that enabled (investigating). But without the gbm feature they work fine. (FWIW this gbm gralloc thing seems to only be an optimization, to make sure the SHM copy-out in the guest proxy goes directly to GPU-managed memory)

Fixed the flags/capset issue, For gbm - I see from magma-gpu/rutabaga_gfx#40 that there's a plan to move from minigbm to upstream GBM. Since the gbm feature isn't currently enabled in our Cargo.toml and you said it crashes with software rendering, maybe let's land this PR first and add gbm support as a follow-up once the upstream rutabaga_gfx gbm migration (magma-gpu/rutabaga_gfx#40) is done? I don't know the timeline for that, I just want to make sure we unblock the migration without getting stuck on an optimization feature. wdyt?
Just to clarify, after taking a second look at the vendored rutabaga_gfx, even though we had minigbm feature defined it was never actually enabled in our Cargo.toml (we only used virgl_renderer). So gbm wasn't being used before either.

@dorindabassey
Copy link
Collaborator Author

/gemini review

@dorindabassey dorindabassey marked this pull request as ready for review March 3, 2026 10:46
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

This pull request migrates from a vendored rutabaga_gfx to an upstream version from a git repository. This is a significant and positive change, removing vendored code. The changes primarily involve adapting to the new rutabaga_gfx API, especially around the RutabagaBuilder and resource handling. The code modifications look correct and handle the API changes well. I have one minor suggestion to improve code style.

@valpackett
Copy link
Contributor

maybe let's land this PR first and add gbm support as a follow-up once the upstream rutabaga_gfx gbm migration is done?

Definitely +1

even though we had minigbm feature defined it was never actually enabled in our Cargo.toml (we only used virgl_renderer). So gbm wasn't being used before either.

Ohhh… huh. I was so sure it was being used, but that seems to be true!

Fixed the flags/capset issue

Thanks a lot, will take a look now

Dorinda Bassey added 3 commits March 4, 2026 12:41
Migrate to new RutabagaBuilder API while preserving virgl_flags
parameter to properly translate GPU mode selection into capset masks.

  Key changes:
  - Replace RutabagaBuilder::new(component, virgl_flags, capset_mask)
    with new(capset_mask, fence_handler) signature
  - Translate virgl_flags to capset_mask respecting mutually exclusive
    GPU modes
  - Explicitly set EGL flag 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>
Migrate to git-based rutabaga_gfx dependency and implement the
VirtioFsLookup trait for virtio-fs file descriptor export to GPU
contexts. Simplifies ExportTable to use (u64, u64) tuple keys.

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>
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