From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E0C9C433DF for ; Thu, 9 Jul 2020 04:22:55 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A4F5420657 for ; Thu, 9 Jul 2020 04:22:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F5420657 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4B2NM10rWTzF1x5 for ; Thu, 9 Jul 2020 14:22:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=atrajeev@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4B2L922kh4zDqkT for ; Thu, 9 Jul 2020 12:44:06 +1000 (AEST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0692VXO5029008; Wed, 8 Jul 2020 22:44:00 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 325p3he2v3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2020 22:43:59 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0692ZL7L010095; Thu, 9 Jul 2020 02:43:56 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 325mdhg8er-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Jul 2020 02:43:56 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0692hrCB61276334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Jul 2020 02:43:53 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A29AC4C046; Thu, 9 Jul 2020 02:43:53 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AEDF4C044; Thu, 9 Jul 2020 02:43:50 +0000 (GMT) Received: from [9.79.221.246] (unknown [9.79.221.246]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 9 Jul 2020 02:43:50 +0000 (GMT) From: Athira Rajeev Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_84966CA6-39E2-47BB-A0BF-B998D422FA69" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Subject: Re: [PATCH v2 07/10] powerpc/perf: support BHRB disable bit and new filtering modes Date: Thu, 9 Jul 2020 08:13:47 +0530 In-Reply-To: <87v9iy2pyt.fsf@mpe.ellerman.id.au> To: Michael Ellerman References: <1593595262-1433-1-git-send-email-atrajeev@linux.vnet.ibm.com> <1593595262-1433-8-git-send-email-atrajeev@linux.vnet.ibm.com> <87v9iy2pyt.fsf@mpe.ellerman.id.au> X-Mailer: Apple Mail (2.3608.80.23.2.2) X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-08_19:2020-07-08, 2020-07-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 phishscore=0 priorityscore=1501 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007090014 X-Mailman-Approved-At: Thu, 09 Jul 2020 14:05:25 +1000 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Neuling , maddy@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" --Apple-Mail=_84966CA6-39E2-47BB-A0BF-B998D422FA69 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 08-Jul-2020, at 5:12 PM, Michael Ellerman = wrote: >=20 > Athira Rajeev > writes: >=20 >> PowerISA v3.1 has few updates for the Branch History Rolling = Buffer(BHRB). > ^ > a >> First is the addition of BHRB disable bit and second new filtering > ^ > is >> modes for BHRB. >>=20 >> BHRB disable is controlled via Monitor Mode Control Register A = (MMCRA) >> bit 26, namely "BHRB Recording Disable (BHRBRD)". This field controls >=20 > Most people call that bit 37. >=20 >> whether BHRB entries are written when BHRB recording is enabled by = other >> bits. Patch implements support for this BHRB disable bit. > ^ > This >=20 >> Secondly PowerISA v3.1 introduce filtering support for >=20 > .. that should be in a separate patch please. >=20 >> PERF_SAMPLE_BRANCH_IND_CALL/COND. The patch adds BHRB filter support > ^ > This >> for "ind_call" and "cond" in power10_bhrb_filter_map(). >>=20 >> 'commit bb19af816025 ("powerpc/perf: Prevent kernel address leak to = userspace via BHRB buffer")' >=20 > That doesn't need single quotes, and should be wrapped at 72 columns > like the rest of the text. >=20 >> added a check in bhrb_read() to filter the kernel address from BHRB = buffer. Patch here modified >> it to avoid that check for PowerISA v3.1 based processors, since = PowerISA v3.1 allows >> only MSR[PR]=3D1 address to be written to BHRB buffer. >=20 > And that should be a separate patch again please. Sure, I will split these to separate patches >=20 >> Signed-off-by: Athira Rajeev >> --- >> arch/powerpc/perf/core-book3s.c | 27 = +++++++++++++++++++++------ >> arch/powerpc/perf/isa207-common.c | 13 +++++++++++++ >> arch/powerpc/perf/power10-pmu.c | 13 +++++++++++-- >> arch/powerpc/platforms/powernv/idle.c | 14 ++++++++++++++ >> 4 files changed, 59 insertions(+), 8 deletions(-) >>=20 >> diff --git a/arch/powerpc/perf/core-book3s.c = b/arch/powerpc/perf/core-book3s.c >> index fad5159..9709606 100644 >> --- a/arch/powerpc/perf/core-book3s.c >> +++ b/arch/powerpc/perf/core-book3s.c >> @@ -466,9 +466,13 @@ static void power_pmu_bhrb_read(struct = perf_event *event, struct cpu_hw_events * >> * addresses at this point. Check the privileges = before >> * exporting it to userspace (avoid exposure of = regions >> * where we could have speculative execution) >> + * Incase of ISA 310, BHRB will capture only = user-space > ^ > In case of ISA v3.1, Ok,=20 >=20 >> + * address,hence include a check before = filtering code > ^ = ^ > addresses, hence = . >> */ >> - if (is_kernel_addr(addr) && = perf_allow_kernel(&event->attr) !=3D 0) >> - continue; >> + if (!(ppmu->flags & PPMU_ARCH_310S)) >> + if (is_kernel_addr(addr) && >> + perf_allow_kernel(&event->attr) !=3D 0) >> + continue; >=20 > The indentation is weird. You should just check all three conditions > with &&. Ok, will correct this. >=20 >>=20 >> /* Branches are read most recent first (ie. = mfbhrb 0 is >> * the most recent branch). >> @@ -1212,7 +1216,7 @@ static void write_mmcr0(struct cpu_hw_events = *cpuhw, unsigned long mmcr0) >> static void power_pmu_disable(struct pmu *pmu) >> { >> struct cpu_hw_events *cpuhw; >> - unsigned long flags, mmcr0, val; >> + unsigned long flags, mmcr0, val, mmcra =3D 0; >=20 > You initialise it below. >=20 >> if (!ppmu) >> return; >> @@ -1245,12 +1249,23 @@ static void power_pmu_disable(struct pmu = *pmu) >> mb(); >> isync(); >>=20 >> + val =3D mmcra =3D cpuhw->mmcr[2]; >> + >=20 > For mmcr0 (above), val is the variable we mutate and mmcr0 is the > original value. But here you've done the reverse, which is confusing. Yes, I am altering mmcra here and using val as original value. I should = have done it reverse. >=20 >> /* >> * Disable instruction sampling if it was enabled >> */ >> - if (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) { >> - mtspr(SPRN_MMCRA, >> - cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE); >> + if (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) >> + mmcra =3D cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE; >=20 > You just loaded cpuhw->mmcr[2] into mmcra, use it rather than = referring > back to cpuhw->mmcr[2] over and over. >=20 Ok, >> + >> + /* Disable BHRB via mmcra [:26] for p10 if needed */ >> + if (!(cpuhw->mmcr[2] & MMCRA_BHRB_DISABLE)) >=20 > You don't need to check that it's clear AFAICS. Just always set = disable > and the check against val below will catch the nop case. My thought here was to avoid writing to MMCRA ( also avoid mb() and = isync() ) if its not needed. But as you suggested, since I am comparing against original value before = writing, I may not need this check. And I missed feature check here. Will correct it. =20 >=20 >> + mmcra |=3D MMCRA_BHRB_DISABLE; >> + >> + /* Write SPRN_MMCRA if mmcra has either disabled >=20 > Comment format is wrong. >=20 >> + * instruction sampling or BHRB >=20 > Full stop please. Sure >=20 >> + */ >> + if (val !=3D mmcra) { >> + mtspr(SPRN_MMCRA, mmcra); >> mb(); >> isync(); >> } >> diff --git a/arch/powerpc/perf/isa207-common.c = b/arch/powerpc/perf/isa207-common.c >> index 7d4839e..463d925 100644 >> --- a/arch/powerpc/perf/isa207-common.c >> +++ b/arch/powerpc/perf/isa207-common.c >> @@ -404,6 +404,12 @@ int isa207_compute_mmcr(u64 event[], int n_ev, >>=20 >> mmcra =3D mmcr1 =3D mmcr2 =3D mmcr3 =3D 0; >>=20 >> + /* Disable bhrb unless explicitly requested >> + * by setting MMCRA [:26] bit. >> + */ >=20 > Comment format again. >=20 >> + if (cpu_has_feature(CPU_FTR_ARCH_31)) >> + mmcra |=3D MMCRA_BHRB_DISABLE; >=20 > Here we do a feature check before setting MMCRA_BHRB_DISABLE, but you > didn't above? >=20 >> + >> /* Second pass: assign PMCs, set all MMCR1 fields */ >> for (i =3D 0; i < n_ev; ++i) { >> pmc =3D (event[i] >> EVENT_PMC_SHIFT) & = EVENT_PMC_MASK; >> @@ -475,10 +481,17 @@ int isa207_compute_mmcr(u64 event[], int n_ev, >> } >>=20 >> if (event[i] & EVENT_WANTS_BHRB) { >> + /* set MMCRA[:26] to 0 for Power10 to enable = BHRB */ >=20 > "set MMCRA[:26] to 0" =3D=3D "clear MMCRA[:26]=E2=80=9D >=20 Ok >> + if (cpu_has_feature(CPU_FTR_ARCH_31)) >> + mmcra &=3D ~MMCRA_BHRB_DISABLE; >=20 > Newline please. >=20 >> val =3D (event[i] >> EVENT_IFM_SHIFT) & = EVENT_IFM_MASK; >> mmcra |=3D val << MMCRA_IFM_SHIFT; >> } >>=20 >> + /* set MMCRA[:26] to 0 if there is user request for BHRB = */ >> + if (cpu_has_feature(CPU_FTR_ARCH_31) && = has_branch_stack(pevents[i])) >> + mmcra &=3D ~MMCRA_BHRB_DISABLE; >> + >=20 > I think it would be cleaner if you did a single test, eg: >=20 > if (cpu_has_feature(CPU_FTR_ARCH_31) && > (has_branch_stack(pevents[i]) || (event[i] & = EVENT_WANTS_BHRB))) > mmcra &=3D ~MMCRA_BHRB_DISABLE; Sure Michael Thanks for the review. I will address all these changes in the next = version Thanks Athira=20 >=20 >> if (pevents[i]->attr.exclude_user) >> mmcr2 |=3D MMCR2_FCP(pmc); >>=20 >> diff --git a/arch/powerpc/perf/power10-pmu.c = b/arch/powerpc/perf/power10-pmu.c >> index d64d69d..07fb919 100644 >> --- a/arch/powerpc/perf/power10-pmu.c >> +++ b/arch/powerpc/perf/power10-pmu.c >> @@ -82,6 +82,8 @@ >>=20 >> /* MMCRA IFM bits - POWER10 */ >> #define POWER10_MMCRA_IFM1 0x0000000040000000UL >> +#define POWER10_MMCRA_IFM2 0x0000000080000000UL >> +#define POWER10_MMCRA_IFM3 0x00000000C0000000UL >> #define POWER10_MMCRA_BHRB_MASK 0x00000000C0000000UL >>=20 >> /* Table of alternatives, sorted by column 0 */ >> @@ -233,8 +235,15 @@ static u64 power10_bhrb_filter_map(u64 = branch_sample_type) >> if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN) >> return -1; >>=20 >> - if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL) >> - return -1; >> + if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL) { >> + pmu_bhrb_filter |=3D POWER10_MMCRA_IFM2; >> + return pmu_bhrb_filter; >> + } >> + >> + if (branch_sample_type & PERF_SAMPLE_BRANCH_COND) { >> + pmu_bhrb_filter |=3D POWER10_MMCRA_IFM3; >> + return pmu_bhrb_filter; >> + } >>=20 >> if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL) >> return -1; >> diff --git a/arch/powerpc/platforms/powernv/idle.c = b/arch/powerpc/platforms/powernv/idle.c >> index 2dd4673..7db99c7 100644 >> --- a/arch/powerpc/platforms/powernv/idle.c >> +++ b/arch/powerpc/platforms/powernv/idle.c >> @@ -611,6 +611,7 @@ static unsigned long power9_idle_stop(unsigned = long psscr, bool mmu_on) >> unsigned long srr1; >> unsigned long pls; >> unsigned long mmcr0 =3D 0; >> + unsigned long mmcra_bhrb =3D 0; >> struct p9_sprs sprs =3D {}; /* avoid false used-uninitialised */ >> bool sprs_saved =3D false; >>=20 >> @@ -657,6 +658,15 @@ static unsigned long power9_idle_stop(unsigned = long psscr, bool mmu_on) >> */ >> mmcr0 =3D mfspr(SPRN_MMCR0); >> } >> + >> + if (cpu_has_feature(CPU_FTR_ARCH_31)) { >> + /* POWER10 uses MMCRA[:26] as BHRB disable bit >=20 > Comment format. >=20 >> + * to disable BHRB logic when not used. Hence Save and >> + * restore MMCRA after a state-loss idle. >> + */ >> + mmcra_bhrb =3D mfspr(SPRN_MMCRA); >> + } >=20 > It's the whole mmcra it should be called mmcra? Yes, we are saving the whole mmcra.=20 >=20 >> + >> if ((psscr & PSSCR_RL_MASK) >=3D pnv_first_spr_loss_level) { >> sprs.lpcr =3D mfspr(SPRN_LPCR); >> sprs.hfscr =3D mfspr(SPRN_HFSCR); >> @@ -721,6 +731,10 @@ static unsigned long power9_idle_stop(unsigned = long psscr, bool mmu_on) >> mtspr(SPRN_MMCR0, mmcr0); >> } >>=20 >> + /* Reload MMCRA to restore BHRB disable bit for POWER10 = */ >> + if (cpu_has_feature(CPU_FTR_ARCH_31)) >> + mtspr(SPRN_MMCRA, mmcra_bhrb); >> + >> /* >> * DD2.2 and earlier need to set then clear bit 60 in = MMCRA >> * to ensure the PMU starts running. >=20 >=20 > cheers --Apple-Mail=_84966CA6-39E2-47BB-A0BF-B998D422FA69 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 08-Jul-2020, at 5:12 PM, Michael Ellerman <mpe@ellerman.id.au> = wrote:

Athira Rajeev <atrajeev@linux.vnet.ibm.com> writes:

PowerISA v3.1 has few updates for the = Branch History Rolling Buffer(BHRB).
          &nb= sp;       ^
          &nb= sp;       a
First = is the addition of BHRB disable bit and second new filtering
          &nb= sp;            = ;            &= nbsp;           &nb= sp;     ^
          &nb= sp;            = ;            &= nbsp;           &nb= sp;     is
modes for BHRB.

BHRB disable is controlled via Monitor Mode Control Register = A (MMCRA)
bit 26, namely "BHRB Recording Disable = (BHRBRD)". This field controls

Most people call that bit = 37.

whether= BHRB entries are written when BHRB recording is enabled by other
bits. Patch implements support for this BHRB disable bit.
      ^
      This

Secondly PowerISA v3.1 introduce filtering support for

.. that should be in a separate patch please.

PERF_SAMPLE_BRANCH_IND_CALL/COND. The patch adds BHRB filter = support
          &nb= sp;            = ;            ^=
          &nb= sp;            = ;            T= his
for = "ind_call" and "cond" in power10_bhrb_filter_map().

'commit bb19af816025 ("powerpc/perf: Prevent kernel address = leak to userspace via BHRB buffer")'

That doesn't need single quotes, = and should be wrapped at 72 columns
like the rest of the text.

added a check in bhrb_read() to = filter the kernel address from BHRB buffer. Patch here modified
it to avoid that check for PowerISA v3.1 based processors, = since PowerISA v3.1 allows
only MSR[PR]=3D1 address to be = written to BHRB buffer.

And that should be a separate = patch again please.

Sure, I will split these to separate = patches


Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
---
arch/powerpc/perf/core-book3s.c =       | 27 +++++++++++++++++++++------
arch/powerpc/perf/isa207-common.c     | = 13 +++++++++++++
arch/powerpc/perf/power10-pmu.c =       | 13 +++++++++++--
arch/powerpc/platforms/powernv/idle.c | 14 ++++++++++++++
4 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/perf/core-book3s.c = b/arch/powerpc/perf/core-book3s.c
index fad5159..9709606 = 100644
--- a/arch/powerpc/perf/core-book3s.c
+++ b/arch/powerpc/perf/core-book3s.c
@@ -466,9 = +466,13 @@ static void power_pmu_bhrb_read(struct perf_event *event, = struct cpu_hw_events *
 * addresses at this point. = Check the privileges before
 * exporting it to userspace = (avoid exposure of regions
 * where we could have = speculative execution)
+  * Incase of ISA 310, BHRB = will capture only user-space
          &nb= sp;            = ;   ^
          &nb= sp;            = ;   In case of ISA v3.1,

Ok, 

+  * address,hence include a = check before filtering code
          &nb= sp;            = ;   ^ =             &n= bsp;           &nbs= p;            =             ^<= /span>
          &nb= sp;            = ;   addresses, hence =             &n= bsp;           &nbs= p;         .
 */
- if = (is_kernel_addr(addr) && perf_allow_kernel(&event->attr) = !=3D 0)
- continue;
+ if = (!(ppmu->flags & PPMU_ARCH_310S))
+ if = (is_kernel_addr(addr) &&
+ = perf_allow_kernel(&event->attr) !=3D 0)
+ = continue;

The indentation is weird. You should just check all three = conditions
with = &&.

Ok, will = correct this.


= = = /* Branches are read most recent first (ie. mfbhrb 0 is
= = =  * the most = recent branch).
@@ -1212,7 +1216,7 @@ static void = write_mmcr0(struct cpu_hw_events *cpuhw, unsigned long mmcr0)
static void power_pmu_disable(struct pmu *pmu)
{
struct cpu_hw_events *cpuhw;
- = unsigned long flags, mmcr0, val;
+ unsigned = long flags, mmcr0, val, mmcra =3D 0;

You initialise it = below.

if = (!ppmu)
return;
@@ -1245,12 +1249,23 @@ static void = power_pmu_disable(struct pmu *pmu)
mb();
= = isync();

+ val =3D = mmcra =3D cpuhw->mmcr[2];
+

For mmcr0 (above), val is the variable we mutate and mmcr0 is = the
original = value. But here you've done the reverse, which is confusing.

Yes, I am = altering mmcra here and using val as original value. I should have done = it reverse.


/*
 * Disable instruction = sampling if it was enabled
 */
- if = (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE) {
- = mtspr(SPRN_MMCRA,
-       = ;cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE);
+ if = (cpuhw->mmcr[2] & MMCRA_SAMPLE_ENABLE)
+ mmcra =3D = cpuhw->mmcr[2] & ~MMCRA_SAMPLE_ENABLE;

You just loaded cpuhw->mmcr[2] into mmcra, use it rather = than referring
back to cpuhw->mmcr[2] over and over.


Ok,
+
+ = = /* Disable BHRB via mmcra [:26] for p10 if needed */
+ = = if (!(cpuhw->mmcr[2] & MMCRA_BHRB_DISABLE))

You don't need to check that it's clear AFAICS. Just always = set disable
and the check = against val below will catch the nop case.

My thought here was to avoid writing to MMCRA ( also = avoid mb() and isync() ) if its not needed.
But as you = suggested, since I am comparing against original value before writing, I = may not need this check.
And I missed feature check here. Will = correct it.
 

+ mmcra |=3D MMCRA_BHRB_DISABLE;
+
+ /* Write SPRN_MMCRA if mmcra has = either disabled

Comment format is wrong.

+  * instruction sampling or = BHRB

Full stop please.

Sure

+  */
+ if (val = !=3D mmcra) {
+ mtspr(SPRN_MMCRA, mmcra);
= = = mb();
isync();
}
diff --git a/arch/powerpc/perf/isa207-common.c = b/arch/powerpc/perf/isa207-common.c
index 7d4839e..463d925 = 100644
--- a/arch/powerpc/perf/isa207-common.c
+++ b/arch/powerpc/perf/isa207-common.c
@@ = -404,6 +404,12 @@ int isa207_compute_mmcr(u64 event[], int n_ev,

mmcra =3D mmcr1 =3D mmcr2 =3D = mmcr3 =3D 0;

+ /* Disable bhrb unless explicitly = requested
+  * by setting MMCRA [:26] = bit.
+  */

Comment format again.

+ if = (cpu_has_feature(CPU_FTR_ARCH_31))
+ mmcra |=3D = MMCRA_BHRB_DISABLE;

Here we do a feature check before setting MMCRA_BHRB_DISABLE, = but you
didn't = above?

+
= /* Second pass: assign PMCs, set all MMCR1 fields */
= for (i =3D 0; i < n_ev; ++i) {
pmc =     =3D (event[i] >> EVENT_PMC_SHIFT) & = EVENT_PMC_MASK;
@@ -475,10 +481,17 @@ int = isa207_compute_mmcr(u64 event[], int n_ev,
}

if (event[i] & = EVENT_WANTS_BHRB) {
+ /* set MMCRA[:26] to 0 for = Power10 to enable BHRB */

"set MMCRA[:26] to 0" =3D=3D = "clear MMCRA[:26]=E2=80=9D

Ok

+ if = (cpu_has_feature(CPU_FTR_ARCH_31))
+ mmcra = &=3D ~MMCRA_BHRB_DISABLE;

Newline = please.

val =3D = (event[i] >> EVENT_IFM_SHIFT) & EVENT_IFM_MASK;
= = = mmcra |=3D val << MMCRA_IFM_SHIFT;
}

+ /* set MMCRA[:26] to 0 if there = is user request for BHRB */
+ if = (cpu_has_feature(CPU_FTR_ARCH_31) && = has_branch_stack(pevents[i]))
+ mmcra = &=3D ~MMCRA_BHRB_DISABLE;
+

I think it would be cleaner if you did a single test, = eg:

= if = (cpu_has_feature(CPU_FTR_ARCH_31) &&
          &nb= sp;       (has_branch_stack(pevents[i])= || (event[i] & EVENT_WANTS_BHRB)))
= mmcra &=3D ~MMCRA_BHRB_DISABLE;

Sure = Michael

Thanks for the review. I = will address all these changes in the next version

Thanks
Athira 

if = (pevents[i]->attr.exclude_user)
mmcr2 |=3D = MMCR2_FCP(pmc);

diff --git = a/arch/powerpc/perf/power10-pmu.c b/arch/powerpc/perf/power10-pmu.c
index d64d69d..07fb919 100644
--- = a/arch/powerpc/perf/power10-pmu.c
+++ = b/arch/powerpc/perf/power10-pmu.c
@@ -82,6 +82,8 @@

/* MMCRA IFM bits - POWER10 */
#define POWER10_MMCRA_IFM1 0x0000000040000000UL
+#define POWER10_MMCRA_IFM2 0x0000000080000000UL
+#define POWER10_MMCRA_IFM3 0x00000000C0000000UL
#define POWER10_MMCRA_BHRB_MASK 0x00000000C0000000UL

/* Table of alternatives, sorted by column 0 = */
@@ -233,8 +235,15 @@ static u64 = power10_bhrb_filter_map(u64 branch_sample_type)
if = (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
= = return -1;

- if = (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
- = = return -1;
+ if (branch_sample_type & = PERF_SAMPLE_BRANCH_IND_CALL) {
+ = pmu_bhrb_filter |=3D POWER10_MMCRA_IFM2;
+ return = pmu_bhrb_filter;
+ }
+
+ = if (branch_sample_type & PERF_SAMPLE_BRANCH_COND) {
+ = = pmu_bhrb_filter |=3D POWER10_MMCRA_IFM3;
+ return = pmu_bhrb_filter;
+ }

= if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL)
= = return -1;
diff --git = a/arch/powerpc/platforms/powernv/idle.c = b/arch/powerpc/platforms/powernv/idle.c
index = 2dd4673..7db99c7 100644
--- = a/arch/powerpc/platforms/powernv/idle.c
+++ = b/arch/powerpc/platforms/powernv/idle.c
@@ -611,6 +611,7 = @@ static unsigned long power9_idle_stop(unsigned long psscr, bool = mmu_on)
unsigned long srr1;
unsigned = long pls;
unsigned long mmcr0 =3D 0;
+ = unsigned long mmcra_bhrb =3D 0;
struct = p9_sprs sprs =3D {}; /* avoid false used-uninitialised */
= bool sprs_saved =3D false;

@@ -657,6 = +658,15 @@ static unsigned long power9_idle_stop(unsigned long psscr, = bool mmu_on)
  */
= mmcr0 = = =3D mfspr(SPRN_MMCR0);
}
+
+ = if (cpu_has_feature(CPU_FTR_ARCH_31)) {
+ /* = POWER10 uses MMCRA[:26] as BHRB disable bit
Comment format.

+  * to disable BHRB logic = when not used. Hence Save and
+  * restore MMCRA after a = state-loss idle.
+  */
+ = mmcra_bhrb =3D mfspr(SPRN_MMCRA);
+ }

It's the whole mmcra it should be called mmcra?

Yes, we are = saving the whole mmcra. 

+
if = ((psscr & PSSCR_RL_MASK) >=3D pnv_first_spr_loss_level) {
= = sprs.lpcr =3D mfspr(SPRN_LPCR);
= sprs.hfscr =3D mfspr(SPRN_HFSCR);
@@ -721,6 +731,10 @@ = static unsigned long power9_idle_stop(unsigned long psscr, bool = mmu_on)
mtspr(SPRN_MMCR0, mmcr0);
}

+ /* Reload MMCRA to restore BHRB = disable bit for POWER10 */
+ if = (cpu_has_feature(CPU_FTR_ARCH_31))
+ = mtspr(SPRN_MMCRA, mmcra_bhrb);
+
/*
= =  * DD2.2 and = earlier need to set then clear bit 60 in MMCRA
 * to ensure the PMU starts = running.


cheers

= --Apple-Mail=_84966CA6-39E2-47BB-A0BF-B998D422FA69--