Unbounded loop in nv_find_pci_capability() hangs a CPU for hours when reading /proc/driver/nvidia/gpus/<bus>/information
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c, linux
調査の方向性
まず kernel-open/nvidia/nv-pci.c の nv_find_pci_capability() と、nv_procfs_read_gpu_info() からの呼び出しを読みます。ループをカーネルの上限付き pci_find_capability() と比較するか、pci_is_pcie(pci_dev) を procfs の呼び出し元で使用できるか確認します。完了条件は、capability リストの走査が無限ループにならず、PCIe と PCI の判定結果が正しいことです。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C
- スター
- 17.5k
- フォーク
- 1.9k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/open-gpu-kernel-modules のほかの issue
-
PlatformRequestHandler: missing !bInit guard on bSystemParamLimitUpdate causes NV_ERR_INVALID_DATA at boot対応中かも @SammyTourani が 29 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
NVIDIA/open-gpu-kernel-modules#1360 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NVIDIA/open-gpu-kernel-modules#1343 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
HKC G27H7Pro redundant long-HPD loop after DisplayPort link training (RTX 5060 Laptop, 610.57.04)オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NVIDIA/open-gpu-kernel-modules#1323 ·
メンテナーはふだん 1 日以内に返信
-
build-problem
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
NVIDIA/open-gpu-kernel-modules#1155 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
build-problem
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
NVIDIA/open-gpu-kernel-modules#1154 · コメント 10 件 ·
メンテナーはふだん 1 日以内に返信
NVIDIA/open-gpu-kernel-modules の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
priority:medium type:chore
難易度 1/5 1〜3時間 初心者へのやさしさ 84/100
crazy-goat/php-fpm-ng#1041 ·
メンテナーはふだん 1 日以内に返信
-
Bug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Test failure on FreeBSD: #26 unexpected system_clock source対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンlow priority rt_lib tests
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信