Skip to content

Commit 5bc4097

Browse files
atishp04avpatel
authored andcommitted
RISC-V: KVM: Remove scounteren initialization
Scounteren CSR controls the direct access the hpmcounters and cycle/ instret/time from the userspace. It's the supervisor's responsibility to set it up correctly for it's user space. They hypervisor doesn't need to decide the policy on behalf of the supervisor. Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20250515-fix_scounteren_vs-v3-1-729dc088943e@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 9f0e6b9 commit 5bc4097

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

arch/riscv/kernel/head.S

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ secondary_start_sbi:
131131
csrw CSR_IE, zero
132132
csrw CSR_IP, zero
133133

134+
#ifndef CONFIG_RISCV_M_MODE
135+
/* Enable time CSR */
136+
li t0, 0x2
137+
csrw CSR_SCOUNTEREN, t0
138+
#endif
139+
134140
/* Load the global pointer */
135141
load_global_pointer
136142

@@ -226,6 +232,10 @@ SYM_CODE_START(_start_kernel)
226232
* to hand it to us.
227233
*/
228234
csrr a0, CSR_MHARTID
235+
#else
236+
/* Enable time CSR */
237+
li t0, 0x2
238+
csrw CSR_SCOUNTEREN, t0
229239
#endif /* CONFIG_RISCV_M_MODE */
230240

231241
/* Load the global pointer */

arch/riscv/kvm/vcpu.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ static void kvm_riscv_vcpu_context_reset(struct kvm_vcpu *vcpu)
7979
cntx->hstatus |= HSTATUS_VTW;
8080
cntx->hstatus |= HSTATUS_SPVP;
8181
cntx->hstatus |= HSTATUS_SPV;
82-
83-
/* By default, make CY, TM, and IR counters accessible in VU mode */
84-
csr->scounteren = 0x7;
8582
}
8683

8784
static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)