From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8173606A320 for ; Tue, 1 Dec 2026 09:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Y0Rvr4KL Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 826E510F6BE; Tue, 1 Dec 2026 09:18:00 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 69A6510F6B8; Tue, 1 Dec 2026 09:17:54 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 51FAF412C8; Tue, 1 Dec 2026 09:17:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E812A1F00919; Tue, 1 Dec 2026 09:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796116674; bh=9o2JgsckZYIuPWEYJ68yaNsVx1MTs7HxEV9cN3pPkCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Y0Rvr4KLRX+2yPsovdT1e/TSKSl0ybMFzL9RiBNcrDIL/FPZCw/cytDAmzW3iwFxI aKmOTVk3VmZFeUZM5St2dMdMG+7SH+vaCWZJo+Z8+Mr/80RcD/PIstvn/VwW/GaqsJ oTA7HBEXp/VPsgDX7myvuag57L8Zg7Gkn5S7hRVbPLKyNUgoPpFHPzmaVkWJBvzgfK OZPQ7K0XkpcrsEZ91WTS9JCvHo9hprExII1W0THNYOchVOYJoi1bgD4zjNBSHfnX9l ziZF2Lg2oUzcQZBj4uBMDySFSTD3mHty3UWBQhchO0DYSBQgh1V06XUrRqK62XG1mA QRrP05gqklyxw== From: Philipp Stanner To: Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Philipp Stanner , Alex Deucher , David Airlie , Simona Vetter , Matthew Brost , Danilo Krummrich , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Tvrtko Ursulin , Pierre-Eric Pelloux-Prayer , Shahyan Soltani , Ruslan Vagner , "Mario Limonciello (AMD)" , Gustavo Padovan , Chris Wilson Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, stable@vger.kernel.org Subject: [PATCH v2 3/3] drm/amdgpu: Fix timestamp misordering Date: Tue, 1 Dec 2026 10:17:13 +0100 Message-ID: <20261201091712.716354-5-phasta@kernel.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261201091712.716354-2-phasta@kernel.org> References: <20261201091712.716354-2-phasta@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 dma_fence timestamps could so far be written and read without any memory ordering, a bug that presumably got overlooked because x86 is strongly ordered. The current misordering allows for the bit DMA_FENCE_FLAG_TIMESTAMP_BIT to be read as true before the union containing the timestamp actually gets the timestamp set. Thus, amdgpu could interpret the list-head pointer in the union as a timestamp value by accident. Fix amdgpu's manual timestamp evaluation with test_bit_acquire(). Cc: stable@vger.kernel.org Fixes: af0b54167009 ("drm/amdgpu: Convert to common fdinfo format v5") Signed-off-by: Philipp Stanner Reviewed-by: Tvrtko Ursulin --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index 2f0349233695..415f23aa08a0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -177,11 +177,11 @@ static ktime_t amdgpu_ctx_fence_time(struct dma_fence *fence) /* When the fence is not even scheduled it can't have spend time */ s_fence = to_drm_sched_fence(fence); - if (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->scheduled.flags)) + if (!test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->scheduled.flags)) return ns_to_ktime(0); /* When it is still running account how much already spend */ - if (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->finished.flags)) + if (!test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->finished.flags)) return ktime_sub(ktime_get(), s_fence->scheduled.timestamp); return ktime_sub(s_fence->finished.timestamp, -- 2.56.0