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

[PATCH] Fix div by zero in xenvif if no queues.


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Martin Harvey <Martin.Harvey@xxxxxxxxxx>
  • Date: Tue, 15 Mar 2022 14:01:00 +0000
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Martin Harvey <Martin.Harvey@xxxxxxxxxx>, Martin Harvey <martin.harvey@xxxxxxxxxx>
  • Delivery-date: Tue, 15 Mar 2022 14:01:41 +0000
  • Ironport-data: A9a23:pDX4f67Qdkk5eFNuxltKJAxRtF7HchMFZxGqfqrLsTDasY5as4F+v mdMD2DVafzcZjegKtAjaoW+9RtU7JfWztVjQAtl+y9nHi5G8cbLO4+Ufxz6V8+wwmwvb67FA +E2MISowBUcFyeEzvuVGuG96yE6j8lkf5KkYAL+EnkZqTRMFWFw0XqPp8Zj2tQy2YPgXlvW0 T/Pi5a31GGNimYc3l08s8pvmDs31BglkGpF1rCWTakjUG72zxH5PrpGTU2CByKQrr1vNvy7X 47+IISRpQs1yfuP5uSNyd4XemVSKlLb0JPnZnB+A8BOiTAazsA+PzpS2FPxpi67hh3Q9+2dx umhurS5ax11A4zGyd87cDxfDCReZ/184e/YdC3XXcy7lyUqclPpyvRqSko3IZcZ6qB8BmQmG f4wcW5XKErZ3qTvnez9GrIEascLdaEHOKsas2t8zDefDf88X53Sa67L+cVZzHE7gcUm8fP2O ZdGNGExNk2ojxtnYQ0aFbcs2+iS12jlSDtxpGjLhpIu7D2GpOB2+Oe0a4eEEjCQfu1Kn0Ddv nyD82nnDxUyMN2E1SHD4n+qnvXIny7wRMQVDrLQyxJxqATNnCpJUkRQDAbl56ni4qKjZz5BA 0U24HYTjKJjz2qIa97iWj3i8ESd7gFJDrK8DNYGwA2Kz6PV5SOQCW4FUiNNZbQaiSMmedA5/ gTXxo20XFSDpJXQECvArenM8VteLABPdQc/iTk4oRzpCjUJiKU6lVrxQ9lqC8ZZZfWlSGirk 1hmQMXT7oj/bPLnNY3mpTgrYBr2//AlqzLZAC2MBgpJCSsjOOaYi3SAswSz0Bq5BN/xoqO9l HYFgdOCy+sFEIuAkieAKM1UQu32vaffaWeM2AQ1d3XEy9hL0yX6FWy3yGsiTHqFz+5eIWO5C KMtkV45CGBv0IuCMvYsPtPZ5zUCxqn8D9X1Ps04nfIVCqWdgDSvpXk0DWbJhjiFuBF1zckXZ MfKGe7xXC1yIfk2k1KLqxI1jOZDKtYWnjiIG/gWDn2PjNKjWZJiYexcYQXUMbxhsv/sTce82 483CvZmAi53CIXWChQ7O6ZIRbzWBRDX3azLlvE=
  • Ironport-hdrordr: A9a23:199a36uu3WiaPXMctYqehMZG7skDetV00zEX/kB9WHVpmszxra 6TdZMgpHvJYVcqKRcdcL+7WJVoLUmxyXcX2/h1AV7BZniEhILAFugLhuGO/9SJIVyYygc378 ZdmsZFZ+EYdWIK7/rH3A==
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

In some cases (live migration), the front/backend can be pending
reconnect at the same point as Tx tries to send packets.
Previously, this caused a div by zero. However, since this is
a transient error, the drivers should ditch the packet,
and carry on.

Signed-off-by: Martin Harvey <martin.harvey@xxxxxxxxxx>
---
 src/xenvif/frontend.c    | 19 ++++++++++++-------
 src/xenvif/frontend.h    |  5 +++--
 src/xenvif/transmitter.c |  8 +++++++-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c
index e38d2bf..fc4b78c 100644
--- a/src/xenvif/frontend.c
+++ b/src/xenvif/frontend.c
@@ -2174,34 +2174,39 @@ fail1:
     return status;
 }
 
-ULONG
+NTSTATUS
 FrontendGetQueue(
     IN  PXENVIF_FRONTEND                Frontend,
     IN  XENVIF_PACKET_HASH_ALGORITHM    Algorithm,
-    IN  ULONG                           Value
+    IN  ULONG                           Value,
+    OUT PULONG                          QueueIndex
     )
 {
-    ULONG                               Queue;
+    if (QueueIndex == NULL)
+        return STATUS_INVALID_PARAMETER;
 
     switch (Algorithm) {
     case XENVIF_PACKET_HASH_ALGORITHM_NONE:
     case XENVIF_PACKET_HASH_ALGORITHM_UNSPECIFIED:
-        Queue = Value % __FrontendGetNumQueues(Frontend);
+        *QueueIndex = (__FrontendGetNumQueues(Frontend) != 0) ?
+            Value % __FrontendGetNumQueues(Frontend) :
+            0;
         break;
 
     case XENVIF_PACKET_HASH_ALGORITHM_TOEPLITZ:
-        Queue = (Frontend->Hash.Size != 0) ?
+        *QueueIndex = (Frontend->Hash.Size != 0) ?
                 Frontend->Hash.Mapping[Value % Frontend->Hash.Size] :
                 0;
         break;
 
     default:
         ASSERT(FALSE);
-        Queue = 0;
+        *QueueIndex = 0;
         break;
     }
 
-    return Queue;
+    return ((*QueueIndex) < __FrontendGetNumQueues(Frontend)) ?
+        STATUS_SUCCESS : STATUS_INTERNAL_ERROR;
 }
 
 static NTSTATUS
diff --git a/src/xenvif/frontend.h b/src/xenvif/frontend.h
index 8e5552e..5004b0e 100644
--- a/src/xenvif/frontend.h
+++ b/src/xenvif/frontend.h
@@ -237,11 +237,12 @@ FrontendSetHashTypes(
     IN  ULONG               Types
     );
 
-extern ULONG
+extern NTSTATUS
 FrontendGetQueue(
     IN  PXENVIF_FRONTEND                Frontend,
     IN  XENVIF_PACKET_HASH_ALGORITHM    Algorithm,
-    IN  ULONG                           Index
+    IN  ULONG                           Value,
+    OUT PULONG                          QueueIndex
     );
 
 #endif  // _XENVIF_FRONTEND_H
diff --git a/src/xenvif/transmitter.c b/src/xenvif/transmitter.c
index ed89f60..d089301 100644
--- a/src/xenvif/transmitter.c
+++ b/src/xenvif/transmitter.c
@@ -5194,13 +5194,19 @@ TransmitterQueuePacket(
         break;
     }
 
-    Index = FrontendGetQueue(Frontend, Algorithm, Value);
+    status = FrontendGetQueue(Frontend, Algorithm, Value, &Index);
+    if (!NT_SUCCESS(status))
+        goto fail2;
+
     Ring = Transmitter->Ring[Index];
 
     __TransmitterRingQueuePacket(Ring, Packet, More);
 
     return STATUS_SUCCESS;
 
+fail2:
+    Error("fail2\n");
+
 fail1:
     Error("fail1 (%08x)\n", status);
 
-- 
2.25.0.windows.1




 


Rackspace

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