diff mbox

xen/x86: don't lose event interrupts

Message ID alpine.DEB.2.10.1604151814580.2526@sstabellini-ThinkPad-X260 (mailing list archive)
State New, archived
Headers show

Commit Message

Stefano Stabellini April 16, 2016, 1:23 a.m. UTC
On slow platforms with unreliable TSC, such as QEMU emulated machines,
it is possible for the kernel to request the next event in the past. In
that case, in the current implementation of xen_vcpuop_clockevent, we
simply return -ETIME. To be precise the Xen returns -ETIME and we pass
it on. However the result of this is a missed event, which simply causes
the kernel to hang.

Instead it is better to always ask the hypervisor for a timer event,
even if the timeout is in the past. That way there are no lost
interrupts and the kernel survives. To do that, remove the
VCPU_SSHOTTMR_future flag.

Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>

Comments

Jürgen Groß April 21, 2016, 8:59 a.m. UTC | #1
On 16/04/16 03:23, Stefano Stabellini wrote:
> On slow platforms with unreliable TSC, such as QEMU emulated machines,
> it is possible for the kernel to request the next event in the past. In
> that case, in the current implementation of xen_vcpuop_clockevent, we
> simply return -ETIME. To be precise the Xen returns -ETIME and we pass
> it on. However the result of this is a missed event, which simply causes
> the kernel to hang.
> 
> Instead it is better to always ask the hypervisor for a timer event,
> even if the timeout is in the past. That way there are no lost
> interrupts and the kernel survives. To do that, remove the
> VCPU_SSHOTTMR_future flag.
> 
> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>

Acked-by: Juergen Gross <jgross@suse.com>

> 
> diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
> index a0a4e55..6deba5b 100644
> --- a/arch/x86/xen/time.c
> +++ b/arch/x86/xen/time.c
> @@ -290,11 +290,11 @@ static int xen_vcpuop_set_next_event(unsigned long delta,
>  	WARN_ON(!clockevent_state_oneshot(evt));
>  
>  	single.timeout_abs_ns = get_abs_timeout(delta);
> -	single.flags = VCPU_SSHOTTMR_future;
> +	/* Get an event anyway, even if the timeout is already expired */
> +	single.flags = 0;
>  
>  	ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &single);
> -
> -	BUG_ON(ret != 0 && ret != -ETIME);
> +	BUG_ON(ret != 0);
>  
>  	return ret;
>  }
>
Stefano Stabellini April 25, 2016, 10:28 a.m. UTC | #2
On Thu, 21 Apr 2016, Juergen Gross wrote:
> On 16/04/16 03:23, Stefano Stabellini wrote:
> > On slow platforms with unreliable TSC, such as QEMU emulated machines,
> > it is possible for the kernel to request the next event in the past. In
> > that case, in the current implementation of xen_vcpuop_clockevent, we
> > simply return -ETIME. To be precise the Xen returns -ETIME and we pass
> > it on. However the result of this is a missed event, which simply causes
> > the kernel to hang.
> > 
> > Instead it is better to always ask the hypervisor for a timer event,
> > even if the timeout is in the past. That way there are no lost
> > interrupts and the kernel survives. To do that, remove the
> > VCPU_SSHOTTMR_future flag.
> > 
> > Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
> 
> Acked-by: Juergen Gross <jgross@suse.com>

I committed it to xentip/for-linus-4.7


> > diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
> > index a0a4e55..6deba5b 100644
> > --- a/arch/x86/xen/time.c
> > +++ b/arch/x86/xen/time.c
> > @@ -290,11 +290,11 @@ static int xen_vcpuop_set_next_event(unsigned long delta,
> >  	WARN_ON(!clockevent_state_oneshot(evt));
> >  
> >  	single.timeout_abs_ns = get_abs_timeout(delta);
> > -	single.flags = VCPU_SSHOTTMR_future;
> > +	/* Get an event anyway, even if the timeout is already expired */
> > +	single.flags = 0;
> >  
> >  	ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &single);
> > -
> > -	BUG_ON(ret != 0 && ret != -ETIME);
> > +	BUG_ON(ret != 0);
> >  
> >  	return ret;
> >  }
> > 
>
diff mbox

Patch

diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
index a0a4e55..6deba5b 100644
--- a/arch/x86/xen/time.c
+++ b/arch/x86/xen/time.c
@@ -290,11 +290,11 @@  static int xen_vcpuop_set_next_event(unsigned long delta,
 	WARN_ON(!clockevent_state_oneshot(evt));
 
 	single.timeout_abs_ns = get_abs_timeout(delta);
-	single.flags = VCPU_SSHOTTMR_future;
+	/* Get an event anyway, even if the timeout is already expired */
+	single.flags = 0;
 
 	ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &single);
-
-	BUG_ON(ret != 0 && ret != -ETIME);
+	BUG_ON(ret != 0);
 
 	return ret;
 }