Skip to content

Commit 50e2fc3

Browse files
Anson Jacobalexdeucher
authored andcommitted
drm/amdkfd: Fix UBSAN shift-out-of-bounds warning
If get_num_sdma_queues or get_num_xgmi_sdma_queues is 0, we end up doing a shift operation where the number of bits shifted equals number of bits in the operand. This behaviour is undefined. Set num_sdma_queues or num_xgmi_sdma_queues to ULLONG_MAX, if the count is >= number of bits in the operand. Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1472 Reported-by: Lyude Paul <[email protected]> Signed-off-by: Anson Jacob <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Tested-by: Lyude Paul <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 47bfa5f commit 50e2fc3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,9 @@ static int set_sched_resources(struct device_queue_manager *dqm)
11281128

11291129
static int initialize_cpsch(struct device_queue_manager *dqm)
11301130
{
1131+
uint64_t num_sdma_queues;
1132+
uint64_t num_xgmi_sdma_queues;
1133+
11311134
pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm));
11321135

11331136
mutex_init(&dqm->lock_hidden);
@@ -1136,8 +1139,18 @@ static int initialize_cpsch(struct device_queue_manager *dqm)
11361139
dqm->active_cp_queue_count = 0;
11371140
dqm->gws_queue_count = 0;
11381141
dqm->active_runlist = false;
1139-
dqm->sdma_bitmap = ~0ULL >> (64 - get_num_sdma_queues(dqm));
1140-
dqm->xgmi_sdma_bitmap = ~0ULL >> (64 - get_num_xgmi_sdma_queues(dqm));
1142+
1143+
num_sdma_queues = get_num_sdma_queues(dqm);
1144+
if (num_sdma_queues >= BITS_PER_TYPE(dqm->sdma_bitmap))
1145+
dqm->sdma_bitmap = ULLONG_MAX;
1146+
else
1147+
dqm->sdma_bitmap = (BIT_ULL(num_sdma_queues) - 1);
1148+
1149+
num_xgmi_sdma_queues = get_num_xgmi_sdma_queues(dqm);
1150+
if (num_xgmi_sdma_queues >= BITS_PER_TYPE(dqm->xgmi_sdma_bitmap))
1151+
dqm->xgmi_sdma_bitmap = ULLONG_MAX;
1152+
else
1153+
dqm->xgmi_sdma_bitmap = (BIT_ULL(num_xgmi_sdma_queues) - 1);
11411154

11421155
INIT_WORK(&dqm->hw_exception_work, kfd_process_hw_exception);
11431156

0 commit comments

Comments
 (0)