From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.72]) by mx.groups.io with SMTP id smtpd.web10.489.1587577361104001899 for ; Wed, 22 Apr 2020 10:42:41 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=gwCjU1Dp; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.72, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RAp4W0pVhHpxr+/hKqGyaX3WXG3lgK9ZfKazb1DdEwkUwiHlbKUehpDLvRXpZU2v3zCxH5whibpt2LOG2G4maR+KL+D19p/0/VxfXSGQ/tREUzzCgI6cAhAA9Ay8b8PZKOS1VLSguUx+K3aPgrrAU39uObTIx6X+dmVKvjEj2WlddGkS/rZUpYcLZBP2zXDO4fi9hRFjqB4lNvL2LLoIhnvgDLPddrf47NED+wcuVKdx3LrmVOfEBZVxagPZZpr5MLLb+Z2bubWaXQb3RAmyfS4dPZU5J3l5ywLFIl5AAhAdXK79rn1LOxnMzPJRVHXcRD6gQZM4i6KqfUSvFEfa2g== 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=OpRmOkzMEIiqZsjjBq0GjIE6D6oZGCd2skTSe1vVZwA=; b=kjDPzoP/fpkrgDvcLy710inxmQoxLAfutCWknawUEdtv4C63+GXRqn1mnVTOU5KAxuz7wSQmJO0hj6Dsw6RCWSWPJZVTJBhcBrTDw0oC7AAlxi9WQuwD+OGyCfVYEFxd5YUHSPVxW9fPW7dS0wjvZ7T2nVoYYVsfpkAgbQLWXXjxEChDtVW54q7W81D9ohO0ZXtUE/pGjOQdrF9XMSm/SjfV2h2VXYJ+DkvycpFasVyIb2TefU+UxW6SjQO1EqV8MiXZlcLSmEWM9hfd9oxZ7mvdxWeeM4Uh3LvV/TtJKjt3QhdXWDAQxCCpz2CsqHOsGnUfVjZXbK+JAZNaxRjzNA== 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=OpRmOkzMEIiqZsjjBq0GjIE6D6oZGCd2skTSe1vVZwA=; b=gwCjU1DpmhVv/iuC8I7HwaU4O2WddYKi1LNYhgU4/3ZHXe7UrEcwMACmWvD0b9QEVBPOmKvCWtCv9lGSH8tM/Rz8ys6rGsk695Qe6xTVIR9Vat5MwAhfQFk27orQY++VbD0/8lzhRnr3eN0708FYJnh57nmpb5Pqr/ru66vsVW8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB3449.namprd12.prod.outlook.com (2603:10b6:5:3b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.25; Wed, 22 Apr 2020 17:42:39 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 17:42:39 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [PATCH v7 22/43] UefiCpuPkg/CpuExceptionHandler: Add support for RDTSCP NAE events Date: Wed, 22 Apr 2020 12:41:37 -0500 Message-Id: <994603f9886f3d9588cc812ea687cd9f19dd11cf.1587577317.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Wed, 22 Apr 2020 17:42:38 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6c1786f7-2839-43ff-fe55-08d7e6e48cf9 X-MS-TrafficTypeDiagnostic: DM6PR12MB3449:|DM6PR12MB3449: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 03818C953D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3163.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(136003)(346002)(376002)(39860400002)(366004)(396003)(66556008)(16526019)(66476007)(186003)(5660300002)(4326008)(86362001)(54906003)(8936002)(81156014)(966005)(6486002)(66946007)(316002)(19627235002)(52116002)(7696005)(956004)(36756003)(6916009)(2906002)(2616005)(8676002)(478600001)(26005)(136400200001);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BaaXPJ6xe/AZ8KfY6N7qYkJVcWAf622UC0TLnfCBgAyiZLToKdM8mOnbn/WgDjd9pN9pFfLImfC0qYN6smIscyZa1JlrkEXyV7imD9altKISb5peZi/B6zbc2GnM20AlXtZe9zUro72WujOUa6SMGI4Aa8XoMZv5XTicNe8AxCATcCpXKMWcf0rQaJwdwbQe9LBad1akfPt8yXT0nz3cIEoDtcficvi+zad0dI1XHVbECmergaBZ1rw2pOouECy/poba5LLgovYBVI6P1ufFyuwYj5w67QEvo0dZTPl2Ac5sAaC1DQjbVroVRcogFJgGqAibyYG2Pe0SE9tX7oY/93R5dPWmZzIl5efoQgPnDwdTpD2yoLLMEoEBSfDHYyacfChqkyY2Ubs89SQX5Q3vAnNjaIVYA8t98mC0ySvmuRH+Ebr3QnrFpfR1/buUlbSDNVkkUKdtSeDrHv4qBVrSaRVwoDD4LeY8/I7cAKbRCvNZA0gs6PFF/CjTxeUJ6l/LDP0TDDI0XsiKTyZzZXWJlgaJFg9Jwj8rAAV9b/4RkPqe1lZwHIpmL8ug5tLTlQYk9X++Rhl3fxJa0hk5L4s0Rg== X-MS-Exchange-AntiSpam-MessageData: h2zwyOp+Ib1xuUnwmCWs9ii8ugRDFFA2s/iHNnno7Nfa2NPwDYdc3K1n+ZXLpt+eUllRC3GDocEkfRET3DLZ2+OvUY0GWdbCcsXKITrkl4y1gGllCSnqVByymzFnuUoCGwoIMmDVjTXNAen7cDM3eA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c1786f7-2839-43ff-fe55-08d7e6e48cf9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:39.0219 (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: tk69DVLFEe8HecvZ44VLxCzZs4ojmYtNBr3cOuqA7IDBw5cJdxSJmEFHpAe9adrczhjcVi5ZJXeo+qFdBsVI9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3449 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/ArchAMDSevVcHandler.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index 4b425696b345..75272c47ba35 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -868,6 +868,49 @@ WbinvdExit ( return 0; } +/** + Handle a RDTSCP event. + + Use the VMGEXIT instruction to handle either a RDTSCP event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @retval Others 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 = VmgExit (Ghcb, SvmExitRdtscp, 0, 0); + if (Status) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax = Ghcb->SaveArea.Rax; + Regs->Rcx = Ghcb->SaveArea.Rcx; + Regs->Rdx = Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a VMMCALL event. @@ -1422,6 +1465,10 @@ DoVcCommon ( NaeExit = VmmCallExit; break; + case SvmExitRdtscp: + NaeExit = RdtscpExit; + break; + case SvmExitWbinvd: NaeExit = WbinvdExit; break; -- 2.17.1