From nobody Sun May 5 05:44:28 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 Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 15107670580721019.9730427775772; Wed, 15 Nov 2017 09:30:58 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 56A9220356886; Wed, 15 Nov 2017 09:26:47 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 DBA40220D4BEC for ; Wed, 15 Nov 2017 09:26:45 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FC345D9E3 for ; Wed, 15 Nov 2017 17:30:54 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-116-243.ams2.redhat.com [10.36.116.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 508DE60F8A; Wed, 15 Nov 2017 17:30:53 +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=209.132.183.28; helo=mx1.redhat.com; envelope-from=pbonzini@redhat.com; receiver=edk2-devel@lists.01.org From: Paolo Bonzini To: edk2-devel@lists.01.org Date: Wed, 15 Nov 2017 18:30:52 +0100 Message-Id: <20171115173052.1503-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 15 Nov 2017 17:30:54 +0000 (UTC) Subject: [edk2] [PATCH] OvmfPkg: PlatformDebugLibIoPort: save on I/O port accesses when the debug port is not in use X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When SEV is enabled, every debug message printed by OVMF to the QEMU debug port traps from the guest to QEMU character by character because "REP OUTSB" cannot be used by IoWriteFifo8. Furthermore, when OVMF is built with the DEBUG_VERBOSE bit (value 0x00400000) enabled in "gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel", then the OvmfPkg/IoMmuDxe driver, and the OvmfPkg/Library/BaseMemEncryptSevLib library instance that is built into it, produce a huge amount of log messages. Therefore, in SEV guests, the boot time impact is huge (about 45 seconds _additional_ time spent writing to the debug port). While these messages are very useful for analyzing guest behavior, most of the time the user won't be capturing the OVMF debug log. In fact libvirt does not provide a method for configuring log capture; users that wish to do this (or are instructed to do this) have to resort to . The debug console device provides a handy detection mechanism; when read, it returns 0xE9 (which is very much unlike the 0xFF that is returned by an unused port). Use it to skip the possibly expensive OUT instructions when the debug I/O port isn't plugged anywhere. Contributed-under: TianoCore Contribution Agreement 1.0 Cc: Laszlo Ersek Signed-off-by: Paolo Bonzini --- OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c b/OvmfPkg/Li= brary/PlatformDebugLibIoPort/DebugLib.c index 5435767c1c..06d6169dc8 100644 --- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c +++ b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c @@ -29,6 +29,16 @@ // #define MAX_DEBUG_MESSAGE_LENGTH 0x100 =20 +// +// The constant value that is read from the debug I/O port +// +#define BOCHS_DEBUG_PORT_MAGIC 0xE9 + +// +// Set to TRUE if the debug I/O port is enabled +// +static BOOLEAN mDebugIoPortFound =3D FALSE; + /** This constructor function does not have to do anything. =20 @@ -41,6 +51,7 @@ PlatformDebugLibIoPortConstructor ( VOID ) { + mDebugIoPortFound =3D IoRead8 (PcdGet16 (PcdDebugIoPort)) =3D=3D BOCHS_D= EBUG_PORT_MAGIC; return EFI_SUCCESS; } =20 @@ -77,9 +88,9 @@ DebugPrint ( ASSERT (Format !=3D NULL); =20 // - // Check driver debug mask value and global mask + // Do nothing if the global mask disables this message or the driver is = inactive // - if ((ErrorLevel & GetDebugPrintErrorLevel ()) =3D=3D 0) { + if ((ErrorLevel & GetDebugPrintErrorLevel ()) =3D=3D 0 || !mDebugIoPortF= ound) { return; } =20 @@ -138,7 +149,9 @@ DebugAssert ( // // Send the print string to the debug I/O port // - IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer); + if (mDebugIoPortFound) { + IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer); + } =20 // // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings --=20 2.14.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel