From patchwork Thu Sep 20 20:05:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10608695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD1F615A6 for ; Thu, 20 Sep 2018 20:05:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C008B2E029 for ; Thu, 20 Sep 2018 20:05:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3B322E032; Thu, 20 Sep 2018 20:05:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6F9D12E029 for ; Thu, 20 Sep 2018 20:05:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 026E86E653; Thu, 20 Sep 2018 20:05:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id C1D216E652; Thu, 20 Sep 2018 20:05:39 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 13840611-1500050 for multiple; Thu, 20 Sep 2018 21:05:29 +0100 From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm: Fix syncobj handing of schedule() returning 0 Date: Thu, 20 Sep 2018 21:05:30 +0100 Message-Id: <20180920200530.2836-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180920200530.2836-1-chris@chris-wilson.co.uk> References: <20180920200530.2836-1-chris@chris-wilson.co.uk> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP After schedule() returns 0, we must do one last check of COND to determine the reason for the wakeup with 0 jiffies remaining before reporting the timeout -- otherwise we may lose the signal due to scheduler delays. References: https://bugs.freedesktop.org/show_bug.cgi?id=106690 Signed-off-by: Chris Wilson Reviewed-by: Tvrtko Ursulin --- drivers/gpu/drm/drm_syncobj.c | 41 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index e254f97fed7d..5bcb3ef9b256 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -672,7 +672,6 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, { struct syncobj_wait_entry *entries; struct dma_fence *fence; - signed long ret; uint32_t signaled_count, i; entries = kcalloc(count, sizeof(*entries), GFP_KERNEL); @@ -692,7 +691,7 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) { continue; } else { - ret = -EINVAL; + timeout = -EINVAL; goto cleanup_entries; } } @@ -704,12 +703,6 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, } } - /* Initialize ret to the max of timeout and 1. That way, the - * default return value indicates a successful wait and not a - * timeout. - */ - ret = max_t(signed long, timeout, 1); - if (signaled_count == count || (signaled_count > 0 && !(flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL))) @@ -760,18 +753,17 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, goto done_waiting; if (timeout == 0) { - /* If we are doing a 0 timeout wait and we got - * here, then we just timed out. - */ - ret = 0; + timeout = -ETIME; goto done_waiting; } - ret = schedule_timeout(ret); + if (signal_pending(current)) { + timeout = -ERESTARTSYS; + goto done_waiting; + } - if (ret > 0 && signal_pending(current)) - ret = -ERESTARTSYS; - } while (ret > 0); + timeout = schedule_timeout(timeout); + } while (1); done_waiting: __set_current_state(TASK_RUNNING); @@ -788,7 +780,7 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, } kfree(entries); - return ret; + return timeout; } /** @@ -829,19 +821,16 @@ static int drm_syncobj_array_wait(struct drm_device *dev, struct drm_syncobj **syncobjs) { signed long timeout = drm_timeout_abs_to_jiffies(wait->timeout_nsec); - signed long ret = 0; uint32_t first = ~0; - ret = drm_syncobj_array_wait_timeout(syncobjs, - wait->count_handles, - wait->flags, - timeout, &first); - if (ret < 0) - return ret; + timeout = drm_syncobj_array_wait_timeout(syncobjs, + wait->count_handles, + wait->flags, + timeout, &first); + if (timeout < 0) + return timeout; wait->first_signaled = first; - if (ret == 0) - return -ETIME; return 0; }