Unbounded loop in nv_find_pci_capability() hangs a CPU for hours when reading /proc/driver/nvidia/gpus/<bus>/information
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- c, linux
- Lĩnh vực
- backend, operating-systems
Hướng nghiên cứu
Bắt đầu bằng cách đọc nv_find_pci_capability() trong kernel-open/nvidia/nv-pci.c và lời gọi hàm này từ nv_procfs_read_gpu_info(). So sánh vòng lặp với pci_find_capability() có giới hạn của kernel, hoặc kiểm tra xem pci_is_pcie(pci_dev) có thể được dùng cho bên gọi procfs hay không. Công việc hoàn tất khi việc duyệt danh sách capability không thể lặp vô hạn và kết quả phân biệt PCIe với PCI vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C
- Star
- 17.5k
- Fork
- 1.9k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/open-gpu-kernel-modules
-
PlatformRequestHandler: missing !bInit guard on bSystemParamLimitUpdate causes NV_ERR_INVALID_DATA at bootCó thể đã có người làm @SammyTourani đã nhận 29 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
NVIDIA/open-gpu-kernel-modules#1360 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NVIDIA/open-gpu-kernel-modules#1343 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
HKC G27H7Pro redundant long-HPD loop after DisplayPort link training (RTX 5060 Laptop, 610.57.04)Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NVIDIA/open-gpu-kernel-modules#1323 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
build-problem
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
NVIDIA/open-gpu-kernel-modules#1155 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
build-problem
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
NVIDIA/open-gpu-kernel-modules#1154 · 10 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của NVIDIA/open-gpu-kernel-modules
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
AOMediaCodec/SVT-AV1#3320 ·
-
Add `CPC_TAKE_TILL_CHARS`Đang mởdifficulty: easy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
ML-KEM: OQS_KEM_encaps/decaps cannot do the FIPS 203 length (type) checks; please document itĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
open-quantum-safe/liboqs#2647 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Broken links in the docsĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày