]> xenbits.xensource.com Git - xen.git/commitdiff
x86/IRQ: don't keep EOI timer running without need
authorJan Beulich <jbeulich@suse.com>
Thu, 6 Jun 2019 14:04:09 +0000 (16:04 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 6 Jun 2019 14:04:09 +0000 (16:04 +0200)
The timer needs to remain active only until all pending IRQ instances
have seen EOIs from their respective domains. Stop it when the in-flight
count has reached zero in desc_guest_eoi(). Note that this is race free
(with __do_IRQ_guest()), as the IRQ descriptor lock is being held at
that point.

Also pull up stopping of the timer in __do_IRQ_guest() itself: Instead
of stopping it immediately before re-setting, stop it as soon as we've
made it past any early returns from the function (and hence we're sure
it'll get set again).

Finally bail from the actual timer handler in case we find the timer
already active again by the time we've managed to acquire the IRQ
descriptor lock. Without this we may forcibly EOI an IRQ immediately
after it got sent to a guest. For this, timer_is_active() gets split out
of active_timer(), deliberately moving just one of the two ASSERT()s (to
allow the function to be used also on a never initialized timer).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/irq.c
xen/common/timer.c
xen/include/xen/timer.h

index d6451a903bdc4134bbbda31ced01f4de0a7dc12f..335c8ffb67a902bc1e641655fdfe740041cd67cb 100644 (file)
@@ -1117,6 +1117,13 @@ static void irq_guest_eoi_timer_fn(void *data)
 
     action = (irq_guest_action_t *)desc->action;
 
+    /*
+     * Is another instance of this timer already running? Skip everything
+     * to avoid forcing an EOI early.
+     */
+    if ( timer_is_active(&action->eoi_timer) )
+        goto out;
+
     if ( action->ack_type != ACKTYPE_NONE )
     {
         unsigned int i;
@@ -1168,6 +1175,13 @@ static void __do_IRQ_guest(int irq)
         return;
     }
 
+    /*
+     * Stop the timer as soon as we're certain we'll set it again further down,
+     * to prevent the current timeout (if any) to needlessly expire.
+     */
+    if ( action->ack_type != ACKTYPE_NONE )
+        stop_timer(&action->eoi_timer);
+
     if ( action->ack_type == ACKTYPE_EOI )
     {
         sp = pending_eoi_sp(peoi);
@@ -1195,7 +1209,6 @@ static void __do_IRQ_guest(int irq)
 
     if ( action->ack_type != ACKTYPE_NONE )
     {
-        stop_timer(&action->eoi_timer);
         migrate_timer(&action->eoi_timer, smp_processor_id());
         set_timer(&action->eoi_timer, NOW() + MILLISECS(1));
     }
@@ -1458,6 +1471,8 @@ void desc_guest_eoi(struct irq_desc *desc, struct pirq *pirq)
         return;
     }
 
+    stop_timer(&action->eoi_timer);
+
     if ( action->ack_type == ACKTYPE_UNMASK )
     {
         ASSERT(cpumask_empty(action->cpu_eoi_map));
index c85273bf82dfd75796e305eedb66997300c595c9..80531d855db5d0cfa3976b6b0d02f70b36c7b5bf 100644 (file)
@@ -282,11 +282,10 @@ static inline void timer_unlock(struct timer *timer)
 })
 
 
-static bool_t active_timer(struct timer *timer)
+static bool active_timer(const struct timer *timer)
 {
     ASSERT(timer->status >= TIMER_STATUS_inactive);
-    ASSERT(timer->status <= TIMER_STATUS_in_list);
-    return (timer->status >= TIMER_STATUS_in_heap);
+    return timer_is_active(timer);
 }
 
 
index 4513260b0d8603cec8b269ea028a59ec0e1e54b6..3a2a05c6def8850fb479184f86ceeb3e038e33af 100644 (file)
@@ -75,6 +75,19 @@ bool timer_expires_before(struct timer *timer, s_time_t t);
 
 #define timer_is_expired(t) timer_expires_before(t, NOW())
 
+/*
+ * True if a timer is active.
+ *
+ * Unlike for timer_expires_before(), it is the caller's responsibility to
+ * use suitable locking such that the returned value isn't stale by the time
+ * it gets acted upon.
+ */
+static inline bool timer_is_active(const struct timer *timer)
+{
+    ASSERT(timer->status <= TIMER_STATUS_in_list);
+    return timer->status >= TIMER_STATUS_in_heap;
+}
+
 /* Migrate a timer to a different CPU. The timer may be currently active. */
 void migrate_timer(struct timer *timer, unsigned int new_cpu);