From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.81]) by mx.groups.io with SMTP id smtpd.web11.1221.1585071682806504193 for ; Tue, 24 Mar 2020 10:41:22 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=bTikRg6a; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.243.81, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fzFLwN1ZyvvTTLXiSLbEVzAjcTyHXiMAkTUzxfwMs/epMM4lBfSVx1HBP7SdNiGDwfUknfXqyYyHZdlChGOYgLC/p/NQ2p4+p9HJEKLeY3AfouBluAMEkuv8FShC8y+W7YtOYSHwWFDtlyFQm8M1J/olDLgKIylLGiqzY+5dhO8oEUD1zUPZxznhJChg7WxFWw0g/sGejjX0htWAfEuqI/0WOiLMVBi/9xGk0fGBbMv0WtyyxahVR1foFKGYdU88efJq38FxNK45gNdOOI78/sL2qRr0Dab8hfWUVvxdZ73Be1Z8UgDEKkW4a3ARC8bPrF5xBQD0AyUazMrhpnxpAQ== 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=o+CRR3KqGqiFCW/LW3agU5S0hklOgfP0JdHI3EXYNx0=; b=XFssuRp9BY8JTsbpZvMN3jH64J89PhGO6KDmT97boMX1CMSEhp5L3icrR8Bx/einj0UfgBi2P61FObhMdFX3rTlFAf0jX3GOvXdTvQGA4CRV1pUnDM0qrek9RylqZkeyUdKx4O0D0ez0+jTsHEqb1n+vHHNIpYEgOTpjbHOOj1mzIttmn587V8DrpKIk/LnbH1oaYFwxOOCn2zHCZXq/HPKEwapDLiYqykr4U3lj0UZ7Y78XZGTcMTCDMrKYKZorYPRyvG1/yi9wflyunIe5Ks3JUSWLd9NQg3i9v/KudfPYGKU7YhsQlnLs6fQT3jkWM8rYF7Jh3KrJt4L7XNRvPQ== 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=o+CRR3KqGqiFCW/LW3agU5S0hklOgfP0JdHI3EXYNx0=; b=bTikRg6awEQSZXWoIEzlh1/Q0eJ+GmDPvYwhyYTePf0s8B8+bpWnUQ4q3b/nFuFI73mDnZfRQ1C5Kl7AqIhE55HJy1s2LrBgR3PtgZ9uxl8BMnsbbe+abB7tzFShlRocx52JlG5hEGQNI1cOChI0PylE/8J9firvRcGWJA0UEQ8= 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 DM6PR12MB3915.namprd12.prod.outlook.com (2603:10b6:5:1c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.22; Tue, 24 Mar 2020 17:41:21 +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.2835.023; Tue, 24 Mar 2020 17:41:21 +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 v6 12/42] UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events Date: Tue, 24 Mar 2020 12:40:26 -0500 Message-Id: <9ddbd75ef76ea2a29fea58f8a2b444c91679fc3a.1585071656.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0025.namprd06.prod.outlook.com (2603:10b6:3:5d::11) 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 DM5PR06CA0025.namprd06.prod.outlook.com (2603:10b6:3:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.19 via Frontend Transport; Tue, 24 Mar 2020 17:41:20 +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: 067ebe94-91b4-43c7-6877-08d7d01a90ba X-MS-TrafficTypeDiagnostic: DM6PR12MB3915:|DM6PR12MB3915: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 03524FBD26 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(366004)(346002)(136003)(396003)(39860400002)(8676002)(8936002)(186003)(316002)(54906003)(16526019)(956004)(66476007)(36756003)(6486002)(19627235002)(66946007)(6916009)(66556008)(2616005)(26005)(4326008)(966005)(81156014)(478600001)(81166006)(5660300002)(2906002)(7696005)(52116002)(86362001)(136400200001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3915;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords; 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: O+bsKmK6KYHzcBznIKz1uJqkYTlZ+HRVw9NQqqp6TG6r1I9xW9GckoiP6DmG1xo/pa0OL9LlHQCogomg4z9YmbCBqJbVea3nNVRQpMtlB+QwanEIirwgZkDh/HzgwKH1v0o/BYQuSt4303FouOwKdLHcYPYEy63c6MipEk1FCh1TfaGUw/rgDJQMgFQaQ6ztbUwcJEo22HulU7tE6ftjaV36zRd99FCKFyM4/LSdFMkfGVubPD5ynht4HbmXaaJDndiSmeTIZ6nfSAn5rMrDg4bejzPoGhP+SDPNZPp6ErxmFt+aKzw4KR39VZbuybvooQCFs0zbIBG6SuIRzxONdBy+1W59FfVwqZ8dlHk+CDd09+j1KejUgzP+EmGfDIAja+LuVsxMg14EM4TCdkHOiPAqgQhzv4cnYUsL6DIdi9HcKWgoOZcIkBsW5+BtSONfzC+ZqTknU73XRNdog5K/My0ILFkON+d2tbLoATiFZYLwg+yGrwBGsrswRIzzquK6P32NgNkR7wDtulS5Uf30VmF57gT3xNHJ5OiI/Ho9K0Lg1QES7ifYTG3GXU/LOf5DU+WjeelaAPjoq62paXFTtA== X-MS-Exchange-AntiSpam-MessageData: h0H3hsz2dRdeU+Py6Y7SojvOoIelyy4hGAQ/MVGxW7OBlsz8RAfVaQohcyaaof2/IjF8Rxfs6mHlNPYOXlSikBTdumd0Vt6Bkf8nSMsKLhhULy2rZXnjIRvEvkYtCkTdJJBcpTHwlpDCro5GKXoEJQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 067ebe94-91b4-43c7-6877-08d7d01a90ba X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2020 17:41:21.3646 (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: uWB4XrQvw3ykLdXmETjCNjMWxC1Gz/jGuuap9+/5/VB72Us6p7PLZzFrvV1tgPwQJSjdR17SBXVMEwZpJChbYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3915 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 577dacfb7ca5..24f746f994ca 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