From: Daniel Vetter <daniel@ffwll.ch>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Ben Widawsky <ben@bwidawsk.net>,
Intel GFX <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 01/12] drm/i915: Assert mutex_is_locked on context lookup
Date: Mon, 6 May 2013 11:44:22 +0200 [thread overview]
Message-ID: <20130506094422.GA5763@phenom.ffwll.local> (raw)
In-Reply-To: <20130506094006.GZ5763@phenom.ffwll.local>
On Mon, May 06, 2013 at 11:40:06AM +0200, Daniel Vetter wrote:
> On Thu, May 02, 2013 at 01:27:32PM -0700, Jesse Barnes wrote:
> > On Tue, 23 Apr 2013 23:15:29 -0700
> > Ben Widawsky <ben@bwidawsk.net> wrote:
> >
> > > Because our context refcounting doesn't grab a ref at lookup time, it is
> > > unsafe to do so without the lock.
> > >
> > > NOTE: We don't have an easy way to put the assertion in the lookup
> > > function which is where this really belongs. Context switching is good
> > > enough because it actually asserts even more correctness by protecting
> > > the default_context.
> > >
> > > Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
> > > ---
> > > drivers/gpu/drm/i915/i915_gem_context.c | 2 ++
> > > 1 file changed, 2 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
> > > index a1e8ecb..411ace0 100644
> > > --- a/drivers/gpu/drm/i915/i915_gem_context.c
> > > +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> > > @@ -444,6 +444,8 @@ int i915_switch_context(struct intel_ring_buffer *ring,
> > > if (dev_priv->hw_contexts_disabled)
> > > return 0;
> > >
> > > + BUG_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex));
> > > +
> > > if (ring != &dev_priv->ring[RCS])
> > > return 0;
> > >
> >
> > Simple enough.
> >
> > Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>
> >
> > We usually do WARN_ONs for this stuff though, in case a user actually
> > does hit it, it may not be fatal so why crash the machine?
> >
> > But that's a minor distinction since we shouldn't hit this except in
> > development anyway.
>
> Well, since this is a patch for upstream the focus should very much be on
> supporting bug reporters and not developers. And for bug reporters a BUG
> is much more annoying than a WARN and greatly reduces the chances that
> we'll get a bug report.
Some more details why a WARN massively beats a BUG for us: BUG kills the
current process and ensures all locks are stuck. Usually that means X is
dead and you can't vt-switch away to the console to take a quick look at
dmesg.
Now even when all rendering is down the toilet due to the follow-up damage
after the WARN and the gpu a zombie, there's a non-zero chance that
vt-switch (or sw rendering in X) will work long enough to grab log files
and debugfs data.
Hence the first rule to only use a BUG on if we have a guaranteed OOPS
otherwise (which again will kill the process and make all locks stuck).
-Daniel
>
> There are imo only very few cases where a BUG instead of a WARN is
> justified:
> - The kernel is _guaranteed_ to oops in the next few lines anyway, so a
> BUG_ON will help in readability of the backtrace. Note that checking 3
> different things for non-NULL in the same BUG actually reduces OOPS
> readability (with an oops you can at least reconstruct the faulting
> address and so probably the pointer). Also, this means the BUG should
> have a neat description of what exactly blew up.
>
> The "a few lines" part is just a guideline with some big exceptions. A
> prime example is refcount over/underflows since those will blow up, but
> only sometimes later (and usually no one will have a clue why).
>
> - BUGs are justified if there's a potential security hole awaiting, e.g.
> when something in the userspace input validation has gone wrong.
>
> - I'm wary of special error handling for WARNs, but if an early return
> (with an error code if possible) transforms a BUG into a WARN I'm in.
> But trying to fix up e.g. modeset state is usually futile, since we'll
> end up with a black/fuzzy/corrupted screen most likely anyway.
>
> But the most important rule is: In case of doubt, just WARN, don't BUG.
>
> [I know, I violate it sometimes, too.]
>
> Patch applied with the s/BUG/WARN bikeshed.
> -Daniel
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> +41 (0) 79 365 57 48 - http://blog.ffwll.ch
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
next prev parent reply other threads:[~2013-05-06 9:41 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-24 6:15 [PATCH 00/12] [RFC] PPGTT prep patches part 1 Ben Widawsky
2013-04-24 6:15 ` [PATCH 01/12] drm/i915: Assert mutex_is_locked on context lookup Ben Widawsky
2013-05-02 20:27 ` Jesse Barnes
2013-05-06 9:40 ` Daniel Vetter
2013-05-06 9:44 ` Daniel Vetter [this message]
2013-05-06 17:59 ` Ben Widawsky
2013-05-06 18:35 ` Daniel Vetter
2013-04-24 6:15 ` [PATCH 02/12] drm/i915: BUG_ON bad PPGTT offset Ben Widawsky
2013-05-02 20:28 ` Jesse Barnes
2013-05-06 9:48 ` Daniel Vetter
2013-05-06 18:03 ` Ben Widawsky
2013-05-06 18:37 ` Daniel Vetter
2013-05-08 16:48 ` Ben Widawsky
2013-05-08 17:55 ` Daniel Vetter
2013-04-24 6:15 ` [PATCH 03/12] drm/i915: make PDE|PTE platform specific Ben Widawsky
2013-05-02 21:26 ` Jesse Barnes
2013-05-02 22:49 ` Ben Widawsky
2013-05-02 22:55 ` Jesse Barnes
2013-05-06 9:47 ` Daniel Vetter
2013-05-08 16:49 ` Ben Widawsky
2013-05-08 17:52 ` Daniel Vetter
2013-04-24 6:15 ` [PATCH 04/12] drm/i915: Extract PDE writes Ben Widawsky
2013-05-02 21:27 ` Jesse Barnes
2013-05-06 9:50 ` Daniel Vetter
2013-04-24 6:15 ` [PATCH 05/12] drm: Optionally create mm blocks from top-to-bottom Ben Widawsky
2013-04-24 6:15 ` [PATCH 06/12] drm/i915: Use drm_mm for PPGTT PDEs Ben Widawsky
2013-05-02 21:42 ` Jesse Barnes
2013-04-24 6:15 ` [PATCH 07/12] drm/i915: Use PDEs as the guard page Ben Widawsky
2013-04-24 6:15 ` [PATCH 08/12] drm/i915: Update context_fini Ben Widawsky
2013-04-24 15:11 ` Mika Kuoppala
2013-04-25 4:11 ` Ben Widawsky
2013-04-25 5:17 ` Ben Widawsky
2013-04-25 15:01 ` Mika Kuoppala
2013-04-25 17:22 ` Ben Widawsky
2013-04-24 6:15 ` [PATCH 09/12] drm/i915: Split context enabling from init Ben Widawsky
2013-04-24 10:04 ` Chris Wilson
2013-04-24 16:39 ` Ben Widawsky
2013-04-24 6:15 ` [PATCH 10/12] drm/i915: destroy i915_gem_init_global_gtt Ben Widawsky
2013-04-24 6:15 ` [PATCH 11/12] drm/i915: Embed PPGTT into the context Ben Widawsky
2013-04-24 6:15 ` [PATCH 12/12] drm/i915: No contexts without ppgtt Ben Widawsky
2013-04-24 10:06 ` Chris Wilson
2013-04-24 16:39 ` Ben Widawsky
2013-04-24 9:53 ` [PATCH 00/12] [RFC] PPGTT prep patches part 1 Chris Wilson
2013-04-24 19:58 ` Chris Wilson
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=20130506094422.GA5763@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=ben@bwidawsk.net \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jbarnes@virtuousgeek.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