Skip to contentSkip to conversation

drm/i915/dg2: Add per-context control for Wa_22013059131

PATCH Superseded Jia Yao 3 participants 3 messages Jun 26

Subsystems (3)

v8 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Jia Yao

author
#0 lore raw

PATCH v8 1/1 drm/i915/dg2: Add per-context control for Wa_22013059131

Wa_22013059131 sets FORCE_1_SUB_MESSAGE_PER_FRAGMENT in LSC_CHICKEN_BIT_0 at engine init, but this is known to cause GPU hangs in certain workloads. Add I915_CONTEXT_PARAM_WA_22013059131 so userspace that handles the workaround itself (e.g. by limiting SLM size) can set it to 1 to let the kernel know bit 15 programming is not needed for that context.

LSC_CHICKEN_BIT_0 is not context-saved by hardware, so the kernel restores the correct value on every context switch via the indirect context batchbuffer to avoid leaking state between contexts. The old unconditional application of Wa22013059131 in intel_workarounds.c is removed.

v8:
- Clarify in the uAPI comment that setting this parameter only opts out of LSC_CHICKEN_BIT_0 bit 15 (FORCE_1_SUB_MESSAGE_PER_FRAGMENT); LSC_CHICKEN_BIT_0_UDW MAXREQS_PER_BANK remains unconditionally programmed by the kernel as the other part of Wa_22013059131

v7:
- Reject ioctl with -ENODEV on non-DG2-G11 platforms

v6:
- Remove excessive blank lines

v5:
- Remove fix and stable

v4:
- Add a link of the userspace using this API

v3:
- Kernel-internal context will not change workaround settings

Bspec: 54833

---
 drivers/gpu/drm/i915/gem/i915_gem_context.c   | 14 ++++++
 .../gpu/drm/i915/gem/i915_gem_context_types.h |  1 +
 drivers/gpu/drm/i915/gt/intel_context_types.h |  1 +
 drivers/gpu/drm/i915/gt/intel_lrc.c           | 43 ++++++++++++++++++-
 drivers/gpu/drm/i915/gt/intel_workarounds.c   | 10 ++---
 include/uapi/drm/i915_drm.h                   | 15 +++++++
 6 files changed, 78 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +14 -0
index 6ac0f23570f3..048393264ede 100644
@@ -911,6 +911,17 @@ static int set_proto_ctx_param(struct drm_i915_file_private *fpriv,
 			ret = -EINVAL;
 		break;
 
+	case I915_CONTEXT_PARAM_WA_22013059131:
+		if (args->size)
+			ret = -EINVAL;
+		else if (!IS_DG2_G11(i915))
+			ret = -ENODEV;
+		else if (args->value)
+			pc->user_flags |= BIT(UCONTEXT_WA_22013059131);
+		else
+			pc->user_flags &= ~BIT(UCONTEXT_WA_22013059131);
+		break;
+
 	case I915_CONTEXT_PARAM_RECOVERABLE:
 		if (args->size)
 			ret = -EINVAL;
@@ -1003,6 +1014,9 @@ static int intel_context_set_gem(struct intel_context *ce,
 	if (test_bit(UCONTEXT_LOW_LATENCY, &ctx->user_flags))
 		__set_bit(CONTEXT_LOW_LATENCY, &ce->flags);
 
+	if (test_bit(UCONTEXT_WA_22013059131, &ctx->user_flags))
+		__set_bit(CONTEXT_WA_22013059131, &ce->flags);
+
 	return ret;
 }
 
drivers/gpu/drm/i915/gem/i915_gem_context_types.h +1 -0
index 0267c924634b..4efc0e758d3b 100644
@@ -338,6 +338,7 @@ struct i915_gem_context {
 #define UCONTEXT_RECOVERABLE		3
 #define UCONTEXT_PERSISTENCE		4
 #define UCONTEXT_LOW_LATENCY		5
+#define UCONTEXT_WA_22013059131		6
 
 	/**
 	 * @flags: small set of booleans
drivers/gpu/drm/i915/gt/intel_context_types.h +1 -0
index 10070ee4d74c..84011ce7c84d 100644
@@ -133,6 +133,7 @@ struct intel_context {
 #define CONTEXT_EXITING			13
 #define CONTEXT_LOW_LATENCY		14
 #define CONTEXT_OWN_STATE		15
+#define CONTEXT_WA_22013059131		16
 
 	struct {
 		u64 timeout_us;
drivers/gpu/drm/i915/gt/intel_lrc.c +42 -1

61 lines not on this page · raw message

drivers/gpu/drm/i915/gt/intel_workarounds.c +5 -5
index 24ea5d8d529c..ef6eea3ab597 100644
@@ -2840,7 +2840,11 @@ general_render_compute_wa_init(struct intel_engine_cs *engine, struct i915_wa_li
 	if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) ||
 	    IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0) ||
 	    IS_DG2(i915)) {
-		/* Wa_22014226127 */
+		/*
+		 * Wa_22014226127: Note that this workaround also needs to be
+		 * re-applied in intel_lrc.c when LSC_CHICKEN_BIT_0 is
+		 * re-written for Wa_22013059131.
+		 */
 		wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0, DISABLE_D8_D16_COASLESCE);
 	}
 
@@ -2867,10 +2871,6 @@ general_render_compute_wa_init(struct intel_engine_cs *engine, struct i915_wa_li
 				     MAXREQS_PER_BANK,
 				     REG_FIELD_PREP(MAXREQS_PER_BANK, 2));
 
-		/* Wa_22013059131:dg2 */
-		wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0,
-				FORCE_1_SUB_MESSAGE_PER_FRAGMENT);
-
 		/*
 		 * Wa_22012654132
 		 *
include/uapi/drm/i915_drm.h +15 -0
index 535cb68fdb5c..dc7e143536ef 100644
@@ -2172,6 +2172,21 @@ struct drm_i915_gem_context_param {
  * Note that this is a debug API not available on production kernel builds.
  */
 #define I915_CONTEXT_PARAM_CONTEXT_IMAGE	0xf
+
+/*
+ * I915_CONTEXT_PARAM_WA_22013059131:
+ *
+ * Default value 0 means the kernel sets LSC_CHICKEN_BIT_0 bit 15
+ * (FORCE_1_SUB_MESSAGE_PER_FRAGMENT) for this context as part of
+ * Wa_22013059131.  Set to 1 to inform the kernel that userspace is
+ * handling the SLM contention workaround itself (e.g. by limiting SLM
+ * size), so bit 15 programming is not needed for this context.
+ *
+ * Note: LSC_CHICKEN_BIT_0_UDW MAXREQS_PER_BANK (bits 39:37) is the
+ * other part of Wa_22013059131 and remains unconditionally programmed
+ * by the kernel regardless of this setting.  DG2-G11 only.
+ */
+#define I915_CONTEXT_PARAM_WA_22013059131	0x10
 /* Must be kept compact -- no holes and well documented */
 
 	/** @value: Context parameter value to be set or queried */
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Race condition between concurrent engines due to per-context toggling of shared global MCR…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Race condition between concurrent engines due to per-context toggling of shared global MCR register LSC_CHICKEN_BIT_0.
- [High] Invalid cross-domain hardware programming by unconditionally emitting Render/Compute workaround on Video (VCS) and Copy (BCS) engines. --

commit 77b4f585118e5a808b879e93ddf1a2f08c7c13c1
Author: Jia Yao <[email protected]>
Subject: drm/i915/dg2: Add per-context control for Wa_22013059131

This commit introduces a per-context control for Wa_22013059131, which toggles FORCE_1_SUB_MESSAGE_PER_FRAGMENT in LSC_CHICKEN_BIT_0 at engine init. It adds I915_CONTEXT_PARAM_WA_22013059131 to allow userspace to manage the workaround itself, skipping the bit 15 programming. LSC_CHICKEN_BIT_0 is dynamically rewritten on every context switch to avoid leaking state between contexts.

Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +0 -0
index 147d22907960b..13344ebb847ec 100644

[ ... ]

Quoted 7 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +3 -0
@@ -1348,6 +1348,37 @@ gen12_invalidate_state_cache(u32 *cs)
 	return cs;
 }
 
+static u32 *
+dg2_g11_emit_wa_22013059131(const struct intel_context *ce, u32 *cs)
+{

[ ... ]

drivers/gpu/drm/i915/gt/intel_lrc.c gen12_invalidate_state_cache(u32 *cs) · line 1377

Quoted 8 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +8 -0
+	if (rcu_access_pointer(ce->gem_context) &&
+	    !test_bit(CONTEXT_WA_22013059131, &ce->flags)) {
+		val |= FORCE_1_SUB_MESSAGE_PER_FRAGMENT;
+	}
+
+	*cs++ = MI_LOAD_REGISTER_IMM(1);
+	*cs++ = i915_mmio_reg_offset(LSC_CHICKEN_BIT_0);
+	*cs++ = val;

[Severity: High]
Does dynamically overwriting LSC_CHICKEN_BIT_0 using MI_LOAD_REGISTER_IMM during an engine-local context switch create a race condition?

Because LSC_CHICKEN_BIT_0 is a shared Multicast (MCR) register across the DSS, concurrent engines (like RCS and CCS) execute independently. Would a context switch on one engine clobber the workaround state of another context actively executing on a concurrent engine, leading to GPU hangs or workload corruption?

Quoted 4 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +4 -0
+
+	return cs;
+}
+

[ ... ]

drivers/gpu/drm/i915/gt/intel_lrc.c gen12_emit_indirect_ctx_xcs(const struct intel_context *ce, u32 *cs) · line 1429

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +5 -1
@@ -1387,7 +1422,13 @@ gen12_emit_indirect_ctx_xcs(const struct intel_context *ce, u32 *cs)
 						    PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE,
 						    0);
 
-	return gen12_emit_aux_table_inv(ce->engine, cs);
+	cs = gen12_emit_aux_table_inv(ce->engine, cs);
+
+	/* Wa_22013059131:dg2 */
+	if (IS_DG2_G11(ce->engine->i915))
+		cs = dg2_g11_emit_wa_22013059131(ce, cs);

[Severity: High]
Does gen12_emit_indirect_ctx_xcs() incorrectly emit a Render/Compute register write on Video (VCS) and Copy (BCS) engines?

Since gen12_emit_indirect_ctx_xcs() is called to build the indirect context batch buffer for all non-Render engines, this unconditionally emits the MI_LOAD_REGISTER_IMM to LSC_CHICKEN_BIT_0.

As LSC (Load/Store Cache) is part of the Xe-Core (Render/Compute domain), Video and Blitter engines don't have access to this register domain. Will this invalid cross-domain hardware programming cause command exceptions, dropped writes, or command streamer hangs?

Would it be better to add an engine class check here, such as (ce->engine->class == COMPUTE_CLASS)?

Quoted 3 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +2 -0
+
+	return cs;
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

✓ i915.CI.BAT: success for drm/i915/dg2: Add per-context control for Wa_22013059131 (rev9)

In reply to Jia Yao
== Series Details ==

== Series Details ==

Series: drm/i915/dg2: Add per-context control for Wa_22013059131 (rev9)
URL : https://patchwork.freedesktop.org/series/164198/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_18723 -> Patchwork_164198v9
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_164198v9/index.html

Participating hosts (42 -> 40)
------------------------------

Missing (2): bat-dg2-13 fi-snb-2520m

Known issues
------------

Here are the changes found in Patchwork_164198v9 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_pm_rpm@module-reload:
- bat-adlp-6: [PASS][1] -> [DMESG-WARN][2] ([i915#15673]) +78 other tests dmesg-warn
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18723/bat-adlp-6/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_164198v9/bat-adlp-6/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@sanitycheck:
- fi-kbl-7567u: [DMESG-WARN][3] ([i915#13735]) -> [PASS][4] +79 other tests pass
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18723/fi-kbl-7567u/igt@i915_selftest@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_164198v9/fi-kbl-7567u/igt@i915_selftest@[email protected]

* igt@kms_busy@basic@flip:
- fi-kbl-7567u: [DMESG-WARN][5] ([i915#13735] / [i915#180]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18723/fi-kbl-7567u/igt@kms_busy@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_164198v9/fi-kbl-7567u/igt@kms_busy@[email protected]

* igt@kms_pm_rpm@basic-pci-d3-state:
- fi-kbl-7567u: [DMESG-WARN][7] ([i915#13735] / [i915#15673] / [i915#180]) -> [PASS][8] +52 other tests pass
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_18723/fi-kbl-7567u/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_164198v9/fi-kbl-7567u/igt@[email protected]

[i915#13735]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13735
[i915#15673]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15673
[i915#180]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/180

Build changes
-------------

* Linux: CI_DRM_18723 -> Patchwork_164198v9

CI-20190529: 20190529
CI_DRM_18723: 5fe805765b01f6e3519421039c3ade7cff1074ca @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_8987: 8987
Patchwork_164198v9: 5fe805765b01f6e3519421039c3ade7cff1074ca @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_164198v9/index.html