public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Dave Gordon <david.s.gordon@intel.com>
To: Damien Lespiau <damien.lespiau@intel.com>,
	intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/i915/bdw: Fix the write setting up the WIZ hashing mode
Date: Mon, 08 Dec 2014 16:56:03 +0000	[thread overview]
Message-ID: <5485D823.403@intel.com> (raw)
In-Reply-To: <1418055747-22702-1-git-send-email-damien.lespiau@intel.com>

On 08/12/14 16:22, Damien Lespiau wrote:
> I was playing with clang and oh surprise! a warning trigerred by
> -Wshift-overflow (gcc doesn't have this one):
> 
>     WA_SET_BIT_MASKED(GEN7_GT_MODE,
>                       GEN6_WIZ_HASHING_MASK | GEN6_WIZ_HASHING_16x4);
> 
>     drivers/gpu/drm/i915/intel_ringbuffer.c:786:2: warning: signed shift result
>       (0x28002000000) requires 43 bits to represent, but 'int' only has 32 bits
>       [-Wshift-overflow]
>         WA_SET_BIT_MASKED(GEN7_GT_MODE,
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     drivers/gpu/drm/i915/intel_ringbuffer.c:737:15: note: expanded from macro
>       'WA_SET_BIT_MASKED'
>         WA_REG(addr, _MASKED_BIT_ENABLE(mask), (mask) & 0xffff)
> 
> Turned out GEN6_WIZ_HASHING_MASK was already shifted by 16, and we were
> trying to shift it a bit more.
> 
> The other thing is that it's not the usual case of setting WA bits here, we
> need to have separate mask and value.
> 
> To fix this, I've introduced a new _MASKED_FIELD() macro that takes both the
> (unshifted) mask and the desired value and the rest of the patch ripples
> through from it.
> 
> This bug was introduced when reworking the WA emission in:
> 
>   Commit 7225342ab501befdb64bcec76ded41f5897c0855
>   Author: Mika Kuoppala <mika.kuoppala@linux.intel.com>
>   Date:   Tue Oct 7 17:21:26 2014 +0300
> 
>       drm/i915: Build workaround list in ring initialization
> 
> v2: Invert the order of the mask and value arguments (Daniel Vetter)
>     Rewrite _MASKED_BIT_ENABLE() and _MASKED_BIT_DISABLE() with
>     _MASKED_FIELD() (Jani Nikula)
>     Make sure we only evaluate 'a' once in _MASKED_BIT_ENABLE() (Dave Gordon)
>     Add check to ensure the value is within the mask boundaries (Chris Wilson)
> 
> Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> Cc: Arun Siluvery <arun.siluvery@linux.intel.com>
> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_reg.h         | 13 ++++++++++---
>  drivers/gpu/drm/i915/intel_pm.c         |  6 +++---
>  drivers/gpu/drm/i915/intel_ringbuffer.c |  8 ++++++--
>  3 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
> index dc03fac..e0cd461 100644
> --- a/drivers/gpu/drm/i915/i915_reg.h
> +++ b/drivers/gpu/drm/i915/i915_reg.h
> @@ -34,8 +34,15 @@
>  #define _PORT3(port, a, b, c) ((port) == PORT_A ? (a) : \
>  			       (port) == PORT_B ? (b) : (c))
>  
> -#define _MASKED_BIT_ENABLE(a) (((a) << 16) | (a))
> -#define _MASKED_BIT_DISABLE(a) ((a) << 16)
> +#define _MASKED_FIELD(mask, value) ({					\
> +	if (__builtin_constant_p(mask) && __builtin_constant_p(value))	\
> +		BUILD_BUG_ON_MSG((value) & ~(mask),			\
> +				 "Incorrect value for mask");		\
> +	(mask) << 16 | (value); })

For even more compile- and run-time robustness we could check that
'mask' and 'value' each fit in 16 bits, as we have an explicit '16' in
there already.

.Dave.

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2014-12-08 16:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-06 20:14 [PATCH] drm/i915/bdw: Fix the write setting up the WIZ hashing mode Damien Lespiau
2014-12-07  4:48 ` shuang.he
2014-12-08 12:33 ` Jani Nikula
2014-12-08 13:59   ` Damien Lespiau
2014-12-08 14:17     ` Dave Gordon
2014-12-08 14:36       ` Damien Lespiau
2014-12-08 14:21     ` Daniel Vetter
2014-12-08 14:23       ` Daniel Vetter
2014-12-08 14:46         ` Damien Lespiau
2014-12-08 16:22   ` [PATCH v2] " Damien Lespiau
2014-12-08 16:27     ` Daniel Vetter
2014-12-08 16:50       ` Dave Gordon
2014-12-08 16:54         ` Damien Lespiau
2014-12-08 16:56     ` Dave Gordon [this message]
2014-12-08 17:33       ` [PATCH v3] " Damien Lespiau
2014-12-09 22:14         ` shuang.he
2014-12-10  9:42         ` Jani Nikula
2014-12-10 12:03           ` Damien Lespiau
2014-12-10 13:55             ` Daniel Vetter
2014-12-09 19:14     ` [PATCH v2] " shuang.he

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5485D823.403@intel.com \
    --to=david.s.gordon@intel.com \
    --cc=damien.lespiau@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox