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.80]) by mx.groups.io with SMTP id smtpd.web11.1778.1596134792339938178 for ; Thu, 30 Jul 2020 11:46:32 -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=yfrXScDi; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.80, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gbw2aOvQ6rNtzTsCI5D4+E2Kifshrra0Hhq0U9Z13XDMAqldjLGjzHWpyE+35c4AEUeEeUAb2FVXz31gYQRF9oJuIKgfcY0f6DSI04vNi+gkKsobuxBeSJkWDPOkzZ8mggn7S6cjllkVRG+Y2HbYPULW5IiHNC8KnY6Q3o9+bDUkH3C1n68v7RxpZtmui/wIE58FL3qFq+0Fue4ncfY6mg+lb7qqAIdro7mTCy0GVwjAaAzvLOMgtEjlZQF+tBfqbzQiYzZ/PmymLXQ/yWOWSAII/ItrAJPg0o90yEit89zaZfraY80DjLBKWsdbed3+6/tByyCRw9tNdAYVPJldIw== 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=nSHaQ8sOhkMs2C/wUngjBq4mbV86dSFwGRqayERpo4Xf9U+9Nb70p3xYH+YlVn8K51db+7gj4wa/wg+lsFJoSxM3Z6B8X/hexivRs8zBViGE5BYMYixktyRvAIF2VUWo8CP8blCwPVc8Gr9QTUYqZGsgEVLNCZEhqHPZJtULYRmM99YFvLydd+nEu4WpW/0jnFzgy3/XdMJ7H23LzHHA7p/MVQ1fWvH4fAszjwu6tjmRcxt/1bjUxosWD6T9kmKmArA9lkcL/l1Gm14IiM804o+w/y8fA+tPyoqAjHzKNhMimXDwoz/tJyebVPLTsqP3v3B8cjvIf9tIjcrJlMqv/Q== 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=yfrXScDidRTTq6baPg9VCvc2L7KcPVRF4ElrH4zChCQFw5vafFcurxytRW9pfBpbLuVGMJzo0Es/TvEXiNR9OPCjkbnqTC5gYSkzUWbOOXdY++1+gt7bVxwFEow0evORVwlh6Niz+7HyiMWSRuHwf//MEHbR6cg4KsdhtZD+wBo= 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:46:30 +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:46:30 +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 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Thu, 30 Jul 2020 13:43:26 -0500 Message-ID: <5983526bdbd3c130d907f32ce1dfaedf97101e4b.1596134638.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) 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 DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:46:28 +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: 8b404ee6-d51c-472a-3699-08d834b8df55 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: iGRhydtb8FMiDb0+m6naeANfMGh/G8e9680W0DdD232hJLAlEV1tOCFJaNPXbYOJoDSxTvZnRwDNiSVwLDuq7qhHKIp9nl1czgoHNEHk8JNpZajo7ZN9aEH6J/N14n+YHg5bVrzsozhnZVsb/edo8DVP13A3QcesLNOAVc9PAtB7WtM6jXwgYVRMqZr78afG0Xnnlof+zVnB5npUurSZ5caKUJSl74oce13fXCUe+cq8tNCCXeEcQTbwOn8/U9q9URa1Um9gsJERmH5oaARy3KSndNSo0L8Spv8wruHmREH9puxyBsdhs6zhC3Lgvrj/EjYN+M8q5EYs+b+sB3tdmgHWi+xUnROmb4etbpbWmKZy/5/5WQYcejFt1bagt2mcjDqiVJpMK6fr2KJHJNZPBpVODTm/4zn/fqK2eIX2OC9QNjFlyhTQen83H9jxCzqsUDRF5r7TVm8dizcEztk+7A== 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)(86362001)(2906002)(2616005)(6916009)(36756003)(966005)(8676002)(83380400001)(478600001)(956004)(8936002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rO+mHwH4NpS733DO2w9N2k1NuUMsNsFrJWpbNMj76cf6Ol6baJSMTjwW1iTMddMWWWa26X2fBFTkDRwWnvslptKUiwlSHPN/jJ9GxFn0/PSg0q5XjG13i6snNdp7gCbdt+LX5sB6fRi+fZNki4xplwWh9aPh7b4hUFNJWCYeSS/9nxzu96qmCiXR22gzxoARU4pmEej0k/FGyNld/on2UgXthvSz7PcgOl/P5aUIE3FoEYjRw0vJDVvTEWo+4yliB/hzrb2lHtt7u9icp5dWj1uoVc2f4HkCBwqCJE8JYhRImUSydCemWO18WjaC4bQ0CFAB8EPhAHPsGLZjS4rs4el9NJkJAkXUsGzu6xS9hprR7tc+wUkjdy7iPwqFx7FEF8sNFcQlGTS9zviVyqry3K/Twpljr2B6AuxOnvKGsuIinB0p2RNON9tyoe4/iH+WtpkAbtw5xelOLRctHmVKMKnw8ng+2roYFscc3dP3wayyMjikRf6rqr/pwpDJPTuc/8PYB1T4hputQ4oDwBu/YDP/gZ+yJN/QhosIODPSIgvErValoDSU8kW3IJ/zOQo5BtKGknzzDjm4uZE5kWyVLx3PgYpEKtOod9O+m/yO0hUUssVvhVnO41Jn8ulcbjQb5uF3H+NzlZ6lfriMuJ27lQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b404ee6-d51c-472a-3699-08d834b8df55 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:46:30.1984 (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: neo16b06FA9aJwAvFMaPkAfCErJxoZlF68v3odAnC7Ol0MK3dFKqNKFg+pOCX1uiPOIW5ofgZ62AoszwbhZKRA== 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 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