From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.70]) by mx.groups.io with SMTP id smtpd.web10.1777.1596134874086125247 for ; Thu, 30 Jul 2020 11:47:54 -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=O4BhgCYp; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.70, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MFQtsa6/JvVwSBaAByaOldr0YDwh+cTzahYn+RlZKCb9+q7R1/EoG6MeUIrSZcoTAw0aY63HCdVN7qgqbVMqc2CiR8PUr0DYXCCiA5LpDoxrL9Qx13w/UgpIhx79iNA7wkFLTbrmxNfxI/YxoSlz+dFYA95QK1tSECWmo7nI6DDb2vjpHYYaMq8RzHEjmMJ0/9yviTubjUwDVc4/tTC5Ha/de/sShdL07ZsVCGLxdT/8hm+teIUzODv3P3VQwCBeCXi5T8FgRBDpxlk4AT6tBm7jF6fQE6GmiuATclGTxvulB2+zbLVGhvQCOtIC6yalZGS2J/DHTZ6krWRA/1Wnuw== 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=5teiAq1eAXmkeZ9hYTs+aZivrTRKKj5B0JXYx2XU70w=; b=jujDfG4zZ8ZcOp/0c8YPYzUG5Brp/RAb+omBvccTsMSf7UhRvkW/K84rNxfRrsKewhOoKWIoalArRAKlv7YmG4B6grbXjJ5UPpLK1U3dgvPlULq7yxCpzu2crPdWu5vopoiigp8Nn3N4VyveK2Z05MyxuqdkK0oh2lgUI6A7iJBVemqPgtJV0VEbvr5VeaNayy4SuACwEpfAhF7vrWFnecNC670jG/GzTcF8Q2Go0f8p2cM+IHoZG/JcjAwHyhJdfnrS2cstxmHLb6WzdDpzRNudb4mBZinceLX3gVCE8eMSi/vXNvepgJCPK5HWK/tZNyDarQ8p8QsgjVoXR06vig== 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=5teiAq1eAXmkeZ9hYTs+aZivrTRKKj5B0JXYx2XU70w=; b=O4BhgCYpPxu2NC2GvlTQtlF1+7t6DVm1fdYh9yLz/BxzQm9X92gbwITJ/QYIlLiu8rzaW56dZuFtJP6lXRoEyVQ9t7jRYwvCm1bA5pfSpeWv/MrYyM9inY2LeF88X8YBgOmVCHJVb/02sEr7vCF/u8lI/8jmAOGWrDlXFC9Nxok= 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 DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47:53 +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.3239.020; Thu, 30 Jul 2020 18:47:53 +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 v13 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Thu, 30 Jul 2020 13:43:35 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM3PR08CA0009.namprd08.prod.outlook.com (2603:10b6:0:52::19) 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 tlendack-t1.amd.com (165.204.77.1) by DM3PR08CA0009.namprd08.prod.outlook.com (2603:10b6:0:52::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:47:51 +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: da3e1979-7b25-4dc7-844f-08d834b910b6 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: LvJzJ6ARDBBKqFfWo0gajSOzPhiytKTyLNMjc7/uqwrVgGGdOPsNaOL+Dcl1NvIM4mpFRiawyXeOl/xfhkHPPuE8P7oUU1xmycBWHnjEAnmVtW+rtqoUISHbUBORCBHI2m8GZCy9vdEu0gpUQL9ESEcX/LPf9V/wEcQq/7C7ESAqeIz3ptQc0+2i4AWlGn02jRZlmVHSf/o3jq9yiZz97H7SbrZJoY1DLzzSmrwYB7hlcHTpIC9FBtXuTgeCPnlVjszBPSE1JBB3jOogIau8yTb9qlz0golHxDA48JQkf0fX3HfQJj6QVrUwwDZtntDIZ3cPfgQoDLKd4MpwbfmVVJVPCeplShMwg6E1jYMtYPQBJTx+qELd0DtyIMED/1LNeEVB03fU7bUUyEMx9y3/0ag0i8aNccqIb5Vfm9VVUwhc/Y6Ec3MiOemEcE8vOeF3eVU4T41cGovLqfr8e9hMDQ== 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)(366004)(346002)(39860400002)(376002)(396003)(136003)(6486002)(52116002)(7696005)(26005)(5660300002)(186003)(16526019)(54906003)(66556008)(4326008)(66476007)(66946007)(316002)(6666004)(86362001)(2906002)(2616005)(6916009)(36756003)(966005)(8676002)(83380400001)(478600001)(956004)(8936002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: q8/PP3Zb0qv6s02QwhO+MKKluVD0nMG9holMSe15PphjzuH8q/iQu2NxbV0/kM6JA8DXHRsep76UmTbQgsMTs9kfC07Y/bTZXUEF9gZqUVmEmOXBu4Y7I633u8vt6bHNsxwJw9oclq9Cb3r6A06b7ZVLBxJmrSH7bMl4Oza3YkoX26GBnCY+rl+UtrMipUiJ/IF5av2n+HDdGVZtvR2msjmpEYn0RSIny7b986QarmroD4xGRe//sN8SgF8Vv/86TmqeJlouzWWQV8HmFJfARhcziNNZn5nOYHxwxK8U82IA6ID0JhhVEP8m5omq0itWdjyvMYOzWUgnY9RdYaSbCcvPlg3+5fkKVNtuCPwsKlJildwNz0D1KxKlInjQxGdcFn1T2mG+w3FrdLma1g6nnRZ11xLb+ZOTuO7k+h/4EuOkCd+7BlOh3rSc/RLzGjrP3qW22qa/DZ6eSjPuGk5N6VrZA84LrtBY8KOwctMqZq73GR1adOOZCXlEIVBU8aVRitxZrY6VhGY+NG8onj09qJqfI2itPlurqmaSx//KxJol9imrwjHTaumzi+WEKHyQLAyd+57mFYuZa5bIR+b9r9oITXhRZMNSbUzdvSl1Qqq45RKnGlW23ivlsh8FZ/Z/ySTv7egI1kq0/c6nEcIaMg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: da3e1979-7b25-4dc7-844f-08d834b910b6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:53.0444 (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: Ds4+xtZQ5wCpfZ46aqm0m8mdgCdyVw7g+9YuBQFgWccmON9rPN4N+NEjHk9IBwdMxPsqF0fHRDKRCrbpwTugDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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 RDTSCP 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 | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 54134f37e614..a1cf792d4d0b 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,49 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a RDTSCP event. + + Use the VMGEXIT instruction to handle a RDTSCP 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 +RdtscpExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a VMMCALL event. =20 @@ -1443,6 +1486,10 @@ VmgExitHandleVc ( NaeExit =3D VmmCallExit; break; =20 + case SVM_EXIT_RDTSCP: + NaeExit =3D RdtscpExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0