Unbounded loop in nv_find_pci_capability() hangs a CPU for hours when reading /proc/driver/nvidia/gpus/<bus>/information
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- c, linux
- Ambito
- backend, operating-systems
Direzione di ricerca
Inizia leggendo nv_find_pci_capability() in kernel-open/nvidia/nv-pci.c e la sua chiamata da nv_procfs_read_gpu_info(). Confronta il ciclo con pci_find_capability() del kernel, che è limitato, oppure verifica se pci_is_pcie(pci_dev) può essere usato dal chiamante procfs. Il lavoro è completato quando l'attraversamento dell'elenco delle capability non può entrare in un ciclo indefinito e il risultato PCIe rispetto a PCI rimane corretto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
NVIDIA Open GPU Kernel Modules Version
610.43.02 (the loop is unchanged on current main / 615.78.08)
Operating System and Version
Ubuntu 24.04.4 LTS
Kernel Release
6.17.0-35-generic
Hardware: GPU
8x NVIDIA RTX A6000 (PCIe Gen3 x16)
Describe the bug
A single read() of /proc/driver/nvidia/gpus/0000:08:00.0/information never returned. The reading thread spun in kernel mode inside nv_find_pci_capability() for more than 15 hours, pinning one CPU. The kernel logged a soft lockup every 28 seconds (more than 200 reports), and the stuck thread could not be killed.
The loop that walks the PCI capability list has no iteration limit (kernel-open/nvidia/nv-pci.c):
do {
cap_ptr &= 0xfc;
pci_read_config_byte(pci_dev, cap_ptr + PCI_CAP_LIST_ID, &cap_id);
if (cap_id == capability)
return cap_ptr;
pci_read_config_byte(pci_dev, cap_ptr + PCI_CAP_LIST_NEXT, &cap_ptr);
} while (cap_ptr && cap_id != 0xff);
It stops only at a NULL next pointer or a capability ID of 0xff. If the walk ever sees a chain that forms a cycle, it spins forever without yielding. A device that has dropped off the bus (all reads 0xff) does terminate, but a cycle does not. The kernel's own pci_find_capability() guards against exactly this by capping the walk at PCI_FIND_CAP_TTL (48) steps.
Here the GPU was healthy and under load: 98% utilization, no Xid, no AER, no ECC errors. The same file was read successfully hundreds of times afterwards by the same program on the same machine. So the cycle was not permanent in config space. Most likely one walk saw a transient bad config read and then never recovered. Whatever caused that read, a procfs read should never be able to hang a CPU indefinitely.
Secondary impact: while that CPU was pinned in kernel mode, fsnotify_mark_destroy_workfn / fsnotify_connector_destroy_workfn kworkers sat in synchronize_srcu indefinitely. Every process that closed an inotify fd then hung in D state (inotify_release → fsnotify_wait_marks_destroyed → __flush_work). That included container runtime shims and new login sessions (systemd --user), so containers could not exit, their filesystems stayed mounted, and SSH logins hung. The only recovery is a reboot.
To Reproduce
We have not found a deterministic reproducer. The trigger was a routine read of /proc/driver/nvidia/gpus/*/information, which our daemon does for each GPU on every workload start: hundreds of reads per hour per machine, across about 30 machines for months. This is the first occurrence we have seen.
The unbounded loop itself is visible by inspection. One way to exercise it is to make the capability list cyclic in a VM or with a PCI config-space injection tool, then read the procfs file.
Bug Incidence
Once
nvidia-bug-report.log.gz
Not available: the machine cannot complete new login sessions in this state. We can attach lspci -vvv / lspci -xxx for 0000:08:00.0 if useful.
More Info
Soft lockup report (repeats every ~28 s on the same CPU and task):
watchdog: BUG: soft lockup - CPU#5 stuck for 53354s! [<daemon>:1233559]
RIP: 0010:_raw_spin_unlock_irqrestore+0x21/0x60
Call Trace:
<TASK>
pci_conf1_read+0xb0/0x100
pci_read+0x55/0x90
pci_bus_read_config_byte+0x3f/0x80
pci_read_config_byte+0x27/0x50
nv_find_pci_capability+0x9a/0xe0 [nvidia]
nv_procfs_read_gpu_info+0xb7/0x2e0 [nvidia]
seq_read_iter+0x134/0x4c0
seq_read+0x11d/0x160
nv_procfs_read_lock_gpu_info+0x80/0xb0 [nvidia]
proc_reg_read+0x69/0xa0
vfs_read+0xba/0x390
ksys_read+0x71/0xf0
__x64_sys_read+0x19/0x30
do_syscall_64+0x80/0xa20
entry_SYSCALL_64_after_hwframe+0x76/0x7e
The stuck thread's open fd was /proc/driver/nvidia/gpus/0000:08:00.0/information, and its accumulated CPU time matched continuous running since the read began.
Downstream D-state stacks:
# kworker
__synchronize_srcu+0x90/0xd0
synchronize_srcu+0x107/0x130
fsnotify_mark_destroy_workfn+0x8b/0x120
process_one_work+0x191/0x3e0
# any exiting process holding an inotify fd
__flush_work+0x85/0xe0
flush_delayed_work+0x35/0x60
fsnotify_wait_marks_destroyed+0x15/0x20
fsnotify_destroy_group+0x57/0x120
inotify_release+0x18/0x70
__fput+0xed/0x2d0
task_work_run+0x60/0xa0
do_exit+0x1fa/0x480
Suggested fix: in nv_find_pci_capability(), use the kernel's pci_find_capability() (bounded by PCI_FIND_CAP_TTL), or add an equivalent iteration cap. In nv_procfs_read_gpu_info(), the only use is to choose "PCIe" vs "PCI"; pci_is_pcie(pci_dev) answers that from cached state without touching config space at all.
- Lingua principale
- C
- Stelle
- 17.5k
- Fork
- 1.9k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/open-gpu-kernel-modules
-
PlatformRequestHandler: missing !bInit guard on bSystemParamLimitUpdate causes NV_ERR_INVALID_DATA at bootForse già presa @SammyTourani l’ha presa 27 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
NVIDIA/open-gpu-kernel-modules#1360 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
NVIDIA/open-gpu-kernel-modules#1343 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
HKC G27H7Pro redundant long-HPD loop after DisplayPort link training (RTX 5060 Laptop, 610.57.04)Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NVIDIA/open-gpu-kernel-modules#1323 ·
I maintainer di solito rispondono entro 1 giorno
-
build-problem
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
NVIDIA/open-gpu-kernel-modules#1155 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
build-problem
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
NVIDIA/open-gpu-kernel-modules#1154 · 10 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di NVIDIA/open-gpu-kernel-modules
Issue simili
-
dspromote: /etc/exports uses -alldirs on non-mount-point directories, so mountd exports nothingApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
nextbsd/nextbsd-userland#434 ·
I maintainer di solito rispondono entro 1 giorno
-
[YSQL] Local-node initdb reads postgres.bki, but YB clusters bootstrap only from yb_postgres.bkiApertaarea/ysql kind/enhancement priority/low status/awaiting-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
yugabyte/yugabyte-db#35763 ·
I maintainer di solito rispondono entro 1 giorno
-
[mimalloc] update to 3.6.0Apertacategory:port-update
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 2 giorni
-
emerge failure MARK mark-unstable media-kit
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
macaroni-os/mark-issues#834 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100