From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.67]) by mx.groups.io with SMTP id smtpd.web10.21144.1594737205291627281 for ; Tue, 14 Jul 2020 07:33:25 -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=GOQDAJt8; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.243.67, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tb+3alFcdbZoQCYwc5Xsfxg1iqIQAG5aAgC6p9H2xt88dbfc5hjAEWXuqmRGCq0N43C7ftIRV27H8xqODTMfxI0OHoOSuIxo5HhpXJrVs2sDTBXunPXLXhydZ6YAetcosuVHLGUrn6HNJttT86QTLMgWFZ1lQh0Avs+BzdKGtlz+ea5/Ack2ZoKb+M1MaO/V0pTIzIvP6u6bU3bwhv20r+34uTRKi2JeYDTWYKzomhruGKvhtl6z0u+rmdVU0Dwpf47SiD9/NgSbfKLVyTxGW4bsEhp9Pistnq8MLXHZnzIFIX1qjvlEdDHsgamgBX6Qox8rNDkKSdKJ3aT8TyuaSQ== 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=oBWDxXnHukjvK49bnXDV3N45PuQd+dm2QdQKmnDGEjzdMu424E4MVus/RzovfhIZHsIpPjY9op7ajkEHTTqjdlGpH2RfrhIPIZSiXZPoIkEWQXkaZatIA8tvAo/uWE4+q6dl/UMRd1MRyeXq7yKqODUotlMrLvWCn/nS4eEqgnvN62rCT01u0YUrw8Gmp3ni70IomnKbxGM/D95/xat4ZtNcIqO6stWZ9zsmDAyEPz1MYDJTXL/rBPV/j/mmxE1xiZv068wbtE/dCwsbglv1ZALP08vDPzIPh5nS3rexLApEtBcZaV3AI/msTf6U5Z152HPyBp2YTGLv2gP6dx5ZYQ== 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=GOQDAJt8nV+WEoczbhPo45o2QSl/dEuhJwiO+IY+yIXFS/L3dc1MjEco5I+R682grNtehELljZjnQaV3rj5Ps8sqqpkYaP/EEQtg+S2NTbzWBBuZGTheqlY2EzxPYznhi7MjsW56e+a0LT1YFN/IoBwVaTLvL+m1281ljR3kaGI= 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 DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:33:23 +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.3174.026; Tue, 14 Jul 2020 14:33:23 +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 v10 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Tue, 14 Jul 2020 09:27:54 -0500 Message-ID: <932ba54006096fe3ccd61279fb290fa2c20db3ca.1594736896.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0089.namprd12.prod.outlook.com (2603:10b6:0:57::33) 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 DM3PR12CA0089.namprd12.prod.outlook.com (2603:10b6:0:57::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:33:22 +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: 75c8c924-f384-44ab-e7ff-08d82802dcb6 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: 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: R+xFOlaXvBEg4dUroJEDKkfbxskygL8xQI7q4kat/lNYEnLAyz1wr6gzEzEegTYX9rZsdXuUun8Jt+s1zVFp3k1Eoq7OgbTQKmfbBzJUzJ7hafneJdHxHcoV+RP+56yYUKHMQzLnjHzCk18puKxfQvU/Y/8Eb7zvUh5QtkObF4Su14zNATh3CaQa9bdsGdsC8ygS+Ks8UE3ErDQGdxfyEJUENyaRBDpkZgUToo7MhR4vKunLgkTkFMQxPOwjC8jeRz0q1MmEf1BFE/BOzZ3QiEEF94lkfuzC5KT5b1drgap6LbX/0YAAd/hYGoJ/yPKEjzSeHH3Cx+v4V6TrcNHteCjUbS6fFZmLIfwPtzRoBGBypLXq3gxZQWKlnWpGrmK5UQcp5A2cxej8PNA8IVnFDHHf085yUmT6Wk8qMnaTdBpI7t5Bqxy2uaib2llZdOoLxWnily4YaBzpfd5r01zXug== 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)(39860400002)(136003)(346002)(366004)(376002)(86362001)(478600001)(8676002)(54906003)(6916009)(2906002)(8936002)(956004)(6486002)(2616005)(52116002)(966005)(7696005)(66946007)(4326008)(6666004)(66476007)(186003)(66556008)(16526019)(26005)(83380400001)(5660300002)(316002)(36756003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: SZDBriEvF8SIinw7M2AvQ/j2o90bXOqjAg2PpUvZXaVMWTmVxMF6k3ZbJttNUYdmIFhBj/T6BPFR7n2wwgaHEef1FVb5nfrkV/BwCBGmODi77j456duEP5CNHq2mcvretUiNBzLsZ7K/JExmCK+aATm9WCqyfhsN2A4ccMSO84nLt7Zcu32fU3BrS0DSQfp+SpY0+DhmvlbmiZCDMhBL9q75cRx/8MPXEv/vTEMEpr4vSNST+b9kLz4wBWFTzfYgG5fBT3eFP4KukMoEwahCo5KjYFaT4r2uVX63ddtPUSlMf0QskNINjANgLO+RV/nEHKd/0lw1jKgi/kz+FI1OJIP3ao/+jsWzHfBXNNiQF61+rjkeKzPUwYwgtVlsvRWEhDmbnvu66F6JnJnZJYkS1XQz+SgaKqtNsRIvDm3ZNF7jweTU3qU/PvnkH1nnP/vQ14DaE8xCGkAPs2WYnBF2ecnStgSSFnC2s68rZ+yG0BA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75c8c924-f384-44ab-e7ff-08d82802dcb6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:33:23.3674 (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: vWm4m9xjs1BaTr9yuAxCDb9Jj4/7nLTEdSmYt9kilogT3tFUG3zcoRO6D9S/iolGDzLP3HOrklxmNXfgbu3oIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 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