[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH xenbus] Avoid a small race window that can lead to stuck EvtchnWait() calls


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Paul Durrant <pdurrant@xxxxxxxxxx>
  • Date: Fri, 15 Nov 2019 14:12:26 +0000
  • Cc: Paul Durrant <pdurrant@xxxxxxxxxx>
  • Delivery-date: Fri, 15 Nov 2019 14:12:42 +0000
  • Ironport-sdr: u9hHzD2OIiEEzOUGsqzgdRUj9988+oXbAAqDVyLSPKWu5J5uO0qAi/aYGSVrzOl3zNYqOVrLXy rAwNxp/au+yQ==
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Make sure an event is ack-ed before Channel->Count is incremented
otherwise EvtchnGetCount() could sample the incremented value whilst new
events would be missed. Thus EvtchnWait() could end up waiting for a
Count value that my never be reached.

Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
---
 src/xenbus/evtchn.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/xenbus/evtchn.c b/src/xenbus/evtchn.c
index 0748e50..8a819f3 100644
--- a/src/xenbus/evtchn.c
+++ b/src/xenbus/evtchn.c
@@ -507,8 +507,6 @@ EvtchnPoll(
 
         KeMemoryBarrier();
         if (!Channel->Closed) {
-            Channel->Count++;
-
             RemoveEntryList(&Channel->PendingListEntry);
             InitializeListHead(&Channel->PendingListEntry);
 
@@ -521,6 +519,16 @@ EvtchnPoll(
                               &Context->EvtchnAbi,
                               Channel->LocalPort);
 
+           /*
+            * Make sure the event is ack-ed before Count is incremented
+            * otherwise there is a small window where EvtchnWait() could
+            * end up waiting on the incremented value whilst new events
+            * would be missed (hence Count would not be further
+            * incremented to wake the waiter).
+            */
+           KeMemoryBarrier();
+            Channel->Count++;
+
 #pragma warning(suppress:6387)  // NULL argument
             DoneSomething |= Channel->Callback(NULL, Channel->Argument);
         } else if (List != NULL) {
@@ -923,6 +931,8 @@ EvtchnGetCount(
 {
     UNREFERENCED_PARAMETER(Interface);
 
+    KeMemoryBarrier();
+
     return Channel->Count;
 }
 
-- 
2.17.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.