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 1DC2A74003A for ; Fri, 19 Jan 2024 13:50:30 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=bP3VyXDeyeHZrMjh9LA7DylYJQvQz7S9d5U3IMgjeew=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1705672229; v=1; b=GkOFJJt0bvf4UUIblXwZjt5gQLAfMkdUbpTiDElbjMHawLKksS7GhYUFj9QbFbDKzRsXZydQ qTVjVvuJuIGPkrjMG/C3KXLW2okQNS9WgpVGeK6sPtl/+YVHNukm22RkD7yVK8H1jpargJRb3Vm PcjJw80fOAL2jxBBmjvFqwF4= X-Received: by 127.0.0.2 with SMTP id CAL7YY7687511xmh1DsmJ3zE; Fri, 19 Jan 2024 05:50:29 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.22438.1705672228995139333 for ; Fri, 19 Jan 2024 05:50:29 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-r105CFOtOCCnmFoURLB_jw-1; Fri, 19 Jan 2024 08:50:22 -0500 X-MC-Unique: r105CFOtOCCnmFoURLB_jw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A2FF85A58A; Fri, 19 Jan 2024 13:50:22 +0000 (UTC) X-Received: from [10.39.192.76] (unknown [10.39.192.76]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A9E8C1690E; Fri, 19 Jan 2024 13:50:21 +0000 (UTC) Message-ID: <6d8d853b-7844-ad56-7f74-c1e4accbde18@redhat.com> Date: Fri, 19 Jan 2024 14:50:20 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH 1/1] StandaloneMmPkg/Core: Remove optimization for depex evaluation To: Nhi Pham , devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, ray.ni@intel.com, sami.mujawar@arm.com References: <20240119045646.3896430-1-nhi@os.amperecomputing.com> From: "Laszlo Ersek" In-Reply-To: <20240119045646.3896430-1-nhi@os.amperecomputing.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.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,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DnSA4z1o7j3mICvJ0pK0SUDbx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=GkOFJJt0; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.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 On 1/19/24 05:56, Nhi Pham wrote: > From: Laszlo Ersek >=20 > The current dependency evaluator violates the memory access permission > when patching depex grammar directly in the read-only depex memory area. >=20 > Laszlo pointed out the optimization issue in the thread (1) "Memory > Attribute for depex section" and provided suggested patch to remove the > perf optimization. >=20 > 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. >=20 > From Laszlo, >=20 > "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." >=20 > (1) https://edk2.groups.io/g/devel/message/113531 >=20 > Signed-off-by: Nhi Pham > --- > StandaloneMmPkg/Core/Dependency.c | 37 ++++---------------- > 1 file changed, 7 insertions(+), 30 deletions(-) >=20 > diff --git a/StandaloneMmPkg/Core/Dependency.c b/StandaloneMmPkg/Core/Dep= endency.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 expr= ession > -/// to save time. A EFI_DEP_PUSH is evaluated on= e an > -/// replaced with EFI_DEP_REPLACE_TRUE. If PI spe= c's Vol 2 > -/// Driver Execution Environment Core Interface u= se 0xff > -/// as new DEPEX opcode. EFI_DEP_REPLACE_TRUE sho= uld be > -/// defined to a new value that is not conflictin= g with PI spec. > -/// > -#define EFI_DEP_REPLACE_TRUE 0xff > - > /// > /// Define the initial size of the dependency expression evaluation stac= k > /// > @@ -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", &DriverG= uid)); > - *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", &DriverGui= d)); > - 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; looks good to me, thanks! (Can't give an R-b or A-b for a patch that was originally written by me, just confirming that the code and commit message look good.) -=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 (#114047): https://edk2.groups.io/g/devel/message/114047 Mute This Topic: https://groups.io/mt/103824815/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-