Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3396784pxf; Mon, 22 Mar 2021 05:36:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGrGrcB0/fGJ+X8qsMNZqf68jE/DUeEDMNnJGYbk3WZ1Sen6sb8H9jbu9GD4aeuedNZRI2 X-Received: by 2002:a17:906:2786:: with SMTP id j6mr18981659ejc.157.1616416619321; Mon, 22 Mar 2021 05:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616416619; cv=none; d=google.com; s=arc-20160816; b=ZTUGY+qXhMCj62FyWXaoPpA0KySfqR4Eoqt8ux+FZ0tOe4/EhsQGxUFiFym1CHEqXc 8uCGYwrFS79hL/8vy+fWboU8VOjCzM1fe2ZK8X4rNSjXa4epZIt4ghIRBMnOUC4vju/C 9LvrpontJzyuUq2RMU3MEJEFQc3Sy1nf8DHqxhCYjMTTaWmt5LNGjxGQxZ0LwyDIU5We IYyUDy0PQUKOVqOukhcuJHR7M8SG/tDFwEFBTlK0PEdXxBLXj07eVOiHVjNQRgKPiCJj X1W6kcAJl51gp8DLQXUM6v0y2YBK+y/J0QiNGLjE2SNenBo8/xvE8njYWxKOUPh0YsbM Xg3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bzxEI00yiuqHsnFm6vO5KfIxKecN6E4LC76Ig34ufpE=; b=RDmbd8Z4g7Jyy/Aj29I1MJuCLJkcqPTvJ2kv0oVzkdmQrQe4mtT8Mylp5eMuefY4zS RwVnmY5dsfAE7ERgFWRA0r3ZzJdBA0/O2QvRZGA6znEmVx4odbp+K0Ete5IJo335qdo5 x3NuNnX4oztD4nIBDkEJcwn2nbB1TGtRvAhYSTp+fYo/ceV/yMVYPTS94u/ue7Yh47M6 2AW7vm5SYUKHCNQqUvcHAawnzc1iMJgHh18+PbxgnQ03XDiRLVR2g35k599ijrGD3hA9 Do1pfVUGM+d9dMvvJju0E4ZzwJNyI3VltVGg1EOT6pIlk9drEhTwA61Hpl56nmfwIzzn UdMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g6q85Tri; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k2si3226199ejx.546.2021.03.22.05.36.36; Mon, 22 Mar 2021 05:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g6q85Tri; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231434AbhCVMdm (ORCPT + 99 others); Mon, 22 Mar 2021 08:33:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:54556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231256AbhCVMbl (ORCPT ); Mon, 22 Mar 2021 08:31:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 63F39619A3; Mon, 22 Mar 2021 12:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416300; bh=QX/kW6ynz4hoZf/ztQb+b6xyWKTXGxR+QwQ42/7E//E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g6q85Tri+VPrWzqizZeeC+Mk+IIWtB/DjB4Run5X8rprmfgGBmpnL1MRkVvvIghVl XfzSKQKv+3bq16Dsws/LUPGYh02HXU97akyKn1eGBaUMzR9mpWOLT09tIEjPYxk7/O 63K80+q7u+3Wk7D5UQD0AmC3hF6xbLciSuHytXI8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Umesh Nerlige Ramappa , Ashutosh Dixit , Lionel Landwerlin , Jani Nikula Subject: [PATCH 5.11 054/120] i915/perf: Start hrtimer only if sampling the OA buffer Date: Mon, 22 Mar 2021 13:27:17 +0100 Message-Id: <20210322121931.489806555@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121929.669628946@linuxfoundation.org> References: <20210322121929.669628946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Umesh Nerlige Ramappa commit 6a77c6bb7260bd5000f95df454d9f8cdb1af7132 upstream. SAMPLE_OA parameter enables sampling of OA buffer and results in a call to init the OA buffer which initializes the OA unit head/tail pointers. The OA_EXPONENT parameter controls the periodicity of the OA reports in the OA buffer and results in starting a hrtimer. Before gen12, all use cases required the use of the OA buffer and i915 enforced this setting when vetting out the parameters passed. In these platforms the hrtimer was enabled if OA_EXPONENT was passed. This worked fine since it was implied that SAMPLE_OA is always passed. With gen12, this changed. Users can use perf without enabling the OA buffer as in OAR use cases. While an OAR use case should ideally not start the hrtimer, we see that passing an OA_EXPONENT parameter will start the hrtimer even though SAMPLE_OA is not specified. This results in an uninitialized OA buffer, so the head/tail pointers used to track the buffer are zero. This itself does not fail, but if we ran a use-case that SAMPLED the OA buffer previously, then the OA_TAIL register is still pointing to an old value. When the timer callback runs, it ends up calculating a wrong/large number of available reports. Since we do a spinlock_irq_save and start processing a large number of reports, NMI watchdog fires and causes a crash. Start the timer only if SAMPLE_OA is specified. v2: - Drop SAMPLE OA check when appending samples (Ashutosh) - Prevent read if OA buffer is not being sampled Fixes: 00a7f0d7155c ("drm/i915/tgl: Add perf support on TGL") Signed-off-by: Umesh Nerlige Ramappa Reviewed-by: Ashutosh Dixit Signed-off-by: Lionel Landwerlin Link: https://patchwork.freedesktop.org/patch/msgid/20210305210947.58751-1-umesh.nerlige.ramappa@intel.com (cherry picked from commit be0bdd67fda9468156c733976688f6487d0c42f7) Signed-off-by: Jani Nikula Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/i915_perf.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) --- a/drivers/gpu/drm/i915/i915_perf.c +++ b/drivers/gpu/drm/i915/i915_perf.c @@ -600,7 +600,6 @@ static int append_oa_sample(struct i915_ { int report_size = stream->oa_buffer.format_size; struct drm_i915_perf_record_header header; - u32 sample_flags = stream->sample_flags; header.type = DRM_I915_PERF_RECORD_SAMPLE; header.pad = 0; @@ -614,10 +613,8 @@ static int append_oa_sample(struct i915_ return -EFAULT; buf += sizeof(header); - if (sample_flags & SAMPLE_OA_REPORT) { - if (copy_to_user(buf, report, report_size)) - return -EFAULT; - } + if (copy_to_user(buf, report, report_size)) + return -EFAULT; (*offset) += header.size; @@ -2678,7 +2675,7 @@ static void i915_oa_stream_enable(struct stream->perf->ops.oa_enable(stream); - if (stream->periodic) + if (stream->sample_flags & SAMPLE_OA_REPORT) hrtimer_start(&stream->poll_check_timer, ns_to_ktime(stream->poll_oa_period), HRTIMER_MODE_REL_PINNED); @@ -2741,7 +2738,7 @@ static void i915_oa_stream_disable(struc { stream->perf->ops.oa_disable(stream); - if (stream->periodic) + if (stream->sample_flags & SAMPLE_OA_REPORT) hrtimer_cancel(&stream->poll_check_timer); } @@ -3024,7 +3021,7 @@ static ssize_t i915_perf_read(struct fil * disabled stream as an error. In particular it might otherwise lead * to a deadlock for blocking file descriptors... */ - if (!stream->enabled) + if (!stream->enabled || !(stream->sample_flags & SAMPLE_OA_REPORT)) return -EIO; if (!(file->f_flags & O_NONBLOCK)) {