From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web11.51681.1597085250802119054 for ; Mon, 10 Aug 2020 11:47:31 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R574m78b; spf=pass (domain: redhat.com, ip: 63.128.21.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597085250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=89Ft7yw/La9kBiqjwHK4iqnAj7HsyZoEbnpZkEOgwCs=; b=R574m78bIJ/MYkib7nPEdRWcDEQ5rKNGmj7Wkl/G5RbwI3JtSItKLWjmfe4mmDibt1Ps+n 34BEsQpbFYSgniiwpE9VFmLx0XfxD26sSlzGU1XRsTadU8hnV7Ede8ekst0it/FjXv8jZJ VsRqAPFkGyLi75sPq6iVBq/eyhQkzIM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-4-gVVkapjBMmSBuqoErAhSNg-1; Mon, 10 Aug 2020 14:47:20 -0400 X-MC-Unique: gVVkapjBMmSBuqoErAhSNg-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5ECDE19057A0; Mon, 10 Aug 2020 18:47:18 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8E5390E95; Mon, 10 Aug 2020 18:47:15 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v14 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction To: devel@edk2.groups.io, thomas.lendacky@amd.com, Liming Gao Cc: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Michael D Kinney , Ray Ni References: From: "Laszlo Ersek" Message-ID: <76d40c90-ea55-4f6a-f3c8-2ad6b8dcd27f@redhat.com> Date: Mon, 10 Aug 2020 20:47:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hi Tom, On 08/07/20 21:38, Lendacky, Thomas wrote: > From: Tom Lendacky > > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 > > VMGEXIT is a new instruction used for Hypervisor/Guest communication when > running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE) > to occur, resulting in a #VMEXIT with an exit code value of 0x403. > > Since SEV-ES is only supported in X64, provide the necessary X64 support > to execute the VMGEXIT instruction, which is coded as "rep vmmcall". For > IA32, since "vmmcall" is not supported in NASM 32-bit mode and VMGEXIT > should never be called, provide a stub implementation that is identical > to CpuBreakpoint(). > > Cc: Michael D Kinney > Cc: Liming Gao > Reviewed-by: Liming Gao > Signed-off-by: Tom Lendacky > --- > MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ > MdePkg/Include/Library/BaseLib.h | 14 +++++++++ > MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 38 ++++++++++++++++++++++++ > MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ > 4 files changed, 86 insertions(+) > create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm > create mode 100644 MdePkg/Library/BaseLib/X64/VmgExit.nasm this patch is identical to the one in v13, but you forgot to pick up my: Reviewed-by: Laszlo Ersek from: https://edk2.groups.io/g/devel/message/63568 http://mid.mail-archive.com/98ff9331-c73b-07f9-de49-f08365c6e003@redhat.com Liming, when you push this series, please add my R-b to the commit message on this patch. Thanks Laszlo > > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf > index 3b93b5db8d24..3b85c56c3c03 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -184,6 +184,7 @@ [Sources.Ia32] > Ia32/DisableCache.nasm| GCC > Ia32/RdRand.nasm > Ia32/XGetBv.nasm > + Ia32/VmgExit.nasm > > Ia32/DivS64x64Remainder.c > Ia32/InternalSwitchStack.c | MSFT > @@ -317,6 +318,7 @@ [Sources.X64] > X64/DisablePaging64.nasm > X64/RdRand.nasm > X64/XGetBv.nasm > + X64/VmgExit.nasm > ChkStkGcc.c | GCC > > [Sources.EBC] > diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h > index 7edf0051a0a0..04fb329eaabb 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -7848,6 +7848,20 @@ AsmXGetBv ( > ); > > > +/** > + Executes a VMGEXIT instruction (VMMCALL with a REP prefix) > + > + Executes a VMGEXIT instruction. This function is only available on IA-32 and > + x64. > + > +**/ > +VOID > +EFIAPI > +AsmVmgExit ( > + VOID > + ); > + > + > /** > Patch the immediate operand of an IA32 or X64 instruction such that the byte, > word, dword or qword operand is encoded at the end of the instruction's > diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm > new file mode 100644 > index 000000000000..69f7fbf3506a > --- /dev/null > +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm > @@ -0,0 +1,38 @@ > +;------------------------------------------------------------------------------ > +; > +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; VmgExit.Asm > +; > +; Abstract: > +; > +; AsmVmgExit function > +; > +; Notes: > +; > +;------------------------------------------------------------------------------ > + > + SECTION .text > + > +;------------------------------------------------------------------------------ > +; VOID > +; EFIAPI > +; AsmVmgExit ( > +; VOID > +; ); > +;------------------------------------------------------------------------------ > +global ASM_PFX(AsmVmgExit) > +ASM_PFX(AsmVmgExit): > +; > +; NASM doesn't support the vmmcall instruction in 32-bit mode and NASM versions > +; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into elf32 > +; format. Given that VMGEXIT does not make sense on IA32, provide a stub > +; implementation that is identical to CpuBreakpoint(). In practice, AsmVmgExit() > +; should never be called on IA32. > +; > + int 3 > + ret > + > diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseLib/X64/VmgExit.nasm > new file mode 100644 > index 000000000000..26f034593c67 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm > @@ -0,0 +1,32 @@ > +;------------------------------------------------------------------------------ > +; > +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
> +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +; Module Name: > +; > +; VmgExit.Asm > +; > +; Abstract: > +; > +; AsmVmgExit function > +; > +; Notes: > +; > +;------------------------------------------------------------------------------ > + > + DEFAULT REL > + SECTION .text > + > +;------------------------------------------------------------------------------ > +; VOID > +; EFIAPI > +; AsmVmgExit ( > +; VOID > +; ); > +;------------------------------------------------------------------------------ > +global ASM_PFX(AsmVmgExit) > +ASM_PFX(AsmVmgExit): > + rep vmmcall > + ret > + >