Skip to content

Commit

Permalink
gui-vm: Enable GPU acceleration
Browse files Browse the repository at this point in the history
This patch will enable hardware accelerated display
for renderering along with media hardware codecs.
Also we are patching Intel i915 driver in gui-vm to
avoid reserving Intel graphics memory during boot
time which in turn fixes DMA Fault error on the
ghaf-host.

Signed-off-by: Vunny Sodhi <[email protected]>
  • Loading branch information
vunnyso authored and brianmcgillion committed Sep 3, 2024
1 parent 73ae009 commit 15f2fd6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
1 change: 1 addition & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ path = [
"modules/jetpack-microvm/*.patch",
"modules/jetpack/nvidia-jetson-orin/virtualization/passthrough/uarti-net-vm/patches/net_vm_dtb_with_uarti.patch",
"modules/common/virtualization/pkvm/0001-pkvm-enable-pkvm-on-intel-x86-6.1-lts.patch",
"modules/microvm/virtualization/microvm/0001-x86-gpu-Don-t-reserve-stolen-memory-for-GPU-passthro.patch",
]

[[annotations]]
Expand Down
13 changes: 10 additions & 3 deletions modules/desktop/profiles/graphics.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in
};
renderer = lib.mkOption {
type = lib.types.enum renderers;
default = "pixman";
default = "gles2";
description = ''
Which wlroots renderer to use.
Expand Down Expand Up @@ -74,12 +74,19 @@ in
};

config = mkIf cfg.enable {
hardware.graphics.enable = true;
hardware.graphics = {
enable = true;
extraPackages = mkIf pkgs.stdenv.hostPlatform.isx86 [ pkgs.intel-media-driver ];
};
environment.noXlibs = false;
environment.sessionVariables = {
WLR_RENDERER = cfg.renderer;
XDG_SESSION_TYPE = "wayland";
WLR_NO_HARDWARE_CURSORS = 1;
WLR_NO_HARDWARE_CURSORS = if (cfg.renderer == "pixman") then 1 else 0;
# 24 is default value set in labwc
XCURSOR_SIZE = 24;
# To Fix "Fontconfig error : No writable cache directories" during new session login
XDG_CACHE_HOME = "$(mktemp -d)";
XKB_DEFAULT_LAYOUT = "us,ara,fi";
XKB_DEFAULT_OPTIONS = "grp:alt_shift_toggle";
# Set by default in labwc, but possibly not in other compositors
Expand Down
2 changes: 1 addition & 1 deletion modules/hardware/lenovo-x1/definitions/x1-gen11.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
kernelConfig.kernelParams = [
"intel_iommu=on,sm_on"
"iommu=pt"
"module_blacklist=i915" # Prevent i915 module from being accidentally used by host
"module_blacklist=i915,xe" # Prevent i915,xe modules from being accidentally used by host
"acpi_backlight=vendor"
"acpi_osi=linux"
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 13c0345fc3e5ed8b6c28d1f272bb2630881d4714 Mon Sep 17 00:00:00 2001
From: Vunny Sodhi <[email protected]>
Date: Thu, 29 Aug 2024 19:46:24 +0300
Subject: [PATCH] x86/gpu: Don't reserve stolen memory for GPU passthrough

Signed-off-by: Vunny Sodhi <[email protected]>
---
arch/x86/kernel/early-quirks.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 59f4aefc6..3b735eea9 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -596,6 +596,9 @@ static void __init intel_graphics_quirks(int num, int slot, int func)
u16 device;
int i;

+ // Nothing to do for GPU passthrough case
+ return;
+
/*
* Reserve "stolen memory" for an integrated GPU. If we've already
* found one, there's nothing to do for other (discrete) GPUs.
--
2.40.1

29 changes: 25 additions & 4 deletions modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ let
]
++ (lib.optional (
config.ghaf.profiles.debug.enable && config.ghaf.virtualization.microvm.idsvm.mitmproxy.enable
) pkgs.mitmweb-ui);
) pkgs.mitmweb-ui)
# Packages for checking hardware acceleration
++ lib.optionals config.ghaf.profiles.debug.enable [
pkgs.glxinfo
pkgs.libva-utils
];
};

time.timeZone = config.time.timeZone;
Expand Down Expand Up @@ -190,6 +195,7 @@ let
buildKernel = import ../../../../packages/kernel { inherit config pkgs lib; };
config_baseline = ../../../hardware/x86_64-generic/kernel/configs/ghaf_host_hardened_baseline-x86;
guest_graphics_hardened_kernel = buildKernel { inherit config_baseline; };

in
{
options.ghaf.virtualization.microvm.guivm = {
Expand Down Expand Up @@ -230,9 +236,24 @@ in
microvm.vms."${vmName}" = {
autostart = true;
config = guivmBaseConfiguration // {
boot.kernelPackages = lib.mkIf config.ghaf.guest.kernel.hardening.graphics.enable (
pkgs.linuxPackagesFor guest_graphics_hardened_kernel
);
boot.kernelPackages =
if config.ghaf.guest.kernel.hardening.graphics.enable then
pkgs.linuxPackagesFor guest_graphics_hardened_kernel
else
# TODO: with pkgs.linuxPackages_latest (6.10.2) default brightness
# value of ghaf system will change from 96000 (max brightness) to
# 4800 (5% of max brightness) which need to be debugged
# so, currently align Kernel version which is used by ghaf-host
config.boot.zfs.package.latestCompatibleLinuxPackages;

# We need this patch to avoid reserving Intel graphics stolen memory for vm
# https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12103
boot.kernelPatches = [
{
name = "gpu-passthrough-fix";
patch = ./0001-x86-gpu-Don-t-reserve-stolen-memory-for-GPU-passthro.patch;
}
];

imports = guivmBaseConfiguration.imports ++ cfg.extraModules;
};
Expand Down

0 comments on commit 15f2fd6

Please sign in to comment.