From nobody Tue Nov 26 00:43:37 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+63856+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+63856+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 1596829300523681.3184453924625; Fri, 7 Aug 2020 12:41:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VUqzYY1788612xacutnExQVC; Fri, 07 Aug 2020 12:41:40 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.57]) by mx.groups.io with SMTP id smtpd.web10.4168.1596829299470571738 for ; Fri, 07 Aug 2020 12:41:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C4E7Pu/FyQkiSXVCUSapnNWavZC7lkWS4ZdjTlBDStos7g5IR+haDMUReJ1Dab/TLhN9O62dmrrqWH7d2EFJSXuOHilHGVvPtVxkuu1Q7ygmUsDrUsHMzAkXaL7LWDbm3ytKQW9Ti8cR2O0oBvzCxuy/szv32UjxBU5IW5Eb+drkGk5ebNV4OiE/AqTB8C/1DYyHWhDby9iSlF/E4MspIzfyI3vShiHuK0sa0Uav0W6xjQWVe3ZnAlQId/SBrTXAFawuJXkrlj/cgP/9AGOKkRobtqmK136hBaNRjsgQ6epAzUiSa76ZrzQhN/yo1CxJ6GuOa+qlLK9aRuup1xLbIw== 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=QsU9z538ohZ+gSll/ViYNK4rF8hs9EY7Z10fIy3XOy0=; b=NDGEUoU/j6JfMW63dgCQ1lia47Ovw8PllqiiO/MLbBaunhRjnaIcgRvxszaN5xcop4bcBaBIOKZ+5dOCj8QZYJFOe+paT0n6pwUzYRTEINudsa34Z8TwrvYSw/vqT8ro38S/zunXE+Icn6vPXiiQg1qnDSJQlpdN6AXp+IjEJD/jzKAXej9jrBUZYZpycCdsFdAfjyJEvMMh9zh4s9iNlSeLfaZ3OvEHDv4S5ltCvXKcC8AOvWKWA2+m5ulvoHya3W8/XQc+U+YXEkO1xZeWPn1x2BZ79VbCR1g+DALmQjhdJVOjo0cukfT7kNfyUMnw1oj8zfB6SWh6Ol7kNE+d8w== 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 CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:37 +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:37 +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 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Fri, 7 Aug 2020 14:38:59 -0500 Message-ID: <1159c1c2d0e03d347e178bd062f8538766a76d15.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0084.namprd02.prod.outlook.com (2603:10b6:5:1f4::25) 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 DM6PR02CA0084.namprd02.prod.outlook.com (2603:10b6:5:1f4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:41:36 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 30c34ad1-a4d9-4b78-f90f-08d83b09e5f8 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ZyQl1ggloYu8bh0rnuv8jLmBxxBSaVDLFIDq547JcAwZC9emwRpKI8zcEl8ht7vY+013jWS+UWgPw8Nt5wR2YTM0sEPI3nK3HlVmXzbLKRuiB3cs0so7yv7IfcAgpKwYilBoqdAteIRtymq1Pp6oHx2x6X0dZwIWMnq0jiPpOFAIri/o1R5zhfyjW1DXg1KsTcsOq+MrkoP8VFbs0ImEVssVhH/ZBadpgIYBBzLS6iany3TEV9ZJVBrOA5SFIrQF0Ca8A7ZrqXxL9tt8NUi+Q/HHIAFZgKHb+drMLyYhuj5MPo/GRsRooGSDw6bSpFV+EbOyLFSLkzpVBnx5FD4M1s2rxmjKLjsYnUx6n1Nn+tiLlIy1U5/vxK7dzfcHSyBcXWFezhhD1QbX7Efa4z19UROFvFUM6M31fTtaVwB7DYHZoedIuu464sneSnV7qne5o+DJWp1O7ofiG13N7+pB9w== X-MS-Exchange-AntiSpam-MessageData: JfP2S9Uq//m9WOF5Liehy48wS+/REA+5FRdBiLl3VCcCdybN7wqP7FXZQeguy638rQCwxIbGbNtga1DcNmd82im6TKKc1gx6+qMrYBFFSTIDGpN0kCmKDTXs5Vj7AiG+q4qJ4e2dTDzTC/aVcwzoXTioUR3oLC85XB6qJZBvbwZsEC8DO2x8BZV/OeTeHTns7ipMODMXxAv48Ib/sjQHj3ogWQhgA9zjRzAHl5JfJS35XtXQEfNOOwk1XGm12NzjdGQDihxCU7SS1KHaZwoF+vqW6/v4PKOP3SC3RjsnCr7wOJrnckZoSwmQ/b99Bu8NZH5F0MlV8BxTVyqgc9K9PnvxZNQhs/jc+ZSKlcZpGlx1L+LIbDVGv+JWQc0j3uHD5rsxIIlMvKrNHvjFS9irrZ0enoTS237/nQW+85iFtfbEDW/fppXzJSzxBWM/4KYErwvSxY+gRma/99MNpkg1LURwmAhXraiJePCde8KHuHYUtoG2t6WWGe7r0Yeyf/cu7YKFTtAzY+Mus94q4XlGUAeZjTlv3jnIM+zvFW6AXsUqwNN940ZDL76jKd2l7TzPNMZ8C2mkD2DPXE1IXPwCFmUwo47/V9MDS7S1vThImPQlWvw6Y/g9ioZfZaNF0XtEqqMvpz0aorgdoEwIN6MJ+w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30c34ad1-a4d9-4b78-f90f-08d83b09e5f8 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:37.4457 (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: OfGyW4vecIGSEm/K5hfDggqZjwO02uZRvare7RRJx06Gf9CsmGGczWk6maaAWROrXNXR4C4sTGGcYFiVDzIi3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: fltzSCguFjEIQRgIYNgdKn32x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829300; bh=nQ0elLKn/NWZvLP4CTGv6OVUFLhyS0vjnxi5v+kxZRc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=oeSMxMV+DVc8ZxncitosEB8Y4He1VqEcIFZBPmiGipvSPfACnFhTbLpyMMKVHatKSsU 40VzvwLXacfFQZ+LE/f7pZSbzjfjNT3WWd0MWQ8dqSxP84l4qtgJcMTz17MVVRMY4bANH jRirf0Vdr/zTe7u1lqiW7K6fmafe29Xl6PA= 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 Add support to the #VC exception handler to handle string IO. This requires expanding the IO instruction parsing to recognize string based IO instructions as well as preparing an un-encrypted buffer to be used to transfer (either to or from the guest) the string contents for the IO operation. The SW_EXITINFO2 and SW_SCRATCH fields of the GHCB are set appropriately for the operation. Multiple VMGEXIT invocations may be needed to complete the string IO operation. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 90 ++++++++++++++++--- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 04e8b8aebf7d..b6ac3552894f 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -397,6 +397,26 @@ IoioExitInfo ( ExitInfo =3D 0; =20 switch (*(InstructionData->OpCodes)) { + // + // INS opcodes + // + case 0x6C: + case 0x6D: + ExitInfo |=3D IOIO_TYPE_INS; + ExitInfo |=3D IOIO_SEG_ES; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + // + // OUTS opcodes + // + case 0x6E: + case 0x6F: + ExitInfo |=3D IOIO_TYPE_OUTS; + ExitInfo |=3D IOIO_SEG_DS; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + // // IN immediate opcodes // @@ -445,6 +465,8 @@ IoioExitInfo ( // // Single-byte opcodes // + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -506,30 +528,70 @@ IoioExit ( IN SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1, Status; + UINT64 ExitInfo1, ExitInfo2, Status; + BOOLEAN IsString; =20 ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); if (ExitInfo1 =3D=3D 0) { return UnsupportedExit (Ghcb, Regs, InstructionData); } =20 - if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { - Ghcb->SaveArea.Rax =3D 0; + IsString =3D ((ExitInfo1 & IOIO_TYPE_STR) !=3D 0) ? TRUE : FALSE; + if (IsString) { + UINTN IoBytes, VmgExitBytes; + UINTN GhcbCount, OpCount; + + Status =3D 0; + + IoBytes =3D IOIO_DATA_BYTES (ExitInfo1); + GhcbCount =3D sizeof (Ghcb->SharedBuffer) / IoBytes; + + OpCount =3D ((ExitInfo1 & IOIO_REP) !=3D 0) ? Regs->Rcx : 1; + while (OpCount) { + ExitInfo2 =3D MIN (OpCount, GhcbCount); + VmgExitBytes =3D ExitInfo2 * IoBytes; + + if ((ExitInfo1 & IOIO_TYPE_IN) =3D=3D 0) { + CopyMem (Ghcb->SharedBuffer, (VOID *) Regs->Rsi, VmgExitBytes); + Regs->Rsi +=3D VmgExitBytes; + } + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes); + Regs->Rdi +=3D VmgExitBytes; + } + + if ((ExitInfo1 & IOIO_REP) !=3D 0) { + Regs->Rcx -=3D ExitInfo2; + } + + OpCount -=3D ExitInfo2; + } } else { - CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); - } - GhcbSetRegValid (Ghcb, GhcbRax); + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + Ghcb->SaveArea.Rax =3D 0; + } else { + CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1= )); + } + GhcbSetRegValid (Ghcb, GhcbRax); =20 - Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); - if (Status !=3D 0) { - return Status; - } + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } =20 - if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1= )); } - CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1)); } =20 return 0; --=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 (#63856): https://edk2.groups.io/g/devel/message/63856 Mute This Topic: https://groups.io/mt/76056510/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-