Skip to content

Commit d7eff46

Browse files
PhilipYangAalexdeucher
authored andcommitted
drm/amdgpu: fix fdinfo race with process exit
Get process vm root BO ref in case process is exiting and root BO is freed, to avoid NULL pointer dereference backtrace: BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 Call Trace: amdgpu_show_fdinfo+0xfe/0x2a0 [amdgpu] seq_show+0x12c/0x180 seq_read+0x153/0x410 vfs_read+0x91/0x140[ 3427.206183] ksys_read+0x4f/0xb0 do_syscall_64+0x5b/0x1a0 entry_SYSCALL_64_after_hwframe+0x65/0xca Signed-off-by: Philip Yang <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 703677d commit d7eff46

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f)
5959
uint64_t vram_mem = 0, gtt_mem = 0, cpu_mem = 0;
6060
struct drm_file *file = f->private_data;
6161
struct amdgpu_device *adev = drm_to_adev(file->minor->dev);
62+
struct amdgpu_bo *root;
6263
int ret;
6364

6465
ret = amdgpu_file_to_fpriv(f, &fpriv);
@@ -69,13 +70,19 @@ void amdgpu_show_fdinfo(struct seq_file *m, struct file *f)
6970
dev = PCI_SLOT(adev->pdev->devfn);
7071
fn = PCI_FUNC(adev->pdev->devfn);
7172

72-
ret = amdgpu_bo_reserve(fpriv->vm.root.bo, false);
73+
root = amdgpu_bo_ref(fpriv->vm.root.bo);
74+
if (!root)
75+
return;
76+
77+
ret = amdgpu_bo_reserve(root, false);
7378
if (ret) {
7479
DRM_ERROR("Fail to reserve bo\n");
7580
return;
7681
}
7782
amdgpu_vm_get_memory(&fpriv->vm, &vram_mem, &gtt_mem, &cpu_mem);
78-
amdgpu_bo_unreserve(fpriv->vm.root.bo);
83+
amdgpu_bo_unreserve(root);
84+
amdgpu_bo_unref(&root);
85+
7986
seq_printf(m, "pdev:\t%04x:%02x:%02x.%d\npasid:\t%u\n", domain, bus,
8087
dev, fn, fpriv->vm.pasid);
8188
seq_printf(m, "vram mem:\t%llu kB\n", vram_mem/1024UL);

0 commit comments

Comments
 (0)