Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import rutabaga_gfx+virtio_gpu from crosvm #144

Merged
merged 12 commits into from
Feb 19, 2024
Merged

Conversation

slp
Copy link
Contributor

@slp slp commented Sep 26, 2023

The code is gated behind the "gpu" feature.

@slp slp force-pushed the virtio-gpu branch 4 times, most recently from 74a58d5 to d62d0f7 Compare September 26, 2023 10:22
@alyssarosenzweig
Copy link
Contributor

Is vendoring these libs necessary? Any way to pull them in as external dependencies for easier tracking of upstream? or is that a no-go for upstream?

@slp
Copy link
Contributor Author

slp commented Sep 26, 2023

Is vendoring these libs necessary? Any way to pull them in as external dependencies for easier tracking of upstream? or is that a no-go for upstream?

@alyssarosenzweig virtio-gpu is not intended to be externally consumed and we also need a number of small but critical changes to make it compatible with libkrun, so I don't think it's really an option.

The case of rutabaga_gfx is more interesting, as it seems like in v0.1.2 they've deliberately dropped some internal dependencies (base and data_model) and published it in crates.io so it can be internally consumed. On the other hand, I kind of prefer to keep this new crates vendorized, eventually dropping them once things settle upstream, just as we did with kbs-types.

@tylerfanelli
Copy link
Member

@slp Is there any docs showing how I could I try this for myself, to test?

@alyssarosenzweig
Copy link
Contributor

Is vendoring these libs necessary? Any way to pull them in as external dependencies for easier tracking of upstream? or is that a no-go for upstream?

@alyssarosenzweig virtio-gpu is not intended to be externally consumed and we also need a number of small but critical changes to make it compatible with libkrun, so I don't think it's really an option.

The case of rutabaga_gfx is more interesting, as it seems like in v0.1.2 they've deliberately dropped some internal dependencies (base and data_model) and published it in crates.io so it can be internally consumed. On the other hand, I kind of prefer to keep this new crates vendorized, eventually dropping them once things settle upstream, just as we did with kbs-types.

ah, entirely reasonable. 👍

@slp
Copy link
Contributor Author

slp commented Sep 28, 2023

@tylerfanelli To test it you need a image with sommelier. I've just added a sommelier package to this COPR repo so you can take it from there if you don't want to build it yourself. Something like this should do the trick:

  1. Prepare an OCI image with sommelier, gedit (or some other Wayland app to test) and firefox (to test Xwayland):
$ podman run -ti --name fedora-gpu fedora:38
# dnf install -y dnf-plugins-core
# dnf copr enable slp/asahi-krun 
# dnf install -y sommelier gedit firefox xorg-x11-server-Xwayland
# exit
  1. Increase chroot_vm microVM settings (to run firefox) and expand the OCI in a directory:
$ cd examples
$ sed -i 's/1, 512/4, 4096/g' chroot_vm.c
$ make
$ mkdir fedora-gpu
$ podman export fedora-gpu | tar xf - -C fedora-gpu
  1. Start the microVM and run some apps with sommelier:
$ ulimit -n 524288
$ buildah unshare
# ./chroot_vm fedora-gpu/ /bin/bash
bash-5.2# echo "nameserver 1.1.1.1" > /etc/resolv.conf
bash-5.2# export XDG_RUNTIME_DIR=/tmp
bash-5.2# sommelier --virtgpu-channel gedit
bash-5.2# sommelier --virtgpu-channel -X  firefox

@mtjhrc
Copy link
Collaborator

mtjhrc commented Feb 7, 2024

For anyone else wants to try this, note that you have to enable virtio-gpu for libkrufw:

diff --git a/config-libkrunfw_x86_64 b/config-libkrunfw_x86_64
index 8fb4eb1..abceeb3 100644
--- a/config-libkrunfw_x86_64
+++ b/config-libkrunfw_x86_64
@@ -1369,7 +1369,8 @@ CONFIG_BCMA_POSSIBLE=y
 #
 # Graphics support
 #
-# CONFIG_DRM is not set
+CONFIG_DRM=y
+CONFIG_DRM_VIRTIO_GPU=y
 # CONFIG_DRM_DEBUG_MODESET_LOCK is not set
 
 #

@slp slp requested a review from mtjhrc as a code owner February 15, 2024 13:56
@slp slp force-pushed the virtio-gpu branch 3 times, most recently from ac21cbf to df102b0 Compare February 15, 2024 14:46
@slp slp marked this pull request as draft February 15, 2024 14:55
slp added 11 commits February 15, 2024 20:35
Import rutabaga_gfx from crosvm as of commit
081bca1c136ff745c0fd5f0dda7be37693ec01af ("Rename struct Window to
GuiWindow.")

The only change from the original sources is in build.rs, which was
simplified to avoid trying to build static versions of minigbm and
virglrenderer, dynamically linking with system libraries instead.

Signed-off-by: Sergio Lopez <[email protected]>
Sources as came from crosvm contain some minor aesthetic clippy errors.
Fix them to satisfy CI.

Signed-off-by: Sergio Lopez <[email protected]>
Extend the API with the public set_use_drm method to allow users to set
the use of drm in virglrenderer.

Signed-off-by: Sergio Lopez <[email protected]>
Refactor descriptor utils to be shared with virtio-gpu implementation.

Signed-off-by: Sergio Lopez <[email protected]>
Import virtio-gpu from crosvm as of commit
081bca1c136ff745c0fd5f0dda7be37693ec01af ("Rename struct Window to
GuiWindow.")

This import tries to make just the minimum amount of changes needed to
work in libkrun, so we can easily track future improvements made in
crosvm.

For the time being, the code will be gated behind the "gpu" feature.

Signed-off-by: Sergio Lopez <[email protected]>
Apply minor changes to rutabaga to ensure it builds properly on macOS.

Signed-off-by: Sergio Lopez <[email protected]>
Reserve a region of shared memory on macOS, just as we do on Linux. This
region will be used for the virtio-gpu device.

Signed-off-by: Sergio Lopez <[email protected]>
virtio-gpu requires a larger shared memory region to be able to interact
with the host's GPU.

Signed-off-by: Sergio Lopez <[email protected]>
Add a step to install the packages required for the gpu feature, and
rework clippy tests to reflect the most common combinations we'll be
offering.

Signed-off-by: Sergio Lopez <[email protected]>
Refresh Cargo.lock after adding rutabaga and virtio-gpu.

Signed-off-by: Sergio Lopez <[email protected]>
Crates are loaded even when they are optional and not actually used,
which means that "rutabaga_gfx/build.rs" is executed even when not
enabling the "gpu" feature. This would force us to install epoxy and
virglrenderer in contexts where we don't really need them. Instead,
let's gate the pkg_config checks behind the "gpu" feature.

Signed-off-by: Sergio Lopez <[email protected]>
@slp slp force-pushed the virtio-gpu branch 2 times, most recently from 7533c6a to 56d0c6e Compare February 16, 2024 22:48
Export virgl flags all the way from RutabagaBuilder to the consumers of
the library so they can freely set the options they need for their
usecase.

Signed-off-by: Sergio Lopez <[email protected]>
@slp slp marked this pull request as ready for review February 16, 2024 22:56
@slp slp merged commit 157ddf0 into containers:main Feb 19, 2024
5 checks passed
@slp slp deleted the virtio-gpu branch February 19, 2024 09:58
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.

4 participants