RISC-V: KVM: Add perf sampling support for guests
authorAtish Patra <atishp@rivosinc.com>
Sat, 20 Apr 2024 15:17:30 +0000 (08:17 -0700)
committerAnup Patel <anup@brainfault.org>
Fri, 26 Apr 2024 07:43:50 +0000 (13:13 +0530)
commit16b0bde9a37c0af404318ca3cf64a11edccb8777
tree15b25401fd17b13b7f3087854c055d6de782bcd1
parentc2f41ddbcdd75689d9f512638a40263e3127be93
RISC-V: KVM: Add perf sampling support for guests

KVM enables perf for guest via counter virtualization. However, the
sampling can not be supported as there is no mechanism to enabled
trap/emulate scountovf in ISA yet. Rely on the SBI PMU snapshot
to provide the counter overflow data via the shared memory.

In case of sampling event, the host first sets the guest's LCOFI
interrupt and injects to the guest via irq filtering mechanism defined
in AIA specification. Thus, ssaia must be enabled in the host in order
to use perf sampling in the guest. No other AIA dependency w.r.t kernel
is required.

Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20240420151741.962500-15-atishp@rivosinc.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/include/asm/csr.h
arch/riscv/include/asm/kvm_vcpu_pmu.h
arch/riscv/include/uapi/asm/kvm.h
arch/riscv/kvm/aia.c
arch/riscv/kvm/vcpu.c
arch/riscv/kvm/vcpu_onereg.c
arch/riscv/kvm/vcpu_pmu.c