Read MSR_IA32_PERF_CAPABILITIES triggers #GP when pmu is disabled by enable_pmu=0 in KVM. Let's check whether pmu is available before issue msr reading to avoid the #GP. Signed-off-by: Yang Weijiang <weijiang.yang@xxxxxxxxx> --- x86/pmu_lbr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x86/pmu_lbr.c b/x86/pmu_lbr.c index 688634d..835a7bb 100644 --- a/x86/pmu_lbr.c +++ b/x86/pmu_lbr.c @@ -74,13 +74,15 @@ int main(int ac, char **av) return 0; } - perf_cap = rdmsr(MSR_IA32_PERF_CAPABILITIES); eax.full = id.a; if (!eax.split.version_id) { printf("No pmu is detected!\n"); return report_summary(); } + + perf_cap = rdmsr(MSR_IA32_PERF_CAPABILITIES); + if (!(perf_cap & PMU_CAP_LBR_FMT)) { printf("No LBR is detected!\n"); return report_summary(); -- 2.31.1