From patchwork Wed Nov 16 11:25:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13044968 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76182C4321E for ; Wed, 16 Nov 2022 11:26:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E83BC10E47D; Wed, 16 Nov 2022 11:26:04 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 590D510E478; Wed, 16 Nov 2022 11:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668597959; x=1700133959; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9RcXpzp2jK/yGykS8Id+3Adle5bDDZsqw2k/4otRQ+w=; b=Aak3nyx/lvitfD+PFJua77MWakygiEvAnBggRrUCAy0V4PAPZS6kY5lC ZK5kwCTHUJKJ/n0lrg3Tbf+YW55Vt4nZjoPYqs994CXsT/eoNaypB0sGb nIYxSt3Yoym5u1IcX3yNAQtTlkqmv30LlVkgzZp4ccV3zOaXE+93bCEVD iJNCEGMFzHvWFMbEYaDqiDQi1IGRLaNCrZU0PlyiZFYnkS2o4BqhjIgXx ai+G2pr3w0UUd6VveKtWoE9El0TWZjYClG8nELf/UKg8zouFyaH3BfPNe cjjM/wfwwGecNpPYpJqH7ozE9Vxyy8sDnghpTyC28ATOwp//3aT44j2qW g==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="295885150" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="295885150" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:25:59 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="670468932" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="670468932" Received: from jkrzyszt-mobl1.ger.corp.intel.com ([10.213.12.208]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:25:56 -0800 From: Janusz Krzysztofik To: Tvrtko Ursulin , Joonas Lahtinen Date: Wed, 16 Nov 2022 12:25:30 +0100 Message-Id: <20221116112532.36253-2-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221116112532.36253-1-janusz.krzysztofik@linux.intel.com> References: <20221116112532.36253-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/3] drm/i915: Fix negative remaining time after retire requests X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , dri-devel@lists.freedesktop.org, Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Commit b97060a99b01 ("drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC") extended the API of intel_gt_retire_requests_timeout() with an extra argument 'remaining_timeout', intended for passing back unconsumed portion of requested timeout when 0 (success) is returned. However, when request retirement happens to succeed despite an error returned by dma_fence_wait_timeout(), the error code (a negative value) is passed back instead of remaining time. If a user then passes that negative value forward as requested timeout to another wait, an explicit WARN or BUG can be triggered. Instead of copying the value of timeout variable to *remaining_timeout before return, update the *remaining_timeout after each DMA fence wait. Set it to 0 on -ETIME, -EINTR or -ERESTARTSYS, and assume no time has been consumed on other errors returned from the wait. Fixes: b97060a99b01 ("drm/i915/guc: Update intel_gt_wait_for_idle to work with GuC") Signed-off-by: Janusz Krzysztofik Cc: stable@vger.kernel.org # v5.15+ Reviewed-by: Andrzej Hajda Acked-by: Nirmoy Das --- drivers/gpu/drm/i915/gt/intel_gt_requests.c | 23 ++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_requests.c b/drivers/gpu/drm/i915/gt/intel_gt_requests.c index edb881d756309..ccaf2fd80625b 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_requests.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_requests.c @@ -138,6 +138,9 @@ long intel_gt_retire_requests_timeout(struct intel_gt *gt, long timeout, unsigned long active_count = 0; LIST_HEAD(free); + if (remaining_timeout) + *remaining_timeout = timeout; + flush_submission(gt, timeout); /* kick the ksoftirqd tasklets */ spin_lock(&timelines->lock); list_for_each_entry_safe(tl, tn, &timelines->active_list, link) { @@ -163,6 +166,23 @@ long intel_gt_retire_requests_timeout(struct intel_gt *gt, long timeout, timeout); dma_fence_put(fence); + if (remaining_timeout) { + /* + * If we get an error here but request + * retirement succeeds anyway + * (!active_count) and we return 0, the + * caller may want to spend remaining + * time on waiting for other events. + */ + if (timeout == -ETIME || + timeout == -EINTR || + timeout == -ERESTARTSYS) + *remaining_timeout = 0; + else if (timeout >= 0) + *remaining_timeout = timeout; + /* else assume no time consumed */ + } + /* Retirement is best effort */ if (!mutex_trylock(&tl->mutex)) { active_count++; @@ -196,9 +216,6 @@ out_active: spin_lock(&timelines->lock); if (flush_submission(gt, timeout)) /* Wait, there's more! */ active_count++; - if (remaining_timeout) - *remaining_timeout = timeout; - return active_count ? timeout : 0; } From patchwork Wed Nov 16 11:25:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13044969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54F54C43219 for ; Wed, 16 Nov 2022 11:26:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E32A10E487; Wed, 16 Nov 2022 11:26:19 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 501C410E47D; Wed, 16 Nov 2022 11:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668597963; x=1700133963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eqH3EStze88zMcUpQM7CyuSzBu94jD0o2LohB7AWFeQ=; b=K5VxSEEg4aF5dXnOGA6EKCrPXaPyOQS8esJcf6pRENJzxZ8mVaiYU2/n YtPdJCTLKrfDskm2PcXCCLXLaruvtShvBQaSks6gbQzQkQqpdpcwkdMLi a5IXZkdYJiY41lYC+CtiqPCzjBzD3qCueAgr2W+y4+aXSNdl6ZRZhSkoR seOwvEVzZEoguwrQF66tKlnX5PoFiGIeamfAfNl8yTqUP5UN7a9IpaRd3 cd02JxVHgCsD/NQ+bUJUnbPlwlaW/WZXIR7e7s2r5cSobfRoXdQZRzEEs RTVTS9UjytVuBa9HIKep7G0d1oDxKk0nk3ZBLOfZvMknmk7Dg1IHMVhEE A==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="295885164" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="295885164" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:26:03 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="670468952" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="670468952" Received: from jkrzyszt-mobl1.ger.corp.intel.com ([10.213.12.208]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:25:59 -0800 From: Janusz Krzysztofik To: Tvrtko Ursulin , Joonas Lahtinen Date: Wed, 16 Nov 2022 12:25:31 +0100 Message-Id: <20221116112532.36253-3-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221116112532.36253-1-janusz.krzysztofik@linux.intel.com> References: <20221116112532.36253-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 2/3] drm/i915: Never return 0 on timeout when retiring requests X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , dri-devel@lists.freedesktop.org, Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Users of intel_gt_retire_requests_timeout() expect 0 return value on success. However, we have no protection from passing back 0 potentially returned by dma_fence_wait_timeout() on timeout. Replace 0 with -ETIME before using timeout as return value. Fixes: f33a8a51602c ("drm/i915: Merge wait_for_timelines with retire_request") Signed-off-by: Janusz Krzysztofik Cc: stable@vger.kernel.org # v5.5+ Reviewed-by: Andrzej Hajda Acked-by: Nirmoy Das --- drivers/gpu/drm/i915/gt/intel_gt_requests.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/i915/gt/intel_gt_requests.c b/drivers/gpu/drm/i915/gt/intel_gt_requests.c index ccaf2fd80625b..ac6b2b1861397 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_requests.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_requests.c @@ -213,6 +213,9 @@ out_active: spin_lock(&timelines->lock); list_for_each_entry_safe(tl, tn, &free, link) __intel_timeline_free(&tl->kref); + if (!timeout) + timeout = -ETIME; + if (flush_submission(gt, timeout)) /* Wait, there's more! */ active_count++; From patchwork Wed Nov 16 11:25:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 13044970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD994C433FE for ; Wed, 16 Nov 2022 11:26:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A98E310E48A; Wed, 16 Nov 2022 11:26:21 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2936E10E487; Wed, 16 Nov 2022 11:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668597967; x=1700133967; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=caBLKR0K5Hn/2pyKFe7g3RceXmf+MKUWWxkOKzJWFss=; b=XgUUfSCjJ25XdFFcrolhlwPvSRhDQEEZq73duptcPxBVba1M0TdXFu6f DLztgWBKXK6BZSbthFs7qyXqKlbkYPpn39qNnht9psoR6UKvXu9Qg/u34 CxefLFbvTVf9UxFXAMBHfor1TYLQEKUnedutV5vjauzlesML8JoPXU0eA 5MPaseU/NVc4Cs5twmqT7n2dtnZZjtfs6er6yMfkyLp4Pg1/qOakgzi6X 5Ec589CDS+RJ2dm0Mxzl2vlcXDb5dc/WT5uSKbqM/lqJyeeYBEGxTUoJR UUBtfx1bDKlXTg0cnvkQKHaYZnEsAzzrOcyU7J/9Y1arrHN/ftwl8vWOB w==; X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="295885172" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="295885172" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:26:06 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10532"; a="670468973" X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="670468973" Received: from jkrzyszt-mobl1.ger.corp.intel.com ([10.213.12.208]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Nov 2022 03:26:03 -0800 From: Janusz Krzysztofik To: Tvrtko Ursulin , Joonas Lahtinen Date: Wed, 16 Nov 2022 12:25:32 +0100 Message-Id: <20221116112532.36253-4-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221116112532.36253-1-janusz.krzysztofik@linux.intel.com> References: <20221116112532.36253-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 3/3] drm/i915: Never return 0 if request wait succeeds X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, Chris Wilson , dri-devel@lists.freedesktop.org, Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" According to the docs of i915_request_wait_timeout(), its return value "may be zero if the request is unfinished after the timeout expires." However, 0 is also returned when the request is found finished right after the timeout has expired. Since the docs also state: "If the timeout is 0, it will return 1 if the fence is signaled.", return 1 also when the fence is found signaled after non-zero timeout has expired. Fixes: 7e2e69ed4678 ("drm/i915: Fix i915_request fence wait semantics") Signed-off-by: Janusz Krzysztofik Cc: stable@vger.kernel.org # v5.17 --- drivers/gpu/drm/i915/i915_request.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_request.c b/drivers/gpu/drm/i915/i915_request.c index f949a9495758a..406ddfafbed4d 100644 --- a/drivers/gpu/drm/i915/i915_request.c +++ b/drivers/gpu/drm/i915/i915_request.c @@ -2079,6 +2079,8 @@ long i915_request_wait_timeout(struct i915_request *rq, timeout = io_schedule_timeout(timeout); } + if (!timeout) /* expired but signaled, we shouldn't return 0 */ + timeout = 1; __set_current_state(TASK_RUNNING); if (READ_ONCE(wait.tsk))