From nobody Thu Dec 26 11:55:56 2024 Delivered-To: importer@patchew.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; 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 1504540647905180.16909605747253; Mon, 4 Sep 2017 08:57:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EDCFA21E74920; Mon, 4 Sep 2017 08:54:37 -0700 (PDT) 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 4CA6221E3EA89 for ; Mon, 4 Sep 2017 08:54:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D559A40431D; Mon, 4 Sep 2017 15:57:23 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-2.rdu2.redhat.com [10.10.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 600A9BF672; Mon, 4 Sep 2017 15:57:22 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D559A40431D Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Mon, 4 Sep 2017 17:57:16 +0200 Message-Id: <20170904155717.31591-2-lersek@redhat.com> In-Reply-To: <20170904155717.31591-1-lersek@redhat.com> References: <20170904155717.31591-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 04 Sep 2017 15:57:24 +0000 (UTC) Subject: [edk2] [PATCH 1/2] MdePkg/BaseIoLibIntrinsic: fix SEV (=unrolled) variants of IoWriteFifoXX() 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: Michael D Kinney , Jordan Justen , Liming Gao 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" In commit b6d11d7c4678 ("MdePkg: BaseIoLibIntrinsic (IoLib class) library", 2017-04-12), the MOV instructions in the write loops were probably copied from the read loops. However, the operand order was not adjusted. As a result, the IoWriteFifoXX() routines, when invoked in SEV guests, now overwrite the source buffer with value 0x01 / 0x0001 / 0x00000001 -- the SevNoRepIo() function returns value 1 in EAX, in SEV guests --, and write the same value to the target IO port. Fix this by putting the target operand (AL / AX / EAX) first, and the source operand (BYTE / WORD / DWORD [ESI/RSI]) second. Cc: Brijesh Singh Cc: Jordan Justen Cc: Liming Gao Cc: Michael D Kinney Fixes: b6d11d7c467810ea7f2e2eda46ef0bdc57bf1475 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Brijesh Singh Reviewed-by: Liming Gao --- MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm | 6 +++--- MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm b/MdePkg= /Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm index 3e80c17d04a3..4b2af807cff8 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm +++ b/MdePkg/Library/BaseIoLibIntrinsic/Ia32/IoFifoSev.nasm @@ -212,7 +212,7 @@ ASM_PFX(IoWriteFifo8): jecxz @IoWriteFifo8_Done =20 @IoWriteFifo8_Loop: - mov byte [esi], al + mov al, byte [esi] out dx, al inc esi loop @IoWriteFifo8_Loop @@ -250,7 +250,7 @@ ASM_PFX(IoWriteFifo16): jecxz @IoWriteFifo16_Done =20 @IoWriteFifo16_Loop: - mov word [esi], ax + mov ax, word [esi] out dx, ax add esi, 2 loop @IoWriteFifo16_Loop @@ -288,7 +288,7 @@ ASM_PFX(IoWriteFifo32): jecxz @IoWriteFifo32_Done =20 @IoWriteFifo32_Loop: - mov dword [esi], eax + mov eax, dword [esi] out dx, eax add esi, 4 loop @IoWriteFifo32_Loop diff --git a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm b/MdePkg/= Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm index 26e016625b72..4d86a6cd5330 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm +++ b/MdePkg/Library/BaseIoLibIntrinsic/X64/IoFifoSev.nasm @@ -205,7 +205,7 @@ ASM_PFX(IoWriteFifo8): jrcxz @IoWriteFifo8_Done =20 @IoWriteFifo8_Loop: - mov byte [rsi], al + mov al, byte [rsi] out dx, al inc rsi loop @IoWriteFifo8_Loop @@ -241,7 +241,7 @@ ASM_PFX(IoWriteFifo16): jrcxz @IoWriteFifo16_Done =20 @IoWriteFifo16_Loop: - mov word [rsi], ax + mov ax, word [rsi] out dx, ax add rsi, 2 loop @IoWriteFifo16_Loop @@ -277,7 +277,7 @@ ASM_PFX(IoWriteFifo32): jrcxz @IoWriteFifo32_Done =20 @IoWriteFifo32_Loop: - mov dword [rsi], eax + mov eax, dword [rsi] out dx, eax add rsi, 4 loop @IoWriteFifo32_Loop --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu Dec 26 11:55:56 2024 Delivered-To: importer@patchew.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; 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 1504540650178809.3287626308627; Mon, 4 Sep 2017 08:57:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 36AFB21E7492A; Mon, 4 Sep 2017 08:54:39 -0700 (PDT) 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 F3F0E21E74925 for ; Mon, 4 Sep 2017 08:54:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C4076DDDC; Mon, 4 Sep 2017 15:57:25 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-2.rdu2.redhat.com [10.10.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DD60BF672; Mon, 4 Sep 2017 15:57:24 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C4076DDDC Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Mon, 4 Sep 2017 17:57:17 +0200 Message-Id: <20170904155717.31591-3-lersek@redhat.com> In-Reply-To: <20170904155717.31591-1-lersek@redhat.com> References: <20170904155717.31591-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 04 Sep 2017 15:57:25 +0000 (UTC) Subject: [edk2] [PATCH 2/2] OvmfPkg/PlatformDebugLibIoPort: write messages with IoWriteFifo8() 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: Jordan Justen 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" Since commit 19c6d9feaaf8 ("MdePkg: Expand BaseIoLibIntrinsic (IoLib class) library", 2017-01-14), IoWriteFifo8() has been widely available to modules. Use it to print debug messages and assertion failures to the QEMU debug port, rather than open-coded loops. In the general case this speeds up logging, because debug messages will now trap to QEMU once per message (as opposed to once per character), due to "REP OUTSB" in "MdePkg/Library/BaseIoLibIntrinsic/*/IoFifoSev.nasm". In SEV guests, there is no speedup (SEV doesn't support the REP prefix). SEV is detected internally to BaseIoLibIntrinsic. Cc: Brijesh Singh Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Acked-by: Brijesh Singh --- OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c b/OvmfPkg/Li= brary/PlatformDebugLibIoPort/DebugLib.c index 44850a9dbad0..5435767c1c69 100644 --- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c +++ b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c @@ -69,7 +69,7 @@ DebugPrint ( { CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; VA_LIST Marker; - UINT8 *Ptr; + UINTN Length; =20 // // If Format is NULL, then ASSERT(). @@ -87,15 +87,13 @@ DebugPrint ( // Convert the DEBUG() message to an ASCII String // VA_START (Marker, Format); - AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); + Length =3D AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); VA_END (Marker); =20 // // Send the print string to the debug I/O port // - for (Ptr =3D (UINT8 *) Buffer; *Ptr; Ptr++) { - IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr); - } + IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer); } =20 =20 @@ -129,20 +127,18 @@ DebugAssert ( ) { CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; - UINT8 *Ptr; + UINTN Length; =20 // // Generate the ASSERT() message in Ascii format // - AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n", FileName, - (UINT64)LineNumber, Description); + Length =3D AsciiSPrint (Buffer, sizeof Buffer, "ASSERT %a(%Lu): %a\n", + FileName, (UINT64)LineNumber, Description); =20 // - // Send the print string to the Console Output device + // Send the print string to the debug I/O port // - for (Ptr =3D (UINT8 *) Buffer; *Ptr; Ptr++) { - IoWrite8 (PcdGet16(PcdDebugIoPort), *Ptr); - } + IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer); =20 // // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel