From: "Zeng, Oak" <Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
To: "amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Cc: "Zhao, Yong" <Yong.Zhao-5C7GfCeVMHo@public.gmane.org>,
"Kuehling, Felix" <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>,
"Freehill, Chris" <Chris.Freehill-5C7GfCeVMHo@public.gmane.org>,
"Zeng, Oak" <Oak.Zeng-5C7GfCeVMHo@public.gmane.org>,
"Liu, Alex" <Alex.Liu-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 6/6] drm/amdkfd: Fix sdma queue allocate race condition
Date: Thu, 6 Jun 2019 18:25:18 +0000 [thread overview]
Message-ID: <1559845507-3052-3-git-send-email-Oak.Zeng@amd.com> (raw)
In-Reply-To: <1559845507-3052-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
SDMA queue allocation requires the dqm lock at it modify
the global dqm members. Move up the dqm_lock so sdma
queue allocation is enclosed in the critical section. Move
mqd allocation out of critical section to avoid circular
lock dependency.
Change-Id: I96abd42eae6e77c82a5ba1b8e600af3efe8d791d
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
.../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 24 +++++++++++-----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 166636c..cd259b8 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1133,23 +1133,27 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
if (dqm->total_queue_count >= max_num_of_queues_per_device) {
pr_warn("Can't create new usermode queue because %d queues were already created\n",
dqm->total_queue_count);
- retval = -EPERM;
- goto out;
+ return -EPERM;
}
+ mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
+ q->properties.type)];
+ q->mqd_mem_obj = mqd_mgr->allocate_mqd(mqd_mgr->dev, &q->properties);
+ if (!q->mqd_mem_obj)
+ return -ENOMEM;
+
+ dqm_lock(dqm);
if (q->properties.type == KFD_QUEUE_TYPE_SDMA ||
q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
retval = allocate_sdma_queue(dqm, q);
if (retval)
- goto out;
+ goto out_unlock;
}
retval = allocate_doorbell(qpd, q);
if (retval)
goto out_deallocate_sdma_queue;
- mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
- q->properties.type)];
/*
* Eviction state logic: mark all queues as evicted, even ones
* not currently active. Restoring inactive queues later only
@@ -1161,12 +1165,8 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
dqm->asic_ops.init_sdma_vm(dqm, q, qpd);
q->properties.tba_addr = qpd->tba_addr;
q->properties.tma_addr = qpd->tma_addr;
- q->mqd_mem_obj = mqd_mgr->allocate_mqd(mqd_mgr->dev, &q->properties);
- if (!q->mqd_mem_obj)
- goto out_deallocate_doorbell;
mqd_mgr->init_mqd(mqd_mgr, &q->mqd, q->mqd_mem_obj,
&q->gart_mqd_addr, &q->properties);
- dqm_lock(dqm);
list_add(&q->list, &qpd->queues_list);
qpd->queue_count++;
@@ -1192,13 +1192,13 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
dqm_unlock(dqm);
return retval;
-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)
deallocate_sdma_queue(dqm, q);
-out:
+out_unlock:
+ dqm_unlock(dqm);
+ mqd_mgr->free_mqd(mqd_mgr, q->mqd, q->mqd_mem_obj);
return retval;
}
--
2.7.4
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2019-06-06 18:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-06 18:25 [PATCH 4/6] drm/amdkfd: Separate mqd allocation and initialization Zeng, Oak
[not found] ` <1559845507-3052-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-06-06 18:25 ` [PATCH 5/6] drm/amdkfd: Fix a circular lock dependency Zeng, Oak
2019-06-06 18:25 ` Zeng, Oak [this message]
[not found] ` <1559845507-3052-3-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-06-06 20:17 ` [PATCH 6/6] drm/amdkfd: Fix sdma queue allocate race condition Kuehling, Felix
2019-06-06 20:13 ` [PATCH 4/6] drm/amdkfd: Separate mqd allocation and initialization Kuehling, Felix
-- strict thread matches above, loose matches on Subject: below --
2019-06-05 16:06 [PATCH 1/6] drm/amdkfd: Only initialize sdma vm for sdma queues Zeng, Oak
[not found] ` <1559750793-16608-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-06-05 16:06 ` [PATCH 6/6] drm/amdkfd: Fix sdma queue allocate race condition Zeng, Oak
[not found] ` <1559750793-16608-6-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-06-05 22:24 ` Kuehling, Felix
2019-06-04 2:52 [PATCH 1/6] drm/amdkfd: Only initialize sdma vm for sdma queues Zeng, Oak
[not found] ` <1559616755-13116-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-06-04 2:52 ` [PATCH 6/6] drm/amdkfd: Fix sdma queue allocate race condition Zeng, Oak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1559845507-3052-3-git-send-email-Oak.Zeng@amd.com \
--to=oak.zeng-5c7gfcevmho@public.gmane.org \
--cc=Alex.Liu-5C7GfCeVMHo@public.gmane.org \
--cc=Chris.Freehill-5C7GfCeVMHo@public.gmane.org \
--cc=Felix.Kuehling-5C7GfCeVMHo@public.gmane.org \
--cc=Yong.Zhao-5C7GfCeVMHo@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox