From nobody Fri Apr 26 18:26:44 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+63478+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+63478+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 1596134669111302.00353848153986; Thu, 30 Jul 2020 11:44:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ohTIYY1788612xNgZngbdm4f; Thu, 30 Jul 2020 11:44:28 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.65]) by mx.groups.io with SMTP id smtpd.web12.1705.1596134667909953693 for ; Thu, 30 Jul 2020 11:44:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h624bb5tHO4DDmQXwRzQsel4spU6SVjnK9Rb5m3Lme2eCVU+Uk4A1Mp05TLXVZfmqEKSNsHf3K7eLjLt1aRyrvf5sdJdCHQFuFjZgVpkLy6tqbTLEiJBPFt8wB9s8jdMkWKr5RGJHcAUlleHweHlnEhAzolXrrserEM5s2+pOWjxARh4Oh2cwkvyhm65YElhC79Na2BAmT5dZ/mYUVEmmYiwCzGFlzikMqt4dZAgId+4xW5VoY/0HzMAX+h7ejuB/HDIdmjb9AzYqjp4RAZFpcDTTQ5Z9lWpQlcpdUEAudIjIe+WNFAe4AcbKNfa68kHOZbiwvhGsUy8H5Vqq9Thug== 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=0iWXAO0KQNMgWvMuC4jwyd6+UTXjz54o0VItCB/P4wE=; b=oAEfiYWwRSQewHuEu1aNRFn+zSAcQWOcd7+Fjplp6OPv6wkKzaA5oHodr7VTMj+sr3pLjtbZAJ82Rz4rdK0v66EsYEC8byq/bblmDvhJEMCmN5np9F/AZtsSGJN154N6gywHuYj76R+ECgOTPOoqR91X/k2zxgZRo/4RwfXET5sgSY2qWem84Jq0TLcArO826wP4lHyeBS5nbJVnqJqAfyEoouyPTd0G76tNFrlToeKbBQKEnfgiQzKqCFfzeJrvDwp8pCg6Vn2+arvbA/lAQ0ye6G82DTTiBNNEh63I+H3nH6r7WrVo7OXJSeYY/ts5h6Iknpm7RXG9JSwGoAJXUA== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:44:23 +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.3239.020; Thu, 30 Jul 2020 18:44: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 , Jian J Wang , Hao A Wu Subject: [edk2-devel] [PATCH v13 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES Date: Thu, 30 Jul 2020 13:43:13 -0500 Message-ID: <5165cd142314eb080a7250733cf66b045eb9bf24.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0010.namprd03.prod.outlook.com (2603:10b6:806:20::15) 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 SA9PR03CA0010.namprd03.prod.outlook.com (2603:10b6:806:20::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24 via Frontend Transport; Thu, 30 Jul 2020 18:44:21 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5ae65f86-c0a4-4406-8191-08d834b893d1 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: xwIlfzGuCgZtnthcV5wCRL/cs2Injw/ADbgSeOPHws3rSeTGAC7R9pf1hePHvA/98YSQBXdiVNADsl+bceyrfmojxstJWuhnra/Acjo5fwo+ZZp/WFSv0KeOeig8ZS+BG3QiqdtXX8doAQdUMWfMYyO3Q4LXUGMJksDzAcj38SOdOy/FJquqmDW2vpkht2CLBrTdBEYoD+aezRadF/rwQhBgnl+LCom1m8SYTTomnvRLeXxNDgppQD0nzHUa3QPRP5KFoDyhOCNgfRZkVZ0QVzTwzCFgxIuMZWtijccDvPmxEoYDRubTTnZVkvW17L1Rriu6uSLZEseqfunAcom1YZ6q16CxPtNsODekmFqN40Xhcx4CsA15sBTKYnEFjSgJEwnIlLYSWXDqRz09YNoYss7m/omGdzdgEAdP5D7+8FhOcrCFQtvCvMwJ+y2Gi6Vh+J7x6CstHWRyVlpaImkVQw== X-MS-Exchange-AntiSpam-MessageData: iioqSuIaOYICVE+QNMPqWV+tlSlETPJw7Vx8ymzhqjydFqJK2FRAoQY4xweHVPI6T0iE+PJVj1kx8HTn1qIcnMIsurDsUvLhCt6gV/w/WfY7JsC2znqoue/DSwgTtGJaYpm+0NUKeVz+42tKAUh5+y5kpdKCuEZ06xL6z8MYBAxgzWRS1HthKazC8V2u5RB6twYgIfkWAO1KgF7FQV2Yz84RCAoq0wfWbtAUnKb0XeNYnPBkrls803LW6drAdPlclYf0jZblOM6dHOp8OWZ0pft4F8hZ3i78JLtKO15MoXISgSh/C63ypARriJvoH/f53v5t7QpA/ivYu3QL4XRIBa8d88D0vfv2qp3B7eHE5zt38job3UeYKnA5z36doYeyafpHAc9yqW4N3PecVSlbSprw67XWVASoMBAEYTl3TpkUA50oIEWJjN3+qrnOuMIi8qU71eazoiKeycLtGRcrR/l5pkvjnYOKHUPmAghpbEo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ae65f86-c0a4-4406-8191-08d834b893d1 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:44:23.5241 (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: qm2ZDBvsJiLYV0tFGW+69Bbo8Y8XB4kt8r0iRm6nlqMInxmSQ3yWbawXQXGOrLkMwMu0rAl4NjD9swxFTKVCIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: 7mUexukZplNunktSosvfCxkyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134668; bh=8m7aSQ8rLkwjo8Mmts4BZG2jsk7BlLOoKdxDJHc/eGw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=HCW+QQVyQMnGGZyco/Vdd2A2kTl3FD4QFls7rx+mBs1abaZuPBoepV2CVUxlnGBiFuf urhFCANRffQfH3ZqtBEIsJDKkrnQXlUgRog5DoNtTdEZ0polHd2JKSm7gGrhtQyExn3YB QFWhCe8SVYSEFhqNjlksJar2gt1jsx3qLXA= 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 Reviewed-by: Hao A Wu --- MdeModulePkg/MdeModulePkg.dec | 9 +++++++++ MdeModulePkg/MdeModulePkg.uni | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index d7572eedd18c..882f3fb28506 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -2063,6 +2063,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 5235dee561ad..1d2a50e23623 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1303,3 +1303,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 (#63478): https://edk2.groups.io/g/devel/message/63478 Mute This Topic: https://groups.io/mt/75892664/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 Fri Apr 26 18:26:44 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+63479+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+63479+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 1596134676769955.8602609761924; Thu, 30 Jul 2020 11:44:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 59j9YY1788612x58HwJ5WlUH; Thu, 30 Jul 2020 11:44:36 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.40]) by mx.groups.io with SMTP id smtpd.web12.1709.1596134675763256094 for ; Thu, 30 Jul 2020 11:44:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P/v+DDgx7QyAHJcYIgPhWBLjECAXxvbipXV3qfzEjBSE/9UIYb3PM5cJ7V5UoDu/EsYg6GNLMXIHKzUhwn5GPIqcEKACrFuwN6j44rxiQ54q8x0TcANEipKdeMXD6R/M5Zo5m+pQsF80yuc5S/POjZUtsLopXCkco/tWS2Svh1wiBg2Kl1Nbw+6IT9CAmhNHeJ5/PHenHD0tUzSgJpGe1BZEWudNVassJjmHxNQFsyhF2q8S55R9occl/etcQH60pSDk7LRui2JbCD9LCrgt5+Z+2B15SByGgWO8BnwMCa08L+B7lWFeR2vb0WFH3JxB5Qn/0Cd3akWUMNuw2Yyv0g== 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=OINC9z6p6GoZ2IcFziq+cbHUiE4DLmJwvKvylX9bN5I=; b=T6R8Uwo1WloTqOvSaazuzjZlKDoe2VmEYzPmwBTVWrA9Oz5b+kPoJ+CMyyrr5ob9Al3u6OCKwy/qIh8reaoIu9qqTBd8LMcmklgEdKwxV9ynKoEI+Wso07g8IGXAG7UkM3TcJ0Iv7QA7pJ8PEbaWj2J89eTQ8Y7Mg38vz2czlmls/RetBLAiAmpoKjkBzIHzhFtzzH3qryOH8gz+lKp+qugDdOPkusJ7MSRGsJkxRzzq58bcxCpiqRXYoMG/XbQQdH9vouIUBTvCHEDt2cCYZvIWA3TvBOr0ini1K/aWPCOP5U7NOcmnf0stwGWtqTTOfN54dFvkpq1z0Fs03xqefg== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:44:33 +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.3239.020; Thu, 30 Jul 2020 18:44: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 v13 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES Date: Thu, 30 Jul 2020 13:43:14 -0500 Message-ID: <353eca28c9e80152ccacca57fee26ac89b7bf9c5.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0013.namprd04.prod.outlook.com (2603:10b6:803:21::23) 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 SN4PR0401CA0013.namprd04.prod.outlook.com (2603:10b6:803:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:44: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: 7afbdf75-4023-4270-857a-08d834b8997b X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: o4rTc0Gmm5nUb1cOnIqSKGADrmvs3MeNcE2GdylmBZwRJNB2r87HqtSHYMM3OcmuWi29fLi1o7LM7Yslynew7uitYRycjg8pnSltJ8+0OREX/er+YXhYVemkmLviy6pDUGOUT6EBw6g/KtnVxrVxUDGA/LshFlH+jvVLd9yEc/XjscVamjmXkrU8Yj9yvYvsShMbiFRoB7z36iT4F/Fdz+K/hMJobReo4nTTXPu+wmOGfabHcuFFcRAZrExQUvj/mkykzsgChp13Xqx6RFiH9yVwAmjxxl61ewD85WUyNDsyk7lz6jZ24zYEhvhOKvkmrqewy1ruhR0JsFKr7SQBQDOERC17lGX2fZTGQ6Gfy2LyLLkgUgzwRQzK9xrAN0+u2AW7ggJieIQiRShEQFFX5s6TCpD+aOXkQ/aRRN/tnL5bwmrJtamvXA0ACnxXd8NlOUp8R4EZZYwxlun6ze1xKA== X-MS-Exchange-AntiSpam-MessageData: ZQ9iRLXL8KnETXUT2zFlY5Svc84fMCmXQdu6/71Q6abMGpj15rBqJV/xgR0x5zeXbtOTXDh1ShsrbaDWMwTFE4nL5oqkqYj7Vs311F/upBDA4j0heo9XUo+ahWkme9/kdCIgO8+pDrojcgbEleSrBFWEF5szhXat3RpuCKdHI/yK2AHNqKE/md17L45lrsSYVQheTuzevSw0PzmOcx/YaW0dysclp6Fxe0a9IhKL0wXoS6PDpFoOOcBAlEEJPDWC7eHMKzVuA7pzEe4wzZA/mRMTG0JcRq1gVI6ySrbJQRU7OXk9nFXNiqbMQ5vRaE84HJ5vwyBJnDLgucFTqMqmql8wdZz/wILYMKsgUNxyTpx0ZgKKqaqoU/XXwvp6SaySZDJG0xn+KxqUQApf+iFnJ89j0wffqveRce+N6WqFQh33AJbNv2e+CgHtjQjtd8TGLCEzc+YzId6NHX4YWfVk2zh9A0j0VkgGIc/QaWXzdaI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7afbdf75-4023-4270-857a-08d834b8997b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:44:32.9759 (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: YC5v9kgkAGT/0e4ITig7qWMBA3pJOZ4RfhyJSuscfsMRo7d9AfwX1Il+4+wUkFNUb6sEKzTGjWfpRSfONWnPDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: K1Ni6tc8Wpytfezx1pENQzQ8x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134676; bh=x3lXknYEFD20U/ch3jb61xEaRXOcc43s+QaBIezDjkM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=kBKSHHAJK7FeTux7IQ0PhGJRVWYsemG73y/YwaFT2Kq4Lvcyqfqi0Giz09ViCj1ioch qgFj6WZZjNOzRKCgpVptEAVkDTQeqlZ5SM2OoCGuKKOAtMuZmdwpKUcSdqRos4xHxHFqg G2M86SthCgN19A6kUDNt4+Bex/VXNXoE49Y= 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 8b2e03d49d07..d52912ddca1f 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -373,5 +373,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 (#63479): https://edk2.groups.io/g/devel/message/63479 Mute This Topic: https://groups.io/mt/75892668/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 Fri Apr 26 18:26:44 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+63480+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+63480+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 159613468657758.97019191799927; Thu, 30 Jul 2020 11:44:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 75Y6YY1788612xy7IZd9BLsP; Thu, 30 Jul 2020 11:44:46 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.40]) by mx.groups.io with SMTP id smtpd.web11.1741.1596134685613652671 for ; Thu, 30 Jul 2020 11:44:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DjvdzuDtS/5nkkwzrA42x8UnGphdrbxFnyEuInmNrKWtVXS1OH5YLDlYPlooPiN0XGj3EYNtTq5wKX63yIIMVbDaVwVxFFaKRw3k9bgDTf7w2nOymRMQN0MBnDF5R7MWd5Nw/eNhZxBlJwrqTMmjYvj0za9NRDv+2Od5De3D6yBnzVuFvr7M0L9GfPJuCaIykSGdg+ba4vupAp+302QNS92iwpb4O3MsCGElaEedPfYXCS92rvZO3zFq65NI+zyXjGLcGieapvq0GnpVTvP3BQrxTNAjP+zIjkZALJ4nmIAuw7yDr2bfqHcgos0jnn1G+/XRFy97AVil8SH4p7o8Bg== 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=tRE7SkFgGOeG66PvdkFIGd/IGhL7swQyOWx8HekFNVI=; b=G/aLFOjpB9N49aZnWyB81Nm0vSRF3dmm3mdS/HUfbABC+iruYuCV86kIKAByJDMwid2F0Q8O8zXKjJSYsw+cDivjVoyo9SaXYBAgTcA4v5BbBiqvT6iPksyMu6+NUm5Cf9+kXeYS2iUj8l7mvUABoNA9Fz4DsUTNCBYoj6LMLbj2S3IFB1TzBRQBI6012KXW/gzM0i3wjEs0W3dU+8GmecJdS31k6i/OgAbdZwkc4tpbvj5ssuPxWzBR6/+sDBc9BpR/w9yrRduvnMtNv3K8mJTpKAV/9ts2ECxJHEjaXJUcjMeeneXTVLDo64tyRVproktZNa8tmn9JeTSYq2wKgQ== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:44:43 +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.3239.020; Thu, 30 Jul 2020 18:44: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 v13 03/46] MdePkg: Add the MSR definition for the GHCB register Date: Thu, 30 Jul 2020 13:43:15 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0048.namprd04.prod.outlook.com (2603:10b6:803:2a::34) 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 SN4PR0401CA0048.namprd04.prod.outlook.com (2603:10b6:803:2a::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:44:41 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 48575941-1a20-4346-a0dd-08d834b89f6a X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: 1IwuNLl0jYm7jfByThOmqI8EB+gukLmU6C9gxPWJmFzapVKBoh1LjsGnaTfbfA5dFy9mgpTTP5EbMpOe8RFIHWEfOhD4PItNQq1rT0oP3A09goXW/hf5NEiP0LhPtIT7VWaYuD6ofrCADsJhaU/4mir+WHVyWSS7OvFSs+jfAxA9A+0ydOs7lDdiSIQYJceGM5B1reqxLhULspUghVlyEZO9CIjNBBZe+z/fk8NVzaQEkKXwp6ZqM15D9BlE0obqG7cyxM8fWVk0ZIswjXQzNgFIGuHSWr7UvB9tTmNYAN/+yzvxxxbjnOb/clIJSSl+o27LWW8rmglWmUke1pr/eoLgVP5+hr4zmNZCGeanOKHXd2uKWzkm7duoAzCP4j4GHLPJsoCTsgsXELsTOsswljfBQu7+lXO+2j0nH6oPw9zJ5Ubrm7fyh4AKhxy//95zltgC2T46yisPjZEgX6+D+A== X-MS-Exchange-AntiSpam-MessageData: Pj/GeqdqPYIHvV6jBeSshO4Iv4ytdgFIfppqrJ63JlTdnhPMZrVVTvyQUBhkqvsNt9nxqzHA0RPS/g3QY89n8g+XkL1nrvKnpT4W5tfP8WUCEgPkcuRkJJL9POn4r766cYJUBy5NURSy/PLj70OvTrNA6+5SJTJFoWGHMgScb++RJqrI8+jNsmhcfqKfxPwjr780IL7yheAgbmgInN5g00u+F9JoPOyjSwcoJs9PPqG6YvBwCteJ6cGzAelWHRWy9dYLxfd/OsmE9pICeuKHkK3MstcI98+1DNEvwtsX5yDdTAZ9uiSfpTnlzoU6WwVKANpUTO4QLHJNzQ3Twc5rmgEECVikA8jdJ9wT24hBPdpoK/q3Kq9yvTjhSJVCJDUN1bH0YXPzDL+7B0DDpOt2Ce/FgBMAisQJD8rBdqfPhlqUjUgd2B11dX8EIDqLsziZ/2MPHwzlOOVxYr8twVXfFGDW0F91DrzkXR2+2l2JrBQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48575941-1a20-4346-a0dd-08d834b89f6a X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:44:43.0305 (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: 9dJC7Tvl8coGDEsXmmNPZX4Vf6ziPlpqH9UCu4xk2bYAGd1Urv3zLX+gFRVEHVScRZc+nSp6Mz0kOz4YilmZEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: 9xypKoVsNg4GLsm2aE3vv6Gcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134686; bh=bRL3X5sMkmDiaV5jnRohVGknQS+aKuDofqAUQWT0EK4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VOPZggaFoUZW0wV1883QIpIzd2uziswGX9uSV4SnqkonrjA7JiGIS+7GU/4YzfXE7eQ nLI2oy0tAE8izrJHsHKqgIZvGASEqi0K/wS3fv4L9p+GxxY5frbkBYtnj538/DHj0rzxM Hvi30JyUk0aukePCqV7X2VT96JZ9DAyYRd0= 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 Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- 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 (#63480): https://edk2.groups.io/g/devel/message/63480 Mute This Topic: https://groups.io/mt/75892670/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 Fri Apr 26 18:26:44 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+63481+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+63481+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 1596134696792583.5485757877046; Thu, 30 Jul 2020 11:44:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id slKOYY1788612xBA4j5TJvA4; Thu, 30 Jul 2020 11:44:56 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.89]) by mx.groups.io with SMTP id smtpd.web11.1746.1596134695473364706 for ; Thu, 30 Jul 2020 11:44:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2QUAvLCvzdcuP70OpdJURneTrmjGe67owOq6C4c6v2IRmVCTCyTfMJsjBSwWEf1tVcyX2o9mkPZE/H3PHyiPYc0qqQlFhs/IJvy3B00g31uoRITgtk4mLV+wS3b3q1VC2ebkca7Tv8uChSuyGTg/WmHXrDBTNn0YlOe13ZXC2bMA4haLZF6VG1ctlKtuOO8ZP+fCssPNLt+J26TnHYNkJTItsEkAzVc6znrfrVZZ6pHzZKzYWbz2Er8joOthj8K2/yYpHe++jziC8qELFiLxRWTHPkOxIojLJultk31Sh2PtfMmIJdqgGtHm+hbh4ELL2Og1DeVwZ0rZBQGED8Rqg== 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=YYkVB64VTGSzUnAsN8IQEH1S+2akt7TobPcbdBPWZn8=; b=V5LkREfg+5IrgurId/tA6M1V5UREbXv/xVwYHjnhOWUwkyebnc0sCIkT/Eg392sw7mWAMV9mwz/dw4us7yltC3aXUtrK2+cCAVozrJnyi2HOnw6Cyf9AImDEiyDE9DoapgJRFETksVovc/q+aecSypS9SHBLCp7887wgRjrvkJ2s5FjqhEDpyDJi3ab/Dm3X1tPIrdGxJAWV7sJSH0qXUzTrSTxrXUNpN333PmmZ8hcCB0EOSLVv0sjq6xX4I+oItdK8DmfR2XU7//AxcQHhGZ0BnKXk3hYrqOr4/k3EqW+xoor3JogmJYvKND//tJVo/NAAmpam9EvEJR21qugFRw== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:44:52 +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.3239.020; Thu, 30 Jul 2020 18:44:52 +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 v13 04/46] MdePkg: Add a structure definition for the GHCB Date: Thu, 30 Jul 2020 13:43:16 -0500 Message-ID: <1868f4d686ffaf8edf633d5902c050f50e714153.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0038.namprd05.prod.outlook.com (2603:10b6:803:41::15) 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 SN4PR0501CA0038.namprd05.prod.outlook.com (2603:10b6:803:41::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Thu, 30 Jul 2020 18:44:51 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a7602788-0d47-4423-89fa-08d834b8a529 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: BUoJqhIY6hdfmm840wQpdQfRCWT8y0NiImQ4GU+Dn+vlGgsCWZQXuFDuxtO0+6MSZoMxVeMK7vnBevMNFEWvpQPupvqgUJ1NIUVt+6rFdyolF2w7HZwEWDbmw3QfA58hJzQ65KaltqQZU/C7a2KDC9XhDJcEJdjk7o3/DkXi4q4a8VtmzhxJ+WYwslh3sKRhjgOCyVyIB2yt/kdkpT1dBk5n3HcrcwAas/I1SFvp/EKO8ZSLaz3jFTq+4JBQkIJljKsOrJvIM7GGJfSLcid9eeOwsXWFipN6MSzRMw+TFCDwdswHt3bVNQJodxLI9c9P7ZN09mrzPGBDgYyzVZAGZMryswR1PXrZMeIRWkXfkaVvwPe2kb360IqmFjvdp6LrUWYHUkh0yupXBpka5Dm5NzcekVTl2TjnDWpKfnCT8C9J1ZAeHShdW+Ol1Lu6k9TjrxIsYBd1OvEafD59cGE24Q== X-MS-Exchange-AntiSpam-MessageData: +eoE+OdU2JWH+0vgMGcWrHbyAXqzcuZexnLbIW5CP987OXt+evG4upub/kzdMTv+u3REX9C9qZvscZ1ntwUM6LwHGDg4js5XZbjBluPDMuqEHTbkMl6CP0mSEw2Nl8NWjyfc1w1hHr5Tr/GtgphEJOxoOt+spZzEjplDDVANT5qwgvSMoHSHz9Yf3r+aYVHAkmfGLhmnWGpuCPteW7MnnoghxF3mDtA79nwehfTkSslhemS1bHYGWGsOJG8N8r7HNneWjAVXwXdQ4AtjWXKwtDoA8wLy3D7Rg6GT9ZcG/g8b69woQlvPFUIkCFmAjLdiVOhJUXSnqAjeSWRXX5iqinoEbqxm0O5OsR7fDLkPiANjt5GdCvtNkZeAkkKyF+vTO8ZCa+kF+YVLMSGZ67oQHjgyEfIYgcd9xQtcagYEItZJbvAOeB2DVQBnpNRE1j7zSOG+QlYzhCw9IDjWxUYb8E8euI6/+IL8+xk4XagWW4Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7602788-0d47-4423-89fa-08d834b8a529 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:44:52.6363 (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: WPQQJSNOt2S4rDwava4r555pBKgoLqG+Q+PK2irdjrEedzzKPWjKd6HWTbNU1hNGPeEQiG0WejiRl8Pikklypw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: QmLUnxdXnLfJ7W5lWAQo5c6kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134696; bh=55z7DyoeIBqGoloUL8Dq/aWWyvRF7nGBc2Siw2YW0+Q=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=v+7C6SOiCpHwfKnSOz8T1YrzWFhmsf6PqX6K/Nr5RWkOqaFG3sp9S7RQ2tp1C+SLhqh +oiI5dT7OqXNeFBJYuxjVPmITuIS7UmS/6dpkE5GCjPOr7FW6J7Ja/ZutZKr//9cDR6mI +exLCqOyxU+pa08TSWCO/agrfWzMeMAgNYU= 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 Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- 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 (#63481): https://edk2.groups.io/g/devel/message/63481 Mute This Topic: https://groups.io/mt/75892672/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 Fri Apr 26 18:26:44 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+63482+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+63482+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 1596134706623151.65114702590427; Thu, 30 Jul 2020 11:45:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QKiuYY1788612xSOXUovbX8N; Thu, 30 Jul 2020 11:45:06 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.47]) by mx.groups.io with SMTP id smtpd.web10.1707.1596134705570295509 for ; Thu, 30 Jul 2020 11:45:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZcKWNMk6dDBOD0rcPvuBwtxzFUheNtnlJVsjvYx35hYrv8aNPM/PbAI4jUj9Z3jRnnST2mNw0M/hBUdoXj4VGSlbwiHHL5l0PXAobw2CzwUHBMBWXQ2Elcc5qMSx08k1JT+Uso6joCjDlxAzkN5tnoASIuaUVtozf/QefP2uUHP3e5VHjQlOlYzTV9Cs5SgYWW1dxRQx4ZXuO6Eu8ZPYeKue3pEjUEBukcYSOn/FUX/moTvZecX0KuWYSTm/KXGKKXIU8fL3XkjXfnsEFikGcYkAAA0/bds26Hsd5jnUpVYOiSeigX5kximJYEHJDwbGkCpAfqY/6ilCARIq5wOmOQ== 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=bJEg5xG+7vcLxz3IYpPOgxogw2+14xwA/7wozPmxYNDJTe7PS0XRe9l4nGD2PWdDlLdX8ePZQvkSwuaxCcD2isKw03yRQa5diK/sx5k9dCQpr6eFS2KhFLZ9Z0jYkvx1hs1lmqVHWw50RTZO/W3j4+sMwtn9mwg2b2jevdlsVfgS6e4Niu+ELCHB0BMs4KNXv2gIms27MYN+6tv7wgqStvs03PpxQXRf74S7vM2l9I37vY+4gb90hw/+W9QVrd1Hc1xW/wqY7Eur7bU1sAdDK7THSnnipX+dusNb0Vo9ggTBcAn7zh1k2gSnE+7/1pm6NQM7Sa3sHogseB/ltQ/nfg== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:02 +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.3239.020; Thu, 30 Jul 2020 18:45:02 +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 v13 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Date: Thu, 30 Jul 2020 13:43:17 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0064.namprd02.prod.outlook.com (2603:10b6:803:20::26) 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 SN4PR0201CA0064.namprd02.prod.outlook.com (2603:10b6:803:20::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:45: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: 343e41e7-454f-4007-fb9e-08d834b8ab26 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: qWslf1OnRBpKbntyWoNl9RDQsLtX2AXvY8E7/40AXI9ZlMNZS6aN/Yxw+qA67lzhljGXpBjRYBFaGoAD9QxjeXGY72U8Pih7HnXBLeHNsDz0tUJnGWLuzxlUze4QLv3u6DG2p4S+v6hrkEw0iF9N1dMCKhGXXMpRcoo7TF97+UagRTWZCFPqB7SHrcJG+ZFeZkaIket/3hdl9dtx0caRwrgdYRMzlkj9m1CVckYmeRqlEbrNRUJOiwRgi6mZyv9AUZYxuNf6YImSLVcaMYdYCtJCR1YEhjNVogApIXYcJ6rQgaa1ovhI8JWjhybt1C9YJYIBuvPsifTskHpZFtGaBeII0LObs62nOT+62wUOmPwq4NaqlJbyecyRZtX8pynaYpDxwt0se6hjl/+ozMP3w3Mt9/odns/QG6MvXBs1j0g2/nupFL+OnI0h/yStVDBRYvjjIeCkHwDDPWrTeIu4gQ== X-MS-Exchange-AntiSpam-MessageData: Ao+nzeBF+K/kDG4adGILe+HOJjecC4M/ht/HesFbfd6thorxeBTvRMWRN+w1yvtRbNRiXP4R0R50A/9oG0J+v6ttT5o4AIJYKfmJh420AQ9h7YEtL8VklbQzGNc4xBIP56n4IPzn84eDEj1ydComtmnrjU3jyLWyNqBpNw5/JqhN+tlqHTdGoutta/nRl2P446bu3rIyyRs5yS7TvhRiLDtO252F3ZCwvHO1iO/U2gL7NZU/YvZQaIA/E1MFJTHVG+DqKTm9EICO+kdbecd/Z1V4GCbnaLqyByjp45Uy6/LvpuYAByGwtE0k2w6jetsqfX2p1COKUhBz38xvtWZq79QGWQNpFg4+OMGFdNNR25Vni1B531tb3cdJx79pYGiBpdZyZQWlv92AExSE3L5axMxgsXp1qmcvK463NhcrGO36eerV5HZPBl2IqHTvN+5yANS3ezzBEbW8/3O7MxbRFb6yFLzu45aNshW5WMRTbgY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 343e41e7-454f-4007-fb9e-08d834b8ab26 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:02.6419 (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: 2yJZRdienjmpz4K6H1wCEVj+gAs99bohRLlgwB6Rl/4ILzS05n93VMUZR3SKHsyR6SDMLoJQk2/stmK1rfm7Yg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: DgUR4T3Gw7Sv7WOdTpjW0wYHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134706; bh=Mq5kI7304bhtWxVLeErFGHvkZO0Dqjoej540PTmb1nc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cpfwPBnSkQDZvYUPXwcd0a4vluTZrdZVG6HUOb0tLduQ/a7ixMRwks8OSd7kyWSHJw2 hV6YwBpeS5Bw8tKmrZa+D5C9sF41OrKHOev9zQ47in5jUoBhz82ahqGDlfbreTLjxSdZm vGzyNmVCZotLWdyi4AfOtcSESMJSlTt9oJM= 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 Acked-by: Hao A Wu --- 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 (#63482): https://edk2.groups.io/g/devel/message/63482 Mute This Topic: https://groups.io/mt/75892685/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 Fri Apr 26 18:26:44 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+63483+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+63483+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 1596134716018719.6222423088935; Thu, 30 Jul 2020 11:45:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id T0DsYY1788612x1kNfHptMFB; Thu, 30 Jul 2020 11:45:15 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.44]) by mx.groups.io with SMTP id smtpd.web11.1751.1596134714981899713 for ; Thu, 30 Jul 2020 11:45:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kZ1AYfc8SAFWJaOVeINSikYui2hDeuZLV5loGsqeKDBMED8gtKvX1mPQAdhRlnlwkz3+rBPiLg+JkTnbnN6fhQEjpuH0oozUgCbCcKtPdxVd7+/6tJMEFL4Fjejad/oLD8f8iW+e9SL855f57+D+oTZBAKx5yD59LHaIp7Iv/SV2BJHgPIgOVAfF/iqvacxkc5VvqE5uPy+Y8e+YpkPN6zObMFCUD2x4OwHLn0iS+othx11PBln/VQHucj3ZFw9+3VNazxrNccDpunfPiGVgDPthFxhsYL+85TjK+4jkcSJQG4/d4pJDQMZvE+G9ev1U4RaTiWeCR2nj6jGWAxsyAA== 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=g94cNBqzH3Pv2WbNbKL2BUYjnAJh6O9Iy6b2wbCpMvU=; b=AEY4E1Mzfx9IWY/kJYoDtgbZ6lH7tMzsOA9vaNiuxwHa26vuiRLa3PBtCX3VHk/uyDcCSe8Pelx2+rKDAyoEic+c5R8Er4QyPnkviE+XCGlPUE44/t20ZoozyxBGDewoAWvHupHgjqU/5P6mJbXbNRZYO6ysbm59uhniiTBwtZN7G4soaBUzHab0tWcf96fHBnVAL27saMpsYlfpegbrZt/4kOcGaIalUsVs8JAw0wzGzcaYKnk2Hu0WOB5gCReU+130t2XX1b2DXTQdu3y6XHE8r02sCKBkmV4fM3R8Ily3HNfI4oq5FsGeoCsTtXtjR9wnnY1luM7auUPxooyX9A== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:12 +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.3239.020; Thu, 30 Jul 2020 18:45: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 v13 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Thu, 30 Jul 2020 13:43:18 -0500 Message-ID: <2bedf06b49b28f260377225af9e52609d5500efa.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0125.namprd05.prod.outlook.com (2603:10b6:803:42::42) 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 SN4PR0501CA0125.namprd05.prod.outlook.com (2603:10b6:803:42::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.10 via Frontend Transport; Thu, 30 Jul 2020 18:45: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: b9666beb-a013-4339-9ab6-08d834b8b0ec X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: ia6KSbriQAWWFW2C6TrQSyN7TsEdBHJ3mpLLBrncAWJPNmhTpb0B2PT0hq7OoJ/gvwdBTLkKRn5/C3N6Fpl7X5RALNohaA1x/bFNDPL93To8wzw25pXHv0zYr2aXgEjql6FHdgtZxTfWl7vStQq5g9OUljVffu8JEeZ3DI/idhDKros5HLZuR6zZlHYpqGKyRE7yyeMFtentZYhEw6NyIzneMQAQU2K70aY41yq6tnOtIBPuZlWL7r/9R5MGchncPd1Tf8UpiQi+aWjzsFw4JYkH6ifkaZJdixtcbBBvAVps9vYyX7J03FOEyjsp0aQvjieNBuHAEjiNo0YqG+p2ei+/3avSqqoEuMZ/npQiOlJ4X/SEIumDCxdH5+K31d3YbesSyHBO3+FI5eDrKhWyzCdMzUMJ9n/fiNyvgTwjUjEOk/691pqt3j7RMW+rIoj7A5pHLWEGAVGqtxnMqeulBA== X-MS-Exchange-AntiSpam-MessageData: HzbrXScoolI6u2M+2IVAXvoZTjldY1hgYUiH8vFSJXDqGXyOKqCeDtRvkcDEIr8wZUAsle5uDfWDrEwrY16rQy07t9txsT3sEBuE0QVslbhrkxPm3B0DckHB1lD6ut5/NPyD0fIRRElbx+mYq3hWDt43rpNb1YbSGsPqnwaixPCpmLVEUpyswRTN1btDehB2maRBINqOtghKCkaZEPJ9M2a6KsThvCXJPweB8qvjiPN55HMV+psasVcXcpRvSORpwVEGLUZgcpsZCV2a8cWr27K4oAkDm/O3In4mP+m0ca8yNy6HvTycsHXdumrIUclYI8ITYO301GvgGSAcfcwL63JsME6FQRqsTCINRv3/sIylr13xlQTD9PbVPVh9XfZi7x2I31zNT/aAu480IwThs73OiczlIj8/bd3gLSnzAl0XfNkWapYzcpfuMMGJhZaz9Lz9rNHxcyyuoj5vsFeY9FPGXzBogrrra3b/K8MZOCc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9666beb-a013-4339-9ab6-08d834b8b0ec X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:12.3326 (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: P2VQ8ELd+u9DcLNBBAjd5sHWAbDOnGHXUqMBTzWdkvN48esQ/2mkCNza2jXBk48viHg53XnxeSjJXaJGiSFt5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: eTDGDGzTFUAphbKgU8HW3zDCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134715; bh=XfqrHOTBYKfWly/uaHb5JPwQnJO5FEZl0m3UwPKtUWY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wT4QQptOBKX5rMchJnl2QUGHzT0mMHU2Y+571qrvdG8mKsBvyPmWU19PQTXfX4IFV/B maPvPIhST1Ijixh/AvTeyXrYnnRpUyZAaAgWGDQPfKq7V6PZADes/YZuMqrRf/12sqCql CAQaVo0Un+m0BE/PzY8uN7B90REMtY0Dads= 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 Reviewed-by: Liming Gao --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 17 +++++++++++++ MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 ++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 +++++++++++++++++++++++++ 4 files changed, 84 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..3b93b5db8d24 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -183,6 +183,7 @@ [Sources.Ia32] Ia32/EnableCache.nasm| GCC Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm + Ia32/XGetBv.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -315,6 +316,7 @@ [Sources.X64] X64/EnableDisableInterrupts.nasm X64/DisablePaging64.nasm X64/RdRand.nasm + X64/XGetBv.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] 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/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 (#63483): https://edk2.groups.io/g/devel/message/63483 Mute This Topic: https://groups.io/mt/75892690/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 Fri Apr 26 18:26:44 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+63484+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+63484+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 1596134725574156.23708777911884; Thu, 30 Jul 2020 11:45:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZdcdYY1788612xK6avbWCQvL; Thu, 30 Jul 2020 11:45:25 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.77]) by mx.groups.io with SMTP id smtpd.web10.1723.1596134724466807625 for ; Thu, 30 Jul 2020 11:45:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fT5npP5xvcfNfm/qLlkFYcx9jBCxWJXjohDoA476qeOJaokp4p3i0DDG1x3dfm9Ss8tzyaeJrwWQf+LjeXaiS687XGnekXXoX4tIoivfUGqY75W+ye9ozVwSBGjTdgrmmn4+p9oLmkr+pNb4IU+pRr/G5bf9mmT4MKLzUUpj411cPnATOxBtzqr5LUAPmMBvpgf8q62aJ2qikO7XCOWcv9y4dTvaVSnjVEJ4K2PEs9KFW3yN5gr4E6b8SKaR6jomRudhkFrWlD9ivohjr5U13vm9FtjNhG4YswfFRPbUO4Qr54s6biw/QkPn3SinyvEuxKBDlu5+IheOD8kZcW+jAw== 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=wtj544/t64Lo8TNHL/DjTcFV0mcHUy5IZTtfblArQrE=; b=nmDTe+uZvLpgC9IOgy7kZdsMtI8N4qLgkiUNcJzr/R/X4P75RwLwzeJlS9UOVqtb63jsndCEmxbwLv4z7NvVIC6I92AlGkyoBoRf2QX7rbZXm0vl6xuldUxA/hB6MmPAHAVtxvIvbvDJ0Pa8R+TfzrVRg+5qSW6CNZJTyJFmno5rVdn58AB0fdkmAiDJz9EEAt+lqqQBSxG12oau1P1xIx6qfl45XaL02xEgcsBAzZE9/A/32yNtu1Fob/zuN0clHPQy0C6aau6jVSNRBzyWwer+qPfqL/K8y6dXj3yVWhU/bQd9DY6mJccM4V11LTGQajenejUB9qv64xialg0lSg== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:21 +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.3239.020; Thu, 30 Jul 2020 18:45:21 +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 v13 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Thu, 30 Jul 2020 13:43:19 -0500 Message-ID: <54ec37fce6382b464c537bf717d3570630c3a2ec.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0015.prod.exchangelabs.com (2603:10b6:805:b6::28) 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 SN6PR01CA0015.prod.exchangelabs.com (2603:10b6:805:b6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:45:20 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 63de5302-7910-4cd5-3a74-08d834b8b6a0 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: R81Dh2Utw9c6OOj7pUKA98whnzD7brnwMBvL5ojRXIe/d8WOVmZ+5TMHaV8c/VwjIce8gVHQpFNUyfPqA8Y2XZMd7fYxOVjNxLf3A9/Yi+2kHkNt4x59bP93ohMuikUWWM+K42r7Hm1fDXzTW4a27mML7r2ibldQPTmfp/9W2VAD7OkWMsYjCnBZAyaAxQcxHoiPKxtlBQUGC9SHkrP0EyudClkfxdqJzvTKnTNbYDHkj6+yuahzMryEtqhtz8hG8W02xQXGR2GQSp1wYRVDfilgdAFPPT6Qv4wdekk0Jh8XzElVjmTAlB0oMMPCx+A3cFiYer9NNU7OnFN7Ec0AhApJfLcOiqNqUqX4su+9m0ZhqzVsnt1VnnFkKB+MxV9vYGp0NlLb2zRyiHKMvlnMaG1XjC5YXokyo9gUQNtl8TyZRJYtVRZ9f9I7HIDVBajrnGBDmPcGvWpod6Xq3i+Fyg== X-MS-Exchange-AntiSpam-MessageData: d/pJaOC5CvRaWP+kS7m5ydBDAZqB8mJvHIthsM6Wf26RFFUChsb7QlLXj1y9PA7yUU2B/2+CWPta3evPeiaugpSv3EVLYdeMruyDZCtYAIL7aC2QuKNEj6hjRio3S31iMc77l/kQDj8rkcX/5WXLIKcxYutvgWZOP8PQHT1rXRIDt21vphRNdbm5ntafo03ZOnqLTJb3d/ZDnymyQcfv7ITJ6bpJ6mr/VoEUwjN6Wku3cISs8Qhv+iCrsMjhFTc1/aczGbmW7miHiAObrzdQ9m3ApLZxCNx18SOEDlJPOVgy/lPLBqg33UzTDNSTtnyXlfrUWeWMeorKIHY73MnMLW/gBEWkhG++w/OwpjxtW8chQXflFCg1O9csY6x10DluFbtlt7wgLHolQ3N7LC0itk4Jkr9yRjxzXOqXPZoE/9PE2d7YkfHasM0pllwQ0t0Y/SWlosS+TKBktDqM3F/MjNAcHj3u36S0XzncJWyQwps= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63de5302-7910-4cd5-3a74-08d834b8b6a0 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:21.8704 (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: 3YhPnO1CFysTBmndAmwsk0rNG0E4cEoni0QGbF/1VmakxE70MeVNIeQLrm0puAth7AHdJYeDbzXjILTKU1GuTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: GSYM5ZQNkvhphrqIYXW7SEBCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134725; bh=9MG0UJOXWI1ncIfyG7O0EeQOhDv6IYs0TQQ/AHVA/aE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Kx15f/lgF/e0dMRQppwKZKQK+i+wdHe0v8JiyKRSRk0x0VzXGexnU9y6J/uQYv7hXTt ZvDIs5mmwI9t1cCI9dAW6MEVYZZPjklFF6AP8lPDRT+gCd8VkwELmoQHc+3zJ9dgGm3Nm 3JQPO1q6sNii15CMAPFz0nA0AQeNFfDZM8o= 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. Since SEV-ES is only supported in X64, provide the necessary X64 support to execute the VMGEXIT instruction, which is coded as "rep vmmcall". For IA32, since "vmmcall" is not supported in NASM 32-bit mode and VMGEXIT should never be called, provide a stub implementation that is identical to CpuBreakpoint(). Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek Reviewed-by: Liming Gao --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 +++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 38 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 4 files changed, 86 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 3b93b5db8d24..3b85c56c3c03 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -184,6 +184,7 @@ [Sources.Ia32] Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm Ia32/XGetBv.nasm + Ia32/VmgExit.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -317,6 +318,7 @@ [Sources.X64] X64/DisablePaging64.nasm X64/RdRand.nasm X64/XGetBv.nasm + X64/VmgExit.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] 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/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..69f7fbf3506a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,38 @@ +;-------------------------------------------------------------------------= ----- +; +; 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 and NASM ver= sions +; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into e= lf32 +; format. Given that VMGEXIT does not make sense on IA32, provide a stub +; implementation that is identical to CpuBreakpoint(). In practice, AsmVmg= Exit() +; should never be called on IA32. +; + int 3 + 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 (#63484): https://edk2.groups.io/g/devel/message/63484 Mute This Topic: https://groups.io/mt/75892696/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 Fri Apr 26 18:26:44 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+63485+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+63485+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 1596134738578993.4026011765262; Thu, 30 Jul 2020 11:45:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fLUGYY1788612x6sIjhdpjpK; Thu, 30 Jul 2020 11:45:38 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.84]) by mx.groups.io with SMTP id smtpd.web12.1728.1596134736363162337 for ; Thu, 30 Jul 2020 11:45:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NCVAsc/hiyHFEI+kYT2TW1UKacf+xdAjUpVeujOgBXXxydkW1OWi64xTw/UYvAesrKHhlk7R4hWWCCCOhlrBHu7YUEZfrOSyiYvidcu6L5JR4lcd6gXfWeOklGkNIUa8HsKuZKbcsIhoBDa168rGyEAKDg/kkrMWP21/R2yAjhw+HtZkXc1KlJhO5SJLXCgNAknFy2w4gK9OkmD900f1YO0Wq/oKbUVWi6w94pqgdR1b5ldX+WFFdoPB6cBJAzi1pYse1qx6lUICNa5p/UPmNNHfyCCl8cBoJn8mbcTePzlEtBHfjpxmby0yHK3gMcyPv14smkZfMj9uX/qo0OlydA== 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=O2DB1e3MhLHb8ACryOPCpgBfPIHE9hpcCSSENsCt/DI=; b=VhsxyUV2qMgEtFjWGh609hmHhS+xXKhsjMmFEAgW9jb2MEfF2UoZG8IC9RHGzNQMApRxwGiIKf+KgXxBna8vJ/3ldDWSyTjE2kT1EUsco55z6vieD/7W/9BVGAnY3MBkxe9ZQYeiGzh683JInn3Ro1vuhxRjRArx3lfAH+gZ9DcYgDbYpQNIs1Fys4BEMxji+uOHOWHCdQPRSUkWXCc53QsmJ0nsbMjVcuNrlqr4u4BLGhdrbclChkAq9VsOo2/B06DhsJA2bLrRjosZLPCsl4go/9Hm3nmlTSkbg33fTmph2u5I6x2wlEoHd9u5DVgZ5ExwQDIRzrZtV0ve22jXWw== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:31 +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.3239.020; Thu, 30 Jul 2020 18:45: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 Subject: [edk2-devel] [PATCH v13 08/46] UefiCpuPkg: Implement library support for VMGEXIT Date: Thu, 30 Jul 2020 13:43:20 -0500 Message-ID: <8793c74d94f52547f3878b885e37de736784f7ad.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0020.namprd10.prod.outlook.com (2603:10b6:806:a7::25) 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 SA9PR10CA0020.namprd10.prod.outlook.com (2603:10b6:806:a7::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:45:29 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9eb170b4-e35f-4dc0-42c6-08d834b8bc48 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: os7JiGPKbJ96UW5Tj/hWEowoLg/oYgKAtzU5q3no6e7b3AmR/OFzwFmwiNti2zrOdzL68HfSfizxYps7VoNXa5PB3Z5GIF4s2fHbZ2wL8KHZTlKGAA5+IyPXJvopQ5u+s06Cbxzg+luyPHHt5yqph5ME5K4tVcwMUsmsSd4MT3sdjN1jv9M/M6/6of2zZboGQ1L8qPm9rrIU1kgMorGnVduJIyWluzIgBczqjUgZn+4kRiyLdCxu1MeofrDP9G55Lao2iPjsS/iJEUZ57aQI88ifV64HQDz5jrthL3rVj8wTl8XE2TtqQ+kd/jPhkKpppfZgNLNr1eqExEvjp2xlNJ2Pd0KTmH64X5b2Uu6ZHJC6HHFmX3/J9slx7fHhXs1XEgdao9EeE8bTyaulzNOrayinH5LvnjQ0AAAfLNjPmjLO19HSmJOdTuUNSEIctApPJ732aWPqsvj5A/04Ad+Yeg== X-MS-Exchange-AntiSpam-MessageData: zk9KaALc+qyzAr03jmVlAMTgikVU3ak9/4FJEybc3HK9UdWFqAQ+lduqatneN2+nCX+8wUOs03wCR3piCJ95t3kLuuoCdq6QPvAi9jBRe7Cqmic1ykDTuItUGSSH2VTLfOCODNP1Cqo6d7EQ78x/DDbOKmzpr1++9o8Z8kqvXqmB7hVjg+PQlePQ42MHZNH4upTUaTNHw4fMwy4JWPTREfvhvijUBrE6WcDtKsITXW0pBrmlfJEJxbdKD4XevjDCDPig1MvV3oEC3aOteY/Wmfai6Rhni/QX1WV1q6pDv8B48o7ygOHNVtTetvXhAQsKT3f9/KeQAx17s9GP4JGStPWV+Wv3szUhA4OClxOOZJ+IjzzbLnQqs/+7HRuUL2rDXHJACDIpnwXUu/Wcww8Hw/mdxNGRFVrW0UvOmg0sDBYuG/5D2+2baRgsZ9WUweT0diHqe9hQOS2/1xSY5YWi/aDuTKdYemOqfZpoMls/DJ0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9eb170b4-e35f-4dc0-42c6-08d834b8bc48 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:31.3462 (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: nVLXk48J8BuA159KOD1hrxR4gj2NnUYkHsj1rzwwlzXDf9+t3I8lAes86Z8HQ1T0FFfMvmtH2aaHa++BSem90w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: aPBVz3DTjRzDBgPaM3HLePRcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134738; bh=TcRjuhW8umoP2YbPtRvlR5h+Dm3GGUzfJJgSFaMWaDw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=bg07m3R25kdYdyVabhq3vFE70WiQWft1/EeH5gC2JMrwEtdnxcIrqpojXRxtVp8jI0e W6Hin8FOMVpbMxIKVZCItO6H613I1sVPwzUEYQponVZ/w4B2zHReUoVZAxiQkS5d75sOU pIxZ0u1d2FVEI55jdKNeu5Qtr2aQB9LVMIo= 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 d52912ddca1f..17228cb5a84f 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 964720048dd7..b2b6d78a71b0 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 (#63485): https://edk2.groups.io/g/devel/message/63485 Mute This Topic: https://groups.io/mt/75892702/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 Fri Apr 26 18:26:44 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+63486+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+63486+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 159613474576764.42812307179952; Thu, 30 Jul 2020 11:45:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id p6w8YY1788612x7IF2tfsXIx; Thu, 30 Jul 2020 11:45:45 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.71]) by mx.groups.io with SMTP id smtpd.web12.1731.1596134744365552336 for ; Thu, 30 Jul 2020 11:45:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bDtPd3N/wmtIvDoPYdCZ4rvSS4RuKINionesO2zJX2nXTXJJF3ErUQk2hJRtrc59KYhrZ3bcaasR4jzcNZ2k8iTxo40EWVVw02mmtkXvFP8r+tvJTkOVWvdKTIv2drfnPqZ9PQtA2OMf9em4pla2TSHlIi9vC/ms6lmWKwgEMaRX13pNzQemW4jcTWGiKJNoTaP5LUpoehBDye6O1PbDU6X0sOlTds6mQf8GghEnJaJ2LyWSsY/P26aYzxhHRVWCfUgwnCJFX8K41IIvedfAwgFKKBJRiOwyR/3Wh+JtnmNB4hAv3fyrUgvXEWkivnze2uJCQYnmrQaJfSL0JZ+5mw== 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=eQaYFkUchk+w7XolM19Ka3m/QUki2Qs7aqRFYJuLoDBf7924EXAuF5MQUhx7oGR+Tg8G5COPLFjZTfdtXsom6uCozEwGvsB1B6q3GN/otv8B/woolA3mV9MX1GEsQJhc4iS3qsAAwfNBQetAVLLLmkZzlAEpuBIylQ3iaCTY84hivwAv9ZIwyPhrvU5hbjntsnX5LY5ILTfL0JLzb7uawueRyEgnrjlY095UAye1JK4GIVoqR0tXdK8RZcVpJPUnCHZyq5IlK3pyMGkWKF0biobPohrX6G/DD2Jdg6lAK/VUNkXu0EfUtUcNYKt4/W2O24HlmJKao35YhAwMm+hG3g== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:41 +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.3239.020; Thu, 30 Jul 2020 18:45:41 +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 v13 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library Date: Thu, 30 Jul 2020 13:43:21 -0500 Message-ID: <3474d990cafd38ba5719b24d6e5397fa79f193d4.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0048.namprd16.prod.outlook.com (2603:10b6:805:ca::25) 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 SN6PR16CA0048.namprd16.prod.outlook.com (2603:10b6:805:ca::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:45: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: d77c7739-7021-4a13-c3b5-08d834b8c209 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: Mde/hl3t3+uYMGl4K/jNbhcaP8c01DQKTh5hoY2ZVafq2evJkLE8DA0VN/EFgtlkbwdd1lNhwdAX7ljqYXYFBZ8vXSwktjV7nCX4xAStd5F6I1Z4l+06Sd3d0iPb8rJ+Zd0qnk9T6MF3Arwx3ka57TzanEe4KS1xg/yXuAdS3+HYELYQmofpIzTT43KurZ+57brkLApq/THFT2EkXcH2VGVzs9aLC7wUdwYlUFCs5yI7zfXrli3naquv1pQIciBBauCLFONZXG7NQSKgN6H+qVlImPxuOUub1ROfcdblJywOdinKorw47HFdkukg4iZb090HSeU03ywEkTp4nSyCIS1aVJG/tLEGag+JgGjwuW05bzH1m/WwRo5SFgMClJv0wOfVngwacInZOkEBzdgO0BfUYQFpK54fXF4YAiujkSl2NBzqOlMBK55EssVDXaGTGeRqg89gSaAieXOuRhLYhw== X-MS-Exchange-AntiSpam-MessageData: H6yFAA3iojoK5KpuifLXErovlJ9v8v9PL6Qz/GRTfyo+jLvUd36QOD8S0oy1AA5tshsEDyx8b8DCoewBh5XsoX8q2YkvsL+iY3O45L9z0zDI/on6awld57/XUbSnT+rW+4wVzH4Zw30uoLLX7ANV0o6s9HpPJD73XjJZ8ogl7GtBUTZdEqEg8tN0k0/jHcKLEos5fhLvAmrtSII60o3b2PgWBRY+H67HA2MuHV7K96RS9pVHq5mjjajLRPfzZhH7+eP6bu26uyf9zG+ixzbGrSPGsiQ9NoJkGjtfq9QTOsQQmMA47uNXFVbSHFmKF21PxYTkvn7DEnIWIGVx2T4i4ePZa9MXDhi8wp+8c417xa1Fpe1D/z/0jFWbMZyeBsTO8gbDk4KiAIyLL8DoxeW9h3to8z+dnkMQMnXM193FJfmN/ItAE125wvak7hOin+ruJZclcVpXbPk8VaVT5802Awj4Si2n6C4Rwl8LhlCi5sk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d77c7739-7021-4a13-c3b5-08d834b8c209 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:40.9650 (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: zPJ0ja8AwatcCXqYrO8VuSFhffDn6b22a66sD+kIbU7hiBsOTnaO6bcQfz4567XQE015YlUtWFJPYjAlLn7D+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: 0aMJfZyX9Sp88z7DidvfLeo2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134745; bh=gkNM6omY2l0PdwKKqhoxbhSzD5/tMHL5+598OGr6+Vg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=COejTI0J7gyRztXhk6z9FS78e/LDwEC2vIplsW7NdltweruS0ORa6e0kPDJOUOvOB6x eYHcv8yMn+loWEdC9S2WAy62+p1MzQFaHY/PeW2TzYkOsLxQpQsh6kScA6W9+3nNpabaI +Z27daRt63CsTtQENf2J1QI78/MYj6+8Vvo= 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 (#63486): https://edk2.groups.io/g/devel/message/63486 Mute This Topic: https://groups.io/mt/75892706/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 Fri Apr 26 18:26:44 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+63487+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+63487+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 1596134756061317.78430805309483; Thu, 30 Jul 2020 11:45:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8dxxYY1788612xCM1c5F4Vrz; Thu, 30 Jul 2020 11:45:55 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.72]) by mx.groups.io with SMTP id smtpd.web10.1735.1596134755152490604 for ; Thu, 30 Jul 2020 11:45:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nolhQQIvPoEQaNAEkfLLjiRmNzFGOwjJ7dRvtedIm4BWWNnClNyT2owhh3JNQhF9Ea6gucXfEjs0FDhV6Ek/1zDir8Dh7e7xDgIdTCIRDuFgbZaHCVy/NJxfPNGFdoLio2VrfcAkqBcLel7qDmi1CmLibJtvd2eOooN7DQdYErTHkfwtw1BB4qo0LewONz0Mu5ws4FhQMLa/T1pquZn5vMjI+k7W/5RUrCEcqdxVbWDIDkn3HjAtJ2JCbAo8/s7yLZzsvWnlLeXMfqXzZbPvnJdue9KEHc3w9Jyp/+oo+OHUgOYPSqO9i5vWMcLVsF5vZu/a4GFLPK3qAJD8cL2d7w== 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=WFwbcLjBYhnrWXTOwao+6Oy6nxNpxn1AdWPnr3RUnIsr6l+tRUakoDFbph3k1jpj9Sg3lMgKxaLLiW2sfwvZCFHy3l2PnD5DflZFXvEqahmrD3ZImDPfy65dYiEcxfCQIm/PRRMIkO2n8a5h0sQd76kLmqY0kJ+EYtHid1Gv57v5P6uGg7GXQ7lZT7DzRg3JcA+872Yt2tGe9TQc8jlTXALsnI8y/EyM4nA3C3NB8f4SwRCCPVnRwUkBmW/Jf0g7ilrNmJy1YQjfLmlYKUHidQ+er3bAiy1TIsjeXDmlFPD1y5hPxx0yVx4/f9XSfDcqMvwZtWq33ns3WBOKy7RfUg== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:45:52 +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.3239.020; Thu, 30 Jul 2020 18:45:52 +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 v13 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library Date: Thu, 30 Jul 2020 13:43:22 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0072.namprd02.prod.outlook.com (2603:10b6:803:20::34) 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 SN4PR0201CA0072.namprd02.prod.outlook.com (2603:10b6:803:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:45: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: 119545d9-d5de-44a6-f232-08d834b8c8bb X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: 2eVV2SYQU7gJp39ujVs33D0/ZNK8nLDdcJCD2FzAQZsajPklTu7iro48+QJbRBALKosUDB3fbadWWn8y81LMpGHkRZHqwFeQsd/rDKrurHPo38NpjLftuevQHJJzm2AFjvEm8Lub+z/mzdiBwCk6TMT6BFW+uf9MqEnNKu0Mmp7/mp3Stjsrqw8sq2phBdvdgh5SKN49cdbXuV5hpidTM/v30sfKZZ3aGY46/GS1Ho5eK1Eicdr8wiNPU+vOJiB7Nhz93m5egWZouVJdVo9D8/J8pkdPv4Re4mV2PT4ZKd1264rwew4brBd6mfdJRYM3xgcZOc8NvS+POg8honv+AIGIBUPb3BrE2DiDu7veMhoQUecYxgPAlXK4jIkoOnqrAIaMqbImL7D3CO/zwo2wakV2mJpj8uikMjGjhnujf4t8ox9UisjjZGwJ3+pVuC0MqhPhupsykm6y89QnoUIaxQ== X-MS-Exchange-AntiSpam-MessageData: xPmFErEQbexP4YGs/Ssd9R5kmFZ2rONvwvmKqbz/04/p7PwMnojZj5yWPKl1yxWr8IYvb2xH3UNbjdPV5zcf9FIu8Mahih1iamw63tTE7MhqkETzegIHAsHm0Ap+ZMN6T0emrV6mzCFFoLanv23Hfj35leE9E8A76kA+Hy23galud+59zyZ+M4bojUTgGnK3xfcMQaf4CZYTTE1SBM9djDdfFjvVsjAiNpy90+v94n/wxzkFdLI6k3+mm9bl8/wsKOcPSLcnkxSVyGiF1h0vJ0mRc9ztG5fTonuQG9yjwl5Iho+p8aueo5B+O+bNdk3OpxOyvk+lzBnCTtjXpY49934/tWJUmqLfCysm+tq4vum87hKNyL1W0EwBVgxDDFtqcbE5AvDUjyQfl+ioSZbKXE5WUxfj1Beyx08CQ5Xrg8NU0TUONac9hKfRiUqZ5FG6rvF3+M+YhcqfvfwBFx+D5HNjNuqWYMb5CyEqLAUEvCc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 119545d9-d5de-44a6-f232-08d834b8c8bb X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:45:52.2760 (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: B5/G1hUmgU2KIMFWBYTiy3n0TYcTENboqv+2EmNXL78Qbme5pxSnV8YRe2AyEFNzO9JHVxpkweZsvjMXEFF5nA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: zubWa2NFqSm7nR1FZJL6zDsDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134755; bh=JLH2juTA+z4ebE3lCEKjHnd1QweUt/HjFNBsmbb8yhM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=T+L19SiCxsVTTfR8Se314fUsnkM4hn28opqh7a0TovkBzvALEluondDp8cYk+BNrPGR MdYl5QTTFSn710mQCiFXJaTAj8w2eS0BANkoNlgJbuPo7lMHMyKeYg3yYKA9iVBT1T3NY HpJbvuAMzyN0GWo1zKuDMCBmKLcZ0copkco= 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 (#63487): https://edk2.groups.io/g/devel/message/63487 Mute This Topic: https://groups.io/mt/75892708/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 Fri Apr 26 18:26:44 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+63488+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+63488+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 1596134765561916.291969274816; Thu, 30 Jul 2020 11:46:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tysmYY1788612xcjja4zEOrh; Thu, 30 Jul 2020 11:46:05 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.77]) by mx.groups.io with SMTP id smtpd.web12.1743.1596134764516194695 for ; Thu, 30 Jul 2020 11:46:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J25iiLj9493Oy4iZnG3CB2L1yofJO8P0R7C3c72do7H2fKs7TEvpFIS8BeY8g8eroyheb9SySuIePUfUzn9lzYX5VskonnciUAXNY4Z5gg5aWxK2BouIzfGvXzwXbPGwJ19GKpfocQrM468S1e+FUsVfsovIpR9sUeMYBZtZ8JRwtZAmkievHKS6TfUHyvQmRlUy9JEFkVSlWcVKmT+FR2h0u9XmxvAe77iKnuY2mFrMp5itnlKlZZcHVotfPvdxOFwvBOllG2V6GivPdBQZgbub4Rv2g0yBxMxFwVVb8q+c8x6bTXlVt+KKom1eWWfYXjv50QQ9b2OtzfwAdaIROw== 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=f5bu1tq9NUYJWwL2OqaO5tAn8o3I9n1PPuom9kEdsc4=; b=E2+3eismNphGTNq44wrnARA+zvEIVOrSieeFSW9JFAYx++Dk6dmvbRMbwAjzyNWu0n3YZAXsGrt0JXaQmXEeBRNffZ5iER7cTyzNXe3ETNzqMFq/x6F+KMGEm8MSXwMx0OtleP2G3lvbli+rlpEKWFs9he/3d2BuONznZ+5yZbXzyV+FsUBF89v5mSRQfgPZwqbgzhrvvCOIAZUiWlzoqOXGn7XG5MsVxAtrthCEG3lUx+c2ld8QIQnA1nlVlj8nOjJvrABnq5/sTW8Z+ERH7ixR71gWDP1orwmqYJD/r4jxG4xl3eqScIw6s2tcT6XMkeN7lAf4CFJb5K2EYp/9dQ== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:46:02 +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.3239.020; Thu, 30 Jul 2020 18:46:02 +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 v13 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Thu, 30 Jul 2020 13:43:23 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0001.namprd08.prod.outlook.com (2603:10b6:805:66::14) 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 SN6PR08CA0001.namprd08.prod.outlook.com (2603:10b6:805:66::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:46: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: b6d680bb-0243-42f3-0b34-08d834b8ce77 X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: HftG6UB52d/5af6srz4Ug0OEat/CiTN6cLfBnnnqb1jYW1FjTV3jbt9ruCBIDar3S//E5TYVxR3uVkATI8p3f3IBzBmAUADNHFdcp32yipI+w8S5xKyxpeD6L9xQEo4Lkj0qMY7MT1Q63PvpRtdZcgZV8gtgYVjxiC0MYL4bQamKWElCvledHJh+r0u1sOHaBEuJnHLGy1x9xWyop54QI7hQrMjOTnzam7HEGaobDibnuWjQzTAOmaLiVPDbt89xPoVlJ7x4DgAlTnBBcNVKgxj6XsBXhdAvhP6yOMCz7nFpxuD4Xhfw61bccPuClJfBUJzN/IhyKkmyeugboI/QmAzV0hvQbhZYT80Cnm4TPWyXkdCx9qgIAO3siyGjarUIuGMyMYBzPe1yf4lLE92JVaJmrM1jlYNH4vbroBJ7HLtN1CX2X0JKVQyPuRFlmrR/M8D9WTK+AJQdp6thStuTmkNHWpOGdad+v1OkRY+jQPsW/zanQZ5EsFP3a758J4aP X-MS-Exchange-AntiSpam-MessageData: R8GJcdUBFeCR+H37smaaKEPLfCVQ6BnqHNNgOX1FdOocyZCWWDcIOfMIjJ4LX4IcDCuhF8d+JZYffbn/bivSEjgQh/6nl8Ty8RP3VikMRR/ZPXg0N+EppYa7HbQUfW8EX0KXJIFeZvBQaEjmMuI2qGx0HoYaBrTKwvn/OVIY9uNVY6k7eZh0AcowadqiAEmKorNf9uesEktr+H2VSxlv3Sk5npOLmat0ZGzdRQkShMT1Kc+Exjg6XOvccPsNJFhA7KiWiUZ8xU+jBwJ2YNAiqPCtrFwIYMJRMW7tNohqucw+KZ5ShPlHB0SoIMLzZ0DVTiXlOQ5mP1HIzLFmT4ofeQ+ZQn1/n0bKLJF0S8H8DRz+NNWPjYWNKJgaSsA0/hpj8gaP41Tze1+Cq8YxUdnwZ4gfMbEBK4rwcxrEjSnlnBUlWvDef+9iv63wBSs5pEF0x6OLbgY7zkrX6Th7ClEfdu3TBoZd+qdGFf5avsxWkHw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6d680bb-0243-42f3-0b34-08d834b8ce77 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:01.9398 (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: KOU5rLVdX4lECyadSAViBKTLO85fBcWZ70FIq0saeNbUNctx1Q7H3gQGi4JXNXQDqWwiAIqbFIvqBC9O9C8weQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: uKEesnJSfBf44uBvUWPYrN3Ax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134765; bh=yBu/Ioh8hNyEwEArVnYr29sxJ5JWc9ottPnrNBQf0JQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=sWlAES8pQISw573BGosNnkrw1mNnSxli9C0XQDilLog4jR35jg+moUZFSdevCc7bcSn KMxnymlHN2MxkgnmgOwHApkqbnP+D58rG3goIcpdTAdJm72U5b6cuvKlqEazJF41yAs6j a/JrJFRxEk8tWeDgZM1oJuon4FACG27cHCw= 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 d4ae153c5742..01b5a2f1f4fc 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 (#63488): https://edk2.groups.io/g/devel/message/63488 Mute This Topic: https://groups.io/mt/75892709/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 Fri Apr 26 18:26:44 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+63489+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+63489+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 1596134775977945.3134289707533; Thu, 30 Jul 2020 11:46:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9I3xYY1788612xZicVU6EWht; Thu, 30 Jul 2020 11:46:15 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.89]) by mx.groups.io with SMTP id smtpd.web11.1771.1596134774609208026 for ; Thu, 30 Jul 2020 11:46:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b0GRP1Q02Y8hJmnw3xjkWXk6dZ0jipBiuGQT+1jta0RsMLL5p4jaIwOLSdSHjlI20qeYITTS9kwBPIC1o1D/Jc8eP7XDuHKQrMjBOPm3k1zL+CN3cEB/AnXw3d7xTmseFjUArSpQTlipUzQJ6palE2m6SVvGG9+go1kMgw7uOHSO7Jui+R+HQjY0aIpVDX1NJXeTp9JLGcNMCCuMYFmbmd9GeKM1xUT235xHeO6YEUml6dmqkqdECkT63P4wfm5TvNvbd9XaBrEh97+be+sSBQbmuYzWVrqYCuVWP13IxR/T1aV08SCYx48FvYUtVZnTOGbVVR4UcGMwgmQIPkeosw== 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=FBw6oZp4VWCLe0sBDrCSu0xb7fgCA5XphU64PWUxIO7+9tFI/Jfbe5U4dq7QwNo9+krNFfZ/GNkEZxFHSeiZKRMFb92KD1mVrQp5SvBpdhnuysGPDSILHkC9Grc/0hDQMHADKKoiVFVvui9PTvyvh2RmjXHSPIzAiV2rzxOrasWawijo3SeZqnapjZ1iYhk/doKB20rBi8hQWditWb9ecZ6LyPnsf9vfP8WV5yIEHRTzZQHyNw3YlYXno11Ez1h9iSOKEHUzS2AVaQq/0UtHII+otnIWd4S2rlN5tg5SxCdpZJdo2y2EPg7+StudD3yLeLuFG6jkgRIR75ITWkcPqA== 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 DM5PR12MB1161.namprd12.prod.outlook.com (2603:10b6:3:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Thu, 30 Jul 2020 18:46:11 +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.3239.020; Thu, 30 Jul 2020 18:46: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 v13 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF Date: Thu, 30 Jul 2020 13:43:24 -0500 Message-ID: <7b6a8f5cdd4a041a14b114aca65157cb2d8cbb4b.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0140.namprd05.prod.outlook.com (2603:10b6:803:2c::18) 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 SN4PR0501CA0140.namprd05.prod.outlook.com (2603:10b6:803:2c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Thu, 30 Jul 2020 18:46: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: c6d16716-c270-41cb-03b6-08d834b8d46d X-MS-TrafficTypeDiagnostic: DM5PR12MB1161: 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: 3eot9umtwxLfVll/C7/Adr/LXx7iocs7ArHQYtuAgP6jRFC/EmkFePF47e8WSeNfqIE+YSL6utNzUQ6bK3KQt7RVrEk+EVq5cSpHyQoxXQ6bp5J2Ng6UsUVpBKfaa8bGSWQWpgWzddrmhl6vpRDOqp6MZY7J0XW147bqo0LiTSs5C1uOARPV7pYkHa/gWKCGutqN4EO3XEzQdWYQDjserq29R90q0P1TugSyeed2lZzGjOrHAD4lRvLovbSUdmAE27+g6xuhf10Sp6sx4gulvsAMbOidwVCTzw/rcWg5w0O2cU37v2pV9KvGjTQdHozaYWKqt/JpFSjFzs/wr0pjTYJsj5vHQoU67qH14DOLz+tZwWrYB0DAcyPJGFlJ+OZC X-MS-Exchange-AntiSpam-MessageData: 22RWJoU6RmhYUxvsV3joKziAWUS0UjEWXKZ57qX71vX6wZMSCFrb+T6DG3FMkRWdjEavbZJsdIUNB6L7ZMwcds9lc227WYXR1GmPrx9sSnq1Yl1EEnA6MeqHIEXYFM+vvt5/ky7rLPnAxEtvIStuLnyURJU75w+1CQI4wzxB/Qwwc5XEGrlv0ZL9g99uG9s/+OTDUuFOUa+g4JhxiftVSmsuY3wG+ts2NvM0buCQSWl5TwgWpXLfoMyq7RrAR8aXib7oeTKKl+2hF5k8nTVmKbB9scewHieXze3CuLY28ek4LC26XF0UNk1Tvm6xqzQBSNFDAE46kqnJ0ejcc7MTus5Qu5j+AOWInYQBwdcRZOxUWvjaTas0+Aae9DORrc+1AZo0a5Hl4nlAjAwesY1geetfVa9L1QNcs+rqXUyKIDRpwCQSHoFNM3AwcNxhHBJfhdt7T/RKMzIYF03E/TyQQgtR9hWpBkMXXYCWP10Um1A= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6d16716-c270-41cb-03b6-08d834b8d46d X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:11.8894 (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: ArJYBOYrSHEYduezxemq4g071t+QJxXYW4489j5VmeK57tRv3FdUnDtAjAh/kTqkBRmITRoOe3GpZ5Qln5kJGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1161 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: bwS0XrQI1KlInM17m5lmExPbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134775; bh=51hij27gfhS7C7xl291dmjKYPxe7aXs/gGASvhbjYHc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PJjlcH/wiEKpynlDBSQyhTjVpDqWedkd3kUp2HrdXhP2xfLTNL+h70MX/duODSEh1mB vQ/fEu6kxvLg4+A0gntCB3Bn3leFOvipqbguOQWOf76/XTIsfuhb2Ep+Lxr6ElrUAwPNd o9U13R9rrqsk+BeI4NmV2s9zCDIL6LKtjzY= 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 (#63489): https://edk2.groups.io/g/devel/message/63489 Mute This Topic: https://groups.io/mt/75892711/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 Fri Apr 26 18:26:44 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+63490+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+63490+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 159613478384282.06850221104787; Thu, 30 Jul 2020 11:46:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id c6MMYY1788612xO9oQ2x8szW; Thu, 30 Jul 2020 11:46:23 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.47]) by mx.groups.io with SMTP id smtpd.web11.1774.1596134782856626077 for ; Thu, 30 Jul 2020 11:46:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VcOkgoZHBbdkeWzG9GQuwauA85M38ITPO3lAh9X2kzgNJluxCPrlnil7Ys5rF6t5d8iGuL7ymL7PW6A8fvNUHMgcrdK1g61D/E6r/hoFmLNkRf97oTcOEg/dxsmPwoCgfUAgGavxaP+mE2si1u0iNpTNOO26DuGyux4bMwerpD0JDK8UqJRFP8pT8D6Fd4D3A9qXb+nG3Rm/Sy/qRvlw7cDPb4EYa+2IN0PVFBPg8uvv0e9Xoze2v+wfat0RdEKZgwqO2ijFSksJzVvViDS8H9NUiPkQCKgtrRlMzLU7Gk8f2dLYbyYYwzSbeG6YFrQnxMA/heivKZEB+2fmv4fCqA== 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=HitbQHoz9Mm65XodhU3l2aKJIh22d0FGEs0d5OY9sZMMdm8b8Z3ODGqhWeUxDvWQ4WcAY/lUIkzZZ+l301AuSfgwPks0knttotkyoe+4y9STqCyNCITYYzp9AvFX+/OGyMoQiSA/TZpKxCVmzobU1KWsLuZ4Zbuy08yW85P9+mOFiUFSHMBHartFI4jGFQOVGigtJOjlNV98hH2wiwxTnlzBYsc/EishciWXGh8pc9wTEbkbaM9RH+cDRMUQ75hxCiOLwLpnPKjhUxPNKoMaMFcOoBnyugaG0bMmBKprmoDiSMBnGKIQ9h/XrKxqmkxb01SsMfB1rhyTOytfNSLvJQ== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:46:21 +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.3239.020; Thu, 30 Jul 2020 18:46:21 +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 v13 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events Date: Thu, 30 Jul 2020 13:43:25 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0102.namprd12.prod.outlook.com (2603:10b6:0:55::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 DM3PR12CA0102.namprd12.prod.outlook.com (2603:10b6:0:55::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:46: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: f804fe29-b453-4a3b-8845-08d834b8d9cb X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: G8TGteTIJVCT1usJ5C2tW/taiBpdWT2Ek//o4kI6JxJvaFBJqbkspBzqfaqTgsxoJy4a/m80zu0GVfmEFssCKDH1lJWMB+U6otbfqSmpsuQ568PE6QKUFSHAsrnsNz+fYcksJfe5FAp+NmYb48iLrdEqA/Dz/PlnHHmO/lMOB8kh/X7tuaJciVAovsroPSvNqdXOIOJonnACOi4nBwW4ZATJGkZUZ9LFD22N6qbWJjdQfu0tE+JOSmLIaseZOaY9E/bNbzgA/2MhprxP2RSAUR6MUmJsjK6D5nlZfxe5vljcpzg7PmFbXkln8JTb8glbY97DlbQWlu1S3vnZ7dW/2NuGgcBNS5QpqkL9VXqIFd0IcRAickCjC4bcMg1tRYd33ROM1+nBsEedWbp9mzp9fFp/Mw3S9fH3aZ1oQiLc+LmZRfCGoIgLJ1curzdIf7hwBdC4Oiq7NSQVjKIWAGBVZg== X-MS-Exchange-AntiSpam-MessageData: 6uNLA3rApy3heTKdeVOhYqO8JrZRKK9K7zMDRKjnuwox32OMX3L32X1/dkZdI/pvjqbLej3ZRrwuUbCcS0oXe3PGXFrrLtA6wJW4KtjKEKqZYJ7OkdsgcW8FOrBFWAE4VC3Sp4ofvJYpKFzGIFhCw8R8jY+/YfmJWYSiOpKUB3B/L0Li8xKSEKHX+0J4IByT8WnWQG1tZsTHIpJwWjWxUs7+l+NlI4rgccl5havVfIEg60e7HlxfWZJaajFcJw9j/ELb82oosnMU1wfmhCAfZkMXdTlbvfT8UrN2Iy11qv1w30gUgShgCaHyg2BIREW7iymQW0X1GMRpnpCISF+0quQErMufECJVPuEbn3i012rhO7pUCFs5o7+TKBrlU2agMvPT6N0G8ORH4X1/2jn/Qs4vk2DUJdUQZI9V9MZYyRzpdBhe/eUEd3EMDbrFc9qI8dM6DIyuzZBzuCPCjfkjSEVDM8GBCccMulpn/sXqg1HkamF6hvEO+YiVOxVY+/oMQYhBd0zIu9bnKANJK2gPpu5fYvwu/Yn/sATwpmg1bM9Oku2Fh0z2RPs+M4vUnFbeKDkhPLjx845iwmnI9gRrEEtFQA99zGHLoR2NtjaxdkNu+GJzXULLZQBTYj90qBL8Cibm5wGR/QWVqBkuUuHJOA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f804fe29-b453-4a3b-8845-08d834b8d9cb X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:20.9884 (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: Yw2xT4Htfsf6Sq0CkQTEjIkqiHDRQC+AAtbgAM8KR3VZz65ELDPvMFuLlhm7xwVG3139yqnB39EuVyXOEoaiTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: tfLQWGOLU0E42PaqTwW6Nldgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134783; bh=CBI/vln75JW/IwPc7oXMAI1alcuIawW4rBl5khp6r7k=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=t3wW1WMTzIvD4Af4OeoY018Ki8hlamyLkJ6vFBZ/q/uX9iov86TIIMvgNTHxhFRSmU/ Ihktw46xqWa8SrcPBKBMYLUxMkXdZKlg2QE60zlFW+9IkJgnm4akXD7rkaFYpL4RAg69O fLlPgicgO4GfDNPAwv6Q6y0TJ5KkmYR7X2Y= 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 (#63490): https://edk2.groups.io/g/devel/message/63490 Mute This Topic: https://groups.io/mt/75892713/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 Fri Apr 26 18:26:44 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+63491+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+63491+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 1596134793469797.4603196089256; Thu, 30 Jul 2020 11:46:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wTycYY1788612xU94jfmHGAd; Thu, 30 Jul 2020 11:46:32 -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.1778.1596134792339938178 for ; Thu, 30 Jul 2020 11:46:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gbw2aOvQ6rNtzTsCI5D4+E2Kifshrra0Hhq0U9Z13XDMAqldjLGjzHWpyE+35c4AEUeEeUAb2FVXz31gYQRF9oJuIKgfcY0f6DSI04vNi+gkKsobuxBeSJkWDPOkzZ8mggn7S6cjllkVRG+Y2HbYPULW5IiHNC8KnY6Q3o9+bDUkH3C1n68v7RxpZtmui/wIE58FL3qFq+0Fue4ncfY6mg+lb7qqAIdro7mTCy0GVwjAaAzvLOMgtEjlZQF+tBfqbzQiYzZ/PmymLXQ/yWOWSAII/ItrAJPg0o90yEit89zaZfraY80DjLBKWsdbed3+6/tByyCRw9tNdAYVPJldIw== 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=nSHaQ8sOhkMs2C/wUngjBq4mbV86dSFwGRqayERpo4Xf9U+9Nb70p3xYH+YlVn8K51db+7gj4wa/wg+lsFJoSxM3Z6B8X/hexivRs8zBViGE5BYMYixktyRvAIF2VUWo8CP8blCwPVc8Gr9QTUYqZGsgEVLNCZEhqHPZJtULYRmM99YFvLydd+nEu4WpW/0jnFzgy3/XdMJ7H23LzHHA7p/MVQ1fWvH4fAszjwu6tjmRcxt/1bjUxosWD6T9kmKmArA9lkcL/l1Gm14IiM804o+w/y8fA+tPyoqAjHzKNhMimXDwoz/tJyebVPLTsqP3v3B8cjvIf9tIjcrJlMqv/Q== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:46:30 +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.3239.020; Thu, 30 Jul 2020 18:46:30 +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 v13 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Thu, 30 Jul 2020 13:43:26 -0500 Message-ID: <5983526bdbd3c130d907f32ce1dfaedf97101e4b.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) 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 DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:46:28 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8b404ee6-d51c-472a-3699-08d834b8df55 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: iGRhydtb8FMiDb0+m6naeANfMGh/G8e9680W0DdD232hJLAlEV1tOCFJaNPXbYOJoDSxTvZnRwDNiSVwLDuq7qhHKIp9nl1czgoHNEHk8JNpZajo7ZN9aEH6J/N14n+YHg5bVrzsozhnZVsb/edo8DVP13A3QcesLNOAVc9PAtB7WtM6jXwgYVRMqZr78afG0Xnnlof+zVnB5npUurSZ5caKUJSl74oce13fXCUe+cq8tNCCXeEcQTbwOn8/U9q9URa1Um9gsJERmH5oaARy3KSndNSo0L8Spv8wruHmREH9puxyBsdhs6zhC3Lgvrj/EjYN+M8q5EYs+b+sB3tdmgHWi+xUnROmb4etbpbWmKZy/5/5WQYcejFt1bagt2mcjDqiVJpMK6fr2KJHJNZPBpVODTm/4zn/fqK2eIX2OC9QNjFlyhTQen83H9jxCzqsUDRF5r7TVm8dizcEztk+7A== X-MS-Exchange-AntiSpam-MessageData: rO+mHwH4NpS733DO2w9N2k1NuUMsNsFrJWpbNMj76cf6Ol6baJSMTjwW1iTMddMWWWa26X2fBFTkDRwWnvslptKUiwlSHPN/jJ9GxFn0/PSg0q5XjG13i6snNdp7gCbdt+LX5sB6fRi+fZNki4xplwWh9aPh7b4hUFNJWCYeSS/9nxzu96qmCiXR22gzxoARU4pmEej0k/FGyNld/on2UgXthvSz7PcgOl/P5aUIE3FoEYjRw0vJDVvTEWo+4yliB/hzrb2lHtt7u9icp5dWj1uoVc2f4HkCBwqCJE8JYhRImUSydCemWO18WjaC4bQ0CFAB8EPhAHPsGLZjS4rs4el9NJkJAkXUsGzu6xS9hprR7tc+wUkjdy7iPwqFx7FEF8sNFcQlGTS9zviVyqry3K/Twpljr2B6AuxOnvKGsuIinB0p2RNON9tyoe4/iH+WtpkAbtw5xelOLRctHmVKMKnw8ng+2roYFscc3dP3wayyMjikRf6rqr/pwpDJPTuc/8PYB1T4hputQ4oDwBu/YDP/gZ+yJN/QhosIODPSIgvErValoDSU8kW3IJ/zOQo5BtKGknzzDjm4uZE5kWyVLx3PgYpEKtOod9O+m/yO0hUUssVvhVnO41Jn8ulcbjQb5uF3H+NzlZ6lfriMuJ27lQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b404ee6-d51c-472a-3699-08d834b8df55 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:30.1984 (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: neo16b06FA9aJwAvFMaPkAfCErJxoZlF68v3odAnC7Ol0MK3dFKqNKFg+pOCX1uiPOIW5ofgZ62AoszwbhZKRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: xeLM4eZhqQdpKWL3znamiyBfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134792; bh=duWV5XzduEjAxL+xbsfCzziShjK/4f+ZRejvCqTfkHo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rAwRU+yrBCFtrBvmAVYKQwbztI6nyKc35+6hPO4CTwAd0Dvvw1MWsDtHcc6OVBRWhdK oZjkl/B4fMU8GAtmEnc/agYiFcxrDM9tW0FsjnWHTkJIZJtGAOnDb0uQFpdIIhozRUcnY fJeQCrYlOdQZyV3Ib8UcXafoNpV9w0XUuYY= 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 (#63491): https://edk2.groups.io/g/devel/message/63491 Mute This Topic: https://groups.io/mt/75892716/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 Fri Apr 26 18:26:44 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+63492+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+63492+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 1596134801749361.7158117795409; Thu, 30 Jul 2020 11:46:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 10rQYY1788612xLVGw0LXplO; Thu, 30 Jul 2020 11:46:41 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.52]) by mx.groups.io with SMTP id smtpd.web10.1747.1596134800912590658 for ; Thu, 30 Jul 2020 11:46:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GVsGbFwwh8hidS7Ak8zlrww7jNtXEPFvZCLTFvqTqnh1vMebCGASSU0rdPT8dl1KRJLit5/fyKh5aM+sgPmtA+yxObyg727sOrdSN3rw84UItuz6tzON24ZJv+mW1bDQdF9hA/ZJx+wnit/RMR+dMVsK3pEm8aNseANoRgAES7J5jTAy2F2m7VQgrVTM2aXqzXNqM716ED6knExYrJjHZzHT//MDYy2BKjAMTE0YfgFCgIE4sApp0i2lUgT/hlGjbfurylwL+CcaW0mTDQGTXNSrntpBQH9KMKYE7kDMLebjuE1raYCLjlPLH3rkFaJ1+WEicG48HMs599sX+qKbGA== 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=Dmq0NdDcTiPJzP2XPNMSQNXsS3YmJoSL89On3eDzjgsrc4OIoQd6YZSuDGcLeDLXyKNQOqYt4C8D9D3fqkpprlYtcOigGX301DebG/nHa+VWV3TKlBjD21ixbV54MeLRQYwBJIaDQx+oAHqTdquv5adIQJiM1avs2qoClC/B1L2JIwQscwXPGydvr/JX+IGaPka3Mg1WDoNCDY/Zpw2oYPAjuIIqVhC52ZR9yOn+2Rle6F5J7gplHtvVAI1ny42v+dFPiqF8kAa9CYjTeVVz4j99q6Kuv+z/tzymVvVS0indHxRfhbT6lZVk2IkVNwkkm3vB/e8S2GUYd7CQa7Sv6w== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:46: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.3239.020; Thu, 30 Jul 2020 18:46: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 v13 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Thu, 30 Jul 2020 13:43:27 -0500 Message-ID: <0c08e8f63f46386bf9e0fd36521cdb726cbee4d7.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR10CA0023.namprd10.prod.outlook.com (2603:10b6:4:2::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 DM5PR10CA0023.namprd10.prod.outlook.com (2603:10b6:4:2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:46: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: fcfec5c0-774f-4943-99f9-08d834b8e500 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: 3V1cEaz35fskI/L1wuS1S9Graics3V5KtEn16kJLtiS1JzhoXC9ehFTPxJ9/ukBi9VPc4w+HLv1flUjRkFn75x5C+Fh4R2IN0NrPbnPK7q10DOeeHHAffiLw1JZXzka/5pNOiPp8Iz7xsNrnI0pKpm36HGiUs5Lb7m8rUauRWVDMbKMhi4NHYciMwQs4gRjGoWdgwtaNaevaFN+Cupdkavu2G3rGenpIgZnnfNI/80ZHeyUE979gl3rqQhgcEXMUUb2uMxwuib8BI/i01/6pVUwFR2Am2gjp56e56XP8Xk98b6DXPMQ5Djtv0760lo5yw76gxfxeli4g9iI7X9CDcvyjj/uXEIIp0akIBhVgDEaNVPHRAYxvsRzn631VGBhbgtVuyocjdB3pu3koNG6vKQAX4GtR7SK0HOREPbYHfCkD7j+9cnpXtkkN9mG9xyYQg7NhlvuNkQC/k5I/A77tuQ== X-MS-Exchange-AntiSpam-MessageData: HI7jK/Au3ylAesT2UZgjpzg8d5VndmgPQ1S1cPcMluVBohUBGz3NHkGr5S4qfqOihUd0dWbdSA6WiBoG3qlMGKFWlpyu3agtP5MP/aIjH0EeCVyQrCE8VBI3Etsqef2e1q02QmX0RG4aVxlssSPQ+x/kAiSde55TrvY1ZSj08jf8wYdFdDyq21driMXJzvxUdM2xoGjDLM4JFd8dvvFBdfUrQkCBII5ZZQEx6pdue3Y5S9IWC3U82mS6CkHBrJjpxbR1JxhGP8Tb3qxz4O3TScCmOpNRuHLg5bgdgGtl7Ikz/0Adj9oEU0R55juqlit2+g3Fn0uKatb3j5+Go1vjmimS8L8L26WmbLv95vU7hUdAAufkDWm2rYKM3QizMtDQyqbdtFZk9YOwuzpNvU/b7LTUrZrDMHPYlAstdhFH5hiFCbdykhAyrNrx/GMBmT7DN8am1lZO8m9iCbPw1j9sGHFIfx50qQQboRnZJ6pkzD8FsueqZOUrBvCD5HRxBl9QG6ODtT3NsK7sDodKIIXoKDqKw9uE6tpSK1dnlvnvJZani4skFRWhQXG1eylstz5JjlTMc0KNcmFEofhudW5OSkET9M1N02I6n6hE0I+7uzWFBeEN1U0HNek2Js9qv0rmh3mi1uEuIjmSvo2KO1qcZw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcfec5c0-774f-4943-99f9-08d834b8e500 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:39.6972 (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: XAZmk6BozEHy/oxi19gmOHX/ZSKTeIun0CjfKdg4HyUreWDbYuvUfCL7/B7Qce1Vg1AFpYnmAVZha9x/0+JJ6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: jeNIbEaP9kcoodF6tCOiI0rwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134801; bh=UGPFqqT3ss9rIINOWuvfXrqG0O/tPhROqxmK8/ZPFOc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=M/SffpKFrVrXuoCR17xldRm7qrCbLcfGlQGctRLcBB/WnNkF/7TVkZLdSeYuZ7X47EZ mHlUUd4Ij2J83/z5zvMbY7SAQIPo0JMWA0CD2eRd6XCuuPcJrlYEnxoyL495Y5HNMqWvj VFLuegfFBRKtBc9tYZxCypuPGt6LSIgY0R8= 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 (#63492): https://edk2.groups.io/g/devel/message/63492 Mute This Topic: https://groups.io/mt/75892719/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 Fri Apr 26 18:26:44 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+63493+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+63493+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 1596134810774791.3159818365389; Thu, 30 Jul 2020 11:46:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id umXMYY1788612xYG9epDpXsK; Thu, 30 Jul 2020 11:46:50 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.77]) by mx.groups.io with SMTP id smtpd.web10.1749.1596134809851432430 for ; Thu, 30 Jul 2020 11:46:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dD8IPg6cHgSNsRYHdIJbwVCVLZN41diFBoC1owXW0ICfxxzCEiLQUV5xX5JQ7jpMKWypJsRn0euZrW++iCZkqL2IvatJLiHlkinFPRHSfkucfdt8g4/rQ2I6obTF6NlYDy36g6ztWK/6fWvqU0I78aap4adIc2X1g04EvDxhggBYrsdjQzAUPEX9AnH/U+lPA8F1XlqRfUnZ55/uvgKhPeYxjx2pF5UnXlhGVEzZjjC/hOdNlUxrSFv+r/Q9SXHLOSS0TIvgBAv6y++HnBhW0blX3uTRJtImJxUQ2/iU51eTucGvlm4EcVs4saYg+4mP/5o637loj/9W+VZ9hf86Lg== 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=nT0TdGvH8HrS6NkFdhJnxRkwWRRu4v2o52uGHbRolBN9nniReWSixR0qWffXkQAKmk7PfHVIaqwRpIkJrnQaOiTdpzhwp65D0+aYIM/aLh26syigEJ4pO58/phNFMHhCVoBiJ/xrQd7FN6Ys+XcmiDH8rvJUWwMyoEMQyuzVL77SD0JWirLrln4bavHjEYyWJGDAoP8DUvh+cApULVX2J7IBoOj50macIA24z6CdS2SMHLTbqpDfrdBtIZ5gD7T8V5I4PSarwfRsqJ9/A/o0Mxw6jVZ77jBxNNFOrA09Dx0LDHpcs4plhWenmh9DNTEzrFGqD84TSTfYnM1hjtgRzw== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:46:48 +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.3239.020; Thu, 30 Jul 2020 18:46:48 +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 v13 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Thu, 30 Jul 2020 13:43:28 -0500 Message-ID: <6846dc1bfc31309a65930d153f8e0ffbc49f45c4.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0121.namprd02.prod.outlook.com (2603:10b6:5:1b4::23) 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 DM6PR02CA0121.namprd02.prod.outlook.com (2603:10b6:5:1b4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:46: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: 13c8a13f-2696-45ff-797c-08d834b8ea62 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: PHxpuA+BX0Fc4VdJ/bdJLGnHb5rE8XYAQBJ+cK19xRiVw8dCtl0DPcc2YPmQ6Tkleu73ttGLjC3dTV0ZjkXRa6/C1UxTNut4iA63UiHAM/STlK+bphJ0LNC4o3kyHMk0k3ugCFZHbNY9zeHi3w10ENIPqYN/8j4T714K/XJdJLx8RaUso0Le0g6AOKWJH0FplCMDXwTKax7+cA8+0fyGSU7lLLgmgWXZdjsegLeQVIxvhFIFAJF/3QfEXCWJ60BXrWHdkzxQcsnRPzctPxCKItVfKnxpfdwbZetvp2H92YPBWrhc0DOTo345pB80G1dV9kRPjL6Vo2u+jtDrcNz3vS+ywAkAdHWs51N3XnAQmhInzR/69pivEeqFZ030WNNpMR2OE25sQZwWN9g1BYYIM0PTAvQ5GFc3a5BpbZ2aRjA20E8ydhx3zlmAI6MtYipMGmFjS7ZjEjbZKG43kCPhgw== X-MS-Exchange-AntiSpam-MessageData: yQu3Qq/yuHcx8tG5flU6s00+quHpyrEoEN84mVwSUYbEvFC75BcvQ4RKlUHvKQnlrHhglz2WRHyLGEQIVQ68NOXzz6HXJXBW2TxsUd6844wKaAk+U7GwC5ruWyq1c7uSFOi0uXjoMmYYxJQTf4O3gFSeyaljc2MfnQKjr3YJw25b4wf12aOppBhVrwIftG1qE8YMbJyhchYXtqupJ5K1a7Ck9G+jUa4KR5iRmAHcA09vU+UOpisjQ0ITFtNqLovR3M1y8omj//Cnli1YS/Oc3eAmFt32cTPj3jhbpnaTLk7zU74Rvv8O4Zhu1EG2N8AXhJzsCpQ4fzR1bS5nKzbJHzJBZ2EqwXIeACd2PiEgdGxgNJU7dD6lLrc6p1xCH/A8iB8ht2+ZJJnTWm75sjHuv+yKYiXuy0rKmD7qquxkAWsKFgqYmr8K1DwdzPevbcpDknjO5fXIsznpssfpwYAo2qr2B6VrqRdwKFQzv3R1K0BXfm6i89WRB5HSkBXNA4hsj90fbURtB2tZhoRiihGs9uo2nXny5H30xtK7pXOoKMVryFWCmTrtCFthmASy6Mo0GfUw5sW0vnPcMRJJgeg/P8vvLHjXHvySCeRx27J2euY7lC2mra+MYa+ieIpElc1jkxuBiGL/CnahCe5VxyQyCQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13c8a13f-2696-45ff-797c-08d834b8ea62 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:48.7492 (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: 3g3fkJ0SBqzQaIo+sOJF7JgLx/8zneKAcpJ5cOVnHYpxhmcVWsPV4WQLyoEjjzoGaU/UwFMPsyGdTApTgsMAnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: AXGy6MavsxTJfXCjKmTPdDsKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134810; bh=fTbWxZN9iCdD8SbLdfwpN+lWB5vsZJj3arVUXZow/1M=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rRuW97tYpa4Eb8xLT2nQNMV0biHCqhbDeeb90k5k/TsSgBzXxb4af30YG8YCrlwoWYx 2h2bT6K1Us6WwobbfD1OPvIc1uk8o1/JmdyPHD7Lg1ziB0mTwCL/pRZQ2XH47jDMFDEI4 c0IPuh1qVAgE1mMyrjADyu43CZVq9lzNNUI= 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 (#63493): https://edk2.groups.io/g/devel/message/63493 Mute This Topic: https://groups.io/mt/75892721/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 Fri Apr 26 18:26:44 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+63494+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+63494+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 1596134820192364.9618405401973; Thu, 30 Jul 2020 11:47:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EJRoYY1788612xcCbFdvmewN; Thu, 30 Jul 2020 11:46:59 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.72]) by mx.groups.io with SMTP id smtpd.web11.1783.1596134819226382876 for ; Thu, 30 Jul 2020 11:46:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hJRt3D5TASmE65V4vrwz3R2oMUoP82wveM1taZpPrCpwG2EfBYi9ppMH356wMCwturyh7AoGEIp8ir8iGe7hjCsn7J8bh5eF7n25OMHNUWExUH5aABciu0VJM7DlXvrUur4dTooxhB2nl0Wwm1spI2cjaj3RLqMaSt5kfGNGX2e0Xm6SEb3vITGWpGqD6mjK4JLlepythQFDMx3tPa/biHbbTC0YdugDHPxhm258ZKzKP/avR9Zgnp5OFN4EKXsY5/dUDUgOH1db9+/m4O4Qb6f0Fd/S5jLaWWO7BPA2OM1kTmaHW+hOMbVxXV8wMWTrH8Wn9j7n4QUtMVtP99xyMA== 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=AMKfCZSdm/M5qJzCpEIjouA6zzK/zhPpK6Lq/hMN+vIFZBzuKQtfARSD5DyMOQ5W//4VHIZpG5fSaOvE9yHKMcgr8D/2gy+QHJRS1W80DY/FDfPWeJMNHx8Weh5U5yZeVGOcrVSepJn7hd7rQq3v7pLdfWYG0eTkxeQZfI9vqPP7Rq4VlM1A1BZ+lSNMJ5EYkjm+hyfyRcVfH9gG8VIYnsXr0Y5iP5sXKpqJviZu9Tf7qJtB8l1/U71yXgdoD47chCUoEeZB+I5koHey1Wm0/5JcFDLBlq78G+jRGDgLovmiN3AaBA4i9+qbZ8pcuknXqG3shS3fDq05a8xRtNaIrA== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:46:58 +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.3239.020; Thu, 30 Jul 2020 18:46: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 v13 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Thu, 30 Jul 2020 13:43:29 -0500 Message-ID: <8cc0d50c1f568b0542d4c5d610fe48fcc0b3f9e1.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0060.namprd06.prod.outlook.com (2603:10b6:5:54::37) 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 DM6PR06CA0060.namprd06.prod.outlook.com (2603:10b6:5:54::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:46:56 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 28b5fd99-b8a3-4724-b258-08d834b8eff4 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: sR2JFQW6Wl/DUh3QjLakfpIx6FA9WG4wJ6ElOZQsY94E6xr6u4M7fMeJl+2N1pc4fCf2bJwl8qRRWcuwXqErrnwCTo1IDF8vyR1AE6eBut1c96vcmxSMtKNZYCmq+vxiwXpnG1pnyUZwip0uXBxO4xmKVJIulWUVnltz7Clc9IeqVr9xvTeDr6C0I441foD+jendDLzgLuhG7WQtFvDkGK6GKwEfF//1PpzyVlIxR4OKJEWJ7BI4Djzw9hmAEJfEffuXkpjcf0Ls8HYvjtAFDava/nE/ptJGlh9SsNMiIrZANqQ8Dss9MxgYld7uS5ImyVxCoFZv+/2WtYji2r8HsNKkl6BEk1WxLARSExdJertEXln6e477D4iDpJvwZRtojZtzkWTiINQ25yMnApWPrKp53PDIy4ebmqxwmbpvRANl6MGEAHn/YM+32JO3taZRzKDh+MZlbdNK1SOwDcnhUw== X-MS-Exchange-AntiSpam-MessageData: vOCrr/E/HZloLhxj9ujC3d0bkFJ0KiwG0QUBLK5rfNdJXaJpsmJoJmtWuuZMQRwMIY0NqVH6rV+1mKxOjiubtpuxjq0xcBZCWQznRdyiwFUf7+OmLoYBn5NkdkTyOA/GJuE5sGgIv18uP50XZuaafdD2Y1qgbpIK2RBpe9RVF6QsD8T9d7ABVEOhrPf0juFgwt4z8yqRchYxPvrhnDQmSiFHk68V2ASKc45JS1kJ8WBk/V4x4KsvJzulh8jro7ACf90UKOnCsjKL9MBgQhjnuaNpbwKzD7lFldTDpXtGrm+6bDsyPRqLsdO9tiPEig6vA2sCM5oU/3xHXtsUO4D3w4uJTQJdNeyhvi5dZtAKsFuQFZhS9uHGChiIZSWrPz8Xa+D6YTRcJLGl8hK7r6KG6RqBM6EC7RswfegqCREgOm7pVwEicweINBnGiRoi1H3V2bxx3Zv/fKDWQrCNwpOmNrs+e0tlPzEJylpgN4exzRJuOTRZZVKeZL4t/eH8ghp/0BXn9bRHufMM2hK3kbLAie/GOy8MnTZgimsT0pwYULLC1IOnF5+Hw3YLK/3JR3THySgvjAHaBeyVblYfED72a0QBX8XSuxJeDSngeorOcYYmK+T0BcaXQYGPj5pXMvkv601rX6tuLysjOXLcwxliWw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28b5fd99-b8a3-4724-b258-08d834b8eff4 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:58.0811 (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: 7Xb30K19bG0ry5mreGbIx4s35ok1DfY6IeKgBIvNUbHyTXg9QjJcG46hzeyJAPygvdZf0BsmWWotNKKa6/Rpqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: LMkE1Pse9KB4k1Uy3vjLX2uzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134819; bh=9u+eX7ElN/wyxWEZrV6OVWZOMUz5KaFHZnw/39vZhLs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wwdaSYvq5POYoVGdE4X1kvP4RTQ2tp5GsvbdwNIAg0r2xgtO2SrUV6XM4TRH27KvByW 5wyuRNhi/SEhLIg8MJoZJ64PVmynrQ2LERYcyN7p5+WhfqcTyFdhYqOnidHvl15xp14xm J+u7l2MTnr9f3COs8SbfT2byP9OBAwlnwoc= 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 (#63494): https://edk2.groups.io/g/devel/message/63494 Mute This Topic: https://groups.io/mt/75892724/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 Fri Apr 26 18:26:44 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+63495+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+63495+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 1596134829070470.463993531166; Thu, 30 Jul 2020 11:47:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3fjeYY1788612x2Gxlcd3h8Z; Thu, 30 Jul 2020 11:47:08 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.44]) by mx.groups.io with SMTP id smtpd.web10.1756.1596134828161493087 for ; Thu, 30 Jul 2020 11:47:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ug3MPcAI30Ca+OGxpGRkdgm5bhpVG/tNizh0jijLrNfB141mByHUVU4z5hWvwsgURRhWS1Pfr5dB0zHQ9FXBFQw1poIa/iOnOzWoZdEz6ml+dsxualCkt/wLk+uHfEu/7pR/B7/HXYEyWzomgx+kBzjO9HVn021zZsOhcXzO/Ei5MB79KZUb76FBEyFvjzkBZhA7iQl9ibk1IiessEJAuuTgHRalx0cLt18vOrHn9wCAQxC6ySrphSCt32RUNuTsElDAyTYR/6eq44y5jvE7RUGEvV0P/AbLRHrgT5/FVnk3LdUrJrr1Rgw7NbW6l8zhkqhxje54Li/MxYhVomSPnw== 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=l1iZwTrfTvr3dO0+Kni5Q05GfL8LknPS7B9eGfrirxYzSRzz1hpJV2qMF+EB+BF5pKP02AHDUJSc0t0u1WFG+kgvzhiaWp1FiW5/IiRLfx9Iuf1r+XcXR2DUtjInAGP9H/4pBxk8LDZGK4yzH/+HubX1QiR5XLmrtKAMRm7/gZfPy+1xXcCBacVsiZqownYxX/9p7sUgdCvZp44dpAQIpH5mgdj4VWWxkZZnRKkm9y46pfw2NhTLNnA3zmLWPh7usFDtO4NtZ5AxDzX2ZsuknJWj6j/YgI72O+JuxUvqGexcr7bGdPTQEEtt2e5dcsyFtAlACgVf9BGFIGjagfZquA== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47:07 +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.3239.020; Thu, 30 Jul 2020 18:47: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 v13 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events Date: Thu, 30 Jul 2020 13:43:30 -0500 Message-ID: <2fe1203af85920953e6690cefe5f4c72dee8861b.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR1101CA0023.namprd11.prod.outlook.com (2603:10b6:4:4c::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 DM5PR1101CA0023.namprd11.prod.outlook.com (2603:10b6:4:4c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:47:05 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d6acb41b-639e-4e9a-02f5-08d834b8f546 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: u0cMMJHxBIcq5kxxB6iCrKgsvuuWFQY0REIssB5IPffVUHBg0NU3kwH/GttgsGiYzTk9fr54q+tjjwD3ZcUZPr8RJS3bDL04e6bxBLGilvuBW52Nzb+K7TPwqBqnZSnFDsLgKqCLUocOrsBWI/q52+k2cw6kKcdp11f3vPRLpeHi/uB8MqEGH2WkUphVeM3mLabXWEQS/m3SbP1lMBP+MxJdfGtOCXEH28P5rOi1PW4CczYU6rxrs1Xpba9PZ1kTvgt+XwcIRSwUihmgYroA2BrDj1axRwXCeAP3zU84Hbxcq3IuhFomvoKjuDb93Hw2gMvqNXyRgUU/FDzeJfr+DlpFDCmyATPs7lCtX+UiP7xMQt6JOUP0uIuJKSCMPT1GTiRKmGJEML5vUGJmysOxgTEZFqOi0bg/UspJiKG2V39qhOIJ1zMyuG0Pn3gAq6pvYgpqkdSNCMTPQ6SjJbX8BA== X-MS-Exchange-AntiSpam-MessageData: kkjyWP9kNoZShz8IgUuCCIKeYTJ10iwVSlz6XDlOO+e/k2G33ihXh3SEFsIbBBMsMcQOC3JPeafVae3xfEcz/UiSDZLTQ9jEPNYK/ddnNsngm9rpmopbzLh9FvEqLrFhTzHlsnwqeG+tuzwe0A1RYt6xa2IBqyz/jZXVjkaxGw+3VeT70pJTx1du4atP0c06xONnYgv1izbFf9AuFhOJ+R82JCXBy+9hT0/SDM7NL+uiWV0t5QLSgl09ulZr6qqqFUqU3be04BqX1Uwn0IQkaoDzA423vsPb+rwdwjpcJxuBOmZlyFeGV8TInoc4L714mPoP6UTuA4PIJ8Zbbcqh5yaPFSahvrbUSLxuP+K7LZ5GiAAAlNJtMy8ZLRdTjlIMyOQb0sqFrCHXGPBuP4MVqixY2p/QwCy5dhhTgLDk2ZaLJmB8VG4QOC6UelWnSoGShxa1RknLOwcORYQMIzCPSPZhEe5OnK+EXptkLSoMlB/rn5DgQa4Po3+7LxJwZuorRv4hrgtbQmDCz4GVf35GHmb6uC54d7qls58sOkAdtMi+RysZ+tKW45MXlqgFAiYl6PBObdlS35WC0gPvyQ6vfyLanZPJLjEOqQybNkYwTtKcpULcjULOtw+WJk6TugDk+bEjhdgWpgJ2EwBjfBxWYQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6acb41b-639e-4e9a-02f5-08d834b8f546 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:06.9936 (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: 5vWa3/cbADQRACbu02M+o78yYGICFYn9R/LQ/UH6JVwztIKwBLtpqRUpLuBUH14+WCT01ASRt8awrayQ3D1yWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: qJsFwDUnbB2tD1e1Lk4ZiFggx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134828; bh=SAfieWYcYVtG7rL5tiNqPlyFllLWj4Vcs4sx0+RtEms=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=q3jGe6UvoLbBe1x9rLfIQRbyl2D2vHcnDMlkgKtE2zAkGl5u70WIss9vaSjCG/yMFAV KZlyZ++DzMtgJsi8Y+4CEHCRUXm5sbNm4mBiW6YNtYAyz9AGfEtfm+4nLYNrxCJmnj+OM DlI9OzjaIGHUR3yA3O/sVIDgD3ip8uS1TUk= 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 (#63495): https://edk2.groups.io/g/devel/message/63495 Mute This Topic: https://groups.io/mt/75892730/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 Fri Apr 26 18:26:44 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+63496+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+63496+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 159613483892216.79588912471729; Thu, 30 Jul 2020 11:47:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0cS0YY1788612x7A4KWPImGV; Thu, 30 Jul 2020 11:47:18 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.51]) by mx.groups.io with SMTP id smtpd.web10.1759.1596134837827973986 for ; Thu, 30 Jul 2020 11:47:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mdZe3XL4QdtVrVpToYkWd1+ydNcAjCXA9h4OxkUO47ClH9W/50z1Z0Ey+cfuNOMhcgchr6W2zjwodsvYu9UrFaM4TcHI68ukXMGHDcc/AzFAfxTNRrL3dt5N3z/yoNz55iuCvsz1D7VlUfOPxY1Fn+UQ2zKYd8D7c3ZHoS9PhQbNfnnM3FzNpBNzK39Ox75jKEBBmP3FD1OruE+mJv11KfpuruJuEzGMMJUSSINot9F4A3VgzNDf9zFxivyXNAfDudj01pHEBELXWjDx/pj8jC70Dqn/7zigTBIofaWgoroAE8k2vkK/rMS/vHk2CnN+q8NP+Np3KwZ63cW9/WDNTg== 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=epxfSmEsdSyJ44PeyIM0ipMesNpd5ea3FRO0RanoTkfMcezBhbYFG1tHLIqGs4yX4Fr41VxA4Dn/fs6nS0xZTXC3FMrdYy0LwBpMFAxhzJzaLPfEvvFBZ7pgnwIRM8yYsAHbu1hRrRsofEafLOxV+TwvGSpE/UNEkXN2oqYatKZcSzNYvwfZfwW0OEU3E+7AA+2iLA2DN6NOLODG8nb5jgyG04yppSAKDrF3/nV0+EXXId2VePEia6oWcaJLMjb/NdAfEINyrWa0osDRuc7xioUj29INf2sHdb8BMasbbDiGiBoE1rSVomVYZYreV2Azj4oW93ZS2hxf7mrNK4vFMg== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47: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.3239.020; Thu, 30 Jul 2020 18:47:16 +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 v13 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Thu, 30 Jul 2020 13:43:31 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR18CA0004.namprd18.prod.outlook.com (2603:10b6:5:15b::17) 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 DM6PR18CA0004.namprd18.prod.outlook.com (2603:10b6:5:15b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:47: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: ae06a581-7538-4ac6-2232-08d834b8fac8 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: KFW+8thRcxAUl4i+hloIw4jyKAAvr9JWZwV/+uBmvTPiAnouMOIgw9IObf3AG4089c+3mg+0e4fvXMxuInf0oVZUJ9VWvxDtvfL0V8QSY0wCAhxAxV36uwm8sqwiZ/akO1+nFvChQ89dO99lAtbKlCURx1X8NWTPqy9jDgF9Wgv2hdIPX4XfN9i01ENUQcssI95lVMBDPK3WtyrErDi1gZP6KzMXFaQ+XUu2vu8R0MB+/iK38CU+4K4VNpz+EG8pVO/D3hYqpacVNN/Ne9tPh20UIH63qCysoz6B5/WnT+M23h8EAG8wP6XA8pE67NST3/tC8lf7BPp5QPeuUyMlhzYSVkZ4tMoNb5u1YJr0cx2/4BRBxyyRTI5r9LR5OSZA3aD0yCmGNpDaZknAZheNtIeZZ1w3pE0iSJHZVdbTpfR1GQbwB+qKJ2FSuTY+HMbXcG0zW63RktjhzA5iEMRzlw== X-MS-Exchange-AntiSpam-MessageData: AxuGa+pYm3GsRaeO6tuuM7hJHKnPTubzzmR54p6u3mFTB3aGqo/CBsRxTu6jTfxHLX0TSUsJLW3UtzEU/ZUcvxLTW4dVPBsvuUJ3AxYCWjpuQ5UbmNCIg81mhvRtDElfC+ZTi8gD/I5qV1x+DbYmw/H8faAYTSYXFX4/8tbwYGgPy9pHKyDA1baqK2p3MLliiWfaA21MqtNspW0dWXxZTA6ysULaOz2Z07oYfk4DOmEaERHN69bKufI4JSYhjAdnvcsKSyL872+skU58rNKdDwvp9Cd7yeua/UP7Fo+fiWFCB5QCyQQQ+cfbgITlxO3Q2F4eCMHM/xg/gM+WyhCoYbRIZglSYRDi45J0l9G13vjLvKUDaKso30OvxgARZz+Pekgom5W2mtAfmJa7KBvo7PM0/6VNZftvxjJLWxyk5GQULhtVw2LLZv8ZqGML1RGwkbhpOSJyyz7Wo/L+EGn3ocLKNXxMW1DmMaOPGbS6uPTG7CwuSAXjAXs/QigGBsz/9FpmWsheww63Vs9uxgqe0wi1fZzoB+RiEfC65RUjNh7kPYicTONRziagLHQ9HraFIweQYcGtf+CpPGWOBUIJ9VysSkohqIF/aGNn/9qYjnJmSs2sPVsrjVK5FBxqraqUEj7y2+ePN3lrnwanxLM7Yw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae06a581-7538-4ac6-2232-08d834b8fac8 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:16.4339 (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: OdqPKPlK9Hr+Z8n9iHYcpK2EZMVDqH9sLxZet2k1MB05G0dD9aNDXO9+hT2VkH6hHEzIKqAufsWoarUK+VNtDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: MyQnTZSoye6i3oDctUhlQmkUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134838; bh=k6FfrqioVIj2rVfefRvJr0PgHUwEgnuwvLjFoIn5hkw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SWu5kGMVSsKCzbIPkT454LQImTxWUFxbtnNpIXdC25crfex6XsOhGTAGyikxwpOcNVx twYLkXJPMZ2AtRsUMIKEyezRbsaMvOpFEPtXVu6turgCAeTyfngTht0x/ZpD4m5LRdV3A ouRfEoylfpQB66cjMNM0HcMopMKlQnRego8= 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 (#63496): https://edk2.groups.io/g/devel/message/63496 Mute This Topic: https://groups.io/mt/75892731/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 Fri Apr 26 18:26:44 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+63497+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+63497+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 159613484740142.727188098689; Thu, 30 Jul 2020 11:47:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qD3yYY1788612x7mbhUHnp28; Thu, 30 Jul 2020 11:47:27 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.56]) by mx.groups.io with SMTP id smtpd.web10.1762.1596134846554840949 for ; Thu, 30 Jul 2020 11:47:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hx6VVM/Wl256MwmHYQ3izcryOVo8modKD8SwxNe+3RiwnBjNmAi6Ij7z/hIBA9lLUi29GXZicafncx3pQ/j5961pT7OhbRu87xxlh1zOEIg9VIrT79obrbi4FsDVxvWYsPRelXYyL+rBZ833OXOyoAOVofv8Yxcu8jxFzwoKnhsijyCsAJygXCrVEPQZeNV8IBelaxZWLLXFs1KA6TJafVvRyjZbqFXtMkXNQIr4Gireqj9UH9BjowKtsAZPrX5zMOGGEUbwJYsE/wdNAgXK3RmZYXvQ/ShUe3EGcv8Kjm8q/SxfHzkByq1nof57w/mseH7JILHTRgJGr3+mmzKp5A== 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=iIckc2DMt6fIw6lBn4xOsvFbQ1miZc04Z038yS0odqVVPsQXVitPHcddoX++qB5Q4M4LWlSy71mkxNlP32OcLlR9UNdsSyshltqGUpxkMpkzEDsfJ7NdWLDL3vu81TvH8LFiiT9oZTRQGYe73dHdl8GQabewFvt0Mj2EOyN8+dgIGdDWFjAL3nS93uCwbF8Mn3Ol621D2BY3aMvoUEa1EJwsWvr/4u6OpO90ECfVFP3pYoMm0MlkGVsJYUzQ73vZBNvRbnJEt70s1WXAGBR89dstPoXp7XIu0gU7SeExPs8PHmj24CMdsfHtAXp53vY0VNzRQ2jPhQYCMY/+qs/Fhg== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47:25 +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.3239.020; Thu, 30 Jul 2020 18:47: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 v13 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Thu, 30 Jul 2020 13:43:32 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0061.namprd04.prod.outlook.com (2603:10b6:3:ef::23) 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 DM5PR04CA0061.namprd04.prod.outlook.com (2603:10b6:3:ef::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:47: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: bd95a31f-e1ec-44a5-2b24-08d834b9004b X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: OZpMKZYFheHqQ9XaElE8GrUSR/VsaDD1nwtJ2oTj+GEsGH2OIYBLCVp3od7dJZIGfVovuPrJRj14ehpS7JIYvhtUPO+ynhrQTFmOkDaEbEUEHDBucV0duc+BVqEs1kkdLbzf20OaodFeEUKIJ7xzQyinubEeuTr2lWEDGhuJ6+plNwKAKfkWg8L8OhIwYjZvKEZvkxuszLwjARJtt7VWu2EA1Cz5//pg1/bdjlG3JpR9pA4uMkbBkrUSHdIXFr+QvMcO+Jo/wsvg+HSHVl7grjjRhVpb4gpuqX4uV0+Tmf7e7MOxlpD2zrVg3755v429uZkHzgXBxbGQavhcTujMMFdKvMRjnwTUz64fMd7uDY4PEHrbT7t5JxbFLQuxI3Ugv4ymfhkuGD1yRezcDNMf57tIVDdHOj01Vd4MQK/u2a/+61S5tDWIvs0O6RukbrOEw8X5WBg6Hxt7oxqsLPk4Tg== X-MS-Exchange-AntiSpam-MessageData: SYRPHi6QEd6iR6S/n93qhTu4gnh5QFwa+l9C8AUhAxvQqOOhhj3Ufbqdmwy3+2toIAJtMytllAdBzXnRUq2RxMLJ4GFSODRH/DRLRq6DgGnClZsNpBwdeSQEmGEr6f9ywEf9I1ePtyM/peVB7ytt9M9gCIRjyJ6SO0vn+alzjdBzWDQNE6KsIRV3pppyGtfX333z1loS6O3uinls+VIIRI71lzwRDM143nIr1Ubo7NtjzJO58ztIF9lV/8cuOlNIm1T+AzizXjBjyBo2mE7FKmSvqvGroW/TWpeV13kjJqzxrfE+2nfh2RAD3e/Lr0235cMHu9mPj72+IYJe8QBz8usqetg0Fs3AU3HTicjuqggZtiZXNY0fq9C76DaAguxy2e00MlczABc/9AKXYZJ4CweusgoMXgwZyHoRsAmyhtUXtqYlRcU461RY7h9b/khvvSK+VQFlRfhIQV5abZXRxmK9WH9cEShR9F5GQkbUhPhLFDIXmRXxOO9PXDpmOwmcWJWpdhromiReJ+6M2KKRkyrJh/blS0Wdz7wog/63erIlXo8TMIl7DXltO69JkyPHUeeYaGoKucPiKFLDcE4lxdevroDoRsQobUf9s+7Do+5i3BUaG7Li7QVu1P3hgvAGinbvUncYuxHn/baeAuiGww== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd95a31f-e1ec-44a5-2b24-08d834b9004b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:25.4774 (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: fzBUHtQANqSlElpU++PUzbz/YVZOjaords0Rgku6sbg5uijIq4RMZicBK08xa0OQ1sDZjh7SwQl0g+vwHgnrJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: Ezzzww7Rjyf6bqXBKaTBd1Xmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134847; bh=Tz+0BZ/XfctALN0K5MnWdKvarQl2DWGZkPaaN4B1WcQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=BkzgTpLFxtIvcvzEwSKQCbCWqjligXSg3UlowkEIWEPKVbzi0XPlWFVKK2uTKWXfWwC G/bI0WY7lCRSeeSxJC71FInC5E07UlnC/W0FbwNazOdSBHSHfJmxD1gYQn4NrVN0AOMJF biMCdpyQ3D6flkPt2ijTOmg15ZAvHMmANK4= 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 (#63497): https://edk2.groups.io/g/devel/message/63497 Mute This Topic: https://groups.io/mt/75892735/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 Fri Apr 26 18:26:44 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+63498+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+63498+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 1596134856827768.5212032843635; Thu, 30 Jul 2020 11:47:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aoOVYY1788612xtQhp8Ap0Zb; Thu, 30 Jul 2020 11:47:36 -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.1765.1596134855970773694 for ; Thu, 30 Jul 2020 11:47:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=maTCM5lDARCT2qD9oxgZBz7Zg8ncnLim2kK/YFt6t1O4RubecvwJlO9OAWoI03HHimu8GKyj5RIFIsV+QlNDSlJHbMNtmksy4SB4Ri4IUUIu96OycxrdiRlZD70losx39mHpJZDkaPv3jGKuWKm3efkte/6PonrvI3q3DWG4FBz3rh9HRO8oD0pbj1q/oPmG9d6QhQALsiXsVu5ttVZGJYAYH8CNqZomD36mXjhfIapODPCrkoxKHzZ9dI1GXDnULoZx7EMcIcOxf4b2emTbGJq7lGjSbJ+g48KhNQDWDtXuFMun1tmRl3UX6ilwvE8YfYFCyHVrDfs8M2Oed86RdQ== 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=GcK5BsvXi2crId3zqVbRXQ7Tst8OPbbuFxJZohVON/pSDWOjQpWBvnnnNi8XUipFqfNcC0rjE2q3k3aSbeGBfo65xRX3YwEUuERgNjo1+Qaff5OyRdr+JyXp+aJ0fKRZ7UWWA9EUODC8Z6J5TRgswXLpiQ7YC5LYLUaYGg1M219+MYEW3jBQfpELafnxhoGYpbMA6Y85YA7lumefjPX+hG0QBuFSPkaRdqqLCcq/vfYGxlSoSrCEy0CiS5RKfAPHYZZmqdnGy0Grh2eGhUHyg3CZm8G7aWmhzhlugOlF3Zh+6pPseVFCRccApyRx0n0CybyBEP+N2/M9EYisGKlYxg== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47:34 +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.3239.020; Thu, 30 Jul 2020 18:47:34 +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 v13 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events Date: Thu, 30 Jul 2020 13:43:33 -0500 Message-ID: <2ace24ff9ce4704fadaee33abde123ff694ed8c4.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR16CA0037.namprd16.prod.outlook.com (2603:10b6:4:15::23) 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 DM5PR16CA0037.namprd16.prod.outlook.com (2603:10b6:4:15::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:47:33 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: aebb647d-f5f1-4307-dc57-08d834b905da X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: tN+2bfegBT1asC40S87wjnjIy1QYLQuX7wFAGDxzgxnd0H7PGQyzoNOoEoahBMS1Y1JUw/YRU2x2Qgrwvg/NTROQ8pZq6yIjnmBcUBlAB3Wm2AxGigm1Ncakg8ZRg+wNaSS253Rcxj1EiQ7O5q+N+Ip9e76VI54uy1w13kgEwkLOMs1gVtHXknYbAMoxlSBV8B/AojK9F79BhuWyYg5ucnZj0OmkhB2OvKZlWszaKFAUws1jGtMDhT6ZRNzIRJ/8S5fsP2NnCGP2uoO6ATnMGrSP8wDRvBHuhtfrINFA1JgGusA0dzibit28GXbQj4lekGhY7m9o4Y8rk8BjEyTT3MkKtOBQ29trsi9z5pZlsxs7W+GvFv/JLLvIFINephjbP54dpCMayWRz0482UuVC1o+RWvMtiS2d6M7dzXxKQO0TPMbjHXCP5+Nn0BopRNkAVm16MWi2AfI8m0lMipoiPg== X-MS-Exchange-AntiSpam-MessageData: XYmmYuMKyEdxDp9y+ruwm60vvU4udWyYSGhuNN6mABz0GMrQiVM5tW+sdCwtxHwSNkDKKF/wHHTnj363c6DVh4HB2ZKbU3U/BvlP1NqpiVwZ5NzSdfKNEZinxbCmRy0++2OeY7l0AMiTY0H427cGswMcG3ClZbiFAN8u9bRp10F5HVxsSq8QuaFiXvaT0EuscGjCHUYgqfcrWRaa6QkrHZDtI+9XE/XcNcuH6pX19W+ryk6VX9rpXx3L6h5moZRs8qIlC5wyS00p21ahrNnC6kZGbMu5YnbN8s6UZYPjW8eS1d9KfM7e8mz+S4Q4ubAYwyUVEPuim1arB2ZObYPYq4mzvmEoIwRwKl+L+lBYfdLJ3KYm1XboRuxqTpqEWUOBFGTMv4wsm0y6/2pLAS+0cTiedyH38xPLUXVBa0fApcqHVeD3BJeeztA3kIUoWKElqQDZVM5kfCRhb3JL1bQtVMi09XUSVOtP+v8I9SsxqV8GGcNRKc/DzzJxChptYPZd4vfGnfcHcL71QIH35TD1IDAU/JYjG8ypUbbJ61lHhRS3nGTP9JPTM0ehoij2RzFPmOoA20oduCsZ4a2OuBo8cF8gCGwA1KlqS6Eyh1cPyL6iP0yxVgi4XcWVkvJp5S4bKkhurThBHz87oYnylFKZrw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: aebb647d-f5f1-4307-dc57-08d834b905da X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:34.8447 (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: b50sJ0AqE7326SHyvuYmMLdFCkZiSilKVOeHDfcD1uPdLo80y/t+Qts8/tsLQ578hoxWKgXvwLquWa9nL6MQYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: ClTBahNA1pLHDLV4OhzNgoq3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134856; bh=WBMbloHz0tdccE2sMqLCNBXVSNtOAvUALQvR6a7fFdU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jItnYz8zv+oqgjGwRIUujtE+ig/tGk/uHjKFM3hnhq4OIVruIRbWUMkVz8Qp+MznZO7 BbuG0no8RCxUyUHxuALp1bJnN728/P4mF74u/vz7D8i4iz89iARND8rDONvMYHgCMk6Je f5nMJu0g4A4X3HA3YFywQ2L1dQy7AM20Nxg= 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 (#63498): https://edk2.groups.io/g/devel/message/63498 Mute This Topic: https://groups.io/mt/75892738/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 Fri Apr 26 18:26:44 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+63499+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+63499+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 1596134866041526.6853956875204; Thu, 30 Jul 2020 11:47:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RxPxYY1788612xxhkhBiQUTr; Thu, 30 Jul 2020 11:47:45 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.65]) by mx.groups.io with SMTP id smtpd.web10.1771.1596134865166080329 for ; Thu, 30 Jul 2020 11:47:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HR/801nZ0+YwrsgzH4edkbrVln7JFiCUfBSGCcgwu+J27wEAcSzhRtTmxt9Y8j6XBBt36aEQ7Hd4jyhzZGgNNM1aqa1PZRmZ7GEazcK17AWwEo7k1aV8kQd76O9qNrPfC5/BceSf5cDimXm05zmd2E89UcicK9Vi23A//jJ+nacUHmCQjlA7Z1fMzwoF6hVYp6PoQ4R74wyAFmh6ka/e4O0YcleqBK6vNCPjS4KyJOAfSo0qNGTrQCqqsxIRucdP7tx3yiPong1waNgiQQzOlqIg63Q5p2vA0ZRMjv/S80+iGmcskr9guScLv36Roftntomm8jSFf+yjEavm3nP8rA== 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=WEV0p8zXUBCrnuJY+bOrdc8XdNEw5vYlBxtBn2QRSXB6iSJtVRCVePfyU2733aKqkXILjDRBPpN2jjCTjTw/R8iOp2xBLMF16RL7X/AuFkQl5ZArzUsQ91JK8glWjpC35b2pxLKBdrproBMVCE4w1Ry2tEBDuEm51YqoaZL793KIXAvLAabUvEpmTBtU5Chnlqs/3oTP2kC6YHnylqBPFqyJ0hZU2q1q0K4CqesR2PTAv4yoYwtnaC2mJ1aJmNAQt6n54lfiyutqgJiKC4RSMwfiiQrPHCnoYwX2kMoTFPJKvKQC8aiyfVLucLG02lTGSC7JMa3SNOgKZjKpl52L7g== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47:44 +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.3239.020; Thu, 30 Jul 2020 18:47: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 v13 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events Date: Thu, 30 Jul 2020 13:43:34 -0500 Message-ID: <3875b1369073db03e6c5c82dddaf498f68505d4b.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR21CA0024.namprd21.prod.outlook.com (2603:10b6:3:ac::34) 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 DM5PR21CA0024.namprd21.prod.outlook.com (2603:10b6:3:ac::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.1 via Frontend Transport; Thu, 30 Jul 2020 18:47: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: f840f035-5931-49a5-43fc-08d834b90b4d X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: CVBrbgpEAvF75RUFfE53xbjz7kL2lb/XiBijmjZOI4vUDsMryJXSV07E7M96aN4jLl1TOii1gqFB3jwV98YmCBEoBmsZrIZPoLQPbpdj4pcrDTnebMEadE8JyuZGIPCUl9sKPz3L6YNKUvCGhA9kkcXcDLRntcNVDNj8SGbRt82+9YNs1H790K61j8Uc912NsxmNVYb5RPJqNIBAsZHqs3/WMBg6fnmnIhKhQ8R6LIRde970aqX5AxqswrCIjhNj6Sauh4Cie+XVdRf5RtJp4na9blCcobJj6RSr4HpHKN1D5lMZFE+X7WnKHx3ddU0gvAV/SfC+HRe/DoK6HvNQO4do0mcAIho41Lo6AglFPikE17O+MF7LiQXPp05RUWVJSdaarNkPZHaVqhN9hhhOsJkKdXH1syNTJJRV0KkKTrrWAqM52EtmseZA3rGTDpJq02nvx5qa6nVQrUcEeLyFww== X-MS-Exchange-AntiSpam-MessageData: AlLGpfvRF6K0+T/fcx75Xl7p343kE9dsNExnuGS3Hf7AEnI6YvJrBbNsKj2dASR+szDbqSjFHRSQflJXxVc7WnJkTjeyxH4kXCmn0E+QMRkbPTnbCw+gGHz+HDnOf/M2lYuAOZGkrl4De7J1Jbc90VskS14dZKD+WMHTSB2fDtp1sGPvjYeaZ/bAVaJemw4QB8jS2hjiaYLJx126dmbe5q9aZEaEvH505VAvqr9V2lWhwgOsRcP15iQkJkRxsudH2bGWsr9U5b9tZvCDzp6UqD4kSc8SAJHVL/lDAM5l4+J/2wskHhOyd7VWXNk5Ilfku2X/rXC/K6p2hANdjBmTQ13huA6iXgvRxUicJmwxjWmAwL8w25+kE6jseXzEv67Z43z8b4NpfOPo8h+YoDBbqeq3aYMfJGdQx3iy+/eh0F3c9s+m0QP8Nlw+4uJqGbtWGFyDVmfgHyvupNEL9CJwzRY5FJD21+QWx8hXc22mUfE3sUxAUaNOxuDPPRbZshVEWTfQsqV0M/jTUQzfS8mZ1MxcW9XY/hR7lzjSCHeivOxlaJY6DxyM2IQN853/4CmwJyrBfKdPA2p+9J3YNxKVnRxjyqf9gyWMd6fSSTBKx+NHyiwaXAMrFGTAFVWjYzh/aGmt1wT/851rz1SGZbyIeA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f840f035-5931-49a5-43fc-08d834b90b4d X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:43.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: ZJbCrl8VEyxgZ15uX3972B1D8AyZTpw7GOySiNqXLUuoiCeRV2zeqd7iL4W7WycUG5z4wigAC0HmKRUsCe2m6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: g4gmNKrcrf0HawD81xVcQAQNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134865; bh=vry8RMuA3Rr0X1cWRcD+iQMosn0dk3TCkr9yl68TsWY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aA+3qERdq6qeBBt7Ad46nEUkEUf4cHl64LBxEAWuBi8YHDK7G/Ds8y7j9q4YsZUj0Gp 2ajUr1DXfkoEl+kC6pyz12DVqii2jHTyh4spDDHVCM2Q6RiS67/YKDeMnFPYuFclpg4Kx +O3Q36XIqeuU2Tso/y7mPcedAd2R+shCHUQ= 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 (#63499): https://edk2.groups.io/g/devel/message/63499 Mute This Topic: https://groups.io/mt/75892744/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 Fri Apr 26 18:26:44 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+63500+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+63500+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 1596134877871751.4649019003244; Thu, 30 Jul 2020 11:47:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ebnBYY1788612xHvHP48jgaq; Thu, 30 Jul 2020 11:47:54 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.70]) by mx.groups.io with SMTP id smtpd.web10.1777.1596134874086125247 for ; Thu, 30 Jul 2020 11:47:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MFQtsa6/JvVwSBaAByaOldr0YDwh+cTzahYn+RlZKCb9+q7R1/EoG6MeUIrSZcoTAw0aY63HCdVN7qgqbVMqc2CiR8PUr0DYXCCiA5LpDoxrL9Qx13w/UgpIhx79iNA7wkFLTbrmxNfxI/YxoSlz+dFYA95QK1tSECWmo7nI6DDb2vjpHYYaMq8RzHEjmMJ0/9yviTubjUwDVc4/tTC5Ha/de/sShdL07ZsVCGLxdT/8hm+teIUzODv3P3VQwCBeCXi5T8FgRBDpxlk4AT6tBm7jF6fQE6GmiuATclGTxvulB2+zbLVGhvQCOtIC6yalZGS2J/DHTZ6krWRA/1Wnuw== 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=jujDfG4zZ8ZcOp/0c8YPYzUG5Brp/RAb+omBvccTsMSf7UhRvkW/K84rNxfRrsKewhOoKWIoalArRAKlv7YmG4B6grbXjJ5UPpLK1U3dgvPlULq7yxCpzu2crPdWu5vopoiigp8Nn3N4VyveK2Z05MyxuqdkK0oh2lgUI6A7iJBVemqPgtJV0VEbvr5VeaNayy4SuACwEpfAhF7vrWFnecNC670jG/GzTcF8Q2Go0f8p2cM+IHoZG/JcjAwHyhJdfnrS2cstxmHLb6WzdDpzRNudb4mBZinceLX3gVCE8eMSi/vXNvepgJCPK5HWK/tZNyDarQ8p8QsgjVoXR06vig== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:47:53 +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.3239.020; Thu, 30 Jul 2020 18:47: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 v13 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Thu, 30 Jul 2020 13:43:35 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM3PR08CA0009.namprd08.prod.outlook.com (2603:10b6:0:52::19) 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 DM3PR08CA0009.namprd08.prod.outlook.com (2603:10b6:0:52::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:47:51 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: da3e1979-7b25-4dc7-844f-08d834b910b6 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: LvJzJ6ARDBBKqFfWo0gajSOzPhiytKTyLNMjc7/uqwrVgGGdOPsNaOL+Dcl1NvIM4mpFRiawyXeOl/xfhkHPPuE8P7oUU1xmycBWHnjEAnmVtW+rtqoUISHbUBORCBHI2m8GZCy9vdEu0gpUQL9ESEcX/LPf9V/wEcQq/7C7ESAqeIz3ptQc0+2i4AWlGn02jRZlmVHSf/o3jq9yiZz97H7SbrZJoY1DLzzSmrwYB7hlcHTpIC9FBtXuTgeCPnlVjszBPSE1JBB3jOogIau8yTb9qlz0golHxDA48JQkf0fX3HfQJj6QVrUwwDZtntDIZ3cPfgQoDLKd4MpwbfmVVJVPCeplShMwg6E1jYMtYPQBJTx+qELd0DtyIMED/1LNeEVB03fU7bUUyEMx9y3/0ag0i8aNccqIb5Vfm9VVUwhc/Y6Ec3MiOemEcE8vOeF3eVU4T41cGovLqfr8e9hMDQ== X-MS-Exchange-AntiSpam-MessageData: q8/PP3Zb0qv6s02QwhO+MKKluVD0nMG9holMSe15PphjzuH8q/iQu2NxbV0/kM6JA8DXHRsep76UmTbQgsMTs9kfC07Y/bTZXUEF9gZqUVmEmOXBu4Y7I633u8vt6bHNsxwJw9oclq9Cb3r6A06b7ZVLBxJmrSH7bMl4Oza3YkoX26GBnCY+rl+UtrMipUiJ/IF5av2n+HDdGVZtvR2msjmpEYn0RSIny7b986QarmroD4xGRe//sN8SgF8Vv/86TmqeJlouzWWQV8HmFJfARhcziNNZn5nOYHxwxK8U82IA6ID0JhhVEP8m5omq0itWdjyvMYOzWUgnY9RdYaSbCcvPlg3+5fkKVNtuCPwsKlJildwNz0D1KxKlInjQxGdcFn1T2mG+w3FrdLma1g6nnRZ11xLb+ZOTuO7k+h/4EuOkCd+7BlOh3rSc/RLzGjrP3qW22qa/DZ6eSjPuGk5N6VrZA84LrtBY8KOwctMqZq73GR1adOOZCXlEIVBU8aVRitxZrY6VhGY+NG8onj09qJqfI2itPlurqmaSx//KxJol9imrwjHTaumzi+WEKHyQLAyd+57mFYuZa5bIR+b9r9oITXhRZMNSbUzdvSl1Qqq45RKnGlW23ivlsh8FZ/Z/ySTv7egI1kq0/c6nEcIaMg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: da3e1979-7b25-4dc7-844f-08d834b910b6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:47:53.0444 (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: Ds4+xtZQ5wCpfZ46aqm0m8mdgCdyVw7g+9YuBQFgWccmON9rPN4N+NEjHk9IBwdMxPsqF0fHRDKRCrbpwTugDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: gZdC2W0SBLu2gAoxtPXBI4Erx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134874; bh=e9j+ePWCCmgGWhSCJajJBVaLZbcbx725Q0LfsnixZWo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=nJN+o3iHA9O5flrjCj3vjo+WJOiJQK9oJEWAguK6RbhGMqL/dmolJzr/tto2LZVE8v9 fhYG+9psOE3rQD+a2YOJrK1BeWU7iKYSfmjHbme2d/OYvfimNE+D7Q1A4oN2VFbUpeHZ5 aQBzmaQub429etQz8tlSpf40Bkpryi2OQfA= 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 (#63500): https://edk2.groups.io/g/devel/message/63500 Mute This Topic: https://groups.io/mt/75892747/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 Fri Apr 26 18:26:44 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+63501+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+63501+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 1596134885124637.7803217246496; Thu, 30 Jul 2020 11:48:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FUbNYY1788612xj28h30Mb9j; Thu, 30 Jul 2020 11:48:04 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.57]) by mx.groups.io with SMTP id smtpd.web10.1780.1596134884222643306 for ; Thu, 30 Jul 2020 11:48:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LEi4vquajWRersJP8OPKyIZqhzR63tni81npLJ8GdrxOjF8BPo5AqshqFSBw7kPLBmsyg+5fA2y5mh9SSUXR9bQJpqh2oUweb62oWjksWJ/cutmaY9ctqI5Wp9rkAWxQzrcM3z7yO7lIsIWHaFgJdbClVFDBKdVDU8yZ45o36IMcEyg5kkdpKbzSNjdbj7gZcy1xRjUmrzhz/11w/ftXN+PzvEYXN6y7IoHvUVURKpXpG+Ztw3euwsC7iEDFSmg8s3pS08dHOIbplTiFG72Fe6JYmMcIHRIB4jUMwqCS+7mzHW46ah73y0bE2J6/0ddfy5W1+reJ6qXLQgkk8R+mXQ== 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=VemWtiPS+sXY34aKbGFbORKjqaZP/Nx+pPOmTVfxOxwca02dJ7LvoZxQstoPm0PT8lT0hKFy4fYA1TTmhClLfg4KzeJGJrhYPCC+dBNcYc04gtrCXcdDwpdz9oTFzrPX+l0HfWEbGzzMsGHl8x0NotidwbZ0iasChk5UuFpavcRkqBjkJCsjHhB8aqQTmGeGyWJ4UW6+i1JyQQoikjJqFysEV4IOwgkjyFNwBCVsrub8KSmI5Ytg8J331EVcZi3j5ROYtV1FK9RrJDDpSv+3lbBqYUGd5cjVvOTXt45LOMbZcnr9xcBF5XnI40NIgE6UaBPpr4PAo8iu+qpQ+0vK4Q== 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 DM6PR12MB4385.namprd12.prod.outlook.com (2603:10b6:5:2a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17; Thu, 30 Jul 2020 18:48:02 +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.3239.020; Thu, 30 Jul 2020 18:48:02 +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 v13 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Thu, 30 Jul 2020 13:43:36 -0500 Message-ID: <391a9756a6a28800daa16468856c08fb5249317e.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0030.namprd07.prod.outlook.com (2603:10b6:3:16::16) 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 DM5PR07CA0030.namprd07.prod.outlook.com (2603:10b6:3:16::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:48: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: eef129fa-aae1-4c42-f908-08d834b9162b X-MS-TrafficTypeDiagnostic: DM6PR12MB4385: 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: kqNN4ZxKe0PiUetZrQwb8kawC1yttrbldh8IAkO85vyHjisriW1/21rRquYe3hTHmaVqL056o9MnByOvC3P2U+pLXAAMBvcHEDXu6gdZGZvb2gEIciEvcl4TLrabQ4GlwaZyfJnMNbe6KdFJ2Mhg5wabiwJJ1DYjj1CMuUiGuJjiJFCraLmhoVKNZxtNxgZoJooLbG2v4gMweZTeMFK/DzPrNaAlFX4oCGYbNGcwUOZ5MThgbPjWvU3dns2sbLvp5dg7THXgHg+K4fFi6C7oaKFcnIqSWee8frcKLEK8bitcES/kmYCI2LS9BNMuoA+NQPNZlhPyM/8tLlZTqSIKYnQpMRKWKkmxhSR1EyyBLL/TkhocOvcNdF/rX7BR6YZUYcLwKmNsTVBW+WlZbS1gTZDAMfTDKYYXhLHktr4Qy7PKRukyC6C5T0iInjgNqlNdonmEORbyscNeNqixWg8xfg== X-MS-Exchange-AntiSpam-MessageData: hUrQ8qRtNSxDK085LTfw7jlzZ9r9U20o+tTClz74bIO/t+r1ig1dQK575aOdY2PludXkpAkdKbAtHj2rzGacUco0LURtFfQ3kpioRtBjVG5KaILvhPYB5KVQoPIFVyfkJkfPVdWAPdyxP1KV+osiD0Jw6qUlTRh43rBsnOBIEx4IKjujkbq2ytB/Mu68sbXBKhPMyIIBeB2sy3TNl+T0xxslmVkaNwXjauQVi0iiyw5TKhpJQE9VK6XxM0XnpXJGp+ghQv9Jy8SVLzBDokhu419w34CKfM3rpt8Tu0gIbCc7cQtyLWE+P9f8t7uT/L2z0CcuHjd1nfCjN8z7Z4l+UuBKNigH+X0bKENTbEGXl0rcrcqw0CEhSAiZeLLigqnWiQjd7owCnmI75EAEsM2Q1V4t8GtSSKdv825Bl81nO830GfZED4tzFDjnEVklbgfeglHmO9nKg5yzbIGzOdDEngAXdvyOZ6LK1qQWU2QjrmDt5zHD3mJCUAQvYOCJly587QVGgYFSZ4v5RWkusTR2Tp2xeULFJ3d99fpIVSbmUcQXWC2xpJytQok4OAeGth1EEFwOYE/8mhPL7Qo3czNKw1CkPp5GSHNMifVmE1mU3/nkipoEEfUbJUqglDfGF4wkGQmmvc2rxKdNZM+2NwShDQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eef129fa-aae1-4c42-f908-08d834b9162b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:02.2138 (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: gMfXsYY6v+2rUoVokxtc1jrcVzyhyMe+ntZN6vpDJPcejB4X5vg/T3Tl3DgjVFg8sHrzWUK9/pL4eggDUPGJug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4385 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: 6bpq13dBNodOf5rC55pKMS9Hx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134884; bh=Ji2oo+gkjUZdw6t2pPTdoWq87lCFEo5+vRPpDd+WiZs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=CDDEJj7GdUy4Q4BB4JknyFLixrPhEOVkLdCjyRBX1a0aK2RBYQdlGDWoMCYTfd2UVLr uGBjygQMetzQCf67QozwvIsw24pT7kWAu4IIqMfz31BU3Tv4RFMDKDUEKO43+4Sv6rTAP P3NLmN7iWVQKDVHaSeGdLsEkGDiJhwKmWlk= 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 (#63501): https://edk2.groups.io/g/devel/message/63501 Mute This Topic: https://groups.io/mt/75892758/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 Fri Apr 26 18:26:44 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+63502+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+63502+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 1596134893384880.164910259987; Thu, 30 Jul 2020 11:48:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UdVYYY1788612xHFZIdqsbx2; Thu, 30 Jul 2020 11:48:13 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.59]) by mx.groups.io with SMTP id smtpd.web10.1782.1596134892515974528 for ; Thu, 30 Jul 2020 11:48:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQ6VODxHZz2cGBwhLmxVdLj6EE481UeevgVnjTl7eEHffBJhlX3vLNEjLD0fPpsxgV9gteRRID592mLW4fWeqBjYWD7NTvPeXl5zjbR48XllMjA86pRAp74DFk/qlNxk0ccTPiIcZoQfjYnTi+vCUwQlmnOrxdXRv5OXsKuo3yY0Fi6tZXsvL0Y/At1C73osd6pTOXPAqTLnFsPB1BVjoZHQOH02JF4aRuTdyDWOc5OyuFvke8b5q9vWEd3ViUssec8yiW3nhJ32bkWVkDJf7P4K19QdTLHsM3cp0cp0fBVCTJAJJ61q+c8v+vEXElOcWqsAOArqDfBwf+99/jYBcA== 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=QYzzkFggv+vACgBj8BmEBUrEal/W4kUfXyeGxiks+rNbspUEKiTweB2+y/eiXxeKIncU9iSm5uwxffSdifCYbmoXBiqdmbKbw8KsR04SKydTqNj3Kt0e0KGQ0lfQ9wxfpmruFEJCD3Swmpp8/HXWY0zVf4m2D0wrwsgLCxKiSIRFEj5iciacQNfyncHkjh451FM5+Nkl6owjijSrj21x9PuBKXeY/LHJmPnJjS+/awkEjMBFHDWi834/AXPrT8zMgRcvoj6TefShcHiJvjkB2iNEXVGaQe9nmLm1s9ibQOrU0fj6tyO20e/aHBtkLBseBH8rBHUqyX62L8Q1c4xtPQ== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:11 +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.3239.020; Thu, 30 Jul 2020 18:48: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 v13 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Thu, 30 Jul 2020 13:43:37 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0134.namprd07.prod.outlook.com (2603:10b6:3:13e::24) 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 DM5PR07CA0134.namprd07.prod.outlook.com (2603:10b6:3:13e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:48: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: be67158d-3e5d-46fe-b87c-08d834b91bb3 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: MWPqQ3eI/CgbR82nZBJWOS3yechmja9sn7RTjZLBwkVl/ZfprOeNf/yj5llqJhX3PnpdDtDrZ+3keejCFn11I4x2p2N4eBP/vrahXAStjqUHNq08UZulw9Mg/5m6k2g895m2etNAGMrbdtIBwhE4J+9U8z/qvr0R/ZQxGlINcEFMcorgB2dAiiG8FcvoDvc+4aWj1ZAkAYBRL1dh2qRoNtRWLXJhbHfo5eCFuUTZY06ofaNjB1NNDLUjnpWkQ5tkQSjBJmS4wWqXnU26k31awno6qyKOa3eukqrA9CZ5cLXrYa5hMZZFcGyWfPPEV8d3NMkZ/nOAYsiw29i6Log4Vcz1q6NYWWjDjULAmVhzM3olA8LWBgwn+6MjJWyVkgILPx3h4To9DGvOU1W/W/KnO8M1IQyc2KJE0jnZWn/JvITifRAmzzGoMtvmqGqToQHC03Z3/Vq1IyxE4zeG01EU3A== X-MS-Exchange-AntiSpam-MessageData: M3oeEc1H7NRdWH5cEc0o6xYHKr/NsjbuOdJmUURC3qnm5ceGYAI8MARUtqX3R7MZvYnF2QoklKC+wvgOdfBV3dGsEGY9simcP/uEmza6FOO9xOYhU7LkzKkS0+m9yPPJNaT1fOqf2a82TRl4OXwwGUeou7ovS7DqFESsxuoeLhp+rEZygLfnQDBL6hBF7n6si0HHWHVfJccHrfG24bB5mpy/wKB6MLgA4OX7bPHhU+bBV7SyCXAUjsDE68f3hu8NJNN7LBLBK5VMN7X1SpKHcewDSZPZsN+ZqPy5l3+DBHKwRPtW3lsyDRY7DMKC3zqiB9Aye59q2mJOiU9DPGnis6a+yOc/4EcBUOeIHyfGtMZPN0LX0S9S9Hb/3aTwlRA8IGjauHx3QU8QgVbmQ2VCHiTrTJDhfM8JRTpbhi1gbe9rhpO7bH6S5hd0AgCjv+GCAwiNIqXo+9D7681JtYfAMt284uvUjY8YJsvNB/d8FSkAHiz5SS9q7nT6oJpbRU7xfQysys0UWP71yKQn7l/+GgpAXPqbY44o+11EDfM7cjvpxQWhnpJmCd8g3IGDX9CyCQ3+W0kb23SQOKNcrOioaTsgtp22WBEKDtTxMdatX1fYBBreG7b92egnxicdRGrvdUr9Bdbmjkvg3DCBE1BEFA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: be67158d-3e5d-46fe-b87c-08d834b91bb3 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:11.4411 (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: ooSwikJyb+25o1gACm20m9b/WVI67cdUkdSRycnVMk7vdoMEFa1V2oXvH2IXGngZMMv592Ovg2tRvn7YM5ZeIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: cT4zLYbNkvFABHJ09ZJUmqPWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134893; bh=ebd+vY/HqKj8jYHNu2xw46dLz3GH27OkNy+JP1GlOoo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cJ8/pxth2h9mFgl8stVyGOf1frtfxEHCzDrTYgMIqXcld4exl8lyPYxMts0M3DE1zR2 6i0Rr4PrqH5royzBo7obBmlLU5p/9kaRK/Qc/dkyE9pgMa5BLnbS84dmkg39eKZ8RU+oZ ZFqRtccGPhHjVl5EydudcdZ1yDbsjWQI9P8= 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 (#63502): https://edk2.groups.io/g/devel/message/63502 Mute This Topic: https://groups.io/mt/75892762/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 Fri Apr 26 18:26:44 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+63503+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+63503+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 1596134902747183.692564008609; Thu, 30 Jul 2020 11:48:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mF6hYY1788612xT2nUckNC0a; Thu, 30 Jul 2020 11:48:22 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.86]) by mx.groups.io with SMTP id smtpd.web11.1815.1596134901826760348 for ; Thu, 30 Jul 2020 11:48:21 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MOZUVBCdSvJMQnoRqfioJPPOv/GD2c90VWsJ6gCGwDpO6cFmv/XWS4ERnacD4f8jR5crYTo/8+RejO8eXRV7yqBGGjclYyxJ/ltOIuQE42vQvtsbCoKjlWxu4JVnNOMbgS7ngBfdnXnOaKQQCo5pQbndzVOROnTMtAPylRkNCDWeNoMMExclLgTuAUmkFJFIbHs2mmHBT+LpAqvO91AVOLQ3a8jDUJ7Y1RnqriTj7WvwfA/H1ZJxGxU/MPa72LQPmwt2TnRrEDk2zzbq6oI0JXWTDexBQ+IV7YWZZG4agFhuZHyHgLefsy2gD6KVk+LA4oeqPT8m6PUp1Jl2vuJhUw== 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=oXilg7mYh5ilvXiGB6z9TuHJmxhwveEoXkAVNCXPtWi5bdfYO3rzcSN0bLPJLJBvVBAne3zdnHf/DDc2oqcJg/J8ya12WOVytrDldARQ9PjuhN7fkLfyWsU40JFz++8lwODS4/kkAiwLxhZEra2O+YgXxhgvFwyvpAVWhibyeEwd48AfffYi3sFtfDpE03UZmbLm3JGOcfzNRLVcrwH4tG3EsrOBxZri0WuR9HFstnJU54mCO8UV+NaG9514fTuykh3ucSzjxIGhkmBnlk1+nR2+nXM3fn5sYO2PHTkm7aX5z5Hp9GFRUgT6+LXwlz5t9/WaKWyepNixFPTooVhfYQ== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:20 +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.3239.020; Thu, 30 Jul 2020 18:48: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 v13 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events Date: Thu, 30 Jul 2020 13:43:38 -0500 Message-ID: <94da03a6937ae5ee04e95d13bf735b7021982224.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR13CA0011.namprd13.prod.outlook.com (2603:10b6:5:bc::24) 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 DM6PR13CA0011.namprd13.prod.outlook.com (2603:10b6:5:bc::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.10 via Frontend Transport; Thu, 30 Jul 2020 18:48: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: 09c24852-99ff-4a8d-7e00-08d834b92115 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: U8SbCoSjapQv8ttRzKMtZho2euU9ErjcWXtesQYFxxStfL/N8X0e3e6lywaC1PQfNqBd3BX8GlsJAWN1M1e1j932LnZ+HwI+fwaqFXvwdoo5Ta3+WGjWVdk6YYISYz9t/2mFhJFWz2nS8gWHpxItIVatWALuM7Quhxkd00Zj9eLMQh9KFDxQJqIUmyax2DJH29mDk+mBDDmYeyjuWjYPhLGc2wD+wULEEKiuXKxBjt8v+Ra5GyNjtbkv9fVMYn1CDZs9obLQ5mf3wKEl4iv1LYVtA0iFtuDFkuyfdiqm53w6lq3U1Nd+dp0gXn9Rzd8cjqITfmeJYbqZzb5knCQcpMrW+WcmKbYglhtSNLuIF+aMmserEdhIJLb9lpOsk5X6sLNOuOcV9Dlin8AwiANQIl3Wvqaac8iZXtlIz8lYi3DMr8Vn/peBBdnUcK0+TvSExnW3FNd8rXYVqhhzOrOY3A== X-MS-Exchange-AntiSpam-MessageData: MnW92IaqnweNW/4+2UCZH9fGpY81RGO7h5sN8CUZCICUlgmFw2odp5AxJ9d6fmi0O16e6BBPzkJU3idIfRJpHU0R0fKdy9Cb4VJs18Hqhtx1gYD9A05f44o9AWM0L0t80i63ZX7apDoEe0sa1DDkwI/Mp5lfGi5qMbrXW9VrrRQF/vhWZk+NBaEQTFA0tHM+NwTmGE07d53eWbza53yafsvk/wgA0vwT/M6zX536kw5T2L21F/lLudmQEIHVEWRvI1crkd7/tAGMG2k8II4uZJHOChIeclVnl9bsWiCPZq0abNM1nqauArpB1W9R/TNQIChSnAyhX35A2sYQhYgTn1pAYukaVPh8hZZryfKKcMSL5Zjaxqi3Kju6OtnIUTYX6QDKU89Wp0hNl2O7LkrUC//eqkuC+oxXHEof9T6HErAXe9WRN22M6OFSBq0ZL196lyV3LAWy5RhXiZiKCkzwOtdt3j+Qf6XB0RHpJ8M0xyxAiPrDPczMZtxUkJGrUkWfiB41rf6NGmrVboiko2XXlrRisBAN4Cc/YAh6Jt2lc21edKlh2aO1gifmorpxgyVZTxSglVLxKh6Z6ApNtfEjrym53MHf2CRG54C72GGZ8tcVeY8rBGb2UqcbvZWYslVw55A/XGKqKIfiuXqz+MunQw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09c24852-99ff-4a8d-7e00-08d834b92115 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:20.4954 (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: MeSSj2zBhLCISLsueBcHxJfpnXBTLp9ImDVXdbkyBn14A9h1XrQ+Ke4EH67eb1Z971Sm6vjuKpnROai0AotYsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: xn6Wz68BHrz7yjK4yfhKyTbrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134902; bh=mxDp/2hFnGp7gU4Fn0iuancdwSBVY7WyiwEsg6dKv/A=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=foUc3oPAPDn96/15abZlR+7eE9LdYWjw9Dux9sHMWpFC2yI458znImLuGRWcnWz2wTa zTNBnkVnOEnS1p3jAGiPGLVxk5BahgCVOVCvBoxnhiymJKDFRuhaD+3No8GYihWEjY0gm S6f3eryqr6OyFour6MIbYFpWvVG+QAOSCf4= 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 (#63503): https://edk2.groups.io/g/devel/message/63503 Mute This Topic: https://groups.io/mt/75892764/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 Fri Apr 26 18:26:44 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+63504+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+63504+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 1596134911689316.8157886786569; Thu, 30 Jul 2020 11:48:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2AT5YY1788612xzYnXWv0yuu; Thu, 30 Jul 2020 11:48:31 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.82]) by mx.groups.io with SMTP id smtpd.web11.1820.1596134910779388931 for ; Thu, 30 Jul 2020 11:48:30 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gJYp8Qs5XKv+irujV4WhSnY+JUYIfHz2LgnMkNcn44py1xOC9aDk03tveLcPgK4nDyoa1DMo3O0/IRhh6cZB6Ss8sq3XEbvFqO9H7yCsP+vJEjx3nDBM5w/d4W0yIMx9zsJa+hj6G0GLc2epeYYVsHyGwPDNjJDV8kVFamzIRMXAAsEJ67ruEdfboluHZF8e+OngVHhUGl6q6eRcKrS5CPNUzZXTdX4enNlaFAvMfxTnZ0NqlzvDV0wKfllBim3q434zYWdiOizm52VPcyTZds3f+LwI+Xi/XHsvt/Yv+bw+lHpWnt7yF4XRVAxwJI5XCGu1JCQPU1dBuiandkkQgg== 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=djevNalRRaunaPaN2OAdIuC1yIZcVLbLgEPeAz0ruVZYq9W1hhIcQ0sNsDEkTYJxM46m/t8TawSwcICqBphIl5B8jlm8wq/uaY+wQFE4qvJYy3FT/zagLqgRrJqMqhV5qjT+FMuLyxukjL6T8G1ddLa4jjxzd62qTfYtsPb1KgO4n+cNbwKMAWax7WrnzQOGAaHF8hhMBq7DFcfXnWtLDvQSGUQaStCUGLiMI/jikwp3Cbmt5+Pn6ya+ALwFTpkr9M20COinhP96bHB3SGiPfuCGIRi11CPjpWkJ1x6f0KNUBrU5Me9ZcAK/dECajMBYmOUVWhxJU1e6eppen1z1Nw== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:29 +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.3239.020; Thu, 30 Jul 2020 18:48:29 +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 v13 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Thu, 30 Jul 2020 13:43:39 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0019.namprd06.prod.outlook.com (2603:10b6:5:120::32) 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 DM6PR06CA0019.namprd06.prod.outlook.com (2603:10b6:5:120::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20 via Frontend Transport; Thu, 30 Jul 2020 18:48:28 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5f3c2afc-f3c6-4f65-d252-08d834b92674 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: PNirAce/SojRV2ES85L5ZDg/treZZ4voqYbJnwk+ydpROEAQB2sQkqwQNrSsa/sadVYccLN5pEVwnjNxe5gzOjk/An4Sriv6c3buSZwzrDVXjOl0xfHW5KFgacLHo0glQPj1dSLCyB83CFnNx15ketuPPqMJDaJpqV6+IQJCzh3RhxVuU3E9eqc7SjQ19II14xMgN1SmIAm902XoT9RsWnpkEX76+LytY5oWpBzt5kiDjuhtsHt82Buh/Gc9C2tVzjl5IJ3ohrtX43rqeZCj1r1xwROG+naM2Utg3n6k9NnzNnkPJVQ5wb0CVuzCSd42Wazd0VSz+QfbUA3aNHu6eNwz9SCA2FNsTBPxEQOJwltMLhbHn3T805dAiWvO144C5wB1/eLbQ2r5zdND714hCE/ixeHxIIuHbrf/R+WmE4J6Rg94g3KSpbGynD1Diu+4bDwQJJud8FTUPpkB+9+yJg== X-MS-Exchange-AntiSpam-MessageData: ch0fbMtvkxCzMQ3atBb5JSRB37ttm9C6w2y9m3/rIPxxdmfP6z/Sn/qpn8it0YQHdcWHRvuQCKuiN07mFeMZVeGY3EPI1FaG39kXwNMxtrSYvwU7nG29r4uowqha9QiVGpeoyWGtV3Uvp+Zp1pjhYW3x6vF7vaxJxbXb0xCOrWBRCuXtneInfhh6SUeN1qIPDxkC/bJ58+FRXhWU0mM7lJJbfIHXdmmoBVghGgkiq/vsaNGYGTLiqCxtz5j/btBv7/8bmyZ7vfT7kkp/BFxgh+rT56qHGBstjyypvvOr+4qZAhpVwbamqJ5DgWSO5O46kwVYeYHC5qNfO4Q1IXlLaNWS4l95aJXtEUc0kqjCC31jAbkUn4xyM7C94PwqxpIUcVkJ9IUbR6q/ZIu/RWjKuxldwDQHOqArQGqiqFjdmCRV0qLCtKRMj8m9TP2RD5ZPDYlLtXX06+hIrwh7JiS5hH5XjrgFuzBR0SMd2t/XtuwLI/MlIuJ4yD/owLd1Y83PLh3Du/sgurQqSPejhLT3WeNnUt4vft7zgWUd71LiaGTDYSoKhwYPZxWGFggSaN3WtPxxftOTAmFnj9QFYN7cpX/PYjlbtxZBTGKJmHCySyIt75Zomj8JekSFZoAtYG3G6jowjCbVh19YUA4um6eRzw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f3c2afc-f3c6-4f65-d252-08d834b92674 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:29.5667 (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: J1eAn8M3+in+7wZUa2t1C3NCN57ShF+CUbrSizcnOIlieCZ4/u4b1s/MkMFTaO49nZRzmHoJohzS9z4oqdWllA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: HFJBEXtMRZ3QvFAALJi7mLVhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134911; bh=Z3eg68KL48a13/m2q5FW38BuLNmXhyGoZEK6Mld8ncQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Oe3Er9qsF0M0mI+q0aMyRSrSB6kZbzK2qdU/rvIBeSsfiYR7797XN7DIg5TnvQNxy/r OzayyIbmT6DnTn/mVS01wiju0wzjxDHdnc+fiIvh83TVyk9mpIcP1/FhJsFv7hEjS64Ya 6eIHbXJgLEpjgHFY/5FohgrsQroN3iuf3sw= 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 (#63504): https://edk2.groups.io/g/devel/message/63504 Mute This Topic: https://groups.io/mt/75892766/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 Fri Apr 26 18:26:44 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+63505+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+63505+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 15961349212331000.2656448468622; Thu, 30 Jul 2020 11:48:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ixJOYY1788612xk84Qfujlmt; Thu, 30 Jul 2020 11:48:40 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.42]) by mx.groups.io with SMTP id smtpd.web11.1822.1596134920161302766 for ; Thu, 30 Jul 2020 11:48:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j29tQu0+rBD1wO+fY4/PBMwRjU8K1i+NqB2y1LVCillnStF3w4c4CGzu7yPSDGze0KhDRTArbeIMQ/EqLAFSASeuAhtV/Gnh3RgTe7m5hgl01WFMa88us1l6RGx3P6VCoUKfZ9kGOiYvbcIV0l7iWUBLhX6AEn646h4ItJCtiJlBSN8e7guKCjbobByhxgDZXA1ZRKfAYUZfpXzBFp31O8z683Q03q3roUpyqv+k1zCaI2eM98CvYVuJAQ0qTYtibFbWFVVhMATWTEv1mneGCuBrlZroUJwsnNQ+dc6a29HNct/MNatj04LO3dAqb3gpqxBOqgCFN/e7cy964Rd9tg== 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=LxRXP3mF9FmwbZY4aJbmVFgpzrJyZYFko4J8VkDBaYTmElqiUAKu7rCIFt9O6cKzbyOaX1W3szinpe7E5X/OAHwKPTzfOgmYbu8y1A5t9Unp/orNJsSWHYTcmd0oXtruBfznB0AXRjSg7/Hywff0k790rrz3HQYR2PguJVQYwyFBjJHnR2lNLQb6IRcwqN8hNbz94IM5jfIwZiqLxnSLEKdNo7gADAbLP2SldhsPM3aJSpbFfZcd6qdWp703HlOEQDOkLl5B97MeTaXXNDM3xU7MVYt2VeL7+3eUEnOftvkRqjXeh6XclcUvBZeEAfTle3yno9anvlyNLynPsIfymQ== 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 DM5PR12MB1867.namprd12.prod.outlook.com (2603:10b6:3:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:38 +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.3239.020; Thu, 30 Jul 2020 18:48:38 +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 v13 28/46] OvmfPkg: Add support to perform SEV-ES initialization Date: Thu, 30 Jul 2020 13:43:40 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR17CA0051.namprd17.prod.outlook.com (2603:10b6:3:13f::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 DM5PR17CA0051.namprd17.prod.outlook.com (2603:10b6:3:13f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:48:37 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 555d5233-deb7-4bf3-74cf-08d834b92bc2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1867: 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: +wI3vH5ljhAnm+yFNeLI20xe0s3rMOkmyLgQ0uFwlZwEJDGAl0dzcH75RZJdB4YYE0GJtoQeE1i05bO4ULfI4uPzCyiVNARaAA5dOwqKlJb0qyidHgJhR7Zp+bmkGQpEKVKozeyMCNvKEb8Lv7Kh+Id0HpK+7RN+bjzBNIguDitreNoF/rtIpPJNT/eHS+O9bohkL8RPwqlGkyClSWZqXCfdltu494ZzTWErq5plOpXxz+KZTJyzRTfdEYd+UmPwCz7KV65vbPokYuPLLEzXfioo0CJKkArrm9dtc6yEYiEe1gji5s52CxdkiGpsKxfUPw8+Rf0vymYW08VckAvrBLo7X3MeI21yEkaPF/iOvkQo3pChr2QX+wUry77s/Nl+/W3rCo3DfTmzX55CbcXBjq0ouNFrtXCbo87/7RCmpgbNi7cumwNjZTjKAIXdB4Sf7uIt4Lbc+LTJoYZl4n497Q== X-MS-Exchange-AntiSpam-MessageData: jhpxy5t8gQVuT5ICeckosAJ0OKfMryTcw9fSnltjx+ROJwXfFbrqkmDNjgI3Qy+XZ0sKrip7SLiblPh/mMGG3klXwm40hfpzLv0mwL9XV855CsGilvDNvgvQ497Yv8XPXb66jlwgRgdk/RjrNXHZvkmgpjPrkNdQ4+6I+mMV8vz3eohLjii2PLpdY5WF/HugEpiVmsPivVhRM/R8Of4X4kh9/L7hMgmgvO+6HCJ8qHtD1GlbvtLR84YINkh99gZ//welW/qOcKHFODIrgfuAEvaxzvPnB9qUGNsSPLDU2hgrHhMZXTfu6TKoyIgzA6slmy7LOAYfjnZp05FiCG46CyyN0fWhSdwVcmpLxn0vTXUUuD//AaHklL7DRMPFLdYnuLUU3WWDWDIhsr7Vi8kSQvRZM5f5eVKvmPT/Ivmwu6dss9sg620rK8bTbQUHj8LuxN4L1fHilFhnP1NsjjvrRhDazrFQhxn+J+egRcp5JgIGcVk2U5scZs4eqAsWGN/FDpr3jegE7HkWypEidZ2HFkkmC3Kxty0eTh0+28u1Ii8Qygq9p2+4awE4/m4NFxiOgVJZuqwByL5f9O32Kaph/M2u07fnLJVmjq/IPbkOGLUl9S4BZ92N7FmFn24AhOcJzAXpruOB9KdU5e7Sjih+OQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 555d5233-deb7-4bf3-74cf-08d834b92bc2 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:38.4421 (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: /vOpDgTGaAaw1gbengunoRQ9UAF/Dw2WZTKRnvaKiXAF67U2GJ1bmE/lbnfR/Zwaw65w/QBNAnSBKfc60dTGDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1867 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: a7XPo4MvzqzBC2JSXsnfxXDOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134920; bh=FRALpjejBKOISlGPvE2vJhkqvFqfn2hLRfj5I4PnBLc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Ax7HEgNiriFnVi/2cgfmuU0o11hkZdBeHn6PVdOKSDiuuStPsHAzsRMT/DflaItUU5X OmtAT0uQckkJjFIoLu+5sszPu0q9eyO5YcvR0ROtuC7ISZy9paJpZU68deIMaUaueX6+i ehzIFcJWnZ+HStSyP0OOmuwhdc4d+Rq7sUs= 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 (#63505): https://edk2.groups.io/g/devel/message/63505 Mute This Topic: https://groups.io/mt/75892769/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 Fri Apr 26 18:26:44 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+63506+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+63506+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 1596134930480573.6275679732241; Thu, 30 Jul 2020 11:48:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id oXjUYY1788612xxkYZxIqt4S; Thu, 30 Jul 2020 11:48:50 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.69]) by mx.groups.io with SMTP id smtpd.web11.1829.1596134929477290917 for ; Thu, 30 Jul 2020 11:48:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BKmAEyYGMSpaGK9EsFaCQ4poH+Ib7k386Gl7vz1yG++2q8733iaNxii9WKAdQlHAeJZSq8uBFQYsVPEBLDm62N2oJ4CmnyqRamr4WfeMnrXFwBny0lyD0hTemFQROFLHXUnr2dnsT7FFos4vf/xJrIKgUVp7+NSuIEloBEMaw/0raWmxs4AtMtplSaOmKhXwV73Q+Aae+PMRIVX9/APRQhsCqjcaH+ooA9E26aM454eQY3vm8DzTiraWP/4fRFJJtIZjZYeVBvf+0uO+pZexiI/MzNd6BJsmYgYV0pNbh4Kn8+kP3W2MICAmfW3jwuC0yeEDFRnVJQhCNcJKy7NYHg== 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=l7NJ7U0gEUkztbXOFm4fDcIFFztUU+LKu8hI4Qs7GElSYDVwxOCPLJsRJUyPSKCpIVLtEV37RbMIYR13hTHn6yJyQsrTuOdErIJVMlF8TuSkyZDQLc/aabGmnR5a2PeNAj+y/zJhuVsuG/LpqkQf6fmOhIJdJBaY276tp/18myxvFjiCihC6p3x8de+7wqu3DJFCztDFQoydQgNFvs7FRXRL2dT5MP/pZwjsNkwmbCrAyBpA5LETH/+m754IA0WRi85QctsmS3pPDTevIGAM5vC06Pn/BHvUPxGDaembs2yg1F9TqoENm2E7ug50oYBsk5Ru0YBi/k/YIZukMyaQnA== 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 DM5PR12MB1867.namprd12.prod.outlook.com (2603:10b6:3:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:48 +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.3239.020; Thu, 30 Jul 2020 18:48:48 +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 v13 29/46] OvmfPkg: Create a GHCB page for use during Sec phase Date: Thu, 30 Jul 2020 13:43:41 -0500 Message-ID: <84e906a67891d8522c5659d5358a194c604f91c6.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0006.namprd19.prod.outlook.com (2603:10b6:3:151::16) 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 DM5PR19CA0006.namprd19.prod.outlook.com (2603:10b6:3:151::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:48: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: 8e3bc3cb-7f8e-4733-5121-08d834b93169 X-MS-TrafficTypeDiagnostic: DM5PR12MB1867: 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: QD8SB8iLq0Zc4M+bRR8wcZF61gaw4wcQSs6Xi3hHjjoHg6Cy7p6SWo+ZzMsiP4DwhutWKXVeKzAu30mcBOMp28et8xhGxOeX3q8hAzWBNb/JUHop0z1DlFF2N7bDjepIoeQOFUIqs9Ma/RiVp3JvTQLJghG+yBwdlUKZ1/D8C5fpHv47ELuP5ow7n0pV9b9GzTDMrtJhU7LEusL0ggzdxnawzWhgu0xF3UWLj1Hlfvgzie/HL4YQitFKssjORIC5DduMTS7sLwLCMD3s442KpsRK8MahfdVAQyVUIhuAi1F5zaiW1tATSyoL2q3KW8QCJ0ywWlbJVQ54Wr0FkDEKOTO2b4ALdQ287nweAiYYqvl4tLfuk6Na0MuqLKPQwslA4+t4E+NnRdTGLJ+rt7v490bKHnek76pyP8zVkGlQeRiOU0thFBRKr63alpfnOAupm0zcR+kdiH4VNq8cvo4Uow== X-MS-Exchange-AntiSpam-MessageData: iGGzTLzAX2hhx6+5CFL5tNBScD14zY3rok3r7WTzOVmBb+hMbZ2s2t4Q5mV7QXg450eC+p0v1YNu8EiOx7L+Hhy8IfltTPcOAQqaCOJG0KsPBXU0gIztqljQIgFy7qxT3bJNwlIjWD4EuRBDen+QZuT9tQEnKFvyFL5oOsn6kNxfLdrzHP4mAeYX8csAqDy/fvcumuH7+hNgLaQMiIZlPdQZX7NMre+NLPjLimwz2Q+2VADTIIbxZ0uQ+TPQBaJj3Mjl963pXPXwDjQDM23GDPeMBozChEG5JtVM8/sJcIpLgWZHDzCyCFccebH4P2CpE6MHbSmbrvHyZtJwMKufiNJ2xPaCL3lLno4Ecd+lFp3IiRZ+d0juaPrvyzf635zfhVCw5DEbl8yrb2wc65EjY71nCezoLvsTDxC+cCYPEcJE9yKPpBy6y/vxsyWPnNbhHFbr8e60ALnTDs/jG+T4zAbm4p2zTh3wuap01YA+O8Q4Y1Z4cs6rxSxpKfyyN3t9zsR0cTt48spQy47VRDNjBe/AzG9RpsN/WjAuYKjwwpUv4Len3uDq+C+TBaQzTYHmc/6YguAlPmVemycddQrlPrmWvvWLNiboYzeuqVZChihVQXvbg26nx6cNKGzXRtawj2wI4kR6jvhr6eypA+Azww== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e3bc3cb-7f8e-4733-5121-08d834b93169 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:47.9453 (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: 1mKakNUDpkNP02DSR9Q64DJ108ZpE4jLtAwxSIRu9u5i1aShX7/c9VE/j3yWxZm2kO7sPN81Prh1+tS3SLYzeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1867 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: PqLD1tjMAmooZATD8PVZlCsix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134930; bh=ogOCs64bnK+xRMABm1Wr/R3WaCLqu/dIgDiZwe4WReI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ESCM7pUFzvC5d0XLoXykSyt8N3pw54pw3fdHY8lo4pvC7bQpRGtd79WS4FwBSftVkXO h/HxynIQ3yqN8c+h6ugspuK2NUTVbWuNBU59aH9EWykMSpvl3MGkJyNzn3fFysAw00m/+ /DjFC8NLwyszWganIKGhUDYqZXcNPn32Ukg= 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 (#63506): https://edk2.groups.io/g/devel/message/63506 Mute This Topic: https://groups.io/mt/75892774/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 Fri Apr 26 18:26:44 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+63507+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+63507+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 15961349401071011.5127647195225; Thu, 30 Jul 2020 11:49:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wYTRYY1788612x4AGyxwJhmj; Thu, 30 Jul 2020 11:48:59 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.43]) by mx.groups.io with SMTP id smtpd.web11.1840.1596134938910999702 for ; Thu, 30 Jul 2020 11:48:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b/gtMHL4G2fzWLHF21p3R0arOm714bwM1J/7hvOXfoJsOBYSefmBks8lya7FRO+fwd5GiSf4+dRrPtoIina7wna4sO31BWdrGP67oCH0HVlgIqJRjcUNZ0+9Zr2sJRYksH+AQIGypdHtrFdd9gZEHanhkl0OlV7cOWGgu8OdqzB1lDm0lJMM1eQZrkAHxXP9Wao+XMZum4OBrDlX783hPA6R9YxDnMjNBPuig0BV0w5bZxpA3N0dBYNGXWsYEOYtblYVID0yyM4g7oSjWrdFBZ53L3MlWwiDnmpVl9duOUPBiKhkLIb7jf6Qh7yNRVJPss9esBAfS3DU3CBX6JTyrw== 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=J470FRQZlLoHANgQQYyLKb6vcjansOg5c2Yatipmjq7nVDinHXEs/fq4SB0lcEDpTd4saJNxqIhc6iTuyte0F40l5bF9el2KBBr68Nnqifnp8I903XdJ6cCJXL7pN19ZBhk5UcjysuIdwGGw0B1Fy0dPTQ0Z2ptL5l0LWeENGpGIGrMPLKZwegB8MGDEAAMdhOaXHXEGfkWocDaeMOPVpE5I8OVjLekPlA9hR/t3mUtTo3LFFkqJvsuFaBtJeD7R8+vWdgybnipitvU3aq6eM9kupj8XDjweK3oTK3FSJaFMyqGtIaWEbysEcF5KV9hY2iRwk2in71I0k1HFDLV+zA== 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 DM5PR12MB1867.namprd12.prod.outlook.com (2603:10b6:3:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:48:57 +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.3239.020; Thu, 30 Jul 2020 18:48:57 +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 v13 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Thu, 30 Jul 2020 13:43:42 -0500 Message-ID: <13af232cd602c26b7fbfcb1614f00d7d3277c6ab.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0051.namprd02.prod.outlook.com (2603:10b6:5:177::28) 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 DM6PR02CA0051.namprd02.prod.outlook.com (2603:10b6:5:177::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:48: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: 9e0db58f-1876-4975-7fbe-08d834b93705 X-MS-TrafficTypeDiagnostic: DM5PR12MB1867: 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: KeAQ7WV2ITt8FXv4vTAheEnMIQp0J+KbVj3m0zFC+nfsnDGssg8VkHrXOmnp3iupsMWbYv2iROCiehWolzGKjBSP3m+P1dx2VDaFF+zt4mjwJ73ypu5QJp7TGUh6xEMW0OhEbj/krkUI3zZxlX3FsAgxkGxkyu8M5S90tHrwrTc6rtixbL5TeEMvd7I5Sf79uF1UHSBPOGToWdbhbiNRh4hhPYWY9rLc3HsGv10iR6CqwOStSnmAwGAHBdJOauEkPb/NpEXer0JkeetYGZcXLobEietPzQbJShrRPuRlNTSLE9zOk+xbqyZWvEPDQSOoja03bRY78YRzx2y1eHWSGv0Cqv+3i8yAR9Muwnu34nuNSWZ38s/5MvLw3BQApdFbvdmj/5M0FXZsSkplaGFSMGykXDHtWlBoqWonBGUVhBQqdXS6fFfjv6/jotNbW/dQDvp80bs7oVTsr5WgN+Qk0A== X-MS-Exchange-AntiSpam-MessageData: dJQNWnEQQCRK/THFMKkDJbiahWUBGKXOKv9CemmRFuahA4VbFwhFxxe/oAQrL6KtZ4meS2zOjEl+xCJfniiuv2y5B9Oxr2Tnz4VN+IftgWIw5Hxrf97O99Nc5bK6Nprv86vYcKmkebWYHa7bF4Dr+yceTgzLNTjEdjbcdb3RXF9rVu/tnZiCjo5FkK10Tc7UvlKJzGOZSwP0M7X3v6yH2YI++1lPI60uy6nGsbiDcM2MQr8JIQyNBjBxK7P0fOgy1rUmfrDwBVzkE/l6/rhA4EZtLNTCAGvL5frYhVZqxBhfbnqoUSrfKfewWAPbAOS/PhYtHq1yANddDD9and+QB7L9ZcWtR/Mb5sWThxb/OJS8tenORwfaA9hpvzbf8Xz+IkB/rDlkYXlRepwmyYDz0eKR9ASu5KV10nt3otLwSQs7/WfUamazi+RK8F4+Zr53KvCTtZSPE+J4zbdfMJP9lY152iBoh27hpbkBAAz4MpOJwxx1h+WKgd8vKWZGn4N53pXAipcwblfyNlDxQ8JIeOdRTq7FAXizq1+xNMuAzGGUnfyAQzuRlAu698W2QiBPskCbJEKuYj1bdhqnBjhro6Msq9dJRaJRHrIzQiHiJ4OkISOsTYVp3xYliBlu/ta1MeXswlFgFPVO51+7KuM/xA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e0db58f-1876-4975-7fbe-08d834b93705 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:48:57.3574 (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: LyWp4kgCBoZDw+1Z1y36daCaIPRkn8pcFNFr+GfpYfKoGJSpNUfHVSUlytSZ/i+JJmltsmTCNR1ZUG73RjqfXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1867 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: ReGaz2G8UIpTecdj2tvLCiz9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134939; bh=r2jHhYBkJwT5kyd+vs7wU820+bwET/7LdpQQt2c/Uo8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=imbePx/UgSScAjHYHwB8503HsNnGaHRdKmewSHEQF1Nv2R+mAElqfOfzwa21YbPpFsj eGB64Dsyjv4I4mK5RXUNaZ8KEjekQmGM5/WVInZoL7z2nSJcZidbd9A9ZEvmCt9r+16vh aSNXw6CG3Xa8A8vzvpkz5rI6jTgQXUTKRWg= 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 (#63507): https://edk2.groups.io/g/devel/message/63507 Mute This Topic: https://groups.io/mt/75892785/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 Fri Apr 26 18:26:44 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+63508+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+63508+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 15961349488301019.1613404610066; Thu, 30 Jul 2020 11:49:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JrLEYY1788612xbH2Li6yVBy; Thu, 30 Jul 2020 11:49:08 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.84]) by mx.groups.io with SMTP id smtpd.web12.1799.1596134947829238914 for ; Thu, 30 Jul 2020 11:49:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=et+rDXVAuyhoHLazpv0WYcHrN8fRN5Us7anQmlh0TFJXd+wm3Oadx6eisMvV2uxCq3DRk8CVgU9WZZBu/9mdu6KLtrzS7NSby4VZdpVNrxyyze9j2PHsTuPbtyQz4QfCyAsak2fnpeZp7eFNvR+gu+w4dU+MqPtVOVJCS1gjfAGjLlp85R82A19svrd5K/pjV99MkHFk95aP+m4fbpOb4oDHmC6icR6JhHLk8Mjo1ET1mQGvbG4L00acnmQWHHTHGDf65szPaioAhBXT7Q2qtK++qTyGgGMXrEvrYGiF8AGWOt+PLwck7c00yyiwyn20vT9gtPdPGVWcVeKb0Amo4g== 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=J4+liIqpVa9bViiwtrnuFTUZbL2KY3Jl6vuGGGYXfCdZ7ImyeunuFcCaQb5MV42rTroVCRh7nYYOfKl9sjOj/yMMceY5OAoLiSmeAyDDPDVGkm+jADFBnZGMYrUunbs7y+czJalwqVzR0bjD8Y7L5suU1lDLMN8Jcx7nvbL1JRqcuY3FojEVV42A9j8OnZLcvcN+GYgAuqymzZby4PLCxX7BV3CevQWhroyhGb3kYAGYrcorWX6tGFrlt5wb0yHeBJa3jYFDOpmHNmP1/Og4gcW3kLv6Gp3HI24GUXGYaYiRwxcci+g4VBuIOiVYOL/DHyCYm7SXs8BQ0wOr/yVMrA== 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 DM5PR12MB1867.namprd12.prod.outlook.com (2603:10b6:3:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49:06 +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.3239.020; Thu, 30 Jul 2020 18:49:06 +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 v13 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Date: Thu, 30 Jul 2020 13:43:43 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0090.namprd06.prod.outlook.com (2603:10b6:3:4::28) 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 DM5PR06CA0090.namprd06.prod.outlook.com (2603:10b6:3:4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:49:05 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 82c57941-dff2-41fc-6a32-08d834b93c67 X-MS-TrafficTypeDiagnostic: DM5PR12MB1867: 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: qpnmF7qiQ/mP23+n8qkMRGoy5xvArPTVSI8C3De/5JkoAaEr/JPybq/3Tcu9/RLBjuKU7Ad0rUh7fgTGrT5500VuFy+eDw0qz9ojHKhPnsT64JuEa4Vli/nwiZGzeDxfzzieIyhJqyjyi9O1jQwYPy+v/92ZQRzXgDHh5zB+N3sRz93vI91X7UMYIXYiYC6eatzOD1ue0qkXws4sb7aCIZaSs8s7I6Q3jJyC+/R+zozsgdPZQIy/L7QVwwuNax1oo0VlXgjfYWYut8TtKF8341QFOugAZygp3qhlywmnNdShVptbsZmKyst4cJB+07PE9r78FAqqoh+04cUvKTHnD3xwrm1fWx64milh2kphIaXNETkpf5EuCEZZmw53Rf6gNcA2l7yQH+BaZhzuTizzZ9UCzUtWmBZnyzStHeStRft/Gvli2LYJNvix1CAhKXQEaF5Ua7yAeYLVJDbjfscVVw== X-MS-Exchange-AntiSpam-MessageData: IY4l7f6Jtlc4UZ2IncVucCuZax/vT3GD20ria5kMnHYnfqHK5wBcvAaLZH6fLkYNb3sodXqnjzpG4POYzetPfQlfBUFFr7xnEzoOD3Mk54fPKWQKon56Y0g4b9IxSa9xf/alSe8aHj6MzLX0vF06PH9f8SIJqMOwyMMOEWS1IqNeAELkTYXuCKtOErnwly9WqMQ6gJiIL+R22zH9VwloNwG8ZJ7K6WprymNo5ziTlLtChjkAurIFBzUDLexqwlbez6LMm7BithjfgKLzxBFE2eqXnTYUqe1oJZ/AiYsVlk/CPAt7dbP4l4KaRcfuOPtiWuFzj31Bka2wnMM77y9JTz2oS45U7nUQuipb1TwHM9m8e/fE9tiECkZs861lNuhqPvu6uIaaQiDpDKzwCqLCVHvEaOxEiID8bTGTnSLqXu7zrczp+Ml4zbvknRKERM/0wr1uTBuT/5Gl0Akz9GC+uRPzG3NMX4P1ogn+J8n0KjJP9Gl7gyfq/oOGoHWETGWFjOLgid+qNTrrr4uNJ+EPx+WaCLlsSWOJ3kWcV//IAsN7d3dfYgaiWsFFMmwAzhN65P2fFvnwoKE2lgOs3KPHpnNktYI1OHRspQe/KvmvsKbqssyjkZBIfD1vJtvq0rMzbsbYvXHRoxAF+XyNnZW4Yw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82c57941-dff2-41fc-6a32-08d834b93c67 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:06.2868 (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: BQ3oYhCdgqOdpvGjBnSLhs7sq2p9ShiAxzICfplc/D1BnWdtpYrzG+8ohpJGN/OT6jXANbazHVUdlvqx7eYkGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1867 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: bg4XPRhZ6ldqSCLGclNdduhUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134948; bh=PqUyIRaWrg9GbWL0LQ1PLEDrmCc4mkhJsZKHDW7S+s0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=uEF++MLFzaBN8fOz96gykhetRjKqyFIc1GY/heFakSWalmYRPrT+9JTt36bpAjv0ov5 FqforyvSCdIIMSf2cX1LVFLi3D4yDbjnrFAy/rJjfo445mIhMPFGjuYMzp7WERwvoYi7/ B+ULUIHUUYiYdYCBWxpRO8DeYRFGKt+SeKc= 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 (#63508): https://edk2.groups.io/g/devel/message/63508 Mute This Topic: https://groups.io/mt/75892790/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 Fri Apr 26 18:26:44 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+63509+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+63509+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 1596134958289326.6696419035884; Thu, 30 Jul 2020 11:49:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XGd6YY1788612xYNyprrhyvZ; Thu, 30 Jul 2020 11:49:17 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.87]) by mx.groups.io with SMTP id smtpd.web11.1850.1596134956915801813 for ; Thu, 30 Jul 2020 11:49:17 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C6PsMusWorVD8mneuNZfnjJzj1f2g2BFD8v+O3ZUFxaJT2T0afUY406TmFqURHQUa5fJj0MYVcY9yI5oLGXZWSMuNGalSSWevVwJlX05DW68BVkZ7TOmfVCtv5DOX/lgv6l6bHkJMLJ1SphQD9r8ELj/mKISBhp5yhbBfTkA8m0l4eqU/9vZEcGaJKNz9GmxqyEv23S+J1NRbVslbjMhiR7Vi0IirJ6sh+1glcu5ZY8S5tNDVuzKbP9O+gXj8m9XQMCTJt1vLPMGa5dQAn+xChWGxUdyP/WQVZ4ZTvJEhcgphYuKRNcFcPOCZKdxObXWd7n9sNxqnFpSrCI2lKd5Mg== 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=BtkMzoRCEZtvG24vLCGKxLd2O8xFN+qUjDJfDj1FHsMA6EGX+tdClvuVumJg2BMCD0jJ92FvaFOHZzAPN2qNJCR8vDM/K/AW+FWy6N5foV2uVGCqKj9gErrH48jeM2/Gmkzcxiqzh7sAHPUZFrZLIs6JtC5pvBziR41R5WFW4YXT0T1TovbuG5snsMhiKzEqkLV/BhQ15noOUGQgmu+BV0p3fCHLj7NbOGl6TXZmZYxYsVksBCBzFYsffrGj5FZW6qPKUUGgn70L+7jXYzjBni3gamLtgujopvqIpESW/xjRCNHD7LbPsgJDacM/q+baom/0zZkNI13gSXUDG+W9pA== 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 DM5PR12MB1867.namprd12.prod.outlook.com (2603:10b6:3:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49:15 +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.3239.020; Thu, 30 Jul 2020 18:49: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 v13 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Thu, 30 Jul 2020 13:43:44 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0047.namprd04.prod.outlook.com (2603:10b6:3:12b::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 DM5PR04CA0047.namprd04.prod.outlook.com (2603:10b6:3:12b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:49:13 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eaf6b8c0-8629-4b1f-c963-08d834b941c9 X-MS-TrafficTypeDiagnostic: DM5PR12MB1867: 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: XXn8/ch4IePM6y96SBtwCQVjYZgOlSmz63A3+DrE/isjk0di+qQkCjAXN+GA49Bm8lumpGkSiMi56nwYMts3HDuBWzWcCm339a09l4X8G86PHhueqLE2oL1CiyV6fgdretr9XQaeiYwgp+ksrPPkUyGQQpxTC+3acS8e1bSeAPt572LdNxO+xY6GTpKcADri1K1iczSD4h5TmOTjRCSGzFe0PWnP/RyJU/N9HUK8KY06thlpCz1lG91dxUH1bb0AUImF9N98X242fvgAQpjw0V50Gd0jqnx8VFHGjQbYav47ln4eu5SDvXA5yWEug/4kjvwY8CyGfZPCoiI1q7XeahaFK3r6LIrKdhWkSF0WX9dxCChIYI5APd9ywyGjeCuiaZc3Lw8T1WS8Vg3va5WgR/pFv9/HVFT1jEiYdR6gXWwjlkQuI7swbOPVTq4hOvNihHrZiWOe0zjS7Op0GmtL5g== X-MS-Exchange-AntiSpam-MessageData: XHkijrc+4tAeuozeMs/hzHZEH9n3Z25p+fNimC+lh+tmzm4LV28RaFTHtQfvZ98lF+vZTZxnHLjPrNpf6lAT1bAF+yDyeCKRlZyPKiSd/GjoVH3fCAgQ8wKRhDjbDKqpmVjKEy86hPGVCONHc/hqQkq/NEAFI63smEiEsS0JKaE7GYG8nt7/xkWdmvu7qrXi4Ml042ifEzoS0IJO+P2z1i55Ew+8H4nhvyKndDbHt8UpmhY9onRYLcnt/pLxsUqHbNpUQFFpRd6QACSTI6rhKHP+/mJf0MPT8fayiJCGUHDuGB9jafWoT/12f5lNqZphUcWmDtYEUjize/WeRoKD2oSqWyqxtMDmeSjtn+wiq135/qhVi2H9qcrHvaMRpbCbTMLgA11OFMpUAyFzYl5cgp9dHPu69mLBQpfd1rvu8WuBliaVcrcfJcui8voxV3LZizQrc8159kG807QUaI/vXzRot482UDPaQ/rtVCpHCdO+oXVIQYU13Hz9i6JEXvxS3Wbc9TRcZ9vds6t2Jpv7Xwm5gErBfcWJdE1IYMxB0RikZcxoLibyObYN5++BnbiyZIs1N10kb5I4kGEYTS1NXCtowSN7VTG2nxka88reuNaUI/dYSVunhwHp4D6sB1KKoAAaG5+nQShHVYTJJFx9rA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eaf6b8c0-8629-4b1f-c963-08d834b941c9 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:15.4780 (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: emJSG/phPZmwjdDNjjQLNeSuVGpv2UubUxaUCzxamN2oGWxgoLSBphXBIWk/XH4SSXn2XeG7bp7I+sY6Etpowg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1867 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: pb8l14vbGcz2YWs4ShQ14qHYx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134957; bh=dGVCp2CEjZv80mALPW5Ixl4xgSCdz3qtVQAbg6js2QM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Ou7FzpK0UOrKD4d7rk/sz+OBiAwWrP+JodeqRWfUbvDHfhLXlNIcastr1De3oHP2tte mbROEFFazKrkBAf7SaXw308iisbpngMrajjBLoKidQwS0WdzX22RXhdJUd4DNG7jABqgu V4AbQcVqCb4IvYxPMU7FZvxsGxh7jadGlL4= 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 (#63509): https://edk2.groups.io/g/devel/message/63509 Mute This Topic: https://groups.io/mt/75892796/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 Fri Apr 26 18:26:44 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+63510+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+63510+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 159613496709121.112003013570074; Thu, 30 Jul 2020 11:49:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CmsHYY1788612x5j0q2WpKyM; Thu, 30 Jul 2020 11:49:26 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.52]) by mx.groups.io with SMTP id smtpd.web12.1805.1596134965785389482 for ; Thu, 30 Jul 2020 11:49:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A83nwiwLUYcZxx/9VDYRxLSqb6TNo6j/OGS53XFC4bqxDsE4o0CTCcVohGDVMEXyx8YVytCFhrQWgr0RPAeTmKTzG+R6ncXMSxpycT2GGFXuVWTc8h3QrayVHg1st9QcgFZvuJPdaxKoR49PU3oQ6LkVSD/tK4pWvt28jYCad3kIIAzpBCxyAVdeRSlCGuA0G5ZTQUp1OMp+dOQpMUrqB6T5m+woJqRzU6f958QGwlDuiQy4osKBbAuZkWObQXTeyg0ZOs7MPCkmI2chiGyR/WXLI2ecBtQBhcABmp1lQtkqyhhpIOvXISlQdSo8QfRaAuO5o7MTK0c95mDUpYwBoA== 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=CkUCsVMLNx44eYiVyLCG98C1A+A/KhHynEKCC72EYLo=; b=GV3jVYAtUCEX3nHM70xjYrGrnlhGXkO3eFJTlahYWr1z/laDH4nyCNBNCCl0ALPHF2o9LpHeSVLrjECRjffTgXeRdEB1W2/PG/Vntg1LAAHAfMmk54ecPkRTc7Kg0jNqeM2L+uB903UIWVkCNw7m37DsA3skuXAPxRoDhvSOIO2VIFuavfaIJCNBnnYvJtQc49sN6LEMOwdnWAl4baquqYbbN5W92t1uIR+6rmimHwxrFcqQDQb8H60wUdsxwYZ1MadLMjlPeb8xq7VGO3eSkyLUwnI4zYyzznB7/w95q2c8nVG40XjSVL89E50Kx0k4XBILhUKEdWOF3mx5bMI/iA== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49: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.3239.020; Thu, 30 Jul 2020 18:49:24 +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 v13 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD Date: Thu, 30 Jul 2020 13:43:45 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0068.namprd07.prod.outlook.com (2603:10b6:4:ad::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 DM5PR07CA0068.namprd07.prod.outlook.com (2603:10b6:4:ad::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:49:23 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 23e7be07-79c7-4a18-c783-08d834b94757 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: +ivVE++V0uaalJOagNvxhugRdKY1NPILi3ygFeV3gFBjf+KSaQXa9MnY6CNGxEH58vN78pbOUfA4vCfcs47q3t1FbO/xa1swwYqZ7WeEwNPschVgnd7X/mzFgaBquINHv9/ykOd25LB1G27EgX4Lgay/wxrdTrEoBOJjjMkl1W68UoHzAzkB7cVmYhlrtP06izzt8M9DHoYdEWcsjcQE+GoPu6PD/BsBPyNs+ammdDxCo7wqR44cS9JlutZfGyv8QDyGshNACb4QyMZjc+hyMb14/g+n0CeTKY/9JVUvSnxWW0pkZq/6bLQSHFKMGIPM9rJkC7v4nVo9iCLdkhVN8Z7aOWkSqxeO6C/AHtajsHSVvFDtBz4QNNG3ElEGFr0kPlhNlN3QGPR1xalX4MeSAD/HFhqZPKsntq0K5LPcCdxedC3HiYkm5q3oLaDh2t0VkgU1zKrJEVVhcUdeUGEpWA== X-MS-Exchange-AntiSpam-MessageData: YmR35sHlAPHCp87B7dOXj/RgV6PpAs1h7aKvJ36IVq8Iw273IoUhJGo5JWOXxLTF4z4Ffpycy2T69xOc6Vjlu/mRumISF7PWxxnGJuqTWoOpDebEsRQENOKYVLW9SUZSDRKJupnliy+gGWCNIRU4iHZ8EmMAhk+/4W2VZsS/wjnWTWbRUl1vZOpT6s3ti++AaygmSxI0q26a9j3pfHu+1YZGWm+CNWAclo/rTeIz+sdjrA0NhILb3qRB0DmMnRsQNix955lWJYMIQO2gGfpXtUIVZS5KTB8Dr8TbHioTdFshsmQWdwH75IoFX+Y/TuS8H6C6iF4q5hybeRavJi8NgsW7XRuX/vlHb6bH5gKkwjmeEjS9iVm9dBMVNZfmvG6HdJvPWydsE5qs7UMgC8x2NZRyDQa3bOnRB5V/YHpzciKSlikl9jPA7QB37PurHQ9RsXea7WkwgEZG4mFa1D/IR9klgD+yOVuzoiIhI7DpyPu5oevIJK4q2t0Y3U5k1pp2nRv4W3/HtBs0aNM8lcNmfUg9MgbgKmGPnkFhlNwU0S/S+u/3bhCcIZejOc6lGQO50fC2em2x9XEY65i/7ugZgoG949x6Azj4jCJ99MQCVm8GJNtAhDyZazh25mUlV5SF4U+P4kLBK+IOcUSwlJPR7A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23e7be07-79c7-4a18-c783-08d834b94757 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:24.6702 (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: JUWj23xFehOanH5PGvvioQngsSy48XtEV27wM40SNB7oMbiMlDqXwaUnp6LNzYJHieWzdB/62Sug+yFUkiXP2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: GZ1ydc9ZLZQ95ijGq0VuhMC9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134966; bh=Uudduh5Z/vV7J6479NOAMbuMMSRkTVamBvY7nOr5SWE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=nDWLhlsf9SpVVDDpmOlbr0W+EskvERH7qZrV6J5qrRwiqGUKYY1sFTKSZhM3tUnspI0 +644Sqifpbf1ROfBEjzkNsJ+8RMtKBS03ngCusbVN8CCz607ZDe/H6rUf3Er68SG/okts AYIxAo2nHjH2f1sVpiq6Ykn721ukFImV7Fw= 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 17228cb5a84f..d83c084467b3 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -164,6 +164,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 (#63510): https://edk2.groups.io/g/devel/message/63510 Mute This Topic: https://groups.io/mt/75892798/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 Fri Apr 26 18:26:44 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+63511+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+63511+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 1596134976302276.2061444478387; Thu, 30 Jul 2020 11:49:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bwFxYY1788612xmiXLQ8s6TP; Thu, 30 Jul 2020 11:49:35 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.67]) by mx.groups.io with SMTP id smtpd.web10.1811.1596134975342200506 for ; Thu, 30 Jul 2020 11:49:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E76yYY83tSYGZCpBgGCRBTuD712gA3vVkRa0ltiXuIyqBc8YyX4lxHu2iHVrSvTAFTskqOKFpKO10+qTBStIifAYVYJdDtGGJYMXUVdXifr4rfpbKUBsjbFsl/mJs3TMSM1m/Zw22kb/1SNV8WXPEEAU53a1uM4BpJ84xG0QJZly4N2gB/pd+xkh2+X3nbGedCfk85sgD1BekIOR5+K7DQoV5vZhN+3v4UpGlcGjBl/f866xiQae4FZU//GiDJhRpXOfaZEOC6VcmspKgzMboOSzfaeDVNCYYL4TqSyUtTuwNiAp/cUMZ+BSMAIfFx3gO7Vzv9LnNxHR5wSz4X87Lg== 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=VzfKUKIX1+4Z9ZDUGeYX2KRtqRh8kq48C4VKNwPL0no9yYpxXX8W4fBlc9pElmRRK3vx8uhqBX+xYZXpYCpV89wtsFfiqMK3RozeUOVO7UvLgceU1YSrsZlMFBDW8ObDFkXwKWhGOE0DIw9l4ACr1BtV83//ou3TVYejltigGYFta3F6uLlwc6A4HpA5Xtu1r9ONnuUGo9uAcRQx76UOK8qzaWCqIyOItz9vtxNjzO5j8dO/p5tZf6aoege/3pRRq0m+Uo6WYSSiH+xv41EBNmrGXeMnZq6DOYov5TNAPPtryrSVbPX1xYsrrLF2MnyNcRrH4di6K57c21DFSEWsdw== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49:33 +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.3239.020; Thu, 30 Jul 2020 18:49: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 v13 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage Date: Thu, 30 Jul 2020 13:43:46 -0500 Message-ID: <4ac39a7e14592d816ccd6cb0f35ccbd3ea4a0175.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0004.namprd08.prod.outlook.com (2603:10b6:5:80::17) 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 DM6PR08CA0004.namprd08.prod.outlook.com (2603:10b6:5:80::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:49: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: e4975f2e-2cfa-43af-9294-08d834b94cb5 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: /HGwfvRNhx69QbvwOlnCZmntO4hJprr1MoXY7DLPkVDQSthqI3DvXMf6bI8YHfYfTFAX6TuvGf2N9Zn8dkn5LDt0JQunoq8cGXLEdQ7bp75baZpIrqBcwHxlb0ItTUIEmXnayUh8POykGVYt/b5f28VtYf6GNho+1Kv80pKHRIDgTYGu0T0U+pKESFgNDTb358+A6YyhlpTOPKjj2+8DhpPa5I0KkpszXJPkMTFTxKz5rnhkJctc0SyfN2iiBmzVq4ZQUytoWUtJ7sBg6JZWu0JnBTadIxYDIZ89+qhERFmEncd7d3uzIe6WzH+nzc+yPO+EuhqcYTNa47YUMjy2JHuz8H88t6EMDQp319Rq1MpWSl7BSi+hSDfcCg+450WrOO8hI6wj2X+zOX8B2WUC2Q5o06IOo02rS/mtL0myIDkAbvajZ4EaqREcCgurmWYBxV+2F9UMLYDvriiEyjYarQ== X-MS-Exchange-AntiSpam-MessageData: x+PPCYvT3kOpiVKh3LxIclr5bU/awAjGSLOyt8Zkg0ZtUVVgYrVGyNV5NETG7MWPjX+Jlz8XKk8RYXcSKyOqmCF8/H8I7nRHZcATQnK4iWzSehpuB2yzDaTT5jApfKuLCMqApE3LSTW4fG69pM5uad5i2oa1viZRQ+rEbqdHvpMbCqu/qtj89EWSslaTpfMB/grGOTboK4FMlAOrqULN0WwbEQrY88C6rzD2vW57nnfFOQDx1liqKxpDur8g560iixDw2oxn6ZesyPASj+sgBytRAeKCKwZ9TE9JhUXzBWTP8GyX9yiJIsKSMOjM43SvpoqQG7Bfz0kTGJN+mLdu6JbOzacbb1W+shrbqelXghS8uog1CMSizdvdk0r52zP61S/JGeHnqEcxNbtqjHVTHjXA2aXfl1zEsI+GoSbicx+pqByn+YsA+YB/igV5yjoVeh1FLNGHQ7Wf4MSxLuaM8OOri35r/j2JjX+jZ2P9qFXi1hSuFszIpC1k/XaT7QJdXhO4oi7t4ocspCNwkyCcekMeAKOH6Hqxux05QusONOgS85bOG+ISfir5suycaPYSH0jfJeunSAuX39Zd8CmxcoXigl/cJD2CJRa8HqHHWZl+xniwNNjWVp56r3INNpxFm2kNpRklhwhvZfGQ6x5mAA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4975f2e-2cfa-43af-9294-08d834b94cb5 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:33.7095 (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: EgmAODNzpfvSrBfUEPCDPupweHhzpR4JQLPq6v9+q01pxWDnnbe1NI+SVqsVIhKgWcNB1KbhsidPirY+UDZiJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: BttsKf0vithmZ3Ay4hoLOxeBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134975; bh=5X0SIrFBl7sj+71ii4tIanlB3TJEXlRX9ckVbFsGVl8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Ni5XNPHKFP6npC2+ltNGC85tzNJhwbtgP2+I2wvBOlO7zTBlY69jbYj+F18r40iqSmW 2vjF9VoICvH1hnecpbP7RFrL0LX34zrBSLwxylsMMOq9l3JamAAiLUh+MkNiEtPkvAa/9 i2Q7P5ggJbvnRQ8ho5o35Qj9XwkbiEqy2UA= 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 (#63511): https://edk2.groups.io/g/devel/message/63511 Mute This Topic: https://groups.io/mt/75892803/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 Fri Apr 26 18:26:44 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+63512+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+63512+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 1596134984941462.71506853809535; Thu, 30 Jul 2020 11:49:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 44B1YY1788612xIisjXcLBjc; Thu, 30 Jul 2020 11:49:44 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.72]) by mx.groups.io with SMTP id smtpd.web10.1814.1596134984093023099 for ; Thu, 30 Jul 2020 11:49:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Idq22ktssbwC/clGjzIDSR0Vnf09RC06vQ1QDZEuNwmSzi7GL5S/yvbMcHyMCB+q5lH3+zpA2p39OrEQbBsYJRMOabVuQPLxaGKUt7ZVXj7nhwDU0isTs4A/F50DXmmhoRz/ybZ90gPUyFlXhXbfBgL13obEvVhzDMvI9JkjYoVax2ZsDAgAF9/szMhHcaugErbNpdXLM1XIxb2a5+J3UfQfHN4rK2bVsdIQfpAf3hDl8k+NGZJmmEGV+MCrPju9VDbtC/UWUQ285vj9TxxenID/QVHssAGOdjnVHTLmM+Fm/Cb7PSXzunIIN5wbKw3LMZbKaLNWoPhN8ay7+9bh8g== 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=R82XGB4r8iIbvgedTCgDGKVHJmO74F26kWohNnjet+hGL30Y0usKtih3CYg1Ub0wU72MX8NRwL3klupMImZwFCxEqmSqwVEkLBJm+ZFCGrX1iz2nMo4PhNIliYob98ZZ8no+vCfdYeDzQq9qPBaNF79p38N1JeUf/shKH5jfCUcyZkY2ny72emCA+xgw5bJlbfJ2L8znaB6ujI/yj+cb9gvvsoLioYRQdnikstQeomKybYrkjcMo3UXTWCX+zeLsrUIcQi1liY6mXKLc73C1BOS0yPYZFZ+Wv8SRJosSi/ZY2dsWn4TrDmtB+JcDFBygupiz5JK6DR1eZJ5lcr1F6A== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49:43 +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.3239.020; Thu, 30 Jul 2020 18:49: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 , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v13 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Thu, 30 Jul 2020 13:43:47 -0500 Message-ID: <164fed78e2bde9486c7a4cc2c9851ff5476b76fb.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR08CA0020.namprd08.prod.outlook.com (2603:10b6:0:52::30) 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 DM3PR08CA0020.namprd08.prod.outlook.com (2603:10b6:0:52::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:49:41 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a59a810b-fd32-4ce4-876a-08d834b9523e X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: OUi3pSpoH/fDVFNpYmK/OzM0iN6WpK5LfnDzYXqh8cAYvly7U/CQfibfeZ5xFxubITwIzkqKXfXh/Tqs18c32YGj0QvUP1ikqsHneF+i4DQfUe9gGowYSFWGG11qW2CP4jyKPi6+cHVmQxNgsKUBvCfAt46gkeiaPotLk/DqNLGZJKWK10JsaDLQGgPCXMW+h0SryEfA3EpSdVTAQYIlEKwlgBlYw6sp2ELRniSs6B2zMpOPO+O3m9WyENzZVSqDW7T1VplW4pPe1cGN2Kvjk7xgnedubVeYJUEkGATDseLbdih8jInU4IhPYy5Qp1uc/9GYGBye9bCOwkmdsn92NsIfTDk+AzHvVzJ9P/Jg3+BmlLT2FNLHBA43iQ50B1z+Dgny/TnDj7uOq7NrukbBQgxnUL3Kxyg+b7b8EeReiBeWWz/umsCisvftA6bCMHVm9qcNOtcgflfA2syJgREieg== X-MS-Exchange-AntiSpam-MessageData: e2xDXXTdarpLHA829xoShgqex9X8Y/mfNEnxRMTzdQ6JLH5fRnCLhAwHCRIoAH6v9eSRAfOH2jtI9Ndo5YDe3c2MIY+/jMEnKFlVmV1hZO/1u+ohW7h9JrgXD62hbfNoNMtlhCad5abCWkMzUU61OH6DRPpkqNThssCJBK4RF0NgmZ8aA8dRqrgzV+iO4N5anWTQszrwzyHmRsjrhmK2g4ZA9/xmjfazu8nTmWnBjYAF0nXrpjGzlL+q0kcB4wWKSYtkhj8NLEEkrpXfKDZJwJ0YAZWJkJ0gtUeCj6iiQS7zCYnuto4q2IqmLFz8GaV2VR5Hs0IC1PgcHsQnn7OD+Je2888RVZqFs/mC0vPQelIvUhUKcxAen8W+dOgh0IF6ohoaDE6srDeAkYcdETCIVj+ITCl7A61hsEAIWdVgf/WUyfhSR9JzS4bm4EeMoZHaUCTWL+AjOhBPTbcKkdxU2HjIyAPgN0EdgYEpeZaKK154j4efW0D97QgsFmuccftJwYAN1/Jg3TBCRS4qAGC9DeL+fObBbOVD4dDtx7/MKmEJNSVwjFm7ub+S6/8Hfbc8/ddSveip+2zq8NUwrTiHUqlCBD3NjCaC5Q8XubywmdLVsF5Xibe7goVAU8DqoObMT3XAEiEzCThXjom7Ho5FJQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a59a810b-fd32-4ce4-876a-08d834b9523e X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:42.9797 (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: /8zO34VhkeoWCdEIDz5y3Ln1fFMbhULu9AEMfSVH5PpKi329d4rXEJBLZiidvXmKj3YWy3em2GEQxwiPs7tA+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: onVv0MzGiYaEuBYMicN4cZXix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134984; bh=R9y3SjOBGcj/QVPl59lzlwHz8og2WdT1ZsyZlOwqUdI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ZC6s+qaJoPb8vV4MKEfoMveihT37IVVxGIEAsKiYCMvH7el5h/c8AZfqAHY5FI5MsX2 ufAYe52zMw0nDz+J4lGPCvlVLSg2CcGUL3U1LOP4z0eW1HhbqYNTC/CNxWcCuw7RYur63 R2KJDH0D+j+p28lIOpfbsphfwSaNEn8Pqnc= 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 (#63512): https://edk2.groups.io/g/devel/message/63512 Mute This Topic: https://groups.io/mt/75892807/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 Fri Apr 26 18:26:44 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+63513+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+63513+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 1596134994314276.4059728262504; Thu, 30 Jul 2020 11:49:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qEF8YY1788612xlhMnSwDEag; Thu, 30 Jul 2020 11:49:53 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.52]) by mx.groups.io with SMTP id smtpd.web11.1868.1596134993360876925 for ; Thu, 30 Jul 2020 11:49:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JlNg/aNI7NZTpXpFrLuNrQ3vGrkk5hDxx4PZmXn+3u79MS31ZpKIeBPdMBT/b8WJSBjkJZ0UrcPDiAPu0YVGGDd1HveoFh0gBkAp8z1RhU7co3+hTP3wGsoSBpRoI6sQW3ZY2LScW39OSoSwI0J1B874tKS0SEUsNOs60M8QjDX9E7JpWKZYBvT3Cc9Ps+rjpGpV7W2hzTU2TM9km7UQ8Gvfs9VM4fqwi4tHuUumeQEYbbXE0chNEdue58ga0/xlKcnKLmh+q5OdpO1CaBBrFnhkrxfCWomhZGfG1HyfwZE0EYZ575K/6X9pBRNlozq2RAgrBEkxi5pMnnS7IExIbA== 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=ennVuK/TP4N7eFvZ08mtxS/G6f4ws09JLmZglwF+fcq6HxaqjPWDE59QyKxD6o/ygpaWHKaNj21fixQUKSaUllOB9WmDNGEEtxhsJwhH//Y8k7soOlA/5RLGTl8cEUDCtrJS97QNU37Qpc1M30f2j7cjs3KN+VkcR7sd76u+W7C89iCKLqss5X9LJIX85ndbpD+bIg0soxKt9XV7aZS640Op+ONjrlZVMXhoxXxibdz6so2dvdSlYNORpoNFUKgxR/JB30nCfhtyrDJg9fUpfEhmcxSbXCF9nSofnRAdReRWYB1a5ql5VFNOEpSYDJ0vFwRblgI4zES+X0KqKFTdNg== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49:52 +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.3239.020; Thu, 30 Jul 2020 18:49:52 +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 v13 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Date: Thu, 30 Jul 2020 13:43:48 -0500 Message-ID: <8d135750e1abf54b6c54894c5e2b8554434f9257.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR17CA0012.namprd17.prod.outlook.com (2603:10b6:5:1b3::25) 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 DM6PR17CA0012.namprd17.prod.outlook.com (2603:10b6:5:1b3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 18:49: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: 8f10a741-137d-417a-5088-08d834b957c9 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: Ef6xy/iGoZhXtDHWYi91u6mN4bYVETDwslOpkBtaPU++yTg5B9mNe1Gr09cz+GI2Z2mkJ372BWv6ut1EeoNyyIRgeBsXyuoCP1G7NZGrJOSt2jpeGJnMpEUX1pm1USa7VTJ5Kahqci5/08SPHfdSyva5HZLjL/2uVRl+DkEjGmDIcJg3GCcHpepPnjfvJQALviitXIDz7W61f+wvQ8mONkvPMFaOc5sHeBG1HRmSvQ4G6ELmpqYtNaZ2fXhB4jisLaLRvYNRVBfQxmfH4mnfo/wUhsFFTr0XDFxxIyPUVeNdOMScouSjJMTxXFmtg/RdURWa6vUwRgSY/EGW3fh/Z6A7fbgLl+24POwxdqXlp0QCNiOy26QYOc3KKu/pWTkLj+SJ21ZEohszve0VnU2Qdg1fENR2+V6wsljYszJA1j+BJDMtPRjov319qcAzLn1Yg432VrMBkNbS93EhDF+euA== X-MS-Exchange-AntiSpam-MessageData: /zJZFms9v8Nf27OHPWwvJsQJ5jzdogI5f4T3hmtbfoyDoEtDgeo2kVri1er3zsfFbog9lLFP3OG41l8XG0Ol7kBjZU3Bf5evSOKg7fDlFXV3adprSXn/JzePzoYE43ZYP+S3GWS0muTKX0lY8tXy/eUqzOeT32aJWS2HZk0geQX4lk2Ri71S8C0DwfzmF7Sm/nDa0pJLrfuopdd4uD9MtgWXmkxCISZLCkZQebmlBEiq4CzQwjCd+lGR09UTldFE8I0Or3sELxLZv1j5M8AIq1R44hvEkBwa6uROyoZ3lunDk0fdiEM4EuS9aatDFRpIV6ydpxGmgIWYpMu9sMxrTcnheScJ+mhXtZs1MoIJcRtdiIH8O+05dGD/Bths5Nh7QYy/+dTRSBwM2xLxWL1xY6BkW88gWMt2ongM3SoPA3U15YeCCJzCrVACceLxBeBIaVanDz7AUOsBZ3/TJRMgrnhGqKgP8s+P6y+kD56ztkNrIm82Ff0DTClm2bnpE69cMsbx/gL8Ds+vvV/FJv/UjZJ0hXTLGHfliOqxLAmBu0aHQt8KvMj3DqQBY+lgjmAgJ/NnUgpEwhwhRmjQo2l/d6WvILURbx2INxdneWDcF0C6B9Et9WwVtQCYvKjaT+2wrGbQr7WVSAyBp5qi/5v8Lw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8f10a741-137d-417a-5088-08d834b957c9 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:52.2219 (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: Btmc+ezuc1rdDfa5eIqEBwCgg2NtTeXSaS6kJt2abd/spWfxSFmUCDlBjyxzf8B8z+Tt8Q/G+CGXmM35E72XEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: Q3bqMCNl1GppBGsROnIb3pWGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596134993; bh=xVlZJ+7Wx2TlcXyRO0QOGlvMAMD8VVw7xkPWGlRBsoA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=gHIETpMpeO3Cwsq6ETlppBM5GHmIUCzTuaTllw+jMKbAx3QDjuh1QGoe6CRlwkb3OXx FbU1M1zSWR7zM9JUACghDygx566gscFt/SUGcG9SFf+vDsHVw7OQkSctqvY6TJoPWluSr fl1adb05daWSQELA+wwNnOzqmdzVle7hCnI= 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 (#63513): https://edk2.groups.io/g/devel/message/63513 Mute This Topic: https://groups.io/mt/75892812/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 Fri Apr 26 18:26:44 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+63514+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+63514+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 1596135003878858.0367732404983; Thu, 30 Jul 2020 11:50:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SMcvYY1788612x9somSOT9UZ; Thu, 30 Jul 2020 11:50:03 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.43]) by mx.groups.io with SMTP id smtpd.web10.1820.1596135002897956594 for ; Thu, 30 Jul 2020 11:50:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aJ8uMQrW+JdVCR7i8pIozVjPFSTS6BfmBbec+VZi4O/dnvZW0psSGQ7wFBMGLXjYTHbQBaPTzBmZVb+FWTmTZxL43uRZJNil01zhs9RT0TFY2MJF7BiHVg4+kU9MgQWQ82yf+eSNTwirzu0ZXLuF4aRCOD14CLHw907roannX1Xu66ar0sLKT5UTq1Tx0OmsEe6K1Hhw87xRueB1VigyFClDF1YPwq/0QFqo4n5NIhe+pB/rDLasVE5u+M0aGeMLM4vUnwciKDKGtXQ+zahRQ6xaW6oZ+0jimddqb/Ql3FP3EdezVE9okWf2b45+VCzqk1vWUe/o28L6htl+DPsn2Q== 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=HoelVB+hgNEEOIh05rByR+c00tNExqjz7bOl0v9Ik9mrbHBaML3RvPeQvOYpePinhVBWv1tX6A85DLD/jzb/JWIOLA/fIvSy7tv3/9fVCSGIxn1o+5mIFf9XWkshZOPDXvbzycwXFhdvvARnDLHGB4qw/Xou4qZUuIfoh7jQ576knqB2foT5mLgKm8FeWn7XgbVVC4jn2zZ6B/aFZTK+h2JY+R9xsBGYUybDTERil8Fjt2Yl0+9yvyZSDT1C6iDPZYNh3Lk0hxWYTs7G1WIW/UPoZJlemGPyMbE/jxOxtxpnPUhdake5FJCewhBWHFqfsf4JA9HClufKO90qCzNfBw== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:50: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.3239.020; Thu, 30 Jul 2020 18:50: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 v13 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase Date: Thu, 30 Jul 2020 13:43:49 -0500 Message-ID: <55b3809f14bd899a208dd16e7b79bd7b7a8b85b2.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0034.namprd06.prod.outlook.com (2603:10b6:5:120::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 DM6PR06CA0034.namprd06.prod.outlook.com (2603:10b6:5:120::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:50: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: c1aaa60f-b1b7-454d-15e8-08d834b95d32 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: /YvakU8tP2OOqNW4ptokRZF3WZdzC1rsb1SOXFEPg4pzf4Jh+Luy8kCiX5ttIdclUuChn2IJr8MZ4/ntZUc4TldarDHdga0LUWzNu2uADLSdOMFVviJqXePAj9U4ttUr8dl3b/oycCnhun3r+EH5Px5pP3lFxd0mo+AoFUC72cgJUxBaj3XJd31h+kpUIwHlCligtLITZWQFWmE3g2cb5E2DnqZ/l7sWf52EE32l3498N54+x6Y7waxasflZ2bnLUKuKVFPcBcR5FYzBP4l1HkpUhmxwfc6Dp9djiEFlM7pjJ8a6tu+fZnTCo/sKyTo4ki50bF6KI0uptszZsQutwT+uVsql/6PhU4v+1WvHyqo1wtrNjDyLZReNvd2JHJyrAyIZ+Z5FDjuoL4nRtaZsnILavWSrD1ECxhRwRQCjcGDD2ojDqNmIxEco42kIY/SPjpoNhLATEQ4BHF5s7lWPGA== X-MS-Exchange-AntiSpam-MessageData: aF4kYkdRaOadHmyBhUrLopW80UKBJ9hg6zSR1IrZBb81kD5Ka9G/pMmQIj8we1Y9LZeOSwDQr3vD/K3/e3+Ja+DgF6VyA8EDb0Yccp3ppAM/U16BMp0fEIS+q+xGQgiucnpgsF+/thfzFEKTEFQaCAeY9RwJLdzaycqQPmPg8NjtbIIELvup/j6CblNI06zuUrarkhLAYbFJ89EONSDYvgLAs5SBA4upd/WZz/StyTJLR/J2+NqRw7DicP4Cj0FpRBZ+U+XPg8EX5ZUY1Q28U07M4OFTXnU0JP13CKOmHiP2p2rBD2Ek5P/8nVPjJiX3bK9IuQVzR4deSO0uq5+7ZuKRqJI8UfZ5Ng3eZz9O9fJBYhJJ2jl0CyAqqmKSyzdc5lJvEFcuclb9PzQxeMHjBsXscVySAz/Qo9DV4FI2GpO5Po2LKONxemK4qfGOKzACbj84HApkVB0tFOXz6NHb2ijZ3bUUcBmUJxGQR4hQyuftRZ6TuccVy6RVCmwvJc6B6iJw3IuDpA0ALImLG6sxlBF6wPDSD4pOO2J03EkUBbAl1wU5YGgGQcrUF2Y/iaOWMW3gOeDNBtefKhrLHbTa1+p3nGqCdUnlc75RTFwJPCAb0sEcvvMxmL0r9g5ur56s/UwCJ7ej11wKF5KGd40wSw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1aaa60f-b1b7-454d-15e8-08d834b95d32 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:50:01.5340 (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: itz35yYXlxQwTwlQqMoY0vKRqd84VOKFcxHoDVWamXqDT3sbfVsVoZGqliu3EilOQ6bFqoKdHXB40VC8/QLPWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: w9MRdK0KqCakidQwNSSCv2inx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596135003; bh=aForY77XW9cTyb+wyNLH0ZUydPN8Hzlae5yiN3K582Y=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=d8EHQ8ODxQUybyNx/1T6n0bNibXyhjodBF7mfZyn2W48S05GFolxBf3LamnCjPVRsG2 kJP4Ir2J4fvaZrbk1gLIWtg3UnkZe7CKwl1Lrc7K7vS1i76xZ5Aql5QsM42xwjqOWcS/Z Au34KAVoMfrH+dvWthl09TyRWD/GVaZxjyM= 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 (#63514): https://edk2.groups.io/g/devel/message/63514 Mute This Topic: https://groups.io/mt/75892817/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 Fri Apr 26 18:26:44 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+63515+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+63515+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 1596135013259576.2337560458221; Thu, 30 Jul 2020 11:50:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7fuFYY1788612xNwc2DR30kz; Thu, 30 Jul 2020 11:50:12 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.65]) by mx.groups.io with SMTP id smtpd.web12.1820.1596135012343610365 for ; Thu, 30 Jul 2020 11:50:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VPKckXm43a/PG5+rZrbHUSYTxk6temGII58phmFryCeHZAoladRRKKjmpuUx71cmjLXq5OYGySNR3FBrc+9+xj/2BP8gwK7neeH67L9S4EvPZhx14q/dC7dE4PpXBeLn6oDwq6tM8r9JMIWifnoiwdinsqV54lH/dbNQ/+8Z3Vh3h6GZczCj4xQTh+WN/sYIVDhF4NqiAUo6OX81yB1uhgl8oe7gdmr893CuPm5Ze3iB8FLDjxe0p2YcQp/v5DSgJbuja9lPDzhjonkmg/+UXJSt8majKi0Ynyizts1XhJa+f0t6+dNVr8b3kUn10/CuoVxnCX3XvGFZgRbVyRTe2g== 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=MfhO27tC7ie78rhKvHdm7rTX1BLDPD+qngHHx8lLdrnBuvLQDHXzCz2QDYSgZvbnlRvBV6u7Z64pOf16jCGZ2Ka4DiHIOWeMPfDU8QoqkqWz2B6W+UE965xOj908IsKa4AnU9FWk5k3iHYL3PPm+VS/s7Lrm+3RowLZrsYlU/DFXWJAEeGcvnd/QdInjcSFVue1KwpollaQ30n8ouceCI0er7CcCF3UYYal3foQWxu4pvz7XztIVyjceyYJbmBgpmT3OAPu+EP+oqHyI35s48zwsh89pt01E/YZYtLWqMFT1+0+BcVp3YbnSLFqKGNRu3sz0dl3lRq6qtbTHG6HHqg== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:50:11 +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.3239.020; Thu, 30 Jul 2020 18:50: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 v13 38/46] OvmfPkg/Sec: Enable cache early to speed up booting Date: Thu, 30 Jul 2020 13:43:50 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR04CA0089.namprd04.prod.outlook.com (2603:10b6:805:f2::30) 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 SN6PR04CA0089.namprd04.prod.outlook.com (2603:10b6:805:f2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:50: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: a608d441-8870-42f3-044c-08d834b962e1 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: 80fNLpW9pezAmK1faX0uaMCHZ6F4ddc5BrxieDXtUvc5q3NMApdHfgVTGSnKAXvja1mRWzwh4HzA4n0IZkf7Q5iTfAFBe6JdxPSjvqv9Y1fK+1LaBRlhn0KS2XlbJ6ohUugG54tLsVZ2Jou7ELJ1geVCuVqHXSAV/hjV3P4LtCDpAbknAkHQdnQEwLPYfY4fpPjshGKMyt+cNeLLvEBslX21z6vracZ01NAZoVLrNDud4ZNcbfkudrE2j4H03m8pVy8y7TshuMMXc0XPo1NptQeKaG9+A3A9iSi1EVrXaEMLBd689pXezblyLouQLKSUG89UJU95c9AhkxYwfvOituw+3+syYuM5rTNWI1qWDnVRPMHboiPgw2qZqU+L21KyCCFupVEAUQHfpw+QnlO2xEWJzpVKK7rR4+i4FMJdhbX2TDA7yw7DHqU8hb0B/U9jzQQBDrc+4u5ws9u31pSsvA== X-MS-Exchange-AntiSpam-MessageData: BdaicFjOX4AbRSuI67Ah8mQwek4Ki3K5OIulJhR6SafEskM35DpdPv+WgqfrKtCW1hroKZAsbpwq5OrL+pVCW5zynLqw53+DQ7AZtANfu0EljABCWENWH1GlQGqZfapcfW/RN837X1PFB25e845eRPavWAak13sak0C0fY7pC3r9kUGNU55LKL2aIWxo6CHnfBmcHpQEGYXM5N1lKYM4Z1POI+3NNfChbLHflUTCy2JfC9laa/mgBFQHFPKhtSF1Mttc7FWXePLG/bY85UvGtiaqneouAnEFoY32sxeKI9QY7KYFOo9O9j/kCmW2RGQAVTscTUirjKb+mayer57DTpawg9u3A55kCNjN0D4g9R2eMIIGxtAeJb+synaGyLARr1IDoKd+XiYXnsaP2HTeDlsqjw6RDaxqeO8oCFNA8qG4SYDMW90Fm7AMMXbd7j1BtLucbyoIDewsqwrFqik+El7dgF1yUQmu7ImVmFVkN9GaBeuFlfpS2PuGXpIptSWlCz7SN3VRDQw4E4C95IT3oQ4jbqa4it0u9heEEo5haEZsJl+rh2XMT3/KNJBaPvUrBOqqQCQfmhwF0iPvFNtuPlE6kfXYp1LgSX4HqDhsOCEU44varmKNrCjaUBE7fBrVFlxyQCNYvCv6/6X3bjUqdg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a608d441-8870-42f3-044c-08d834b962e1 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:50:11.2600 (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: ZxPR7heHmBIoo9162wK3UqLkmt3EPm+T/b5tr8VSPiCc8+O20dnQr4jsk+iJ+mZyK402+E4h2uhlftEKXtcXjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: nZEOnSw0JSxMJwesMkIucUnBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596135012; bh=nbWxuvCmVz3Z6ubWZ7GFNxM3bRclkbgaGFInxFIaZ94=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ppa+7bprRjjXaRg32zSxd6bR47mln51T0+Ny0RqwbQqkauN/nTCOEOJRYi/3/5JjAxb +XstMll2uOZpkBhshuVxyFDnyOje260k8A4jo6OScbrLr044sk2MHFy/V52PvI1IcTUkt y17x5Ieg6h5i5/fyp0HsjsWSfmj6YXVVviA= 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 (#63515): https://edk2.groups.io/g/devel/message/63515 Mute This Topic: https://groups.io/mt/75892820/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 Fri Apr 26 18:26:44 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+63516+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+63516+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 1596135023154665.6134301786005; Thu, 30 Jul 2020 11:50:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id e8zEYY1788612xrqgTB9TCLJ; Thu, 30 Jul 2020 11:50:22 -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.web10.1829.1596135022252949277 for ; Thu, 30 Jul 2020 11:50:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FQSMDc6WjRLmEvhzl3vKz4ureEmo9U/qER6CwhRYoChbvY7znNKl/BN0mvFUSorT2eMdTfdYUAFpIUqTe3Zq8FruSmGL94rYZJmKt2ivBmpPLI9cP4iZQ4RzQY97VF6CFvt2gfrSC8QpdMpeGQxq5oSxb6fODXLZddqUVFBKAzoLCALAqPdnxhXB9a5y5P15LxujBEmTelk4XuVnmgxMXsO2nTh5R8T4L6+hcr084lq4nfbnhzkvVSS3ve23hETDJoyMKNhFKYZ65h1YCe8jlxE2wN5JM8aD1RaXXxDzUOfe4TBOb10LQBSrtXEahlWZkPktGLvy/SloOn4psYMM2w== 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=dUhNREyFNKm1nKM4dwsj3qp7oKvfTcHONqgsj30TTiXqi7MoDWZiijN3Y11moLYr7ddwhlpxb/hLuniXbEgiD+YwNu9IbUNFbTKJ6r/JSCUDEa1js46MwAfRW2FMrRe4fLBrqtBxOPEfTND8RdONR8ypntZaEtyHxLywB5RTwlPX1WrGTG0BFJohXbHJWXscEO9Q3YZFFZmx1qYoRe0RbhPMPZTS5yr5F8Tk4V1s29ovKTgDUWjxo0JwzgS6/obEXSXmhWTXYGKSOL4Q5L6yKQVDyxrVcskwoDoTywviH7HCCxGHM2KDx9iQD5tb6m13GEVH+WW4NNill7os0Q1H9Q== 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:50:21 +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.3239.020; Thu, 30 Jul 2020 18:50:21 +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 v13 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES Date: Thu, 30 Jul 2020 13:43:51 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR04CA0091.namprd04.prod.outlook.com (2603:10b6:805:f2::32) 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 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.3239.17 via Frontend Transport; Thu, 30 Jul 2020 18:50: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: 94dafc9b-2a65-4a31-6436-08d834b968fc X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: 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: ZztdfR++SkrgHEMjq2kb7BVxwmTuzPH/jUQJrUiHtp6ctW1REz+jU+DMznwDfj3RCjkPzFP3zjazlQyVRvUUePX7szNoowToSyfzXnSrSeVyXtWjdHHzfa2lKZ8G/iMf4xLhTji0/qeZGhdgvWydkTz/llXk+jd/RZz6YRAGvmozFIkIZ3YSMngDR0epQj72BKYJxWBI/rL5kp/nyaJYaSpF5S6MxvBE0cGYmuQamFLu1/f+/qaUMciruQf7bkPyLO0Jzi1rwL0fKpmlP+Pey1ifGKqAU6iYjPNNIxGdd56V9Ew638bZ1mtkZUNRIaWzwjUcVKGjGXVM5gPqhPvCZIo1YgxjQrtvjo3Nr+CUCPTDPY5lEsprxVgbxXJbhBmjV4/CyMSu37F2zq7CCna+/WnWoLKBI9qgLlGLyn0Pzgxq6k6nTGr18+KoWitRVf+U6fZvED4/AqxFk85cbRBR6zD6CugSWBmMGUSE9h2yZlM= X-MS-Exchange-AntiSpam-MessageData: rO1QYbPJvULdpCxGzsu7BTRP2DOEan+4+A+cN3HgC3a2xiEA1IVDwrWUG+Lg9I0hb9Vw6eNRecyNTlJNDVzzSGkBPr1kxAq6Ax4cjhVW5bjdLNhmhdRbLv8WMb5mq3x5Y42kloWmKqwKCBEOmfM9DsfE0ampgHSdhNjTsgQD39GXw/Ie4g9v4h8L/0JixuU9+o49pI1sC/VpvkqF4mawCNraRLLc7wb6+ra5QdmL6PGT/ypH4GOdfwE1c06TcF0dNnVo5wBiv5XI8jFLx/NI2D9PAq8hsH0SjojkVDOCiO1xwV0Zo2DhavCgrbEkRAD0v1zkGe7tzYmOtUVwb9KrcKDIdYKvyY7HBrKwSz4Pgl2nIU3O+AacQBDkhND9jRmZqj5v9kHcYzjPwYJa9dTE0GJL8foCcyx9MDf+nhSdjit99ufq9h/6ub1MbZoLDzUYvdN+DEkbH02DJzjCdFbOZENUxWqaWGryZDTJIg4T4WSHM3N7gT1xzb+PGFCulimbmrXGCn+S5fT3GPFZr6n4Wl0pmTZ6xe9m7gosoCHeeOOCfr8zb4PugHRf+WA/oUAm3JsosfONia0p5vK5vTAXEmBmIIuc6rE1Kln5MHwvH07oM1v754XXvNkGgKGoAHRzAd3hSXUrtWAcm2bnnXzOow== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94dafc9b-2a65-4a31-6436-08d834b968fc X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:50:21.0929 (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: /x17a+Bgm8+L3HeIMuYmWwtsj7Ytw7qHlralhUuRXGVRL3krqYt7JENepsS87FU43j6VMwc6mp2PgXL3lPCTww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 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: jaESxTrwyuwtjTdKgHF0Gfscx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596135022; bh=hZdZqShkbWtLgA6BdsWlu6KzEMadW5HKHHxjdROZtJ0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=enxLyiKWJznorw3sesukIUb2U/htWuGWvheFnlOEye1szC0BQWJmEnlIMftMPn5xFrR IlC6XvfH8lh6BdtCVy88HVYWaRAylse4PYZlhU5VrrR1U4WubpkN+H0xpsHW5mqaZm0LC 7sx8LVp24GsChcO1v3OlIqvGDviqDRvICUY= 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 (#63516): https://edk2.groups.io/g/devel/message/63516 Mute This Topic: https://groups.io/mt/75892822/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 Fri Apr 26 18:26:44 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+63521+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+63521+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 15961417285831018.2871362453814; Thu, 30 Jul 2020 13:42:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MyMmYY1788612x7Y80BAP5xZ; Thu, 30 Jul 2020 13:42:08 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.82]) by mx.groups.io with SMTP id smtpd.web11.4354.1596141727092546180 for ; Thu, 30 Jul 2020 13:42:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kl7Umsi96mC3XfZbb8OPevW5cYqGOd3EPTN7Hf9B7jQkVBDXkn+04WKLj+76rvLbrnZr9AuaxW5AHlU6liHjEzAMQ30NNRBAxpqC4nbGCsh/GCM6IPc06F1vRAY6vUfKIlhiNM3+oWICWT28gWf1JBoR8ataw/082BpO+7U9qzMX+FySLGq5WiVL765qh7PIoQOf3TrYWLmnHAQZ4L6zz4+eGcVlsSARoN2I4CV0y5gNMEBTmuWNRk1FDufENZYmn189CEK82pmHb1Qf/GD9dYljbTKVsFY8n/al9ZEm786kpVg+RyyCtzIVMTVQpZ/wttHbXPd39ldgZevDyMI+RQ== 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=MKH1TankgAgP90y8WmoJANbcpcWQv7Zm9DIFTDyiP6a8FQFPcEdZN3lPzBYH59LUKSaqUbESavmHU/qHhwzDT/e9rGuVTHaNk8getCRwaOqK9Jzat6Ny0d8VrCc3qljx1SHhzwCU/ZaMpEaBO9QHRbFAk3hOs5sEzBhF5DiHD/IFa3uhmgIZllS1shEsYg8Ixk92INeyK4iPBbFDGTLJk18B357LbSWdtLXaY87aFd54HtHq/0bM9K4F7BOgAdRDFiKmncreYejmlcePsF0gmczw2g+ZvCDXGjvgojy1AmRGGb7boQsHt8b0dP2XA4uxTypDom8jawOF8L83nCqT2A== 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 DM6PR12MB3868.namprd12.prod.outlook.com (2603:10b6:5:1c8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 20:42:05 +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.3239.020; Thu, 30 Jul 2020 20:42:05 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Thu, 30 Jul 2020 15:41:49 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0001.namprd06.prod.outlook.com (2603:10b6:5:120::14) 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 DM6PR06CA0001.namprd06.prod.outlook.com (2603:10b6:5:120::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 20:42:05 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 30afda86-c386-4143-c51a-08d834c90525 X-MS-TrafficTypeDiagnostic: DM6PR12MB3868: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: nvGN3vkAqVq5ZOKYtSgp6yTsvEb7QWoen++4bH08xSATeWjAXSqQxiyqVT+TtYubqqhh8w3cC3pGRV7MEe80dvc9Yskxng89NUHNVwImezaYDBaA0Nw4Omd5NAPKRq4MY2BYfjpXglYhP/eQvhAiUvLTIDaz+l7XiaxwmixtTqvEPJvLrWOO8nxbmZXQI80cToKF9rPAQVv5LiOmU13ae9FnHkqrEEXamHXRe2lvTx6SVILfRIVFpO2dX2KdYciSPvsxQK5GbeJAUggqfdKGdZzD1kpQrNqp6im9A0r1/Y3Hb4LF8Ggur1FWt0EpUaYFG7afX2flzIHV5jRG23fdPBv1aAJLK2lwNCGkB03AM0X9xG7Hu6uwphDrgIq+NcJjtkfFR2dToJHLGmU1AQRVnSVCJsKB++OzfPSMixhw0KSzoeYO7j4ffJBgL3XU0yyL4Eh/rwfoCoo/9INrZ6p/gw== X-MS-Exchange-AntiSpam-MessageData: gM/WnRubzVwnYNXW4k76tLwj50Z6jQWFXrK35moRG13YtulLkw+oSAP9ZqNKmk9h9/5hGxVDsJbEfd1a4h8pEYP8La5MOCcbCOf7X7DbwAVEE05z3AoKoKgxTXjaCGrr3EAMQazV/1cMpd1r8s68nnDnPilsbbMShfJaMryW4nJvL+l4SHziLddUbMthgi0mukL2cYWR/9+i6KvUaF6Eg1a4qNsjq4uxjk52/fHZX5yySqWbOZtgF3bS/u/4Xs+ro1JQhHndYzliUladrk1V2hJXD/Dl/PBDeXDf7kEmQ1kmmoeytoTiN/FBFUMHBRGZzPA960v2fifT7IzLQFN19QPngc8qLuzdaJe+v5NoX0IlwqePbYLKQVv2QOPyeFM5hb+pJgkt97UiK4TlrB4rBfNTLFlhhhO0X9VoPzlyOe4uNpp3b9xSvrj76GrtdNqHLIwP3G00ovdFfLpjISwSWWbxwDJsVeOVqh5A0E8c52t4G1twWYDbyrCvcfvUNS16bNf6b3Qg95ChskvJ4GXxhxpZc0/JZBhCNWxl3oFglsc5XBUlt70YidIkMA5uTARvqxCsnU3VI9p+EkrRVoQ0a4tK3Z0CS3VJEagSBZsZG8YBRno6aI53/tRhKEj9h/0oS+QJ/krDXvP6rTbncQzc2w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30afda86-c386-4143-c51a-08d834c90525 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:05.4486 (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: Qd111NCtUXqfh4Tbv3dVTNh7Cyq/v5k3xfOTzx6ljh+wRLm9fbYyHODnYuWXoj8b224LjVQkwGaPWuQdcnSfZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3868 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: I9HviJQtKmgE68b3tdSmsDSvx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141728; bh=CAN4EdGWAgylIneDc3Pf0dJ7B9lr1OjIXg91sMCxWbU=; h=Content-Type:Date:From:Reply-To:Subject:To; b=FhOL5z+WODYA9bBxglzP+KufCkTBWoCBMaljgcq8X3DCxplSepO2oMPs8YgYSK0wc2c mZLjl0T9/n1QR9Ni/cPZZf5YvdZ6/uHk3ZkIPAm5SiYTFFcVLjK1k+jx7ftKxNAHrxqmg vT5ntLi3Dh7oRkymGdY0oA++YtMoIfSEUXA= 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 (#63521): https://edk2.groups.io/g/devel/message/63521 Mute This Topic: https://groups.io/mt/75894989/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 Fri Apr 26 18:26:44 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+63522+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+63522+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 1596141735082382.6363897460195; Thu, 30 Jul 2020 13:42:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0Vx6YY1788612xZ3sQ8wloIg; Thu, 30 Jul 2020 13:42:14 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.58]) by mx.groups.io with SMTP id smtpd.web12.4249.1596141733952250183 for ; Thu, 30 Jul 2020 13:42:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WFk9SEwRfaDSk5JER4t3u/icFBG5UHH5hLFRne2nvF9mPhcoMuqFGJL/3C5FjhzC9VxLNePdr5eAQKPA+JdwEgnGMKcnDizlu/GAZQ1y4LORab18VZTsiP3vED28A8se8KdAC2SgmhQvds0yoWQgMgKnVnOxD1q1JlnbgKAJcUKea6CKVS2aomsv33C8CcHDB7ffDaPQBKNNvAPDH5E6/9WX/DUiBch6gHxmJ1DUSVFaQtvGrMgILoin5FGaJQo7M8V0eXb4V1UQulL5BDb5JggL5o+7PyUtdLs3Npa8xZSpldl6MkaxO7irLxba65AhnBsPlijB7aQ8+trRMeD1ig== 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=aW+npegOUm5Xk+GHJrxmLiVYcMLloUbZNY91lF9UPbDdqtkkfbA0sZyyeH3/6kOCQdqAp7vdBpQ6Qw07btQe/05YGRwaBHdDukqjfiMpMXWUBUyCsyfzl7KEGpxsfZ71bRETBbnDP3P5i9cHucc9bfkrOQ4LmNH5P4b6EWgTJ1AKUJGIRhpllOjDzV8Eg/oAToRcxgq68McHqVi+bdXFsvK4vS9Xc3bQscOamFjk218EW4qEGxaL0x6H3D+6gMvLjejgQ07l40zGdAKZWfgNdUC9qIubLjnl2YY/a0FMiKPlIgvDGDkwVE8+jxSm2BVzrjDcB44k6jE4Ocmy42NwTA== 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 DM6PR12MB3868.namprd12.prod.outlook.com (2603:10b6:5:1c8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 20:42:13 +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.3239.020; Thu, 30 Jul 2020 20:42:13 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled Date: Thu, 30 Jul 2020 15:41:50 -0500 Message-ID: <1b3d23968783b26244e66f216eea8cce6b9e5582.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR21CA0050.namprd21.prod.outlook.com (2603:10b6:3:129::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 DM5PR21CA0050.namprd21.prod.outlook.com (2603:10b6:3:129::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.1 via Frontend Transport; Thu, 30 Jul 2020 20:42:12 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fb7d7fc4-6147-4af0-9b73-08d834c909a5 X-MS-TrafficTypeDiagnostic: DM6PR12MB3868: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: nX7OtXnKlUCAC5qmFJVFLP86wHfy9jVTT9r6WepSRtelzmu6ls7FEHLzwipbgL55E9hVhNordaNHnwuBTelDxlQN16X2uO7vGcxYhpjNs9RmsSTW3LPtecMDah7qa035jUWAHIKlKQod/DBUpIQl1sd76pwfy/cS508VhutKoycm3SX4DzZ2U2OEUujg32aZKEv7l4tq2LU8kLaBtxdWkhPR55jrkQTp/ka5ylKRjcR8sFl/ILBYypK5X7WsgQ1192poRfjT+UVx+D7N32yNfPDDoCrEwqIRR23kd0taUCAJe+TjMEuIjL4V2iOCFUxnAJGom8macboGX6SpVe7pzbXxH3Jqcq1WWZyhBYd1Z1lRKYSq1omjojGmQtcbVh+Q8zJgTWhs0houoqu6TdF4l8VVbJWPcTr9eJ8ac/W4p0bwjFBD6Dk5VOt5hKSFWeex2vLfL/K1SbFL2EEpNO+90Q== X-MS-Exchange-AntiSpam-MessageData: stOtCn+gdt8rfe6pPkdqikuOHfv/hcQc5alzsBHZTSywRVm7S0tUnUW2kJ/gPRQ3LdlO5bCkXRezHSx2qYqnBpYgciEYTiACbJqWEWnOiwzXlaOD4Aaf+f2GTUFiTy9HV7ctjD2HDu0DNWM8OuLVmEr3OawisSpLIRz0jhsOmNPHSbp9jkZEZb5DZiWXvt+NyldkabtgdTWKVxT9qImTMEGfoUN6HmDCE6bBpRlJ+USxIOpbIVClvBX+xAwHmBQuHW8ti36KVhspYZjN2kbuWLwABG+LV5xfDEUHI9ebDslAUUCqNdA1/PRvuenuzCE73pKU26lUFRFXVbZaD+KssKxQOY+EazTgq52rd27HbM3xR9LECHHCaygZCQ3FocVKHPJMzZSJWpafBNwB86fCSI2VOZUUZMG+yif7LbltuxZiKNtYIEKE8si2J5pnELYRLbktzg9fbxVYMrx/V9pV6EfeUMc67bEmZ80wTXH3KZyKRHCHDDQYnOOcfCfajLgWgl+s7yVxJ6hreEiYd+Ki2dgNkXen5282GgIV3ptYGf+5LyjmwCnAyTARv6ezwCrQKEV5WkbvrTvaB+jyoSjJjTsy2+snSS9RM1W+ash03kHNMGtnHFJOd/SzSOLZjEXlRRWmx3M9Pf/KBZMaw60bkg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb7d7fc4-6147-4af0-9b73-08d834c909a5 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:12.9793 (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: lmxbV0SV3vGkiPDcet/A/5ShWwetI1MGC7WhYtrGHv04tts/FWeMCvbbKTrVxBwYO5Kih153M06inJJ9+cMc+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3868 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: drrMYHtETD3dXCGfOkQoXKOmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141734; bh=CdxuMuZA7n+jBZkh1+4TbsuI/zNLOK1x3KEHIYW4MR0=; h=Content-Type:Date:From:Reply-To:Subject:To; b=TFOFuO+6X1FcG2sonA7sSy6n7O0p7pautPT0cAcUp3D8khW3VSC5tj6jDfLpEIHsk2X xisaBiK2f/gCb8P9AgHuBjZtkDnIY9XD+X2JnSuWwWyMsgj2spqF4JieTIU1Yj1XwuByY 8VuXN35TgNedXZVlfbGCfz7nknm450DWDX8= 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 (#63522): https://edk2.groups.io/g/devel/message/63522 Mute This Topic: https://groups.io/mt/75894993/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 Fri Apr 26 18:26:44 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+63523+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+63523+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 1596141744066208.1001464082807; Thu, 30 Jul 2020 13:42:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YI07YY1788612xwAxBVHEHyo; Thu, 30 Jul 2020 13:42:23 -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.4359.1596141743137639536 for ; Thu, 30 Jul 2020 13:42:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=elYev0CCC47zAJzCpdBcyx/jutJNxv8k/PUbZK+1I+7KQY4NdW7KMFbG7myIpbzx4EH+3eMSgz6B+fWIshIzbXhnecL1r4+QCZ7DyUAeN3h4haZssjZLeto2Affx4iA2pZFQy7GOOLWNvp++RQVXFiN5gqAAVlvvf7VR2vdfD5btUeuU6/hxIeiPGperE3XmSilPddRTH4uquEwrSxJqzMQYbKHzVMexFYwUDbX7dWCaOp3oEh/Peq5Ue3FMNjDyshrOa8G5r2QxIGEElYRlAc6i83ciZDSRLvsNm2qyxrgfh+W+TIJ4XrrsHRKBENrAqYVVhiDxSOhRFJczVG9wtg== 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=Siz9O/6y6gyX2wL2+YZndLmu+fTGh1WCERKM+L6ZohERO6ZHqEnysOC15T2CM6COoRuIj4dt9iby5AImprnZQZrBdb0BEGL1PJ7Pkvg155Nx7OwTW4iWH5lJ3Vo38Trcp14JyS064/BFuoIR8mUZLPML4zqo38MytNsSRas4ib1EN8gincE+pt7KWHeFC5O7CpTELUidxj4LxfiLR40UniFEcwXktyKIJB4gPr2oYhHYtypqOWXobbBR8mU6ewS4bHy5n88gv2FAzc4m0QvHruHB2g5FiUBJpCtRvdjlmLr4oX2UYsnCUmTSPIIqjIhgOagdzFHyg6s0Q0sygDWJ2A== 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 DM5PR1201MB0027.namprd12.prod.outlook.com (2603:10b6:4:59::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 20:42:20 +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.3239.020; Thu, 30 Jul 2020 20:42:20 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 42/46] UefiCpuPkg: Allow AP booting under SEV-ES Date: Thu, 30 Jul 2020 15:41:51 -0500 Message-ID: <6b32577ad81569ef6dd667f0e0b2137c582a9dac.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR11CA0022.namprd11.prod.outlook.com (2603:10b6:0:54::32) 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 DM3PR11CA0022.namprd11.prod.outlook.com (2603:10b6:0:54::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 20:42: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: 055f4517-cb21-4745-c598-08d834c90dff X-MS-TrafficTypeDiagnostic: DM5PR1201MB0027: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: kgdsFBtNuGe6UX8hQjel2Ri3hkd3xQGATnXb5ga1ouqb4LbBsHnnbf5mXqOLGvXqH+DOMcYiSLwPMUcmMZQy+0jLaU4wmzARy85DAlQT5eRTd84aCU+0wrpW1mrh77mgrWOK6QdbDmFFfxhHeSIIn0ZGfSqFqwe/VCkhe2qprWZe2DPxdmpFEts5GT0LK5QtgofJnqfAWkMOoRu7ud68JyhTqY4/W4A7aIMM9iWHrS7+4taP9EMWGFzTMBQ0j4rxcf6HumuORRq9iAAUwjiBRLZe2ghm+xAOlyYD6rsiTttz+RNqHzAwR+8GQtC3F9vzY5YqHBGo4l/EPowV0So4ImvSWF98ZY0ENyMYmr9D8tgUesgGtIImZy23PorBen1Tb672UcTe8eH3p11GEU156QVz/BPol6+x4iAbWuvml6P0MSrny3huH8MHez8ldZLTOKzj25zYD1pfcUaGMuxIYQ== X-MS-Exchange-AntiSpam-MessageData: 3O2Bu3X3Lzoja7D5xTFRoDS1lSq+yGzN0eGaDH03xoUdvcGOh1XZssTp41MYYZw8JEft6jSqHyodK0cdCEVGqu4HhjJN3Tm86Gs23ihxQzysgKowbVS4JYe0z2gvYE4RkV2xMbmg/SpLJ3NxvkkM4LbvQMMSgUL5kynYllwZBu7g2tBr+jv5woYP2mAi1grSHvcqUd4R6ka1K5b8wVXMGtU7H+10n02RWYFfXDQcF+8e6lK/ckxmbFq4WHs/R4+5Zxv0KkfTiUB1qLoiKmsBvXnkNfHxOXIUfRHfQoVSgM7WOZYE20mhO3c1qrKIH1avb0O8e4eaNYyEwRW9fQ54zzm++kSvI7ieoo5k2Mzx7mFYWw8Egr5zV2KeKRqv/+Z1lrN5lL5LHRXGBlgyrF856yiN2QP9v9zpZVcLVYz+t+3lYdhuLdxYWi1RfOR5184js4ZBIukaKVeGpKI6sDrMpqNLikZz4Ub8SBOT/hTmMpI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 055f4517-cb21-4745-c598-08d834c90dff X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:20.6219 (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: OerLksigvhGL0Xsckc6zWnTIUahoQdNqK52co7ag9p7rArnbTul3wNWAcKpPpxilcQFROvTC+x5tUjffvQqj1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0027 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: 5Vk9NzBiSHa02yUUTEmGt0hHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141743; bh=NyYQyU4ttAyZArnCDabG6pXFvQP8zU9flG7Zajlb1k8=; h=Content-Type:Date:From:Reply-To:Subject:To; b=ElphN5ti1u1vHlexDMUaDezaJ+Ynl80frhR8t5fkqfgNcbNmNRl5Qyvgpd1wjksWipK XgY3itUoOMj7IDfmuOMrioarwUy/JDgBdjOrt7BbUCNCgLiLAqLAJxSkfOMwvGeWHIIN7 WeXN1t5Egl23LipcUlu9CCQccxhy+LG0clY= 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 (#63523): https://edk2.groups.io/g/devel/message/63523 Mute This Topic: https://groups.io/mt/75894997/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 Fri Apr 26 18:26:44 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+63524+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+63524+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 15961417501111.793256336073; Thu, 30 Jul 2020 13:42:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kwzAYY1788612xPfbhSddEj7; Thu, 30 Jul 2020 13:42:29 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.53]) by mx.groups.io with SMTP id smtpd.web11.4360.1596141749034938902 for ; Thu, 30 Jul 2020 13:42:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cxZ66JGQPgjZ9MZkTT2RjV49MbpT9jY3Eoho95ItTBWZoiK/UpDSHm5wWE2WgyKgn87Z7enPGoJ6BPJZnfaXzSfKUwfij4BJ2RdKYzuBnhPuNT1kQGAxbrvgeerv93Xige+LrQU6UX/VFBppvk478x6NRT5Sizht7p2qTF2bK1O11oIcGwLayfaF+UTDEZ1+UaEqMcDsW7RiNml7bQ1hvQix0357eXncLYtjJIe3CeRdwIvcRJhVXlq0UKUVwch3H2GL33IduwTK2qwF9CA4idnEAqc9bJiwzVp8ZYbMHLZVZHkuT6Mv27tavAhYxvYIeQX9kPRfReWwLdTosBFXAg== 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=VThS39YRiwAt6IxPRZh1mDaOz/9Vz1FAB7ZIQYS0+GL//E4Fov6IRTsRoYvMqBgf6iaLguHUM/vNhaOrdo/6hiuRq01ZfsrlceczNp3wvINq9uwvQyhJ6afKiWa9c2vXZY+NNGteO2SNxjZXSXg7YZmprU5roQksgX7+fR/+WoTL/lnjMf5VrddElWqqjhIgW6qH+hFDcMiqmPFEqOe779PAUSMr8lITgphE2S+uPoCYFgfFs8iE6ZXdOsf98riglcCcwNOrIddQVjX8i6Wl9Z3CiI4bdIJWy0PsU9RdQJYB4LddE+GS1qdyDMCXyJeTcs6dvDXuwTmwwOdvPx261Q== 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 DM5PR1201MB0027.namprd12.prod.outlook.com (2603:10b6:4:59::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 20:42:28 +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.3239.020; Thu, 30 Jul 2020 20:42:28 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector Date: Thu, 30 Jul 2020 15:41:52 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0045.namprd06.prod.outlook.com (2603:10b6:3:5d::31) 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 DM5PR06CA0045.namprd06.prod.outlook.com (2603:10b6:3:5d::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 20:42: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: 88f48d5d-72ed-4800-376f-08d834c91292 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0027: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: rm+JL+oc0h3F5Cb3Hi5zG0qtp0vmrmtPTuF7ZEWtoWrfKwDJDF7UOhcgOcqQi82yrcGsHOmTu8GqczRK9dHFE4D1cJzL2A4QVmr61JNDFb3CKZAfy31eLK3dUqNOHR6u1ftAnV0DW26eV1cxz+Amph2YtTqmx62AAm34OhonWaH58hVHnW7+8YeNS1OD34jc1QkKyVfEoHiUWi44QVJGOsQwpCsSrEDiPVTXEiVF04YC1ltMfO+wTR6ZbEgS91lYGRktBJ7xmtxlmQJxWY4AuJYtaA2TERAAmv1LsojCeZdxbD+sTRQ/o5KrzUoKCS6o1DA6/u/JOb7yEi+I51CtBYnUszyjbYhhdTpCUTHBHeHA9QcAUifTXiLYOiK0AikHzfpAThV0EqwZKUuTZlwIchphYzX5Js+R3kQvKqfxTa4dtwsJBFeL191hL2hdp+0wxgZFOGAber4iYEpkJ1sWHQ== X-MS-Exchange-AntiSpam-MessageData: pk63m8cgH3eZk4j13G0EBL7a0TRT0xwPpgYkj3al+hxIKfbTj/d4LMNqQUVI4URPUL5g0Y59VCXEiXr0REGmI5aZtiFHdS07xyOVbn0RLXQL/sq82VVLOltIXc/0f/YGvQCy3BbtLWITQnw86rmVGIdRAMAmNTJdbdSqt/eLIID2sEHFqON5BeK6WaWNLkvdsC0ITNRmK6dWp09wPWMi29gXk11WvueHci4/IUpMFSJm4BUAxF0EJLG0J3/0DZfEl5VoNZwDRxsNGgMyz6qlnO1JmCiiLZSCmzSZSmuw/xaiy7k488btz0h9oec4serG98+WXJW99ZSpkf+9gnaut/pMR2Y14YgH0sB+grL74P2rCrrGsbxQ3n3ByceAoNsxn0Q5brEDx87OM2lIyiC64FNnpjYDniVblARwuJNcvzd3A+gCsXoZEXJlfSqLJhk5AM6v2yS5aycwA/pZ+wZZHskQPToCGICnJsm5oVx91gk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88f48d5d-72ed-4800-376f-08d834c91292 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:27.9697 (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: 0JANx+5RS4VKfggx8NZO6DcB3e5wk7rOl5yzYCpSl9/1VplzV4oC5LyKp7eDZMFSw4c9NNPKx2iM42hSPv+iKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0027 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: fUPX6ih8y5buQq07jeyS9Ojex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141749; bh=J4F2+zKdeIEarpj/cyrP8ngCk27i3hZKbqxA5BygEDM=; h=Content-Type:Date:From:Reply-To:Subject:To; b=LNhCGNiCf1Rg8eU35VlzeO1rExfZHJo2oj1r0EaPk6tfDr5Srb3GcidXORlOmarIFQB u0d9hyKr8RteI4zpbi3wreOrND7552xHh1GTKhoe86Klxu+EkQZlXtbZ3Q4UgSTVnAZWA ujvls2XhTt66ZnI/rk45XLTVt0zGThp9YIc= 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 (#63524): https://edk2.groups.io/g/devel/message/63524 Mute This Topic: https://groups.io/mt/75895003/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 Fri Apr 26 18:26:44 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+63525+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+63525+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 1596141757409740.9681133378025; Thu, 30 Jul 2020 13:42:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4bWzYY1788612xmbeGx7xKj0; Thu, 30 Jul 2020 13:42:36 -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.web12.4259.1596141756256713394 for ; Thu, 30 Jul 2020 13:42:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QLNZpx5ewUBY4GSikny2BfyvxXrYOOqRQHj2kr+EzRe6L9ZnCHEyNaI0Skg5z0icL0yASCdQAil/F7HRSiRm0a91GbLmrYXuFWCfrvW7mKJdaAruJlL3nEFJDEVcFzmCRbEN4AgzdQA05TZPsZdEOQMlTZPSc4b9KWOb0A8Kbt0GICD2VCFfWlPeKBEVtGMkzjuZe7Sl575UHvtahDPe77x/Rpe51gAaT38DB+wo9HdJ4aZukQP+TPLu9WuY2mHowQdlw7eahYK7lLPa/utZ7TCS9Uu0iwkJdcHN8ecDxqZ/HkD+bkqvyDRY9UQ67ghZhGXWfVnYwEnZu+ibjrk/Cw== 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=oGWXukGC8AqS41dPauIxhl0TC5XOVCIJyUFB4TWdZ45n5MH9NvvNYGDAjHWWfF9+upZav5WaoCB46p6nqj0UvH9C6l/P/HOr3GkwSLs+ntXloSCgaYj5xgh7eccVIXiGzQ/M2yN0CQgizCfyPfKS1J7Gcc9rWjbc7nsshcxZ+IJLOgplTKguwFzI2U1IYjSKqU3SLJ2my5ZOU9hNeKOVDGNlkYPik+NN3FOHUEb4PLWy4nBfQKvh6DKpEuzjZEwY2x6TjBxG/0xVhkDY21SfSQGXn2UBwRQZ2rfsFRRRkn/NdhYrC5HG12yzwuk3dfDOrL3ROWK6pRfjtd/JNQUJBQ== 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 DM5PR1201MB0027.namprd12.prod.outlook.com (2603:10b6:4:59::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 20:42:35 +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.3239.020; Thu, 30 Jul 2020 20:42:35 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 44/46] OvmfPkg: Move the GHCB allocations into reserved memory Date: Thu, 30 Jul 2020 15:41:53 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0026.namprd06.prod.outlook.com (2603:10b6:5:120::39) 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 DM6PR06CA0026.namprd06.prod.outlook.com (2603:10b6:5:120::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Thu, 30 Jul 2020 20:42: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: 129f4602-0bd4-4f3f-ec73-08d834c916eb X-MS-TrafficTypeDiagnostic: DM5PR1201MB0027: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: yLlICEFUWlymEV+y1OPG4VvCdV8U8lhPxc7N9ab4cfjmYVvP+TOCkf1+r10zVH/S7GOwWpdDxwXlUjyECGAZ3fbH3AASEqaLhzYYlnu0GYqznl3Lq/D5nnL2V7oeb5qXuphE3ldtbsnjm+IxNdkxBm1CNKbkWBHAkHgWPwA9NdFjZavIk5qkTpA2QxPsxDB2IbkgAq7DzkX1prA107/hzpFswfqNNPVdl2bJwajmgZqhR2nDOP6sx1So5QAx6yEIT2TfpzwGDbUwsKXreHCFV9UNmIP+zwjPC6LLtuZ6ClbiQQfxDxhSW1YEpbndu0FfMoBjuffBBGEox1efFweK79OISF3rcoDQ9Ynvc23N4JPmZCmqivClbyR/QVJn7gaCR6T7r/3+/TlKDud0d5UMiMIF6yiZ0BosU53hhxy1giyJBy6D43X6ySX5LoFjqDr7oCi0SLBDFwBvS1NBdchaUw== X-MS-Exchange-AntiSpam-MessageData: oRXj6MjDxJG0U5lRjS8eTA8mvNpXjG0e6N2zv5dLzioVZJHukKHiurG+jv1XPQrLsIuZDprpt9zSNFgeJWvqw4RH7oS97W0t1hISrsdoJWGhu9ipbgPsU9/l27xhN0B6aMHvGYHnHXUWrjlplcpkH+JW6mZGrBumMhbAIl4z+sfgrf+LkIVTskCCORiK/STcUq2BeZcQJYDnjfyHAMbo3XzXDw7e9v/YSRXVVgfrfj73/YMRL8rftGKofKlbxbhO/lIlKnmgyp7GMmKzkcmjYha/3rEJTmUoaFKOTddXPTj3iEquC96mK9lEm/hEbKCbMNeVEpgVHkB2l3b6uvauW0fMUEyr8M8WeNA1HynpKE0wwclJchyPffmSu5iLtyJaXKpNtq2nsmcQfWtnmmvAGN866V7mAWhLR/MqzKfVYZtbK32R4aZssPNsROsQ5oZi/rv72KW0tIyhF2HyUjXCgaA28M8ELkkJDvQJIPRR7js= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 129f4602-0bd4-4f3f-ec73-08d834c916eb X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:35.2795 (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: K9DUGuQCRALNsrW1yWPGg+bjzT/w3T+XFVi6fE8C0Pi8kLLQwivEqz48QYGiY8z4RTOoKxUubW+Wo/WkIqcWOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0027 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: k8WghFVYGQmu3xNDS2QMOUWDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141756; bh=s/ulrS2GTxy+aknk+byrPUMEoKgsdMEkjsAAYO8hMbw=; h=Content-Type:Date:From:Reply-To:Subject:To; b=epfu4nks4K2woHl+/SZVpWE/1gyhsbrieKhT0F2P1wGSmUnm9YdKj/78lVzN5iskEwO lG1+c0kESdcKBrADS0lG5SNEN/Ez7Ph4Gw7XU4lC0+jek0tCQW0gMiCSrClHUIrrQP4oo 2hdDBGT2iBn0RY3BQzLlIlFXhu3Fn8QuCBE= 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 (#63525): https://edk2.groups.io/g/devel/message/63525 Mute This Topic: https://groups.io/mt/75895005/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 Fri Apr 26 18:26:44 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+63526+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+63526+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 1596141764968955.1759693726715; Thu, 30 Jul 2020 13:42:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uB13YY1788612xQKWp6BidOU; Thu, 30 Jul 2020 13:42:44 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.45]) by mx.groups.io with SMTP id smtpd.web10.4180.1596141764010796347 for ; Thu, 30 Jul 2020 13:42:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O8iN5NXjGsmSy16GQG8AALlMjvoR9IhQ2jAkxiNyDEjsJU2DFSflbUb/rYsQs/0o6K4aaS021yXYDYOvdtICQGjMm05GpRc6TRyRJVX49dbEQMyFKLg7teku8U/NdbQT/awFtAPq0fDjNlrrn3I3JmhP+YMMus0KIv0uXVJt0LX+9PdOlv+8AVlsAbpT8vaE1jAQkv8gRtTEnUvcA4FA1MU7+9QE1prQ8GEgPZTmIe5QZGlpP8GgEp6AyO2hPJVYdDDk4sSvErXlJnPdcMdS4yn8SBCxL3cay5sT94aK0bmcrwWs5ZbmW7yMmw9t5Ij5s3ZTRQgpVNo66EKhQN6xrg== 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=b+2u9/niYu8XTeyDLdi/7cd82W/o7khau9UbDzR/Ydv2HXvdQfyPsaNFZw2NYW5ZOyPfhxTYP0KjriwhyP68DkprLzzN6ovqjtIG8tQr8GJsOIsc/eE2bN6IAPEFTHAl96F8mAbmNqGkYaUicSfCJV4A1m2WtfRc1Gt8zHrDuX6mFiZQMfgwWOt2FAjgDetEdlQRxRLLIyLfNm+eRFW3FE6Ek2JFLxL6n8X/pGmZpbcZFjxIlAAw9xO2xz45OWj3mWFvleY1EkjzW8Mok01n97AtXif6s2mGYjug9x0rzE69Ja0+vSMJ3BBW/yDuBVhIUoKMnD3VuOug2wv2UbIk+A== 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 DM5PR1201MB0027.namprd12.prod.outlook.com (2603:10b6:4:59::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 20:42:42 +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.3239.020; Thu, 30 Jul 2020 20:42:42 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Date: Thu, 30 Jul 2020 15:41:54 -0500 Message-ID: <9d41b17caa823ab3f39f08464785afd0fd03578f.1596134638.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0028.namprd07.prod.outlook.com (2603:10b6:3:16::14) 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 DM5PR07CA0028.namprd07.prod.outlook.com (2603:10b6:3:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 20:42: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: 28b8e369-3ebe-4803-4113-08d834c91b5f X-MS-TrafficTypeDiagnostic: DM5PR1201MB0027: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: C0BqS3AhJnCUPXk3/yKxE1Bpozew4FxWsS5mC8z2mXmd2/1lcBb5TWPBXsQbYDr5OF7pGjuzYdKPJzflRHxxxzrFup5bQ2AxaY3dHk0VNIbjtNWU13hCI/umVpTgGOyF8UXVIdCrs0uLRobYpPl2U7sILHajf3i3xumNu41f48yYZ0ZZvftgfmpjGjDQSBW0n2bOqh9912ntm5WgoDVM4Ydzl93PpEPkf+4508CutI0c+smHYvXJadZxo+soa62MJzsYPx1umKxlCKvS6AV2laD/q4dzy4lWz2DdwMcpgEV3BGrpTeEObKQYV0CvPbMOsQ6DBVUIpfpcAPckWdem1/cdiIuOTBKUafrFo/94Vt0rovphP3DExvdyEWmCh2kwiy8GH4GbAq/+L/s5FKepbdooGvW/YetpFT+95wUK95NiyATKtVi7WVIVeohXJbT+Gwx3xYSuuSsmoYec2Lg/Wg== X-MS-Exchange-AntiSpam-MessageData: jFUBqVe6MHOpVfQKWuTYggH4We4RWZ32fBlg26czOtIvQ9t83joKsQTPLEDIQ/1m8GJyszZ2vZkBqPSNweTiQSwY7r7d1tMREBkSR+uvM5W0UtAF/6CzPC0JyLL0D7XHIhFok49KTPiefNy/LsY5F9gLIFQUszn1aNV6zpmla+4pXJ8++6jEHtykqSdtOugiwTSj+kYx5aFFQsdem05eEU+NSEiAL5avDZPDRdwhW457ssGXJFbur18JHnBRukO3Qy7O3A3zv8ezRUjrIHLB1ATK8iR7lBmeM27aqsgFpKtn3w8PsiufgEU4Qs89GqmZof8gn2Wap4byuNwNb3N2gQjFrqC8pbu2JYxphTAZd8sSd3XOVwLQjF8fYeXb3MfJuP8DerLraU4G6/Hs9TXgUVoXd4hPTP/jhLXwql3l2kIVWn2AddODnaBCIqmSDDzH1SYojqninge8tLZhG5vznJ+bn4qlA2Hoxhv1Sjkp7mg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28b8e369-3ebe-4803-4113-08d834c91b5f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:42.7392 (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: c4n0nKsmSPyO9MaaaX5cDhDrlnGWsr1WWxyMVJLXUSONdq/Z0TcZzDqnsrvg+pas1+JjpIsd19B1KMqzvH04BA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0027 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: 9wEqbpZaclhQaB5i9w3etGQBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141764; bh=t6CQY8NaNsU9F8ixQvzuKcL58qua5Ri65+kjr7H69DE=; h=Content-Type:Date:From:Reply-To:Subject:To; b=PK2W/DbzEPqcUA1We/ZiJwgQ+BR2P9bQ5pbd3j54+aP2cOeaGj98zzta4QAVN/P8+E6 N3Gjmx0mFk4/K6/qgpl5IBrXZDhGWpxJiGr5PKLq+G7xheAjl7BLHmcwCrux1oy99Za8A D1keoj/9XjxLLGT7CiwSWF/B+23H24kYatA= 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 (#63526): https://edk2.groups.io/g/devel/message/63526 Mute This Topic: https://groups.io/mt/75895009/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 Fri Apr 26 18:26:44 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+63527+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+63527+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 1596141771783173.88992418655175; Thu, 30 Jul 2020 13:42:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id v3xyYY1788612xGB0sjfy4pn; Thu, 30 Jul 2020 13:42:51 -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.4367.1596141770972828143 for ; Thu, 30 Jul 2020 13:42:51 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c/X2eiW6Fa2iYdTe62uPx37srVUIWiuoRkXFWcLXXotre2L7bu3BLOkgrsajsdG1qHswIA0PlewDquzNwhVhk3MZykvnwjvXhaMbahPvueYxZ8nIF6NShKujIii5QM7Bl5QY6cFQ/28+okOGE9G8R2r3/ISVr/lQ2Dkv3203GYBXG7LcTEUq+YnYZdr7EmJo5mOVDkTqsGHaDByR4KGAlHwsNhKsT6AFcjFJgrsse6AYnAk5oLnpqv/lkqVPBEhZXbmsTRTOuGUEkDcigJW74w8W0pPpjhmvnT3sUoXcGDKiUCHvajXr1tEHSBg8uLStH8LjhW8Xty5hx+diMj2KbA== 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=XCnaAzxMkOBWc2lJckBTpLScRWzaGsdTjPPPS/httsc=; b=VD12riBRo2tePflppOVPrsP920HjfcT/cToINIvDHGHCzQjjnqh9hd865gNB1NNkcEeZLeLUPg6zIE1jmcdHHcWJEIAzESxuq/tK904oeJw6qQyAzt4hVlRoR/tYB/bsGpLglPXqlr48OqgwbkHUIhy0K2XMXOVCBU0S+S2Bbs1ak3W1BoPFoos6fth2EQmO5QtTZurb5CBXvRACWxtk5RHimwsegqcrDZ8RmoZQY6gfr3bv6jzJ6BkvYRAB4E+zE7vJ5M/LJSm6cn5ae6LtOaw7rcVf2crSdbTEepwb3Q/q4fppCiTqzX8XTY9ZiBIcGDmvVkcMcJdir7aUhxHkgg== 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 DM5PR1201MB0027.namprd12.prod.outlook.com (2603:10b6:4:59::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Thu, 30 Jul 2020 20:42:50 +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.3239.020; Thu, 30 Jul 2020 20:42:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v13 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files Date: Thu, 30 Jul 2020 15:41:55 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR17CA0069.namprd17.prod.outlook.com (2603:10b6:3:13f::31) 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 DM5PR17CA0069.namprd17.prod.outlook.com (2603:10b6:3:13f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 20:42: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: 2fab99b7-f63d-44df-6f99-08d834c91fb7 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0027: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 1Uue51BAW1tHbuoz2pKdYkdnFoKVs9C2xIR0K41DfP6+Tir6QsbE2SwqnElkLIctA36UXZc8UplUfghaX5zEyFRw0ehaDvbpDSkudqRtAx62I/gZJyhFALTV9j6lYgy6Js5yPfv1octq4b/gztAICGafUEDa2qRp4XLSBSL6obae7Q36ch0SSCq8OuMS4ZBJbKbCDlxnTcSPvfx0j/GgmewRNCjYaCMFMhcqcUHwHjkzbt8uWSeaLWcn1wC2QgCuLkWaMdjaLUIdnmUUBCOHqIYoSTzP7JuwKmn3ReTY3evIP/RwCu0ZYIClnNbfLISglvDVrQ5RFASPqPqMGn0PcDyzk1KnyEqBTHsiDHlOHhvf82YP8K/Acb3XRVjgOMmJ X-MS-Exchange-AntiSpam-MessageData: nrunSlYS+0DBmvdJYem0+KSnKuQI4h2CstbqgJ152OCnD1yg6gsZI5Icm8/sXlt1pjaAwEjlX5RXBjMoZXcVaI71Ldh+N6IMq10oIPgBcWh30hajeff2zJww5vdw9kZjtA+gQ89gRcWZuiY6TYZCfY9q/45eqVepaKiLkg5nefQmOHcYZ4moO0DWr3AAwWcLZp+zeAul4ZD9tZBwNndkjRhXQCaIJtL/rn6XXN1y8PzAKQTQYStQ6+G1zHvSwsL5PFwA5tpnZ6QH/r1eKkVvoTu1cOB+Zd+I0M2sYXuhXYXBjeOwfRJGoj5uHI8JUOv/qp2FYS7MMYWpsLnAMreVhr+8ODCkxGlgR5k+DgMpmgMrHmFLL5e1+6WYDS0EVg3LXtVFm8CS6w0ggb4qyfYYH+ufd52dFLBLN5gPEDgBgg+ehKUhrJbeNykoajexgAX45+maeu658I6T7r4pjy4ogmdKAC6sv3/c+Z+WaFnNLXw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fab99b7-f63d-44df-6f99-08d834c91fb7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:50.0400 (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: TBG12XBS/WHHLyvjQ65w0eAatLYLOjAXyy2EQo+jM2IO+ROvJTXBYFBdrwMnWVbyjfufztgmHsvf8h7qJ48Y8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0027 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: dSh1JJQe2jRnXc1ZpXSke5Jqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596141771; bh=hF+ChwkNE54kbVFAt9CHJTAYBu9E7Q3WHx+2OKApppw=; h=Content-Type:Date:From:Reply-To:Subject:To; b=a/tBuQfcChjQSjVYzDDkIraILlba+5mVKMss/WkyOkwjOkFAZVwXXQzH7zMqf9+osKC kjlrer5dwHt+QFnbseEFs0nuBVMBC/NN+9c/6EuDxCuMkROtzsXqh2LSFf2TZyOoe4gGU 1FNNa6+RkTOVUMykMchkGyt6xn+2UeOJ7Oc= 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 5504bb3d17cc..dc7ac7a5daf6 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -412,6 +412,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 (#63527): https://edk2.groups.io/g/devel/message/63527 Mute This Topic: https://groups.io/mt/75895011/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-