From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.4305.1614761354285363107 for ; Wed, 03 Mar 2021 00:49:14 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=R1L8r+bp; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: jiaxin.wu@intel.com) IronPort-SDR: y1prTsN5D+C5U9Y9kgCdwAkwATWwFFuxLKfXm1wR2M/MVEJ97IGwj0VA+U5fHS+rR2vzf7uX7e 61cvqOQFJ10A== X-IronPort-AV: E=McAfee;i="6000,8403,9911"; a="187259944" X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="187259944" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2021 00:49:13 -0800 IronPort-SDR: aeMtiy4oP8261DzYZNjbZuchyEnJCwF5XmpoOJKSDlQ89TgaGJxlZ1A/sn0kTwd+PIgA6BhTEw TlSRN3OotZ3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="407142540" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by orsmga008.jf.intel.com with ESMTP; 03 Mar 2021 00:49:12 -0800 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Wed, 3 Mar 2021 00:49:12 -0800 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Wed, 3 Mar 2021 00:49:11 -0800 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2 via Frontend Transport; Wed, 3 Mar 2021 00:49:11 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.49) 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.2106.2; Wed, 3 Mar 2021 00:48:42 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Is/R2+MXci6FeIpB5Sa6xWpG2CDavsOh+8n471a/+n7QgcKCXWZFEYx0yP0HcbRegVs6968vhZYhYrfqxTWswvA25MpSs7t9MyztnwPL9oeYyDFumKJzsWee920mOZ/1fnr/hjUBpvKcztTVLP8pmpbnRFKypl78dTIN0Jz2EEzCf/VIFRD3ZP6wPpTzto+/jNw6y6JmPfPahv6wtDeBzlKlC8kD20ikHCfj65IA0kHJHjHxlkC2rRsPw+b2sAWlY3UIQmH6OQhwtDIA6WUgDbkwzrlugFw2mYHf9qTY+5F5m3izFvsfG8jQUDXrgcJUmnAJ08nZ1ociplhnEsqkUg== 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-SenderADCheck; bh=WybaQmC4sZnLk4ye2BDWj079POP2kHHj2ui4IeXg4Po=; b=XNtDGzPzG/mswyIWyN2RMFJJJU4lhc/qW3x0t51+DXr0hVZqMLAlwXm/xrf7G2ouRoXRi4NuqiakJB3n0/Qwjsdm60Ye+Q9C7BahRB7WqANFdCd7bvZeW8EBCNZvg8Jac4hptycl7+E3sm3iQ6dawxXkrYw3T5drRDq15tzqbzzMCR+QdZj/IZHzCgM0OGmT0AezXu74EJuZZLSNKeqogy6MRgvpYGinTzQOERT+oM/j87xj6CdINNxjTgMxuf/6JWnmuBMvzNvlffD1MoIl7fyMXILHAxlXiQmpPuOFp3NfUy/tXGvkP+JdEV3XSnCeoXyfYoRFz1LGw36jRME5Qw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WybaQmC4sZnLk4ye2BDWj079POP2kHHj2ui4IeXg4Po=; b=R1L8r+bpntmEcVFX7GyKeHDtqHK/79IBpmrvkDqPCahW3cbYPQJgJIl/xml2wYp5R8OS+o6lCwXR7uCVb5ArPF/7iggxZ1wLqaO9hhM208ckXobZRDVqRKh3JYgMzA/2LAKJ2g2SMy/VNzR5QwLJUpkXBxEHfxxZ0mxv2+6/8T8= Received: from DM5PR11MB1372.namprd11.prod.outlook.com (2603:10b6:3:11::14) by DM5PR11MB1641.namprd11.prod.outlook.com (2603:10b6:4:a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Wed, 3 Mar 2021 08:48:41 +0000 Received: from DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::7810:33d:859a:f05a]) by DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::7810:33d:859a:f05a%4]) with mapi id 15.20.3912.017; Wed, 3 Mar 2021 08:48:41 +0000 From: "Wu, Jiaxin" To: "devel@edk2.groups.io" , "Wu, Jiaxin" CC: "Kinney, Michael D" , Liming Gao , "Liu, Zhiguang" , "Fu, Siyuan" Subject: Re: [edk2-devel] [PATCH v1] MdePkg: Support standalone MM Driver Unload capability Thread-Topic: [edk2-devel] [PATCH v1] MdePkg: Support standalone MM Driver Unload capability Thread-Index: AQHXDm7A6k7zaANG9Ue3Kd/Iq2GB+apx9uag Date: Wed, 3 Mar 2021 08:48:40 +0000 Message-ID: References: <166828338BB555BC.18336@groups.io> In-Reply-To: <166828338BB555BC.18336@groups.io> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.220] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 700098fb-2099-468f-f88b-08d8de212530 x-ms-traffictypediagnostic: DM5PR11MB1641: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 16mL0ECy+ZRHPryndVYqaSGC1PEi9tKvqrDiq9/u3K0OoNUsp4WsJ2VPpIOpvEa3OvKIVmeOaSmshnZjPQFxmM0Km6Jea1UqUSh1cjfPVnJmdqorR3WoJVvq1Uqbezs5oNz/x0FDf70xzzdQ887iFqz5wylSf7q2UQ7LBRj6r0X0sDY9MZBPhaGpaZ2WLi3bQYvekbeJwuHroXMKsmtry1zr8oYQ/xpThIEyMUJ1Ly+XEwW+fClOQeYbXW/bZ7HLgjghs7dv6pfMU4TOLdkjOjin9M+DRuZsoK7Ulft0ph90ROHACPnxj1YjEsMvcT94YtsWIIi6htgydJa0hwwXQZjOtevi64T+Byfu5G5yo+bvy5esDOQtH0K4ooSnSqiJhpp4r2174TFmcnoz+V7B2qKNJSgqIwVIDi3db+howrVqbd0g8qYCTF1Qqc9ILB3kLNiCtKdEGuQS25UcFeFoz95D7YJ1qyPMzadShNQkbLDVm7b6Mj2wPey8zcfx9Jyn6WO8XZKpa7POExLWYC2HIr/+mHa6NCFYkM8+6pZCoYwOhMTTNWiAYmKHo3RcY6srVs3yCa7xE5sOXgmp+Ke47ewlNB7S+vAUjUmVZIb30L8= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR11MB1372.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(39850400004)(346002)(366004)(376002)(136003)(83380400001)(53546011)(4326008)(186003)(26005)(86362001)(966005)(8936002)(66446008)(52536014)(107886003)(54906003)(110136005)(76116006)(33656002)(478600001)(7696005)(66946007)(64756008)(66476007)(8676002)(66556008)(9686003)(55016002)(5660300002)(316002)(6506007)(2906002)(71200400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?4H2GTTUDsio934CEtj9abBsRXHcJ01vNA6rwmdrTErL0oWGEhrqY8OAga26M?= =?us-ascii?Q?cMfy3qMRLq2u7jmO10pmouuukL6MYQcg1jdzr6a86xgsIf08fUBfm38rCa6I?= =?us-ascii?Q?NvwdlIhTYZ1RM8xOHQPIICnA5asLhdQHmAlgCyHq8lL92wD0FBlPucEn4rMZ?= =?us-ascii?Q?GLVs6HGfZY9r4TnU2r1bwnQOeNwlEZ81BIIlHnRfCwwr8pEJtBsSWCxFZaf3?= =?us-ascii?Q?3XU+DQYhrITTVuW4Bptb4T0Xlgh1hh5v1kWq2RQ/i3Tm0X6NB8TQucRUMNgC?= =?us-ascii?Q?WmBUlNIiRPJY1jroK7NE0t/ka1NA3X3flWba0kllVqk1okp9GjrqZUZDu+0Z?= =?us-ascii?Q?CWXwXC6oYHph8Q0J6gEL8j+GFiHgYnuRvpleYi0I9GS+B2gUcrjex/xfJAFX?= =?us-ascii?Q?R1Bd/hn3XiW1QEJdOgkaJmiPlln1JMGRzxdMWrdYYwN5KiVo2sQqgvcLxFTO?= =?us-ascii?Q?R+L95Wu1wydROMMdUTyYwVqZpuRBPrDdTKmA391IMbvJ45WykrTwrIF+4G1x?= =?us-ascii?Q?1IIfMZfCYVexFHwstt/8tzpmuHrqeTCLhozFhj4OfQoIoaPEz0mVIFIvr4Qb?= =?us-ascii?Q?vWyIYJnbl7Q7Ik61ym8YP6oN7rxZu2ji0BDdxzGF6OUEj/N01ZGqq09xD8oe?= =?us-ascii?Q?vTSr/FYj+WH2j89+k4MGLDVVZR+3yistYntHfMdBodW/T0m9SKlUVbpEETbe?= =?us-ascii?Q?lWFRLXe1Ql0JCEY79EZtnBfL8d8CH63XRZ9Tk2RaI0RIGrt/OFHPdccFaCki?= =?us-ascii?Q?5pknwPtCcadCEjdo0F9iYM9uSk6dhjm4VLoFzF0gM99608oAHj83rmAmBW6j?= =?us-ascii?Q?P1ih8meySbRzPexJwlF0YGP7e7/8kNlpB5S5tYREVSsac0KzywQLvyy6rh+c?= =?us-ascii?Q?pzIF2X9W+9tW/+cEaENEVAzEWH69UmYa9Kl7/oUcBch8lHIFiCCnIcT4WL7V?= =?us-ascii?Q?8v9kmX0QDYWXnM64O0MLwdKKs7//ztwew2Mi0LEGEccTwyK59p3dk2i1kNla?= =?us-ascii?Q?J4kHBmm+EF5zGP2CF25RMBBXW6hcr9NW36hIdQ7Bpv+830Iusl2pXX+4lZr+?= =?us-ascii?Q?nZCEKwU7ysI7wbVR3/X2D2XLPjDqnJTe9W83BeFIqHL1zJYJsFQYP0q62823?= =?us-ascii?Q?/bTCnzz6TSgVp8uVJdzJZEtrFpo1Rrrav5fc7gitzWX/UsaDfjuJer8EmJqc?= =?us-ascii?Q?wqqM57P317E7rtuFqMeuQIElB8CA30iMJjQrIVdCwHckQl7Z6LowhucKWBBZ?= =?us-ascii?Q?va3f+yql5vgsTZMA2Wo4NTsfYEJUYiCuV70Ckl+T+fZFr7LYzUoFQ89dE/yl?= =?us-ascii?Q?iHBpNpMfqVLxVCl5AbnDkCEL?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1372.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 700098fb-2099-468f-f88b-08d8de212530 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2021 08:48:41.0579 (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: 0Hya9RRPbsGTeUMCdXhLQGFoiG6DpYqUJodOAxUaqbRE5jsFl/QJxhz7r9rg4E2ouQnr6mAXJXzph4n8KUClQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1641 Return-Path: jiaxin.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Mike & Zhiguang & Liming, Could you help review this patch? Thanks, Jiaxin=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Wu, > Jiaxin > Sent: Monday, March 1, 2021 3:44 PM > To: devel@edk2.groups.io > Cc: Kinney, Michael D ; Liming Gao > ; Liu, Zhiguang ; Fu, > Siyuan > Subject: [edk2-devel] [PATCH v1] MdePkg: Support standalone MM Driver > Unload capability >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D3240 >=20 > This patch is to support standalone MM Driver Unload capability > by providing _DriverUnloadHandler() function. >=20 > Change-Id: I26cdbfccb7052685c464d6394e472c7579b7b67e > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Siyuan Fu > Signed-off-by: Jiaxin Wu > --- > .../Include/Library/StandaloneMmDriverEntryPoint.h | 25 ++++++++++ > .../StandaloneMmDriverEntryPoint.c | 56 > +++++++++++++++++++++- > .../StandaloneMmDriverEntryPoint.inf | 5 +- > 3 files changed, 84 insertions(+), 2 deletions(-) >=20 > diff --git a/MdePkg/Include/Library/StandaloneMmDriverEntryPoint.h > b/MdePkg/Include/Library/StandaloneMmDriverEntryPoint.h > index 25b2d8d68d..12f7886640 100644 > --- a/MdePkg/Include/Library/StandaloneMmDriverEntryPoint.h > +++ b/MdePkg/Include/Library/StandaloneMmDriverEntryPoint.h > @@ -16,10 +16,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > /// Declare the PI Specification Revision that this driver requires to = execute > /// correctly. > /// > extern CONST UINT32 _gMmRevision; >=20 > +/// > +/// Declare the number of unload handler in the image. > +/// > +extern CONST UINT8 _gDriverUnloadImageCount; > + > /** > The entry point of PE/COFF Image for a Standalone MM Driver. >=20 > This function is the entry point for a Standalone MM Driver. > This function must call ProcessLibraryConstructorList() and > @@ -120,6 +125,26 @@ EFIAPI > ProcessModuleEntryPointList ( > IN EFI_HANDLE ImageHandle, > IN EFI_MM_SYSTEM_TABLE *MmSystemTable > ); >=20 > +/** > + Autogenerated function that calls a set of module unload handlers. > + > + This function must be called from the unload handler registered by > _ModuleEntryPoint(). > + This function calls the set of module unload handlers. > + This function is autogenerated by build tools and those build tools a= re > responsible > + for collecting the module unload handlers and calling them in a speci= fied > order. > + > + @param ImageHandle The image handle of the DXE Driver, DXE Runtime > Driver, DXE SMM Driver, or UEFI Driver. > + > + @retval EFI_SUCCESS The unload handlers executed normally. > + @retval !EFI_SUCCESS The unload handlers failed to execute normally. > + > +**/ > +EFI_STATUS > +EFIAPI > +ProcessModuleUnloadList ( > + IN EFI_HANDLE ImageHandle > + ); > + > #endif > diff --git > a/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.c > b/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.c > index 2c41e23a03..d74c9bdfed 100644 > --- > a/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.c > +++ > b/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.c > @@ -1,23 +1,63 @@ > /** @file > Entry point to a Standalone MM driver. >=20 > -Copyright (c) 2015, Intel Corporation. All rights reserved.
> +Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
> Copyright (c) 2016 - 2018, ARM Ltd. All rights reserved.
> Copyright (c) 2018, Linaro, Limited. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ >=20 > #include >=20 > +#include > #include > #include > #include > #include >=20 > +/** > + Unloads an image from memory. > + > + This function is a callback that a driver registers to do cleanup > + when the UnloadImage boot service function is called. > + > + @param ImageHandle The handle to the image to unload. > + > + @return Status returned by all unload(). > + > +**/ > +EFI_STATUS > +EFIAPI > +_DriverUnloadHandler ( > + EFI_HANDLE ImageHandle > + ) > +{ > + EFI_STATUS Status; > + > + // > + // If an UnloadImage() handler is specified, then call it > + // > + Status =3D ProcessModuleUnloadList (ImageHandle); > + > + // > + // If the driver specific unload handler does not return an error, th= en call all > of the > + // library destructors. If the unload handler returned an error, the= n the > driver can not be > + // unloaded, and the library destructors should not be called > + // > + if (!EFI_ERROR (Status)) { > + ProcessLibraryDestructorList (ImageHandle, gMmst); > + } > + > + // > + // Return the status from the driver specific unload handler > + // > + return Status; > +} > + > /** > The entry point of PE/COFF Image for a Standalone MM Driver. >=20 > This function is the entry point for a Standalone MM Driver. > This function must call ProcessLibraryConstructorList() and > @@ -44,10 +84,11 @@ _ModuleEntryPoint ( > IN EFI_HANDLE ImageHandle, > IN IN EFI_MM_SYSTEM_TABLE *MmSystemTable > ) > { > EFI_STATUS Status; > + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; >=20 > if (_gMmRevision !=3D 0) { > // > // Make sure that the MM spec revision of the platform > // is >=3D MM spec revision of the driver > @@ -60,10 +101,23 @@ _ModuleEntryPoint ( > // > // Call constructor for all libraries > // > ProcessLibraryConstructorList (ImageHandle, MmSystemTable); >=20 > + // > + // Install unload handler... > + // > + if (_gDriverUnloadImageCount !=3D 0) { > + Status =3D gMmst->MmHandleProtocol ( > + ImageHandle, > + &gEfiLoadedImageProtocolGuid, > + (VOID **)&LoadedImage > + ); > + ASSERT_EFI_ERROR (Status); > + LoadedImage->Unload =3D _DriverUnloadHandler; > + } > + > // > // Call the driver entry point > // > Status =3D ProcessModuleEntryPointList (ImageHandle, MmSystemTable); >=20 > diff --git > a/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.inf > b/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.inf > index 2f33a6d4ad..9303566309 100644 > --- > a/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.inf > +++ > b/MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEnt > ryPoint.inf > @@ -1,9 +1,9 @@ > ## @file > # Module entry point library for Standalone MM driver. > # > -# Copyright (c) 2015, Intel Corporation. All rights reserved.
> +# Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved. > # Copyright (c) 2016-2018, ARM Ltd. All rights reserved.
> # Copyright (c) 2018, Linaro, Limited. All rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > @@ -34,5 +34,8 @@ >=20 > [LibraryClasses] > BaseLib > DebugLib > MmServicesTableLib > + > +[Protocols] > + gEfiLoadedImageProtocolGuid ## SOMETIMES_CONSUMES > -- > 2.16.2.windows.1 >=20 >=20 >=20 >=20 >=20