From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jesse Barnes Subject: Re: [PATCH 01/12] drm/i915: Assert mutex_is_locked on context lookup Date: Thu, 2 May 2013 13:27:32 -0700 Message-ID: <20130502132732.169fb0ff@jbarnes-desktop> References: <1366784140-2670-1-git-send-email-ben@bwidawsk.net> <1366784140-2670-2-git-send-email-ben@bwidawsk.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from oproxy9.bluehost.com (oproxy9.bluehost.com [69.89.24.6]) by gabe.freedesktop.org (Postfix) with SMTP id A22A1E5CDE for ; Thu, 2 May 2013 13:26:50 -0700 (PDT) In-Reply-To: <1366784140-2670-2-git-send-email-ben@bwidawsk.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: Ben Widawsky Cc: Intel GFX List-Id: intel-gfx@lists.freedesktop.org On Tue, 23 Apr 2013 23:15:29 -0700 Ben Widawsky 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 > --- > 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 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. -- Jesse Barnes, Intel Open Source Technology Center