Skip to content

Commit 457123d

Browse files
committed
drm/xe: Don't compare GT ID to GT count when determining valid GTs
On current platforms with multiple GTs, all of the GT IDs are consecutive; as a result we know that the GT IDs range from 0 to gt_count-1 and can determine if a GT ID is valid by comparing against the count. The consecutive nature of GT IDs may not hold true on future platforms if/when we have platforms that are both multi-tile and have multiple GTs within each tile. Once such platforms exist, it's quite possible that we could wind up with something like a GT list composed of IDs 0, 2, and 3 with no GT 1 (which would be a 2-tile platform with media only on the second tile). To future-proof the code we should stop comparing against the GT count to determine whether a GT ID is valid or not. Instead we should do an actual lookup of the ID to determine whether the GT exists. This also means that our GT loop macro should not end at the GT count, but should rather examine the entire space up to (# of tiles) * (max GT per tile) to ensure it doesn't stop prematurely. Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com> Link: https://lore.kernel.org/r/20250701201320.2514369-15-matthew.d.roper@intel.com Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
1 parent bd6a4b9 commit 457123d

4 files changed

Lines changed: 8 additions & 9 deletions

File tree

drivers/gpu/drm/xe/xe_device.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,8 @@ static inline bool xe_device_uc_enabled(struct xe_device *xe)
127127
for ((id__) = 1; (id__) < (xe__)->info.tile_count; (id__)++) \
128128
for_each_if((tile__) = &(xe__)->tiles[(id__)])
129129

130-
/*
131-
* FIXME: This only works for now since multi-tile and standalone media
132-
* happen to be mutually exclusive. Future platforms may change this...
133-
*/
134130
#define for_each_gt(gt__, xe__, id__) \
135-
for ((id__) = 0; (id__) < (xe__)->info.gt_count; (id__)++) \
131+
for ((id__) = 0; (id__) < (xe__)->info.tile_count * (xe__)->info.max_gt_per_tile; (id__)++) \
136132
for_each_if((gt__) = xe_device_get_gt((xe__), (id__)))
137133

138134
static inline struct xe_force_wake *gt_to_fw(struct xe_gt *gt)

drivers/gpu/drm/xe/xe_eu_stall.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,13 @@ static int set_prop_eu_stall_wait_num_reports(struct xe_device *xe, u64 value,
258258
static int set_prop_eu_stall_gt_id(struct xe_device *xe, u64 value,
259259
struct eu_stall_open_properties *props)
260260
{
261-
if (value >= xe->info.gt_count) {
261+
struct xe_gt *gt = xe_device_get_gt(xe, value);
262+
263+
if (!gt) {
262264
drm_dbg(&xe->drm, "Invalid GT ID %llu for EU stall sampling\n", value);
263265
return -EINVAL;
264266
}
265-
props->gt = xe_device_get_gt(xe, value);
267+
props->gt = gt;
266268
return 0;
267269
}
268270

drivers/gpu/drm/xe/xe_exec_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
610610
if (XE_IOCTL_DBG(xe, err))
611611
return -EFAULT;
612612

613-
if (XE_IOCTL_DBG(xe, eci[0].gt_id >= xe->info.gt_count))
613+
if (XE_IOCTL_DBG(xe, !xe_device_get_gt(xe, eci[0].gt_id)))
614614
return -EINVAL;
615615

616616
if (args->flags & DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT)

drivers/gpu/drm/xe/xe_hw_engine.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,13 @@ struct xe_hw_engine *
10591059
xe_hw_engine_lookup(struct xe_device *xe,
10601060
struct drm_xe_engine_class_instance eci)
10611061
{
1062+
struct xe_gt *gt = xe_device_get_gt(xe, eci.gt_id);
10621063
unsigned int idx;
10631064

10641065
if (eci.engine_class >= ARRAY_SIZE(user_to_xe_engine_class))
10651066
return NULL;
10661067

1067-
if (eci.gt_id >= xe->info.gt_count)
1068+
if (!gt)
10681069
return NULL;
10691070

10701071
idx = array_index_nospec(eci.engine_class,

0 commit comments

Comments
 (0)