KVM support: detect KVM and avoid touching unimplemented MSRs

This commit is contained in:
Balazs Gerofi
2016-05-26 01:11:08 +09:00
parent 435e2bdeb4
commit 14ec92518e
2 changed files with 31 additions and 0 deletions

View File

@@ -14,6 +14,7 @@
#include <registers.h>
extern unsigned int *x86_march_perfmap;
extern int running_on_kvm(void);
#define X86_CR4_PCE 0x00000100
@@ -22,6 +23,9 @@ void x86_init_perfctr(void)
unsigned long reg;
unsigned long value = 0;
/* Do not do it on KVM */
if (running_on_kvm()) return;
/* Allow PMC to be read from user space */
asm volatile("movq %%cr4, %0" : "=r"(reg));
reg |= X86_CR4_PCE;