drm/amdkfd: Fix sdma queue allocate race condition
authorOak Zeng <Oak.Zeng@amd.com>
Sat, 15 Jun 2019 00:27:58 +0000 (19:27 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 17 Jun 2019 16:01:41 +0000 (11:01 -0500)
SDMA queue allocation requires the dqm lock as it modify
the global dqm members. Enclose it in the dqm_lock.

Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
Reviewed-by: Philip Yang <philip.yang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c

index b75ec379425c5b636994efc79a15ceec5323bd00..3528590ae90b91f10edcc818261eb77a38d76028 100644 (file)
@@ -1144,7 +1144,9 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
 
        if (q->properties.type == KFD_QUEUE_TYPE_SDMA ||
                q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
+               dqm_lock(dqm);
                retval = allocate_sdma_queue(dqm, q);
+               dqm_unlock(dqm);
                if (retval)
                        goto out;
        }
@@ -1203,8 +1205,11 @@ out_deallocate_doorbell:
        deallocate_doorbell(qpd, q);
 out_deallocate_sdma_queue:
        if (q->properties.type == KFD_QUEUE_TYPE_SDMA ||
-               q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI)
+               q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
+               dqm_lock(dqm);
                deallocate_sdma_queue(dqm, q);
+               dqm_unlock(dqm);
+       }
 out:
        return retval;
 }