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: Felix Kuehling <Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 07/16] drm/amdkfd: Fix event destruction with pending waiters
Date: Fri, 20 Oct 2017 20:23:11 -0400	[thread overview]
Message-ID: <1508545400-24338-8-git-send-email-Felix.Kuehling@amd.com> (raw)
In-Reply-To: <1508545400-24338-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>

When an event with pending waiters is destroyed, those waiters may
end up sleeping forever unless they are notified and woken up.
Implement the notification by clearing the waiter->event pointer,
which becomes invalid anyway, when the event is freed, and waking
up the waiting tasks.

Waiters on an event that's destroyed return failure.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 72 +++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
index 5bb88b74..6050e88 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
@@ -345,18 +345,24 @@ void kfd_event_init_process(struct kfd_process *p)
 
 static void destroy_event(struct kfd_process *p, struct kfd_event *ev)
 {
+	/* Wake up pending waiters. They will return failure */
+	while (!list_empty(&ev->waiters)) {
+		struct kfd_event_waiter *waiter =
+			list_first_entry(&ev->waiters, struct kfd_event_waiter,
+					 waiters);
+
+		waiter->event = NULL;
+		/* _init because free_waiters will call list_del */
+		list_del_init(&waiter->waiters);
+		wake_up_process(waiter->sleeping_task);
+	}
+
 	if (ev->signal_page) {
 		release_event_notification_slot(ev->signal_page,
 						ev->signal_slot_index);
 		p->signal_event_count--;
 	}
 
-	/*
-	 * Abandon the list of waiters. Individual waiting threads will
-	 * clean up their own data.
-	 */
-	list_del(&ev->waiters);
-
 	hash_del(&ev->events);
 	kfree(ev);
 }
@@ -646,22 +652,36 @@ static void init_event_waiter_add_to_waitlist(struct kfd_event_waiter *waiter)
 		list_add(&waiter->waiters, &ev->waiters);
 }
 
-static bool test_event_condition(bool all, uint32_t num_events,
+/* test_event_condition - Test condition of events being waited for
+ * @all:           Return completion only if all events have signaled
+ * @num_events:    Number of events to wait for
+ * @event_waiters: Array of event waiters, one per event
+ *
+ * Returns KFD_IOC_WAIT_RESULT_COMPLETE if all (or one) event(s) have
+ * signaled. Returns KFD_IOC_WAIT_RESULT_TIMEOUT if no (or not all)
+ * events have signaled. Returns KFD_IOC_WAIT_RESULT_FAIL if any of
+ * the events have been destroyed.
+ */
+static uint32_t test_event_condition(bool all, uint32_t num_events,
 				struct kfd_event_waiter *event_waiters)
 {
 	uint32_t i;
 	uint32_t activated_count = 0;
 
 	for (i = 0; i < num_events; i++) {
+		if (!event_waiters[i].event)
+			return KFD_IOC_WAIT_RESULT_FAIL;
+
 		if (event_waiters[i].activated) {
 			if (!all)
-				return true;
+				return KFD_IOC_WAIT_RESULT_COMPLETE;
 
 			activated_count++;
 		}
 	}
 
-	return activated_count == num_events;
+	return activated_count == num_events ?
+		KFD_IOC_WAIT_RESULT_COMPLETE : KFD_IOC_WAIT_RESULT_TIMEOUT;
 }
 
 /*
@@ -745,11 +765,6 @@ int kfd_wait_on_events(struct kfd_process *p,
 
 	mutex_lock(&p->event_mutex);
 
-	/* Set to something unreasonable - this is really
-	 * just a bool for now.
-	 */
-	*wait_result = KFD_IOC_WAIT_RESULT_TIMEOUT;
-
 	for (i = 0; i < num_events; i++) {
 		struct kfd_event_data event_data;
 
@@ -766,17 +781,22 @@ int kfd_wait_on_events(struct kfd_process *p,
 	}
 
 	/* Check condition once. */
-	if (test_event_condition(all, num_events, event_waiters)) {
-		*wait_result = KFD_IOC_WAIT_RESULT_COMPLETE;
+	*wait_result = test_event_condition(all, num_events, event_waiters);
+	if (*wait_result == KFD_IOC_WAIT_RESULT_COMPLETE) {
 		ret = copy_signaled_event_data(num_events,
 					       event_waiters, events);
 		goto out_unlock;
-	} else {
-		/* Add to wait lists if we need to wait. */
-		for (i = 0; i < num_events; i++)
-			init_event_waiter_add_to_waitlist(&event_waiters[i]);
+	} else if (WARN_ON(*wait_result == KFD_IOC_WAIT_RESULT_FAIL)) {
+		/* This should not happen. Events shouldn't be
+		 * destroyed while we're holding the event_mutex
+		 */
+		goto out_unlock;
 	}
 
+	/* Add to wait lists if we need to wait. */
+	for (i = 0; i < num_events; i++)
+		init_event_waiter_add_to_waitlist(&event_waiters[i]);
+
 	mutex_unlock(&p->event_mutex);
 
 	while (true) {
@@ -809,15 +829,13 @@ int kfd_wait_on_events(struct kfd_process *p,
 		 */
 		set_current_state(TASK_INTERRUPTIBLE);
 
-		if (test_event_condition(all, num_events, event_waiters)) {
-			*wait_result = KFD_IOC_WAIT_RESULT_COMPLETE;
+		*wait_result = test_event_condition(all, num_events,
+						    event_waiters);
+		if (*wait_result != KFD_IOC_WAIT_RESULT_TIMEOUT)
 			break;
-		}
 
-		if (timeout <= 0) {
-			*wait_result = KFD_IOC_WAIT_RESULT_TIMEOUT;
+		if (timeout <= 0)
 			break;
-		}
 
 		timeout = schedule_timeout(timeout);
 	}
@@ -837,6 +855,8 @@ int kfd_wait_on_events(struct kfd_process *p,
 out:
 	if (ret)
 		*wait_result = KFD_IOC_WAIT_RESULT_FAIL;
+	else if (*wait_result == KFD_IOC_WAIT_RESULT_FAIL)
+		ret = -EIO;
 
 	return ret;
 }
-- 
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-10-21  0:23 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-21  0:23 [PATCH 00/16] KFD interrupt and signal event handling improvements Felix Kuehling
     [not found] ` <1508545400-24338-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-21  0:23   ` [PATCH 01/16] drm/amdkfd: Add SDMA trap src id to the KFD isr wanted list Felix Kuehling
     [not found]     ` <1508545400-24338-2-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  6:13       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 02/16] drm/amdkfd: Don't dereference kfd_process.mm Felix Kuehling
     [not found]     ` <1508545400-24338-3-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  6:45       ` Oded Gabbay
2017-10-26  7:33       ` Christian König
     [not found]         ` <183a1c77-23a2-3015-e019-cb3fc57cdb3c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-26 16:47           ` Felix Kuehling
     [not found]             ` <f42bdbcc-0264-f189-fa6f-9989016b380d-5C7GfCeVMHo@public.gmane.org>
2017-10-26 18:11               ` Christian König
     [not found]                 ` <b04933a4-e585-d1ff-57a3-d9ba1f09c0b0-5C7GfCeVMHo@public.gmane.org>
2017-10-26 18:54                   ` Felix Kuehling
     [not found]                     ` <0ff645b5-1906-2ce3-a9a6-d34c2ce2c516-5C7GfCeVMHo@public.gmane.org>
2017-10-27  7:22                       ` Christian König
     [not found]                         ` <19defd90-bf38-315b-cb4a-eb78e4acafec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-27  7:41                           ` Christian König
     [not found]                             ` <fa2c0104-7a85-f250-bafc-c8096f910d92-5C7GfCeVMHo@public.gmane.org>
2017-10-27 19:09                               ` Felix Kuehling
2017-10-21  0:23   ` [PATCH 03/16] drm/amdkfd: increase limit of signal events to 4096 per process Felix Kuehling
     [not found]     ` <1508545400-24338-4-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:31       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 04/16] drm/amdkfd: Short cut for kfd_wait_on_events without waiting Felix Kuehling
     [not found]     ` <1508545400-24338-5-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:39       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 05/16] drm/amdkfd: Fix scheduler race in kfd_wait_on_events sleep loop Felix Kuehling
     [not found]     ` <1508545400-24338-6-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:45       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 06/16] drm/amdkfd: Clean up kfd_wait_on_events Felix Kuehling
     [not found]     ` <1508545400-24338-7-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:49       ` Oded Gabbay
2017-10-21  0:23   ` Felix Kuehling [this message]
     [not found]     ` <1508545400-24338-8-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:50       ` [PATCH 07/16] drm/amdkfd: Fix event destruction with pending waiters Oded Gabbay
2017-10-21  0:23   ` [PATCH 08/16] drm/amdkfd: remove redundant kfd_event_waiter.input_index Felix Kuehling
     [not found]     ` <1508545400-24338-9-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25  8:54       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 09/16] drm/amdkfd: Use wait_queue_t to implement event waiting Felix Kuehling
     [not found]     ` <1508545400-24338-10-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:28       ` Oded Gabbay
     [not found]         ` <CAFCwf10QwD3JNz6BGWBC94WHfU2EpDx1CJSkjjwjNt7AnZLpyA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-25 16:02           ` Felix Kuehling
2017-10-21  0:23   ` [PATCH 10/16] drm/amdkfd: Simplify events page allocator Felix Kuehling
     [not found]     ` <1508545400-24338-11-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:40       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 11/16] drm/amdkfd: Simplify event ID and signal slot management Felix Kuehling
     [not found]     ` <1508545400-24338-12-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:42       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 12/16] drm/amdkfd: Use IH context ID for signal lookup Felix Kuehling
     [not found]     ` <1508545400-24338-13-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 10:46       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 13/16] drm/amdkfd: use standard kernel kfifo for IH Felix Kuehling
     [not found]     ` <1508545400-24338-14-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:15       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 14/16] drm/amdkfd: increase IH num entries to 8192 Felix Kuehling
     [not found]     ` <1508545400-24338-15-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:18       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 15/16] drm/amdkfd: wait only for IH work on IH exit Felix Kuehling
     [not found]     ` <1508545400-24338-16-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:20       ` Oded Gabbay
2017-10-21  0:23   ` [PATCH 16/16] drm/amdkfd: use a high priority workqueue for IH work Felix Kuehling
     [not found]     ` <1508545400-24338-17-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org>
2017-10-25 12:21       ` Oded Gabbay
2017-10-25  6:57   ` [PATCH 00/16] KFD interrupt and signal event handling improvements Oded Gabbay
     [not found]     ` <CAFCwf11ao-E7Y+LvE6e++74xq+RiH+B1xA9nrk_u_8CTXyUuVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-10-25  7:31       ` Christian König
2017-10-25 16:04       ` Felix Kuehling

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=1508545400-24338-8-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 \
    /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.