Message ID | 20221201135110.3855965-1-conor.dooley@microchip.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp272533wrr; Thu, 1 Dec 2022 05:56:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7e4vTlMSPQZ0fs9vgCGbzqJy33UsqMJE1IpvOkMR6prQr1rY00d+X/eTBZ+7aARjtwaX7Z X-Received: by 2002:a17:90a:cf02:b0:219:63d9:5167 with SMTP id h2-20020a17090acf0200b0021963d95167mr9063671pju.204.1669902986101; Thu, 01 Dec 2022 05:56:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669902986; cv=none; d=google.com; s=arc-20160816; b=q6MfSHT48R0/mrz65fRK3lgPR5eSgYDNS7+HBsAdp+lLNhl3NTl4KyPscItFF9HYFZ QQ9dgmG3TqDzFu1UmDC8zS6lh3cP1cjfmfHkbtmoHkvolrCMgURAYmpq2W8ZR7H41+ZJ l0+fi0jnbWJAm0fD+LNRY9dH7X33gv5TNzvmqBa8A1CKiiIHrg4zOscqsDBy6KzIuD07 oHf8bE2DQDQLCIo/PeH9r0Si6gbihZyAsruca7MM6CC2rPKcAj1sv/NeWCJ6pfil9pBh TKlstV0xZxuMgg8dAtvBr2wVsV5FVr4FHSWmeb5MOWEseqUaUsNWyPyoC+DFloDD+nO2 QsHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4PVi4DlhjpFB8MDcUUthy1pI5SFFXJwfh8LZu4eEtlU=; b=GvW7e8ZZXkwkDxFeEI4DICpSKbEEwN/C/gvf597qyc66axcX4MB8NmVEScpyTgWjQ0 zuDyQytYI4zOZfWsgAjXu8B+fe2bjTFn0n/cVdh2nHw4HjPzZuv+FVzqjh2AiMa6p4QI r9FtA83cA7lb2+dSPR6hf8S1EyLvV06JHZXZ614p9c3D3CPGHhvSmEBRar2FvgOOSPQ+ 3Nbstze/3uGDUViO+Y95qiErHL6ayn8Jn6VbWfuQ4oRQWXEUFfUinzyueGORR4CaFU2k 2l+TNoRthmAKR0CYLKcHRG3equnoRtd+V3HR/KdSXp5I2QsZWDTDGVRlnXaz5mkO0/p0 p26A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=E9pR5cOH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c24-20020a170902b69800b00186a06a3396si4138185pls.153.2022.12.01.05.56.12; Thu, 01 Dec 2022 05:56:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=E9pR5cOH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbiLANwB (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Thu, 1 Dec 2022 08:52:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbiLANv4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 1 Dec 2022 08:51:56 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A58050D69; Thu, 1 Dec 2022 05:51:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669902715; x=1701438715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bav08OV3LsnmXxf0ohUY0Zv4EUZl+WnAgOolhM8CEvc=; b=E9pR5cOHEpOrvWNkeKO6TCO5iw21e8hMnaSMHD1pE1TIZRWWFvh0+4uS xwzyF76N7bQJ/pCf7WI8oDnBVA8U1FrpamL7PvE6SiNZ/k3OwiZRxfuK0 jFjJv591u3V7siZMdZW/A8u6YxFWcjL3cpm/P0uEexp/vY3yMyyzHkUhG KibRg/+DNto97OccAMA200zRmNvn+DuqBCMdtYJZmTUz0zy4dQYUT+t3g BEMxboqe6v/ANcSAOsSf61RhOMNRelb8KpnqwppcJMbhqmeyVHamjKkdh AHnroB46KlNAklJUNQFE4adHj4tTGMKW7QjK+K2y3guTlQCRUcfDVKmtR g==; X-IronPort-AV: E=Sophos;i="5.96,209,1665471600"; d="scan'208";a="186069167" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 01 Dec 2022 06:51:54 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Thu, 1 Dec 2022 06:51:52 -0700 Received: from wendy.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Thu, 1 Dec 2022 06:51:50 -0700 From: Conor Dooley <conor.dooley@microchip.com> To: Jonathan Corbet <corbet@lwn.net>, Palmer Dabbelt <palmer@dabbelt.com> CC: Conor Dooley <conor.dooley@microchip.com>, <linux-doc@vger.kernel.org>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH] Documentation: riscv: note that counter access is part of the uABI Date: Thu, 1 Dec 2022 13:51:10 +0000 Message-ID: <20221201135110.3855965-1-conor.dooley@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <Y4XvnHIPw8ZuBZEk@wendy> References: <Y4XvnHIPw8ZuBZEk@wendy> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751020193567839128?= X-GMAIL-MSGID: =?utf-8?q?1751020193567839128?= |
Series |
Documentation: riscv: note that counter access is part of the uABI
|
|
Commit Message
Conor Dooley
Dec. 1, 2022, 1:51 p.m. UTC
Commit 5a5294fbe020 ("RISC-V: Re-enable counter access from userspace")
fixed userspace access to CYCLE, TIME & INSTRET counters and left a nice
comment in-place about why they must not be restricted. Since we now
have a uABI doc in RISC-V land, add a section documenting it.
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
---
Based on an, as yet, unsent v2 of my other uABI changes. I don't expect
it to be applicable, just getting a patch into patchwork while I don't
forget about this.
---
Documentation/riscv/uabi.rst | 7 +++++++
1 file changed, 7 insertions(+)
base-commit: 13ee7ef407cfcf63f4f047460ac5bb6ba5a3447d
prerequisite-patch-id: d17a9ffb6fcf99eb683728da98cd50e18cd28fe8
prerequisite-patch-id: 0df4127e3f4a0c02a235fea00bcb69cd94fabb38
prerequisite-patch-id: 171724b870ba212b714ebbded480269accd83733
Comments
On Thu, 01 Dec 2022 05:51:10 PST (-0800), Conor Dooley wrote: > Commit 5a5294fbe020 ("RISC-V: Re-enable counter access from userspace") > fixed userspace access to CYCLE, TIME & INSTRET counters and left a nice > comment in-place about why they must not be restricted. Since we now > have a uABI doc in RISC-V land, add a section documenting it. > > Signed-off-by: Conor Dooley <conor.dooley@microchip.com> > --- > Based on an, as yet, unsent v2 of my other uABI changes. I don't expect > it to be applicable, just getting a patch into patchwork while I don't > forget about this. > --- > Documentation/riscv/uabi.rst | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/Documentation/riscv/uabi.rst b/Documentation/riscv/uabi.rst > index 8d2651e42fda..638ddce56700 100644 > --- a/Documentation/riscv/uabi.rst > +++ b/Documentation/riscv/uabi.rst > @@ -3,6 +3,13 @@ > RISC-V Linux User ABI > ===================== > > +Counter access > +-------------- > + > +Access to the CYCLE, TIME and INSTRET counters, now controlled by the SBI PMU > +extension, were part of the ISA when the uABI was frozen & so remain accessible > +from userspace. > + > ISA string ordering in /proc/cpuinfo > ------------------------------------ > > > base-commit: 13ee7ef407cfcf63f4f047460ac5bb6ba5a3447d > prerequisite-patch-id: d17a9ffb6fcf99eb683728da98cd50e18cd28fe8 > prerequisite-patch-id: 0df4127e3f4a0c02a235fea00bcb69cd94fabb38 > prerequisite-patch-id: 171724b870ba212b714ebbded480269accd83733 Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> I think I merged the last one of these, but if the doc folks pick it up that's fine with me. Otherwise I'll take it when it comes back around, so folks have time to take a look.
Palmer Dabbelt <palmer@dabbelt.com> writes: > On Thu, 01 Dec 2022 05:51:10 PST (-0800), Conor Dooley wrote: >> Commit 5a5294fbe020 ("RISC-V: Re-enable counter access from userspace") >> fixed userspace access to CYCLE, TIME & INSTRET counters and left a nice >> comment in-place about why they must not be restricted. Since we now >> have a uABI doc in RISC-V land, add a section documenting it. >> >> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> >> --- >> Based on an, as yet, unsent v2 of my other uABI changes. I don't expect >> it to be applicable, just getting a patch into patchwork while I don't >> forget about this. >> --- >> Documentation/riscv/uabi.rst | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/Documentation/riscv/uabi.rst b/Documentation/riscv/uabi.rst >> index 8d2651e42fda..638ddce56700 100644 >> --- a/Documentation/riscv/uabi.rst >> +++ b/Documentation/riscv/uabi.rst >> @@ -3,6 +3,13 @@ >> RISC-V Linux User ABI >> ===================== >> >> +Counter access >> +-------------- >> + >> +Access to the CYCLE, TIME and INSTRET counters, now controlled by the SBI PMU >> +extension, were part of the ISA when the uABI was frozen & so remain accessible >> +from userspace. >> + >> ISA string ordering in /proc/cpuinfo >> ------------------------------------ >> >> >> base-commit: 13ee7ef407cfcf63f4f047460ac5bb6ba5a3447d >> prerequisite-patch-id: d17a9ffb6fcf99eb683728da98cd50e18cd28fe8 >> prerequisite-patch-id: 0df4127e3f4a0c02a235fea00bcb69cd94fabb38 >> prerequisite-patch-id: 171724b870ba212b714ebbded480269accd83733 > > Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> > Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > > I think I merged the last one of these, but if the doc folks pick it up > that's fine with me. Otherwise I'll take it when it comes back around, > so folks have time to take a look. "Doc folks" applied it, thanks. :) jon
Jonathan Corbet <corbet@lwn.net> writes: > Palmer Dabbelt <palmer@dabbelt.com> writes: >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> >> >> I think I merged the last one of these, but if the doc folks pick it up >> that's fine with me. Otherwise I'll take it when it comes back around, >> so folks have time to take a look. > > "Doc folks" applied it, thanks. :) Actually, I take that back. I'd missed this part from the patch: > Based on an, as yet, unsent v2 of my other uABI changes. I don't expect > it to be applicable, just getting a patch into patchwork while I don't > forget about this. ...but b4 happily picked up a couple of *other* patches from this thread and applied them instead; I've now undone that. Sorry for the noise. jon
On Sat, Dec 03, 2022 at 03:45:35AM -0700, Jonathan Corbet wrote: > Jonathan Corbet <corbet@lwn.net> writes: > > > Palmer Dabbelt <palmer@dabbelt.com> writes: > >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> > >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > >> > >> I think I merged the last one of these, but if the doc folks pick it up > >> that's fine with me. Otherwise I'll take it when it comes back around, > >> so folks have time to take a look. > > > > "Doc folks" applied it, thanks. :) > > Actually, I take that back. I'd missed this part from the patch: > > > Based on an, as yet, unsent v2 of my other uABI changes. I don't expect > > it to be applicable, just getting a patch into patchwork while I don't > > forget about this. > > ...but b4 happily picked up a couple of *other* patches from this thread > and applied them instead; I've now undone that. Sorry for the noise. Huh, I accidentally put an "in-reply-to" header on this patch. I have been updating some of my submission helper scripts & I must have left the field populated from sending another set by accident: https://lore.kernel.org/linux-riscv/20221129144742.2935581-1-conor.dooley@microchip.com/ Apologies!
On Sat, Dec 3, 2022 at 2:57 AM Conor Dooley <conor@kernel.org> wrote: > > On Sat, Dec 03, 2022 at 03:45:35AM -0700, Jonathan Corbet wrote: > > Jonathan Corbet <corbet@lwn.net> writes: > > > > > Palmer Dabbelt <palmer@dabbelt.com> writes: > > >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> > > >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > > >> > > >> I think I merged the last one of these, but if the doc folks pick it up > > >> that's fine with me. Otherwise I'll take it when it comes back around, > > >> so folks have time to take a look. > > > > > > "Doc folks" applied it, thanks. :) > > > > Actually, I take that back. I'd missed this part from the patch: > > > > > Based on an, as yet, unsent v2 of my other uABI changes. I don't expect > > > it to be applicable, just getting a patch into patchwork while I don't > > > forget about this. > > > > ...but b4 happily picked up a couple of *other* patches from this thread > > and applied them instead; I've now undone that. Sorry for the noise. > > Huh, I accidentally put an "in-reply-to" header on this patch. I have > been updating some of my submission helper scripts & I must have left > the field populated from sending another set by accident: > https://lore.kernel.org/linux-riscv/20221129144742.2935581-1-conor.dooley@microchip.com/ > I don't see the patch upstream. Is this patch merged already ? If not, please hold on merging this for now. We had some discussions around this in the perf community. Here is the thread https://lore.kernel.org/lkml/Y7gN32eHJNyWBvVD@FVFF77S0Q05N/T/ TLDR; Even though x86 allows unrestricted access through rdpmc (not default), it still reads zero unless a privileged root user modifies the MSR interface exposed by the kernel. Quoting PeterZ "RDPMC is only useful if you read counters you own on yourself -- IOW selfmonitoring, using the interface outlined in uapi/linux/perf_events.h near struct perf_event_mmap_page. Any other usage -- you get to keep the pieces." "Anyway, given RISC-V being a very young platform, I would try really *really* *REALLY* hard to stomp on these applications and get them to change in order to reclaim the PMU usage." We need to decide what's the best approach for RISC-V. The current text in uABI will let users assume that cycle/instret can be read without any issues which is wrong. There are few options what we can do for RISC-V: 1. We can trap n emulate and report 0 always as suggested by Mark in that thread. 2. Continue to allow the user to read the counters directly but expects the garbage value depending on the other activities on the system. Hopefully, folks will fix their application by that time. Once we have the procfs interface, we enforce the behavior by breaking the application. In either case, the uABI needs to be updated accordingly. > Apologies! > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv -- Regards, Atish
On Mon, Jan 09, 2023 at 01:36:19PM -0800, Atish Patra wrote: > On Sat, Dec 3, 2022 at 2:57 AM Conor Dooley <conor@kernel.org> wrote: > > > > On Sat, Dec 03, 2022 at 03:45:35AM -0700, Jonathan Corbet wrote: > > > Jonathan Corbet <corbet@lwn.net> writes: > > > > > > > Palmer Dabbelt <palmer@dabbelt.com> writes: > > > >> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> > > > >> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> > > > >> > > > >> I think I merged the last one of these, but if the doc folks pick it up > > > >> that's fine with me. Otherwise I'll take it when it comes back around, > > > >> so folks have time to take a look. > > > > > > > > "Doc folks" applied it, thanks. :) > > > > > > Actually, I take that back. I'd missed this part from the patch: > > > > > > > Based on an, as yet, unsent v2 of my other uABI changes. I don't expect > > > > it to be applicable, just getting a patch into patchwork while I don't > > > > forget about this. > > > > > > ...but b4 happily picked up a couple of *other* patches from this thread > > > and applied them instead; I've now undone that. Sorry for the noise. > > > > Huh, I accidentally put an "in-reply-to" header on this patch. I have > > been updating some of my submission helper scripts & I must have left > > the field populated from sending another set by accident: > > https://lore.kernel.org/linux-riscv/20221129144742.2935581-1-conor.dooley@microchip.com/ > > > > I don't see the patch upstream. Is this patch merged already ? No it's not. I was going to resend it actually, but I noticed the thread yesterday or something. Not sure why you CC'ed half the world on it but not linux-riscv? Or me if you didn't want me resending it! > If not, please hold on merging this for now. We had some discussions > around this in the perf community. > Here is the thread > https://lore.kernel.org/lkml/Y7gN32eHJNyWBvVD@FVFF77S0Q05N/T/ > > TLDR; Even though x86 allows unrestricted access through rdpmc (not > default), it still reads zero unless a privileged root user modifies > the MSR interface exposed by the kernel. > > Quoting PeterZ > > "RDPMC is only useful if you read counters you own on yourself -- IOW > selfmonitoring, using the interface outlined in uapi/linux/perf_events.h > near struct perf_event_mmap_page. > > Any other usage -- you get to keep the pieces." > > "Anyway, given RISC-V being a very young platform, I would try really > *really* *REALLY* hard to stomp on these applications and get them to > change in order to reclaim the PMU usage." > > We need to decide what's the best approach for RISC-V. The current > text in uABI will let users assume that > cycle/instret can be read without any issues which is wrong. > > There are few options what we can do for RISC-V: > > 1. We can trap n emulate and report 0 always as suggested by Mark in > that thread. > 2. Continue to allow the user to read the counters directly but > expects the garbage value depending on the other activities > on the system. Hopefully, folks will fix their application by that time. > > Once we have the procfs interface, we enforce the behavior by breaking > the application. > > In either case, the uABI needs to be updated accordingly. I don't disagree with what I saw either PeterZ or Mark say. I'm happy not to resend this, I've got no skin in the game other than not wanting something like that "documented" only in the driver. What do you intend doing to instigate the "stomping"? Thanks, Conor.
diff --git a/Documentation/riscv/uabi.rst b/Documentation/riscv/uabi.rst index 8d2651e42fda..638ddce56700 100644 --- a/Documentation/riscv/uabi.rst +++ b/Documentation/riscv/uabi.rst @@ -3,6 +3,13 @@ RISC-V Linux User ABI ===================== +Counter access +-------------- + +Access to the CYCLE, TIME and INSTRET counters, now controlled by the SBI PMU +extension, were part of the ISA when the uABI was frozen & so remain accessible +from userspace. + ISA string ordering in /proc/cpuinfo ------------------------------------