From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id D7BA8AC0269 for ; Thu, 9 Nov 2023 02:36:07 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=z4bW2HnJpNFeQyPlpCIoriz7/XQwK6OugRMywhXZ+8Q=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20140610; t=1699497366; v=1; b=B+paJZP1fxV2CYQZiJr8x9U6Ofmg3l6gtXi2nz6VUCoYXsHwguA1R6/12bVs+d7/uiC0djEH 0dB5R6PAuRMGObF5B7CZ4/VXdery7dP5cYw8fo7JjtZotA2PYMZg10xmVuc6Vo1b7qz2S0tYeVq nebR/KeRQ1vHUwvv8V/NCN00= X-Received: by 127.0.0.2 with SMTP id aQ70YY7687511xawH7R8VeUL; Wed, 08 Nov 2023 18:36:06 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web11.113271.1699497365326002740 for ; Wed, 08 Nov 2023 18:36:05 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="393813554" X-IronPort-AV: E=Sophos;i="6.03,288,1694761200"; d="scan'208,217";a="393813554" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 18:36:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="1094714739" X-IronPort-AV: E=Sophos;i="6.03,288,1694761200"; d="scan'208,217";a="1094714739" X-Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga005.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Nov 2023 18:36:04 -0800 X-Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 8 Nov 2023 18:36:04 -0800 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Wed, 8 Nov 2023 18:36:03 -0800 X-Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Wed, 8 Nov 2023 18:36:03 -0800 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.169) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Wed, 8 Nov 2023 18:36:03 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e8dDaAM+wGKrA/5aP8T+ql5NgPfAnLusK36w7fazH/Uz08h1Su+4tg036Z2eHDQGIwXUV9rsw8hHWqzoOudgIUNGVzR4XL5A13RDsVfs29awgz6DipssbwESW9c51gGZYQUK16awq4bVniyhsCQyvhwebbAyKWBc7ESTozPddaWo9L3R/0hdUlJZXMWFDH4hapBeBa50P6Zr4Dlzh1sKkl/2GXqvlpYjChDzCNl1orxSSGYN0mrWVnLzs7Hss1Zjed3eMO2rjvN98h87XH1dShVXqwX2tihjri87FBwe6Srh6xxbIQFVXxDLkY2qHR3TQrAipPxmVIzYI9wWqZdOwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Y/ZeyZ9WZyv4W2nXm2GgDe/uSmSEmXvvK/g/5cp26uM=; b=XdkeeEVi/KutQw7354oPJrAYB0aC76gHKpZr/finUWOV0l3eguJEZOUW/8ZWDQMfxrLelzN+BtoF8G+/koJiYIwpmfvSnBFWYzOdsC1rP9B54z8fGLmtbqXoteCjiRnwBpHEdDOaUhudmjNB0gMHQSFAGe0zFn/8L5t4xuVXCUdxd3iQme3f7MJOsm81JLA2iXB849xsBCoeiAnvTNZecTgfTFidypzE9yECLCotOQHE5yVZS2mqoTgfbW13ijSskF4PxG+d52xD+WEX10BY3D5hB1xP1NAiyzc8skWY3+aMJ7eREiXWye/HfkJ8UIq6vs1YMwFfsPCrVreNPGilbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by DM4PR11MB5246.namprd11.prod.outlook.com (2603:10b6:5:389::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.18; Thu, 9 Nov 2023 02:36:01 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::b614:1f5e:8b0c:9858]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::b614:1f5e:8b0c:9858%4]) with mapi id 15.20.6954.030; Thu, 9 Nov 2023 02:36:01 +0000 From: "Ni, Ray" To: "Jin, Zhi" , "devel@edk2.groups.io" CC: "Wang, Jian J" , "Gao, Liming" , "Bi, Dandan" Subject: Re: [edk2-devel] [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Thread-Topic: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInterfaces Thread-Index: AQHaEq59BoDTezHUJ0q4bZzA57c7UbBxRXVH Date: Thu, 9 Nov 2023 02:36:00 +0000 Message-ID: References: <20231109014607.573019-1-zhi.jin@intel.com> In-Reply-To: <20231109014607.573019-1-zhi.jin@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|DM4PR11MB5246:EE_ x-ms-office365-filtering-correlation-id: 04bf8b99-e57a-4ff1-6f6b-08dbe0cc9cb7 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: pRaA3S6cBpXFY+mwrjAQcGKlFIOCrOzxL3EZiXv7CkW6klEN5mljvuGK67p4jXsqSFPwGIjrKbFRyZxVURir+dhB3ats1DCOjoLMAyVHS/CyJEXmARqISIOQxFOGp+oHr58IEMHZS/7uEEi9RQ+dP243Gqf+rtAK4vE66KJu08R+AeBDwlOjuXgIV20Wb7BmnzvjQkpCoXV33vYBTQocSKaeSGgrVH5qjExXf2qjWo7ClZ1i6n2ca1myNabx8h4lkodebfP163YuVEBW39QwICqgtSUp75+dFUYn56/b1GAEugoXnIqzXE9i6ZUzcPOeh493BatRZjujaUhtmO+5/TuzwUf9p/kCvF7oozEl0F0aCwrwS079rBEGNNB2Cd2V7HWgU2LrIVOxXE8nEeRUEL28A5S0wqcmzOVMApscHhNKYXHTt0kKKyp8r8HCJoF8Sn4McrVwR/bkzi8jin2iiebZXj+7ESxhWfxP1BMVsK/BSulA6+2s/ziPIoKmL5K1unsWukyUs+rXVjKMPE74heNE++GiTgNRoqWa0dyrQKN2mryvam/9lEnWGyWSmON04TLb84+qF1ejoBwwQynQhBjSS+THP7yOzYuYyFaUw5/beIKAgGr5oTvE++hgEip/SDctDcSvxpa3Q7ujG4mbVA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?qfQFt83UTr1iIxrMz2x7fw7E0rtbh1dwrHWSimaekMjq9GnTpR0ludepKikh?= =?us-ascii?Q?uH3viI4VNfw6cr/ZPgG49Vj0xWY0bdpdfhCgYekaxr75RXiIAt+oRHgUFf0/?= =?us-ascii?Q?VpQ6VA3qDPPKlxV2aOZ757hMtjXDLUrvtFzz5IxvdxhXQ+ZdLNO+FtbsWw3Z?= =?us-ascii?Q?RK+kpiMRMJxuWHgWnEswbx9ROfOSlsyFAU1OZTRPyZw/KsfZrc1LJAQ7eTrZ?= =?us-ascii?Q?+5ww5Mjp8eSQSMCxEEJRl2Sgv9VnFRL39mtMW8sK3X19pPG+T/nzc+W2DaBV?= =?us-ascii?Q?Bpi/fNPPMQId3nn4lBhOhMjI7xMxd8GukM6yoETg4gzZNWda1laU5i86NGiN?= =?us-ascii?Q?hRm5GQvJIzM2nIsZmwRM+IgrCpPQVN90UzpJVpWYrX4hXoecgf3P6QyZ/M9I?= =?us-ascii?Q?PUC6Zb0kVqE2GLYGiSkpzlxKDjrmJk+4Z8lFEw1nTZ7GdFd0WVzsww5K3KeC?= =?us-ascii?Q?5xPP1hihKK7vr4syZMb0QMzYgjblq1UcdgoTSj475gmStcAgrSPVBa5Qz7kn?= =?us-ascii?Q?TOYxjGmMn/SqD39a6YTJysggFOtg3kBfw90KwAx0bIOrQtH58fRx1obILrk7?= =?us-ascii?Q?FbZ2gC9l+0k7N94pHeMA0p/Iu8i35W+mET0Oqf69Xht7DUbT4HZ4tWqaxOpM?= =?us-ascii?Q?eaGDKlKJvca2gc80qds0F83Up0YMsXkQX/V/CbrLrvL6XuSl5bH7YU3+p3zb?= =?us-ascii?Q?wiDuI0rVRPH0706OBUEccocVOmOsA1aE5uzWPqYXyVf7LbvYZXzFpFrIBKRE?= =?us-ascii?Q?40DLCscv6PaUd3L1CB7ZN/Qw9YjGxUgB69z9TaxMU1s7oEyE/Qo+fF1l55e1?= =?us-ascii?Q?Ph1Skp0vQikB7gwVMAerp5wZL3UlC1NIn6BJ4eLAT0dHsdMbc9Y4o+abXxms?= =?us-ascii?Q?Xrv0nfl2VlGpRuVPZS/c2+oSB6cNyrBkduqjBKVo5Ly6doTPKUxLV2ivIsUo?= =?us-ascii?Q?VG1i6LKO5C0RxFodeFmcOBSy5F8DHLHoqDCnDTx5mjvcqIRa9dy+dqY42S6T?= =?us-ascii?Q?XdfrHAmzCC4TuQYajHZlCISP5NU4HXsrg9OnjgyGsP0LP7Vupr8gqSA9+W9U?= =?us-ascii?Q?+nv7BhdUkcITF9O60PkVVcmiyPVRkL7IupPJ2Zy02oo6WI4+2Lf3uNyFHiN5?= =?us-ascii?Q?0IZ/eD9ENZAwS4ABqDZQ8yAWKNqS7j9Dw2w63WcwFwdDYiaTCClCn041GXn9?= =?us-ascii?Q?MeAEZV8/oXC5LJrK6fa/K/z1bghVegmbfUNLh6bbp7vlmnVS9Muqz1hSLWqx?= =?us-ascii?Q?Q/Kf3wM9nM+3S9FfSe+BH9Mj6ZCfIhS/Y7ZpkxiUxCSdp5+3tv4819KsIQUQ?= =?us-ascii?Q?KPUurSbUnJ2sMiKs7t9FQsRWOF7YC1CAh096qW50sPXajWywE7a1ZLwTZhUg?= =?us-ascii?Q?VOLCUsx3aHU35u+QIUHgYekJ7Z0iCHcSLUc6IlxqKszLSdKp+otnhBF3Mv8L?= =?us-ascii?Q?E6YhQRentnPzSNCDNwcfB5eZbQfyHDompDk9rsM4lP1C1XT2u+uCTXy+zyRY?= =?us-ascii?Q?QoOTSVGqf+t7YFUXDRnSt5V97CL9YzmbUmfy5UnfF4kDNzs/Cr4gGbZfl/Y3?= =?us-ascii?Q?kxw0WSD3uefJoNLaSEU=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04bf8b99-e57a-4ff1-6f6b-08dbe0cc9cb7 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Nov 2023 02:36:01.0138 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: h5pjs0CuhQug6cTWZgRyIMa19Bk+YkUsbxlCn7r2XM/Lniyan5VtALjZiwWDatVB0FEXKM7qYtyMhfq5g2M5Uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5246 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: NthHCHmXcOGyDjN06g8ycHrTx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB82448EADF0AF3FBF034522F98CAFAMN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=B+paJZP1; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --_000_MN6PR11MB82448EADF0AF3FBF034522F98CAFAMN6PR11MB8244namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni Thanks, Ray ________________________________ From: Jin, Zhi Sent: Thursday, November 9, 2023 9:46 AM To: devel@edk2.groups.io Cc: Jin, Zhi ; Wang, Jian J ; Gao= , Liming ; Bi, Dandan ; Ni, = Ray Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProtocolInte= rfaces CoreLocateDevicePath is used in CoreInstallMultipleProtocolInterfaces to check if a Device Path Protocol instance with the same device path is alreay installed. CoreLocateDevicePath is a generic API, and would introduce some unnecessary overhead for such usage. The optimization is: 1. Implement IsDevicePathInstalled to loop all the Device Path Protocols installed and check if any of them matchs the given device path. 2. Replace CoreLocateDevicePath with IsDevicePathInstalled in CoreInstallMultipleProtocolInterfaces. This optimization could save several seconds in PCI enumeration on a system with many PCI devices. Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi Cc: Ray Ni Signed-off-by: Zhi Jin --- MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Ha= nd/Handle.c index bd6c57843e..a08cf19bfd 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -197,6 +197,66 @@ CoreFindProtocolInterface ( return Prot; } +/** + Check if the given device path is already installed + + @param DevicePath The given device path + + @retval TRUE The device path is already installed + @retval FALSE The device path is not installed + +**/ +BOOLEAN +IsDevicePathInstalled ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + UINTN SourceSize; + UINTN Size; + BOOLEAN Found; + LIST_ENTRY *Link; + PROTOCOL_ENTRY *ProtEntry; + PROTOCOL_INTERFACE *Prot; + + if (DevicePath =3D=3D NULL) { + return FALSE; + } + + Found =3D FALSE; + SourceSize =3D GetDevicePathSize (DevicePath); + ASSERT (SourceSize >=3D END_DEVICE_PATH_LENGTH); + + CoreAcquireProtocolLock (); + // + // Look up the protocol entry + // + ProtEntry =3D CoreFindProtocolEntry (&gEfiDevicePathProtocolGuid, FALSE)= ; + if (ProtEntry =3D=3D NULL) { + goto Done; + } + + for (Link =3D ProtEntry->Protocols.ForwardLink; Link !=3D &ProtEntry->Pr= otocols; Link =3D Link->ForwardLink) { + // + // Loop on the DevicePathProtocol interfaces + // + Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_= SIGNATURE); + + // + // Check if DevicePath is same as this interface + // + Size =3D GetDevicePathSize (Prot->Interface); + ASSERT (Size >=3D END_DEVICE_PATH_LENGTH); + if ((Size =3D=3D SourceSize) && (CompareMem (DevicePath, Prot->Interfa= ce, Size - END_DEVICE_PATH_LENGTH) =3D=3D 0)) { + Found =3D TRUE; + break; + } + } + +Done: + CoreReleaseProtocolLock (); + return Found; +} + /** Removes an event from a register protocol notify list on a protocol. @@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces ( EFI_TPL OldTpl; UINTN Index; EFI_HANDLE OldHandle; - EFI_HANDLE DeviceHandle; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; if (Handle =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces ( // // Make sure you are installing on top a device path that has already = been added. // - if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid)) { - DeviceHandle =3D NULL; - DevicePath =3D Interface; - Status =3D CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, = &DevicePath, &DeviceHandle); - if (!EFI_ERROR (Status) && (DeviceHandle !=3D NULL) && IsDevicePathE= nd (DevicePath)) { - Status =3D EFI_ALREADY_STARTED; - continue; - } + if (CompareGuid (Protocol, &gEfiDevicePathProtocolGuid) && + IsDevicePathInstalled (Interface)) { + Status =3D EFI_ALREADY_STARTED; + continue; } // -- 2.39.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110937): https://edk2.groups.io/g/devel/message/110937 Mute This Topic: https://groups.io/mt/102478834/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB82448EADF0AF3FBF034522F98CAFAMN6PR11MB8244namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Ray Ni <ray.ni@intel.com>

Thanks,
Ray

From: Jin, Zhi <zhi.jin@= intel.com>
Sent: Thursday, November 9, 2023 9:46 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Jin, Zhi <zhi.jin@intel.com>; Wang, Jian J <jian.j.wang= @intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; Bi, Dandan &l= t;dandan.bi@intel.com>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH 1/1] MdeModulePkg: Optimize CoreInstallMultipleProto= colInterfaces
 
CoreLocateDevicePath is used in CoreInstallMultipl= eProtocolInterfaces to
check if a Device Path Protocol instance with the same device path is
alreay installed.
CoreLocateDevicePath is a generic API, and would introduce some
unnecessary overhead for such usage.

The optimization is:
1. Implement IsDevicePathInstalled to loop all the Device Path
   Protocols installed and check if any of them matchs the given = device
   path.
2. Replace CoreLocateDevicePath with IsDevicePathInstalled in
   CoreInstallMultipleProtocolInterfaces.

This optimization could save several seconds in PCI enumeration on a
system with many PCI devices.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhi Jin <zhi.jin@intel.com>
---
 MdeModulePkg/Core/Dxe/Hand/Handle.c | 74 +++++++++++++++++++++++++---= -
 1 file changed, 64 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Ha= nd/Handle.c
index bd6c57843e..a08cf19bfd 100644
--- a/MdeModulePkg/Core/Dxe/Hand/Handle.c
+++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c
@@ -197,6 +197,66 @@ CoreFindProtocolInterface (
   return Prot;
 }
 
+/**
+  Check if the given device path is already installed
+
+  @param  DevicePath       &n= bsp;    The given device path
+
+  @retval TRUE         &= nbsp;        The device path is already = installed
+  @retval FALSE         =         The device path is not installed=
+
+**/
+BOOLEAN
+IsDevicePathInstalled (
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath
+  )
+{
+  UINTN          &n= bsp;          SourceSize;
+  UINTN          &n= bsp;          Size;
+  BOOLEAN          =          Found;
+  LIST_ENTRY         &nb= sp;      *Link;
+  PROTOCOL_ENTRY         = ;   *ProtEntry;
+  PROTOCOL_INTERFACE        *Prot;=
+
+  if (DevicePath =3D=3D NULL) {
+    return FALSE;
+  }
+
+  Found         =3D FALSE; +  SourceSize    =3D GetDevicePathSize (DevicePath); +  ASSERT (SourceSize >=3D END_DEVICE_PATH_LENGTH);
+
+  CoreAcquireProtocolLock ();
+  //
+  // Look up the protocol entry
+  //
+  ProtEntry =3D CoreFindProtocolEntry (&gEfiDevicePathProtocolGui= d, FALSE);
+  if (ProtEntry =3D=3D NULL) {
+    goto Done;
+  }
+
+  for (Link =3D ProtEntry->Protocols.ForwardLink; Link !=3D &P= rotEntry->Protocols; Link =3D Link->ForwardLink) {
+    //
+    // Loop on the DevicePathProtocol interfaces
+    //
+    Prot =3D CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROT= OCOL_INTERFACE_SIGNATURE);
+
+    //
+    // Check if DevicePath is same as this interface
+    //
+    Size =3D GetDevicePathSize (Prot->Interface);
+    ASSERT (Size >=3D END_DEVICE_PATH_LENGTH);
+    if ((Size =3D=3D SourceSize) && (CompareMem (De= vicePath, Prot->Interface, Size - END_DEVICE_PATH_LENGTH) =3D=3D 0)) { +      Found =3D TRUE;
+      break;
+    }
+  }
+
+Done:
+  CoreReleaseProtocolLock ();
+  return Found;
+}
+
 /**
   Removes an event from a register protocol notify list on a pro= tocol.
 
@@ -517,8 +577,6 @@ CoreInstallMultipleProtocolInterfaces (
   EFI_TPL         &= nbsp;         OldTpl;
   UINTN         &nb= sp;           Index;
   EFI_HANDLE        &nbs= p;       OldHandle;
-  EFI_HANDLE         &nb= sp;      DeviceHandle;
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
 
   if (Handle =3D=3D NULL) {
     return EFI_INVALID_PARAMETER;
@@ -548,14 +606,10 @@ CoreInstallMultipleProtocolInterfaces (
     //
     // Make sure you are installing on top a device pa= th that has already been added.
     //
-    if (CompareGuid (Protocol, &gEfiDevicePathProtocolG= uid)) {
-      DeviceHandle =3D NULL;
-      DevicePath   =3D Interface;
-      Status       = =3D CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath,= &DeviceHandle);
-      if (!EFI_ERROR (Status) && (DeviceH= andle !=3D NULL) && IsDevicePathEnd (DevicePath)) {
-        Status =3D EFI_ALREADY_STARTED;=
-        continue;
-      }
+    if (CompareGuid (Protocol, &gEfiDevicePathProtocolG= uid) &&
+        IsDevicePathInstalled (Interfac= e)) {
+      Status =3D EFI_ALREADY_STARTED;
+      continue;
     }
 
     //
--
2.39.2

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#110937) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB82448EADF0AF3FBF034522F98CAFAMN6PR11MB8244namp_--