From nobody Sun Feb 8 17:22:31 2026 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+50950+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 1574280450156464.29015349752046; Wed, 20 Nov 2019 12:07:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id lbwTYY1788612xd5Y4hFe9KP; Wed, 20 Nov 2019 12:07:29 -0800 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.13455.1574280447980323941 for ; Wed, 20 Nov 2019 12:07:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lImu1QUDstUYajnzGxf2SFC5/4nMwyabNMk3odUf44cgZzg2uwr8zfGgOrUA4VAxROH3a3gpUNZ++J6X0NCjhVygQFRJ+pdkpcGSnyo/MbrmUoYe1Lt1+wCh9cKM21sspvqhUb3q5OgGalf3Wd5Dq83ajtfsN3LFOUpfQYzWSgJTtHNR5DqWEpxkykt6t0mtZ5PLdxNgFHlxuxqxlhiVHHiJ4ZvYM/mfEhsQqFONQxXTi/gJK0UxTy9QL6R7v7Ol6ZOJS2ZXtDPO+5up76VWa7HGEkzMXFbRqclkZbmjWzcisUpp/mbEyaEz/Tw1F7GWwI94uRDKy47gX2zERSmMWw== 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=GWO7aXsRi6RyawU8qPncOP+g8pxt6GP85m2IFpZh5HI=; b=cThvOHi0SmVF8CFVT0/P3e16nadWiyIU8Jq0Ib311TqFaJdQfvX5NLvoOjwzUhqxFey3oOCq9xDrMqukY/PZFx2JpJfc2PTWIH58R2n5jw4BsGIP9O/N+SWyOEnGoKSaM54CwcPpFYqp3JHthQV1g54hm1EJ5ysa5e88/0tVnr/kO6CmJIY7JAjJhocoiegdhrChNLCe6CZLUhzZ1gCBzY+iG2us6KJkGMIqAqxlbAS5PVRGZlaiev/ksm7XHkRR0jyVJjopYNHeXqJvEuQY3a+qLk3MhL9gt+TENdRKbKrGxYcQWbbALYGkbBy4B3cTZd48ObHN27nIvrjvvuFFhA== 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 DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3675.namprd12.prod.outlook.com (10.255.76.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.28; Wed, 20 Nov 2019 20:07:27 +0000 X-Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4%5]) with mapi id 15.20.2451.031; Wed, 20 Nov 2019 20:07:27 +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 , Brijesh Singh Subject: [edk2-devel] [RFC PATCH v3 10/43] UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events Date: Wed, 20 Nov 2019 14:06:32 -0600 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (2603:10b6:0:57::31) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e55cf542-0231-4780-87dd-08d76df543f3 X-MS-TrafficTypeDiagnostic: DM6PR12MB3675: X-MS-Exchange-PUrlCount: 1 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+50950+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: B8rXLVvMhf6fyEiS7PmI8o2YFyixQNFcJveGLZPJZXNmGUBolBd+chYwKl6MFY+CcjtIdh/lp8Sb8pQ0vQYnGQ+CB6w9n9NS2rZcXMYIBTLTC02L0aXoS+bd48OvyjfBrUTexWfyyVOebdJPtDRph4KLuHhKY7Y/m6iOEIc5h2GrhWnnm5shl2Zr6WHpQpSIWNebLgqCoI/h56Bo1kLwUXtCwJ4dHc3kemcXJXvYc+I4HJ/abyAhyXhey9IU7ntKqY/FzkuyPkw1tE5O1C6oOI0UkztaRtvIGAbSVD0qS4WQ1X3MxEAzCAIC5L8KK3aNSLB+UHPxlm/WA2xkI3b9BDkgM2E1+GuoTjNJTP2DIPjGKZWG+dC3gf4I5Y+aMmr47MAz4xqepXWyrnXlzdjh0RVByUpWU/J2oE18g035/ILwzwsh7Zzyz8Ts2fNB93QiLpvG/As6b+/EGQ8vJ0+x0HDbJfGBPIAXthY1m51rqxk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e55cf542-0231-4780-87dd-08d76df543f3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 20:07:27.2572 (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: /ODI5GZ+PXy1eWaM6+inaBJquSlnN5u8ajk1lZKBqOgUuncD3fDWcjak8DzdJHfDrQkpZwL2qLL47mSffhKroA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3675 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: tu74r02sDbMiQ1simqYXWYm5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1574280449; bh=Y9+E4Q/IMlc1m72/6tZH3XjFnOEhUUMHEzYeBRO9gX0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=RtYsTuCsyglO5/Q1OkZBIoRTF4pVelYV7imOj3TIE0KqN0b2rBM1so+9MWXFW/xRSaM sYfGacf/F8e2nG+At5fw3pQTJwnf+zcumHuTj1UXYHi5/jmoXxdG3BPNBsAbWyzmhOQVv 7bpzhTY+W01teblTz+HXjP8CcCRDFdVq4c8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/AMDSevVcCommon.c | 82 ++++++++++++++++--- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index c42fe632f255..98b62c21bbce 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -312,6 +312,22 @@ IoioExitInfo ( UINT64 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 case 0xE4: case 0xE5: @@ -349,6 +365,8 @@ IoioExitInfo ( } =20 switch (*(InstructionData->OpCodes)) { + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -395,8 +413,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) { @@ -414,17 +433,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 (#50950): https://edk2.groups.io/g/devel/message/50950 Mute This Topic: https://groups.io/mt/60973106/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-