From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.83]) by mx.groups.io with SMTP id smtpd.web12.5631.1595366589681725703 for ; Tue, 21 Jul 2020 14:23:09 -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=yX6ROc3e; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.83, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=abCF+kJ++xm/EAvsIoqwrcpE5oqE+2pa8Fk8jD6OArifb6vDb5eAJ0N6mEItEe4WW0I0rqaf8WM4V3QZenWs3wVoaB5EEh/VY4AkGcLq3pZ/FEntWwlNoC6oj576WjnLzne7LkaPibZBTLh4JHKV+0wiXcdojHgPzrpn9/VfiCnqQL4341WBkjbU98de/gbUz3MD1dixEZRoph40vGmhvrBXck9NoqfgzEBFXJNIPl9n7xfWgI62V7+BfZTwK4vU1xWBi9IezL0qHQblQSKnvP+AY4VXkfVCw95qoMx3gpFNRjiFTnAXL7l8mfklrQKcHTbq+9A3fSWmgqor7AS2uw== 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=4ovVcxdgW2M+goyz4Wril5Z4GVk0Gp8R9simGO5DPIA=; b=nar6/S4eUE71fYH1Ls6TSCAty+vnU5pcIwhTo/2z+DO5/R2CNXaLrJkIAwIkqz/cBa7Nu9nkLHi7jyZ16ur4auD74BxNTApdYFxlT/lbbnmY8YB9z5ZsN4vJ/5OpLDva3ZD++cvHuxO8AFw6Iex0eMxPHjyIeqatjgpj2FFb3DmTSTj9LobgF09JbkxrmJgJ3E++E4YGjdIZaGEKTGSVXVKth0180mReOCtuRXvNvZZ8Yk0Z8KAPl6JXP2O6lDVk4UQ0OFm1aMi8lCu7JM60LjPalUmdn61QoDlP7RG7z11WuCifgizDyyk5oTn+u9uWKGHW8dSUHYnay0l8KT2geg== 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=4ovVcxdgW2M+goyz4Wril5Z4GVk0Gp8R9simGO5DPIA=; b=yX6ROc3e/GdO3/DJ4StcOyWarU3F976+LCVpwtSicIL8J7tsIXx/6LVWRe1IqPR4O0IxpJ3f2ZI1DBfaJAuv941cYxjwthi29lR7wfX1nIE+zD0m2L6pJGR+ndvTi+6ksiOziz20sfnVl5/NpdksWajgRcQU+BV+IXYXzDKcgJA= 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 CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:08 +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.3216.020; Tue, 21 Jul 2020 21:23:08 +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 v11 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Tue, 21 Jul 2020 16:19:02 -0500 Message-ID: <2c2a5fda09bfa253fd06d24afd29d1f46fc4eece.1595366363.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0056.namprd02.prod.outlook.com (2603:10b6:5:177::33) 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 DM6PR02CA0056.namprd02.prod.outlook.com (2603:10b6:5:177::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:23:07 +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: 5d733700-ba5e-47f0-eda0-08d82dbc436e X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KF9NI497Qj7fpgonfpQ1+ngNLFOwDb9/8irYqsbkcybf0vRda51V1EXuxKYhsVxlKopWGa3UzzgWlJglkebGRjW2nfLJ2JK0zuO9f9djmZC5yMaxQbSZbtRGkOEVbnNBeHx//I9sjWlPDb6fEX1A5vgThrJiN94wUBlQATsiaLYe8ghXKpyB0uEz1Ecy4MWRKezd6dTLtlwwJer3TcoDIqjtOjZIeafyWyUSZo1HuM3bUfQCgQ2clnix+LLWpiITuG8VxV0OyWStGhkVtLJIKo5W2qGSpx200WlXB6X7+eRHR42eWLVTeZx7/JuCksyJoovT6TznktC7o7EdLvFRJZ3cIh1P1Yq4daERwPiQ7CnRDDHZxeIJW/tsWaOyJty4RCXd6Sa37LUO/LHUIjUGStS5nw2ygumMHajmDiH6e06Vd8Hc4IZGM/8mIzr6ANLiuEgFLs9UmAQKeJSIrDBWDA== 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)(396003)(346002)(136003)(39860400002)(376002)(366004)(966005)(6916009)(26005)(6486002)(86362001)(8936002)(2906002)(66946007)(36756003)(8676002)(16526019)(186003)(2616005)(956004)(54906003)(478600001)(4326008)(66556008)(66476007)(7696005)(6666004)(52116002)(5660300002)(83380400001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: RqjghWQo4Z7AGl/1Ostm1ApTQrA2qhO/Sg0/zdZXwimfilc35U3eZti1QWVX9zb/tzKa8Ak3zhAofZmZ9v1MElpwlnZmz09Wfn3qoHjSIC4bGYmfTfM6tFuR7e8s4aepyy7nn6ylYfG86/da0yoz+88vzmSXtFEbUVTSVZUBao0WkcQ/nRyOdRgeouc9qMDnj/GJWk2Uyj7esjAPj7cAhR2rMzU1tsxAfaDcfrdQ0bIa5X3jGyMJC03QLeQFoZSWm9CRj6MPwC46MN73BFVXTyFxQ1bi5WW7OgXFeMNRrgCiXiuDjPgT7mMOJqgErBNCfCupVyIKO7UxQS0HxJHa+0JU9ZLO4oAyhf842FIjZAYAg1xA8241CN7pZfGE4U0uDMegFoLTG7ZVl+Z8DmLx0ZZgS/HAHsCN5z1qH/6WpKaEHmEVMs0wWz2gNSm+i2jEndX4CYZS4T4YiMmvCQG1+CrSytGg8y8nGv43lsBHMAI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d733700-ba5e-47f0-eda0-08d82dbc436e X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:23:08.3139 (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: yIyu0/4Jk8MYCQno+K1a6+9mDpuK27TVEtbiW5O8Ug5uWfCwr2oX+y1VqiXLAPeNmknOohMpppd/hvS2oCWDxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 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 MWAIT/MWAITX 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 | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index fe08b1e0ff49..e70e0ef82f68 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,38 @@ MmioExit ( return Status; } =20 +/** + Handle a MWAIT event. + + Use the VMGEXIT instruction to handle a MWAIT 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 +MwaitExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0); +} + /** Handle a MONITOR event. =20 @@ -1532,6 +1564,10 @@ VmgExitHandleVc ( NaeExit =3D MonitorExit; break; =20 + case SVM_EXIT_MWAIT: + NaeExit =3D MwaitExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0