diff options
author | Matthew Justin Bauer <mjbauer95@gmail.com> | 2018-06-01 23:14:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 23:14:35 -0400 |
commit | 0135f04d778df96d4b6427ddc441f2eab565057b (patch) | |
tree | 459e653fd931180398004fa3e500f0842bf4efc2 /nixos/modules/virtualisation | |
parent | cf152c2791c3a525736bcd540422d9b99a8f2a38 (diff) | |
parent | a3e239ac6233dc895edaf90d8d4ba6728d4d4a41 (diff) | |
download | nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.tar nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.tar.gz nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.tar.bz2 nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.tar.lz nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.tar.xz nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.tar.zst nixlib-0135f04d778df96d4b6427ddc441f2eab565057b.zip |
Merge pull request #40242 from gnidorah/gvt
linux: enable support for iGVT-g VGPU
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r-- | nixos/modules/virtualisation/kvmgt.nix | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/kvmgt.nix b/nixos/modules/virtualisation/kvmgt.nix new file mode 100644 index 000000000000..fc0bedb68bd0 --- /dev/null +++ b/nixos/modules/virtualisation/kvmgt.nix @@ -0,0 +1,64 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.virtualisation.kvmgt; + kernelPackages = config.boot.kernelPackages; + vgpuOptions = { + uuid = mkOption { + type = types.string; + description = "UUID of VGPU device. You can generate one with <package>libossp_uuid</package>."; + }; + }; +in { + options = { + virtualisation.kvmgt = { + enable = mkEnableOption '' + KVMGT (iGVT-g) VGPU support. Allows Qemu/KVM guests to share host's Intel integrated graphics card. + Currently only one graphical device can be shared + ''; + # multi GPU support is under the question + device = mkOption { + type = types.string; + default = "0000:00:02.0"; + description = "PCI ID of graphics card. You can figure it with <command>ls /sys/class/mdev_bus</command>."; + }; + vgpus = mkOption { + default = {}; + type = with types; attrsOf (submodule [ { options = vgpuOptions; } ]); + description = '' + Virtual GPUs to be used in Qemu. You can find devices via <command>ls /sys/bus/pci/devices/*/mdev_supported_types</command> + and find info about device via <command>cat /sys/bus/pci/devices/*/mdev_supported_types/i915-GVTg_V5_4/description</command> + ''; + example = { + "i915-GVTg_V5_8" = { + uuid = "a297db4a-f4c2-11e6-90f6-d3b88d6c9525"; + }; + }; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = singleton { + assertion = versionAtLeast kernelPackages.kernel.version "4.16"; + message = "KVMGT is not properly supported for kernels older than 4.16"; + }; + boot.kernelParams = [ "i915.enable_gvt=1" ]; + systemd.services = mapAttrs' (name: value: + nameValuePair "kvmgt-${name}" { + description = "KVMGT VGPU ${name}"; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = "${pkgs.runtimeShell} -c 'echo ${value.uuid} > /sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${name}/create'"; + ExecStop = "${pkgs.runtimeShell} -c 'echo 1 > /sys/bus/pci/devices/${cfg.device}/${value.uuid}/remove'"; + }; + wantedBy = [ "multi-user.target" ]; + } + ) cfg.vgpus; + }; + + meta.maintainers = with maintainers; [ gnidorah ]; +} |