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

[PATCH] Revert to KeMemoryBarrier() as poll loop barriers


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Mon, 1 Jun 2026 10:16:13 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Feedback-ID"
  • Cc: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Delivery-date: Mon, 01 Jun 2026 08:16:24 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

7a4a79fe169d ("Weaken and delete unnecessary barriers") attempted to
replace barriers in the transmitter/receiver poll loops with their
xen_mb/rmb/wmb equivalents. Part of this involved replacing the full
barrier at the end of each poll loop with a "release barrier"
consisting of xen_rmb + xen_wmb.

This is fine on x86 since each store has release ordering. However, this
is incorrect in the Linux memory model, as rmb/wmb (and their smp_
equivalents) did not guarantee relative ordering of loads and subsequent
stores, unlike a release operation. Therefore, without specializing for
each architecture, a release barrier in this model would require a full
memory barrier (i.e. mb()).

Inconveniently, WDK doesn't provide a release barrier nor a release
store. I couldn't measure a performance difference from 7a4a79fe169d in
my limited testing, so revert the change.

Fixes: 7a4a79fe169d ("Weaken and delete unnecessary barriers")
Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xenvif/receiver.c    | 14 ++++++--------
 src/xenvif/transmitter.c |  7 +++----
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/xenvif/receiver.c b/src/xenvif/receiver.c
index bde1cba..0ed46e6 100644
--- a/src/xenvif/receiver.c
+++ b/src/xenvif/receiver.c
@@ -1836,12 +1836,12 @@ ReceiverRingFill(
     Receiver = Ring->Receiver;
     Frontend = Receiver->Frontend;
 
-    xen_mb();
+    KeMemoryBarrier();
 
     req_prod = Ring->Front.req_prod_pvt;
     rsp_cons = Ring->Front.rsp_cons;
 
-    xen_rmb();
+    KeMemoryBarrier();
 
     while (req_prod - rsp_cons < RING_SIZE(&Ring->Front)) {
         PXENVIF_RECEIVER_PACKET     Packet;
@@ -1879,8 +1879,7 @@ ReceiverRingFill(
         Ring->Pending[id] = Fragment;
     }
 
-    xen_rmb();
-    xen_wmb();
+    KeMemoryBarrier();
 
     Ring->Front.req_prod_pvt = req_prod;
 
@@ -2051,12 +2050,12 @@ ReceiverRingPoll(
         TailMdl = NULL;
         EOP = TRUE;
 
-        xen_mb();
+        KeMemoryBarrier();
 
         rsp_prod = Ring->Shared->rsp_prod;
         rsp_cons = Ring->Front.rsp_cons;
 
-        xen_rmb();
+        KeMemoryBarrier();
 
         if (rsp_cons == rsp_prod) {
             RING_IDX WorkToDo;
@@ -2245,8 +2244,7 @@ ReceiverRingPoll(
         ASSERT3P(TailMdl, ==, NULL);
         ASSERT(EOP);
 
-        xen_rmb();
-        xen_wmb();
+        KeMemoryBarrier();
 
         Ring->Front.rsp_cons = rsp_cons;
     }
diff --git a/src/xenvif/transmitter.c b/src/xenvif/transmitter.c
index cc6e52f..88dfb60 100644
--- a/src/xenvif/transmitter.c
+++ b/src/xenvif/transmitter.c
@@ -2482,12 +2482,12 @@ TransmitterRingPoll(
         RING_IDX    rsp_cons;
         ULONG       Extra;
 
-        xen_mb();
+        KeMemoryBarrier();
 
         rsp_prod = Ring->Shared->rsp_prod;
         rsp_cons = Ring->Front.rsp_cons;
 
-        xen_rmb();
+        KeMemoryBarrier();
 
         if (rsp_cons == rsp_prod) {
             RING_IDX WorkToDo;
@@ -2633,8 +2633,7 @@ TransmitterRingPoll(
         }
         ASSERT3U(Extra, ==, 0);
 
-        xen_rmb();
-        xen_wmb();
+        KeMemoryBarrier();
 
         Ring->Front.rsp_cons = rsp_cons;
     }
-- 
2.54.0.windows.1



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

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