Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lenovo Legion 15ach6h : amdgpuBusId seems incorrect #1388

Open
Malix-Labs opened this issue Feb 23, 2025 · 11 comments
Open

Lenovo Legion 15ach6h : amdgpuBusId seems incorrect #1388

Malix-Labs opened this issue Feb 23, 2025 · 11 comments

Comments

@Malix-Labs
Copy link

Malix-Labs commented Feb 23, 2025

On my machine (a factory-modified-issued Lenovo Legion 15ach6h), the amdgpuBusId seems to be PCI:5:0:0 instead of PCI:6:0:0

Subject

https://github.com/NixOS/nixos-hardware/tree/master/lenovo/legion/15ach6h#setup-at-the-time-of-testing

amdgpuBusId = lib.mkDefault "PCI:6:0:0";

Log

fastfetch

[nix-shell:~]$ fastfetch
          ▗▄▄▄       ▗▄▄▄▄    ▄▄▄▖             malix@nixos
          ▜███▙       ▜███▙  ▟███▛             -----------
           ▜███▙       ▜███▙▟███▛              OS: NixOS 24.11 (Vicuna) x86_64
            ▜███▙       ▜██████▛               Host: 82JU (LEGION 5 15ACH6H)
     ▟█████████████████▙ ▜████▛     ▟▙         Kernel: Linux 6.13.2
    ▟███████████████████▙ ▜███▙    ▟██▙        Uptime: 8 mins
           ▄▄▄▄▖           ▜███▙  ▟███▛        Packages: 1094 (nix-system)
          ▟███▛             ▜██▛ ▟███▛         Shell: bash 5.2.37
         ▟███▛               ▜▛ ▟███▛          Display (AUO5895): 1920x1080 @ 165 Hz in 15" [Built-in] *
▟███████████▛                  ▟██████████▙    Display (ASUSTek COMPUTER INC 27"): 2560x1440 @ 120 Hz in 27" [External]
▜██████████▛                  ▟███████████▛    DE: GNOME 47.2
      ▟███▛ ▟▙               ▟███▛             WM: Mutter (Wayland)
     ▟███▛ ▟██▙             ▟███▛              WM Theme: Adwaita
    ▟███▛  ▜███▙           ▝▀▀▀▀               Theme: Adwaita [GTK2/3/4]
    ▜██▛    ▜███▙ ▜██████████████████▛         Icons: Adwaita [GTK2/3/4]
     ▜▛     ▟████▙ ▜████████████████▛          Font: Cantarell (11pt) [GTK2/3/4]
           ▟██████▙       ▜███▙                Cursor: Adwaita (24px)
          ▟███▛▜███▙       ▜███▙               Terminal: GNOME Console 47.1
         ▟███▛  ▜███▙       ▜███▙              Terminal Font: Source Code Pro (10pt)
         ▝▀▀▀    ▀▀▀▀▘       ▀▀▀▘              CPU: AMD Ryzen 7 5800H (16) @ 4.46 GHz
                                               GPU 1: NVIDIA GeForce RTX 3060 Mobile / Max-Q [Discrete]
                                               GPU 2: AMD Radeon Vega Series / Radeon Vega Mobile Series [Integrated]
                                               Memory: 2.07 GiB / 13.51 GiB (15%)
                                               Swap: 0 B / 14.86 GiB (0%)
                                               Disk (/): 12.97 GiB / 922.70 GiB (1%) - ext4
                                               Local IP (eno1): 192.168.1.50/24
                                               Battery (L20D4PC1): 100% [AC Connected]
                                               Locale: en_US.UTF-8

                                                                       
                                                                       

lspci

[nix-shell:~]$ lspci
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne Root Complex
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne IOMMU
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:01.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge
00:01.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:02.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:02.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:08.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:08.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus
00:08.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus
00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller (rev 51)
00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge (rev 51)
00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 0
00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 1
00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 2
00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 3
00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 4
00:18.5 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 5
00:18.6 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 6
00:18.7 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 7
01:00.0 VGA compatible controller: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GA106 High Definition Audio Controller (rev a1)
02:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet Controller (rev 15)
04:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8852AE 802.11ax PCIe Wireless Network Adapter
05:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne [Radeon Vega Series / Radeon Vega Mobile Series] (rev c5)
05:00.2 Encryption controller: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) Platform Security Processor
05:00.3 USB controller: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1
05:00.4 USB controller: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1
05:00.5 Multimedia controller: Advanced Micro Devices, Inc. [AMD] ACP/ACP3X/ACP6x Audio Coprocessor (rev 01)
05:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Family 17h/19h/1ah HD Audio Controller
06:00.0 SATA controller: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] (rev 81)
06:00.1 SATA controller: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] (rev 81)

nix-info -m

[nix-shell:~]$ nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 6.13.2, NixOS, 24.11 (Vicuna), 24.11.714433.0ff09db9d034`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.12`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@Malix-Labs
Copy link
Author

@Lyndeno @yuannan

@Lyndeno
Copy link
Contributor

Lyndeno commented Feb 23, 2025

I don't have this model to test. Has anyone else seen identical models with different IDs?

@Mic92
Copy link
Member

Mic92 commented Feb 24, 2025

Sometimes Lenovo has different versions of the same model depending on the location you buy it.
We noticed it with X1 laptops bought in Europe vs UAE.

@Mic92
Copy link
Member

Mic92 commented Feb 24, 2025

Is there a way to accustom for both pcie ids?

@Malix-Labs
Copy link
Author

Would there be a way to detect the PCI ports dynamically?

@yuannan
Copy link
Contributor

yuannan commented Mar 6, 2025

Hello, sorry for the late reply. I've been pretty busy with work and some personal stuff.

On my machine 6:00.0 is the right ID. Here is the full ID if you want to look at it.

> doas lspci

00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne Root Complex
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne IOMMU
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:01.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe GPP Bridge
00:01.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:02.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:02.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:02.4 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:08.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:08.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus
00:08.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus
00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller (rev 51)
00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge (rev 51)
00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 0
00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 1
00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 2
00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 3
00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 4
00:18.5 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 5
00:18.6 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 6
00:18.7 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 7
01:00.0 VGA compatible controller: NVIDIA Corporation GA106M [GeForce RTX 3060 Mobile / Max-Q] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GA106 High Definition Audio Controller (rev a1)
02:00.0 Non-Volatile memory controller: Phison Electronics Corporation E12 NVMe Controller (rev 01)
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet Controller (rev 15)
04:00.0 Network controller: Intel Corporation Wi-Fi 6 AX200 (rev 1a)
05:00.0 Non-Volatile memory controller: Sandisk Corp WD Black SN850X NVMe SSD (rev 01)
06:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne [Radeon Vega Series / Radeon Vega Mobile Series] (rev c5)
06:00.2 Encryption controller: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) Platform Security Processor
06:00.3 USB controller: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1
06:00.4 USB controller: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1
06:00.5 Multimedia controller: Advanced Micro Devices, Inc. [AMD] ACP/ACP3X/ACP6x Audio Coprocessor (rev 01)
06:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Family 17h/19h/1ah HD Audio Controller
07:00.0 SATA controller: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] (rev 81)
07:00.1 SATA controller: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] (rev 81)                                                                                 

I'm pretty busy with work for the next few weeks, but I cannot see why we couldn't do this dynamically, not just for this, but the entire repo via a "compile time" script. I think if we were to do this, a simple pattern match should work. The prefix seems to be always VGA, followed by the name of the GPU. If this is different on different kernels and systems is not information that I know currently. If you create a new ticket/issue for tracking lspci outputs, with the goal to generalise this ID matching for all systems supported in this repo, I would be happy to contribute to a PR once I've got the time to do so.

This can be merged into the higher level nvidia and amd files, with lower level dedicated nix files such as this for specific machines as overwrites. This should be fairly trivial with default values that nix supports.

Personally, I've just switched to just using the Nvidia GPU only as I've had loads of random crashes and during gaming and general usage trying to use both GPUs. The only real advantage that I saw from using both is potentially lower power usage, as well as VRAM usage. But overall, I've found using just the Nvidia GPU is the best for stability and performance. If that is something that you could do, it's the best way to use this laptop for me. I've found that I'm rarely requiring the lower power usage of shutting down the Nvidia GPU. It's a gaming laptop so I'm pretty much always plugged in.

@Mic92
Copy link
Member

Mic92 commented Mar 7, 2025

If we can do this more dynamically, this should be preferred over our current approach.

@yuannan
Copy link
Contributor

yuannan commented Mar 7, 2025

I've written a script to get the string for the GPUs as per the specs: https://search.nixos.org/options?channel=unstable&query=busid and NixOS/nixpkgs#365241

#!/usr/bin/env bash

lspci_output="$(lspci)"

amdID=$(echo "$lspci_output" | grep VGA | grep -i AMD | grep -o '^[0-9]*:[0-9]*.[0-9]*')
nvidiaID=$(echo "$lspci_output" | grep VGA | grep -i nvidia | grep -o '^[0-9]*:[0-9]*.[0-9]*')

amdChunks=("$(echo $amdID | grep -o '[0-9 a-f A-F]*')")
nvidiaChunks=("$(echo $nvidiaID | grep -o '[0-9 a-f A-F]*')")

AMDSTR='PCI'
for c in $amdChunks; do
    AMDSTR+=":$((16#$c))"
done
echo $AMDSTR

NVIDIASTR='PCI'
for c in $nvidiaChunks; do
    #echo "hex:$c dec: $((16#$c))"
    NVIDIASTR+=":$((16#$c))"
done
echo $NVIDIASTR

Please test this on your machines and let me know if there are any bugs or changes that need to be done.

I've tried to simply use the outputs of this as a string, but I've not had any luck. The closest I've gotten was with this: https://discourse.nixos.org/t/how-to-create-a-timestamp-in-a-nix-expression/30329/3

To include this as a string will require break chars and a bunch of conversions in order to import it directly as a string. I'm not sure what the cleanest way to do this is, but I hope this has helped in the meantime.

Here is also a generic version that takes the first var as the name of the GPU vendor, and then searches it.

get_ID.sh

#!/usr/bin/env bash

help() {
    echo "GPU vendor required!"
    echo "Usage:   $0 GPU_VENDOR_NAME_HERE"
    echo "Example: $0 nvidia"
}

if [ $# != 1 ]; then
    help
    exit
fi

lspci_output="$(lspci)"

gpuID=$(echo "$lspci_output" | grep VGA | grep -i $1 | grep -o '^[0-9]*:[0-9]*.[0-9]*')

if [ -z "$gpuID" ]; then
    echo "NO GPU DETECTED"
    exit
fi

gpuChunks=("$(echo $gpuID | grep -o '[0-9 a-f A-F]*')")

PCISTR='PCI'
for c in $gpuChunks; do
    PCISTR+=":$((16#$c))"
done
echo $PCISTR

@yuannan
Copy link
Contributor

yuannan commented Mar 8, 2025

Also, as per the README.md (https://github.com/NixOS/nixos-hardware/tree/master/lenovo/legion/15ach6h#using-multiple-drives-with-this-configuration) this is due to having more than 1 drive.

Should we change the default ID to assume users only have 1 drive instead of 2? I don't really know the statistics, but I personally dual boot with Windows, and even if I didn't, I'd probably have 2 drives anyway.

@yuannan
Copy link
Contributor

yuannan commented Mar 10, 2025

There are some docs here that could facilitate this (https://nix.dev/manual/nix/2.26/language/import-from-derivation).

@Mic92 You seem to be one of the largest maintainers here, what are your thoughts on doing something like this? In my honest opinion this could cause more problems then it solves. This is really a vendor (nvidia) issue. I don't think it's user friendly to inspect the IDs manually and set it. In an ideal world the nvidia driver would be able to see that it has the right GPUs and set all of this info at the driver level instead.

However, I don't think the current approach is very user friendly.

The right approach to be to do this at runtime instead of trying to set all of this statically, that includes detecting the PCI ports using a script as this will at the very minium require the user to rebuild their system to get the right config.

imo, this is either a can't fix/won't fix as it goes against the very philosophy of nix.

In the meantime, this is still an issue, any hack we put in is just that, a hack. I think we need to open this discussion up to the greater nix community before any meaningful work can be done. In lieu of this, should we make a new ticket and move the discussion there? I don't want to clutter up this ticket any more.

@Mic92
Copy link
Member

Mic92 commented Mar 10, 2025

Mhm. If you try to use import-from-derivation here, I don't think this is feasible for two reasons:

  1. I don't think nix currently allows nix builds to access hardware device nodes in it's sandbox
  2. If it was possible to access this information, It would break if someone uses remote building on a different machine.

The configuration that uses this information seems to be passed directly to the xorg server via commandline flag. I haven't seen a way to add dynamic configuration to that file.
So maybe it's not so trivial to make this information more dynamic.
So should we just stick to the more common configuration and than document that people might have to change this value, if they have a different driver configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants