Skip to content

Commit 8049e39

Browse files
brianweltyThomas Hellström
authored andcommitted
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: 8c54ee8 ("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> (cherry picked from commit 52e3fa3) Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
1 parent 7425c43 commit 8049e39

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ static struct xe_mem_region *res_to_mem_region(struct ttm_resource *res)
125125
static void try_add_system(struct xe_device *xe, struct xe_bo *bo,
126126
u32 bo_flags, u32 *c)
127127
{
128-
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
129-
130128
if (bo_flags & XE_BO_CREATE_SYSTEM_BIT) {
129+
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
130+
131131
bo->placements[*c] = (struct ttm_place) {
132132
.mem_type = XE_PL_TT,
133133
};
@@ -145,6 +145,8 @@ static void add_vram(struct xe_device *xe, struct xe_bo *bo,
145145
struct xe_mem_region *vram;
146146
u64 io_size;
147147

148+
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
149+
148150
vram = to_xe_ttm_vram_mgr(ttm_manager_type(&xe->ttm, mem_type))->vram;
149151
xe_assert(xe, vram && vram->usable_size);
150152
io_size = vram->io_size;
@@ -175,8 +177,6 @@ static void add_vram(struct xe_device *xe, struct xe_bo *bo,
175177
static void try_add_vram(struct xe_device *xe, struct xe_bo *bo,
176178
u32 bo_flags, u32 *c)
177179
{
178-
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
179-
180180
if (bo->props.preferred_gt == XE_GT1) {
181181
if (bo_flags & XE_BO_CREATE_VRAM1_BIT)
182182
add_vram(xe, bo, bo->placements, bo_flags, XE_PL_VRAM1, c);
@@ -193,9 +193,9 @@ static void try_add_vram(struct xe_device *xe, struct xe_bo *bo,
193193
static void try_add_stolen(struct xe_device *xe, struct xe_bo *bo,
194194
u32 bo_flags, u32 *c)
195195
{
196-
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
197-
198196
if (bo_flags & XE_BO_CREATE_STOLEN_BIT) {
197+
xe_assert(xe, *c < ARRAY_SIZE(bo->placements));
198+
199199
bo->placements[*c] = (struct ttm_place) {
200200
.mem_type = XE_PL_STOLEN,
201201
.flags = bo_flags & (XE_BO_CREATE_PINNED_BIT |

0 commit comments

Comments
 (0)