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 5D573740032 for ; Fri, 19 Jan 2024 04:58:51 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=/jpbv0Kw5WeHXbKSaXqAOfjqe5i0jQfPKHgfWdoJQ+g=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1705640329; v=1; b=ZqUEXq3xNBUXjzFZbMp/GyV99BrajIicKatKInD9VvddjahMOKyz910RdpjOHsHiS/L2WzVp JaNdc3Hnxwp74lcP8U+NViH3VvgIJzHOWi7SYyK9olItlkB9GibrjdZ5GqtaBeMF0f5H0hJBxAC IPUrIk8Oex6wRK56ZrTwqIEg= X-Received: by 127.0.0.2 with SMTP id 9v35YY7687511xAFP6NAE9nW; Thu, 18 Jan 2024 20:58:49 -0800 X-Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.104]) by mx.groups.io with SMTP id smtpd.web10.15046.1705640328925688022 for ; Thu, 18 Jan 2024 20:58:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VhSug45xYl3Ok45BTz93DJVc66Z6LsnWpQMYkUAtp1Bqa4Q4pqCgLyg504FR7jDpCYUAzWAle9r65thjjXjsfch5axLvaobinmKEGwb10fckk3C/CrzklzqQ3U3W2z16XUEWybQoaZ/JsYilM7CGmUNobfetTwybobArW3EHqm8eCOI65bgrjWZaNHiVW+hJjheCLjMoDzA91AlCRuAtFoTTkylGqxZ6mYyztB5CO5LEbkfRcPkwsLyv4o+B6XwNwWcuKxgDRtrX2NweCYUU/U0yoF8qXoQeWky5j7mSOZ9+B84fEQPmaBiS5LTmmVRw1ReiNDrImdQ68IPn7pFN8g== 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=qxDqRAK3kOYgv2RNfJsWv5D5NMUmVSoJbtWk3dVO9YA=; b=dLd+f4PaGzXOPfUh7rcKN8eCc1jrWl2/DBLCq8gNKTyMpWyny7qvN0ez6OBxKiIGplmSYPNkUIbsZvD6eAm3ornkloF18bu0RjbYmZ4+sNs/66RTVJ0dU9xVlFJcRJrdfzijNa32A0e1hYqFt+JfscjExYc7CJbUJ471G10rg/TanSg4+pbAxl5TWZC9szI0Fqy75iJhI7KLTSeqJyyps7nrjfxCz1QXNyZdJY58EybLvUb8XJV2IYBVkABaGH/mtgYsne0yyvkxw8DM+xV/wc6OGnLNPGuqnXWKE0fIBevpEuu9soZJLHEcFxJc36H0bxwVTpVrWKYEgrBrRBt0yA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none X-Received: from PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) by CO1PR01MB7339.prod.exchangelabs.com (2603:10b6:303:156::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24; Fri, 19 Jan 2024 04:58:45 +0000 X-Received: from PH0PR01MB7287.prod.exchangelabs.com ([fe80::d2bd:7ad:570c:9dc8]) by PH0PR01MB7287.prod.exchangelabs.com ([fe80::d2bd:7ad:570c:9dc8%6]) with mapi id 15.20.7202.024; Fri, 19 Jan 2024 04:58:45 +0000 From: "Nhi Pham via groups.io" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, ray.ni@intel.com, sami.mujawar@arm.com, lersek@redhat.com, Nhi Pham Subject: [edk2-devel] [PATCH 1/1] StandaloneMmPkg/Core: Remove optimization for depex evaluation Date: Fri, 19 Jan 2024 11:56:46 +0700 Message-Id: <20240119045646.3896430-1-nhi@os.amperecomputing.com> X-ClientProxiedBy: SI2PR06CA0017.apcprd06.prod.outlook.com (2603:1096:4:186::15) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7287:EE_|CO1PR01MB7339:EE_ X-MS-Office365-Filtering-Correlation-Id: 79638ea9-61fa-4cb8-8080-08dc18ab50e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: UJUb1vDCgdkSCZze9v36Xe2jdMO1tPKihxkwIe53kr5EEUUIJTua1oOpS9cr7+zv7k8AaKIivZzNcLZbhBFTfnrP+tiw1/36d6D/4c3/O+mjKBk0k2kbXXE8xtebt5adJa6wrftIoS4YSSUfZtE+Zoj0phTTqNfRbPufnliNuWhGplSZ8i43NaosUb1teRRAgkyl9rgSFyFQ/lf6fhZEDSPM4945LK8gT3HVKzMjeBxbvaYV8ba5xcyh7+gXeNIsm/AlBUt/fTBZAmmTMBQPwN1gF6K60u/BvkA5aGmYzpPPEkSQH2IFyx1XMKa0EoGjmXX6jEtiL2RWsioyS/uOB+n5KiSrLhBEvq6xfaJ+XngxJYu/aGcXgdkSPakJkvZFso6czfMH5KSMtq6iR9d8cT1NXBtVGINO2Hv4GgnhfdXSXHf7GKXWzCM32Yhra1e10K/RYaGTMgUWMsQFjrZufR20M0thP8jQ6CHtShex036IDUfyQpcfnI5Q+B7z+K/WzfiORMHN36pfrbAKpLA0VkWnGgOQcjVoKgGKuRmmMqbw3M7CcuraoHurDrEkITa25dXZYrtI6H2f4/UjMDnv8AOFaai1UrimHBl8GH5FML8= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?vPz+cKuS17CscbTfm//R+Ect5H7qvdJjjvZA30pQcyRrdXGCEYhJ6Goq4bSC?= =?us-ascii?Q?7u10SZPHpBEUbdLOlF/afBs4DhT38d9IsnTOofslLQS6cqOA1ogDcXBfT7+6?= =?us-ascii?Q?VykzmveTZC5B62LADFjXy8RMUPIGGWjUoqbC00K4vUDiy42EbKzqv4sGk3lO?= =?us-ascii?Q?x6QAOOQEQahFFGeX/8hxaNTzqd/GpcwTX4e2+3zRv9GHnOrU5K4HbF8T3t7g?= =?us-ascii?Q?B0POJWTCj2SF9Qn8C/H+GwReDwTl8ktBqMXbBW7xY0z5PQDd5lArpkrWBizm?= =?us-ascii?Q?SgCZfiBJHbzk7y/lhjOGD4MIuwHNjGtYSh77nXQRHqGGKT2k05XAGPA7GtoK?= =?us-ascii?Q?Y9y9oxNGxL/gTnQzjXaHogRr2hwRFoFfwpTUNyDDXJPaoezlP11NSOPdSmUQ?= =?us-ascii?Q?YRGoM4ToSJpOHhlrMeBlTdFxm/9vSEtyii1cvWwxuXJDGTuQebohPg0VXjp3?= =?us-ascii?Q?utvi9CzGkWymLoG7rvf2+xYKT7fSIHO3Dj4Ut/CPtKPFPZ5R7O0nXnEKJydP?= =?us-ascii?Q?NXp2/IpzojO/HQYlzkFuRAop7fOL64EOvHcZd9lUvQ3ZA8YWrSUNmaV84umn?= =?us-ascii?Q?N7qTR9pF1iEIga598upBu12jK11V856ic5/mppsnkV1HmzsqolXJFowgfSoz?= =?us-ascii?Q?Pa+uYkp6huXiOOlm3jB6g4b1VZfEG40yPMn5avnrPVfcKTiW12MzGdFXC1KJ?= =?us-ascii?Q?JRMj96MT5GsLGm9EO1GiDEt1FI2v4ONbrAxVt9HORVgQXhCljcl2w9fMYDlH?= =?us-ascii?Q?BLUKiV+pazjrK7xY8y6veGfA9fsR4HSKn3B+TEzjhHnlEYHM3c8sxAsbU0Nj?= =?us-ascii?Q?kyU7jXxv6hVU1NwZu50tBKHuU0QT4gpzcDWs00H0T9rYK18nURhU2VyYwtiA?= =?us-ascii?Q?rB8lxDXHst+lGLAFcYxwVVmWvJV5Php3bK5f6yGQdqQKB5Xx1I7ZxSBfIQoV?= =?us-ascii?Q?rpEJJPzegAx/K4+yH2pnGO3QXtP1b4SvSHHfDp8660U9lIKmtbP1xnGWOS4X?= =?us-ascii?Q?1ysQDrNsppajyuhCLHvU+LUyPqZFcY1+wEYalBaabVnPQrOW0s/wH+nRA5SY?= =?us-ascii?Q?E6bBqgw90xMZlgQAFbxYxI7gJCLbPkKxw4E108D77VNcsqdKbzd0x5CR+DkY?= =?us-ascii?Q?FHUWXB8kNQ5XhLdH3fFDRgxu6FBQLa1uFWOI5fFqkUhw+1UEepHWxjqFFxBq?= =?us-ascii?Q?Bi3MJW8HAoEpJCesHKvxseT1bLR8UpbLgWGAW4Un1yT7ku91dqEJux69oLmA?= =?us-ascii?Q?psp1BPkUy85Zp54y3h8lTFk3gClqVIfy/MieIvW9RoNcxhLY7hS9QQytZCor?= =?us-ascii?Q?xkIKoG22+LX3mBfnsnZ77e6t890wKWYlz1YPhvk3MrXC/du7sEI/6cR+v3jl?= =?us-ascii?Q?NmKV663CERP5yOXnlFoI9v3y7/BgiLJhG//d6kyO4egOLfQpJpePnh5Rxjs4?= =?us-ascii?Q?ZZqZpV/1x8c/MMicz8lMmnIHINzYb/Q6EbcvOLIBXTXNzadHEIIpzgMsosgX?= =?us-ascii?Q?y+GRqT6AuHqvFF4U0gpLGqs5tju8qEwpTpdgXia3vh/mTyEoIUEO3tfpw/BN?= =?us-ascii?Q?BgQ9RCPzUbArDCYVLtt5vMiILKNwm9sM0Uhll7zH94AhicSIPiDoanBbGIbJ?= =?us-ascii?Q?WQ=3D=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 79638ea9-61fa-4cb8-8080-08dc18ab50e1 X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2024 04:58:45.7948 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rpsX0j4Kx8ZyVnMY3CWI00TMoGKj/zTNqx6rMe0yC9Yabf6aTcIwajU4xJc/LgImcorhF4FbWMFTdz0KYJGE7VlCuYpRruBNe9e6JqKjQpY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR01MB7339 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,nhi@os.amperecomputing.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: CW08LbCKVwGYiBH8auwiSWUux7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=ZqUEXq3x; dmarc=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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") From: Laszlo Ersek The current dependency evaluator violates the memory access permission when patching depex grammar directly in the read-only depex memory area. Laszlo pointed out the optimization issue in the thread (1) "Memory Attribute for depex section" and provided suggested patch to remove the perf optimization. In my testing, removing the optimization does not make significant perf reduction. That makes sense that StandaloneMM dispatcher only searches in MM protocol database and does not depend on UEFI/DXE protocol database. Also, we don't have many protocols in StandaloneMM like UEFI/DXE. >From Laszlo, "The patch removes the EFI_DEP_REPLACE_TRUE handling altogether, plus it CONST-ifies the Iterator pointer (which points into the DEPEX section), so that the compiler catch any possible accesses at *build time* that would write to the write-protected DEPEX memory area." (1) https://edk2.groups.io/g/devel/message/113531 Signed-off-by: Nhi Pham --- StandaloneMmPkg/Core/Dependency.c | 37 ++++---------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/StandaloneMmPkg/Core/Dependency.c b/StandaloneMmPkg/Core/Depen= dency.c index 440fe3e45238..2bcb07d34666 100644 --- a/StandaloneMmPkg/Core/Dependency.c +++ b/StandaloneMmPkg/Core/Dependency.c @@ -13,16 +13,6 @@ =20 #include "StandaloneMmCore.h" =20 -/// -/// EFI_DEP_REPLACE_TRUE - Used to dynamically patch the dependency expres= sion -/// to save time. A EFI_DEP_PUSH is evaluated one = an -/// replaced with EFI_DEP_REPLACE_TRUE. If PI spec'= s Vol 2 -/// Driver Execution Environment Core Interface use= 0xff -/// as new DEPEX opcode. EFI_DEP_REPLACE_TRUE shoul= d be -/// defined to a new value that is not conflicting = with PI spec. -/// -#define EFI_DEP_REPLACE_TRUE 0xff - /// /// Define the initial size of the dependency expression evaluation stack /// @@ -170,12 +160,12 @@ MmIsSchedulable ( IN EFI_MM_DRIVER_ENTRY *DriverEntry ) { - EFI_STATUS Status; - UINT8 *Iterator; - BOOLEAN Operator; - BOOLEAN Operator2; - EFI_GUID DriverGuid; - VOID *Interface; + EFI_STATUS Status; + CONST UINT8 *Iterator; + BOOLEAN Operator; + BOOLEAN Operator2; + EFI_GUID DriverGuid; + VOID *Interface; =20 Operator =3D FALSE; Operator2 =3D FALSE; @@ -253,8 +243,7 @@ MmIsSchedulable ( Status =3D PushBool (FALSE); } else { DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) =3D TRUE\n", &DriverGui= d)); - *Iterator =3D EFI_DEP_REPLACE_TRUE; - Status =3D PushBool (TRUE); + Status =3D PushBool (TRUE); } =20 if (EFI_ERROR (Status)) { @@ -356,18 +345,6 @@ MmIsSchedulable ( DEBUG ((DEBUG_DISPATCH, " RESULT =3D %a\n", Operator ? "TRUE" : "= FALSE")); return Operator; =20 - case EFI_DEP_REPLACE_TRUE: - CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID)); - DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) =3D TRUE\n", &DriverGuid)= ); - Status =3D PushBool (TRUE); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT =3D FALSE (Unexpected error)\n= ")); - return FALSE; - } - - Iterator +=3D sizeof (EFI_GUID); - break; - default: DEBUG ((DEBUG_DISPATCH, " RESULT =3D FALSE (Unknown opcode)\n")); goto Done; --=20 2.25.1 -=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 (#114025): https://edk2.groups.io/g/devel/message/114025 Mute This Topic: https://groups.io/mt/103824815/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-