drm/xe: Fix bounds checking in __xe_bo_placement_for_flags()
authorBrian Welty <brian.welty@intel.com>
Thu, 11 Jan 2024 00:21:11 +0000 (16:21 -0800)
committerMatthew Brost <matthew.brost@intel.com>
Fri, 12 Jan 2024 17:36:37 +0000 (09:36 -0800)
commit52e3fa3e3ea3ee05e32c1a8d72bb3ae306a4da64
treee571807fb0babf0a28b216980931ed165227b61b
parentca630876aa98c5118ada07604ed8688ee707ddfa
drm/xe: Fix bounds checking in __xe_bo_placement_for_flags()

Requesting all memory regions on PVC will fill bo->placements up to
XE_BO_MAX_PLACEMENTS. The subsequent call to try_add_stolen() will trip
over the bounds checking even though XE_PL_STOLEN is not expected to
be used in this case.

This is hit with igt@xe_exec_fault_mode@once-basic-prefetch:
    xe 0000:8c:00.0: [drm] Assertion `*c < (sizeof(bo->placements) / sizeof((bo->placements)[0]) + ((int)(sizeof(struct { int:(-!!(__builtin_types_compatible_p(typeof((bo->placements)), typeof(&(bo->placements)[0])))); }))))` failed!
    WARNING: CPU: 30 PID: 6161 at drivers/gpu/drm/xe/xe_bo.c:203 __xe_bo_placement_for_flags+0x218/0x240 [xe]

Is fixed here by moving the bounds checks closer to where we actually
write into the bo->placement array.

Fixes: 8c54ee8a8606 ("drm/xe: Ensure that we don't access the placements array out-of-bounds")
Link: https://patchwork.freedesktop.org/patch/msgid/20240111002111.10190-1-brian.welty@intel.com
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Brian Welty <brian.welty@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
drivers/gpu/drm/xe/xe_bo.c