Skip to content

Commit 7bc597c

Browse files
hghimiraThomas Hellström
authored andcommitted
drm/xe/vm: Fix BO prefetch with CONSULT_MEM_ADVISE_PREF_LOC
When prefetch region is DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC for a BO VMA, the code used it as an index into region_to_mem_type[], causing an out-of-bounds access since the value is -1. Resolve the preferred location for BO VMAs directly: local VRAM on dGFX (using the BO's tile placement) or system memory on iGPU. Discovered using AI-assisted static analysis confirmed by Intel Product Security. v2: -Fix null dereference Reported-by: Martin Hodo <martin.hodo@intel.com> Fixes: c1bb69a ("drm/xe/svm: Consult madvise preferred location in prefetch") Cc: Matthew Brost <matthew.brost@intel.com> Cc: stable@vger.kernel.org Reviewed-by: Matthew Brost <matthew.brost@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20260624174943.2808767-2-himal.prasad.ghimiray@intel.com Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com> (cherry picked from commit d9a4906) Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
1 parent a13c140 commit 7bc597c

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,11 +3255,26 @@ static int op_lock_and_prep(struct drm_exec *exec, struct xe_vm *vm,
32553255
.request_decompress = false,
32563256
.check_purged = true,
32573257
});
3258-
if (!err && !xe_vma_has_no_bo(vma))
3259-
err = xe_bo_migrate(xe_vma_bo(vma),
3260-
region_to_mem_type[region],
3261-
NULL,
3262-
exec);
3258+
if (!err && !xe_vma_has_no_bo(vma)) {
3259+
struct xe_bo *bo = xe_vma_bo(vma);
3260+
u32 mem_type;
3261+
3262+
if (region == DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC) {
3263+
unsigned int i;
3264+
3265+
mem_type = XE_PL_TT;
3266+
for (i = 0; i < bo->placement.num_placement; i++) {
3267+
if (mem_type_is_vram(bo->placements[i].mem_type)) {
3268+
mem_type = bo->placements[i].mem_type;
3269+
break;
3270+
}
3271+
}
3272+
} else {
3273+
mem_type = region_to_mem_type[region];
3274+
}
3275+
3276+
err = xe_bo_migrate(bo, mem_type, NULL, exec);
3277+
}
32633278
break;
32643279
}
32653280
default:

0 commit comments

Comments
 (0)