From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web12.16012.1596192993078223326 for ; Fri, 31 Jul 2020 03:56:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q0KCHMFU; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596192992; 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=K8JLehroZ5Eof91v/QRPYMBDMlY+KzWpakFfi/VFveI=; b=Q0KCHMFUNQvOm7EHBYNRYGILzzNGIjP6ZcWGSTtxCAmE64mz0bvpHdQrFXXQTGeG1fJn1R SMrHe1s4EYwf1PrHI4Sf0k5xVo1/4gCDTzR+8jTRln+Xqq+at1w19LbldnwNYuzq+zFlmx ik3TTDj0/M9KiMZ2pBAOM/PygTigoIQ= 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-11-N_aaftIgNXG4Lx70zmy-0Q-1; Fri, 31 Jul 2020 06:56:23 -0400 X-MC-Unique: N_aaftIgNXG4Lx70zmy-0Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9038800472; Fri, 31 Jul 2020 10:56:20 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-160.ams2.redhat.com [10.36.114.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id 401255D992; Fri, 31 Jul 2020 10:56:17 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v13 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction To: devel@edk2.groups.io, thomas.lendacky@amd.com Cc: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Liming Gao , Michael D Kinney , Ray Ni References: <54ec37fce6382b464c537bf717d3570630c3a2ec.1596134638.git.thomas.lendacky@amd.com> From: "Laszlo Ersek" Message-ID: <98ff9331-c73b-07f9-de49-f08365c6e003@redhat.com> Date: Fri, 31 Jul 2020 12:56:17 +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: <54ec37fce6382b464c537bf717d3570630c3a2ec.1596134638.git.thomas.lendacky@amd.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 On 07/30/20 20:43, 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 > 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 > > 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 > + > FWIW: Reviewed-by: Laszlo Ersek