Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10422430ybi; Wed, 24 Jul 2019 22:57:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqylrhI63H4LI7PhzQIKNS8fZl4TcmONN5JNpLoVDHf95s/AsJjL9QEKLv/NlMOdr+J8o5tH X-Received: by 2002:a63:1743:: with SMTP id 3mr6479908pgx.435.1564034233836; Wed, 24 Jul 2019 22:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034233; cv=none; d=google.com; s=arc-20160816; b=JfvHyVXDkAcGZkeAggc159Ccp909BBl+pMASO4CVMdtnt9ui5L+BJYeOmO1t0P/TrD NKQrCoA/ZguvvwkZ+oMncKO7SdFwyRrkfs2lH5KBz3NlvTYH4bfg0uHLfGkRm1BhRA5K jb4p5L1iuZcFGnuIT80xFQIpRV94QcbvKhyHjYEhqR8FRcA9mEf1PDSb4Np+XIG9ILUd NjNLB902n9bkA89fpVwXNvBeAKAoWogCQyGW+3KGn106wDE7eQDb5Vv9lA3yjSIEWVej MJgi/2JS+6zNI29Ae4MDUAUiFrDEl0TcP1TNijArzljKtwV5mAwrDoILSAfxs6bfvMzE 7FsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2th6zVe0tfSZOfKMQIC5vM3bHnUIHtnrQcQf3PTY/DI=; b=nccXJ8BE8jR/celKWIvde0CCLdFMvcAHmXokO11+ukjlHyDwSFcziNFhpDop4LosVg 5q55vpyzXVkRlEPMe3T7SU8z/10dgO+A5teZIpEVq3Y5UEOCA59cDt3WGuDgYlXaOE+L hsi8B4q4V3PMkHbZD2VzKTp2wbB3IeouJgeKDfVulLQeKgeCmpb6gpeQQtquPDnN3pdY XHq4ZuMNA9OKmXFJJrgZWKsnQobxFV5jjYGVAaH3OKqVGyJ8XinYn++a9nj70zVIAz6B EjWiW800+uFK6wyxX1tjc4tzxr5J+F/Qi+h/w7rwUJl5MIhuwbAj51X5Yl6ExIzcpAfn JqTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o56kGNCi; 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 f2si16432274plt.386.2019.07.24.22.56.58; Wed, 24 Jul 2019 22:57:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b=o56kGNCi; 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 S2404329AbfGYFkQ (ORCPT + 99 others); Thu, 25 Jul 2019 01:40:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:54476 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404269AbfGYFkF (ORCPT ); Thu, 25 Jul 2019 01:40:05 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0482F22C97; Thu, 25 Jul 2019 05:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033204; bh=djMy0ZkF1cNdzzJkInuRNcFK9iveLhe5RDIiDs8gmkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o56kGNCiHeAUCGrnkqOKdKyOhgHRiGhoK8e9h5/OEaWVT70ELg0kuQXhBDfAmUVo0 J5SghAuk3rHB7k+xgM8PjS11wmLeAA19h7iBMZdXiAayoxTDMWRTW2GIlMpiHxPlU3 9L96mfaP3DBWZdXMWg+NzRTN3YdtO7lV3YA1Tusg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kan Liang , "Peter Zijlstra (Intel)" , Linus Torvalds , Thomas Gleixner , acme@kernel.org, eranian@google.com, Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 078/271] perf/x86/intel/uncore: Handle invalid event coding for free-running counter Date: Wed, 24 Jul 2019 21:19:07 +0200 Message-Id: <20190724191701.880558315@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 543ac280b3576c0009e8c0fcd4d6bfc9978d7bd0 ] Counting with invalid event coding for free-running counter may cause OOPs, e.g. uncore_iio_free_running_0/event=1/. Current code only validate the event with free-running event format, event=0xff,umask=0xXY. Non-free-running event format never be checked for the PMU with free-running counters. Add generic hw_config() to check and reject the invalid event coding for free-running PMU. Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: acme@kernel.org Cc: eranian@google.com Fixes: 0f519f0352e3 ("perf/x86/intel/uncore: Support IIO free-running counters on SKX") Link: https://lkml.kernel.org/r/1556672028-119221-2-git-send-email-kan.liang@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/events/intel/uncore.h | 10 ++++++++++ arch/x86/events/intel/uncore_snbep.c | 1 + 2 files changed, 11 insertions(+) diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index cc6dd4f78158..42fa3974c421 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -402,6 +402,16 @@ static inline bool is_freerunning_event(struct perf_event *event) (((cfg >> 8) & 0xff) >= UNCORE_FREERUNNING_UMASK_START); } +/* Check and reject invalid config */ +static inline int uncore_freerunning_hw_config(struct intel_uncore_box *box, + struct perf_event *event) +{ + if (is_freerunning_event(event)) + return 0; + + return -EINVAL; +} + static inline void uncore_disable_box(struct intel_uncore_box *box) { if (box->pmu->type->ops->disable_box) diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c index b10e04387f38..8e4e8e423839 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -3585,6 +3585,7 @@ static struct uncore_event_desc skx_uncore_iio_freerunning_events[] = { static struct intel_uncore_ops skx_uncore_iio_freerunning_ops = { .read_counter = uncore_msr_read_counter, + .hw_config = uncore_freerunning_hw_config, }; static struct attribute *skx_uncore_iio_freerunning_formats_attr[] = { -- 2.20.1