From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.81]) by mx.groups.io with SMTP id smtpd.web10.4170.1596829307059575760 for ; Fri, 07 Aug 2020 12:41:47 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=Qr71TuPQ; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.81, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CtO7iLX05wQrqTbUpDokHMv3NUupCCDirXAQ7b94NVmvDjb0TA5+Jv/3QP5FJ7ktccsqhcW7sPLseq7CnmdnGnUkib/RvdGKdZld7h/BzJ1MXYA6OfBminAEzmbtW9HSmvQEmaqM6sV2g21baJ4e6Q1IDLqtFyu8UvfPkmUtT21ioepQVGDUbOGpdA+d2tcdguvjRQiP5+cfoT3znQFd6ONsD65UkA52pT4PHPEFtOyknWNQjX05s3ymBuBOp8KvBvqRi7w6MvfuV6NrT31AvtalXx4fFB1/C/C8ap6ZyRgZCo4x4IS/uyv4MqLDQSLfVuW7skzNWrP3aUVFIb2OrA== 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=DefcxGXcet0YpbciDB6cqSIPAFoRtyFhEUPqxpHT3rE=; b=ABJGFkRUVLXxL03MmCySH10bNOqTiDUC5ZnLoaYN1obNSWsdctxuuWVBa7O7+IZaM3QCO3zqlHnbosSSqUlI10PzfetFTdb2gnKWiwLDxohlx3CvUnhfGB7GWrqPABICGHG1FKhe3il1TzZSCOZXRv2lBxrOVJFMCwoGKXfxfNT12TKUIup9CiUaaYWG1Z4lzURiJXKiDG7CtBiP4HJmjPfL7Wj8FfR5HtPCaOv/FGzFh20WVaDIIVBEEijR6d2+gt3AGYlLnWRWOIWBGunxg5qEokQx+mgCL2r0PMB5pP8CiDXZ2Zx8DEZHXpudbRWKIWK2tmMHJ7k+EkfJ8Xsncw== 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=DefcxGXcet0YpbciDB6cqSIPAFoRtyFhEUPqxpHT3rE=; b=Qr71TuPQXkmrsYz02bgnO84hfmrKWBDB5wsXVZ/zrya3SgHac/3nMucVusQ9FIzbxU+N2WzrUlf66HXRu0MlGjSGhGzX1QGiUgyHv9Yx5hJ855AFeHre/XbmZrmVrWU2tAFjIyEYnQe0bU/gmCHj+tzNODymtMwAB6FAZuj77xQ= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:45 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41:45 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [PATCH v14 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Fri, 7 Aug 2020 14:39:00 -0500 Message-ID: <4a070fe4b5ca06e27465881d2e8697781f57779a.1596829170.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR12CA0016.namprd12.prod.outlook.com (2603:10b6:4:1::26) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR12CA0016.namprd12.prod.outlook.com (2603:10b6:4:1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:41:44 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c593cf8e-251d-46c1-7214-08d83b09eac0 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jv4ZlXyY6wWsV2V+cBVefhN0Dw+XWQ7iABXj0nXcY2Ke5OyA+GmyTvQgRkSfhJElw5P7NCHFinb3GYWyEfExfH8gK3rcvZwwutSO/+rZxMwhRbdXcOPj/2gwIoLeaRZHararAqVAa3X6+FGnN0ZDakHL9M8M5dL+kF57/bUJqkIjlxuEG2Qe9jxsk/1bC4zXg4FbAK3nLbJvBYAo9dhrx+K6YOrXUUtp+r+YB1PBPENCEnR/27jNfZjyCU5iZPzGcS7wwg74KJv8UTty+wIJkutaDxlpWhlZRKigDn6/Xw3v1YihuYhG6EUIy0Mmwn7D11S6MMomlDHx+HgPY1yURnToKNPBjjUzCU6ZSKu/9gqQRmyw7zIdH0Udj19iCkNi0Fv3rgxFzjy4tWbNIeotmaZBTTcJpwK5FjfBhIOJWMoUe21OTCQnWdtP8aTMfxbQytlCKqVMV8jlGycpdGr+aQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(136003)(39860400002)(346002)(366004)(376002)(52116002)(7696005)(6486002)(8676002)(83380400001)(186003)(2616005)(16526019)(26005)(36756003)(2906002)(8936002)(956004)(6916009)(4326008)(86362001)(6666004)(54906003)(478600001)(5660300002)(316002)(966005)(66556008)(66476007)(66946007)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: G+Iz2tkqKp5sRUEhHp6thnc/uBX3W524OylyuSWiHdCm1TzK7LhvYNT0dQcbHrfmCFys9VcQ5cIyt56VSBsatW+sxWG5oF4CAf/lOTL7/VrfaoUPXRokdOf7/THFVc2kuF13lumIzHKkoGc8CEVwCWBT7nyCc+vHz9KVpl/xyqAprZQUxhpJB0iYv2nPs4PwVBt3MQnre9TgxMCVoa/XfHtclRUF1ltAC6OPUponII6g2VmR/NQAEDwuSPH8QrLLjnXwIDs52kI7gW1ztSjnoP00BlEXMQn+btWtlhDZ0llQtZrAmqpgT2oVmkqbr8e2qTbUt/oMBaHD4H3752IYsAhM3MP7nf7gHhbVKvkfTf2pkZyY0fsKiDVQl/cevhhYFrbPhJqJ/xjj+Qh4QNCeSkq4aUvUhcEuHn7AN40kPj8ywS1ZaTvD3T4KMyan/S8Ln00zvcwP1cH8Bat38AStou300RarXsAqWxqMKMDHKi+fKWUIGxnK9FXgtHc9imuOsE2ENLWvFwvDuleq8htKBiUywV9pWzBJuk40Jk/eW8mNEkK2+0tPaqLjbzB9pxg6BH2JQiNey2lFEhK3vXnAYe1dCQJSPeb3cySZuZU7dBa4dIl2SgmsRC7EfvDkdUrld3R6LMuY1MT0X5OknFizYA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c593cf8e-251d-46c1-7214-08d83b09eac0 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:45.4159 (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: fB4z+3kzjDcoWKBeuzRziIOatkMo9TPubMENbz1qSGW9Tvu1EUzYcchjqXCu32CpzwO9na8iDVEhU0/AUwvhwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a CPUID NAE event. Additionally, CPUID 0x0000_000d (CPUID_EXTENDED_STATE) requires XCR0 to be supplied in the GHCB, so add support to issue the XGETBV instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6ac3552894f..1c9c272a250e 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 // @@ -597,6 +598,61 @@ IoioExit ( return 0; } =20 +/** + Handle a CPUID event. + + Use the VMGEXIT instruction to handle a CPUID event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +CpuidExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + if (Regs->Rax =3D=3D CPUID_EXTENDED_STATE) { + IA32_CR4 Cr4; + + Cr4.UintN =3D AsmReadCr4 (); + Ghcb->SaveArea.XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; + GhcbSetRegValid (Ghcb, GhcbXCr0); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRbx) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rbx =3D Ghcb->SaveArea.Rbx; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -641,6 +697,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_CPUID: + NaeExit =3D CpuidExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0