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.59]) by mx.groups.io with SMTP id smtpd.web10.1782.1596134892515974528 for ; Thu, 30 Jul 2020 11:48:12 -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=QfMP2+WK; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.59, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQ6VODxHZz2cGBwhLmxVdLj6EE481UeevgVnjTl7eEHffBJhlX3vLNEjLD0fPpsxgV9gteRRID592mLW4fWeqBjYWD7NTvPeXl5zjbR48XllMjA86pRAp74DFk/qlNxk0ccTPiIcZoQfjYnTi+vCUwQlmnOrxdXRv5OXsKuo3yY0Fi6tZXsvL0Y/At1C73osd6pTOXPAqTLnFsPB1BVjoZHQOH02JF4aRuTdyDWOc5OyuFvke8b5q9vWEd3ViUssec8yiW3nhJ32bkWVkDJf7P4K19QdTLHsM3cp0cp0fBVCTJAJJ61q+c8v+vEXElOcWqsAOArqDfBwf+99/jYBcA== 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=QYzzkFggv+vACgBj8BmEBUrEal/W4kUfXyeGxiks+rNbspUEKiTweB2+y/eiXxeKIncU9iSm5uwxffSdifCYbmoXBiqdmbKbw8KsR04SKydTqNj3Kt0e0KGQ0lfQ9wxfpmruFEJCD3Swmpp8/HXWY0zVf4m2D0wrwsgLCxKiSIRFEj5iciacQNfyncHkjh451FM5+Nkl6owjijSrj21x9PuBKXeY/LHJmPnJjS+/awkEjMBFHDWi834/AXPrT8zMgRcvoj6TefShcHiJvjkB2iNEXVGaQe9nmLm1s9ibQOrU0fj6tyO20e/aHBtkLBseBH8rBHUqyX62L8Q1c4xtPQ== 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=QfMP2+WK0Xq5OIfQJqWJMhGjdIqrVnBb76LX/i9zQhQaUk9Ck71VJZ3L79KmRi9cDCHNToOcg9mncIE4YYB5siMC7RpE/qjoSrXP5YjVNSppGukigjc16bS7eQFuBdrMZ15RXv+eGsQ8FILKJZb/X+IXzLj/Xg5mUQpjjvTjrk8= 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:11 +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.3239.020; Thu, 30 Jul 2020 18:48:11 +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 v13 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Thu, 30 Jul 2020 13:43:37 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0134.namprd07.prod.outlook.com (2603:10b6:3:13e::24) 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 DM5PR07CA0134.namprd07.prod.outlook.com (2603:10b6:3:13e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:48:10 +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: be67158d-3e5d-46fe-b87c-08d834b91bb3 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: MWPqQ3eI/CgbR82nZBJWOS3yechmja9sn7RTjZLBwkVl/ZfprOeNf/yj5llqJhX3PnpdDtDrZ+3keejCFn11I4x2p2N4eBP/vrahXAStjqUHNq08UZulw9Mg/5m6k2g895m2etNAGMrbdtIBwhE4J+9U8z/qvr0R/ZQxGlINcEFMcorgB2dAiiG8FcvoDvc+4aWj1ZAkAYBRL1dh2qRoNtRWLXJhbHfo5eCFuUTZY06ofaNjB1NNDLUjnpWkQ5tkQSjBJmS4wWqXnU26k31awno6qyKOa3eukqrA9CZ5cLXrYa5hMZZFcGyWfPPEV8d3NMkZ/nOAYsiw29i6Log4Vcz1q6NYWWjDjULAmVhzM3olA8LWBgwn+6MjJWyVkgILPx3h4To9DGvOU1W/W/KnO8M1IQyc2KJE0jnZWn/JvITifRAmzzGoMtvmqGqToQHC03Z3/Vq1IyxE4zeG01EU3A== 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)(366004)(346002)(39860400002)(376002)(396003)(136003)(6486002)(52116002)(7696005)(26005)(5660300002)(186003)(16526019)(54906003)(66556008)(4326008)(66476007)(66946007)(316002)(6666004)(86362001)(2906002)(2616005)(6916009)(36756003)(966005)(8676002)(83380400001)(478600001)(956004)(8936002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: M3oeEc1H7NRdWH5cEc0o6xYHKr/NsjbuOdJmUURC3qnm5ceGYAI8MARUtqX3R7MZvYnF2QoklKC+wvgOdfBV3dGsEGY9simcP/uEmza6FOO9xOYhU7LkzKkS0+m9yPPJNaT1fOqf2a82TRl4OXwwGUeou7ovS7DqFESsxuoeLhp+rEZygLfnQDBL6hBF7n6si0HHWHVfJccHrfG24bB5mpy/wKB6MLgA4OX7bPHhU+bBV7SyCXAUjsDE68f3hu8NJNN7LBLBK5VMN7X1SpKHcewDSZPZsN+ZqPy5l3+DBHKwRPtW3lsyDRY7DMKC3zqiB9Aye59q2mJOiU9DPGnis6a+yOc/4EcBUOeIHyfGtMZPN0LX0S9S9Hb/3aTwlRA8IGjauHx3QU8QgVbmQ2VCHiTrTJDhfM8JRTpbhi1gbe9rhpO7bH6S5hd0AgCjv+GCAwiNIqXo+9D7681JtYfAMt284uvUjY8YJsvNB/d8FSkAHiz5SS9q7nT6oJpbRU7xfQysys0UWP71yKQn7l/+GgpAXPqbY44o+11EDfM7cjvpxQWhnpJmCd8g3IGDX9CyCQ3+W0kb23SQOKNcrOioaTsgtp22WBEKDtTxMdatX1fYBBreG7b92egnxicdRGrvdUr9Bdbmjkvg3DCBE1BEFA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: be67158d-3e5d-46fe-b87c-08d834b91bb3 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:11.4411 (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: ooSwikJyb+25o1gACm20m9b/WVI67cdUkdSRycnVMk7vdoMEFa1V2oXvH2IXGngZMMv592Ovg2tRvn7YM5ZeIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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