Skip to contentSkip to conversation

drm/i915: GEM_WARN_ON considered harmful

PATCH In review Tvrtko Ursulin 4 participants 5 messages Oct 12, 2018 – Oct 18, 2018

Subsystems (2)
lore
Share & tools
lore

Tvrtko Ursulin

author maintainer
#0 lore raw

PATCH v2 1/1 drm/i915: GEM_WARN_ON considered harmful

From: Tvrtko Ursulin <[email protected]>

GEM_WARN_ON currently has dangerous semantics where it is completely compiled out on !GEM_DEBUG builds. This can leave users who expect it to be more like a WARN_ON, just without a warning in non-debug builds, in complete ignorance.

Another gotcha with it is that it cannot be used as a statement. Which is again different from a standard kernel WARN_ON.

This patch fixes both problems by making it behave as one would expect.

It can now be used both as an expression and as statement, and also the condition evaluates properly in all builds - code under the conditional will therefore not unexpectedly disappear.

To satisfy call sites which really want the code under the conditional to completely disappear, we add GEM_DEBUG_WARN_ON and convert some of the callers to it. This one can also be used as both expression and statement.

From the above it follows GEM_DEBUG_WARN_ON should be used in situations where we are certain the condition will be hit during development, but at a place in code where error can be handled to the benefit of not crashing the machine.

GEM_WARN_ON on the other hand should be used where condition may happen in production and we just want to distinguish the level of debugging output emitted between the production and debug build.

v2:
* Dropped BUG_ON hunk.

Cc Chris Wilson <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Mika Kuoppala <[email protected]>
Cc Tomasz Lis <[email protected]>
---
 drivers/gpu/drm/i915/i915_gem.h          | 4 +++-
 drivers/gpu/drm/i915/i915_vma.c          | 8 ++++----
 drivers/gpu/drm/i915/intel_engine_cs.c   | 8 ++++----
 drivers/gpu/drm/i915/intel_lrc.c         | 6 +++---
 drivers/gpu/drm/i915/intel_workarounds.c | 2 +-
 5 files changed, 15 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem.h +3 -1
index 599c4f6eb1ea..b0e4b976880c 100644
@@ -47,17 +47,19 @@ struct drm_i915_private;
 #define GEM_DEBUG_DECL(var) var
 #define GEM_DEBUG_EXEC(expr) expr
 #define GEM_DEBUG_BUG_ON(expr) GEM_BUG_ON(expr)
+#define GEM_DEBUG_WARN_ON(expr) GEM_WARN_ON(expr)
 
 #else
 
 #define GEM_SHOW_DEBUG() (0)
 
 #define GEM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
-#define GEM_WARN_ON(expr) (BUILD_BUG_ON_INVALID(expr), 0)
+#define GEM_WARN_ON(expr) ({ unlikely(!!(expr)); })
 
 #define GEM_DEBUG_DECL(var)
 #define GEM_DEBUG_EXEC(expr) do { } while (0)
 #define GEM_DEBUG_BUG_ON(expr)
+#define GEM_DEBUG_WARN_ON(expr) ({ BUILD_BUG_ON_INVALID(expr); 0; })
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
drivers/gpu/drm/i915/i915_vma.c +4 -4
index 31efc971a3a8..82652c3d1bed 100644
@@ -305,12 +305,12 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
 	GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
 	GEM_BUG_ON(vma->size > vma->node.size);
 
-	if (GEM_WARN_ON(range_overflows(vma->node.start,
-					vma->node.size,
-					vma->vm->total)))
+	if (GEM_DEBUG_WARN_ON(range_overflows(vma->node.start,
+					      vma->node.size,
+					      vma->vm->total)))
 		return -ENODEV;
 
-	if (GEM_WARN_ON(!flags))
+	if (GEM_DEBUG_WARN_ON(!flags))
 		return -EINVAL;
 
 	bind_flags = 0;
drivers/gpu/drm/i915/intel_engine_cs.c +4 -4
index f27dbe26bcc1..78e42c0825d2 100644
@@ -273,13 +273,13 @@ intel_engine_setup(struct drm_i915_private *dev_priv,
 	BUILD_BUG_ON(MAX_ENGINE_CLASS >= BIT(GEN11_ENGINE_CLASS_WIDTH));
 	BUILD_BUG_ON(MAX_ENGINE_INSTANCE >= BIT(GEN11_ENGINE_INSTANCE_WIDTH));
 
-	if (GEM_WARN_ON(info->class > MAX_ENGINE_CLASS))
+	if (GEM_DEBUG_WARN_ON(info->class > MAX_ENGINE_CLASS))
 		return -EINVAL;
 
-	if (GEM_WARN_ON(info->instance > MAX_ENGINE_INSTANCE))
+	if (GEM_DEBUG_WARN_ON(info->instance > MAX_ENGINE_INSTANCE))
 		return -EINVAL;
 
-	if (GEM_WARN_ON(dev_priv->engine_class[info->class][info->instance]))
+	if (GEM_DEBUG_WARN_ON(dev_priv->engine_class[info->class][info->instance]))
 		return -EINVAL;
 
 	GEM_BUG_ON(dev_priv->engine[id]);
@@ -402,7 +402,7 @@ int intel_engines_init(struct drm_i915_private *dev_priv)
 		err = -EINVAL;
 		err_id = id;
 
-		if (GEM_WARN_ON(!init))
+		if (GEM_DEBUG_WARN_ON(!init))
 			goto cleanup;
 
 		err = init(engine);
drivers/gpu/drm/i915/intel_lrc.c +3 -3
index ff0e2b36cb8b..22b57b8926fc 100644
@@ -1515,7 +1515,7 @@ static int intel_init_workaround_bb(struct intel_engine_cs *engine)
 	unsigned int i;
 	int ret;
 
-	if (GEM_WARN_ON(engine->id != RCS))
+	if (GEM_DEBUG_WARN_ON(engine->id != RCS))
 		return -EINVAL;
 
 	switch (INTEL_GEN(engine->i915)) {
@@ -1554,8 +1554,8 @@ static int intel_init_workaround_bb(struct intel_engine_cs *engine)
 	 */
 	for (i = 0; i < ARRAY_SIZE(wa_bb_fn); i++) {
 		wa_bb[i]->offset = batch_ptr - batch;
-		if (GEM_WARN_ON(!IS_ALIGNED(wa_bb[i]->offset,
-					    CACHELINE_BYTES))) {
+		if (GEM_DEBUG_WARN_ON(!IS_ALIGNED(wa_bb[i]->offset,
+						  CACHELINE_BYTES))) {
 			ret = -EINVAL;
 			break;
 		}
drivers/gpu/drm/i915/intel_workarounds.c +1 -1
index e4136590fed9..01b9b7591c5d 100644
@@ -948,7 +948,7 @@ struct whitelist {
 
 static void whitelist_reg(struct whitelist *w, i915_reg_t reg)
 {
-	if (GEM_WARN_ON(w->count >= RING_MAX_NONPRIV_SLOTS))
+	if (GEM_DEBUG_WARN_ON(w->count >= RING_MAX_NONPRIV_SLOTS))
 		return;
 
 	w->reg[w->count++] = reg;
Signature · 6 lines
2.17.1

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

✓ Fi.CI.BAT: success for drm/i915: GEM_WARN_ON considered harmful (rev2)

== Series Details ==

== Series Details ==

Series: drm/i915: GEM_WARN_ON considered harmful (rev2)
URL : https://patchwork.freedesktop.org/series/49340/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4976 -> Patchwork_10434 =

== Summary - SUCCESS ==

No regressions found.

External URL: https://patchwork.freedesktop.org/api/1.0/series/49340/revisions/2/mbox/

== Known issues ==

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

=== IGT changes ===

    ==== Issues hit ====

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
      fi-byt-clapper:     PASS -> FAIL (fdo#103191, fdo#107362)
      fi-icl-u:           PASS -> INCOMPLETE (fdo#107713)

    
    ==== Possible fixes ====

    igt@kms_flip@basic-flip-vs-modeset:
      fi-glk-j4005:       DMESG-WARN (fdo#106097) -> PASS

    igt@kms_frontbuffer_tracking@basic:
      fi-byt-clapper:     FAIL (fdo#103167) -> PASS

    igt@kms_pipe_crc_basic@read-crc-pipe-c:
      fi-skl-6700k2:      FAIL (fdo#103191, fdo#107362) -> PASS

    igt@pm_rpm@module-reload:
      fi-skl-6600u:       INCOMPLETE (fdo#107807) -> PASS
      fi-glk-j4005:       FAIL -> PASS

fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#103191 https://bugs.freedesktop.org/show_bug.cgi?id=103191
fdo#106097 https://bugs.freedesktop.org/show_bug.cgi?id=106097
fdo#107362 https://bugs.freedesktop.org/show_bug.cgi?id=107362
fdo#107713 https://bugs.freedesktop.org/show_bug.cgi?id=107713
fdo#107807 https://bugs.freedesktop.org/show_bug.cgi?id=107807

== Participating hosts (45 -> 41) ==

Missing (4): fi-ctg-p8600 fi-ilk-m540 fi-byt-squawks fi-bsw-cyan

== Build changes ==

* Linux: CI_DRM_4976 -> Patchwork_10434

CI_DRM_4976: dec9886eff39d38332bb5ea438b9b053d6b2177c @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4674: 93871c6fb3c25e5d350c9faf36ded917174214de @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_10434: a5c8a240cd324ed77a36dfced6ac50912c53cc04 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

a5c8a240cd32 drm/i915: GEM_WARN_ON considered harmful

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_10434/issues.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

Re: ✓ Fi.CI.BAT: success for drm/i915: GEM_WARN_ON considered harmful (rev2)

Quoted 62 lines · Patchwork

== Series Details ==

Series: drm/i915: GEM_WARN_ON considered harmful (rev2)
URL : https://patchwork.freedesktop.org/series/49340/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4976 -> Patchwork_10434 =

== Summary - SUCCESS ==

No regressions found.

   External URL: https://patchwork.freedesktop.org/api/1.0/series/49340/revisions/2/mbox/

== Known issues ==

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

   === IGT changes ===

     ==== Issues hit ====

     igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
       fi-byt-clapper:     PASS -> FAIL (fdo#103191, fdo#107362)
       fi-icl-u:           PASS -> INCOMPLETE (fdo#107713)

     
     ==== Possible fixes ====

     igt@kms_flip@basic-flip-vs-modeset:
       fi-glk-j4005:       DMESG-WARN (fdo#106097) -> PASS

     igt@kms_frontbuffer_tracking@basic:
       fi-byt-clapper:     FAIL (fdo#103167) -> PASS

     igt@kms_pipe_crc_basic@read-crc-pipe-c:
       fi-skl-6700k2:      FAIL (fdo#103191, fdo#107362) -> PASS

     igt@pm_rpm@module-reload:
       fi-skl-6600u:       INCOMPLETE (fdo#107807) -> PASS
       fi-glk-j4005:       FAIL -> PASS

     
   fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
   fdo#103191 https://bugs.freedesktop.org/show_bug.cgi?id=103191
   fdo#106097 https://bugs.freedesktop.org/show_bug.cgi?id=106097
   fdo#107362 https://bugs.freedesktop.org/show_bug.cgi?id=107362
   fdo#107713 https://bugs.freedesktop.org/show_bug.cgi?id=107713
   fdo#107807 https://bugs.freedesktop.org/show_bug.cgi?id=107807

== Participating hosts (45 -> 41) ==

   Missing    (4): fi-ctg-p8600 fi-ilk-m540 fi-byt-squawks fi-bsw-cyan

== Build changes ==

* Linux: CI_DRM_4976 -> Patchwork_10434

Quoted 8 lines
   CI_DRM_4976: dec9886eff39d38332bb5ea438b9b053d6b2177c @ git://anongit.freedesktop.org/gfx-ci/linux
   IGT_4674: 93871c6fb3c25e5d350c9faf36ded917174214de @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
   Patchwork_10434: a5c8a240cd324ed77a36dfced6ac50912c53cc04 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

a5c8a240cd32 drm/i915: GEM_WARN_ON considered harmful

Pushed, thanks for the comments and review!

Regards,

Tvrtko

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

✗ Fi.CI.IGT: failure for drm/i915: GEM_WARN_ON considered harmful (rev2)

In reply to Tvrtko Ursulin
== Series Details ==

== Series Details ==

Series: drm/i915: GEM_WARN_ON considered harmful (rev2)
URL : https://patchwork.freedesktop.org/series/49340/
State : failure

== Summary ==

= CI Bug Log - changes from CI_DRM_4976_full -> Patchwork_10434_full =

== Summary - FAILURE ==

Serious unknown changes coming with Patchwork_10434_full absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_10434_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

== Possible new issues ==

Here are the unknown changes that may have been introduced in Patchwork_10434_full:

=== IGT changes ===

    ==== Possible regressions ====

    igt@kms_flip@flip-vs-fences-interruptible:
      shard-kbl:          PASS -> DMESG-WARN

    
    ==== Warnings ====

    igt@perf_pmu@rc6:
      shard-kbl:          PASS -> SKIP

== Known issues ==

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

=== IGT changes ===

    ==== Issues hit ====

    igt@gem_cpu_reloc@full:
      shard-skl:          NOTRUN -> INCOMPLETE (fdo#108073)

    igt@gem_exec_schedule@pi-ringfull-render:
      shard-skl:          NOTRUN -> FAIL (fdo#103158) +1

    igt@gem_ppgtt@blt-vs-render-ctx0:
      shard-skl:          NOTRUN -> TIMEOUT (fdo#108039)

    igt@kms_busy@extended-modeset-hang-newfb-with-reset-render-a:
      shard-skl:          NOTRUN -> DMESG-WARN (fdo#107956) +1

    igt@kms_busy@extended-modeset-hang-newfb-with-reset-render-b:
      shard-snb:          NOTRUN -> DMESG-WARN (fdo#107956) +1

    igt@kms_ccs@pipe-a-crc-sprite-planes-basic:
      shard-skl:          NOTRUN -> FAIL (fdo#105458)

    igt@kms_chv_cursor_fail@pipe-c-256x256-top-edge:
      shard-skl:          NOTRUN -> FAIL (fdo#104671)

    igt@kms_cursor_crc@cursor-128x42-sliding:
      shard-skl:          NOTRUN -> FAIL (fdo#103232) +2

    igt@kms_cursor_crc@cursor-256x256-suspend:
      shard-apl:          PASS -> FAIL (fdo#103232, fdo#103191)

    igt@kms_cursor_crc@cursor-64x21-random:
      shard-apl:          PASS -> FAIL (fdo#103232) +3

    igt@kms_fbcon_fbt@fbc:
      shard-skl:          NOTRUN -> FAIL (fdo#103833, fdo#105682)

    igt@kms_fbcon_fbt@psr:
      shard-skl:          NOTRUN -> FAIL (fdo#107882)

    igt@kms_flip@flip-vs-expired-vblank-interruptible:
      shard-skl:          NOTRUN -> FAIL (fdo#105363)

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-render:
      shard-apl:          PASS -> FAIL (fdo#103167) +2

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-onoff:
      shard-glk:          PASS -> FAIL (fdo#103167) +2

    igt@kms_frontbuffer_tracking@fbcpsr-1p-indfb-fliptrack:
      shard-skl:          NOTRUN -> FAIL (fdo#105682) +2

    igt@kms_frontbuffer_tracking@fbcpsr-1p-offscren-pri-indfb-draw-render:
      shard-skl:          PASS -> FAIL (fdo#103167) +1

    igt@kms_frontbuffer_tracking@fbcpsr-1p-shrfb-fliptrack:
      shard-skl:          PASS -> FAIL (fdo#105682)

    igt@kms_frontbuffer_tracking@psr-rgb565-draw-render:
      shard-skl:          SKIP -> FAIL (fdo#103167)

    igt@kms_plane@plane-position-covered-pipe-c-planes:
      shard-glk:          PASS -> FAIL (fdo#103166)

    igt@kms_plane_alpha_blend@pipe-a-alpha-7efc:
      shard-skl:          NOTRUN -> FAIL (fdo#108145) +7

    igt@kms_plane_alpha_blend@pipe-a-coverage-7efc:
      shard-skl:          PASS -> FAIL (fdo#108145)

    igt@kms_plane_alpha_blend@pipe-c-alpha-7efc:
      shard-skl:          NOTRUN -> FAIL (fdo#108146) +1

    igt@kms_plane_multiple@atomic-pipe-c-tiling-yf:
      shard-apl:          PASS -> FAIL (fdo#103166) +1

    igt@kms_setmode@basic:
      shard-skl:          NOTRUN -> FAIL (fdo#99912)

    igt@kms_sysfs_edid_timing:
      shard-skl:          NOTRUN -> FAIL (fdo#100047)

    igt@perf@blocking:
      shard-hsw:          PASS -> FAIL (fdo#102252)

    igt@pm_backlight@fade_with_suspend:
      shard-skl:          NOTRUN -> FAIL (fdo#107847)

    igt@prime_vgem@basic-busy-default:
      shard-glk:          PASS -> DMESG-WARN (fdo#105763, fdo#106538) +1

    
    ==== Possible fixes ====

    igt@kms_busy@extended-pageflip-hang-newfb-render-b:
      shard-glk:          DMESG-WARN (fdo#107956) -> PASS

    igt@kms_ccs@pipe-b-crc-sprite-planes-basic:
      shard-glk:          FAIL (fdo#108145) -> PASS

    igt@kms_cursor_crc@cursor-256x256-random:
      shard-apl:          FAIL (fdo#103232) -> PASS +3

    igt@kms_cursor_crc@cursor-64x64-suspend:
      shard-skl:          INCOMPLETE (fdo#104108) -> PASS

    igt@kms_cursor_legacy@2x-long-cursor-vs-flip-legacy:
      shard-hsw:          FAIL (fdo#105767) -> PASS

    igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-mmap-gtt:
      shard-apl:          FAIL (fdo#103167) -> PASS

    igt@kms_frontbuffer_tracking@fbc-2p-primscrn-spr-indfb-onoff:
      shard-glk:          FAIL (fdo#103167) -> PASS +4

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
      shard-skl:          INCOMPLETE (fdo#107773, fdo#104108) -> PASS +2

    igt@kms_plane@plane-position-covered-pipe-a-planes:
      shard-glk:          FAIL (fdo#103166) -> PASS +1

    igt@kms_plane_multiple@atomic-pipe-a-tiling-x:
      shard-apl:          FAIL (fdo#103166) -> PASS

fdo#100047 https://bugs.freedesktop.org/show_bug.cgi?id=100047
fdo#102252 https://bugs.freedesktop.org/show_bug.cgi?id=102252
fdo#103158 https://bugs.freedesktop.org/show_bug.cgi?id=103158
fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#103191 https://bugs.freedesktop.org/show_bug.cgi?id=103191
fdo#103232 https://bugs.freedesktop.org/show_bug.cgi?id=103232
fdo#103833 https://bugs.freedesktop.org/show_bug.cgi?id=103833
fdo#104108 https://bugs.freedesktop.org/show_bug.cgi?id=104108
fdo#104671 https://bugs.freedesktop.org/show_bug.cgi?id=104671
fdo#105363 https://bugs.freedesktop.org/show_bug.cgi?id=105363
fdo#105458 https://bugs.freedesktop.org/show_bug.cgi?id=105458
fdo#105682 https://bugs.freedesktop.org/show_bug.cgi?id=105682
fdo#105763 https://bugs.freedesktop.org/show_bug.cgi?id=105763
fdo#105767 https://bugs.freedesktop.org/show_bug.cgi?id=105767
fdo#106538 https://bugs.freedesktop.org/show_bug.cgi?id=106538
fdo#107773 https://bugs.freedesktop.org/show_bug.cgi?id=107773
fdo#107847 https://bugs.freedesktop.org/show_bug.cgi?id=107847
fdo#107882 https://bugs.freedesktop.org/show_bug.cgi?id=107882
fdo#107956 https://bugs.freedesktop.org/show_bug.cgi?id=107956
fdo#108039 https://bugs.freedesktop.org/show_bug.cgi?id=108039
fdo#108073 https://bugs.freedesktop.org/show_bug.cgi?id=108073
fdo#108145 https://bugs.freedesktop.org/show_bug.cgi?id=108145
fdo#108146 https://bugs.freedesktop.org/show_bug.cgi?id=108146
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912

== Participating hosts (6 -> 6) ==

No changes in participating hosts

== Build changes ==

* Linux: CI_DRM_4976 -> Patchwork_10434

CI_DRM_4976: dec9886eff39d38332bb5ea438b9b053d6b2177c @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_4674: 93871c6fb3c25e5d350c9faf36ded917174214de @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_10434: a5c8a240cd324ed77a36dfced6ac50912c53cc04 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_10434/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v2 1/1
#4 lore raw
In reply to Tvrtko Ursulin
Quoted 25 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

GEM_WARN_ON currently has dangerous semantics where it is completely compiled out on !GEM_DEBUG builds. This can leave users who expect it to be more like a WARN_ON, just without a warning in non-debug builds, in complete ignorance.

Another gotcha with it is that it cannot be used as a statement. Which is again different from a standard kernel WARN_ON.

This patch fixes both problems by making it behave as one would expect.

It can now be used both as an expression and as statement, and also the condition evaluates properly in all builds - code under the conditional will therefore not unexpectedly disappear.

To satisfy call sites which really want the code under the conditional to completely disappear, we add GEM_DEBUG_WARN_ON and convert some of the callers to it. This one can also be used as both expression and statement.

From the above it follows GEM_DEBUG_WARN_ON should be used in situations
where we are certain the condition will be hit during development, but at a place in code where error can be handled to the benefit of not crashing the machine.

Quoted 6 lines

GEM_WARN_ON on the other hand should be used where condition may happen in production and we just want to distinguish the level of debugging output emitted between the production and debug build.

v2:
* Dropped BUG_ON hunk.

I have to agree with the need to "fix" GEM_WARN_ON() - ran into not realizing the difference to WARN_ON() myself. And while nobody likes multiplying variants of macros, I can't disagree with the need of having DEBUG-only version as well.

Quoted 119 lines
Cc Chris Wilson <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Matthew Auld <[email protected]>
Cc Mika Kuoppala <[email protected]>
Cc Tomasz Lis <[email protected]>
---
  drivers/gpu/drm/i915/i915_gem.h          | 4 +++-
  drivers/gpu/drm/i915/i915_vma.c          | 8 ++++----
  drivers/gpu/drm/i915/intel_engine_cs.c   | 8 ++++----
  drivers/gpu/drm/i915/intel_lrc.c         | 6 +++---
  drivers/gpu/drm/i915/intel_workarounds.c | 2 +-
  5 files changed, 15 insertions(+), 13 deletions(-)
drivers/gpu/drm/i915/i915_gem.h +3 -1
index 599c4f6eb1ea..b0e4b976880c 100644
@@ -47,17 +47,19 @@ struct drm_i915_private;
  #define GEM_DEBUG_DECL(var) var
  #define GEM_DEBUG_EXEC(expr) expr
  #define GEM_DEBUG_BUG_ON(expr) GEM_BUG_ON(expr)
+#define GEM_DEBUG_WARN_ON(expr) GEM_WARN_ON(expr)
 
  #else
 
  #define GEM_SHOW_DEBUG() (0)
 
  #define GEM_BUG_ON(expr) BUILD_BUG_ON_INVALID(expr)
-#define GEM_WARN_ON(expr) (BUILD_BUG_ON_INVALID(expr), 0)
+#define GEM_WARN_ON(expr) ({ unlikely(!!(expr)); })
 
  #define GEM_DEBUG_DECL(var)
  #define GEM_DEBUG_EXEC(expr) do { } while (0)
  #define GEM_DEBUG_BUG_ON(expr)
+#define GEM_DEBUG_WARN_ON(expr) ({ BUILD_BUG_ON_INVALID(expr); 0; })
  #endif
 
  #if IS_ENABLED(CONFIG_DRM_I915_TRACE_GEM)
drivers/gpu/drm/i915/i915_vma.c +4 -4
index 31efc971a3a8..82652c3d1bed 100644
@@ -305,12 +305,12 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
  	GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
  	GEM_BUG_ON(vma->size > vma->node.size);
 
-	if (GEM_WARN_ON(range_overflows(vma->node.start,
-					vma->node.size,
-					vma->vm->total)))
+	if (GEM_DEBUG_WARN_ON(range_overflows(vma->node.start,
+					      vma->node.size,
+					      vma->vm->total)))
  		return -ENODEV;
 
-	if (GEM_WARN_ON(!flags))
+	if (GEM_DEBUG_WARN_ON(!flags))
  		return -EINVAL;
 
  	bind_flags = 0;
drivers/gpu/drm/i915/intel_engine_cs.c +4 -4
index f27dbe26bcc1..78e42c0825d2 100644
@@ -273,13 +273,13 @@ intel_engine_setup(struct drm_i915_private *dev_priv,
  	BUILD_BUG_ON(MAX_ENGINE_CLASS >= BIT(GEN11_ENGINE_CLASS_WIDTH));
  	BUILD_BUG_ON(MAX_ENGINE_INSTANCE >= BIT(GEN11_ENGINE_INSTANCE_WIDTH));
 
-	if (GEM_WARN_ON(info->class > MAX_ENGINE_CLASS))
+	if (GEM_DEBUG_WARN_ON(info->class > MAX_ENGINE_CLASS))
  		return -EINVAL;
 
-	if (GEM_WARN_ON(info->instance > MAX_ENGINE_INSTANCE))
+	if (GEM_DEBUG_WARN_ON(info->instance > MAX_ENGINE_INSTANCE))
  		return -EINVAL;
 
-	if (GEM_WARN_ON(dev_priv->engine_class[info->class][info->instance]))
+	if (GEM_DEBUG_WARN_ON(dev_priv->engine_class[info->class][info->instance]))
  		return -EINVAL;
 
  	GEM_BUG_ON(dev_priv->engine[id]);
@@ -402,7 +402,7 @@ int intel_engines_init(struct drm_i915_private *dev_priv)
  		err = -EINVAL;
  		err_id = id;
 
-		if (GEM_WARN_ON(!init))
+		if (GEM_DEBUG_WARN_ON(!init))
  			goto cleanup;
 
  		err = init(engine);
drivers/gpu/drm/i915/intel_lrc.c +3 -3
index ff0e2b36cb8b..22b57b8926fc 100644
@@ -1515,7 +1515,7 @@ static int intel_init_workaround_bb(struct intel_engine_cs *engine)
  	unsigned int i;
  	int ret;
 
-	if (GEM_WARN_ON(engine->id != RCS))
+	if (GEM_DEBUG_WARN_ON(engine->id != RCS))
  		return -EINVAL;
 
  	switch (INTEL_GEN(engine->i915)) {
@@ -1554,8 +1554,8 @@ static int intel_init_workaround_bb(struct intel_engine_cs *engine)
  	 */
  	for (i = 0; i < ARRAY_SIZE(wa_bb_fn); i++) {
  		wa_bb[i]->offset = batch_ptr - batch;
-		if (GEM_WARN_ON(!IS_ALIGNED(wa_bb[i]->offset,
-					    CACHELINE_BYTES))) {
+		if (GEM_DEBUG_WARN_ON(!IS_ALIGNED(wa_bb[i]->offset,
+						  CACHELINE_BYTES))) {
  			ret = -EINVAL;
  			break;
  		}
drivers/gpu/drm/i915/intel_workarounds.c +0 -0
index e4136590fed9..01b9b7591c5d 100644

drivers/gpu/drm/i915/intel_workarounds.c struct whitelist { · line 954

Quoted 8 lines
drivers/gpu/drm/i915/intel_workarounds.c +1 -1
@@ -948,7 +948,7 @@ struct whitelist {
 
  static void whitelist_reg(struct whitelist *w, i915_reg_t reg)
  {
-	if (GEM_WARN_ON(w->count >= RING_MAX_NONPRIV_SLOTS))
+	if (GEM_DEBUG_WARN_ON(w->count >= RING_MAX_NONPRIV_SLOTS))
  		return;
 
  	w->reg[w->count++] = reg;

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx