Skip to contentSkip to conversation

RISC-V: Re-enable counter access from userspace

PATCH Applied Palmer Dabbelt 3 participants 4 messages Sep 28, 2022 – Oct 13, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: Re-enable counter access from userspace

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

Fixes e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")
---
 drivers/perf/riscv_pmu_sbi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/perf/riscv_pmu_sbi.c +5 -2
index 6f6681bbfd36..e45daffbfb36 100644
@@ -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);
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 5 lines · Palmer Dabbelt

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

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.

Quoted 31 lines
---
 drivers/perf/riscv_pmu_sbi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/perf/riscv_pmu_sbi.c +5 -2
index 6f6681bbfd36..e45daffbfb36 100644
@@ -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);
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Tested-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Palmer Dabbelt
Quoted 6 lines · Palmer Dabbelt

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

Fixes e9991434596f ("RISC-V: Add perf platform driver based on SBI PMU extension")

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 :)

Quoted 30 lines
---
 drivers/perf/riscv_pmu_sbi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/perf/riscv_pmu_sbi.c +5 -2
index 6f6681bbfd36..e45daffbfb36 100644
@@ -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);
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author Applied
#3 lore raw
In reply to Palmer Dabbelt
Quoted 4 lines · Palmer Dabbelt

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,

Signature · 6 lines
Palmer Dabbelt <[email protected]>

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv