From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.54]) by mx.groups.io with SMTP id smtpd.web11.5163.1595909274239531953 for ; Mon, 27 Jul 2020 21:07:54 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=Jb9sbrmO; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.54, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JY1KT9qcUS7XH8sURmPRdOmSZZpRs04fxyO/e3xdWgcbs9wrhmRev5RHD0qt/B24p8f+wGTxUZvQLmxMRstjluCiWubsldCb7LHTagxZugPlabeay00Bv0oshCHBDHznBg0fKvmuC9j3WerRBp6F1F6L7d635OuV9QoJxlCr0z20HAwSqS4z+LAbpzI3UB45gjLn7ex8ia6xtwcOxqM2CDWwcjpep8YwJmhNCXjQLn9xokS3hLzZaroVlTN48CEQcI0uJ4kSQO4sqY58dbL/wosKsxRLNehF7Qb0IQkMaalWzBGzcCvuYv1oUQP20WqGWPjMwUoeACNshdroMU3nNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wTeE1S7jvB5yN1ID+DTpQaa/wpzxeAZRYN0N/3ObF3E=; b=kom7w+/9gpn2MuAmnEKA8qxiWCNG+H5s/tkHU2GapE+fKgvrbI8G9DV9vrWAhvFWQuEq5GxnEc5/EwL8v9W/h9buFYQsJpjHIHxJdMg8tK1hX9yFL/YLhQRFEdf/U3p25QMvIE4yoih1u4PgnOV7ieP8n7Q20u6LCVk6/S72p8H5XFgueSD2yHsaeI57nGYkYMWEdEzom2gYgPYX3k30y26yHTW/ucqqk7et0y+PRLaVqUf1jhBTlzq2RHe2jUPP4Azj+MEnkiYqhk1kiyY0Qu9LqQ94Xcm0+RS1muS2Pv+r512xoMGEfiBo/ZqnaBsJElz1dG+hRfI418yFEfap+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wTeE1S7jvB5yN1ID+DTpQaa/wpzxeAZRYN0N/3ObF3E=; b=Jb9sbrmOEueFvek73ENQtCh1A/wdHCEOMEn5KBTVTJ6dfBA4DBqfg+aDQJoZpUnyJNrF8gR94krc/hzzu8Z93t6TZPyEafR55rmTm+GYtMNJvJkDzizt947o8rABoSFtre+N6vi+oYu3+o3N6m9BZmTH7TDKDs09gsFmLZ6RarE= Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1450.namprd12.prod.outlook.com (2603:10b6:4:3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Tue, 28 Jul 2020 04:07:51 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.034; Tue, 28 Jul 2020 04:07:51 +0000 Subject: Re: [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction To: "Gao, Liming" , "devel@edk2.groups.io" Cc: Brijesh Singh , Ard Biesheuvel , "Dong, Eric" , "Justen, Jordan L" , Laszlo Ersek , "Kinney, Michael D" , "Ni, Ray" References: From: "Lendacky, Thomas" Message-ID: <57cfa8bb-f683-08c4-7262-5762a9e0a4c1@amd.com> Date: Mon, 27 Jul 2020 23:07:49 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: X-ClientProxiedBy: SN4PR0601CA0013.namprd06.prod.outlook.com (2603:10b6:803:2f::23) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from office-linux.texastahm.com (67.79.209.213) by SN4PR0601CA0013.namprd06.prod.outlook.com (2603:10b6:803:2f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Tue, 28 Jul 2020 04:07:50 +0000 X-Originating-IP: [67.79.209.213] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0af2d449-f407-4caa-cefc-08d832abcbca X-MS-TrafficTypeDiagnostic: DM5PR12MB1450: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aYahGwLeUzODGuRf9TDSlZJ2NsxFQu7Cl1D+YIKMj1QIhD6CFFPSgHhXH4m5IPfaOnHpqUXauchob8A/H/Yi7evcael27m98dF01rxK+eTT/1ugUKfUYecHNE8VQ/BH4XOx34JRiSS9xVJ8UJ7Q3cuMxIj/AcmSif8c17YfLdg105sWAPmmnH/V091VHnuneV/LLBAsWPzKEw7yTkb+ps5/tQlfX70rf+b+kK1L5pXDF4AiSXmJ8ia6b/e/lGBrO/81rqvVGD0IKPGz5JoqXrKUKyiVDPTQzfUuED1DwJPccuT2p0/Y+jDKYFvP+gLdt9rE8k9PxFurbtgQbqCki9Q5EDZMpzISowcodGu5RKKOcwjGg46Rbh/Bvv/n9lxUfEJEh9HZmkyT5q4LqtIINQ3uuTyjpt+YV0c9aRCmDyn5ShMXP3eUgP1YZyLjQk8n5dq0JI5bOs3g4TteuxTqsnA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(110136005)(52116002)(478600001)(956004)(4326008)(54906003)(19627235002)(16526019)(8676002)(2616005)(186003)(316002)(6486002)(45080400002)(31686004)(8936002)(53546011)(83380400001)(6506007)(6512007)(966005)(86362001)(5660300002)(26005)(66946007)(31696002)(2906002)(66556008)(66476007)(36756003)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GhaNoFgXgJjZr6pXaghRcOTircMvIekl2RBrHjS1S30TU0+eXMQW8dZe3y4l72TMjiXgs7uVth6O/haV+SIVB0nSTmLIN2JpfOomC8vUlF+t1N7qWS++BIwq8j9RAKD5ydKDL14yX0SAbIFeUjxvvxJ2rJhblLLPJptS0reAcfmkv7kn20zQhVsbnlkNyFbSFwqWJsAapIzy7IsSsrRxcjjSKKytIc1OWc8IlvKGfpl5huTqkrNVsI26VOXl0tBOcpdplkLvFyXaitVvQjaTTZCKSkjWKcFOd6ThaezFkS/Np0SDzQ/G7QzxFoSrg+vVziQy53I/AcLP4OOKKsi2Sp/9jIQOsFzohxQKroJz8m8b8x5MdHFb3ARrU9xtMn0mTOXex82BdCIrQhxUCeFVLa7+MPApQPd/RCMyXpnKkBiJw9PpIZzR1dKn6t6BlopY6hjvEk+3uXY85e73t3l8a7PMmJLuo90OPHkxuO4l5EPSCTWnyYawOyHM09AI9G8V X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0af2d449-f407-4caa-cefc-08d832abcbca X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2020 04:07:51.6196 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Uwk/YAvbVQXakByaGxrkxL+ygzXEnWs3HcB9QYho82Zc6uZlzFshNctobbjQEX1C1++x00oYFDeGwMcUEyqLCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1450 Content-Type: text/plain; charset=iso-2022-jp; format=flowed; delsp=yes Content-Language: en-US Content-Transfer-Encoding: 7bit On 7/27/20 8:34 PM, Gao, Liming wrote: > Tom: Hi Liming, > I meet with GCC failure on this patch. Can you help check it? If nasm doesn't support the vmmcall instruction in 32-bit mode, you have to use inline assembly to support it. What version of GCC are you using. I was able to successfully build the Ia32 version with my GCC level. The Ia32 version uses a trick to do switch to 64-bit just to encode the instruction. Looks like that doesn't work with your version of GCC. I can probably switch to defining the instruction as bytes. Let me look into that and possibly send you a patch to test. Thanks, Tom > > Edk2/Build/IntelFsp2Pkg/DEBUG_GCC5/IA32/MdePkg/Library/BaseLib/BaseLib/OUTPUT/Ia32/VmgExit.iii:33: error: elf32 output format does not support 64-bit code > GNUmakefile:741: recipe for target > > Thanks > Liming > -----Original Message----- > From: Tom Lendacky > Sent: 2020年7月27日 23:26 > To: devel@edk2.groups.io > Cc: Brijesh Singh ; Ard Biesheuvel ; Dong, Eric ; Justen, Jordan L ; Laszlo Ersek ; Gao, Liming ; Kinney, Michael D ; Ni, Ray > Subject: [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction > > From: Tom Lendacky > > BZ: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Cthomas.lendacky%40amd.com%7C77c8250cd9e14f2929a008d832965726%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637314968570901400&sdata=6zqseI3tVmaw351w9mfEymMnDcjDzjvcBrhARU6r3Ho%3D&reserved=0 > > 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. > > Provide the necessary support to execute the VMGEXIT instruction, which is "rep; vmmcall". > > 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 | 37 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ > 4 files changed, 85 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..a4b37385cc7a > --- /dev/null > +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm > @@ -0,0 +1,37 @@ > +;---------------------------------------------------------------------- > +-------- > +; > +; 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, so work > +around ; this by temporarily switching to 64-bit mode. > +; > +BITS 64 > + rep vmmcall > +BITS 32 > + 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 > + > -- > 2.27.0 >