microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

With two distros in WSL2, group of `/dev/dri/card0` may be changed by the last started distro, and cause `vainfo` failed in the first distro

viruscamp opened this issue · comments

Windows build number:

10.0.22631.0

Your Distribution version:

Arch and Ubuntu-24.04

Your WSL versions:

WSL Version: 2.0.14.0
Kernel Version: 5.15.133.1-1
WSLg Version: 1.0.59
MSRDC Version: 1.2.4677
Direct3D Version: 1.611.1-81528511
DXCore Version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows Version: 10.0.22631.3235

Steps to reproduce:

  1. Install two different WSL2 distros in one compute, and install required packages in both
  2. In powershell, execute wsl --shutdown
  3. start Arch, execute the code below, it will be all OK.
$ ls -l /dev/dri
crw-rw---- 1 root video  226,   0  3月 5日 15:51 card0
crw-rw-rw- 1 root render 226, 128  3月 5日 15:51 renderD128

$ ls -ln /dev/dri
crw-rw---- 1 0 985 226,   0  3月 5日 15:51 card0
crw-rw-rw- 1 0 989 226, 128  3月 5日 15:51 renderD128

$ cat /etc/group | grep -E "video|render"
render:x:989:
video:x:985:user1

$ vainfo --display drm
Trying display: drm
vainfo: VA-API version: 1.20 (libva 2.20.1)
vainfo: Driver version: Mesa Gallium driver 24.0.2-arch1.1 for D3D12 (NVIDIA GeForce RTX 4060 Laptop GPU)
vainfo: Supported profile and entrypoints
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
  1. start Ubuntu after 1 minute, execute the code below, it will be all OK too.
$ ls -l /dev/dri
crw-rw---- 1 root video  226,   0 Mar  5 15:52 card0
crw-rw---- 1 root render 226, 128 Mar  5 15:52 renderD128

$ ls -ln /dev/dri
crw-rw---- 1 0  44 226,   0 Mar  5 15:52 card0
crw-rw---- 1 0 110 226, 128 Mar  5 15:52 renderD128

$ cat /etc/group | grep -E "video|render"
video:x:44:user1
render:x:110:

$ vainfo --display drm
libva info: VA-API version 1.20.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/d3d12_drv_video.so
libva info: Found init function __vaDriverInit_1_20
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.20 (libva 2.12.0)
vainfo: Driver version: Mesa Gallium driver 24.0.1-1ubuntu1 for D3D12 (NVIDIA GeForce RTX 4060 Laptop GPU)
vainfo: Supported profile and entrypoints
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
  1. switch back to Arch and execute the code below, you will found that the group of /dev/dri/card0 had been the to the gid of video from the last started distro, and make the current user does not have the access right to /dev/dri/card0, make vainfo --display drm failed.
$ ls -l /dev/dri
crw-rw---- 1 root   44 226,   0  3月 5日 15:52 card0
crw-rw---- 1 root  110 226, 128  3月 5日 15:52 renderD128

$ vainfo --display drm
Trying display: drm
error: failed to initialize display 'drm'

WSL logs:

No response

WSL dumps:

No response

Expected behavior:

No response

Actual behavior:

As the reproduce

Actually, we can see they are the same files, even in different distros.

Arch$ sudo chgrp video /dev/dri/card0

Arch$ ls -l /dev/dri/
crw-rw---- 1 root video 226,   0 Mar  7 10:46 card0
crw-rw---- 1 root   110 226, 128 Mar  7 10:46 renderD128

Arch$ stat /dev/dri/card0
  File: /dev/dri/card0
  Size: 0               Blocks: 0          IO Block: 4096   character special file
Device: 0,5     Inode: 94          Links: 1     Device type: 226,0
Access: (0660/crw-rw----)  Uid: (    0/    root)   Gid: (  985/   video)
Access: 2024-03-07 10:46:19.750578888 +0800
Modify: 2024-03-07 10:46:19.750578888 +0800
Change: 2024-03-07 10:47:40.876383552 +0800
 Birth: -
Ubuntu$ ls -l /dev/dri/
crw-rw---- 1 root    985 226,   0 Mar  7 10:46 card0
crw-rw---- 1 root render 226, 128 Mar  7 10:46 renderD128

Ubuntu$ stat /dev/dri/card0
  File: /dev/dri/card0
  Size: 0               Blocks: 0          IO Block: 4096   character special file
Device: 0,5     Inode: 94          Links: 1     Device type: 226,0
Access: (0660/crw-rw----)  Uid: (    0/    root)   Gid: (  985/ UNKNOWN)
Access: 2024-03-07 10:46:19.750578888 +0800
Modify: 2024-03-07 10:46:19.750578888 +0800
Change: 2024-03-07 10:47:40.876383552 +0800
 Birth: -

As I know, user distro is a linux namespace under system distro, there is a feature called user_namespaces can be used to mapping groups.
Maybe it as echo '0 1000 1' > /proc/2/gid_map.
https://www.man7.org/linux/man-pages/man7/user_namespaces.7.html

I've updated my existing Ubuntu 22.04 to 24.04 and facing the the issue.