All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	oded.gabbay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: Yong Zhao <yong.zhao-5C7GfCeVMHo@public.gmane.org>,
	Felix Kuehling <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 14/14] drm/amdkfd: Simplify locking during process creation
Date: Mon, 27 Nov 2017 18:29:56 -0500	[thread overview]
Message-ID: <1511825396-24579-15-git-send-email-Felix.Kuehling@amd.com> (raw)
In-Reply-To: <1511825396-24579-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>

From: Yong Zhao <yong.zhao@amd.com>

Also fixes error handling if kfd_process_init_cwsr fails.

Signed-off-by: Yong Zhao <yong.zhao@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 46 +++++++++++++++-----------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 096710c..a22fb071 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -50,7 +50,8 @@ static struct workqueue_struct *kfd_process_wq;
 
 static struct kfd_process *find_process(const struct task_struct *thread);
 static void kfd_process_ref_release(struct kref *ref);
-static struct kfd_process *create_process(const struct task_struct *thread);
+static struct kfd_process *create_process(const struct task_struct *thread,
+					struct file *filep);
 static int kfd_process_init_cwsr(struct kfd_process *p, struct file *filep);
 
 
@@ -80,9 +81,6 @@ struct kfd_process *kfd_create_process(struct file *filep)
 	if (thread->group_leader->mm != thread->mm)
 		return ERR_PTR(-EINVAL);
 
-	/* Take mmap_sem because we call __mmu_notifier_register inside */
-	down_write(&thread->mm->mmap_sem);
-
 	/*
 	 * take kfd processes mutex before starting of process creation
 	 * so there won't be a case where two threads of the same process
@@ -94,16 +92,11 @@ struct kfd_process *kfd_create_process(struct file *filep)
 	process = find_process(thread);
 	if (process)
 		pr_debug("Process already found\n");
-
-	if (!process)
-		process = create_process(thread);
+	else
+		process = create_process(thread, filep);
 
 	mutex_unlock(&kfd_processes_mutex);
 
-	up_write(&thread->mm->mmap_sem);
-
-	kfd_process_init_cwsr(process, filep);
-
 	return process;
 }
 
@@ -274,15 +267,12 @@ static const struct mmu_notifier_ops kfd_process_mmu_notifier_ops = {
 
 static int kfd_process_init_cwsr(struct kfd_process *p, struct file *filep)
 {
-	int err = 0;
 	unsigned long  offset;
-	struct kfd_process_device *temp, *pdd = NULL;
+	struct kfd_process_device *pdd = NULL;
 	struct kfd_dev *dev = NULL;
 	struct qcm_process_device *qpd = NULL;
 
-	mutex_lock(&p->mutex);
-	list_for_each_entry_safe(pdd, temp, &p->per_device_data,
-				per_device_list) {
+	list_for_each_entry(pdd, &p->per_device_data, per_device_list) {
 		dev = pdd->dev;
 		qpd = &pdd->qpd;
 		if (!dev->cwsr_enabled || qpd->cwsr_kaddr)
@@ -293,12 +283,12 @@ static int kfd_process_init_cwsr(struct kfd_process *p, struct file *filep)
 			MAP_SHARED, offset);
 
 		if (IS_ERR_VALUE(qpd->tba_addr)) {
-			pr_err("Failure to set tba address. error -%d.\n",
-				(int)qpd->tba_addr);
-			err = qpd->tba_addr;
+			int err = qpd->tba_addr;
+
+			pr_err("Failure to set tba address. error %d.\n", err);
 			qpd->tba_addr = 0;
 			qpd->cwsr_kaddr = NULL;
-			goto out;
+			return err;
 		}
 
 		memcpy(qpd->cwsr_kaddr, dev->cwsr_isa, dev->cwsr_isa_size);
@@ -307,12 +297,12 @@ static int kfd_process_init_cwsr(struct kfd_process *p, struct file *filep)
 		pr_debug("set tba :0x%llx, tma:0x%llx, cwsr_kaddr:%p for pqm.\n",
 			qpd->tba_addr, qpd->tma_addr, qpd->cwsr_kaddr);
 	}
-out:
-	mutex_unlock(&p->mutex);
-	return err;
+
+	return 0;
 }
 
-static struct kfd_process *create_process(const struct task_struct *thread)
+static struct kfd_process *create_process(const struct task_struct *thread,
+					struct file *filep)
 {
 	struct kfd_process *process;
 	int err = -ENOMEM;
@@ -337,7 +327,7 @@ static struct kfd_process *create_process(const struct task_struct *thread)
 
 	/* register notifier */
 	process->mmu_notifier.ops = &kfd_process_mmu_notifier_ops;
-	err = __mmu_notifier_register(&process->mmu_notifier, process->mm);
+	err = mmu_notifier_register(&process->mmu_notifier, process->mm);
 	if (err)
 		goto err_mmu_notifier;
 
@@ -361,8 +351,14 @@ static struct kfd_process *create_process(const struct task_struct *thread)
 	if (err != 0)
 		goto err_init_apertures;
 
+	err = kfd_process_init_cwsr(process, filep);
+	if (err)
+		goto err_init_cwsr;
+
 	return process;
 
+err_init_cwsr:
+	kfd_process_destroy_pdds(process);
 err_init_apertures:
 	pqm_uninit(&process->pqm);
 err_process_pqm_init:
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-11-27 23:29 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 23:29 [PATCH 00/14] KFD upstreaming 20171127 Felix Kuehling
     [not found] ` <1511825396-24579-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-11-27 23:29   ` [PATCH 01/14] drm/amdgpu: fix get_max_engine_clock_in_mhz Felix Kuehling
     [not found]     ` <1511825396-24579-2-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-11-30 16:03       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 02/14] drm/amdkfd: Add crash protection in debugger register path Felix Kuehling
     [not found]     ` <1511825396-24579-3-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-11-30 16:14       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 03/14] drm/amdkfd: map multiple processes to HW scheduler Felix Kuehling
     [not found]     ` <1511825396-24579-4-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-05  8:04       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 04/14] drm/amdkfd: Fix oversubscription accounting Felix Kuehling
     [not found]     ` <1511825396-24579-5-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-05  8:10       ` Oded Gabbay
     [not found]         ` <CAFCwf11eM8pYmBOHdD1o4NVDj9nesJwp3Ny9dGukzstM5iP=Ag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-12-05 19:27           ` Felix Kuehling
     [not found]             ` <9f625c72-a44e-6560-1d2b-6d998ad0e2e2-5C7GfCeVMHo@public.gmane.org>
2017-12-10  9:00               ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 05/14] drm/amdgpu: Fix definition of KFD_CIK_SDMA_QUEUE_OFFSET Felix Kuehling
     [not found]     ` <1511825396-24579-6-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-05  8:15       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 06/14] drm/amdgpu: Add kfd2kgd APIs for dumping HQDs Felix Kuehling
     [not found]     ` <1511825396-24579-7-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-05  8:23       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 07/14] drm/amdkfd: Add debugfs support to KFD Felix Kuehling
     [not found]     ` <1511825396-24579-8-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-05  8:27       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 08/14] drm/amdkfd: Get reference to lead_thread task struct Felix Kuehling
     [not found]     ` <1511825396-24579-9-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-05  8:43       ` Oded Gabbay
     [not found]         ` <CAFCwf12ELNgXW7bL+zb2F3v1XWn914maeRP3e3M+3U15B521wg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-12-05 19:14           ` Felix Kuehling
     [not found]             ` <e23118b1-eb9b-6a2b-e937-09747b4a9aac-5C7GfCeVMHo@public.gmane.org>
2017-12-10  9:04               ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 09/14] drm/amdkfd: Make kfd_process reference counted Felix Kuehling
     [not found]     ` <1511825396-24579-10-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-10 10:00       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 10/14] drm/amdkfd: Use ref count to prevent kfd_process destruction Felix Kuehling
     [not found]     ` <1511825396-24579-11-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-11-28  9:52       ` Christian König
     [not found]         ` <7fb6a8a7-5616-95d6-c2c9-3b69a75a3613-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-12-01 21:17           ` Felix Kuehling
     [not found]             ` <ab143937-aca3-9f3e-b6f4-4d354fde3c05-5C7GfCeVMHo@public.gmane.org>
2017-12-10  9:59               ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 11/14] drm/amdkfd: Return NULL if kfd_lookup_process_by_pasid fails Felix Kuehling
     [not found]     ` <1511825396-24579-12-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-10 10:12       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 12/14] drm/amdkfd: Reduce nesting in kfd_create_process_device_data Felix Kuehling
     [not found]     ` <1511825396-24579-13-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-10 10:13       ` Oded Gabbay
2017-11-27 23:29   ` [PATCH 13/14] drm/amdkfd: Factor PDD destruction out of kfd_process_wq_release Felix Kuehling
     [not found]     ` <1511825396-24579-14-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-10 10:15       ` Oded Gabbay
2017-11-27 23:29   ` Felix Kuehling [this message]
     [not found]     ` <1511825396-24579-15-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-12-10 10:22       ` [PATCH 14/14] drm/amdkfd: Simplify locking during process creation Oded Gabbay

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=1511825396-24579-15-git-send-email-Felix.Kuehling@amd.com \
    --to=felix.kuehling-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=oded.gabbay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=yong.zhao-5C7GfCeVMHo@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.