Ship a udev rule to tag NVIDIA devices as master-of-seat (for logind/multiseat purposes)

Hi there!

NVIDIA drivers for Linux should ship a udev rule for tagging any kernel device exposed with these drivers (e.g. /dev/dri/card*) as master-of-seat, so it will work properly with systemd-logind (specially on multiseat setups). systemd-logind already tags any /dev/fb* devices as master-of-seat by default, which is OK for Nouveau open-source drivers, but not for NVIDIA binary ones, since they expose no framebuffer kernel devices.

A suitable udev rule for NVIDIA drivers is the following:

SUBSYSTEM==“drm”, KERNEL==“card[0-9]*”, ATTRS{vendor}==“0x10de”, DRIVERS==“nvidia”, TAG+=“master-of-seat”

See also: Bug #1365336 “After upgrading lightdm, system boots to the tty1 ...” : Bugs : lightdm package : Ubuntu

How is this supposed to work? Nvidia’s drivers don’t create sysfs entries. And if they were, it wouldn’t be SUBSYSTEM==“drm”, KERNEL==“card[0-9]*”. This rule will never get applied.

It does here and the rule works fine on fedora.

$ ls -lRa /sys/module/nvidia
/sys/module/nvidia:
total 0
drwxr-xr-x   6 root root    0 Sep  6 12:11 .
drwxr-xr-x 161 root root    0 Sep  6 12:11 ..
-r--r--r--   1 root root 4096 Sep  6 12:11 coresize
drwxr-xr-x   2 root root    0 Sep  6 12:11 drivers
drwxr-xr-x   2 root root    0 Sep  6 12:11 holders
-r--r--r--   1 root root 4096 Sep  6 12:11 initsize
-r--r--r--   1 root root 4096 Sep  6 12:11 initstate
drwxr-xr-x   2 root root    0 Sep  6 12:11 notes
-r--r--r--   1 root root 4096 Sep  6 12:11 refcnt
drwxr-xr-x   2 root root    0 Sep  6 12:11 sections
-r--r--r--   1 root root 4096 Sep  6 12:11 taint
--w-------   1 root root 4096 Sep  6 12:11 uevent
-r--r--r--   1 root root 4096 Sep  6 12:11 version

/sys/module/nvidia/drivers:
total 0
drwxr-xr-x 2 root root 0 Sep  6 12:11 .
drwxr-xr-x 6 root root 0 Sep  6 12:11 ..
lrwxrwxrwx 1 root root 0 Sep  6 12:11 pci:nvidia -> ../../../bus/pci/drivers/nvidia

/sys/module/nvidia/holders:
total 0
drwxr-xr-x 2 root root 0 Sep  6 12:11 .
drwxr-xr-x 6 root root 0 Sep  6 12:11 ..

/sys/module/nvidia/notes:
total 0
drwxr-xr-x 2 root root  0 Sep  6 12:11 .
drwxr-xr-x 6 root root  0 Sep  6 12:11 ..
-r--r--r-- 1 root root 36 Sep  6 12:11 .note.gnu.build-id

/sys/module/nvidia/sections:
total 0
drwxr-xr-x 2 root root    0 Sep  6 12:11 .
drwxr-xr-x 6 root root    0 Sep  6 12:11 ..
-r--r--r-- 1 root root 4096 Sep  6 12:11 .bss
-r--r--r-- 1 root root 4096 Sep  6 12:11 __bug_table
-r--r--r-- 1 root root 4096 Sep  6 12:11 .data
-r--r--r-- 1 root root 4096 Sep  6 12:11 .exit.text
-r--r--r-- 1 root root 4096 Sep  6 12:11 .gnu.linkonce.this_module
-r--r--r-- 1 root root 4096 Sep  6 12:11 .init.text
-r--r--r-- 1 root root 4096 Sep  6 12:11 __ksymtab
-r--r--r-- 1 root root 4096 Sep  6 12:11 __ksymtab_strings
-r--r--r-- 1 root root 4096 Sep  6 12:11 __mcount_loc
-r--r--r-- 1 root root 4096 Sep  6 12:11 .note.gnu.build-id
-r--r--r-- 1 root root 4096 Sep  6 12:11 .parainstructions
-r--r--r-- 1 root root 4096 Sep  6 12:11 __param
-r--r--r-- 1 root root 4096 Sep  6 12:11 .rodata
-r--r--r-- 1 root root 4096 Sep  6 12:11 .rodata.cst1
-r--r--r-- 1 root root 4096 Sep  6 12:11 .rodata.str1.1
-r--r--r-- 1 root root 4096 Sep  6 12:11 .rodata.str1.8
-r--r--r-- 1 root root 4096 Sep  6 12:11 .smp_locks
-r--r--r-- 1 root root 4096 Sep  6 12:11 .strtab
-r--r--r-- 1 root root 4096 Sep  6 12:11 .symtab
-r--r--r-- 1 root root 4096 Sep  6 12:11 .text
-r--r--r-- 1 root root 4096 Sep  6 12:11 .text.unlikely

The entries you show are created by the kernel upon module insertion. They don’t match the rule given above. SUBSYSTEM==“drm”, KERNEL==“card[0-9]*” matches for in-kernel drm drivers like nouveau, which create entries in /sys/class/drm, e.g.

> ls /sys/class/drm
card0       card0-DP-2      card0-LVDS-1  controlD64
card0-DP-1  card0-HDMI-A-1  card0-VGA-1   version

The card0 directory here is a symlink to nvidia

$ ls -al /sys/class/drm
total 0
drwxr-xr-x  2 root root    0 Sep  6 18:23 .
drwxr-xr-x 47 root root    0 Sep  6 18:23 ..
lrwxrwxrwx  1 root root    0 Sep  6 18:23 card0 -> ../../devices/pci0000:00/0000:00:03.0/0000:01:00.0/drm/card0
-r--r--r--  1 root root 4096 Sep  6 18:22 version
$ ls -Ral /sys/devices/pci0000:00/0000:00:03.0/0000:01:00.0/driver/module
lrwxrwxrwx 1 root root 0 Sep  6 18:25 /sys/devices/pci0000:00/0000:00:03.0/0000:01:00.0/driver/module -> ../../../../module/nvidia

My system with the nvidia drivers doesn’t have /sys/class/drm. These entries are created by the opensource drivers in the kernel. Nvidia’s drivers don’t make sysfs entries. The kernel sysfs API is GPL-only.

I suspect you’re missing the DRM kernel module. Check with:

$ zgrep "DRM.*=" /proc/config.gz 
CONFIG_DRM=m
etc.

Further evidence:

$ lsmod | grep nvidia
nvidia              10481437  33 
<b>drm</b>  <---- oh look    224600  3 nvidia

Thank you for the feedback!

Here is an alternative udev rule that doesn’t rely on DRM module being loaded:

SUBSYSTEM=="pci", ATTRS{vendor}=="0x10de", DRIVER=="nvidia", TAG+="seat", TAG+="master-of-seat"

I’m trying to combine this rule with the other one so that this one is only applied if no DRM kernel device is found (otherwise, apply the other rule above). Do you have any suggestions?