From nobody Tue Nov 26 01:35:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63858+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63858+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1596829318039824.8632945778875; Fri, 7 Aug 2020 12:41:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1OhiYY1788612xgpHoEJbFM7; Fri, 07 Aug 2020 12:41:57 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.45]) by mx.groups.io with SMTP id smtpd.web11.4239.1596829317024343339 for ; Fri, 07 Aug 2020 12:41:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ic+PT+8mbS2+py4ddtkVr+iWvUjrnkE0sPM8fYmm1d70vcYo2oqBa7840/++iBnPb3YODreSZtGPj+DiCdFyCzXkM6vP/IIPJxGLyXx4qZc4ixJH3yffhkbno5q4vt1CJY1vTLkUd5vqG0LmykpsqmmLyD/8nYBgYXv5RVj3cniIRcO3ZAR398ukKD4S1uCnEL/t/TnS3oPbD70Irn8B6cJRHwa8/XKHxq1JSx0CCGtc3UaGJ4nNXg8eazYv6KHN7PtxIr7L0GHYRJ9iaDwF0MECVC5ibn9kpEwUXhLLkgZEgxquEZFblBtesbRRjEM+BQA+qbBPGfWjLdCpT9iyLg== 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=z7KM/QY3QdiNzO0sLsMAJB/dGUXDqeKlzSZHqwBk/3M=; b=Q/nW9GeJDyxLz7fG+ahTaqr4yQT4y6tN8rOf4ApPLowUWU+RDv2xw65SGykxgUcTPD+SV8c2GjJB7SRzjfXJ9ON/g1/XIU5wy37uxib0FH+1HPHXu0tBtOsP0Gr1QoGVz8bxOoLsQsf+leqIL0AQh5cYU9HfX/5Ekh8R/v6gNQmjERFR2oUATYuQCll9DO6iEbU2GLkUXJ0+GSsTVuzH1TDmZiGE+vP1w/SVU4QBtPpSjZEKyfjhobPDMRa/m2zmlWShpkHRO3oZIk3EI56LGAnpW4mMEjTItHMSJEJSRsXUQeYzEXpSJazhE8lqt4RKI513j+fc8eidzlm+wd/kJg== 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 X-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:41:53 +0000 X-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:41:53 +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: [edk2-devel] [PATCH v14 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Fri, 7 Aug 2020 14:39:01 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0136.namprd07.prod.outlook.com (2603:10b6:3:13e::26) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0136.namprd07.prod.outlook.com (2603:10b6:3:13e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.17 via Frontend Transport; Fri, 7 Aug 2020 19:41:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2dc458e4-c403-4455-ef0a-08d83b09ef8e X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 7t8AG2m1P+xU0ygiQpevOqhX0/2MX6wKZBiaFS6Z7AQx4riD0CVuHzDNH7OGi8nU5DcLPNgLjWlRDh3pv0jx9/ibadXiTO8x2h94aJ1ho5aq8fSy5AUF4GBo3j3pIUTTdgpUiKK76EBzB7SNaz/lFiMNxEhYsIDg4gWF5mupqPlWn3JYxlBqU7bfuo702cOj2qVjOaupR8sdRJmgF8P9RjdnWoW/d7ZjZ1vdSBMRq3XdP8OYOu6c9pwiTzhxJELMff80RwH2R0HJc7xvmQqa78AVtt+xFmNlGFVO6FN9RwkU3jlZiUVEimLc3R6OszwaZBAFA2hYKjNpaIejTyM7ItIsYf37coKCNqA3mjzI0OTa12xTaLuuY0jgb7uULCEqBBcM1+yADhwx3voaFpXLbQ0gnOYeZapd/YKgabKGQVsiLE6gXGWcA3M2HEymFHIFN1i/CZhOkfPxaxKigWCs8g== X-MS-Exchange-AntiSpam-MessageData: ziBG8vQ6/qbuEriVstObIqHhfvKjNNdZvDPCE5Ns/k51m+g6yUr+bEMI5+ALTaieaBiyJt2Gyo2EiCx5Y7xn/Rszv8KC/lrWuEQHZOgUxVgc7lX2zhjeyVrKVKmCfPj5xXteIeRtNj0wsV67OqERaaxCYPkl3YzUXqPwCJdM9Bp+UkrZd/VVplin5tsL/TDfu3tJqQ33PG8WOXAXlnx4SmR0OS9tILcVGCkXqKQKeqXusiqaqvGm666URzkG8NCKM1Op8KPARG1G5AAxGJelkTCNYKGZlsipL1HUuWVZ7ErwBZ54BpXtI1FULYgu7gRDcvcTRlCkaKtEKL2Eq6NiMYAX429y8csymQoSkiCjiFUHmmiVzxVZ052rwR+qt+o5gBK/IEJ9fZ/9ln7ICHbPj3u2aeYJITYwIPjPq/1+2TGJO4xoA/u33KB60RO1KmOqoZTfZVOO3zV7WE+4gTv+vaiWxuoE9pZIsjGnJ2UC7qBR58kZI68xO5nVC1Oqmm+HGbHVMAYwwA5I/3RDWYtpouWR4Wxnm96eQxpzpZalmIeeEGhP3Y/aIbT/K4eQp9Ce5P7Tu9i6LuvL5N/j8IZuEkk0UnydYhoz7HwrD8tvW+X2np3D1ml6T/TAHcyHIgGB7f1hUpXkpoAVf0X2Lxxr5Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dc458e4-c403-4455-ef0a-08d83b09ef8e 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:41:53.4480 (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: nGf9ENNS1BOaBgLpFOLMf+CkLTGMLeclxuoAzm68C4Og7ID7G/ORI83pxLV9NDN6DQMhypwZ0vReNnVzHdeDuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 84R2oJ0uXSYmzcmlNR5M0F8Zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829317; bh=yf+92cJXdJX0XtwEnheXe7QwKEP5GX30dFQOXBhVU9g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jEFgFXeoISUeMf+MFCu/q9v5ZWWaHgRY+3DgR6RbKgo+7DT4vYdkPik6y0GzanEIHRe Lmrq7TVzRBUAXENbA1x2dPUXeGZ8embFqv7addD24dRG88mzFf3xeCUqcPIC3wukWH2KO ZR15S1DSyF2wJjyzmu5ugMg+GkYUBNUuBkc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MSR_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support an MSR_PROT NAE event. Parse the instruction that generated the #VC exception to determine whether it is RDMSR or WRMSR, setting the required register register values in the GHCB and creating the proper SW_EXIT_INFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 1c9c272a250e..dbedd4e9f95d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -374,6 +374,67 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MSR event. + + Use the VMGEXIT instruction to handle either a RDMSR or WRMSR 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 +MsrExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D 0; + + switch (*(InstructionData->OpCodes + 1)) { + case 0x30: // WRMSR + ExitInfo1 =3D 1; + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + // + // fall through + // + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if (ExitInfo1 =3D=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + } + + return 0; +} + /** Build the IOIO event information. =20 @@ -705,6 +766,10 @@ VmgExitHandleVc ( NaeExit =3D IoioExit; break; =20 + case SVM_EXIT_MSR: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63858): https://edk2.groups.io/g/devel/message/63858 Mute This Topic: https://groups.io/mt/76056518/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-