Received: by 10.213.65.68 with SMTP id h4csp476828imn; Tue, 13 Mar 2018 10:15:21 -0700 (PDT) X-Google-Smtp-Source: AG47ELtAHMV9EDyXhgjHeMum9WX/Ep6bRW9EZgq9CnhTZMrIhrvwbBR2opfnwEtyUV06XuU1wral X-Received: by 10.98.36.25 with SMTP id r25mr1344626pfj.106.1520961321047; Tue, 13 Mar 2018 10:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520961321; cv=none; d=google.com; s=arc-20160816; b=xV8SUoGCkL2PC/bLBLiviST6CLx9O/lYFCsWzCFwGK2rHxuizfP0PIsN5mkQc6SxDm BPLhLu2IMiHRVcOImQOC1VOnf5woZhXB+STv3IJ3bTzoEjSbH3ZPYOcbrSE9eUOa65b1 NnyHanD/75XHO1XLxieg8X6a2syXQ1DjlSDS/y1ihAp3v035TWCV/bKELP7pkyGP6yFD 7WcHRlylRHJjhThNYTs+ek4qSAjWiGcdt/MqL7tX0GYyv5rJKDMmwXZ0njfNp6ReEA2i +DG2uTH2tQ15JPf6LskWTYLk1uPHIl0LAydpkbKJAM/Evk3G0JcqEOFClbR++5c9Rv9R Rs0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XryEAeli4LHrJ+PNjTF7DKdRyO8yc1v5Mcxrc/byR+I=; b=t2r7Y7zontkzS+UT3OxtONmj7KmQG3nRLHNgRGTQd8qhdOk9OnOiIeMDrYU3+27Yy7 58NrMdWX8MPj8eHmaM3mq4QzQR+B7kRwqzkY6qyYmVEkPbGp5B4Io88gpz8e9NnIbYiR 8S65Cjy775pEbOowYqUhy3dODtskmrw3i6gpQa1XO74EAjAzp4FwoDrjVYpgLw+Lo9dT cEYdwoqmA20fBcpFAkpOJQf33Oixy7ttQWfakj8Td2lZPwMzhuDHGAAu/hTkHbnQDYLY SJ0ro2vyDJ93/FWWBsj9pnbMU++CFyQeTqLzp4oVAcQoZATd2ybxScSqPQzYGBIcerZA pxfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t63si262967pgt.745.2018.03.13.10.15.06; Tue, 13 Mar 2018 10:15:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932971AbeCMP3b (ORCPT + 99 others); Tue, 13 Mar 2018 11:29:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58394 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932951AbeCMP31 (ORCPT ); Tue, 13 Mar 2018 11:29:27 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D6EFFF8F; Tue, 13 Mar 2018 15:29:26 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lionel Landwerlin , Matthew Auld , Chris Wilson , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , intel-gfx@lists.freedesktop.org Subject: [PATCH 4.15 016/146] drm/i915/perf: fix perf stream opening lock Date: Tue, 13 Mar 2018 16:23:03 +0100 Message-Id: <20180313152321.784391855@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152320.439085687@linuxfoundation.org> References: <20180313152320.439085687@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lionel Landwerlin commit f616f2830c1ed79245cfeca900f7e8a3b3c08c06 upstream. We're seeing on CI that some contexts don't have the programmed OA period timer that directs the OA unit on how often to write reports. The issue is that we're not holding the drm lock from when we edit the context images down to when we set the exclusive_stream variable. This leaves a window for the deferred context allocation to call i915_oa_init_reg_state() that will not program the expected OA timer value, because we haven't set the exclusive_stream yet. v2: Drop need_lock from gen8_configure_all_contexts() (Matt) Signed-off-by: Lionel Landwerlin Reviewed-by: Matthew Auld Reviewed-by: Chris Wilson Fixes: 701f8231a2f ("drm/i915/perf: prune OA configs") Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102254 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103715 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103755 Link: https://patchwork.freedesktop.org/patch/msgid/20180301110613.1737-1-lionel.g.landwerlin@intel.com Cc: Jani Nikula Cc: Joonas Lahtinen Cc: Rodrigo Vivi Cc: intel-gfx@lists.freedesktop.org Cc: # v4.14+ (cherry picked from commit 41d3fdcd15d5ecf29cc73e8b79c2327ebb54b960) Signed-off-by: Rodrigo Vivi Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/i915_perf.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -1301,9 +1301,8 @@ static void i915_oa_stream_destroy(struc */ mutex_lock(&dev_priv->drm.struct_mutex); dev_priv->perf.oa.exclusive_stream = NULL; - mutex_unlock(&dev_priv->drm.struct_mutex); - dev_priv->perf.oa.ops.disable_metric_set(dev_priv); + mutex_unlock(&dev_priv->drm.struct_mutex); free_oa_buffer(dev_priv); @@ -1755,22 +1754,13 @@ static int gen8_switch_to_updated_kernel * Note: it's only the RCS/Render context that has any OA state. */ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv, - const struct i915_oa_config *oa_config, - bool interruptible) + const struct i915_oa_config *oa_config) { struct i915_gem_context *ctx; int ret; unsigned int wait_flags = I915_WAIT_LOCKED; - if (interruptible) { - ret = i915_mutex_lock_interruptible(&dev_priv->drm); - if (ret) - return ret; - - wait_flags |= I915_WAIT_INTERRUPTIBLE; - } else { - mutex_lock(&dev_priv->drm.struct_mutex); - } + lockdep_assert_held(&dev_priv->drm.struct_mutex); /* Switch away from any user context. */ ret = gen8_switch_to_updated_kernel_context(dev_priv, oa_config); @@ -1818,8 +1808,6 @@ static int gen8_configure_all_contexts(s } out: - mutex_unlock(&dev_priv->drm.struct_mutex); - return ret; } @@ -1862,7 +1850,7 @@ static int gen8_enable_metric_set(struct * to make sure all slices/subslices are ON before writing to NOA * registers. */ - ret = gen8_configure_all_contexts(dev_priv, oa_config, true); + ret = gen8_configure_all_contexts(dev_priv, oa_config); if (ret) return ret; @@ -1877,7 +1865,7 @@ static int gen8_enable_metric_set(struct static void gen8_disable_metric_set(struct drm_i915_private *dev_priv) { /* Reset all contexts' slices/subslices configurations. */ - gen8_configure_all_contexts(dev_priv, NULL, false); + gen8_configure_all_contexts(dev_priv, NULL); I915_WRITE(GDT_CHICKEN_BITS, (I915_READ(GDT_CHICKEN_BITS) & ~GT_NOA_ENABLE)); @@ -2127,6 +2115,10 @@ static int i915_oa_stream_init(struct i9 if (ret) goto err_oa_buf_alloc; + ret = i915_mutex_lock_interruptible(&dev_priv->drm); + if (ret) + goto err_lock; + ret = dev_priv->perf.oa.ops.enable_metric_set(dev_priv, stream->oa_config); if (ret) @@ -2134,23 +2126,17 @@ static int i915_oa_stream_init(struct i9 stream->ops = &i915_oa_stream_ops; - /* Lock device for exclusive_stream access late because - * enable_metric_set() might lock as well on gen8+. - */ - ret = i915_mutex_lock_interruptible(&dev_priv->drm); - if (ret) - goto err_lock; - dev_priv->perf.oa.exclusive_stream = stream; mutex_unlock(&dev_priv->drm.struct_mutex); return 0; -err_lock: +err_enable: dev_priv->perf.oa.ops.disable_metric_set(dev_priv); + mutex_unlock(&dev_priv->drm.struct_mutex); -err_enable: +err_lock: free_oa_buffer(dev_priv); err_oa_buf_alloc: