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 2F379AC0AD1 for ; Mon, 22 Jan 2024 02:34:00 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=je0NgOOmltdhRnC+0mswV3UPahViO/YajQZSPyOmQm8=; 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=1705890839; v=1; b=crPFkGPXjiHW63VWUxWq8ZfBcCHCkK+vBdnBql+gBx+ms9IizpDRkKzhVZM5DfbkYEt7uMQZ ULbHDNjW2yd4hoSVKkbwBa6xH4bl7iGTsBZhg5mBCzmKMufTBDoG2FwIReRO1IHbCBGp9RFhhkw wtoZNkFMnWJznf+ch4Xgq0Ng= X-Received: by 127.0.0.2 with SMTP id tQNyYY7687511xr7cFe3t20A; Sun, 21 Jan 2024 18:33:59 -0800 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.125]) by mx.groups.io with SMTP id smtpd.web10.64459.1705890836619839289 for ; Sun, 21 Jan 2024 18:33:58 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EAFckrpYKr7ILmwJVQk1TeHnLGVmepUUPQZ1LoumGXDOtJoFCsMeWkvD5pa+LDHpWM4fb7aIzv4cUpiG7rvQXWEEQwkYI1hg+r2xU1kShFgVakJ59so7yPC0p9owxrylmRHT+3PI3n1B/XPK7VOg2TirFtTMjvxOaP1l1KVco0vamCylUS3WodeaNbMwYGvJWbVwcz1jRMQREU5ddtpAldiDs4wUNIKkmZgyYZ19teN+Iw7F41nH0EJjf25mm9XdGd9/Jg8rZ9PgvhXCqcuv4+nsr5gcn7vux1z+VdqeE6aBMF1erdDWwbU0BM764xMMXkCUlPyMkald7yv5DoZo6Q== 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=ZLm24F7hYHyWlfNGeYZm5SByGp0s7U1wvTau52G2d0c=; b=GK3PCQbZ2CzvSUWzuxO+AnmTVcYL3HgqJse/N3hLHFWgt9NpFe3ePtbMxBi5CmXuYD1lmSPjrZqZp8N0zkswJSIPzvtLTTCk0GjsaCyTNAyZE39FBIhhcMNvnTGPcUzi6oNeltJeUOi+3thnPPBhESeak5ZgtESZUu9neNC86Dr7UZZ0ZFeUrItUv4S+gxTz+9Og+Gqvp+XjXJJB6KRskvH+neBR1qDQhLZtjl9gKKQzekghMQQxsonlm5X66YqJIwAY0ACuCHZM3fseSzbMFD9AplhKxEnotH8IaEh1LSTYMyqIKF6r36DdSfYpwywiTGOGCzzlkB47KwD3eqJatg== 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 MW4PR01MB6450.prod.exchangelabs.com (2603:10b6:303:7b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.29; Mon, 22 Jan 2024 02:33:53 +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.031; Mon, 22 Jan 2024 02:33:53 +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 , "levi . yun" Subject: [edk2-devel] [PATCH RESEND 1/1] StandaloneMmPkg/Core: Remove optimization for depex evaluation Date: Mon, 22 Jan 2024 09:31:41 +0700 Message-ID: <20240122023141.1620010-1-nhi@os.amperecomputing.com> X-ClientProxiedBy: SI1PR02CA0005.apcprd02.prod.outlook.com (2603:1096:4:1f7::13) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7287:EE_|MW4PR01MB6450:EE_ X-MS-Office365-Filtering-Correlation-Id: feea5777-f593-487d-94fb-08dc1af292ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 52VCueZ4Tf0uclB9qoGoBQIWlUd3SBiQQ+K2CUl9b/ADfB9Ww26qm3h/g6frJFOsBm5jclHfv4KsWPj7VTWRXTPm34Y+k8Tt7+Yn/uKDvrNwbewzBOZP48oLGXeb41pW95pMe8vvDTjI9TGLhUk0S5Dm7TBlEz7LnORAflgIKcn6Y1fF8IbnQTPFrNRhxBntcczEmdkvu1czdNKEwM5I3Wi29PqArc+HRnBZnLlvZFIPCsH+2DE9/TTFbXntzmYeQpB9locKBKcHfXpBKTFoYUFpBaQghLaf2ZqU2DLvB/SVPkYM6ZoNg4S5glLihSHqNHWXhZY11rEh6aLX92k94Vj0K7iHww9NKUrTX9jg2i9Pk488uaQPeFccmzRkDP/rePXBvP+hUeU5diKRaG+8aEu+qp1ux8W3mGUslDX2xO1UFI2umDqc186bGtVZBD63E0Z7TBFO9QvEKYyWXHu2g93EghIa9n6m56AbQBVKQ0aXsSqX6mx0ol4+om7ll8M7rSxeMYxapUBbiqSlh5az5MTXihMJM1QD+CJttXwaKq6KRRKoMM7ggPeK8XGAytik/ciugS7c7rythkzIm2BRU0w3kOi9yQ65kBiST0NwPUo= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kdb1AAW99S9WSeH2AAkyB+IOr7kCY1qcwedoU7M9Vi/A7tk/OnyN0t4qc5Hm?= =?us-ascii?Q?IXbOyR0H52zpsQOFmq/WduNKnPLToEmh3iafkSRrbAWNb+FuiP4I4Fef7bU2?= =?us-ascii?Q?rTpgiiqzNOfCuyJrfKA54fFnxZpEr0a0x2pwPtj55/NaYjoEAQtliMnF8+2b?= =?us-ascii?Q?mzBwqkreSq/ULIRhW9zlQzOX83uajdoqkum9JB1wchlWu8YVbOeHE/Vz2sIN?= =?us-ascii?Q?ZD/2dks1DGeVfcO6iceredDZ1vRTPgoh/D/FxJHu1cSYg+1pUEDWYh1Ceeg1?= =?us-ascii?Q?z/WNu+x1B8ZYQLCL3ezX6/7SalcA777J2QLKK+Hn9l4l6sKJC8KTwby9jRw/?= =?us-ascii?Q?icEqeyoDK16MQn53PbGICyHNuERUDzHfy0ZjAhmYbCfDwKyyLSE5a2xo1Thv?= =?us-ascii?Q?itBB2+ZitdwO8U3w5MvaYhLXTbiixgKkJGf2yQrv8b5H6eSrs3yOnSmePLD4?= =?us-ascii?Q?ftiak2vqlMOdbOXRHwqhfMzMsWpZzyEdffdaXCt3wJwz3wdfcISUISYfj4gT?= =?us-ascii?Q?ASc0QZlWnaN6btlGP3RyhodZGSm5A+UYw2kB9trBdHk7g5iJAcQFGZHxYvsJ?= =?us-ascii?Q?afXLbS0ubradmAnZDYZusk7LqEZCFvv25UTEwygHzjipgO3viItYIX8mHSxO?= =?us-ascii?Q?AeH+tM4YnPJdzfjkVUOHVsnkKaDvOhDLETCluk3gY/pWzMtxBP1K4G8Uq8ic?= =?us-ascii?Q?y6m8n3bBiPQCLghq7KEyTjrXTrEBTUOyd7LzZhMMHOF1Fmo/rJddizAjFfbO?= =?us-ascii?Q?qDVvjxzNasWhEAZSoWnpqZRI5CzMHHIHLi7BezZ1/fvI0U5dMYKMBsCybLqn?= =?us-ascii?Q?ZQc/P6tHcyReHFWEwL936VCgRaFQHnP+9TUpbuDPP9wit+DbReRwruxlPk95?= =?us-ascii?Q?ztPpnvvVI2v5wQ8eLtgtBYZYdHpchMnD2lwuMXw4+bakB8NQAG0hEg4tCXQv?= =?us-ascii?Q?Dpr+2tHpwASfGOf/7U/JispAojulfHBQXN3JFShMr00VpUzfJZwwb86CXrJf?= =?us-ascii?Q?8hDIvCA4rCrqmFccPaF/kKMQ9n9dsUtch4ZkswYuUB37tmgcG0o07I/6BmZF?= =?us-ascii?Q?EbZzZGgVY8ZQpxPmF8W8JUb4sXOMLqpelUChkDNylEpHzni+zjN0LzLUnlDa?= =?us-ascii?Q?+khqzX2DN39hv/xQ4TM5w3lmcpwqgGRWnASZw6wpzNWh6i2rmdTpDQsELrPQ?= =?us-ascii?Q?f2ITzRCJErVfFoidfz3V2BA+b/bYWulHLgsdPH+CCUVLBOANUAuXG6cRn1Cd?= =?us-ascii?Q?Hjp//xWq9Cg7XPxtEQtcIeFAJZtNC50WXInE1Zx9/16F2CphkQF0iq9P/Xkb?= =?us-ascii?Q?KCb+kyQIdrjqwemqJG9yPoLmLIezmn7e3r2d1rjKlTtkxmHHwGIHYdTFsHW0?= =?us-ascii?Q?DKTvtctlPZyV6F+gitSJejxj0NSREotuRChLYntdMm0GT1wU314ia10cYETn?= =?us-ascii?Q?RyVYyXmeSHYpY+Ctlyq3cV3WZCpuqvExOY95eBqUgod5QZr7xUak/lUQOs66?= =?us-ascii?Q?ct//pAxVzra8gsJB74IWYhO9sCvAMUAgB8vFcediJCWIgvWNvN8TPfoQKBZN?= =?us-ascii?Q?4z9HC36mevrJ7ga6DvLxgCik46mFcIuKjwehhBwOnhS6ObMPT4zzCvKQKCRm?= =?us-ascii?Q?kA=3D=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: feea5777-f593-487d-94fb-08dc1af292ce X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2024 02:33:52.9833 (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: 9MSFhD4CoFwh7QE5yUwEctjCX/hL3zlD76CEMl8fJApVIKyi1ojiMFFOh6ohILNwaeBv2sI2J0JTpHmkmT5kskrHsQpFZ5ZWD1g0FsLrXjs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR01MB6450 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: u6OJFNTARvSvhsfwk8lvJZQgx7686176AA= 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=crPFkGPX; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 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 Tested-by: levi.yun Reviewed-by: levi.yun --- 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 (#114130): https://edk2.groups.io/g/devel/message/114130 Mute This Topic: https://groups.io/mt/103879487/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-