From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.919.1589925104949452645 for ; Tue, 19 May 2020 14:51:46 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=dQUG8se0; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i9yhsRQzZCcs2zu/49uj2P7/Hs5lD1pGgtpStdvaV+0CuuLek9SJ16dNlfYdPT//oiNnLjcJo8MZxJomztYYIbIb3D9y0H4yDDqzuabkAuJU9rdwSCoHgGvX0g1vMrsWo0BK1CnkUYdOeD0qBjSTSVdTwbmE0rIKeQaJdeu7N65drdHdXo/hCSDHTTjjfSxytTOLqWsOsib52F73hUJlWiqQdfBbOeZdtjNf+dF4k/KaQQYhYtnzchRGKqGtUKiTxL6rCIpuRf+b7Qv4gP0s3BlKH7hxY5DHJXlxRZ980cNAwB+cEDSP8nNc+jDR0D2FMyeqttLrtS+Mk8SjoJltDg== 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=ml7B94NA4Peh6+nRzEMjMn69VDEs4N2m48ed2KIn/HA=; b=iQRUc7LWxw2c/dS85kFbM/zh5r9RTuposgD1TmyxFSsxVP+nWFBt9YneuJsTf/vasbU5FO8HfNc4gVtMngTkbhkMFEGz0b22Vk+haIEWlj9alhi/EftcKXYzDGGlR8KdGYmy9ZKQ8ozep8PY9GXVvZBO5aCv78+oojt7rqp4TJ8cadaS/seGEUXv+4o5BxHXmNQ7WdW9YjYfKi29v7KzPUuDdTUD2IApqz/aom1pGIalAcjyrVmFzbsNLhBnAoetlScAJ0v4qgKrpgFRMAbEZPpm6dkpwA5X20XawqdXMfK0xDBO2V5ikIFlQu4fwxdMUFD1i7SPYBjvEYwq/tEMhw== 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=ml7B94NA4Peh6+nRzEMjMn69VDEs4N2m48ed2KIn/HA=; b=dQUG8se0VYYWymw2ZUYKTmY+W0ahs36Ba0Ynwg67h8XdArBaHkqzUOdxytdQGG2K3h5cYY6QH6cGMhOG3OfzsKaic7dqwPkyGLeEf94N7SbhAX7XUEVYoRKsBbq0Os9AWHMPAmnF0tLCWVxmugE18CsfOft1nZErgzOSMz8uyi8= 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:43 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:43 +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 , Ard Biesheuvel Subject: [PATCH v8 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Tue, 19 May 2020 16:50:42 -0500 Message-Id: <96260a004ba86ab5e7ad440d40415fda3814ab3c.1589925074.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) 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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:42 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d7d0bf50-1a46-4da8-fe13-08d7fc3ed1ce X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yNhpkfRlCmxZ2U3QGqgWVLz48dZUqSl0XLMTc6k2k9/e8VufVQp6bR0PWpkjM1v7p2FLfd64MR3OzKhHwP6taivk4n4ZprDINiB9PWISg3Kem84W1uw9g1N9ty6DPLZC2SCYcOnW5E47MhdkGRPcX4VJaFmL68PrnE+GBpoNBUNP2AYiOn34wlXKPgqCnhmqleE4XuA14TCTLJx3GES3DeS+z5NL41N2uDg5hGbsABQHI/Tmit4KK7Rmc0cYpv17rR71CvIbU65yS7HBvCPejTzkLc1WoJlbKuS5aKC9CO28/LVwKBVaXs7VHG71PJJ9FgDzfUmk+S2NWilxot2dfaCA/RBDhraiuib4Q4TyR2yiFW9zEHPECpZWxCOVpeR445tOaS5sfvpFmUMcRufQiiQTTPUfpwUA2ypTekzCj4HYqWyFTZkrwkRfsT+UIJd+8kR8ASzMZypwH3h+zUYmywdrr/RqPZz7fF8Cw1w4cZbZpDUuu3IibZHjw7p+tItF+t42sFP9Q/xGXJCuV/kq9gYO0WmpCLP7VIv4V5ino23MP1i/bx15i58RbbCwqIKamU5mAIQTdvXrQ5xTrQhK7Q== 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)(376002)(39860400002)(136003)(346002)(396003)(366004)(316002)(86362001)(2906002)(54906003)(7696005)(52116002)(2616005)(956004)(66946007)(66476007)(19627235002)(66556008)(36756003)(26005)(16526019)(186003)(4326008)(8676002)(5660300002)(966005)(6486002)(8936002)(6916009)(478600001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vp2VGh7JpNwQ2gNjr7D+SRKaPFP1dFx4kxtl20lAQUjclxqseimUXVV2N2m7XzLCGfVwoTgGhEpMfFl0udXK+CB0vx+hdAF/ii1mGdKuZwyUAv2/GjnNuVFph/wxa+lz5xJ/zWIJYcpaKaJ+1euYZf/9w7bSAnlVOoMYvQ/pKxAXKKOqCqYwFw4G2pl2P94bfFXaa/jKtnSCw3hEe4a1yi7zkIcXGinPoSUpRhEt4Xe/bwNZ/3ZGpXo7PhhWKKnc1ct0LlD6rOgcLWeJBT84x6Z2Vol9B4Onl6K1Zdfsb3YsgjFoJW/jLJk8pcwqRJQKKNg37tiVrplEBK77uVfPiTIJIrWlbIN0rOWTkS0+Jbcnd5SWZuQ6mIsJHX01fFZoLH7iqQ7M14kRO1WIvcONqAvjIICa4qeQDjOPE8/n/EkbuweAiisGB1d+7GU+oTd3PX1ak6xwia2PzgiP8yWWHZO7OZyNJswOU3ko0XMDiqU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7d0bf50-1a46-4da8-fe13-08d7fc3ed1ce X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:43.6559 (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: jxHKWck5RbeQbLEnJ8ISA8r1AWJuSykm57psqFZl1Yik4DM9SXsJHPfvtgzFBY2FcvfyPVbm2OjtPKIVU5hDBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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 Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 86 ++++++++++++++++--- 1 file changed, 72 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c index b4578ae922c1..906b32e93d53 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -453,6 +453,22 @@ IoioExitInfo ( ExitInfo = 0; switch (*(InstructionData->OpCodes)) { + // INS opcodes + case 0x6C: + case 0x6D: + ExitInfo |= IOIO_TYPE_INS; + ExitInfo |= IOIO_SEG_ES; + ExitInfo |= ((Regs->Rdx & 0xffff) << 16); + break; + + // OUTS opcodes + case 0x6E: + case 0x6F: + ExitInfo |= IOIO_TYPE_OUTS; + ExitInfo |= IOIO_SEG_DS; + ExitInfo |= ((Regs->Rdx & 0xffff) << 16); + break; + // IN immediate opcodes case 0xE4: case 0xE5: @@ -490,6 +506,8 @@ IoioExitInfo ( } switch (*(InstructionData->OpCodes)) { + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -550,30 +568,70 @@ IoioExit ( IN SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1, Status; + UINT64 ExitInfo1, ExitInfo2, Status; + BOOLEAN String; ExitInfo1 = IoioExitInfo (Regs, InstructionData); if (!ExitInfo1) { return UnsupportedExit (Ghcb, Regs, InstructionData); } - if (ExitInfo1 & IOIO_TYPE_IN) { - Ghcb->SaveArea.Rax = 0; + String = (ExitInfo1 & IOIO_TYPE_STR) ? TRUE : FALSE; + if (String) { + UINTN IoBytes, VmgExitBytes; + UINTN GhcbCount, OpCount; + + Status = 0; + + IoBytes = (ExitInfo1 >> 4) & 0x7; + GhcbCount = sizeof (Ghcb->SharedBuffer) / IoBytes; + + OpCount = (ExitInfo1 & IOIO_REP) ? Regs->Rcx : 1; + while (OpCount) { + ExitInfo2 = MIN (OpCount, GhcbCount); + VmgExitBytes = ExitInfo2 * IoBytes; + + if (!(ExitInfo1 & IOIO_TYPE_IN)) { + CopyMem (Ghcb->SharedBuffer, (VOID *) Regs->Rsi, VmgExitBytes); + Regs->Rsi += VmgExitBytes; + } + + Ghcb->SaveArea.SwScratch = (UINT64) Ghcb->SharedBuffer; + Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, ExitInfo2); + if (Status) { + return Status; + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes); + Regs->Rdi += VmgExitBytes; + } + + if (ExitInfo1 & IOIO_REP) { + Regs->Rcx -= ExitInfo2; + } + + OpCount -= ExitInfo2; + } } else { - CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); - } - GhcbSetRegValid (Ghcb, GhcbRax); + if (ExitInfo1 & IOIO_TYPE_IN) { + Ghcb->SaveArea.Rax = 0; + } else { + CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); + } + GhcbSetRegValid (Ghcb, GhcbRax); - Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); - if (Status) { - return Status; - } + Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status) { + return Status; + } - if (ExitInfo1 & IOIO_TYPE_IN) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + if (ExitInfo1 & IOIO_TYPE_IN) { + 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)); } return 0; -- 2.17.1