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 5E9DAC43458 for ; Tue, 7 Jul 2026 20:08:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B92DC10E29A; Tue, 7 Jul 2026 20:08:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="UUSjl7YA"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 19BB110E29A for ; Tue, 7 Jul 2026 20:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=fjrFh7LPxqIVsPzhhkZi9bSCfDkNO5Nv+dwFa29Cj2U=; b=UUSjl7YAL7FMGSJRk/9RK4zl9r Ed5Nbrsnu0ROY30yz+9pPFVN6pyaADVEsA7sO9CCW/qLKcnNltzFRSRk+dgM5N6bjCDSmcrhwcGdD LTVYa8eTLl0IU80Nxu679uFuxAohNw+HGD4c3pCCWLGt+gVwT60XiGaLIiX8cYOisXV2dexl9EsaR HOxOZMbYN+Gu472DeqgUkkjSFz3n0lZQ1g/f7yS8dNuxmCaPvvBuRqwK26QZgSqhLQoCm0Vr0WEJm MAlHG4vumCYqyNpqf57pPsL/zltD8xEEhFvt0yQneJzD1JAxBe1oUN2MnYIX1dxD/JdqQf4ro/H0z I5NyD1Dg==; Received: from [189.7.87.67] (helo=prince) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1whC5J-00B2R1-Ic; Tue, 07 Jul 2026 22:08:02 +0200 From: =?UTF-8?q?Ma=C3=ADra=20Canal?= To: Melissa Wen , Iago Toral , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, kernel-dev@igalia.com, =?UTF-8?q?Ma=C3=ADra=20Canal?= , stable@vger.kernel.org Subject: [PATCH] drm/v3d: Widen cache_clean_lock over the whole L2TCACTL sequence Date: Tue, 7 Jul 2026 17:05:48 -0300 Message-ID: <20260707200738.659002-2-mcanal@igalia.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" v3d_clean_caches() and v3d_flush_l2t() both write the single L2TCACTL register and poll its status bits. The mutex cache_clean_lock exists to serialize them, but v3d_clean_caches() only took the lock around its final FLM_CLEAN write. These functions run concurrently: v3d_flush_l2t() is issued from the BIN/RENDER/CSD invalidate path while v3d_clean_caches() runs from the CACHE_CLEAN queue, and each queue's scheduler uses its own ordered workqueue, so their run_job callbacks execute in parallel. Because clean locked only its final write, a concurrent flush can write L2TCACTL during clean's unlocked phase. Both use non read-modify-write writes to the one register, so whichever lands last wins: clean's TMUWCF write can land on the flush's in-flight L2TFLS invalidate, triggering the GFXH-1897 hazard of writing L2TCACTL while a flush is pending. Hold cache_clean_lock across the entire L2TCACTL access sequence so it is fully mutually exclusive with v3d_flush_l2t(), which already takes the lock around its own write. Cc: stable@vger.kernel.org Fixes: abf888b03a98 ("drm/v3d: Wait for pending L2T flush before cleaning caches") Signed-off-by: MaĆ­ra Canal --- drivers/gpu/drm/v3d/v3d_gem.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c index c43d9af41374..e597b6fd47c4 100644 --- a/drivers/gpu/drm/v3d/v3d_gem.c +++ b/drivers/gpu/drm/v3d/v3d_gem.c @@ -204,6 +204,8 @@ v3d_clean_caches(struct v3d_dev *v3d) struct drm_device *dev = &v3d->drm; int core = 0; + guard(mutex)(&v3d->cache_clean_lock); + trace_v3d_cache_clean_begin(dev); /* GFXH-1897: Ensure pending flushes complete before writing L2TCACTL */ @@ -220,7 +222,6 @@ v3d_clean_caches(struct v3d_dev *v3d) drm_err(dev, "Timeout waiting for TMU write combiner flush\n"); } - mutex_lock(&v3d->cache_clean_lock); V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL, V3D_L2TCACTL_L2TFLS | V3D_SET_FIELD(V3D_L2TCACTL_FLM_CLEAN, V3D_L2TCACTL_FLM)); @@ -230,8 +231,6 @@ v3d_clean_caches(struct v3d_dev *v3d) drm_err(dev, "Timeout waiting for L2T clean\n"); } - mutex_unlock(&v3d->cache_clean_lock); - trace_v3d_cache_clean_end(dev); } -- 2.54.0