Skip to content

uvm: fix NULL pointer dereference in uvm_hmm_unregister_gpu#1110

Open
JCorners68 wants to merge 1 commit intoNVIDIA:mainfrom
JCorners68:fix/uvm-hmm-null-devmem-check
Open

uvm: fix NULL pointer dereference in uvm_hmm_unregister_gpu#1110
JCorners68 wants to merge 1 commit intoNVIDIA:mainfrom
JCorners68:fix/uvm-hmm-null-devmem-check

Conversation

@JCorners68
Copy link
Copy Markdown

Summary

Fixes #1082 — kernel NULL pointer dereference in uvm_hmm_unregister_gpu() during CUDA process exit.

gpu->parent->devmem is dereferenced unconditionally, but it is only initialized when uvm_pmm_devmem_init() succeeds during init_parent_gpu(). When it is NULL, the dereference crashes the kernel:

BUG: kernel NULL pointer dereference, address: 00000000000000a8
RIP: uvm_hmm_unregister_gpu+0x51/0x3a0 [nvidia_uvm]

The existing uvm_hmm_is_enabled(va_space) guard only checks the VA space — it does not guarantee the specific GPU has device-private memory initialized.

Fix

  • Guard the devmem dereference and page-eviction loop with if (gpu->parent->devmem).
  • When devmem is NULL there are no device-private pages to evict, so skip straight to HMM block unregistration.
  • Move lock assertions above the devmem access so they fire before the NULL dereference (secondary bug: in the original code, the assertions were placed after the crash site and could never trigger).

Reproduction

Observed repeatedly on two different systems:

Triggered by any CUDA process exit (training jobs, nvtop, tokio async runtime, fossilize shader compilation). The kernel oops corrupts driver state and cascades to Xid 79 ("GPU has fallen off the bus") within minutes to hours, requiring a full node reboot.

Testing

  • Confirmed options nvidia_uvm uvm_disable_hmm=1 (which skips this code path entirely) eliminates the crash, validating that the fault is in this function.
  • The NULL guard is the minimal targeted fix for the same code path.

Guard gpu->parent->devmem dereference with a NULL check.

devmem is only initialized when uvm_pmm_devmem_init() succeeds during
init_parent_gpu(). When it is NULL — because init failed or was never
called for this GPU — the unconditional dereference at the top of
uvm_hmm_unregister_gpu() causes a kernel NULL pointer dereference
(Xid 79, "GPU has fallen off the bus") during CUDA process exit:

  BUG: kernel NULL pointer dereference, address: 00000000000000a8
  RIP: uvm_hmm_unregister_gpu+0x51/0x3a0 [nvidia_uvm]
  Call Trace:
   unregister_gpu+0xc4/0x5b0 [nvidia_uvm]
   uvm_va_space_destroy+0x22e/0x770 [nvidia_uvm]
   uvm_release+0x7a/0x180 [nvidia_uvm]
   __fput+0xea/0x2d0
   do_exit+0x1fa/0x480

The existing uvm_hmm_is_enabled(va_space) check only validates that
HMM is enabled for the VA space — it does not guarantee that the
specific GPU has device-private memory initialized.

When devmem is NULL there are no device-private pages to evict, so
skip the eviction loop and proceed directly to block unregistration.

Also move the lock assertions above the devmem access so they can
actually fire before the NULL dereference.

Fixes: NVIDIA#1082
Tested: confirmed workaround (uvm_disable_hmm=1) resolves the crash;
        this patch is the proper fix for the same code path.

Signed-off-by: Jonathan Corners <[email protected]>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


jcorners68 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

NULL pointer dereference in uvm_hmm_unregister_gpu during CUDA UVM VA space teardown on process exit

2 participants