RISC-V: KVM: Fix the initial sample period value
authorAtish Patra <atishp@rivosinc.com>
Sat, 20 Apr 2024 15:17:26 +0000 (08:17 -0700)
committerAnup Patel <anup@brainfault.org>
Fri, 26 Apr 2024 07:43:42 +0000 (13:13 +0530)
The initial sample period value when counter value is not assigned
should be set to maximum value supported by the counter width.
Otherwise, it may result in spurious interrupts.

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20240420151741.962500-11-atishp@rivosinc.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/vcpu_pmu.c

index 86391a5061dda98d534908a3d17ef78f2ff1fd9e..cee1b9ca4ec481c4abd67912b0731b42f70456e1 100644 (file)
@@ -39,7 +39,7 @@ static u64 kvm_pmu_get_sample_period(struct kvm_pmc *pmc)
        u64 sample_period;
 
        if (!pmc->counter_val)
-               sample_period = counter_val_mask + 1;
+               sample_period = counter_val_mask;
        else
                sample_period = (-pmc->counter_val) & counter_val_mask;