From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.86]) by mx.groups.io with SMTP id smtpd.web12.964.1589925117656726354 for ; Tue, 19 May 2020 14:51:57 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=RCnlemb1; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.86, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c5O7bEWwHWxY2nYVao8n7HPD0Eac7MelFDl8m4aGZzvfcSAUwir6pwaVBlNNduEPoaYDo0bXiOj1JrR7RCN2qFz8Fbb2TOYF8kF/bSNWUJ31QJDs/Ps11q5GnF7PfMDcF0y5uFM0CdT9I57ltIQ06o3u0rcYTc4MzIiw16vTJY5vSQsHiOzrRF9AXk8iH3542mKpKD2QB8joRA7p87dk93nk8GruNwqpgI28K7WimbP2sNotVxOvW0XATadG+c4hIQW3QrGlRJNhBwhvgiU85RgEEzI6kbsXYo2nLo5hi6/Vxz5eYEgXdq2KuqvPU2ezsVBTmq7VFqGl6lmWvCAqlw== 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=QHD6v5WFOJIeOr34QY6bahHQiQ+TTLhz2DIMF3kxPl4=; b=DI2QzRTbfJAfpgOlF9eyGzflEtcWfy+Gaq+1RxSVs3FCb5JDWRbxCN+nzkpWaJ4YT56vZenxMkSUCP0+R0X/fgRmZifAL8jw6ZGHKS4CXW30cLdMV9Zo9Kpb70SbuYEmbLmX4oTOCIAyPKzpSB9NAj9FWuGR4K9E1LF0o8dBaP7jXhyV4vsZuZyNYDpBE27RIPbJ0Ji48vy6DIKI4qUZl+xmL9M0EHsR9Fu8qK6Egx/gZOEAzV6VVwlHC4fb9YWSzYKsX7lQLp6nW5xR6qmOOGrQ8LwiM5EfIV1ZsV1lzY6q9s22rcsjV8ARn/v74YinAfHXDd25AmOnjF31mle7zA== 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=QHD6v5WFOJIeOr34QY6bahHQiQ+TTLhz2DIMF3kxPl4=; b=RCnlemb1I0uHlPLPfWgXMVyeJqWX5Ed9kXT+zjfpoQUI40XWiz64Ft0Dz71QvW4DadrtZ7gyfILsYAOhR3t5DA48boLdk0RavtJjQExFVGPS7z+dl9KBU7Tt9MlpPA+OjxW+6HWOmq5Dy7vEC4qbHnmE/SlDYCDEQ6dGPWd4TSY= 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:56 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:54 +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 , Ard Biesheuvel Subject: [PATCH v8 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Tue, 19 May 2020 16:50:53 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) 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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:54 +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: a459ad39-19fa-4b1e-6436-08d7fc3ed879 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HKvxjW8IH3yBGhxhshaYIIxbZZgfOJEPdaeIQLd8n8Swz1ZNsWwLBLoP+F4H7akKiPxYpByQKCp2K8dAqzGULPYgEsdw9nP3zGE/p6ATY1MR4NDhPj8rOFJeqb9z61UzN/jGN2PyR7nv74l9fZNBL7DT3iUSSWAeIh3GY7gXPnV5mfHBp+Se8Eb0CnJubAlHisemyCSzswPYU667UQXknjqVXpQorIxj+byZRcf18eG+a4+ydgZxQSslvd5DeIaT8NW5rJJy9Zl3UxuaXlWPljBZ7bX38rnElNb4qmw1+1Y3m+jFPtcUbvkhAinbPMkzNE1+uiWPe1IHHe2ozuUgENWz5Eqmf2aOQs/Era8q6YoQjhVn+IVCW+QNND8a1PMKALZjopCglkmVnMtbFNLdPHg0gK/B1HMD7YgIdQzEs4AOI0nc6pwmlToiR9djUxbM3LNbs3cpCgoBRam3tqeofLqv5A0Yqy5EHvb5DmifNKKtRHyWKHxU2C24cFKP3uITnMUxU04OFRQjJTMteP0bBikUOjRK61KLTzwsr9ZWAXC8/j8Q4vKtDoGZwVo4/u1VnGe1SuIQq6VuijlxsmcbOw== 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)(136003)(346002)(396003)(366004)(316002)(86362001)(2906002)(54906003)(7696005)(52116002)(2616005)(956004)(66946007)(66476007)(19627235002)(66556008)(36756003)(26005)(16526019)(186003)(4326008)(8676002)(5660300002)(966005)(6486002)(8936002)(6916009)(478600001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: dFNgkV77bT7sb5mtUQbH+lH5ta4qKItJYAQ5b+PbeTV+INSGeqPogQ6jsogFEVRVqVsw42J750CUKCkQBSDFzRjkc5s0IwpSX8Z8qdmVVPxGeLI3x/Y4oBVxVMtX7bu5la+sYHUa1QcYqDW6xbWGU+OGiuZaTDXQ+JYL3XG2zbyvGu2g1bEWZFpiNVxilzm1OyeA3DDZ8ORiewTfV4rgP3hOwcI14Aw1eN8aF3DkQTVMmpt8mLBO5G5o2cVNlTWGVR1ic5aY4MVgFvLfaWD8/JM8Pkfgnn37ZzXdRq20c3soehuxYcCfpzeFz7li2PEmMsswVuRnpiqsBYFui+q9gQQ+ubX40+lqN5VkNIuskklqY7CG8ur2hm3fe7BzXy/kUlDpUnRdKQqgQ4f8IPy8G/DJJCwKcdQAHjMirHwuMfKlDMEnT+bEQU7yhJBkHUTrE/rf87RS9UttK2QfMi5Ef3aOqzt5nPQVPURNN++rmWs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a459ad39-19fa-4b1e-6436-08d7fc3ed879 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:54.8189 (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: nJhtNIQRGC2SRj+Kd6A2PG6HbMcSbSXPO6q6Z1ZfJNxWqOXAcODqS9BO5mEdbwYlyPm/5K8zW4M5fwjHXc+VaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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 Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c index 9b7639069276..b028b20f255a 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -843,6 +843,45 @@ MmioExit ( return Status; } +/** + Handle a MWAIT event. + + Use the VMGEXIT instruction to handle a MWAIT 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 +MwaitExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax = Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx = Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status = VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle a MONITOR event. @@ -1539,6 +1578,10 @@ VmgExitHandleVc ( NaeExit = MonitorExit; break; + case SVM_EXIT_MWAIT: + NaeExit = MwaitExit; + break; + case SVM_EXIT_NPF: NaeExit = MmioExit; break; -- 2.17.1