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.56]) by mx.groups.io with SMTP id smtpd.web10.52506.1597086767836211315 for ; Mon, 10 Aug 2020 12:12:48 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=PqUkdE8X; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.56, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UJc5yVeFIihEgEQaPBRJ7sZJDGA8DpSjbD7Tj3KYk69aYpnQxylCSBRPIwxJ5Wo2tyY/MOA9ltUJWkeDrlesFBeHY3Z95NWBz9YRZFrwauUX5tjJ6vak911lJ/1BUPZB9Iq1BnFvz0kt1ZYLNvPaYEA+ihvVGo1ZDXegGiwHMAPJkwflFBVK1JNzEgAwqt2Gm+Ur+ZwApKAqfuCre+Z0JghDlmCfpIiI6SKn4XQ0QxSkbDhmxWqdjbzlJKPpWv0t4Ym7s42rHkE1HnapeqjbkxW91KHbGjdB1Yd3yG7ktXlQfjetFQb6ImXCxSJ66u6Fi4hgNe0D1+PAx2I1L4sM4w== 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=Z4xZuoMxOqpoYux4KYicN80lpJarD6AjmCZEUiW5YY0=; b=ilj12jgHCSihLWx3dYEQIYg+Ht8bVWlh55DD9e06GctQTuagjJ1VGaT2jfdiRs0v5YFypJo1QyKYjOh432GjVhGvOAgIrc/f89em/THrNSpdDweWUdOJ2t6Ob9T4iNtMyrJz8EnmVLMFOJt/mH70dMJ1IfHAXeU7L1JjIx0lLdy9M0NyvYk7UW0kThM/vdcXUVGZOvLaPzYw3TeoZqPyjHLy3Xh+aW7pPjc4zNeLwu2egTphZqnUIMpOsEBRye1vu8LYXzRHb1xILGyT1mVEHuyIVsYXOYbbbUsKqu8vgnQPRdnWvU1HbShcTpJMkLdZ0z2hu8vL3DCehSfjNGITzA== 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=Z4xZuoMxOqpoYux4KYicN80lpJarD6AjmCZEUiW5YY0=; b=PqUkdE8X6olpXhm1MOls+UFU93CBBH4VISGSskcMYkoefNs+ZyIun0RD8VCgGMOe6X1mdvlQJte+kJYk75UGOcaSpHiyB/9qPNJblFJFH1rv/jNkBt7Qx8L7naKq5APlyraQh69I67XeGzqB6sY624oRgefsJo4W+noIPAuHYc4= 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 DM5PR1201MB2504.namprd12.prod.outlook.com (2603:10b6:3:e3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.22; Mon, 10 Aug 2020 19:12:46 +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.3261.024; Mon, 10 Aug 2020 19:12:46 +0000 Subject: Re: [edk2-devel] [PATCH v14 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction To: Laszlo Ersek , devel@edk2.groups.io, Liming Gao Cc: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Michael D Kinney , Ray Ni References: <76d40c90-ea55-4f6a-f3c8-2ad6b8dcd27f@redhat.com> From: "Lendacky, Thomas" Message-ID: <842de351-7e52-5a55-2edb-f3ddf9c3e553@amd.com> Date: Mon, 10 Aug 2020 14:12:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <76d40c90-ea55-4f6a-f3c8-2ad6b8dcd27f@redhat.com> X-ClientProxiedBy: SN6PR08CA0003.namprd08.prod.outlook.com (2603:10b6:805:66::16) 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 [10.236.30.118] (165.204.77.1) by SN6PR08CA0003.namprd08.prod.outlook.com (2603:10b6:805:66::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Mon, 10 Aug 2020 19:12:45 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3e212580-ab77-4359-51bf-08d83d615d27 X-MS-TrafficTypeDiagnostic: DM5PR1201MB2504: 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: ynCpz5DXaFIpSk3rps26uTepC0ZBSm3p6u/mwnfyEzMN21ZC+mTrKPH9zloBNfbetVre6REjoe5Jfenxcpw1it53x0uHrK1DEhYYjiNNPZjl18sWzHfwDZMGs2UtuqWFcJ/oryE1LfoHcxSnNcEfHTnacmytLiRTNRiSqI1o4iR0L7HniZi5ESJiiMq1tvZ6I9kQdLdta+HiwYG2K3UX+zDtS9fIXwvHnOWGOvi/N6xCDf4YKBpqjXQ1Bn7F1krxYnnL6lEZdcNEvyaKnoQVKoJjxD9tJwG7I/V6PmQSl/dhvHc1qyGPqd2Jat3bEvydExCIkHu1oRrvYWzBk1Kni6TS+ZqUz15COW6Z4HHt1pFaM0APUxOrV4pL7lBwsTv3DwPUpJgTOhhS5wfSJUbbMIgXDJu8ZHsjDJpMa4wAgJoo6s0GJsU4Vu3Y9WR4LzwKNf6fVE5nWg6FZQAsTlXbBg== 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)(396003)(346002)(366004)(376002)(39860400002)(136003)(316002)(966005)(16526019)(186003)(110136005)(16576012)(45080400002)(8936002)(66946007)(86362001)(66556008)(31696002)(478600001)(5660300002)(36756003)(66476007)(6486002)(8676002)(83380400001)(2616005)(54906003)(4326008)(956004)(2906002)(19627235002)(31686004)(26005)(52116002)(53546011)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kF2/LQUCUwkWuR+cwNThEqz+raPofh67sIXlM6QaYN4MsKQoVtCg9LA+NGnltYL8N/mlbUF1YCt4irqqeB4WjdjaXNT4FbfK/NrNm0LdosPlPMRH/lv9vJdsq3inl4kXIXc3bdAWIZAo4VRR26L1Lkek7GgK6MCYd7AZuGCEtP9cWS7qScKjDCgLzuG7qo9M67CbiP6u1y0QdUFK+XB1ulJPvDTV+WvacYdZ+s1UOAByEWNAeDFQcXj2aOICsHlUxAyrIF+z32Cp7yxVp/BC/qOs0CN6T3S53hh8LB2oM3WCthU7p+x8fG8FotTL/IaY4e5NQLoGN+r7Z6HRMakp3CKLpZPJgNd4pLHZCWYGizyN8V1Bq3Vfubg5V4zdmXGIlXV7BqrguPFWa4WF+TShLUb+ARMlu744cHuWaYtj1szc/6I5OuZDm6LL2mcUunxHMYsZlVcL2aoPnXykYXzSUo9k4eYcL4/2sZIP/cyDIVBln6Uj+NfKfTid3dtGdXL5AvgKku5h5qkKAh0hf/0EHPbxVziES56x8MIEN+fkIYzjxTipGaNjepsuHzJLrCz8He7kSB8wRsfZKx5mE4d378CppxahxdCVzEKcXf1qhP9YX2JZnn+17iYY3jFxrVKPQEmK6lTAZ61KcG3uIhTAtg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e212580-ab77-4359-51bf-08d83d615d27 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2020 19:12:45.9034 (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: wOQhIlXXOd3nSYYxllHflY7kUV7jzB7maTD6gFpw3ha4UMD52ba3WS1QXL2rCuiHZzsq7wyqpv5UVM/+0c3mqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB2504 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 8/10/20 1:47 PM, Laszlo Ersek wrote: > Hi Tom, Hi Laszlo, > > On 08/07/20 21:38, Lendacky, Thomas wrote: >> 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%7C243b5723f67c4fe89ed008d83d5dd5db%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637326820522631996&sdata=vyh1QG9W%2Fi%2FOHrjG6oiOySzF6B5%2BTi76pZ2UYAH5e3M%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. >> >> 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 Yup, sorry about that, I missed it. Thanks, Tom > > from: > > https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F63568&data=02%7C01%7Cthomas.lendacky%40amd.com%7C243b5723f67c4fe89ed008d83d5dd5db%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637326820522631996&sdata=jWS0M5i780Nt53YX6CjEdIxP51CNhYhEo3qReHJUQvw%3D&reserved=0 > https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmid.mail-archive.com%2F98ff9331-c73b-07f9-de49-f08365c6e003%40redhat.com&data=02%7C01%7Cthomas.lendacky%40amd.com%7C243b5723f67c4fe89ed008d83d5dd5db%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637326820522631996&sdata=ZZHmJPS9MNeEqI08WDDgPwnwsi8TPV7JjyPgziseYm4%3D&reserved=0 > > 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 >> + >> >