Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp331468ybi; Fri, 7 Jun 2019 08:45:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNXNQa2X66ZhvLRAAJHKII0JkJ7sXWTMVuRbD+Xzs9GhPBhw+SRugIo+dcgIpUrwFymyav X-Received: by 2002:a17:902:868f:: with SMTP id g15mr56022047plo.67.1559922339997; Fri, 07 Jun 2019 08:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559922339; cv=none; d=google.com; s=arc-20160816; b=Y4HOs86ZhNp9PEq+/uD2b3s19E6hNR6/5yrRdb1oP1l4mjeXXFvNO/SnxAUv4RPMzg 6+rf6dVSEU1nwGyjwkOo1KIAEYrvPedQ2rhN4kwWSX7JyLqbYst75dwznEC1t6pRslDb FD0Y9gk/CxO5YOYK1B0A04IcsKB4I6tmt+H33ORkcnG4m+E7fYTFXRfg4OuKyMP+N0+n 090HavasYtiOB5gLPy4Rt7MAB5TOK1kGS/f+VNhcJ/HkJmcIv0c8+rtn3vB9gIoyuqnN jAdiPRFEPnvWsgZBWWBCVj4FUoNTzaM0UenD5IKnNI0/6MDp0OngMyd3rB6Y3mkWllVd 5YWg== 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=A3iGX+qp09zrj/pqROi7Bppwo6+mykZ8H0lhscPZ+Pc=; b=mg7pf42n/eK0Of5m2Jh61iFyicIXicfPmFmgE2k2WNWP6rlWRDb5fIDxeFciDrgiTY zvNOdkQry+OctfFp+znh6XmPnqYOIWlcYmA+fJlGg4pXfwXqM3DlnY8ImpynLFTqCETq jhKWH4vaWyiB2QZx5oEqpB5JgjS6ofa+W9AX3szhd0Efb1HmVx5bT9dJnLpieTA5oS8r allKG342lvv6cc1lv/FuQgYL2dGTrdkWfLekUA32HM7zKVO7vWZRXiFOMg1IVdcDEYc9 E9LLtBy5icfCjo3YZUQaO7VELsqoNVK3fbuXApPCsPBX+50C7qhJut33AMIBNzx83xmN 8B/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZypwXPyY; 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 m3si1965765pjk.86.2019.06.07.08.45.22; Fri, 07 Jun 2019 08:45:39 -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=ZypwXPyY; 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 S1730827AbfFGPnS (ORCPT + 99 others); Fri, 7 Jun 2019 11:43:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:54350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730805AbfFGPnP (ORCPT ); Fri, 7 Jun 2019 11:43:15 -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 69D7A2146F; Fri, 7 Jun 2019 15:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559922194; bh=/PYpOuWtbavN9xB2JzD9aSkp9gW4QFJNMRvXyQgn8PE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZypwXPyY86jVdBqfsWcVk0fC7SKCiQwIxzlTx1vBkrQESbsMEfZjUJa3DM8xjKUD5 w03AFQdUpuIwNdQokkiK+EsN68LyWWQWu7IbdsX4WOmAVDZiZN3189AQj2o5XEngnI ahcQqhb1rN2eaZs+J7uB2WCcjW8ksvf2BaQzi5lo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ravi Bangoria , Madhavan Srinivasan , Michael Ellerman Subject: [PATCH 4.14 44/69] powerpc/perf: Fix MMCRA corruption by bhrb_filter Date: Fri, 7 Jun 2019 17:39:25 +0200 Message-Id: <20190607153853.820106294@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607153848.271562617@linuxfoundation.org> References: <20190607153848.271562617@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 From: Ravi Bangoria commit 3202e35ec1c8fc19cea24253ff83edf702a60a02 upstream. Consider a scenario where user creates two events: 1st event: attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY; fd = perf_event_open(attr, 0, 1, -1, 0); This sets cpuhw->bhrb_filter to 0 and returns valid fd. 2nd event: attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; attr.branch_sample_type = PERF_SAMPLE_BRANCH_CALL; fd = perf_event_open(attr, 0, 1, -1, 0); It overrides cpuhw->bhrb_filter to -1 and returns with error. Now if power_pmu_enable() gets called by any path other than power_pmu_add(), ppmu->config_bhrb(-1) will set MMCRA to -1. Fixes: 3925f46bb590 ("powerpc/perf: Enable branch stack sampling framework") Cc: stable@vger.kernel.org # v3.10+ Signed-off-by: Ravi Bangoria Reviewed-by: Madhavan Srinivasan Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/perf/core-book3s.c | 6 ++++-- arch/powerpc/perf/power8-pmu.c | 3 +++ arch/powerpc/perf/power9-pmu.c | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -1845,6 +1845,7 @@ static int power_pmu_event_init(struct p int n; int err; struct cpu_hw_events *cpuhw; + u64 bhrb_filter; if (!ppmu) return -ENOENT; @@ -1941,13 +1942,14 @@ static int power_pmu_event_init(struct p err = power_check_constraints(cpuhw, events, cflags, n + 1); if (has_branch_stack(event)) { - cpuhw->bhrb_filter = ppmu->bhrb_filter_map( + bhrb_filter = ppmu->bhrb_filter_map( event->attr.branch_sample_type); - if (cpuhw->bhrb_filter == -1) { + if (bhrb_filter == -1) { put_cpu_var(cpu_hw_events); return -EOPNOTSUPP; } + cpuhw->bhrb_filter = bhrb_filter; } put_cpu_var(cpu_hw_events); --- a/arch/powerpc/perf/power8-pmu.c +++ b/arch/powerpc/perf/power8-pmu.c @@ -29,6 +29,7 @@ enum { #define POWER8_MMCRA_IFM1 0x0000000040000000UL #define POWER8_MMCRA_IFM2 0x0000000080000000UL #define POWER8_MMCRA_IFM3 0x00000000C0000000UL +#define POWER8_MMCRA_BHRB_MASK 0x00000000C0000000UL /* PowerISA v2.07 format attribute structure*/ extern struct attribute_group isa207_pmu_format_group; @@ -179,6 +180,8 @@ static u64 power8_bhrb_filter_map(u64 br static void power8_config_bhrb(u64 pmu_bhrb_filter) { + pmu_bhrb_filter &= POWER8_MMCRA_BHRB_MASK; + /* Enable BHRB filter in PMU */ mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter)); } --- a/arch/powerpc/perf/power9-pmu.c +++ b/arch/powerpc/perf/power9-pmu.c @@ -100,6 +100,7 @@ enum { #define POWER9_MMCRA_IFM1 0x0000000040000000UL #define POWER9_MMCRA_IFM2 0x0000000080000000UL #define POWER9_MMCRA_IFM3 0x00000000C0000000UL +#define POWER9_MMCRA_BHRB_MASK 0x00000000C0000000UL /* PowerISA v2.07 format attribute structure*/ extern struct attribute_group isa207_pmu_format_group; @@ -289,6 +290,8 @@ static u64 power9_bhrb_filter_map(u64 br static void power9_config_bhrb(u64 pmu_bhrb_filter) { + pmu_bhrb_filter &= POWER9_MMCRA_BHRB_MASK; + /* Enable BHRB filter in PMU */ mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter)); }