Skip to content

Commit f7d05ee

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Prevent host from managing timer offsets for protected VMs
For protected VMs, the guest's timer offset state should not be controlled by the host and must always run with a virtual counter offset of 0. The existing timer logic allowed the host to set and manage the timer counter offsets for protected VMs in certain cases. Disable all host-side management of timer offsets for protected VMs by adding checks in the relevant code paths. Signed-off-by: Fuad Tabba <tabba@google.com> Link: https://patch.msgid.link/20251211104710.151771-10-tabba@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent b12b3b0 commit f7d05ee

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

arch/arm64/kvm/arch_timer.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,10 +1056,14 @@ static void timer_context_init(struct kvm_vcpu *vcpu, int timerid)
10561056

10571057
ctxt->timer_id = timerid;
10581058

1059-
if (timerid == TIMER_VTIMER)
1060-
ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;
1061-
else
1062-
ctxt->offset.vm_offset = &kvm->arch.timer_data.poffset;
1059+
if (!kvm_vm_is_protected(vcpu->kvm)) {
1060+
if (timerid == TIMER_VTIMER)
1061+
ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;
1062+
else
1063+
ctxt->offset.vm_offset = &kvm->arch.timer_data.poffset;
1064+
} else {
1065+
ctxt->offset.vm_offset = NULL;
1066+
}
10631067

10641068
hrtimer_setup(&ctxt->hrtimer, kvm_hrtimer_expire, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD);
10651069

@@ -1083,7 +1087,8 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
10831087
timer_context_init(vcpu, i);
10841088

10851089
/* Synchronize offsets across timers of a VM if not already provided */
1086-
if (!test_bit(KVM_ARCH_FLAG_VM_COUNTER_OFFSET, &vcpu->kvm->arch.flags)) {
1090+
if (!vcpu_is_protected(vcpu) &&
1091+
!test_bit(KVM_ARCH_FLAG_VM_COUNTER_OFFSET, &vcpu->kvm->arch.flags)) {
10871092
timer_set_offset(vcpu_vtimer(vcpu), kvm_phys_timer_read());
10881093
timer_set_offset(vcpu_ptimer(vcpu), 0);
10891094
}
@@ -1687,6 +1692,9 @@ int kvm_vm_ioctl_set_counter_offset(struct kvm *kvm,
16871692
if (offset->reserved)
16881693
return -EINVAL;
16891694

1695+
if (kvm_vm_is_protected(kvm))
1696+
return -EINVAL;
1697+
16901698
mutex_lock(&kvm->lock);
16911699

16921700
if (!kvm_trylock_all_vcpus(kvm)) {

0 commit comments

Comments
 (0)