Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1195870ybn; Wed, 2 Oct 2019 12:16:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWwEXVhhPJ9sZr85RJ5yRK7imMyn4EbjKDwTojUcO+6APx9NLa0xb/Y9kYDVLoJsBvz+sI X-Received: by 2002:a17:906:82c1:: with SMTP id a1mr4579927ejy.187.1570043762257; Wed, 02 Oct 2019 12:16:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043762; cv=none; d=google.com; s=arc-20160816; b=dlCVY2lop8Ruwgj1Lm3b1Z1huA6Lv9AKlYo+f2jWGngZnz/d0g9IbsTzr1dv/uv8V7 iYbqisl1Zg6oPE4kU+3Z0pBkl7aj+zYVOSYjfRjflIvSNYdFgQiQPB2Klzyj7g9p7eE9 7ESfc1nAhOiqmqDeAh4qutNvE8ErTzYhfjhRMT0c2VXJm/c63OCF6cAC4pEevak6Wifd 29sdDzFfuWFqgRcZqCCDGzpsrR10sv+GSGAu90DsrnHbRA1eMVjQff5OPqGfSCzmbinE NJ57kBkbJG0vOHKSh/FevvUF/rOKxpqQqYdhwh3+7xVD53/mUlwAFK44LonK51csKs0y XXXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=3t25hg/vuDLV0susKHOMKozfcdIkBRU/ii9dNnY1Mgo=; b=s2yjUk5UHv6+Ncq3wRo0i1yOZw3Nks789KYShb3UA4t40XvKvXPS8I5B7IkUAgYY+3 36mNvUoGJlfpyNmeNvwvlZzww6XfcChhtRCVTs+jflWBir5BO+5vsDiPYQMrsqBYznYx 1FV/c/8s2AUB2uLzZJ3g6ix5NNm+FJEOi7EkKdKbWe1UzLKfzTxMsPh/B5JqYcSacF6A y9zaxO5lGlET1es9p5QEmXhYdvaokE/kPabEXK3BllE3U5vYoOfJ52S1eNIJ3ZOarY8b Bh7co9D1tWcCeQsWbW++dFMf5vT7VZ3qY6cK0rhx2e7N+6irNvE9sYLnRFXLgbJWqkSm JJTg== 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 y20si15615edo.436.2019.10.02.12.15.37; Wed, 02 Oct 2019 12:16:02 -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 S1730149AbfJBTNK (ORCPT + 99 others); Wed, 2 Oct 2019 15:13:10 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35378 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729097AbfJBTIK (ORCPT ); Wed, 2 Oct 2019 15:08:10 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyn-00035W-QK; Wed, 02 Oct 2019 20:08:05 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyn-0003az-A6; Wed, 02 Oct 2019 20:08:05 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Madhavan Srinivasan" , "Michael Ellerman" , "Ravi Bangoria" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 15/87] powerpc/perf: Fix MMCRA corruption by bhrb_filter In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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") Signed-off-by: Ravi Bangoria Reviewed-by: Madhavan Srinivasan Signed-off-by: Michael Ellerman [bwh: Backported to 3.16: drop changes in power9-pmu.c] Signed-off-by: Ben Hutchings --- --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -1726,6 +1726,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; @@ -1822,13 +1823,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 @@ -175,6 +175,7 @@ #define POWER8_MMCRA_IFM1 0x0000000040000000UL #define POWER8_MMCRA_IFM2 0x0000000080000000UL #define POWER8_MMCRA_IFM3 0x00000000C0000000UL +#define POWER8_MMCRA_BHRB_MASK 0x00000000C0000000UL #define ONLY_PLM \ (PERF_SAMPLE_BRANCH_USER |\ @@ -666,6 +667,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)); }