All of lore.kernel.org
 help / color / mirror / Atom feed
* [XEN PATCH] evtchn/fifo: Don't set PENDING bit if guest misbehaves
@ 2022-03-16 18:38 Raphael Ning
  2022-03-16 18:58 ` Andrew Cooper
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Raphael Ning @ 2022-03-16 18:38 UTC (permalink / raw)
  To: xen-devel
  Cc: Raphael Ning, Raphael Ning, Andrew Cooper, George Dunlap,
	Jan Beulich, Julien Grall, Stefano Stabellini, Wei Liu,
	David Vrabel

From: Raphael Ning <raphning@amazon.com>

Currently, evtchn_fifo_set_pending() will mark the event as PENDING even
if it fails to lock the FIFO event queue(s), or if the guest has not
initialized the FIFO control block for the target vCPU. A well-behaved
guest should never trigger either of these cases.

There is no good reason to set the PENDING bit (the guest should not
depend on this behaviour anyway) or check for pollers in such corner
cases, so skip that. In fact, both the comment above the for loop and
the commit message for

 41a822c39263 xen/events: rework fifo queue locking

suggest that the bit should be set after the FIFO queue(s) are locked.

Take the opportunity to rename the was_pending variable (flipping its
sense) and switch to the standard bool type.

Suggested-by: David Vrabel <dvrabel@amazon.co.uk>
Signed-off-by: Raphael Ning <raphning@amazon.com>
---
 xen/common/event_fifo.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c
index ed4d3beb10f3..6c74ccebebb7 100644
--- a/xen/common/event_fifo.c
+++ b/xen/common/event_fifo.c
@@ -165,7 +165,7 @@ static void cf_check evtchn_fifo_set_pending(
     unsigned int port;
     event_word_t *word;
     unsigned long flags;
-    bool_t was_pending;
+    bool_t check_pollers = false;
     struct evtchn_fifo_queue *q, *old_q;
     unsigned int try;
     bool linked = true;
@@ -226,8 +226,6 @@ static void cf_check evtchn_fifo_set_pending(
         spin_unlock_irqrestore(&q->lock, flags);
     }
 
-    was_pending = guest_test_and_set_bit(d, EVTCHN_FIFO_PENDING, word);
-
     /* If we didn't get the lock bail out. */
     if ( try == 3 )
     {
@@ -249,6 +247,8 @@ static void cf_check evtchn_fifo_set_pending(
         goto unlock;
     }
 
+    check_pollers = !guest_test_and_set_bit(d, EVTCHN_FIFO_PENDING, word);
+
     /*
      * Link the event if it unmasked and not already linked.
      */
@@ -314,7 +314,7 @@ static void cf_check evtchn_fifo_set_pending(
                                  &v->evtchn_fifo->control_block->ready) )
         vcpu_mark_events_pending(v);
 
-    if ( !was_pending )
+    if ( check_pollers )
         evtchn_check_pollers(d, port);
 }
 
-- 
2.32.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-03-21 10:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 18:38 [XEN PATCH] evtchn/fifo: Don't set PENDING bit if guest misbehaves Raphael Ning
2022-03-16 18:58 ` Andrew Cooper
2022-03-17 10:45   ` Raphael Ning
2022-03-17 14:26   ` Luca Fancellu
2022-03-17 15:29     ` Raphael Ning
2022-03-21 10:23   ` Julien Grall
2022-03-17  6:28 ` Juergen Gross
2022-03-17  8:45   ` David Vrabel
2022-03-21  9:55 ` David Vrabel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.