]> Git Repo - linux.git/commitdiff
drm/amdkfd: Fix UBSAN shift-out-of-bounds warning
authorAnson Jacob <[email protected]>
Wed, 3 Mar 2021 17:33:15 +0000 (12:33 -0500)
committerAlex Deucher <[email protected]>
Wed, 24 Mar 2021 03:00:57 +0000 (23:00 -0400)
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]>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

index 37de451447b197f6179d2234179daeb94f2249a0..965f9f230045c7603b72d988a7a2870265f8f4df 100644 (file)
@@ -1128,6 +1128,9 @@ static int set_sched_resources(struct device_queue_manager *dqm)
 
 static int initialize_cpsch(struct device_queue_manager *dqm)
 {
+       uint64_t num_sdma_queues;
+       uint64_t num_xgmi_sdma_queues;
+
        pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm));
 
        mutex_init(&dqm->lock_hidden);
@@ -1136,8 +1139,18 @@ static int initialize_cpsch(struct device_queue_manager *dqm)
        dqm->active_cp_queue_count = 0;
        dqm->gws_queue_count = 0;
        dqm->active_runlist = false;
-       dqm->sdma_bitmap = ~0ULL >> (64 - get_num_sdma_queues(dqm));
-       dqm->xgmi_sdma_bitmap = ~0ULL >> (64 - get_num_xgmi_sdma_queues(dqm));
+
+       num_sdma_queues = get_num_sdma_queues(dqm);
+       if (num_sdma_queues >= BITS_PER_TYPE(dqm->sdma_bitmap))
+               dqm->sdma_bitmap = ULLONG_MAX;
+       else
+               dqm->sdma_bitmap = (BIT_ULL(num_sdma_queues) - 1);
+
+       num_xgmi_sdma_queues = get_num_xgmi_sdma_queues(dqm);
+       if (num_xgmi_sdma_queues >= BITS_PER_TYPE(dqm->xgmi_sdma_bitmap))
+               dqm->xgmi_sdma_bitmap = ULLONG_MAX;
+       else
+               dqm->xgmi_sdma_bitmap = (BIT_ULL(num_xgmi_sdma_queues) - 1);
 
        INIT_WORK(&dqm->hw_exception_work, kfd_process_hw_exception);
 
This page took 0.062118 seconds and 4 git commands to generate.