The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Philipp Stanner <phasta@kernel.org>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	Alex Deucher <alexander.deucher@amd.com>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Matthew Brost <matthew.brost@intel.com>,
	Danilo Krummrich <dakr@kernel.org>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
	Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>,
	Shahyan Soltani <shahyan.soltani@amd.com>,
	Ruslan Vagner <rusya92266@gmail.com>,
	"Mario Limonciello (AMD)" <superm1@kernel.org>,
	Gustavo Padovan <gustavo.padovan@collabora.com>,
	Chris Wilson <chris@chris-wilson.co.uk>
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: Re: [PATCH v2 2/3] drm/sched: Prevent overwrite of non-existing timestamp
Date: Tue, 1 Dec 2026 15:09:18 +0100	[thread overview]
Message-ID: <10b66979-1e30-4e01-97fd-72b62fc23b0c@amd.com> (raw)
In-Reply-To: <20261201091712.716354-4-phasta@kernel.org>



On 12/1/26 10:17, Philipp Stanner wrote:
> 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. On more weakly ordered architectures, however, bugs could arise
> at any moment since this is UB.
> 
> The current misordering allows for the bit DMA_FENCE_FLAG_TIMESTAMP_BIT
> to be read as true before the union containing the timestamp actually
> has the timestamp set.

That is unproblematic as far as I can see.

> 
> drm_sched currently (sort of illegally) overwrites a fence's timestamp.
> To do that somewhat safely, you have to wait for the timestamp to be
> present, otherwise you overwrite another member of the union whose
> memory the timestamp shares.

That here is the real problem, but is that actually possible?

> 
> Ensure correct ordering in the scheduler's timestamp evaluation through
> test_bit_acquire().
> 
> Cc: stable@vger.kernel.org
> Fixes: f7fe64ad0f22 ("drm/sched: Split free_job into own work item")
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>  drivers/gpu/drm/scheduler/sched_main.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 99252674e266..1a40a3549d7a 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -928,8 +928,19 @@ drm_sched_get_finished_job(struct drm_gpu_scheduler *sched)
>  		next = list_first_entry_or_null(&sched->pending_list,
>  						typeof(*next), list);
>  		if (next) {
> -			/* make the scheduled timestamp more accurate */
> -			if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT,
> +			/* Make the scheduled timestamp more accurate.
> +			 *
> +			 * TODO:
> +			 * Stop overwriting a fence's timestamp.
> +			 *
> +			 * test_bit_acquire() ensures ordering so that only
> +			 * timestamps that are actually present already get
> +			 * overwritten (timestamp is a union).
> +			 *
> +			 * The counter-part of the barrier is located in
> +			 * dma_fence_signal_timestamp_locked().
> +			 */
> +			if (test_bit_acquire(DMA_FENCE_FLAG_TIMESTAMP_BIT,
>  				     &next->s_fence->scheduled.flags))
>  				next->s_fence->scheduled.timestamp =
>  					dma_fence_timestamp(&job->s_fence->finished);


  reply	other threads:[~2026-12-01 14:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:17 [PATCH v2 0/3] dma-fence: Properly order timestamps Philipp Stanner
2026-12-01  9:17 ` [PATCH v2 1/3] dma-buf: dma-fence: Fix timestamp misordering Philipp Stanner
2026-12-01 10:57   ` Tvrtko Ursulin
2026-12-01 13:43   ` Christian König
2026-12-01  9:17 ` [PATCH v2 2/3] drm/sched: Prevent overwrite of non-existing timestamp Philipp Stanner
2026-12-01 14:09   ` Christian König [this message]
2026-12-01  9:17 ` [PATCH v2 3/3] drm/amdgpu: Fix timestamp misordering Philipp Stanner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10b66979-1e30-4e01-97fd-72b62fc23b0c@amd.com \
    --to=christian.koenig@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo.padovan@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.brost@intel.com \
    --cc=mripard@kernel.org \
    --cc=phasta@kernel.org \
    --cc=pierre-eric.pelloux-prayer@amd.com \
    --cc=rusya92266@gmail.com \
    --cc=shahyan.soltani@amd.com \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=superm1@kernel.org \
    --cc=tvrtko.ursulin@igalia.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox