From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.74]) by mx.groups.io with SMTP id smtpd.web11.58100.1595863712802475943 for ; Mon, 27 Jul 2020 08:28: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=YVEGKEd4; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.70.74, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C3AtjNZOa25w6upmseuAH1cDFI6HxXO1hjJFZ7ItRDzy1e9Nmm+h5ikJ9vv26eYSr7QhJmH+psm72dazWC1lYfYx9X4n/F2+vlWUBLIzFLoEgCvQB8TWfogX6W2TgaoFpIaLTVqdKrgpMgTNAKmTauw9GAeenotYFN/kXS3cDinfZLRQ/GnmapTHYg6UpmEz2T4t87YlMNKpH/Uq0vmcGathWKstqL2sf+l7opjK/PWOZkrDalwMu0azRPsgC82vL7fAayP2Jn6Q82lTmbmOskyIJ2Yt/CNx9LdF0qbPQJu3ijnyIGtpYsFB9tJd4c3RfPqgiRKUKHfyEQvjpb/Ozw== 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=WgIMfJ8OYkikTZJ1D9fxZK3RpdI8V4GyaU4nRTVdwj+8s/tBlfTG27wwR6iXk8NWC4sWpScM2/QUKLt+Ghj1Vx4O6otgA9QjCmAdwY0bF4VCOWVNekSfe2XRQqsBMwo+sj5oxA9QVuPlqvKUhUu6/9Xe9AAFdN1Tx0ga7iR9AyFZRumrhdMOVVtmr59WK7cLA5tzhTJHIjQwsbAGSP6UuvsQ2WIhuIAzCaADNRvFm2ebiYNEnxYzn8Ye0teZ1v7pLgOpWIoH6QghwUwCSERA+ilbjsNSNonWn52bEWbyhnyZqQg2++XlLMQAbzyAH/j92Qbz3DzHfqNK+Ve4DEpQCw== 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=YVEGKEd42iTu+wXdZ49YXrFyqXWZnaF+/PFABYPKrXdYBvRECaKFobCA1byWdTlM7fSjZkCYupJZRJjtGqPNMYOo1NMl+Z7TBeHhLr1XuDPsobbh2sOIhgLD1WoftLFiQ6F2y0Tt1y2QgtJEXOkGgzNDmT/mHPwfZRN2E7K6aUo= 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:31 +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.3216.031; Mon, 27 Jul 2020 15:28:31 +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 v12 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Mon, 27 Jul 2020 10:25:55 -0500 Message-ID: <66da13b911a4283f3eab35e821b7f7795e119261.1595863587.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0026.namprd21.prod.outlook.com (2603:10b6:805:106::36) 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 SN6PR2101CA0026.namprd21.prod.outlook.com (2603:10b6:805:106::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.1 via Frontend Transport; Mon, 27 Jul 2020 15:28:30 +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: f63a5e64-555c-4348-e4f4-08d83241b7d6 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 06b012IzpW5f+ddcXBrUuwDcd8SuFPMic+5dVp48xqFklRzrp1Ze81LyHrIgXyN8pXH8YM0Tg0wIdyOlmOC1jk7LGq51LkPOEO7TVzZHjnDgH1nI7d/244RJ4J8lRnVh4ACetv6ZYaI+fHxggsEXbZQNyEDNsLRziaW2XJOAtaAcuRoVO4ibIc0pG0a9FiUf3vK/jHc8ii0FN1h2VZHeUyTkCMJ4nAU9zEco3Of+674uRB7orLkZ1pPHtRlhwrm7eX6eOy/JhfGKnacnGwVVM1WYaJOrAYBIB+anmXJAjTR8ta2GYR8SksJ78b6tDac4MZATcLTUAvgRzv1DdijWN/wTEdPx2LUlaZtpZ/I7rXsbejDbXNOntow4Db9H3pAhqG6pbKltGgMZd+Cemkurv6QsGnLydvWhRVCJepZ+MX4gDBtKUDIuMzIxN3PdDRmMx+TT5Wr/07I4uS5K8OIRug== 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)(346002)(396003)(136003)(366004)(26005)(7696005)(16526019)(52116002)(186003)(66946007)(2616005)(66556008)(316002)(36756003)(956004)(966005)(5660300002)(66476007)(54906003)(6666004)(478600001)(2906002)(4326008)(6486002)(8676002)(8936002)(6916009)(83380400001)(86362001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: TM9E5XkZekg+DUlHKoGVtryQt4kWhEC8a/eTIELe8HvJZVs5KKj2SUKUame/4T/Cvgou+bQ7u/UlNBMuua2MKm+k43e4z06/R2TKoC+0Kj2rc2RfZyDXA8AfYzKOrfQGV52gQRd7scPJwsk2PMWjDpnvSoHKaeD7cZjV6eG9FBoG5ReHsZCthBJFj1DOJeBazIWKgFXFcYe9Wy8T27UPAhV42Iu55mH3HJnY3gr4Om8dC7rJI7prJYXZ3B2azpvdhN72Q25LsBNBVCcG5qHm7+yX4obqXRtLO1QLU4xmJCMe64q+wFPhS84xB0z74RHH1XeNnQmYeLDOap+ypj4dBXEjtKSIwalYsFGvQLCORevl7Fp+Vj0giFyWQDhQEcl1Wxd+BZlcbdpNrW9PqPMxDh38YXOM3EHVd7ivTJeVRq6PNQ36T3TEQ+6pg9gnmNLqWUaBki+znh+G/WNJ5PgLaS8iZG0MnvUzy0GlNVm7ovI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f63a5e64-555c-4348-e4f4-08d83241b7d6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:31.2981 (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: QqXdep/qg0bTtSZHUdDE4oh2QPR1FMVK7gDp/EcD7Orl+BYEDBRRNxt4Kgyc7t9DGhc6mWG3G3T8MHL/s807cQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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