Skip to content

Commit f2aeb7b

Browse files
akihikodakioupton
authored andcommitted
KVM: arm64: PMU: Set raw values from user to PM{C,I}NTEN{SET,CLR}, PMOVS{SET,CLR}
Commit a45f41d ("KVM: arm64: Add {get,set}_user for PM{C,I}NTEN{SET,CLR}, PMOVS{SET,CLR}") changed KVM_SET_ONE_REG to update the mentioned registers in a way matching with the behavior of guest register writes. This is a breaking change of a UAPI though the new semantics looks cleaner and VMMs are not prepared for this. Firecracker, QEMU, and crosvm perform migration by listing registers with KVM_GET_REG_LIST, getting their values with KVM_GET_ONE_REG and setting them with KVM_SET_ONE_REG. This algorithm assumes KVM_SET_ONE_REG restores the values retrieved with KVM_GET_ONE_REG without any alteration. However, bit operations added by the earlier commit do not preserve the values retried with KVM_GET_ONE_REG and potentially break migration. Remove the bit operations that alter the values retrieved with KVM_GET_ONE_REG. Cc: stable@vger.kernel.org Fixes: a45f41d ("KVM: arm64: Add {get,set}_user for PM{C,I}NTEN{SET,CLR}, PMOVS{SET,CLR}") Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Acked-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20250315-pmc-v5-1-ecee87dab216@daynix.com Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 7eb1721 commit f2aeb7b

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,26 +1051,9 @@ static bool access_pmu_evtyper(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
10511051

10521052
static int set_pmreg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, u64 val)
10531053
{
1054-
bool set;
1055-
1056-
val &= kvm_pmu_accessible_counter_mask(vcpu);
1057-
1058-
switch (r->reg) {
1059-
case PMOVSSET_EL0:
1060-
/* CRm[1] being set indicates a SET register, and CLR otherwise */
1061-
set = r->CRm & 2;
1062-
break;
1063-
default:
1064-
/* Op2[0] being set indicates a SET register, and CLR otherwise */
1065-
set = r->Op2 & 1;
1066-
break;
1067-
}
1068-
1069-
if (set)
1070-
__vcpu_sys_reg(vcpu, r->reg) |= val;
1071-
else
1072-
__vcpu_sys_reg(vcpu, r->reg) &= ~val;
1054+
u64 mask = kvm_pmu_accessible_counter_mask(vcpu);
10731055

1056+
__vcpu_sys_reg(vcpu, r->reg) = val & mask;
10741057
return 0;
10751058
}
10761059

0 commit comments

Comments
 (0)