Skip to content

Commit 1db4aaa

Browse files
akihikodakioupton
authored andcommitted
KVM: arm64: PMU: Reload when user modifies registers
Commit d0c94c4 ("KVM: arm64: Restore PMU configuration on first run") added the code to reload the PMU configuration on first run. It is also important to keep the correct state even if system registers are modified after first run, specifically when debugging Windows on QEMU with GDB; QEMU tries to write back all visible registers when resuming the VM execution with GDB, corrupting the PMU state. Windows always uses the PMU so this can cause adverse effects on that particular OS. The usual register writes and reset are already handled independently, but register writes from userspace are not covered. Trigger the code to reload the PMU configuration for them instead so that PMU configuration changes made by users will be applied also after the first run. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250315-pmc-v5-4-ecee87dab216@daynix.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 64074ca commit 1db4aaa

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

arch/arm64/kvm/pmu-emul.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,6 @@ int kvm_arm_pmu_v3_enable(struct kvm_vcpu *vcpu)
917917
return -EINVAL;
918918
}
919919

920-
/* One-off reload of the PMU on first run */
921-
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
922-
923920
return 0;
924921
}
925922

arch/arm64/kvm/sys_regs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@ static int set_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 va
10701070
u64 mask = kvm_pmu_accessible_counter_mask(vcpu);
10711071

10721072
__vcpu_sys_reg(vcpu, r->reg) = val & mask;
1073+
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
1074+
10731075
return 0;
10741076
}
10751077

@@ -1228,6 +1230,8 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
12281230
val |= ARMV8_PMU_PMCR_LC;
12291231

12301232
__vcpu_sys_reg(vcpu, r->reg) = val;
1233+
kvm_make_request(KVM_REQ_RELOAD_PMU, vcpu);
1234+
12311235
return 0;
12321236
}
12331237

0 commit comments

Comments
 (0)