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.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS 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 90764C433DF for ; Thu, 9 Jul 2020 04:21:30 +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 E542C20657 for ; Thu, 9 Jul 2020 04:21:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E542C20657 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 4B2NKN2Bq5zDsFH for ; Thu, 9 Jul 2020 14:21:28 +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 4B2KDl29XTzDqWQ for ; Thu, 9 Jul 2020 12:02:15 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06921o52036848; Wed, 8 Jul 2020 22:02:10 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 325kh0sht4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Jul 2020 22:02:10 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06921V93002421; Thu, 9 Jul 2020 02:02:07 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04fra.de.ibm.com with ESMTP id 325k2dr541-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Jul 2020 02:02:07 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 069224BM55377982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Jul 2020 02:02:05 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C85004C044; Thu, 9 Jul 2020 02:02:04 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C63364C046; Thu, 9 Jul 2020 02:02:01 +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:02:01 +0000 (GMT) From: Athira Rajeev Message-Id: <954EDC98-8860-4450-8C8F-1F1738255702@linux.vnet.ibm.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_9D76A3AA-46AB-4C8F-9D7C-DF0114D4E834" 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 07:31:58 +0530 In-Reply-To: <20200708074315.GA21370@in.ibm.com> To: ego References: <1593595262-1433-1-git-send-email-atrajeev@linux.vnet.ibm.com> <1593595262-1433-8-git-send-email-atrajeev@linux.vnet.ibm.com> <0cf26e42a3b190d5ea69d1ba61ae71bcaeee1973.camel@neuling.org> <20200708074315.GA21370@in.ibm.com> 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 mlxscore=0 malwarescore=0 spamscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007090010 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: Vaidyanathan Srinivasan , 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=_9D76A3AA-46AB-4C8F-9D7C-DF0114D4E834 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 08-Jul-2020, at 1:13 PM, Gautham R Shenoy = wrote: >=20 > On Tue, Jul 07, 2020 at 05:17:55PM +1000, Michael Neuling wrote: >> On Wed, 2020-07-01 at 05:20 -0400, Athira Rajeev wrote: >>> PowerISA v3.1 has few updates for the Branch History Rolling = Buffer(BHRB). >>> First is the addition of BHRB disable bit and second new filtering >>> 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 >>> whether BHRB entries are written when BHRB recording is enabled by = other >>> bits. Patch implements support for this BHRB disable bit. >>=20 >> Probably good to note here that this is backwards compatible. So if = you have a >> kernel that doesn't know about this bit, it'll clear it and hence you = still get >> BHRB.=20 >>=20 >> You should also note why you'd want to do disable this (ie. the core = will run >> faster). >>=20 >>> Secondly PowerISA v3.1 introduce filtering support for >>> PERF_SAMPLE_BRANCH_IND_CALL/COND. The patch adds BHRB filter support >>> for "ind_call" and "cond" in power10_bhrb_filter_map(). >>>=20 >>> 'commit bb19af816025 ("powerpc/perf: Prevent kernel address leak to = userspace >>> via BHRB buffer")' >>> 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 >>> 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 ++++++++++++++ >>=20 >> This touches the idle code so we should get those guys on CC (adding = Vaidy and >> Ego). >>=20 >>> 4 files changed, 59 insertions(+), 8 deletions(-) >>>=20 >=20 > [..snip..] >=20 >=20 >>> 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; >=20 > We are saving the whole of MMCRA aren't we ? We might want to just > name it mmcra in that case. >=20 >>> 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 >>> + * to disable BHRB logic when not used. Hence Save and >>> + * restore MMCRA after a state-loss idle. >>> + */ >=20 > Multi-line comment usually has the first line blank. Hi Gautham Thanks for checking. I will change the comment format Yes, we are saving whole of MMCRA.=20 >=20 > /* > * Line 1 > * Line 2 > * . > * . > * . > * Line N > */ >=20 >>> + mmcra_bhrb =3D mfspr(SPRN_MMCRA); >>=20 >>=20 >> Why is the bhrb bit of mmcra special here? >=20 > The comment above could include the consequence of not saving and > restoring MMCRA i.e >=20 > - If the user hasn't asked for the BHRB to be > written the value of MMCRA[BHRBD] =3D 1. >=20 > - On wakeup from stop, MMCRA[BHRBD] will be 0, since MMCRA is not a > previleged resource and will be lost. >=20 > - Thus, if we do not save and restore the MMCRA[BHRBD], the hardware > will be needlessly writing to the BHRB in the problem mode. >=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 > -- > Thanks and Regards > gautham. --Apple-Mail=_9D76A3AA-46AB-4C8F-9D7C-DF0114D4E834 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

On 08-Jul-2020, at 1:13 PM, Gautham R Shenoy <ego@linux.vnet.ibm.com> wrote:

On Tue, Jul 07, 2020 at = 05:17:55PM +1000, Michael Neuling wrote:
On Wed, 2020-07-01 at 05:20 -0400, = Athira Rajeev wrote:
PowerISA v3.1 has few updates for the Branch History Rolling = Buffer(BHRB).
First is the addition of BHRB disable bit = and second new filtering
modes for BHRB.

BHRB disable is controlled via Monitor Mode Control Register = A (MMCRA)
bit 26, namely "BHRB Recording Disable = (BHRBRD)". This field controls
whether BHRB entries are = written when BHRB recording is enabled by other
bits. = Patch implements support for this BHRB disable bit.

Probably good to note here that = this is backwards compatible. So if you have a
kernel that = doesn't know about this bit, it'll clear it and hence you still get
BHRB. 

You should also note why you'd want to do = disable this (ie. the core will run
faster).

Secondly = PowerISA v3.1 introduce filtering support for
PERF_SAMPLE_BRANCH_IND_CALL/COND. The patch adds BHRB filter = support
for "ind_call" and "cond" in = power10_bhrb_filter_map().

'commit = bb19af816025 ("powerpc/perf: Prevent kernel address leak to userspace
via BHRB buffer")'
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.

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 ++++++++++++++

This touches the idle code so we = should get those guys on CC (adding Vaidy and
Ego).

4 files = changed, 59 insertions(+), 8 deletions(-)


[..snip..]


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;

We are saving the whole of MMCRA aren't we ? We might want to = just
name it mmcra = in that case.

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
+  * to disable BHRB logic = when not used. Hence Save and
+  * restore MMCRA after a = state-loss idle.
+  */

Multi-line comment usually has the first line = blank.

Hi = Gautham

Thanks for checking. I will = change the comment format
Yes, we are saving whole of = MMCRA. 

= /*
      = ;   * Line 1
=  * Line 2
 * = .
=  * .
 * = .
=  * Line N
 */

+ = = mmcra_bhrb =3D mfspr(SPRN_MMCRA);


Why is the bhrb bit of mmcra special here?

The comment above could include the consequence of not saving = and
restoring = MMCRA i.e

- If the user = hasn't asked for the BHRB to be
 written the value of MMCRA[BHRBD] =3D 1.

- On wakeup from stop, = MMCRA[BHRBD] will be 0, since MMCRA is not a
 previleged resource and = will be lost.

- Thus, if we = do not save and restore the MMCRA[BHRBD], the hardware
 will be needlessly writing = to the BHRB in the problem mode.


+ }
+
= 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.


--
Thanks and Regards
gautham.

= --Apple-Mail=_9D76A3AA-46AB-4C8F-9D7C-DF0114D4E834--