From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382200; b=a8BXX/YPGuWo0UA+5qFFg0swMXk5lPXWYyyvL//UcXe+Ptxb+K+/TSYEuynLaIU3JR1T ji/UP8Tb3mSKK1DaQ3yu/+EMo0ghMIdR2prB0HLGt144C7GuXCzk6/bydRUvXkxzV3xD4 TATkArZU1NFxPYbdHpYTHfM7STdyBa60dR3BmdeMMzKum7+NKcA48ZQXGL54e5xKdmXfN S9IxgRmYxI4m4vy6cFd05ARB9EkaBzgicpUIWudntOR2YyYB+pjnGaWdUwOHZQlCNI4Ro Ume7fO7J/gzvMmoVda5ZFux/y6e3kGQrEDu8Oz1oC7dNdXMlCB3j5LmEtRXQPzKbGgw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382200; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=k05ty+25O1sxNtO2Nf2dCZd+bis5+w12iIqkGiIESFU=; b=hZbD7ZyExj8JL7QJ7WdBPEdjCPR5d9AYeWlkXjHr5Gk5kyONkKmw9TiXmRQ7eYq9sYpn rgf2JI+cHGENeXJB+Z0/IAPRP83sCAFXPNMMj9XAGo3jv4S2eCaYS20i47nbW+7hKdWwO 7jLfV/CDsFOr1CFMiehN7fdcvtBbCPXfX03PpxBOfTpObH49zwDfB21zNY26iltHtAMP6 bagLw9yfqagPJgCXgleB2gHVdaemmk+cHT7sB534knizPFOjl2ZheYzFGGN/Th+3Z+LQI SRiL6cB63L8ZdnfzbW5A4T4al4kI8OmFAEuBap9O8GStWaoiznRlak43pv4Us2WDiVA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EA4OXDA1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87614606A322; Fri, 4 Dec 2026 11:03:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=EA4OXDA1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00AA71F000C2; Fri, 4 Dec 2026 11:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382200; bh=k05ty+25O1sxNtO2Nf2dCZd+bis5+w12iIqkGiIESFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EA4OXDA1Ia7rR3X0yPGKJHqw4WuJ3FGyRwBQbFW1o5csyeM+ITccFbAL8hXr1zy2P cVmxYGu13bePI8SXf7KVam8M9DLh6Ixj0jbqOKZlNdA3VcipPfwlwmYiq3lfBHvRDx GHOHRls7bHWeMOAajpK4iWF29yW+qvswOSv51hqw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Umesh Nerlige Ramappa , Matthew Brost , Rodrigo Vivi , Aleksander Czerwionka , Sanjay Yadav Subject: [PATCH 6.18 351/703] drm/xe/query: Use ordered clock reads for engine cycles cpu_delta Date: Fri, 4 Dec 2026 19:04:10 +0900 Message-ID: <20261204100637.135575064@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sanjay Yadav commit 65ef9dec511c018bcbe5993e9749c52c26e573e2 upstream. cpu_delta is meant to bound the time taken to read the engine timestamp register, but it is measured with local_clock(), which on x86 is a plain RDTSC that is not ordered against loads. Either end of the window can thus be sampled while an earlier MMIO read is still in flight. A reproducer looping on DRM_XE_DEVICE_QUERY_ENGINE_CYCLES on BMG reports cpu_delta as low as 18 ns, while the MMIO read alone takes > 1.5 us. Use ktime_get_raw_ns() at both ends instead. Its clocksource read is ordered (rdtsc_ordered() on x86). With this, the reproducer reports min/median cpu_delta of 1567/1745 ns and no short values. Fixes: 7793d00d1bf5 ("drm/xe: Correlate engine and cpu timestamps with better accuracy") Cc: # v6.8+ Cc: Umesh Nerlige Ramappa Cc: Matthew Brost Cc: Rodrigo Vivi Suggested-by: Aleksander Czerwionka Signed-off-by: Sanjay Yadav Reviewed-by: Umesh Nerlige Ramappa Signed-off-by: Umesh Nerlige Ramappa Link: https://patch.msgid.link/20261111090401.975803-2-sanjay.kumar.yadav@intel.com (cherry picked from commit 146dec4ce1f0794fefe5ad1d549655745358b515) Signed-off-by: Matthew Brost Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/xe/xe_query.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/gpu/drm/xe/xe_query.c +++ b/drivers/gpu/drm/xe/xe_query.c @@ -6,7 +6,6 @@ #include "xe_query.h" #include -#include #include #include @@ -97,13 +96,14 @@ hwe_read_timestamp(struct xe_hw_engine * u32 upper, lower, old_upper, loop = 0; struct xe_reg upper_reg = RING_TIMESTAMP_UDW(hwe->mmio_base), lower_reg = RING_TIMESTAMP(hwe->mmio_base); + u64 delta_start; upper = xe_mmio_read32(mmio, upper_reg); do { - *cpu_delta = local_clock(); + delta_start = ktime_get_raw_ns(); *cpu_ts = cpu_clock(); lower = xe_mmio_read32(mmio, lower_reg); - *cpu_delta = local_clock() - *cpu_delta; + *cpu_delta = ktime_get_raw_ns() - delta_start; old_upper = upper; upper = xe_mmio_read32(mmio, upper_reg); } while (upper != old_upper && loop++ < 2);