* [PATCH 0/2] Fixes for KVM PMU trap/emulation
@ 2024-08-16 7:08 Atish Patra
2024-08-16 7:08 ` [PATCH 1/2] RISC-V: KVM: Allow legacy PMU access from guest Atish Patra
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Atish Patra @ 2024-08-16 7:08 UTC (permalink / raw)
To: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, Atish Patra
This series contains two small fixes to improve the KVM PMU trap/emulation
code. The issue can be observed if SBI PMU is disabled or forced the kvm
to use hpmcounter31.
Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
Atish Patra (2):
RISC-V: KVM: Allow legacy PMU access from guest
RISC-V: KVM: Fix to allow hpmcounter31 from the guest
arch/riscv/include/asm/kvm_vcpu_pmu.h | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
---
base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
change-id: 20240729-kvm_pmu_fixes-26754d2a077d
--
Regards,
Atish patra
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] RISC-V: KVM: Allow legacy PMU access from guest
2024-08-16 7:08 [PATCH 0/2] Fixes for KVM PMU trap/emulation Atish Patra
@ 2024-08-16 7:08 ` Atish Patra
2024-08-16 7:08 ` [PATCH 2/2] RISC-V: KVM: Fix to allow hpmcounter31 from the guest Atish Patra
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Atish Patra @ 2024-08-16 7:08 UTC (permalink / raw)
To: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, Atish Patra
Currently, KVM traps & emulates PMU counter access only if SBI PMU
is available as the guest can only configure/read PMU counters via
SBI only. However, if SBI PMU is not enabled in the host, the
guest will fallback to the legacy PMU which will try to access
cycle/instret and result in an illegal instruction trap which
is not desired.
KVM can allow dummy emulation of cycle/instret only for the guest
if SBI PMU is not enabled in the host. The dummy emulation will
still return zero as we don't to expose the host counter values
from a guest using legacy PMU.
Fixes: a9ac6c37521f ("RISC-V: KVM: Implement trap & emulate for hpmcounters")
Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
arch/riscv/include/asm/kvm_vcpu_pmu.h | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h
index fa0f535bbbf0..c309daa2d75a 100644
--- a/arch/riscv/include/asm/kvm_vcpu_pmu.h
+++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h
@@ -10,6 +10,7 @@
#define __KVM_VCPU_RISCV_PMU_H
#include <linux/perf/riscv_pmu.h>
+#include <asm/kvm_vcpu_insn.h>
#include <asm/sbi.h>
#ifdef CONFIG_RISCV_PMU_SBI
@@ -104,8 +105,20 @@ void kvm_riscv_vcpu_pmu_reset(struct kvm_vcpu *vcpu);
struct kvm_pmu {
};
+static inline int kvm_riscv_vcpu_pmu_read_legacy(struct kvm_vcpu *vcpu, unsigned int csr_num,
+ unsigned long *val, unsigned long new_val,
+ unsigned long wr_mask)
+{
+ if (csr_num == CSR_CYCLE || csr_num == CSR_INSTRET) {
+ *val = 0;
+ return KVM_INSN_CONTINUE_NEXT_SEPC;
+ } else {
+ return KVM_INSN_ILLEGAL_TRAP;
+ }
+}
+
#define KVM_RISCV_VCPU_HPMCOUNTER_CSR_FUNCS \
-{.base = 0, .count = 0, .func = NULL },
+{.base = CSR_CYCLE, .count = 3, .func = kvm_riscv_vcpu_pmu_read_legacy },
static inline void kvm_riscv_vcpu_pmu_init(struct kvm_vcpu *vcpu) {}
static inline int kvm_riscv_vcpu_pmu_incr_fw(struct kvm_vcpu *vcpu, unsigned long fid)
--
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] 5+ messages in thread
* [PATCH 2/2] RISC-V: KVM: Fix to allow hpmcounter31 from the guest
2024-08-16 7:08 [PATCH 0/2] Fixes for KVM PMU trap/emulation Atish Patra
2024-08-16 7:08 ` [PATCH 1/2] RISC-V: KVM: Allow legacy PMU access from guest Atish Patra
@ 2024-08-16 7:08 ` Atish Patra
2024-08-20 5:40 ` [PATCH 0/2] Fixes for KVM PMU trap/emulation Anup Patel
2024-10-01 11:35 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 5+ messages in thread
From: Atish Patra @ 2024-08-16 7:08 UTC (permalink / raw)
To: Anup Patel, Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Andrew Jones
Cc: kvm, kvm-riscv, linux-riscv, linux-kernel, Atish Patra
The csr_fun defines a count parameter which defines the total number
CSRs emulated in KVM starting from the base. This value should be
equal to total number of counters possible for trap/emulation (32).
Fixes: a9ac6c37521f ("RISC-V: KVM: Implement trap & emulate for hpmcounters")
Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
arch/riscv/include/asm/kvm_vcpu_pmu.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/riscv/include/asm/kvm_vcpu_pmu.h b/arch/riscv/include/asm/kvm_vcpu_pmu.h
index c309daa2d75a..1d85b6617508 100644
--- a/arch/riscv/include/asm/kvm_vcpu_pmu.h
+++ b/arch/riscv/include/asm/kvm_vcpu_pmu.h
@@ -65,11 +65,11 @@ struct kvm_pmu {
#if defined(CONFIG_32BIT)
#define KVM_RISCV_VCPU_HPMCOUNTER_CSR_FUNCS \
-{.base = CSR_CYCLEH, .count = 31, .func = kvm_riscv_vcpu_pmu_read_hpm }, \
-{.base = CSR_CYCLE, .count = 31, .func = kvm_riscv_vcpu_pmu_read_hpm },
+{.base = CSR_CYCLEH, .count = 32, .func = kvm_riscv_vcpu_pmu_read_hpm }, \
+{.base = CSR_CYCLE, .count = 32, .func = kvm_riscv_vcpu_pmu_read_hpm },
#else
#define KVM_RISCV_VCPU_HPMCOUNTER_CSR_FUNCS \
-{.base = CSR_CYCLE, .count = 31, .func = kvm_riscv_vcpu_pmu_read_hpm },
+{.base = CSR_CYCLE, .count = 32, .func = kvm_riscv_vcpu_pmu_read_hpm },
#endif
int kvm_riscv_vcpu_pmu_incr_fw(struct kvm_vcpu *vcpu, unsigned long fid);
--
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] 5+ messages in thread
* Re: [PATCH 0/2] Fixes for KVM PMU trap/emulation
2024-08-16 7:08 [PATCH 0/2] Fixes for KVM PMU trap/emulation Atish Patra
2024-08-16 7:08 ` [PATCH 1/2] RISC-V: KVM: Allow legacy PMU access from guest Atish Patra
2024-08-16 7:08 ` [PATCH 2/2] RISC-V: KVM: Fix to allow hpmcounter31 from the guest Atish Patra
@ 2024-08-20 5:40 ` Anup Patel
2024-10-01 11:35 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 5+ messages in thread
From: Anup Patel @ 2024-08-20 5:40 UTC (permalink / raw)
To: Atish Patra
Cc: Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
Andrew Jones, kvm, kvm-riscv, linux-riscv, linux-kernel
On Fri, Aug 16, 2024 at 12:38 PM Atish Patra <atishp@rivosinc.com> wrote:
>
> This series contains two small fixes to improve the KVM PMU trap/emulation
> code. The issue can be observed if SBI PMU is disabled or forced the kvm
> to use hpmcounter31.
>
> Signed-off-by: Atish Patra <atishp@rivosinc.com>
> ---
> Atish Patra (2):
> RISC-V: KVM: Allow legacy PMU access from guest
> RISC-V: KVM: Fix to allow hpmcounter31 from the guest
Queued this patch for Linux-6.11 fixes.
Regards,
Anup
>
> arch/riscv/include/asm/kvm_vcpu_pmu.h | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
> ---
> base-commit: 8400291e289ee6b2bf9779ff1c83a291501f017b
> change-id: 20240729-kvm_pmu_fixes-26754d2a077d
> --
> Regards,
> Atish patra
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] Fixes for KVM PMU trap/emulation
2024-08-16 7:08 [PATCH 0/2] Fixes for KVM PMU trap/emulation Atish Patra
` (2 preceding siblings ...)
2024-08-20 5:40 ` [PATCH 0/2] Fixes for KVM PMU trap/emulation Anup Patel
@ 2024-10-01 11:35 ` patchwork-bot+linux-riscv
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-10-01 11:35 UTC (permalink / raw)
To: Atish Patra
Cc: linux-riscv, anup, atishp, paul.walmsley, palmer, aou, ajones,
kvm, kvm-riscv, linux-kernel
Hello:
This series was applied to riscv/linux.git (fixes)
by Anup Patel <anup@brainfault.org>:
On Fri, 16 Aug 2024 00:08:07 -0700 you wrote:
> This series contains two small fixes to improve the KVM PMU trap/emulation
> code. The issue can be observed if SBI PMU is disabled or forced the kvm
> to use hpmcounter31.
>
> Signed-off-by: Atish Patra <atishp@rivosinc.com>
> ---
> Atish Patra (2):
> RISC-V: KVM: Allow legacy PMU access from guest
> RISC-V: KVM: Fix to allow hpmcounter31 from the guest
>
> [...]
Here is the summary with links:
- [1/2] RISC-V: KVM: Allow legacy PMU access from guest
https://git.kernel.org/riscv/c/7d1ffc8b087e
- [2/2] RISC-V: KVM: Fix to allow hpmcounter31 from the guest
https://git.kernel.org/riscv/c/5aa09297a3dc
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-01 11:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-16 7:08 [PATCH 0/2] Fixes for KVM PMU trap/emulation Atish Patra
2024-08-16 7:08 ` [PATCH 1/2] RISC-V: KVM: Allow legacy PMU access from guest Atish Patra
2024-08-16 7:08 ` [PATCH 2/2] RISC-V: KVM: Fix to allow hpmcounter31 from the guest Atish Patra
2024-08-20 5:40 ` [PATCH 0/2] Fixes for KVM PMU trap/emulation Anup Patel
2024-10-01 11:35 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox