From: Like Xu <likexu@xxxxxxxxxxx> The check_emulated_instr() testcase fails when the KVM module parameter "force_emulation_prefix" is 1. The root cause is that the value written by the counter exceeds the maximum bit width of the GP counter. Signed-off-by: Like Xu <likexu@xxxxxxxxxxx> --- x86/pmu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x86/pmu.c b/x86/pmu.c index 356d589..4dbbe71 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -477,6 +477,7 @@ static void check_running_counter_wrmsr(void) static void check_emulated_instr(void) { uint64_t status, instr_start, brnch_start; + uint64_t gp_counter_width = (1ull << pmu.gp_counter_width) - 1; unsigned int branch_idx = pmu.is_intel ? 5 : 2; pmu_counter_t brnch_cnt = { .ctr = MSR_GP_COUNTERx(0), @@ -498,8 +499,8 @@ static void check_emulated_instr(void) brnch_start = -EXPECTED_BRNCH; instr_start = -EXPECTED_INSTR; - wrmsr(MSR_GP_COUNTERx(0), brnch_start); - wrmsr(MSR_GP_COUNTERx(1), instr_start); + wrmsr(MSR_GP_COUNTERx(0), brnch_start & gp_counter_width); + wrmsr(MSR_GP_COUNTERx(1), instr_start & gp_counter_width); // KVM_FEP is a magic prefix that forces emulation so // 'KVM_FEP "jne label\n"' just counts as a single instruction. asm volatile( -- 2.39.0