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

[win-pv-devel] [PATCH] Always select queue using the packet hash algorithm



There may be a mismatch between the configured receive hash algorithm
and the actual algorithm present in a transmit-side packet.
E.g. Toeplitz may be configured but a transmitted packet may have no
hash information.

It makes no sense to use a hash mapping table configured for a Toeplitz
hash if the packet hash is not Toeplitz, therefore the code should pass
the actual packet hash algorithm into the FrontendGetQueue(). This patch
makes the that change.

Suggested-by: Owen Smith <owen.smith@xxxxxxxxxxx>

This patch also makes sure we cannot attempt to indirect through a zero-
sized mapping table (thereby incurring a divide-by-zero exception).

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/frontend.c    | 13 ++++++++-----
 src/xenvif/frontend.h    |  5 +++--
 src/xenvif/transmitter.c |  7 +++++--
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c
index b443a35..27796a1 100644
--- a/src/xenvif/frontend.c
+++ b/src/xenvif/frontend.c
@@ -2138,20 +2138,23 @@ fail1:
 
 ULONG
 FrontendGetQueue(
-    IN  PXENVIF_FRONTEND    Frontend,
-    IN  ULONG               Value
+    IN  PXENVIF_FRONTEND                Frontend,
+    IN  XENVIF_PACKET_HASH_ALGORITHM    Algorithm,
+    IN  ULONG                           Value
     )
 {
-    ULONG                   Queue;
+    ULONG                               Queue;
 
-    switch (Frontend->Hash.Algorithm) {
+    switch (Algorithm) {
     case XENVIF_PACKET_HASH_ALGORITHM_NONE:
     case XENVIF_PACKET_HASH_ALGORITHM_UNSPECIFIED:
         Queue = Value % __FrontendGetNumQueues(Frontend);
         break;
 
     case XENVIF_PACKET_HASH_ALGORITHM_TOEPLITZ:
-        Queue = Frontend->Hash.Mapping[Value % Frontend->Hash.Size];
+        Queue = (Frontend->Hash.Size != 0) ?
+                Frontend->Hash.Mapping[Value % Frontend->Hash.Size] :
+                0;
         break;
 
     default:
diff --git a/src/xenvif/frontend.h b/src/xenvif/frontend.h
index 06ae78a..035f75a 100644
--- a/src/xenvif/frontend.h
+++ b/src/xenvif/frontend.h
@@ -238,8 +238,9 @@ FrontendSetHashTypes(
 
 extern ULONG
 FrontendGetQueue(
-    IN  PXENVIF_FRONTEND    Frontend,
-    IN  ULONG               Index
+    IN  PXENVIF_FRONTEND                Frontend,
+    IN  XENVIF_PACKET_HASH_ALGORITHM    Algorithm,
+    IN  ULONG                           Index
     );
 
 #endif  // _XENVIF_FRONTEND_H
diff --git a/src/xenvif/transmitter.c b/src/xenvif/transmitter.c
index 61f2cc9..ddc8efa 100644
--- a/src/xenvif/transmitter.c
+++ b/src/xenvif/transmitter.c
@@ -5125,6 +5125,7 @@ TransmitterQueuePacket(
     PUCHAR                          StartVa;
     PXENVIF_PACKET_PAYLOAD          Payload;
     PXENVIF_PACKET_INFO             Info;
+    XENVIF_PACKET_HASH_ALGORITHM    Algorithm;
     ULONG                           Value;
     ULONG                           Index;
     PXENVIF_TRANSMITTER_RING        Ring;
@@ -5158,7 +5159,9 @@ TransmitterQueuePacket(
 
     (VOID) ParsePacket(StartVa, TransmitterPullup, Transmitter, Payload, Info);
 
-    switch (Hash->Algorithm) {
+    Algorithm = Hash->Algorithm;
+
+    switch (Algorithm) {
     case XENVIF_PACKET_HASH_ALGORITHM_NONE:
         Value = __TransmitterHashPacket(Packet);
         More = FALSE;
@@ -5179,7 +5182,7 @@ TransmitterQueuePacket(
         break;
     }
 
-    Index = FrontendGetQueue(Frontend, Value);
+    Index = FrontendGetQueue(Frontend, Algorithm, Value);
     Ring = Transmitter->Ring[Index];
 
     __TransmitterRingQueuePacket(Ring, Packet, More);
-- 
2.5.3


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

 


Rackspace

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