Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3871975pxb; Tue, 17 Nov 2020 05:54:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+jvFAMR76JPr4Ye17fII4f23oj+mirRIh1TnBFaBYwu34jgRI3667v1Obrg4t22HV1ohH X-Received: by 2002:a05:6402:b8b:: with SMTP id cf11mr20931945edb.74.1605621268511; Tue, 17 Nov 2020 05:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621268; cv=none; d=google.com; s=arc-20160816; b=tHfzV8KVh2aE71L/ZySOHkZhxlAA12RMtj46mIw/z5oPdTzWw0kzLYn77J1Vt7eMuL 8pzu6+Kasnzdn20klxeRh/DjkIjl1Mod1WgwtQIj7MwYiKG2wESiC3wn56WzfABey/Mk 8JnTljGd5eWoVbctSNlg0DGkHNw7DhU8snpc0vSjAPTGpAIRWGGRkdwst9v2GTIYunRu iSq3PsGNjIa9W1mVP98Yxe0NhWkK+Vuey1JY8X3m7LL2PGC4gckKgjJLlF5mdEqyGU3A W03h8pN8RTMiLLvElZaZqpsiCg9ZTn7djBgxwzikUlDzFdtKb6gV68V37KG4EbAdpzrU 7XcQ== 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=PJ8HJQB5YCbyar3T1miO9FVog+EZr+gpsbVX2yDY76s=; b=EeXbMY8fWh2dVZu3qgjf9DUZWzbP1yLPfm2J8t0S2m1EkrKJTBmspZM2Rp0QWKSi8O C5il8E4bFgPww0SZ4oHFjsuvSAMSwtUn7T6LZ/+pxnpCwYqG+oIDvxgi4hHXF8e8Brj8 DlwFMcb6KDqC5wQuqh2Amexy7AAQh8TwKnc8ax0mbnsqjsX7ukw1OpV3YePZ6mfSC6hk +sMKp1RJaME/IE4wjgqOxJI0UoHyewXzmwBgbbg79b9uTsIJTMrYoKnmIWGJxOpVLgJ0 b0dXtBv0rvnisoo+YEWQx05KXspqKt/h4vP7AmF+ZWCtdOl4AC9m+j3E24gwQ78VAHBY Yp8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j9emVM3I; 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=fail (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 v10si13474659ejg.0.2020.11.17.05.54.05; Tue, 17 Nov 2020 05:54:28 -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=@kernel.org header.s=default header.b=j9emVM3I; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731983AbgKQNa7 (ORCPT + 99 others); Tue, 17 Nov 2020 08:30:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:39710 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731758AbgKQNae (ORCPT ); Tue, 17 Nov 2020 08:30:34 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B2FD20781; Tue, 17 Nov 2020 13:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619835; bh=FXhnEZUHqx+tUFAwV1GiZtp7xAjItAUvEr3Lkrfh9w8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j9emVM3IxVjC/h9YjemngtBl98UXLR4ddrOfo+jLvNZ89IBvc58pbgSvMZW6pXp3g YciQzluG+C9rISSpeoJe6Bq0JpDDjQnmMS42t9HIAlqgp+cFB1D/a5UTlV704+fuSl onVx8sgZAc+cFt3dtetg4PGXaUI36TX1fyGz8tKw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Zbigniew=20Kempczy=C5=84ski?= , Chris Wilson , Joonas Lahtinen , Matthew Auld , Matthew Auld , Rodrigo Vivi , Sasha Levin Subject: [PATCH 5.9 002/255] drm/i915/gem: Flush coherency domains on first set-domain-ioctl Date: Tue, 17 Nov 2020 14:02:22 +0100 Message-Id: <20201117122139.047545665@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@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 [ Upstream commit 59dd13ad310793757e34afa489dd6fc8544fc3da ] Avoid skipping what appears to be a no-op set-domain-ioctl if the cache coherency state is inconsistent with our target domain. This also has the utility of using the population of the pages to validate the backing store. The danger in skipping the first set-domain is leaving the cache inconsistent and submitting stale data, or worse leaving the clean data in the cache and not flushing it to the GPU. The impact should be small as it requires a no-op set-domain as the very first ioctl in a particular sequence not found in typical userspace. Reported-by: Zbigniew Kempczyński Fixes: 754a25442705 ("drm/i915: Skip object locking around a no-op set-domain ioctl") Testcase: igt/gem_mmap_offset/blt-coherency Signed-off-by: Chris Wilson Cc: Joonas Lahtinen Cc: Matthew Auld Cc: Zbigniew Kempczyński Cc: # v5.2+ Reviewed-by: Matthew Auld Link: https://patchwork.freedesktop.org/patch/msgid/20201019203825.10966-1-chris@chris-wilson.co.uk (cherry picked from commit 44c2200afcd59f441b43f27829b4003397cc495d) Signed-off-by: Rodrigo Vivi Signed-off-by: Sasha Levin --- drivers/gpu/drm/i915/gem/i915_gem_domain.c | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_domain.c b/drivers/gpu/drm/i915/gem/i915_gem_domain.c index 7f76fc68f498a..ba8758011e297 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_domain.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_domain.c @@ -484,21 +484,6 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, if (!obj) return -ENOENT; - /* - * Already in the desired write domain? Nothing for us to do! - * - * We apply a little bit of cunning here to catch a broader set of - * no-ops. If obj->write_domain is set, we must be in the same - * obj->read_domains, and only that domain. Therefore, if that - * obj->write_domain matches the request read_domains, we are - * already in the same read/write domain and can skip the operation, - * without having to further check the requested write_domain. - */ - if (READ_ONCE(obj->write_domain) == read_domains) { - err = 0; - goto out; - } - /* * Try to flush the object off the GPU without holding the lock. * We will repeat the flush holding the lock in the normal manner @@ -536,6 +521,19 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, if (err) goto out; + /* + * Already in the desired write domain? Nothing for us to do! + * + * We apply a little bit of cunning here to catch a broader set of + * no-ops. If obj->write_domain is set, we must be in the same + * obj->read_domains, and only that domain. Therefore, if that + * obj->write_domain matches the request read_domains, we are + * already in the same read/write domain and can skip the operation, + * without having to further check the requested write_domain. + */ + if (READ_ONCE(obj->write_domain) == read_domains) + goto out_unpin; + err = i915_gem_object_lock_interruptible(obj); if (err) goto out_unpin; -- 2.27.0