Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp725980pxb; Tue, 2 Feb 2021 16:49:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOdL7dogA0hHQubCmbrARmqUfhwZUEbUs9M2aRColqRdqYKDHoN7fiFNInqht4mETcVP2F X-Received: by 2002:a17:906:af6b:: with SMTP id os11mr625232ejb.472.1612313378717; Tue, 02 Feb 2021 16:49:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612313378; cv=none; d=google.com; s=arc-20160816; b=Tq3xQZCorrSgaW07ev+nGF9eMOMzD7kwNFSCPBEr1pgu9CYW1GCJ2etGKNDECcCiaZ DPehgNKUL6dd/L0nxDPfWpLhKqcIIAj2jO1Dbs4Hw29L8e4fppLvj42jDLAUYaU8BsAK HNAFt9yAY8LbqsGiLWOb3fIjpkg0d76+iqxkV7A1GzyGJbei0uD5tvP+uZIbZOOGFTIV 8SmDwgGvuLorEKaGqXZDEIwTDVzm7WTMND4oN4e16EGWjf4klXxr7A5Nz3tBPjHKSkQb Nz+1Lbe/ucgHI7whf+oV1rwQXbKaEWDGub/PFePoBWjpE03oai8S+5PPcxpO/CDvqbYk S7kQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ElA/A1JBM1NK1EzWYTUI+0QX96SDtj6zsKCLoMO8SHY=; b=UwnHpM1ImvskGrUStEJm0C0F7RGzsvQ88VHrXQxGrqIEWqdwnnjh1CFC+wG2cyNIG3 0GljTi6ykaW7Re+A4Lv1LoOVUQhMkHADWSiy68QsdscgKAf2WXr6Hls/d/bAu7KEJ5Uf d1Tk+6oOwjH6rIWzKuV/fNCu7/8dTaliEYlaK+hV0hCBBuGjcy725L/zU9xtsMi5aE0C I51keZ/Te4sMARrh15X/Z3fq6Vm8NUUwN/Ro6vGddaU6d+dVjjVqb8z4ngGo8/zhU8vu VNSd5giBJafmUMnFkLknScHd6LScEp4Fbz9fuum4NxBkgOzbpvWEI7nM2V36N8VzA8f+ RMJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X2wxaZw9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o15si296732ejx.665.2021.02.02.16.49.13; Tue, 02 Feb 2021 16:49:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X2wxaZw9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240379AbhBBUGH (ORCPT + 99 others); Tue, 2 Feb 2021 15:06:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:36544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232715AbhBBNnN (ORCPT ); Tue, 2 Feb 2021 08:43:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4110F64F69; Tue, 2 Feb 2021 13:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612273216; bh=SuaqPjJeRzovVcZthpTQGI6mBv/Tovh+I0x//MkMnWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X2wxaZw9nJXI6iVIUqL4x7ZqF+VJcNbCRkahAwPWMRJ27i0iBIBMaRFmeyKICJY8X N9eYdE+50WQ9M1oJCemrFqOiRnbUjHECHXLRRlzXmeAwszgGhSdcRt0ekSfQThgfbU 8P81m3OoeB6MYqbNpXgbnX5DLsj1aOYqVguOVKVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Matthew Auld , Tvrtko Ursulin , Jani Nikula Subject: [PATCH 5.10 024/142] drm/i915: Always flush the active worker before returning from the wait Date: Tue, 2 Feb 2021 14:36:27 +0100 Message-Id: <20210202132958.712870599@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210202132957.692094111@linuxfoundation.org> References: <20210202132957.692094111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chris Wilson commit f6e98a1809faa02f40e0d089d6cfc1aa372a34c0 upstream. The first thing the active retirement worker does is decrement the i915_active count. The first thing we do during i915_active_wait is try to increment the i915_active count, but only if already active [non-zero]. The wait may see that the retirement is already started and so marked the i915_active as idle, and skip waiting for the retirement handler. However, the caller of i915_active_wait may immediately free the i915_active upon returning (e.g. i915_vma_destroy) so we must not return before the concurrent access from the worker is completed. We must always flush the worker. Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/2473 Fixes: 274cbf20fd10 ("drm/i915: Push the i915_active.retire into a worker") Signed-off-by: Chris Wilson Cc: Matthew Auld Cc: Tvrtko Ursulin Cc: # v5.5+ Reviewed-by: Matthew Auld Link: https://patchwork.freedesktop.org/patch/msgid/20210121232807.16618-1-chris@chris-wilson.co.uk (cherry picked from commit 977a372e972cb42799746c284035a33c64ebace9) Signed-off-by: Jani Nikula Signed-off-by: Greg Kroah-Hartman diff --git a/drivers/gpu/drm/i915/i915_active.c b/drivers/gpu/drm/i915/i915_active.c index 10a865f3dc09..9ed19b8bca60 100644 --- a/drivers/gpu/drm/i915/i915_active.c +++ b/drivers/gpu/drm/i915/i915_active.c @@ -631,24 +631,26 @@ static int flush_lazy_signals(struct i915_active *ref) int __i915_active_wait(struct i915_active *ref, int state) { - int err; - might_sleep(); - if (!i915_active_acquire_if_busy(ref)) - return 0; - /* Any fence added after the wait begins will not be auto-signaled */ - err = flush_lazy_signals(ref); - i915_active_release(ref); - if (err) - return err; + if (i915_active_acquire_if_busy(ref)) { + int err; - if (!i915_active_is_idle(ref) && - ___wait_var_event(ref, i915_active_is_idle(ref), - state, 0, 0, schedule())) - return -EINTR; + err = flush_lazy_signals(ref); + i915_active_release(ref); + if (err) + return err; + if (___wait_var_event(ref, i915_active_is_idle(ref), + state, 0, 0, schedule())) + return -EINTR; + } + + /* + * After the wait is complete, the caller may free the active. + * We have to flush any concurrent retirement before returning. + */ flush_work(&ref->work); return 0; }