From nobody Tue Nov 26 22:41:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46106+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 1566301167987453.143287697544; Tue, 20 Aug 2019 04:39:27 -0700 (PDT) Return-Path: X-Received: from NAM01-BN3-obe.outbound.protection.outlook.com (NAM01-BN3-obe.outbound.protection.outlook.com []) by groups.io with SMTP; Mon, 19 Aug 2019 14:36:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NcoQyiBd78bGSz76/3dI2uA9rPFmvhXqclsGBXur3tzl+nofnSmNWmBshBt0uANsq6dPaTCBNfVMlR6mFjjwyy3SfdoGROE1G7IE/XArWh5xjGpywUxizVngxEM+ti6vlpdmMnq6kKvoap01Gq5MsT7UpcAAC1/eNBG4L6UGnfcERcsGgx7EnBJV+t3NF5KGLpQAB0/fOScX3Oykux+em8VD2mlnHglZjNe153srIcRhV/1txyVitnQrPdledBvKihZJe2yku8aI28YeFb5/M5E90oB8hAddiusRPXAwPPBXJQmQgyC98Ax07tdx0q/p1V+XoLxouCTMpXTFAUHtuw== 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=DIVdaFrfnhkddBwWcMDPfcd4QLzcpfYr1GtSrPLf3QY=; b=g6R4wBWntI4EIA2ghj3NVfRI3/RTMkZPnJdcaEri2Ic8+eJPhjbcMfGFY6GK/r1VHRd64IzlTsN+gdO3FEbTVaQzPu3LsC+7YCqgpEuKJUxJW+fROQrf0jGkFoAPPdhbhkkLw0r+1bUBuD3Z59+/H4qcI5+P+F2YMycenIFJcXzA1KZklb9kftNgkrU3kqbefByE7DpTDZaYaASA9vO0Z9ZJGfvPG4AEkNl+vzQ2wBdNbFnbTLGkYhhgN/y+WHxfE/l++JRRv+77fEAzmWRyvxD8MDeTH9x9QFYp+UpDOe/I+5SmOL90b0PBXZ+EZRaJKmAtbnXLBEnAiwpCMTrolw== 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 BYAPR12MB3158.namprd12.prod.outlook.com (20.179.92.19) by BYAPR12MB2965.namprd12.prod.outlook.com (20.178.52.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Mon, 19 Aug 2019 21:36:02 +0000 X-Received: from BYAPR12MB3158.namprd12.prod.outlook.com ([fe80::39b9:76bd:a491:1f27]) by BYAPR12MB3158.namprd12.prod.outlook.com ([fe80::39b9:76bd:a491:1f27%6]) with mapi id 15.20.2157.022; Mon, 19 Aug 2019 21:36:02 +0000 From: "Lendacky, Thomas" To: "devel@edk2.groups.io" CC: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , "Singh, Brijesh" Subject: [edk2-devel] [RFC PATCH 12/28] UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events Thread-Topic: [RFC PATCH 12/28] UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events Thread-Index: AQHVVtYZKQjhj8NYP0KajIGU36TiVA== Date: Mon, 19 Aug 2019 21:36:02 +0000 Message-ID: <43b23558db24d8f33039e2dbee59d369a20bda18.1566250534.git.thomas.lendacky@amd.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SN2PR01CA0031.prod.exchangelabs.com (2603:10b6:804:2::41) To BYAPR12MB3158.namprd12.prod.outlook.com (2603:10b6:a03:132::19) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e7b5eec2-28ef-44b8-6e95-08d724ed3b65 x-ms-office365-filtering-ht: Tenant x-ms-traffictypediagnostic: BYAPR12MB2965: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+46106+1787277+3901457@groups.io; helo=web01.groups.io; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: xGqBB6e79hGyRde0A8pm8Dpy08dbIXsCnfDmi9rM+QUbmQ2DLQeLAnXq8bj+SYk+76tq9LT/gj4FZCISoiGhCIs1N8Vwjj9HMde4JWaZOqZFFawbhFLiZwdp2+FBAjN77sZUdwUZW/BmOwc/wDG2ujvO5RsEMTQeXFvJ2d7eacW2ub7U7LkWCIEx0V2GMZPDQPiwUuStcfU8ckF+g1xCt0p4n1auppHb36B+zCOfukbBDGkk5Cz/7A+tg2DWWy4/eue57WMPV0ou/+UGLbFNuu7VdeCII6uApDr5UuvjktEnflqp1LYx4VmcMolq2uLhZCECAyh24ejNBZXCtegNeT4LzcnLkmpIWwn2tLqqRraDglYZPyyLjZWBeoXH1bFz/FOTn+nmQVgtyoHRnU8KS2ioM/lrnPVyeKjfkEkUnK0= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7b5eec2-28ef-44b8-6e95-08d724ed3b65 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Aug 2019 21:36:02.1055 (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: 5WxwRYGUZpskNzcH/aGfsGE3zm/C1P8IH2D5FhNd8kyquriegPkFcpkLPCbGiINzF+GOosCXKhTaCeim7HzGPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2965 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 Content-Language: en-US Content-ID: <59CD7F3C207828458A04B67A2CC1FD7F@namprd12.prod.outlook.com> Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1566301167; bh=8zKnnZQTF7MfhWbbE5MnQ5EFnEY8eLdNVyuA2V2cMMc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cyaRR1f+vi7h4EjnJNzSH19yA4IJObj6rEu7FykpuqTStQg4O8eNXyd/PlUNw78kjDH 1Edoi2IGdr/40yxVWw1vbkg6EpG/6TRVQqKQhGZkn7aXqt66SglRLNqumAnlkYCbPpS0n iRwNNGxcMCNVY1C9Igpvf2fbEbZdPkQLz9E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky 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. Signed-off-by: Tom Lendacky --- .../X64/AMDSevVcCommon.c | 92 ++++++++++++++++--- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index 3b69aca48055..2bc156840e74 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -278,6 +278,34 @@ IoioExitInfo ( UINT64 ExitInfo =3D 0; =20 switch (*(InstructionData->OpCodes)) { + case 0x6C: /* INSB / INS mem8, DX */ + ExitInfo |=3D IOIO_TYPE_INS; + ExitInfo |=3D IOIO_DATA_8; + ExitInfo |=3D IOIO_SEG_ES; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + case 0x6D: /* INSW / INS mem16, DX / INSD / INS mem32, DX */ + ExitInfo |=3D IOIO_TYPE_INS; + ExitInfo |=3D (InstructionData->DataSize =3D=3D Size16Bits) ? IOIO_DAT= A_16 + : IOIO_DATA_32; + ExitInfo |=3D IOIO_SEG_ES; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + case 0x6E: /* OUTSB / OUTS DX, mem8 */ + ExitInfo |=3D IOIO_TYPE_OUTS; + ExitInfo |=3D IOIO_DATA_8; + ExitInfo |=3D IOIO_SEG_DS; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + case 0x6F: /* OUTSW / OUTS DX, mem16 / OUTSD / OUTS DX, mem32 */ + ExitInfo |=3D IOIO_TYPE_OUTS; + ExitInfo |=3D (InstructionData->DataSize =3D=3D Size16Bits) ? IOIO_DAT= A_16 + : IOIO_DATA_32; + ExitInfo |=3D IOIO_SEG_DS; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + case 0xE4: /* IN AL, imm8 */ InstructionData->ImmediateSize =3D 1; InstructionData->End++; @@ -370,8 +398,9 @@ IoioExit ( SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1; - UINTN Status; + UINT64 ExitInfo1, ExitInfo2; + UINTN Status; + BOOLEAN String; =20 ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); if (!ExitInfo1) { @@ -389,17 +418,56 @@ IoioExit ( Ghcb->SaveArea.Rax =3D Regs->Rax; GhcbSetRegValid (Ghcb, GhcbRax); =20 - Status =3D VmgExit (Ghcb, SvmExitIoioProt, ExitInfo1, 0); - if (Status) { - return Status; - } - - if (ExitInfo1 & IOIO_TYPE_IN) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - VmgExit (Ghcb, SvmExitUnsupported, SvmExitIoioProt, 0); - ASSERT (0); + String =3D (ExitInfo1 & IOIO_TYPE_STR) ? TRUE : FALSE; + if (String) { + UINTN IoBytes, VmgExitBytes; + UINTN GhcbCount, OpCount; + + Status =3D 0; + + IoBytes =3D (ExitInfo1 >> 4) & 0x7; + GhcbCount =3D sizeof (Ghcb->SharedBuffer) / IoBytes; + + OpCount =3D (ExitInfo1 & IOIO_REP) ? Regs->Rcx : 1; + while (OpCount) { + ExitInfo2 =3D MIN (OpCount, GhcbCount); + VmgExitBytes =3D ExitInfo2 * IoBytes; + + if (!(ExitInfo1 & IOIO_TYPE_IN)) { + CopyMem (Ghcb->SharedBuffer, (VOID *) Regs->Rsi, VmgExitBytes); + Regs->Rsi +=3D VmgExitBytes; + } + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SvmExitIoioProt, ExitInfo1, ExitInfo2); + if (Status) { + return Status; + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes); + Regs->Rdi +=3D VmgExitBytes; + } + + if (ExitInfo1 & IOIO_REP) { + Regs->Rcx -=3D ExitInfo2; + } + + OpCount -=3D ExitInfo2; + } + } else { + Status =3D VmgExit (Ghcb, SvmExitIoioProt, ExitInfo1, 0); + if (Status) { + return Status; + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + VmgExit (Ghcb, SvmExitUnsupported, SvmExitIoioProt, 0); + ASSERT (0); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; } - Regs->Rax =3D Ghcb->SaveArea.Rax; } =20 return 0; --=20 2.17.1 -=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 (#46106): https://edk2.groups.io/g/devel/message/46106 Mute This Topic: https://groups.io/mt/32966278/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-