linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Re-enable counter access from userspace
@ 2022-09-28 13:18 Palmer Dabbelt
  2022-09-28 13:39 ` Conor Dooley
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2022-09-28 13:18 UTC (permalink / raw)
  To: linux-riscv; +Cc: Palmer Dabbelt

These counters were part of the ISA when we froze the uABI, removing
them breaks userspace.

Link: https://lore.kernel.org/all/YxEhC%2FmDW1lFt36J@aurel32.net/
Fixes: e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
---
 drivers/perf/riscv_pmu_sbi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
index 6f6681bbfd36..e45daffbfb36 100644
--- a/drivers/perf/riscv_pmu_sbi.c
+++ b/drivers/perf/riscv_pmu_sbi.c
@@ -645,8 +645,11 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node)
 	struct riscv_pmu *pmu = hlist_entry_safe(node, struct riscv_pmu, node);
 	struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events);
 
-	/* Enable the access for TIME csr only from the user mode now */
-	csr_write(CSR_SCOUNTEREN, 0x2);
+	/*
+	 * Enable the access for CYCLE, TIME, and INSTRET CSRs from userspace,
+	 * as is necessary to maintain uABI compatibility.
+	 */
+	csr_write(CSR_SCOUNTEREN, 0x7);
 
 	/* Stop all the counters so that they can be enabled from perf */
 	pmu_sbi_stop_all(pmu);
-- 
2.34.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Re-enable counter access from userspace
  2022-09-28 13:18 [PATCH] RISC-V: Re-enable counter access from userspace Palmer Dabbelt
@ 2022-09-28 13:39 ` Conor Dooley
  2022-09-28 20:53 ` Conor Dooley
  2022-10-13 19:45 ` Palmer Dabbelt
  2 siblings, 0 replies; 4+ messages in thread
From: Conor Dooley @ 2022-09-28 13:39 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: linux-riscv

On Wed, Sep 28, 2022 at 06:18:07AM -0700, Palmer Dabbelt wrote:
> These counters were part of the ISA when we froze the uABI, removing
> them breaks userspace.
> 
> Link: https://lore.kernel.org/all/YxEhC%2FmDW1lFt36J@aurel32.net/
> Fixes: e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")

At the risk of stating the obvious, I assume this will also be CC:stable
when you apply it since this goes back as far as (I think) 5.18?

Thanks,
Conor.

> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
> ---
>  drivers/perf/riscv_pmu_sbi.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index 6f6681bbfd36..e45daffbfb36 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -645,8 +645,11 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node)
>  	struct riscv_pmu *pmu = hlist_entry_safe(node, struct riscv_pmu, node);
>  	struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events);
>  
> -	/* Enable the access for TIME csr only from the user mode now */
> -	csr_write(CSR_SCOUNTEREN, 0x2);
> +	/*
> +	 * Enable the access for CYCLE, TIME, and INSTRET CSRs from userspace,
> +	 * as is necessary to maintain uABI compatibility.
> +	 */
> +	csr_write(CSR_SCOUNTEREN, 0x7);
>  
>  	/* Stop all the counters so that they can be enabled from perf */
>  	pmu_sbi_stop_all(pmu);
> -- 
> 2.34.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Re-enable counter access from userspace
  2022-09-28 13:18 [PATCH] RISC-V: Re-enable counter access from userspace Palmer Dabbelt
  2022-09-28 13:39 ` Conor Dooley
@ 2022-09-28 20:53 ` Conor Dooley
  2022-10-13 19:45 ` Palmer Dabbelt
  2 siblings, 0 replies; 4+ messages in thread
From: Conor Dooley @ 2022-09-28 20:53 UTC (permalink / raw)
  To: Palmer Dabbelt; +Cc: linux-riscv

On Wed, Sep 28, 2022 at 06:18:07AM -0700, Palmer Dabbelt wrote:
> These counters were part of the ISA when we froze the uABI, removing
> them breaks userspace.
> 
> Link: https://lore.kernel.org/all/YxEhC%2FmDW1lFt36J@aurel32.net/
> Fixes: e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")
> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>

Completely forgot about this and was wondering why my timer accessing,
userspace program was not working on an unmatched but did on an
icicle... This patch makes it work again :)

Tested-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>

> ---
>  drivers/perf/riscv_pmu_sbi.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c
> index 6f6681bbfd36..e45daffbfb36 100644
> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -645,8 +645,11 @@ static int pmu_sbi_starting_cpu(unsigned int cpu, struct hlist_node *node)
>  	struct riscv_pmu *pmu = hlist_entry_safe(node, struct riscv_pmu, node);
>  	struct cpu_hw_events *cpu_hw_evt = this_cpu_ptr(pmu->hw_events);
>  
> -	/* Enable the access for TIME csr only from the user mode now */
> -	csr_write(CSR_SCOUNTEREN, 0x2);
> +	/*
> +	 * Enable the access for CYCLE, TIME, and INSTRET CSRs from userspace,
> +	 * as is necessary to maintain uABI compatibility.
> +	 */
> +	csr_write(CSR_SCOUNTEREN, 0x7);
>  
>  	/* Stop all the counters so that they can be enabled from perf */
>  	pmu_sbi_stop_all(pmu);
> -- 
> 2.34.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] RISC-V: Re-enable counter access from userspace
  2022-09-28 13:18 [PATCH] RISC-V: Re-enable counter access from userspace Palmer Dabbelt
  2022-09-28 13:39 ` Conor Dooley
  2022-09-28 20:53 ` Conor Dooley
@ 2022-10-13 19:45 ` Palmer Dabbelt
  2 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2022-10-13 19:45 UTC (permalink / raw)
  To: linux-riscv, Palmer Dabbelt

On Wed, 28 Sep 2022 06:18:07 -0700, Palmer Dabbelt wrote:
> These counters were part of the ISA when we froze the uABI, removing
> them breaks userspace.
> 
> 

Applied, thanks!

[1/1] RISC-V: Re-enable counter access from userspace
      https://git.kernel.org/palmer/c/5a5294fbe020

Best regards,
-- 
Palmer Dabbelt <palmer@rivosinc.com>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-13 19:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 13:18 [PATCH] RISC-V: Re-enable counter access from userspace Palmer Dabbelt
2022-09-28 13:39 ` Conor Dooley
2022-09-28 20:53 ` Conor Dooley
2022-10-13 19:45 ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).