Skip to content

Fix AMD GPU i2c bus PCI ID detection on Linux (sysfs path traversal)#90

Open
AlexJawhari wants to merge 1 commit into
CalcProgrammer1:masterfrom
AlexJawhari:fix/amdgpu-i2c-sysfs-pci-id-detection
Open

Fix AMD GPU i2c bus PCI ID detection on Linux (sysfs path traversal)#90
AlexJawhari wants to merge 1 commit into
CalcProgrammer1:masterfrom
AlexJawhari:fix/amdgpu-i2c-sysfs-pci-id-detection

Conversation

@AlexJawhari
Copy link
Copy Markdown
Contributor

Problem

On newer kernels with the amdgpu driver, all AMDGPU i2c buses fail
to read their PCI device IDs, producing repeated errors like:

[i2c_smbus_linux] Failed to read i2c device PCI device ID

This happens because AMDGPU i2c bus symlinks in /sys/bus/i2c/devices/
resolve to paths inside the PCI device directory, e.g.:

/sys/devices/pci.../0000:03:00.0/i2c-4

The old code appended '/..' to the resolved path and relied on sysfs
path traversal to reach the parent PCI device. This is unreliable on
newer kernels and causes all AMDGPU buses to register with zeroed PCI
IDs (0000:0000), making GPU RGB detection impossible.

Fix

After resolving the symlink with realpath(), truncate the path at the
last '/' to directly obtain the parent PCI device directory. Also
handle DT_UNKNOWN d_type, which some kernels return for sysfs symlink
entries instead of DT_LNK.

Result

Before: all AMDGPU i2c buses show Device 0000:0000 Subsystem: 0000:0000
After:
AMDGPU SMU 0 (/dev/i2c-4) Device 1002:747E Subsystem: 1849:5323
AMDGPU DM i2c hw bus 0 (/dev/i2c-6) Device 1002:747E Subsystem: 1849:5323
AMDGPU DM i2c OEM bus (/dev/i2c-10) Device 1002:747E Subsystem: 1849:5323
(etc.)

Tested on

  • Linux Mint, kernel 6.x
  • ASRock Radeon RX 7700 XT 12GB (PCI ID 1002:747E, subsystem 1849:5323)
  • Related issue: #3649

On newer kernels with the amdgpu driver, i2c bus symlinks in
/sys/bus/i2c/devices/ resolve to paths like:
  /sys/devices/pci.../0000:03:00.0/i2c-4

The previous code appended '/..' and relied on sysfs path traversal
to reach the parent PCI device directory. This is unreliable and
causes 'Failed to read i2c device PCI device ID' errors for all
AMDGPU i2c buses.

Fix: after resolving the symlink with realpath(), truncate at the
last '/' to directly obtain the parent PCI device directory path.
Also handle DT_UNKNOWN d_type which some kernels return for sysfs
symlink entries instead of DT_LNK.

This allows OpenRGB to correctly register AMDGPU i2c buses with
their proper vendor/device/subsystem PCI IDs, which is a prerequisite
for any GPU RGB controller detection on AMD hardware under Linux.

Tested on Linux Mint with ASRock Radeon RX 7700 XT (1002:747E,
subsystem 1849:5323) and kernel 6.x.
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

Successfully merging this pull request may close these issues.

1 participant