]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Nt32Pkg/SnpNt32Dxe: Fix hang issue when multiple network interfaces existed
authorJiaxin Wu <jiaxin.wu@intel.com>
Fri, 5 May 2017 01:01:08 +0000 (09:01 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Tue, 9 May 2017 06:32:16 +0000 (14:32 +0800)
Currently all the network interfaces share the one recycled transmit buffer
array, which is used to store the recycled buffer address. However, those
recycled buffers are allocated by the different MNP interface if the multiple
network interfaces existed. Then, SNP GetStatus may return one recycled transmit
buffer address to the another MNP interface, which may result in the MNP driver
hang after 'reconnect -r' operation.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Nt32Pkg/SnpNt32Dxe/SnpNt32.c
Nt32Pkg/SnpNt32Dxe/SnpNt32.h

index 901880023b58123d5048bd32ae7403dde6414b67..c1ef32430a28f76a31087b1168cb412659256608 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -44,9 +44,6 @@ SNPNT32_GLOBAL_DATA         gSnpNt32GlobalData = {
     0,\r
     EfiLockUninitialized\r
   },                          //  Lock\r
-  NULL,                       //  RecycledTxBuf\r
-  0,                          //  RecycledTxBufCount\r
-  32,                         //  MaxRecycledTxBuf\r
   //\r
   //  Private functions\r
   //\r
@@ -396,6 +393,9 @@ SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {
     NULL,\r
     NULL\r
   },                                      //  Entry\r
+  NULL,                                   //  RecycledTxBuf\r
+  0,                                      //  RecycledTxBufCount\r
+  32,                                     //  MaxRecycledTxBuf\r
   NULL,                                   //  GlobalData\r
   NULL,                                   //  DeviceHandle\r
   NULL,                                   //  DevicePath\r
@@ -865,16 +865,13 @@ SnpNt32GetStatus (
   )\r
 {\r
   SNPNT32_INSTANCE_DATA *Instance;\r
-  SNPNT32_GLOBAL_DATA   *GlobalData;\r
 \r
   Instance    = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
 \r
-  GlobalData  = Instance->GlobalData;\r
-\r
   if (TxBuffer != NULL) {\r
-    if (GlobalData->RecycledTxBufCount != 0) {\r
-      GlobalData->RecycledTxBufCount --;\r
-      *((UINT8 **) TxBuffer)    = (UINT8 *) (UINTN)GlobalData->RecycledTxBuf[GlobalData->RecycledTxBufCount];\r
+    if (Instance->RecycledTxBufCount != 0) {\r
+      Instance->RecycledTxBufCount --;\r
+      *((UINT8 **) TxBuffer)    = (UINT8 *) (UINTN)Instance->RecycledTxBuf[Instance->RecycledTxBufCount];\r
     } else {\r
       *((UINT8 **) TxBuffer)    = NULL;\r
     }\r
@@ -961,22 +958,22 @@ SnpNt32Transmit (
   if (ReturnValue < 0) {\r
     return EFI_DEVICE_ERROR;\r
   } else {\r
-    if ((GlobalData->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {\r
+    if ((Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {\r
       return EFI_NOT_READY;\r
     }\r
 \r
-    if (GlobalData->RecycledTxBufCount < GlobalData->MaxRecycledTxBuf) {\r
-      GlobalData->RecycledTxBuf[GlobalData->RecycledTxBufCount] = (UINT64) Buffer;\r
-      GlobalData->RecycledTxBufCount ++;\r
+    if (Instance->RecycledTxBufCount < Instance->MaxRecycledTxBuf) {\r
+      Instance->RecycledTxBuf[Instance->RecycledTxBufCount] = (UINT64) Buffer;\r
+      Instance->RecycledTxBufCount ++;\r
     } else {\r
-      Tmp = AllocatePool (sizeof (UINT64) * (GlobalData->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));\r
+      Tmp = AllocatePool (sizeof (UINT64) * (Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));\r
       if (Tmp == NULL) {\r
         return EFI_DEVICE_ERROR;\r
       }\r
-      CopyMem (Tmp, GlobalData->RecycledTxBuf, sizeof (UINT64) * GlobalData->RecycledTxBufCount);\r
-      FreePool (GlobalData->RecycledTxBuf);\r
-      GlobalData->RecycledTxBuf    =  Tmp;\r
-      GlobalData->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;\r
+      CopyMem (Tmp, Instance->RecycledTxBuf, sizeof (UINT64) * Instance->RecycledTxBufCount);\r
+      FreePool (Instance->RecycledTxBuf);\r
+      Instance->RecycledTxBuf    =  Tmp;\r
+      Instance->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;\r
     }\r
   }\r
 \r
@@ -1116,11 +1113,6 @@ SnpNt32InitializeGlobalData (
   InitializeListHead (&This->InstanceList);\r
   EfiInitializeLock (&This->Lock, TPL_CALLBACK);\r
 \r
-  This->RecycledTxBuf = AllocatePool (sizeof (UINT64) * This->MaxRecycledTxBuf);\r
-  if (This->RecycledTxBuf == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
   //\r
   //  Get the WinNT thunk\r
   //\r
@@ -1213,7 +1205,7 @@ SnpNt32InitializeGlobalData (
   //\r
   for (Index = 0; Index < InterfaceCount; Index++) {\r
 \r
-    Instance = AllocatePool (sizeof (SNPNT32_INSTANCE_DATA));\r
+    Instance = AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA));\r
 \r
     if (NULL == Instance) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
@@ -1224,6 +1216,14 @@ SnpNt32InitializeGlobalData (
     //\r
     CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));\r
 \r
+    //\r
+    // Allocate the RecycledTxBuf.\r
+    //\r
+    Instance->RecycledTxBuf = AllocatePool (sizeof (UINT64) * Instance->MaxRecycledTxBuf);\r
+    if (Instance->RecycledTxBuf == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
     //\r
     //  Set the interface information.\r
     //\r
index cb95c5711c228d3f8c61642d33baf729025fd329..56251342e693bac879d68f9b77b60bb70f75e3ee 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -160,20 +160,6 @@ struct _SNPNT32_GLOBAL_DATA {
 \r
   EFI_LOCK                          Lock;\r
 \r
-  //\r
-  // Array of the recycled transmit buffer address.\r
-  //\r
-  UINT64                            *RecycledTxBuf;\r
-\r
-  //\r
-  // Current number of recycled buffer pointers in RecycledTxBuf.\r
-  //\r
-  UINT32                             RecycledTxBufCount;\r
-\r
-  // The maximum number of recycled buffer pointers in RecycledTxBuf.\r
-  //\r
-  UINT32                             MaxRecycledTxBuf;\r
-\r
   //\r
   //  Private functions\r
   //\r
@@ -195,6 +181,21 @@ struct _SNPNT32_INSTANCE_DATA {
   //\r
   LIST_ENTRY                  Entry;\r
 \r
+  //\r
+  // Array of the recycled transmit buffer address.\r
+  //\r
+  UINT64                      *RecycledTxBuf;\r
+\r
+  //\r
+  // Current number of recycled buffer pointers in RecycledTxBuf.\r
+  //\r
+  UINT32                      RecycledTxBufCount;\r
+\r
+  //\r
+  // The maximum number of recycled buffer pointers in RecycledTxBuf.\r
+  //\r
+  UINT32                      MaxRecycledTxBuf;\r
+\r
   SNPNT32_GLOBAL_DATA         *GlobalData;\r
 \r
   EFI_HANDLE                  DeviceHandle;\r