Skip to content

Commit f6e1276

Browse files
covanamKAGA-KOKO
authored andcommitted
KVM: x86/xen: Initialize hrtimer in kvm_xen_init_vcpu()
The hrtimer is initialized in the KVM_XEN_VCPU_SET_ATTR ioctl. That caused problem in the past, because the hrtimer can be initialized multiple times, which was fixed by commit af735db ("KVM: x86/xen: Initialize Xen timer only once"). This commit avoids initializing the timer multiple times by checking the field 'function' of struct hrtimer to determine if it has already been initialized. This is not required and in the way to make the function field private. Move the hrtimer initialization into kvm_xen_init_vcpu() so that it will only be initialized once. Signed-off-by: Nam Cao <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/all/9c33c7224d97d08f4fa30d3cc8687981c1d3e953.1730386209.git.namcao@linutronix.de
1 parent 482a483 commit f6e1276

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

arch/x86/kvm/xen.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,6 @@ static void kvm_xen_stop_timer(struct kvm_vcpu *vcpu)
263263
atomic_set(&vcpu->arch.xen.timer_pending, 0);
264264
}
265265

266-
static void kvm_xen_init_timer(struct kvm_vcpu *vcpu)
267-
{
268-
hrtimer_init(&vcpu->arch.xen.timer, CLOCK_MONOTONIC,
269-
HRTIMER_MODE_ABS_HARD);
270-
vcpu->arch.xen.timer.function = xen_timer_callback;
271-
}
272-
273266
static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic)
274267
{
275268
struct kvm_vcpu_xen *vx = &v->arch.xen;
@@ -1070,9 +1063,6 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data)
10701063
break;
10711064
}
10721065

1073-
if (!vcpu->arch.xen.timer.function)
1074-
kvm_xen_init_timer(vcpu);
1075-
10761066
/* Stop the timer (if it's running) before changing the vector */
10771067
kvm_xen_stop_timer(vcpu);
10781068
vcpu->arch.xen.timer_virq = data->u.timer.port;
@@ -2235,6 +2225,8 @@ void kvm_xen_init_vcpu(struct kvm_vcpu *vcpu)
22352225
vcpu->arch.xen.poll_evtchn = 0;
22362226

22372227
timer_setup(&vcpu->arch.xen.poll_timer, cancel_evtchn_poll, 0);
2228+
hrtimer_init(&vcpu->arch.xen.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD);
2229+
vcpu->arch.xen.timer.function = xen_timer_callback;
22382230

22392231
kvm_gpc_init(&vcpu->arch.xen.runstate_cache, vcpu->kvm);
22402232
kvm_gpc_init(&vcpu->arch.xen.runstate2_cache, vcpu->kvm);

0 commit comments

Comments
 (0)