Compare
3c516a5646285442e1cd71dff2584b77eb4fc421..32d0771ef4ca69c30a1db3aefa34dd177cd2a047
drm/amdgpu/userq: actually validate userq BOs
This was supposed to loop over the individual evicted list, as the
kernel and always_valid evicted lists were already handled in
amdgpu_vm_validate.
Without this, BOs that were created and evicted before a userq was made
would never end up in an eviction fence rearm.
Also add the missing ref to the BO before drm_exec locks and refs it.
Fixes: 4cdbba5a16aa ("drm/amdgpu: restructure VM state machine v4")
Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 18decfc9e8cc0fa70b6de9944cc27a37729edfbd)
Cc: stable@vger.kernel.org
Benjamin Cheng <benjamin.cheng@amd.com> · 2026-10-09 13:31 UTC · committed by Alex Deucher
4 files changed,
+21
−27
- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
modified drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
| @@ -1431,6 +1431,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser) | |||
| 1431 | 1431 | int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) | |
| 1432 | 1432 | { | |
| 1433 | 1433 | struct amdgpu_device *adev = drm_to_adev(dev); | |
| 1434 | + | struct amdgpu_bo_list_entry *e; | |
| 1434 | 1435 | struct amdgpu_cs_parser parser; | |
| 1435 | 1436 | int r; | |
| 1436 | 1437 | ||
| @@ -1465,25 +1466,31 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) | |||
| 1465 | 1466 | ||
| 1466 | 1467 | r = amdgpu_cs_patch_jobs(&parser); | |
| 1467 | 1468 | if (r) | |
| 1468 | - | goto error_fini; | |
| 1469 | + | goto error_free_user_pages; | |
| 1469 | 1470 | ||
| 1470 | 1471 | r = amdgpu_cs_vm_handling(&parser); | |
| 1471 | 1472 | if (r) | |
| 1472 | - | goto error_fini; | |
| 1473 | + | goto error_free_user_pages; | |
| 1473 | 1474 | ||
| 1474 | 1475 | r = amdgpu_cs_sync_rings(&parser); | |
| 1475 | 1476 | if (r) | |
| 1476 | - | goto error_fini; | |
| 1477 | + | goto error_free_user_pages; | |
| 1477 | 1478 | ||
| 1478 | 1479 | trace_amdgpu_cs_ibs(&parser); | |
| 1479 | 1480 | ||
| 1480 | 1481 | r = amdgpu_cs_submit(&parser, data); | |
| 1481 | 1482 | if (r) | |
| 1482 | - | goto error_fini; | |
| 1483 | + | goto error_free_user_pages; | |
| 1483 | 1484 | ||
| 1484 | 1485 | amdgpu_cs_parser_fini(&parser); | |
| 1485 | 1486 | return 0; | |
| 1486 | 1487 | ||
| 1488 | + | error_free_user_pages: | |
| 1489 | + | /* amdgpu_cs_submit() only drops the ranges once it got that far. */ | |
| 1490 | + | amdgpu_bo_list_for_each_userptr_entry(e, parser.bo_list) { | |
| 1491 | + | amdgpu_hmm_range_free(e->range); | |
| 1492 | + | e->range = NULL; | |
| 1493 | + | } | |
| 1487 | 1494 | error_fini: | |
| 1488 | 1495 | amdgpu_cs_parser_fini(&parser); | |
| 1489 | 1496 | return r; | |
modified drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
| @@ -1266,7 +1266,6 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf, | |||
| 1266 | 1266 | { | |
| 1267 | 1267 | struct amdgpu_device *adev = f->f_inode->i_private; | |
| 1268 | 1268 | int r; | |
| 1269 | - | ssize_t result = 0; | |
| 1270 | 1269 | uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data; | |
| 1271 | 1270 | ||
| 1272 | 1271 | if (size > 4096 || size & 3 || *pos & 3) | |
| @@ -1310,25 +1309,11 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf, | |||
| 1310 | 1309 | mutex_unlock(&adev->grbm_idx_mutex); | |
| 1311 | 1310 | ||
| 1312 | 1311 | pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); | |
| 1312 | + | amdgpu_virt_disable_access_debugfs(adev); | |
| 1313 | 1313 | ||
| 1314 | - | while (size) { | |
| 1315 | - | uint32_t value; | |
| 1316 | - | ||
| 1317 | - | value = data[result >> 2]; | |
| 1318 | - | r = put_user(value, (uint32_t *)buf); | |
| 1319 | - | if (r) { | |
| 1320 | - | amdgpu_virt_disable_access_debugfs(adev); | |
| 1321 | - | goto err; | |
| 1322 | - | } | |
| 1323 | - | ||
| 1324 | - | result += 4; | |
| 1325 | - | buf += 4; | |
| 1326 | - | size -= 4; | |
| 1327 | - | } | |
| 1328 | - | ||
| 1314 | + | r = copy_to_user(buf, data, size) ? -EFAULT : size; | |
| 1329 | 1315 | kfree(data); | |
| 1330 | - | amdgpu_virt_disable_access_debugfs(adev); | |
| 1331 | - | return result; | |
| 1316 | + | return r; | |
| 1332 | 1317 | ||
| 1333 | 1318 | err: | |
| 1334 | 1319 | pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); | |
modified drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
| @@ -1238,7 +1238,7 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data, | |||
| 1238 | 1238 | bo_entry->alloc_flags = bo->flags & AMDGPU_GEM_CREATE_SETTABLE_MASK; | |
| 1239 | 1239 | bo_entry->preferred_domains = bo->preferred_domains; | |
| 1240 | 1240 | bo_entry->gem_handle = id; | |
| 1241 | - | bo_entry->alignment = bo->tbo.page_alignment; | |
| 1241 | + | bo_entry->alignment = (u64)bo->tbo.page_alignment << PAGE_SHIFT; | |
| 1242 | 1242 | ||
| 1243 | 1243 | if (bo->tbo.base.import_attach) | |
| 1244 | 1244 | bo_entry->flags |= AMDGPU_GEM_LIST_HANDLES_FLAG_IS_IMPORT; | |
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
| @@ -980,19 +980,21 @@ amdgpu_userq_bo_validate(struct amdgpu_device *adev, struct drm_exec *exec, | |||
| 980 | 980 | { | |
| 981 | 981 | struct ttm_operation_ctx ctx = { false, false }; | |
| 982 | 982 | struct amdgpu_bo_va *bo_va; | |
| 983 | - | struct amdgpu_bo *bo; | |
| 983 | + | struct amdgpu_bo *bo, *tmp; | |
| 984 | 984 | int ret; | |
| 985 | 985 | ||
| 986 | 986 | spin_lock(&vm->individual_lock); | |
| 987 | - | while (!list_empty(&vm->always_valid.evicted)) { | |
| 988 | - | bo_va = list_first_entry(&vm->always_valid.evicted, | |
| 987 | + | while (!list_empty(&vm->individual.evicted)) { | |
| 988 | + | bo_va = list_first_entry(&vm->individual.evicted, | |
| 989 | 989 | struct amdgpu_bo_va, | |
| 990 | 990 | base.vm_status); | |
| 991 | + | bo = bo_va->base.bo; | |
| 992 | + | tmp = amdgpu_bo_ref(bo); | |
| 991 | 993 | spin_unlock(&vm->individual_lock); | |
| 992 | 994 | ||
| 993 | - | bo = bo_va->base.bo; | |
| 994 | 995 | ret = drm_exec_prepare_obj(exec, &bo->tbo.base, | |
| 995 | 996 | TTM_NUM_MOVE_FENCES + 1); | |
| 997 | + | amdgpu_bo_unref(&tmp); | |
| 996 | 998 | if (unlikely(ret)) | |
| 997 | 999 | return ret; | |
| 998 | 1000 | ||