Skip to content

Commit d823445

Browse files
committed
drm/i915/uncore: fix race around i915->params.mmio_debug
Only check the conditions for unclaimed reg debug once to avoid locking problems when i915->params.mmio_debug changes between header and footer. Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/8749 Cc: Lee Shawn C <shawn.c.lee@intel.com> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Signed-off-by: Jani Nikula <jani.nikula@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/a53fb0fd84c4627398ccd4304b35db05603b89b6.1690886109.git.jani.nikula@intel.com
1 parent 7afe234 commit d823445

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

drivers/gpu/drm/i915/intel_uncore.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,27 +1925,26 @@ __unclaimed_previous_reg_debug(struct intel_uncore *uncore,
19251925
i915_mmio_reg_offset(reg));
19261926
}
19271927

1928-
static inline void
1928+
static inline bool __must_check
19291929
unclaimed_reg_debug_header(struct intel_uncore *uncore,
19301930
const i915_reg_t reg, const bool read)
19311931
{
19321932
if (likely(!uncore->i915->params.mmio_debug) || !uncore->debug)
1933-
return;
1933+
return false;
19341934

19351935
/* interrupts are disabled and re-enabled around uncore->lock usage */
19361936
lockdep_assert_held(&uncore->lock);
19371937

19381938
spin_lock(&uncore->debug->lock);
19391939
__unclaimed_previous_reg_debug(uncore, reg, read);
1940+
1941+
return true;
19401942
}
19411943

19421944
static inline void
19431945
unclaimed_reg_debug_footer(struct intel_uncore *uncore,
19441946
const i915_reg_t reg, const bool read)
19451947
{
1946-
if (likely(!uncore->i915->params.mmio_debug) || !uncore->debug)
1947-
return;
1948-
19491948
/* interrupts are disabled and re-enabled around uncore->lock usage */
19501949
lockdep_assert_held(&uncore->lock);
19511950

@@ -2008,13 +2007,15 @@ __gen2_read(64)
20082007
#define GEN6_READ_HEADER(x) \
20092008
u32 offset = i915_mmio_reg_offset(reg); \
20102009
unsigned long irqflags; \
2010+
bool unclaimed_reg_debug; \
20112011
u##x val = 0; \
20122012
assert_rpm_wakelock_held(uncore->rpm); \
20132013
spin_lock_irqsave(&uncore->lock, irqflags); \
2014-
unclaimed_reg_debug_header(uncore, reg, true)
2014+
unclaimed_reg_debug = unclaimed_reg_debug_header(uncore, reg, true)
20152015

20162016
#define GEN6_READ_FOOTER \
2017-
unclaimed_reg_debug_footer(uncore, reg, true); \
2017+
if (unclaimed_reg_debug) \
2018+
unclaimed_reg_debug_footer(uncore, reg, true); \
20182019
spin_unlock_irqrestore(&uncore->lock, irqflags); \
20192020
trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \
20202021
return val
@@ -2112,13 +2113,15 @@ __gen2_write(32)
21122113
#define GEN6_WRITE_HEADER \
21132114
u32 offset = i915_mmio_reg_offset(reg); \
21142115
unsigned long irqflags; \
2116+
bool unclaimed_reg_debug; \
21152117
trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \
21162118
assert_rpm_wakelock_held(uncore->rpm); \
21172119
spin_lock_irqsave(&uncore->lock, irqflags); \
2118-
unclaimed_reg_debug_header(uncore, reg, false)
2120+
unclaimed_reg_debug = unclaimed_reg_debug_header(uncore, reg, false)
21192121

21202122
#define GEN6_WRITE_FOOTER \
2121-
unclaimed_reg_debug_footer(uncore, reg, false); \
2123+
if (unclaimed_reg_debug) \
2124+
unclaimed_reg_debug_footer(uncore, reg, false); \
21222125
spin_unlock_irqrestore(&uncore->lock, irqflags)
21232126

21242127
#define __gen6_write(x) \

0 commit comments

Comments
 (0)