diff mbox

[1/4] KVM: x86: fix interrupt dropping race in PIT

Message ID 1454516585-28491-2-git-send-email-rkrcmar@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Radim Krčmář Feb. 3, 2016, 4:23 p.m. UTC
A misuse of atomic operations opened a window

             kvm_pit_ack_irq:              |         pit_timer_fn:
  value = atomic_dec_return(&ps->pending); |
                                           |  !atomic_read(&ps->pending)
  if (value < 0) atomic_inc(&ps->pending); |

If ps->pending starts as 0 and we are using the discard policy, we don't
inject any interrupt in kvm_pit_ack_irq or pit_timer_fn, leading to a
missed PIT cycle.

Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
---
 arch/x86/kvm/i8254.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

Comments

Radim Krčmář Feb. 4, 2016, 1:35 p.m. UTC | #1
2016-02-03 17:23+0100, Radim Kr?má?:
> A misuse of atomic operations opened a window
> 
>              kvm_pit_ack_irq:              |         pit_timer_fn:
>   value = atomic_dec_return(&ps->pending); |
>                                            |  !atomic_read(&ps->pending)
>   if (value < 0) atomic_inc(&ps->pending); |
> 
> If ps->pending starts as 0 and we are using the discard policy, we don't
> inject any interrupt in kvm_pit_ack_irq or pit_timer_fn, leading to a
> missed PIT cycle.
> 
> Signed-off-by: Radim Kr?má? <rkrcmar@redhat.com>
> ---
> diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
> @@ -239,13 +239,7 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
>  	int value;
>  
>  	spin_lock(&ps->inject_lock);
> -	value = atomic_dec_return(&ps->pending);
> -	if (value < 0)
> -		/* spurious acks can be generated if, for example, the
> -		 * PIC is being reset.  Handle it gracefully here
> -		 */
> -		atomic_inc(&ps->pending);
> -	else if (value > 0)
> +	if (atomic_add_unless(&ps->pending, -1, 0))

This is not right, I'll redo the series.  Sorry.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index b0ea42b78ccd..de5f5018026f 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -239,13 +239,7 @@  static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
 	int value;
 
 	spin_lock(&ps->inject_lock);
-	value = atomic_dec_return(&ps->pending);
-	if (value < 0)
-		/* spurious acks can be generated if, for example, the
-		 * PIC is being reset.  Handle it gracefully here
-		 */
-		atomic_inc(&ps->pending);
-	else if (value > 0)
+	if (atomic_add_unless(&ps->pending, -1, 0))
 		/* in this case, we had multiple outstanding pit interrupts
 		 * that we needed to inject.  Reinject
 		 */