From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.74]) by mx.groups.io with SMTP id smtpd.web10.707.1583190461945999317 for ; Mon, 02 Mar 2020 15:07:42 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=AIi8YG/G; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.74, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LNJGVqbprJW+QpEpng3ymG/nZExSJdQ/ZbPIEvn2IMXFncSt+cok+5PdPTmh62rX2wZjAmjRo6/ByuICyZuC3SBUNvWg1BF6AhqkHseVEpWRVdleqq7NhtGfgSXFWdgG3/GdfaOGERyTd7cf/QGRJefxGfYWOjSkY902E7zyqeU+8M2m5WUTka9faeLRNyhb9LpEPcL25UIL3iknyNqcxf8/tr2uuTmaQLtQ9Z3UVAnrLIp4YFpsLD79u98Ok714CLSS+5FhhdufZXaUryV1nvUWa5SXCsCxovuvlqJgJ83C05OWoBViv9LqD3ozq91H1wSCSHTkMAA6L9iJ9tZ/aA== 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=pXeeouQgfdd/1NgHqUWkLrFttVn5sSlBWpDrJ5BK2ts=; b=SCE3tDb9r7OJSHpdRcZZvTDbkT4hOvwvo//AgRW9g4OLmLhLCl8v2ybZFEROX3l4ByTHsGIBXTdq9ZQGOdZXmvj90FKWLr1ewzqrX0W5SdJKaHE15QJvqgzi7Pijlsam38VEvDDosdBd4aIHbC4EoQ76hpGxwy6gowAIO5fFa0syDr8+pm0Qpl+PvNUDJ8m1rfjFUUUql8wgv5LqemkG/pluc1iWr771FZxQT14qXlA+hPhKvOkQw9zyNBLFPl3vbCjtioJvf5ygUzZJcY3libANwz9u9SbBCHz5jcEkUfIBP41m85fhrcEMV36XK65EGScl+FCuIm9TapyzOw8cQA== 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=pXeeouQgfdd/1NgHqUWkLrFttVn5sSlBWpDrJ5BK2ts=; b=AIi8YG/GZYI8UgsdfhCXGgklMB5UWo/z7b1Y6EJ6xb1/FGGjNXHsYmBLLtdeV7e4OGrq77wFEuoXnBLNv+PZ+hscUWZmzpY8rrDGxKJzLjOl5ryno3N44ND+lfj9X7zwVGxbRray4OgxgrPUWChjw5IXG+e5I2PkHnOFh/qIcHs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB4041.namprd12.prod.outlook.com (2603:10b6:5:210::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15; Mon, 2 Mar 2020 23:07:41 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733%7]) with mapi id 15.20.2772.019; Mon, 2 Mar 2020 23:07:40 +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: [PATCH v5 12/42] UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events Date: Mon, 2 Mar 2020 17:06:43 -0600 Message-Id: <9dfff0e61e94f33487bdddd096c9097fcde13e6c.1583190432.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.16 via Frontend Transport; Mon, 2 Mar 2020 23:07:40 +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: 33380975-18a7-4e9c-0387-08d7befe81dd X-MS-TrafficTypeDiagnostic: DM6PR12MB4041:|DM6PR12MB4041: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(39860400002)(366004)(346002)(396003)(136003)(199004)(189003)(478600001)(86362001)(5660300002)(81156014)(36756003)(6916009)(316002)(4326008)(54906003)(2906002)(6486002)(8936002)(81166006)(8676002)(966005)(956004)(2616005)(66476007)(66556008)(7696005)(52116002)(19627235002)(66946007)(186003)(26005)(16526019);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4041;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jUihZbk6W3TJzhbYOUw6Ajzpih44/dOg5HFGYiI/PazXNSGrKacQhsrkozRDSHQbomVHhsO8knMXXo2uppTUZt00q8zG9TXs65tMrQt6asWuxOs44J4l4d/UAlIsqLZuDILZRPIWyR29AxGqZYiaXWeoLeDfPC+K8wJ/0+YBX268+64Dt4QxYEf74fKCrHLw/JlGxOF5SCnXebn8/f0owI1qj64DsXpLaeq76p8RirDtB2jeRWpSQa9PPn8HIf6Ix/gN0nGsNXLNYd7UBs8UAzidR8JmhYygtpstxecFUg6VmjhRVRSLgsOexY24uNWxuIxPLUxow/eE7zPhtqnoIIBp0xet7Y0e6VbwJTibzcUdqqXR5x+wbqL1c9e/QvxhFwRJIj1QzoqtONgSVLDBiMqHxtjyWUp420PJq0m9/YCIYz1LsVPwKVpFgL19vIydy4nO2vng5LQqAgeGeYz18d+Ta5TcZRH2VOdWw983fMVBzgUfkzXOQ7pO1jmeOK8+mZAWNlLh9pqGqmV1ugw+GA== X-MS-Exchange-AntiSpam-MessageData: /0sQSEj0pJUz2ojyeQQHiclrPIid/YITSRlFB3g2pKuCyPt0j1l+LARwEqIdyRA3Z0O9fTPQtInbmM0vhmEsjitrgfNZlQtWDhvmNQRCkKRqdXF3gRV761fcyMQGaKJmeGE5nhDBbKFdmvTTdA/0QQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33380975-18a7-4e9c-0387-08d7befe81dd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 23:07:40.8588 (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: 8Qh621sons/ZaT14OL13soLrCv9JBAmW4kMrZGYv/zzHMVu9gJlQzeP+l3XxsmUzK6GVxIC17VpvvRxFfcbuUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4041 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: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/ArchAMDSevVcHandler.c | 78 ++++++++++++++++--- 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index eb7b776859c1..28adf0d5e9c4 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -321,6 +321,22 @@ IoioExitInfo ( UINT64 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: @@ -358,6 +374,8 @@ IoioExitInfo ( } switch (*(InstructionData->OpCodes)) { + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -404,7 +422,8 @@ IoioExit ( SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1, Status; + UINT64 ExitInfo1, ExitInfo2, Status; + BOOLEAN String; ExitInfo1 = IoioExitInfo (Regs, InstructionData); if (!ExitInfo1) { @@ -421,16 +440,55 @@ IoioExit ( Ghcb->SaveArea.Rax = Regs->Rax; GhcbSetRegValid (Ghcb, GhcbRax); - Status = VmgExit (Ghcb, SvmExitIoioProt, ExitInfo1, 0); - if (Status) { - return Status; - } - - if (ExitInfo1 & IOIO_TYPE_IN) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + 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, SvmExitIoioProt, 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 { + Status = VmgExit (Ghcb, SvmExitIoioProt, ExitInfo1, 0); + if (Status) { + return Status; + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax = Ghcb->SaveArea.Rax; } - Regs->Rax = Ghcb->SaveArea.Rax; } return 0; -- 2.17.1