From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.87]) by mx.groups.io with SMTP id smtpd.web12.58120.1595863782880763815 for ; Mon, 27 Jul 2020 08:29:43 -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=TiILaXyg; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.70.87, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hhfCU8H0tzFtUHOc5jpU5/bIpTr3fI15BcardzYEYGquYBd26wM/XiNqbTQ4WIC7kcpmH3aarDlTGuJqDks0LgYJG/l7r0LDLHeHI/XG/tBLty0x91Idr8AL7CavbT6/ToIA+GBQB61lj8eY/MRP7i9rozh7OQ4E/I3Zt/fwpWlYjLqcwUER81ZhFCHTabXiwWVEHxRb+YTvxITDNAPDSulyk8JdTRekeEyJu2iDZN+TDD8ij818s8uvspwaE8RlhhBtTjnwMtdlMCC4IwnlwkfLDXb+hIbBAVqLgGCMw+HTmnIZvKPqE/UAwiFPn79puUAg/t0q8Gg2GEX95qK9Og== 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=iMxoM2Mlx4VVnsZXKAGeHPUTZwLjhFYXBCULbr0HR3eqmfPlpU0XvuaUv65dCHqH1vuwd6YZBr5wPjbb7ZRK48NulFE97BhZu3UlHYVf/KW+f03n71STwMbD7gGVrAG/R2hPxV3xxoLRlLMUFcnraMhbs3ZU522oGKzLAs2egFtXOmOrk8B6LSRUu0x3PhUE4dwoYyXbxI9ISlq5LLjI9x5RiHZUDo3PKArSFVNr+9/o9I9hGO05Pp+dLFBCnWQjE71cP6BPqrEng+NzA96WbOjnz25E6lSpp3kDL+6OgU0DdlKJSOJ42tNWhPNuVnnen+mQDVkJtHre4pM4ETouiQ== 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=TiILaXygct0ZQuMbdjd8FuUlfFj4BD6yEUCKxxcvzIV8W8Xan8sdj9a6i2fQKJND5IDZNMhc2idu5mlS4jI4kULzSxPQlTAdyk//YQmBquA9iXf1BmV0DWZVaHtrJ3YHMkkSc6Q9b7Fj9w43BV+Fjupn9tPRKQ8oOi2rQmm3gjI= 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:41 +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.3216.031; Mon, 27 Jul 2020 15:29:41 +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 v12 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Mon, 27 Jul 2020 10:26:04 -0500 Message-ID: <56bc2205b02c7d430415547c995d440f75274c6d.1595863587.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0062.namprd07.prod.outlook.com (2603:10b6:4:ad::27) 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 DM5PR07CA0062.namprd07.prod.outlook.com (2603:10b6:4:ad::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:29:40 +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: 7bc11c7a-ed99-4822-86be-08d83241e1a4 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: /Gz/Vnjaywy8tNLNaKSMLqH+ES+fuqNRBxBiMNv8aBFGymjrSUIXKHan8GyXjIT9dYEIZuf3Sh3JF5XjxPfLK0Q4OmGc9fFGnSmOasN4wCSILcgj0gXtUiLX3VmAi9XDxNJKCa1ovzMWKzTWR49xhzQEzT7y8cN/OTidung4MmbKVa9L1UqjtUT4wt0BXU5MtkRFZZSLzaR7uE/4l/APZG26vGHWaFSP42l/e+GVWTSRWbqGkHba/IkFqcRHkKfZBhsJhfoL3cAQ7cZG1EHvLWoz6AXDXn84qYTmBGvXsZPBEOdgrww2vZUfwK6lY5YIykHVL/641eqgG8AHfyZExWztsHSECxT/BXh/VDu9iVNPfGVypQ8Pqqbl2w7c0WI/zaQsVn/PV5GGeSvwxIsjaZ/zpXzPHAsrXg53F2Za2u9iqxzAATXEXMV40eg/rvKXxm2sofTZRkURd8OpwZJ0yA== 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)(376002)(39860400002)(346002)(396003)(136003)(366004)(26005)(7696005)(16526019)(52116002)(186003)(66946007)(2616005)(66556008)(316002)(36756003)(956004)(966005)(5660300002)(66476007)(54906003)(6666004)(478600001)(2906002)(4326008)(6486002)(8676002)(8936002)(6916009)(83380400001)(86362001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: /zap2+yLJ6oki8FBCoqoTN4Q6sUQ7y/ufPJaoaacHd72o+Re7CFW9zjgfCaC/JQxhDBR8Y2nJBe9g/E2uRcOFUWDiYRk5HIIplIPwwpQxXVGbUlZ3tZgMwZZLRjU80/0kbBJz9hcJTr9xGP/78+i3JNkhLRM8Wy2+9pj100qGqGiKbko62qv/ARuDpzVDS51nWCcylbnai+g82xEbJNsYHEmnIb8cGsfjE665aXDlNw1ChNDPsk6JCCrOkmp+GBJqxc4q9QVJkRNVi6hJNU/BZYU93uHR0symSYg47whVDnG92xAnq0upKcy9iOQKMizoPKvwc1YUH42N85iIv+cIZNRRjCt0RgiVd+QzTKZnzB7oaSWLnbbvBZNgP9nm3sE2BhhU60pw9e4Q7H2Erhcb83p4HEXC92b6OWc+sDDivLoUazZyO+Tl7AWCSIBR8H8+jxXfPlOSnAcHc95aC6sSGL0jasYZD3aMtu80cdAN10= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7bc11c7a-ed99-4822-86be-08d83241e1a4 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:41.4303 (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: R1HJsBbo3hr46i7WbG3L6UNLhWb5bKQZP0CsaET+0smApERnyoz58Mj8Hu7abcLd8+8j13C/j1+7GlI7ukUxCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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