Skip to content

Commit 2bf463d

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Implement arch-specific functions for guest perf
Three architecture specific functions are added for the guest perf feature, they are kvm_arch_vcpu_in_kernel(), kvm_arch_vcpu_get_ip() and kvm_arch_pmi_in_guest(). Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 6a16e44 commit 2bf463d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

arch/loongarch/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/kvm.h>
1313
#include <linux/kvm_types.h>
1414
#include <linux/mutex.h>
15+
#include <linux/perf_event.h>
1516
#include <linux/spinlock.h>
1617
#include <linux/threads.h>
1718
#include <linux/types.h>
@@ -292,6 +293,8 @@ static inline int kvm_get_pmu_num(struct kvm_vcpu_arch *arch)
292293
return (arch->cpucfg[6] & CPUCFG6_PMNUM) >> CPUCFG6_PMNUM_SHIFT;
293294
}
294295

296+
bool kvm_arch_pmi_in_guest(struct kvm_vcpu *vcpu);
297+
295298
/* Debug: dump vcpu state */
296299
int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu);
297300

arch/loongarch/kvm/vcpu.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,32 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
361361

362362
bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
363363
{
364-
return false;
364+
unsigned long val;
365+
366+
preempt_disable();
367+
val = gcsr_read(LOONGARCH_CSR_CRMD);
368+
preempt_enable();
369+
370+
return (val & CSR_PRMD_PPLV) == PLV_KERN;
365371
}
366372

373+
#ifdef CONFIG_GUEST_PERF_EVENTS
374+
unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
375+
{
376+
return vcpu->arch.pc;
377+
}
378+
379+
/*
380+
* Returns true if a Performance Monitoring Interrupt (PMI), a.k.a. perf event,
381+
* arrived in guest context. For LoongArch64, if PMU is not passthrough to VM,
382+
* any event that arrives while a vCPU is loaded is considered to be "in guest".
383+
*/
384+
bool kvm_arch_pmi_in_guest(struct kvm_vcpu *vcpu)
385+
{
386+
return (vcpu && !(vcpu->arch.aux_inuse & KVM_LARCH_PMU));
387+
}
388+
#endif
389+
367390
bool kvm_arch_vcpu_preempted_in_kernel(struct kvm_vcpu *vcpu)
368391
{
369392
return false;

0 commit comments

Comments
 (0)