public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Order OP vs. timeout correctly in __wait_for()
@ 2026-03-13 11:07 Ville Syrjala
  2026-03-17 13:07 ` Jani Nikula
  0 siblings, 1 reply; 2+ messages in thread
From: Ville Syrjala @ 2026-03-13 11:07 UTC (permalink / raw)
  To: intel-gfx; +Cc: stable

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Put the barrier() before the OP so that anything we read out in
OP and check in COND will actually be read out after the timeout
has been evaluated.

Currently the only place where we use OP is __intel_wait_for_register(),
but the use there is precisely susceptible to this reordering, assuming
the ktime_*() stuff itself doesn't act as a sufficient barrier:

__intel_wait_for_register(...)
{
	...
	ret = __wait_for(reg_value = intel_uncore_read_notrace(...),
 			 (reg_value & mask) == value, ...);
	...
}

Cc: stable@vger.kernel.org
Fixes: 1c3c1dc66a96 ("drm/i915: Add compiler barrier to wait_for")
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_wait_util.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_wait_util.h b/drivers/gpu/drm/i915/i915_wait_util.h
index 7376898e3bf8..e1ed7921ec70 100644
--- a/drivers/gpu/drm/i915/i915_wait_util.h
+++ b/drivers/gpu/drm/i915/i915_wait_util.h
@@ -25,9 +25,9 @@
 	might_sleep();							\
 	for (;;) {							\
 		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
-		OP;							\
 		/* Guarantee COND check prior to timeout */		\
 		barrier();						\
+		OP;							\
 		if (COND) {						\
 			ret__ = 0;					\
 			break;						\
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/i915: Order OP vs. timeout correctly in __wait_for()
  2026-03-13 11:07 [PATCH] drm/i915: Order OP vs. timeout correctly in __wait_for() Ville Syrjala
@ 2026-03-17 13:07 ` Jani Nikula
  0 siblings, 0 replies; 2+ messages in thread
From: Jani Nikula @ 2026-03-17 13:07 UTC (permalink / raw)
  To: Ville Syrjala, intel-gfx; +Cc: stable

On Fri, 13 Mar 2026, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Put the barrier() before the OP so that anything we read out in
> OP and check in COND will actually be read out after the timeout
> has been evaluated.
>
> Currently the only place where we use OP is __intel_wait_for_register(),
> but the use there is precisely susceptible to this reordering, assuming
> the ktime_*() stuff itself doesn't act as a sufficient barrier:
>
> __intel_wait_for_register(...)
> {
> 	...
> 	ret = __wait_for(reg_value = intel_uncore_read_notrace(...),
>  			 (reg_value & mask) == value, ...);
> 	...
> }
>
> Cc: stable@vger.kernel.org
> Fixes: 1c3c1dc66a96 ("drm/i915: Add compiler barrier to wait_for")
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

Reviewed-by: Jani Nikula <jani.nikula@intel.com>

> ---
>  drivers/gpu/drm/i915/i915_wait_util.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_wait_util.h b/drivers/gpu/drm/i915/i915_wait_util.h
> index 7376898e3bf8..e1ed7921ec70 100644
> --- a/drivers/gpu/drm/i915/i915_wait_util.h
> +++ b/drivers/gpu/drm/i915/i915_wait_util.h
> @@ -25,9 +25,9 @@
>  	might_sleep();							\
>  	for (;;) {							\
>  		const bool expired__ = ktime_after(ktime_get_raw(), end__); \
> -		OP;							\
>  		/* Guarantee COND check prior to timeout */		\
>  		barrier();						\
> +		OP;							\
>  		if (COND) {						\
>  			ret__ = 0;					\
>  			break;						\

-- 
Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-17 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 11:07 [PATCH] drm/i915: Order OP vs. timeout correctly in __wait_for() Ville Syrjala
2026-03-17 13:07 ` Jani Nikula

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox