From nobody Tue Nov 26 00:37:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63861+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63861+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1596829340591629.3048003442894; Fri, 7 Aug 2020 12:42:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6IcCYY1788612x2F1HcX4Wct; Fri, 07 Aug 2020 12:42:20 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.67]) by mx.groups.io with SMTP id smtpd.web12.4233.1596829339556035071 for ; Fri, 07 Aug 2020 12:42:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nod3w68v297Bq1C8HVneuQcLRzyvnkol4sqoV1fj6oiV20eRixBsZ8xGw0Xb1LgkSwnYvzos1miFTntJ1Pbhrb6glkaJSXYMp+PkkxPiJj+jjXGwHkl4KUj48afHp+/c/TSiXFq0wAuIUa3x4qem6fcqcIGMDAZUKc3bADXzXFNq7ggBo2JHpjrWWPEZiJdl5IQCTgXD5OlLV5VLzdfB/TxTpEuKX8dVPewrZ8XMMeNpKnwfE+IOxFmzTfx4dOzRE2+QS3izgVU0Q89cGgMFDMY5UDxgFV+hDZbqSkNyAW4WsZaGobL8vxqM7JVyHm2blp5pmklY9ozI/st+iHA+4A== 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=USgsM8Rl6EpLJ5c3s6M+GM0VgGXdhMjbZpC0I9bDPHiZ0ahlIH3abU2/D+6neC0kAXNe7VupCc5nkNCiz9HR6zqtgPkm5WHAilJoa6n8vVcoB1GK8rxPscB24UdPWseMaBNsnSsyZH8mmMWidLNn6KuzMDt4tCOLDtr6vi2CZL56EghPxNJGfcz4S4B8y/iP7rAq4UyZ/AirIaQ1KR87Eygv6ut3D4upcsMw/8E6LTC0mBsdThQVGYHeE04S6WQASn4JR32OTwx7GKuUujsPHWvHwmgdsRFv9tOBr4psjID0jWRSwHGN6xXrCXcLNci/PnjiZwqQaAynA9zMtNfveg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:17 +0000 X-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:42:17 +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: [edk2-devel] [PATCH v14 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Fri, 7 Aug 2020 14:39:04 -0500 Message-ID: <5f68d178f0e64a8ba3994faff8ef66bc26a3ec58.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0093.namprd06.prod.outlook.com (2603:10b6:3:4::31) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR06CA0093.namprd06.prod.outlook.com (2603:10b6:3:4::31) 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:42:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1ad58a6c-6593-4768-30c7-08d83b09fe12 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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-Message-Info: dshebcWVuV8EANWcSSN6MXNzO0jzT0dPVt7JGUgy4qxtofTjjMUaCbEokHWuVI2rM7qt5pv+K6IiDvekGDs5IsUegwA5YYWFulIDsQJThiHFOnNG7yLu7fYnKbc9RAuuY9Z/ncqX2kzzUE9NdidyeyEqDP+o/+DYHwXCdRmNL0aW86xo3dT3XwwYTzPz0N4u5ZdXhltfPsVNcqrM0XUF3kk1IbQjFoHcbmrsS6cYrUSrijz0wGPhlGMsMjDQSzoU0OJVxVh9AyH/IRKCbjFKNGUUcLsqKcjS48keI7J6QzBctH6Zp8sONDOOELNRPyrYesn7CCVgcGZPsCwQk2VpQTQ7suTOyluRwP2jtiswCABpuUgK9VDfPiDtB0et9URh7JHkoaE6VjIcRSr87xLy6HylaUGmaY8cYHOYzVsgo+h/TpBrMIs8I9UgMYaOwoVqPG1OueTMkPU8/qwYrGl7lw== X-MS-Exchange-AntiSpam-MessageData: QhrZv5k4BZtmXNN0p1LlTU3Ub+w9Wg41hXPckCy0Txg+3WqjDmIgo/3LMdE02aiSBqWKQF46clrik3+VBVirz6OkhxsfkdlXVG1itNPmyX6kfcZ7nNrCl3FVxX8iax7JtdS+Yb5bUEbdG6w04lYqJQXA57AKyjlcr7DBNkFE83Eb2C5Zd2H1k3CFwS0QahXLfiW+7sRAu2UboxkrPPfC18S91C9eo5Jlh8zaErlFnRdmq3Zm77/WLfd5eKESKSX2Ky6ybbDESu30PNuBtm3MYBpgWw2Mg4egljRmWUrKrCUVN77KwOKqWrTApH9imi61RPlxgqVza+V/wH9s2UVV8GinImrFXvzdaGrtgyFaARSXZhoEfHpCcUN0frdXJ+1W6ibHoRMOvLrvTnPpJQlTKWJfO6APtRhfTGYHEi6wh16DSmiRx0OWhpI9eg4uBN1Dfib6Ol89MPTdzeeP6gEWaMnQLy7UMDQ6t7WKSh0tQlO5MYZ7Z6zYXEtwk0kJTkghj5SXArPFRXKr9Rbpv1a0lTNp0QUBp84UnD7GBZZymJgOLQXvPrktKNn1S0K3aGykYnHLa/LFPrvK9bqFzPirDu4vwGGu0kZo787k9FRoaYQ9vxASiBFz9pI64S9kMTV/GnCqRG+YPL3ofBV3hK3pug== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ad58a6c-6593-4768-30c7-08d83b09fe12 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:42:17.8213 (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: XBui/cpXwwuzceytSJALmyKfmgRk6F1thm5biGz3mz1oDear6/F4xXu03BOe3441LOvCsStMBqC486sAODUcTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: bk4mNbOkVgfmHWAf54Dw7pTUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829340; bh=hea+BIHJ0tIHZ6XrrH69ImZtA14oEm1NN8yqDFooB7Q=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aZwyo9Ww1suzSgQ8WTBj7Rh35BYfdLGz4D5wgzHfTQ0q1eI4zMDq5S68T0PzDJJZWb5 i4xwfOZu4sABZsGeRn+no7ufqXzM0Nxx84lQ4VPgqTD65f7BBdwEv+tfRpfcV/Evov1Ge 9QbLzaH5eqq6+6CKKs3masWGq+QbbBxfgNI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63861): https://edk2.groups.io/g/devel/message/63861 Mute This Topic: https://groups.io/mt/76056526/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-