Can't use Nvidia PRIME with Laptop

I have a Thinkpad T480 with a MX150. I’m running nixos-unstable.

lspci| grep -E 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 620 (rev 07)
01:00.0 3D controller: NVIDIA Corporation GP108M [GeForce MX150] (rev a1)

°

xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x47 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 5 associated providers: 0 name:modesetting
Provider 1: id: 0xf7 cap: 0x0 crtcs: 0 outputs: 0 associated providers: 0 name:modesetting
nvidia-smi
Sat Apr 18 22:59:23 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.82       Driver Version: 440.82       CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce MX150       Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   49C    P8    N/A /  N/A |      0MiB /  2002MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.32, NixOS, 20.09pre221706.b61999e4ad6 (Nightingale)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.4`
 - channels(root): `"nixos-20.09pre221706.b61999e4ad6"`
 - channels(edi): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos

configuration.nix


{ config, pkgs, ... }: {
  imports = [ ./hardware-configuration.nix ];

  nixpkgs.config.allowUnfree = true;

  services = {
    xserver = {
      enable = true;
      exportConfiguration = true;
      videoDrivers = [ "modesetting" "nvidia" ];
      displayManager.gdm = {
        enable = true;
        wayland = false;
      };
      desktopManager.gnome3.enable = true;
    };

  };

  hardware = {
    nvidia = {
      modesetting.enable = true;
      prime = {
        offload.enable = true;
        intelBusId = "PCI:0:2:0";
        nvidiaBusId = "PCI:1:0:0";
      };
    };

    opengl = {
      driSupport = true;
      driSupport32Bit = true;
    };
  };

  system.stateVersion = "20.09";
}

glxinfo | grep "OpenGL renderer"
OpenGL renderer string: Mesa Intel(R) UHD Graphics 620 (KBL GT2)
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia __VK_LAYER_NV_optimus=NVIDIA_only __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G1 glxinfo | grep "OpenGL renderer"
name of display: :1
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  152 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  39
  Current serial number in output stream:  40"

I used to have a working PRIME setup when I used Archlinux. I don’t know what I’m missing?

Everything looks fine except your xrandr --listproviders. Can I see your logs, like journalctl -b?

AFAIK videoDrivers are tried in orders, try to set it as [ "nvidia" "modesetting"] instead.

paste

Especially the line nvidia: Process '/nix/store/ffli6m23501dkiznwlkf6n4xvrj02snr-bash-4.4-p23/bin/bash -c 'mknod -m 666 /dev/nvidiactl c $(grep nvidia-frontend /proc/devices | cut -d \ -f 1) 255'' failed with exit code 1. looks a bit weird.

Switching the order of the nvidia and modesetting drivers didn’t change anything.

Try removing "modesetting" from your videoDrivers.

1 Like

I was about to dismiss this, as the last time I’ve tried this, all I got was a black screen. But there must have been some other error in my config, which I’ve fixed in the meantime. Everything seems to work for now. Thank you.

I am in a very similar situation, but I couldn’t solve by adding/moving/removing modesetting.

$ lspci| grep -E 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630 (Mobile)
01:00.0 3D controller: NVIDIA Corporation TU117M [GeForce GTX 1650 Mobile / Max-Q] (rev a1)
$ xrandr --listproviders
Providers: number : 1
Provider 0: id: 0x49 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 7 associated providers: 0 name:modesetting
$ nvidia-smi
No devices were found
$ nix-shell -p nix-info --run "nix-info -m"                                                                               ~
 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.46, NixOS, 20.09pre229870.22c98819ccd (Nightingale)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.6`
 - channels(root): `"nixos-20.09pre229870.22c98819ccd, nixos-hardware, nixpkgs-20.03, release-20.03.tar.gz-20.03"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

relevant configuration.nix

{ config, pkgs, ... }:

let
  nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
    export __NV_PRIME_RENDER_OFFLOAD=1
    export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
    export __GLX_VENDOR_LIBRARY_NAME=nvidia
    export __VK_LAYER_NV_optimus=NVIDIA_only
    exec -a "$0" "$@"
  '';
in
{

  services.xserver.enable = true;
  services.xserver.videoDrivers = [ "nvidia" ];
  # services.xserver.videoDrivers = [ "nvidia" "modesetting" ];

  hardware.nvidia.prime = {
    offload.enable = true;
    intelBusId = "PCI:0:2:0";
    nvidiaBusId = "PCI:1:0:0";
  };
}
$ glxinfo | grep "OpenGL renderer"
OpenGL renderer string: Mesa Intel(R) UHD Graphics 630 (CFL GT2)
$ nvidia-offload glxinfo | grep "OpenGL renderer"
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  152 (GLX)
  Minor opcode of failed request:  24 (X_GLXCreateNewContext)
  Value in failed request:  0x0
  Serial number of failed request:  39
  Current serial number in output stream:  40

Kernel parameters

BOOT_IMAGE=(hd0,gpt2)//kernels/mkpv02ci0s8f5fz8kxyc1zb6rjv451ql-linux-5.4.46-bzImage systemConfig=/nix/store/syccmvrxq3q00z59ln13bkbscs0wxpjh-nixos-system-host-20.09pre229870.22c98819ccd init=/nix/store/syccmvrxq3q00z59ln13bkbscs0wxpjh-nixos-system-host-20.09pre229870.22c98819ccd/init mem_sleep_default=deep splash loglevel=4 nvidia-drm.modeset=1

I tried enabling modesetting in videoDrivers as above (both before and after nvidia), but with no luck: glxinfo will always fail with that error. The only notable difference with modesetting is that I get 2 providers in xrandr (2nd being modesetting).

When not using modesetting, I get this in my log:

blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (II) NVIDIA: The X server supports PRIME Render Offload.
blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (EE) NVIDIA(GPU-0): Failed to initialize the NVIDIA GPU at PCI:1:0:0.  Please
blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (EE) NVIDIA(GPU-0):     check your system's kernel log for additional error
blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (EE) NVIDIA(GPU-0):     messages and refer to Chapter 8: Common Problems in the
blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (EE) NVIDIA(GPU-0):     README for additional information.
blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (EE) NVIDIA(GPU-0): Failed to initialize the NVIDIA graphics device!
blahblah-gdm-3.34.1/libexec/gdm-x-session[1664]: (EE) NVIDIA(G0): Failing initialization of X screen

But I don’t understand what is the root cause.

In both cases (with and without modesetting in the config), I can see this in the logs:

(EE) modeset(0): failed to set mode: Permission denied

What am I doing wrong?

Thanks to my colleagues I found a solution. The problem is that the driver was being unloaded, so it was necessary to use nvidia-persistenced to my configuration:

hardware.nvidia.nvidiaPersistenced = true;
4 Likes