]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Mtftp4Dxe: Separate the timer ticking to calculate the packet live time.
authorFu Siyuan <siyuan.fu@intel.com>
Fri, 2 Mar 2018 03:33:28 +0000 (11:33 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Sat, 3 Mar 2018 01:35:51 +0000 (09:35 +0800)
TPL deadlock issue was enrolled by the commit of 39b0867d. To resolve the issue,
this patch separated the timer ticking for all the MTFTP clients to calculate the
packet live time in TPL_NOTIFY level.

Cc: Wang Fan <fan.wang@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Driver.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h

index a23d405baa2fbb48e43c4ad0e031d853a9d5c5bf..713cc66dd17325a1a7b208280bcd6cab9a2e9cb9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of Mtftp drivers.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -162,11 +162,12 @@ Mtftp4CreateService (
   MtftpSb->ChildrenNum    = 0;\r
   InitializeListHead (&MtftpSb->Children);\r
 \r
-  MtftpSb->Timer          = NULL;\r
-  MtftpSb->TimerToGetMap  = NULL;\r
-  MtftpSb->Controller     = Controller;\r
-  MtftpSb->Image          = Image;\r
-  MtftpSb->ConnectUdp     = NULL;\r
+  MtftpSb->Timer            = NULL;\r
+  MtftpSb->TimerNotifyLevel = NULL;\r
+  MtftpSb->TimerToGetMap    = NULL;\r
+  MtftpSb->Controller       = Controller;\r
+  MtftpSb->Image            = Image;\r
+  MtftpSb->ConnectUdp       = NULL;\r
 \r
   //\r
   // Create the timer and a udp to be notified when UDP is uninstalled\r
@@ -178,8 +179,20 @@ Mtftp4CreateService (
                   MtftpSb,\r
                   &MtftpSb->Timer\r
                   );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (MtftpSb);\r
+    return Status;\r
+  }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL | EVT_TIMER,\r
+                  TPL_NOTIFY,\r
+                  Mtftp4OnTimerTickNotifyLevel,\r
+                  MtftpSb,\r
+                  &MtftpSb->TimerNotifyLevel\r
+                  );\r
   if (EFI_ERROR (Status)) {\r
+    gBS->CloseEvent (MtftpSb->Timer);\r
     FreePool (MtftpSb);\r
     return Status;\r
   }\r
@@ -196,6 +209,7 @@ Mtftp4CreateService (
                   &MtftpSb->TimerToGetMap\r
                   );\r
   if (EFI_ERROR (Status)) {\r
+    gBS->CloseEvent (MtftpSb->TimerNotifyLevel);\r
     gBS->CloseEvent (MtftpSb->Timer);\r
     FreePool (MtftpSb);\r
     return Status;\r
@@ -211,6 +225,7 @@ Mtftp4CreateService (
 \r
   if (MtftpSb->ConnectUdp == NULL) {\r
     gBS->CloseEvent (MtftpSb->TimerToGetMap);\r
+    gBS->CloseEvent (MtftpSb->TimerNotifyLevel);\r
     gBS->CloseEvent (MtftpSb->Timer);\r
     FreePool (MtftpSb);\r
     return EFI_DEVICE_ERROR;\r
@@ -234,6 +249,7 @@ Mtftp4CleanService (
 {\r
   UdpIoFreeIo (MtftpSb->ConnectUdp);\r
   gBS->CloseEvent (MtftpSb->TimerToGetMap);\r
+  gBS->CloseEvent (MtftpSb->TimerNotifyLevel);\r
   gBS->CloseEvent (MtftpSb->Timer);\r
 }\r
 \r
@@ -294,6 +310,12 @@ Mtftp4DriverBindingStart (
     goto ON_ERROR;\r
   }\r
 \r
+  Status = gBS->SetTimer (MtftpSb->TimerNotifyLevel, TimerPeriodic, TICKS_PER_SECOND);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ON_ERROR;\r
+  }\r
+  \r
   //\r
   // Install the Mtftp4ServiceBinding Protocol onto Controller\r
   //\r
index f5f9e6d8f7a40a89e955c431af3eb2e072d0bfdd..d8c48ec8b2b563ef00b7927d8b15d432628f68cf 100644 (file)
@@ -1082,6 +1082,7 @@ EfiMtftp4Poll (
 {\r
   MTFTP4_PROTOCOL           *Instance;\r
   EFI_UDP4_PROTOCOL         *Udp;\r
+  EFI_STATUS                Status;\r
 \r
   if (This == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1096,7 +1097,9 @@ EfiMtftp4Poll (
   }\r
 \r
   Udp = Instance->UnicastPort->Protocol.Udp4;\r
-  return Udp->Poll (Udp);\r
+  Status = Udp->Poll (Udp);\r
+  Mtftp4OnTimerTick (NULL, Instance->Service);\r
+  return Status;\r
 }\r
 \r
 EFI_MTFTP4_PROTOCOL gMtftp4ProtocolTemplate = {\r
index 527fd1db10d1723b4c6d75023f3c4f90911595d7..851b595eee037ad451ff5ee2e33820f7699cd141 100644 (file)
@@ -9,7 +9,7 @@
   RFC2348 - TFTP Blocksize Option\r
   RFC2349 - TFTP Timeout Interval and Transfer Size Options\r
   \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -72,7 +72,8 @@ struct _MTFTP4_SERVICE {
   UINT16                        ChildrenNum;\r
   LIST_ENTRY                    Children;\r
 \r
-  EFI_EVENT                     Timer;  ///< Ticking timer for all the MTFTP clients\r
+  EFI_EVENT                     Timer;  ///< Ticking timer for all the MTFTP clients to handle the packet timeout case.\r
+  EFI_EVENT                     TimerNotifyLevel; ///< Ticking timer for all the MTFTP clients to calculate the packet live time.\r
   EFI_EVENT                     TimerToGetMap;\r
 \r
   EFI_HANDLE                    Controller;\r
@@ -135,6 +136,7 @@ struct _MTFTP4_PROTOCOL {
   //\r
   NET_BUF                       *LastPacket;\r
   UINT32                        PacketToLive;\r
+  BOOLEAN                       HasTimeout;\r
   UINT32                        CurRetry;\r
   UINT32                        MaxRetry;\r
   UINT32                        Timeout;\r
index c625fda020e81034aca5fdf4baf07616bc3eb03e..e4366b6ddb83bda1dfd2ecdefd65fb7a859595b4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for Mtftp.\r
   \r
-Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -568,6 +568,42 @@ Mtftp4Retransmit (
 }\r
 \r
 \r
+/**\r
+  The timer ticking function in TPL_NOTIFY level for the Mtftp service instance.\r
+\r
+  @param  Event                 The ticking event\r
+  @param  Context               The Mtftp service instance\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Mtftp4OnTimerTickNotifyLevel (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  )\r
+{\r
+  MTFTP4_SERVICE            *MtftpSb;\r
+  LIST_ENTRY                *Entry;\r
+  LIST_ENTRY                *Next;\r
+  MTFTP4_PROTOCOL           *Instance;\r
+\r
+  MtftpSb = (MTFTP4_SERVICE *) Context;\r
+\r
+  //\r
+  // Iterate through all the children of the Mtftp service instance. Time\r
+  // out the current packet transmit.\r
+  //\r
+  NET_LIST_FOR_EACH_SAFE (Entry, Next, &MtftpSb->Children) {\r
+    Instance = NET_LIST_USER_STRUCT (Entry, MTFTP4_PROTOCOL, Link);\r
+    if ((Instance->PacketToLive == 0) || (--Instance->PacketToLive > 0)) {\r
+      Instance->HasTimeout = FALSE;\r
+    } else {\r
+      Instance->HasTimeout = TRUE;\r
+    }\r
+  }\r
+}\r
+\r
+\r
 /**\r
   The timer ticking function for the Mtftp service instance.\r
 \r
@@ -591,29 +627,28 @@ Mtftp4OnTimerTick (
   MtftpSb = (MTFTP4_SERVICE *) Context;\r
 \r
   //\r
-  // Iterate through all the children of the Mtftp service instance. Time\r
-  // out the packet. If maximum retries reached, clean the session up.\r
+  // Iterate through all the children of the Mtftp service instance.\r
   //\r
   NET_LIST_FOR_EACH_SAFE (Entry, Next, &MtftpSb->Children) {\r
     Instance = NET_LIST_USER_STRUCT (Entry, MTFTP4_PROTOCOL, Link);\r
-\r
-    if ((Instance->PacketToLive == 0) || (--Instance->PacketToLive > 0)) {\r
+    if (!Instance->HasTimeout) {\r
       continue;\r
     }\r
+    \r
+    Instance->HasTimeout = FALSE;\r
 \r
     //\r
     // Call the user's time out handler\r
     //\r
     Token = Instance->Token;\r
 \r
-    if ((Token->TimeoutCallback != NULL) &&\r
+    if (Token != NULL && Token->TimeoutCallback != NULL &&\r
         EFI_ERROR (Token->TimeoutCallback (&Instance->Mtftp4, Token))) {\r
-\r
       Mtftp4SendError (\r
-         Instance,\r
-         EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,\r
-         (UINT8 *) "User aborted the transfer in time out"\r
-         );\r
+        Instance,\r
+        EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,\r
+        (UINT8 *) "User aborted the transfer in time out"\r
+        );\r
 \r
       Mtftp4CleanOperation (Instance, EFI_ABORTED);\r
       continue;\r
index 802e3867db810472b32fd8c60da60bc1bd6042ea..fd8703a925cf12d459c99a877ff958bf223a60d1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support routines for MTFTP.\r
   \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -187,6 +187,20 @@ Mtftp4Retransmit (
   IN MTFTP4_PROTOCOL        *Instance\r
   );\r
 \r
+/**\r
+  The timer ticking function in TPL_NOTIFY level for the Mtftp service instance.\r
+\r
+  @param  Event                 The ticking event\r
+  @param  Context               The Mtftp service instance\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+Mtftp4OnTimerTickNotifyLevel (\r
+  IN EFI_EVENT              Event,\r
+  IN VOID                   *Context\r
+  );\r
+\r
 /**\r
   The timer ticking function for the Mtftp service instance.\r
 \r