From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.50]) by mx.groups.io with SMTP id smtpd.web10.4194.1596829372180631883 for ; Fri, 07 Aug 2020 12:42:52 -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=qNnWlaea; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.50, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JccK+nYeiCqaFVldn4CN9Q2LqJx99LmCGhycaALbXcFv5/Yz04M4rg/8b6d6y3iSd72cN0GAO+2ufMx5ZF0VBUoeFKhtvUZhZFcbMUIUrXVmE0P3nKdha2meYj/BWugmXgYPKZwcIz27DMRicdokOuoNdqC/Wy2adHp90d3XrYTpfKcBIn9Zp+aOddrq677By4wmy/fi0zgozvA8QkbUC2tC70GOOuq1MrZgix++CjzOkUncdaa3ySPIWiktcOFyOlPSb06aJtmgALGqySlloRVKD99f1jVu/UJlQpGMxeP31zh6i9P8K9vR+jSEk/kAuqgfNPeNTpAg2imDJqDqkg== 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=i+t8AY+Re+wJWa/YnL+z/9j9Bz8K+I8mCXonB/snldtjzCm4YMXhBzXslyW/h4AtEhGzK1hCrN7o/YMTXmt/Tq5Gpf9cLM2+OHGTf6yyUIFQjsHnJYoRrOIZCRJJOcNPgONjWQkF/Ve1Fs5K1aMAsb4PRq+EKjiFZkqA7JAIJzwtHKEtW72OGtQvmzem9MJ2B9Olf6jWmnTBprDDcrImTZa/ki9L9RSRAxpCFX0Q0Cx+JiCkYtTS3XBp+UC+t3j0q8Szax0UDI6Ke9ocavDWrPOg+YUvl3JkbUgAiHCtIfj9wr35u4Fl2lHudGNlGPUEayxjCXWnA2+zJ8e+sjd2ig== 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=qNnWlaeaQzzIOSy6xfd44HMn33bsEkOcUqjZAqt75kW75IWMngIw4QA/lYnsQ3ne3aPYLJLbWNnc8nnoeb+3c+BG7Fu7xSpckGgBhI/BNeq+1qn/MgStQjBPmdh5j9sX6i8iB1WnO/y6r7luOzPWXMFOeAX7RZRlq3KmtfDmOvw= 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 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:50 +0000 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:50 +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 v14 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Fri, 7 Aug 2020 14:39:08 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0078.namprd05.prod.outlook.com (2603:10b6:803:22::16) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) 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 SN4PR0501CA0078.namprd05.prod.outlook.com (2603:10b6:803:22::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 19:42:49 +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: 5122e948-868a-4969-f991-08d83b0a119c 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: BCL:0; X-Microsoft-Antispam-Message-Info: yCGvLVQ2/p3Dvhy38OaymzOJwrblJNOI7EpE587UOolYE0AsY/FNhrIYEGaYG9/OFNm/lbcrG/lFJz1O/QWnRGCw5NYGAodJtsTCyTRrmXDeejRfLUusWWpniBJV4vK77jZaqHHRguYMuLuaH/RESKr6CkNNc7Faq0qucnI6ZhVi5Fm3OqV/8hA7nIM2AipMvdjmUSjARDy28N8uVl7JUAbDIE/lXNXcuDzFRxkdt3jzCZbRQGVYqgWv2ktCPAWjaymCZMM2NJSrTynjipjunvVnCmhudefPoQ6/ZRhkjrIpjryxk3uI2hz0M/SsKMFXglz4WiDWEXnBuC9OxAQaPGx75/1ro6zBr5begsyYN9YbQJQGGucQDuqqS7jx8GzkCsCqXXJt7jGtVaxwgnn8Jht9sPJNo9cg4OsVsP1ute2TFGjrahmiAj+CMOtLmqMSCmehOD2BZLPude1eQMG+gw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(136003)(366004)(39860400002)(346002)(396003)(4326008)(66946007)(6486002)(2906002)(66556008)(66476007)(5660300002)(966005)(478600001)(8676002)(7696005)(26005)(8936002)(16526019)(186003)(86362001)(956004)(6916009)(36756003)(2616005)(6666004)(52116002)(316002)(54906003)(83380400001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hGId623kne3dtIqzPqAPT3EYqs/3H743sXvCwkZtzw9uHD38goQLlw00ri5nmQ9AW2kwup43mH8MXb0KOeICfTf5TbkCXxj4Ogv5TDn5O50aw1qwtWmNgjFXz0lcnJeOVNWGvYxvpaDaLxCLh9bNR+jXm9jGbmFknl+m5npKJIan9gqXynh1drYcOhaclpFl3imoIVEsYbL2LlKT4XxWar8W28svWverUiGVqhX1eBFw4X0vRMK22X8MyJStUWanptSaaX72beRfIM3SThYCMwQT/TDOy1V5RDH8ZZyrfYHanH+UJuhc7KE7voX4n2xcxUcThAye94bAZvcKT9ZC2BsvDP5TrXyGzMME+nxqSiGIJids83KFpcMBQ/HJpa5GIhw9EwngASPoNSecjt60BmgI9FtQ482Zwe1HF4f2+wG1a0fUNDoJCIShL7it3+cf9si+ovi2FESaJ3m/xYsHm8aWLl3xp7wQi6OsIwokR4uVp/Tjvvi9wm/3uo51MmvbD2UVv7TW4KONDPgsi4P7McfvkXvvYiEwIxiaiylrVjXDx7k4I2fxf8uI8QbxAZYjcLkyV21dwvUZliiBU70BaQXT1prM1MltZn1UvoeXpa27tOtJb2a8s8rM5XbDuVjBZQU6wsTMzxDweA3tt6DW8A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5122e948-868a-4969-f991-08d83b0a119c 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:50.5836 (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: QEIBxRFQeda2iHgF7XVP1ZjyygvuhUvTAnwIT+GgAakImcJCTfsIGIcHqb6JI2Z/CxVsouOt0V3LMRdJCFjFew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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