From nobody Sat Nov 2 08:32:46 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1493955039321988.9819843593782; Thu, 4 May 2017 20:30:39 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 48D5821A134BB; Thu, 4 May 2017 20:30:37 -0700 (PDT) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CAB5921A134AE for ; Thu, 4 May 2017 20:30:35 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 May 2017 20:30:35 -0700 Received: from jiaxinwu-mobl2.ccr.corp.intel.com ([10.239.196.209]) by orsmga005.jf.intel.com with ESMTP; 04 May 2017 20:30:34 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,290,1491289200"; d="scan'208";a="95862703" From: Jiaxin Wu To: edk2-devel@lists.01.org Date: Fri, 5 May 2017 11:30:31 +0800 Message-Id: <1493955031-20716-1-git-send-email-jiaxin.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [Patch] Nt32Pkg/SnpNt32Dxe: Fix hang issue when multiple network interfaces existed X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ye Ting , Ruiyu Ni , Fu Siyuan , Wu Jiaxin MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 multip= le network interfaces existed. Then, SNP GetStatus may return one recycled tra= nsmit buffer address to the another MNP interface, which may result in the MNP dr= iver hang after 'reconnect -r' operation. Cc: Ye Ting Cc: Fu Siyuan Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan --- Nt32Pkg/SnpNt32Dxe/SnpNt32.c | 50 ++++++++++++++++++++++------------------= ---- Nt32Pkg/SnpNt32Dxe/SnpNt32.h | 31 ++++++++++++++------------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Nt32Pkg/SnpNt32Dxe/SnpNt32.c b/Nt32Pkg/SnpNt32Dxe/SnpNt32.c index 9018800..c1ef324 100644 --- a/Nt32Pkg/SnpNt32Dxe/SnpNt32.c +++ b/Nt32Pkg/SnpNt32Dxe/SnpNt32.c @@ -1,8 +1,8 @@ /** @file =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at http://opensource.org/licenses/bsd-license.php =20 @@ -42,13 +42,10 @@ SNPNT32_GLOBAL_DATA gSnpNt32GlobalData =3D { { 0, 0, EfiLockUninitialized }, // Lock - NULL, // RecycledTxBuf - 0, // RecycledTxBufCount - 32, // MaxRecycledTxBuf // // Private functions // SnpNt32InitializeGlobalData, // InitializeGlobalData SnpNt32InitializeInstanceData, // InitializeInstanceData @@ -394,10 +391,13 @@ SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate =3D { SNP_NT32_INSTANCE_SIGNATURE, // Signature { NULL, NULL }, // Entry + NULL, // RecycledTxBuf + 0, // RecycledTxBufCount + 32, // MaxRecycledTxBuf NULL, // GlobalData NULL, // DeviceHandle NULL, // DevicePath { // Snp EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision @@ -863,20 +863,17 @@ SnpNt32GetStatus ( OUT UINT32 *InterruptStatus, OUT VOID **TxBuffer ) { SNPNT32_INSTANCE_DATA *Instance; - SNPNT32_GLOBAL_DATA *GlobalData; =20 Instance =3D SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This); =20 - GlobalData =3D Instance->GlobalData; - if (TxBuffer !=3D NULL) { - if (GlobalData->RecycledTxBufCount !=3D 0) { - GlobalData->RecycledTxBufCount --; - *((UINT8 **) TxBuffer) =3D (UINT8 *) (UINTN)GlobalData->RecycledT= xBuf[GlobalData->RecycledTxBufCount]; + if (Instance->RecycledTxBufCount !=3D 0) { + Instance->RecycledTxBufCount --; + *((UINT8 **) TxBuffer) =3D (UINT8 *) (UINTN)Instance->RecycledTxB= uf[Instance->RecycledTxBufCount]; } else { *((UINT8 **) TxBuffer) =3D NULL; } } =20 @@ -959,26 +956,26 @@ SnpNt32Transmit ( EfiReleaseLock (&GlobalData->Lock); =20 if (ReturnValue < 0) { return EFI_DEVICE_ERROR; } else { - if ((GlobalData->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >=3D S= NP_MAX_TX_BUFFER_NUM) { + if ((Instance->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >=3D SNP= _MAX_TX_BUFFER_NUM) { return EFI_NOT_READY; } =20 - if (GlobalData->RecycledTxBufCount < GlobalData->MaxRecycledTxBuf) { - GlobalData->RecycledTxBuf[GlobalData->RecycledTxBufCount] =3D (UINT6= 4) Buffer; - GlobalData->RecycledTxBufCount ++; + if (Instance->RecycledTxBufCount < Instance->MaxRecycledTxBuf) { + Instance->RecycledTxBuf[Instance->RecycledTxBufCount] =3D (UINT64) B= uffer; + Instance->RecycledTxBufCount ++; } else { - Tmp =3D AllocatePool (sizeof (UINT64) * (GlobalData->MaxRecycledTxBu= f + SNP_TX_BUFFER_INCREASEMENT)); + Tmp =3D AllocatePool (sizeof (UINT64) * (Instance->MaxRecycledTxBuf = + SNP_TX_BUFFER_INCREASEMENT)); if (Tmp =3D=3D NULL) { return EFI_DEVICE_ERROR; } - CopyMem (Tmp, GlobalData->RecycledTxBuf, sizeof (UINT64) * GlobalDat= a->RecycledTxBufCount); - FreePool (GlobalData->RecycledTxBuf); - GlobalData->RecycledTxBuf =3D Tmp; - GlobalData->MaxRecycledTxBuf +=3D SNP_TX_BUFFER_INCREASEMENT; + CopyMem (Tmp, Instance->RecycledTxBuf, sizeof (UINT64) * Instance->R= ecycledTxBufCount); + FreePool (Instance->RecycledTxBuf); + Instance->RecycledTxBuf =3D Tmp; + Instance->MaxRecycledTxBuf +=3D SNP_TX_BUFFER_INCREASEMENT; } } =20 return EFI_SUCCESS; } @@ -1114,15 +1111,10 @@ SnpNt32InitializeGlobalData ( InterfaceCount =3D MAX_INTERFACE_INFO_NUMBER; =20 InitializeListHead (&This->InstanceList); EfiInitializeLock (&This->Lock, TPL_CALLBACK); =20 - This->RecycledTxBuf =3D AllocatePool (sizeof (UINT64) * This->MaxRecycle= dTxBuf); - if (This->RecycledTxBuf =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - // // Get the WinNT thunk // Status =3D gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, (VOID= **)&This->WinNtThunk); =20 @@ -1211,11 +1203,11 @@ SnpNt32InitializeGlobalData ( // // Create fake SNP instances // for (Index =3D 0; Index < InterfaceCount; Index++) { =20 - Instance =3D AllocatePool (sizeof (SNPNT32_INSTANCE_DATA)); + Instance =3D AllocateZeroPool (sizeof (SNPNT32_INSTANCE_DATA)); =20 if (NULL =3D=3D Instance) { Status =3D EFI_OUT_OF_RESOURCES; goto ErrorReturn; } @@ -1223,10 +1215,18 @@ SnpNt32InitializeGlobalData ( // Copy the content from a template // CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE= _DATA)); =20 // + // Allocate the RecycledTxBuf. + // + Instance->RecycledTxBuf =3D AllocatePool (sizeof (UINT64) * Instance->= MaxRecycledTxBuf); + if (Instance->RecycledTxBuf =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // // Set the interface information. // CopyMem (&Instance->InterfaceInfo, &NetInterfaceInfoBuffer[Index], siz= eof(Instance->InterfaceInfo)); // // Initialize this instance diff --git a/Nt32Pkg/SnpNt32Dxe/SnpNt32.h b/Nt32Pkg/SnpNt32Dxe/SnpNt32.h index cb95c57..5625134 100644 --- a/Nt32Pkg/SnpNt32Dxe/SnpNt32.h +++ b/Nt32Pkg/SnpNt32Dxe/SnpNt32.h @@ -1,8 +1,8 @@ /** @file =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at http://opensource.org/licenses/bsd-license.php =20 @@ -159,24 +159,10 @@ struct _SNPNT32_GLOBAL_DATA { NT_NET_UTILITY_TABLE NtNetUtilityTable; =20 EFI_LOCK Lock; =20 // - // Array of the recycled transmit buffer address. - // - UINT64 *RecycledTxBuf; - - // - // Current number of recycled buffer pointers in RecycledTxBuf. - // - UINT32 RecycledTxBufCount; - - // The maximum number of recycled buffer pointers in RecycledTxBuf. - // - UINT32 MaxRecycledTxBuf; - - // // Private functions // SNPNT32_INITIALIZE_GLOBAL_DATA InitializeGlobalData; SNPNT32_INITIALIZE_INSTANCE_DATA InitializeInstanceData; SNPNT32_CLOSE_INSTANCE CloseInstance; @@ -193,10 +179,25 @@ struct _SNPNT32_INSTANCE_DATA { // // List entry use for linking with other instance // LIST_ENTRY Entry; =20 + // + // Array of the recycled transmit buffer address. + // + UINT64 *RecycledTxBuf; + + // + // Current number of recycled buffer pointers in RecycledTxBuf. + // + UINT32 RecycledTxBufCount; + + // + // The maximum number of recycled buffer pointers in RecycledTxBuf. + // + UINT32 MaxRecycledTxBuf; + SNPNT32_GLOBAL_DATA *GlobalData; =20 EFI_HANDLE DeviceHandle; EFI_DEVICE_PATH_PROTOCOL *DevicePath; =20 --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel