From nobody Fri Apr 26 17:04:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533256253373752.2502766978284; Thu, 2 Aug 2018 17:30:53 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 23E0220D7ADF8; Thu, 2 Aug 2018 17:30:52 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9E90321A143EF for ; Thu, 2 Aug 2018 17:30:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE4C3FA47C; Fri, 3 Aug 2018 00:30:48 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-123-32.rdu2.redhat.com [10.10.123.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EEF02026D69; Fri, 3 Aug 2018 00:30:47 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 02:30:45 +0200 Message-Id: <20180803003045.31740-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 03 Aug 2018 00:30:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 03 Aug 2018 00:30:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH] OvmfPkg/PlatformDebugLibIoPort: fix port detection for use in the DXE Core X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Brijesh Singh MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The DXE Core is one of those modules that call ProcessLibraryConstructorList() manually. Before DxeMain() [MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c] calls ProcessLibraryConstructorList(), and through it, our PlatformDebugLibIoPortConstructor() function, DxeMain() invokes the DEBUG() macro multiple times. That macro lands in our PlatformDebugLibIoPortFound() function -- which currently relies on the "mDebugIoPortFound" global variable that has (not yet) been set by the constructor. As a result, early debug messages from the DXE Core are lost. Move the device detection into PlatformDebugLibIoPortFound(), also caching the fact (not just the result) of the device detection. (We could introduce a separate DebugLib instance just for the DXE Core, but the above approach works for all modules that currently consume the PlatformDebugLibIoPort instance (which means "everything but SEC").) This restores messages such as: > CoreInitializeMemoryServices: > BaseAddress - 0x7AF21000 Length - 0x3CDE000 MinimalMemorySizeNeeded - 0= x10F4000 Keep the empty constructor function -- OVMF's DebugLib instances have always had constructors; we had better not upset constructor dependency ordering by making our instance(s) constructor-less. Cc: Ard Biesheuvel Cc: Brijesh Singh Cc: Jordan Justen Fixes: c09d9571300a089c35f5df2773b70edc25050d0d Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Jordan Justen Tested-by: Brijesh Singh --- Notes: Brijesh, can you please test this patch on SEV, with and without capturing the debug port? (In the first case, the debug log should just work; in the second case, the boot should remain fast.) Thanks! =20 Repo: https://github.com/lersek/edk2.git Branch: debuglib_dxecore OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c | 24 +++++++++++++= +++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c b/Ovmf= Pkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c index 81c44eece95f..74aef2e37b42 100644 --- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c +++ b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c @@ -16,14 +16,26 @@ #include #include "DebugLibDetect.h" =20 + +// +// Set to TRUE if the debug I/O port has been checked +// +STATIC BOOLEAN mDebugIoPortChecked =3D FALSE; // // Set to TRUE if the debug I/O port is enabled // STATIC BOOLEAN mDebugIoPortFound =3D FALSE; =20 /** - This constructor function checks if the debug I/O port device is present, - caching the result for later use. + This constructor function must not do anything. + + Some modules consuming this library instance, such as the DXE Core, invo= ke + the DEBUG() macro before they explicitly call + ProcessLibraryConstructorList(). Therefore the auto-generated call from + ProcessLibraryConstructorList() to this constructor function may be prec= eded + by some calls to PlatformDebugLibIoPortFound() below. Hence + PlatformDebugLibIoPortFound() must not rely on anything this constructor + could set up. =20 @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS. =20 @@ -34,12 +46,12 @@ PlatformDebugLibIoPortConstructor ( VOID ) { - mDebugIoPortFound =3D PlatformDebugLibIoPortDetect(); return RETURN_SUCCESS; } =20 /** - Return the cached result of detecting the debug I/O port device. + At the first call, check if the debug I/O port device is present, and ca= che + the result for later use. At subsequent calls, return the cached result. =20 @retval TRUE if the debug I/O port device was detected. @retval FALSE otherwise @@ -51,5 +63,9 @@ PlatformDebugLibIoPortFound ( VOID ) { + if (!mDebugIoPortChecked) { + mDebugIoPortFound =3D PlatformDebugLibIoPortDetect (); + mDebugIoPortChecked =3D TRUE; + } return mDebugIoPortFound; } --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel