Skip to content

Commit 5188388

Browse files
committed
Merge tag 'drm-intel-fixes-2023-01-12' of git://anongit.freedesktop.org/drm/drm-intel into drm-fixes
- Reserve enough fence slot for i915_vma_unbind_vsync (Nirmoy) - Fix potential use after free (Rob Clark) - Reset engines twice in case of reset failure (Chris) - Use multi-cast registers for SVG Unit registers (Gustavo) Signed-off-by: Dave Airlie <[email protected]> From: Rodrigo Vivi <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
2 parents 28d31e1 + 58fc14e commit 5188388

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,10 @@ void i915_gem_init__contexts(struct drm_i915_private *i915)
16881688
init_contexts(&i915->gem.contexts);
16891689
}
16901690

1691+
/*
1692+
* Note that this implicitly consumes the ctx reference, by placing
1693+
* the ctx in the context_xa.
1694+
*/
16911695
static void gem_context_register(struct i915_gem_context *ctx,
16921696
struct drm_i915_file_private *fpriv,
16931697
u32 id)
@@ -1703,17 +1707,17 @@ static void gem_context_register(struct i915_gem_context *ctx,
17031707
snprintf(ctx->name, sizeof(ctx->name), "%s[%d]",
17041708
current->comm, pid_nr(ctx->pid));
17051709

1706-
/* And finally expose ourselves to userspace via the idr */
1707-
old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
1708-
WARN_ON(old);
1709-
17101710
spin_lock(&ctx->client->ctx_lock);
17111711
list_add_tail_rcu(&ctx->client_link, &ctx->client->ctx_list);
17121712
spin_unlock(&ctx->client->ctx_lock);
17131713

17141714
spin_lock(&i915->gem.contexts.lock);
17151715
list_add_tail(&ctx->link, &i915->gem.contexts.list);
17161716
spin_unlock(&i915->gem.contexts.lock);
1717+
1718+
/* And finally expose ourselves to userspace via the idr */
1719+
old = xa_store(&fpriv->context_xa, id, ctx, GFP_KERNEL);
1720+
WARN_ON(old);
17171721
}
17181722

17191723
int i915_gem_context_open(struct drm_i915_private *i915,
@@ -2199,14 +2203,22 @@ finalize_create_context_locked(struct drm_i915_file_private *file_priv,
21992203
if (IS_ERR(ctx))
22002204
return ctx;
22012205

2206+
/*
2207+
* One for the xarray and one for the caller. We need to grab
2208+
* the reference *prior* to making the ctx visble to userspace
2209+
* in gem_context_register(), as at any point after that
2210+
* userspace can try to race us with another thread destroying
2211+
* the context under our feet.
2212+
*/
2213+
i915_gem_context_get(ctx);
2214+
22022215
gem_context_register(ctx, file_priv, id);
22032216

22042217
old = xa_erase(&file_priv->proto_context_xa, id);
22052218
GEM_BUG_ON(old != pc);
22062219
proto_context_close(file_priv->dev_priv, pc);
22072220

2208-
/* One for the xarray and one for the caller */
2209-
return i915_gem_context_get(ctx);
2221+
return ctx;
22102222
}
22112223

22122224
struct i915_gem_context *

drivers/gpu/drm/i915/gt/intel_gt_regs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@
406406
#define GEN9_WM_CHICKEN3 _MMIO(0x5588)
407407
#define GEN9_FACTOR_IN_CLR_VAL_HIZ (1 << 9)
408408

409-
#define CHICKEN_RASTER_1 _MMIO(0x6204)
409+
#define CHICKEN_RASTER_1 MCR_REG(0x6204)
410410
#define DIS_SF_ROUND_NEAREST_EVEN REG_BIT(8)
411411

412-
#define CHICKEN_RASTER_2 _MMIO(0x6208)
412+
#define CHICKEN_RASTER_2 MCR_REG(0x6208)
413413
#define TBIMR_FAST_CLIP REG_BIT(5)
414414

415415
#define VFLSKPD MCR_REG(0x62a8)

drivers/gpu/drm/i915/gt/intel_reset.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,25 +278,47 @@ static int ilk_do_reset(struct intel_gt *gt, intel_engine_mask_t engine_mask,
278278
static int gen6_hw_domain_reset(struct intel_gt *gt, u32 hw_domain_mask)
279279
{
280280
struct intel_uncore *uncore = gt->uncore;
281+
int loops = 2;
281282
int err;
282283

283284
/*
284285
* GEN6_GDRST is not in the gt power well, no need to check
285286
* for fifo space for the write or forcewake the chip for
286287
* the read
287288
*/
288-
intel_uncore_write_fw(uncore, GEN6_GDRST, hw_domain_mask);
289+
do {
290+
intel_uncore_write_fw(uncore, GEN6_GDRST, hw_domain_mask);
289291

290-
/* Wait for the device to ack the reset requests */
291-
err = __intel_wait_for_register_fw(uncore,
292-
GEN6_GDRST, hw_domain_mask, 0,
293-
500, 0,
294-
NULL);
292+
/*
293+
* Wait for the device to ack the reset requests.
294+
*
295+
* On some platforms, e.g. Jasperlake, we see that the
296+
* engine register state is not cleared until shortly after
297+
* GDRST reports completion, causing a failure as we try
298+
* to immediately resume while the internal state is still
299+
* in flux. If we immediately repeat the reset, the second
300+
* reset appears to serialise with the first, and since
301+
* it is a no-op, the registers should retain their reset
302+
* value. However, there is still a concern that upon
303+
* leaving the second reset, the internal engine state
304+
* is still in flux and not ready for resuming.
305+
*/
306+
err = __intel_wait_for_register_fw(uncore, GEN6_GDRST,
307+
hw_domain_mask, 0,
308+
2000, 0,
309+
NULL);
310+
} while (err == 0 && --loops);
295311
if (err)
296312
GT_TRACE(gt,
297313
"Wait for 0x%08x engines reset failed\n",
298314
hw_domain_mask);
299315

316+
/*
317+
* As we have observed that the engine state is still volatile
318+
* after GDRST is acked, impose a small delay to let everything settle.
319+
*/
320+
udelay(50);
321+
300322
return err;
301323
}
302324

drivers/gpu/drm/i915/gt/intel_workarounds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ static void icl_ctx_workarounds_init(struct intel_engine_cs *engine,
645645
static void dg2_ctx_gt_tuning_init(struct intel_engine_cs *engine,
646646
struct i915_wa_list *wal)
647647
{
648-
wa_masked_en(wal, CHICKEN_RASTER_2, TBIMR_FAST_CLIP);
648+
wa_mcr_masked_en(wal, CHICKEN_RASTER_2, TBIMR_FAST_CLIP);
649649
wa_mcr_write_clr_set(wal, XEHP_L3SQCREG5, L3_PWM_TIMER_INIT_VAL_MASK,
650650
REG_FIELD_PREP(L3_PWM_TIMER_INIT_VAL_MASK, 0x7f));
651651
wa_mcr_add(wal,
@@ -775,7 +775,7 @@ static void dg2_ctx_workarounds_init(struct intel_engine_cs *engine,
775775
wa_masked_field_set(wal, VF_PREEMPTION, PREEMPTION_VERTEX_COUNT, 0x4000);
776776

777777
/* Wa_15010599737:dg2 */
778-
wa_masked_en(wal, CHICKEN_RASTER_1, DIS_SF_ROUND_NEAREST_EVEN);
778+
wa_mcr_masked_en(wal, CHICKEN_RASTER_1, DIS_SF_ROUND_NEAREST_EVEN);
779779
}
780780

781781
static void fakewa_disable_nestedbb_mode(struct intel_engine_cs *engine,

drivers/gpu/drm/i915/i915_vma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ int i915_vma_unbind_async(struct i915_vma *vma, bool trylock_vm)
21162116
if (!obj->mm.rsgt)
21172117
return -EBUSY;
21182118

2119-
err = dma_resv_reserve_fences(obj->base.resv, 1);
2119+
err = dma_resv_reserve_fences(obj->base.resv, 2);
21202120
if (err)
21212121
return -EBUSY;
21222122

0 commit comments

Comments
 (0)