From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.74]) by mx.groups.io with SMTP id smtpd.web10.5659.1595366540319566580 for ; Tue, 21 Jul 2020 14:22:20 -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=IkBnWh6j; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.74, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GDJftEE2LuWtFrLScXiG+nFoYRgGb9rtb797iEoxfDRd8/lc6uuieLXBscHOOsuv9MZCGwcsf6IApkeopkzezaEumWUxHV8Kb9GFB8doXqOeqsYqRxsLYcahNzxLXhpk0p+K4HjQbCF0DA8w4RgLjq20eUTGbpEIfWm592OjlU5XOGD0NbYF9BlwVu/ZpWqEjAmh0vX8Ko51YxKRbtWfKdf5Xoafl8icgrEDcFu3kAK5VcFk7oZLGQy3MLDZ4BzYvvjMt9DXut/JENqeJRfP+wBfdLM32k2HamVo44LNCVtGGLJLwjvgjV5tmBKnZuCYcL7Zwzbat6z1lRLfTx9WrQ== 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=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=Dv+AfJWJMlSrm88v3uYLmJM7Cl+eIWPpnBITRQzfgkz5enO3lGq16NGdZEqNBJoqOxcFC+VT179NNzgVtl+0nn2Zb7Pa4Hxvfn4ikDnWQ5o0PRMqBBAhMCVyRzEnSq+b8TWo9DvkETc15JzFwDHI/aB3RjHy//k8QUENgYXjXK/KHuqTBnD6I31P6HKUikQ4nM9/38oIiEqIlljyJSw3JWBrMUbAuNYVJIbEh0VOYZ35ZNkAIGg85Dnq9EbsrsMVH+t5Iop+oOI+9MShmaCRiMDWZBk47H8PCAbPyL1ypED49hIV5lHxLmvSEVDBCvQF+pT0W0WntQDXcw62yjNTeA== 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=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=IkBnWh6j6mJocQ0FND0LW4E+vY06MziX/qivwPZYwKtDSnnLSaVmNtaDUlUlPgwyEsnozWcp4vmWEcpZJvSXGU2wJcDUC0qMZS0qss8Nb+DjU9ThBbfPebEYvW/OILtvu3KFFAweeHtYic0ceQDwztu5faDruZnEAloYIOVc3DA= 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 CY4PR12MB1606.namprd12.prod.outlook.com (2603:10b6:910:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Tue, 21 Jul 2020 21:22:18 +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.3216.020; Tue, 21 Jul 2020 21:22:18 +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 v11 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Tue, 21 Jul 2020 16:18:56 -0500 Message-ID: <8e3e7c72918a8523c26ee7ea910715a0b9ab90c4.1595366363.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) 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 SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.16 via Frontend Transport; Tue, 21 Jul 2020 21:22:17 +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: dd5bec2b-9dd5-43db-3c9d-08d82dbc2599 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: 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: zDbczTMWialuIRCvIp7qKlz+soQIEdVmvTszPfNHAC6rkrcX+VPyDkeHpQ51XLQHsg8dYRb4XIbi/xuNhIwtA9aZ0zSOwAJRvoQ8buol/5gfx/+OUrlixB7RZhLxL1QFsesr7HG+4g1q9UBdA6mqxzwYc/W0GxjLSxj96ZCYw8YJ4CumKUhPihBCbur9u+YMHTECbAYKrMxj15+eJZbOCewzxgK8LkVaFiLB3veObynBctO9y86zc5SNjB/NZ9xxIIrZ+GDOqPrZOK4gL+7K62v4lfIGAOdvDT8sMYy8BC+30M/TaVF+DRhJwRIzrE8trrPVnepeFz7EdqRB+oadGCfAzbuEvZDV3W4Fd1dPwIMw+BBVlplg2Na6/gRHch3j1/8JLOUBItZlY1mTUOuVQS3N0IBiM1iURzI9E0waqN/TroEy9xMFetnj39dE0UVY3r+OTRVSLD4Jo2f0Ws1OVg== 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)(136003)(39860400002)(346002)(396003)(366004)(376002)(6916009)(54906003)(2616005)(956004)(316002)(6666004)(26005)(4326008)(186003)(66476007)(36756003)(16526019)(66556008)(66946007)(2906002)(6486002)(8676002)(52116002)(83380400001)(966005)(5660300002)(478600001)(86362001)(8936002)(7696005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UELlJBvRDxSQERBfKplKmv+PP9LK2RrcmkxPZzzlNNmikVSYlj+DA1Wky+VbhtCNrzNKD0QtiPbi8Kd+iNRk3gYAfXUlBPqvJpSOecCcKBwQTMMxymfF/pzm/lr2pN0e1Z2rnXqmKv+15+66zHwnnSEez87a/Va7WNCqAji/QQObpHxwmIOtjnvic7/nuKWJmK26gGKiaKjt1pXUyb9u2189EtonK4HpPLtf8Nyoal/iGHPsCsYJit4FCRehvkckr0X47bH148DmgdviXevUvIgXLj/hFc0A+SgZwxTw5/9SHtKj3V9sCUZulBvPGR9UmrU9gENSD4czplK6aSSSiQjflkngUXEn2ax7ntX6A9bO9rE+ueAZtYSGaO66pp0uVyE3BzEpX8Ii/tdvswVrMD1LcbMhuR5f3MBql/cfrRuwh1K3ke6d3UPW6rZgm610NA+sp6UTs8Z9ZoWi/cBqkM89YatAJg1kN47/VzVV19E= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd5bec2b-9dd5-43db-3c9d-08d82dbc2599 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:22:18.2575 (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: 3vP/Rbh4SVIq6c7crYxsyJFCKB33mPcpi21qzsS0atSn2POevGNj+L6IGpdBpifv0Gusg1W3qYp1SDZGRX7/Qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 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 RDTSC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index bf07f960e380..65af57046063 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,45 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDTSC event. + + Use the VMGEXIT instruction to handle a RDTSC 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 +RdtscExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1265,6 +1304,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_RDTSC: + NaeExit =3D RdtscExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0