From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62992+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62992+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366388645590.6118391545702; Tue, 21 Jul 2020 14:19:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FSN0YY1788612xo8qgpRcyI5; Tue, 21 Jul 2020 14:19:48 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.64]) by mx.groups.io with SMTP id smtpd.web10.5598.1595366387629071851 for ; Tue, 21 Jul 2020 14:19:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cYJPcjRcjFdMvcgj+fSu3GxnkJL8Yu9qJyR8VZNm1TP7WUx9DFk3zgnpUyK8hnduNfjwFxVctk8coBMvSLOZDD2CDBYNzCEyZ3BaCky28yHngvWNEZknbx5MzVoPgVjeg39iDx/oT0y9Mjk5VsYr0hF47P5RaGwY7Hwm5XfGlh+H3Bke+vSvymvV39KYeJW0yLmQZeld0Qc6oVEBszcsjGOw4SdYYYjmHRqOU/X+iCwPr1UjsLc72Vpw1zRjrmkEdebSBu0wJ/jR6oNHLaKJOYqTQGCYIAPgluIDByHnbpjyCEBQFzWuJ3QrPZ1KItfwm1d9L4n5pqKzbGDvmW9F2g== 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=Hqe1rDuCswusit5U/Sbl9vY8AnSbuBv1xrlSJIgoLm4=; b=FJxdXEUHp/antCDQtsh3McekccFMB/1Jp0S+FfYhq310HPUVQqcK5gL54p2/fkrnvzJORQP6VK7oD9cB3zIWlZJ2ZXCkWPMckZ7CykWe4qjl08TW3uIOvwSo8Rwt/DmdeyjJIZyUmfXRnQfBwZ9sPFugVvVMiEGf6/HrhuP0sxh1SBgAi0gVyjgpmgCxc30kROcczUOtoo9AhwU8I34ZKVlwL4wEZeaGkPXXwO4Y+wgW6R1WXPV9TJYN/ztQbqEW7/w87zviGlMHzwEjYlZZ+QYrJacxIFyl2j92iN4u2fOPMue2ZaoxEdj4XgD9S7hGpK6SkRe47LdXroqp/8gNnw== 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 X-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:19:45 +0000 X-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:19:45 +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 , Jian J Wang , Hao A Wu Subject: [edk2-devel] [PATCH v11 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES Date: Tue, 21 Jul 2020 16:18:38 -0500 Message-ID: <0e4c84fc8f06d00ca2d13061153fd9a64f9e3b2c.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0012.namprd07.prod.outlook.com (2603:10b6:803:28::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0701CA0012.namprd07.prod.outlook.com (2603:10b6:803:28::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:19:43 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1a6e0540-268a-44a8-f07d-08d82dbbca48 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ZEsxHerXsjYsGmfXonSPwyVUX44WZJN4z3FhRACmQ6ycJ2F7efPdg4h17VbvOpg+k+XrZsdec2ixj5bEGt1D/HUhIm9TacdGgS4FG3UdOtwy12+TpFsOL0tZm9pehv3cXE7/Kp7rAomFMlyIJWuu3k95WkwEGC2TFmNBwStoCnM6bxGsxUcf3AjXGdDblJo7X7/yLYLhxkptLPoVGQHnzqbpOkeIJaimqzZGcrwQYyRJFoAsL3e3Pzlh556eSGOidbFEJVF6tog/+Db8Mny0T7U9dv7Kj9DvGLKbGhpL7jwqPS9zXp9dKWLo4bnkFcuezFJ9aIzCVrsPqaWkqLaWInNPx8OZ88OxPthjJGpms50jM5KmzUpf2UFaaujmyCBxlZrQtsm9TK3mMNtg8sv4C8SaHyAqTij0IuDsakuvZ5YhmhRzf1dDzAyyf0Ra+DkPwcUXkaOHwUSPJpd4//FCZQ== X-MS-Exchange-AntiSpam-MessageData: FczrwOCV9XewOn3Z/1RpD/mdV1ryTyENoqt8b8J9vcMOwoxT2u43KGwYu2XNIc8g+zK73yaQtMSNUVIxiQHWCSi0DYgEh1P9UsASuxXtPDgtHQyZfiRPplAmdAGbGpkE00b3HU96MW/43rg1H15mA5KxzijBoqAkLmRWec8EsRw7OwPC9r9KXgqARF9/yVHRmrzwbf31V8MYkcW4FBKeax7bSZAbwdQBlhEa0/yvLdtmfhisttWrk+8VRB2AAhGolz6/xU1Nqwru7ICQ21xdoEHjiqJrteEBlbsTCKiVgTChvZgwMG5pZAvFuggO5XPEhyO0zzgmIX9h1viIMAnffwg2My9om0k7ySHNJpq5X+ZtzXChEbgD5Vtj0sIba9tiXjsVyAQuqmq3fxtDLLrhLG96X7x3qdIS6PoSfff74S+tYjOHZt/73GvexXMNdOIWSnG263ShwJq4kjzdgSeHUUSDsGSfeQXwtp3cAz1uZsI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a6e0540-268a-44a8-f07d-08d82dbbca48 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:19:45.2395 (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: nGB1FUVYhftPwgGqyGjoQOP7rZqkjxkqXNGJt4ur+MOn9qnIS6bOGSY0jmrPuyU072vrrL+HqDH/qIWiRuYx0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 3npQKqJGQ7S8YZgWALVxDxSgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366388; bh=nQKbhrm2izv+51oxytsQry6w7qwzM9jgqUQQ3x1lFlA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=oSGYDATPXygTHpIAHpP6jwd2UEg1bcZ2MzmYYESmmDldnxOUY0qTdlRx+GuLzzzcNBb ggwbjQT/ILhYjMRkMNeoqZD7zPpYCagK3n8+N3PApQNf3g0y+vnxKWbsJ+l82uUylxcEM 9QPsuHZRZnK1Li4iQuOOX+XALfI/GRim3JE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Two new dynamic MdeModulePkg PCDs are needed to support SEV-ES under OVMF: - PcdGhcbBase: UINT64 value that is the base address of the GHCB allocation. - PcdGhcbSize: UINT64 value that is the size, in bytes, of the GHCB allocation (size is dependent on the number of APs). Cc: Jian J Wang Cc: Hao A Wu Signed-off-by: Tom Lendacky --- MdeModulePkg/MdeModulePkg.dec | 9 +++++++++ MdeModulePkg/MdeModulePkg.uni | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 843e963ad34b..f8cd9239b4ce 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -2051,6 +2051,15 @@ [PcdsDynamic, PcdsDynamicEx] # @Prompt If there is any test key used by the platform. gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed|FALSE|BOOLEAN|0x00030003 =20 + ## This dynamic PCD holds the base address of the GHCB pool allocation. + # @Prompt GHCB Pool Base Address + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0|UINT64|0x00030007 + + ## This dynamic PCD holds the total size of the GHCB pool allocation. + # The amount of memory allocated for GHCBs is dependent on the number o= f APs. + # @Prompt GHCB Pool Size + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0|UINT64|0x00030008 + [PcdsDynamicEx] ## This dynamic PCD enables the default variable setting. # Its value is the default store ID value. The default value is zero as= Standard default. diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 2007e0596c4f..2f8cca03e527 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1297,3 +1297,11 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_PR= OMPT #language en-US "TCG Platform Firmware Profile revision" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_HE= LP #language en-US "Indicates which TCG Platform Firmware Profile revision = the EDKII firmware follows." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_PROMPT #language en= -US "GHCB Pool Base Address" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_HELP #language en-U= S "Used with SEV-ES support to identify an address range that is not to be = encrypted." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_PROMPT #language en= -US "GHCB Pool Base Size" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_HELP #language en-U= S "Used with SEV-ES support to identify the size of the address range that = is not to be encrypted." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62992): https://edk2.groups.io/g/devel/message/62992 Mute This Topic: https://groups.io/mt/75713031/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62993+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62993+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366398915751.3406676151143; Tue, 21 Jul 2020 14:19:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id zFDrYY1788612x2k6CRtZkyO; Tue, 21 Jul 2020 14:19:58 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.78]) by mx.groups.io with SMTP id smtpd.web10.5601.1595366397837123202 for ; Tue, 21 Jul 2020 14:19:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A6/3rS/mRVTqRb1PixzVseD7jrFepucZ8KvSYOLvTQlLP9SIZ3ffsgdwChGv6VUP/FWNk6V50aFmk0puA7mFxrNcgGpSeuSqI+8utFrHTwL/QjC4CdXfA3wGlYc/lZlRzaQCUGNMKVIRo0WyLB1xeYPr+Sf+3oKOuZlX3kEE5WgRZhUEsPJyASCGKloQnT597q9kwFT7yzi/sGZLKSuznUcNMAaAPAJp/zMxCs0byxAyWsfFvR0+blyUTDp/NrSQf3ut8yFO57V1S/wmjXdAy06DtZFP4PU5R/OiKX9QkOBzPBb4FXibJ0zbQM5lwiH/Y6DApZQITfDSKkwSvunEVg== 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=iUIg1b4EwDhKpEO96e51MuPrwJUs/s5zD1/37hv4dng=; b=Qd9cYiSZbEgFRMpYYYub6MFK3aniPtyTznxLUi0439v5HLAcs6K31qdQ5yxhS6dPZumLgLfKETCP0zS8w1bvow48mKQ1P/1l42XlkznHOCG/i0SydqzO9MpmA64R/wbPVuM/vBSi+TauMl1YipXvn0upuT2I64y2wFJn945cA7GPRsdGFSyuz6ARRgI09f4o8VrjHtHwB8oFn/p1QZKpiF9BrC/cRsm/xrIf9huxxrDJKO7MeRLkKHC22YUGVVMSupq2l8SYG2HTp7xiBkqcodyVjjmrmVPTk/gNr/HruC7coZ9JPwhJEFhw+sAUvLYUwSPYORIwQ5CtQbqx210cpw== 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 X-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:19:55 +0000 X-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:19:55 +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: [edk2-devel] [PATCH v11 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES Date: Tue, 21 Jul 2020 16:18:39 -0500 Message-ID: <05dee7b7fcdf2fcfb748008dff2ce9dbff3df7ce.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0035.prod.exchangelabs.com (2603:10b6:805:b6::48) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR01CA0035.prod.exchangelabs.com (2603:10b6:805:b6::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.19 via Frontend Transport; Tue, 21 Jul 2020 21:19:53 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a971a3e4-30ea-4a85-a934-08d82dbbd088 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: qqx+c4rgxT2MbSTYhHODZIyLR1R06X84boPaI4WskY0+1EOOO8bw1sjGcvCbCxkNC8bIZGfh+QIeoQ3cjGak8aUUawR4EeKQdjHPas67crrn/0vaIJv3K87RLxqVVrhOXdGG9BG5yWeH0ZmKbqG+bnm5zGqEZ2XPJx3zbbJCrLrcZ4zFviVXrMGYTr6GicXfc8Vwje2uvZ+v3B4dDA3ihyd/oIMSCtmD5LB5G4lVLaWmIiGjWPtvJAX5hU1GIwcpHouqeK3HFkFm9TzjHaL0aWO1jOPgm2BZnU0D1NtaBRB5F7QLvuS+OWWr3A6oquM0vTGkzBueDUj2aD0tOqhz9J0IkiE0VLdDM5g8GcFyY01kjUQRDFWIp+1QZoWaK9Sv9wG2DqNPh+0DBPbsGBBbcRO61lgeAQfUpgw3JhYKLREXbcJb6efRMkluf5jexL6TBMUj6vmR0vmVwy2JPs5/YA== X-MS-Exchange-AntiSpam-MessageData: ocw1r8IACKeBBZdPPbXe8HUVp9Su1Tz8msBcmOiFMZib4/5wym1eFVg1RB/iFIAQqRZsmE1xT0Z04Czey1GsIdoO8724sVZR5Psk5r92KWi2NltSH9jtwO3GwFJAaPf/+ZLdzY3tZeWXPkvGoxnw/0gfZnyYC7vNF942/evHOPiiOBW62n+cP4JUBetW6FzDFON0ZXrWekTNVpTi9jVlj3/JarrzjNOYz7SyUWEzH223mhHdRGs5D0sM+LmdL4vuGkeLsOthg1MMaFHM2s3fvR1aX3GxhCxDeFeflcYc9sQ2+fOuv4Is1Ow14fRksPJQLl9AJit/DBYqhZAOj4FQsWhU46KB8gYaDkL2bk2gb8Du7US4vEHbw5TUYrQIXM/yngmkJo15gp58Qro4+tF+UI5EwR/jL+3uVBDPgVJYv2240GZ8ogmf3EIn9bg/BsNpRMOHgB1y4VRWALLlCuabtfgCt4eZgRPZ0Y9e6eMRnbo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a971a3e4-30ea-4a85-a934-08d82dbbd088 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:19:55.6295 (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: YGbheQZNFljo0O5erZN3uoB2bfRy5vNpGg7LjUKBQG7e0GDMcDtPXSxz3VElh/hx8+0B9b5N79HTk1SfF+0OLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: rfbTmmCzCbtfsBmcGfb93f26x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366398; bh=THBnvZfd37vhuOrqNY6Q4qDcAZl28UwI88nZcuay9CE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=XizDfkaxSzW0f1/GFiDrskCxUZsd0SP/FcY/NjqtHzR6bQe5WPEJLs3DC9l/+dKKLkz Jh+iC9teROwz+67h1dovPJaZ7qtmJRLtNqZMsqmKPxmXUA/UHlcJg38BTaFkW2pmLIQMz 58A5NPbiSOUlX28XeiMKr/5OXM+OCipTEvs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A new dynamic UefiCpuPkg PCD is needed to support SEV-ES under OVMF: - PcdSevEsIsEnabled: BOOLEAN value used to indicate if SEV-ES is enabled Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 6 ++++++ UefiCpuPkg/UefiCpuPkg.uni | 3 +++ 2 files changed, 9 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 762badf5d239..df5d02bae6b4 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -370,5 +370,11 @@ [PcdsDynamic, PcdsDynamicEx] # @ValidRange 0x80000001 | 0 - 1 gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme|0x0|UINT8|0x600000= 15 =20 + ## This dynamic PCD indicates whether SEV-ES is enabled + # TRUE - SEV-ES is enabled + # FALSE - SEV-ES is not enabled + # @Prompt SEV-ES Status + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|FALSE|BOOLEAN|0x60000016 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index 1780dfdc126d..f4a0c72f6293 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -278,3 +278,6 @@ =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSe= conds_PROMPT #language en-US "Periodic interval value in microseconds for = AP status check in DXE.\n" #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSe= conds_HELP #language en-US "Periodic interval value in microseconds for = the status check of APs for StartupAllAPs() and StartupThisAP() executed in= non-blocking mode in DXE phase.\n" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT #language = en-US "Specifies whether SEV-ES is enabled" +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP #language = en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62993): https://edk2.groups.io/g/devel/message/62993 Mute This Topic: https://groups.io/mt/75713033/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62994+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62994+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366407287828.7859019702322; Tue, 21 Jul 2020 14:20:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5NrbYY1788612xMAJ4Gtjq31; Tue, 21 Jul 2020 14:20:06 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.86]) by mx.groups.io with SMTP id smtpd.web11.5477.1595366406360363975 for ; Tue, 21 Jul 2020 14:20:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oGbNGK/dxYTciZCq350u71zQtIyWuo66a/46xPA7DkAS7kGdFHekgLT/o+XCwyoY3r1zYWmNCxg9Tnu/ArLR9c8MIlrQAW7xj/PWtCa0ZklXp1Lq6pYf5WzkSDuzIJHbTvCYxrCe0WangIpoMKEkTgiXrpGOGd9Ga+kL609mwBjPQi8NNWuSHdiS+WL6VGYYISuHkWs37ch//J/gkJMHMchs/J3eIpyzM50k8m3zWc89BgYOjqwMQU0eDdGuzymGnjnLq7HL5MQjr+bD5p5OG3mGcldY8fkNF6gGBSGT4gIFBbdQ8VujnukDwAvBfkEymFbFHXF3uUM5SC/zvLEzsg== 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=zoB4WdNcnMndSIE8frIBiBw/orhv555JRD+2P5oKvXs=; b=YvvPlXhoKWVJ2mOutxIJNvf9M7Y2Kh4ADFMVRiS5pY6fXoVoeklD77qBuBFXID7DJf/dz4NK8rX40T02ihsSJR37psWam2SebF/KkArK/Qk6cIZsGJZqZvbkaF9S1FUZ3u8v9XmyydpU8NBTLMbdhceAiKpw6JefZLvUcqW2QOo1E2tSfhsEFRSYGzdavhA+zkBpZ01xxhNCXb51Oj/is+6YSVEcRSyDgIhmF3hjuZlCtf7NmFKM5CxjJ04c9S5OVQzee8d4cNM526q8WHmmRizbUVKf5mRKNlkgu21P5sCD/ewA53OfzbpD85XXfppyy28IGG/cmsxtvPkIeBZBDg== 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 X-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:20:04 +0000 X-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:20:04 +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: [edk2-devel] [PATCH v11 03/46] MdePkg: Add the MSR definition for the GHCB register Date: Tue, 21 Jul 2020 16:18:40 -0500 Message-ID: <74e9ee3de48dfe101aebdebc0304e002a88e74f7.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR11CA0020.namprd11.prod.outlook.com (2603:10b6:806:6e::25) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR11CA0020.namprd11.prod.outlook.com (2603:10b6:806:6e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:20:03 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 964d01cb-352d-435d-e845-08d82dbbd5b8 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: lOIj37A+8RH451HV1SOU8JVXL6MoJ2UFChQ78xuQn3jw2f7rhKO/oxcz6JzBTKlbfRcZrvqTnLHM+cqDAP3bZIhfGjOIWYDiMa++r21USJT+b/4z/ucH237uUWLcY5DzBYxgHj1Q8k0yuh7DhmQziQx8hfcoQuNh0IvFF/LxZFSx6/sPSuoGt8IxecM7svqv2uY/XnmBek11UtLNK/BX6N7AdhJk0pwYWzC6O70tVJaS40Mnam0e/IdunDGkeed4zWY5O4YkLznJImLAnclsAv0IRkmlMEDGRYPfw0wH8roZIi7KHi10e+sWEWCi2S0D83pWDUzPk4OxQ47tm2OpZ35C2MSwiVvQl91BW9rZbzn21G6Es5viaFbeDEwzrVZy+DHmkX5HOOnHtDlBaf2w0kU2RbsxKZZqbuYuuOjCMUklB9fIlbpkrUKICSb5Kvti0ne6rdvAapn5G6NSSfYqlA== X-MS-Exchange-AntiSpam-MessageData: VIu8Lrnba0IVw2UCBrncOk2CK3uM/5kw2fXMXG8LoadC+Ryu0MOz/VKhBnPw0ZNQmHXIzJMTWlb9EqWyDhW96pkXO/vCZSsh1eKCl+tBMKiq6MrRJi2A+BjeTydfq0k583G9pkgxI2u/EnJuYdwDj70kS5PdfT3UWtGfqnAHeyxjX4m8QnxJGAOT0/LuLBQkbtw0Q3467SCGgsEMmgE6R14hE5FieZ/JATix/GMO6sOPPIPUov+XnbgRnjt6So5zrwqDWkTDipFNWPNDmhdB3ecjeb41hoWCfU1AmdRzCUu5crhVVPlP0P4Bj2SEph80Smr4iYU15QO+5IQ80seWcc9y61l9qw8bhrxjw0OGkPnEbxB7mj2yvuRlrTXkM+301Vc5xc5lQaCPznJGGTJmubAL5ebr0aGTejiL+LtrpWn0LPDrQzqXD1qASlbA72Bb2Uljj0AKIOXUXJLvYij4DsbnJlm+BAH5KcS/oxWJ2Fs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 964d01cb-352d-435d-e845-08d82dbbd5b8 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:20:04.3833 (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: /Isj5RdKSoVYkrPYdlseribeaotoYMLskt7X9AkvGRVLaPR4qIk7hsiJabUeNELfICO9yRX0zglyRnP6pXO/ug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: uXT5vuqQ1DAlesKL0SKyfi7ux1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366406; bh=ku+aqtelBwBmqC7+ObJDnZuN5JbkYdB1f/KIC8mIAZQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=T64QHlTRiNd0DjlEUxhXeT2WzUId/zAX4KlVH39VpvyPTrlp52n35FdZvkvEylrz8+K fmHkt/NHaWxY4LONv76bvw3yk0jVH8AN09fv4+07PQAusZgGI3gPSp+zycw58nh/SNB1E lmtL0taReyh+fumagwqtrYmyl7HhGnFkXVM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 For SEV-ES, the GHCB page address is stored in the GHCB MSR register (0xc0010130). Define the register and the format used for register during GHCB protocol negotiation. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky Reviewed-by: Liming Gao --- MdePkg/Include/Register/Amd/Fam17Msr.h | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Regist= er/Amd/Fam17Msr.h index 6ef45a9b21d3..e4db09c5184c 100644 --- a/MdePkg/Include/Register/Amd/Fam17Msr.h +++ b/MdePkg/Include/Register/Amd/Fam17Msr.h @@ -17,6 +17,52 @@ #ifndef __FAM17_MSR_H__ #define __FAM17_MSR_H__ =20 +/** + Secure Encrypted Virtualization - Encrypted State (SEV-ES) GHCB register + +**/ +#define MSR_SEV_ES_GHCB 0xc0010130 + +/** + MSR information returned for #MSR_SEV_ES_GHCB +**/ +typedef union { + struct { + UINT32 Function:12; + UINT32 Reserved1:20; + UINT32 Reserved2:32; + } GhcbInfo; + + struct { + UINT8 Reserved[3]; + UINT8 SevEncryptionBitPos; + UINT16 SevEsProtocolMin; + UINT16 SevEsProtocolMax; + } GhcbProtocol; + + struct { + UINT32 Function:12; + UINT32 ReasonCodeSet:4; + UINT32 ReasonCode:8; + UINT32 Reserved1:8; + UINT32 Reserved2:32; + } GhcbTerminate; + + VOID *Ghcb; + + UINT64 GhcbPhysicalAddress; +} MSR_SEV_ES_GHCB_REGISTER; + +#define GHCB_INFO_SEV_INFO 1 +#define GHCB_INFO_SEV_INFO_GET 2 +#define GHCB_INFO_CPUID_REQUEST 4 +#define GHCB_INFO_CPUID_RESPONSE 5 +#define GHCB_INFO_TERMINATE_REQUEST 256 + +#define GHCB_TERMINATE_GHCB 0 +#define GHCB_TERMINATE_GHCB_GENERAL 0 +#define GHCB_TERMINATE_GHCB_PROTOCOL 1 + /** Secure Encrypted Virtualization (SEV) status register =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62994): https://edk2.groups.io/g/devel/message/62994 Mute This Topic: https://groups.io/mt/75713037/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62995+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62995+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15953664153361005.6277092954249; Tue, 21 Jul 2020 14:20:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Y7ySYY1788612xQ2FZ920W8a; Tue, 21 Jul 2020 14:20:15 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.60]) by mx.groups.io with SMTP id smtpd.web11.5484.1595366414351612001 for ; Tue, 21 Jul 2020 14:20:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E9vyBT1tABdN2dNz9zvWunyxfj5MuvT9Bww9ho/KLCj4kKjS7DWJcr13/QjnOsu6IYmq7Vvl7BAbKJZbtRwNpF9fu4RZc2l+j1U2BiP8MOJNvMlfQWrrnFuWkvx7z6Y1hL/fCOOxXou3/fyp5uyPPBgUG68qBQsnv8yn9KsBMeXAvX5MZAg4ZuHEuGR8PwJkjQ8TpW1LcUFzWFCldxPSP3GhZLBFMJ5oZm8jhyTS5yDrksSArfI5NdEfCbLq2HYiGjNOA+Ed3QQaUBSi1tF4dSSXDdIOT9C3Ly012l6XGwUjIOSJAsvYeDir9/9fp+ZzdYPymBXI2wZXIQNWuNnnjg== 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=ZgE2Sj67C3LtS3PnR3u+8JIYDmbxku5n7Xkbew9f6S4=; b=U+Xa9498Lm/1RxJBO6AiNmHsLM5s2z4LVLfaSRx+XaoLqDEdcYZzHwN/ols4d20tujOBSmUcVNmCMy9sC4XTbTsIT2VxmNl9A0VSDtUNZaDgDgickRMXc89I2iI5Fs2Il/UU+JWSv42jNt7Zk0Ovw2bPsrNFqtEZK6ENRBHTwec9YFNGEROS05R/X3qrAAvzCj7dcVTcDJeo49OP5mz1vcjYsNLbpV7DHjRfFyzSSImacWXLBRI9z8M6PSVRmVC+eJN7l9QEL6D0uaKBsBrcrvcQJ2bXJyXX7QJ/tCxJHOdRfsgJkY1PdKlJTrZU645Lwj10tJI9cux6JowjrEEXVQ== 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 X-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:20:12 +0000 X-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:20:12 +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: [edk2-devel] [PATCH v11 04/46] MdePkg: Add a structure definition for the GHCB Date: Tue, 21 Jul 2020 16:18:41 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0085.namprd12.prod.outlook.com (2603:10b6:802:21::20) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0085.namprd12.prod.outlook.com (2603:10b6:802:21::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:20:11 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5db250bc-e55f-4eb0-6e0e-08d82dbbda71 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 09pgCt4QfL6cUDH3UO2MAhEUk02yG91ReQx/5r+MT5gRr5geJX5lyyCjRmb9EDQvl+kpcLLF/xXR7RKNoR2pNXcu3idDoG1Fl4aOioVzGxkGkwp8V0EwrFnjHmsPpuB4UmUOMc3nK7o6u99/kAmwl2cjJg42UA2uzsvKI/MGWmYI92GtU5YVBtEKGr5fc450uQC5c/AkfSmImAmpUay8rX7yvVIA6y45LOMxXf+lNP7Y+xNUWd9HCQZvwzuNpFju07bInmZXi7vsolE2tI7VVBdIkzNTUI9Tj7T1q7RQWvntwdb4+/p2dvfC/t9HJXIeEBaGK7ZxneA2csF90PRB7B1yjqRaU4vSKck/YabpbbRCGlG1+Y+1CH/YyoY7Jiwb0DWYipYKXGp5Xj1LqhSYmdQzSbJCly3v10yRUc1JquMLgYscGyUGVareOcYP3oWcSz+7E0iykhngHtff2nLaBQ== X-MS-Exchange-AntiSpam-MessageData: R8LSveSJVp/A9ufAHj6dojJxXuMUFDAYrdL19DLiLy87eKdAiiaJ18w0yciVYraO6vCkIadwA/RCO0LyhjxHm5mmBnOOk19cV0L3ovATcHnj7nU9VLf/4FtA7683Yazza91xULs88+/KCGJsRVwPx1uWxy/AAxL4FmAmPC/XibNfFt+CR/4lWjevMCEvkPj8G63nfJqpzB6UxKMm9HvP3nTjvHBXNM6xv9eJysy4ZuZp9ySKUQltky3d7UN4y3+qlTgqXjXlLe5XPPGQHQJQ8pfwmv7999AFsSl9pHkkTv5bODZD8NQ1g9O9qhsSFUoGb4HepPJ1Lvtz1LdmYF4h3L9CC6xdQct02zmTXXn9qyeoDIZ5xlM6n7bOBAkWYsZIeMsbt+kwxEN763sfb2SAlZcxpsHdSgX7F6M0vgidGWRqXb1PutyQ/dPiRlfNemizytWOovDV0qdHYtFvbODsfB9qsQWFIezkZvcMGApcMk0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5db250bc-e55f-4eb0-6e0e-08d82dbbda71 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:20:12.2505 (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: KT9r3LIVD4aI+oKVzM5Wc50aWaN+Gb2P1kwaDiptuV3HaGVuzaMmKpP4W5YEw2EgQKA6TQLwNAFEc39qmTpUnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: D94eOOjkHe2MICXBqC0GUStSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366415; bh=a17b89xV2z7PAqRFdIAma1i7SznNHpGP3JBc9k6Cqek=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=dkNc6JNzHikoZV3NAFd0suML+qiMxZuEDghaNTsAM48v03X0569Mwca+fMEVICVgST/ ddgozdrwPDXdnwEpf4PtNdoUwNKREMi70Za+19otAeXB+DwxIdspGz2/DtqOwQPWyDSor 59p0NwRe+34mCwSFzXois/axf8nHMWIh0M8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The GHCB is used by an SEV-ES guest for communicating between the guest and the hypervisor. Create the GHCB definition as defined by the GHCB protocol definition. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky Reviewed-by: Liming Gao --- MdePkg/Include/Register/Amd/Ghcb.h | 166 +++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 MdePkg/Include/Register/Amd/Ghcb.h diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h new file mode 100644 index 000000000000..54a80da0f6d7 --- /dev/null +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -0,0 +1,166 @@ +/** @file + Guest-Hypervisor Communication Block (GHCB) Definition. + + Provides data types allowing an SEV-ES guest to interact with the hyperv= isor + using the GHCB protocol. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Specification Reference: + SEV-ES Guest-Hypervisor Communication Block Standardization + +**/ + +#ifndef __GHCB_H__ +#define __GHCB_H__ + +#include +#include +#include + +#define UD_EXCEPTION 6 +#define GP_EXCEPTION 13 +#define VC_EXCEPTION 29 + +#define GHCB_VERSION_MIN 1 +#define GHCB_VERSION_MAX 1 + +#define GHCB_STANDARD_USAGE 0 + +// +// SVM Exit Codes +// +#define SVM_EXIT_DR7_READ 0x27ULL +#define SVM_EXIT_DR7_WRITE 0x37ULL +#define SVM_EXIT_RDTSC 0x6EULL +#define SVM_EXIT_RDPMC 0x6FULL +#define SVM_EXIT_CPUID 0x72ULL +#define SVM_EXIT_INVD 0x76ULL +#define SVM_EXIT_IOIO_PROT 0x7BULL +#define SVM_EXIT_MSR 0x7CULL +#define SVM_EXIT_VMMCALL 0x81ULL +#define SVM_EXIT_RDTSCP 0x87ULL +#define SVM_EXIT_WBINVD 0x89ULL +#define SVM_EXIT_MONITOR 0x8AULL +#define SVM_EXIT_MWAIT 0x8BULL +#define SVM_EXIT_NPF 0x400ULL + +// +// VMG Special Exit Codes +// +#define SVM_EXIT_MMIO_READ 0x80000001ULL +#define SVM_EXIT_MMIO_WRITE 0x80000002ULL +#define SVM_EXIT_NMI_COMPLETE 0x80000003ULL +#define SVM_EXIT_AP_RESET_HOLD 0x80000004ULL +#define SVM_EXIT_AP_JUMP_TABLE 0x80000005ULL +#define SVM_EXIT_UNSUPPORTED 0x8000FFFFULL + +// +// IOIO Exit Information +// +#define IOIO_TYPE_STR BIT2 +#define IOIO_TYPE_IN 1 +#define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR) +#define IOIO_TYPE_OUT 0 +#define IOIO_TYPE_OUTS (IOIO_TYPE_OUT | IOIO_TYPE_STR) + +#define IOIO_REP BIT3 + +#define IOIO_ADDR_64 BIT9 +#define IOIO_ADDR_32 BIT8 +#define IOIO_ADDR_16 BIT7 + +#define IOIO_DATA_32 BIT6 +#define IOIO_DATA_16 BIT5 +#define IOIO_DATA_8 BIT4 +#define IOIO_DATA_MASK (BIT6 | BIT5 | BIT4) +#define IOIO_DATA_OFFSET 4 +#define IOIO_DATA_BYTES(x) (((x) & IOIO_DATA_MASK) >> IOIO_DATA_OFFSET) + +#define IOIO_SEG_ES 0 +#define IOIO_SEG_DS (BIT11 | BIT10) + + +typedef enum { + GhcbCpl =3D 25, + GhcbRflags =3D 46, + GhcbRip, + GhcbRsp =3D 59, + GhcbRax =3D 63, + GhcbRcx =3D 97, + GhcbRdx, + GhcbRbx, + GhcbRbp =3D 101, + GhcbRsi, + GhcbRdi, + GhcbR8, + GhcbR9, + GhcbR10, + GhcbR11, + GhcbR12, + GhcbR13, + GhcbR14, + GhcbR15, + GhcbXCr0 =3D 125, +} GHCB_REGISTER; + +typedef PACKED struct { + UINT8 Reserved1[203]; + UINT8 Cpl; + UINT8 Reserved2[148]; + UINT64 Dr7; + UINT8 Reserved3[144]; + UINT64 Rax; + UINT8 Reserved4[264]; + UINT64 Rcx; + UINT64 Rdx; + UINT64 Rbx; + UINT8 Reserved5[112]; + UINT64 SwExitCode; + UINT64 SwExitInfo1; + UINT64 SwExitInfo2; + UINT64 SwScratch; + UINT8 Reserved6[56]; + UINT64 XCr0; + UINT8 ValidBitmap[16]; + UINT64 X87StateGpa; + UINT8 Reserved7[1016]; +} GHCB_SAVE_AREA; + +typedef PACKED struct { + GHCB_SAVE_AREA SaveArea; + UINT8 SharedBuffer[2032]; + UINT8 Reserved1[10]; + UINT16 ProtocolVersion; + UINT32 GhcbUsage; +} GHCB; + +typedef union { + struct { + UINT32 Lower32Bits; + UINT32 Upper32Bits; + } Elements; + + UINT64 Uint64; +} GHCB_EXIT_INFO; + +typedef union { + struct { + UINT32 Vector:8; + UINT32 Type:3; + UINT32 ErrorCodeValid:1; + UINT32 Rsvd:19; + UINT32 Valid:1; + UINT32 ErrorCode; + } Elements; + + UINT64 Uint64; +} GHCB_EVENT_INJECTION; + +#define GHCB_EVENT_INJECTION_TYPE_INT 0 +#define GHCB_EVENT_INJECTION_TYPE_NMI 2 +#define GHCB_EVENT_INJECTION_TYPE_EXCEPTION 3 +#define GHCB_EVENT_INJECTION_TYPE_SOFT_INT 4 + +#endif --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62995): https://edk2.groups.io/g/devel/message/62995 Mute This Topic: https://groups.io/mt/75713039/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62996+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62996+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366423921100.96241497729022; Tue, 21 Jul 2020 14:20:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id j7wAYY1788612xazL119KSlC; Tue, 21 Jul 2020 14:20:23 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.81]) by mx.groups.io with SMTP id smtpd.web11.5487.1595366422889538654 for ; Tue, 21 Jul 2020 14:20:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0HvAYGsewo1cgf89zHZmzbmmch8lOZECmL0Fm8GU1km1Pvlgh4HbI2yiugxsE1Jg5A4BJf4ITn53cgqMgVXxTRxXw4suj7MfU4V2mkuIrhkl5XllavklldqvUCpNNYY0RHH295TGaqV5vuKcbzbwaIRqpCwLTX+y/gpMGm9qqkhTC7HoNfo5gtyycbE3YsI8Y+kydeDeg+nv70CjBFYVcebgk+GNnDoXF2rB8+AuGFDSfrleArUYy+YlzGXdCEje4XU4sSQqF/W5QG3khJ3IDUwMgq2FHjGRG9yTHsN70LRf0Xus05XNRFv2ZVXPK4xsZXol4SjLLSumu0Xh3/Utw== 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=1CQV39IMQU98kDP7Cw8EBWMcqMw2WdJpQzO/hKKOH84=; b=nZ484ppqIxDKI/tRrMPaWMUn8N8/RhtnN5YYGcTq2cHXJKevN+qmug0t0Ur5hXZPkVHaYWYUl+XE5nPf8RqiSDb64RNogyr2ar6q+nVjD4M+rMsWQJuyZOTfWIZ4sC3OrfFLtzdW1GKHH14Liixhxwj91eYCzCK+a2j6nyaww8HEo0Jia9W2adtLPJIHuELfz3UMU+ZKIiU/DkGaAHoCjsmaGAkAwuMfD56rK0e/0VEW+MUvEZI59R+xd1kS2cP8/BAF1u0aHA36RBZMspoUv9J04Kj9YZjY75rm3Jq3jN2+sVYOj9ZYtZ3ya4dQIpPWMf0Bf8/xtN2lh7Kos/4qFw== 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 X-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:20:20 +0000 X-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:20:20 +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 , Jian J Wang , Hao A Wu , Dandan Bi Subject: [edk2-devel] [PATCH v11 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Date: Tue, 21 Jul 2020 16:18:42 -0500 Message-ID: <7906100a601e5c6b45eeda3f99d08a6f2137382d.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0012.namprd08.prod.outlook.com (2603:10b6:803:29::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0801CA0012.namprd08.prod.outlook.com (2603:10b6:803:29::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:20:19 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 28e6dda2-59c4-44da-77c4-08d82dbbdf61 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-Message-Info: 8EplxofM2VG8afP0IMOy+R4aCw84NfzF+EVat89j9Sdd+6GSkOHQmPIN4dSWdhZJuyLmeg/X1fuVRLssg4BF5IxEIzAou4t70szSuj1VufqY4zzyXvgkZuV3arGWy5Q52lDvjGAr+IbOULuPa7WlESVeQbCdpPJIEmExhNThCeOMp6FcFa6+xQZw4uYGJUJKHyDl2wSRJVLWvFbpnZQTw9leK3O6BDaF+E7KvVCqJzbEx4oqcIHNv00vAsKW0DXtGl6RCsPKtlLUSONVeA3kcFqHVWY0PSN/vN6aLgRy1do4BxMXFU6lqQMzXSdIh0S6aY50HYQrF0fLXVgOjai0WATWQQ3ukzr1iY8Wc5Srzzjrz01YI9DyQ2etUsVykM62tpsHYJLpfMIiO8PjHGNyZxVeBPyXDSRRYbIq0a0ADDEeBiwI1rn8rZxqaOjE4tF5+QuYa8dC0CEMGG9+J0xfmg== X-MS-Exchange-AntiSpam-MessageData: awQcJdO6SS5qj6ZP0zeLjCJfOCckUD65M6fB7fB3mytlyaBn6iRgk2CKxUm/JEQalACi4wkuAnmMRrQ/URjpZM2YoJcWEKV8zdI+JTYUpHsm4jfFSEgZh5Loe6PiS0uv2YgRQWhkxCoLrVvrkhZojHH3T2BI4gZfAv3Mij2oHG1EtN3uuqlXVam+srDVCi8IFEADW1mqJyGkM5fsApsJzVOhaXotJEp3LmQz5z32NSNdxiLiuBobhApGOJvnnBmwLy3/MW+fuF/vwGl3spiUrCkpie8D/7oRx/4BwKlqvkmro5MQxjPF+WrSCN9n2pXtT1rEaa/GutuXNynbd2tVGb8fkF1UpDb6+IPDCKZXEIW4JfJ1ow6iSJNEe/n/vr8vkb4lAolTKnCvPxZZK3/HgQmj8irCQ9EnrDRNxseqfcXeeYslHHylKfjQChcVVibiYAnkXQa4NgTPPBE2MbHVJmyBm1gktOaqNPgwFwmtnuE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28e6dda2-59c4-44da-77c4-08d82dbbdf61 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:20:20.4325 (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: 5VYlXAJEA2vKuK5jgka9ROTnKK0CQFWWxXFc7q8jNKt71d0wKy++E8PSvRX8IIh5T1HFeuxLVEVm1IiwCjE9pg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: UYgsJ8GzCATd4SPwM7zfSwPEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366423; bh=S99L/MIgoI2FhyDquNGivVsC+ROL6R0v2haZdUgCikA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rNlzGpEbgsXIoB37iqCbMWzdZGBpMSrV0gZJQy2iGR73OgcxXbFF6DxVj3dzCyELyxF V4ogBIgbHtCMAS+L3JPrJ4VersIj0BiUE4F/stpq9opdfmFcV7/Q0FWmuM8NFWsuSLDPm G+bpeXdWkmHzu8ssKCZJPYA5ekVcqnl5KXo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 GHCB pages must be mapped as shared pages, so modify the process of creating identity mapped pagetable entries so that GHCB entries are created without the encryption bit set. The GHCB range consists of two pages per CPU, the first being the GHCB and the second being a per-CPU variable page. Only the GHCB page is mapped as shared. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 2 + .../Core/DxeIplPeim/X64/VirtualMemory.h | 12 +++- .../Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 4 +- .../Core/DxeIplPeim/X64/DxeLoadFunc.c | 11 +++- .../Core/DxeIplPeim/X64/VirtualMemory.c | 57 +++++++++++++++---- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 3f1702854660..19b8a4c8aefa 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -115,6 +115,8 @@ [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable ##= SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.h index 2d0493f109e8..6b7c38a441d6 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h @@ -201,6 +201,8 @@ EnableExecuteDisableBit ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -208,7 +210,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ); =20 /** @@ -217,6 +221,8 @@ Split2MPageTo4K ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 @return The address of 4 level page map. =20 @@ -224,7 +230,9 @@ Split2MPageTo4K ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbkSize ); =20 =20 diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg= /Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 6e8ca824d469..284b34818ca7 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -123,7 +123,7 @@ Create4GPageTablesIa32Pae ( // // Need to split this 2M page that covers stack range. // - Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, 0, 0); } else { // // Fill in the Page Directory entries @@ -282,7 +282,7 @@ HandOffToDxeCore ( // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E); + PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E, 0, 0); =20 // // End of PEI phase signal diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/X64/DxeLoadFunc.c index f465eb1d8ac4..156a477d8467 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -35,6 +35,8 @@ HandOffToDxeCore ( UINT32 Index; EFI_VECTOR_HANDOFF_INFO *VectorInfo; EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; + VOID *GhcbBase; + UINTN GhcbSize; =20 // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. @@ -81,12 +83,19 @@ HandOffToDxeCore ( TopOfStack =3D (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_= SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); =20 + // + // Get the address and size of the GHCB pages + // + GhcbBase =3D (VOID *) PcdGet64 (PcdGhcbBase); + GhcbSize =3D PcdGet64 (PcdGhcbSize); + PageTables =3D 0; if (FeaturePcdGet (PcdDxeIplBuildPageTables)) { // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE); + PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE, + (EFI_PHYSICAL_ADDRESS) (= UINTN) GhcbBase, GhcbSize); } else { // // Set NX for stack feature also require PcdDxeIplBuildPageTables be T= RUE diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.c index 516cf908bc88..6831946c54d3 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -181,6 +181,8 @@ EnableExecuteDisableBit ( @param Size Size of the given physical memory. @param StackBase Base address of stack. @param StackSize Size of stack. + @param GhcbBase Base address of GHCB pages. + @param GhcbSize Size of GHCB area. =20 @retval TRUE Page table should be split. @retval FALSE Page table should not be split. @@ -190,7 +192,9 @@ ToSplitPageTable ( IN EFI_PHYSICAL_ADDRESS Address, IN UINTN Size, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { if (IsNullDetectionEnabled () && Address =3D=3D 0) { @@ -209,6 +213,12 @@ ToSplitPageTable ( } } =20 + if (GhcbBase !=3D 0) { + if ((Address < GhcbBase + GhcbSize) && ((Address + Size) > GhcbBase)) { + return TRUE; + } + } + return FALSE; } /** @@ -322,6 +332,8 @@ AllocatePageTableMemory ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -329,7 +341,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress4K; @@ -355,7 +369,20 @@ Split2MPageTo4K ( // // Fill in the Page Table entries // - PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K | AddressEncMask; + PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K; + + // + // The GHCB range consists of two pages per CPU, the GHCB and a + // per-CPU variable page. The GHCB page needs to be mapped as an + // unencrypted page while the per-CPU variable page needs to be + // mapped encrypted. These pages alternate in assignment. + // + if ((GhcbBase =3D=3D 0) + || (PhysicalAddress4K < GhcbBase) + || (PhysicalAddress4K >=3D GhcbBase + GhcbSize) + || (((PhysicalAddress4K - GhcbBase) & SIZE_4KB) !=3D 0)) { + PageTableEntry->Uint64 |=3D AddressEncMask; + } PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && PhysicalAddress4K =3D=3D 0) || @@ -383,6 +410,8 @@ Split2MPageTo4K ( @param[in, out] PageEntry1G Pointer to 1G page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -390,7 +419,9 @@ Split1GPageTo2M ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry1G, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress2M; @@ -413,11 +444,11 @@ Split1GPageTo2M ( =20 PhysicalAddress2M =3D PhysicalAddress; for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntries < 51= 2; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += =3D SIZE_2MB) { - if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e)) { + if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack range. // - Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -616,6 +647,8 @@ EnablePageTableProtection ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB base address. + @param[in] GhcbSize GHCB size. =20 @return The address of 4 level page map. =20 @@ -623,7 +656,9 @@ EnablePageTableProtection ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { UINT32 RegEax; @@ -809,8 +844,8 @@ CreateIdentityMappingPageTables ( PageDirectory1GEntry =3D (VOID *) PageDirectoryPointerEntry; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntrie= s < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress= +=3D SIZE_1GB) { - if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e)) { - Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize); + if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { + Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -840,11 +875,11 @@ CreateIdentityMappingPageTables ( PageDirectoryPointerEntry->Bits.Present =3D 1; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntr= ies < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress= +=3D SIZE_2MB) { - if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize)) { + if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack rang= e. // - Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize); + Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62996): https://edk2.groups.io/g/devel/message/62996 Mute This Topic: https://groups.io/mt/75713042/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62997+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62997+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366431909745.4390479161887; Tue, 21 Jul 2020 14:20:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YPuaYY1788612xCjkY93aTYV; Tue, 21 Jul 2020 14:20:31 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.88]) by mx.groups.io with SMTP id smtpd.web10.5611.1595366431016897619 for ; Tue, 21 Jul 2020 14:20:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DHUxQ6MBxCgQmPfDcFLz25KwOCWyihJdWywSE5mgBnGqaj+/OlZ1UfcVKjPh5hWkRdFZbhIr04VZnGd6qx2YyrPmR+MS2TYlf/nxjB7K1GmQlTmqjX/RKaF1u4CsZWoznrJ1/Ep1GeXnRfJvYSmqc8QAIDm+8JrVpFg3xme8Fn7huhEZtxq8Tm1dOGJYnlHj/lZ3BJV8Tz1z6c9EKwla3jjWUCMs5M2YZWlpxpyvhJ/zZsbN1gHXXAmtdCpALCCH2FQsxheKrfxiKKPHlcgChA5hi0U9t10nOknbPWbxsDzae+QpnR9Iractf+aKZRZwhU1Y5Mj+w/q5l2M491Uq1g== 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=2ayQejRVDoGBP8sd1K4oywwjRrcrbY8KDkVKs4a/sBo=; b=Xsgc2R6/BuCluBpUD9I4z1nrjjYCEuvh4ezUa6FctmuTe2MvsQFlHkTN3uOCfeuTjPyiJK0YRyOa3N3r3o7KJgoFqZHhALVMJLu4g1DMwqJGH0qJqe2SyHmF7nOST6mtO++A53jHticrRCk/QlsneTfuzsmFvkNRr1fjYdb0wbSU1T+JrUTJpCkDm9Itjj/abmTer83NxtR+5/l1Gq8kMR2FQh06iJJ+WuwtEy47tEJdRQWNScnaBaQPEjodlT7rBH2EPlXoIELVS2OYoKQLF/CSpOapyFOAsa26SOg2wl9f8Ie1szo3xlGlczpegwICCstQ1nvPTERQtDbXzc7ZLw== 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 X-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:20:29 +0000 X-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:20:28 +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: [edk2-devel] [PATCH v11 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Tue, 21 Jul 2020 16:18:43 -0500 Message-ID: <0d091f43ae96ca4617f6a95a018bfaed6280eec2.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR04CA0091.namprd04.prod.outlook.com (2603:10b6:805:f2::32) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR04CA0091.namprd04.prod.outlook.com (2603:10b6:805:f2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:20:27 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c65bc314-037d-445c-e700-08d82dbbe42c X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: bVITvdFlY2xzR8AYWwVlzrBIIRz8pTynaI+94g8Qd0s2ZvMMgTK+uYNBOHjSf4dHTZ5LgvQ/hU0ApLFhFCuckTaqK6uLTGEsWRrATZ+ovCw0oVuKhnwkcSHfyFHmitVFC8Vc/vZXjL9lZos02MjmPL7408bo3+d+2UY4C10bAcxCyCVpAxLz8/dona5KIWB1/otIO9kiM4dr8v8JrBfzQDmoZzNjjHD+BYyBEB/rT78QuR/0UU5ayjsFVAlzzhQ5xMDtG3x2SHBfBwSpjg8PzTXJD3R6HQ7T3wx1tdHjULQC/5AAvONjdj+1w49WPjNnFmFt2xRmJollpbGpSJlD9p8Gxc7EENKx2Pn/9h79TpKlPZw0R3is5JJOR7hlOiguUzIcpBPvd0PC+KHYOcz0qIa5ya6+CTjx4mHt8JYCot0GX/IGXbSr7/rO3BsEmuBwKzKQ5BcJq7Zt8lmuCanljQ== X-MS-Exchange-AntiSpam-MessageData: DdP6T/QFsoc0TYbGC8wi9G9+Qf2XCtSdOtq8BSkDLauNwJ085mwYl8W9g37gTQQAEZ/ZW5Xy5lCML91fNcwtRy1UieXTAHSX0jSubYRuwwR1bUuGktriIuTFahCkNQHI6Odc8oivOZ6I2LnDWKMK9rn6fE/uKYIIH1rjFTfUab+dhe/HJeZTcwicxiGyuJg1yl6XFk3bo9i3MbokF/RjgHGz2DPrp2WZ8sOYNTIFufco4UsDklGdid4E9E+jkWnn7Iv1rjJkQmL03EQ35bqlUNqF3iYo2cjUwLH4Av58sgSNGpXNnCyoptipztEUW1mqeXosfrfyPxW1rLndjNyT1PKTMer4eWRzz6uZoy5J6yQSrWqDniWuJpZG/q9+8b3kXtfLXNMJJfFYEgxbJycYsHozrAiF8JC+0F53nQgd0uaJFnFy/UEYoiAj1ItAjK/AhrzhKJSIiKGgIU83PO8pQ4RiZoW7TnSpbu8eTEZK3Mg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c65bc314-037d-445c-e700-08d82dbbe42c 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:20:28.4946 (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: QLLO/Zbg8c4FXdsRWbROIPuR24trAEvEkJ8qvznho+1tupwDniSwszp8VNtL18qCVDqODgDwxW/puCRVhMbXIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: lRUMxJVnNayQksoiIefLK8RJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366431; bh=phjvSYejKgUCurFiVzXgptHW85/E87+A9k62MzlqaTg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VzBhJHSRe9xMlLuTp1/SCVCes2jMsa+knKeITE0TgDanFoQVvejlyZFUcnY3s43lyei OWMeM/rNi20HPbjKDU7/OQ78YuunqPhFkzmh/zVQHU3Fr8uVQ3ezcT5PUfSWaHjb0UL78 Shni2kX7dhyeHpClI4NMDdiyCmBK1gIvt94= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID instruction requires the current value of the XCR0 register. In order to retrieve that value, the XGETBV instruction needs to be executed. Provide the necessary support to execute the XGETBV instruction. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 17 +++++++++++++ MdePkg/Library/BaseLib/Ia32/GccInline.c | 28 ++++++++++++++++++++ MdePkg/Library/BaseLib/X64/GccInline.c | 30 ++++++++++++++++++++++ MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 ++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 +++++++++++++++++++++++++ 6 files changed, 142 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index c740a819cacf..e26c0d8cb0ac 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -153,6 +153,7 @@ [Sources.Ia32] Ia32/ARShiftU64.c | MSFT Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT + Ia32/XGetBv.nasm | MSFT =20 =20 Ia32/GccInline.c | GCC @@ -288,6 +289,7 @@ [Sources.X64] X64/ReadCr2.nasm| MSFT X64/ReadCr0.nasm| MSFT X64/ReadEflags.nasm| MSFT + X64/XGetBv.nasm | MSFT =20 =20 X64/Non-existing.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 8e7b87cbda4e..7edf0051a0a0 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7831,6 +7831,23 @@ AsmLfence ( VOID ); =20 +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index 6ed938187a08..c2565ab9a183 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -584,3 +584,31 @@ AsmReadTsc ( =20 return Data; } + + +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ) +{ + UINT64 Data; + + __asm__ __volatile__ ( + "xgetbv" + : "=3DA" (Data) + : "c" (Index) + ); + + return Data; +} diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLi= b/X64/GccInline.c index 40a208f1985f..65f864e35922 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -560,3 +560,33 @@ AsmReadTsc ( =20 return (((UINT64)HiData) << 32) | LowData; } + + +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ) +{ + UINT32 LowData; + UINT32 HighData; + + __asm__ __volatile__ ( + "xgetbv" + : "=3Da" (LowData), + "=3Dd" (HighData) + : "c" (Index) + ); + + return (((UINT64)HighData) << 32) | LowData; +} diff --git a/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm b/MdePkg/Library/BaseL= ib/Ia32/XGetBv.nasm new file mode 100644 index 000000000000..9f7b03bbff35 --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm @@ -0,0 +1,31 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; XGetBv.Asm +; +; Abstract: +; +; AsmXgetBv function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; UINT64 +; EFIAPI +; AsmXGetBv ( +; IN UINT32 Index +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmXGetBv) +ASM_PFX(AsmXGetBv): + mov ecx, [esp + 4] + xgetbv + ret diff --git a/MdePkg/Library/BaseLib/X64/XGetBv.nasm b/MdePkg/Library/BaseLi= b/X64/XGetBv.nasm new file mode 100644 index 000000000000..09f3be8ae0a8 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/XGetBv.nasm @@ -0,0 +1,34 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; XGetBv.Asm +; +; Abstract: +; +; AsmXgetBv function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; UINT64 +; EFIAPI +; AsmXGetBv ( +; IN UINT32 Index +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmXGetBv) +ASM_PFX(AsmXGetBv): + xgetbv + shl rdx, 32 + or rax, rdx + ret + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62997): https://edk2.groups.io/g/devel/message/62997 Mute This Topic: https://groups.io/mt/75713044/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62998+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62998+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366441919111.8355113906714; Tue, 21 Jul 2020 14:20:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ihQKYY1788612xcGeFQBaGyK; Tue, 21 Jul 2020 14:20:41 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.44]) by mx.groups.io with SMTP id smtpd.web11.5494.1595366439995846620 for ; Tue, 21 Jul 2020 14:20:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GO3fpyb/tiFsBz2C9m4mcA0s0l7aPgqGciJpxyVDYcy2L7YZ1D2DI+yK1VC8IkRIkFtiGhvNhtxUtXzpUPciCldBTL9OhIigVIdUDmQGEzO7ReuC2k7TF4jxk2iIUdeDBBiPFMNU4QWZtUInJY5O8DQStaiyEkJYWf0MZtR4k7OF99rITaCPAYjs6q/yoMgO6uFntWJOsgLbvAc1QdY6I9eEPs5so+fqBJ5n2ni9LIVfbDWqWN4bfOek7YtV/jHKhCBOX06IM4b3mUth0aaMLYbSFVcs/LAnJrORfKLdenaJnhSF436/DmFKFkY6VbE0FxtEV6Bj8MNfEqwQ7a5VzA== 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=lCOhEwJaFD0Tm2qEF7vWUe/Mwd9En5D3z82fbsggc88=; b=lfqHVfEU9CYmEsc7YoTq2XRdY0r7S2qiPAd4fOEfTKRqT3DPOTrFLyGGF7SS3z3TUdmqDCG9WDSGNOuubtPB6xvBRGcGIi9YjodXzF0XxTwlmrBvY5Rb1OEItzzOK6YzvG4ORGu5yST4o2VWXZbR4haHlgYzoMxaczoJaOx4m9oxlo9ersWtHgpKwk4t6pao7j/Iz6SbGMTMy+5KtJlj4lfhpjdjd0Vr7hCLtPzsOuyFnJWBXDDdWFT9Rdyna5VcmPrv6ogzdCIJV8QGSgCw3kzgnFKncE8rOGnpXvybeajC2dw7tcSpOYMVvURhyrs7N9izNdm3Zu4bm6K1gDk2Gw== 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 X-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:20:37 +0000 X-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:20:37 +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: [edk2-devel] [PATCH v11 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Tue, 21 Jul 2020 16:18:44 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR18CA0052.namprd18.prod.outlook.com (2603:10b6:3:22::14) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR18CA0052.namprd18.prod.outlook.com (2603:10b6:3:22::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:20:36 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0e14ad61-6048-4bba-528f-08d82dbbe9a1 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-Message-Info: TzFnJmDfBVLVMIw3/f70w2tdpKQalfn+kETDtxXyvybMKaGQ6ie4UaDADtiOllJwGr9R+RlQosaFV86THMH6QTF9Bd+n9V66Ps147RnuV8ZK4HUWR74FIpqcol/gEImMDMIOfwOUfnvW7ebHfgJLhd1auhOZStQhOYKgewNz6m9ckr347YJzHIn9MK7ecINn88a+GwCiMKqHDoniY30mUVGi9gHSaVlg/nEHeBnQa4rSncmpgqQweOtATUsjEgiMMrdRX/MiaQRjrl5CtOoHwcNuU/GSe7zANvpGOjhPTnXp8Tz4vHp+0SCC0vRGfalyaI4a6gkI9IeoZYGGPDl/bY+Hz7nV0HhfTUP+MH2hBap5zBuGAlPMGNnME3p+dMEW+UDRPz7sWZc1uzP2vbwjJE578UHFAjPklJV+UwKyU3bz+NuqjTlWAuQoObcBYyweqxMVycwDW3tft8iauXKnWg== X-MS-Exchange-AntiSpam-MessageData: 4r9OVrJ5V0/NKW64iz73uYnz1IMD2t46Oa+zI4mcqgj3ATwJoJHAI1czKgeG2iME/2/55rYZP05W/BqM1CkDvpuOfBx3bZoWgOypXTvLqyc+WpFeld2aR/Vw4LRW7hc6rOiml+K2U8hLeAEQmA7lwTbv/II1jPYFoHUivUSjLsCUR4wJhHObzcKMil6eqiHHGOpygy0IGeOgF7Y4loWYR5V4IZG/PBQs/3KewfP5pYj23+K2Kl4okQV7Zd7iwszWc+swdDvtvpItvWs71b2cseINYOzbMbxscS/0IWXY5Jn4dTnfY+nsaLoREL3wSygV+PXNWWVDbbbAjwRUM3O2P6OWwtvLDms4iCFu6l40mVq1NR80zlarPu4pYjglqQpJTrBCEKQg/bRFkNxAJvw1ZDfOoXs3VS8KCl+fX1zQ/6PvFtD1wG8/oI9J4n4adRUQfdK2/3DxE8s+IVckLgPC+G04w894eF4BeVlbu9FR5iI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e14ad61-6048-4bba-528f-08d82dbbe9a1 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:20:37.7491 (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: TkAY+Mw1sZDioOmMP8wRZjGuLK4KTEBNL1jxNp5gFJJDIy/ZQelRilIQQzic77PQvCNfxwrY6eRDXfGL0p0mIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: h15pIbCACqnd847SyO7ICepkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366441; bh=86eCTsYf48HI2rPz0Er/yoSawOYfx4UfXREes2jCc7Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UteJkz9r0A96fuk2jRqywpwA0xW72FIcz9AcM2jZsMzgp1djFWBycnqrDOx2BQHNFNR Q3kXlru7dJCYwqR28QcERupUZ1HUdEjGEwRH6VflOMYUxY8/+WgpjHgZlTGzTnhTheE6U sOUFMejXyM/xh8i4m+GK4VeOT7FfBsUnTvs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 VMGEXIT is a new instruction used for Hypervisor/Guest communication when running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE) to occur, resulting in a #VMEXIT with an exit code value of 0x403. Provide the necessary support to execute the VMGEXIT instruction, which is "rep; vmmcall". Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 +++++++++ MdePkg/Library/BaseLib/Ia32/GccInline.c | 17 +++++++++++ MdePkg/Library/BaseLib/X64/GccInline.c | 17 +++++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 37 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm create mode 100644 MdePkg/Library/BaseLib/X64/VmgExit.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index e26c0d8cb0ac..1bcc90d5a4c9 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -154,6 +154,7 @@ [Sources.Ia32] Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT Ia32/XGetBv.nasm | MSFT + Ia32/VmgExit.nasm | MSFT =20 =20 Ia32/GccInline.c | GCC @@ -290,6 +291,7 @@ [Sources.X64] X64/ReadCr0.nasm| MSFT X64/ReadEflags.nasm| MSFT X64/XGetBv.nasm | MSFT + X64/VmgExit.nasm | MSFT =20 =20 X64/Non-existing.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 7edf0051a0a0..04fb329eaabb 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7848,6 +7848,20 @@ AsmXGetBv ( ); =20 =20 +/** + Executes a VMGEXIT instruction (VMMCALL with a REP prefix) + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + x64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index c2565ab9a183..26732acd8431 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -612,3 +612,20 @@ AsmXGetBv ( =20 return Data; } + + +/** + Executes a VMGEXIT instruction. + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + X64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ) +{ + __asm__ __volatile__ ("rep; vmmcall":::"memory"); +} diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLi= b/X64/GccInline.c index 65f864e35922..1f584b6e50fe 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -590,3 +590,20 @@ AsmXGetBv ( =20 return (((UINT64)HighData) << 32) | LowData; } + + +/** + Executes a VMGEXIT instruction. + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + X64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ) +{ + __asm__ __volatile__ ("rep; vmmcall":::"memory"); +} diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..a4b37385cc7a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,37 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): +; +; NASM doesn't support the vmmcall instruction in 32-bit mode, so work aro= und +; this by temporarily switching to 64-bit mode. +; +BITS 64 + rep vmmcall +BITS 32 + ret + diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseL= ib/X64/VmgExit.nasm new file mode 100644 index 000000000000..26f034593c67 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm @@ -0,0 +1,32 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): + rep vmmcall + ret + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62998): https://edk2.groups.io/g/devel/message/62998 Mute This Topic: https://groups.io/mt/75713051/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62999+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62999+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366450736395.6471869639247; Tue, 21 Jul 2020 14:20:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QtJFYY1788612xhhM2W7YV72; Tue, 21 Jul 2020 14:20:50 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.58]) by mx.groups.io with SMTP id smtpd.web11.5500.1595366449267270537 for ; Tue, 21 Jul 2020 14:20:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=STQtbiQpV4N4sQb3l3Uys8M4+IZrrhLVOAwGOgzsXDjlDVyE+UQXLbrMopugscOvaV0xAmm2TlpfEoXWYjp54PkTizqgQn5LqHhvnZnfrbuvbWbPR+5z7999NcQoWNHgnaTM/uHrvgjRHl4ED0IbBklkDz3TN50DXvio05k1FAHrHm6Nm2OqxqFA2q0/CdYhSwqNLw39lA3FMlxYjtnxRwK0OiEIf0OjydcbkHCHSZ/G7be80z4B5Rb1oWB0d9BGkvlC1bnS67PtEjqNx8VLTOMKE99QZnRscGFNQZ6ga635hSu+80gyQQbQXxYuzeooRrIN9aVTXixbJq3TI2uaFA== 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=/BJELomezd9RuQOtYb+gTmMe10Anbl6BkYn9LkHsNc0=; b=fGNHuAjcHBk88AOYUPhfie22CHgtqxiw55oVkvWRhvgfiW9dKMox31C47aiTec3Lt6jhpkQS/FO4lz/LBjeXv+mEXsjXMBOQ51IIGYigttxC0gJoSroS1Eh7lwea69IkjVJ1EbzfKaalqLOpPCD+WJbXOoN8TmVHq/orx/jDgydCAL1PStT2ImOfdRjJ03YLelCXH5ghV0GUG8xq90EkZsIfifyRE35kjqvw+sRnRL+RFYT3YEdP0x3STquz/k6uuJjsHl8SplfVXfXplFGoAtB+yq3LZhnAB8Nn4YIPNDudakZhLBI+/u6PlZAcRp1yinkA1g0ku2a8BBo9YJ1++g== 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 X-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:20:47 +0000 X-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:20:47 +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: [edk2-devel] [PATCH v11 08/46] UefiCpuPkg: Implement library support for VMGEXIT Date: Tue, 21 Jul 2020 16:18:45 -0500 Message-ID: <199707bfe2e7b6929bfd25ef1db6bbd2fb56296a.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0082.namprd06.prod.outlook.com (2603:10b6:3:4::20) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR06CA0082.namprd06.prod.outlook.com (2603:10b6:3:4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:20:45 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8585c06e-206c-4c7c-18ad-08d82dbbef22 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 0AyiUfocgF1LrcKvoywXJBeMY6MMlnetrCYUf8aDTpXNjz4RTdER/B9mfrAa2NY1gEHD2KdmnQem9u+mSecqrwuq08A+4jsjjaMYsKgih35vNdi8PqtPbWkVoaq5aPxcqiewgeowRBWR1HR8c9MkiLkr4LnUEPsSSuR6orNrIFgQPPPLX1H0jkEqoaisUxHGJstnobrbLMxtLKOqjNmdyt63FKMO06fZCOIOR6qrgHJLF58Ba8AmXK/VFOYJ5I6+JsTmdwr8XnyqaPhHjal1BJWDAEiTLmbBNYDuABd/1yB8dIkLbJxC3SDLdyRAiBvkbpBP9hC6TZZ6AEk56dsLhLWjFaF3rZ347Vm5NDaOk0/JK8/w5X/7XRUjEDKNjELqkRUCrPwpApf5qBiXg8vLIYDvNUInC1HDHrC6ZW6vLZ5zL+j4uPJTny6s7OiVJKJSmuXy6T/SnDSrMzVcfaFXbg== X-MS-Exchange-AntiSpam-MessageData: PdhaO0wtmb3Kt/1FdAyDONyRxBH6qoC7pJ3NrhuFbWFXTDYUHamADPyJzcYkRoUU34fabF483YNtuEWUld1cNE+JZ3YjVMx5ztc8EiE6VdXIbh1AUsg4tHIW7yPlx4TFPlsGlJfe7KoylWTuMXS0UhHdmL21vk/sxxUDANNjO7MFdqxbtKsjGIGNiVs9qjQLrkwQflxfxp8EhEa3sE4k6uqdIclGptO5fXXMUEXG9Z8SyMtfHcgE1pYdn3Ncclep/UY/VGprv6z2aMvVdL/rJpPimRzRSAkOFP0yq5kprwwk6EHUfjNajFgDEBcw2vqMnlvlwuDhPWqKw2aqrT32YVx3afRydLc2NGUD2KwWVHkHbkWdhw5bi4DWV91mIsAHD+PVLteA5B+IcgfIoUbrVDC08yYiGR/WDqyIa/NiP9ZIgyt1gHEvTSSpo5rJJYxJ6uxslD8HcMnHWAvfU8266KdAmcYOF0ZX8m2wVlFDqpI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8585c06e-206c-4c7c-18ad-08d82dbbef22 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:20:46.9847 (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: NQe1AtsDrEpepbiHUNCbfl589AyWb6MlGzDTdTmfEF2CB/0OHKleriiIWfOff9k/YrC/vzixE525LrIsRAPwYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 8afaN7NIXtm2qdLy8Z0Dp8Ugx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366450; bh=A6nJeJQXub9Ep1NUHwKDtRk6xzm5+KNE/PuQpl2rWB8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Ul0+lHNSmRJpZK9ciggYRVVHven3ju7W6g932WmOuoQa9vJIUUTWaL2GzNPDYQSXcQL 3lROTPfpRh8CYGSow+NJ9px+4ZBxv/IOulX8DDGUulmmFHURFeixXjSVeXypochSfJmty M2+jmLQkGsqEVlaY47dGn28vdlLXRpMoNe0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 To support handling #VC exceptions and issuing VMGEXIT instructions, create a library with functions that can be used to perform these #VC/VMGEXIT related operations. This includes functions for: - Handling #VC exceptions - Preparing for and issuing a VMGEXIT - Performing MMIO-related write operations to support flash emulation - Performing AP related boot opeations The base functions in this driver will not do anything and will return an error if a return value is required. It is expected that other packages (like OvmfPkg) will create a version of the library to fully support an SEV-ES guest. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + .../Library/VmgExitLibNull/VmgExitLibNull.inf | 27 ++++ UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++ .../Library/VmgExitLibNull/VmgExitLibNull.c | 121 ++++++++++++++++++ .../Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++ 6 files changed, 271 insertions(+) create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf create mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index df5d02bae6b4..cb92f34b6f55 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## MpInitLib|Include/Library/MpInitLib.h =20 + ## @libraryclass Provides function to support VMGEXIT processing. + VmgExitLib|Include/Library/VmgExitLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid =3D { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,= 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid =3D { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,= 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index afa304128221..f0e58b90ff0a 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -56,6 +56,7 @@ [LibraryClasses] PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.= inf @@ -143,6 +144,7 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.i= nf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf b/UefiCpu= Pkg/Library/VmgExitLibNull/VmgExitLibNull.inf new file mode 100644 index 000000000000..d8770a21c355 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf @@ -0,0 +1,27 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D VmgExitLibNull + MODULE_UNI_FILE =3D VmgExitLibNull.uni + FILE_GUID =3D 3cd7368f-ef9b-4a9b-9571-2ed93813677e + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib + +[Sources.common] + VmgExitLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h b/UefiCpuPkg/Include/L= ibrary/VmgExitLib.h new file mode 100644 index 000000000000..45fc27d35e29 --- /dev/null +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h @@ -0,0 +1,103 @@ +/** @file + Public header file for the VMGEXIT Support library class. + + This library class defines some routines used when invoking the VMGEXIT + instruction in support of SEV-ES and to handle #VC exceptions. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __VMG_EXIT_LIB_H__ +#define __VMG_EXIT_LIB_H__ + +#include +#include + + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ); + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ); + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ); + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + The base library function returns an error equal to VC_EXCEPTION, + to be propagated to the standard exception handling stack. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ); + +#endif diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c b/UefiCpuPk= g/Library/VmgExitLibNull/VmgExitLibNull.c new file mode 100644 index 000000000000..bb265e1700d2 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c @@ -0,0 +1,121 @@ +/** @file + VMGEXIT Base Support Library. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + The base library function returns an error in the form of a + GHCB_EVENT_INJECTION representing a GP_EXCEPTION. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ) +{ + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D 0; + Event.Elements.Vector =3D GP_EXCEPTION; + Event.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + Event.Elements.Valid =3D 1; + + return Event.Uint64; +} + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + The base library function does nothing. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ) +{ +} + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + The base library function does nothing. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ) +{ +} + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + The base library function returns an error equal to VC_EXCEPTION, + to be propagated to the standard exception handling stack. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + *ExceptionType =3D VC_EXCEPTION; + + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni b/UefiCpu= Pkg/Library/VmgExitLibNull/VmgExitLibNull.uni new file mode 100644 index 000000000000..8639bc0e8ce9 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni @@ -0,0 +1,15 @@ +// /** @file +// VMGEXIT support library instance. +// +// VMGEXIT support library instance. +// +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support N= ULL library instance" + +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT support N= ULL library instance." + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62999): https://edk2.groups.io/g/devel/message/62999 Mute This Topic: https://groups.io/mt/75713057/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63000+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63000+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366459164562.5845757952266; Tue, 21 Jul 2020 14:20:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kaS8YY1788612x6vi8UzrXnl; Tue, 21 Jul 2020 14:20:58 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.43]) by mx.groups.io with SMTP id smtpd.web11.5502.1595366457593437892 for ; Tue, 21 Jul 2020 14:20:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GVcnFU2uUuzYiO8ubLyfytI3jkQcLvcBiAOW3itG2p4ZG2BDADTecNnr2P+zEznx0liuBntvsi0aFq1Oe6ucMUzmUEKcHxtK65xn6XANIU7SrzxsPVXkVhJnsq0mLXYqrh7s8uJhDioluEhXfjQ7EL2JiM2QE4RNyzVoqAs4i9cliGmCHeAPDbAukRn97QpY5nRqEJ2ViAPWquaCTAeguk32szyF5szfMFYZjEotNMV+6h/atAiuCefffAAC5q9VYqbkh+v3/04vlbXnPooFjaNpIYI1icLG+zCa2oFitpxRm8sGIVKV1QsUP6uv19QuvaZsRhI1DIgkyVXTT8W0/Q== 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=U9b/kKvH3tVOLRpdFrO8SCIdJMh8PK+H2a8qgSS46bs=; b=lhDtGWk3/kWaBydUpb93bTL3I4qyz1I/CWsWmh4ffcP5Fk9sDJHmkbjZ2QoUIuix/gJLXOVNjl1uXXJgDTw9xv7lv5+wIHLhLVoLZmFzUdRgc5RFhZlUtSy87aMo6xilLmWPJOq6PfX85PRRuJW6dXSlPXENggQpSNu1fIUma+54ddAX9Jh/h2R0rQB82dGhScGQLWmfSrF83yTzJz2K/rG5cv1k0HS1TjBQqvUo+jOtrBtXuL4GgPoz524kqEgh3eJCBZSbcNLAbT5A9CPBDqE3PZAXGXc/StIUCLwte5vKgRoexH1niGGgXxJ12/aFakoND1N8XH2cqWrQUHyTxw== 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 X-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:20:55 +0000 X-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:20:55 +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 , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v11 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library Date: Tue, 21 Jul 2020 16:18:46 -0500 Message-ID: <9f83474d175064d31c843cb543c8cb3cfe7721c0.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0037.namprd06.prod.outlook.com (2603:10b6:3:5d::23) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR06CA0037.namprd06.prod.outlook.com (2603:10b6:3:5d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.19 via Frontend Transport; Tue, 21 Jul 2020 21:20:54 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cbe6e6a8-2142-403d-63a5-08d82dbbf40f X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: hDU08c5aS2wmpviIdU3MNHwcQrxG2xE+/vsR5o00IQc3nDWvDP65G5Qx5j3pjXVal0Kp9rcQPKiRolk5bqeG3kDOH7FbiJ8OIy+JxSOCJYkiKUfiBjBZmW2GReWLn01ev7aYLv5gacUBjHw5bhUXVhivb8OcoRdRdzxDThg7A20Njb+dN1jpUYeJW2zA7YqWbNk46gl4pjSaqQ5pjOW03YMiyXSZiIaBNHcyLtxqVSBirMjPzDOQQZ8zbgQB38iGKWFlmgSmGVsr4FUtoYV88wIX9jXm+ODH5L3smwD7TLUknuI7dkVMePTCrpq05s1DfJKRMKXtLzqy/YN/WKIOVPVwO+9b8bSbbv42s99KMW2r+S4LkHDZw0ZAkAnzaKte2HOGBylcwI1fkwq1D81Cjq8LF6jHiWeE1YSBRBsSWgspGxO8yzN8Frf9KD2niqVy8G2dctcgp8NNtkK+ogAhyA== X-MS-Exchange-AntiSpam-MessageData: N8uIDDbJmQVk87EopPOSTdPDW7MDqNeT5MZMBMS2G0KrMN8A5rg64RzuOd97zA/tJx9X13s1RzACx9/xC3ce849zcFxthrqUiUxBPTgKLyyf5Xm7cdRUmDIoIC31csatDuqIU5Y+14efSCSnbuYDqVA8M+DSt4U8Mw8j4Woyg6JrDHNk2BiC5sS9Ibo+pKPHPlw+gHo6x4wXu+uSBOnaar5fbdLb0voAmvGDLgCwaXmmL+SoT5EJU6q1jqLGHFUL+XeGL86Mb6FaDfuimRCSEVBASqhjbl0uSizUVaa2sbjfN8pN06nDeZLrEbh29AuNElB5oRCY0eNoCey0v0JKJJcvlSQEIrVmlkGjW/p9NTXnvdTOsxGvvWJLHah6BLwe60kW4pL1PUtiwl6nrEZAw1/WMPd2hviT+PirLlXg6Xq7a/u6I0u57XvaUNQVeEvbqZmDEoUj96+myRrcqVjii4L53lNPgoDCdi12iQ9j/I4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cbe6e6a8-2142-403d-63a5-08d82dbbf40f 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:20:55.1557 (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: wH4MoWfiztzzuS8OCWbEZ2RAi3NA99RdrghSpVHWhEtzC198H2VV/m4208DGmk/OS/ptQshRBvMxYluAku2L0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: pd1mzSO5r2vwAEjXxTr1o0yNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366458; bh=FouSxQfXmlRst1NKZcNYNN5uZ9k2t4RmO7IgOUgngJI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=CZu5QIGmQ9Mp3ZASWIWz/RxAc0Ih73vOgIHv1kNsXS139FCY+zM6xyebUbPjQjVm8ES rQ2CBG12UD5s9do05tYMmM52+Ks/E2Hdc/CgWFekZY5uB2zRkSO3urSJ/o6HuamEEokxh bEZZkk+CaW6R4iR5zTbDDDjwqS5+S0tOCO0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Various CpuExceptionHandlerLib libraries will updated to use the new VmgExitLib library. To prevent any build breakage, update the OvmfPkg DSC files that use a form of the CpuExceptionHandlerLib library to include the VmgExitLib library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 4 files changed, 4 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 9178ffeb71cb..c57bba1ba197 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -229,6 +229,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index a665f78f0dc7..22e930b12b9b 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -233,6 +233,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 17f345acf4ee..27f5225fc281 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -233,6 +233,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 782803cb2787..37b63a874067 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -213,6 +213,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63000): https://edk2.groups.io/g/devel/message/63000 Mute This Topic: https://groups.io/mt/75713061/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63001+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63001+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366467119808.5564033498274; Tue, 21 Jul 2020 14:21:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GAZ6YY1788612xsN6W0uOGGj; Tue, 21 Jul 2020 14:21:06 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.45]) by mx.groups.io with SMTP id smtpd.web10.5623.1595366465606954826 for ; Tue, 21 Jul 2020 14:21:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lP/xSB7WmpgCsMGF9xrsjFJuJafROb6oMEKhP/3RzZ/ulh2zWIlk+35Ja0PyCzurli+bIn4EhRYdEqC6HnuSegPYDq4wZqWzsR/KZ2lKeBxqTB1RN1sVdPyVwBALo2hbFyt2oopsJmB+sj+x8Aqzn/ikQHUfJvaNGOixSeFYWjwgL5zsKQzDhetd9i9zl/QFfl7WnnXUsWm2G3lGvEaXn4ZsF+UeID2pFOYOFBLD0hyRmPe2RaIXF144Ocngquvq7KLfJXrom58Dl64RldCAeggPlSKIaPDiyBp04uUkSGHkXY1BdRk7qi+fVDN292DpRzyWX97ipEdqxx5g8tBByw== 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=8gIPuv0Fy7s+RjQntMgos8V2fokI9BA9s2pD9HQviYg=; b=fSy6/2lFHCKtvlgKSui5RrNpeckff7RgvsCmJqV+k/8BQlIhkkt18+45fMFdeDlftdvesYJEJKp6E9vRfAetXqi2tN5mMUqW9tKlJXaL2e/rkMmVXBbi02T+MXxU/CXmT3MSoV4sf+ykSR5mN7/0SzHHq8ADC+dxBISNwzwxETu2Qxp3otwjVUmQK2tdEK5PvAdwnRCUqqDPkHpt8gSNgOjXY1O0IU5R/nM9h6fYgN27c7zTvZpHOZg2d3jiH2bKfiat7B1cmHFarQQY4q2qU4tMZyR9hrkSY8isn2B0gSeP81Esozp13xkWynKE7N7TaHwF6IohPWY3pJIrML13RQ== 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 X-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:03 +0000 X-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:03 +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 , Maurice Ma , Guo Dong , Benjamin You Subject: [edk2-devel] [PATCH v11 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library Date: Tue, 21 Jul 2020 16:18:47 -0500 Message-ID: <168bf8827e326f62f313f4317502e13bababb7a6.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR08CA0004.namprd08.prod.outlook.com (2603:10b6:0:52::14) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR08CA0004.namprd08.prod.outlook.com (2603:10b6:0:52::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:21:02 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8e41d4be-6420-4807-e2f1-08d82dbbf8f6 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: KJVey9pBb8ncEBB1myYCVpwC6pgPWo9FuEDFgXSby9obUVK4a9qMUyL5WknOmmiLaweKEefCZxcd0WnpD4jQkhrXiwbBZuVcp+JzZkJBl61zOPe7IkxlZbgK8sFmRqPe/yz1QAHix+zmx24s4Oei4CHHXYkfrjWgzp+ffdt0xQ1qC6TuZT4lhH7jBTYJVHTo0VQsYqzw2nPCd3lSelUn6wK2UnYxJ5r9F3Leznt2QYIs71d3BiThLWkP52peWAKjCTF3Ot3R4fHSryKJbLXCTWH+EK2qdB933FnIZ+3RVQrghTz4r5IR8oTgqVL+ObvB7uk9K+hAo5fgmXObNYP0RTGxL+peHvbNLK8TKMs/4AYIWZoSSvobOfxxvMqoume1UutZL0A0QuZ2oFo6H8uAhzlX2xixpD8zuSb162Kw59/+WiSdU9q8j6t7xAOyOXrjnqZI+TXMkb2YpG0KYLBFgA== X-MS-Exchange-AntiSpam-MessageData: kmLftk3zd0Y/wzr/rrxRyCflYL20jzzigGSdM6YOFU5kfmU/MXh8fHKcq3tJ3C3VIIXsJHv9mKWK2lIiTHWL5MmDVGhdjMGW+/YpW8MdA2VqyJv3unX0Ls63bgIGVpJURSY2WWBoH2KCI2G+Iz3K1I3kjgx/6nazy/aAhvH0Gh3qAUY8kS5gepKhGOzvPZJNhu5vx6HETERtXmFXj8ph602pq0Bay7B5091sM7TiLnz0EgYneyg6PId7EDc+76NiLJltGqmfgDswlBOZ7I3oo/UwGQWj5tJ0f57iMBtSU8nfJ1eXuEFlkWL5t+vFJoeR4o9wTATIYI1QZPohXKdZIBfOdVMYNAZS1H1QGpHehuL3JUMjj0Z2q63SX2M5a/7Ip0twJ+c9MRkHCl8WxJvISWtn+cPzCWkV+qNhBTo7wOqNMA0QQJV/snYWGpj3vA5D7TZTVDt5PGuO2cxx5t4KLKdF0PXNSTDjtpLWvmsdoKA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e41d4be-6420-4807-e2f1-08d82dbbf8f6 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:03.3508 (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: md1U67FH6sHD2+KdSq4vSs8XjlgXHSUkP/O07X8IeAoHxQfqJVlvKPDidcppZ3Fo30qjtIe2C2e5c3QE8ELTBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: cXcbYMVW05MCwg9dEODN0ehsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366466; bh=vteyLrcuk3hQmXj5JiweBue3YXveOpX7baWCVhtNyAg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=FhA3hNGh4BbeqfaPODbHW0Nw6vT4Sckvw9gQvQoM8JTCKePF9yW3w4EtY/xjL4cyDmz uH+5/FpRgebgRGp08HIOu5ugTX0i3IhXW5RodkLH6mYplnLIG7Qbz/EwKdL8+6Jd6iHcz pzScqtS536/P6OvQ93NJELkLwLqM0P8jwdY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Various CpuExceptionHandlerLib libraries will updated to use the new VmgExitLib library. To prevent any build breakage, update the UefiPayloadPkg DSC files that use a form of the CpuExceptionHandlerLib library to include the VmgExitLib library. Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Reviewed-by: Guo Dong Reviewed-by: Maurice Ma Signed-off-by: Tom Lendacky --- UefiPayloadPkg/UefiPayloadPkgIa32.dsc | 2 ++ UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc b/UefiPayloadPkg/UefiPay= loadPkgIa32.dsc index 9a9ca3060e47..460da1c504dc 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc @@ -237,6 +237,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -249,6 +250,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/Uefi= PayloadPkgIa32X64.dsc index a768a8702c66..942bc9076634 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc @@ -238,6 +238,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -250,6 +251,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63001): https://edk2.groups.io/g/devel/message/63001 Mute This Topic: https://groups.io/mt/75713068/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63002+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63002+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366476981445.19459805860765; Tue, 21 Jul 2020 14:21:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EWTKYY1788612x8OjlUvaCqu; Tue, 21 Jul 2020 14:21:16 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.48]) by mx.groups.io with SMTP id smtpd.web10.5628.1595366475673796788 for ; Tue, 21 Jul 2020 14:21:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NK8jIu9dHQuDd+aT9bvK3rhmwwSFkm1dzKuZ0nXzBx2+eK6c438UYRKvBKgLR1dY+/4Zvr8kiL3gjj/19Eo316kyK0g/valmjdNlaUjjw24deZorTLEN+arLkT1c9RXLPCoKbUiBjLaRtoZYfHZR+RakJ6BWWav30QskN6qyATRH5IC2mOtHDjNAhKndxex1aOQwTz+EmZjnZDuXZCWjZENePSouxBG1SIaL9K7XRwKm15ZMsvxfZdSthw5tlfCHeg+ys9fHd7qRqaqmW+3Y2ag4qVozPiJTFBWZJOfbehWhoJXrODDTZ+EZLZdW7CqHy1bwAQpEYjsvJWsqmD0D0g== 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=5xOrmFSZA+Wi3b0xrnNBRCIpwsGnmCOwMSFuIiVOZU0=; b=VvEK3uL4vow/GjB3U6cF0Hl+gZJ2i1gbgAc69Pda8MuqPEIX2GTdOT1xgT+kHpZTfjKrFbwX0OlkxYuY6bIcf/OZ/3YgsGnqIqb54U6iT5V8loNSCFrdjBfDMgsHWYQI7oxFXvIxkk8Z7sJXQ3dJZqk57zoVGs1xVkPyRzAMrYOutfack4l1nlS9qVmZTStzE9vMCl8wZ8RjVw65tgdiVUgiKh2oet/KhHxd6LlEgERARVbOJbSYQXEzdNFh/ioqh3NGuHbJ+zL1xnkD9bKACKxVJ4T/oXwhjh1AUIt3pcMf2kjAgvSS0S3avaKUPyaIXcZEUlpm5/KfnyDOKpKt7g== 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 X-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:11 +0000 X-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:11 +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: [edk2-devel] [PATCH v11 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Tue, 21 Jul 2020 16:18:48 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0014.namprd20.prod.outlook.com (2603:10b6:4:16::24) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR2001CA0014.namprd20.prod.outlook.com (2603:10b6:4:16::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:21:10 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7f9de418-fb3f-473b-73f7-08d82dbbfdd6 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-Message-Info: l9Xe04LWPFx+42G6ICVB/0XX54jXWRYMNkUE1yjzCKqA2bRxagHGxaYWPJf3kC7s+whfN5VJRK8KbHtwbC3yWBrECGq3zvN0rT+iGs89ZPz+t4V1wIE8SDVhJMGTqYFzfP5+2eDAWzKYis5W9aWc3FnrMSAoIxDkh4LV1veXgz6TUHYl2YUq/Ttv7h2Yw26RAAnEIqYrhvJFLl3zVXw8thHGNi5YhY0xh/7rAWRCqCz7BeEsf0AEla+znXuNa3ZKWP8gpt187DXFfARdDXP0NJUhi7oh5ji0AzuSoCCMWSkF8MnkH6ZaMMFMsWyqy9Rt32LUoo7U8yMVrqAyZaVvIGSwUl5NHfJqSsg0VX2vrln+8NrtRDsnAuJ65tb1WPh1B50A1mbbGcbNsmytpxmI9hp2xbmy3sROb8PrR/2992eHQ150SfjQ5qrQmRczu7krSj/nvAYoat5mXukgmBag/X0XIRcLNKwGKXarA2Gkh5la8ItFM8UQ/+aEOdBfPddU X-MS-Exchange-AntiSpam-MessageData: HNTfCodj9KVxnqDsJnTWSUR7135sx41rWeIkgZwg/0PP98k4tGBccwO5GyPlfk/DELfAgSK7z8+8jy0FMek2vCehHCbruTUWfLTNBPK9PpLWNa6Km8lS9ZfyviQDbfsrkC4WCA5lE4wqiMcqtNiuKxajbsnEm8ub4+aTUOoAMrxnIKVvux1IkmONwkeUy71xOv7ET4QNkClzp1Q/VCFMqT53GGPoiKJ3VS5QOIxvy4QD0LDVs3ZHdYCmEZTdOSg4V4pfrhLOllCw0EZunvekVkP9/B0MkjwzMsLzCML/8kpJ44IimPRJqz0Nyg2waeAO42RTmoXYT3loqj3jcgBbYRtMncXXid9R3LNGqNYP1dl5sGToTRJPCdYi04MNVS5DfWLi2IdnOEorC9197dHnADhtDk3rQ1lTWnMlHZYuYfmAJbb4hEquoX6ifQnhs38LCuRB3DgPNK9QIqefPLwef34f9LV7escpgtLvNYSI/sY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f9de418-fb3f-473b-73f7-08d82dbbfdd6 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:11.5768 (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: +6S+pN35I+V+LfL3lpoLgKIwqafd6PEjpZ63dboWkdcrc0x427Pfc1R+EAXzkN1PnIYT/iPderSmzf1IDCiH2Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 170fYjIhe10tffw8mbJ2YVAgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366476; bh=qd01Tg2jkKNxa0fGl6xeAXpcH1zo+A6PT6XDKsgL03E=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=UQDM1o8x9WTQY7wpnqZguD5Ih4byS91HRWisU7KfDOqY7bkpdyL1qpX/fS7/RbcSuyk LnJiGRea1I1xfWBKY/g/alWXwOazNr+oY59HQqHBQseTXVqnGwLVO37JEvuGjVi8ytJgD i9voaI29ZsBeLMBa+jzyXjNZkI32vkDRNJA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Add base support to handle #VC exceptions. Update the common exception handlers to invoke the VmgExitHandleVc () function of the VmgExitLib library when a #VC is encountered. A non-zero return code will propagate to the targeted exception handler. Under SEV-ES, a DR7 read or write intercept generates a #VC exception. To avoid exception recursion, a #VC exception will not try to read and push the actual debug registers into the EFI_SYSTEM_CONTEXT_X64 struct and instead push zeroes. The #VC exception handler does not make use of the debug registers from the saved context and the exception processing exit code does not attempt to restore the debug register values. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- .../DxeCpuExceptionHandlerLib.inf | 1 + .../PeiCpuExceptionHandlerLib.inf | 1 + .../SecPeiCpuExceptionHandlerLib.inf | 1 + .../SmmCpuExceptionHandlerLib.inf | 1 + .../Xcode5SecPeiCpuExceptionHandlerLib.inf | 1 + .../CpuExceptionCommon.c | 10 +++++++++- .../PeiDxeSmmCpuException.c | 20 ++++++++++++++++++- .../SecPeiCpuException.c | 19 ++++++++++++++++++ .../X64/ExceptionHandlerAsm.nasm | 17 ++++++++++++++++ .../X64/Xcode5ExceptionHandlerAsm.nasm | 17 ++++++++++++++++ 10 files changed, 86 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index 61e2ec30b089..07b34c92a892 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -57,3 +57,4 @@ [LibraryClasses] PeCoffGetEntryPointLib MemoryAllocationLib DebugLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandle= rLib.inf index 093374944df6..feae7b3e06de 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf @@ -52,6 +52,7 @@ [LibraryClasses] HobLib MemoryAllocationLib SynchronizationLib + VmgExitLib =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index 6d25cafe2ca3..967cb61ba6d9 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -48,3 +48,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 2ffbbccc302f..4cdb11c04ea0 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -51,4 +51,5 @@ [LibraryClasses] LocalApicLib PeCoffGetEntryPointLib DebugLib + VmgExitLib =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExcep= tionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPei= CpuExceptionHandlerLib.inf index 7e21beaab6f2..743c2aa76684 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf @@ -53,3 +53,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 8adbd43fefb4..c9003b10e552 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -14,7 +14,7 @@ // // 1 means an error code will be pushed, otherwise 0 // -CONST UINT32 mErrorCodeFlag =3D 0x00227d00; +CONST UINT32 mErrorCodeFlag =3D 0x20227d00; =20 // // Define the maximum message length @@ -45,6 +45,14 @@ CONST CHAR8 *mExceptionNameStr[] =3D { "#XM - SIMD floating-point", "#VE - Virtualization", "#CP - Control Protection" + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "#VC - VMM Communication", }; =20 #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CH= AR8 *)) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuExceptio= n.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c index 6a2670d55918..892d349d4b37 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c @@ -6,8 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "CpuExceptionCommon.h" #include +#include +#include "CpuExceptionCommon.h" =20 /** Internal worker function for common exception handler. @@ -27,6 +28,23 @@ CommonExceptionHandlerWorker ( RESERVED_VECTORS_DATA *ReservedVectors; EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler; =20 + if (ExceptionType =3D=3D VC_EXCEPTION) { + EFI_STATUS Status; + // + // #VC needs to be handled immediately upon enabling exception handling + // and therefore can't use the RegisterCpuInterruptHandler() interface. + // + // Handle the #VC: + // On EFI_SUCCESS - Exception has been handled, return + // On other - ExceptionType contains (possibly new) exception + // value + // + Status =3D VmgExitHandleVc (&ExceptionType, SystemContext); + if (!EFI_ERROR (Status)) { + return; + } + } + ExceptionHandlerContext =3D (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (Syst= emContext.SystemContextIa32); ReservedVectors =3D ExceptionHandlerData->ReservedVectors; ExternalInterruptHandler =3D ExceptionHandlerData->ExternalInterruptHand= ler; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 20148db74cf8..52c6886f0372 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include +#include #include "CpuExceptionCommon.h" =20 CONST UINTN mDoFarReturnFlag =3D 0; @@ -24,6 +25,24 @@ CommonExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { + if (ExceptionType =3D=3D VC_EXCEPTION) { + EFI_STATUS Status; + // + // #VC needs to be handled immediately upon enabling exception handling + // and therefore can't use the RegisterCpuInterruptHandler() interface + // (which isn't supported under Sec and Pei anyway). + // + // Handle the #VC: + // On EFI_SUCCESS - Exception has been handled, return + // On other - ExceptionType contains (possibly new) exception + // value + // + Status =3D VmgExitHandleVc (&ExceptionType, SystemContext); + if (!EFI_ERROR (Status)) { + return; + } + } + // // Initialize the serial port before dumping. // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandler= Asm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAs= m.nasm index 3814f9de3703..2a5545ecfd41 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm @@ -18,6 +18,8 @@ ; CommonExceptionHandler() ; =20 +%define VC_EXCEPTION 29 + extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag extern ASM_PFX(CommonExceptionHandler) @@ -224,6 +226,9 @@ HasErrorCode: push rax =20 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; + cmp qword [rbp + 8], VC_EXCEPTION + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored + mov rax, dr7 push rax mov rax, dr6 @@ -236,7 +241,19 @@ HasErrorCode: push rax mov rax, dr0 push rax + jmp DrFinish =20 +VcDebugRegs: +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid excep= tion recursion + xor rax, rax + push rax + push rax + push rax + push rax + push rax + push rax + +DrFinish: ;; FX_SAVE_STATE_X64 FxSaveState; sub rsp, 512 mov rdi, rsp diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionH= andlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5Except= ionHandlerAsm.nasm index 19198f273137..26cae56cc5cf 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm @@ -18,6 +18,8 @@ ; CommonExceptionHandler() ; =20 +%define VC_EXCEPTION 29 + extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag extern ASM_PFX(CommonExceptionHandler) @@ -225,6 +227,9 @@ HasErrorCode: push rax =20 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; + cmp qword [rbp + 8], VC_EXCEPTION + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored + mov rax, dr7 push rax mov rax, dr6 @@ -237,7 +242,19 @@ HasErrorCode: push rax mov rax, dr0 push rax + jmp DrFinish =20 +VcDebugRegs: +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid excep= tion recursion + xor rax, rax + push rax + push rax + push rax + push rax + push rax + push rax + +DrFinish: ;; FX_SAVE_STATE_X64 FxSaveState; sub rsp, 512 mov rdi, rsp --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63002): https://edk2.groups.io/g/devel/message/63002 Mute This Topic: https://groups.io/mt/75713073/1787277 Mute #vc: https://groups.io/g/edk2/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63003+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63003+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366482786524.0543693545313; Tue, 21 Jul 2020 14:21:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id deJFYY1788612x5pLxo3PWCa; Tue, 21 Jul 2020 14:21:22 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.61]) by mx.groups.io with SMTP id smtpd.web10.5632.1595366481924599903 for ; Tue, 21 Jul 2020 14:21:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VcAaE455zCLqsYeqSMfqYBwfgFKa5IS52s9eWDkLMcTZdeazlAO0ytj0MW9JzCwegFATuUwlRQleW9iAbj4/gFMRQ3KAD8zWCyA7RC8cNl4UvKSZ80W4ZCVBXlWmRJfmZ4sGqq0sFh5S+Pdiv023XYI5NEfgIZHZDRdfSKxwnXzqLphHd4WDXE/+HZ27AVJF2TjANezw2VGh1FjObTSLixkuXkWLa5gC0rlXUqNPiWNkrP/rDOADknV0kEPPZqFBDn8PnJ8lTAWSW9X0bOOT3oMaTYNOvqmyRuWUkHX/0NbHjsYfTbTnsu5Z24Ye5J2Boe6LbU+zg8Atmc15Oocwlg== 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=j1UHV++AGGkyKk8R3P6uIZpa9edH9ot35jHOpgxb3jM=; b=CLXui0uk/Des44z9eJtcRW4j24sg3fTbIXqC9lsqg1UPS2D7KFBddQf13HIoacqeMP3HkNIwGzZaiCdfjdmmrCZGrbGN2/5F39jcEugV/47TqdNUZFDmNRZYCGtDCEqD46j++rOFXcfSPnKTglSGvCWgn1gEwsLGG8mSR27WQg4O7d9WiukaMY43g0ZOMo/dVxDSaN8lMwiUNru9/mJyRMgPS+CkKoBhVK5uQc44cSFW5X1WPpwW4kdYfJdh/LWRQ/Kc85uZxP0L13lZW8/Oeu25qfrqM1YTGF81xNqvis02Ia5WO7dhX5X8BNfad2MoCjG+sinGDD0CmIiw3kUvlQ== 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 X-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:20 +0000 X-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:20 +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: [edk2-devel] [PATCH v11 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF Date: Tue, 21 Jul 2020 16:18:49 -0500 Message-ID: <84d0ad37aeba0f402e48381c7c47afc38903e428.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR13CA0064.namprd13.prod.outlook.com (2603:10b6:3:117::26) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR13CA0064.namprd13.prod.outlook.com (2603:10b6:3:117::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.16 via Frontend Transport; Tue, 21 Jul 2020 21:21:18 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eac9d8a3-8532-4bbc-e24d-08d82dbc02b5 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: iZkfY9cq5/shq1wjdL9RpXdwK2m42aKJ6PHFYmnuZtKeO9PTrgPerHpy2ih5L8oGaygRvEcWQ1ArZGnpmr9VBZL/6N/D1BIpxk9vcDphxQQUpoHG7EdPOohdOs4QROGue4OTkFpOQWiSk02GZVFnL8Ejlebk3KJWYx2UmezZ3lbb9gfjZntwsS2SfxC1vCbrrfNzxnQcu53APBf1hAw97BkyKeoW92DtOUsC0xQirANFcBDmGKROwmJrOdfPwchbuKF1HdAqcpdHomWZCJqwdOAInnQBAbkjym3S8CsSij3JxIH6dZtUFLy3ZpuBlwX31D0F7q8mA73XCzZKVNIEVPw6Tghs2YKH7vpm2i+l5Uj+N9VGNBEEB8fqboLUBl0t X-MS-Exchange-AntiSpam-MessageData: +q7FyXsg0czuYYZNBuns0gkODnilBgyPchHbObONYuE1Ykb3INA6/Jt7FkUhIWgShnsto5y3qjjMBtxI9JK4wkpvIVgrDEQn3MfOAtBpwKXduzJukbSWGnEOJAytGw5wbGO6wVCDEvJFWpDHhOeMtYCoVgMvqu3fwBMrdOkPO3HFWmgMfXe7MMGRy/s563Jw2e2br07UCgFRC0JWFr+mUcha/QXMsA1c7Bp11HqK01JoAIzhVvzy4YTXe28/WCIIhNXN/qzAbIIDS4AuwqJX9X4CGKHlyQM8TldxYnotaX6cDRv4/8HyaiYLkzszd2c+uqEy3iqetNMzQSI+KvrfTMxFLVvRWUB8T2sFX7gAXt3OaiN1EGny/zMXO/+SZ0B9qd4NTWMgj0pKpo6xX4Xe4QWvvM+JOclHyhbQ1xuBrbh4DnsDjm3XBHKu/PpCl+rRBlc1xidO+CglMop/mQ/KsrUgYmuf0N4N6eSI9eB5Vso= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eac9d8a3-8532-4bbc-e24d-08d82dbc02b5 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:19.7989 (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: vc17RwpzMMeSSsNbA648b76KfiCIh11FkfO3qp0DpPDSVeH8Ud5zG4x38LXuSxuH2pkEs7bpHQsVnHcxXppnng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: MKeSAHBi4F6AGuhq2WSkOSJgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366482; bh=6397TKf6zB0+Q1k20AJOTrNQE/3+Y+TH6VhYiZmSXOQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=w/tkduVky4qGbVnvPfYy/yjZWEpZoRjvjlmvqGvdczigwc0wtdezfGiixL1jXe6visN 3r1SfYPc8vwNO2ZfdDOPN6xn+CRdl7OQde8VJtZsoNWpLBBaqR5m3RNRtAHJ9buXn/Bgl JjHoUKAR7zwhHGlXLYX8Ha7r0PCxQAAB9AY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky The base VmgExitLib library provides a default limited interface. As it does not provide full support, create an OVMF version of this library to begin the process of providing full support of SEV-ES within OVMF. SEV-ES support is only provided for X64 builds, so only OvmfPkgX64.dsc is updated to make use of the OvmfPkg version of the library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 36 ++++ OvmfPkg/Library/VmgExitLib/VmgExitLib.c | 159 ++++++++++++++++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 81 +++++++++ 4 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.c create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 27f5225fc281..60be5eae3d2b 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -233,7 +233,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.inf new file mode 100644 index 000000000000..d003ac63173e --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -0,0 +1,36 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D VmgExitLib + FILE_GUID =3D 0e923c25-13cd-430b-8714-ffe85652a97b + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D X64 +# + +[Sources.common] + VmgExitLib.c + VmgExitVcHandler.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c b/OvmfPkg/Library/VmgE= xitLib/VmgExitLib.c new file mode 100644 index 000000000000..53040cc6f649 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c @@ -0,0 +1,159 @@ +/** @file + VMGEXIT Support Library. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Check for VMGEXIT error + + Check if the hypervisor has returned an error after completion of the VM= GEXIT + by examining the SwExitInfo1 field of the GHCB. + + @param[in] Ghcb A pointer to the GHCB + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT proces= sing + did not succeed. + +**/ +STATIC +UINT64 +VmgExitErrorCheck ( + IN GHCB *Ghcb + ) +{ + GHCB_EVENT_INJECTION Event; + GHCB_EXIT_INFO ExitInfo; + UINT64 Status; + + ExitInfo.Uint64 =3D Ghcb->SaveArea.SwExitInfo1; + ASSERT ((ExitInfo.Elements.Lower32Bits =3D=3D 0) || + (ExitInfo.Elements.Lower32Bits =3D=3D 1)); + + Status =3D 0; + if (ExitInfo.Elements.Lower32Bits =3D=3D 0) { + return Status; + } + + if (ExitInfo.Elements.Lower32Bits =3D=3D 1) { + ASSERT (Ghcb->SaveArea.SwExitInfo2 !=3D 0); + + // + // Check that the return event is valid + // + Event.Uint64 =3D Ghcb->SaveArea.SwExitInfo2; + if (Event.Elements.Valid && + Event.Elements.Type =3D=3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION) { + switch (Event.Elements.Vector) { + case GP_EXCEPTION: + case UD_EXCEPTION: + // + // Use returned event as return code + // + Status =3D Event.Uint64; + } + } + } + + if (Status =3D=3D 0) { + GHCB_EVENT_INJECTION GpEvent; + + GpEvent.Uint64 =3D 0; + GpEvent.Elements.Vector =3D GP_EXCEPTION; + GpEvent.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + GpEvent.Elements.Valid =3D 1; + + Status =3D GpEvent.Uint64; + } + + return Status; +} + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ) +{ + Ghcb->SaveArea.SwExitCode =3D ExitCode; + Ghcb->SaveArea.SwExitInfo1 =3D ExitInfo1; + Ghcb->SaveArea.SwExitInfo2 =3D ExitInfo2; + + // + // Guest memory is used for the guest-hypervisor communication, so fence + // the invocation of the VMGEXIT instruction to ensure GHCB accesses are + // synchronized properly. + // + MemoryFence (); + AsmVmgExit (); + MemoryFence (); + + return VmgExitErrorCheck (Ghcb); +} + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ) +{ + SetMem (&Ghcb->SaveArea, sizeof (Ghcb->SaveArea), 0); +} + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ) +{ +} + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c new file mode 100644 index 000000000000..b6a955ed8088 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -0,0 +1,81 @@ +/** @file + X64 #VC Exception Handler functon. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + EFI_SYSTEM_CONTEXT_X64 *Regs; + GHCB *Ghcb; + UINT64 ExitCode, Status; + EFI_STATUS VcRet; + + VcRet =3D EFI_SUCCESS; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT (Msr.GhcbInfo.Function =3D=3D 0); + ASSERT (Msr.Ghcb !=3D 0); + + Regs =3D SystemContext.SystemContextX64; + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + + ExitCode =3D Regs->ExceptionData; + switch (ExitCode) { + default: + Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, ExitCode, 0); + if (Status =3D=3D 0) { + Regs->ExceptionData =3D 0; + *ExceptionType =3D GP_EXCEPTION; + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid !=3D 0) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; + } else { + Regs->ExceptionData =3D 0; + } + + *ExceptionType =3D Event.Elements.Vector; + } + + VcRet =3D EFI_PROTOCOL_ERROR; + } + + VmgDone (Ghcb); + + return VcRet; +} --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63003): https://edk2.groups.io/g/devel/message/63003 Mute This Topic: https://groups.io/mt/75713074/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63004+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63004+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366491662797.5863177759497; Tue, 21 Jul 2020 14:21:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tQ1xYY1788612x4w5bE78rq4; Tue, 21 Jul 2020 14:21:31 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.49]) by mx.groups.io with SMTP id smtpd.web10.5642.1595366490803631592 for ; Tue, 21 Jul 2020 14:21:30 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KmNa2YWypvYgELSbEc7171O3Wn6Wo1+MM3dMpH/lkLNGf8B1XKzXhHn6JnxNoko46Q5dACOoCy6UFC7UMdb6Jkajqv4wqMnrXHRUBt6PBNHXtRYZw3op8ILi3F1rsm4rv0LMQ7xaiO/+w9w09K+KFkLHFpfeQcMuwIK8J2jMRd4dDRS+8ZsxEpW6XGc6zZvbD4Is/jqp3GausskG47fjf+jTqBHVpuXP8QIxmiXXB1a5pueTpr4UkLYut2wj/pL3VkH/86MNMGDUJwhnIuvgC3dAZalaSE7V2syj6EJjw6pghv7If50dnxtHCZYxCjuIo976WZzc7muJG0unBtdjqQ== 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=YLiynLfWPYBI3p6aciiysyOQa+ljPEYq8UZEiba60Qk=; b=R8v1n58hJqtKCJdVUd2jk+ohj+Lg4oiFNgurqij2UGZFIzouAHnKRN8l1eZ6iBVqYb6ocbDGYS0M37QhCdfz03QR4rNgGRTq4tqLfZ6yDpeZ0YfDPPPuImpM+yyCXlxy4orjheOT+WvaZKOsJgcAis8DygEcxPf7XZdLid6GedGPGqBDAFeWGz3+uM7vC4B2N3nMJtE0SyghzITF5BlEFV7E0In8tI5SP9wi6ro0mj0m6jn8O4ZkTZI09v7o8W/WeUjK9oDhwFdI3RK2yNrhD6Ff3BJssgo8TwO/Bw2vYrJA2IpoS4B9F+oFUHkn8ueslb2Lv0LqlQHmejUfMq+bAg== 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 X-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:28 +0000 X-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:28 +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: [edk2-devel] [PATCH v11 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events Date: Tue, 21 Jul 2020 16:18:50 -0500 Message-ID: <236c27b64ecff470d2758a1bc26daa5cf3922d67.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0006.namprd02.prod.outlook.com (2603:10b6:803:2b::16) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0006.namprd02.prod.outlook.com (2603:10b6:803:2b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:21:27 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 710e0543-df1a-429d-b8cf-08d82dbc079b X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: GLAP0kCDbkDtGY/1DGTwnL/RaAx6emok+thkyw4uJPfOdxppHUX5ipKIg89tVJilUs3zEW1ZLkb7fyT6HQRREnaqBOzlI78KZu4q/Uk7ZQzy6tPV4l/JVpxKgadChRvhjqCaSew4Vo/CmXRaLa70R4GEVDPvnmWWHOsT+8QdNl86gWu4CA4BQF9O95xdj+G8FS1p+A3C/6l7+2NvEPZc3x/plganjDbh7EZs2yn9TAgbZVx4qOvqIQ0U6Qb1nFhgitmw+Lft1QoE/KHLT8w4aAJaAEx2ztzAM4JN0HjT9z1FoyQ4Url9aEn62X71QSAiNQYTd6/UyuJt7ikFKUUYsI2E3xZm6XsrDBTHnH9Fe0Fy3ISJ4diyLVl4m9JiqfGsZFfo7larGcpuT/6GT0wLqv9CL703c2vgeTtkF/jMY+FPsJtQ3uIdOE3ERXqfrRGzlnezsL6lcpf+iUsDlGPSAQ== X-MS-Exchange-AntiSpam-MessageData: quXE/fqxeRUabVsDWGJ3jREHAch1wdpFumo6y8nICLKvfKrGlQTv7rOPUWtgMFHDrC5sZZJU1ByilWj0B3IAtuev88K53xFiyvTsKaaR7fVCyom1Fhh1r05FySof5QzkdmmEo9fSivf9WiRnz1nzsrkCchd3LH2vU0kHaqb0gtRu8iI31uzymKviW0WL5Ug9iLFnrJrK/9WGnG70CPE3cS4XntdED6ACV08QZsAZm3H6I+6X4Wz5D1ESWDg33Fte/IH6hP9kj8mlL+gAKQBWvRquhNBIuweqjMxY7xon5vkSvqcWd4yhm9yxAop1vmf74jM5LxwStyuUckXqJU55pyCJnoWRklTy/o1pROyxGcwmW4PFkaskzvzDDwn069pQfJ7m4Uh8PfTWrgIanY0rw5h3imzeQVlNWNi6CNqPMhq0m/c7pLvv0HmFmvecdDWgFzrcdHcFxuhbRZrEVSe1EEAeA9kBMGmmFPuN0jf30gk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 710e0543-df1a-429d-b8cf-08d82dbc079b 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:27.9511 (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: 1L7ZHSMg18dNkriUZFjpsoZs8eCyT/grX+cYVzfo2xScxj1k+HOMbkTX2XNfVR0syk5yuEY5BN257UMYPbzQ4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: pXp9QeMbKw8n24upmg0LUimex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366491; bh=NczE0U5gZLEdPO9+SqDBDEoBO+0uw6aMIVO6PgOOzZM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GFuqGyEhkdrVnR88ImjWCzegoExU8MEhZI3rxLTeVDxhdTMZcyN9ho7oFpljCRMD6At PlXv48ZjEZ9IF42js1nnU9kK22Dgoie3RncdwjxxrAJmcTXTiD9fEI+AS3DtHFQS9W9Vk rcqAfyGd4cZkxl7QHfvMiT3f+KPoYdTj6fs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a IOIO_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a IOIO_PROT NAE event. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXITINFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../IndustryStandard/InstructionParsing.h | 83 +++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 560 +++++++++++++++++- 2 files changed, 629 insertions(+), 14 deletions(-) create mode 100644 OvmfPkg/Include/IndustryStandard/InstructionParsing.h diff --git a/OvmfPkg/Include/IndustryStandard/InstructionParsing.h b/OvmfPk= g/Include/IndustryStandard/InstructionParsing.h new file mode 100644 index 000000000000..149ff328e06c --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/InstructionParsing.h @@ -0,0 +1,83 @@ +/** @file + Instruction parsing support definitions. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __INSTRUCTION_PARSING_H__ +#define __INSTRUCTION_PARSING_H__ + +#include +#include + +// +// Instruction REX prefix definition +// +typedef union { + struct { + UINT8 BitB:1; + UINT8 BitX:1; + UINT8 BitR:1; + UINT8 BitW:1; + UINT8 Rex:4; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_REX_PREFIX; + +// +// Instruction ModRM definition +// +typedef union { + struct { + UINT8 Rm:3; + UINT8 Reg:3; + UINT8 Mod:2; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_MODRM; + +// +// Instruction SIB definition +// +typedef union { + struct { + UINT8 Base:3; + UINT8 Index:3; + UINT8 Scale:2; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_SIB; + +// +// Legacy Instruction Prefixes +// +#define OVERRIDE_SEGMENT_CS 0x2E +#define OVERRIDE_SEGMENT_DS 0x3E +#define OVERRIDE_SEGMENT_ES 0x26 +#define OVERRIDE_SEGMENT_SS 0x36 +#define OVERRIDE_SEGMENT_FS 0x64 +#define OVERRIDE_SEGMENT_GS 0x65 +#define OVERRIDE_OPERAND_SIZE 0x66 +#define OVERRIDE_ADDRESS_SIZE 0x67 +#define LOCK_PREFIX 0xF0 +#define REPNZ_PREFIX 0xF2 +#define REPZ_PREFIX 0xF3 + +// +// REX Prefixes +// +#define REX_PREFIX_START 0x40 +#define REX_PREFIX_STOP 0x4F +#define REX_64BIT_OPERAND_SIZE_MASK 0x08 + +// +// Two-byte Opcode Flag +// +#define TWO_BYTE_OPCODE_ESCAPE 0x0F + +#endif diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6a955ed8088..04e8b8aebf7d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,529 @@ #include #include #include +#include + +// +// Instruction execution mode definition +// +typedef enum { + LongMode64Bit =3D 0, + LongModeCompat32Bit, + LongModeCompat16Bit, +} SEV_ES_INSTRUCTION_MODE; + +// +// Instruction size definition (for operand and address) +// +typedef enum { + Size8Bits =3D 0, + Size16Bits, + Size32Bits, + Size64Bits, +} SEV_ES_INSTRUCTION_SIZE; + +// +// Intruction segment definition +// +typedef enum { + SegmentEs =3D 0, + SegmentCs, + SegmentSs, + SegmentDs, + SegmentFs, + SegmentGs, +} SEV_ES_INSTRUCTION_SEGMENT; + +// +// Instruction rep function definition +// +typedef enum { + RepNone =3D 0, + RepZ, + RepNZ, +} SEV_ES_INSTRUCTION_REP; + +typedef struct { + UINT8 Rm; + UINT8 Reg; + UINT8 Mod; +} SEV_ES_INSTRUCTION_MODRM_EXT; + +typedef struct { + UINT8 Base; + UINT8 Index; + UINT8 Scale; +} SEV_ES_INSTRUCTION_SIB_EXT; + +// +// Instruction opcode definition +// +typedef struct { + SEV_ES_INSTRUCTION_MODRM_EXT ModRm; + + SEV_ES_INSTRUCTION_SIB_EXT Sib; + + UINTN RegData; + UINTN RmData; +} SEV_ES_INSTRUCTION_OPCODE_EXT; + +// +// Instruction parsing context definition +// +typedef struct { + GHCB *Ghcb; + + SEV_ES_INSTRUCTION_MODE Mode; + SEV_ES_INSTRUCTION_SIZE DataSize; + SEV_ES_INSTRUCTION_SIZE AddrSize; + BOOLEAN SegmentSpecified; + SEV_ES_INSTRUCTION_SEGMENT Segment; + SEV_ES_INSTRUCTION_REP RepMode; + + UINT8 *Begin; + UINT8 *End; + + UINT8 *Prefixes; + UINT8 *OpCodes; + UINT8 *Displacement; + UINT8 *Immediate; + + INSTRUCTION_REX_PREFIX RexPrefix; + + BOOLEAN ModRmPresent; + INSTRUCTION_MODRM ModRm; + + BOOLEAN SibPresent; + INSTRUCTION_SIB Sib; + + UINTN PrefixSize; + UINTN OpCodeSize; + UINTN DisplacementSize; + UINTN ImmediateSize; + + SEV_ES_INSTRUCTION_OPCODE_EXT Ext; +} SEV_ES_INSTRUCTION_DATA; + +// +// Non-automatic Exit function prototype +// +typedef +UINT64 +(*NAE_EXIT) ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ); + + +/** + Checks the GHCB to determine if the specified register has been marked v= alid. + + The ValidBitmap area represents the areas of the GHCB that have been mar= ked + valid. Return an indication of whether the area of the GHCB that holds t= he + specified register has been marked valid. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication Block + @param[in] Reg Offset in the GHCB of the register to check + + @retval TRUE Register has been marked vald in the GHCB + @retval FALSE Register has not been marked valid in the GHCB + +**/ +STATIC +BOOLEAN +GhcbIsRegValid ( + IN GHCB *Ghcb, + IN GHCB_REGISTER Reg + ) +{ + UINT32 RegIndex; + UINT32 RegBit; + + RegIndex =3D Reg / 8; + RegBit =3D Reg & 0x07; + + return ((Ghcb->SaveArea.ValidBitmap[RegIndex] & (1 << RegBit)) !=3D 0); +} + +/** + Marks a register as valid in the GHCB. + + The ValidBitmap area represents the areas of the GHCB that have been mar= ked + valid. Set the area of the GHCB that holds the specified register as val= id. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication Bl= ock + @param[in] Reg Offset in the GHCB of the register to mark valid + +**/ +STATIC +VOID +GhcbSetRegValid ( + IN OUT GHCB *Ghcb, + IN GHCB_REGISTER Reg + ) +{ + UINT32 RegIndex; + UINT32 RegBit; + + RegIndex =3D Reg / 8; + RegBit =3D Reg & 0x07; + + Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit); +} + +/** + Decode instruction prefixes. + + Parse the instruction data to track the instruction prefixes that have + been used. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + +**/ +STATIC +VOID +DecodePrefixes ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_MODE Mode; + SEV_ES_INSTRUCTION_SIZE ModeDataSize; + SEV_ES_INSTRUCTION_SIZE ModeAddrSize; + UINT8 *Byte; + + // + // Always in 64-bit mode + // + Mode =3D LongMode64Bit; + ModeDataSize =3D Size32Bits; + ModeAddrSize =3D Size64Bits; + + InstructionData->Mode =3D Mode; + InstructionData->DataSize =3D ModeDataSize; + InstructionData->AddrSize =3D ModeAddrSize; + + InstructionData->Prefixes =3D InstructionData->Begin; + + Byte =3D InstructionData->Prefixes; + for ( ; ; Byte++, InstructionData->PrefixSize++) { + // + // Check the 0x40 to 0x4F range using an if statement here since some + // compilers don't like the "case 0x40 ... 0x4F:" syntax. This avoids + // 16 case statements below. + // + if ((*Byte >=3D REX_PREFIX_START) && (*Byte <=3D REX_PREFIX_STOP)) { + InstructionData->RexPrefix.Uint8 =3D *Byte; + if ((*Byte & REX_64BIT_OPERAND_SIZE_MASK) !=3D 0) { + InstructionData->DataSize =3D Size64Bits; + } + continue; + } + + switch (*Byte) { + case OVERRIDE_SEGMENT_CS: + case OVERRIDE_SEGMENT_DS: + case OVERRIDE_SEGMENT_ES: + case OVERRIDE_SEGMENT_SS: + if (Mode !=3D LongMode64Bit) { + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D (*Byte >> 3) & 3; + } + break; + + case OVERRIDE_SEGMENT_FS: + case OVERRIDE_SEGMENT_GS: + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D *Byte & 7; + break; + + case OVERRIDE_OPERAND_SIZE: + if (InstructionData->RexPrefix.Uint8 =3D=3D 0) { + InstructionData->DataSize =3D + (Mode =3D=3D LongMode64Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + } + break; + + case OVERRIDE_ADDRESS_SIZE: + InstructionData->AddrSize =3D + (Mode =3D=3D LongMode64Bit) ? Size32Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + break; + + case LOCK_PREFIX: + break; + + case REPZ_PREFIX: + InstructionData->RepMode =3D RepZ; + break; + + case REPNZ_PREFIX: + InstructionData->RepMode =3D RepNZ; + break; + + default: + InstructionData->OpCodes =3D Byte; + InstructionData->OpCodeSize =3D (*Byte =3D=3D TWO_BYTE_OPCODE_ESCAPE= ) ? 2 : 1; + + InstructionData->End =3D Byte + InstructionData->OpCodeSize; + InstructionData->Displacement =3D InstructionData->End; + InstructionData->Immediate =3D InstructionData->End; + return; + } + } +} + +/** + Determine instruction length + + Return the total length of the parsed instruction. + + @param[in] InstructionData Instruction parsing context + + @return Length of parsed instruction + +**/ +STATIC +UINT64 +InstructionLength ( + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return (UINT64) (InstructionData->End - InstructionData->Begin); +} + +/** + Initialize the instruction parsing context. + + Initialize the instruction parsing context, which includes decoding the + instruction prefixes. + + @param[in, out] InstructionData Instruction parsing context + @param[in] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in] Regs x64 processor context + +**/ +STATIC +VOID +InitInstructionData ( + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, + IN GHCB *Ghcb, + IN EFI_SYSTEM_CONTEXT_X64 *Regs + ) +{ + SetMem (InstructionData, sizeof (*InstructionData), 0); + InstructionData->Ghcb =3D Ghcb; + InstructionData->Begin =3D (UINT8 *) Regs->Rip; + InstructionData->End =3D (UINT8 *) Regs->Rip; + + DecodePrefixes (Regs, InstructionData); +} + +/** + Report an unsupported event to the hypervisor + + Use the VMGEXIT support to report an unsupported event to the hypervisor. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication + Block + @param[in] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @return New exception value to propagate + +**/ +STATIC +UINT64 +UnsupportedExit ( + IN GHCB *Ghcb, + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, Regs->ExceptionData, 0); + if (Status =3D=3D 0) { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D 0; + Event.Elements.Vector =3D GP_EXCEPTION; + Event.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + Event.Elements.Valid =3D 1; + + Status =3D Event.Uint64; + } + + return Status; +} + +/** + Build the IOIO event information. + + The IOIO event information identifies the type of IO operation to be per= formed + by the hypervisor. Build this information based on the instruction data. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + + @return IOIO event information value + +**/ +STATIC +UINT64 +IoioExitInfo ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo; + + ExitInfo =3D 0; + + switch (*(InstructionData->OpCodes)) { + // + // IN immediate opcodes + // + case 0xE4: + case 0xE5: + InstructionData->ImmediateSize =3D 1; + InstructionData->End++; + ExitInfo |=3D IOIO_TYPE_IN; + ExitInfo |=3D ((*(InstructionData->OpCodes + 1)) << 16); + break; + + // + // OUT immediate opcodes + // + case 0xE6: + case 0xE7: + InstructionData->ImmediateSize =3D 1; + InstructionData->End++; + ExitInfo |=3D IOIO_TYPE_OUT; + ExitInfo |=3D ((*(InstructionData->OpCodes + 1)) << 16) | IOIO_TYPE_OU= T; + break; + + // + // IN register opcodes + // + case 0xEC: + case 0xED: + ExitInfo |=3D IOIO_TYPE_IN; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + // + // OUT register opcodes + // + case 0xEE: + case 0xEF: + ExitInfo |=3D IOIO_TYPE_OUT; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + default: + return 0; + } + + switch (*(InstructionData->OpCodes)) { + // + // Single-byte opcodes + // + case 0xE4: + case 0xE6: + case 0xEC: + case 0xEE: + ExitInfo |=3D IOIO_DATA_8; + break; + + // + // Length determined by instruction parsing + // + default: + ExitInfo |=3D (InstructionData->DataSize =3D=3D Size16Bits) ? IOIO_DAT= A_16 + : IOIO_DATA_32; + } + + switch (InstructionData->AddrSize) { + case Size16Bits: + ExitInfo |=3D IOIO_ADDR_16; + break; + + case Size32Bits: + ExitInfo |=3D IOIO_ADDR_32; + break; + + case Size64Bits: + ExitInfo |=3D IOIO_ADDR_64; + break; + + default: + break; + } + + if (InstructionData->RepMode !=3D 0) { + ExitInfo |=3D IOIO_REP; + } + + return ExitInfo; +} + +/** + Handle an IOIO event. + + Use the VMGEXIT instruction to handle an IOIO event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +IoioExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); + if (ExitInfo1 =3D=3D 0) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + 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); + + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + 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)); + } + + return 0; +} =20 /** Handle a #VC exception. @@ -38,6 +561,8 @@ VmgExitHandleVc ( MSR_SEV_ES_GHCB_REGISTER Msr; EFI_SYSTEM_CONTEXT_X64 *Regs; GHCB *Ghcb; + NAE_EXIT NaeExit; + SEV_ES_INSTRUCTION_DATA InstructionData; UINT64 ExitCode, Status; EFI_STATUS VcRet; =20 @@ -54,24 +579,31 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_IOIO_PROT: + NaeExit =3D IoioExit; + break; + default: - Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, ExitCode, 0); - if (Status =3D=3D 0) { - Regs->ExceptionData =3D 0; - *ExceptionType =3D GP_EXCEPTION; + NaeExit =3D UnsupportedExit; + } + + InitInstructionData (&InstructionData, Ghcb, Regs); + + Status =3D NaeExit (Ghcb, Regs, &InstructionData); + if (Status =3D=3D 0) { + Regs->Rip +=3D InstructionLength (&InstructionData); + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid !=3D 0) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; } else { - GHCB_EVENT_INJECTION Event; - - Event.Uint64 =3D Status; - if (Event.Elements.ErrorCodeValid !=3D 0) { - Regs->ExceptionData =3D Event.Elements.ErrorCode; - } else { - Regs->ExceptionData =3D 0; - } - - *ExceptionType =3D Event.Elements.Vector; + Regs->ExceptionData =3D 0; } =20 + *ExceptionType =3D Event.Elements.Vector; + VcRet =3D EFI_PROTOCOL_ERROR; } =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63004): https://edk2.groups.io/g/devel/message/63004 Mute This Topic: https://groups.io/mt/75713083/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63005+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63005+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366499194885.8741225325581; Tue, 21 Jul 2020 14:21:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id yGjRYY1788612xXYD8woCP8E; Tue, 21 Jul 2020 14:21:38 -0700 X-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 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 X-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 X-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: [edk2-devel] [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: 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) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-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-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-Message-Info: 7bGTLvvxa6lysmplb3RO5UEdZ4LOFiDGLnSfCl+sDQy17nXCtd4gqsaXFTN4h6HWNaadI1fXDhxB+BiuGaevrarX0zB9OCQMOzNw93RlRRXXDP7MwWUf+OM+be+/q9AFes/RbgaooeQUc6XwocQAYVnS3y9dlR4d+CHD/zvRZGAAapSUOeKBvyNe4fK0l17yjyx3CAnidQB1VTQxjEuek6xjLBFGagpOLPBkqbdnvM0NdjjJwzvHLybKjdHsusd3mXpTcPBaSHpCf3ArbwE+rhM9n8cEMzWTKDNz3utBAqhnpYiZHQO53X+lx1Q2gw+sw51m3xanKZoakDz0lNQdjRPEb/ChDK47lGow/fXUvKp6z45FOOBzFbzSMs7ysJlu8Vt9EBP5tDVUMuw4eJzSDop0ERXYHAgFBVsQAioKKaBRIwwWIKIzxGIG61G+EicI3KY1udZM8laY4n+eQDsbDA== 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 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: ip6NeWotgInbQg6td3sniI9Ox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366498; bh=xb0uwugfrP3+NA3ZR0xdKnU0MZjz7512fkJGN5LtUJQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Nb+ApD7L+PWiDRd56OKQRt4oomSDr1+Uz35JatVmw7apb1vxwDFLqsXvRNS+skidrlr V9PmC/Z44eMt/of/TlDfv4w2qisGGNi9uZkpAPMMR3Bjgpj/3W+gg5TmGNRw1gmOj1s8m dK6Di6DPiaJncCTedxIDbKs+9jXKLmnUyIs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63005): https://edk2.groups.io/g/devel/message/63005 Mute This Topic: https://groups.io/mt/75713086/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63006+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63006+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366507486190.87958982947225; Tue, 21 Jul 2020 14:21:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9UHGYY1788612xJ4Fpnd8rLs; Tue, 21 Jul 2020 14:21:47 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.79]) by mx.groups.io with SMTP id smtpd.web10.5646.1595366506640805999 for ; Tue, 21 Jul 2020 14:21:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h7jZVsZ/48sTgv7ZEfXssUaOJawGgq/2+TQEVH1nDy6CZ1pvRFdtHI9IaFiizH3lMi9QqKdCNM3UMm8kWr/3VXj6nGufQY+0qVQNHEk9BSq6A5DHUNnIDfGPDMOx9w4Luss+SdbopBWvGDl0/L1hxSVopwcAf9Dek2y/InrhD2LeKNba+JYgX9gY/OlDRX2GOlmWOyYaCZ9N/PyZmsA9ppy6FJPKtlJayA4N05tpeJLPvp5nK6arqTwxLVXME8uuh42VmPgNbR7G+Uja30j9mB7/3UWRr4OFUSh5gbWGs2H7BA9ts5yRYmlAhvSaViq/WiI7+wjue5XkKkGuYB+NBg== 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=DefcxGXcet0YpbciDB6cqSIPAFoRtyFhEUPqxpHT3rE=; b=AcvBFnPWd63YE1CywwEPnzgMCpsH4RXjGccCRfOa4SFYszbcJlFKIF1aeZm4TSNhK2fqjoqoTYBlmuHz/1KZYZ4FPeSToomHakx6rGkPVkrE0e/GSs2ycaU7MXM0FqAKEZH1PWYm7UrSCrzmGvk/XrBgNIwzcrAxNv+0xlZ6FDX47AgQYhiZUF7FQYlH5baGMFu11+4qEnmQjkN29oCw/4UbdHJVuhjhGccFPFvv9nnZ0XwhbV9V0J+LjxEuLb18kXroBVlUWSy3f2qpdiXgGI7iPOHmwCRxbXxJPbNFQ0TBEWWtoy4QJXtC2Bo9pzssJzK4fDD5gCvRvt3bejd48w== 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 X-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:44 +0000 X-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:44 +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: [edk2-devel] [PATCH v11 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Tue, 21 Jul 2020 16:18:52 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0021.namprd08.prod.outlook.com (2603:10b6:805:66::34) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR08CA0021.namprd08.prod.outlook.com (2603:10b6:805:66::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:21:43 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8428ef09-70ac-47c4-49a0-08d82dbc118e X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: JXtHF/OrMIH4N//8Z4Hd/alU8UgXSRAzqatVGi5UMKnhZK+3sMFQZH86OZZqH/TF1b/sfobptSHXlU/JKu/qGPYeaJYLtaPHIj81a3wLdoUs5VGpocf5qkN/c7dlh76W8MC+o8gr+c/L1ZhjbaIU5Qem9uNM7ky7UiqapAbHWyG0uMdUYr3ShEepeJqvRvJzeV6PpGr9TDD++X+UDnuf3k3gV+k3lBd4vNCywGXawZsTxLYh2uFRBud9SzkqIKl0vN+9qo/OcuaY29MXHLmcqBF4QfhzVcFbpKixuKoWkG6MKEO1dWLEqenmDFQepJbSX6iCnsJkN6yjUSfVmWjaWfbK2kMAyQXEqab+Hbo/vk03Hrj+G1K71j1MshRu+8UUVpBnx+QNfjlE+SkBh1cQlmAmw9IlzOH4k/Emvm6o8Dpq+9G1y5Y+Qlqomg0CyNZaQHrIT12VjfHWibqghZp0Tg== X-MS-Exchange-AntiSpam-MessageData: fpWwEVV1LpkxN1JQsehdwQndafGqnIIPHi8Ea5Awi+Ql+X81QBYy7kmEGsJp0qKElepp+113+yzAt4t9FxBOMuc9IpcdkvHz5ajYBJ/QNhl443EFBt/fXdREiBbzCFG4Hcs1WTTxdXRcLTWjpmxL+Ol0teRbx9l8bs/5Mofi6+iptBxse4jPEZNWWt21atbmYzCuoxUjocR0YPWfa1lvh8TKQ2sBY+Cs6iNXETKK6sXmqsiSJ/Vjcjx1pVckFrBq0oi+xhaGUm9O4wFMy673uXhzCcg82YzkWtVpi8vsVKKLoCoyBX40ImGBLLraZHM9hExfIdRinSlPuPxLbkuddWaHQ7/IPkl5lpjTfHMsmtzCTikz09KJ2dZL7XgmhhDm3XpCq1RCGn04IizBqAZuIlx9efN6+gy/7vvpimatwV1VyDX+FR38YQ7U8JzUvQXCMVQCER1LU7EmAD7xO3SpwxapDs8lNtpo5AK8Sqjb2Is= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8428ef09-70ac-47c4-49a0-08d82dbc118e 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:44.6563 (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: iIvaYInVrW7C99sZXE3Ggf5tJeyI1PE/3goyeExHpQsO8pHGRqyXDTqKoxDmCkkZj/sAto6zkBL29xcPGQ6HGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: cwYiykiWAZGCaUVVhTvCBQWTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366507; bh=JmQFSqwwg9Yqf7qM1TWCcIs2BSTygKpnqk5cBXePS9Q=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LaYZomDJV9240JuDD5w7TCiIb/DlNXe5QezDVkImgOEPGy7Uanp8VfOmqfA1o2TZek5 AesUONFIvJ+aadP4I3snQWE6qwgIn0sRsEA0LN06ubvCdSjn5Dkqi2xOCbKyWpJCDOBiF 2+TD1mfuYGZw3od52MvfQV+m6Jj0VGg+f2g= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a CPUID NAE event. Additionally, CPUID 0x0000_000d (CPUID_EXTENDED_STATE) requires XCR0 to be supplied in the GHCB, so add support to issue the XGETBV instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6ac3552894f..1c9c272a250e 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 // @@ -597,6 +598,61 @@ IoioExit ( return 0; } =20 +/** + Handle a CPUID event. + + Use the VMGEXIT instruction to handle a CPUID event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +CpuidExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + if (Regs->Rax =3D=3D CPUID_EXTENDED_STATE) { + IA32_CR4 Cr4; + + Cr4.UintN =3D AsmReadCr4 (); + Ghcb->SaveArea.XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; + GhcbSetRegValid (Ghcb, GhcbXCr0); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRbx) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rbx =3D Ghcb->SaveArea.Rbx; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -641,6 +697,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_CPUID: + NaeExit =3D CpuidExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63006): https://edk2.groups.io/g/devel/message/63006 Mute This Topic: https://groups.io/mt/75713088/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63007+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63007+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15953665165181000.5870329380629; Tue, 21 Jul 2020 14:21:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7SXHYY1788612xBRssi58INj; Tue, 21 Jul 2020 14:21:56 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.50]) by mx.groups.io with SMTP id smtpd.web11.5518.1595366515662480706 for ; Tue, 21 Jul 2020 14:21:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BmuRCOC6PVEUFeN6Lol9Y42Nvf3amX1/7Q3f1jXTXGcp3nnaavcI8wSeduZc/f1YBOHbeuGuKirUYln8CuRRidIHYJZeY4XshtUZ2e6eWcmmN1oPk5tKAonIpUilF+EaIx7aJut6clEeSIiCZJBmJGhiFB1ciTvc25DRMrlT5dovkXOazG09buYorhyIAwMShCOrZQmMV4Z4gwLAA+ZhH6Vg4zMK3HeFsDRCEhAMxjbhV9ZZmjw2CTXy4jd03LzZKyV7BCBxr6WeUv8EuMsVI2ZJJhxvRIhzC6lJ/A9149sPMVKuenn8w56VJlhxxZef0Q6PQ9SeThH1ze2SoChDPA== 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=z7KM/QY3QdiNzO0sLsMAJB/dGUXDqeKlzSZHqwBk/3M=; b=oKcz1TyLtTP53xz9r5Abi1rLrbM0xBrqgPfQtZR7EfRzTaWLAdNdbJ1dNeDs+AVMCNIGoGOk28IL2yGuTIm5fgVpoaiQWScut+bCcvEgL8yNFKacAMMtFHAM/wWukS/QJm+a6oLKD6a5+AgSss1S58XqjMzBz1PF0+UTmYv+N/xjUEcaASb7Mz3MCKkWiT6V7iJpPxObgJ4SC4vmeGIxsJWR41ht4fH6ZqbP6seQlkQtcW1LesO0N9nF2JraiC22VfBuiqb5OhFj44hsWGVq/RINLlRfNC8ZjYO7DDcTgKzz46b/niX8rXzRUG1rhj272WOW/BvWbPpyo/CCe/FKhA== 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 X-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:53 +0000 X-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:53 +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: [edk2-devel] [PATCH v11 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Tue, 21 Jul 2020 16:18:53 -0500 Message-ID: <91f16c26903a7d26ca9457f4d2d1631505a8c7cd.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0035.namprd05.prod.outlook.com (2603:10b6:803:40::48) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0035.namprd05.prod.outlook.com (2603:10b6:803:40::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.17 via Frontend Transport; Tue, 21 Jul 2020 21:21:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 981c7022-3929-4322-d552-08d82dbc16e4 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ocRboPTsE7k+fc67sfYrF0SrERRaIOkNL76xwQnAH0EtQG8snhbQxaANqvQwBQAsnPkN6La/GAd6HWimR1N6GQK5IWnhsGMB9tM23LRbo00VNKPAqFOO3og4aD2KY8hMNytlFJPRc+gdlvdjEsPp1pzzf7hr5mRo+DAOyJmJzIUQFFC7QID0lt9uyHL/IocrUgVuUTeN/rOthTlz9lKhwre0XKIw8cHZNGQd+OiwhLX9pWdHpPdlnOVLLWkPwY0DrURj7Pj9G2bTx+IjR4ix0/0FF+zilweiK5zEhw9oDSBKgw3Y2WfW1c2thkj3dN4yoeFFgGEqSMzvvTMR/87FXKx26wXl5CZqbkkNOGXGbOJkMa56i7/LWXrLmzkY88x6qrzjDaNuMIa2r5mMbhc1O4l8Ws0QeQDdqUD12MwwY8Tgmt/gJOWa5oTD66m/xCrY+nnTyt+QhoFaLPGNaXqIrQ== X-MS-Exchange-AntiSpam-MessageData: hFLDJ9UbZI0iZ/nXK3liJTbqjQYinM+8WzXfwnSRHJ5yKc5EqetO8Wb7XYuLOU8QoEnv2mshtkxNRjpC8C580BQfvlOWNeLTkCun7UG2X2cWgDSxRy7G+7xh5RaJHsTELSW7/V0VJdIhNGisB0fWsJveg73aHGFPXMeK4i3LSet9QOjUe31UZci2uABtG1S8WCxBj4OcB1Ue5WFlFaS+EkRtRlH+vpsfDZmiYUfCHQCHCZYeK7rBj/aaZ5y+Qu3oetmwSwFdJg4E3u7uZmdWeavC0dt0Xt92BoJAgg73PFe1lW4rtU9G294BhPARW1azz739v7t5Dl7Me8D+LoRCjeGCyzhEAaMqyFZJvHDavyK2d2vodvorwPxpFTHKjuin5bjcs1DUDquYdcfEu8aLJJZLhhUDuuOTCxTZnhEUbFoOlA2Aew0ZO4THeX4A34p3BiN9Fv8Pp2vZ8FNohohux/69HeMpM7uiXHdng3Tb1v8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 981c7022-3929-4322-d552-08d82dbc16e4 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:53.6041 (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: YAneDSer2ZHqLP9TOHdq8y9sGIxdfNvkN9f/5ztMtPgiPU1TJMR4jcYJSARljv6mu4z77hRY6pS/YvcH5zthAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: bZoie8hecuFVpCLr24ICvlFJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366516; bh=A2nNLyNKIKxBgXPVpp2A+BXgDTiCgFpoNH8Zj5SBkwY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=HjAfNRH3FgIGVyq43yE0ijrNNfTsp0436OmDH/zxz4JJ/Y5bQc2lS3KtpX+i9BU56VK 7HNiiiKKh+T1HfiXX4tDkK5iMU7DVCMTXPqA/BDIOHF8i6pOmVWOiECBucGYj/sukNcP2 7pKtqMVQ96adPVPCqjTnLKp3bq+yXHr8ISY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MSR_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support an MSR_PROT NAE event. Parse the instruction that generated the #VC exception to determine whether it is RDMSR or WRMSR, setting the required register register values in the GHCB and creating the proper SW_EXIT_INFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 1c9c272a250e..dbedd4e9f95d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -374,6 +374,67 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MSR event. + + Use the VMGEXIT instruction to handle either a RDMSR or WRMSR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MsrExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D 0; + + switch (*(InstructionData->OpCodes + 1)) { + case 0x30: // WRMSR + ExitInfo1 =3D 1; + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + // + // fall through + // + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if (ExitInfo1 =3D=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + } + + return 0; +} + /** Build the IOIO event information. =20 @@ -705,6 +766,10 @@ VmgExitHandleVc ( NaeExit =3D IoioExit; break; =20 + case SVM_EXIT_MSR: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63007): https://edk2.groups.io/g/devel/message/63007 Mute This Topic: https://groups.io/mt/75713095/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63008+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63008+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366525232479.5334476714685; Tue, 21 Jul 2020 14:22:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WTf4YY1788612xyArx1zf2tf; Tue, 21 Jul 2020 14:22:04 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.79]) by mx.groups.io with SMTP id smtpd.web12.5611.1595366524258566922 for ; Tue, 21 Jul 2020 14:22:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y8S3Lh8hxPVB6C2cBCCkkf5AC4vPmGEUgGcvIEyZxSH0aWjvH3cCtx0fWsgW/l3IV5wqAiEBrex7Lzg8KtbaopGKotUu4NYLvt85NX93HfV9Tg/+z3CmuaNICLaxTaQc/YQ42jhtswQiAQLkMy+EOf2h+2HOWA7EC/xsHXuZtuxcwJclVHaZF4XUALlpka+IZJRDbMB5YFfabwpeMHuqbzafpRowEXRffbf37G8PgIhD0T98q9hFjEaKqp+e3DqM2W9wcHF9e/++Z69ZMjVPxNw0biiWHmEWaY/F37H5qG566D6qM8nV8yJiD5bI7k35ywEvbmvUkZJEFLsA3lB/5w== 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=3fv0LySMv02Eoii4eBNtz7XCoDCF4qBd0ZrJwx44Uo0=; b=RDZWVY8+Ef7nSlmp6hayJ1xjoaUwCvq4zNuFUmgGJDhUYWBgaq7fprZ6c1HRpD/eQ2RCHrUoMahc8SbmCho6j+T7kh/QwR9PMwcPW1AoLKiDFelZ2XFB4NYB3fPNUCbv0Yfp97LAK4gjMUBPxTy6olNmBnSK1psMEk0TcAbLgvAJ+OPBys961gWSgb4gyHJiQb7XzuNSxEFdeYgr/8K4ar6SHIex754c88sMMXdAqj78r3t4PUV8y5SJ0UqclAN4O4eAty7+MOUpkVWp2eR/s6SPB0wVgMSF9zT/kqKH+hf16Bbccr7z4n4xeH15qvkwyfr86iq1eLZhubuJsEO7nw== 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 X-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:22:02 +0000 X-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:22:01 +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: [edk2-devel] [PATCH v11 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Tue, 21 Jul 2020 16:18:54 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0057.prod.exchangelabs.com (2603:10b6:800::25) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0057.prod.exchangelabs.com (2603:10b6:800::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:22:01 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 459d7b90-185a-4eab-1c62-08d82dbc1bc4 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-Message-Info: GfZdsJ4UPtDviCw7bYrZRS0gvpUJJD4qVXrcYK/oyjWF0LKHhIv9FYt+GVhl0OqT4xamwIt2agbgbrk4zYvMfJmjBXQ/TPcKxmzY3NKqYbM/TaWw3AaDM8IdjTPTRraV/ONGYamb3cHk9lj/l7Zy3rScWqpmIvn/jYTaMmFn0+fJR+Uc8jq0FREnkB7TpGJ0hFLMCY0h/O+iUQdB3H42UcTCTRf/5dDFHsvwvs1cck494culZJ7PIOK1oeh7+zZe805D/LQjSiCdAThrkRlnROqtbP/Xiz0AN22iXY/+X6IVEM6US/sxrLAssxypWZVG2O/U3lsBSVQ1VTSPSZaehSp1tA2/EygV4VABgUHg7DKvpdxG4H2csHZcKguKXR/X0OFRXhyeR/6dJWnMrCEaZqQIKQ5TYRoB+5WI0KEOQ8X0K2ZhrNt6EXequPXmLxw88hSRURIpblCXDrwaKOGCMw== X-MS-Exchange-AntiSpam-MessageData: 6vLAMnD5qCVFs/Agon/IjoNnlFiGl9L6UpW5wO9XjmNqEYMuaRHBrv1MIgdF81iPS9yC0T2gOGzgUapVXXbHBu5fPcssHoCHu/igv1wgkx25Oidwwe6JlveQzH5otHgdftIyNa+vRUrEKYlIpO4/qA+jhI3PwZDhtiykeoWdwuB5TEeuPcnPQwj21VfQJz/mn5N4Wqdp3Vk2TLNxUdQIDBmHufRIZb4WDbGFNp6h2NuECNSoprt5/ktF5sYyFaf4yPtTZY4zsP57MclRYXvXMDPNolqBxITi6to0kNVwsB+mJGeBZjZRHAepc3zIafjxZJexJmZyVOIbjrOWVz4yFECCEYZEOybX4Io7D7bpN6YjedXzjAQYpKJWzHKRyxW3sFZvl+9ewkQQKjP7IyD5ICpdxn1ZgFFhdfIY/GoKKX6wo2V88gVSpGvg+M3SHx6Qj1nyyGLTYdSyePKHqih+T4AXcc4e+jIZ80rxRLjR7fg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 459d7b90-185a-4eab-1c62-08d82dbc1bc4 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:22:01.7892 (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: CdRZWP24Sm2/DkGomuGsBOw1tdl8aYUyd7NqlKKLmWG5koeq2N85YEPJMlWcs63H6jl78wDihDQWSS/x9YEwPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: yAiSLacEwTvJhkdeGWn03tWUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366524; bh=hciwnK+rH8peVHthZFCe4veM5Dayp83wzNWGquZBX9c=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=M836/sIv8Y95/a+zmmbjFTck7EQFWSdv6HW5kWS78gZ7pBjuy+BEYLj8jbadIHKFzj1 oCro+Ff5Q1RCF40mRiAEuLz4GJbMOsbJC657nCcgaa/SrPD6C59rsQCsi/NO7ipl/DmFz OKMqp5b3OTFmx/FKix4JYMrbJZxnzJGiEn0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a NPF intercept for an NPT entry with a reserved bit set generates a #VC exception. This condition is assumed to be an MMIO access. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a NPF NAE event for MMIO. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXIT_INFO1, SW_EXITINFO2 and SW_SCRATCH values in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 486 ++++++++++++++++++ 1 file changed, 486 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index dbedd4e9f95d..0e502ac14819 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -183,6 +183,281 @@ GhcbSetRegValid ( Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit); } =20 +/** + Return a pointer to the contents of the specified register. + + Based upon the input register, return a pointer to the registers contents + in the x86 processor context. + + @param[in] Regs x64 processor context + @param[in] Register Register to obtain pointer for + + @return Pointer to the contents of the requested register + +**/ +STATIC +UINT64 * +GetRegisterPointer ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN UINT8 Register + ) +{ + UINT64 *Reg; + + switch (Register) { + case 0: + Reg =3D &Regs->Rax; + break; + case 1: + Reg =3D &Regs->Rcx; + break; + case 2: + Reg =3D &Regs->Rdx; + break; + case 3: + Reg =3D &Regs->Rbx; + break; + case 4: + Reg =3D &Regs->Rsp; + break; + case 5: + Reg =3D &Regs->Rbp; + break; + case 6: + Reg =3D &Regs->Rsi; + break; + case 7: + Reg =3D &Regs->Rdi; + break; + case 8: + Reg =3D &Regs->R8; + break; + case 9: + Reg =3D &Regs->R9; + break; + case 10: + Reg =3D &Regs->R10; + break; + case 11: + Reg =3D &Regs->R11; + break; + case 12: + Reg =3D &Regs->R12; + break; + case 13: + Reg =3D &Regs->R13; + break; + case 14: + Reg =3D &Regs->R14; + break; + case 15: + Reg =3D &Regs->R15; + break; + default: + Reg =3D NULL; + } + ASSERT (Reg !=3D NULL); + + return Reg; +} + +/** + Update the instruction parsing context for displacement bytes. + + @param[in, out] InstructionData Instruction parsing context + @param[in] Size The instruction displacement size + +**/ +STATIC +VOID +UpdateForDisplacement ( + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, + IN UINTN Size + ) +{ + InstructionData->DisplacementSize =3D Size; + InstructionData->Immediate +=3D Size; + InstructionData->End +=3D Size; +} + +/** + Determine if an instruction address if RIP relative. + + Examine the instruction parsing context to determine if the address offs= et + is relative to the instruction pointer. + + @param[in] InstructionData Instruction parsing context + + @retval TRUE Instruction addressing is RIP relative + @retval FALSE Instruction addressing is not RIP relative + +**/ +STATIC +BOOLEAN +IsRipRelative ( + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + + Ext =3D &InstructionData->Ext; + + return ((InstructionData->Mode =3D=3D LongMode64Bit) && + (Ext->ModRm.Mod =3D=3D 0) && + (Ext->ModRm.Rm =3D=3D 5) && + (InstructionData->SibPresent =3D=3D FALSE)); +} + +/** + Return the effective address of a memory operand. + + Examine the instruction parsing context to obtain the effective memory + address of a memory operand. + + @param[in] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @return The memory operand effective address + +**/ +STATIC +UINT64 +GetEffectiveMemoryAddress ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + UINT64 EffectiveAddress; + + Ext =3D &InstructionData->Ext; + EffectiveAddress =3D 0; + + if (IsRipRelative (InstructionData)) { + // + // RIP-relative displacement is a 32-bit signed value + // + INT32 RipRelative; + + RipRelative =3D *(INT32 *) InstructionData->Displacement; + + UpdateForDisplacement (InstructionData, 4); + + // + // Negative displacement is handled by standard UINT64 wrap-around. + // + return Regs->Rip + (UINT64) RipRelative; + } + + switch (Ext->ModRm.Mod) { + case 1: + UpdateForDisplacement (InstructionData, 1); + EffectiveAddress +=3D (UINT64) (*(INT8 *) (InstructionData->Displaceme= nt)); + break; + case 2: + switch (InstructionData->AddrSize) { + case Size16Bits: + UpdateForDisplacement (InstructionData, 2); + EffectiveAddress +=3D (UINT64) (*(INT16 *) (InstructionData->Displac= ement)); + break; + default: + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement)); + break; + } + break; + } + + if (InstructionData->SibPresent) { + INT64 Displacement; + + if (Ext->Sib.Index !=3D 4) { + CopyMem ( + &Displacement, + GetRegisterPointer (Regs, Ext->Sib.Index), + sizeof (Displacement) + ); + Displacement *=3D (INT64)(1 << Ext->Sib.Scale); + + // + // Negative displacement is handled by standard UINT64 wrap-around. + // + EffectiveAddress +=3D (UINT64) Displacement; + } + + if ((Ext->Sib.Base !=3D 5) || Ext->ModRm.Mod) { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->Sib.Base); + } else { + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement)); + } + } else { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } + + return EffectiveAddress; +} + +/** + Decode a ModRM byte. + + Examine the instruction parsing context to decode a ModRM byte and the S= IB + byte, if present. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + +**/ +STATIC +VOID +DecodeModRm ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + INSTRUCTION_REX_PREFIX *RexPrefix; + INSTRUCTION_MODRM *ModRm; + INSTRUCTION_SIB *Sib; + + RexPrefix =3D &InstructionData->RexPrefix; + Ext =3D &InstructionData->Ext; + ModRm =3D &InstructionData->ModRm; + Sib =3D &InstructionData->Sib; + + InstructionData->ModRmPresent =3D TRUE; + ModRm->Uint8 =3D *(InstructionData->End); + + InstructionData->Displacement++; + InstructionData->Immediate++; + InstructionData->End++; + + Ext->ModRm.Mod =3D ModRm->Bits.Mod; + Ext->ModRm.Reg =3D (RexPrefix->Bits.BitR << 3) | ModRm->Bits.Reg; + Ext->ModRm.Rm =3D (RexPrefix->Bits.BitB << 3) | ModRm->Bits.Rm; + + Ext->RegData =3D *GetRegisterPointer (Regs, Ext->ModRm.Reg); + + if (Ext->ModRm.Mod =3D=3D 3) { + Ext->RmData =3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } else { + if (ModRm->Bits.Rm =3D=3D 4) { + InstructionData->SibPresent =3D TRUE; + Sib->Uint8 =3D *(InstructionData->End); + + InstructionData->Displacement++; + InstructionData->Immediate++; + InstructionData->End++; + + Ext->Sib.Scale =3D Sib->Bits.Scale; + Ext->Sib.Index =3D (RexPrefix->Bits.BitX << 3) | Sib->Bits.Index; + Ext->Sib.Base =3D (RexPrefix->Bits.BitB << 3) | Sib->Bits.Base; + } + + Ext->RmData =3D GetEffectiveMemoryAddress (Regs, InstructionData); + } +} + /** Decode instruction prefixes. =20 @@ -374,6 +649,213 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MMIO event. + + Use the VMGEXIT instruction to handle either an MMIO read or an MMIO wri= te. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MmioExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, ExitInfo2, Status; + UINTN Bytes; + UINT64 *Register; + UINT8 OpCode, SignByte; + + Bytes =3D 0; + + OpCode =3D *(InstructionData->OpCodes); + if (OpCode =3D=3D TWO_BYTE_OPCODE_ESCAPE) { + OpCode =3D *(InstructionData->OpCodes + 1); + } + + switch (OpCode) { + // + // MMIO write (MOV reg/memX, regX) + // + case 0x88: + Bytes =3D 1; + // + // fall through + // + case 0x89: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 : + 0); + + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) { + // + // NPF on two register operands??? + // + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + CopyMem (Ghcb->SharedBuffer, &InstructionData->Ext.RegData, Bytes); + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + break; + + // + // MMIO write (MOV reg/memX, immX) + // + case 0xC6: + Bytes =3D 1; + // + // fall through + // + case 0xC7: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + 0); + + InstructionData->ImmediateSize =3D Bytes; + InstructionData->End +=3D Bytes; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + CopyMem (Ghcb->SharedBuffer, InstructionData->Immediate, Bytes); + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + break; + + // + // MMIO read (MOV regX, reg/memX) + // + case 0x8A: + Bytes =3D 1; + // + // fall through + // + case 0x8B: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 : + 0); + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) { + // + // NPF on two register operands??? + // + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + if (Bytes =3D=3D 4) { + // + // Zero-extend for 32-bit operation + // + *Register =3D 0; + } + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + // + // MMIO read w/ zero-extension ((MOVZX regX, reg/memX) + // + case 0xB6: + Bytes =3D 1; + // + // fall through + // + case 0xB7: + Bytes =3D (Bytes !=3D 0) ? Bytes : 2; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + SetMem (Register, InstructionData->DataSize, 0); + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + // + // MMIO read w/ sign-extension (MOVSX regX, reg/memX) + // + case 0xBE: + Bytes =3D 1; + // + // fall through + // + case 0xBF: + Bytes =3D (Bytes !=3D 0) ? Bytes : 2; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + if (Bytes =3D=3D 1) { + UINT8 *Data =3D (UINT8 *) Ghcb->SharedBuffer; + + SignByte =3D ((*Data & BIT7) !=3D 0) ? 0xFF : 0x00; + } else { + UINT16 *Data =3D (UINT16 *) Ghcb->SharedBuffer; + + SignByte =3D ((*Data & BIT15) !=3D 0) ? 0xFF : 0x00; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + SetMem (Register, InstructionData->DataSize, SignByte); + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + default: + Status =3D GP_EXCEPTION; + ASSERT (FALSE); + } + + return Status; +} + /** Handle an MSR event. =20 @@ -770,6 +1252,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_NPF: + NaeExit =3D MmioExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63008): https://edk2.groups.io/g/devel/message/63008 Mute This Topic: https://groups.io/mt/75713099/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63009+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63009+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366533316300.0281820306535; Tue, 21 Jul 2020 14:22:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FLoEYY1788612xeBWMFDqRWh; Tue, 21 Jul 2020 14:22:13 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.75]) by mx.groups.io with SMTP id smtpd.web11.5523.1595366532480900793 for ; Tue, 21 Jul 2020 14:22:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZuOLQGe5nVUP9IRAkq+cfaabuLeFCNfnhOiIB9hnFYg1Gq4E9rBJ/NUZrgnN35GZrJZ+3ooBFWHN0r2lT7cXE8zaZ32BRW8CJ2J9tCcg3D5+m+M+VEi47beo4cjTqdZaZ2EwLQWLkOWVCDTloP+6oJIThaMYjq0gfWmxb75BZYN2PWuSFwWl9t6jbs9NkSwJ8N9xcpba33CbHWG3vAdE+Qe4hN71RGsnHKfZrbkOrCizL+ALYy9o/8kYIOk11mdfJB6U83oZNJSq+xoc4T+xJfwydkjR3UDkQonGSN4SEuuUwqs5hqhbnTedMzRD8tK8x7mkOT11LPALG833glAqFg== 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=crbmyZ65afRC34Vt1/yjGXXSEbQgatvY+leMn0es1AI=; b=XYin4P81GIO7cJ7+hpLoaSOukmDnnkqU26/XXz/37PHnpO/emY1v9Ip9/x0iB3qI5MEcmVmE2uRI2RnPsF7s/a68hkVyVH6Sh6lVLI2UKKAe2Bb3LFfDW3e1xupz59oqW4f7n+jofQWherSnxH67k4PQXTEGhK4zyrG8AsZgbbPL5XwvVYW8Dt6TQ89o3KDpCYGAgMRUijKHdaZvXLn23p2WQwBZXeyN5/nZI8LVXPxRA2uGyAlYB32r3LlvQVMZ66nsrSi7P8NYqxsSIgGurV4ALYv+FHkuIY0FGvJz14VdrNp7CZIGWQ0+01YbDMC2dMngWTJZVvsJ4naVAK49oQ== 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 X-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:22:10 +0000 X-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:22:10 +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: [edk2-devel] [PATCH v11 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events Date: Tue, 21 Jul 2020 16:18:55 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0054.namprd02.prod.outlook.com (2603:10b6:803:20::16) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0054.namprd02.prod.outlook.com (2603:10b6:803:20::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:22:09 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d322c3ab-a7f2-439d-59a2-08d82dbc20b9 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: YmVDAs+5Il/P4yxMJB85iPTGUOoU8AVoXSvjDEudxXQgeoZRs1uUZjaD2pZqVveOygDSVVeRjtC/L+rsBfUrACq1qF/+UMmQQzxt15t81xSzN3YL5VEdEFiW0jGMNsOWk7mUIwfkTdPRWUYhTrSuySuKJW5hcMqhumtT9CESPdbYygQpTYYA0uEwIRdD7ZN47tlFSOiWpdij7jz0/WiG1MC5yEoGQkrCX1BZ+kH2NDyQGS/V1Ro9hgIUhYGIt3wq+PtH5usH4AO/heeXZ0Djw7Q15q93IyvW1P2cvHf1fLdjfOafmVw6QPpYBpc+l6/3AR15OFgdHx337oqb4QeknTMKUJtMUZxXB4FpAeqf+dWV2naSxIOCCO5Wvv/J8p+XW0nfDXUPAStNB1QZfMXHwMPKnoxJxKke8HK9M5nwEpYO4wBADzsGPVndWl7UIZc2Uj3B0WtGeILqMKSwNuIsKg== X-MS-Exchange-AntiSpam-MessageData: 9RxA9XdwjcRaiNvQ5MNy7jz1IVfLjVG7V5WO0ESfEaLlbdvKsEgGdLpmRHSPbgROATts4w7VFCSnrhtg4Hggd6K0jBITW/LJcjjslOdA47e4UMBr8ZNJ/EGPYqEgJjz3aNaRKrD62xIjeZZ24pRb6xWmkoT/X9ZAhrF0RPCVHCGY70nQ7hudKxmwAyL2CSfJY9HYQ9VeA89b8t8RnL6m23lUslzQqQhulEeZjubkwOiiMGch2sat3ZnOH7J8blnZG8YO9NsVpr7makZL0VRdZp5XXDM4wg+98YSK5QNXHXMdoCUbuTLU8iiRaPugwI53pRCQegSNKzbkpOo4G49tZkdUSqC6qtwg7jKS65rhaEF0Wz7+myIElaxkAGhhmB0PKDR2vZzzgd3yT26ag+DbieMPUL9Lg8oLXnI2WkSjqmowysswIZ+b2NxaNkWg067GHbEqpBQgkqofTU2qeRCbkFFlPr6uYFaihG1QRcGwqJc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d322c3ab-a7f2-439d-59a2-08d82dbc20b9 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:22:10.1113 (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: 09ee8Cut7VjkDpmHBtU9wAopaGUbtsg94NTqt8dDPQj+aivka9DbX6/fpSJBnYx02+Lta2t2YlJHx+0ivEo/Yg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: WtaE2gEl9W99FavQjnfS4st4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366533; bh=ZcTSUkk49d9zkp394hUpCcLxTRZlAxkhGMU+ksTbmeI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=micZoJ/WSwaOm+c9C2+S0c74mzAgS18NwctOCaBUtmkgMOm6Q3nJwrgKsMIQpqBhsOW FyWk06ym4BllmfBYCGn7GO5xMbZdUMXzo93FBQEbMXHZB7uA2a/v1sJEVJhAxYlUZQBKy n/tLtprn00wd0CK33LN4Ru+X2QPCobvD9yw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a WBINVD intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 0e502ac14819..bf07f960e380 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,31 @@ MmioExit ( return Status; } =20 +/** + Handle a WBINVD event. + + Use the VMGEXIT instruction to handle a WBINVD event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +WbinvdExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); +} + /** Handle an MSR event. =20 @@ -1252,6 +1277,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_WBINVD: + NaeExit =3D WbinvdExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63009): https://edk2.groups.io/g/devel/message/63009 Mute This Topic: https://groups.io/mt/75713104/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63010+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63010+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366541281288.6144059317203; Tue, 21 Jul 2020 14:22:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id j7POYY1788612xy1i8d4Siq2; Tue, 21 Jul 2020 14:22:20 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.74]) by mx.groups.io with SMTP id smtpd.web10.5659.1595366540319566580 for ; Tue, 21 Jul 2020 14:22:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GDJftEE2LuWtFrLScXiG+nFoYRgGb9rtb797iEoxfDRd8/lc6uuieLXBscHOOsuv9MZCGwcsf6IApkeopkzezaEumWUxHV8Kb9GFB8doXqOeqsYqRxsLYcahNzxLXhpk0p+K4HjQbCF0DA8w4RgLjq20eUTGbpEIfWm592OjlU5XOGD0NbYF9BlwVu/ZpWqEjAmh0vX8Ko51YxKRbtWfKdf5Xoafl8icgrEDcFu3kAK5VcFk7oZLGQy3MLDZ4BzYvvjMt9DXut/JENqeJRfP+wBfdLM32k2HamVo44LNCVtGGLJLwjvgjV5tmBKnZuCYcL7Zwzbat6z1lRLfTx9WrQ== 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=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=Dv+AfJWJMlSrm88v3uYLmJM7Cl+eIWPpnBITRQzfgkz5enO3lGq16NGdZEqNBJoqOxcFC+VT179NNzgVtl+0nn2Zb7Pa4Hxvfn4ikDnWQ5o0PRMqBBAhMCVyRzEnSq+b8TWo9DvkETc15JzFwDHI/aB3RjHy//k8QUENgYXjXK/KHuqTBnD6I31P6HKUikQ4nM9/38oIiEqIlljyJSw3JWBrMUbAuNYVJIbEh0VOYZ35ZNkAIGg85Dnq9EbsrsMVH+t5Iop+oOI+9MShmaCRiMDWZBk47H8PCAbPyL1ypED49hIV5lHxLmvSEVDBCvQF+pT0W0WntQDXcw62yjNTeA== 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 X-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:22:18 +0000 X-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:22:18 +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: [edk2-devel] [PATCH v11 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Tue, 21 Jul 2020 16:18:56 -0500 Message-ID: <8e3e7c72918a8523c26ee7ea910715a0b9ab90c4.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0030.namprd05.prod.outlook.com (2603:10b6:805:de::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.16 via Frontend Transport; Tue, 21 Jul 2020 21:22:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: dd5bec2b-9dd5-43db-3c9d-08d82dbc2599 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: zDbczTMWialuIRCvIp7qKlz+soQIEdVmvTszPfNHAC6rkrcX+VPyDkeHpQ51XLQHsg8dYRb4XIbi/xuNhIwtA9aZ0zSOwAJRvoQ8buol/5gfx/+OUrlixB7RZhLxL1QFsesr7HG+4g1q9UBdA6mqxzwYc/W0GxjLSxj96ZCYw8YJ4CumKUhPihBCbur9u+YMHTECbAYKrMxj15+eJZbOCewzxgK8LkVaFiLB3veObynBctO9y86zc5SNjB/NZ9xxIIrZ+GDOqPrZOK4gL+7K62v4lfIGAOdvDT8sMYy8BC+30M/TaVF+DRhJwRIzrE8trrPVnepeFz7EdqRB+oadGCfAzbuEvZDV3W4Fd1dPwIMw+BBVlplg2Na6/gRHch3j1/8JLOUBItZlY1mTUOuVQS3N0IBiM1iURzI9E0waqN/TroEy9xMFetnj39dE0UVY3r+OTRVSLD4Jo2f0Ws1OVg== X-MS-Exchange-AntiSpam-MessageData: UELlJBvRDxSQERBfKplKmv+PP9LK2RrcmkxPZzzlNNmikVSYlj+DA1Wky+VbhtCNrzNKD0QtiPbi8Kd+iNRk3gYAfXUlBPqvJpSOecCcKBwQTMMxymfF/pzm/lr2pN0e1Z2rnXqmKv+15+66zHwnnSEez87a/Va7WNCqAji/QQObpHxwmIOtjnvic7/nuKWJmK26gGKiaKjt1pXUyb9u2189EtonK4HpPLtf8Nyoal/iGHPsCsYJit4FCRehvkckr0X47bH148DmgdviXevUvIgXLj/hFc0A+SgZwxTw5/9SHtKj3V9sCUZulBvPGR9UmrU9gENSD4czplK6aSSSiQjflkngUXEn2ax7ntX6A9bO9rE+ueAZtYSGaO66pp0uVyE3BzEpX8Ii/tdvswVrMD1LcbMhuR5f3MBql/cfrRuwh1K3ke6d3UPW6rZgm610NA+sp6UTs8Z9ZoWi/cBqkM89YatAJg1kN47/VzVV19E= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd5bec2b-9dd5-43db-3c9d-08d82dbc2599 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:22:18.2575 (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: 3vP/Rbh4SVIq6c7crYxsyJFCKB33mPcpi21qzsS0atSn2POevGNj+L6IGpdBpifv0Gusg1W3qYp1SDZGRX7/Qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: i5knTyLyr0wmHU7yKwUCRSHZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366540; bh=YdpsTxaEncH/YsKYLXkZTjCcN8x4QZzw2qmsO4BV5+Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=W3UVE1KH/XR9YqhbCSBJMT5hzlR37I7xWuHh8gqNheMa6GJ3+U7lrnEgu9woY7DfidQ 9QRe5QkG/On/IyO1SQJ9/guAx8ztXIcnZPO+j1zhKJGYhfdbKx6mySa/GtyiMbTtbyuMz zRDAE5XYq2ahA3zN26WoicL0JO7MxKIusBs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index bf07f960e380..65af57046063 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,45 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDTSC event. + + Use the VMGEXIT instruction to handle a RDTSC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdtscExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1265,6 +1304,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_RDTSC: + NaeExit =3D RdtscExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63010): https://edk2.groups.io/g/devel/message/63010 Mute This Topic: https://groups.io/mt/75713106/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63011+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63011+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366549957562.2392690505321; Tue, 21 Jul 2020 14:22:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gO3aYY1788612xDczMZD8znf; Tue, 21 Jul 2020 14:22:29 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.64]) by mx.groups.io with SMTP id smtpd.web12.5620.1595366549074569970 for ; Tue, 21 Jul 2020 14:22:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V27nMOVMbkGOjGTqZaTTpu0HkmwWRBUsY1Ziy3UI7BpKs0IVZcq4K+3kLKlZUB0LrULzvIaj1j3I0oFyu2k7lSE3fYP4FCdhOTlqf8rbrjZVS536ZXyqELj8lI8qYSLN6T59PBmXfjnuENGWhUTY//Gd6ELAsjKk90dcvStBxdUXQ9rnK/4QEwyyDOqA7GgoHxkkKWe5IMlENm2lhkUTTus73omsa8A2trdMPxzCjhuECPvoDG2HF0phIU9ndyBeD7lCf3IPs6dutsGnUuW0f7dRCo0l85uSA5mXjxFqLl0XOpc2bsEQjifj2w6h91S++nhXpDe2SUXOmYPRe4XHHA== 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=4O6+S0hN1CMnpBWLQIazWEUnN+r5+tUBAtS8g+NsqAw=; b=GHH4ApU2U11x/7TjVijLtoS+TY12u6H6L/qRK68XIDgPdyHIAYAsHra/STvqtWLUxa2ub2cYnx1AodC92zEDoYZWtgiSPAWTHInLnGMgWSgML0wfdEdMmN3OcJu1cNioOUY6sxD3CT+9eme7num1u/GllUuV+H0g2utjGN2ruMlkMpRmbojBMrGYZUkkVh8qPqpzPOZcT6xiDkdqorjADOwTva394cg9swhCBD8vO+IFZOkoP4RjECh/Z4OBtWUCFuA3hXnuaL4F0Alo6q7ggT6NUnuWsMqrFefT8boDg8Wm/j9o6CbCZDUzN2CEAPjbqpqzzFQ4094bs6uwpHM7JQ== 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 X-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:22:26 +0000 X-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:22:26 +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: [edk2-devel] [PATCH v11 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Tue, 21 Jul 2020 16:18:57 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR03CA0064.namprd03.prod.outlook.com (2603:10b6:5:100::41) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR03CA0064.namprd03.prod.outlook.com (2603:10b6:5:100::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:22:25 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7ada56eb-24e2-47e6-8a2c-08d82dbc2aa1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 5bN0SUC7+BShU0bDiRRnpK8Cx9DzGOdZsUpBiwTV0ZqLJp8mTCffJaEN7RO2qE7MRJd3SDNlVbY1899Z/TUuRjGk98ESP+DC73bcYzcLhJKS5QtOQWbYTv+JUpj96dkUIFE5bV769YdEJISOAvgWX18wFm81seEPIcEIubBgLLFCCOKF7SCfszln6DHjnnRhGTtKscG6Uoh7X7HPERavAkGqGnqAVSozOgKcp4CYtwbsezJA7PHA6vyWC0aM36Lvg/qbUqUpwYfAXDTs8w8hobRtnFvY7NRpt3yM+acBm9/akGXYoZKkXlCu/zhBxErXD5ZxpuP3fZ70/HggkYLoDqvHBlDGFHZNAd8QaVhAOR28xKuq/ZR0in07y40X7HFP9xxt5V1tJnxvESc7ZTIvDGHP9OflWiE6sPbmrX5VhElbvnijppX/mKw9SCEA+K2n0jshGyghzu/0snhGJcrsiw== X-MS-Exchange-AntiSpam-MessageData: BgQDXRTQGEAaFRv2w0M5jCb65W7qB+bzGR8NFDqG/Ci/5hR9pFP/8N4h3Du7jdRlxE3loBBaXUcVjVLi1dCyZyGmlAves8hvOqEOn0u8uSEPFwZmARfuBDiuWq7ShvYhwRG45uO1eo9MJIIYXceocNsGaM15STU/G2fjR3vO8xmDmO8TFAo6YEBUzyu8OGNyBFoNV92rscNcgDhBlTXbFiWSUscqqRiu7bIFxTZhJWPfBmUhcfoKqUp+AaOrZYfBfTdeeOyDtE8PDA9kb8BBo9VwXNbQAJ3mK9xNoEzX5AQM1ZqDQPjTx+mEza0Vi4iULeEUCJGa6KqOM3UpKvQ0WL23nUtLubaDHqfL6TqrEYmoj51EYjpoptyOcBT5WsPUWc1Wx0eXESPNVO0UL+JANo4FjAIfiNmTUGIEnFLHqamN+7Gk1v0iUeCebDHSZUGGmF98LU+LsFnASHGottHC1WHZmg7KTGEMv/dQUhWfYaQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ada56eb-24e2-47e6-8a2c-08d82dbc2aa1 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:22:26.7485 (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: p1kMMWrEP7EBckTPYUc09rGF3C1Ef8inH6bkH/+LE0QvQ9SyRdu4xKH0Rdr6Gi0KRKrC4sHlPkTU3NQqjFYCLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: Y2f1u8piNxrEVHMBY395dqFsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366549; bh=d/mtOxYFMZNS7i13STB+Gxc6G2APgjOG237izMgJUzo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SxpK8g17HT/YjVXquiNqQTEnMP1d6nxEgNwYdSFoRtQtg5+cm3NnqE7n0iJUi71Q9eQ xak9h5dWnF8t7C/HkN8re6Za5FcJvhZndu7mrwXSZVagv3zyrbSLk0hczmGrgQaoohki7 woxPjL2QZQ7KTxGTlJcynQBej8ABdeSF7k0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDPMC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 65af57046063..b19bd3ee8906 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,48 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDPMC event. + + Use the VMGEXIT instruction to handle a RDPMC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdpmcExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a RDTSC event. =20 @@ -1308,6 +1350,10 @@ VmgExitHandleVc ( NaeExit =3D RdtscExit; break; =20 + case SVM_EXIT_RDPMC: + NaeExit =3D RdpmcExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63011): https://edk2.groups.io/g/devel/message/63011 Mute This Topic: https://groups.io/mt/75713109/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63012+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63012+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366557804123.63007947499796; Tue, 21 Jul 2020 14:22:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OW8gYY1788612x9AkH0d31I7; Tue, 21 Jul 2020 14:22:37 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.66]) by mx.groups.io with SMTP id smtpd.web12.5622.1595366556989802833 for ; Tue, 21 Jul 2020 14:22:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iaVb+BR/mvdYYBt06fQoyVm5WMqhSp4OeKw1TjFRHFro8G9BLwIUdTIbv/fU+iEJHiY0HxvTKTa8aBbWD1Co27O8sTL/LWdvxhgZe5pEKCR8uoII5Wt1GqlHvvHiXk8PB85xk7mnAl5vepdsEDaq9hE5lYg+bGpXxIIMfqX+l6lnqDoYq69ZQCaImq0Aj/1TJJ7coLubcwAuMncPRhNTANInr1BxGy1pK/dlMCarm44BKDnrsaLvVDqwFiYQANKSXCCnq2IZlxkdZZKOPiFGmksoNGS+F9m1+u3HE0Awr7a3xUcCIydxNimaO2PHGvMmCDsEH04Y38ipfSICxOhAnQ== 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=VWf8IlBLc5H2/zm6u8ihdDB1OPHPbvu83zMDyNap3VM=; b=gM5hGms2Z8/bycPNfon5q6Q35qpXEowxwd5XhZ9Nq8qS01RTf5pFjWSsZqupsBjIZQaGSscP/N5tXKMksLf+Af8QGYtpBl0VZvM9eu2IAM5VMWq1/DZ2SDgTKUkBhOgryj+O5bcKBneh0mu3LaJSGyOV2hiOgiVA2xpkr0cseo9DlRpX++XrE19lwjsRqUrf56fzBQrpcuk8BwXCbm+OkkEMNuL7mw4PC51MSCROtnzZr1b7a1g8uZCgZXlrYlZlxsnBKygiMoqBf1XDJ3zvwCxqenmlqLp7c97DlZ6FFpMbNuDbIbRO1oUivs+36piuDfUgvO2G38f7n5kqSZO32Q== 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 X-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:22:35 +0000 X-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:22:35 +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: [edk2-devel] [PATCH v11 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events Date: Tue, 21 Jul 2020 16:18:58 -0500 Message-ID: <0c86b1e20e5850225a70e6ab265118accb7ccb58.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR07CA0041.namprd07.prod.outlook.com (2603:10b6:5:74::18) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR07CA0041.namprd07.prod.outlook.com (2603:10b6:5:74::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:22:34 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e963a416-7f60-487b-03d7-08d82dbc2f96 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 0t/tj27hq2ii4Xwwz8h1WgKg8VcBAZwj1AuT6ZUDxyLsmBw2KDjtINrm0DpZdzhB5wjQxDT4qQ7NZzza3ocDJVCizI1kc82DodVtijuZKC6h7ljpF9RiTBkBcwxug6xSBLPnEcODzh+tZCMrYRwinOGaxJtT2XxZFNF2kob6TziDWuZuTZ7BIHUCgTUy7yRYFbWB0z6Me7cMlw/3a3U/N3OjyPI5IaBB7GVTn5J95XMuBK77NzF78yS9myGbv9JtSAvaM8TuFSlDqFHCOpF7lAUqtFEH0iqgVjOfYOpijhqdORXU8/jyMG++b/10lZLWVeR3w4psr1VIefUwDokdrAXbCmpC6XgO1hWz1Hnj3wCXOSCBReBcra/pN2cojwENReV2zZOI8yzGNgSIV7OfFr376IK10kLZg/RO7HiekZf2nBiBV0teqItq1EjSFeTFsm1T4kOy9mM8wwIAzgOvmQ== X-MS-Exchange-AntiSpam-MessageData: /dIGMoa8Q8z0rUT3PLU+gfR2i4S1gsbtd8vybn9IEfiLYt5btd4949MMwG8ekB06AyCGVOCyas1gpU44Rr0LDv1Mp5QhFgKMYW2VPDumWL+VapeBId50vQHUKJuQCEKIxDjQYlXrQl/kX4YypbSQaSSG7OoBQd2u4gH7YxfiVApn5QU37N6NSRvl6hbkM3yE0pjaDBQVD3LLb1TUoTK9Z8Wjzut41fSqcvG/tJy20CcTXmB8wJreJuMAd5eg+zBa/W9hh+aKWsxH5NUK5ES9uBc4zIuTkYOAx8hMGaq6RrajS5yvHpg+Qyd3rUaFdbVQyRusb3gnia7lZMn3euchbDDHqxUs+2WEJQSyu2vH1lMXvb+D7PHiKzh4tztW0KH7JyKXwLgoGizRWoXEQx5F763MZ6gdI3HhNe2Mb5CKpuI6bMiuogdit2rGl0f1M8oM7/+bhpNkSyFCJUlTxKTwA4OOVmuVFavI2Jag0szVJ0c= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e963a416-7f60-487b-03d7-08d82dbc2f96 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:22:35.0266 (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: Bq5La0/oSSFWkCojlkJRKwZWW0PklaCQ2xEto2XbmItKS9lMspMxWNIeZEhwj6M8RT9/+XECc7Ol2JLtjw+bHg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: mdLQ7IlW8OZ8REuAh4cRbPCox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366557; bh=woiawswKrHGbUUVri/DpSFU0koxpHc4+Ds+xtRVwmaU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PYIO6bPXEpDG7SBg1YbLWz7KpCDOhXLQyojaMwbcg6o4I5osilZWhM6x42pbkTRHjIJ Y6RteSg66MXWQ1BocVIYprXuVsol7Gka1HiGdeoADs6EYT/8tO+48+Xz+MiAJMpsL3pHA mqvgyw566/kwW5Ej8bSOGu7b3cB+oO7rIC8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a INVD intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b19bd3ee8906..af5264095b98 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1166,6 +1166,31 @@ IoioExit ( return 0; } =20 +/** + Handle a INVD event. + + Use the VMGEXIT instruction to handle a INVD event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +InvdExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0); +} + /** Handle a CPUID event. =20 @@ -1358,6 +1383,10 @@ VmgExitHandleVc ( NaeExit =3D CpuidExit; break; =20 + case SVM_EXIT_INVD: + NaeExit =3D InvdExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63012): https://edk2.groups.io/g/devel/message/63012 Mute This Topic: https://groups.io/mt/75713111/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63013+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63013+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15953665659431018.4420996354262; Tue, 21 Jul 2020 14:22:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mj9FYY1788612x44DDz5nn6Q; Tue, 21 Jul 2020 14:22:45 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.44]) by mx.groups.io with SMTP id smtpd.web11.5530.1595366565091683515 for ; Tue, 21 Jul 2020 14:22:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T1ASFl/f5KOIVgbxPGgg46s/HpZh0PWnDF++vbtt1WW8DeGNBkyPM+jhUZnGV9zigz0nZa+BGMa4GR7ZLur5icS/X1oiYamIhhOqaNOV+NOFtS5CWXLbHq9YbMBQLZ08YlE5mxGx+fYyPBhgjM9B3hOkLEH+qdWhF9Utz9jaADGNeOsSERp8LwFoXik2XEIrxwVjtuTI/WHAMkCKOydXkcusKsy2h2s2eLoTsSFsnMKnS7xRqgBrbOdFeyFFoXSjIoYA+b+D6g78wXjELdrF9XydfO/TPWVMZsEz8aqOwYSRYgOhKCCtc2sGW8gp8lzpiP4MD1PIq9jXldfUbZjVjA== 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=8NTCnoZUa8l7fJRJjHTmN6rj4HEhSC81uhz1zBZyzhs=; b=ZjVVuiwHeP+968zAj0IwHX0+QqqlX6bbPf7fHZnCoW9SpHOHlPM9T8E+gwMdymmRiZw1v/zCKfX+Z+ilweelX6I4c0wkixEz4dbiY3yEheeqJF0MRSCCTisaI6mwU6gBBCS74Fu4Q8bP4v/mdxZNyovbYoKpu02Wev7LUm6jxG87a7zwRpz8/0vl7omoc8KMxevJzI3HRrtT3KO0VCvBgxqIZ1wPpWWgwyHBOP6lnIoRCBBqs0Aac23DeFCPx77kaDtXgowbrfQY2lZiFeVpAkZc+LJi2n0paekdt/acJxV322R0tpgzPG8O743UC2kvYnoF1xd10OeZwdPlv4HXnA== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:22:43 +0000 X-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:22:43 +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: [edk2-devel] [PATCH v11 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events Date: Tue, 21 Jul 2020 16:18:59 -0500 Message-ID: <37907ae12cd09fcf942d6af57e74c4d623dbf28d.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR15CA0071.namprd15.prod.outlook.com (2603:10b6:3:ae::33) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR15CA0071.namprd15.prod.outlook.com (2603:10b6:3:ae::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.19 via Frontend Transport; Tue, 21 Jul 2020 21:22:42 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0f64feef-9e14-4efa-c84e-08d82dbc3471 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: XAyP52WhJ0SDgudHA2+03sbcLZMqfNXgcCWKE+2P00VAbHPKuirwEa3sgXLLTG1M3PiKZLoSVhh5SycMGYxrENxyfoDdWno8sbOZI3tCnC231/GHVEoz4EL5/B86q4m3tU+JXi/HuN+1c/cK53b4DkO6CObWcSc5qYrbUGf/wVNvgewGa15zZ+JzzuTk7L3qmZOQ+Xqjh8pET04ahMMI8vL4PJiWU1uQgDp1qLye+DQ/W2OBqlyO/XkIO0clsma/VGBrsaF0DH25dVnz0vB4v16+PlV6zPz1Rz9a/gy4MePZ8tQk07e4finhriEqInb9saHzoImUgSRCrU0mfU9SRwYlcLt4R/GpqNYDbLpAmXSxCP8wwlRJPSaiwDpkCl8z6TQI+yHn1rnFQCQL6SqERxF1V03no2iY74vuj0AK82XHuZkmJlQCrPBxzsHnGttrg5Uapeo2ZJAqtpiUNfykeQ== X-MS-Exchange-AntiSpam-MessageData: 1DBm/EH4vJKOg/pOg3Yx/NpBi/r6T+xycOY/MtrH8PupIWhYwq08DGILl1JHiOsAKYb0Xx8TNMFYKWFvGT81HF5Ys0KAgMOVJDNxqUU3bySM+o6sKkEICxY9jlCPN+NiVMy2wLGtxvoPJrKT2uGYGlY3YrMeGtib4nBpSSaQvLnC7byhvjZ/5+oDTUmzs3vonkAT9ttl5kv6IhGEAjzfalWc+wDsmNbs0hHS/wqTPNHi2wzlopln9rcFK4gf7Cg6hXRcEaImiwN5eP7BCKTX79NyQUfQYdO5eGAgSnx4r9CNgfCo2ANnYuHDw8EmpppJUFAs4FejXOY6CxWCZ/ZoHiFc1j8WtPo+NbGkpfCCfgzAtOAEHV2C8evEyvyybF7NnpWa9v8jvg/2m19JsQU6pei9cMrIRdJOh2LUNFlMPeh1kFwdjOyEcOu5C/bM0YMRI4zGNB1nEiDEx1++cUQCUx3pfBnc4rUK2gam9EiwFDo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f64feef-9e14-4efa-c84e-08d82dbc3471 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:22:43.2167 (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: sOqi9Kij5B4HMVtmyScZ4NvQIx3zX3xhBJrRK6bfVZCxS/jSnX9Whw/ggVgUrnZpuqWCBsz36knn37BEvBALwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 77QaTkQbCGhP8r8GwoAA2iuWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366565; bh=G6ucMF8+2R+kguFbFbnsI6jKDmM1k0ZlgGMndQBvVKc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=co8XQDAKZRoqTVIzeRCVfR7bocTAwlLpU/9qBnwQ5CbEHb4CoGFyGYXCi8y2xcICUd3 09rj8TCfinXuz6WcBAzLtvFKum3+iwtGqVRF6Mfpg+njeD6K+6yL5HrG4naYII5AICI+1 mXEeA80KKYAW/pYLpWpx8/D6HxmfH9OUn0E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a VMMCALL intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index af5264095b98..54134f37e614 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,50 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a VMMCALL event. + + Use the VMGEXIT instruction to handle a VMMCALL event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +VmmCallExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Cpl =3D (UINT8) (Regs->Cs & 0x3); + GhcbSetRegValid (Ghcb, GhcbCpl); + + Status =3D VmgExit (Ghcb, SVM_EXIT_VMMCALL, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + + return 0; +} + /** Handle an MSR event. =20 @@ -1395,6 +1439,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_VMMCALL: + NaeExit =3D VmmCallExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63013): https://edk2.groups.io/g/devel/message/63013 Mute This Topic: https://groups.io/mt/75713113/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63014+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63014+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366573704644.8705557563233; Tue, 21 Jul 2020 14:22:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wxjJYY1788612xJzHsv5yQNj; Tue, 21 Jul 2020 14:22:53 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.55]) by mx.groups.io with SMTP id smtpd.web10.5670.1595366572501981546 for ; Tue, 21 Jul 2020 14:22:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R+bSEI9l1faw9yNCQE8JUormH1kwUDc8vdjd8CVVydLj9tr17h7S83ZEHmSzw6TXIKRzGyXnmYx2gS3MttCtDI4EUg+/ddcRlez9rumqgp9UYi8ur2D1MzX4AL9WG/MpbKZcQV79S6WPZDVPXBvg0RGD/4bNB6/eQvdRKpuYYhUdcIyEn3Df6wuUj8pZtmVUxDyYsR7lFdxferx547WXm0ta3FN+SgwdFzAwRYfjIWAZrE9xizbjtd+Gzr5rVnyc8oLjcVY699tixqkMDy8j7MSXipIZ7NEH0XL1KcxZYtmSMBf0+nGTzmRWCcgdHlfv5OU1bZqFvAsAtQaTgIQdWg== 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=5teiAq1eAXmkeZ9hYTs+aZivrTRKKj5B0JXYx2XU70w=; b=h5kNY6H8wlFeg5atlVD24AjFjI8XgCkQbK7aMJzuh4BWoEijB/LdAP2fpHTQTJOYqbNhPQhQtB4NKxKRTcYNCPYPBvHteRYYKxACzt4aG5NxwtndoxqxNO1NEF+Z6Q0zRwpbX+ZY0almJbcBZn/22mdfmpQQlKQqcRJ5fTbfWCH+H8q+WhxrXPNbRn9OWUG2/GDfGsi4vz4822GnNF4bOSvhvx4MmOLHcpw6MvmFUE01ZESI3uXguIx6M221fUdLCO/FYl6U3cy9+dc/u69d2TNt6m/xPt7SSKRQ6d51emMzILKixcu8OrfPoALFVq/sI6X4PyFFQ91JwU6Sy9R2Ig== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:22:51 +0000 X-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:22:51 +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: [edk2-devel] [PATCH v11 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Tue, 21 Jul 2020 16:19:00 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR21CA0006.namprd21.prod.outlook.com (2603:10b6:5:174::16) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR21CA0006.namprd21.prod.outlook.com (2603:10b6:5:174::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.0 via Frontend Transport; Tue, 21 Jul 2020 21:22:50 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bffe7177-a70b-4e9b-6f3f-08d82dbc3937 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ubA/etK4aPxfzMtSAqxhD4pLFw7wbzMUuavBYSpwXhm83tnUSdv0dslMXoS81xNW/e0WAQAIg/B9qLzGXK6S3lVQ1M8VfNjDrf5siurQVQ5CAT/zfvg6auELKLQTfQ89IKOqTvDiLLNjr/ueZK2l56DF6MLhnZJpND95Io60lyZIjgBN8KPl+GB7aSx36yo9yhGnZ0BrR8QF4ZYXOxJmZv9BR6d1jCQAXOA2TM364OCIYsujPrf3Peiyrr67CEMhrDkDyO6G1kcqMr4J0oZKmKcgkucIguMUfnaj1FS0j3kZ/2UrgK8b3db37fA/GT4oRIXOpHZ59s6PJKmuJroYU2pXXglgEzsm7yvPCC+BlpX72CtZaDP2UF2z5jhPsSAXsvnr2fkP0dCnwkHzg6feTE8iDecBUCE6nFrRg2lrCkJHFmQkHP6P03YzS25rScyfWjuFfHq5hYDIgdcWzSMDJA== X-MS-Exchange-AntiSpam-MessageData: 5AlyZUpEdaDrglv9K3RuokxK+SnWwHQ6HVkGZVLskR18dYhQr95EDFuAbw4dhWUGT+vWOQk8KfQKxGBQ2VOEuGU0t9H6/O06sJb5nckP2rUCNYMYBeJJXlYxafrVMXCvOQR0bEUB7H0pWzZ6o3WiASULAnUM2Ch+DjzCf0TTWhIry+srDdeWhl/qVZb/zDGmPkShNvlSn+wqOOiIOEEGmRFxcxumbRZtAyAcpDi1n6A+tJWn8w8OWhZ76wF4XGMHQyY4KsU2nOUT7PWd1AJ5t9N8ZRMlaGx6dS3XghKtHuzg5YYDmTw0qvZmzXr6ZK3kRyILHRUF+Uoe0xi7vEwVDB90Fnm4+BGZut7fuJtlbDb5AXdoP2ywampHFbOWw+7m+2Jbj+SR7PlgdOluAc8ZDsZdU/pRzGEyIPNPzdgr2OjrsJ9wV7v5KkEd8OESMBa1WDX8DzeHkeo6j9tKq2qAdoSoDZNV1fjB0/TKYZ6qWCo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bffe7177-a70b-4e9b-6f3f-08d82dbc3937 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:22:51.1500 (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: i+1DzRch9UpggoXIFvFKOlk/9N1Gbw+h6hKvEV1x9EiLfoxGKrEYwOby9EM/lqxHPQvARQc30ygI/ZIOyzdKpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: H80MQYgJT7AwfSRNPxHe4oXDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366573; bh=KkRSd2a0ETZD4Plb5BfDfzqa5ieriRsFiLRsyL1NmzM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=hRxwxm0InGR+nYMVUMhTuPyTZHIGQ+LeyWLUv6F3asZ7qR9j6E79MnwSP7c3U0a03LO 9gULz0u1Y7ao+I6ZkvTTGUnZF85JrLKHpGVkV00uCxtPrOkXdA1ke5ZyUBL9EZScUK7IA K4D3pIa9IKjzzSZkwqiJuOBYQZqivNwAnP0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 54134f37e614..a1cf792d4d0b 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,49 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a RDTSCP event. + + Use the VMGEXIT instruction to handle a RDTSCP event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdtscpExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a VMMCALL event. =20 @@ -1443,6 +1486,10 @@ VmgExitHandleVc ( NaeExit =3D VmmCallExit; break; =20 + case SVM_EXIT_RDTSCP: + NaeExit =3D RdtscpExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63014): https://edk2.groups.io/g/devel/message/63014 Mute This Topic: https://groups.io/mt/75713118/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63015+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63015+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366581892749.3785311973777; Tue, 21 Jul 2020 14:23:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RjmuYY1788612xDFoapyb0al; Tue, 21 Jul 2020 14:23:01 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.80]) by mx.groups.io with SMTP id smtpd.web12.5629.1595366581075516144 for ; Tue, 21 Jul 2020 14:23:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n5erAB/i5j/NX+01qgB3hlfuYgAxnmao+MPQnBkmpqXKYheWqil56tO6M48e73PjKbS55kRcQIrFrPY8WfjnFYj87Dy+pB2VH6FEwF+4O8YqW6P7olnAEXvDYoo9EFOvVw5M5VkwebX3mvSeRMgB3G6CDPp7k/pRo6cLACOvpCiq8ztJd45mAUnLUJUt96NtFaVd9/ceiycFHibBri3D3Nsz3axcUphLJcSez5BL/xr54QBkKrdl9y+uqdNEi+P+3dNu2Z2jOgkrs42Aytjo4X2MlYHp0Dolr3cNJQFdu+upcxFxtljPWwS+EcEwfyC7xSGO6mOkd+n8kBQ4chQeXw== 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=8ngCipJpXdBRXheijMbZLSMbkg66Y4aDLYNKKgZfARY=; b=NYyW2a/9cj49jjIAs04Y/7bm7vQ6voBlubC+2c2AKK4rFIyPRZWH4yUdROEZrWDd9rhHAwsroToycQuDvRNuSvST06/D0kRK9P9kgbWRxtA8QVnG46ggezKPeCCdC3Cr4AV+UXXbZ8HAZzyygQJmJsaKLj3rSf4ne19y3mezm1/ppic98ZBVIyg+WL0Vl5qqDumfRYjFHpixvQ0DprX+CoknPadIQL61olQV3K7dFvnwD0Pwt1PBQtz1cl4wPyQw46QAdh6Dc9xBu/wRYcPRcTgQtSEXKhDVokil+Cm6qfEFXEJWEcn40F25SjI2EIBut0AYyxiySB3dmwpb7LlLGg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:22:59 +0000 X-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:22:59 +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: [edk2-devel] [PATCH v11 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Tue, 21 Jul 2020 16:19:01 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR12CA0028.namprd12.prod.outlook.com (2603:10b6:5:1c0::41) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR12CA0028.namprd12.prod.outlook.com (2603:10b6:5:1c0::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:22:58 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ab6c464e-0f6c-4c95-1281-08d82dbc3e4e X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: uU4Me1jI5sSS02Wiyf3hlgIEG5koJRXK+ROFkKRrN8Nd4IplCZbAKPcfxq2SPiuDWEdWPyCePjm4pKS7krlEBMpXB1YFZO6xIw9k1LXv+MEfpqaJg4YUyQ/vn1k6VZ3fF9dd1HpsfyNWaRcIhh8O+RVTPF0oYabH3EEDQSYBfdRsxM0FMrsa5eMzEri/0pPnkvlJ0iDJCoc/dKDDOO/PtKONQ/5SadmouUPFvSDlMl9zvmFqysCRJYmUafKT09S3iuxzgLwPlo6YgFY5eqoMUqQZOY9gCjACzVqrdufk6Q4TyKicKxt1PwVFiSpvgi3GVntRwGWwKDfVnpYLR5svts6pwE3aADFq5A7Yv058G20bOj27L2fzAxttr27WVgY2bWFKimwD9ZG8vPAwujdff/C14iR0kvPRiWmVvso1QYW0npmJwqajns8swjMSxDFdkcomQ8Ebvranlb436ovdkw== X-MS-Exchange-AntiSpam-MessageData: UTbiyyoSuE14G5jUN6/TrJnCAcbHhHP+7bRlQcQT/7Vb6g3PvwZ5tVAJSGZ6DHLgzBZV4RQWRR3+K21DqkQuteHwQgdLGtWYOtTzPvTSyVHdbrxxyJF4WNu1ZjyEqyACXK0uIAqsYsXJbWoYUzgL1PDOKU9f8tEAR1u4y78lt5HA4H5eom8iRMMPvwzeBDd7Rxh9TelbOKDJY6vAcenVLyM24fPU/TldFNaMtCpzOVyQk+HpoYcugeALdarJNOWQf6d5CHQWLHiKCstKjGMjodCkpFG5TphGQzE4oExymdeFtcCqS+VESc/54n74bkD9zz7/xMs4HkwCLVtr/X3R6OcmDeujGCBZi9S5HE/9S+Q/pXzxntTZe5htgzTUSiMR3geAuqmymnDUZnuBvmrWAiawWTA+UzkxtBd4prWEC4zQzl1wn1KS3zaET4auv42Zo4entr3qsYDOcMbalqyf5T/SqWeZI1BDYSF+o1KyU2Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab6c464e-0f6c-4c95-1281-08d82dbc3e4e 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:22:59.7189 (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: sy2cqJK4vr4KbP1pnfJh+HyWHGUYR35hYbGtbJrPvbFg8rtGq9E8aAcDa2M4oqf9sPxxXw/zOwdo92+vSQ+YJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: MddJybCACM3M2vc6AHtf54lox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366581; bh=8TuQmW/GSDUWQlt6s/s2/t6Uo5c5jFb31Aj3iXJPD5Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=pFS2c7sBf7FMtvczhuEl6dUj+dsR1Ax5YaqRlCcc/DLncNi0XEVE9EmhuJFQOS2SLGp pPwirScvJaA2ACv13bW6lQQ7nMiWYemDROb7Mww584fGQeeAbFKLVDPIohN1jGay0m1wX FySeVCxOq5AMi9AZVtcOJnTMBJaoJonDNOU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MONITOR/MONITORX intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index a1cf792d4d0b..fe08b1e0ff49 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,40 @@ MmioExit ( return Status; } =20 +/** + Handle a MONITOR event. + + Use the VMGEXIT instruction to handle a MONITOR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MonitorExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; // Identity mapped, so VA =3D PA + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + + return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0); +} + /** Handle a WBINVD event. =20 @@ -1494,6 +1528,10 @@ VmgExitHandleVc ( NaeExit =3D WbinvdExit; break; =20 + case SVM_EXIT_MONITOR: + NaeExit =3D MonitorExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63015): https://edk2.groups.io/g/devel/message/63015 Mute This Topic: https://groups.io/mt/75713120/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63016+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63016+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366591221511.70213768088024; Tue, 21 Jul 2020 14:23:11 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id whXqYY1788612xQK0aXW6A5i; Tue, 21 Jul 2020 14:23:10 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.83]) by mx.groups.io with SMTP id smtpd.web12.5631.1595366589681725703 for ; Tue, 21 Jul 2020 14:23:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=abCF+kJ++xm/EAvsIoqwrcpE5oqE+2pa8Fk8jD6OArifb6vDb5eAJ0N6mEItEe4WW0I0rqaf8WM4V3QZenWs3wVoaB5EEh/VY4AkGcLq3pZ/FEntWwlNoC6oj576WjnLzne7LkaPibZBTLh4JHKV+0wiXcdojHgPzrpn9/VfiCnqQL4341WBkjbU98de/gbUz3MD1dixEZRoph40vGmhvrBXck9NoqfgzEBFXJNIPl9n7xfWgI62V7+BfZTwK4vU1xWBi9IezL0qHQblQSKnvP+AY4VXkfVCw95qoMx3gpFNRjiFTnAXL7l8mfklrQKcHTbq+9A3fSWmgqor7AS2uw== 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=4ovVcxdgW2M+goyz4Wril5Z4GVk0Gp8R9simGO5DPIA=; b=nar6/S4eUE71fYH1Ls6TSCAty+vnU5pcIwhTo/2z+DO5/R2CNXaLrJkIAwIkqz/cBa7Nu9nkLHi7jyZ16ur4auD74BxNTApdYFxlT/lbbnmY8YB9z5ZsN4vJ/5OpLDva3ZD++cvHuxO8AFw6Iex0eMxPHjyIeqatjgpj2FFb3DmTSTj9LobgF09JbkxrmJgJ3E++E4YGjdIZaGEKTGSVXVKth0180mReOCtuRXvNvZZ8Yk0Z8KAPl6JXP2O6lDVk4UQ0OFm1aMi8lCu7JM60LjPalUmdn61QoDlP7RG7z11WuCifgizDyyk5oTn+u9uWKGHW8dSUHYnay0l8KT2geg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:08 +0000 X-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:23:08 +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: [edk2-devel] [PATCH v11 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Tue, 21 Jul 2020 16:19:02 -0500 Message-ID: <2c2a5fda09bfa253fd06d24afd29d1f46fc4eece.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0056.namprd02.prod.outlook.com (2603:10b6:5:177::33) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR02CA0056.namprd02.prod.outlook.com (2603:10b6:5:177::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:23:07 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5d733700-ba5e-47f0-eda0-08d82dbc436e X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: KF9NI497Qj7fpgonfpQ1+ngNLFOwDb9/8irYqsbkcybf0vRda51V1EXuxKYhsVxlKopWGa3UzzgWlJglkebGRjW2nfLJ2JK0zuO9f9djmZC5yMaxQbSZbtRGkOEVbnNBeHx//I9sjWlPDb6fEX1A5vgThrJiN94wUBlQATsiaLYe8ghXKpyB0uEz1Ecy4MWRKezd6dTLtlwwJer3TcoDIqjtOjZIeafyWyUSZo1HuM3bUfQCgQ2clnix+LLWpiITuG8VxV0OyWStGhkVtLJIKo5W2qGSpx200WlXB6X7+eRHR42eWLVTeZx7/JuCksyJoovT6TznktC7o7EdLvFRJZ3cIh1P1Yq4daERwPiQ7CnRDDHZxeIJW/tsWaOyJty4RCXd6Sa37LUO/LHUIjUGStS5nw2ygumMHajmDiH6e06Vd8Hc4IZGM/8mIzr6ANLiuEgFLs9UmAQKeJSIrDBWDA== X-MS-Exchange-AntiSpam-MessageData: RqjghWQo4Z7AGl/1Ostm1ApTQrA2qhO/Sg0/zdZXwimfilc35U3eZti1QWVX9zb/tzKa8Ak3zhAofZmZ9v1MElpwlnZmz09Wfn3qoHjSIC4bGYmfTfM6tFuR7e8s4aepyy7nn6ylYfG86/da0yoz+88vzmSXtFEbUVTSVZUBao0WkcQ/nRyOdRgeouc9qMDnj/GJWk2Uyj7esjAPj7cAhR2rMzU1tsxAfaDcfrdQ0bIa5X3jGyMJC03QLeQFoZSWm9CRj6MPwC46MN73BFVXTyFxQ1bi5WW7OgXFeMNRrgCiXiuDjPgT7mMOJqgErBNCfCupVyIKO7UxQS0HxJHa+0JU9ZLO4oAyhf842FIjZAYAg1xA8241CN7pZfGE4U0uDMegFoLTG7ZVl+Z8DmLx0ZZgS/HAHsCN5z1qH/6WpKaEHmEVMs0wWz2gNSm+i2jEndX4CYZS4T4YiMmvCQG1+CrSytGg8y8nGv43lsBHMAI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d733700-ba5e-47f0-eda0-08d82dbc436e 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:23:08.3139 (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: yIyu0/4Jk8MYCQno+K1a6+9mDpuK27TVEtbiW5O8Ug5uWfCwr2oX+y1VqiXLAPeNmknOohMpppd/hvS2oCWDxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: R2ngjdoAFJ8QUAu1BZk4RiCHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366590; bh=GnO+bbGHchN4XILibjlTjaY5nHb3oR715IywjMzDtHA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=gL+u2WiM0JbNZfJvqzLzw8aNEONVh0zJb4zDJFgev4Q++4K/+R4lT07vbTliUfSaA6V cLW9VWhOJgY+blqHi7wsk01pVQC/iOo6n7FKDH3ZbfSXzhr9GtWtdiU0D05GZtiatrwor 9dAadRhHrhjCilHbsTzQv8rN9kfwfQ1oL3Q= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MWAIT/MWAITX intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index fe08b1e0ff49..e70e0ef82f68 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,38 @@ MmioExit ( return Status; } =20 +/** + Handle a MWAIT event. + + Use the VMGEXIT instruction to handle a MWAIT event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MwaitExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0); +} + /** Handle a MONITOR event. =20 @@ -1532,6 +1564,10 @@ VmgExitHandleVc ( NaeExit =3D MonitorExit; break; =20 + case SVM_EXIT_MWAIT: + NaeExit =3D MwaitExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63016): https://edk2.groups.io/g/devel/message/63016 Mute This Topic: https://groups.io/mt/75713124/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63017+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63017+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366599527374.7551409509906; Tue, 21 Jul 2020 14:23:19 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vAR1YY1788612xz8DU4UA1Mc; Tue, 21 Jul 2020 14:23:19 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.79]) by mx.groups.io with SMTP id smtpd.web11.5544.1595366598591878279 for ; Tue, 21 Jul 2020 14:23:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BAy/dlih5ymzWxcw9wFUuLCRmRWDk6ss44EgmTAHsQYgu64V/4SUBm+r6ZF0mp3j3nLwCFILxNKmXGjnqx0S8QgrdiM+NbhyaSv9fknSonscbaSAngxrHrITNPGpN9EdqLBvYy9e9SM8UQzMM3QYczMDot3BaHxluB5EQ8jOLW89V70BXtKdXacUPJrNcBFUeNMlUjClhZudOoRNKVLbOd2ysqO19vHN9zFBqP4hjjcxK5FoOV1wM14r4uk8iqgwRyyaM394CV8CDKvy9/PtL2drPc9+SkhIJq2fEsdWrwJBm3BZOBvmjJivJjcbsAO1K3MzEIPvEpaITnPGiFEqEQ== 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=eqxKEl1jkDkoQSy0tcmI5Mo0oyJK/DNNn+LhL12PTF0=; b=KgjUFrfPNkr/v6RntFuo7DZ4BqRdRWyt6vr06PzXK3ohb1bmRl7eNO9GZgDyAuThdeyCnpAqmxymVuXaIwnz3KWZiUC1fwRbvRcXA5db1fdTQXV01zjP93FuD8aIz8wa7/F6+3NX6va163ljEkU6oezaC41QiVpUUe81j2WeiOAbkCws+waaVajfoVrCpcynJ3Nb9cFhssWSfWSzHrMXMuC54XEf8Kj6FSPF2uYA0m6tdeNPp5S6JQn0d0XcFoDu0iBVKC/b16qIGxI0Ce+GXcwT+K7aGfflDeYnb+6E8kapP+K7h6Eggb4ssk2Dc1HNdJxKzXShJHzo/S80hpBsqw== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:17 +0000 X-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:23:17 +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: [edk2-devel] [PATCH v11 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events Date: Tue, 21 Jul 2020 16:19:03 -0500 Message-ID: <2343dd7cfbe0c9eb8fb19c252d3a189b15290e4a.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR1101CA0007.namprd11.prod.outlook.com (2603:10b6:4:4c::17) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR1101CA0007.namprd11.prod.outlook.com (2603:10b6:4:4c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:23:16 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5499f3fc-c227-4ff5-2e6f-08d82dbc48c3 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Ar9/IYz8OcP7gSfF2vLbCMdSYWIExABK2a5DBsOT4DItAdFCCUfHVMEWEzewjaeMZDJKqCJE4RYmL1PtGPgR6menQqA7MSv1vzInH4MCsh97o/CLt39Rp7TjVx0jdA8n+nbEWF93Ldd0ItnA9mIt90XTORZupHTBlv0A6xea39TqreXiTR2rZ+7scLDRocsCf+9YLtNlbznu1+wllydbv73V7/b17po8RPNsXgSzR24pKL7C9LVFQMwl9eT5Fc63VNt5fySDAGtka15JLNEqki1cpIANlyxo2ePKp7YLUGx0QbV6fRNiAA+ZsYTHwpnt+vgfdktxQ96255VRA3vhgaKUlTKNAHSe82lJsDx3R6HqGDb8ot7z7mqE70NWfeBSeAWvccTq+f3RPQ2EE6RwCzJ3QKxWtTu/Ct72GnfT04eVanKAEtjtkj5YvRVDAPxW6HZavBC1PKFReuJGc08nJA== X-MS-Exchange-AntiSpam-MessageData: MMGSASQ2AfzIa69nJ/HpXsgQCLjt6YIzBxIMDzIl4Op4Su5WDjDW+hK7wh0TcVpa2VH1c9p9aekoSWZpmYBxW453UvcF9rAqqTfSlGg5blkgfz19MFVxFcUBh4pCN7KwM+bgf1x2ap5QSaNggxjSfFzOasWcEjOb52u9Nhr+THhCy13qvuas2MHNstnyC012zrKNZ6XQuFKQiqupQc5KNJO8za/zUMDewSva8W+vNu1nVKbzuHtrXxYoDp1/8KCfZRZB/iFFpZ4lno5Eo0DaQgvZgNcr0ydJGp7W1RrYvmtqVpCK2Y1t8GseswDqPxF/wMrFvxDzaEkdjUz5jfBdBr90wiuf47Nv+xoxbFmEp5y766bBDD80cR4u34BDg+hkJxpA0KZ2/QwO/aSr6C6xGrt17zgTfbNbn/WtJNOfZvTr/Fxozcww2o/Mw6o4mub13G60ArQe2KOMl2mWqQ90ikybRYOPjHJLAADX63BbYNE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5499f3fc-c227-4ff5-2e6f-08d82dbc48c3 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:23:17.2676 (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: 0igwiVf24H+2pDdt6CSCHi/QkLwx1KCmDrNBmU7QF1Qau0CVDa0ESvcOjQNwwJgwa1VMXNKYj0jGAHqCmHx46w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: Wo8xthKzegzCjuRkxFeXDAIjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366599; bh=2SIaL4fLfOEGFKT/xtbiWCz71OrAYuUF9Rq+p+/FlWE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=FMVeNnMTF78T+CabHUBGF05H+WRETlfNrlznC5kYPJLvJHGkAML7sPXyEvu8Dl+PFz7 q0qOQE/53PfTMTpuYiAw90ob705GzgeAd6+jjuSS17Gy7WBbx2hOr4k5v3rlzSrPLG+J1 GgU8udl/wEEzJAMT8CuvWw+vaBRWgr9fNJU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a DR7 read or write intercept generates a #VC exception. The #VC handler must provide special support to the guest for this. On a DR7 write, the #VC handler must cache the value and issue a VMGEXIT to notify the hypervisor of the write. However, the #VC handler must not actually set the value of the DR7 register. On a DR7 read, the #VC handler must return the cached value of the DR7 register to the guest. VMGEXIT is not invoked for a DR7 register read. The caching of the DR7 values will make use of the per-CPU data pages that are allocated along with the GHCB pages. The per-CPU page for a vCPU is the page that immediately follows the vCPU's GHCB page. Since each GHCB page is unique for a vCPU, the page that follows becomes unique for that vCPU. The SEC phase will reserves an area of memory for a single GHCB and per-CPU page for use by the BSP. After transitioning to the PEI phase, new GHCB and per-CPU pages are allocated for the BSP and all APs. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index e70e0ef82f68..c57c8c4ba203 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -126,6 +126,14 @@ UINT64 SEV_ES_INSTRUCTION_DATA *InstructionData ); =20 +// +// Per-CPU data mapping structure +// +typedef struct { + BOOLEAN Dr7Cached; + UINT64 Dr7; +} SEV_ES_PER_CPU_DATA; + =20 /** Checks the GHCB to determine if the specified register has been marked v= alid. @@ -1480,6 +1488,104 @@ RdtscExit ( return 0; } =20 +/** + Handle a DR7 register write event. + + Use the VMGEXIT instruction to handle a DR7 write event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +Dr7WriteExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_PER_CPU_DATA *SevEsData; + UINT64 *Register; + UINT64 Status; + + Ext =3D &InstructionData->Ext; + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + + DecodeModRm (Regs, InstructionData); + + // + // MOV DRn always treats MOD =3D=3D 3 no matter how encoded + // + Register =3D GetRegisterPointer (Regs, Ext->ModRm.Rm); + + // + // Using a value of 0 for ExitInfo1 means RAX holds the value + // + Ghcb->SaveArea.Rax =3D *Register; + GhcbSetRegValid (Ghcb, GhcbRax); + + Status =3D VmgExit (Ghcb, SVM_EXIT_DR7_WRITE, 0, 0); + if (Status !=3D 0) { + return Status; + } + + SevEsData->Dr7 =3D *Register; + SevEsData->Dr7Cached =3D TRUE; + + return 0; +} + +/** + Handle a DR7 register read event. + + Use the VMGEXIT instruction to handle a DR7 read event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + +**/ +STATIC +UINT64 +Dr7ReadExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_PER_CPU_DATA *SevEsData; + UINT64 *Register; + + Ext =3D &InstructionData->Ext; + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + + DecodeModRm (Regs, InstructionData); + + // + // MOV DRn always treats MOD =3D=3D 3 no matter how encoded + // + Register =3D GetRegisterPointer (Regs, Ext->ModRm.Rm); + + // + // If there is a cached valued for DR7, return that. Otherwise return the + // DR7 standard reset value of 0x400 (no debug breakpoints set). + // + *Register =3D (SevEsData->Dr7Cached) ? SevEsData->Dr7 : 0x400; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1524,6 +1630,14 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_DR7_READ: + NaeExit =3D Dr7ReadExit; + break; + + case SVM_EXIT_DR7_WRITE: + NaeExit =3D Dr7WriteExit; + break; + case SVM_EXIT_RDTSC: NaeExit =3D RdtscExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63017): https://edk2.groups.io/g/devel/message/63017 Mute This Topic: https://groups.io/mt/75713131/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63018+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63018+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366609341646.35296985658; Tue, 21 Jul 2020 14:23:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vDzqYY1788612xcBPgMyNMRi; Tue, 21 Jul 2020 14:23:29 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.84]) by mx.groups.io with SMTP id smtpd.web10.5683.1595366608553496250 for ; Tue, 21 Jul 2020 14:23:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GMvlXrDJPydwnfPOLDnLxGFyJygFTXUSsolbj29Icww6RWZjHONVX5i0UI+BtsXPBRaVMQiYQbwNrOqUt7ALabk8S1iFsHoqQbQa6xZaCQmbtP5YkIIRhdztHWLiYBAtyLPgZepoKKR9aroM/O6TC9a580kGbOL4MhijeGhiTOmjJuA2IlozstVgqwP13cx/9eLGcTq0xy9kaKywpWp1GnKAG7SG0M0xsmbM+rtN7J9naJTWhL5+RodQ2JEjYfgI4txaa202oJ/fLTm1qhvYYp8d+p6xb+37cHvxxGkTl1Ahm3LxPlXa7jGTtShdboehwmpS6x5SkW8FMEFv+ptWtQ== 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=vjUCEgWiruW32rdghdGFw/QPeneWsq53gmsGSiMfqdM=; b=OiOliDalNWCYhx7RaADIUj5Z8UgrTrAZ32oE+wLNZ1RyUBf0O0qFggOoYcq2/rpM/mMHXaYNiWOQofiKFZbfF8etZ00Zdhe8E6FjvGaQTcCePea/U7AptQjb4t3dgzbLYyzNcRPcZHPZtIYo5H4U+cFTQAzVLTU+chz7+ju0EPQ/Rh2nNveG+oOpTcs1KWPVqnkWbZ8cnPv9TFcEKvPsUHrdURnLCSdIQ7xqMtNVk+WNV5TRZsPRJro4C9mGkFYOfoCIPHtF0bfEDY4+IJKCrw6QJQgLoQ7GI8fAu9epAhicrKcvXTavaaycBjw12oLEfulykhwLCTBqMhPk7d1SHg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:25 +0000 X-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:23:25 +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: [edk2-devel] [PATCH v11 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Tue, 21 Jul 2020 16:19:04 -0500 Message-ID: <9617a7ed9a01abdeb95a08ee56dda9c0f5fcbfd9.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0024.namprd08.prod.outlook.com (2603:10b6:803:29::34) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0801CA0024.namprd08.prod.outlook.com (2603:10b6:803:29::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:23:24 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: af69607f-6e6b-46e7-32ca-08d82dbc4dae X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 0IvjlwqtNEqjL0Hkdag2+UUCkWJeOZ6r99fXtXXZ+cFrcgWL9Ym45RBsG4+fX8JBSOLuxujdByt9lzigV5zVOJ/kihnWOAlEHEPPh1yq87/XiR/V6W5NLUgZ9ldOBUKMlVTvppMK0FnNFqzYDp0oxenf9cYgpa/hNEjW+aXbRPDI754sONaMd7XE+qjeNklMPByKaA7CEyUe/8RLZ49wS57T7LMKfgn0a7DAmOMeof/DJfB1I0bDHlRCeyPUtSb9gseGjqnLP6Q2uQ4rr6k6RVsJItUxv7a9+EJj12xt0iRf30Z6v6wC/c63I25ikajdWd3fQw+IYEOOZoA5EUimSI/VBTi99atB+oyuColGmnJiMa3HK+AHw8uZpfF4DIbhL7Sza6QglmDdwSYm8/y4qhdm2Lk8dDjwEKeY1ozJI09SskZj4F7rf9S7yl5z0NAt10lWeCHp9vpvty8Z/VeVfQ== X-MS-Exchange-AntiSpam-MessageData: JgxnTVLEWOkcrR/c0by6If42Y0o+xC/uj5FF3bc9e6MYSwNyf6bNdf+73ggWJJhnm4IQVuuassYqFsfD0QAW5kUS/igA+9w/NbNo7WNLQTXcLP0Tw0CA9K6UrDWWIq3j8fwM2QoRsINwoMp3fEflu6/Z6Xv3J3tPRIUHwWI/DszmxFy/hRuD84yDE8ub/Ombnqw3l/LYxFR2IH7rkczHZct3IkZvzkTctsLZll6HFy77C/xTa55vP6KHYXAZGGq3zAJUaQ1E1ZcBnlMlPYVoMQeR6Dy29KDvBbn10B5NvsNe4PNDAeD1kvBd1UZM4SWMfwUmBfs870cSS/K2Q1cbekk3aPp02nhAKewptxkgpHogMGwqpx8buWJHGZACfNox02AFBTLfxCGRTDCLp3ix+uAO77a0NiRIK+Uf9oIVrNOiz+qONuCZCQCnzvKtel4aRS3mBsbqOeNPTb0HZpcfS3eFTevMFslQ1PxLHeVbtgY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: af69607f-6e6b-46e7-32ca-08d82dbc4dae 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:23:25.4827 (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: xD4hvXqd9rVqbEXoCrFtyeNcaoenMQqBkFfIvyLmp15/vxN4t/ZqXn78uT1u+D1NBfRHiMjc3qZIebk9h8D0hA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: iRUkbqmEld110csriy5PyioNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366609; bh=NhcFMcmgu2OCNxQ3GZ7tgYKQdJmP0zL2k94Ctp8V+04=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=hSTch5iXB0qDMYCVuOGluOEOyBMnl/Wb7L/5wL5hAN0lgIg3J5wu7wf5Feuo8De1ClI lgyhUKQyUqTeN3U6gsnNX3dfR9b99orJApH2huYtfKzXcA5hzHXrNDTPYU9qmBBE9FkDS xjfYoubjCbrRclqIbYGwUzRVJhZ7KLPPqSg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create a function that can be used to determine if the VM is running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 +++ .../MemEncryptSevLibInternal.c | 75 ++++++++++++------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 64dd6977b0f8..a50a0de9c870 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -13,6 +13,18 @@ =20 #include =20 +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ); + /** Returns a boolean to indicate whether SEV is enabled =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.= c b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c index 96a66e373f11..3301c5c2862f 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c @@ -20,19 +20,17 @@ #include =20 STATIC BOOLEAN mSevStatus =3D FALSE; +STATIC BOOLEAN mSevEsStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 /** + Reads and sets the status of SEV features =20 - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled **/ STATIC -BOOLEAN +VOID EFIAPI -InternalMemEncryptSevIsEnabled ( +InternalMemEncryptSevStatus ( VOID ) { @@ -56,32 +54,55 @@ InternalMemEncryptSevIsEnabled ( // Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { - return TRUE; + mSevStatus =3D TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus =3D TRUE; } } } =20 - return FALSE; -} - -/** - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled -**/ -BOOLEAN -EFIAPI -MemEncryptSevIsEnabled ( - VOID - ) -{ - if (mSevStatusChecked) { - return mSevStatus; - } - - mSevStatus =3D InternalMemEncryptSevIsEnabled(); mSevStatusChecked =3D TRUE; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevEsStatus; +} + +/** + Returns a boolean to indicate whether SEV is enabled + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } =20 return mSevStatus; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63018): https://edk2.groups.io/g/devel/message/63018 Mute This Topic: https://groups.io/mt/75713133/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63019+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63019+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366615398692.8446945518406; Tue, 21 Jul 2020 14:23:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MoYjYY1788612xONwIrtk4cM; Tue, 21 Jul 2020 14:23:35 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.42]) by mx.groups.io with SMTP id smtpd.web12.5645.1595366614542794575 for ; Tue, 21 Jul 2020 14:23:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eb9yLYfXezB42o4dAVLS+29TmpLaFTAQHv7yYaL8S3lMuLjldCoYmdTd2Q2Bq/sPYHl3n6Is+uCr4leg11XfQj8U4CRSP+E5/Qyo6dchyg7+6jgmxFQjVubB9vt54Rp/g8M2B2IxNnbd3TQTgVEgG3Pqvpkv6CoUMwtITmf4vKZYKphuZQlziTRBfeekmXJ0L0iTP6cJi+meVjSq1MMHtfDxlid7m5YfJ2maFwBqZ1/aDS6yRgjXNw/bniMG7bO74ffYpPHwiEDUGMJcBADnputVjG7wmIuzGCsHX0v5mnFjp1z3qH34unKXzHJA2xEYJqGt1Nw4w7ocsOuvZJCpQw== 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=tpMCGKkJ/vd5g9S5fco/aQoufjhaVtd6vFQYZt6tvPo=; b=js9icTynN4/EQ6GW0R69TLNkyL+oGZD51awsD6LF42VqXFrxeKXBTuouriV/EzmD2T37MI9Fas0MewzO/C2C3uhFFFKm9ZAVgzL5GVJw6AqhrLlQVFKkyZDOXom5YISAP7SI1TBzMcprXZqHG7DT1ulJ0uUIz8HVDv5+MSw7y/OAO40AcyjVqhyplvI0wbnxrTeVQlBvzjxJc0uE/rkr/4oloOOQ9m0o7htAHl7EdYrWz1MwG82NdRmc61xYH37BaXZR53cOhM0f24vzpzxwTXrmTRmyEG8XAJy7Qj6Z/DnF/zt1/SYj4MGwmtWKt2KeMDDfmhvB5WR91fs8xFfWZw== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:33 +0000 X-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:23:33 +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: [edk2-devel] [PATCH v11 28/46] OvmfPkg: Add support to perform SEV-ES initialization Date: Tue, 21 Jul 2020 16:19:05 -0500 Message-ID: <14be6eba14cef5469aefd825d2ef0ed58746b9ed.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0018.namprd08.prod.outlook.com (2603:10b6:803:29::28) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0801CA0018.namprd08.prod.outlook.com (2603:10b6:803:29::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:23:32 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 05b1ffbe-6262-4f9e-abcc-08d82dbc5241 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: O/peq+jXXvEFtozKJuhme/ZlEC0jtfp5IdYqPHWLdLzuGkPl2tunEw6slQ2tk+MaApR67wsCxi318PQSzXYd9JoWxvFrDUAizP+hEyOKBVIfCzayLz+lHGvqhAI0oFMWXycRPICeuPTxKgbGCR6ztAK/YBhtrkRNbNqbBIXlMIfqDiVmlSQdSu6L57a9g1XHfYmX1V/19gz1nDSV8Bg70z9paQX2iUCfjxcXmdG750lPYIt6GfL2iHGrHrvVRwkHB/l26PZy/gRTiQQNXSoHqKcePPZ5Z+80Sm90up7QCc4W9bOiQVNFUBnpLyqjcPdLM+WhricaXAh6LI6R6ca4ZttMYjnRFFIsGQjyhhKeNTPItmf5xpfg98cXd7NbgSMyJwCQcL10+nNjpsv1C4L6+LIkDCT03hi6oe4FddJn9eyXFsmhe9MLXJ5VGOFK8xYvfCkKVxcHlYrZgG0AGctd6Q== X-MS-Exchange-AntiSpam-MessageData: U2IP1rtGlSAF4eDQpdAyT3J3ryOQLTz0Aak2M0BNuVHjlBd01AHaMqvEpcTuMTir4Q3ZE8gtUTHZRLHZzM0da1oS/BTCXOoH5MkaqOLaP/2VbGrMJpfD1FUDjtqgmS+T4oHBmAqzox4MY0RdHlwDL+BjpL+xnMNs/KFf7p3IeDmpK/veivT7BMvebTsXTed5dGA8qI6dFCeOuVs05NbSIozvutn/f2Bp4vFQ/xDnNcTsi32jQFZb27I14h6c6roAgPzCP5bITPbhlAjtQnOC3jOudwG71fWgOe//iSpA8UYH8AkUNWOH6t159UUfA/pOnMCYrlIJBkWUpuV1iBs+DISVnnUkhkbnfS7GfqMtxUimdy891bb9q9Qbqx6m41xKgLNpo8zj14HUf4nqY3PjN7om0xt5K+GpABrVu4Kb5Mraw6GfZNv2dxwAl0R+SzZZ1equM304Uufm5Qf5/blSm/wNY9DTo21cdHSS+YfdlqY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05b1ffbe-6262-4f9e-abcc-08d82dbc5241 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:23:33.1751 (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: INmg+qKFodd7C3cQzlwrtRfGhtWLSa9/nma8JGFyIXYrI+JRpzyhYkEBgRbJis6PLcIzLVppumTnivK4yRLuAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 9TbgFm35iF5gO2tawvK9wmkmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366615; bh=Bu2KO9AtbY/Zr1R+/IL1/CqBXgSJdSOgg4+MzgKWkoY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=mhRKyIG2kYo7ebWc16FUIVaz4ciDpzoFM/EdtoKekI0KdH73YhwZXwWDMZYQ7Mj84jV QPa3VChoRQN55b9h+VH64QIlNwjLGxNfeU//nxsuc2ZpgFQf8adPw0CKViupba63H/rzM lmaUrs4XhlHYbQW2vWhalE0hIEZgBmH0s0U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 When SEV-ES is enabled, then SEV is also enabled. Add support to the SEV initialization function to also check for SEV-ES being enabled, and if enabled, set the SEV-ES enabled PCD (PcdSevEsIsEnabled). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/AmdSev.c | 26 ++++++++++++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index c57bba1ba197..f84f23f250ef 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -607,6 +607,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 22e930b12b9b..a66abccf8266 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -619,6 +619,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 60be5eae3d2b..2a8975fd3d29 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -617,6 +617,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index ff397b3ee9d7..00feb96c9308 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -103,6 +103,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index e484f4b311fe..4dc5340caa7a 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -21,6 +21,27 @@ =20 #include "Platform.h" =20 +/** + + Initialize SEV-ES support if running as an SEV-ES guest. + + **/ +STATIC +VOID +AmdSevEsInitialize ( + VOID + ) +{ + RETURN_STATUS PcdStatus; + + if (!MemEncryptSevEsIsEnabled ()) { + return; + } + + PcdStatus =3D PcdSetBoolS (PcdSevEsIsEnabled, TRUE); + ASSERT_RETURN_ERROR (PcdStatus); +} + /** =20 Function checks if SEV support is available, if present then it sets @@ -103,4 +124,9 @@ AmdSevInitialize ( ); } } + + // + // Check and perform SEV-ES initialization if required. + // + AmdSevEsInitialize (); } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63019): https://edk2.groups.io/g/devel/message/63019 Mute This Topic: https://groups.io/mt/75713134/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63020+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63020+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366627754970.7617972834313; Tue, 21 Jul 2020 14:23:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EnYNYY1788612xCxyRB5Kg9s; Tue, 21 Jul 2020 14:23:47 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.70]) by mx.groups.io with SMTP id smtpd.web11.5555.1595366623668726332 for ; Tue, 21 Jul 2020 14:23:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FyhfiOy3j5m4r9O4pqvwUssWqFpHbby+yAOuOtUNDVkQ5bguK21jGGaDQAzAnCwKuxCcATJITMeWKUgjuo/zr5IEX4Vlyvdt75X3G8qNPazBCUriN9vXCCwL8OnFunbgNqU7Eo15UII4LtFSwZ4JBc6A6fldi1FuBh2SrOZae2vxkLXLBsNApRi7yGlq5V5NyqMw5/66z7kEBV3aK/8S5FlX4+cTNqesMVO0W3DcrwZYrDQngl+jcflOpWFcn8SefptqO485B6Kwq9yyxHyGCAzjpxlFaSWC6WHWscNPsD10MFOAbB9snv28lNl7XlHDDOSgfEJrpoewlJzgb2cOtw== 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=Ke60PaVdSxYJQ3IyGhV7lZu5CXMr29+Cm4iFcbrKpTU=; b=R3vQsrakbIWclsNQgbMdoJpNUGFU64piK+ZdFy+fAk2D6tHprJkyAq2h8PSwCpqQaR+2P9+voU0y1kgE26RN9+B6nLTM5YftYqgFQRWiFBuIdgFjqseEPi+V8G35r6RLuaaIZzXLR2nSyRz2cespQ+62MHVr6IppFijwd2hu5gCRv2x6csvUCYEbd6edPYK5aRRHzOoG+m+zqzkxMI/PxkPPSJkgSwQ5Tm3hSf495p8fOPzN1S2+n2eCiXWsQQv115uzZ+4Dvt7NLEG3nQ5yFYFzmHgrhsTinNQP444ii2tkQrVUumJIwgYpj0gjD9azD14z0NKrfHaKBNjrTTIsMg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:42 +0000 X-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:23:42 +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: [edk2-devel] [PATCH v11 29/46] OvmfPkg: Create a GHCB page for use during Sec phase Date: Tue, 21 Jul 2020 16:19:06 -0500 Message-ID: <5076b2a43303c175d80794e3305393c3f0fa5228.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0122.namprd05.prod.outlook.com (2603:10b6:803:42::39) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0122.namprd05.prod.outlook.com (2603:10b6:803:42::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.15 via Frontend Transport; Tue, 21 Jul 2020 21:23:40 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0b6712b2-d58e-4edf-779d-08d82dbc578c X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: fVdAFYF2Xl5mK85T71X+ZCWGq4ZFrLMI6N81AUdyEbakT0WYTfID91+OJSvE2ZQ6ybJzj7ZubYMIxzROpogN2XpS0bkyuNYuRwQ5e57HwZg4pl0ZgxS+h7fZUEbm//GQ2EV8QzZrWi3O2Jkis6gKwWpJRCtXmEeSsbXde6lJUrhjB1HG83+tYlOmZv6HtH/tI56XqCdlIjDCKkMiejiHcIx4G+4Er++v2aAwBvWUL6j4M6/vNwRWFMEHYttZrWv8F7AzEOTEzqkXeKjEob3IraKkJHdcuhSwlIxmjjyunzpn6F/Nn+y/HYLznqlv0G6KYSYKKI0yyVv0VVGA2MapUxDPB5ckp7iKe733YxgrXPDzK5Y0xF/OhbiarPuE4BxwbH8f/keMdVcUe9bKjEnuj/05/cIub0Lt2KNvFR5OxT7l1JNofsrY+NLZJOEhw041yNx/Qqarcub554n22E6Etg== X-MS-Exchange-AntiSpam-MessageData: W1c2hVpRIWxJ7rbDa7yUIcIZ2b9YsQejEWOKPnRJTqwmDPWlXibodEiUdzIv63HfqWgnxgNmBpUM96163t46ZF8AiZlzqx0sreNFd0PnVoaQJtmFtIka6D1rhk6zgVuBz0BiV+f4R8oUQph5iC2TogkSqLGry9807pPEq9ZpNRpJPNW2AdWHW9qZrXtzONDgLAuX+6yqaE8yUhbiUlHxz/LzhHv/EeUHrqcpaB/AyierMeKtp9K00UzVoBOylDc4/xERJZgJzG+laRmSUUVtB2+G6lFizxEmxvLxm4t90+Jn8n1jX+wJzFI8CYjPpQw5UsoKqhfEq6Ydylfb1Npd70qo6a5cftEpIJ8zjYMF8VHA0ftIJrqaPlSSMyBWs6yJVadjFftrhmzQRGr45p2Avt1Le6VzJmmgdu6MLMWuIHLgnJZ184wDLklQevnSlwjWKPK6ZwvRResMK5alEwZN8GmqIj4DhfdcAansM/fSJuI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b6712b2-d58e-4edf-779d-08d82dbc578c 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:23:42.0889 (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: 4Bppfp+Vo9gjT/lyrjN7Wa7tHafhsgLyU3SNn06abKdiW/QcQa/f3HIayU3kIASJ5OZ45PNiltQIgiH6DZXGFQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: R3jskzbTif04Ch9yAQIdwW1mx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366627; bh=UcEvLsxblx0xLmyWzb1RSesNZf1wvBSkzBKtVhduxbk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=gTH62vPsu97mcVt2S3WsMEyPX/jvR1VYDFWHWO+/LecUVylyHhohSzJM6ql4xSH2LqS QEIprn0H0XmpMoV/5Ge4DmCJ+urmC4fE6qYHXk0hx3CWGtSnec2JEU4HzXzsC6vZzq7Zn 6SfDIyX6Yt+PVGXco84uCgXve5VIMk6z5qc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A GHCB page is needed during the Sec phase, so this new page must be created. Since the #VC exception handler routines assume that a per-CPU variable area is immediately after the GHCB, this per-CPU variable area must also be created. Since the GHCB must be marked as an un-encrypted, or shared, page, an additional pagetable page is required to break down the 2MB region where the GHCB page lives into 4K pagetable entries. Create a new entry in the OVMF memory layout for the new page table page and for the SEC GHCB and per-CPU variable pages. After breaking down the 2MB page, update the GHCB page table entry to remove the encryption mask. The GHCB page will be used by the SEC #VC exception handler. The #VC exception handler will fill in the necessary fields of the GHCB and exit to the hypervisor using the VMGEXIT instruction. The hypervisor then accesses the GHCB in order to perform the requested function. Four new fixed PCDs are needed to support the SEC GHCB page: - PcdOvmfSecGhcbBase UINT32 value that is the base address of the GHCB used during the SEC phase. - PcdOvmfSecGhcbSize UINT32 value that is the size, in bytes, of the GHCB area used during the SEC phase. - PcdOvmfSecGhcbPageTableBase UINT32 value that is address of a page table page used to break down the 2MB page into 512 4K pages. - PcdOvmfSecGhcbPageTableSize UINT32 value that is the size, in bytes, of the page table page. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkg.dec | 9 +++ OvmfPkg/OvmfPkgX64.fdf | 6 ++ OvmfPkg/ResetVector/ResetVector.inf | 5 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 76 +++++++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 17 +++++ 5 files changed, 113 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index f16c00ad5b99..74d88f61617c 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -289,6 +289,15 @@ [PcdsFixedAtBuild] ## Number of page frames to use for storing grant table entries. gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames|4|UINT32|0x33 =20 + ## Specify the extra page table needed to mark the GHCB as unencrypted. + # The value should be a multiple of 4KB for each. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|0x0|UINT32|0x3e + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize|0x0|UINT32|0x3f + + ## The base address of the SEC GHCB page used by SEV-ES. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|0|UINT32|0x40 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize|0|UINT32|0x41 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 83ff6aef2e8c..edb03b5464d4 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -76,6 +76,12 @@ [FD.MEMFD] 0x007000|0x001000 gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgT= okenSpaceGuid.PcdGuidedExtractHandlerTableSize =20 +0x008000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|gUefiOvmfPkgTokenSp= aceGuid.PcdOvmfSecGhcbPageTableSize + +0x009000|0x002000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.P= cdOvmfSecGhcbSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index b0ddfa5832a2..483fd90fe785 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -26,6 +26,7 @@ [Sources] [Packages] OvmfPkg/OvmfPkg.dec MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 [BuildOptions] @@ -33,5 +34,9 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index abad009f20f5..9f86ddf6f08f 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -21,6 +21,11 @@ BITS 32 %define PAGE_2M_MBO 0x080 %define PAGE_2M_PAT 0x01000 =20 +%define PAGE_4K_PDE_ATTR (PAGE_ACCESSED + \ + PAGE_DIRTY + \ + PAGE_READ_WRITE + \ + PAGE_PRESENT) + %define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \ PAGE_ACCESSED + \ PAGE_DIRTY + \ @@ -75,6 +80,37 @@ NoSev: SevExit: OneTimeCallRet CheckSevFeature =20 +; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure +; is enabled. +; +; Modified: EAX, EBX, ECX +; +; If SEV-ES is enabled then EAX will be non-zero. +; If SEV-ES is disabled then EAX will be zero. +; +CheckSevEsFeature: + xor eax, eax + + ; SEV-ES can't be enabled if SEV isn't, so first check the encryption + ; mask. + test edx, edx + jz NoSevEs + + ; Save current value of encryption mask + mov ebx, edx + + ; Check if SEV-ES is enabled + ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) + mov ecx, 0xc0010131 + rdmsr + and eax, 2 + + ; Restore encryption mask + mov edx, ebx + +NoSevEs: + OneTimeCallRet CheckSevEsFeature + ; ; Modified: EAX, EBX, ECX, EDX ; @@ -139,6 +175,46 @@ pageTableEntriesLoop: mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx loop pageTableEntriesLoop =20 + OneTimeCall CheckSevEsFeature + test eax, eax + jz SetCr3 + + ; + ; The initial GHCB will live at GHCB_BASE and needs to be un-encrypted. + ; This requires the 2MB page for this range be broken down into 512 4KB + ; pages. All will be marked encrypted, except for the GHCB. + ; + mov ecx, (GHCB_BASE >> 21) + mov eax, GHCB_PT_ADDR + PAGE_PDP_ATTR + mov [ecx * 8 + PT_ADDR (0x2000)], eax + + ; + ; Page Table Entries (512 * 4KB entries =3D> 2MB) + ; + mov ecx, 512 +pageTableEntries4kLoop: + mov eax, ecx + dec eax + shl eax, 12 + add eax, GHCB_BASE & 0xFFE0_0000 + add eax, PAGE_4K_PDE_ATTR + mov [ecx * 8 + GHCB_PT_ADDR - 8], eax + mov [(ecx * 8 + GHCB_PT_ADDR - 8) + 4], edx + loop pageTableEntries4kLoop + + ; + ; Clear the encryption bit from the GHCB entry + ; + mov ecx, (GHCB_BASE & 0x1F_FFFF) >> 12 + mov [ecx * 8 + GHCB_PT_ADDR + 4], strict dword 0 + + mov ecx, GHCB_SIZE / 4 + xor eax, eax +clearGhcbMemoryLoop: + mov dword[ecx * 4 + GHCB_BASE - 4], eax + loop clearGhcbMemoryLoop + +SetCr3: ; ; Set CR3 now that the paging structures are available ; diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 75cfe16654b1..bfb77e439105 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -53,8 +53,25 @@ %error "This implementation inherently depends on PcdOvmfSecPageTables= Size" %endif =20 + %if (FixedPcdGet32 (PcdOvmfSecGhcbPageTableSize) !=3D 0x1000) + %error "This implementation inherently depends on PcdOvmfSecGhcbPageTa= bleSize" + %endif + + %if (FixedPcdGet32 (PcdOvmfSecGhcbSize) !=3D 0x2000) + %error "This implementation inherently depends on PcdOvmfSecGhcbSize" + %endif + + %if ((FixedPcdGet32 (PcdOvmfSecGhcbBase) >> 21) !=3D \ + ((FixedPcdGet32 (PcdOvmfSecGhcbBase) + FixedPcdGet32 (PcdOvmfSecGhc= bSize) - 1) >> 21)) + %error "This implementation inherently depends on PcdOvmfSecGhcbBase n= ot straddling a 2MB boundary" + %endif + %define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Off= set)) %include "Ia32/Flat32ToFlat64.asm" + + %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) + %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) + %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63020): https://edk2.groups.io/g/devel/message/63020 Mute This Topic: https://groups.io/mt/75713139/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63021+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63021+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366633638519.158712252638; Tue, 21 Jul 2020 14:23:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kq3lYY1788612xZ7oJjjIk47; Tue, 21 Jul 2020 14:23:53 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.63]) by mx.groups.io with SMTP id smtpd.web12.5657.1595366632766196578 for ; Tue, 21 Jul 2020 14:23:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OvrTd+70sL5wJPAe3WWdmflJ0B/Ny45EDhPsqhXTKJpA+CAnU+WNv/ll2yvS0GeNneoBrKe3A8kxAiXQ/YP2Cnjn/jPAX6v94q/sADauCJbsAUdh2/SgEiKrk5f26R/4we4y/HzdvREoseEguHLSlXspfnWMrQ5bFBJo1EjpqS38Jbb2nKEk+1O70n+zCCPm4WLH1m0ysH0lE/6C6h8G6hpCK3oC5al7s0F+OcIyQNFVXFqNQjOyUPyKlDD4lJnWMy2WkZW5Qk5SiivAQqX8pWjUUXOakpzqqSqKpJ4/9vVZPe7jnF5KlhdCTP9NaFCtEvayuNl9CMOuixiJotVbMg== 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=JR+MS9LL61uEdrhA9WIjPAHChgJxbHnfKw/wTMqc9/Y=; b=lUhSkYWu1MmrEy84AM1StHR5itgjGOcNR3ah81Llby6nkGMEnH5761I1/B6nWvu2MPOsKDbxqMeaw4obnDOINtWLL9YgtPCl4j1RyCTCvTz/JAPYbcaxd1uGBlIJem0zumQgpBBZon85Ma8UeB2H9nr6VC3X5unlAvyRptskjyGVJR/qNBZHTSbSyzi/FolZOFdZNPcqEHlaQRrSRxSFf87CQHiy9MnBteDtBiKaOpyYHt2zDZgXixWDtYyuwkb4jaNDpko/1HJ2wDRNcRbDoQbHRqCo+So6aDs7j5fK2GXL8wt/Yw87xEJHm68Ph+iVLsxN8i+nyHcrpShN49ByQA== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:51 +0000 X-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:23:50 +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 , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v11 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Tue, 21 Jul 2020 16:19:07 -0500 Message-ID: <9b3188da79b85f740f0f56bdc1c4673dbd252bda.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0003.prod.exchangelabs.com (2603:10b6:804:2::13) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0003.prod.exchangelabs.com (2603:10b6:804:2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:23:49 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8da1f088-68b8-4698-9579-08d82dbc5c7d X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: YL3gAVDApOgpEtM8DzsYZIsFTJ1jZ0UjkiSUN7qISSDC56yiPDK95t2x6J8krdbj+K2mZiU2FR8/1Sdu5V53gyZvWtuiATwMeumLBpLFR0VN8qjK6cpDpA9tGBRXcIKxf5VDSO/5QNR6p0fSAuetLpLkO95A3b8zDh2/Y5ikpzKfgu8E6i028osQCxy11/GDqmV5UJMQfmzZkbjtvRs4pLJLUoGdR//k0TFFU5J7GF5UMDCPNd4/gN4SnZSEoxq/JSqjO8EWpXSWz9JZsR+V+jgmXO7hz27zZ0RwhGVmCoQjSF2czq3hhtDP7uzfw4TknLW1B2hp498FuWAdFuVw3P5RABugMzl+hsYuPc+UXVJOm+zLG8pD7uuT2np/Ltsy2slaI86A0Pr0bocKHLdyW0iaACd7OZueBuRUTpn4byToPvasrDU6PUanKKqvrbRjhDYksaUtadX+LgOWElWdRQ== X-MS-Exchange-AntiSpam-MessageData: jsxhZJhkfjD9+TpkbMCg1l2/8x7GL9cgz777Mag0c0aSMLq01hl7ObRRVmcbHKYvYte1LeeIFBl4fktsuTcaiEUwotklkqYdPdqtlSKXQvlrujd/8/IP/af8mg/btfj6cmKjj/4UBa5kpE7NWBCizNxUFaWnWToU4hnRuiLhQ8JvFbkqCz6nm98xy07qXj2u669V86hSFIEQrUaWMpFXeCjZLJT1yfGzGBKu1ml+cFzgRyuvCHyTFFgKxxSFVFsaHUGlsjhjEFCb8BC28+h++Edx13QgOpnc5aM4QvThiinG0SApNxj9FknN4wNu1TlV8c7MxLixhAzDuC9ccd24pIHu24TLhTIW3l788OF0jCfK1LYOA1iazy5VWbtSxpR/lmq6PLbZXwoa7b8iuCi2+XwUEuO7TiYnTcMu5UvA2Jfc8mehJ3pXwJLBvIfulDxPQD9ooC0/lHlBdrT4CxTMvlFkP4DOZzPeLM+GMwoGNuc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8da1f088-68b8-4698-9579-08d82dbc5c7d 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:23:50.3560 (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: CLEgAHEEWkgO/9EFg9jNKuyfgtESp+SoXjNgteLA3TM0UyvOxvHtOSDfwv1lyk/+u2L4CFRoCa1FFptrJ5m4iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: pqvrAJLJ8NHyrX6ECaHAKf0rx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366633; bh=ms1yuU5aO0p1fXaU7KtoKl3ussBskYqp6E2iyijCf3M=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=gen0CdUSkzF4pYJEe4zzICAqnq+jMw0uYTMTqvRjcHAYRHJiagyWaEfKAidiw+3wG3f EG12EPMT89mcpnlg3l+ZVWigmpnnVTziqlrSdnbSyd+mAm1aJQFFtgWHOQaURDXE5qJJz SiJ53hZ9tEOJWD38WsJCtRnINEXNLrKgHAk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the memory used by an SEV-ES guest when S3 is supported. This includes the page table used to break down the 2MB page that contains the GHCB so that it can be marked un-encrypted, as well as the GHCB area. Regarding the lifecycle of the GHCB-related memory areas: PcdOvmfSecGhcbPageTableBase PcdOvmfSecGhcbBase (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the GHCB-related areas are initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If S3 and SEV-ES are enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS memory allocation HOB, in PEI. If S3 is disabled, then these ranges are not protected. DXE's own page tables are first built while still in PEI (see HandOffToDxeCore() [MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c]). Those tables are located in permanent PEI memory. After CR3 is switched over to them (which occurs before jumping to the DXE core entry point), we don't have to preserve PcdOvmfSecGhcbPageTableBase. PEI switches to GHCB pages in permanent PEI memory and DXE will use these PEI GHCB pages, so we don't have to preserve PcdOvmfSecGhcbBase. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/MemDetect.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 00feb96c9308..a54d10ba90d5 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -75,6 +75,10 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 3b46ea431ade..6b5fee166b5d 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -27,6 +27,7 @@ Module Name: #include #include #include +#include #include #include #include @@ -866,6 +867,28 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), EfiACPIMemoryNVS ); + + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the GHCB-related memory area. This + // includes the extra page table used to break down the 2MB page + // mapping into 4KB page entries where the GHCB resides and the + // GHCB area itself. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBas= e), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize), + EfiACPIMemoryNVS + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), + EfiACPIMemoryNVS + ); + } #endif } =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63021): https://edk2.groups.io/g/devel/message/63021 Mute This Topic: https://groups.io/mt/75713145/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63022+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63022+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366641005719.3899599188974; Tue, 21 Jul 2020 14:24:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id L8gEYY1788612xyMTf53Mzvz; Tue, 21 Jul 2020 14:24:00 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.53]) by mx.groups.io with SMTP id smtpd.web12.5661.1595366640111716569 for ; Tue, 21 Jul 2020 14:24:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G9ioLo6oE+Hp6+SG+5iGjZT4lfLdp4WSWZGpDb2QVdMRKPOMQa3fjSDPoj5cjBXKEn81kEoS5qdLWOQVdIX0MgFOz2uwxC5oMvkVPRubfzWsNJLnMsQFqzsnqEfAhEo3PopuBZJl67YdEahzZ4Y9vxpHhQnUrSONUyWUd3qXh3Ls6zkzrBzHdzL3Xo504pHAAVT8/4S5EguwOF+u4W0G+LK6tEhinVygCzt9WSw8ilXz+WZ1L4t4PBcwULVjeU20yydy94Mw8HUJlOhUEVRl4TKjvRCY5f/yRYX27/CxWYB5IqkEwKOP9j8QUKtLRbxnsjSHmMw6N7YYKzcv5AxKEA== 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=FTwQOqZtSgveKyDVyv5Xn+OjC06eT2L6v4s746V/714=; b=TdMA5Zujbu5BrfqHeBf0cRvnkxFDIEktFbP0RxEH85gRoJlA23A4FSKlcrzAQ2MrphFCtI32z4c4w2MpjPmbCpnl0YILWDA6+Ks/RjZdxm6/an6rgbvixw9xs2nE7qk1zZxm+XQc9D9TLvjY1gVhXrGKitMJw1OmpKBIix1us9e0c1TXcrdvpepNLso6AGj5riD6tu2mK2nDUlSv7//u8jngAoVC7VOaCThgfvnS6RDXrDYKo8uBA58RnTLK4IJ6uvEwjB66XZrftG160GYbgqiVPZuix3UTRguyxw2Tbro9KwyrDg3ix+/SpXdBPCgcVCJeBWPmly6/wUxZZ+4+jw== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:58 +0000 X-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:23:58 +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: [edk2-devel] [PATCH v11 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Date: Tue, 21 Jul 2020 16:19:08 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0007.namprd10.prod.outlook.com (2603:10b6:806:a7::12) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR10CA0007.namprd10.prod.outlook.com (2603:10b6:806:a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Tue, 21 Jul 2020 21:23:57 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 57224c6b-6188-4aca-720e-08d82dbc6171 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 4gJGlEDmOYUhQmhi1OycJa66HmhO8OYTNxQ1XKO9Ufg4HVRZKHI3UtjpHchciKyAHTpanNpCzzCo98nH/jsiKfMVwVyj7c0VW1wqga9zj+0IMb3BVwfu/onMkNBEYrxN/j6fLJa0VdVzUcziM+d/9Q4TsfG5TCjMXhR73U7PW2DPJRrWIzIy+hTAEiE+7BMhNI5bnUAB22MYCZ6cxns7FD2LCsIAOvgZKEqHmSsOIunkMMvBSYJ4FXJwYlsrjXnFs2nFjgUVLy9vxKdvw0Q0sLlLIRZMIS8DAWn1Lc0pYWu6Njd4IiZluRYHgefYVyypOTgYE3bR4rEqj7Gl2Y2ebc9u6KyKqdInD2vSTwS60ksI3r8UgzsO8I0AbSAT0pnv2Z+lSwpxhh42BKwiiSoIf9c1T98xBdY47xwRB2BR+DgfpIO8/zzYTTKT0UAwkXvaQMtPOyXhnqpV8L0TVxuW7Q== X-MS-Exchange-AntiSpam-MessageData: TVPASLT70d1R93zptLRBpzzvtW22Cm64MxZ5nCl5WH9sGuMdIZi7Vyx/XtKJRpcqIDqmsXJpXxv12atE5zJzYjSFcpFKzenanU8va/lXzjmMBIOKRWElzyeKdOXmZEPXAj2XAq+62RtY/dSRs4KY3A6cT+0mWiVsYnGxTwE5h1i/PdK9D29WUVAZ53yQ9wGYBUF99ZDleV+OrsYOmlVmv3+R8paRWoxwaofit3HvA49u3sFmXh9iTfZXjtO4EIhBWWHxAsImA5OWncgEShIIPFIIcgsNrWGgnu/EXSoCxACUuOP1HQGqvm3czRA9vafcHOnHIfxCITBxYjyotbh4ViXJP8pJzSFIOcMH3nowO6r9abWilL4+4AyzYxdTO1913+PHq/H8Vc8mHbUaKVUL0T0RFv/9x8/f/0ARoKjgyqstMRQ7jkSJmBDxwruGjXDxQE0iXOcWVlmgNVl0ZbonbLYxiCRWwolSV6HLvaxih7I= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57224c6b-6188-4aca-720e-08d82dbc6171 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:23:58.6770 (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: S6+XmS9SMa1I0Oj7RYnwUGHPvKAivuDp6EezMSPtkMgFgHyGIoAwK35Iu1jQZH5F1n2SiFSFC4fN7BxFwsE2QQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 8jETcbo9f4t1VDV42ethIOJsx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366640; bh=y/bojv2qiYFBA/Ngr6eHA2xjQoOh0D9iw0f1BsiH+xU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=piJHjQBnE8xhJ30foMC21NCH6yfcnMYvKw9fK7bEwbFtQ4pUBwWEsPHSNFa+bkJdCL1 fZRtIDgnydeRdEY0a5IowL3U2oe1bo8VZcqf2A/fefnXcma3htQoDhXDplN4S9NSiquXE I4lfEUKaEEh9gAxIyv0BngPIkeyUxy9dFHU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Allocate memory for the GHCB pages and the per-CPU variable pages during SEV initialization for use during Pei and Dxe phases. The GHCB page(s) must be shared pages, so clear the encryption mask from the current page table entries. Upon successful allocation, set the GHCB PCDs (PcdGhcbBase and PcdGhcbSize). The per-CPU variable page needs to be unique per AP. Using the page after the GHCB ensures that it is unique per AP. Only the GHCB page is marked as shared, keeping the per-CPU variable page encyrpted. The same logic is used in DXE using CreateIdentityMappingPageTables() before switching to the DXE pagetables. The GHCB pages (one per vCPU) will be used by the PEI and DXE #VC exception handlers. The #VC exception handler will fill in the necessary fields of the GHCB and exit to the hypervisor using the VMGEXIT instruction. The hypervisor then accesses the GHCB associated with the vCPU in order to perform the requested function. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 2 ++ OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/AmdSev.c | 45 ++++++++++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index f84f23f250ef..133a9a93c071 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -608,6 +608,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index a66abccf8266..338c38db29b5 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -620,6 +620,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 2a8975fd3d29..b80710fbdca4 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -618,6 +618,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index a54d10ba90d5..4742e1bdf42b 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -102,6 +102,8 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4dc5340caa7a..4fd4534cabea 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -10,12 +10,15 @@ // The package level header files this module uses // #include +#include #include #include #include +#include #include #include #include +#include #include #include =20 @@ -32,7 +35,10 @@ AmdSevEsInitialize ( VOID ) { - RETURN_STATUS PcdStatus; + VOID *GhcbBase; + PHYSICAL_ADDRESS GhcbBasePa; + UINTN GhcbPageCount, PageCount; + RETURN_STATUS PcdStatus, DecryptStatus; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -40,6 +46,43 @@ AmdSevEsInitialize ( =20 PcdStatus =3D PcdSetBoolS (PcdSevEsIsEnabled, TRUE); ASSERT_RETURN_ERROR (PcdStatus); + + // + // Allocate GHCB and per-CPU variable pages. + // + GhcbPageCount =3D mMaxCpuCount * 2; + GhcbBase =3D AllocatePages (GhcbPageCount); + ASSERT (GhcbBase !=3D NULL); + + GhcbBasePa =3D (PHYSICAL_ADDRESS)(UINTN) GhcbBase; + + // + // Each vCPU gets two consecutive pages, the first is the GHCB and the + // second is the per-CPU variable page. Loop through the allocation and + // only clear the encryption mask for the GHCB pages. + // + for (PageCount =3D 0; PageCount < GhcbPageCount; PageCount +=3D 2) { + DecryptStatus =3D MemEncryptSevClearPageEncMask ( + 0, + GhcbBasePa + EFI_PAGES_TO_SIZE (PageCount), + 1, + TRUE + ); + ASSERT_RETURN_ERROR (DecryptStatus); + } + + ZeroMem (GhcbBase, EFI_PAGES_TO_SIZE (GhcbPageCount)); + + PcdStatus =3D PcdSet64S (PcdGhcbBase, GhcbBasePa); + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus =3D PcdSet64S (PcdGhcbSize, EFI_PAGES_TO_SIZE (GhcbPageCount)); + ASSERT_RETURN_ERROR (PcdStatus); + + DEBUG ((DEBUG_INFO, + "SEV-ES is enabled, %lu GHCB pages allocated starting at 0x%p\n", + (UINT64)GhcbPageCount, GhcbBase)); + + AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); } =20 /** --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63022): https://edk2.groups.io/g/devel/message/63022 Mute This Topic: https://groups.io/mt/75713147/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63023+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63023+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366649756669.2049754839522; Tue, 21 Jul 2020 14:24:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id crrlYY1788612xiLYItlBIPd; Tue, 21 Jul 2020 14:24:09 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.50]) by mx.groups.io with SMTP id smtpd.web11.5565.1595366648927729549 for ; Tue, 21 Jul 2020 14:24:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TdkBfQmhgBfyL4COPN3kE8GxIizN/IVCFXaX1R3yvvnGcZxGFRKXlmrFTcUN7rRW15/x/9WSF46/dDTShcqCK4Bv9pKHwuWiMfJkw5SeRyQxepn7rNy74fpC+9nf7G3zhjt4E5H5v/mGpFJyY9V+b9YRt1/JIVafY1WGrBI1FCQtPWTsuOAyDC5VKTqTtHg6yrBYss3zKqr/IcrFiGgd4EhM7DnayH8JJcCfRnEZ2PIQ5dxV9oQIK0QxLgWpC4qcej0GtihDe+Nh1ftglCNLe9wavWyXXSD/Yvgrurc6ksVO0pIe+tqVSYB7+SZyrFQudzvKvgC+QdacDEPlC39TOA== 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=LKE7+qHjsZIcvRUcMZufAvxligKtvF8CIKEGq/A8VMQ=; b=nGS49fBqKG3mGwSdZRfZtCar0i0NYFegA+mxHG9TsN/GHtRQtXq6R5c6CefcGkBqz1ywtB6YqvyJsCSzFakWBK2MOJHSevlFOAEzf9RM9IKZUjXTWX1fjgX2xWI0pt1qdeIdLbY17QQyQNx/l0LIKOc0gumjkQ0UILa1r1oZNGTPFRIttycZzdtJPV2f3OFOyhyeVBx0EtS20eYojR1Iwunoh0DaTUCFIf66M5OZTFborA4BnH0tk2dzMdaBSf9badBHzNBlPoUswQUo84JMTbJAemFi4ZcszJbOVfkJUQ15wLVwTLOpALZbvLvSuJYqMOWd5ItAkhxi0mVkiWPnCQ== 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 X-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:24:07 +0000 X-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:24:07 +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: [edk2-devel] [PATCH v11 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Tue, 21 Jul 2020 16:19:09 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0021.namprd21.prod.outlook.com (2603:10b6:805:106::31) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR2101CA0021.namprd21.prod.outlook.com (2603:10b6:805:106::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.1 via Frontend Transport; Tue, 21 Jul 2020 21:24:06 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 593da76b-8967-4499-4618-08d82dbc6660 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: HKYcW5qYuKCRcAvt2HOe/CpyAxNvzz1UDKM/YoIERH7BwQjkG8Qroo+wyKfHK+n08+tKAh0N4UI/1Ir6nS9gIIiV42ySAQKDRpdQUuxhdQwKY6O1/L2ZoGWmaxGMGowttTyLcAeSVTh8Gi6t34NRZB5RMZ5v/W2302mm0TKmqaCTkwvJz6IcT/s+DMH4FDZPilk5GI6wFrure/NnOnbENwa9OrkHrSRiVNnT4fJPFvJMW0zuViSPvVdzidfeN1aC2UMV7bFFEMLWw75C6p8FwwhEXfld5FOJwq4aL/kMsY0b4pRiheuoa3p6mdeMivB1KnptdjfhxZ1XSuXVzscuJ02mrO27rc5A+1B0a+y0zccaRmlMETFjfcxYqWjDvOeRSc9ysGe5ph5MYHI0H5t6kD6ssj/ilDP/7YK41xWLShdXYZfK0vyDOXgYVP4mf4R9SUwmGYnu1PuzduEvH3mh0w== X-MS-Exchange-AntiSpam-MessageData: okrBRf1xJtE8Fc3N+SUCmOl70/wv6uU3hxJkV1zbzzs5LyaTfnveF9gZKhEILJmjD43FYcCZWW5uwwMfKkSQFGupnei1y33ksng7qN7YkNwin/QIKnH1h4APn37wMerCTiAnm4bBxnqYRW2vJqk4IM4ENADk8/6BjV8iLJ3GFb4Ws9LIK+ATp7U66msUDhCqe2I0HtQHv5xdNIV5CVDWDUzdlJnELMyS97whl/LC2RRwyGKYEMMG1BQB3drCQ1Ds3znfTwDn0AA+rx9Ib9VpTSjrAqEAEJymJEVOV3G1NwwHEatbRqQ03jai8LbaXm1lzvR6B5ehOfWQxiNHoCSx1bXlty4eUzPDTDz7FFqSYF8UaO0bp/WkraORuuZ55j6B7LuUsfcz43x/cqoU7WgJr+Woohr2DVJ15Fs2vsUHJE/Lkx/pHCuE0W32YcA0Qw7ptLVChHOYIstMNIChakZgVpOp637KyvNCZVDubbrHqi0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 593da76b-8967-4499-4618-08d82dbc6660 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:24:06.9001 (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: C8hhBjCRNuDUVTvnTZO0ZZD3lD2+Krg+l3546tLl+UxQf9Z0fqt+3b6+KFx7T0MVFmuxALAexD07yLqvt5PeJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: NfXcdtIfnejmlUcRRjnxhsvRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366649; bh=YaeAtDCZU45lRsxpEdbBIWEKn3a82q0zI/0HeELdjjo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jPga8Tl1aipAfU1nBrU/CikHGiK3pKfwirKNAuBxsX1e08Rw2DfwW2b8Y5ISH7MliNL AEkrRhYj6UEXi03Y1/HlVRcS6mqpLZBHphp6gXqG5X44bBgMt1wiYgfbBul2oJa9XlXPr JYVfUBN/kpb7KQ0wKAr2GsQxwEVUS9JkAi8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The SEV support will clear the C-bit from non-RAM areas. The early GDT lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT will be read as un-encrypted even though it is encrypted. This will result in a failure to be able to handle the exception. Move the GDT into RAM so it can be accessed without error when running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/AmdSev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4fd4534cabea..a2b38c591236 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -39,6 +39,8 @@ AmdSevEsInitialize ( PHYSICAL_ADDRESS GhcbBasePa; UINTN GhcbPageCount, PageCount; RETURN_STATUS PcdStatus, DecryptStatus; + IA32_DESCRIPTOR Gdtr; + VOID *Gdt; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -83,6 +85,22 @@ AmdSevEsInitialize ( (UINT64)GhcbPageCount, GhcbBase)); =20 AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); + + // + // The SEV support will clear the C-bit from non-RAM areas. The early G= DT + // lives in a non-RAM area, so when an exception occurs (like a #VC) the= GDT + // will be read as un-encrypted even though it was created before the C-= bit + // was cleared (encrypted). This will result in a failure to be able to + // handle the exception. + // + AsmReadGdtr (&Gdtr); + + Gdt =3D AllocatePages (EFI_SIZE_TO_PAGES ((UINTN) Gdtr.Limit + 1)); + ASSERT (Gdt !=3D NULL); + + CopyMem (Gdt, (VOID *) Gdtr.Base, Gdtr.Limit + 1); + Gdtr.Base =3D (UINTN) Gdt; + AsmWriteGdtr (&Gdtr); } =20 /** --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63023): https://edk2.groups.io/g/devel/message/63023 Mute This Topic: https://groups.io/mt/75713151/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63024+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63024+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366657362363.6691085419476; Tue, 21 Jul 2020 14:24:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vZIAYY1788612xUk4UyPonft; Tue, 21 Jul 2020 14:24:17 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.73]) by mx.groups.io with SMTP id smtpd.web11.5567.1595366656563483483 for ; Tue, 21 Jul 2020 14:24:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eIO2BlX0Zzi3vgBQdoYVDYBnup8sAHo0zMj/buEg5eCipMtvMTrtYBRxm9wSdlpX1r3ZoSckGpNT+5Yhw8pkERrI/RFtwe7HnNgLCayqWiAeq7EjKaRKqwlhxA8A2NUYHkkRgb65Qe0ginQxFrxwMfaTlzjnD11/bqI4bf47Y8fccwMmeYVZiUK1qwDKNYqEDJ/SH3XyFIfCx6TVTLPvq8HiIrqkyCWURkbPqsFutE5Yo/kBEqFIbLIiNtxS4FZzBDyeGevQMAyElCRh19j5HM5ioUlyz9QXW7EgzdMlNgrcaQMrJU/e6KzdQmNGRkKFDnIn1EqHlif4VP2DlA5fkw== 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=RmbqkIxYiPPEKoCZtNux7cvM35+H6P1bYXxGk/GrTms=; b=gVwHXxD/PlNz0dN2TCCAW00TYUNeMIrp2u5T0Q2V7Fda9toEIBTBYUwmomUwtrv4YDoeLljwJns1N9kMuubGXiBPFclj9NlFNDmVf6WyCJy3B6Lxoc0nYCq1F2mRCWEsR443nwypoIGymBrdy+v82CqGhGcfquof2yAbR1sUKZ2m7szFVPZqPQZFSeouxq3ZQgVdmnEZah8BMHwLL00Bmjq2o8fCkLiEGLhzLuf+O6E+RoaGInF6IuUnNNqK+enxUyooa/NbcwfUmo/l7EiIjSFjAgc3AaD9gJva2mcSnlW1B5X7w5cOaplMHySms2q9ioRIEymbgGQyeO57UHRxxw== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:24:15 +0000 X-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:24:15 +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: [edk2-devel] [PATCH v11 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD Date: Tue, 21 Jul 2020 16:19:10 -0500 Message-ID: <5564a9591c935d25e3e41d3862424db48a2409b0.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0043.namprd16.prod.outlook.com (2603:10b6:805:ca::20) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR16CA0043.namprd16.prod.outlook.com (2603:10b6:805:ca::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:24:14 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b33050b5-b97b-478f-4924-08d82dbc6b5d X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: REf3ZRanKT4JbVMfn+qp33QW4PWwJPZUzDMDJR149NTkjFm/hmjZP0/LX0FLKLPjSKP6GgFUC83Z1HU/qNAY41aB2yr3AKVfCkBAKQSGd8/Rg4h1vTr3kmYUVOX1ADmxMnl5+FUZ7viFybykcSpt1imtvzafuNT6u4ADM2Z9xQc9PXOBiNPHnlZGQ2DEQXP6XCvoUYswNqzHzOu/QOJU91psZnA2F+AnnbQmLKJFdhN9W5Gz6uJYk+BIj21spHFn132w8lFWPpZTlI7N+UXtasKr3UIfQzcOQ+dHCiQbsD8s740reRM7nyILYWROfb6cmLhF5yxd/Yzhc0sMyf6x2SJSM/Cbrbl+z21XY8jeLb3JhYGp0gf6srUNOu3X7zLra0rdP+sa1SF9dkmwXYFVUBMPv1USf7U26Z39SzHRTErJgxrVFMU03wcDAZb3ncBStkf0SYZcA5ilwjVmAzokMw== X-MS-Exchange-AntiSpam-MessageData: EQfFgTCDwddu0+yqrb3qWk+NSCBBqUlzfUg22c8gdErjruFbvX6GVLtfFAwSq0uojCwLPU+ZjScsM4wBuUkmRjUd+7C31L3D/s2CzIZbKtulsugP0ge3doqHMBByli4DKDhCxOUDhr/bfgiVKi1YiQ0NLWgEHMXijgp5MNMzzZ4MO/iZQS6gd+GOHQTXroVet3RE+YPB7+BnlnCZpBcdd0WbBNEw04vfgio0ufDtQK/PkNP7qv/Sy9F0ldIf4qBtbZwQk0ovSRz7F1Xp8TBu3t0xcmt6KjFhR27JIj3MmCj1EIEcUNutmi6HmxWtf6IiNTHKl6/B7mGn9zqEYq/Vv6OqmFRm1MlQFfAXcWYLt5EvoMnKQcJbgcutDRCUH0IYvynJkWNbKkfcQ7mMaAkhJj6PgSAPmP13KcBc+0AI8SrP8cDQ30mcGJmilh00mUzKbOR18+aYyIaGE38WnmRGb4N5nVKdXLSaW9B3vHVbLUQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b33050b5-b97b-478f-4924-08d82dbc6b5d 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:24:15.3211 (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: YnZWf9IMiBqDEYKVdZ5E5f2tAZXLYRjRNsk0L+gBE1ev7INRD4ucnQnHpgq6YQ+EWZDTD3AA5BSKziEL3uebcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 9CRIRifuvRPG9bna218jh2KFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366657; bh=03CerRl2b4H5k4mIXF2ijVVQcQbvj6W7Sgzt3vtJn4c=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=KYLnjr9S0mVvlsQQh7P8Rr50riDZQVBeK+DS1amWEeZBXUy9HkDHxxzvHhfyezqLSc7 L4wnaTGwG5Z8Offb9MIlSgoaw7zGY04VZyXu5cnddNUQxSSgbjw+bx3ACPwUu7ztX/96r F309y8It1hO9wcPo6Z6ixvMJPRXzXYjCIGI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create an SEV-ES workarea PCD. This PCD will be used for BSP communication during SEC and for AP startup during PEI and DXE phases, the latter is the reason for creating it in the UefiCpuPkg. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 8 ++++++++ UefiCpuPkg/UefiCpuPkg.uni | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index cb92f34b6f55..8c614f9b42bd 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -161,6 +161,14 @@ [PcdsFixedAtBuild] # @Prompt Specify the count of pre allocated SMM MP tokens per chunk. gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk|64|UINT32|0x3000= 2002 =20 + ## Area of memory where the SEV-ES work area block lives. + # @Prompt Configure the SEV-ES work area base + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|0x0|UINT32|0x30002005 + + ## Size of teh area of memory where the SEV-ES work area block lives. + # @Prompt Configure the SEV-ES work area base + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize|0x0|UINT32|0x30002006 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## This value is the CPU Local APIC base address, which aligns the addre= ss on a 4-KByte boundary. # @Prompt Configure base address of CPU Local APIC diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index f4a0c72f6293..219c1963bf08 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -281,3 +281,11 @@ =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT #language = en-US "Specifies whether SEV-ES is enabled" #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP #language = en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise." + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_PROMPT #langua= ge en-US "Specify the address of the SEV-ES work area" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_HELP #langua= ge en-US "Specifies the address of the work area used by an SEV-ES guest." + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_PROMPT #langua= ge en-US "Specify the size of the SEV-ES work area" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_HELP #langua= ge en-US "Specifies the size of the work area used by an SEV-ES guest." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63024): https://edk2.groups.io/g/devel/message/63024 Mute This Topic: https://groups.io/mt/75713153/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63025+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63025+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366665462437.2513797115987; Tue, 21 Jul 2020 14:24:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ueQlYY1788612xcD9k6xA6EO; Tue, 21 Jul 2020 14:24:25 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.80]) by mx.groups.io with SMTP id smtpd.web11.5568.1595366664627080350 for ; Tue, 21 Jul 2020 14:24:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X/4Aso5bHUSSV1fSKpMCKLoH60ixUszXcu61GkpfnmDrSAbhfzs6jYPfdce5pwMPRn3JdbBKMTMmxM7ixjWMc4Z/Cc/R9Wz/MJbb6/dga0LEwP2cEXnfQm8rZrqT2YKor9nt3oLWwP0xX/+3GLjVHrMnqlKzyde4ONNaWC/ArwqBZOidk+6RISg/sD2gBuT0JSgkUTGW6119aS3ZKaUmb4CAn6+QhU59N0502XrNlRzh4dfKYr9wiVMYplULhMZh8n3DHJhtue8w/jUPKMGbgi+iRIzWYdOMQ26K1JGGI8OuerEE9um2Xp6SPclh9oAR+yyo1/jf6xxlBuo4vHwFVA== 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=TjAY63iLn0C9S3DzH549SsJshW3SZE3x2r3RtZTyabw=; b=A33fonBvFg387z9ZbaPeoaZWST9QuJwmByfpBX4fPwnYEdwXGIJX/JLE7kyoLbF6gH2SYDrYpBYpjhYyuotMw0Ogc2fIlzfeSc8lAU4juGS2CNhEtkhKmu4nQKdDIXxTHGYpgw+p8TWH9wPnq3QWynuLWk2L96eYod/TA/doVjNxHVOUT/KBmwHJiBxlsiTlx4xLHI0Yw4RonS3ocVdVJ1QT2/iywu2kHw1ak9DY+Slodjdns0y4ai0I+6GaEbewrEoD5zrve/f078IPWpVcSaUdG5zU5uI+ea6I5DL6gGfQqhJ+xPjwN3Pghz4wGZRte57JuQefu4Btk72qcmaOGQ== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:24:23 +0000 X-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:24:23 +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: [edk2-devel] [PATCH v11 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage Date: Tue, 21 Jul 2020 16:19:11 -0500 Message-ID: <1186671901bb8c6afc94c9d92bb6853c03eb13d1.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0069.namprd12.prod.outlook.com (2603:10b6:0:57::13) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR12CA0069.namprd12.prod.outlook.com (2603:10b6:0:57::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:24:22 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 22724244-6e4d-4eac-f38e-08d82dbc7020 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 3AEvNRy32p1d3RzFEwkIpceGzwp0Yf+NCYJWOfI7bdeBLpJlSfLt+xzQi6UXHnvnVa49VFJwb2/R/UKElewPZhiWy8yPdNOVx4qRtAh8AA5W79HHh2mJwxX0nAvvwbVN53SZ8sqIFY6AJyeOaQukE0oRfJF2X0mG55FIYnQS7WF7A/fyWtRl63J1iU7XRlh5s/RtfELBokDLv4IABFtw29+WCBNfzlgsyb0w5N4UAhoknPoq7XmFpMjaPY365KC+da3BFl9Td8tpqHullBOtTsCGbgHsCoMb4jVfMLllY0GCJWoWpe1Os2sTKOJdc/Rwv56/ONcAANrPQ2LRQXC8UWCtgNIT278+M4IX850KiZXW998wp5k5ZZWG9zHfikZqlU8ti/H02coGZXlXwjztdcGsUKPRlYRpF3VEyNbuH5jBM+o8ujtctaI1Lgz5cON2oWOGDq0Un4UsFedgQvmjuw== X-MS-Exchange-AntiSpam-MessageData: BY7oXBiaZcoNeR5OnNx4J9UvsUhIK5a+mXKioFkV6Tl1Egx8npRsqtp8nlL2rwdqarI55s9gxS0zU/YZ/TpO/sZLyVX6uHBgJzlE/f+FAhLNDd0j4mocXRAaNp+BqBqjRqAnANVMY21o+qo8GMvR0SXKLM9+AbCCHtVMpo+oNIet/6OY4DLdAg11BJTb60WJghYeYXf5YOOiYKlrfzVCMTmAQioVU6J+e2NbZ5YhOO5kEOLdmtliWmdBnxEvfQOtoBPuW6K8zXQ6Q49fZ2HK0uK43/TaZ6mGVeBdai/Az/kalt6yB/dlUv+a1ywro4nx/QuiBHLNLhF3keHHtPRg+L2ozvMx3/2yuv9TC1DmshkUy8DRfxi65wDpzxww6Z3awY7i+yiOI5jWPoyawaHnsAA5QjVjhAaQUQEC+wH9Kk5pK/5MruBDgDARrfCzYoL6RTUtCXs6z56Y2KdXw5Oo0in4ajkmfBRB1epxFQ3CPiE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22724244-6e4d-4eac-f38e-08d82dbc7020 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:24:23.2953 (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: HMvNJZIgI7BQn7Tep9mBm4BclaKWzE2EX588SytiqcHrLVmXVHrV/LcFFPYbnZlsiUn+bcDYQWCP+8nuvFhlgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 8sh0fHolZ8EEWrD14UX36qB0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366665; bh=8u5XMZrg0CBMJYdoMPlCoyp5/2Bl4YU+DtzufpyNbi8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rNTYGi0CnIv4LeQVi1bfaxeBVU+lik5DMob6T39LlOCP92hXiwONBmFEtKN5mM7slY5 N2lqW17x+mpuo3ww6g1Jpek0PquDVfqK8dQCswKLBOgdYLRUSRdB0BvCs2UHalZV+iBW8 wYu9FNELw3bM0/BM2/svmfoAk9ChWrUoM18= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Reserve a fixed area of memory for SEV-ES use and set a fixed PCD, PcdSevEsWorkAreaBase, to this value. This area will be used by SEV-ES support for two purposes: 1. Communicating the SEV-ES status during BSP boot to SEC: Using a byte of memory from the page, the BSP reset vector code can communicate the SEV-ES status to SEC for use before exception handling can be enabled in SEC. After SEC, this field is no longer valid and the standard way of determine if SEV-ES is active should be used. 2. Establishing an area of memory for AP boot support: A hypervisor is not allowed to update an SEV-ES guest's register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead an SEV-ES AP must be re-directed from within the guest to the actual requested staring location as specified in the INIT-SIPI-SIPI sequence. Use this memory for reset vector code that can be programmed to have the AP jump to the desired RIP location after starting the AP. This is required for only the very first AP reset. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgX64.fdf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index edb03b5464d4..8da59037e5f0 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -82,6 +82,9 @@ [FD.MEMFD] 0x009000|0x002000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.P= cdOvmfSecGhcbSize =20 +0x00B000|0x001000 +gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|gUefiCpuPkgTokenSpaceGuid.P= cdSevEsWorkAreaSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63025): https://edk2.groups.io/g/devel/message/63025 Mute This Topic: https://groups.io/mt/75713157/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63026+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63026+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366675599865.2938395601414; Tue, 21 Jul 2020 14:24:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RrJgYY1788612xvXIe7Nwr2Q; Tue, 21 Jul 2020 14:24:35 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.86]) by mx.groups.io with SMTP id smtpd.web11.5574.1595366674495006884 for ; Tue, 21 Jul 2020 14:24:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eSHMa3QoniZnbP2CiNzNDKOlPV9lKnAVGY6fUxVU8QXrHRS0xj3QvGn+Z/HoJktoB9elj6UknYZ2LDcCQvd6ouRcx2jcPQj2NGWzVGpzqIhMlzOTRybR9m93g5dxAleYV60MkyFbnNYddNV9EQKUNpqHgdmsU4jBU5broxWs13tkB+/0SIY8dzwbEMkesBKh+w+moKQEMPmTvM1PNCk+3ownku2Xd5kkBJpMugsK2k2JfCBd+Fs2MfnTJK8MM0kE/Csr/AV4V7ncon+aDh2hK6lXqhFTUkFW0lKYAvTesQEC9Clm136VGGLGitUrF10Wbq9NJtj2FRc6I+yQnBkILQ== 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=JkyhLOofvIbow8VdM+XsfKiaUSck6a3v3S8jdpNjfQo=; b=ZGRaNLIr8V3IyulV52Hv4vy7P+QNy4vWFmC/BcMhKYkZ64SMPkOcqePM7T9zkv6/3ywmGoe/ii50FhODAm39vBJ36JHf6TcwmuU42oG+sKuKpF9lFl4N4CiefnDgcsHvuTmFOt4BmCdao1gviEHHhRweGV7EU6GSAtsYHE4pDZ+JvCpEit/rp0+4+dm6djcpfaexzELIPAkTdmuWutCaT3KBnBMuLb60+DV1hwD43NmxAmwhDNK9wnzZsteldQ1jzZH21lFLxzCY6tY3AnpYi6W8oTb5dZdstoNlEYB1Xxu/5QS661eWk0zKDt4C7BRTOo31h3uhJ9ibPahuM0fwzA== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:24:31 +0000 X-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:24: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 , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v11 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Tue, 21 Jul 2020 16:19:12 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR18CA0084.namprd18.prod.outlook.com (2603:10b6:3:3::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR18CA0084.namprd18.prod.outlook.com (2603:10b6:3:3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.19 via Frontend Transport; Tue, 21 Jul 2020 21:24:30 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0d949c5e-2d5a-40a1-93da-08d82dbc7503 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: MntlnjeYPDjZ8uj9Zol63ZkH2RSIBuCjktBsP/6yiIfWnjd34HhW23eP2vFnqWzXG48pd2yO6u5fMt7pp6f+Ak62KMULoNACkovrcM1KHVIFCS91ASI1LV5iDPX9jRNv290vb820VXvxqkXxfio36TCTcWkIWmGiiolY0xGnpbMk9RJ60EC6Kw85YEkICqcqhiANC/mO7xM1A2jPlU7Z2OxNj1Y5QD335Cn2m86DN7YKG2hwrsm8PzfdvsUXR1D3xHbAa21VeYaePKNj6itRPmQ6GqKZH5XLeYYlep3Hoc9yE5koo7ZOIhttAOLXOnq9mMBDdyYpJ5zrXgt8aj8pTFOIEMTjVqRAP6DkC/7vqDcMHl/NFtQgLPbpA1vKspGGUzXBWr2ylwnR3zzH5j7sknqGMMK8KHc60uFaY3msThczdsUTR68F29pqJy7KDND5qSNF0eGuiXjtO9nJTL5dww== X-MS-Exchange-AntiSpam-MessageData: AbvpX0mEZCDMzVrU2F5zYxvVbltPW6EaBYqwNZhoWyPQQcU+qFONB5B9jyD/nZ0/ZQ2zCmMCVwgdg9ykkRVlO/tVhSPr0BStRklKxAbKSnPl20hR50ss1NI1QOGd3KTPAaGsqFAaOdSTkV4LMlhtagPpF/sZSgMO5BgxlEPEYLTox7AVhj6YTuJczSpXFF+hBTvod0C6T9Wutk5lQeALyqEOdlDypsdtexMCA33dDi9imH9HhmjxXg/wMiSySAFAAZmpZPmm3D7eHI840KBxMYYP+mr1a2/TpaNrf2CeMZzZiFdziIcvlpzCX5vpMRtEaYT9V6BV5dxX9B2s/8XkUNiA/KJlFOJtXVAsCLdKLdP6vqZOaNMMA3reUALHVI13YRQEn537KQ1AzhpQGvJgmEo8aiAItHcl5D7o3+Iv+TKPtFQ7E/crZXg9niRnfY00n91Kjzh0/7u1W8UHzKDd1BO1xZcWNzQZcyeADojtvss= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d949c5e-2d5a-40a1-93da-08d82dbc7503 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:24:31.5124 (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: d4KncCYig1gQlz6DwvdCWcXSqrJbFHFePLx+PW3Yh4IwAOd9FNEjDv58ldv7sfKjaFeB+j6iMCS3lehqBhdDpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: v7CHZhb4M8bLtQAL5EDzcXySx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366675; bh=JOsGw2S4L9QAPhDyzMWOXPwuEzLI7xQOF2QOCn0RMoE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tuP7nGze1B39IbDnQRO2tpXGPR3BWXygxv6LBUJSl4bxBtRPLY5jrb3WxUFqr6NUzBx BlQb9K+v5zOyJl2ovZqiVKxyc7pKxV5hjwpJBKwOWrEq9+XUQUpMFCYA6wEZUw9OAog8j 6mIytQFnmJmoFdQsWRlpiV1RIQbimbc6qOA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the SEV-ES work area memory used by an SEV-ES guest. Regarding the lifecycle of the SEV-ES memory area: PcdSevEsWorkArea (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the SEV-ES area is initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If SEV-ES is enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with either an AcpiNVS (S3 enabled) or BootServicesData (S3 disabled) memory allocation HOB, in PEI. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/MemDetect.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 4742e1bdf42b..c53be2f4925c 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -118,6 +118,8 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 6b5fee166b5d..ffbbef891a11 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -940,5 +940,25 @@ InitializeRamRegions ( ); } } + +#ifdef MDE_CPU_X64 + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the SEV-ES work area. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + // If S3 is unsupported, then various drivers might still write to t= he + // work area. We ought to prevent DXE from serving allocation reques= ts + // such that they would overlap the work area. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase), + (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize), + mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData + ); + } +#endif } } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63026): https://edk2.groups.io/g/devel/message/63026 Mute This Topic: https://groups.io/mt/75713162/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63027+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63027+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366682188914.3872579007739; Tue, 21 Jul 2020 14:24:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0UkPYY1788612xy11kCUC5kD; Tue, 21 Jul 2020 14:24:41 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.44]) by mx.groups.io with SMTP id smtpd.web10.5715.1595366681145320138 for ; Tue, 21 Jul 2020 14:24:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jbH1SJFrgWM1caTdywQdX08WFpCxhhbT6j/nmfdhilp0OZT28mcPzmMSTVBMyuQwEfzyMcVKCHgPCV1OGN34miKIWZrMHP/98Re3j0/aePPXUGf3Wotl6Gf9wPZ2BqWaFjjyBsIEPZR41PtMPfh1Dqch7WnBh9OQS+E5PUDQ5MHlG6jBpHayxt9tMmH7jgKNXplY/n3f41sMw68PMqlJpPwXJILf7jj4uyfP3mj3+OrOxagLjEXUYbjwd+Zvx9d4ThgYo1Altn7ofoAarL5+/wa3aHrily6S5yo4G0JXCib0xLZYHycM8JBw0a+JKZs/gUOMVBAC3p1EZORpGpPxvw== 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=TPNpIjuNhjb8J+fWbM5hVjQ7IHF8lsFxPXU/EZJhZFw=; b=XHqvNPzlpnOSsh7idONoq+05FBjV++au/bgUXzzom03k4oehgfmF3aIoBUqk4XywmjpEgPjaJnTWB45ZmP9hLRSiDNBjX4fWuA+4aPzOIdpDCYzWqdP3G6UvoVWdhy+3rQSgakCBklG5NF2flFA4PCNlNL7ghCpGHg4CRTmmQRYOEQTBa7TEIL/mhPDN9OCL+uzTKhx+TIak5sBw6kqSy/IA2fik4QsxgMPwRLLZ9obHsxer4r7MwDpxqgYT9D+XWYjOW88P5HMDY//nfb4GjN6zCtcTUGp4cszjTahTMjlEAuyfxj1k45E+31/VW/ySIAKXue5I2D+voCheLocROQ== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:24:39 +0000 X-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:24:39 +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: [edk2-devel] [PATCH v11 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Date: Tue, 21 Jul 2020 16:19:13 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM3PR11CA0014.namprd11.prod.outlook.com (2603:10b6:0:54::24) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR11CA0014.namprd11.prod.outlook.com (2603:10b6:0:54::24) 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:24:38 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 343ff920-750c-48bb-7af9-08d82dbc79c6 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 5eXMv0Etpe/YiNLteaktFXRFvz3692CW39p7YzrwHejr1mUnnAx8YhhI8fGc0PdrDkkMFac+0DaVbvOYxuR8ANCXh1mv2p8tqAQ4CNoOSMQl3Ok8naIjR0MiHrVoq+8mH979sKhQI7q3HtkXwSwrtKjCoDF4aiIqVFE/QZoMNJ/mUH8BwgQRVF2dWPG929e/89Mlq+mixY+7nfa1BQvJ77Cuzb/C+xqRzoUdN3xyKwcKpvlmigobgeZL+QJXq3jLoQAOGOTK7KON/retLr8TZIZghYM9DOf9PUAygV5jVhKNAzWnTZd9nw+oX9qX7+a4OhwZupFTznNPpvlIvJmMb/QcEgEkEfhQoNPHDWoIfFwbHNNTdH1LWbuZzir0ex4vbPkel58aV1J8s4wT2wgCBdrDx0Eue8ANilJdpaWAErEHcsvZbjBCshvoBX7ueEzEdI0NZMLnhoS2Relb/oQQmA== X-MS-Exchange-AntiSpam-MessageData: WzgW9/ngUoilQuJ9JaBzfs2Li3H4+GnAPyAYLBPySXmPQwjMJ4UnG0AIAA9zkDtUVBo3eOC21htNq7gletn0/+yw8ew80ocrk4iZgzNjnza0mLZUX/eYFuYA7Jy1d1e962yEPTTv3riPmaGKwx2kzjOKyJGmsuH0290xcKTmCchlj4ES3NR68KRX6l1vWFs5V79vxc4KjMVXWAaMZ55vhai7iStMYhs+8B+pUwV/QGSAajuyRF2r59cxkIYvneOiczbl+irHVZ7q/Xp/aoTO/6DxfZPjC0kxq5mvZGpk/uwAdZZkm5z9vM0MVIxQWCgfraZb0OYBRkk97gZl9eBgVHbhBa0T/o4/229v55b70czjjVzXBW5sQ6H80aEdaOHMuWvnDxUcncGHCZ0Hq6erRjrOyt+tzetlboX80C6THRSPYszmGb4zZ6zsm2Z7zYrFM3JDyMyAjBEJxfBjKoGwu1wisejQvWw8sIE9eUajnR8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 343ff920-750c-48bb-7af9-08d82dbc79c6 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:24:39.6655 (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: VJ4WEmSVAxlGujPRM0XhI/ojH+myDEX+stTsH97rCAftOFUpft8J74imQeqxGA4tsanYQsM81VWJ28CY+8rwZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: iiL76P6qwKaQgLZYIirwGozcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366681; bh=cB7tcZ8RkB8wXp2yYPYlSTYqbcC5kwQG/OLB7HIygso=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wwvjEkYTuEWCLbTSdhUvdjgiefTTTNDhf+dvKCjYgnTwLkoGTQyPI5cPvesGTDOWhd4 7x0EEbxKjo++xoPvpdJUaM/flHxR3VVgpOW80Q3n2ShuxylV2q5U3+1/aWVOLb3t24zjL QNcDIqw4myUw43JqlJmKMT3fVtZDUYFswLI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 During BSP startup, the reset vector code will issue a CPUID instruction while in 32-bit mode. When running as an SEV-ES guest, this will trigger a #VC exception. Add exception handling support to the early reset vector code to catch these exceptions. Also, since the guest is in 32-bit mode at this point, writes to the GHCB will be encrypted and thus not able to be read by the hypervisor, so use the GHCB CPUID request/response protocol to obtain the requested CPUID function values and provide these to the guest. The exception handling support is active during the SEV check and uses the OVMF temporary RAM space for a stack. After the SEV check is complete, the exception handling support is removed and the stack pointer cleared. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/ResetVector.inf | 3 + OvmfPkg/ResetVector/Ia32/PageTables64.asm | 275 +++++++++++++++++++++- OvmfPkg/ResetVector/ResetVector.nasmb | 2 + 3 files changed, 277 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 483fd90fe785..a53ae6c194ae 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -34,9 +34,12 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index 9f86ddf6f08f..7c72128a84d6 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -36,13 +36,58 @@ BITS 32 PAGE_READ_WRITE + \ PAGE_PRESENT) =20 +; +; SEV-ES #VC exception handler support +; +; #VC handler local variable locations +; +%define VC_CPUID_RESULT_EAX 0 +%define VC_CPUID_RESULT_EBX 4 +%define VC_CPUID_RESULT_ECX 8 +%define VC_CPUID_RESULT_EDX 12 +%define VC_GHCB_MSR_EDX 16 +%define VC_GHCB_MSR_EAX 20 +%define VC_CPUID_REQUEST_REGISTER 24 +%define VC_CPUID_FUNCTION 28 + +; #VC handler total local variable size +; +%define VC_VARIABLE_SIZE 32 + +; #VC handler GHCB CPUID request/response protocol values +; +%define GHCB_CPUID_REQUEST 4 +%define GHCB_CPUID_RESPONSE 5 +%define GHCB_CPUID_REGISTER_SHIFT 30 +%define CPUID_INSN_LEN 2 + + ; Check if Secure Encrypted Virtualization (SEV) feature is enabled ; -; If SEV is enabled then EAX will be at least 32 +; Modified: EAX, EBX, ECX, EDX, ESP +; +; If SEV is enabled then EAX will be at least 32. ; If SEV is disabled then EAX will be zero. ; CheckSevFeature: + ; Set the first byte of the workarea to zero to communicate to the SEC + ; phase that SEV-ES is not enabled. If SEV-ES is enabled, the CPUID + ; instruction will trigger a #VC exception where the first byte of the + ; workarea will be set to one. + mov byte[SEV_ES_WORK_AREA], 0 + + ; + ; Set up exception handlers to check for SEV-ES + ; Load temporary RAM stack based on PCDs (see SevEsIdtVmmComm for + ; stack usage) + ; Establish exception handlers + ; + mov esp, SEV_ES_VC_TOP_OF_STACK + mov eax, ADDR_OF(Idtr) + lidt [cs:eax] + ; Check if we have a valid (0x8000_001F) CPUID leaf + ; CPUID raises a #VC exception if running as an SEV-ES guest mov eax, 0x80000000 cpuid =20 @@ -53,8 +98,8 @@ CheckSevFeature: jl NoSev =20 ; Check for memory encryption feature: - ; CPUID Fn8000_001F[EAX] - Bit 1 - ; + ; CPUID Fn8000_001F[EAX] - Bit 1 + ; CPUID raises a #VC exception if running as an SEV-ES guest mov eax, 0x8000001f cpuid bt eax, 1 @@ -78,6 +123,15 @@ NoSev: xor eax, eax =20 SevExit: + ; + ; Clear exception handlers and stack + ; + push eax + mov eax, ADDR_OF(IdtrClear) + lidt [cs:eax] + pop eax + mov esp, 0 + OneTimeCallRet CheckSevFeature =20 ; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure @@ -222,3 +276,218 @@ SetCr3: mov cr3, eax =20 OneTimeCallRet SetCr3ForPageTables64 + +; +; Start of #VC exception handling routines +; + +SevEsIdtNotCpuid: + ; + ; Use VMGEXIT to request termination. + ; 1 - #VC was not for CPUID + ; + mov eax, 1 + jmp SevEsIdtTerminate + +SevEsIdtNoCpuidResponse: + ; + ; Use VMGEXIT to request termination. + ; 2 - GHCB_CPUID_RESPONSE not received + ; + mov eax, 2 + +SevEsIdtTerminate: + ; + ; Use VMGEXIT to request termination. At this point the reason code is + ; located in EAX, so shift it left 16 bits to the proper location. + ; + ; EAX[11:0] =3D> 0x100 - request termination + ; EAX[15:12] =3D> 0x1 - OVMF + ; EAX[23:16] =3D> 0xXX - REASON CODE + ; + shl eax, 16 + or eax, 0x1100 + xor edx, edx + mov ecx, 0xc0010130 + wrmsr + ; + ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-b= it + ; mode, so work around this by temporarily switching to 64-bit mode. + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; We shouldn't come back from the VMGEXIT, but if we do, just loop. + ; +SevEsIdtHlt: + hlt + jmp SevEsIdtHlt + iret + + ; + ; Total stack usage for the #VC handler is 44 bytes: + ; - 12 bytes for the exception IRET (after popping error code) + ; - 32 bytes for the local variables. + ; +SevEsIdtVmmComm: + ; + ; If we're here, then we are an SEV-ES guest and this + ; was triggered by a CPUID instruction + ; + ; Set the first byte of the workarea to one to communicate to the SEC + ; phase that SEV-ES is enabled. + mov byte[SEV_ES_WORK_AREA], 1 + + pop ecx ; Error code + cmp ecx, 0x72 ; Be sure it was CPUID + jne SevEsIdtNotCpuid + + ; Set up local variable room on the stack + ; CPUID function : + 28 + ; CPUID request register : + 24 + ; GHCB MSR (EAX) : + 20 + ; GHCB MSR (EDX) : + 16 + ; CPUID result (EDX) : + 12 + ; CPUID result (ECX) : + 8 + ; CPUID result (EBX) : + 4 + ; CPUID result (EAX) : + 0 + sub esp, VC_VARIABLE_SIZE + + ; Save the CPUID function being requested + mov [esp + VC_CPUID_FUNCTION], eax + + ; The GHCB CPUID protocol uses the following mapping to request + ; a specific register: + ; 0 =3D> EAX, 1 =3D> EBX, 2 =3D> ECX, 3 =3D> EDX + ; + ; Set EAX as the first register to request. This will also be used as a + ; loop variable to request all register values (EAX to EDX). + xor eax, eax + mov [esp + VC_CPUID_REQUEST_REGISTER], eax + + ; Save current GHCB MSR value + mov ecx, 0xc0010130 + rdmsr + mov [esp + VC_GHCB_MSR_EAX], eax + mov [esp + VC_GHCB_MSR_EDX], edx + +NextReg: + ; + ; Setup GHCB MSR + ; GHCB_MSR[63:32] =3D CPUID function + ; GHCB_MSR[31:30] =3D CPUID register + ; GHCB_MSR[11:0] =3D CPUID request protocol + ; + mov eax, [esp + VC_CPUID_REQUEST_REGISTER] + cmp eax, 4 + jge VmmDone + + shl eax, GHCB_CPUID_REGISTER_SHIFT + or eax, GHCB_CPUID_REQUEST + mov edx, [esp + VC_CPUID_FUNCTION] + mov ecx, 0xc0010130 + wrmsr + + ; + ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-b= it + ; mode, so work around this by temporarily switching to 64-bit mode. + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; Read GHCB MSR + ; GHCB_MSR[63:32] =3D CPUID register value + ; GHCB_MSR[31:30] =3D CPUID register + ; GHCB_MSR[11:0] =3D CPUID response protocol + ; + mov ecx, 0xc0010130 + rdmsr + mov ecx, eax + and ecx, 0xfff + cmp ecx, GHCB_CPUID_RESPONSE + jne SevEsIdtNoCpuidResponse + + ; Save returned value + shr eax, GHCB_CPUID_REGISTER_SHIFT + mov [esp + eax * 4], edx + + ; Next register + inc word [esp + VC_CPUID_REQUEST_REGISTER] + + jmp NextReg + +VmmDone: + ; + ; At this point we have all CPUID register values. Restore the GHCB MS= R, + ; set the return register values and return. + ; + mov eax, [esp + VC_GHCB_MSR_EAX] + mov edx, [esp + VC_GHCB_MSR_EDX] + mov ecx, 0xc0010130 + wrmsr + + mov eax, [esp + VC_CPUID_RESULT_EAX] + mov ebx, [esp + VC_CPUID_RESULT_EBX] + mov ecx, [esp + VC_CPUID_RESULT_ECX] + mov edx, [esp + VC_CPUID_RESULT_EDX] + + add esp, VC_VARIABLE_SIZE + + ; Update the EIP value to skip over the now handled CPUID instruction + ; (the CPUID instruction has a length of 2) + add word [esp], CPUID_INSN_LEN + iret + +ALIGN 2 + +Idtr: + dw IDT_END - IDT_BASE - 1 ; Limit + dd ADDR_OF(IDT_BASE) ; Base + +IdtrClear: + dw 0 ; Limit + dd 0 ; Base + +ALIGN 16 + +; +; The Interrupt Descriptor Table (IDT) +; This will be used to determine if SEV-ES is enabled. Upon execution +; of the CPUID instruction, a VMM Communication Exception will occur. +; This will tell us if SEV-ES is enabled. We can use the current value +; of the GHCB MSR to determine the SEV attributes. +; +IDT_BASE: +; +; Vectors 0 - 28 (No handlers) +; +%rep 29 + dw 0 ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw 0 ; Offset high bits 31..16 +%endrep +; +; Vector 29 (VMM Communication Exception) +; + dw (ADDR_OF(SevEsIdtVmmComm) & 0xffff) ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw (ADDR_OF(SevEsIdtVmmComm) >> 16) ; Offset high bits 31..16 +; +; Vectors 30 - 31 (No handlers) +; +%rep 2 + dw 0 ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw 0 ; Offset high bits 31..16 +%endrep +IDT_END: diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index bfb77e439105..762661115d50 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -72,6 +72,8 @@ %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) + %define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase)) + %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63027): https://edk2.groups.io/g/devel/message/63027 Mute This Topic: https://groups.io/mt/75713167/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63028+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63028+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366691470836.6470744601643; Tue, 21 Jul 2020 14:24:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2WhAYY1788612xWmmQ5JPZVp; Tue, 21 Jul 2020 14:24:51 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.55]) by mx.groups.io with SMTP id smtpd.web11.5581.1595366690476028978 for ; Tue, 21 Jul 2020 14:24:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KqvuqgXqcrCCG6keoTbRD0shMtrWrXj2qIhjSj/HXfabc/+LKjH5DYiZvJK0MlpFgfOLEBXOJwDzEHZ0V4KFBMlvfKVIRg/rwKi17QeMmhlDmFoeW6I64qS6uPoWBchbiwkWUvM1R0+OJ5lMLQofr2FgltPxh61Xsk6u27QVw7BYyC+DMdq9jxpNfr8/FAY8lxGS2GOfCAMq2bW5EJtDghjlRyqolVa56MvCmLMl2Oxzn0Tb0hSvRnoR841eL8dVc088xi67hDspuvn/pA2FB8oD+DebLsgVUKOxAmOQbbgkb8REQGbONaMusT8uMR5IbGxkghoHgFGe6aiveaCNGQ== 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=S26Dux0cwurzGpks92C9p7rCgsyx41XUiYYP5lYQTJU=; b=hupT/597N1dmO3ihMbsAp+gJkeVvMyXYRPl/PEBKA9mK/e1n2tDyN5OZe7aBTdoUXoNeDbcjRCdZwJDwvl2xBOl+LFk+bo7aE6Adud+zMlybupmWwrbZjRtAVGpihxTJU7NvxD/Xj9gyLINwIt3Dq2kDSA0nF3E1b7Oormx8iywF9GQKnaXTIq9TTyH6gt19EmDIPdrl98lCHerTZQ5lS/X2vkcR1oKN0PVanD/lOCzLaoEtqfAssZlXjUbJK/etq91KX+i/Xb9qU6haxUrDOvy32pCDKcn+Mj8iiHW689ohDK7K7x7UdAVIkd8uRuKDWPw3mQUc74WM90/8BSOkbg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:24:47 +0000 X-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:24:47 +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: [edk2-devel] [PATCH v11 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase Date: Tue, 21 Jul 2020 16:19:14 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR16CA0012.namprd16.prod.outlook.com (2603:10b6:3:c0::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR16CA0012.namprd16.prod.outlook.com (2603:10b6:3:c0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:24:46 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: addf2e9a-0710-4cfa-95e5-08d82dbc7e8c X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: r+QcZvF+S2psddyfxXFHcInHHHUQ9zmh86QCpC38gZsESGGaUbBQE64zp8IXhKRNQQ3Woqw8houAFKUuaoXs8IjFwnWSk5t3+Hqu9fyiQkFO7Q3TQ0lhjNwKl5anTWfBzJBFplc9m1Gx3aPifOivfGmi21NwR72I5tnGiGrlAl7Gp9G3g26fD2nqO8l4TWatblSBKLfQvCY2F0N76t5g+BI8E57eaT1PAiQjOrDvcDhlfdo5JgKvkD/J0l2k5D+v3ID0v7gEa1AtgPHDIDtzRsERTJE8YtQa3kLUuPB/fvWPz/HXTdW+bud6N6dqZ5OmkYzOiNWg6DNF2KotNoFcvk0mY1Jpt5963Zc2Nkob9LMddBso6Ivq+Uhmfk8D0KIE6oDRmLTRS/tO2BZZqUYVXHh/4BDcEUMl6ihD5wlDYCCH3KbTzo8PJ4vXtsZhwYCoI9atWdGbkBYGjFJ+c5Yrqg== X-MS-Exchange-AntiSpam-MessageData: dq6kPiDpHrdb4GSm4woslL7hBabOoIWCW68qZv8KT2QJ9S5pAJ3/cVwaUObkEO4o8je9eNHQdGLyzWXGGruT6ItnMkGMp9E1mXD0rNRtvTR1ZbrjAOEQ+cr9mEDzMRgXIxAbHRax/8whWTQk6JZq5AsylBLEcFJJkLYm9NJRhZxx/6Y0yl8zVxsh7yzl/zx7oYOS0BfiSeHyYEtB+aIWM66KeBymZcCyE0LUBNhq6MMwFJFIlzG2yxvCd7jvBFghpYJ1iaQ8fkZNMMzy+8e2wdeoC0PhrP7PfZkl4SA3xY2IyHIC2D2+jd/Nqqb8hlFfm/KBmNu5qBg9xNpKJMpmxcXZ5adTJoZkutE4hV1NjXjUDjfSiVWzpoEr7h28Q2b7qnHpRRpDoYipP0i2mHrMDY+WYKDge68vh+8BuMKxGa/un76Hu6Q6VQY+OyZRKVI8reDIL2VUpS2K1QYxkdxylLafpncRdMYLHp6Ar0QIc/c= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: addf2e9a-0710-4cfa-95e5-08d82dbc7e8c 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:24:47.5148 (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: nCjqgsje76qbIlw0cl/6H0rJbuQlS+Ev/SW+bKca9aUS5kmkDbAXNgIURch6PHJqaLvAXjKWYBSfQkfJPcDoUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: ltkb3HBE99O1xtymHw3mrj0lx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366691; bh=4HDuMFPTnrQzT5zTgzulXHafWKJzU77COCudo6IhqsE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ctzn60xbzRFMSaKUAMnpcIgYe8fXxOLDzETbAGOU4qFE32X32pZp/DcpmNLBhhhZY9P nBScuob0nv8vGFlIoWQ59TZR6A8vsTcuPe/ioTAApYXEvC8ILh0xaoO19Kqs2cRueTTkp /zuIx+2JOho0q/BnQaxLiWxPsV+CJNUvwjA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 An SEV-ES guest will generate a #VC exception when it encounters a non-automatic exit (NAE) event. It is expected that the #VC exception handler will communicate with the hypervisor using the GHCB to handle the NAE event. NAE events can occur during the Sec phase, so initialize exception handling early in the OVMF Sec support. Before establishing the exception handling, validate that the supported version of the SEV-ES protocol in OVMF is supported by the hypervisor. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.inf | 4 + OvmfPkg/Sec/SecMain.c | 181 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 172 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 63ba4cb555fb..7f78dcee2772 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -50,15 +50,19 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + CpuExceptionHandlerLib =20 [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 6dea6e771a29..c2a35463dce4 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include =20 #include =20 @@ -34,6 +37,10 @@ typedef struct _SEC_IDT_TABLE { IA32_IDT_GATE_DESCRIPTOR IdtTable[SEC_IDT_ENTRY_COUNT]; } SEC_IDT_TABLE; =20 +typedef struct _SEC_SEV_ES_WORK_AREA { + UINT8 SevEsEnabled; +} SEC_SEV_ES_WORK_AREA; + VOID EFIAPI SecStartupPhase2 ( @@ -712,6 +719,120 @@ FindAndReportEntryPoints ( return; } =20 +/** + Handle an SEV-ES/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest + wishes to be terminated. + + @param[in] ReasonCode Reason code to provide to the hypervisor for the + termination request. + +**/ +STATIC +VOID +SevEsProtocolFailure ( + IN UINT8 ReasonCode + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request termination by the hypervisor + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; + Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; + Msr.GhcbTerminate.ReasonCode =3D ReasonCode; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + Validate the SEV-ES/GHCB protocol level. + + Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor + and the guest intersect. If they don't intersect, request termination. + +**/ +STATIC +VOID +SevEsProtocolCheck ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + // + // Use the GHCB MSR Protocol to obtain the GHCB SEV-ES Information for + // protocol checking + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbInfo.Function =3D GHCB_INFO_SEV_INFO_GET; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + if (Msr.GhcbInfo.Function !=3D GHCB_INFO_SEV_INFO) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMa= x) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) || + (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + // + // SEV-ES protocol checking succeeded, set the initial GHCB address + // + Msr.GhcbPhysicalAddress =3D FixedPcdGet32 (PcdOvmfSecGhcbBase); + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + Ghcb =3D Msr.Ghcb; + SetMem (Ghcb, sizeof (*Ghcb), 0); + + // + // Set the version to the maximum that can be supported + // + Ghcb->ProtocolVersion =3D MIN (Msr.GhcbProtocol.SevEsProtocolMax, GHCB_V= ERSION_MAX); + Ghcb->GhcbUsage =3D GHCB_STANDARD_USAGE; +} + +/** + Determine if SEV-ES is active. + + During early booting, SEV-ES support code will set a flag to indicate th= at + SEV-ES is enabled. Return the value of this flag as an indicator that SE= V-ES + is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled + +**/ +STATIC +BOOLEAN +SevEsIsEnabled ( + VOID + ) +{ + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAr= eaBase); + + return ((SevEsWorkArea !=3D NULL) && (SevEsWorkArea->SevEsEnabled !=3D 0= )); +} + VOID EFIAPI SecCoreStartupWithStack ( @@ -737,8 +858,55 @@ SecCoreStartupWithStack ( Table[Index] =3D 0; } =20 + // + // Initialize IDT - Since this is before library constructors are called, + // we use a loop rather than CopyMem. + // + IdtTableInStack.PeiService =3D NULL; + for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { + UINT8 *Src, *Dst; + UINTN Byte; + + Src =3D (UINT8 *) &mIdtEntryTemplate; + Dst =3D (UINT8 *) &IdtTableInStack.IdtTable[Index]; + for (Byte =3D 0; Byte < sizeof (mIdtEntryTemplate); Byte++) { + Dst[Byte] =3D Src[Byte]; + } + } + + IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; + IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); + + if (SevEsIsEnabled ()) { + SevEsProtocolCheck (); + + // + // For SEV-ES guests, the exception handler is needed before calling + // ProcessLibraryConstructorList() because some of the library constru= ctors + // perform some functions that result in #VC exceptions being generate= d. + // + // Due to this code executing before library constructors, *all* libra= ry + // API calls are theoretically interface contract violations. However, + // because this is SEC (executing in flash), those constructors cannot + // write variables with static storage duration anyway. Furthermore, o= nly + // a small, restricted set of APIs, such as AsmWriteIdtr() and + // InitializeCpuExceptionHandlers(), are called, where we require that= the + // underlying library not require constructors to have been invoked and + // that the library instance not trigger any #VC exceptions. + // + AsmWriteIdtr (&IdtDescriptor); + InitializeCpuExceptionHandlers (NULL); + } + ProcessLibraryConstructorList (NULL, NULL); =20 + if (!SevEsIsEnabled ()) { + // + // For non SEV-ES guests, just load the IDTR. + // + AsmWriteIdtr (&IdtDescriptor); + } + DEBUG ((DEBUG_INFO, "SecCoreStartupWithStack(0x%x, 0x%x)\n", (UINT32)(UINTN)BootFv, @@ -751,19 +919,6 @@ SecCoreStartupWithStack ( // InitializeFloatingPointUnits (); =20 - // - // Initialize IDT - // - IdtTableInStack.PeiService =3D NULL; - for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { - CopyMem (&IdtTableInStack.IdtTable[Index], &mIdtEntryTemplate, sizeof = (mIdtEntryTemplate)); - } - - IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; - IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); - - AsmWriteIdtr (&IdtDescriptor); - #if defined (MDE_CPU_X64) // // ASSERT that the Page Tables were set by the reset vector code to --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63028): https://edk2.groups.io/g/devel/message/63028 Mute This Topic: https://groups.io/mt/75713168/1787277 Mute #vc: https://groups.io/g/edk2/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63029+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63029+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366698538111.62265824012127; Tue, 21 Jul 2020 14:24:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aY0eYY1788612xJ0SLBlIMxu; Tue, 21 Jul 2020 14:24:58 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.65]) by mx.groups.io with SMTP id smtpd.web12.5687.1595366697631290938 for ; Tue, 21 Jul 2020 14:24:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y9LY0kBqyBPXwjBjhODPR4JScO4tiKvnuAoXhAybVkkXEJUvl+Ktz3LmnMcwpnVIKtuGy416tByoAEf93rfgAG1cBf2wIcZlp2LpFjHbb858zpRYEWND8mByrqnPXug8KomBjpUpWN6USECuod+aQiF3M4ffb2P4faxi4/lL7TYF51iAnc4wdeJ2SzQgx1UQx6onECLPrlgm4K9/kVf9J/TBD/9MmHpu4XeSnp106G3pn6ZRtdCpkGFckXPoH7S5cv16pntFfU+XIYbpEkw9p7nzI9ro3giIJwlAO9DnuMfhbtCVmBMSxIKBKMTVFtLfJF3hks539scvsma408SIow== 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=3E0ymlPSxNH6aH1t6SQyGEJdjjI6yseFWWKhpBgBa7E=; b=mHSlSaiUStg2E/hrz0yXfru5WvhsEtMbQ1N+4hI/ds4hsPoz0dfrossHmIppmRgqvSLVIXObkKRmeRHhO2zMWKe6ZSkNeekzHKGx4pd++Ik/R45tbKKkXu8Lygksuuq+CDY5otJf5mueXzB6kC3YO0Gv7rmGG5zOIWXejSaXYeLignup3N01scHOWqv81RfG0OkSIYEmEix7X5Fcnzz88Sh/znkAMAHqxYzWgNoykyCk/WxMeXra11NiTYLqy1LfmxAoZMr83iV5y3oRR6r+UTZed1bX/5twBq6qgA0NeqeEb05em1qdVpLJ0fo0SX4IcxgImiJ7OP+E/8aaMtIxrA== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:24:56 +0000 X-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:24:56 +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: [edk2-devel] [PATCH v11 38/46] OvmfPkg/Sec: Enable cache early to speed up booting Date: Tue, 21 Jul 2020 16:19:15 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0161.namprd07.prod.outlook.com (2603:10b6:3:ee::27) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0161.namprd07.prod.outlook.com (2603:10b6:3:ee::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:24:55 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3d934da5-5b61-4409-faca-08d82dbc83ac X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 1t5lNyA3yoQRFFkMFl9LiJaBZfHr9QS6CpvTsAQJt+igYwhQR3r3MeBYQXc8UtMbLJwNkwxpJoPFqRWTelHsDro/nejZi+VvP/1+QWsyspDv9JzYya8AfBZ9q9MgIjVEED2Mq/01B2U2O+La6TLbAphIsi7qat0wLPcEwS6fBtMZnSh/AmXrOmF5Xe3L26qd2E1zDF+OLcY6BXk4hJ+SA58p2EZ6pKr52hNkc5+59jDn7WpIYZ+0OHjIs5bl1rq0jWGs7NKP/RWg2VyOuNPF4TIYIF3djn+KVk+2J9ayaACWe7bMSxBOaOzE1AHl40qBZzSBATg8QupTrOFn7ZPkQdvHUVEnmACnT1d/27gSZHULLiSqjMCnWkKbohuC7kN7UmUjRP7V/0FhTDz2ApC4l63Iv81idsGLdm1bzSVAcDPczYbOIOoauGcZbmEDlJEq3WqmIGq/CnW+w8N1Jr8dhA== X-MS-Exchange-AntiSpam-MessageData: TObFyhqek3C1VwTjoWYIAPW55p2+LZavFgXpslsIc+f9bQO4JIPvAbnVPGrO7+qmXh4Xd1atLHjZxT/IG5qkfcP6unRzR88G/dBk4DxTmiAMPeqceTpIxqj2NAhDpliakmtLzsd/yJtuIGh5Z5HzcTYXOr1rMInz/OB+/ZwRpCESFZzB89gno6hsdjFNRH/5YcgG3r/GGHVDVYMVdqOoRRHHYc/RP/hGkZR/7ZMgw+Kg8aGjmjqxpDjDCKKI0KnRZwNAQlCloDr+tlXKpmq5p+jB3i6PH0kGGEy6l8jWXDWQTFszzZKNXiAd+AHGNmEQsk1RzH7HnYAtOihzjKjLa8FSDU6XWkcMq+ZeTeS5YYdez/5Yfl4QsR/9DU9Pot+XTCs8lPCyIWlgQKH0+LkuUhnSfe6ztp6D47iImmyi1I9ReinqgnnZwmp2glWUhodUk6SXDD45a/sVcXF2B/E0DU9pI0t/UOnE82Jwsbe/PcA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d934da5-5b61-4409-faca-08d82dbc83ac 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:24:56.1287 (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: 0qMgaMOizJHtxZA/pnb2yq1rro2kNiCY5R8N5dpaJ+f9FdW/x70qZfGQLdC2c4AQKRs6BeLgQZy1jh/sgiwzsg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: D7It4kvyI0OwgeTfBbGnRVm0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366698; bh=IPX65sBoEcit7YTXAPNrBrE82bZZSOIz+d8oh6UxVWs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=vv2H5gsD0fZz/syIXSg7Zfsi0YaNh53Vh80vEwt89Q1VkY2L6ho4/JfWUR/W+no86Yj nUPM3Np0wyT2AyiyclfrE+WXPD+pNvN+MJlsfMN7dq9MOYOImQFVEDhN6KMNrL9uxZWtG x6lPJc52ofuLWl5xqZs3kxC6gUbZmR6IBu4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Currently, the OVMF code relies on the hypervisor to enable the cache support on the processor in order to improve the boot speed. However, with SEV-ES, the hypervisor is not allowed to change the CR0 register to enable caching. Update the OVMF Sec support to enable caching in order to improve the boot speed when running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index c2a35463dce4..271a06348ed8 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -905,6 +905,13 @@ SecCoreStartupWithStack ( // For non SEV-ES guests, just load the IDTR. // AsmWriteIdtr (&IdtDescriptor); + } else { + // + // Under SEV-ES, the hypervisor can't modify CR0 and so can't enable + // caching in order to speed up the boot. Enable caching early for + // an SEV-ES guest. + // + AsmEnableCache (); } =20 DEBUG ((DEBUG_INFO, --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63029): https://edk2.groups.io/g/devel/message/63029 Mute This Topic: https://groups.io/mt/75713169/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63030+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63030+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595366707465984.6641811777836; Tue, 21 Jul 2020 14:25:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ESs0YY1788612xjJLoYkYc3L; Tue, 21 Jul 2020 14:25:07 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.46]) by mx.groups.io with SMTP id smtpd.web12.5690.1595366705903455232 for ; Tue, 21 Jul 2020 14:25:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=az0ll7zSigesbpQiZ+q0gu+BJ2160s2r/iNnd6kp4YoqheCG2jFLxcogFf2Mut6dINav/CQfaAT3M78yWXraaLeyZou3shFjphCP5hKdhG+DIARcpJnxWF+rfzRhX4r9aTZ48HDObb0yTprFXrK6quARxmCbu0wHgGFdjsjclraKpC2gwyFpP/KgukjELR8oOLiR+bdiExAFi3Yb1b750PBkbJT22/o7YosOzOeihxMbePYuLDuVrb5I9RYQZcK9Ea3uW44uFjOiopuQgV7mjcs9NL7CbJre2WRhN4BWNvKFX1vAJyyGR9vp7kcPYIzSl4I5/OjN/HMgFv99WCCslQ== 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=9SL7ZuvVbtegSaUIJvRjeIedgAr9HaaB2JEMJds61HY=; b=Z04Oa6DfDs1pYM5Rv6JK716m90XaMmuAsb37RnwAXVyw9ie0e65Z7pjtRyqJ46AfQQUdPXGEOtZPqPZaYLX2MWFmOu5qfK1da/HRFgE9JFk9Ly73ys29/JvMtg/kIcEuqzLXQWVcELqdIqX//5wYRNfeprydmzlORHVsDDNwVgH9wM3WPgasNoZeVKwPV7N4e1Cwdvel9aVzDTnxA09YgAJ6JmQF4Y7PENOuawS9hqIWlNbJCvz3+8atVbqkT6NHZgTp6dR1jZn5suuR+e6SKZIGkueb7eWXHLa7qyJ/EBWK2by7b3WvWDhlDQAoDgUmkdR7a2eUGTKSIHlMrjZHcg== 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 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:25:04 +0000 X-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:25:04 +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: [edk2-devel] [PATCH v11 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES Date: Tue, 21 Jul 2020 16:19:16 -0500 Message-ID: <1feb7f85599f50a791c39acfd6119a8e25a36703.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR05CA0001.namprd05.prod.outlook.com (2603:10b6:3:d4::11) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR05CA0001.namprd05.prod.outlook.com (2603:10b6:3:d4::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.17 via Frontend Transport; Tue, 21 Jul 2020 21:25:03 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 575bb502-198c-40e3-0f8d-08d82dbc8899 X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: MY7Ghrxrf9TKqlg9ijzhS4MGWG50lGQjuZJsk7lspSk2zdLp2gU2kUZ+t1qdS7l8mVzxFnQKOq9hiBDu9lLqfpa/yFmEyMe2O6GCVTAJhJ23pEnPzrPwTtpbFalInQkZ4vpxa/LgNji6LEC8H6sQqetQPmJiRenO1prBin4XKfWRMLFn8yiu0GxDMO5hT3A5Lf8WHvId0jE7OiiA5MgdIf4Iio4IF19zaNSxegGzUbuD2QWojHb/efte/Cpgdb9FD29Vy7AAS3PAHyfANsqASWEABh0JjWCRNb1u4Gl8rXNBrAvTMgpv4zYdU1KS5MmM/m8Os5RKa6R9NDyA5qI4R00I08GEDuiLU9xQZKuIyrv8GIOfD2bsCLbI4WWcU6pfuF3+ZaFRgAphSgTrsnjC4OkfgDZ7qFVj8YKgrAkle/pfcx8XS8I5C5k+0BCxLF0mo80QQc56HwFRj/Gs4rp05MupPGw4ypMa3WSA9kRlrpamarQ/zG/93Ole9K1fZ4YZ X-MS-Exchange-AntiSpam-MessageData: t94EdCtlGu2M+pV7iiK5Sr86Gd/X9+l7Y+a5y5G8ju2fTSy8pN/nV3VhIhwIaeApvimGurm53x3aw8N4OI2rwkEk61ntxA6g9FOM5KJ6npiXSYpPL51YuNK7U+Gw/0DLjkwwVzrwZqWDdX6yibGZmDigRp4u1Q8ucalbi+Fr6DH8RRfSzkXbzQwks6vzN6C11Lxim5OqjMkc4/PjtHpWTVAIePpeGkVRD0SU2ZveAE3FwfflKSPzI8lFOwsZqqMmVdvzEWDxhO4dKjQqFmBhXKvwZMcIOKHSQM7SK4pJp58UFcZPcnI9Bxn0GCCB+8RWWqnicLuDjEAdy/Y/B3LqXSiPulnmNcl9jrb6hgY2X8cG8wp2BWEygKKlDXT+179TDaV7+6etPEHiizZV8qxxMboGdyfay58iwGFClgmJdpvnoch+zpBaWqfUTASigtcxT9vc73eiymsPrKY61mJ/spwUox2HkfrXAmws3h9UqSA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 575bb502-198c-40e3-0f8d-08d82dbc8899 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:25:04.4477 (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: zFjbHchMMkDh2cV+nLVRkQw5RWcIBxCq+3X9FDK4pBf+4unIqo0Ol4efv19uSBmptUl9EzV/zwSFRBXABlr2jw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: gydbnkSYupmiriV4oDMc3u5qx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595366707; bh=NAv00EZwtTLlC2peri4KjB86RqbPUrqww7Gty2s0/NE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=TYGpMbze/MGnlv84aTkqQ2GWVD7wDiu5+30XtKKv0DWgN2Szzx2Yt6m334Y/yr6jjik bDNJWEJTWQzMsNqtPklY1VXFvtdKzmU7WKa3AaisCxfMqrwiNl3tsUFJvEQj05lB7+xc+ HJgpPSXUWA6K3JOLyuvYLS5rr9a+HdbkST4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The flash detection routine will attempt to determine how the flash device behaves (e.g. ROM, RAM, Flash). But when SEV-ES is enabled and the flash device behaves as a ROM device (meaning it is marked read-only by the hypervisor), this check may result in an infinite nested page fault because of the attempted write. Since the instruction cannot be emulated when SEV-ES is enabled, the RIP is never advanced, resulting in repeated nested page faults. When SEV-ES is enabled, exit the flash detection early and assume that the FD behaves as Flash. This will result in QemuFlashWrite() being called to store EFI variables, which will also result in an infinite nested page fault when the write is performed. In this case, update QemuFlashWrite() to use the VMGEXIT MMIO write support to have the hypervisor perform the write without having to emulate the instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../FvbServicesRuntimeDxe.inf | 2 + .../QemuFlash.h | 13 ++++++ .../QemuFlash.c | 23 +++++++++-- .../QemuFlashDxe.c | 40 +++++++++++++++++++ .../QemuFlashSmm.c | 16 ++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.i= nf b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf index 72cabba4357d..8bb2325157ea 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf @@ -38,6 +38,7 @@ [Sources] [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] @@ -52,6 +53,7 @@ [LibraryClasses] UefiBootServicesTableLib UefiDriverEntryPoint UefiRuntimeLib + VmgExitLib =20 [Guids] gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h b/OvmfPkg/Q= emuFlashFvbServicesRuntimeDxe/QemuFlash.h index f1afabcbe6ae..219d0d6e83cf 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h @@ -89,5 +89,18 @@ QemuFlashBeforeProbe ( IN UINTN FdBlockCount ); =20 +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ); + #endif =20 diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/Q= emuFlashFvbServicesRuntimeDxe/QemuFlash.c index 1b0d6c053f1a..0d29bf701aca 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c @@ -9,6 +9,7 @@ =20 #include #include +#include #include =20 #include "QemuFlash.h" @@ -80,6 +81,21 @@ QemuFlashDetected ( =20 DEBUG ((DEBUG_INFO, "QEMU Flash: Attempting flash detection at %p\n", Pt= r)); =20 + if (MemEncryptSevEsIsEnabled ()) { + // + // When SEV-ES is enabled, the check below can result in an infinite + // loop with respect to a nested page fault. When the memslot is mapped + // read-only, the nested page table entry is read-only. The check below + // will cause a nested page fault that cannot be emulated, causing + // the instruction to retried over and over. For SEV-ES, acknowledge t= hat + // the FD appears as ROM and not as FLASH, but report FLASH anyway bec= ause + // FLASH behavior can be simulated using VMGEXIT. + // + DEBUG ((DEBUG_INFO, + "QEMU Flash: SEV-ES enabled, assuming FD behaves as FLASH\n")); + return TRUE; + } + OriginalUint8 =3D *Ptr; *Ptr =3D CLEAR_STATUS_CMD; ProbeUint8 =3D *Ptr; @@ -181,8 +197,9 @@ QemuFlashWrite ( // Ptr =3D QemuFlashPtr (Lba, Offset); for (Loop =3D 0; Loop < *NumBytes; Loop++) { - *Ptr =3D WRITE_BYTE_CMD; - *Ptr =3D Buffer[Loop]; + QemuFlashPtrWrite (Ptr, WRITE_BYTE_CMD); + QemuFlashPtrWrite (Ptr, Buffer[Loop]); + Ptr++; } =20 @@ -190,7 +207,7 @@ QemuFlashWrite ( // Restore flash to read mode // if (*NumBytes > 0) { - *(Ptr - 1) =3D READ_ARRAY_CMD; + QemuFlashPtrWrite (Ptr - 1, READ_ARRAY_CMD); } =20 return EFI_SUCCESS; diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c index 5aabe9d7b59c..565383ee26d2 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c @@ -10,6 +10,9 @@ **/ =20 #include +#include +#include +#include =20 #include "QemuFlash.h" =20 @@ -32,3 +35,40 @@ QemuFlashBeforeProbe ( // Do nothing // } + +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ) +{ + if (MemEncryptSevEsIsEnabled ()) { + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + // + // Writing to flash is emulated by the hypervisor through the use of w= rite + // protection. This won't work for an SEV-ES guest because the write w= on't + // be recognized as a true MMIO write, which would result in the requi= red + // #VC exception. Instead, use the the VMGEXIT MMIO write support dire= ctly + // to perform the update. + // + VmgInit (Ghcb); + Ghcb->SharedBuffer[0] =3D Value; + Ghcb->SaveArea.SwScratch =3D (UINT64) (UINTN) Ghcb->SharedBuffer; + VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1); + VmgDone (Ghcb); + } else { + *Ptr =3D Value; + } +} diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c index 7eb426e03855..7eb80bfeffae 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c @@ -46,3 +46,19 @@ QemuFlashBeforeProbe ( ); ASSERT_EFI_ERROR (Status); } + +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ) +{ + *Ptr =3D Value; +} --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63030): https://edk2.groups.io/g/devel/message/63030 Mute This Topic: https://groups.io/mt/75713178/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63055+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63055+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595390763867734.1426298061034; Tue, 21 Jul 2020 21:06:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Zi7cYY1788612xhMWvieep3z; Tue, 21 Jul 2020 21:06:03 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.64]) by mx.groups.io with SMTP id smtpd.web11.11817.1595390762495615758 for ; Tue, 21 Jul 2020 21:06:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UnWv6zisUPF403WBTUS86bukJ0QxcL2bpOXSBXoCZkn1nXco6ESiSiMgs36lWBBYQizK31y7x97E0UjfyUL3mxxM6L2/MHxeQ9Ja6qjs9BXOp55czwKu6RyraiUeJr9vZfCkilMP0J1TjQ3EfioaZvC+PWAA3FVmTv7RaLaVyyY94UW60CLmBiiwFW+/vVtLAc+XPp9+bNhrnh34LBDuLjfEGXNSfTHD65YuIRe46/1wYTP45aD6qJXlW4zVpzl2hVUIo8y5uXsD917GnBl7FqVsVi7pBaYOUZQTThUyfJOp+FRqvSW6sR/LgPwDg64nzsqYM8bglHloRfJNXibO9w== 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=y42cNfhmfyz07xseYeQYH9zbpfMlzMLWf83yCfosPcg=; b=cAI47V/7OpQ784k2xQXe6xEIASxr0XL06CLQSLv0EMh/nN4kpKYiwx6laD9yMNvsqQJbIIlujFoeoktCt9fnYxXGQ2QJ1ZVHTpX6G/8qks/E40Gqrc9KfKZLiDrGRa/qyqMJJfq1gCz+FQ5OOy6cOjNxKWDmFzrjdBc4t7SdEWw0PHGOps4ph30QsiJ/IqU5Rph4eO8S0LEUb3NyMYGIEW+D3dZyV5Rg6f1iGU7rCTr0AEeF8JXWtokOW9HXMI1+LTmZW+fXPPvWd2TjYCd77sVmtG8K7RpCGpIS9rLb2T8mYCcT2oGtlEGDBAGYtBHg2vrGt1vVKbNypqiKugLh7Q== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB2827.namprd12.prod.outlook.com (2603:10b6:5:7f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18; Wed, 22 Jul 2020 04:06:01 +0000 X-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.021; Wed, 22 Jul 2020 04:06:01 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Tue, 21 Jul 2020 23:05:44 -0500 Message-ID: <805cc06d70f87d1744af7b64ac7a7c69d3faf747.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0014.namprd05.prod.outlook.com (2603:10b6:803:40::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0014.namprd05.prod.outlook.com (2603:10b6:803:40::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.16 via Frontend Transport; Wed, 22 Jul 2020 04:06:00 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b46605a2-f4bc-4c9b-2a80-08d82df48b66 X-MS-TrafficTypeDiagnostic: DM6PR12MB2827: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: LnHqZgFiLO6EUyVjXIw2cmQmmNzjqtoHfo9x1wnbEXXs1X3IboQnRQSlPs64MM8wR1l0yWo8p8LEXhbgsNbDDHFLBFnA0zqtD1Zca5muqGmbFApuSBNlu1QcB/eTJuF4E/rP1radzmxzMYQUv6S4mfgKn16GDTyj4+4Nhlx8L1U6NBW5OX/srdUAfsq4BCameUKKFkX09LxyuAnBnHfDAJXRmlZxiwywodzGrgCX/RK31dtiBH49FDJSxios5Pfe10cTAEpXrSv4fL0Mlyr0cGbgXS3TjEDwtIt5W2B6Jjt1P3t6UHU2yErA01+wlJVnIAgaxAmLJaaI9OkIq+QKlCeT5pqOThb34JzyBqzVlC8p0wkUe9MhEBvUE4GPHnAa9aSz8ErCqWh/8C/arHblTsZqlBDReTKuD025AW6Qh9G0MeAkMwxbefC3yKkwTEyNFL0YJzTs0/NZv+NQ6BVLUQ== X-MS-Exchange-AntiSpam-MessageData: skYeZ/+lk9lZNZEmPI5wZrWKEgwO3uuc55TEFptM0I40unA5bYATrQS3QpAvFBnwv1le55XqDk6QqOCaxTc8N59RHuuxnnbja7ltX9PINdnqbfooeXlo3r27CVNQbt1fUrN4VTQW42mtMHJT4PTADxxD/xk/ESkc+Q7p47zzBBO6VjtpGuhea3CN9kw0mZWo/z46lYN6pIqBqK7k/zMo/Z9TVejxD8APH/nLoYOPXoOmOGz//Ld0ae8I9Quvm44CS9mZQm+m2NPCcGizEuqK6gR6Kf7Qh2J4VevC5iUXSMWOZhFx0PMQ6TZdMYGgNnZcJR6HqiYRKhlVW3NBcsNhZvyhsu/LdfkMy27cApQHV4UDvJSI3uroQY1c6DIPvUgjxk52iuH5e/G8HMSU5bT3yUcJXjRj9BcyPPuiZfomKqezeClO/VVvUq5IEqBira7ZiFHYorHAVoOBCyD8xPAZcXqkPugvJMLmCqEiC0dJAMM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b46605a2-f4bc-4c9b-2a80-08d82df48b66 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:01.0082 (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: GNYw1IdTVHRq7JA4UGwenb4RGMt8B14X54bkWtHRMGVwgctQ66VzTZN644H+vugVfISLGImtJqfDJh8+o8SlwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2827 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: JVCYllF3B5ADNsoUm2iNyosxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390763; bh=RoEH25n2+ssgQLdwaCWNfb20T5Py93FScdL4BizqpgE=; h=Content-Type:Date:From:Reply-To:Subject:To; b=f/rLXJw0r+Zq3tRGSJsvsY7sLb0Efn9C5gpCp2x/wnOz/pcKUgljePdCFjvDZLugDWD NOKA1KuGg0T0E8JE18izuZ1HxisqnGHauC47LTCJIiw0UHiqRegwAvB65MOpetXETgWAU pNWMTRqLDEhfVOHkzOTGP3pV5Hl2l8Cbj9g= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A hypervisor is not allowed to update an SEV-ES guests register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead, an SEV-ES AP must be transition from 64-bit long mode to 16-bit real mode in response to an INIT-SIPI-SIPI sequence. This requires a 16-bit code segment descriptor. For PEI, create this descriptor in the reset vector GDT table. For DXE, create this descriptor from the newly reserved entry at location 0x28. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/CpuDxe/CpuGdt.h | 4 ++-- UefiCpuPkg/CpuDxe/CpuGdt.c | 8 ++++---- UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/CpuGdt.h index 3a0210b2f172..1c94487cbee8 100644 --- a/UefiCpuPkg/CpuDxe/CpuGdt.h +++ b/UefiCpuPkg/CpuDxe/CpuGdt.h @@ -36,7 +36,7 @@ struct _GDT_ENTRIES { GDT_ENTRY LinearCode; GDT_ENTRY SysData; GDT_ENTRY SysCode; - GDT_ENTRY Spare4; + GDT_ENTRY SysCode16; GDT_ENTRY LinearData64; GDT_ENTRY LinearCode64; GDT_ENTRY Spare5; @@ -49,7 +49,7 @@ struct _GDT_ENTRIES { #define LINEAR_CODE_SEL OFFSET_OF (GDT_ENTRIES, LinearCode) #define SYS_DATA_SEL OFFSET_OF (GDT_ENTRIES, SysData) #define SYS_CODE_SEL OFFSET_OF (GDT_ENTRIES, SysCode) -#define SPARE4_SEL OFFSET_OF (GDT_ENTRIES, Spare4) +#define SYS_CODE16_SEL OFFSET_OF (GDT_ENTRIES, SysCode16) #define LINEAR_DATA64_SEL OFFSET_OF (GDT_ENTRIES, LinearData64) #define LINEAR_CODE64_SEL OFFSET_OF (GDT_ENTRIES, LinearCode64) #define SPARE5_SEL OFFSET_OF (GDT_ENTRIES, Spare5) diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c index 64efadeba601..a1ab543f2da5 100644 --- a/UefiCpuPkg/CpuDxe/CpuGdt.c +++ b/UefiCpuPkg/CpuDxe/CpuGdt.c @@ -70,14 +70,14 @@ STATIC GDT_ENTRIES GdtTemplate =3D { 0x0, }, // - // SPARE4_SEL + // SYS_CODE16_SEL // { - 0x0, // limit 15:0 + 0x0FFFF, // limit 15:0 0x0, // base 15:0 0x0, // base 23:16 - 0x0, // type - 0x0, // limit 19:16, flags + 0x09A, // present, ring 0, code, execute/read + 0x08F, // page-granular, 16-bit 0x0, // base 31:24 }, // diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm b/UefiCpuP= kg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm index ce4ebfffb688..0e79a3984b16 100644 --- a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm +++ b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm @@ -129,5 +129,14 @@ LINEAR_CODE64_SEL equ $-GDT_BASE DB 0 ; base 31:24 %endif =20 +; linear code segment descriptor +LINEAR_CODE16_SEL equ $-GDT_BASE + DW 0xffff ; limit 15:0 + DW 0 ; base 15:0 + DB 0 ; base 23:16 + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE) + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIM= IT(0xf) + DB 0 ; base 31:24 + GDT_END: =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63055): https://edk2.groups.io/g/devel/message/63055 Mute This Topic: https://groups.io/mt/75718561/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63056+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63056+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159539077203681.310230076155; Tue, 21 Jul 2020 21:06:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id exD8YY1788612xpeGLykzRFM; Tue, 21 Jul 2020 21:06:11 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.76]) by mx.groups.io with SMTP id smtpd.web11.11820.1595390771099770677 for ; Tue, 21 Jul 2020 21:06:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cRIyLVu21Xh7z52p1P6w0FAv43WEdZNoJphtOB3tcCCBJ4EYvE2IjggOx4RBNsOGjP/LZgxMY/lXYYNygj3pJM9WsnvW//LAydpowF2ejsCuoyRsbJLAgVPsqHZ6L7JDaOMik9g2FWH6k5Z1iHs7zX8xuNw6BaF/5lpYjbYS5knbf5G8Yo5BFnU3L3bH916Wd/cHIWPCVSz5DEschgEnqQmnpsgdgXb1r0t84NArpALCoX5c+gXPKyzzD5ps6jkcNvFXUi+pMiLQJ7l6PLRM8C+03gjRGmi0s4A4vNIV9+Xf+4cutFPB8xiPY3oX0ac4vWiyllZq2stXcp4jk8rzyg== 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=2xL2RAVEP5XW/LxYrRr+kHwaYvf60goYc3Dt2uOHhXI=; b=c28OFY15DFboTaBYuVM84fOygKq8F2iMUyrsujGtOsA98oAMjI7zUUyPxlmZMfzQuipnahnAU1i4t+YbM9hZ34X5i1gmIoisjy55mxX9SBiEoUYeYiFuk8OYTATZn9QfJlqx2ZpnRKIDqzaMpBLlz+BXQNzu9eXeiPTjSkm0NxKu79w/hFYk7uX1t0koUWYME0KtpPhW96PFDDqS+OSS1Mnb6baxrqNxdZid5o4J/iRG3dc571XV8eOX9S/zipHYLJM07AcTriSP9NRcXuiOTNPrQoRS9xlSBxo1d8wD7CAGfNUBId99E+2gRamnko9I8KL5+Cgnqox7/ddYQfrt3g== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.24; Wed, 22 Jul 2020 04:06:09 +0000 X-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.021; Wed, 22 Jul 2020 04:06:09 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled Date: Tue, 21 Jul 2020 23:05:45 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0071.namprd02.prod.outlook.com (2603:10b6:803:20::33) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0071.namprd02.prod.outlook.com (2603:10b6:803:20::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.19 via Frontend Transport; Wed, 22 Jul 2020 04:06:08 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f173a82b-9c80-49af-7d06-08d82df49018 X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: pXkLsnarBA+mD30kPaUfwsAbnxMA0t2iZh/9BV7kV5dgrwra8vhEYHGLuKHrAIrS2eIY1NZgN/yQ8wYIG9NKVjtiA8gy7Voxz9o4l9NsVJm99ao66OG61c5rB7xLWnyS98ko4AYOabEYHNJetWHh6U3sYKO+WmppgkZYva9iJinTacPALc4GsN5vSKrH3w+KnkKydwUcToACD5IADLxEImnmuBrm3SKy5ul0+P11RkPO9n4rciPDwLHthYSM2Ji6f8n0Cxiv3pqpqJ3/f32Oa2K/VEzzKXzgBPyuxIMLza8aAphF35GWi+3fGvKBOhC1K2xEQyA9rEPnhTfNaCz5lvSk4KTOF5SQFPV8FElw0xjEShV9kKEaoppIhkF5Q89q57vng3tJnWq+9CBj4d2h42xgUcxo0DdnjJftqBKFd/Z/q098S68v55QssXc4foEHG3H9BcOzvBqHKd6LAf5q7A== X-MS-Exchange-AntiSpam-MessageData: RqzC5BjyMN/h6iqun9RQSgwe8soIX2CHxHsuWR2S36ZGQUkOOTSXvqgKdvvZlbmiqU3cSRk5KPf1kPn7DMKhwYdAuQ3zPdMc1YiU+RstQLr9RUXz45S6gD+iOtKJTKkFGtK08Zr8i1CThovxRvlZ8iv0M4rpvRB2E7ZrmY1MJpBeFvNhfwcXpWYKt1dM7VbR27m3C5LhYWajKY+AMwdBN3DnACDHGqbDFAtlbE5iGMvpeSQ7zjYV+/qvtrf2Lxti2uCoYSNv9ZB2YoRe4TKJM6VY10Dm3OcvFTRx/zB7U2ogL8EqPygRNB98SJoB1uWVCbcbnsZfG/Zl7ifgpGR++H0vgIHycuiCeZxz7SFQgPaNBxenP8JWy49BHVMx9FS5iNwUvsoueFXhJ3J91vUz7tIOV2SD2XbwhKtxciAKYOKAYJ83ydYR2jeGNpFudGMTNPtZCBug4lqIu6nA3BUwRSGms5+jrlFzAgWu1STHDk0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f173a82b-9c80-49af-7d06-08d82df49018 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:08.8937 (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: Dl7eJmUsj36pmxJoltx6dvREjtIm0Gwig4DrW/1m7gbmMQLCe3z2IasYinfJdWLGNaTvk8GMDLmXrcRjF3U1sA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: DDnXvBbxA638wH8cjzaMrsQwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390771; bh=5bsz0j9sZhWDQ4tN5E5aBmirOHiJ/vRnBUdnMhcfkCA=; h=Content-Type:Date:From:Reply-To:Subject:To; b=nbeJh9OuHUaD1kRCyIedyqIpGXv3e2G95ani2hiCc2oNqWEh3j8PdWmqHWlgMmbV6vM m87/HFw5tSquHFb7Vl4LTCZrrbVSu0QKxAHpjXJAxfJv63InYln6LE90FtHEKAE8iA9JL 9aucx3Axw5p43a9xA6XPJl2QE3kJDXLk6Nc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 When starting APs in an SMP configuration, the AP needs to know if it is running as an SEV-ES guest in order to assign a GHCB page. Add a field to the CPU_MP_DATA structure that will indicate if SEV-ES is enabled. This new field is set during MP library initialization with the PCD value PcdSevEsIsEnabled. This flag can then be used to determine if SEV-ES is enabled. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 ++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 1 + 4 files changed, 5 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 9907f4157b09..583276595619 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -71,4 +71,5 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 89ee9a79d8c5..4b3d39fbf36c 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -61,6 +61,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index a8ca03efb8e3..5b46c295b6b2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -276,6 +276,8 @@ struct _CPU_MP_DATA { // driver. // BOOLEAN WakeUpByInitSipiSipi; + + BOOLEAN SevEsIsEnabled; }; =20 extern EFI_GUID mCpuInitMpLibHobGuid; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9b0660a5d4ea..2a3fbeef35f7 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1704,6 +1704,7 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *) (CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); + CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); =20 // // Make sure no memory usage outside of the allocated buffer. --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63056): https://edk2.groups.io/g/devel/message/63056 Mute This Topic: https://groups.io/mt/75718563/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63057+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63057+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595390779646582.219639109195; Tue, 21 Jul 2020 21:06:19 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sxnGYY1788612xhVh7qrX54t; Tue, 21 Jul 2020 21:06:19 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.73]) by mx.groups.io with SMTP id smtpd.web10.11915.1595390778603322477 for ; Tue, 21 Jul 2020 21:06:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H7XQhpIeS41ErGoOhlL07Tb9DsYXlzyIrn6DIq/qp4ybUJBeUIcbuvd0ZCQyKFy1af6cvyo0yV0vzgfuSTuNRAHmr6qVSWOUIp6POimPSdHBK55bCUaNIxQWTdg3NpvEu9r5lDPbtd0zhxPr2reX+bs0I+NTDte1+YgIMWYczMpoB7YUmU0ougjEqJxzVmL7Zx30+RCAQ25GoGqUiPyDt/iGTsmk+yOJQ1bLzuZDIehbWHB+fvRJyYCvFPy8bJFpbWgPeEFLo554aRbL+KXmIr4xlbz1D9nYG52GTECPD5Eji5+5cTOyBstxbpwR20te5VpFQ4bO86/WQFJF9lEU+Q== 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=WCk/CA+jozBck5AK8R4O4zwmWnyQS6sAEXmZdErb7+k=; b=d1k846e/MLnGsvMmcjA3g1RtFFs5sicf40XjywdVqTfGmJO3L0ZSrd8efAZu2FurFY4RLDNftrnsTVs+3otH18DtU4xF9dA6CkXeiE70l6bS+sP9WhAfRuhO6uTKMDLbPPg1jCnWiy/Bh1va/aTsreG/9NoQzwBR2eqS9Hh9PUy9oqMwl7mj4hTYJCAtxlxKcYs0g5pMYmILl/jh0tYSNOzai8k+t/r7pA0cvOBIL2hTbiNkK5kmvolv1b5izoeNtnzOkWdq33CR3fFpZlEp2OLeX6SoN8VpBIsssaAhqx5WO4BvOOizO4Fn7Vb6TiEA5ft3uYh+GM6kOPo9l7lQrQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.24; Wed, 22 Jul 2020 04:06:16 +0000 X-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.021; Wed, 22 Jul 2020 04:06:16 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 42/46] UefiCpuPkg: Allow AP booting under SEV-ES Date: Tue, 21 Jul 2020 23:05:46 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0002.namprd08.prod.outlook.com (2603:10b6:803:29::12) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0801CA0002.namprd08.prod.outlook.com (2603:10b6:803:29::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Wed, 22 Jul 2020 04:06:16 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c0dcc016-d1f0-48c2-1a7c-08d82df494a9 X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: A+QLnF0RMoA3a2pLPaB/z6mNyWPVCjFWatWnr+Ei9IImghe+zH73XY/yGRR2EyaVadwI5tyb4745HuqV0WaDIIkk5SM+hz8D/QvLaBlaLPZBThZ1284KlDEAWnES2HwS1PkGwmkH9AenTRDJL7BR8vU3VIWHFbxAA2IyQmZsUdrWRYyOdd4tiJoTmD5zUgsbBhQK+eYLn+h+awVs4oXPMFWbNf62IFFf1nhuq9bRgNfJ7BhSs9chAzbwfeXbYDxqePYhUiXQn/UeUarLqBf4DhH4pkNUsQlQIkz1U0bVYoTbysvuyr5JquD7wGElI6xJBNe/BopJLYBUiuWx8fXVBdGc20HWivdCrPT2y5vA2HV+RrVd9Ut+FrEaj2E6h0IfV60Sy34l+ds5RiSBRF+XpYdwXbiOS8iVm/rSu5TAOa9Na5YtDMRfj8VuNI5NGIPHPYe26bPF5TtLuCBGpwourw== X-MS-Exchange-AntiSpam-MessageData: EwjnqrWcAd/xad4Hm3ULDFqfqfsQn1kFlk6CGIlhnsU0KA2cVEx8yA9PNQrvcjqOGPa9QxxZbWjqCr0o5VttPZlJTd3pwYURZbWfPoYQTX7gry3+FgfVMSjS4hhCbHGTt3VnH0hitRjCWLQ1gy4CGZpnHfMcZTd6+vd7c5tQssujOezOiHI9mpiMI05j4bXxBr1DdeN4tnCzbeREWQy5B4g/B32E48D9fCXks8UEhzXFtgBKDwjN7gqnd0wbPorpl0gOGvClTT2wjvpRgNU3+i4ZhCOyW3w58ATaIs6at0Uos7G4OqiRhzTrT8MDN84Av545NE80alyOW3AvKJgb2txOsKYHqqkeZVXN2NPslOUsBO5Pfn5LAZH0QHmRyD+tnhUd+VvuRukPZ1g19vtRatFpUsyCNgAmT7CW8yAB/xmLzpjxaXDlGw7MVRj8wk09uRbR2jiwPl5Fi6hu5oHB8bFwAid5zKg9Px1nbiEmaV4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0dcc016-d1f0-48c2-1a7c-08d82df494a9 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:16.6353 (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: VUE+FyCb7PkaZw7YZPOW5xFE+RDGH24eFKKkG360He4Oz3Gin7lCpz/JawtkkLy7q6JBoghviXKHojXlkZo77g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: owc3B4pOsAlxN0zupDd6Aoccx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390779; bh=SntXVb0M1vWeGz2l32RUpByIV6fvc0O3bEiP9p0p9z4=; h=Content-Type:Date:From:Reply-To:Subject:To; b=oYaPlXkvuRpkZpgyvknhDefI7XVBBK0mUg+b4lV75FQsotA+ldfsekVco49gSSSMOob CWk1klUmU7Wm1CMV9cbDqbslRTP1ewg8AIj+bKdQ+QV/JRCF1EHgpyOjn2BLFbMGPq9/v xiXBxsM6coFutw6IRG2wYcEDtoyikVJ1V5M= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Typically, an AP is booted using the INIT-SIPI-SIPI sequence. This sequence is intercepted by the hypervisor, which sets the AP's registers to the values requested by the sequence. At that point, the hypervisor can start the AP, which will then begin execution at the appropriate location. Under SEV-ES, AP booting presents some challenges since the hypervisor is not allowed to alter the AP's register state. In this situation, we have to distinguish between the AP's first boot and AP's subsequent boots. First boot: Once the AP's register state has been defined (which is before the guest is first booted) it cannot be altered. Should the hypervisor attempt to alter the register state, the change would be detected by the hardware and the VMRUN instruction would fail. Given this, the first boot for the AP is required to begin execution with this initial register state, which is typically the reset vector. This prevents the BSP from directing the AP startup location through the INIT-SIPI-SIPI sequence. To work around this, the firmware will provide a build time reserved area that can be used as the initial IP value. The hypervisor can extract this location value by checking for the SEV-ES reset block GUID that must be located 48-bytes from the end of the firmware. The format of the SEV-ES reset block area is: 0x00 - 0x01 - SEV-ES Reset IP 0x02 - 0x03 - SEV-ES Reset CS Segment Base[31:16] 0x04 - 0x05 - Size of the SEV-ES reset block 0x06 - 0x15 - SEV-ES Reset Block GUID (00f771de-1a7e-4fcb-890e-68c77e2fb44e) The total size is 22 bytes. Any expansion to this block must be done by adding new values before existing values. The hypervisor will use the IP and CS values obtained from the SEV-ES reset block to set as the AP's initial values. The CS Segment Base represents the upper 16 bits of the CS segment base and must be left shifted by 16 bits to form the complete CS segment base value. Before booting the AP for the first time, the BSP must initialize the SEV-ES reset area. This consists of programming a FAR JMP instruction to the contents of a memory location that is also located in the SEV-ES reset area. The BSP must program the IP and CS values for the FAR JMP based on values drived from the INIT-SIPI-SIPI sequence. Subsequent boots: Again, the hypervisor cannot alter the AP register state, so a method is required to take the AP out of halt state and redirect it to the desired IP location. If it is determined that the AP is running in an SEV-ES guest, then instead of calling CpuSleep(), a VMGEXIT is issued with the AP Reset Hold exit code (0x80000004). The hypervisor will put the AP in a halt state, waiting for an INIT-SIPI-SIPI sequence. Once the sequence is recognized, the hypervisor will resume the AP. At this point the AP must transition from the current 64-bit long mode down to 16-bit real mode and begin executing at the derived location from the INIT-SIPI-SIPI sequence. Another change is around the area of obtaining the (x2)APIC ID during AP startup. During AP startup, the AP can't take a #VC exception before the AP has established a stack. However, the AP stack is set by using the (x2)APIC ID, which is obtained through CPUID instructions. A CPUID instruction will cause a #VC, so a different method must be used. The GHCB protocol supports a method to obtain CPUID information from the hypervisor through the GHCB MSR. This method does not require a stack, so it is used to obtain the necessary CPUID information to determine the (x2)APIC ID. The new 16-bit protected mode GDT entry is used in order to transition from 64-bit long mode down to 16-bit real mode. A new assembler routine is created that takes the AP from 64-bit long mode to 16-bit real mode. This is located under 1MB in memory and transitions from 64-bit long mode to 32-bit compatibility mode to 16-bit protected mode and finally 16-bit real mode. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 60 ++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 70 +++- UefiCpuPkg/Library/MpInitLib/MpLib.c | 336 +++++++++++++++++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 19 + UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 2 +- UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 2 +- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 15 + UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 4 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 239 +++++++++++++ 11 files changed, 738 insertions(+), 15 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 583276595619..1771575c69c1 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -52,6 +52,7 @@ [LibraryClasses] DebugAgentLib SynchronizationLib PcdLib + VmgExitLib =20 [Protocols] gEfiTimerArchProtocolGuid ## SOMETIMES_CONSUMES @@ -72,4 +73,6 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## = SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 4b3d39fbf36c..34abf25d43cd 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -51,6 +51,7 @@ [LibraryClasses] SynchronizationLib PeiServicesLib PcdLib + VmgExitLib =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONS= UMES @@ -62,6 +63,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOME= TIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 5b46c295b6b2..b1a9d99cb3eb 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -173,6 +173,11 @@ typedef struct { UINT8 *RelocateApLoopFuncAddress; UINTN RelocateApLoopFuncSize; UINTN ModeTransitionOffset; + UINTN SwitchToRealSize; + UINTN SwitchToRealOffset; + UINTN SwitchToRealNoNxOffset; + UINTN SwitchToRealPM16ModeOffset; + UINTN SwitchToRealPM16ModeSize; } MP_ASSEMBLY_ADDRESS_MAP; =20 typedef struct _CPU_MP_DATA CPU_MP_DATA; @@ -211,6 +216,8 @@ typedef struct { // Enable5LevelPaging indicates whether 5-level paging is enabled in lon= g mode. // BOOLEAN Enable5LevelPaging; + BOOLEAN SevEsIsEnabled; + UINTN GhcbBase; } MP_CPU_EXCHANGE_INFO; =20 #pragma pack() @@ -257,6 +264,7 @@ struct _CPU_MP_DATA { UINT8 ApLoopMode; UINT8 ApTargetCState; UINT16 PmCodeSegment; + UINT16 Pm16CodeSegment; CPU_AP_DATA *CpuData; volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo; =20 @@ -278,8 +286,47 @@ struct _CPU_MP_DATA { BOOLEAN WakeUpByInitSipiSipi; =20 BOOLEAN SevEsIsEnabled; + UINTN SevEsAPBuffer; + UINTN SevEsAPResetStackStart; + CPU_MP_DATA *NewCpuMpData; + + UINT64 GhcbBase; }; =20 +#define AP_RESET_STACK_SIZE 64 + +#pragma pack(1) + +typedef struct { + UINT8 InsnBuffer[8]; + UINT16 Rip; + UINT16 Segment; +} SEV_ES_AP_JMP_FAR; + +#pragma pack() + +/** + Assembly code to move an AP from long mode to real mode. + + Move an AP from long mode to real mode in preparation to invoking + the reset vector. This is used for SEV-ES guests where a hypervisor + is not allowed to set the CS and RIP to point to the reset vector. + + @param[in] BufferStart The reset vector target. + @param[in] Code16 16-bit protected mode code segment value. + @param[in] Code32 32-bit protected mode code segment value. + @param[in] StackStart The start of a stack to be used for transitioni= ng + from long mode to real mode. +**/ +typedef +VOID +(EFIAPI AP_RESET) ( + IN UINTN BufferStart, + IN UINT16 Code16, + IN UINT16 Code32, + IN UINTN StackStart + ); + extern EFI_GUID mCpuInitMpLibHobGuid; =20 /** @@ -385,6 +432,19 @@ GetModeTransitionBuffer ( IN UINTN BufferSize ); =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ); + /** This function will be called by BSP to wakeup AP. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 8ccddf8e9f9c..9115ff9e3e30 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include =20 #include =20 @@ -144,6 +146,39 @@ GetModeTransitionBuffer ( return (UINTN)StartAddress; } =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + + // + // Allocate 1 page for AP jump table page + // + StartAddress =3D BASE_4GB - 1; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiReservedMemoryType, + 1, + &StartAddress + ); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory =3D %lx\n", (UINTN) StartAddress= )); + + return (UINTN) StartAddress; +} + /** Checks APs status and updates APs status if needed. =20 @@ -218,6 +253,38 @@ CheckApsStatus ( } } =20 +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 0) { + break; + } + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + /** Get Protected mode code segment from current GDT table. =20 @@ -238,7 +305,7 @@ GetProtectedModeCS ( GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; for (Index =3D 0; Index < GdtEntryCount; Index++) { if (GdtEntry->Bits.L =3D=3D 0) { - if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 1) { break; } } @@ -300,6 +367,7 @@ MpInitChangeApLoopCallback ( =20 CpuMpData =3D GetCpuMpData (); CpuMpData->PmCodeSegment =3D GetProtectedModeCS (); + CpuMpData->Pm16CodeSegment =3D GetProtectedMode16CS (); CpuMpData->ApLoopMode =3D PcdGet8 (PcdCpuApLoopMode); mNumberToFinish =3D CpuMpData->CpuCount - 1; WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE); diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 2a3fbeef35f7..90416c81b616 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,6 +9,9 @@ **/ =20 #include "MpLib.h" +#include +#include +#include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; =20 @@ -291,6 +294,14 @@ GetApLoopMode ( // ApLoopMode =3D ApInHltLoop; } + + if (PcdGetBool (PcdSevEsIsEnabled)) { + // + // For SEV-ES, force AP in Hlt-loop mode in order to use the GHCB + // protocol for starting APs + // + ApLoopMode =3D ApInHltLoop; + } } =20 if (ApLoopMode !=3D ApInMwaitLoop) { @@ -587,6 +598,112 @@ InitializeApData ( SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } =20 +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0 && + GdtEntry->Bits.DB =3D=3D 0 && + GdtEntry->Bits.Type > 8) { + break; + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Get Protected mode code segment with 32-bit default addressing + from current GDT table. + + @return Protected mode 32-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode32CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0 && + GdtEntry->Bits.DB =3D=3D 1 && + GdtEntry->Bits.Type > 8) { + break; + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Reset an AP when in SEV-ES mode. + + If successful, this function never returns. + + @param[in] Ghcb Pointer to the GHCB + @param[in] CpuMpData Pointer to CPU MP Data + +**/ +STATIC +VOID +MpInitLibSevEsAPReset ( + IN GHCB *Ghcb, + IN CPU_MP_DATA *CpuMpData + ) +{ + UINT16 Code16, Code32; + AP_RESET *APResetFn; + UINTN BufferStart; + UINTN StackStart; + + Code16 =3D GetProtectedMode16CS (); + Code32 =3D GetProtectedMode32CS (); + + if (CpuMpData->WakeupBufferHigh !=3D 0) { + APResetFn =3D (AP_RESET *) (CpuMpData->WakeupBufferHigh + CpuMpData->A= ddressMap.SwitchToRealNoNxOffset); + } else { + APResetFn =3D (AP_RESET *) (CpuMpData->MpCpuExchangeInfo->BufferStart = + CpuMpData->AddressMap.SwitchToRealOffset); + } + + BufferStart =3D CpuMpData->MpCpuExchangeInfo->BufferStart; + StackStart =3D CpuMpData->SevEsAPResetStackStart - + (AP_RESET_STACK_SIZE * GetApicId ()); + + // + // This call never returns. + // + APResetFn (BufferStart, Code16, Code32, StackStart); +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -648,7 +765,14 @@ ApWakeupFunction ( InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack= ); ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; =20 - InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->NumA= psExecuting); + // + // Delay decrementing the APs executing count when SEV-ES is enabled + // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly + // performs another INIT-SIPI-SIPI sequence. + // + if (!CpuMpData->SevEsIsEnabled) { + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->Nu= mApsExecuting); + } } else { // // Execute AP function if AP is ready @@ -755,7 +879,52 @@ ApWakeupFunction ( // while (TRUE) { DisableInterrupts (); - CpuSleep (); + if (CpuMpData->SevEsIsEnabled) { + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + UINT64 Status; + BOOLEAN DoDecrement; + + if (CpuMpData->InitFlag =3D=3D ApInitConfig) { + DoDecrement =3D TRUE; + } + + while (TRUE) { + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + + if (DoDecrement) { + DoDecrement =3D FALSE; + + // + // Perform the delayed decrement just before issuing the fir= st + // VMGEXIT with AP_RESET_HOLD. + // + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeIn= fo->NumApsExecuting); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_AP_RESET_HOLD, 0, 0); + if ((Status =3D=3D 0) && (Ghcb->SaveArea.SwExitInfo2 !=3D 0)) { + VmgDone (Ghcb); + break; + } + + VmgDone (Ghcb); + } + + // + // Awakened in a new phase? Use the new CpuMpData + // + if (CpuMpData->NewCpuMpData !=3D NULL) { + CpuMpData =3D CpuMpData->NewCpuMpData; + } + + MpInitLibSevEsAPReset (Ghcb, CpuMpData); + } else { + CpuSleep (); + } CpuPause (); } } @@ -868,6 +1037,9 @@ FillExchangeInfoData ( ExchangeInfo->Enable5LevelPaging =3D (BOOLEAN) (Cr4.Bits.LA57 =3D=3D 1); DEBUG ((DEBUG_INFO, "%a: 5-Level Paging =3D %d\n", gEfiCallerBaseName, E= xchangeInfo->Enable5LevelPaging)); =20 + ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; + ExchangeInfo->GhcbBase =3D (UINTN) CpuMpData->GhcbBase; + // // Get the BSP's data of GDT and IDT // @@ -894,8 +1066,9 @@ FillExchangeInfoData ( // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. // if (CpuMpData->WakeupBufferHigh !=3D 0) { - Size =3D CpuMpData->AddressMap.RendezvousFunnelSize - - CpuMpData->AddressMap.ModeTransitionOffset; + Size =3D CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize - + CpuMpData->AddressMap.ModeTransitionOffset; CopyMem ( (VOID *)CpuMpData->WakeupBufferHigh, CpuMpData->AddressMap.RendezvousFunnelAddress + @@ -948,7 +1121,8 @@ BackupAndPrepareWakeupBuffer( CopyMem ( (VOID *) CpuMpData->WakeupBuffer, (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize ); } =20 @@ -969,6 +1143,44 @@ RestoreWakeupBuffer( ); } =20 +/** + Calculate the size of the reset stack. + + @return Total amount of memory required for stacks +**/ +STATIC +UINTN +GetApResetStackSize ( + VOID + ) +{ + return AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); +} + +/** + Calculate the size of the reset vector. + + @param[in] AddressMap The pointer to Address Map structure. + + @return Total amount of memory required for the AP reset= area +**/ +STATIC +UINTN +GetApResetVectorSize ( + IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap + ) +{ + UINTN Size; + + Size =3D ALIGN_VALUE (AddressMap->RendezvousFunnelSize + + AddressMap->SwitchToRealSize + + sizeof (MP_CPU_EXCHANGE_INFO), + CPU_STACK_ALIGNMENT); + Size +=3D GetApResetStackSize (); + + return Size; +} + /** Allocate reset vector buffer. =20 @@ -982,16 +1194,22 @@ AllocateResetVector ( UINTN ApResetVectorSize; =20 if (CpuMpData->WakeupBuffer =3D=3D (UINTN) -1) { - ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); + ApResetVectorSize =3D GetApResetVectorSize (&CpuMpData->AddressMap); =20 CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *) (UINTN) - (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.Rende= zvousFunnelSize); + (CpuMpData->WakeupBuffer + + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize); CpuMpData->WakeupBufferHigh =3D GetModeTransitionBuffer ( - CpuMpData->AddressMap.RendezvousFunnel= Size - + CpuMpData->AddressMap.RendezvousFunnel= Size + + CpuMpData->AddressMap.SwitchToRealSize= - CpuMpData->AddressMap.ModeTransitionOf= fset ); + // + // The reset stack starts at the end of the buffer. + // + CpuMpData->SevEsAPResetStackStart =3D CpuMpData->WakeupBuffer + ApRese= tVectorSize; } BackupAndPrepareWakeupBuffer (CpuMpData); } @@ -1006,7 +1224,80 @@ FreeResetVector ( IN CPU_MP_DATA *CpuMpData ) { - RestoreWakeupBuffer (CpuMpData); + // + // If SEV-ES is enabled, the reset area is needed for AP parking and + // and AP startup in the OS, so the reset area is reserved. Do not + // perform the restore as this will overwrite memory which has data + // needed by SEV-ES. + // + if (!CpuMpData->SevEsIsEnabled) { + RestoreWakeupBuffer (CpuMpData); + } +} + +/** + Allocate the SEV-ES AP jump table buffer. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AllocateSevEsAPMemory ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + if (CpuMpData->SevEsAPBuffer =3D=3D (UINTN) -1) { + CpuMpData->SevEsAPBuffer =3D + CpuMpData->SevEsIsEnabled ? GetSevEsAPMemory () : 0; + } +} + +/** + Program the SEV-ES AP jump table buffer. + + @param[in] SipiVector The SIPI vector used for the AP Reset +**/ +VOID +SetSevEsJumpTable ( + IN UINTN SipiVector + ) +{ + SEV_ES_AP_JMP_FAR *JmpFar; + UINT32 Offset, InsnByte; + UINT8 LoNib, HiNib; + + JmpFar =3D (SEV_ES_AP_JMP_FAR *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + ASSERT (JmpFar !=3D NULL); + + // + // Obtain the address of the Segment/Rip location in the workarea. + // This will be set to a value derived from the SIPI vector and will + // be the memory address used for the far jump below. + // + Offset =3D FixedPcdGet32 (PcdSevEsWorkAreaBase); + Offset +=3D sizeof (JmpFar->InsnBuffer); + LoNib =3D (UINT8) Offset; + HiNib =3D (UINT8) (Offset >> 8); + + // + // Program the workarea (which is the initial AP boot address) with + // far jump to the SIPI vector (where XX and YY represent the + // address of where the SIPI vector is stored. + // + // JMP FAR [CS:XXYY] =3D> 2E FF 2E YY XX + // + InsnByte =3D 0; + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // CS override prefix + JmpFar->InsnBuffer[InsnByte++] =3D 0xFF; // JMP (FAR) + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // ModRM (JMP memory location) + JmpFar->InsnBuffer[InsnByte++] =3D LoNib; // YY offset ... + JmpFar->InsnBuffer[InsnByte++] =3D HiNib; // XX offset ... + + // + // Program the Segment/Rip based on the SIPI vector (always at least + // 16-byte aligned, so Rip is set to 0). + // + JmpFar->Rip =3D 0; + JmpFar->Segment =3D (UINT16) (SipiVector >> 4); } =20 /** @@ -1043,6 +1334,7 @@ WakeUpAP ( CpuMpData->InitFlag !=3D ApInitDone) { ResetVectorRequired =3D TRUE; AllocateResetVector (CpuMpData); + AllocateSevEsAPMemory (CpuMpData); FillExchangeInfoData (CpuMpData); SaveLocalApicTimerSetting (CpuMpData); } @@ -1079,6 +1371,15 @@ WakeUpAP ( } } if (ResetVectorRequired) { + // + // For SEV-ES, the initial AP boot address will be defined by + // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address + // from the original INIT-SIPI-SIPI. + // + if (CpuMpData->SevEsIsEnabled) { + SetSevEsJumpTable (ExchangeInfo->BufferStart); + } + // // Wakeup all APs // @@ -1170,6 +1471,16 @@ WakeUpAP ( *(UINT32 *) CpuData->StartupApSignal =3D WAKEUP_AP_SIGNAL; if (ResetVectorRequired) { CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; + + // + // For SEV-ES, the initial AP boot address will be defined by + // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address + // from the original INIT-SIPI-SIPI. + // + if (CpuMpData->SevEsIsEnabled) { + SetSevEsJumpTable (ExchangeInfo->BufferStart); + } + SendInitSipiSipi ( CpuInfoInHob[ProcessorNumber].ApicId, (UINT32) ExchangeInfo->BufferStart @@ -1646,7 +1957,7 @@ MpInitLibInitialize ( ASSERT (MaxLogicalProcessorNumber !=3D 0); =20 AsmGetAddressMap (&AddressMap); - ApResetVectorSize =3D AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_E= XCHANGE_INFO); + ApResetVectorSize =3D GetApResetVectorSize (&AddressMap); ApStackSize =3D PcdGet32(PcdCpuApStackSize); ApLoopMode =3D GetApLoopMode (&MonitorFilterSize); =20 @@ -1705,6 +2016,8 @@ MpInitLibInitialize ( CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); + CpuMpData->SevEsAPBuffer =3D (UINTN) -1; + CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 // // Make sure no memory usage outside of the allocated buffer. @@ -1763,6 +2076,7 @@ MpInitLibInitialize ( // APs have been wakeup before, just get the CPU Information // from HOB // + OldCpuMpData->NewCpuMpData =3D CpuMpData; CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index a548fed23fa7..3989bd6a7a9f 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -280,6 +280,25 @@ GetModeTransitionBuffer ( return 0; } =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ) +{ + // + // PEI phase doesn't need to do such transition. So simply return 0. + // + return 0; +} + /** Checks APs status and updates APs status if needed. =20 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c b/UefiCpuPkg/PiSm= mCpuDxeSmm/X64/SmmFuncsArch.c index 6298571e29b2..28f8e8e133e5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c @@ -121,7 +121,7 @@ GetProtectedModeCS ( GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; for (Index =3D 0; Index < GdtEntryCount; Index++) { if (GdtEntry->Bits.L =3D=3D 0) { - if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 1) { break; } } diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc b/UefiCpuPkg/Libra= ry/MpInitLib/Ia32/MpEqu.inc index efb1bc2bf7cb..4f5a7c859a56 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc @@ -19,7 +19,7 @@ CPU_SWITCH_STATE_IDLE equ 0 CPU_SWITCH_STATE_STORED equ 1 CPU_SWITCH_STATE_LOADED equ 2 =20 -LockLocation equ (RendezvousFunnelProcEnd - Rendez= vousFunnelProcStart) +LockLocation equ (SwitchToRealProcEnd - Rendezvous= FunnelProcStart) StackStartAddressLocation equ LockLocation + 04h StackSizeLocation equ LockLocation + 08h ApProcedureLocation equ LockLocation + 0Ch diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index b74046b76af3..309d53bf3b37 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -215,6 +215,16 @@ CProcedureInvoke: jmp $ ; Never reach here RendezvousFunnelProcEnd: =20 +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;NOT USED IN 32 BIT MODE. +;-------------------------------------------------------------------------= ------------ +global ASM_PFX(SwitchToRealProc) +ASM_PFX(SwitchToRealProc): +SwitchToRealProcStart: + jmp $ ; Never reach here +SwitchToRealProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); ;-------------------------------------------------------------------------= ------------ @@ -263,6 +273,11 @@ ASM_PFX(AsmGetAddressMap): mov dword [ebx + 0Ch], AsmRelocateApLoopStart mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoop= Start mov dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart + mov dword [ebx + 18h], SwitchToRealProcEnd - SwitchToRealProcSt= art ; SwitchToRealSize + mov dword [ebx + 1Ch], SwitchToRealProcStart - RendezvousFunnel= ProcStart ; SwitchToRealOffset + mov dword [ebx + 20h], SwitchToRealProcStart - Flat32Start = ; SwitchToRealNoNxOffset + mov dword [ebx + 24h], 0 = ; SwitchToRealPM16ModeOffset + mov dword [ebx + 28h], 0 = ; SwitchToRealPM16ModeSize =20 popad ret diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc b/UefiCpuPkg/Librar= y/MpInitLib/X64/MpEqu.inc index 58ef369342a7..c92daaaffd6b 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc @@ -19,7 +19,7 @@ CPU_SWITCH_STATE_IDLE equ 0 CPU_SWITCH_STATE_STORED equ 1 CPU_SWITCH_STATE_LOADED equ 2 =20 -LockLocation equ (RendezvousFunnelProcEnd - Rendez= vousFunnelProcStart) +LockLocation equ (SwitchToRealProcEnd - Rendezvous= FunnelProcStart) StackStartAddressLocation equ LockLocation + 08h StackSizeLocation equ LockLocation + 10h ApProcedureLocation equ LockLocation + 18h @@ -41,3 +41,5 @@ ModeTransitionSegmentLocation equ LockLocation + 9= 8h ModeHighMemoryLocation equ LockLocation + 9Ah ModeHighSegmentLocation equ LockLocation + 9Eh Enable5LevelPagingLocation equ LockLocation + 0A0h +SevEsIsEnabledLocation equ LockLocation + 0A1h +GhcbBaseLocation equ LockLocation + 0A2h diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 87f2523e856f..6956b408d004 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -184,9 +184,97 @@ Releaselock: add edi, StackStartAddressLocation add rax, qword [edi] mov rsp, rax + + lea edi, [esi + SevEsIsEnabledLocation] + cmp byte [edi], 1 ; SevEsIsEnabled + jne CProcedureInvoke + + ; + ; program GHCB + ; Each page after the GHCB is a per-CPU page, so the calculation pro= grams + ; a GHCB to be every 8KB. + ; + mov eax, SIZE_4KB + shl eax, 1 ; EAX =3D SIZE_4K * 2 + mov ecx, ebx + mul ecx ; EAX =3D SIZE_4K * 2 * C= puNumber + mov edi, esi + add edi, GhcbBaseLocation + add rax, qword [edi] + mov rdx, rax + shr rdx, 32 + mov rcx, 0xc0010130 + wrmsr jmp CProcedureInvoke =20 GetApicId: + lea edi, [esi + SevEsIsEnabledLocation] + cmp byte [edi], 1 ; SevEsIsEnabled + jne DoCpuid + + ; + ; Since we don't have a stack yet, we can't take a #VC + ; exception. Use the GHCB protocol to perform the CPUID + ; calls. + ; + mov rcx, 0xc0010130 + rdmsr + shl rdx, 32 + or rax, rdx + mov rdi, rax ; RDI now holds the original GHCB GPA + + mov rdx, 0 ; CPUID function 0 + mov rax, 0 ; RAX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + cmp edx, 0bh + jb NoX2ApicSevEs ; CPUID level below CPUID_EXTENDED_TOP= OLOGY + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + test edx, 0ffffh + jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 0c0000000h ; RDX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + + ; Processor is x2APIC capable; 32-bit x2APIC ID is now in EDX + jmp RestoreGhcb + +NoX2ApicSevEs: + ; Processor is not x2APIC capable, so get 8-bit APIC ID + mov rdx, 1 ; CPUID function 1 + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + shr edx, 24 + +RestoreGhcb: + mov rbx, rdx ; Save x2APIC/APIC ID + + mov rdx, rdi ; RDI holds the saved GHCB GPA + shr rdx, 32 + mov eax, edi + wrmsr + + mov rdx, rbx + + ; x2APIC ID or APIC ID is in EDX + jmp GetProcessorNumber + +DoCpuid: mov eax, 0 cpuid cmp eax, 0bh @@ -253,12 +341,158 @@ CProcedureInvoke: =20 RendezvousFunnelProcEnd: =20 +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENC= E THIS PROC +;IS IN MACHINE CODE. +; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINT= N StackStart) +; rcx - Buffer Start +; rdx - Code16 Selector Offset +; r8 - Code32 Selector Offset +; r9 - Stack Start +;-------------------------------------------------------------------------= ------------ +global ASM_PFX(SwitchToRealProc) +ASM_PFX(SwitchToRealProc): +SwitchToRealProcStart: +BITS 64 + cli + + ; + ; Get RDX reset value before changing stacks since the + ; new stack won't be able to accomodate a #VC exception. + ; + push rax + push rbx + push rcx + push rdx + + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for = RDX + + pop rdx + pop rcx + pop rbx + pop rax + + ; + ; Establish stack below 1MB + ; + mov rsp, r9 + + ; + ; Push ultimate Reset Vector onto the stack + ; + mov rax, rcx + shr rax, 4 + push word 0x0002 ; RFLAGS + push ax ; CS + push word 0x0000 ; RIP + push word 0x0000 ; For alignment, will be discar= ded + + ; + ; Get address of "16-bit operand size" label + ; + lea rbx, [PM16Mode] + + ; + ; Push addresses used to change to compatibility mode + ; + lea rax, [CompatMode] + push r8 + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; +o64 retf + +BITS 32 +CompatMode: + ; + ; Set up stack to prepare for exiting protected mode + ; + push edx ; Code16 CS + push ebx ; PM16Mode label address + + ; + ; Disable paging + ; + mov eax, cr0 ; Read CR0 + btr eax, 31 ; Set PG=3D0 + mov cr0, eax ; Write CR0 + + ; + ; Disable long mode + ; + mov ecx, 0c0000080h ; EFER MSR number + rdmsr ; Read EFER + btr eax, 8 ; Set LME=3D0 + wrmsr ; Write EFER + + ; + ; Disable PAE + ; + mov eax, cr4 ; Read CR4 + btr eax, 5 ; Set PAE=3D0 + mov cr4, eax ; Write CR4 + + mov edx, esi ; Restore RDX reset value + + ; + ; Switch to 16-bit operand size + ; + retf + +BITS 16 + ; + ; At entry to this label + ; - RDX will have its reset value + ; - On the top of the stack + ; - Alignment data (two bytes) to be discarded + ; - IP for Real Mode (two bytes) + ; - CS for Real Mode (two bytes) + ; +PM16Mode: + mov eax, cr0 ; Read CR0 + btr eax, 0 ; Set PE=3D0 + mov cr0, eax ; Write CR0 + + pop ax ; Discard alignment data + + ; + ; Clear registers (except RDX and RSP) before going into 16-bit mode + ; + xor eax, eax + xor ebx, ebx + xor ecx, ecx + xor esi, esi + xor edi, edi + xor ebp, ebp + + iret + +SwitchToRealProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: +BITS 64 cli ; Disable interrupt before switching to 3= 2-bit mode mov rax, [rsp + 40] ; CountTofinish lock dec dword [rax] ; (*CountTofinish)-- @@ -324,6 +558,11 @@ ASM_PFX(AsmGetAddressMap): mov qword [rcx + 18h], rax mov qword [rcx + 20h], AsmRelocateApLoopEnd - AsmRelocateApLoop= Start mov qword [rcx + 28h], Flat32Start - RendezvousFunnelProcStart + mov qword [rcx + 30h], SwitchToRealProcEnd - SwitchToRealProcSt= art ; SwitchToRealSize + mov qword [rcx + 38h], SwitchToRealProcStart - RendezvousFunnel= ProcStart ; SwitchToRealOffset + mov qword [rcx + 40h], SwitchToRealProcStart - Flat32Start = ; SwitchToRealNoNxOffset + mov qword [rcx + 48h], PM16Mode - RendezvousFunnelProcStart = ; SwitchToRealPM16ModeOffset + mov qword [rcx + 50h], SwitchToRealProcEnd - PM16Mode = ; SwitchToRealPM16ModeSize ret =20 ;-------------------------------------------------------------------------= ------------ --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63057): https://edk2.groups.io/g/devel/message/63057 Mute This Topic: https://groups.io/mt/75718565/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63058+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63058+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595390786410500.52905278042317; Tue, 21 Jul 2020 21:06:26 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3zOnYY1788612xL43UGltmZw; Tue, 21 Jul 2020 21:06:26 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.67]) by mx.groups.io with SMTP id smtpd.web12.11949.1595390785605570946 for ; Tue, 21 Jul 2020 21:06:25 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b+DF96Ht10aZbiIQdcZxUe/xuWkwmBCZAQrfuTsA/9fmJ4xmEHb8XhGDsGOCQUDUIIppNowEZHwPOTBX7zMNgG2DfrhFO9AvME+3ZteVFzI5sUXkotA6IHkDERbMl/UqdqIBTp4EpFWIq9/44pPxIi7n8GaTzNucX2XdSeZCKhxy6am6KjQx7rfmRTas1HPIVGR7+pDi6lPsAWHGXCO3NT3Ur4qk/P5kVTK+ZNaU5s6+I+IbKyYntMk+f2+BVDpYBJ/my8AF+UhgtgbTZkWk9OI9TSQnwwllzjzQvEpzdd9IYRLCvAaP6VtrgiOw30Ztzz6H8JF876zrXxQ7tM2aIA== 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=Cly63GpVgtcX7Qni9pbo9m94/AhxXLuSc1r4QOxC/u8=; b=UiWwLei1IsMMG2jcCY0o5V010rYkdT3QemiRQfcU6fsoWndRyBB5WzP8hWBw2dWHIpVVGmqUKp9A4teH32AASBammGwnDg32maJ9U/P/S7qVu4M6HVoTU/l425W9lvmPoZivxN2ZfDKv8SS7k8hxxqPRH7JRsCRxPZ/Spay1FKQ+QiqyrDQRo9pYzP2o5osqSwv7mUcQAI7NDAFOgidF22JI0RgCZ8vMWJVUBApNlq8SB6f/+ShaXWho2hgVe3Xb7j5YstUGuAsJJvvxhEibf2LIdCi5t98MV4VP25HuUsiT0BVCVxNcDWOh6VuRILzM4Oqdy20Drs4Q1XwRmnf+gg== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.24; Wed, 22 Jul 2020 04:06:24 +0000 X-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.021; Wed, 22 Jul 2020 04:06:24 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector Date: Tue, 21 Jul 2020 23:05:47 -0500 Message-ID: <26e126738b763be1abfd0df3929fbc558599db63.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0022.namprd05.prod.outlook.com (2603:10b6:805:de::35) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0022.namprd05.prod.outlook.com (2603:10b6:805:de::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.15 via Frontend Transport; Wed, 22 Jul 2020 04:06:24 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b944dbc2-70f8-4528-08cf-08d82df49965 X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: CW7IgwCyJCz8FJx0QN8hBxK78GV9ERgy6XCuFOrd+rBtxNqiw9UJHWympuHWwgT1uUyQgP9s4IYUe14Tamyn4DzFxvyYr3zn81VdTkL3TSTHRsAugARbqCR6+zsQm4pXUKwjjGH7BZMcwDjjUY7tVY9Wb5rLewQkemqb4GbEhLNwUoZfOskoLdWH0tkXMqHyn6bmHyushWezftA+4eMcCI4POUjECT/IemIoxezTwp1o/gaIFEWLMgw7TBNdUtmVKk6gquLKmffbK3uIcWrfcsZ/ihqyQLb0Gv8VrlCqzlVKajk3GeB3ccBh8Vfs+3kJO1Phs05X6RsABV8SD5P2b0VQKKV6q4oVnozKHcIrtX7OdaVt51lB96pMtZfyE8vtvoWt8EEAQIXUL/JJBCfJl7j+V2K1KiYwJxteUcEVXNmrGrVFgWtjOBSIUTxp/ViVK07TY1LypEHEDoTSJ2oqVw== X-MS-Exchange-AntiSpam-MessageData: 8jXCVzRXMEHJM8KYdnRxRS39YjotTfsJQa7w2ADVEk5wOeQ6ZOvTS6ok99vuz6H04U46REFLyy3LSfKYoH0LxyvcEdoD2uV0OKjFz9GBzeGS7rKcJor0Gri7dBKa9A4HyCoNlzz0PQKD/Z+iaAZWwA03GydeKV0iSkyEYf0LpZQLAd9kFu37Ot0glZaIA6XUEUv3NOYV7Dl4ABezS+Oxu9DTk0H0F56UnK5qwYQpKGmgBhoKN1dFC0jNbepUQEtb3u8iYtTnWB3G4r9TuGmry63iMRYltH/ByG9DJYLHwmLDXpwHjLbcZitQfVRRw/CbvWDYNfmu5raBHeGP6/ambJ2H716WKlflCb8XVSXx2SbPBBL17rAG973wPCEicsfg285Vt/1E1ZA5qSNSh3euz3lXy4YXxKlOSatbQlQO16gsMy+yaZSnXUhYBHNGDwR7O5cwxtyLbJ3UfVZgGGsI5jb50Tr39F2txKM3vPvNddM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b944dbc2-70f8-4528-08cf-08d82df49965 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:24.4059 (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: UjPNl0pvndvM36LJrEl6uFaYsfJNtxUjDOCDXGYvgqJ043gX3OYzCkioA5a166PoVEOAB7zL5VpNDR0ph+p6+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: ubCuMOIxlsyzhUGUhenERQbLx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390786; bh=UzQYwSoJwxovTnBt4HgGqeun42KGR3pk0XZylfkWbYI=; h=Content-Type:Date:From:Reply-To:Subject:To; b=ajRztKxLi1+Niy7/EpTc/gqponB46vFGwkog46x97Dsc8OgCSVx/qw+lVloFvIQBWon ToRG3eaA7KXjBqFRE7KLd4epXgAwMmsT1CeUwwJ+NGJoFoBjBIhVxtspEUy+VSF80viXt p+jpA6aWGIx6l8SOuQgGzfFf6NcqnhYQ2/M= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A hypervisor is not allowed to update an SEV-ES guest's register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead an SEV-ES AP must be re-directed from within the guest to the actual requested staring location as specified in the INIT-SIPI-SIPI sequence. Use the SEV-ES work area for the reset vector code that contains support to jump to the desired RIP location after having been started. This is required for only the very first AP reset. This new OVMF source file, ResetVectorVtf0.asm, is used in place of the original file through the use of the include path order set in OvmfPkg/ResetVector/ResetVector.inf under "[BuildOptions]". Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 100 +++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 2 files changed, 101 insertions(+) create mode 100644 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe= ctor/Ia16/ResetVectorVtf0.asm new file mode 100644 index 000000000000..980e0138e7fe --- /dev/null +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -0,0 +1,100 @@ +;-------------------------------------------------------------------------= ----- +; @file +; First code executed by processor after resetting. +; Derived from UefiCpuPkg/ResetVector/Vtf0/Ia16/ResetVectorVtf0.asm +; +; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ----- + +BITS 16 + +ALIGN 16 + +; +; Pad the image size to 4k when page tables are in VTF0 +; +; If the VTF0 image has page tables built in, then we need to make +; sure the end of VTF0 is 4k above where the page tables end. +; +; This is required so the page tables will be 4k aligned when VTF0 is +; located just below 0x100000000 (4GB) in the firmware device. +; +%ifdef ALIGN_TOP_TO_4K_FOR_PAGING + TIMES (0x1000 - ($ - EndOfPageTables) - 0x20) DB 0 +%endif + +; +; SEV-ES Processor Reset support +; +; sevEsResetBlock: +; For the initial boot of an AP under SEV-ES, the "reset" RIP must be +; programmed to the RAM area defined by SEV_ES_AP_RESET_IP. A known offs= et +; and GUID will be used to locate this block in the firmware and extract +; the build time RIP value. The GUID must always be 48 bytes from the +; end of the firmware. +; +; 0xffffffca (-0x36) - IP value +; 0xffffffcc (-0x34) - CS segment base [31:16] +; 0xffffffce (-0x32) - Size of the SEV-ES reset block +; 0xffffffd0 (-0x30) - SEV-ES reset block GUID +; (00f771de-1a7e-4fcb-890e-68c77e2fb44e) +; +; A hypervisor reads the CS segement base and IP value. The CS segment b= ase +; value represents the high order 16-bits of the CS segment base, so the +; hypervisor must left shift the value of the CS segement base by 16 bit= s to +; form the full CS segment base for the CS segment register. It would th= en +; program the EIP register with the IP value as read. +; + +TIMES (32 - (sevEsResetBlockEnd - sevEsResetBlockStart)) DB 0 + +sevEsResetBlockStart: + DD SEV_ES_AP_RESET_IP + DW sevEsResetBlockEnd - sevEsResetBlockStart + DB 0xDE, 0x71, 0xF7, 0x00, 0x7E, 0x1A, 0xCB, 0x4F + DB 0x89, 0x0E, 0x68, 0xC7, 0x7E, 0x2F, 0xB4, 0x4E +sevEsResetBlockEnd: + +ALIGN 16 + +applicationProcessorEntryPoint: +; +; Application Processors entry point +; +; GenFv generates code aligned on a 4k boundary which will jump to this +; location. (0xffffffe0) This allows the Local APIC Startup IPI to be +; used to wake up the application processors. +; + jmp EarlyApInitReal16 + +ALIGN 8 + + DD 0 + +; +; The VTF signature +; +; VTF-0 means that the VTF (Volume Top File) code does not require +; any fixups. +; +vtfSignature: + DB 'V', 'T', 'F', 0 + +ALIGN 16 + +resetVector: +; +; Reset Vector +; +; This is where the processor will begin execution +; + nop + nop + jmp EarlyBspInitReal16 + +ALIGN 16 + +fourGigabytes: + diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 762661115d50..4913b379a993 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -82,5 +82,6 @@ =20 %include "Main.asm" =20 + %define SEV_ES_AP_RESET_IP FixedPcdGet32 (PcdSevEsWorkAreaBase) %include "Ia16/ResetVectorVtf0.asm" =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63058): https://edk2.groups.io/g/devel/message/63058 Mute This Topic: https://groups.io/mt/75718566/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63059+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63059+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595390794744351.6197238760676; Tue, 21 Jul 2020 21:06:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YEheYY1788612x7WPar80pTi; Tue, 21 Jul 2020 21:06:34 -0700 X-Received: from NAM02-BL2-obe.outbound.protection.outlook.com (NAM02-BL2-obe.outbound.protection.outlook.com [40.107.75.48]) by mx.groups.io with SMTP id smtpd.web10.11916.1595390793757931178 for ; Tue, 21 Jul 2020 21:06:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V/cHB9QzmtALPJNsyU4Lt1Rd3RK/dTEhAn0R0/0aeaIFZqYTnQHP/mnQW3aWA1RmH4ewuHt4MkMXxKABFn4+T7sXGaXNKuclgkIH7mmZGCLiA1KQflccrwfaLIqKW+h7Z2dgJ+mBVmOFkKtkYXXmtlaYLOBJUFyVWSS2X10xA9CsgcjNKF8fLk7rZlt44kQkxGeR3P9kRblIkvvPt6aiBOQ0IpQhDyD/AIE89w3uzodpDsMRg5oG/tnKWENbU7R3wCVw6Mx3Mo5/8SPMEoVun4adfJyGgJpLiIASzaA5MnKXfDFTTSRIUVIbDsgPeJm6vHhgMxYaiavnKvfa9tnsjQ== 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=cYWmh/fcAwIXIlWubzjDdUIKKdxtd9nRLkFVJO7hvKY=; b=jGgZjT7f4rh2id+QfliuBKJk3oTrdloVO4vDq4rsuhNbVYcLqzDzsSVdd5aWjbLSd9f2STYuPEtXO8arwcMjhYsGG0gLGgrH1otjZK3a6n+kLM47yTcjf1KXHuDaYaYN9FGK4Af2QBtyCo0Jvwp05TS0LWCcKS2vpdsY8ygCuxhUhvg52XNb1yk986vNzy5OyTLuphdJHn3O3Z7ClQjfcJW+DoyCh/w9keaLr8lYtifdxpS4713/9GRebSd6pyATR4HMeFzvNsKJXeVzXT4dZyxB43BpNapuJHNS9YTdt0Q1bKBNeXNifzepF99xFjuvrBnEZ78dos+0nNLadDN1xg== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.24; Wed, 22 Jul 2020 04:06:32 +0000 X-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.021; Wed, 22 Jul 2020 04:06:32 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 44/46] OvmfPkg: Move the GHCB allocations into reserved memory Date: Tue, 21 Jul 2020 23:05:48 -0500 Message-ID: <0ad2c75541fcc5da38f54659252bd579994b5fb5.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0079.prod.exchangelabs.com (2603:10b6:800::47) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0079.prod.exchangelabs.com (2603:10b6:800::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.22 via Frontend Transport; Wed, 22 Jul 2020 04:06:31 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eeee0599-89b9-435c-3eaa-08d82df49de6 X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: QTIIk/jbTtVThYSGRkuQoFXNdBE7GJ6b86wpt/AjUp2ap2EMITR8dZBIXNN0+GxtcqxiES72cLoe70Hmknmt7yQsUOSZVdkBzscduUFVHSjhtVYnpAFDq7gChFIb+8yQacnEHl+cN/GShaYOGoysPu+1LDkRVAAbMwhntPw044/GjLfHg3TGG0lpLtiqYOZS7IoZCwO1l0khff+sb2P5lRJUypREU4nPROJGm5Vsl/OYcVqWaeonZR5u9Ck3JTVM8jswFBiBEl6KJ/TZVLFXvDpeLLuWL3ROJ6lBAyn/hLNHwe4aJMkUOiWcIioQC2HdGqXrE4ugr4Lc3CdDJyXiSVDCRu2RiiAslJkoW//gs2SkO630a0ZxFbIVYtaFL9b9jMOKjS4z5/vjRG3F8LJp/FTPxy2CQl4PNzUjetxlas05PESLG2zuvLmpMzxSj4Ps55pTZbHXUsnrpfHLBpUgTQ== X-MS-Exchange-AntiSpam-MessageData: 5HD6VyLeX2YdnbdtRp7Nb7WU0gMrIg/kHfiRRLmqpXqr2PGUEnpzEXoilRLWLkLoCE7CI/tV1EBFtFN8jmVTH0DIJM6qARgdbzHgpEzNKxcTsdKsz6SE4l5e6JmS7L0rHA7LaB39ct5+C3vX29BP+h60BPqTKyFzwmGrk9gsUsFmSKRfSoW8G5TJbeybqkRBsrL/z30bBOjGuMQ/NuvP6vwd62TnTdbTYM4h+0D7FZzq/V5Nnb2Gj1hXZSi6BeRqAYsCdxg2cc6QswWmSR3faZB12agCepsYo7XwM71fx5LMg7e5ByklR7IDmUnpXKsCss+nOo4sK0on4zo1XMBLj+Ko7YyaRhAG1fP+rX/Z8CgnlKwAWELpZ882NlwZ5ezVzgXM2d2+BnsORMnhWPR4pp0EW2qOcYUZcvTxuFtrmiT2PZS8KK0qQO0lR70bW/ryC44wvXkCzS+lrJD/TDz+WjkOXHOG9xi/BKlVDXgTe30= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeee0599-89b9-435c-3eaa-08d82df49de6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:31.9106 (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: 4Be3bO4e2ye/RK4bKqGIkDWW0Omc11kzy4fAr1FgkrlIf0tNS1QzymsGJo5qMMrrg6CYFxtAGf3t4YBmXybkOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: RSZou6GzoNJrsLt67ovGlTIXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390794; bh=RkN2IQdvwTyBDnYtV5TTiWsZ1FIVSosHbw20f0ehq0g=; h=Content-Type:Date:From:Reply-To:Subject:To; b=Gc1hah5oVG2F77XBjMOzIunkqnFWqRqxfVO3yHdlpw8elIWthUWH3gBX2627EdFUGSD B/ewZh4LN7UR4aoAPLmB7R8HgxtUIbxY9R2N435MqofU7D83IS9qJOzYmTpatXwkqTLM5 AHv00f+6K/Mu/LNTWSl+x/B6nlB8ja4xVac= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 After having transitioned from UEFI to the OS, the OS will need to boot the APs. For an SEV-ES guest, the APs will have been parked by UEFI using GHCB pages allocated by UEFI. The hypervisor will write to the GHCB SW_EXITINFO2 field of the GHCB when the AP is booted. As a result, the GHCB pages must be marked reserved so that the OS does not attempt to use them and experience memory corruption because of the hypervisor write. Change the GHCB allocation from the default boot services memory to reserved memory. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/AmdSev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a2b38c591236..4a515a484720 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -51,9 +51,11 @@ AmdSevEsInitialize ( =20 // // Allocate GHCB and per-CPU variable pages. + // Since the pages must survive across the UEFI to OS transition + // make them reserved. // GhcbPageCount =3D mMaxCpuCount * 2; - GhcbBase =3D AllocatePages (GhcbPageCount); + GhcbBase =3D AllocateReservedPages (GhcbPageCount); ASSERT (GhcbBase !=3D NULL); =20 GhcbBasePa =3D (PHYSICAL_ADDRESS)(UINTN) GhcbBase; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63059): https://edk2.groups.io/g/devel/message/63059 Mute This Topic: https://groups.io/mt/75718567/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63060+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63060+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595390801769731.8338978804541; Tue, 21 Jul 2020 21:06:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id F2KoYY1788612xtoisuFJKBt; Tue, 21 Jul 2020 21:06:41 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.82]) by mx.groups.io with SMTP id smtpd.web11.11828.1595390800829222641 for ; Tue, 21 Jul 2020 21:06:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=koQT6Ovr6hCHVqEbYPKCZShfGI2xP4h+THZmfw8FlCDwJ5hXNga49D76axe8d4ARqGIMMzdwJfXyIIyj36UQ60GPQZ6C7oKNLJe6VtyO0L3hrec25Zvf5skn2wOp9Re0BfhDEWsowxvdxhQF27e/AV1mHNjH9ddMyvz6W67KlE8XMoKBDKrNTWL8U7wKSHEc4ii/uTTbOW9PD3mkCP3yn5+qJcmG5on5n8JYNDV7ASmTurrmMgEBoRBWcITNghLo1aNNKCa6JUyk8Qa+gBS+nPY8UXhQyXk+wTYNR+ygEzfwbU87kKKDb/l/6VKEeZALWiQ4z64IDqFHMb3NzRaN2Q== 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=NB9l/B18lE6yAUYEdm6Gf7eEH/WJWN/404HvIJKlhK4=; b=aowwmRIqrJcTEX6qDAB1BZxEt02Jn2lq1v4SgWxcDkQuhn2tksssYjAvs47jWIT/BRbRipTPE5yENc4zvCWFy+KnWVIYaOwaTneEdTd1kSaTg0IPDvHijgh75iVChYT0RvYb/E515t9X7+ub3Nd/O/pupk0GW0b8V6eL6ni78sWyY+IafSYTf97qWztpR8PmUQGSTBo6sOHkRAkxS9L3ewmGQU5h4SMU5JsEyHny8KmlQr2uEuC6T5x57OxycrDcfDOY4UDwZdPhKcrUSjcCqazbfIhoOT/vwFppN6G7bpcT5GGgDEJRiv3dSngPfjhBn2VcB2bbdSjl4/OVbnDkPA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.24; Wed, 22 Jul 2020 04:06:39 +0000 X-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.021; Wed, 22 Jul 2020 04:06:39 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Date: Tue, 21 Jul 2020 23:05:49 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0045.prod.exchangelabs.com (2603:10b6:800::13) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0045.prod.exchangelabs.com (2603:10b6:800::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Wed, 22 Jul 2020 04:06:39 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7d12e058-49dd-46e1-89ee-08d82df4a26f X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 4raHWeGb/9rjtfi7KVB61LY/WMO1Flata07pP8O9jBueW9Yj1cCPB0VCn4IwTBaq6T90+tSn5Sl+uxPXQ5EGyGleBU8p6tfNO0tvl/SKkRWnQzdqIOXJY0rBq+4xK2EESlWPeJx+hSUeCKMLL6CiUqQ2eB8Z1H7YvKJ4C8tFjTPqGh8uJLgY0cLxYiXrPJwF8b9TOSuqPKqdPz0Ib+2I9tzXol7ZfeCg4d8yVj+UPyCbSIyvhJyGXXyY1y5Cpxn23rbn579ZZMuwSy8khi6cvXTmUnZrR2OR5SbSg0dxPCS5RZ4dWV+3wEOOiam7iZA/odMOfGxTOx/EsC8uRM/4aU/qLnmR0deq8PrC+XADBa/oxYG/AiWIwZeS0Pf726Vq0LMEhIeHDEZd/nI5KvH9eIebuxb/CkDjEyczdFRAuCX3v61736xZOFAwzlkJ/E7JH/Y7Hzl7j/iNsnfaLFbbYw== X-MS-Exchange-AntiSpam-MessageData: IZCiRHKDCZUv6guXddT5A4optgxlVw2UAZ6Cq5cIXBxM0AmFQSHZWRt05ZhQI1Ga6dkd1GZgzsM5Y9bLQXZkcBQzO8mBJNkbzLUUT6wjCzHt8ByzUMSEaJYsNqhIjgPJHQsXydtB88DtLnf9y5YtzR4qSLUiXmY3y6PRrKkpt+6a/M+81vCwLQp5qcY6UqWZwUd8Bsoqz68MrdJuWWlXaSOiGqBGWIotALJwNu3MUwoE19nBvVViImMxZNIS9d1acHE1L03IwUPLcL/ZCAYyjPmU8t2QqnOhHeku5oEpV4GJeklWMXfwTrfYu4fHD0oyhQVuXtzkTq5A4gGoKj8cGQ45BL/5eJVBpqXKgSIVtyhgo7WvkMIx0e/TZLH0vSpVm6fmIVk+xBFljkYN4LeXfgpYK5lrhY2rwaQxou3S5VoVAJqlfM+IiSXMpt537/c4Vip7clqjOk48PbNtw8gQRS0SUndDg3+dy7gC7jNnz+E= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d12e058-49dd-46e1-89ee-08d82df4a26f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:39.5593 (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: tB5BjnPLCpdyhrBwovxLPcTNLRN6TRkr8R8bHV+aZlKAwVS3zJH6y7Zie+oHnmGhRa7WGacYTPaZeTYIYQVjxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: BS1GkdLbCPZp362NelDTwbjOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390801; bh=Bw/lIT5p+msTO8XsJ7kCd1PxaKUTznK+5u0YI+urHLA=; h=Content-Type:Date:From:Reply-To:Subject:To; b=N6sfzYOj+P9wx0RrvHhajzCbEviAH4nROMGj60ffxEMOuHirn2KO2U4dWsPZqlvCo8T WeqL3a55JJNS+B8GSfN88BMMFqcHDoVm0Q7JpzVchshyDwTDKgn3YtR+iS7bIQ+hIbG8l 6bc5dm5yXBrPrFllM5FAk8YCuxsyrFZ7NFk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Before UEFI transfers control to the OS, it must park the AP. This is done using the AsmRelocateApLoop function to transition into 32-bit non-paging mode. For an SEV-ES guest, a few additional things must be done: - AsmRelocateApLoop must be updated to support SEV-ES. This means performing a VMGEXIT AP Reset Hold instead of an MWAIT or HLT loop. - Since the AP must transition to real mode, a small routine is copied to the WakeupBuffer area. Since the WakeupBuffer will be used by the AP during OS booting, it must be placed in reserved memory. Additionally, the AP stack must be located where it can be accessed in real mode. - Once the AP is in real mode it will transfer control to the destination specified by the OS in the SEV-ES AP Jump Table. The SEV-ES AP Jump Table address is saved by the hypervisor for the OS using the GHCB VMGEXIT AP Jump Table exit code. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 8 +- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 54 +++++++- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 131 ++++++++++++++++-- 3 files changed, 175 insertions(+), 18 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b1a9d99cb3eb..267aa5201c50 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -293,7 +293,8 @@ struct _CPU_MP_DATA { UINT64 GhcbBase; }; =20 -#define AP_RESET_STACK_SIZE 64 +#define AP_SAFE_STACK_SIZE 128 +#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE =20 #pragma pack(1) =20 @@ -349,8 +350,11 @@ VOID IN BOOLEAN MwaitSupport, IN UINTN ApTargetCState, IN UINTN PmCodeSegment, + IN UINTN Pm16CodeSegment, IN UINTN TopOfApStack, - IN UINTN NumberToFinish + IN UINTN NumberToFinish, + IN UINTN SevEsAPJumpTable, + IN UINTN WakeupBuffer ); =20 /** diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 9115ff9e3e30..7165bcf3124a 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -85,6 +86,13 @@ GetWakeupBuffer ( { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS StartAddress; + EFI_MEMORY_TYPE MemoryType; + + if (PcdGetBool (PcdSevEsIsEnabled)) { + MemoryType =3D EfiReservedMemoryType; + } else { + MemoryType =3D EfiBootServicesData; + } =20 // // Try to allocate buffer below 1M for waking vector. @@ -97,7 +105,7 @@ GetWakeupBuffer ( StartAddress =3D 0x88000; Status =3D gBS->AllocatePages ( AllocateMaxAddress, - EfiBootServicesData, + MemoryType, EFI_SIZE_TO_PAGES (WakeupBufferSize), &StartAddress ); @@ -159,8 +167,10 @@ GetSevEsAPMemory ( VOID ) { - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS StartAddress; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; =20 // // Allocate 1 page for AP jump table page @@ -176,6 +186,16 @@ GetSevEsAPMemory ( =20 DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory =3D %lx\n", (UINTN) StartAddress= )); =20 + // + // Save the SevEsAPMemory as the AP jump table. + // + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress); + VmgDone (Ghcb); + return (UINTN) StartAddress; } =20 @@ -330,17 +350,26 @@ RelocateApLoop ( BOOLEAN MwaitSupport; ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc; UINTN ProcessorNumber; + UINTN StackStart; =20 MpInitLibWhoAmI (&ProcessorNumber); CpuMpData =3D GetCpuMpData (); MwaitSupport =3D IsMwaitSupport (); + if (CpuMpData->SevEsIsEnabled) { + StackStart =3D CpuMpData->SevEsAPResetStackStart; + } else { + StackStart =3D mReservedTopOfApStack; + } AsmRelocateApLoopFunc =3D (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoop= Func; AsmRelocateApLoopFunc ( MwaitSupport, CpuMpData->ApTargetCState, CpuMpData->PmCodeSegment, - mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE, - (UINTN) &mNumberToFinish + CpuMpData->Pm16CodeSegment, + StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE, + (UINTN) &mNumberToFinish, + CpuMpData->SevEsAPBuffer, + CpuMpData->WakeupBuffer ); // // It should never reach here @@ -374,6 +403,21 @@ MpInitChangeApLoopCallback ( while (mNumberToFinish > 0) { CpuPause (); } + + if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer !=3D (UINTN) -= 1)) { + // + // There are APs present. Re-use reserved memory area below 1MB from + // WakeupBuffer as the area to be used for transitioning to 16-bit mode + // in support of booting of the AP by an OS. + // + CopyMem ( + (VOID *) CpuMpData->WakeupBuffer, + (VOID *) (CpuMpData->AddressMap.RendezvousFunnelAddress + + CpuMpData->AddressMap.SwitchToRealPM16ModeOffset), + CpuMpData->AddressMap.SwitchToRealPM16ModeSize + ); + } + DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__)); } =20 diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 6956b408d004..3b8ec477b8b3 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -465,6 +465,10 @@ BITS 16 ; - IP for Real Mode (two bytes) ; - CS for Real Mode (two bytes) ; + ; This label is also used with AsmRelocateApLoop. During MP finalizati= on, + ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start= of + ; the WakeupBuffer, allowing a parked AP to be booted by an OS. + ; PM16Mode: mov eax, cr0 ; Read CR0 btr eax, 0 ; Set PE=3D0 @@ -487,32 +491,95 @@ PM16Mode: SwitchToRealProcEnd: =20 ;-------------------------------------------------------------------------= ------------ -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, Pm16Cod= eSegment, TopOfApStack, CountTofinish, SevEsAPJumpTable, WakeupBuffer); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: BITS 64 + cmp qword [rsp + 56], 0 + je NoSevEs + + ; + ; Perform some SEV-ES related setup before leaving 64-bit mode + ; + push rcx + push rdx + + ; + ; Get the RDX reset value using CPUID + ; + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for RDX + + ; + ; Prepare the GHCB for the AP_HLT_LOOP VMGEXIT call + ; - Must be done while in 64-bit long mode so that writes to + ; the GHCB memory will be unencrypted. + ; - No NAE events can be generated once this is set otherwise + ; the AP_RESET_HOLD SW_EXITCODE will be overwritten. + ; + mov rcx, 0xc0010130 + rdmsr ; Retrieve current GHCB address + shl rdx, 32 + or rdx, rax + + mov rdi, rdx + xor rax, rax + mov rcx, 0x800 + shr rcx, 3 + rep stosq ; Clear the GHCB + + mov rax, 0x80000004 ; VMGEXIT AP_RESET_HOLD + mov [rdx + 0x390], rax + + pop rdx + pop rcx + +NoSevEs: cli ; Disable interrupt before switching to 3= 2-bit mode - mov rax, [rsp + 40] ; CountTofinish + mov rax, [rsp + 48] ; CountTofinish lock dec dword [rax] ; (*CountTofinish)-- - mov rsp, r9 - push rcx - push rdx =20 - lea rsi, [PmEntry] ; rsi <- The start address of transition = code + mov rax, [rsp + 56] ; SevEsAPJumpTable + mov rbx, [rsp + 64] ; WakeupBuffer + mov rsp, [rsp + 40] ; TopOfApStack + + push rax ; Save SevEsAPJumpTable + push rbx ; Save WakeupBuffer + push r9 ; Save Pm16CodeSegment + push rcx ; Save MwaitSupport + push rdx ; Save ApTargetCState + + lea rax, [PmEntry] ; rax <- The start address of transition = code =20 push r8 - push rsi - DB 0x48 - retf + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; +o64 retf + BITS 32 PmEntry: mov eax, cr0 btr eax, 31 ; Clear CR0.PG mov cr0, eax ; Disable paging and caches =20 - mov ebx, edx ; Save EntryPoint to rbx, for rdmsr will = overwrite rdx mov ecx, 0xc0000080 rdmsr and ah, ~ 1 ; Clear LME @@ -525,6 +592,8 @@ PmEntry: add esp, 4 pop ecx, add esp, 4 + +MwaitCheck: cmp cl, 1 ; Check mwait-monitor support jnz HltLoop mov ebx, edx ; Save C-State to ebx @@ -538,10 +607,50 @@ MwaitLoop: shl eax, 4 mwait jmp MwaitLoop + HltLoop: + pop edx ; PM16CodeSegment + add esp, 4 + pop ebx ; WakeupBuffer + add esp, 4 + pop eax ; SevEsAPJumpTable + add esp, 4 + cmp eax, 0 ; Check for SEV-ES + je DoHlt + + cli + ; + ; SEV-ES is enabled, use VMGEXIT (GHCB information already + ; set by caller) + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; Back from VMGEXIT AP_HLT_LOOP + ; Push the FLAGS/CS/IP values to use + ; + push word 0x0002 ; EFLAGS + xor ecx, ecx + mov cx, [eax + 2] ; CS + push cx + mov cx, [eax] ; IP + push cx + push word 0x0000 ; For alignment, will be discarded + + push edx + push ebx + + mov edx, esi ; Restore RDX reset value + + retf + +DoHlt: cli hlt - jmp HltLoop + jmp DoHlt + BITS 64 AsmRelocateApLoopEnd: =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63060): https://edk2.groups.io/g/devel/message/63060 Mute This Topic: https://groups.io/mt/75718569/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 23:25:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+63061+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+63061+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1595390810147829.5514274166604; Tue, 21 Jul 2020 21:06:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uTPAYY1788612xJK9eqtDEue; Tue, 21 Jul 2020 21:06:49 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.47]) by mx.groups.io with SMTP id smtpd.web10.11919.1595390809169582105 for ; Tue, 21 Jul 2020 21:06:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TjSJTlXYRGl3Vg3xK1e7R7HWSGpYpIn2QPwyhANbHncurBwa/hZouHEmPGMIODNMdG9aQIAyRGsVDhMfsOU8yGXI9jx2eMX4be/+MOSTWj+Xcno4BoLWu3vid4zR5BZIpMRjkySCZNYA3T9Cf+seJa1ayyf1yG4FmY/qLCvkjxN7P7YmeX82HaAl/u4vVdhxj3MGIsBA0DO2vSX50h/hux6G+2AkdseJTdSRljD8pmVtMv3Ydsaaa9meJMD2GuGgWMjy6j7AJ/au8CRu5MMeUypl5FtjWtoiorgNtp7g7mPfahgYe3xi29sXCVBlb7zmRP0qZNqqvNra1btKKb3BqQ== 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=Z3k8tTZlrxl4DrDU35VneXy7HkF+21ouyF6ICRsQ+r0=; b=AwSrVw6WZivJBdE7l4N7sWcIynHHb7CEe+ja6P0BqbAcThLI+m4BUcR3os6n6IFToa+gIrhZAGtlc1Ld3tCBKP6U/8yoJtL3UNi74dV24otTnF0NW3ypMgYJOoSPb1reGG9XUyHpn0uhAhhiz4QoWDSaKCUxnqL3Wh+O7kIq1pqVPmHR/nGwjEqqcdsj9RUibZGK9s8r28/S2zgPsOUcff9KztBFw6znAI3SfWE2oR1d8yZhVsdfNQTWicU8lyCc05RoWqYnRInjTpjYD5jfpszXCY96xvPJXxF/kUIs9J9q1eLobhwYqnX5v9r1zWE+gvuZXScETVvUjCzib1IkOw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.24; Wed, 22 Jul 2020 04:06:47 +0000 X-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.021; Wed, 22 Jul 2020 04:06:47 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v11 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files Date: Tue, 21 Jul 2020 23:05:50 -0500 Message-ID: <39f731667f4ab2c5041e70cce5dc9b420345adf5.1595366363.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0009.namprd05.prod.outlook.com (2603:10b6:805:de::22) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0009.namprd05.prod.outlook.com (2603:10b6:805:de::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.14 via Frontend Transport; Wed, 22 Jul 2020 04:06:47 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 65ab7495-ebe4-4778-9986-08d82df4a751 X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Flfjdeo8HMhTRhgSRf7vq510UaGoqm4AfZH6cUC3QkI6g0TF6HTfszteMP7KN9D02t9jyRNk7x2eFk9IPybbmb46Lz5n3bbnUH3QOdbjmCkzEj7WLjTZAYponmle0OsOa+wFWt1rA6G3+LTJ0FM0/vwEpFBqN4iU37fm8r8nikpVySxPT7eIIaQaFpy8K3oxJOaMmGXl8D6uLpKho8B/DEyNUO+jLo408e0v+N2PGSoHLfWCucn6i6+9YUTlbFCanZD4JxzW3x2YKiJIbr0ILFABRClLrcLAj3IDBdlniK1zaHu3QJBMb5r+3NU0Ccxyf4LoF0oyA63eXvxOy4jWP4xzbv9+if+EyXWYVtYyy+kPs4D0Oqgu/IHbnbOVky2s X-MS-Exchange-AntiSpam-MessageData: TNH2ZKeIIBAocpCBcrE5R59aEBBEBLfbp6WuZcjuzd3cN2oczq29VfL6/sSE774ctJWEV4LjmsmVJGq1EM+Z256GToni6OdI8S3STvOjUPIlE+BkXddVcnGiZikFteRnOSBruO1xjQl1lgqtZv5LzNrlYy/ywX6GPja+EwWwyLjyKbKmDluvuKrUZJ7b6yeCjYKFMgsp3QKLlnadNFFEI5/ikt7bdHSUvrW/FaNKfgNtLJEqYp+rhbJQ7AqON7d8xLUwl8GSZZUU+I7NyxNLpGqakQoSTdjQJQlJLyxlSaxOEsAaxEZmzgTaMK9LH0pszRRO0tQFecwESE2k7C7Xjvh51r1FIMuzFf+Vd/H9ajg/XDi5WZ5em7wGYJ36fzSFh8/shikZLZm6igRq/EUS+3XBv+rU/UoKPF9pjmKgfaVnQ/3sekqevsMvE2Sbfrd7keAsbnb/vQ2VA2XDQ9rSPpiIlAH1kyG6EQfBPzY69nk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 65ab7495-ebe4-4778-9986-08d82df4a751 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2020 04:06:47.7587 (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: W9ITq0snmNldhxzNzgE+NfJnIs5eBXLDHXw1yNtynMY3x3B+Oz1H5Byiw3Fsg67JF5zp0w/4LYcYCNfQAEEUnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 0VuFsX9YEioPmiddBa9mG7BAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595390809; bh=xGwlpq/joF6Ob0FO4qJP4WcZ0h0W95S6WVvYMyGUSgI=; h=Content-Type:Date:From:Reply-To:Subject:To; b=VgSDAJN5wNISzutvVwhOJGnYle7gVTpCMHMua3g+9DDs0xdrXRVuiaz6spIfs5xy71T Ir4HlfN5FHPjY7H7KWKKVmNIuA4QV9nGL0m0oVwDHBd753J88eEPxyRIIhNoWjnI5W3i3 FUjz0CjSctzDfPfsHvttWkoZSj5Y31tB7/Q= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky Register reviewers for the SEV-related files in OvmfPkg. Cc: Andrew Fish Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Michael D Kinney Cc: Brijesh Singh Acked-by: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- Maintainers.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 599f94d57a3d..3326b9c2fb63 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -411,6 +411,16 @@ F: OvmfPkg/PvScsiDxe/ R: Liran Alon R: Nikita Leshenko =20 +OvmfPkg: SEV-related modules +F: OvmfPkg/AmdSevDxe/ +F: OvmfPkg/Include/Library/MemEncryptSevLib.h +F: OvmfPkg/IoMmuDxe/AmdSevIoMmu.* +F: OvmfPkg/Library/BaseMemEncryptSevLib/ +F: OvmfPkg/Library/VmgExitLib/ +F: OvmfPkg/PlatformPei/AmdSev.c +R: Tom Lendacky +R: Brijesh Singh + OvmfPkg: TCG- and TPM2-related modules F: OvmfPkg/Include/IndustryStandard/QemuTpm.h F: OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63061): https://edk2.groups.io/g/devel/message/63061 Mute This Topic: https://groups.io/mt/75718570/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-