Nvidia-settings crash while nvidia as primary GPU

Device: Legion 5 Pro(Ryzen 5800H and RTX 3060 Laptop)
OS: Arch Linux
Kernel: 5.17.1-arch1-1
NVIDIA Driver: 510.60.02
DE: GNOME 42.0
Display Server: X11

Due to the update to 510.xx driver, the discrete GPU mode cannot control the backlight. (Legion 5 Pro - Backlight control not working from driver 510.54 - #2 by cronus)

So I switched to hybrid GPU mode.
In hybrid GPU mode, nvidia-settings works when AMD GPU is the primary GPU, nvidia-settings crashes when NVIDIA GPU is the primary GPU.

  1. AMD GPU is the primary GPU:
Section "Device"
    Identifier	"amdgpu"
    BusID       "PCI:6:0:0"
    Driver	"amdgpu"
    Option	"VariableRefresh" "true"
EndSection

Section "Screen"
    Identifier	"amdgpu"
    Device	"amdgpu"
EndSection

Section "Device"
    Identifier	"nvidia"
    Driver	"nvidia"
    BusID       "PCI:1:0:0"
    VendorName	"NVIDIA Corporation"
    BoardName	"NVIDIA GeForce RTX 3060 Laptop GPU"
    Option      "AllowEmptyInitialConfiguration"
    Option	"AllowExternalGpus" "yes"
    Option	"PrimaryGPU" "no"
    Option	"HardDPMS" "on"
EndSection

Section "Screen"
    Identifier	"nvidia"
    Device	"nvidia"
    Option	"MetaModes" "nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}"
    Option	"AllowIndirectGLXProtocol" "off"
    Option	"TripleBuffer" "on"
EndSection

Section "ServerLayout"
    Identifier "layout"
    Screen 	0 "amdgpu"
    Inactive	"nvidia"
    Option	"AllowNVIDIAGPUScreens"
EndSection

$ glxinfo | grep "OpenGL renderer"      
OpenGL renderer string: AMD RENOIR (LLVM 13.0.1, DRM 3.44, 5.17.1-arch1-1)

//nvidia-settings works
$ nvidia-settings
(nvidia-settings:38299): GLib-GObject-CRITICAL **: 01:48:56.325: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
  1. NVIDIA GPU is the primary GPU:
Section "Device"
    Identifier	"amdgpu"
    BusID       "PCI:6:0:0"
    Driver	"amdgpu"
    Option	"VariableRefresh" "true"
EndSection

Section "Screen"
    Identifier	"amdgpu"
    Device	"amdgpu"
EndSection

Section "Device"
    Identifier	"nvidia"
    Driver	"nvidia"
    BusID       "PCI:1:0:0"
    VendorName	"NVIDIA Corporation"
    BoardName	"NVIDIA GeForce RTX 3060 Laptop GPU"
    Option      "AllowEmptyInitialConfiguration"
    Option	"AllowExternalGpus" "yes"
    Option	"PrimaryGPU" "yes"
    Option	"HardDPMS" "on"
EndSection

Section "Screen"
    Identifier	"nvidia"
    Device	"nvidia"
    Option	"MetaModes" "nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}"
    Option	"AllowIndirectGLXProtocol" "off"
    Option	"TripleBuffer" "on"
EndSection

Section "ServerLayout"
    Identifier "layout"
    Screen 	0 "nvidia"
    Inactive	"amdgpu"
    Option	"AllowNVIDIAGPUScreens"
EndSection

$ glxinfo | grep "OpenGL renderer"
OpenGL renderer string: NVIDIA GeForce RTX 3060 Laptop GPU/PCIe/SSE2

//nvidia-settings crash
$ nvidia-settings
[1]    35780 segmentation fault (core dumped)  nvidia-settings

Please run nvidia-bug-report.sh as root and attach the resulting nvidia-bug-report.log.gz file to your post.

nvidia-bug-report.log.gz (556.9 KB)

~ » xrandr --listmonitors
Monitors: 2
 0: +*DP-2 3840/628x2160/335+2560+0  DP-2
 1: +eDP-1-1 2560/345x1600/215+0+560  eDP-1-1
~ » xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x1b7 cap: 0x1, Source Output crtcs: 4 outputs: 6 associated providers: 1 name:NVIDIA-0
Provider 1: id: 0x203 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 4 outputs: 1 associated providers: 1 name:modesetting

Your xorg.conf in /etc/X11/xorg.conf.d/11-gpu-primary-nvidia.conf doesn’t look sane, please delete it and instead create
/etc/X11/xorg.conf.d/11-nvidia-prime.conf just containing

Section "OutputClass"
    Identifier "nvidia-primary"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "PrimaryGPU" "yes"
    Option "ForceFullCompositionPipeline" "true"
EndSection

Furthermore, please add kernel parameter (or module option)
nvidia-drm.modeset=1

nvidia-settings still crashes

nvidia-bug-report.log.gz (474.0 KB)

~ » sudo rm -rf /etc/X11/xorg.conf.d/*
~ » sudo cp /usr/share/X11/xorg.conf.d/10-amdgpu.conf /etc/X11/xorg.conf.d/
~ » sudo cp /usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf /etc/X11/xorg.conf.d/
~ » cat /etc/X11/xorg.conf.d/10-amdgpu.conf 
Section "OutputClass"
	Identifier "AMDgpu"
	MatchDriver "amdgpu"
	Driver "amdgpu"
EndSection

~ » cat /etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf 
Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    ModulePath "/usr/lib/nvidia/xorg"
    ModulePath "/usr/lib/xorg/modules"
EndSection

~ » sudo vim /etc/X11/xorg.conf.d/10-amdgpu.conf 
~ » sudo vim /etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf
~ » cat /etc/X11/xorg.conf.d/10-amdgpu.conf
Section "OutputClass"
	Identifier "AMDgpu"
	MatchDriver "amdgpu"
	Driver "modesetting"
EndSection

~ » cat /etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf
Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "PrimaryGPU" "yes"
    Option "ForceFullCompositionPipeline" "true"
    ModulePath "/usr/lib/nvidia/xorg"
    ModulePath "/usr/lib/xorg/modules"
EndSection