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 C0F519410FC for ; Mon, 9 Oct 2023 06:47:27 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=BfB9lcA7WrLjuDECXfvcPkmTsrrouYpGgqg6UQJ6CaI=; 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=1696834046; v=1; b=sB3XEuVMLn0DSEryqoMAY1f1wpVyFqjmiZ562e0o0EkmaR5Tjwyz6CCR8AdEJGGKSnool35N m+huMBlWdDIZwQxARjsC/fmFTm9YzIkzvPiGoz+BHiR0YQtVkdSJ1C2B/0Uho4/sfZrE6LiaamS +TggMA4bcKC03ZHakR0jZHsg= X-Received: by 127.0.0.2 with SMTP id XW3uYY7687511xo7PR39ILXD; Sun, 08 Oct 2023 23:47:26 -0700 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.web11.55335.1696834045771147649 for ; Sun, 08 Oct 2023 23:47:25 -0700 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-25-KEcf47qlPN2J0pAFrPdwwA-1; Mon, 09 Oct 2023 02:47:21 -0400 X-MC-Unique: KEcf47qlPN2J0pAFrPdwwA-1 X-Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B86D8805B32; Mon, 9 Oct 2023 06:47:20 +0000 (UTC) X-Received: from [10.39.192.114] (unknown [10.39.192.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A67363F53; Mon, 9 Oct 2023 06:47:19 +0000 (UTC) Message-ID: Date: Mon, 9 Oct 2023 08:47:18 +0200 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v5 05/28] MdeModulePkg: Copy PEI PCD Database Into New Buffer To: devel@edk2.groups.io, taylor.d.beebe@gmail.com Cc: Jian J Wang , Liming Gao , Dandan Bi References: <20231009000742.1792-1-taylor.d.beebe@gmail.com> <20231009000742.1792-6-taylor.d.beebe@gmail.com> From: "Laszlo Ersek" In-Reply-To: <20231009000742.1792-6-taylor.d.beebe@gmail.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: dlA4nyUrOBOrZAMyFLwZgE1nx7686176AA= 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=sB3XEuVM; 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 10/9/23 02:07, Taylor Beebe wrote: > HOB memory should not be written to in DXE phase. This patch > copies the PCD database from PEI into a new buffer so updates > to dynamic PCDs don't write to HOB memory. > > Signed-off-by: Taylor Beebe > Cc: Jian J Wang > Cc: Liming Gao > Cc: Dandan Bi > --- > MdeModulePkg/Universal/PCD/Dxe/Service.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/MdeModulePkg/Universal/PCD/Dxe/Service.c b/MdeModulePkg/Univ= ersal/PCD/Dxe/Service.c > index 1ae06a639c43..0feb11142545 100644 > --- a/MdeModulePkg/Universal/PCD/Dxe/Service.c > +++ b/MdeModulePkg/Universal/PCD/Dxe/Service.c > @@ -885,15 +885,17 @@ BuildPcdDxeDataBase ( > // be NULL. If it is NULL, we just copy over the DXE Default > // Value to PCD Database. > // > - PeiDatabase =3D (PEI_PCD_DATABASE *)GET_GUID_HOB_DATA (GuidHob); > + PeiDatabase =3D AllocateCopyPool ((UINTN)GET_GUID_HOB_DATA_SIZE (Gui= dHob), GET_GUID_HOB_DATA (GuidHob)); > + ASSERT (PeiDatabase !=3D NULL); > > // > // Get next one that stores full PEI data > // > GuidHob =3D GetNextGuidHob (&gPcdDataBaseHobGuid, GET_NEXT_HOB (Guid= Hob)); > if (GuidHob !=3D NULL) { > - mPeiPcdDbBinary =3D (PEI_PCD_DATABASE *)GET_GUID_HOB_DATA (GuidHob= ); > mPeiPcdDbSize =3D (UINTN)GET_GUID_HOB_DATA_SIZE (GuidHob); > + mPeiPcdDbBinary =3D (PEI_PCD_DATABASE *)AllocateCopyPool (mPeiPcdD= bSize, GET_GUID_HOB_DATA (GuidHob)); > + ASSERT (mPeiPcdDbBinary !=3D NULL); > } > > // I'm only skimming the MdeModulePkg patches to get a feel for them, but this ASSERT() catches my eye. Using ASSERT()s for error checking is an ani-pattern. I realize that BuildPcdDxeDataBase() cannot return a value, and also that it already contains two instances of this anti-pattern: mPcdDatabase.PeiDb =3D AllocateZeroPool (sizeof (PEI_PCD_DATABASE)); ASSERT (mPcdDatabase.PeiDb !=3D NULL); mCallbackFnTable =3D AllocateZeroPool (mPcdTotalTokenCount * sizeof (LIST= _ENTRY)); ASSERT (mCallbackFnTable !=3D NULL); but at least please don't add more of it. The right way to deal with this is: mPeiPcdDbBinary =3D AllocateCopyPool (...); if (mPeiPcdDbBinary =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a: ...\n", __func__)); ASSERT (FALSE); CpuDeadLoop (); } This way: - you'll get an informative error message in DEBUG/NOOPT builds, - you'll get a source file name and line number, - via ASSERT -> DebugAssert -> PcdDebugPropertyMask, you'll see either CpuBreakpoint() or CpuDeadLoop() (or nothing) called, dependent on platform choice, - regardless of platform choice and build target (DEBUG/NOOPT/RELEASE), execution will not progress past the explicit CpuDeadLoop(). (This approach was originally suggested by Mike Kinney to me.) Plain ASSERT() for error checking is a bad pattern in the edk2 core; please avoid it if you can. Laszlo -=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 (#109435): https://edk2.groups.io/g/devel/message/109435 Mute This Topic: https://groups.io/mt/101843346/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-