From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.83]) by mx.groups.io with SMTP id smtpd.web10.5645.1595366498286126724 for ; Tue, 21 Jul 2020 14:21:38 -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=l/kZ3pkg; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.83, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YUUKaKzt2yZb3xKaog9fZxaP4vN1aFYwXF5GNIenkVLnVtWwtwlp50qBS+h+IWSHdWvV/YTKHuZllBr/30rsKcMmQqUTFjudcatUAC96WNxPmCNuMzJ1oxVxNO5Ud6TM13kpQROfqL9p7w0FO5sC8xZ8/JmHVS5sDkmpE3kAFIq6pA24zoAVM8EpaulZpedUFM12E3YcqW86bo8USoRTxmF4ANXcOOObI622pYvwXUECGPUexGyDej2RlTYBYmGMiS17ALJvjYt/xJTgKSfo8a16LCw6RLmZ2KE7cdqIycLVw8jAuD73m+bEVSvJ40RGFdIw2E4tFCF2G1EcKyZGvA== 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=FaEnYxd561M8PGXE77bd+f8s+ex3qWET/vWvyNzfdaOVsM/UDcJ0MRqka0NUPPuMGs57m3YAboVVSaTrbi/QpqtpdttDdVjKQ9Sqk27ZmeuBu8BIYjyDIGvq5c/Zs+Z4UNpt/T1U52hEjwjSlvAgZmwhUP4oS1viQkriQ/cbbEkMJQVeNKcYesCsMMuZ9OJZUsMpHuosNwu326yRec0ZcKqyfeSm9/pj+XTsD8/JPYCNk95QAIPl+iI4dw78vfLoD8AoEaqU0sU83BoPLMqpMt2XbRnqCoApBW+jTtUYoYS479WrC+1XZptyxdJGhA47FvU+/6PkSUy+Rv4Zfebn4g== 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=l/kZ3pkg2tlhIlvDZAx1WXHEoptMLiK1ErjoMzNidWQDyqzUDuBp9kuHjmuJUXoDoHOno2iEfk/4ik/r5Kl9hPALIBx1UQzJKBcD1whJMZObSIzdBLeadqbyOQOBYEtRzmaTngROb/Q7K6Q4DwFTf7jr1qY4hs5sOKtuZzxBF5s= 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 CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1606.namprd12.prod.outlook.com (2603:10b6:910:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Tue, 21 Jul 2020 21:21:36 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3216.020; Tue, 21 Jul 2020 21:21:36 +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 v11 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Tue, 21 Jul 2020 16:18:51 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0004.namprd03.prod.outlook.com (2603:10b6:806:20::9) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) 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 SA9PR03CA0004.namprd03.prod.outlook.com (2603:10b6:806:20::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.20 via Frontend Transport; Tue, 21 Jul 2020 21:21:35 +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: 2bcbaf83-5e69-48b4-8f23-08d82dbc0c81 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: 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: 7bGTLvvxa6lysmplb3RO5UEdZ4LOFiDGLnSfCl+sDQy17nXCtd4gqsaXFTN4h6HWNaadI1fXDhxB+BiuGaevrarX0zB9OCQMOzNw93RlRRXXDP7MwWUf+OM+be+/q9AFes/RbgaooeQUc6XwocQAYVnS3y9dlR4d+CHD/zvRZGAAapSUOeKBvyNe4fK0l17yjyx3CAnidQB1VTQxjEuek6xjLBFGagpOLPBkqbdnvM0NdjjJwzvHLybKjdHsusd3mXpTcPBaSHpCf3ArbwE+rhM9n8cEMzWTKDNz3utBAqhnpYiZHQO53X+lx1Q2gw+sw51m3xanKZoakDz0lNQdjRPEb/ChDK47lGow/fXUvKp6z45FOOBzFbzSMs7ysJlu8Vt9EBP5tDVUMuw4eJzSDop0ERXYHAgFBVsQAioKKaBRIwwWIKIzxGIG61G+EicI3KY1udZM8laY4n+eQDsbDA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(39860400002)(346002)(396003)(366004)(376002)(6916009)(54906003)(2616005)(956004)(316002)(6666004)(26005)(4326008)(186003)(66476007)(36756003)(16526019)(66556008)(66946007)(2906002)(6486002)(8676002)(52116002)(83380400001)(966005)(5660300002)(478600001)(86362001)(8936002)(7696005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mNBbWsnF7hvwKLU+1bBbM+VFQrZBXhe3QpCnpB4QXUHn1RXtckEF0lGXE/SsBPRKBBahJTnjZDEZZFG02IXCYJM0I36NmmmTRXB00ZUW4tw272LLvyYG8MPPpPCoV+M67hdi+fomOuI6Frxo/6nU5ZfMmYjwlQAQ84EE01YOSPQ0N0Edr5Z5PtUENr3qoTnemAmE6mnP33TVy4xN5Z47kygBTqQbTX91J5RM6r18DONDWdt+7FazBh9mYYW1sS3qK/wVrXPKaLzJlc+/g7a940bKNp8YbagEc/YLTjGE1BsXq8u0VyG8UGbMBHnONHFccfY44fDj5PfigbgE/7s6t12lJYnEOkhXFadugDG+pPq9iZu89QeR9g+EL8dv0N7+/9jvVkQjEG6oL7XHZ1Go9OibkuBjUTD3qpxH4OlQRVTOMws7AQ4W7dh1YbkiLfjKEG4sdTxzVr20fk85HtvCNYgTVSImVSzFevbmzdGU5mo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bcbaf83-5e69-48b4-8f23-08d82dbc0c81 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:21:36.1853 (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: WEpn6XOgFzuNBVtYHzsalNqexXj2FyynUrQheVcv137pSkTjx8ehBMofwBz7SsB4SEBNtw4crgAdLOQeeywN6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 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