From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.13455.1574280447980323941 for ; Wed, 20 Nov 2019 12:07:28 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=C+qa76b3; 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=lImu1QUDstUYajnzGxf2SFC5/4nMwyabNMk3odUf44cgZzg2uwr8zfGgOrUA4VAxROH3a3gpUNZ++J6X0NCjhVygQFRJ+pdkpcGSnyo/MbrmUoYe1Lt1+wCh9cKM21sspvqhUb3q5OgGalf3Wd5Dq83ajtfsN3LFOUpfQYzWSgJTtHNR5DqWEpxkykt6t0mtZ5PLdxNgFHlxuxqxlhiVHHiJ4ZvYM/mfEhsQqFONQxXTi/gJK0UxTy9QL6R7v7Ol6ZOJS2ZXtDPO+5up76VWa7HGEkzMXFbRqclkZbmjWzcisUpp/mbEyaEz/Tw1F7GWwI94uRDKy47gX2zERSmMWw== 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=GWO7aXsRi6RyawU8qPncOP+g8pxt6GP85m2IFpZh5HI=; b=cThvOHi0SmVF8CFVT0/P3e16nadWiyIU8Jq0Ib311TqFaJdQfvX5NLvoOjwzUhqxFey3oOCq9xDrMqukY/PZFx2JpJfc2PTWIH58R2n5jw4BsGIP9O/N+SWyOEnGoKSaM54CwcPpFYqp3JHthQV1g54hm1EJ5ysa5e88/0tVnr/kO6CmJIY7JAjJhocoiegdhrChNLCe6CZLUhzZ1gCBzY+iG2us6KJkGMIqAqxlbAS5PVRGZlaiev/ksm7XHkRR0jyVJjopYNHeXqJvEuQY3a+qLk3MhL9gt+TENdRKbKrGxYcQWbbALYGkbBy4B3cTZd48ObHN27nIvrjvvuFFhA== 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=GWO7aXsRi6RyawU8qPncOP+g8pxt6GP85m2IFpZh5HI=; b=C+qa76b3pP+Xnd/2yeHp+90wCY+pypoeCJUEroNPCQoaiCb8ouxkLiapv2VUPd21i1aHCWmbyfBOie5E8JBFkMfvh4ZqR5je0aLO+XMDNEuGfdOep2woWiueV9kg46LpyV1OTWX5uhjJeq+9TUM6KMNcGJkrxeGa/KkU9yqIF8I= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3675.namprd12.prod.outlook.com (10.255.76.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.28; Wed, 20 Nov 2019 20:07:27 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4%5]) with mapi id 15.20.2451.031; Wed, 20 Nov 2019 20:07:27 +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: [RFC PATCH v3 10/43] UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events Date: Wed, 20 Nov 2019 14:06:32 -0600 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (2603:10b6:0:57::31) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 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: e55cf542-0231-4780-87dd-08d76df543f3 X-MS-TrafficTypeDiagnostic: DM6PR12MB3675: X-MS-Exchange-PUrlCount: 1 X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(346002)(396003)(39860400002)(366004)(136003)(189003)(199004)(2361001)(50226002)(81156014)(81166006)(8676002)(2906002)(6486002)(99286004)(66476007)(486006)(47776003)(66556008)(25786009)(2616005)(476003)(54906003)(11346002)(118296001)(8936002)(316002)(2351001)(7736002)(305945005)(66066001)(6916009)(86362001)(16586007)(3846002)(6116002)(48376002)(14454004)(478600001)(966005)(5660300002)(66946007)(446003)(76176011)(36756003)(51416003)(6506007)(386003)(50466002)(52116002)(4326008)(6436002)(6666004)(6306002)(6512007)(19627235002)(26005)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3675;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: B8rXLVvMhf6fyEiS7PmI8o2YFyixQNFcJveGLZPJZXNmGUBolBd+chYwKl6MFY+CcjtIdh/lp8Sb8pQ0vQYnGQ+CB6w9n9NS2rZcXMYIBTLTC02L0aXoS+bd48OvyjfBrUTexWfyyVOebdJPtDRph4KLuHhKY7Y/m6iOEIc5h2GrhWnnm5shl2Zr6WHpQpSIWNebLgqCoI/h56Bo1kLwUXtCwJ4dHc3kemcXJXvYc+I4HJ/abyAhyXhey9IU7ntKqY/FzkuyPkw1tE5O1C6oOI0UkztaRtvIGAbSVD0qS4WQ1X3MxEAzCAIC5L8KK3aNSLB+UHPxlm/WA2xkI3b9BDkgM2E1+GuoTjNJTP2DIPjGKZWG+dC3gf4I5Y+aMmr47MAz4xqepXWyrnXlzdjh0RVByUpWU/J2oE18g035/ILwzwsh7Zzyz8Ts2fNB93QiLpvG/As6b+/EGQ8vJ0+x0HDbJfGBPIAXthY1m51rqxk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e55cf542-0231-4780-87dd-08d76df543f3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 20:07:27.2572 (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: /ODI5GZ+PXy1eWaM6+inaBJquSlnN5u8ajk1lZKBqOgUuncD3fDWcjak8DzdJHfDrQkpZwL2qLL47mSffhKroA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3675 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/AMDSevVcCommon.c | 82 ++++++++++++++++--- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index c42fe632f255..98b62c21bbce 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -312,6 +312,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: @@ -349,6 +365,8 @@ IoioExitInfo ( } switch (*(InstructionData->OpCodes)) { + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -395,8 +413,9 @@ IoioExit ( SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1; - UINTN Status; + UINT64 ExitInfo1, ExitInfo2; + UINTN Status; + BOOLEAN String; ExitInfo1 = IoioExitInfo (Regs, InstructionData); if (!ExitInfo1) { @@ -414,17 +433,56 @@ 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)) { - VmgExit (Ghcb, SvmExitUnsupported, SvmExitIoioProt, 0); - ASSERT (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, 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)) { + VmgExit (Ghcb, SvmExitUnsupported, SvmExitIoioProt, 0); + ASSERT (0); + } + Regs->Rax = Ghcb->SaveArea.Rax; } - Regs->Rax = Ghcb->SaveArea.Rax; } return 0; -- 2.17.1