From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.57]) by mx.groups.io with SMTP id smtpd.web10.1780.1596134884222643306 for ; Thu, 30 Jul 2020 11:48:04 -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=ZTZBnCYR; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.68.57, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LEi4vquajWRersJP8OPKyIZqhzR63tni81npLJ8GdrxOjF8BPo5AqshqFSBw7kPLBmsyg+5fA2y5mh9SSUXR9bQJpqh2oUweb62oWjksWJ/cutmaY9ctqI5Wp9rkAWxQzrcM3z7yO7lIsIWHaFgJdbClVFDBKdVDU8yZ45o36IMcEyg5kkdpKbzSNjdbj7gZcy1xRjUmrzhz/11w/ftXN+PzvEYXN6y7IoHvUVURKpXpG+Ztw3euwsC7iEDFSmg8s3pS08dHOIbplTiFG72Fe6JYmMcIHRIB4jUMwqCS+7mzHW46ah73y0bE2J6/0ddfy5W1+reJ6qXLQgkk8R+mXQ== 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=8ngCipJpXdBRXheijMbZLSMbkg66Y4aDLYNKKgZfARY=; b=VemWtiPS+sXY34aKbGFbORKjqaZP/Nx+pPOmTVfxOxwca02dJ7LvoZxQstoPm0PT8lT0hKFy4fYA1TTmhClLfg4KzeJGJrhYPCC+dBNcYc04gtrCXcdDwpdz9oTFzrPX+l0HfWEbGzzMsGHl8x0NotidwbZ0iasChk5UuFpavcRkqBjkJCsjHhB8aqQTmGeGyWJ4UW6+i1JyQQoikjJqFysEV4IOwgkjyFNwBCVsrub8KSmI5Ytg8J331EVcZi3j5ROYtV1FK9RrJDDpSv+3lbBqYUGd5cjVvOTXt45LOMbZcnr9xcBF5XnI40NIgE6UaBPpr4PAo8iu+qpQ+0vK4Q== 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=8ngCipJpXdBRXheijMbZLSMbkg66Y4aDLYNKKgZfARY=; b=ZTZBnCYRhtyVlTtqGnSiZTnev96XxW+FoEbBA5qwGrYjS8OE80t3czu8PAFO5HnyeEn9NQmHDaeUXkRFqjIPcJXPNAfwTdRY/v4k3ZjppwKOYxu52+UwCR3VVingFmyg3glcW/BST9zmYC8md6UQQbV9CME9mKooOwa5FmVXLQM= 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 DM6PR12MB4385.namprd12.prod.outlook.com (2603:10b6:5:2a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17; Thu, 30 Jul 2020 18:48:02 +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:02 +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 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Thu, 30 Jul 2020 13:43:36 -0500 Message-ID: <391a9756a6a28800daa16468856c08fb5249317e.1596134638.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0030.namprd07.prod.outlook.com (2603:10b6:3:16::16) 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 DM5PR07CA0030.namprd07.prod.outlook.com (2603:10b6:3:16::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:48:00 +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: eef129fa-aae1-4c42-f908-08d834b9162b X-MS-TrafficTypeDiagnostic: DM6PR12MB4385: 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: kqNN4ZxKe0PiUetZrQwb8kawC1yttrbldh8IAkO85vyHjisriW1/21rRquYe3hTHmaVqL056o9MnByOvC3P2U+pLXAAMBvcHEDXu6gdZGZvb2gEIciEvcl4TLrabQ4GlwaZyfJnMNbe6KdFJ2Mhg5wabiwJJ1DYjj1CMuUiGuJjiJFCraLmhoVKNZxtNxgZoJooLbG2v4gMweZTeMFK/DzPrNaAlFX4oCGYbNGcwUOZ5MThgbPjWvU3dns2sbLvp5dg7THXgHg+K4fFi6C7oaKFcnIqSWee8frcKLEK8bitcES/kmYCI2LS9BNMuoA+NQPNZlhPyM/8tLlZTqSIKYnQpMRKWKkmxhSR1EyyBLL/TkhocOvcNdF/rX7BR6YZUYcLwKmNsTVBW+WlZbS1gTZDAMfTDKYYXhLHktr4Qy7PKRukyC6C5T0iInjgNqlNdonmEORbyscNeNqixWg8xfg== 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)(346002)(396003)(39860400002)(376002)(136003)(366004)(83380400001)(6666004)(6916009)(54906003)(966005)(66946007)(16526019)(186003)(86362001)(316002)(478600001)(36756003)(8676002)(26005)(52116002)(66556008)(956004)(4326008)(2616005)(8936002)(2906002)(5660300002)(6486002)(66476007)(7696005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hUrQ8qRtNSxDK085LTfw7jlzZ9r9U20o+tTClz74bIO/t+r1ig1dQK575aOdY2PludXkpAkdKbAtHj2rzGacUco0LURtFfQ3kpioRtBjVG5KaILvhPYB5KVQoPIFVyfkJkfPVdWAPdyxP1KV+osiD0Jw6qUlTRh43rBsnOBIEx4IKjujkbq2ytB/Mu68sbXBKhPMyIIBeB2sy3TNl+T0xxslmVkaNwXjauQVi0iiyw5TKhpJQE9VK6XxM0XnpXJGp+ghQv9Jy8SVLzBDokhu419w34CKfM3rpt8Tu0gIbCc7cQtyLWE+P9f8t7uT/L2z0CcuHjd1nfCjN8z7Z4l+UuBKNigH+X0bKENTbEGXl0rcrcqw0CEhSAiZeLLigqnWiQjd7owCnmI75EAEsM2Q1V4t8GtSSKdv825Bl81nO830GfZED4tzFDjnEVklbgfeglHmO9nKg5yzbIGzOdDEngAXdvyOZ6LK1qQWU2QjrmDt5zHD3mJCUAQvYOCJly587QVGgYFSZ4v5RWkusTR2Tp2xeULFJ3d99fpIVSbmUcQXWC2xpJytQok4OAeGth1EEFwOYE/8mhPL7Qo3czNKw1CkPp5GSHNMifVmE1mU3/nkipoEEfUbJUqglDfGF4wkGQmmvc2rxKdNZM+2NwShDQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eef129fa-aae1-4c42-f908-08d834b9162b 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:02.2138 (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: gMfXsYY6v+2rUoVokxtc1jrcVzyhyMe+ntZN6vpDJPcejB4X5vg/T3Tl3DgjVFg8sHrzWUK9/pL4eggDUPGJug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4385 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 MONITOR/MONITORX 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 | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index a1cf792d4d0b..fe08b1e0ff49 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,40 @@ MmioExit ( return Status; } =20 +/** + Handle a MONITOR event. + + Use the VMGEXIT instruction to handle a MONITOR 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 +MonitorExit ( + 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; // Identity mapped, so VA =3D PA + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + + return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0); +} + /** Handle a WBINVD event. =20 @@ -1494,6 +1528,10 @@ VmgExitHandleVc ( NaeExit =3D WbinvdExit; break; =20 + case SVM_EXIT_MONITOR: + NaeExit =3D MonitorExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0