From: "Zeng, Oak" <Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
To: "amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Cc: "Kuehling, Felix" <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>,
"Zeng, Oak" <Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 6/6] drm/amdkfd: Fix sdma queue allocate race condition
Date: Tue, 4 Jun 2019 02:52:50 +0000 [thread overview]
Message-ID: <1559616755-13116-6-git-send-email-Oak.Zeng@amd.com> (raw)
In-Reply-To: <1559616755-13116-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
SDMA queue allocation requires the dqm lock as it modify
the global dqm members. Introduce functions to allocate/deallocate
in locked/unlocked circumstance.
Change-Id: Id3084524c5f65d9629b12cf6b4862a7516945cb1
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
.../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 34 ++++++++++++++++------
1 file changed, 25 insertions(+), 9 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 2cd47e3..8c66abd 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -53,6 +53,8 @@ static int map_queues_cpsch(struct device_queue_manager *dqm);
static void deallocate_sdma_queue(struct device_queue_manager *dqm,
struct queue *q);
+static void deallocate_sdma_queue_locked(struct device_queue_manager *dqm,
+ struct queue *q);
static inline void deallocate_hqd(struct device_queue_manager *dqm,
struct queue *q);
@@ -436,10 +438,10 @@ static int destroy_queue_nocpsch_locked(struct device_queue_manager *dqm,
deallocate_hqd(dqm, q);
} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
dqm->sdma_queue_count--;
- deallocate_sdma_queue(dqm, q);
+ deallocate_sdma_queue_locked(dqm, q);
} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
dqm->xgmi_sdma_queue_count--;
- deallocate_sdma_queue(dqm, q);
+ deallocate_sdma_queue_locked(dqm, q);
} else {
pr_debug("q->properties.type %d is invalid\n",
q->properties.type);
@@ -909,9 +911,12 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
{
int bit;
+ dqm_lock(dqm);
if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
- if (dqm->sdma_bitmap == 0)
+ if (dqm->sdma_bitmap == 0) {
+ dqm_unlock(dqm);
return -ENOMEM;
+ }
bit = __ffs64(dqm->sdma_bitmap);
dqm->sdma_bitmap &= ~(1ULL << bit);
q->sdma_id = bit;
@@ -920,8 +925,10 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
q->properties.sdma_queue_id = q->sdma_id /
get_num_sdma_engines(dqm);
} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
- if (dqm->xgmi_sdma_bitmap == 0)
+ if (dqm->xgmi_sdma_bitmap == 0) {
+ dqm_unlock(dqm);
return -ENOMEM;
+ }
bit = __ffs64(dqm->xgmi_sdma_bitmap);
dqm->xgmi_sdma_bitmap &= ~(1ULL << bit);
q->sdma_id = bit;
@@ -937,13 +944,14 @@ static int allocate_sdma_queue(struct device_queue_manager *dqm,
get_num_xgmi_sdma_engines(dqm);
}
+ dqm_unlock(dqm);
pr_debug("SDMA engine id: %d\n", q->properties.sdma_engine_id);
pr_debug("SDMA queue id: %d\n", q->properties.sdma_queue_id);
return 0;
}
-static void deallocate_sdma_queue(struct device_queue_manager *dqm,
+static void deallocate_sdma_queue_locked(struct device_queue_manager *dqm,
struct queue *q)
{
if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
@@ -957,6 +965,14 @@ static void deallocate_sdma_queue(struct device_queue_manager *dqm,
}
}
+static void deallocate_sdma_queue(struct device_queue_manager *dqm,
+ struct queue *q)
+{
+ dqm_lock(dqm);
+ deallocate_sdma_queue_locked(dqm, q);
+ dqm_unlock(dqm);
+}
+
/*
* Device Queue Manager implementation for cp scheduler
*/
@@ -1353,10 +1369,10 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
dqm->sdma_queue_count--;
- deallocate_sdma_queue(dqm, q);
+ deallocate_sdma_queue_locked(dqm, q);
} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
dqm->xgmi_sdma_queue_count--;
- deallocate_sdma_queue(dqm, q);
+ deallocate_sdma_queue_locked(dqm, q);
}
list_del(&q->list);
@@ -1582,10 +1598,10 @@ static int process_termination_cpsch(struct device_queue_manager *dqm,
list_for_each_entry(q, &qpd->queues_list, list) {
if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
dqm->sdma_queue_count--;
- deallocate_sdma_queue(dqm, q);
+ deallocate_sdma_queue_locked(dqm, q);
} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA_XGMI) {
dqm->xgmi_sdma_queue_count--;
- deallocate_sdma_queue(dqm, q);
+ deallocate_sdma_queue_locked(dqm, q);
}
if (q->properties.is_active)
--
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-04 2:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 2/6] drm/amdkfd: Only load sdma mqd when queue is active Zeng, Oak
2019-06-04 2:52 ` [PATCH 3/6] drm/amdkfd: Refactor create_queue_nocpsch Zeng, Oak
2019-06-04 2:52 ` [PATCH 4/6] drm/amdkfd: Separate mqd allocation and initialization Zeng, Oak
2019-06-04 2:52 ` [PATCH 5/6] drm/amdkfd: Fix a circular lock dependency Zeng, Oak
2019-06-04 2:52 ` Zeng, Oak [this message]
-- 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-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 6/6] drm/amdkfd: Fix sdma queue allocate race condition Zeng, Oak
[not found] ` <1559845507-3052-3-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-06-06 20:17 ` Kuehling, Felix
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=1559616755-13116-6-git-send-email-Oak.Zeng@amd.com \
--to=oak.zeng-5c7gfcevmho@public.gmane.org \
--cc=Felix.Kuehling-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