From patchwork Wed Nov 9 19:09:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 17767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp513915wru; Wed, 9 Nov 2022 11:11:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM5m6oN173kd2A8VSucczQwfaTwgRVhFY9g15i+y4g0IE1tCxHj3v7yuEmvIS09byv9q/mBf X-Received: by 2002:a17:907:a808:b0:7ad:caf4:9e92 with SMTP id vo8-20020a170907a80800b007adcaf49e92mr1557749ejc.510.1668021114386; Wed, 09 Nov 2022 11:11:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668021114; cv=none; d=google.com; s=arc-20160816; b=XvNRkmW4nLR4WpXhFQl8lyvMaIe5FcQRxf44XIkgA/WmIQLf358Ygxu3XF6iZ4pZzO ZXhZxw964Kjcx66Gl1bCQySKOCOJ3h36hjsuQZIoGdx1yU+/kC24KNfcQOsiEhZBBahY iF0sBUvvF7AjnLmti5bB3YJ/AbpPasV4xZVwHul0O2M60O13IFW4akg5BWZ2g7NtHxtx SC6UuvNY6/7pXTOQcc07JSIGJLkI8Zbv++CqKimxNqGZS2xzpYhYzRlEuVH8jAbCHNQ6 tXswKyZNiIEM7N9VeRsRXQCuOU4BZbAI5MIWArrCvrk/XfX3jdjK1e5fo5a6yceq4pqw DX1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RNfDq9r/I5/CejdahrCZIvUvcV+/QqlRpV7No6EP2So=; b=Ab7dCu5/KOuH1m36VSBJP4ExGCjRrWWkhw3rKn6bglvsWF0Cl1+IWvhNWtTwaDwl7r Bek0t+a/1CiWRaD1SWZDc/++Zt5rlFQu8PIZaAPCjLnRSQzvu8IBjfnXQQ7s6OcuYVkx 9E5/K6RLl/Puz4Bv8weU2GnIhAGWDhH+VbhprdN34L1FwRRCb0MkUFgg/WCCWeT9ImFm HHtO1MGIh2SkyRlFbFOdFzLn/j99GyTkW1yAWzMdUrPzNdWLoQUsM3xcwYb9UHYGyQ5l PR6yTM9MQdgAG98f/fUxfl9mqBg4t1hLGXEpUXmTpeJjkfkZTtBnzifqfoe+AewUVKns wCSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lQXr/GQG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn1-20020a1709070d0100b00791a41d1b39si16324061ejc.656.2022.11.09.11.11.29; Wed, 09 Nov 2022 11:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="lQXr/GQG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231272AbiKITKb (ORCPT + 99 others); Wed, 9 Nov 2022 14:10:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbiKITK3 (ORCPT ); Wed, 9 Nov 2022 14:10:29 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF22E272C for ; Wed, 9 Nov 2022 11:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668021028; x=1699557028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DsqDFyDE3Xf+Eud5zTFYaL4RaK2z0k0BfhahtubW9bI=; b=lQXr/GQG25ERBKZ2yqqrNKLVWY/vkbNNENKNoMB5vdzBGJ9bPKNUXVlk pF3eCi8X7NT0TMr15gHgeOGDmOH1So4aSso2A4Fx8tcnrutfpJK4It5IS hCI2UNUAbMcQU4uHlXK2FHHGZf1Othrk9cY4oXo3pP7xkghbY+GCvKtDm 5Uelki0ID7mYgab1aW40bssQlnwARXFmTV6Y3RWNoItSGIWIIBCe8+zJ/ l3JtX04AUX1J13uSdujIVQ7V3UNN+SqcprVDdo6dZ8JN9EJvGGRQGlrR2 NPm9nedTuf4ohMXGZvWJ/gZ0toxVzh0VIdplhEdc3l709XBkV0zGCBk7d w==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="311072244" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="311072244" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 11:10:25 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="668105815" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="668105815" Received: from jkrzyszt-mobl1.ger.corp.intel.com ([10.213.6.201]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 11:10:22 -0800 From: Janusz Krzysztofik To: Joonas Lahtinen Cc: Jani Nikula , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , Chris Wilson , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] drm/i915: Fix timeout handling when retiring requests Date: Wed, 9 Nov 2022 20:09:35 +0100 Message-Id: <20221109190937.64155-2-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221109190937.64155-1-janusz.krzysztofik@linux.intel.com> References: <20221109190937.64155-1-janusz.krzysztofik@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749046908489893828?= X-GMAIL-MSGID: =?utf-8?q?1749046908489893828?= I believe that intel_gt_retire_requests_timeout() should return either -ETIME if all time designated by timeout argument has been consumed while waiting for fences being signaled, or remaining time if there are requests still not retired, or 0 otherwise. In the latter case, remaining time should be passed back via remaining_timeout argument. Remaining time is updated with return value of each consecutive call to dma_fence_wait_timeout(). If an error code is returned instead of remaining time, a few potentially unexpected side effects occur: - we no longer wait for consecutive timelines' last request fences being signaled before we try to retire requests from those timelines -- while expected in case of -ETIME, that's probably not intended in case of other errors that dma_fence_wait_timeout() can return, - the error code (a negative value) is passed back as remaining time and if no more requests happen to be left pending despite the error, a user may pass that value forward as a remaining timeout -- that can potentially trigger a WARN or BUG, - potentially unexpected error code is returned to user when a non-critical error that probably shouldn't stop the user from retrying occurs while active requests are still pending. Moreover, should dma_fence_wait_timeout() ever return 0 (which should mean timeout expiration) while we are processing requests and there are still pending requests when we are about to return, that 0 value is returned to user like if all requests were successfully retired. Ignore error codes from dma_fence_wait_timeout() other than -ETIME and don't overwrite remaining time with those error codes. Also, convert 0 value returned by dma_fence_wait_timeout() to -ETIME. Fixes: f33a8a51602c ("drm/i915: Merge wait_for_timelines with retire_request") Signed-off-by: Janusz Krzysztofik Cc: stable@vger.kernel.org # v5.5+ --- drivers/gpu/drm/i915/gt/intel_gt_requests.c | 17 ++++++++++++++--- 1 file changed, 14 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..6c3b8ac3055c3 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt_requests.c +++ b/drivers/gpu/drm/i915/gt/intel_gt_requests.c @@ -156,11 +156,22 @@ long intel_gt_retire_requests_timeout(struct intel_gt *gt, long timeout, fence = i915_active_fence_get(&tl->last_request); if (fence) { + signed long time_left; + mutex_unlock(&tl->mutex); - timeout = dma_fence_wait_timeout(fence, - true, - timeout); + time_left = dma_fence_wait_timeout(fence, + true, + timeout); + /* + * 0 or -ETIME: timeout expired + * other errors: ignore, assume no time consumed + */ + if (time_left == -ETIME || time_left == 0) + timeout = -ETIME; + else if (time_left > 0) + timeout = time_left; + dma_fence_put(fence); /* Retirement is best effort */