From mboxrd@z Thu Jan 1 00:00:00 1970 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 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=ogW/iZCT; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.236.57, mailfrom: thomas.lendacky@amd.com) 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 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=QsU9z538ohZ+gSll/ViYNK4rF8hs9EY7Z10fIy3XOy0=; b=ogW/iZCTO3w8q55V/Q6sRZlmrfH/3galjK4hgONrCHcl4Jb7jCLAfWItSrW3jZ07bv+qjfdI3EcxybXiyQPCIPdgjp0XgytgzukSm8OMUwvDcoC/NI/0rIf4ndtWxQBYqyEOd8NNF+0G1u4U2UM0L7QeYjaeixSTpQqogmYc3OI= 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 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 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: [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> X-Mailer: git-send-email 2.27.0 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) 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 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-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: 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: BCL:0; X-Microsoft-Antispam-Message-Info: ZyQl1ggloYu8bh0rnuv8jLmBxxBSaVDLFIDq547JcAwZC9emwRpKI8zcEl8ht7vY+013jWS+UWgPw8Nt5wR2YTM0sEPI3nK3HlVmXzbLKRuiB3cs0so7yv7IfcAgpKwYilBoqdAteIRtymq1Pp6oHx2x6X0dZwIWMnq0jiPpOFAIri/o1R5zhfyjW1DXg1KsTcsOq+MrkoP8VFbs0ImEVssVhH/ZBadpgIYBBzLS6iany3TEV9ZJVBrOA5SFIrQF0Ca8A7ZrqXxL9tt8NUi+Q/HHIAFZgKHb+drMLyYhuj5MPo/GRsRooGSDw6bSpFV+EbOyLFSLkzpVBnx5FD4M1s2rxmjKLjsYnUx6n1Nn+tiLlIy1U5/vxK7dzfcHSyBcXWFezhhD1QbX7Efa4z19UROFvFUM6M31fTtaVwB7DYHZoedIuu464sneSnV7qne5o+DJWp1O7ofiG13N7+pB9w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(136003)(39860400002)(346002)(366004)(376002)(52116002)(7696005)(6486002)(8676002)(83380400001)(186003)(2616005)(16526019)(26005)(36756003)(2906002)(8936002)(956004)(6916009)(4326008)(86362001)(6666004)(54906003)(478600001)(5660300002)(316002)(966005)(66556008)(66476007)(66946007)(136400200001);DIR:OUT;SFP:1101; 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 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 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