All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915: Make sure fb gtt offsets stay within 32bits
Date: Fri, 21 Sep 2018 20:07:29 +0300	[thread overview]
Message-ID: <20180921170729.GG5565@intel.com> (raw)
In-Reply-To: <153754654008.21139.16522252152684045368@skylake-alporthouse-com>

On Fri, Sep 21, 2018 at 05:15:40PM +0100, Chris Wilson wrote:
> Quoting Ville Syrjälä (2018-09-21 14:06:02)
> > On Thu, Sep 20, 2018 at 09:07:35PM +0100, Chris Wilson wrote:
> > > Quoting Ville Syrjala (2018-09-20 20:10:18)
> > > > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > > 
> > > > Let's try to make sure the fb offset computations never hit
> > > > an integer overflow by making sure the entire fb stays
> > > > below 32bits. framebuffer_check() in the core already does
> > > > the same check, but as it doesn't know about tiling some things
> > > > can slip through. Repeat the check in the driver with tiling
> > > > taken into account.
> > > > 
> > > > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > > ---
> > > >  drivers/gpu/drm/i915/intel_display.c | 18 +++++++++++++++++-
> > > >  1 file changed, 17 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> > > > index e642b7717106..67259c719ffe 100644
> > > > --- a/drivers/gpu/drm/i915/intel_display.c
> > > > +++ b/drivers/gpu/drm/i915/intel_display.c
> > > > @@ -2400,10 +2400,26 @@ static int intel_fb_offset_to_xy(int *x, int *y,
> > > >                                  int color_plane)
> > > >  {
> > > >         struct drm_i915_private *dev_priv = to_i915(fb->dev);
> > > > +       unsigned int height;
> > > >  
> > > >         if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
> > > > -           fb->offsets[color_plane] % intel_tile_size(dev_priv))
> > > > +           fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
> > > > +               DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
> > > > +                             fb->offsets[color_plane], color_plane);
> > > >                 return -EINVAL;
> > > > +       }
> > > > +
> > > > +       height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
> > > > +       height = ALIGN(height, intel_tile_height(fb, color_plane));
> > > > +
> > > > +       /* Catch potential overflows early */
> > > > +       if (mul_u32_u32(height, fb->pitches[color_plane]) +
> > > 
> > > if (add_overflows(mul_u32_u32(height, fb->pitches[color_plane]),
> > >                 fb->offsets[color_plane],
> > >                 U32_MAX) {
> > > ?
> > 
> > Didn't know we had that. Looks like what we have right now doesn't quite
> > work as it only takes two arguments.
> 
> True, we would need the mul_overflows as well I guess (unless we are
> happy that's eliminated earlier).

I guess we'd really want a mac_overflows() to document what it's
really checking.

>  
> > Oh interesting. __builtin_add_overflow_p() & co. work supposedly work on
> > bitfields as well.
> > 
> > Bah. Looks like this stuff generatess worse code than the normal thing:
> 
> True. Maybe harmless though since we are on an init path (and who
> would reinitialise their fb on every update...) So the dilemma is having
> if (add_overflows()) better than a /* check if add overflows */ comment,
> and is that worth waiting on better code generation.

Yeah, in this case doesn't really matter. Just disappointed that
a builtin gives us suboptimal code even though the documentation
goes out of its way to point out that it can use fancy optimizations.

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2018-09-21 17:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20 19:10 [PATCH] drm/i915: Make sure fb gtt offsets stay within 32bits Ville Syrjala
2018-09-20 19:50 ` ✓ Fi.CI.BAT: success for " Patchwork
2018-09-20 20:07 ` [PATCH] " Chris Wilson
2018-09-21 13:06   ` Ville Syrjälä
2018-09-21 16:15     ` Chris Wilson
2018-09-21 17:07       ` Ville Syrjälä [this message]
2018-09-20 23:14 ` ✓ Fi.CI.IGT: success for " Patchwork

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=20180921170729.GG5565@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.