From nobody Sun May 5 18:51:34 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+63843+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+63843+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 1596829196272439.46336093043146; Fri, 7 Aug 2020 12:39:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fdk5YY1788612x7k0NZmvOZG; Fri, 07 Aug 2020 12:39:55 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.55]) by mx.groups.io with SMTP id smtpd.web12.4175.1596829195383266165 for ; Fri, 07 Aug 2020 12:39:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ey4xttb1HbSCVdKF1SG8m7pppfrbqQpMkYP6qqWw8VEXM/BjiGzm3ZZ+Vt/esrZd7vupiocIrOiDn8MCjJ6hUodul1zObN5O7ng7t+5lN2p3QGLSrHe6RsvzHRjauxTENPC55CxBiZwJnf1wZKOA3XzZBelPPEBhOLTUhRDQcsSgUhLiOdSpgF16puP6HLeVD65vnlZEl6yekWVsiSXtzyS3rMdeeY4z0POnQbNTWNaBxbvTHyyt66hj1wi5IoLgfFF/nmQkt736HnWpt8k3sC5jIJW+oTRh9FWjZeKP5H4GFlhIU99hiIFFnKXAhYx/L5CIvDBUp6zF9p9iC3Snbw== 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=gHi+Xp4siy9T/cX8B6vif+UAHONsYLKZ2ig742WdjzE=; b=JJpMW6ESSpH7erRwqMqtMB3mB4Qb3EG5Q3DdT+CBWez38n/dAhB9/rxhKHLJB8rcMavBGB2FVytrxoadFsiY+Y8MiFotgj4vMqO2/Rv3eEiaiODWynfEGQngt68vmarnRIUksCmWStnqytPch+jYBYesX7RTsx2KPYDbyhC/LBV0H0kL1/T6CUYRMvb+cP50T2Ljsqg8v2H7NtogWi/7B25r3hwLRFIIcJifaLRME8FYPYsk7DTudnR62Cj9naAoSsFAZ0fW6LBsJ3UeX4dqPVj3EyoxZT3l8nwuIC0eTyPa/i7Tr1RHflwFsheNGmNoxt1pCc4ua4a69+WUwsqDUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR1201MB2532.namprd12.prod.outlook.com (2603:10b6:903:d8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20; Fri, 7 Aug 2020 19:39:51 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:39:51 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu Subject: [edk2-devel] [PATCH v14 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES Date: Fri, 7 Aug 2020 14:38:46 -0500 Message-ID: <0af5022ceb7f7d203a135dc7735642f6377fec42.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0001.namprd08.prod.outlook.com (2603:10b6:805:66::14) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by 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.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:39: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: 2429790e-af00-425b-1a49-08d83b09a6d2 X-MS-TrafficTypeDiagnostic: CY4PR1201MB2532: 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: uOSZm6M4TKjLIuFIKT36aMF9cwKdqrQEVv7XifAczl3D3Rt9Ttxdxun0vW8iNLLxv3vVFMJWsHBaCPFy06qvVJRRuWCrG6r+65azlRN1JT0Zcckyw/vsHYMWU+JUZIQeEDKYt6j+BAtuXLWuWeiLnbnNne0PzX8i24Ae3z5Hdahd/a7HZfCRlwjcEoRn/K2sdOBRVSggS6D4W62GpaxH1K9lehfuzVpBzVoxZX6Hr4LPfBgN2MKyMKbD5YEd2WsXgt6pI9XLT3CI/FiEOTbu4ypK2sTW9FCQ1Ctz2ipAE4vGM7cyU6Tji2zY6OEAdW/yTc7pcEsh6Q6Q0iUcZ3C74XGUpPqdA6cRqq0jOKj1ylNVNSgMDspseh5AFk1DrkZVqiBHhCoimVGP0n9OeO8PQ6pwekpm37slJEwBxvXNEIZe1A/Qpn/MN94quN1xziRkurC96PrfIbFnmL+eY4XWhg== X-MS-Exchange-AntiSpam-MessageData: gBDLfHQvsfK4BR8pkG0ZSL9Xlb2Qr8caih2E/u/AQ9mWqwzcS8APUvniG+pgk8B0uQmsUpaILQRjuz226Ydo2xtV7dvWyVWOSkHRKGo3cyXnoSVeZlBmL1UlnikEZnWio9TQR+uoZ9K+oghomfVlhXAVhQYOuKFU2p0lLrLl9zTP2ODRpcD5Zk+7gUE/9NET9Z33anWYRIYNQ2O279bLrJ/zqR1zv80ndGBSkHsj823hJ1MfXIo4MU91lKo4mnPmNf2J72ohNC8IPNHHdoXRCSuNlvYPX8TvB6qzXYyLH1FJL90tNjh7HVr56L7MR2YprJLhgKaQYF2tULz+YkoHcUQHMiAQz8+AXAcbi0RI/RP/liXDENSMbVPcRMiKyYBfGFXlHwUuKs4Jlq1QjSS9pAobhYnuOGwm5wcRv6Fr5NgCliVwQg4lqJMqz8LHPsGIS2IWoxs9B+O98fSVMoDJhU3lsz0i2kIpHjHp/zxy8C13mxGEmEZKuXy48x6X4tCJRxjui8Vmtarn2Y7+T2bD/nl/5rBKLwxch7FO7/E5woPtxtEoOI6HUfol65oNjqKJCbQlt2McS5+8rKjkRIRJh1lluyq7ItOrjtfg1pwyt4LfNYY7VwN97dkZdKyANvWI3/VvkRJ+AUMq1SwDME58tw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2429790e-af00-425b-1a49-08d83b09a6d2 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:39:51.4165 (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: gSWJ9/mg8DPbNfJJN/qjeJhpMdMrr4rnCmuywRh+B2app1Koung2477lut7X6YuZT+LJ2G3PiOSUm1vu7WOu7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB2532 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: QsVhMBzRtqoR9hP8o0JUW3Yrx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829195; bh=8lsIj6lKF2cTF6DYgNn6eupV9CnUOOW0KYT8OWquYeU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VdyEBds2Y7Z07AIJnfeDfzszs7YFxr4i6wK6rYAEEAkDGei5PaabANb5ROqQwFiR4G8 abTFuA+NLM6QWhAty3CnRlKAprdLvaSfjGR1OkV9fIUU3QM49t+B4UQlhrr1p6q7X2qFo d6PyB3WAnCeN9+kjJ/mhXNhiu7YpdOP5Voo= 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 Reviewed-by: Hao A Wu Signed-off-by: Tom Lendacky --- MdeModulePkg/MdeModulePkg.dec | 9 +++++++++ MdeModulePkg/MdeModulePkg.uni | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index d7572eedd18c..cb30a7975849 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 Guest-Hypervisor Commu= nication Block (GHCB) pool allocation. + # @Prompt GHCB Pool Base Address + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0|UINT64|0x00030007 + + ## This dynamic PCD holds the total size of the Guest-Hypervisor Communi= cation Block (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..b8c867379a86 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 "Guest-Hypervisor Communication Block (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 "Guest-Hypervisor Communication Block (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 (#63843): https://edk2.groups.io/g/devel/message/63843 Mute This Topic: https://groups.io/mt/76056466/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 Sun May 5 18:51:34 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+63844+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+63844+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 1596829203043998.2686725882764; Fri, 7 Aug 2020 12:40:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9MqsYY1788612xqIxHEEFUlP; Fri, 07 Aug 2020 12:40:02 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.50]) by mx.groups.io with SMTP id smtpd.web10.4129.1596829202070011122 for ; Fri, 07 Aug 2020 12:40:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FG3mLKH0oQHX23FkPxO/Ihp9wFNc8oHFTfyS2INFmx9sCDHDZ/xixce5ye1dYlANsT7dYOyIPaD2peBPGRNn6BB4+1Yfi1Psi5Oaz5/Ygv7avkoCVnuYPUwBTvOoTjVbAzA8KteTumB2TOtc3QPtFwkrp4sGEH73TtxJrWHD1ZfEXNacPeekLDzlzMxIxUqQZgsvv5/pYZv3GeLw25O+ftF8wCqPz/aABSsKsK9xtSyCNIEcJZKgBbb0kqZNEzKMpsRCv3L32QAKcPbM0BD1epCzk6iJjiBV3W3s9xaf7t+eJ7QEvQGnPpsrbXL00zToNpzIS8oFaJyxXTypG8OUXw== 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=VK2DEqcPEZEwJxcTrSZ4FzPe70uLFZQ9ZpL7SlznWen5WYRAB8B4eVR4SXeD/YxWPSHn41uUKj6Ht0EqffDrI9aW7oIFkE4Xv8bogBAHmqovjWt5KkiEarLpfkWyBqKLpaDkngPUQu1qTYW4ijpibE1I314E981xO85dDd7pXSXLpXrN3ffOyrknv/5A/UPffRrSa57Ne8koCJBai/SoV9XFrnhUW9014q6C78ob5h71msaQzngjTpZC8vESrfslcFtQ6rLpIPeFrY+u7ggmpNcNO5FcLRGfxvLYLV2m+WXKFzSd2DJL9/P9cjLa2ukEP8y8WEdBYElaeHphMCdkJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR1201MB2532.namprd12.prod.outlook.com (2603:10b6:903:d8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.20; Fri, 7 Aug 2020 19:39:59 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:39:59 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES Date: Fri, 7 Aug 2020 14:38:47 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0066.namprd16.prod.outlook.com (2603:10b6:805:ca::43) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR16CA0066.namprd16.prod.outlook.com (2603:10b6:805:ca::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:39:58 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c3ed3e3d-814d-4b8f-d0e4-08d83b09ab8f X-MS-TrafficTypeDiagnostic: CY4PR1201MB2532: 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: C/DEw2MvDX1h1D94xMCQRJKlVtTRo5Is6r9c6bTpMQXi+fziykOhVu6cRtPhroH1+cjIxoRsSWsnqZ28TtoPwAV2RuHH2xCZX9fkgsTQlKYJTU3/njENBiSWR/BlcRr0bJxcIpodCk+cg/DLl+svYdtXKRHwDnhBqoULjZN4lamTSZ6wSjEC7+BUoI0sjCfeKukXZCxAQ7Ynv7EDdZvJB2GBwYz2Ixs75kl3LV5dRvCTkMsjCytPkGN5+uxpGRRSXiGuMjFoM4b2spRyJCLmATVbeLUsZ1PrgbrqjuYfVMWn3NVoND4xk2i2smRgLSyi7JcajBNlVwavsuagThz3pKo/VQ6fNmZcNZkQsAY0iT6v/vX8+Oz9B6bzT5Yjw4McGjUG+bgYS4klYKwcZQ/Ts++PMopF809l3IbxwX7pHVtKd8kgWzxhquyAbB8bgH+YUHFLf6u2dfpOv+mHfsUjhA== X-MS-Exchange-AntiSpam-MessageData: hr+3KwwSIcHhKJJEzVB9Sld5sv8f0b17ObosN+V47bVgmJsifjG+Z+7Y6Ty+wFRtd4jEb89eczIfBms0QcQHHpXAF9kiql0jl+SQUZWSPsUfQhDkW+UbN2/09/xxwnwEwzAC+8+6I7TvHBcFZl4cYcomGB72SHE9nMa0mv30vLkO6POvGqoUbi7Zg+fl7cObr1se3T18HhQa3ov66Er52FJBaZdOFdBD1Jz+NhJN09kjRf92hf/1pqfDM6FxxbkQmsy81UA199IVgaF7LCA7EILU4MxuqAIF7mFmO5OjARqVVoS51HWIu29b2+Sfi61ubxiwVxvGTsELbGg3H+/815FJbmQzbTn9u9uKPpIf43J+T+RTaJ1HqNxhlTikfVriPBFlreP6hzOAX4dQxzhtlRjJ+YwnT+I2iJQ+Q3RlL3EfKpojAFm/xXR/uBBo/sty8ujf3MWUDMR0bppAISoEo5Qv/bwANXH7ubVZfqt2cj3rXdYM8C5SNC6b0cMkdkMM9KY04icz0wBrzwVrt2yKqssYoDb0jvJIlf92sWtzeWcTyHC95XAh3OH2j2kwzKKKYlAAVuZo94OBi/2seWi9XwvW3294kwMqguT6GGDcew9SIqCCXzzQzu1hNDv6aaBpG1QQTsQtyYVNjdHxEkgiKQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3ed3e3d-814d-4b8f-d0e4-08d83b09ab8f X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:39:59.3887 (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: uMip3nsRzzHhIrG8e2KhVUEzGx3GpWgG+TdmLAl1vpL8gUojx2Ox/uMZIQ7EHUeavlHgkYmsuSGdbXutE68nTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB2532 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: x1OME8SF4zRGP0ixKaLVWhd0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829202; bh=ZASxpU4KVYA79XIoVUlp2MKGpslscq8EDpNTxFKs+Vw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=QYFF0WagCyN+vyENG7HHpD4MrevL9D/cIm8TSdGP4dbO3Ahq3gZZkytqfKTJldSngtV ipuuSEtojOWU9YqbKtHZPv0oW8JnWa8+m7+gvb2gEVdcX9lY2ZvkZkon5/4oi5bkFwKjp qmDnjcFTaiwwmZbMB2ilT3nZaZWxoaxE9Qo= 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 (#63844): https://edk2.groups.io/g/devel/message/63844 Mute This Topic: https://groups.io/mt/76056468/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 Sun May 5 18:51:34 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+63845+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+63845+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 1596829209387526.7236918119721; Fri, 7 Aug 2020 12:40:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IN6YYY1788612xoDINqsR8k4; Fri, 07 Aug 2020 12:40:09 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.76]) by mx.groups.io with SMTP id smtpd.web11.4200.1596829208536705463 for ; Fri, 07 Aug 2020 12:40:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JPUriJ05ZBIALw8SOBHTHi6hKw2fQL1E9kbqCbDvIx3Hy+ZBHKf+jeJM/0stNkNqdndGO5WEhpeTQ5mhf3DHnODyR/7mwMVxvR014UFB/4W2U+CGiEfxiJh2tKG/BmTH+O6KxLzeyKfLs9IACPd7d0LclE6z3P4j7Ua5bvtIHGFBFOzDz/mW1zYyiddJULhmnKRdDV35hKKd0o16war9k7UokazQsnGQSOnJ2qWsPQEMeKEUM+I1JpCzhsBWxB+RN4lRO5xGYUs0bOy6CfKwc/q9fHBZPzZYS6KGRRmBxO7JjXB9vUdxqin9CvfVlTLTko2ct1Kwuh8x6BhR9kgs2A== 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=FY8MUPDm0EsCsVZPdf3r1b9AQi+L+TZ2V46E6lQP+OmvU/sCUCCxt7bVVKF/xFpUsiVb69BfXm5sIUeVN6KIvLZ65ua+dQL4IMDP3lXV7U+/gMNTisOFkDo4NBFjUBamPrjAVr0z9CCAYxj9SASAP7q/xp8eD6Zpoew36M1P3SAPofljy1NQp9gNrxk4VCi3IKZWgFoK/5G/mJhp4slQFlGXLBuzDz2p2DmtMvfU0WddtmpESUXEizPJUesn9dac/A35ENNgYCR5DWvEyR43RAUMw7UYaHh1uTyVxZf3U+improVGd060zZmYbuKCSNzPosL9cFqoSwCxkAGph4S4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:07 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40: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 v14 03/46] MdePkg: Add the MSR definition for the GHCB register Date: Fri, 7 Aug 2020 14:38:48 -0500 Message-ID: <372b26f6ac52fd65bf069b51982c76d87ce91831.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0021.namprd21.prod.outlook.com (2603:10b6:805:106::31) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR2101CA0021.namprd21.prod.outlook.com (2603:10b6:805:106::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.2 via Frontend Transport; Fri, 7 Aug 2020 19:40:06 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7d2f882b-e1c9-4a50-599b-08d83b09b024 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: 6ld/GK9FQ7a5yW24IjETd54TYlnU4Ky5FNJSwdbV0o6IrivdBhfNQ6qh24RxCdIGXsPxLebnMng3NxhY/EGgvT/9IaGp+BGeb9IWf6TUp4WN5BScOPsNSCW029IpLNs0uJIy7qvHetEZqNh67qmsXLpXWk5MtqwCF1zIYhL1H3WL96/0eMyqTKtDtIuisCvr4JIzRDzbgDXeOOLPSjlyR8WN0v1FIx2E3v9N92neHFMurFeMtatbFrgTMN0485FuP+JAMMT8Eju7tnHsiQLO3lRnoRAMwhbNU1z6UB7+y1a85UwmqLytu2qSF0WG4B1UfPOeGerUnnH1tZGyfJTOoHQq/yGp067m17Fih8PuEjFbFLtUyq7osuSOUdthWjGZu1bYqpv0Bo5CWc3axr90t6gIS8mfwUD0Aqb7T5c8g0KvwkZK5tHRz0dOobEb9caALqwEQnBcs6ALNEwvDNKw1w== X-MS-Exchange-AntiSpam-MessageData: z/rh5t2B5OV9AJ4/NUY7ZKcurMlecz79tCLj5IKudC6tKOCH9Bqck0h3MOkIsT40yepOJKsjU72i66kTeENxolj9+72yr7iOCRkZdywj4s0d3lZf9CD3YWoJU7g9Sgf/i/Y+a+FsQtXW7hRzCebgINV6m9Q8nrvnW4UaffZ8qpsxXL50H8G3Yn6QJEqLi34kiN0rD4qc9DPaJIgC/sv65FmIxvH+mUK3JKuNs8984KwGzRbDnIg4awg6ia0ZltOgh3s0epFaFqIwAh7DcyJ6DLtq1goYQXV/6ueKJBluYRgxrPhR9xIpKRoe1LSYiIkZK3B/M35rQAjwcFiaYQL8WepkN47x9lbe1u3GsXaIAa9HpZHrB/nkWPC+HL6h/N98vEEEznlufb9peI4b3eY24J0Urb8FV/XRGfb0EGNyyXDQ2tiFcqSY380jEYJ+sN8bVltiuNWk4kATI1RJRInz62V6BCJk+A6ivfSzLcoREZx2HXUolhURczbYHzFJyqnWwMAgsgbwZCMvRyGi5zGn8ZSPy1tjo7MEKyV3TffBqg58IfYpmbBwDLmG4P/DG5cE7fdqL9CRxjYiNqpT/CFEbPNxJdw8dp57MhkQD8MBIE7UOl4iYXzhO0LKy/oSsPkVpwe2HyLXN0K+5riQhLsySw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d2f882b-e1c9-4a50-599b-08d83b09b024 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:07.0800 (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: HyS/RQf1+aw4V8MW3AypLMnOUoRX4YrTbz6vqGQAqIqAdVRWc8mopnd2SS3eBDeOEtciTppCjwXqmzG2e0iu4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: O0UqbqX15Q9TSJUly1MgIQiHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829209; bh=jjCrzVUel/dSRekpjcafdGmNU8RvsX0rxnREVonjzb0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jA24ZCUHtadXVXYgHeO8m1FRoZwx1d3juTRBnfzH+lW7oh+De9/p8ddyQmJlh5aIj1o 1UYeyYquxQ93GoekLseCUuDu1Fe8eTMErGwgFfnIZrIRJTQ2Axpurpn8cr88VvyhMevUt XVhaq+Zt2xYvWCuzTAhhBjFw+vFes2qIFZ4= 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 (#63845): https://edk2.groups.io/g/devel/message/63845 Mute This Topic: https://groups.io/mt/76056471/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 Sun May 5 18:51:34 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+63846+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+63846+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 1596829217580757.7855657771772; Fri, 7 Aug 2020 12:40:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id a7B5YY1788612xmkBtvO7gF6; Fri, 07 Aug 2020 12:40:17 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.72]) by mx.groups.io with SMTP id smtpd.web11.4201.1596829216664183947 for ; Fri, 07 Aug 2020 12:40:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GuQDytbLwFwJcHth3wuvrkHglfGy4yJxtpG/iXAjldTkB60u93a3Eh7YPzPipeh5ZmApEac4TS5twf581N0uxQDl5LrSvuRZ46yB8MCwYzGmMymAQOblzAe8gWFTfcYJYaHDYMaoP/lLRCTxCMNPWwvFHdpxUhvbVHdCSu4jBkBFSroDF1SJSVtNrshmLHWy8cEkfjUNFStUhr1m/5403gDFju3y+IWvLJLLxxHYr4iGObUmdFHfZr8bKQCQLb9SXoj4dQ+ImxStH7nGaMaljA/7iNGjqj3rA9oSe3JSw2EQaClk6K/u2+ise0UATHsK0OYxMyYzgmsiATT8NjhUww== 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=IK1T4VIz/+nGftHbRKMRyYoL2Or8ONgL6MTtBzjmUpTNZfKXik0bL9/CMO2HVb2MeA571AEYlCVrnw70bxQJbjyAod6FCsFv6mLkAy9Wh5DVIZ6V15Uw0kPA+bVLD5zxx9nKP/OAVOSClKZhR+E35NjMa4EYEAiItMq3wboTpN4emfsYaEXKyque3idL/gEjM/4xHmjBoo7/Xmj7FKfPzSkJYPpGhlY7YwW5oFQqhN/C8bGKisC7VyeQ6KxHBTAaD0ctG8G3OMlwlrQwE9STA7UOYU4TOX1hykwe8RXjBANZXRbBx61o5a3i43GPzmPPGr2iaIky73PvWyRayRXoMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:15 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40: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 v14 04/46] MdePkg: Add a structure definition for the GHCB Date: Fri, 7 Aug 2020 14:38:49 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0067.namprd02.prod.outlook.com (2603:10b6:803:20::29) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0067.namprd02.prod.outlook.com (2603:10b6:803:20::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:40: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: e3a19cb0-7a31-4fdf-bcc0-08d83b09b4f5 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: MSyTf65YVVu5OKaRjsEFSLB4IZ3/ESuPn/DdWfzeKLhM6nfxZB3oL6kWYBJQR9r1TH2ZNJOWOiFE5AIBtOCfPS1bLyAe6pWTqZJQWNz6Gl+wj2DXoaFlroZ1tyxrpAFcinvSNWiTXG13PSkdIRFg3xXLdywz3Zjl1BJoF1xZ9U9CUOJmrBpKoDrwDV5aaDB4vxieLUi06NZyQUJSFLiQHRzFmHSqpAGxnICVayCSQ3pk5obnqg8b8t2sqJGXAYmdu7IsNrVmaLOhhEFbyjyRrRggqGN4JXPwjB2qlRla7U8um1ui+brhXqYqrihFXcM6Gj834dgomQSKnSNpsE6tm5Yxoda4lGF/LgwAd3+vAGe4JBamez8DuTaawNqMfbKGhzzqhYRkTnNrqwlmvs9kyLGxn1mubhJAMbbpZQS2FD7YsTEjwktO4xMiFw7OwosaxpLbN3ZdlHN2hdtKV8Caaw== X-MS-Exchange-AntiSpam-MessageData: juW+f21rLI6x7QJTpRyeVj0wIllp6gAd+5LaVtmUnhMnIOK3uSyfSCZHBYrpvf7FkoNGnxNLWuLAB2ALcEeFYfOebOtE0JLhoZuF9bEcibsM3xiPkBnygFNbBtqhsMfqYkZ0947eXpaShy6QFtbYbV2OnuVLGyO5+ysIfw9KXYnjaQ7+LobITFqp2UswCAw3npY5D1GfqnEJpDF4oLIQ4uwAKIYi6JRx2Yn/8FWlhlU7pMiZyOvDzxHGIj1cSN3pzX5kqNg7nV+5ExhakI9nUIsP0dkzd8LMf4bfND7R/SLa1FI9WVlXLVwRJHfP8emnc6Y7tk8McMQu1rj76giONaAs2gBZBda53TDCHB1iaB+f1aS/ICR/wwYNUgwkVScAZXwibyRGYESrcXOcCCzdGrxTMaRAf1ZPHNsIthzsX2gBwMCQ34KGN27aFJqtWYsilvqxfzgTE7VaLNnynI8CcFpZwbIZX0YiGa+8UCzi0Edtmfe11h6rYTKxwEHoSANceiH+n5WAL47FGO9CZxq9z7OUY0pvmnRwtadpnZbINp/2AlnP04VPT0spoYDv5YdMuGFfUSYwG4jMwUzBsjEzV8xQpDn6nSt1i07UcTJ3F+twtaDTLJz4pp178YS7hKRWMxGIXqqQz/WvfFs1xIelYw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3a19cb0-7a31-4fdf-bcc0-08d83b09b4f5 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:15.1222 (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: HxoDi7g/glLwiih64fuZIQsZmY4S05w+yQEqRB5q7eKxEDfISl4CPp8AR4cH8f8SJTR+S8fSW8J9Qe1PLuTBvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: VFHYCaf5D6P6bcBgDVA7Uwwgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829217; bh=exck8PRq3zsjy+7lvZv450dHHOg83B3DYFgKydwIxcE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=dbcngx6CNcdbDg6RuMmeH0ZBRJLNRBJTJ9KE59fWzZyXfdHxwGJ5pQY9nmblhGdRPS+ iRmL/YrdxxhpwMjpVATzfVqCfEQU96zbDRoz/ukETcF+68HHcZl5wGbA+6zHJe1LiFZnj +dmIs8pQ9vOr1PKT+ht/vDZg+yRYAc49G6I= 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 (#63846): https://edk2.groups.io/g/devel/message/63846 Mute This Topic: https://groups.io/mt/76056473/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 Sun May 5 18:51:34 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+63847+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+63847+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 1596829225863739.3985413560808; Fri, 7 Aug 2020 12:40:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SEIbYY1788612x77mbiOYQQL; Fri, 07 Aug 2020 12:40:25 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.68]) by mx.groups.io with SMTP id smtpd.web12.4188.1596829224956570372 for ; Fri, 07 Aug 2020 12:40:25 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fjbofIw2WRg5tdpnlm2lfQ9ks6ytafO2K/5Nj7R3F2BmhpTGVoPMZ4+W1CJwsabjG0kLoMSXnki00TTWc1ezgcNuxWe8nu7o2h/UATg0FlTeGzR0nZIMkgx3QzBMS9Znq5fcUFtqaa/A9mhe56axT4ZAwk8zf90h2I7UL2mEdatZKjJ0XJqg9BNkc8D9Q99Co8DLD4YfAN6KEd2AdOdQbUWzv2VCgdEKMpD497jokkiYp5thwTMruZG7/huxZwLSyhVLPZ3NaPPJM6wWkU7FF9J67WYOvxZfib4MvnXA9lcBBxHNGJpVLRnFjgMcy5RGwZful4Sev6075Lw1v8B+XQ== 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=q/E956LSldIet99vGpN1Qo1qbvlPuwT1yjmn+70xruo=; b=PmDPHQ05jL5YGc7Wtz+bkJuPKEmSx8az5UW1q3yYduH0OXGFj7HHZMstq7WW/wCryfD/l+bj2th0ILEQZaQpnS6OjQbShH29YC+Qe0q09TBfzghcq+Knc3wC3pLqeHmLXYk+VrxIENL8P4CI9t8YNwu8kd+sEHHnf0mXy2I3rVHhwBLM61E4LMI0pWgie61tRyOfj/guIuykjmU3lq66rOtrAEdxsvROZgC3KDxuHXGf+f6nZWvLfXbu9mpIJvP/P5YEm9fPOoRDha1a5IffHAjrv6GQN2FoSCS0hxKw7SjtJOPWaQ5jlaQEGM4mQ6H1la3Lhw+kr8THCX2JUugOsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:23 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40: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 , Dandan Bi Subject: [edk2-devel] [PATCH v14 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Date: Fri, 7 Aug 2020 14:38:50 -0500 Message-ID: <1c2fc21ba0b65674aad29a89304d0d16981102b3.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0036.namprd07.prod.outlook.com (2603:10b6:803:2d::30) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0701CA0036.namprd07.prod.outlook.com (2603:10b6:803:2d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16 via Frontend Transport; Fri, 7 Aug 2020 19:40:22 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9a04f538-5ff6-4a6a-8822-08d83b09b9c4 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: +6ihKoZZI8eKl2CJepUFVHQcNq46T+BGxnxQRQ2uT4cU7u6U0WlipMwuI2TpUDzcFmV617kJm+RViGwebdFv1Ww6AB1aelH4eO7sxMcGNWp/NNrIi8dKVHILEk+tqAGG+Zn1z65fRETIYR7Fg1Xt+2fM/zRqKAfIdrHX2aGVdLmBRT6/GM4blKWIVsqH0OVGHFKOFgQyS9bLGZiLCzaN9PjP0258WOcm80wgun6Ttlzn6R5XzY8+lJ2WaVgv88/CIPObH44HISgIiMXn1y4th/lKIEztesnyXFiZsSUsYJMyMu+UwUKZ//F2d/QINJEa5WMQ46D7GDOPaJ7MZIEPbS8VDnsNEiVO9CfngWLaPbjyljaXg4ljmxyvy3wo9kx8oiAu3OtuwmRAWzfFJG2H1aLyNZpP1Y/7Qm/RobL02mvsMY3M61OZjrHVLCEbjQybV0irl2EzAbkMAn8eISyQ+w== X-MS-Exchange-AntiSpam-MessageData: Gyxbgx8zWgdhQSCgNJFrFuewOxNPDCDrjA8KKV6LU/428Ml7bbHr6GBXx6ovc5qTruk2SSpufKftFQQkK4lUpStpY7l5DY/qGXspZ1wSYoLgnrn05bHGqeuUMM9Qg9JvVppMaMPtrFBHhtuTtBsS8vy4Hbi11hT0rSeTdONl7nWMMbX713PaMX5/pZ0So3MNioMIN5KQkLx/2q/faoEW45733gUHufpSmQWgf7MokOGctziJB4lqNTY/TfdiXXKB7kgcRMSg390M+/S/vR5TL4RLbjLdUui2QsYQ/skIUQItcWeunzrvTeV9lBEb8C/jP3494rZWd9ERUqF/kEBgrBxUQUf34rU0nS8KbjHIoI3BTDRSM4w7fEvXmPF75kRm+JjYCZxbpQGX3RNrMBidQSBg2n17mN/t1zvb1eH5zEp/JC+wjzHT5nTxUFQSzEiFnaiy4e5Yl1tbhKrqXgPUw+znj5oIo6c1684+joiemrVN42rfB8mXtMplF1MRQkl+fmSDMHCkSgpYztZrM2FLCJ0IBoSZK5YQOrIfHeTmW41O/3Cq6KYp6xFDIQW6kwrvaMb9wh6Yws9WlbogxjDWOD3tN0r2ZPxUktTFaCOPOTDFaNrQCG6Akcj8sLjaG2HsqpkUzDEJPv91VeQZnbr3pw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a04f538-5ff6-4a6a-8822-08d83b09b9c4 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:23.2603 (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: Pu1p0zhyll9Y9bAZKEpvTcDm2ssefTr68y7ojMV/u9an7Ma3+mcccvAhermIOTA4F+f11h1D6lPdD2077Tdyfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: vB6mFLdLKZYBXoiczoOPjjwwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829225; bh=4Ae9goI8KEPQua3HMmL5zrQfOpZUG7INAp5nZhs3QCg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=fX19DPn5c01619yfqFpcMBjJbfvVubkKddmxzQNEG6jWDHRdrGZElxxEapgXSw4a9Ly K/tAOjfO/bCuvQGBR6Xx2TR+WLoVRlKlvO+MbluyfBV6+7y1vwsRarUiGxZTENjKEM2Fl B5+f9SdH11Hz3UPg8NAF3MIIWF1YxPOMeuI= 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 Acked-by: Hao A Wu Signed-off-by: Tom Lendacky --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 2 + .../Core/DxeIplPeim/X64/VirtualMemory.h | 12 +++- .../Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 4 +- .../Core/DxeIplPeim/X64/DxeLoadFunc.c | 11 +++- .../Core/DxeIplPeim/X64/VirtualMemory.c | 57 +++++++++++++++---- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 3f1702854660..19b8a4c8aefa 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -115,6 +115,8 @@ [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable ##= SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.h index 2d0493f109e8..6b7c38a441d6 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h @@ -201,6 +201,8 @@ EnableExecuteDisableBit ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -208,7 +210,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ); =20 /** @@ -217,6 +221,8 @@ Split2MPageTo4K ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 @return The address of 4 level page map. =20 @@ -224,7 +230,9 @@ Split2MPageTo4K ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbkSize ); =20 =20 diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg= /Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 6e8ca824d469..284b34818ca7 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -123,7 +123,7 @@ Create4GPageTablesIa32Pae ( // // Need to split this 2M page that covers stack range. // - Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, 0, 0); } else { // // Fill in the Page Directory entries @@ -282,7 +282,7 @@ HandOffToDxeCore ( // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E); + PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E, 0, 0); =20 // // End of PEI phase signal diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/X64/DxeLoadFunc.c index f465eb1d8ac4..156a477d8467 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -35,6 +35,8 @@ HandOffToDxeCore ( UINT32 Index; EFI_VECTOR_HANDOFF_INFO *VectorInfo; EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; + VOID *GhcbBase; + UINTN GhcbSize; =20 // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. @@ -81,12 +83,19 @@ HandOffToDxeCore ( TopOfStack =3D (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_= SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); =20 + // + // Get the address and size of the GHCB pages + // + GhcbBase =3D (VOID *) PcdGet64 (PcdGhcbBase); + GhcbSize =3D PcdGet64 (PcdGhcbSize); + PageTables =3D 0; if (FeaturePcdGet (PcdDxeIplBuildPageTables)) { // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE); + PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE, + (EFI_PHYSICAL_ADDRESS) (= UINTN) GhcbBase, GhcbSize); } else { // // Set NX for stack feature also require PcdDxeIplBuildPageTables be T= RUE diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.c index 516cf908bc88..6831946c54d3 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -181,6 +181,8 @@ EnableExecuteDisableBit ( @param Size Size of the given physical memory. @param StackBase Base address of stack. @param StackSize Size of stack. + @param GhcbBase Base address of GHCB pages. + @param GhcbSize Size of GHCB area. =20 @retval TRUE Page table should be split. @retval FALSE Page table should not be split. @@ -190,7 +192,9 @@ ToSplitPageTable ( IN EFI_PHYSICAL_ADDRESS Address, IN UINTN Size, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { if (IsNullDetectionEnabled () && Address =3D=3D 0) { @@ -209,6 +213,12 @@ ToSplitPageTable ( } } =20 + if (GhcbBase !=3D 0) { + if ((Address < GhcbBase + GhcbSize) && ((Address + Size) > GhcbBase)) { + return TRUE; + } + } + return FALSE; } /** @@ -322,6 +332,8 @@ AllocatePageTableMemory ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -329,7 +341,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress4K; @@ -355,7 +369,20 @@ Split2MPageTo4K ( // // Fill in the Page Table entries // - PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K | AddressEncMask; + PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K; + + // + // The GHCB range consists of two pages per CPU, the GHCB and a + // per-CPU variable page. The GHCB page needs to be mapped as an + // unencrypted page while the per-CPU variable page needs to be + // mapped encrypted. These pages alternate in assignment. + // + if ((GhcbBase =3D=3D 0) + || (PhysicalAddress4K < GhcbBase) + || (PhysicalAddress4K >=3D GhcbBase + GhcbSize) + || (((PhysicalAddress4K - GhcbBase) & SIZE_4KB) !=3D 0)) { + PageTableEntry->Uint64 |=3D AddressEncMask; + } PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && PhysicalAddress4K =3D=3D 0) || @@ -383,6 +410,8 @@ Split2MPageTo4K ( @param[in, out] PageEntry1G Pointer to 1G page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -390,7 +419,9 @@ Split1GPageTo2M ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry1G, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress2M; @@ -413,11 +444,11 @@ Split1GPageTo2M ( =20 PhysicalAddress2M =3D PhysicalAddress; for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntries < 51= 2; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += =3D SIZE_2MB) { - if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e)) { + if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack range. // - Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -616,6 +647,8 @@ EnablePageTableProtection ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB base address. + @param[in] GhcbSize GHCB size. =20 @return The address of 4 level page map. =20 @@ -623,7 +656,9 @@ EnablePageTableProtection ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { UINT32 RegEax; @@ -809,8 +844,8 @@ CreateIdentityMappingPageTables ( PageDirectory1GEntry =3D (VOID *) PageDirectoryPointerEntry; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntrie= s < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress= +=3D SIZE_1GB) { - if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e)) { - Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize); + if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { + Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -840,11 +875,11 @@ CreateIdentityMappingPageTables ( PageDirectoryPointerEntry->Bits.Present =3D 1; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntr= ies < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress= +=3D SIZE_2MB) { - if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize)) { + if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack rang= e. // - Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize); + Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63847): https://edk2.groups.io/g/devel/message/63847 Mute This Topic: https://groups.io/mt/76056479/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 Sun May 5 18:51:34 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+63848+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+63848+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 159682923335241.49554879102686; Fri, 7 Aug 2020 12:40:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SbV4YY1788612xwIuVDPpQId; Fri, 07 Aug 2020 12:40:33 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.55]) by mx.groups.io with SMTP id smtpd.web12.4192.1596829232476844191 for ; Fri, 07 Aug 2020 12:40:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Et4qu34fDr4g/tFtidKoD2eqwQ9MfenMWPmJQkRa600wRTytGBNq/UF4h+pLok17Kegfb+sKgQO8HaYa55/hJ6kVcC8GoJAhh45JKa/8PjM2tsxwpRpQCXw9Ue8V5E+vgFUujhTblYNYFJdYBbJ5rkplQpKDia6jkMZNHNYftaxrEhDoaE1Qz1SNsU4FuRf16X6Sj1uVfYA2564T2OTQfg3pg1qDG+kOIcTNOpCrEPtiRdllroNhGnVQeXrj+BuIo9RG6HNWEcfygxcDM9yo+YWAm/QKoVtwHbcGJeVE6xxcRX/GUa+b/cA3S2/l4hFEdkOC4c7ev8T/JLpSW7ST7A== 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=3ozCs/ZVggMJEwwyBP/NbeOfp3jjnVRv7aWB6hRKksA=; b=GG1brXFulI7CZOfYuWVGUIkNR61h25zf1c+VWAeLit29d+qPf3j10cKg9nq/htctT5jHAhcdklQpkwLrNKhLF9OrzEAT6y9D97qVY8BI3ELL6HBpNffyh5I9ZI5LeXIZgCHQc1/jE6RfaK44a254Pf2okzFhS5BT3IDAcvYJXFscNIbYbLbEos59qK/2UIXfCfN3mkQI5j+TLvEye90SJBtb5WuQ0Pjz9jZUygN20CXZZmf0JQv9mbKANN8gex0rvD9Fe6khrAw/613usf24I67EgZ7CU2ShBKiwdEem18ZkHlnOdTsoM6BYyMoCCwpAAa1sB+p9HLXyiQcrXLKcrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:31 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40: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 v14 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Fri, 7 Aug 2020 14:38:51 -0500 Message-ID: <2c48f43ea66ee1b2392f7eeb68fde664af412cf0.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA0PR11CA0037.namprd11.prod.outlook.com (2603:10b6:806:d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:40:30 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 600e23cb-2b5b-41c9-4be4-08d83b09be7c X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: AySVcJ3TmDU6F2K7e7E1x9L5TNrF8xToelWs3tVDxRfyd38u4HG1n708LQyk4AwDprhlkAciDLZZKq0Ve4IZDHvZKlQZVuXOfzSBLyjccr//XRuO5HfqiS4Hh+rzWoRLQZqxlL9ga7biI8kGNaQilfqiHZm6X4NX7s6SzdcwSKLothqYNgj990mb230bk4ohSCX00znyduiJWLlalp3ZsjuA9aIEALSi/f2SSrnqHUgwXK/Ivj+3TUP+x0cks97JZ7rpC44ze42SgzHRNNOZOBOFPPdxVetq8HlxFyxScAydJX2EK89xRJFOY+OOJc2+dnGQMyTwaUX785vI+9FpW1MykVhkhxBwwuO0KUJZdEehwNv64qmxwQhIDnigFr+EIuRnjOiNUDXSWsGOk6g9rgGakXOLBZ9OLijILyQTaleIHlBa4UlAjhp8ylQ5CaUOGrAN4bvorKWyTbrNRKRjRA== X-MS-Exchange-AntiSpam-MessageData: YDAPLc1NQK22vXqScFpbzexe4/9Lv4eFujoHuIfcagcq+Wr/npgvmuWO5by8Do/0w0pbYuZrkiZ7b/8jyOj7NfpYJL87sI5jPvWh0SNhNIZ9zgpTRozhNPAyGGLV8bXvs3eNHXIgywzFa8mofwwUbe14T5ftD92pMnwoXl3yjuvQSbVZlFmC96vTcgaf/exWuToof1FuOJfe1cagO4sB3d581bZx61aWd0JYPwIMyQPvQUlaksk/AFnqJ7zoc6vCJRDcANRsABq+kumFRYXxLmz6rreB4HbPeRe9qW30+c2691QoHtlz6vd5MmTINFjme1mhnjGfPHtsdgsV6bk4/e8zpjeofg+qG7D3wQrYnXDh4GEmLEx44WrVXOfyTPTbS2h4UA4Kw/OSRcp9lxWjznQLtmdDyXqu9fupUTC/yhX7XTaVHG07NWdU40X6V55UrrWEHqXcvhQASoy0mWOeyqC23pX8Ue0kQzPULQ/90t1Nmh8T+BryKLIDluWxsJaCYrTGbBU74gLtvv7ihohxaSP7sAOPnWt9cFhQpnzL/dXfeNf0ofAjMWNhOXaft2NuF7HbfHNXkQrU5i1SZUOU03jCQ3PR+EZKQ18pnDcpAjE2KzWUz1t60COEJNUVSWfZ8izcX6yV6O+LxCiUeWDkEg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 600e23cb-2b5b-41c9-4be4-08d83b09be7c X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:31.1115 (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: 8s3wIXRShCamaTxsXyWr7P+hIswUG61CflWaK/Yy8yREg4cTSb1r4DpVAnRoP3Usc9c6Jw+WsXsPAbkdNbqnOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: anvf39KGsIWERXSgsZZHBjirx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829233; bh=kE4HkMs0oIX/bJUNbN7DKw3IePvPGge+Px0Q7dv9Nyw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=iQUkhZrFrEfG+h9QtEzqc172/1mNO5o081BkfB447qCzMb9phvJ4XbVMg2/V+3fqGI9 JfLmNgdyt31/lXH2m+Ch2mPFKMKtwPGDk0N9CIqznVQoyYTt/dF56lZV9eGWeH6HVY/Q2 dLyJ0GqCgwhAnSK2EhgFpdLdtGX9AJ2aEEc= 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 Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- 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 (#63848): https://edk2.groups.io/g/devel/message/63848 Mute This Topic: https://groups.io/mt/76056480/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 Sun May 5 18:51:34 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+63849+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+63849+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 1596829242092647.7537994699046; Fri, 7 Aug 2020 12:40:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 32NgYY1788612xNMazo56U0M; Fri, 07 Aug 2020 12:40:41 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.56]) by mx.groups.io with SMTP id smtpd.web10.4142.1596829241078753668 for ; Fri, 07 Aug 2020 12:40:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IjrXPb3S///9qnF4Yw7kCLvdeUiIbCY+L1PI+PCtj254a1g6dcq+PcxJil23wY7GUJQqiIjMPHqkmjTJIx8aO82XHoe4JbKh/bs4B2posYBfTmlZm3rCReKznHCkLAHsrMI6HKRCacwHzyzdT3+W9nZ4e2BT1cPb+vFPhJhPeB6s4AtC+gOmXVMcxdpiaET4h4mtGxJZPqKxZWTB8mgaK+bU+2FoUFam0d7wbYkGlbDa6J5yf62FqbbZmCiZfjcGchptJkLqOo4P9Rz+mcNpHXoPygVQWORQKaUbb8q840rz7651xR9HXMLndUwiVD8/bKBHsyTapJus2eMFJ55K2Q== 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=SG0/xz40UTc2ofcPShd0s/8+tONPPX8uNVFh9cVFY24=; b=Gy24eUtcufUN2ONTa9pbv6oovUjPTMaOiAI4yXrM4QWzyCG9zLyIBxgAUepX7NL4lbKuEbQNzEL42nEg4th1740Dk4l+YHQzW157R7H7FENrwXhijbfKWe6R6Jr5Bxl3SJ44POTY4mtKo3s0FF3o9whMD4/wkcIdUJ4Eg9Vfx9TGmKR8gomx2lMdWhtjskvknA6VV9KLHS4TTlJ5DrYBJeRBqh9uFz74wJxWLouVSB1rqzQLLrp+XEsnvjl5DciHnZTVI6MO4cjbCMi0kouphCsRrN8wB3xoSkpzXE6niJNldqCRL4sveEuEAiFGEjyaE75dA9/4iPnoQUEqkFP3Qg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:39 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40: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 v14 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Fri, 7 Aug 2020 14:38:52 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 19:40: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: 12549db4-b395-46b0-ac77-08d83b09c383 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: hCSqE3OYOXYq+kx/YVCMqnld0PlAYhL5Wc0rH97vAzxJx2BACnr2wX5WGjFLO9ScJj7MHfCuaLAyunglK8E1CyN1DOVU1hJTLqW3paMgxdsHeWBs+HtXUXbUvSwQrNaMiEC1tUSZbV0C7vwboYtRcSAnJpT1unUlDFQt+ecdCzEG2YsjnoELdDSe+8BBjgkxexiM5G0ZMbj4tLzAT/Ud1BAEgh1YArWDPwETglKnUTbwfW6ZM46Ii69LP74H2HRCn7d7LdhdXGx3wbdlUfOdwaMyCP8G98QXU//lS5nvu3X8lxd4aSQFKeqDQP7no0dnMBG+9BDmpXSDSlUm4+AbXZqRlc1rfe62XMk5tCZFFlyvhH7I3lXMg8h0dbFnFzDwJxpnnhB8ydMILwyjaMjvU+QjVn3xziR628wcO3mkAiP7GU0vq0rdnAjEQHdJlxby0pRfkmA84kC9dddLPAQLGg== X-MS-Exchange-AntiSpam-MessageData: /CupCScTChccsNeARCgz5zCjlN1VuIyNbOOvj8CZZWSWa5Z19IbC7n3GeLrGYoakTfg8EvX00j7/h9RFGXNRZhLM7oV8ZquWlSXG3358hWAOI0DL1sK4s3p9WAC503qdPdbXAqqcEmaAzBrVmCMKSZpxi2UXzvkSdYzQsTP8jW6gsxjR4UC1hGJdXGqw73j9SXC2/pyL57+IXKoPv1RUNTw8EtbqplJgLo40Maq/m/bcW2myz7jBKstkY2YPfBOrXIkpElehCi/9F6r/sCGU9IqNG2cat1hOzKfU5s+t07kadX+QhB/rnq2qpUlCSAgVd1EFlLCzyb22nhfBNOBDYnQV1bIj4k8vcuYDZkDQ+a/NONEbppAb7WCEjAXZNmXcvvn3ttwD/VfbSH50O8n+uhm7s9RXvZCXigfhRBPHuZvYBnJfhOJb4IM67JjOCYCSRwzHQM0pQ+nb3gMiz2ZbVLfS+5OIV15590nq2EZNwTz3rWTWU+xtTnV7Y8ezM46qenjVMfgS6Cr+Ad4bYXqZ6QL07AdsYrTRS3sRWy1Nq1gXW3cswqee2VOUhprqMuVlVd/i2ZxhY+mHGHcz3Y8gjqjgtlJkJ4kKFMN2LB27d11VtFK/zXvyT6DRAXTeKFdnm/+s5s9F1xhxv/5tCsquEA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12549db4-b395-46b0-ac77-08d83b09c383 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:39.5625 (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: oCe0P86usF0JGRnIG208GrcVy0t3d3g3qqty9sEzOku0etUZstrgMJrqfRrzwtRfYneD+/s4tJG+imXSv+iD7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: UxEvXEqGu3prUNP0VuquiqOWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829241; bh=WmBe8OAq1Mq/GPk+EEK0YMg+Yr6p5q5yEWjYF8TuMtI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MWQHwIqPFratgNNQ12MUBJ+5mLcoR/6veT8FHe5/VO8uomEhMZbVO1A18DEPsl3UtHq Ji9ciwRbBKGT+CBPKLDtHKhM7negEd/lnnhHBVj82QQI1dmhBqSaU9s94w3kPJvJm8hhO gW6G0DcmTWV/wLR68Np7bVuiDbVYNr+6pbc= 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 Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- 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 (#63849): https://edk2.groups.io/g/devel/message/63849 Mute This Topic: https://groups.io/mt/76056483/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 Sun May 5 18:51:34 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+63850+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+63850+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 159682925097570.33403099873192; Fri, 7 Aug 2020 12:40:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id o6bdYY1788612xTKpVsv1pdq; Fri, 07 Aug 2020 12:40:50 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.88]) by mx.groups.io with SMTP id smtpd.web10.4147.1596829249965973287 for ; Fri, 07 Aug 2020 12:40:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BdCinHtAhP7ochtVs31XtrSV5DuT4vwve3NO9iTnFWboQoSa99I4f94s0dxEDD60OnShaIaaygL+1NBPxG75k474GNfYiDxQKJ6BHAxKEL8tY0scG+0a/XqOClA8wEZZPkPsixfT0BmjJgSjM/SpUDUZbd9TxlLhW952WBFdROGwDBA9GU7Dsejh6eEbTs/WmaT7ce0vr11Ct7+TIPcWAGkQNZJESx4k0lox8Jwjzg/AhEaEY8IlY28EDqwN1FU2TVKYNJjURUtjl98+MaTK+GKLtw2VC9S65uv/6M4hGXztvEQ9CHRxjU7+rCMB1rFmLIR8RI9WWmPaTjHt248jaQ== 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=YE0EkV7YraUz3LhwTD4uWcgwwddj333eQ6X6OXLDbIvB6tgI8mrbtynoN6KJ99RhodTfxkVzRWpBYABoDC7jARVhJJWv53DGZoxvt+wCfMeYDaNCAFGYIDwKsW+tubi/TBGGA0HP0aNrdSl5nFk9ThcDjUgWoka1EYNH96qLck6fqkFLrC4Z6Va+0RCHk/kQoqEt6A9zXOZB+5EetrKrWTNIeh73SVYrWFb08NVn5yfLxKfP+JFHTuooiNfgzHpS2lv54m1UMUEWHTJyCPXl0mNYUUS9A6gu455Wr9Go3mcCcyg2Melxrp9LYRPkYtjlrf5JyEOUi69y/Y8qGff3MQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:48 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40: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 v14 08/46] UefiCpuPkg: Implement library support for VMGEXIT Date: Fri, 7 Aug 2020 14:38:53 -0500 Message-ID: <20b1fc76dc3fe20e65ea98b65ccf5f981acaa6ff.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR10CA0015.namprd10.prod.outlook.com (2603:10b6:4:2::25) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR10CA0015.namprd10.prod.outlook.com (2603:10b6:4:2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:40: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: 0c381359-5acf-40cd-fbb7-08d83b09c889 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: Fsu//l3dwQYB6dPkrQe27Ggyb1y2rwDo4ivPxjNjhafxJMczlw1VsR8/eO0SmwceQferDfThL5LiUMvBKc2QIo6GEv8T38W3QcXkOP9rEnhxLSRtTRSDFbKv43ePF6DWj9pYqYz5AylimKb+p1tysR0bK18KQ29wgq3gRMQfaqYwhdkI9+FkmpOsGiG4N5YsZblaQKSILyP3cOxNSG2GLUwdvgXlhzjevOBidmWeM2LbAH4snP7VIMXlvjPBc7qNXNGZ3tBeadtKg3vKGRS2Ov52X2/RQENzag5HOHin5sHcIlBGiYMsvMvXNRhpiRlRiyJd3upOZCmx5JLgH1Hu7H8ASvF6c6mVgiF6+GjlUG1/5Z3TwcnQtn/RKFH/E7MhfWCXhgunD5Bd7H5HxtKYEjt8rE8inWNBQqav2qdYHPyTTgvqU1HA3PyfF2ZjAuzrFhclYm4Kr6MU4r9y4QMmHA== X-MS-Exchange-AntiSpam-MessageData: ygNHJkZkji1bR6q9vezGUtyxt6vjr9RwVgRHSyPEL6AES6HQZNqs3qJJnkUF9eBnWA9zFQ6x9VybswbQFL8vZw0RFCTVtyd7y4kIq2y6tS57cLKNuiVtROH1gbBd+Hp8rlY2yXsAJoS4LfSDeuVDBzagB4JGlGX4J6laQV9MOBpy5jYzri2yEu5YDL9MU31Qbo/xjnIOzmaHli7QPj83AIpeUsdnlHsoxSZMRqlbOcbrNsRX54pIKmj4bEpnZKyztUVTsZJbRoU7lXxYf91a+OfYKhgJQ9z5EquT3B4neNshrthl+0CFyx0GKbw+spid0OmfTav+ep4ggqbkWHr6nCq/dCazqTXCBHz98oVkNJJqdYkH6+DjGNt7YyQ/0r5kmtutYyNHRY0i+qYtpnQBiHtScwk9GR0Hh88J3iZVaq9bRYRcLlTPcFZVpcYxH8Tn1PCuEDQhHFqW9PJ+cgrk+25q6zB7qGPqHhlOnk+NAhJFGcPLeJOAiEpaZJrHy1nWXkBr1pZ4g0Lc9kYFMuNo9cIx83kelxRLobIMcOyU95av+lgjhXpXvENMsU7n1knagfFAoui34cdjaESvyqS5tnH8N1EUXuWX8P7MulAznuhav4HBKY/Ty8UxPO81o2iUQTNbxlll0onkCqLErif6vA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c381359-5acf-40cd-fbb7-08d83b09c889 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:48.0314 (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: 2ltk2AZONbjzCC47hoW6kevNWA1gyT9DvqVUu5KiyzCLJg5jW7+gx1PH4lvCjBEHWkw60OYAmBat8FeuTCyYEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: 9iUaPwZcoA6xhO7T2CqS98mEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829250; bh=H9xTgcOgCxsiBjSv7qqIE37OWriA7XsFNQjHWE+4Pm0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=fOKW5PZX2cXVgBcgg2aODRuIyxvNSdZcATA4YjXI4qG1lH0l+Rp3aJciPrS6t8hvQAb fdDSn0cggaY2Zceq/+/i5jFhowuGWwvSArvzZNbMXeVRwEKuROZiVF6c3qOykNDcYE6Xk sE5n6KDrvqRlU1sOymaDJ5pER72laHI1RfQ= 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 (#63850): https://edk2.groups.io/g/devel/message/63850 Mute This Topic: https://groups.io/mt/76056489/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 Sun May 5 18:51:34 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+63851+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+63851+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 1596829260502447.61440872382695; Fri, 7 Aug 2020 12:41:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WsJ2YY1788612xNRYlbgH8Bp; Fri, 07 Aug 2020 12:41:00 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.51]) by mx.groups.io with SMTP id smtpd.web12.4200.1596829258341109569 for ; Fri, 07 Aug 2020 12:40:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AB4ghMoob4myf2UvbZDT/Y3NRkfCs+OJKAMn7+pMEMDDjABMOcG8MBJ4bNQVjt/bgS/6BWrtI2/2N2xt2cJ3sDScpITq14FEH70x3VRUEFiLQBpLD5UHm03yD66ISoasatYatvArZwdvLvZFWyoRYwLRXEZpsDf49NAbUEmbJq82vFWgIRXzP0sJymSQx305v1nxl6yY8Kmv7YvnhpWqZzE6vLW7Zwq/S2laImb4HX0SPGGwY9UeOMggwNnQhqtsoQNJenDSrZMBQn4mRRfFz3SlhnLQYddAHsDbGv+4pT9y8WY+ReSjvTS96aL5wU+y//luzocpsL6Qp2D4/wRaRw== 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=Eeqfh1uzeCpF4QR1dPHkZPl00O9tO76MbFSXzOSMifaoTqpErdFlLPMPT5GrAhXB1TjHczw+1U2yQRVQGOTkID+n+tzJ0yo5ghLrhm9Q1NAgqm9QZSB80iowWNZjt3LKW/lDbZAgypXa3qi/9lumfWSb3uG2nbLdtI4ZztYzkPpZSyMexR6/c0aZY2HAIAYTvA408LXpNAxwVKixIZK7jhYKf4ABfmbtEzoJQ9wYeh38sQEIcHxUJcGDTEED0gNMnA+Vm1Wnl1S2ki314P5RZ74ab75hWHrrgjOUxvbdTBpNtz2ni5e9MgJUtjzL9Pm8Sg2XtJc6YHBbu6seBBF0pQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:40:56 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:40:56 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v14 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library Date: Fri, 7 Aug 2020 14:38:54 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR1101CA0021.namprd11.prod.outlook.com (2603:10b6:4:4c::31) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR1101CA0021.namprd11.prod.outlook.com (2603:10b6:4:4c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:40: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: d77c962a-7a6c-4fe6-92e3-08d83b09cdb6 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: vQym6utpxDWIcUb6RF9fVU/0caXItPRiXwEEpv+13X8QRnNjngLFrQOoP6P3V+Hykuw/tSmU8dKyCU+uV2iw8PuaOkHeg/oIRolt3xjzamUypdLXIznR6hSiESjp+n4NloE4B9IMgPSlI+lMI3Oz9/m1NhFvr75aePowiB6yfwfKXhnoApMeASDaZIgxjY4idOFDVYkqb1h0f4myEWrOersNCq5h38wSXDrrdzVC0F4qhiZOtm5oB99GqQvM09ui99+wm5jn4/n1awZeRXUKrFFIejtapR1f/Tz8+/VQXPrInpamoQAeBQEZcHaeot3EtqbhLtmKIm+25Cd0Li7SQ8l6gRQ8gbLi6LmxNQEIJ03WR5AUTcBy0rKV/gufpCn/BkVCgEMJ9Lygcj+4UYimepKCs7SBL4mzvC4+PYTON8iPMpIQe0MTIatlofUoSUuCPlIUp63ko+tBNaMMo3tPVQ== X-MS-Exchange-AntiSpam-MessageData: xRFkt5CrfSeOsO2QiAezZqZl5SNqR9JoSAVdCaH4ZiPIuOzRrs6+MAeS6oyyI75oYPG2+H+uM4xSFy66aGqIMcxTQ2WfkwAec3pll3obJldc2krIhpDT5IFL3k9tA8CI6TimG5hO4i2kWNvKbq0MMmTbZssLMybcxeq9xdSxaSniXdyWb2+iP9cWRL1f0ezBrbFn/koWxuM5cMaUw3r41Yy58UlfKSB85ssHNag2WPI/EMvUBsaV7brQMNO5XKnfb0W0pWIPsCUWveHQZpAYsYgzZOAQhr1aoZWOBH81eFxZUCUpuuUhub2tMiLWMVRSryNlhq2F0mcGZVvpWt7E80/rh8a7R61o8L/DtQ43mohsP7a4VQ4C9YkPMaxNUq1VbXwmB2zyrluhi+GZUSvhgpQ20aQj+gE6aEALZz7GzaEwxu/hv+JU3RG/B9HbJ+2a4967eFN8gN1bnAAuFRtfjhFZQ9ZMtGQ63BAtPkKAEP9K2P70SgaenBu2VaEtGoEhlkVSs/vu+zyoNyxA4Q1UrMjYiu5Ae8cV71zYFv9sXpZeKIiEmje6irsm5uUyTPL6wPIoTAP3rvDQc0WstiNWCEigYQxJeTpufj/Cy2E11eYOV9fkbEukNZjR6jZPQa+Utq9JVbb2Pi+B881WlszZHQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d77c962a-7a6c-4fe6-92e3-08d83b09cdb6 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:40:56.7232 (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: 9P/2dI9e0JhvI85kBVoe9QPEdDYcLCcNePS54RxljXUbVWWW50nwjkANlGjmRyPshdBkh12H9WyAJtLYhm94eA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: 6QbU8bxRuKrj89E12QBnMafVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829260; bh=96d6EIpxA1PjLNn+OVoHLs8iIUofCT3bbp/EMi9RqDg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Xh1gB5zO9TlI2nzhWlOOCbumrfDd5k8t+gE0P8+11TAq8hXq9V3ykdkyxubO2i/uhrZ S+ouBcwDzzgbt8zt/UYrpG64gZwMWP3hEByM4q0ENctnYoBe0JTnX7F1np0BHFPokwEGP ZtMPOfA+/q7ZKYWW9IZ7SaZKbJ0VjnunUEQ= 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 (#63851): https://edk2.groups.io/g/devel/message/63851 Mute This Topic: https://groups.io/mt/76056494/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 Sun May 5 18:51:34 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+63852+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+63852+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 1596829268473968.0733829907145; Fri, 7 Aug 2020 12:41:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4wRVYY1788612xA48rMqfolJ; Fri, 07 Aug 2020 12:41:08 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.54]) by mx.groups.io with SMTP id smtpd.web11.4216.1596829266876911826 for ; Fri, 07 Aug 2020 12:41:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RSPqA+8LqdI3ncJNvKAVkdH//HockAaOeC6TIyzEMKf7XeSRBcxvqmTcxqCRJHNLgb0a8goyNUuIs6GSjBrjTAVYp5Lpy8WlieCovGdhYwLQWSb82tgz3qfxviV0mu0WBGwGKh9htkPPJNFOzQ/1mDll2+r1i5j3mDMWfsl1oQdI75IB4zPEQcaCZF1WwF9zjdBRmAudyZNcPuXVCb0wMqR6PwAOytXb3jGS2isylCpnNdOgZqgA9w8srx/uVFuFgyFEK9ZaGN7PL+WjUUPIo+vG3NsM2OgL39EYURfla/itKlgUGARnZ3t4sdUJ8ZImGX71n9nHIKR4oZXxQjDSvQ== 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=CHiCJ4kyrNGGDzqpdRauvOAc/05oQogAk3MIP9CqXPLOIUfxcWONHca9vt1YowhjUd1WjZFb4OKjzuJvToDPoOrm0m972PsbtXtkahsl2JXxtv6S0rvI00lCfGcd/P/NyF2zMN6MhW1G2jscRi591Jpu4eH7WrOwKTKuC7TV2R8eOWWonIxnCqWf97VYZTLn77ehWKNC+RrXAN6g2OXLmTkIhyjCXHhpCEfp9YPfXAaGizbCD4q85lFi6S4SUWfYtOk1BVPZoojyFVllG6Q/p9pfrw7bLp9cqhvmC2BR6eZ849v8VEEuuL52sTm0gDqtL9fSKqmqaHqBAvjBtP45Wg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:05 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41:05 +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 v14 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library Date: Fri, 7 Aug 2020 14:38:55 -0500 Message-ID: <62e4d7ada247832fac0557c4965d949302ad3792.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR11CA0015.namprd11.prod.outlook.com (2603:10b6:3:115::25) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR11CA0015.namprd11.prod.outlook.com (2603:10b6:3:115::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.17 via Frontend Transport; Fri, 7 Aug 2020 19:41:04 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 45291108-e466-46f3-069e-08d83b09d2f3 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: slRAIrTLN6hLasmZ0l2mKGxCrM9u7frbKgviFtno+yMOvzS87gl1DPDlpo+E8VyyblSecmWfkpF6oasEJ/uz+n0GraI6QkP+cTvy/r93hmgm0RYyaaoEnkW6KkR50pchOHv1VNrU6yaZV1Ofy8/NYfPmeTJ3W3DWyPQW70K9NlnHFIxqLVSXv1HJ4GbToxtYmHpkPs2V2K+4uBmiIk6JWGjT42VrgtR2tpB6aTs0KStoklTxcJiLaBnrgook18JMat4+AMQqoabFC+Nh3Vp/q7d5ZQG6VRSbJ5odowYfCb8G2JT4LVHEqCCTFOpS5fmwKThFMwNgg+aVzTY+BvloUCWcprv4SMcxtuUf8xA/UxNuI6dLWcMD4j96LZfXtz/zfBUzQuOjYQGQnQ7LFO9rH32ILVJ7Mso7Ua2Rej9tBUi18TUs7cZxu9DgsxF9l4Ech7jF/R0eq47697uijjiHAg== X-MS-Exchange-AntiSpam-MessageData: s4ElzSAGHcUx02MtgQLXmLDGPnvXuqKOjQiPFrkJPu8fn9m4q8kjpqKdNFet1JMdw/IPHpdIBVEKx5FqFB+tbzKFkYdrWmYePtqdi1KI+xNsclQmwASo53uSSVQCIZy4Ee4jcxNQO4CbWLYue0BhyRsKVJK2ej7gpHRBkHqoww8TfjhJSg7i5MnVw9+pCj/Ixva9PON0Sjc+BmxXeLJ7rtFaS7nghDTzWpOdZrZlCK5pBpQrf5Z1wWD8MbEn1b75kTxts6nk7DdbA/DCWzXd+Q9Akm82TQZ6o6QAMZpQ4VML3dAVDDKOHrkspe0CxuxXQRvNjw0R6iHF9CYf63MMUIzsy2H5rUvhd3V4qBn8ZpJaZ99J4OLv+r9NA3TUQBIMAeD/+jEuBeTqRRjIs2GgEZnvgnZIu+E2KF/owNDT8Szuvrg9tDBn1PUAKkJP8r93U/rOktZ1hMAq7RZgkcOhVkmE9FS7HTM75n6UJ7A4piDpZ6mGSf8uX4s+UZrdCYBTwNJ3dVXoxKtMnT4Q0irvhrnW/mhbtZbblckNHsvmUwPbtTxHbdrtGUZBR52aeWNaV2AQW9QAbRYFI1Pmd/bJtA47ubZXnTsJUGdKz/d/gVBpFCUeFlRzQ8MAVj83hUYY9BR9jvWgBcxmB/JlmSLNHA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45291108-e466-46f3-069e-08d83b09d2f3 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:05.4691 (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: 5HrLfMixaKMecQU6WuiZO+/sU9U3Tjo+pIJ+TzOZhDuX2Qn9ae6Y6B89MZfUQskPL71K2+aysgkKnyHarnF3AQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: Sjejqxas5GU9gobjtnCGnSV3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829268; bh=UeiFwCHhlf3qYUWB/dmgb4O8q/cMw3N8wdvuBVndWsU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=eBWKHdg4rsKP1x7X5CPP++CIB0ZPbD8cEdFPKkx7xP/r6qLAayaCdiaP2N8ZWUxZP/0 h4UCdJp07B7j9oho/qXn4kqrJW17N84V5lV2iNryX3hKL6Hy0+884fahqrPbnDEGdXDOR yPhW8ZK8nfWq+5Mr6KHbpdB9MAD+rClEGnQ= 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 (#63852): https://edk2.groups.io/g/devel/message/63852 Mute This Topic: https://groups.io/mt/76056498/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 Sun May 5 18:51:34 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+63853+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+63853+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 1596829276089583.9939623132768; Fri, 7 Aug 2020 12:41:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0pHJYY1788612xGqLb5kfk5C; Fri, 07 Aug 2020 12:41:15 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.44]) by mx.groups.io with SMTP id smtpd.web11.4221.1596829275224640027 for ; Fri, 07 Aug 2020 12:41:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M31XSAS3DhlsLt/RunsIbh5aTtgbKGzBlL/pmC4qAptjRCtkZJyJmOaLyZqAIvUy8I2vo/vMu5owgv4Y4eqIXtYpj5DOGnx52RLxodqdicLa1h/fpZo9UBAjpaSQ2alREN6c5oyaZC3psUT6MqV2z30N+MWjfSAo2kz0Yq8bWvsDZRMWwmdrDZcu0c8cjyTwtQMLXXpc6ooKPYID2gWlTI08G6TVQZIpvB2jbDeZaim+79FLbzKRm2p8z4x/MnvqlGkfc0WzsPwMPL6azyJ6eVKuR/SlmJq5C6d6o1MO43T0QvnJPj/73/nwA5plUg2JGgiOUFAEyjnGtEBfmSMAxg== 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=Iqzh9gPc1gxvvkLaxw6C0AyTHEsq8HuhXsAHqjp0wMHzLLnqpfkyGYi8K0RCU6sAdZ7gEXlTZDeugCZBndfiLabJjemUCQdbjsdIchDcDLtwGouBa+M//FlTgCFixEiQUkeyOB4gCaQ1T15AKQ5goxGwU+XXDYFInM36mquoorLSYVqgzokYLEXYVhWzWlg5KWAvuxGwejanp/Wpjl/WkvKjvkhV4xan0ldc/fg/fGTrs4OZJvCn7gS7DVFlgWxEuLHLPu5PHDL/PbmI7CWr37dvKhB8nw/Z7akwi5k8u5dfPEqixCjKQczdSpIQsdX/tLS55914C/r0UtY8m1IHDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:13 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41:13 +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 v14 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Fri, 7 Aug 2020 14:38:56 -0500 Message-ID: <63145571e35de6b6d518ca8a2a0571d8296129f6.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR13CA0070.namprd13.prod.outlook.com (2603:10b6:3:117::32) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR13CA0070.namprd13.prod.outlook.com (2603:10b6:3:117::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.7 via Frontend Transport; Fri, 7 Aug 2020 19:41: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: 0778694a-a7b7-47ab-de4d-08d83b09d7cd X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: ZzCRdMGq7gWZcCb9IRbMXG0YI3WGvrO3DWRsGu2ysSFDzve4/Nx3x0CG6/05AGf3EYMTPO8LdfDW4NzHLHcvLttG+9Jrg6zt0CroqGDF4+7d4KpNF58NCK192oCECof8IgQ9AntIe9bQGCRMelPowyVtJ9c7ZXs7nvK45cJoZGRtxDSgGGRHkyvln8/cSulfTctgO3XdamUZlgRZRLjKPrl6EO1o2Gi89zelmtvE0GfvIOff/8HRiNuzNE8ewTytOYT59I7AMRLF0Huocohd8P/DXkjTW6uGgk1Ywhyuq31pXxaDfpFVlyhdV+LubSYTIXkixntYgEaYcviG9PGDNaSjLBm80z7pj1msqlALcL9DbO/T/qFyFlwC3WhWqj3DeE/0mSLIfUGOPrpojP/X3z7C5N4eoel8fZLExGQR5aGvKJ+NucmMfufLPGqR9/ZjWKkVrfHCqAtCp01kqVCu2JQOLW8YkzScW/NtVIFveo1OWj00mKhn7E3pyZcFVQtl X-MS-Exchange-AntiSpam-MessageData: CNgkwqteXQq+t1pq2hVu6p5q9M9HbTBEca4Yu5p3Y4Qa/DU9yHM8O9qTBAWXyIG87ZXUCoqVT8q+0Iyi3D7uGIByMYVSb/JbEL/Tjv3NaQx+GmvC3e6Ya+TGC3DSvoVRBTrLwjjnW66qryIDZrHDXxk4RdAxtahGGVfOix/UD0KVXVVmQa3Wrfkdy05V5+8v5+lysn6OjUSz9qY14NEl6Hx9yFt7Vz2UGjyjgM5iRjJ8KUuzJCunZzQGiOyhe0gvdVJR5Ndz/WEQKi3hnuUeLJ2yr7NWYfDC12oWm87z0ucshxyixhsQofcfK8/YKpOtiuCyKLviRjRIjJnbBN1s44rmnMbZelWt43CRDHuWqwEE+PUnGtUCLicDA3CawwuIrDOc1f3HqazxTzL9d0VkF6wqYvKNxQZUzZ0PnfV4P8QZs9lOz/cFFX/aDfalhzoJMJA9LFUjisXGDdft8Qb6k1NnnYYqXTwIF8Q+crp5TLt8fS3LpjDpFyXq1oFu9Lkb5zKufIsotNT6g6R0BU6XDrf0ZaWX25ISqewoQBHQ7NGe85x4cAwImdk/ttQxzhL+5t8mCgdudKbwCJMSaY754bodWo4RRt/4kYoc0SgVNTc6rHl89+nzGilqS8fADgDwJ4E2iH6L9gOqb4skdgGZFg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0778694a-a7b7-47ab-de4d-08d83b09d7cd X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:13.6861 (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: ZbyymMm4w5/xF5OxD47NdRw6xCerrWxILp27ZLEOKLwLahUs0och+Vh5F8e7PskjK69yffMZYrefgy4wluQT6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: 4VTB65TEsrcpLJ4GdFUUJEgnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829275; bh=FPAHPeEMXtRrwZh/8N9XETThDB4NQdKwxP4eZHNq9U4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aMxz1xMf6u7TapvCMgYPjA31s47l6jyrs63NWCXThmKCoNaChxnJe5IavtPtE+bJmYk DuEvsZOKaxLMviOLv+H7cdWoiEbIghHpBo0ipw7/lWkHit/O8BgSaH8pjdTYFdgjucrfn 8fjoeC8iaXtRgZNeBMi4018imTuaZX0fQOw= 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 (#63853): https://edk2.groups.io/g/devel/message/63853 Mute This Topic: https://groups.io/mt/76056502/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 Sun May 5 18:51:34 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+63854+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+63854+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 159682928407793.06850777176544; Fri, 7 Aug 2020 12:41:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q0klYY1788612xJ4zPPQumtu; Fri, 07 Aug 2020 12:41:23 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.62]) by mx.groups.io with SMTP id smtpd.web12.4210.1596829283126297095 for ; Fri, 07 Aug 2020 12:41:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eNYhWR9dg7/zDoycswEAKk8EXjSE7S4hKV2bNqPGprs2EhN783RSdxZvd269/1FHz26JytTZzU1bY5ePg/LHepqyTb59T3a5MBo6A8Ks0YueAOj9Ao75gnEU5QpbCAZ1z2jen58FlNwqZyZ9Wchdq3EKpozu16mYPw4hSb4ji+tHgWZBp3CFW/YFXO4sPx22KGUjxrkgZezysToxzISHtT9aLZEl8xZw5jFEdTi24ZQtXw8XvHEPIrNGobr41dErRJYc3br1uoy5olQTttcGRhCGqn5u9d/btyVKea/UBupLc2VF9CWMl/z5psqeZoTSpVYRK6L7J4sOjGa8Iqo/IQ== 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=jTYVunuBjHpR9Zq4L1G3OkN6whFTmMktHUJeF6bqSiggyHmHnJNsUiqfX44Akdfv/2CS13W1/wbyV1ooXPZ+kTNugQPr8zvyBZGprcFqC8G8/6yJJd8KZLivWpZkkQFt8HNlXvJX651z0axwBHqHdTv78r7OS72a6Uh/QXj0iqZ49/NWXJvnsiYsbfbQ1X0cWzFRyp353BhFJLNKrGfAdWzWCcVYP5xHYsYGgUJVLDlMuaasBSO5/B5yDKXI3GrubglM036itaqPjl41NKpYSXFkN34nkaYm8nIAaK+htVPyP+KlevweLIKxvrhW/VAUt8aj7v/tckLMLyBJVFscbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:21 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41: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 v14 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF Date: Fri, 7 Aug 2020 14:38:57 -0500 Message-ID: <6a566b99618b8608223bf234f2e2fc5c1b308880.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0033.namprd06.prod.outlook.com (2603:10b6:3:5d::19) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR06CA0033.namprd06.prod.outlook.com (2603:10b6:3:5d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:41: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: d2ecc367-f215-4990-8bb4-08d83b09dc8f X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: qIQRBZSV0C19FLLvEpM1xaFNDHeeAXhMVXWkJDqEgMeMHFjGBs9pHjam/zTxkDkMq0C6NDbP2TQ1J2Syqht9m+Tm0Fmb70FNEW2qYXL0VqpV9ABSkRamdD9u7W1QLu4SDWvfIC8VmpjB3lU/iLA3RH7i6BHIEH3Em/Kw7WJwXi2FwWdqhWc6gXjRXnds3haHzETlq0Y73oIVfAVUcNlT5E1gv1QZk48lslRsvn2G972hyzwvrZxrND5cZI01bx1+w1/r4+zBwf0zJ94vmaYFpSIhBZCwyvTh2q+YOjpPWUmIhNJ3vhdjKBHWn13NuZZ6qlzE8BB10yJANBBWx+ycoZHsJv8jPligp0MWM85AMxJZAGhv8OElJ/cTgm9WzCGg X-MS-Exchange-AntiSpam-MessageData: KE5qdAmf4tgEyV5imMX0N6qDiW8kld5qlsOdsYkBquMDvIFaFUJxn2iykDuc7B4vLcgLdxp3Q8KUyA8/v/YawLJxgNgQNtIYiSwT2sY5ayd4ttMZYCOw0KWNFYN09Ianl4gOH+IeosWBE9FVBNyJQgAxKziibyJ7qKRdqvtcOFTF9zzT7TB7bfbXoA1m8Zr1Pnqdtf9kLZfGRaiQptLrTKuU0KXcIXlqp0HLmNEqcpRZNFUaI9IyZ3DMKhxU2b/8v2ayYPMKidcQWGEE8YoR2cTnvRD9WEwApGhkHZ8FYbQnf0mnO+o+dpamqDBbX1APW1Jvk/qx825C5wHBv9Uocr7QAVqM/vWHW5Z5PRpgCdjHPXzXqvh+cnzzFVRvW3vbrXCWhYEv6x3xH+zhyfpTQXiyZi8VR3Dg9FLcu6D6zDg2Q1I/Q1/wQs/xJrnPN/qLeOdegeqa1ayCEbniDi1Yz8nxMb6A+1b631iE5Nz7IcunoVo40bcGU9YNuvy7JyZn+D3/YixgeS3G39wFcXuyk643K0w8QzhOFvMFJrSGwA3Vi1jhrgM6LYWACC7lynOhFeSXctRppRRVuX3V3o05CdpIDC4zdvKlDwaX5GC16MS2Tr2PgWQ5u887hDn5nYAU+g42zWXqoQ17sNoBQB+/Dw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2ecc367-f215-4990-8bb4-08d83b09dc8f X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:21.6103 (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: 8nf165EvNY59++ymXY8gENvM4EL4MTjX2bLQMWDcgJGZ6cfKwV1+64So/UTbbsbt+/O2pbx9onquDg5FrSTgUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: tXx24TTzqTeYuQRDolrNEc3kx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829283; bh=aQxIxdBMB+R1wbrzO5+Z2+aGGxDdKCU7p2a1Y9LcCjk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cDOEPuY/jkYReqUi1uTSjQ5CTQH3EAxVsQfzyi2UsdJWwJO+FPWHzGUGj92koPmelRv rvy2N8jFSxsb2DIvCXCc6+dD3x9nNP30UEasChXulrzvTj/neL5JJa69p+m8jWMBIUQkg 3ZUB2bCKcR0ojnhKfF6w24ccisWal/cRl4o= 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 (#63854): https://edk2.groups.io/g/devel/message/63854 Mute This Topic: https://groups.io/mt/76056505/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 Sun May 5 18:51:34 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+63855+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+63855+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 1596829292078328.35373288968367; Fri, 7 Aug 2020 12:41:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0niDYY1788612xXBP4wEeYv4; Fri, 07 Aug 2020 12:41:31 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.64]) by mx.groups.io with SMTP id smtpd.web10.4161.1596829291147108547 for ; Fri, 07 Aug 2020 12:41:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dX7SnNW7jN9yrPoHNHRblfqNHpy4W/dtgHExjcsPCazH3W2ponSXiM8gdyKo6erIHog95KjvpemC4khLT/MCeyX99jNHwbbyq1G7wAyQe6jVB0zyi88eYpVOXwIOe7f7UJG7CU320JWwODwCwEd749qmXLM9XO2+30IMgrWdTA06BUoNZIarJaTnL8icKwKlp065rKHXeH1XeTtM1LiJbc681F14DK4cM9SFi63E1ScSZwEuB3BX5UvAxpdVlFsHqsf37QrfDTXaWdwJBPoNEy7idm0RFinQkKED/mHrEZrXeEsuPkMQ+zkWRn/CNV4Ddgsbsvjb3qf95Z6z4TllVg== 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=TwtEAW5rJmo7vbc3noMhCy3FHgbuw+5mCf/Pag1Y59dC7e3OeQNqBzFvGkObKY+sAmV/quzhebDzui3rCk356RAKhINApMXFgYVms/H/8JoB/AP+eh1vS8UAn2QZqJqmc9FZ24MiTpBlghN+yv0689oBexuKQRZQgqMkZqg+SAi5120SvGJTD8LJf6tziOjWhqf72JGjWze7KHN3hZVgbqebzfHMasGViSvS4FOVEq7qTLEFjfkvaSlkUZNxKCrepNjPirudg9UF6xIk2FYvCd+8QFGgJKpZzvm4HOoiFwknqGNcoFh0P2M5plc1Apk3vWnCFr3lz7jpTyDa4LK4Uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:29 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41: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 v14 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events Date: Fri, 7 Aug 2020 14:38:58 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0054.namprd11.prod.outlook.com (2603:10b6:5:14c::31) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR11CA0054.namprd11.prod.outlook.com (2603:10b6:5:14c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.17 via Frontend Transport; Fri, 7 Aug 2020 19:41: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: 1104131e-7ff6-4b47-9073-08d83b09e144 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: ZL50he/4L9l/rjrC+i4ViwO529kuvE+xLVTsAWBnKhm5PUWsya2CDR6L3TEm7FyvSOINa3CgTY4o3VXXtIaktL4z91f7M1qJEdr7kU1uVncYf9WGadBouEpwHYDe24i5i/loyHIy5l/1c1WdlOsFCk7hb58HlwiuXilsksFTvNNZzxz7VBUzvjfrTfuju/MOPY59zoPfHM9Frs2Ju8pUQtE+cgUIcekjfkOSuizqcPRlsHnnvdzy7quIEBaqKE7n/2hcl6Y02Ecn67dkA2wnp4r1qW3PI0WfKz/fiXnvHXM8o/QStAMHxew2MWwAKblR9w+mbStWGdMkG0U7rWyhOQlsTuut9zX12DgfuIIrJshGy4K5hnuMiloJEQIwmmbwCJKkLXqcV2H9BjF29rbBMMqnnFvuCXBypF2pVBaxEgm8HN2N+Ukn7Zl1sYZAk8AECqcPFyZyHmCcR7fBP5G7qA== X-MS-Exchange-AntiSpam-MessageData: rNUrBHlZvOuXCbR1Vr39XXDLqdZv2Va4mGe0tELg+2RvFqLv9EZ1cj5Id4kDrMUXiz60O6Jv09bW1DLu6mAARxwngRQkNlhdfq6avJoiPkfyFQxjmoADd7URGFQUo5oRjZZVYSpJt/Hr8LNcXk2UlwXT6Q3HMdzyOObR3XgjamA3SYG5GrvmP7fwEA3XOQeVQpLZd4hO3dBIhH87RolQ6Sgomk1hKE4OJPazNXUIiW7GDdlOhtHa30MBTus0UnFhwFqHved5APwuY+lOIpYpqSbO80rkiOCJ3GTB6DuLdbz5WQc5BC6NLJqMEcJcgcVjoyXRVi/FA6K11fp4nzEoZDgO17Rv6V342ue6vAq79+DGK2gH2UaYmUFJthQWW2mQu+TXsxqdTLZaNJGRYiXd53/zLGRV+HfeKfClYqhPUa91R1t7L5tgEFH0QTrMjltJvEn+nXqiRdnhIShBDTMmQJM9JO4F9l4NHfL1YQwfELNDQRnYAUI8qtmGxi/4/6ZDjuU6/SMsB8ebakzHYmDN7tvFs86p3Yd+CJZ1DT2I2ZNehsXVevoYeNGfq/U/otRriuak8CiUKwUg4zRq2ayrdOYs7rFRJvZBhMO9vTJvRcdty3vyw62KHv3AQvDZ/nPBBC/1eG5EHbFDwYRlXgcQdw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1104131e-7ff6-4b47-9073-08d83b09e144 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:29.5155 (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: ZFG3L3H0Z/3wn4lEsKIxQy/+dLYAjsen1b5CppDYzoLF2NGS/MrKMeWNT6W4owJe+/VEhYC+wIGYVo8q+JWa6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: jj4qHKMUaPqfkCMajXEj2Lsnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829291; bh=et4PSbFgiuQBlmfViSd5l9hHXMERZxAlGI+XESWw8So=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PaA/LAfZboIBvTg9/lV5RS5lc3NIfbfGtrNpP5rxDEcEC5KmhAhnkS+YRhXP24A6Yvm +0ibKzKwDHxN72+81fHxvXOemXzItDvUhFT+f92YtASCgNt6c7fccqDGehg/BkEZtMfp/ Dr/9ov1eaT3TbvVDjKW8+Idhg7nhbg8Huko= 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 (#63855): https://edk2.groups.io/g/devel/message/63855 Mute This Topic: https://groups.io/mt/76056506/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 Sun May 5 18:51:34 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+63856+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+63856+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 1596829300523681.3184453924625; Fri, 7 Aug 2020 12:41:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VUqzYY1788612xacutnExQVC; Fri, 07 Aug 2020 12:41:40 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.57]) by mx.groups.io with SMTP id smtpd.web10.4168.1596829299470571738 for ; Fri, 07 Aug 2020 12:41:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C4E7Pu/FyQkiSXVCUSapnNWavZC7lkWS4ZdjTlBDStos7g5IR+haDMUReJ1Dab/TLhN9O62dmrrqWH7d2EFJSXuOHilHGVvPtVxkuu1Q7ygmUsDrUsHMzAkXaL7LWDbm3ytKQW9Ti8cR2O0oBvzCxuy/szv32UjxBU5IW5Eb+drkGk5ebNV4OiE/AqTB8C/1DYyHWhDby9iSlF/E4MspIzfyI3vShiHuK0sa0Uav0W6xjQWVe3ZnAlQId/SBrTXAFawuJXkrlj/cgP/9AGOKkRobtqmK136hBaNRjsgQ6epAzUiSa76ZrzQhN/yo1CxJ6GuOa+qlLK9aRuup1xLbIw== 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=NDGEUoU/j6JfMW63dgCQ1lia47Ovw8PllqiiO/MLbBaunhRjnaIcgRvxszaN5xcop4bcBaBIOKZ+5dOCj8QZYJFOe+paT0n6pwUzYRTEINudsa34Z8TwrvYSw/vqT8ro38S/zunXE+Icn6vPXiiQg1qnDSJQlpdN6AXp+IjEJD/jzKAXej9jrBUZYZpycCdsFdAfjyJEvMMh9zh4s9iNlSeLfaZ3OvEHDv4S5ltCvXKcC8AOvWKWA2+m5ulvoHya3W8/XQc+U+YXEkO1xZeWPn1x2BZ79VbCR1g+DALmQjhdJVOjo0cukfT7kNfyUMnw1oj8zfB6SWh6Ol7kNE+d8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:37 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41:37 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Fri, 7 Aug 2020 14:38:59 -0500 Message-ID: <1159c1c2d0e03d347e178bd062f8538766a76d15.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0084.namprd02.prod.outlook.com (2603:10b6:5:1f4::25) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR02CA0084.namprd02.prod.outlook.com (2603:10b6:5:1f4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:41:36 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 30c34ad1-a4d9-4b78-f90f-08d83b09e5f8 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: ZyQl1ggloYu8bh0rnuv8jLmBxxBSaVDLFIDq547JcAwZC9emwRpKI8zcEl8ht7vY+013jWS+UWgPw8Nt5wR2YTM0sEPI3nK3HlVmXzbLKRuiB3cs0so7yv7IfcAgpKwYilBoqdAteIRtymq1Pp6oHx2x6X0dZwIWMnq0jiPpOFAIri/o1R5zhfyjW1DXg1KsTcsOq+MrkoP8VFbs0ImEVssVhH/ZBadpgIYBBzLS6iany3TEV9ZJVBrOA5SFIrQF0Ca8A7ZrqXxL9tt8NUi+Q/HHIAFZgKHb+drMLyYhuj5MPo/GRsRooGSDw6bSpFV+EbOyLFSLkzpVBnx5FD4M1s2rxmjKLjsYnUx6n1Nn+tiLlIy1U5/vxK7dzfcHSyBcXWFezhhD1QbX7Efa4z19UROFvFUM6M31fTtaVwB7DYHZoedIuu464sneSnV7qne5o+DJWp1O7ofiG13N7+pB9w== X-MS-Exchange-AntiSpam-MessageData: JfP2S9Uq//m9WOF5Liehy48wS+/REA+5FRdBiLl3VCcCdybN7wqP7FXZQeguy638rQCwxIbGbNtga1DcNmd82im6TKKc1gx6+qMrYBFFSTIDGpN0kCmKDTXs5Vj7AiG+q4qJ4e2dTDzTC/aVcwzoXTioUR3oLC85XB6qJZBvbwZsEC8DO2x8BZV/OeTeHTns7ipMODMXxAv48Ib/sjQHj3ogWQhgA9zjRzAHl5JfJS35XtXQEfNOOwk1XGm12NzjdGQDihxCU7SS1KHaZwoF+vqW6/v4PKOP3SC3RjsnCr7wOJrnckZoSwmQ/b99Bu8NZH5F0MlV8BxTVyqgc9K9PnvxZNQhs/jc+ZSKlcZpGlx1L+LIbDVGv+JWQc0j3uHD5rsxIIlMvKrNHvjFS9irrZ0enoTS237/nQW+85iFtfbEDW/fppXzJSzxBWM/4KYErwvSxY+gRma/99MNpkg1LURwmAhXraiJePCde8KHuHYUtoG2t6WWGe7r0Yeyf/cu7YKFTtAzY+Mus94q4XlGUAeZjTlv3jnIM+zvFW6AXsUqwNN940ZDL76jKd2l7TzPNMZ8C2mkD2DPXE1IXPwCFmUwo47/V9MDS7S1vThImPQlWvw6Y/g9ioZfZaNF0XtEqqMvpz0aorgdoEwIN6MJ+w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30c34ad1-a4d9-4b78-f90f-08d83b09e5f8 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:37.4457 (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: OfGyW4vecIGSEm/K5hfDggqZjwO02uZRvare7RRJx06Gf9CsmGGczWk6maaAWROrXNXR4C4sTGGcYFiVDzIi3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: fltzSCguFjEIQRgIYNgdKn32x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829300; bh=nQ0elLKn/NWZvLP4CTGv6OVUFLhyS0vjnxi5v+kxZRc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=oeSMxMV+DVc8ZxncitosEB8Y4He1VqEcIFZBPmiGipvSPfACnFhTbLpyMMKVHatKSsU 40VzvwLXacfFQZ+LE/f7pZSbzjfjNT3WWd0MWQ8dqSxP84l4qtgJcMTz17MVVRMY4bANH jRirf0Vdr/zTe7u1lqiW7K6fmafe29Xl6PA= 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 (#63856): https://edk2.groups.io/g/devel/message/63856 Mute This Topic: https://groups.io/mt/76056510/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 Sun May 5 18:51:34 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+63857+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+63857+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 1596829308251729.4879790304417; Fri, 7 Aug 2020 12:41:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id P3kPYY1788612xBH7pqiYVPp; Fri, 07 Aug 2020 12:41:47 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.81]) by mx.groups.io with SMTP id smtpd.web10.4170.1596829307059575760 for ; Fri, 07 Aug 2020 12:41:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CtO7iLX05wQrqTbUpDokHMv3NUupCCDirXAQ7b94NVmvDjb0TA5+Jv/3QP5FJ7ktccsqhcW7sPLseq7CnmdnGnUkib/RvdGKdZld7h/BzJ1MXYA6OfBminAEzmbtW9HSmvQEmaqM6sV2g21baJ4e6Q1IDLqtFyu8UvfPkmUtT21ioepQVGDUbOGpdA+d2tcdguvjRQiP5+cfoT3znQFd6ONsD65UkA52pT4PHPEFtOyknWNQjX05s3ymBuBOp8KvBvqRi7w6MvfuV6NrT31AvtalXx4fFB1/C/C8ap6ZyRgZCo4x4IS/uyv4MqLDQSLfVuW7skzNWrP3aUVFIb2OrA== 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=ABJGFkRUVLXxL03MmCySH10bNOqTiDUC5ZnLoaYN1obNSWsdctxuuWVBa7O7+IZaM3QCO3zqlHnbosSSqUlI10PzfetFTdb2gnKWiwLDxohlx3CvUnhfGB7GWrqPABICGHG1FKhe3il1TzZSCOZXRv2lBxrOVJFMCwoGKXfxfNT12TKUIup9CiUaaYWG1Z4lzURiJXKiDG7CtBiP4HJmjPfL7Wj8FfR5HtPCaOv/FGzFh20WVaDIIVBEEijR6d2+gt3AGYlLnWRWOIWBGunxg5qEokQx+mgCL2r0PMB5pP8CiDXZ2Zx8DEZHXpudbRWKIWK2tmMHJ7k+EkfJ8Xsncw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:41:45 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41:45 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Fri, 7 Aug 2020 14:39:00 -0500 Message-ID: <4a070fe4b5ca06e27465881d2e8697781f57779a.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR12CA0016.namprd12.prod.outlook.com (2603:10b6:4:1::26) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR12CA0016.namprd12.prod.outlook.com (2603:10b6:4:1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:41:44 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c593cf8e-251d-46c1-7214-08d83b09eac0 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: jv4ZlXyY6wWsV2V+cBVefhN0Dw+XWQ7iABXj0nXcY2Ke5OyA+GmyTvQgRkSfhJElw5P7NCHFinb3GYWyEfExfH8gK3rcvZwwutSO/+rZxMwhRbdXcOPj/2gwIoLeaRZHararAqVAa3X6+FGnN0ZDakHL9M8M5dL+kF57/bUJqkIjlxuEG2Qe9jxsk/1bC4zXg4FbAK3nLbJvBYAo9dhrx+K6YOrXUUtp+r+YB1PBPENCEnR/27jNfZjyCU5iZPzGcS7wwg74KJv8UTty+wIJkutaDxlpWhlZRKigDn6/Xw3v1YihuYhG6EUIy0Mmwn7D11S6MMomlDHx+HgPY1yURnToKNPBjjUzCU6ZSKu/9gqQRmyw7zIdH0Udj19iCkNi0Fv3rgxFzjy4tWbNIeotmaZBTTcJpwK5FjfBhIOJWMoUe21OTCQnWdtP8aTMfxbQytlCKqVMV8jlGycpdGr+aQ== X-MS-Exchange-AntiSpam-MessageData: G+Iz2tkqKp5sRUEhHp6thnc/uBX3W524OylyuSWiHdCm1TzK7LhvYNT0dQcbHrfmCFys9VcQ5cIyt56VSBsatW+sxWG5oF4CAf/lOTL7/VrfaoUPXRokdOf7/THFVc2kuF13lumIzHKkoGc8CEVwCWBT7nyCc+vHz9KVpl/xyqAprZQUxhpJB0iYv2nPs4PwVBt3MQnre9TgxMCVoa/XfHtclRUF1ltAC6OPUponII6g2VmR/NQAEDwuSPH8QrLLjnXwIDs52kI7gW1ztSjnoP00BlEXMQn+btWtlhDZ0llQtZrAmqpgT2oVmkqbr8e2qTbUt/oMBaHD4H3752IYsAhM3MP7nf7gHhbVKvkfTf2pkZyY0fsKiDVQl/cevhhYFrbPhJqJ/xjj+Qh4QNCeSkq4aUvUhcEuHn7AN40kPj8ywS1ZaTvD3T4KMyan/S8Ln00zvcwP1cH8Bat38AStou300RarXsAqWxqMKMDHKi+fKWUIGxnK9FXgtHc9imuOsE2ENLWvFwvDuleq8htKBiUywV9pWzBJuk40Jk/eW8mNEkK2+0tPaqLjbzB9pxg6BH2JQiNey2lFEhK3vXnAYe1dCQJSPeb3cySZuZU7dBa4dIl2SgmsRC7EfvDkdUrld3R6LMuY1MT0X5OknFizYA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c593cf8e-251d-46c1-7214-08d83b09eac0 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:45.4159 (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: fB4z+3kzjDcoWKBeuzRziIOatkMo9TPubMENbz1qSGW9Tvu1EUzYcchjqXCu32CpzwO9na8iDVEhU0/AUwvhwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: ISnG9W7cPkgJ8AAthNtfD1fox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829307; bh=mXF3A+rIZ3SXh5nad2KUAE620D67lczc1T6xeZ6zwc4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=MQ0Rl0VVZXWEMpG8jwZqHH1XsGRLhV5UWjWpiMdpr8P7zLqVzNlP28Ypa7/uT7y3x01 TNvnjZ0bCy5KtBGKgPBVVh/v/2y0dtwAtv4jscIc2ETfIfF+mMIYZP1GlydgBPzhwR+ah dDA8w3K++ynhPLkkB31jDWWM9lzhAlz2MsQ= 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 (#63857): https://edk2.groups.io/g/devel/message/63857 Mute This Topic: https://groups.io/mt/76056511/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 Sun May 5 18:51:34 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+63858+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+63858+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 1596829318039824.8632945778875; Fri, 7 Aug 2020 12:41:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1OhiYY1788612xgpHoEJbFM7; Fri, 07 Aug 2020 12:41:57 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.45]) by mx.groups.io with SMTP id smtpd.web11.4239.1596829317024343339 for ; Fri, 07 Aug 2020 12:41:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ic+PT+8mbS2+py4ddtkVr+iWvUjrnkE0sPM8fYmm1d70vcYo2oqBa7840/++iBnPb3YODreSZtGPj+DiCdFyCzXkM6vP/IIPJxGLyXx4qZc4ixJH3yffhkbno5q4vt1CJY1vTLkUd5vqG0LmykpsqmmLyD/8nYBgYXv5RVj3cniIRcO3ZAR398ukKD4S1uCnEL/t/TnS3oPbD70Irn8B6cJRHwa8/XKHxq1JSx0CCGtc3UaGJ4nNXg8eazYv6KHN7PtxIr7L0GHYRJ9iaDwF0MECVC5ibn9kpEwUXhLLkgZEgxquEZFblBtesbRRjEM+BQA+qbBPGfWjLdCpT9iyLg== 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=Q/nW9GeJDyxLz7fG+ahTaqr4yQT4y6tN8rOf4ApPLowUWU+RDv2xw65SGykxgUcTPD+SV8c2GjJB7SRzjfXJ9ON/g1/XIU5wy37uxib0FH+1HPHXu0tBtOsP0Gr1QoGVz8bxOoLsQsf+leqIL0AQh5cYU9HfX/5Ekh8R/v6gNQmjERFR2oUATYuQCll9DO6iEbU2GLkUXJ0+GSsTVuzH1TDmZiGE+vP1w/SVU4QBtPpSjZEKyfjhobPDMRa/m2zmlWShpkHRO3oZIk3EI56LGAnpW4mMEjTItHMSJEJSRsXUQeYzEXpSJazhE8lqt4RKI513j+fc8eidzlm+wd/kJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:41:53 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:41: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 v14 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Fri, 7 Aug 2020 14:39:01 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0136.namprd07.prod.outlook.com (2603:10b6:3:13e::26) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0136.namprd07.prod.outlook.com (2603:10b6:3:13e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.17 via Frontend Transport; Fri, 7 Aug 2020 19:41:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2dc458e4-c403-4455-ef0a-08d83b09ef8e X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: 7t8AG2m1P+xU0ygiQpevOqhX0/2MX6wKZBiaFS6Z7AQx4riD0CVuHzDNH7OGi8nU5DcLPNgLjWlRDh3pv0jx9/ibadXiTO8x2h94aJ1ho5aq8fSy5AUF4GBo3j3pIUTTdgpUiKK76EBzB7SNaz/lFiMNxEhYsIDg4gWF5mupqPlWn3JYxlBqU7bfuo702cOj2qVjOaupR8sdRJmgF8P9RjdnWoW/d7ZjZ1vdSBMRq3XdP8OYOu6c9pwiTzhxJELMff80RwH2R0HJc7xvmQqa78AVtt+xFmNlGFVO6FN9RwkU3jlZiUVEimLc3R6OszwaZBAFA2hYKjNpaIejTyM7ItIsYf37coKCNqA3mjzI0OTa12xTaLuuY0jgb7uULCEqBBcM1+yADhwx3voaFpXLbQ0gnOYeZapd/YKgabKGQVsiLE6gXGWcA3M2HEymFHIFN1i/CZhOkfPxaxKigWCs8g== X-MS-Exchange-AntiSpam-MessageData: ziBG8vQ6/qbuEriVstObIqHhfvKjNNdZvDPCE5Ns/k51m+g6yUr+bEMI5+ALTaieaBiyJt2Gyo2EiCx5Y7xn/Rszv8KC/lrWuEQHZOgUxVgc7lX2zhjeyVrKVKmCfPj5xXteIeRtNj0wsV67OqERaaxCYPkl3YzUXqPwCJdM9Bp+UkrZd/VVplin5tsL/TDfu3tJqQ33PG8WOXAXlnx4SmR0OS9tILcVGCkXqKQKeqXusiqaqvGm666URzkG8NCKM1Op8KPARG1G5AAxGJelkTCNYKGZlsipL1HUuWVZ7ErwBZ54BpXtI1FULYgu7gRDcvcTRlCkaKtEKL2Eq6NiMYAX429y8csymQoSkiCjiFUHmmiVzxVZ052rwR+qt+o5gBK/IEJ9fZ/9ln7ICHbPj3u2aeYJITYwIPjPq/1+2TGJO4xoA/u33KB60RO1KmOqoZTfZVOO3zV7WE+4gTv+vaiWxuoE9pZIsjGnJ2UC7qBR58kZI68xO5nVC1Oqmm+HGbHVMAYwwA5I/3RDWYtpouWR4Wxnm96eQxpzpZalmIeeEGhP3Y/aIbT/K4eQp9Ce5P7Tu9i6LuvL5N/j8IZuEkk0UnydYhoz7HwrD8tvW+X2np3D1ml6T/TAHcyHIgGB7f1hUpXkpoAVf0X2Lxxr5Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2dc458e4-c403-4455-ef0a-08d83b09ef8e X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:41:53.4480 (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: nGf9ENNS1BOaBgLpFOLMf+CkLTGMLeclxuoAzm68C4Og7ID7G/ORI83pxLV9NDN6DQMhypwZ0vReNnVzHdeDuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: 84R2oJ0uXSYmzcmlNR5M0F8Zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829317; bh=yf+92cJXdJX0XtwEnheXe7QwKEP5GX30dFQOXBhVU9g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jEFgFXeoISUeMf+MFCu/q9v5ZWWaHgRY+3DgR6RbKgo+7DT4vYdkPik6y0GzanEIHRe Lmrq7TVzRBUAXENbA1x2dPUXeGZ8embFqv7addD24dRG88mzFf3xeCUqcPIC3wukWH2KO ZR15S1DSyF2wJjyzmu5ugMg+GkYUBNUuBkc= 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 (#63858): https://edk2.groups.io/g/devel/message/63858 Mute This Topic: https://groups.io/mt/76056518/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 Sun May 5 18:51:34 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+63859+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+63859+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 1596829325118300.629675699989; Fri, 7 Aug 2020 12:42:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id K2LDYY1788612x2t9Eg4nOFO; Fri, 07 Aug 2020 12:42:04 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.51]) by mx.groups.io with SMTP id smtpd.web11.4242.1596829323611167644 for ; Fri, 07 Aug 2020 12:42:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ijB92+aZjvG6xEnskD+sCyUUT/YD0cKVqz3bmgE1CWTBgwpWvh5+c5613s2Ic3YVBbfnzTcNa6MVJcZFp7ywbwH36tS584//YRC+JleDhQTQul+m5HVI6OBpKZ0IuDa7+C5R9lqA2u1Y+S3BCsWDDYKeyQ2nSIrASpgRZdEdwN5yOyMsMoVM0YDCLzyyIPJ9V58AIwUJ5JhIbd8Laf556RJau0DSkct5SckNU/FN1GDEQaRUWq6CGoHNBx0E0cHqSif1kgmuEO22M0XyH4KvXo1T/iX/5ZJznXokHrmGLnGXxTHZMawAWaTHSH66Tpvq5D6aaw08TbCNXBwKdw6P2A== 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=I/i3CyZfmqnD+UeQcRIKcvfCtCKZSnFHvuSE9EK6BWIbamTAHYeoSvk85PcgPHWAjKnFFwbKhxLDSvGSWTusiHxfeHmibM6uAw59xad/zpXwKWOitxaO8kD/7/I1+RmAAboJyTZzRv+oQxzB55bwPADHzRvk/EzoRcdGADD5UdP9iuHzS4n64XVR6J79gdZ6rF5AZ+FO5KFZHMHhNOLD57oYGRzr/OppQfE8ZFxgRpKjnb1Q2bokdb7adwP3CZuyIAe9DqyHMHge+QzVAcMJghC1qsk8Y6Bq1dzr3U4aySv3skz72WZo28O3BC4FrTlZffJ9mHtSaX94UyyAtqFfpw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:01 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42: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 v14 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Fri, 7 Aug 2020 14:39:02 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0115.namprd12.prod.outlook.com (2603:10b6:0:51::11) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR12CA0115.namprd12.prod.outlook.com (2603:10b6:0:51::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:42: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: 6039bae5-754a-4972-2202-08d83b09f464 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: Xsrbtj76VwnboDuXn/c7MqXU1vfFieymK0PsVKBkne+wDdtTbinoGxylSoMNAPD8+hv2Dq6OL20JTlesNSgOr0BLpykKB82PPoqkz/GnjkjF5quJ4jQjbCHMRCM2Bi/RH1001/zuXGagpQtHIIuWBggv6b76r1EsE1tJhxUevE9k+fwPWJnOjVRfQ4DlheK9NRWQzuFoNQFKiTgcYAjNppacuDZvl/pyWpkmVUvV8ty2qnVRQGti/RJMwCbMNqChO4AKJcnY/+URypYCiDJnXpjR5oI1qa2hhJJ+oQkqGwUSfZUfHlslJrHFgXfzchpjZNexjPEHsEtgnQdViCzSo+ABsUl6Nx45t/1zhClnZ6ykdgHaXhaQuggf4/kjqlyGmK+l3QoOTPuBUGuUuJliPxRoNnxvi+Fq2yPWliitw3cZ5ajGITW0sxsGivZ1h3iyYMQSLl0qnwyaop1QWRbpAw== X-MS-Exchange-AntiSpam-MessageData: FARTvKhoBUFzbNvIHDyeTMfsJj0CYOtWApp9+JBZ88/OF6DhOVwXtc7XVjzwj91pLJIXO7nV4k81keb4CQd+6usEuEfuZIJ6vmzsWRoWeANRbZCYX+oYcHa43mCXDYLc29TEFCj+lN0j4XijKwbGptg+04sIeM8l9AgeGyx8Dp5FEPHb6Bynvx74UtWaWo1JRIwsRUK/+YCNXvZvp+vq6noNFxT+dp7L+AjHk53gCAKtgj1gQ1Ox6wgKLXZw3iFYE6UPkaKsOoPAdrrvOO5vdK7bNdABcB4TF5ffKy0MbeT2lmiQ/7rABuQDx4CEgroZN8UfZB4lKYbIyeV6lfTRu4IhhyH3D/Wd+HprxfG4jMOpIZQ6/uXuXsBUBW0CJQEfvdHQ/29Wo18j1IRHRHgIXNjbts9A8/tQxFDReFpbGtiV6/iIK1YpKx/lthBb7upOSZ2XB0c2pQIIgFaACJ5emMmVKWR5/jRXbN14a9yHiU/h7ZnSaY5BejQavgP9qK3+/nwxUDSodQv1hzIzhVXgIamuDe15qOgWe1S2Aws7K4xmvcWDum18RXc4aypjG1yYBMUeSnzv9lHveI3VfQzRJLTQVU3+iUwns3c6xKBYKx/3Kk3s6c5ogstVHTE2H4Y2MMqZOlpvMdEtmHDA1U6jwg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6039bae5-754a-4972-2202-08d83b09f464 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:01.6321 (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: 0JVpmPH5mlEYHl8sL5XelLOYqp+kP0UGQ1uLxJsJFeKNSl4lEk+DjbAAOvJbOJLIti88Bh2Coyvq9Puvj8QRKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: rFDtjBkP90LPrLFa6FHHXfxxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829324; bh=Iqjn5RttyJ/xkud3HzJWZzCJGiIfgpwiauV5CfTkuSI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PLBDBnCywWOlSJZ4XTwf/oEBNfNxRUVdLOn8dvi9hCebIJEeQ5asnoU09eRXqKqVkE7 QlRG4faKSqsswL7QggzmUarwzvJVrxQKxLhxqjq09mGnA1d4JYgLyncRu0whSgjV3LROJ 3xtgf8tJbCQ1WgpgafHEhOFbEyv7gzyRsGE= 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 (#63859): https://edk2.groups.io/g/devel/message/63859 Mute This Topic: https://groups.io/mt/76056519/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 Sun May 5 18:51:34 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+63860+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+63860+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 1596829332500853.0252119689331; Fri, 7 Aug 2020 12:42:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tjY8YY1788612xkCTTy8Lmb9; Fri, 07 Aug 2020 12:42:12 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.56]) by mx.groups.io with SMTP id smtpd.web11.4246.1596829331614841472 for ; Fri, 07 Aug 2020 12:42:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PLUrGFmulCElyWHZnh/0Un1q0VgVS2jj33IGvBB9UElmC1oFuRyZ94LLwhXODsDzDzqxhRuPrxiO2rU5C663ZPvIgNQu5EA0Cfs5TbH2DWYPMk4ojKhU1v0AHs5gXlO6yUqx75Il93LZYsXDWVtMlyoR46qvjSASuBqhQClCWdSIILGY42njhHOq82amCD1bXS3/zca3BYWC3WDdg7n3t/2HBJkXMUXfW4Nivs0oU7YVUkn+1IJiDqBMpNqHqvPrhVo9yJ6aRBB2Aq2ZpU36JHV//MW2uw1gZHmiJK0jmob/ZBN4L0zsELBL7wt+VrjhjLCa3CNETuXkP3mTSMDuuw== 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=cT7/csKTQd85nMsrhPzyNsp6MkVjGrUoZi6j0eTvedfpH+Ul6fV1AR1aUr3Pu+NtB3zFLPFA1per4u1P3sPhEKLr+FJcVXYDcJrn41ecNuMwWBTVGlJisOaPa6DMMW+W+68oJl0FSP5NUyO3nEbdg1q72Smmtpo7jTkq/wCAWPJTlCSP7Rnrmptd08turrGNfqUG+hyOlvrtQLfROSP0GhB9f0ZtF5rAazySAwd0yMZ09mz3m6BzHVVH4e4u4j3gjdtltK8ndtGRStM8kSyJlO723HQ7fXDjVXMnW94a6g26IhOnaMogzQGE5dm5DJu4VGHVVUmIAM/IN6rsjXjHEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:09 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42:09 +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 v14 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events Date: Fri, 7 Aug 2020 14:39:03 -0500 Message-ID: <7114e4024f2af77999a7a35c1e928e8103732a6e.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0057.namprd11.prod.outlook.com (2603:10b6:5:14c::34) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR11CA0057.namprd11.prod.outlook.com (2603:10b6:5:14c::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.17 via Frontend Transport; Fri, 7 Aug 2020 19:42:08 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 42c0cbba-fd37-495c-f09d-08d83b09f942 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: lUa7gbHBEqkOW7LlJNJ9O6WPeXq5hVOnZR4q/rF14mqJzbQVudZRLaRsk/GmER/6ehyba3UeQm913appPLxK7BK/13QUyPpslkqudqWDdaOguBO+IecApuvnZEL0Jv4J6emc1PlGwbOSrjNkIQyi+dx7ylUqBHmcQJkzzqWEJyzjXpp6IQqdyRC6YHhbcjcAm/MSE6i3GCcGvyQ/O3ldrqAIg+y6W2La4yN24Yy88p8iWBPY035mQvBhU3mYlBpTfKN8uHmw9J5TtMsBPcFKTwszafJLkak81+RAkU7RbJXWJkH+SzbhqJ+VKyExZwQMZMIWklo0suXAoAoA8UV8vXqlBeibdhuikCDoAW/9UamZSg3F15tobKhk58y5gmVhhIIvBc38DGbf6yowLBK6RPejExZ5LyZCFmSFfbLrHwXOlt86Bh7h2ZrnQriSH/PqSLb0PywGSGVaRkGbNQ83RA== X-MS-Exchange-AntiSpam-MessageData: DlT1XJIvawx+oEFdLIY1fdABnKMifR9gf8w8SX7+1kG0wTXYFE5tyNyHiRTLTk3oVirEuxK2xct5stLlXoYynL02A8+h4kdTM6rb+Lmzke1Q2XnghYSRw4SKeuRp2U3Yw3HKwQ2qG3ClXDlV3PfS0CIX8xYJ+DMt+O7yVo1wnnFRcNOdHPVhkD6Er3kiLqyuYOAb89+qRwgJ4XG2By/T7uLa27T0YihjL98wTu8B8qhVIuHeq7YvXBBvMi5MXy2ChuI4y9PC9NwV6tHdZXN74R+QGg9BQCiSx53r1wzcNS5DoET5U2C9WWs1wgwvFWq9u3qiRPuvbjnnb9f5cv4krwX8lYijpEe3Ar97EBBOL2Up+br2iIyTcSLx7WLZ6okp1rf6HIo8zynZ2Ty9n76/ysa50+nkASBb6t/AaF92VnxbGOhzARM1YghR8N8zAb6I6xB3ojcD+2g7cYRcsQOG2DPGDGV05aUgFe9Rnmx8TV0G0yKZhlT+XvrXw3DTlQt+jTGa4Dc2y/+VdU+ilThTK+PP1F8hSNgxoXdwNfXpp//pWTN+7+hAvkFcf3C/pKT9LpkdPnH1ItT3yCeIXC1K0CYN6oMbyMjQlX7K3bVmV3sD/SW0MYOktsoZI99n1oQ7jXaBEu7UfW0i9tetSJP8Lw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42c0cbba-fd37-495c-f09d-08d83b09f942 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:09.7402 (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: B5qpHoUY18uL5A7SFIacnPpKPhWNCTAOEvSJ8sibLFq2bnikos+JsTxe0PKLdDETxVyZUGUbEwJ83/zgF8vCrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: fUTclR1O3KuUedZtzVnWwmx0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829332; bh=yLheDVmEYwTad2aLi0Z+O2ZVvvtRiyhG4ZHj7pGnz3g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=HddszZLFEVfW/2yTADcUPeMWt/Am6xb3cU8ocFYnU/yfQ00eKm0LwFcPHGl2VipUS7Y 8m59Yq8om1qBpztIY4JeNWpPySDi2DlieqqwXK3zWClH1bnJJtSp+eNMgOiO9WYSujkyS RNSkCnNq0gaGAFjDVTbHAibOKz2dRPW2Vos= 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 (#63860): https://edk2.groups.io/g/devel/message/63860 Mute This Topic: https://groups.io/mt/76056522/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 Sun May 5 18:51:34 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+63861+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+63861+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 1596829340591629.3048003442894; Fri, 7 Aug 2020 12:42:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6IcCYY1788612x2F1HcX4Wct; Fri, 07 Aug 2020 12:42:20 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.67]) by mx.groups.io with SMTP id smtpd.web12.4233.1596829339556035071 for ; Fri, 07 Aug 2020 12:42:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nod3w68v297Bq1C8HVneuQcLRzyvnkol4sqoV1fj6oiV20eRixBsZ8xGw0Xb1LgkSwnYvzos1miFTntJ1Pbhrb6glkaJSXYMp+PkkxPiJj+jjXGwHkl4KUj48afHp+/c/TSiXFq0wAuIUa3x4qem6fcqcIGMDAZUKc3bADXzXFNq7ggBo2JHpjrWWPEZiJdl5IQCTgXD5OlLV5VLzdfB/TxTpEuKX8dVPewrZ8XMMeNpKnwfE+IOxFmzTfx4dOzRE2+QS3izgVU0Q89cGgMFDMY5UDxgFV+hDZbqSkNyAW4WsZaGobL8vxqM7JVyHm2blp5pmklY9ozI/st+iHA+4A== 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=USgsM8Rl6EpLJ5c3s6M+GM0VgGXdhMjbZpC0I9bDPHiZ0ahlIH3abU2/D+6neC0kAXNe7VupCc5nkNCiz9HR6zqtgPkm5WHAilJoa6n8vVcoB1GK8rxPscB24UdPWseMaBNsnSsyZH8mmMWidLNn6KuzMDt4tCOLDtr6vi2CZL56EghPxNJGfcz4S4B8y/iP7rAq4UyZ/AirIaQ1KR87Eygv6ut3D4upcsMw/8E6LTC0mBsdThQVGYHeE04S6WQASn4JR32OTwx7GKuUujsPHWvHwmgdsRFv9tOBr4psjID0jWRSwHGN6xXrCXcLNci/PnjiZwqQaAynA9zMtNfveg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:17 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42:17 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Fri, 7 Aug 2020 14:39:04 -0500 Message-ID: <5f68d178f0e64a8ba3994faff8ef66bc26a3ec58.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0093.namprd06.prod.outlook.com (2603:10b6:3:4::31) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR06CA0093.namprd06.prod.outlook.com (2603:10b6:3:4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:42:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1ad58a6c-6593-4768-30c7-08d83b09fe12 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: dshebcWVuV8EANWcSSN6MXNzO0jzT0dPVt7JGUgy4qxtofTjjMUaCbEokHWuVI2rM7qt5pv+K6IiDvekGDs5IsUegwA5YYWFulIDsQJThiHFOnNG7yLu7fYnKbc9RAuuY9Z/ncqX2kzzUE9NdidyeyEqDP+o/+DYHwXCdRmNL0aW86xo3dT3XwwYTzPz0N4u5ZdXhltfPsVNcqrM0XUF3kk1IbQjFoHcbmrsS6cYrUSrijz0wGPhlGMsMjDQSzoU0OJVxVh9AyH/IRKCbjFKNGUUcLsqKcjS48keI7J6QzBctH6Zp8sONDOOELNRPyrYesn7CCVgcGZPsCwQk2VpQTQ7suTOyluRwP2jtiswCABpuUgK9VDfPiDtB0et9URh7JHkoaE6VjIcRSr87xLy6HylaUGmaY8cYHOYzVsgo+h/TpBrMIs8I9UgMYaOwoVqPG1OueTMkPU8/qwYrGl7lw== X-MS-Exchange-AntiSpam-MessageData: QhrZv5k4BZtmXNN0p1LlTU3Ub+w9Wg41hXPckCy0Txg+3WqjDmIgo/3LMdE02aiSBqWKQF46clrik3+VBVirz6OkhxsfkdlXVG1itNPmyX6kfcZ7nNrCl3FVxX8iax7JtdS+Yb5bUEbdG6w04lYqJQXA57AKyjlcr7DBNkFE83Eb2C5Zd2H1k3CFwS0QahXLfiW+7sRAu2UboxkrPPfC18S91C9eo5Jlh8zaErlFnRdmq3Zm77/WLfd5eKESKSX2Ky6ybbDESu30PNuBtm3MYBpgWw2Mg4egljRmWUrKrCUVN77KwOKqWrTApH9imi61RPlxgqVza+V/wH9s2UVV8GinImrFXvzdaGrtgyFaARSXZhoEfHpCcUN0frdXJ+1W6ibHoRMOvLrvTnPpJQlTKWJfO6APtRhfTGYHEi6wh16DSmiRx0OWhpI9eg4uBN1Dfib6Ol89MPTdzeeP6gEWaMnQLy7UMDQ6t7WKSh0tQlO5MYZ7Z6zYXEtwk0kJTkghj5SXArPFRXKr9Rbpv1a0lTNp0QUBp84UnD7GBZZymJgOLQXvPrktKNn1S0K3aGykYnHLa/LFPrvK9bqFzPirDu4vwGGu0kZo787k9FRoaYQ9vxASiBFz9pI64S9kMTV/GnCqRG+YPL3ofBV3hK3pug== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ad58a6c-6593-4768-30c7-08d83b09fe12 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:17.8213 (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: XBui/cpXwwuzceytSJALmyKfmgRk6F1thm5biGz3mz1oDear6/F4xXu03BOe3441LOvCsStMBqC486sAODUcTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: bk4mNbOkVgfmHWAf54Dw7pTUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829340; bh=hea+BIHJ0tIHZ6XrrH69ImZtA14oEm1NN8yqDFooB7Q=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aZwyo9Ww1suzSgQ8WTBj7Rh35BYfdLGz4D5wgzHfTQ0q1eI4zMDq5S68T0PzDJJZWb5 i4xwfOZu4sABZsGeRn+no7ufqXzM0Nxx84lQ4VPgqTD65f7BBdwEv+tfRpfcV/Evov1Ge 9QbLzaH5eqq6+6CKKs3masWGq+QbbBxfgNI= 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 (#63861): https://edk2.groups.io/g/devel/message/63861 Mute This Topic: https://groups.io/mt/76056526/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 Sun May 5 18:51:34 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+63862+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+63862+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 1596829348820664.6825529636418; Fri, 7 Aug 2020 12:42:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MVUPYY1788612xfjq5r9S4jl; Fri, 07 Aug 2020 12:42:28 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.60]) by mx.groups.io with SMTP id smtpd.web11.4250.1596829347827318178 for ; Fri, 07 Aug 2020 12:42:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oil223olcoPXFf3bEWEzf1qM26CZvSJev5ehUfMEYOHzWfPkrfAg4Cn2AmEJ9ZY+ysjhRgodtXy1/s1otqxGCkSdRFdHoTrB/bHGWeC9DvpN/2jLcGNhWN2guASNHa0A6QVNjiXPf8l1pZnmMY/AV9MeDPHWc2g4See8gUm+PIoKnh/xKndjeqnmwzmxziFa7E044/0aDQLo5HS3RyBeBoOgKbEtpNOc/CDXPsBE3eJOiqY08dPl+U/J1ZEDGHgDgmXO/vWNMp8RR5t8rJbjTm43VVde6UicjzYc20JvkaOxCBP/ONFNjIA8RLgTjLpG41Ld2/s2qFvQqyCff/YGBA== 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=Cwy8ZPrcwpqMgBUqXKJ9IPvcZyHcW8VLL2/Hb4z2qC9/M1MwCXcHSNAVPyTTRbqyPtft3IjFaSyVtjEGt+1rww6vNWI9tEFxxR0kMrH3kZOgmlYzBnmXyygGKbBLNvwLB3PZM/kaVfrrEzh0f5PdN+sCShO1J8782zJNOluKZ01CXWRN4gdtohbTJDd6GEOwwmEM2kj9ey/1FR9W44ynekrmUx/dFJ+4ZTSIKfU8PgKbEjtensUlLyo8miHp0yyCqzs1pTjCwleyGnxgCneWC9W0xSTb5zVjst6miY31NffA+xoE9uYyMNLw3LgS7OSRVMsCXUzL8yhcn9N594IK0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:26 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42:26 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Fri, 7 Aug 2020 14:39:05 -0500 Message-ID: <69cb6f8349d4a4dafa791b73d5b24c43c15507b3.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0090.namprd07.prod.outlook.com (2603:10b6:4:ae::19) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0090.namprd07.prod.outlook.com (2603:10b6:4:ae::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15 via Frontend Transport; Fri, 7 Aug 2020 19:42:25 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 10ce0a97-f71e-4b33-f0e0-08d83b0a0311 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: oBS/kuzFTnYvaAD4aGvJ8Fh9Fb330M9WoAIfcQCqoYH+cyjsNcQBhNERUnAf8NNWmhYsUXCOmtiK47f2wIcqwJ1OYLgo3HQJ6j7vVjlA+8oJIG23XbxG9qu7dIjbfwbPD29WqQODm3Qf3C5DPnr2Wv+81xmK4v9h3Yrzf1CZhuMhza+n84j9mRbM2H2ihwnsYZ5quYCqYivNfQ/YKBcp7vwAJjBxp6+0E2IipEDpjWU/0i/IuE6f9wNzqZtLJNW7npNylBCWfww5EoY74aBtnHryrNVIoI/WdO4Y/CeUgRJQggAOq1x08byFz18rnYyr5UoaJMOJNmWnX1Pws62wMwA+2dpfosIyYlub9Hp/16Pdwhn2wPHoiLG/uwYKk9Ffxrw2UQxIPs5vhlYP+QWcpvCSOm6WyaBnmmZVLBU7s3wC7CTrnstqDawsefPmJw8SNGFeULRlBNbhX+yv74R6Hw== X-MS-Exchange-AntiSpam-MessageData: ni7lZ8bAT15AfyRsvHHGsbU/Fntkc4ReBBKnjmAnJgBZHh7SkDbyJRT5h2tn/PAwLphf+zBh3jcB3iBX5LYGvWYHhH89oYj1hcfXkjhB1Tln//9PByeiaAZ3mVrMXAYn6rI50T8ARgs82kgxRLUqKHO+8BcMqb3qiRWZmRKD9J/L7EDqWejf6+u5HckPtPL48IYjR8l2Y4iMYkofjEV7WBSIiwrt0bSu/hw9mO+AYv0RfZXhJQ3JGCSTJMwkzEQWEVWT0MzxlXLmYJdfo+J24ff7vajYqCO58LPo6X9Q6YiAYflUDyiyYXpEbfVOCqVOq/AcicOedhyXLlALZR8dA848gsVrMNwVHbzZnB/aB0ZodLzRYQu9n7Jw8U+RHU1CSd6wSCmzfUCRBZYcbAkNfyftdobtdgmpfP9erp6jug2h2wcb9Bn2IvCzdVWDQA+Nmxd1cwci7I2X4hx6yOKs7FZIZqtHI5qU6/ovBkysCi8QYS0psxngEEC9KgUULBqxNwT0B2RLA9G12SCyfi9dx8nqvhgzJ99NffzrKjuhes1VLjP8NCNtHnvOp5/uJ+GXbh3Fv2PqglQSth+fazJMFwOX+L6TIfHXXIXUmkMdl0pNPT7sjxv1AuhOBSm9RAY1phpPOtr2ZN70PzA9NC36UA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10ce0a97-f71e-4b33-f0e0-08d83b0a0311 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:26.2483 (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: aM/+xYU9Z7SORrSGszUvxUp1pIbSW/AL0yxgIUpQYNGbTXW8XdFUF7+6o9PaFKNUUNVXvtBHOaJQ3j3HdB6mxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: lDYfzwbZTUi9bBkSEHL5srosx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829348; bh=4w0rZipRZB3yKPXx0+1AfnVHHVdZpswMiqXfUrmi/nk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=nWfkSbI3LVwgfFThGN3Aqn4Qum8Ike1NaQFiZRoGg3g6Lksxk8vVs61uOIDyzaxcLiC mj6bBii2I6IfM5eD6hyRYWMPQXWZJxlQvzPJX71QwW8I2daFASbmBr7rvaNoxbiWdu+71 mgW2i4wBS5Fy2PlycfpDFo7p+X+67IEzzBs= 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 (#63862): https://edk2.groups.io/g/devel/message/63862 Mute This Topic: https://groups.io/mt/76056529/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 Sun May 5 18:51:34 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+63863+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+63863+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 1596829357363907.8832878783809; Fri, 7 Aug 2020 12:42:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VkHrYY1788612xwzPQFhRnui; Fri, 07 Aug 2020 12:42:37 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.40]) by mx.groups.io with SMTP id smtpd.web10.4187.1596829356407846566 for ; Fri, 07 Aug 2020 12:42:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JqCEyQrDXi6w610sWtBMxf0/XiHYSjLhnSdAKaw4Hh5sb1EpypyL2QcWmHL5dhR9ODCQNqJzmODuHO9Jh0ieJMXQcnjABDviElYqg5bgIiFoOb6At5U9cW0iPRn7glDvitcwnj850MGPz6RFX9HZakYNzaKBR+6okrZzgD0yRciVqfDYfyumrrRBDPmu4k+foPUvXgj5HeHRE0xp7Atpq+vb15b1+xaHvJDcqWztVevoSQauI4QkoWVizt/TJGjco0y2sRn0t1+f0UT2265RZg0C1HC30ttUpjhdnZHoBwxKV1136darfUGBYDf4XQ5bDDYoS7KwbAIWIAbKu3qMew== 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=Cd2D60jER+Bejfi2+iLP5vJrI9yP3XcdIL6yA2/juUahciA9m4nU0R2Gd1r/NRlWswz/MwiYBsLrBanwHfYB5Crft7o4ktDwzXEzvylf2CIMEQR/T4qsFaGtVZq3f38cjA2fg/v2hx9f73HDC1PuLD1KY41dpPz8Tz1hA9X2dqFqfkK2CyQ55/9640js6QLcZ/WYqnFMuDG8pB2146V/JLiiD+bzhzLTcYkk7OIeAghySGRYLr2iCcSh0YyFmlFXliSExTIVxL/h9GMlFTZ2Db0efKKkApuE+MhU5L//T7DRG9o7zv0cL2Ou6aHEXrTcLOJsDLKRIA2q6X//pqF8kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:34 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42: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 v14 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events Date: Fri, 7 Aug 2020 14:39:06 -0500 Message-ID: <0e27a2b00a0f5acdcf941ee03c63e1c88aed1c8a.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR10CA0022.namprd10.prod.outlook.com (2603:10b6:4:2::32) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR10CA0022.namprd10.prod.outlook.com (2603:10b6:4:2::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:42: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: 96362415-566a-45cb-fd7d-08d83b0a07d4 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: eW9PdbjL1cBP7mej2KI9ZM1Cz6pCO7vIv2CssspVNUoaWmJDTi3ukX07AkbudDAYgTFRlF89qQ7OfvSx6L9/xvMjgu6L1q2CtP7e7UTxfpFha0wrE0Rr2ldkPJJH0r/5DStktT5C08thOOJ1qS+RIVbeYgzPWs0KB4+HqUkJRnH4W0EtDAh5xsEdpnKwxivcqZeCkEbtpl30PD//VbsSUzy4Z/eK/0rlVU/bmDOX2Hj+8B9jonxL+7ZVU2Pq0I3xtowdBGhfbvCEJTOfNDmaew+6KhbA6FaIAu/RaWPmtc4sgYhoEDE+nu+1YvmV/1WVStDADsS0QaYGdaEqrf7ujcgz2kjZrjXZMeZHfMtB2dCx5Ia9K8FnozU38gG8hfzMSsHArJ16M5D13PjGYSGxz1YK9O+Flki02RopS6QaqOzRKa54MHnVygyDZpWcppOecrpePvBWFjqw/OUUKM1J0A== X-MS-Exchange-AntiSpam-MessageData: U5+CDQRzOKaWJ1MwVOhZwh/39vnxFfewdDzHVMZzvdgeMELcxyGXX3nCi5Ydl2T8nIW4LqeKyYcoEsuKGV9qw1f7X6OBy8OXIA5I0j6eegs/24AQpXFdZfkZ87lvneu3cZkswz2sANX+vLWk7cZf5Sds49POwtpSYfft7n63OMe8XVp+y68Er2GE9FS5t7O5C2wlCPRuUR8WUx8quNGUhOlUreD95lml+dGRqGH5DM9hpuVFlE/EFrhkUnpvDv1WKYFPX7oDnQjh0efToJOVeancomD4ztZdSAsqqbQiA2j6KSwJKbHndtv3jFXtnFTYyRSsDTzPUAICorNvX4imEBOWQe/tK9xhIaKPkVFHze+UdFyfi0QvSV3stWjukpHK+CDrN/Ip4g020TgNKfZ1XIMTFfCcrkZ7XJ50dFGmgkwbzrKNHBxJj4xJNhmzLx5PvqZhsDY8ukgVWYZLfcaX9CnmG69+w0Il9bfhRewzQlf+ffw9I/lTQ2HZkFCBrfbwdpi/YozgZs0W6hy36ye+9hiE0z0m+BVkZpjwQQ+X3d3V8m6DJX3l8/Nb4EbYu9R51HR7k/UYkRDlr4iIwsgWMLiclaV5Q0s2WfQyDXsEZTVawLhxKT1cz06xO3E4qegEG5kM4i1sXxpxvA2jpLY0vg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96362415-566a-45cb-fd7d-08d83b0a07d4 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:34.2344 (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: /KdaqK71utv+QMBoaTAFIn1+01ESdTJrr6pPUEc2yuC8yiARvuiD5zfqF6ywsIYopeIaw+0Ay9yhMEi9nTERSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: E5vqSy5KvB6vJXFnJgsgzB5Bx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829357; bh=XnV06cCKiitkYlzePtlIxV8REMYo0lQS5zZM4AGZVlU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=IcQjeGQiIhY9RnHEdaZxt35ZAyciT6bHn/ONNZO3sXmeLzX8XdI8k1uvLMgRAVO4op5 hR24IUhJBo8oV2TPpa3TeVZDYYhWuPZNuupfPOXQUxtRaf4ImJtOITs0BeyrVXIMmwXvs gcGgn25PK9QoDqH/ZKs7KccJ78Rbfn7tKCQ= 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 (#63863): https://edk2.groups.io/g/devel/message/63863 Mute This Topic: https://groups.io/mt/76056534/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 Sun May 5 18:51:34 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+63864+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+63864+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 1596829365259840.3902928497239; Fri, 7 Aug 2020 12:42:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 7oXxYY1788612x2aiZqvKIe5; Fri, 07 Aug 2020 12:42:44 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.51]) by mx.groups.io with SMTP id smtpd.web12.4241.1596829364273279876 for ; Fri, 07 Aug 2020 12:42:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GgtRIigUzzlhuokqoYC/1WrTOO0jqGv7Us6TKNu2nC2Dp5++sRm8UWclQcb8SM+zm05IQ7wZzYur+d/GUkZPMXRv/vQjDNFidAYnlf6wsdm3/m+TZFXcc5u1uLdiHklahLSIPDT/g9QqaO3hkC45ERYZve+7r8LHrdgnN/nQ7epJNv16eMvWKbfIdDl/tO6YO09vyO/1BfJ4tXsAOCpEMJmFKPZTbRab93IJXwMnKLYJ0HEV57w8VAkLnL760ndomm3irOcJ+V26lBZRkWkdfGf+YAFyIctZiLvDJ6PWgMo/IQzdTTrSp1Fp7WnSOlvFD+QfIBRAFNpBTdW7qzMEtg== 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=WYxBZQk9Hy3roS2gczqkQCKbpK+tEBAWgVrXKjiFqNoY7k4+i4Jy4cTUWazRVkXm6dk/FXosaK6F+h0kXLvSYgEKJNP7Hui52ux9C6AcN2tNnQh6dZFt6dGwz/D7+/pKItlQVKlg4chsGV5Xj88Z2l+JkhJUgAewBFqeaeAyeRWJok7x/4kWiXWiNHoQuT+v5OtkQ9NUW+FJZsdG36QKQm/P/cT8YYP0d96nBpqe7/cd/e3ovzp+ha28EYOvDsnhOmuvlyj7qRZlDQNrDhue4xMh/DlxhES1lUd82SRPOX9iPIgKHcljOwXpFl4sivV92hmOD+eqbGykS3rg5goM0Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:42 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42:42 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events Date: Fri, 7 Aug 2020 14:39:07 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0084.namprd05.prod.outlook.com (2603:10b6:803:22::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0084.namprd05.prod.outlook.com (2603:10b6:803:22::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.6 via Frontend Transport; Fri, 7 Aug 2020 19:42: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: 5beb73b4-b619-4d63-48cc-08d83b0a0ccb X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: FuQJz3GCZDxMKmb7k7M0stWP92/ZlLTEYeutAzOxSY7gSUOC7EYsR1AFuZo9thI6biHb7EVluauzW/jSgqFi9S8zrVHkSYxiNga0CrQWmTql8leWKDP292wBb95pjFzZ7Kp1eJkGU9ibOXGCtSuli787yBcPcptK+7igmG5ddU0GxKPuNlgvcRv8w1zGuI2N5C9yRYWcIL+EZKp/3PgO2IsTaHzJTNacuac4aS21SqcvA/MnqzOog2j9o/wMPFGBzJ282zEOo1wzNb6JDbg8zc3skw28wl8Zj6Alo7IcyLrW6y18MPx4Tz/e3Zue47NvX61kQSpXmsWO4Qha5EJThU65msMNpM+3vHGj5Sm6z//M88GXj2ixSs/uG0AHgm3mGCpz+8zRnSnmZiRocPbVa98htt0vvIbWpFgmJQE09qfAGh0NufwBugJr6Td6d59rr0YblS07iMfClkLMebJiTA== X-MS-Exchange-AntiSpam-MessageData: CgncJm7AJk59bhnWePFYxoT4nPRn4tXTutPcJxNPUyXfp8TrByjv+ip4NnJoOTQ7OwhLXSGF78B5Sg3CB83YpK2BftuQxdB6XMljtXiLDjfcBuPdEp58CtnIIxxrMXY/WzyWDc+nWWu2E8i4csjoYGyABORupu50u1gvJp7VGHV53Q4rrpxYT52jc21RG+a9niURryM5tp5xnFgt6t0Ckx9+8ZOcgn2dqysSrFja+OcE/FewhnIWMzHdsdE4s/yXFTiQeYZ/YUsS7pD3Ww7d7w47LPPSKgM4EJQ+ECE8D+6l5/LGpHyNqMXDez2fHVKLiEQTKeESD2ceIpaZyxpGlydPMpg9SYGfqmEvAQpMXcAMRz+iINdIAN+BTZENKHsVTlNwVIR+xFQifT9hw8hpc9MZLWRticojKsE22vL7IHMDh288klRHWpvU5+fY0ZPUl3xQl4OIGJPHx1NUuZ8T8wGbmNivWzAGBaO1Qa+SFKC2WQA9W5nMJjvguNP9Xvdiu1D2zHPhFiVmfg35W6eokoACnHmUFURnT2rSx1bypIkZ/IZIo3PDWN4Ng8xRn8Dk5LK3o2arLt3jnse5v/Ci1Y25XdQ1cAtS0SnUo/ahGwxNdCxW2vwKW+27nNo62PyKE3ge5pheitUrZJfOn0BAtA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5beb73b4-b619-4d63-48cc-08d83b0a0ccb X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:42.5494 (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: TbBwHKvTMxqL55tH6J8oTJu/MIoDqi0SAtz2zTRqjHzior1w0bFfutLNjI/lCwwjodjmR8cVYEjrl9WhPQqUCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: 7hryzQEYGxbZtZjqg2RWvC5bx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829364; bh=5vNQMNgQivwAAgwqqrCjOYIlPep/1vEXYa3dtaBPXas=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=FUsX/ZuenGbksfnAwpfKX1kD2WU7u47SVkp3qeTEaPh4E4ABvIserOspqmUPRaLNFju nKCN5iCQZ25Rp9XrJoYrOo+V+i+GbVUjRmK6NKholtxRNNyEFpHrErvHNzSZng83e+Qmx u5q3l0N7gSTEEr90kmuttTKU8tw7CmgHh0c= 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 (#63864): https://edk2.groups.io/g/devel/message/63864 Mute This Topic: https://groups.io/mt/76056538/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 Sun May 5 18:51:34 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+63865+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+63865+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 1596829375459752.422698760944; Fri, 7 Aug 2020 12:42:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6dTvYY1788612xPP2xk4tb6D; Fri, 07 Aug 2020 12:42:55 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.50]) by mx.groups.io with SMTP id smtpd.web10.4194.1596829372180631883 for ; Fri, 07 Aug 2020 12:42:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JccK+nYeiCqaFVldn4CN9Q2LqJx99LmCGhycaALbXcFv5/Yz04M4rg/8b6d6y3iSd72cN0GAO+2ufMx5ZF0VBUoeFKhtvUZhZFcbMUIUrXVmE0P3nKdha2meYj/BWugmXgYPKZwcIz27DMRicdokOuoNdqC/Wy2adHp90d3XrYTpfKcBIn9Zp+aOddrq677By4wmy/fi0zgozvA8QkbUC2tC70GOOuq1MrZgix++CjzOkUncdaa3ySPIWiktcOFyOlPSb06aJtmgALGqySlloRVKD99f1jVu/UJlQpGMxeP31zh6i9P8K9vR+jSEk/kAuqgfNPeNTpAg2imDJqDqkg== 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=i+t8AY+Re+wJWa/YnL+z/9j9Bz8K+I8mCXonB/snldtjzCm4YMXhBzXslyW/h4AtEhGzK1hCrN7o/YMTXmt/Tq5Gpf9cLM2+OHGTf6yyUIFQjsHnJYoRrOIZCRJJOcNPgONjWQkF/Ve1Fs5K1aMAsb4PRq+EKjiFZkqA7JAIJzwtHKEtW72OGtQvmzem9MJ2B9Olf6jWmnTBprDDcrImTZa/ki9L9RSRAxpCFX0Q0Cx+JiCkYtTS3XBp+UC+t3j0q8Szax0UDI6Ke9ocavDWrPOg+YUvl3JkbUgAiHCtIfj9wr35u4Fl2lHudGNlGPUEayxjCXWnA2+zJ8e+sjd2ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:50 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v14 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Fri, 7 Aug 2020 14:39:08 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0078.namprd05.prod.outlook.com (2603:10b6:803:22::16) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0078.namprd05.prod.outlook.com (2603:10b6:803:22::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 19: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: 5122e948-868a-4969-f991-08d83b0a119c X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: yCGvLVQ2/p3Dvhy38OaymzOJwrblJNOI7EpE587UOolYE0AsY/FNhrIYEGaYG9/OFNm/lbcrG/lFJz1O/QWnRGCw5NYGAodJtsTCyTRrmXDeejRfLUusWWpniBJV4vK77jZaqHHRguYMuLuaH/RESKr6CkNNc7Faq0qucnI6ZhVi5Fm3OqV/8hA7nIM2AipMvdjmUSjARDy28N8uVl7JUAbDIE/lXNXcuDzFRxkdt3jzCZbRQGVYqgWv2ktCPAWjaymCZMM2NJSrTynjipjunvVnCmhudefPoQ6/ZRhkjrIpjryxk3uI2hz0M/SsKMFXglz4WiDWEXnBuC9OxAQaPGx75/1ro6zBr5begsyYN9YbQJQGGucQDuqqS7jx8GzkCsCqXXJt7jGtVaxwgnn8Jht9sPJNo9cg4OsVsP1ute2TFGjrahmiAj+CMOtLmqMSCmehOD2BZLPude1eQMG+gw== X-MS-Exchange-AntiSpam-MessageData: hGId623kne3dtIqzPqAPT3EYqs/3H743sXvCwkZtzw9uHD38goQLlw00ri5nmQ9AW2kwup43mH8MXb0KOeICfTf5TbkCXxj4Ogv5TDn5O50aw1qwtWmNgjFXz0lcnJeOVNWGvYxvpaDaLxCLh9bNR+jXm9jGbmFknl+m5npKJIan9gqXynh1drYcOhaclpFl3imoIVEsYbL2LlKT4XxWar8W28svWverUiGVqhX1eBFw4X0vRMK22X8MyJStUWanptSaaX72beRfIM3SThYCMwQT/TDOy1V5RDH8ZZyrfYHanH+UJuhc7KE7voX4n2xcxUcThAye94bAZvcKT9ZC2BsvDP5TrXyGzMME+nxqSiGIJids83KFpcMBQ/HJpa5GIhw9EwngASPoNSecjt60BmgI9FtQ482Zwe1HF4f2+wG1a0fUNDoJCIShL7it3+cf9si+ovi2FESaJ3m/xYsHm8aWLl3xp7wQi6OsIwokR4uVp/Tjvvi9wm/3uo51MmvbD2UVv7TW4KONDPgsi4P7McfvkXvvYiEwIxiaiylrVjXDx7k4I2fxf8uI8QbxAZYjcLkyV21dwvUZliiBU70BaQXT1prM1MltZn1UvoeXpa27tOtJb2a8s8rM5XbDuVjBZQU6wsTMzxDweA3tt6DW8A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5122e948-868a-4969-f991-08d83b0a119c X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:50.5836 (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: QEIBxRFQeda2iHgF7XVP1ZjyygvuhUvTAnwIT+GgAakImcJCTfsIGIcHqb6JI2Z/CxVsouOt0V3LMRdJCFjFew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: J27b4VH85jkzgG2asTsb1zmJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829375; bh=WK7ggEZdvfjJCIniFvFLVXFMXkwo7ld+lgdbSug3VSA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=JbauPj/ASsRqGDxsVHb18sU3a6EZ3gNeVwtru2LVTAfm6NpQe2HcJ7pv90oHN9SYfEa 5GMigmHKjBZ6LtU5Lmbg82Q/fZHspXehKy7MJq0cstgD3tzz0KF2bjtq2jV0sMTH+EvLH vOkMpDXAFVhNTCj2HT1JHujpehrh824ZdEI= 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 (#63865): https://edk2.groups.io/g/devel/message/63865 Mute This Topic: https://groups.io/mt/76056541/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 Sun May 5 18:51:34 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+63866+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+63866+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 1596829381684213.65029010717615; Fri, 7 Aug 2020 12:43:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ErV5YY1788612xDSdj4vFy1f; Fri, 07 Aug 2020 12:43:01 -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.4260.1596829380488888821 for ; Fri, 07 Aug 2020 12:43:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kVctTK0YINaPpGr0RlRkO2yAoVNfIFE8dWD5kK222hJAAAoFODSjxB+JS0KVX1F+aWRVQnlt162N2MXNz87pE2vy/yiPriLThbRkfhfrvJWTGKT0LIItaIdO6UjsQ71/o4PYwKxoevI22Jg8NRgtrR7Zt64NwZmamsY19AwS0hzmhwFImyu5dncuXTqRwc7kBSNV4rN+Zew4ON6xuvKCLq3+amYvHXS+NVDBqehnPNI2UwBKkvIhWebjmoRb1l1o2yEvLVHwNFvTDjWeJE4xwY31aW1aidv6+kunqLkGhZmXwc4dO03JtOtKPL5X8t7ELsy8zzZqYutkM1PFThPUeQ== 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=QfGgMJglK1bS+EHDdNg7lIURDyc+9HCjQIFQsCUYhikfPbO2tR3xvFJOEiN7UlfSMu0IEL1kd7y94kbcgq5XFjpcX5rorsRbhwEA9GLlAVES5mSJUlED/Pg8o5/pASv71/wOacJVHh9xzLLfEU3+5XHAf4TK4/ljvzIKEK7ZaEhIi6MtMjX56D8YjfZRnxjsD/ptXZ/P4cBA50gE0LyD8qth9npLB4QCdGeHdRWYYMA3tH9x6a3WFWEmvmE2psGG+cUazsedRzbUeE58X4y5qKFEhionZh8LQKK/pLgVDrnPk8wRdS6Pp9WEiPIHXyfrlINoF3ZeoN3JiypSwaOGjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42:58 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:42: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 v14 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Fri, 7 Aug 2020 14:39:09 -0500 Message-ID: <7a56a78a07635c124f27e7c4ac1a9c3eb6877e55.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0028.prod.exchangelabs.com (2603:10b6:805:b6::41) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR01CA0028.prod.exchangelabs.com (2603:10b6:805:b6::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:42:57 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6585d997-caf8-470b-305a-08d83b0a1679 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: PkD8LZaGEB0fp/YliTmzw3jyUYFdIsrCpul/EF9lKV9Vw2Ko9s15y0g4fNCxKH27fzR8CY13qigNfJSzOX4vbZJQnI1LS+MdKXp5xTi5TXgbcWqS85xfgeenl/ApHMNcx+J0fP/TMBojBuLuRu6Mr7S89GD1gQ3DBWuWbawKWWrU9bXjV2FjXln76AFqTAu1/1TKXSXKlqyORvWK1B5D5agBUdYGZk5+jw28lQvy2G+qYNxXUfmSQAqEiivUImIRgLZ1PRz35kfpeIYUyPdE465ESDv4lP2pFzJA2dvrLwBmM/N0RQUQqMJwejwLLO6y1bGwc61YzrXROfVMfxeDR/0xyakRNPtvHkh4xdv3xN/EciFR8uBGtiwO3zeqY/P7g05Dyj7IJAiYch2ex5FlEDv0LK/5LyXca5W5/PJsZIZEmRrsaC41FSC96H9nxi2KkBqRmtUTZrsKLjIVA3NkCg== X-MS-Exchange-AntiSpam-MessageData: 8mWlRlJjOevA4pscpXODKcqzz+o/V+yvToNMC7asBMf4A3iGo3G9CD25bqIWJBydBEw0JdEgjJ8K5P36lpU95/p6jnIAT6U4lx30tcVQr8xNm2ub5+8QI+7ZDstn2VdivHhJqPOLmuOWLM8LV3Ga/omGT4C5e9S0bCmTmFYssCiT9IE2XSA9p3NyCRkgifYjWu2L+PPBSab0ZShi9hoKozfg+tCXAPYx4IEHkfVTbCZPwVBM6EwcYH+xi0IkwvqonHP0UyF20oifzBsGbHaJ7TVi/3Qv1FIiDGb5Ntn4Ke1Gwka4n3SvXvHolGr0M1ugMNC58pkp3t63uDftzWUfMjfQjlu2xCEVz2YAbeTUxKImS17QK7jHhGg0wpxmFG9N1e4faB67kzJ1weyT9KPUkm8wwzEvIgpl1HaOVDhB0U0buwUAYDwRzpe85YwPgLYGAQ4wYnB0AHfYF77w9k0cbK+0Kt2TzoYvoF45kqTl/LMcO1mXPBp3NRQf6llIRr09MlvZS4eS1IHfaeOZYzbAst1A9y7UuwjAXltd7Dm2j/MxCnDD7umv6J+bCTvtIGFQE5pO1x2z0Ovp9GcB38qKiFoW7egD4Hnj8s04NrszHygKH3wTOA5ujlpQSz7WxGLgDLsFzk5KSnOwItWNOiC4Fw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6585d997-caf8-470b-305a-08d83b0a1679 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:58.7876 (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: tcNfidmDLZl51gjFc4463cXwXIgr+sLz/qzBGqjImVYH7sKOvi6elzfI6JinxlG/m0M33KUlieN/EuLzi1dFBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: Aznmh1Sdas48tkUnuFd3rLo4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829381; bh=gGXX2UwKOkr0vQnirUmGqEPjbsdT9DFG/QKV8Mkw6w0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=fLBQN31M0Jd0XmBSEWizDsfdL3UTS5R+l6YvoliUtR3fq0xhj88Z5scUJhuHI02iwJr Bie7c3it9tQAOwraBgfR35FgEYtod6xiGltNMojHm1qF1NQJHMRzfm2bR/u+ttKCuuPTz a/v4zjpKt55e+ajTSdUAhAEsp/SNDXNYQiA= 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 (#63866): https://edk2.groups.io/g/devel/message/63866 Mute This Topic: https://groups.io/mt/76056543/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 Sun May 5 18:51:34 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+63867+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+63867+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 1596829389349883.3812828555874; Fri, 7 Aug 2020 12:43:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FVDYYY1788612xcpTmifrLxS; Fri, 07 Aug 2020 12:43:09 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.56]) by mx.groups.io with SMTP id smtpd.web10.4200.1596829388516195980 for ; Fri, 07 Aug 2020 12:43:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IHWcI8gok+htS3gVrW0ZPy4sZhh72DOe3ZXaF928R4tdmfHafbxXksSr9AffP06Al2ZHMdzDvBDZbnv7hbeAQZfQkBtohRpnmf62KGWdvDFlgpdEv9Y+uJJxVG/+fm5VW2aGj1G9CANNpKpZO5JXz/Q7fUL1Hy3DUuyzP0f2laUqrFX26rmEva7ctf0DbHDB08tbegT8fHVkndvOLT7fooMSOcF8oGFcWjWv1dFputEonhENxt/tWG7bqKTYQo4TD0+ln2cOD07B6oLLr51MRk245TmxIKeUDWPLEuRUeOG93w8+QdkMD1DkQJroCYJV08hyQpvHl01Yik3M4hiMaw== 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=kGZBUIFQqAd47lpOqs+fO8+pHBkBagz/oaMMu4+30EKnwTYwQclMrpa+yke2gc7oWkF2Rqca9xWnC7/kFai+pUGadcZWAJOoHtI8T7L9CFNWL8+FlmupP03CqXyphFg7woO6X3HluY7NlxxNfZzNh21VEAVYD5X53vZsbM4G4ToITe0KHMk+KtlqZ3dIJH62HPaqx7WtieDL3XySEd+233XWc686eWVQkru5mu9h8p8s6EKOqeEehCs9wLhL22X2KUdAeVRJQ9Yh4OUIbfBEZCQLjwMY59fijMTfczG23i4wPYyBludYiiFDFEibBmjxEKdeIaVU7RXA+7DO4W+s5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:06 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43: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 v14 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Fri, 7 Aug 2020 14:39:10 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0113.namprd12.prod.outlook.com (2603:10b6:802:21::48) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0113.namprd12.prod.outlook.com (2603:10b6:802:21::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20 via Frontend Transport; Fri, 7 Aug 2020 19:43:06 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e1813f71-15a1-4121-f743-08d83b0a1b40 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: DlIl2CCDvBCIVmSNRzpjJNDZisNiWKlyBka8x+skQevtvOK8JJou+wtun31qYHiEIhS415KSfvMQ7Ajit8pefbkGrrPhb9RxZndcZ6WgPg0wjzVPrbFHEpFADz45GGibAbwovnDzsNlVzEIJc8V8C8p0GBe9Gub+slHKt+cRxEKsuSg3+UygBr/VRq7nszVwgwYls32py44VchYNLCYUyabofYKyq0+aQ4UGexTi+Pc9e11tJiwXvv9PdwdqC86O1rRUBFIAzJF18jjApKivPRQqoLYivxRHRDpFmMq2DEfwIX7jVhGjDRrzAqa1zC01neInU+T/xiIvjkEGw+6H4gDMbuls4UAToScBjx1dnvYIj2F3yO+5/StYaOrXIBDkOqzmaVE+T4CxO/jEvOTq3BjlTyUbvwITymubFqXQ9uaMGc0Be6blvOt6M3/v68hdqkjRQE7Bo1RYU2QWCz503g== X-MS-Exchange-AntiSpam-MessageData: pH1UMRZSkOyNtZ7mWEzWf3x73hl2R6Vrxu7TcV+2FiQBuqnQnQpx7DuTRthm2ah+D9krTXJnkHohzsIQ926oRCxBhC1E/M2f3YZliKKAGcEB+vDzL+folX7pGWFyQrN4l2tKguNeJ+cCMgNjLMol2jrZGwpAHLvo8IGApyGmlbhKw4NoWFsid6NSBoctXoDa7zm7usBxCePvWzeYuzNF/jLoFMzQ5de3iUra5ZZbdapghlTCBd9EohhnRF2LnUUy/dFoc+dkCy0HLBzubRWjgXdEajts0RCDGKmvxt+nomXA1ktJ1LLSW4KNXVPe2W6jTLwjkLubgsk/W3COLbJYE3vM3xvCRmDr2yguyBOzAph8iK+jYsh8y59Oo5MSTENvJMAwTKjPIhEk22HukVTNo5EFuQcVzGMLrJA2BwDiNEuoFTJMJyXARYUE6C8LaF9yONDShZp7AFhSgaCjpFS9fNou16otbtd4nrZYznWhglH/gK+mZ+DR2CuvIkYNoPKe2u8IDZHDsNPVcg3xPv0/g8Xer4zplvWGYvrTEvbsyhfth2ry49nlrfvfEMMC8u0Owi9dIM3etLVlmtwTJyZ7k10eies8V0ETkM2kxKy8upo8umWlQyiwPJRUsIY0VhtlRUZO88qgFLgtTjpaaoKmEw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1813f71-15a1-4121-f743-08d83b0a1b40 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:06.7398 (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: 1sslpqKKWJV+8DlM9u5MeTmVu6v8ywpiPqjxJTkCcPu0LmpobbPVHHLFrVnmRJbSgowScXmn4w7dJzqVnNbg2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: KYoqyceTZAs8let3JkZpMVO0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829389; bh=9W7Njdg6JXTv+ZDDNjGGpX45bJpQyuAnNDpL/nGl81Q=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=L+jhbU5WDeOow+Zxii7x57YAYi31lcluYAXELBHHqNPv+1w1XmYL5H0WauCRe2kqSVK 8wnPJfEburejg+BjC9FZ0s7Hez1dVa0wGazm4sl/Wghd+e6AmPwrkRjFiooAMtsJ/AcQf Ul1ppVcq/o68VJI6+i2B71osUw8PblrAxiU= 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 (#63867): https://edk2.groups.io/g/devel/message/63867 Mute This Topic: https://groups.io/mt/76056549/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 Sun May 5 18:51:34 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+63868+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+63868+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 1596829398121639.1300488819151; Fri, 7 Aug 2020 12:43:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kueZYY1788612xi6Kh4aiz8N; Fri, 07 Aug 2020 12:43:17 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.42]) by mx.groups.io with SMTP id smtpd.web10.4206.1596829396756722428 for ; Fri, 07 Aug 2020 12:43:17 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XV0SiF+AEMlXvxQoMTAgiCfUFd+S27qHe0rwrVTQfIa4VhpeNJ5tvHQe+rVfQVijVWvabntCLnVJqrx//KoVDy06ZmZExdCZ+xeKOqHoSjUtvmVbJTu0nm3u6n8emWQfwOEkT1J0whwqgIuyWH4iiN5r/lW7p4HbrkLEAxnGZv/9h4qMlRgpbZm481xe06yrnlCrgpjMI2p4NXAh0dpQ29m+250ZY08QaXRKHXge4M9mlkH0mlTlrjOoq15ekryfs7OgkMjjuvsT7Pu0PfdAlxOkUaotPCWTymssYzYbcwhGptU+OB6wVQ55ygp5If/RGJdUNLzcwsjvQ4HhCA90vA== 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=jNt6H7qBQggEGefP6f4ILHrKwB+m2dUUd/uSuP9VutEBBJu9+dpqB39cY3FE4P4XJuWX0Sjk+ZuQUk3BI3s0nE707BSg9QkwrNFtNDQFiyHCTEIvXcX+z2/mc47MoIBomYSMOzfhy+Rx7wkDiBd1Fv6JIeRVYzLiO3rVIOQZacScxY3pw/wnuHxYdax8yQnkzHJ0lJ4IvLb/CwKaSIkO1paxqNHjiHef5ZO46MtSUuxhENCfvA3tZyD+EnN2Pb0XASRiKmoDU0bALOa0sYk9p+kfFoHdMwXg+b2af819jsayHsBHPxso7pZ7PiOV+K5Q6t5sH67aqRCOs7CtLwyZTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:14 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43:14 +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 v14 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events Date: Fri, 7 Aug 2020 14:39:11 -0500 Message-ID: <340ece6d1a871e8e15a672cbdf56e87dc5d9f5af.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0048.namprd16.prod.outlook.com (2603:10b6:805:ca::25) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by 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.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:43: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: 0dd40a77-eed1-4dc6-ea14-08d83b0a1ffd X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: RYzQ2v2Sw89wQs4Es7o9opaE5r5Gfd2soEYSMG2joUtdJhrz7eJCfrQH8o27KS+qDKoX9T1v06XWoXTmvsu+BDumJifJsVFMNkpSHkDSEdXqgt9DqCEmtRdzS6988jrB3HXO1vUqQuithjJ9y3L8UCM2bL3JhF4bNLphrTZ6dEkZHAA+NQydsAzEx9CH1S3ZejDGjGwvCbiNwTmNqxVU6JcTkwPObVC1vTUgHBx9OplfRxSvHkDXmKIM4mM0F3Gs5MqCHaInT+DqlzTpeKn05ZSiv5NRpWHuukxVP7JQxHXihqLsLds+4BntKnb9wwqdzkYJQzZSN/otG3cBOp5K5Q3hzawBLUDEmIDku7l26IJVyzWLh+DSdWWnfR/j6nYAQrL+VjevHj6YldEevu5Yras4ozgwPvGLKqlcLpEjKhEKUfNGM5n5p8hpUVY7z3ELuqipoPo+0sXkT4dlbD4ZAw== X-MS-Exchange-AntiSpam-MessageData: 7fMDTHO3ftzb7zCKtbSGBzzHTwSbLuqQ9m/5DkGnAQ/fPlBaj5BNngrI6qEdaBjpE/yodQH2CwS56R3AIsTkconjpt3dhY7Bs9ZCCv/8LSKjqNC/vS2BM1YB6nvkE3TNGGKYg7aX9uf8+xk2KAJ0xr/IgXVYdEVO1hEVGlgzswEvOfEVIZ9YM3XLth20D61MDm9S5SONCzav2580kbuOp00VVXgubAz5+KPSvjc1xqluzSyIwcegvmFK2/aeduV3EMR8MCUbPdfvM7d+Bh2SzKiPqPgFklQ6zi18EDFrxfqq/fwMKbjTHyBWbMFCO90PYQGAtKc/IDK9B8nNYgzNDy2HIHh3ArmkGrBrsh55KjZMvIVJrgQFI5xw7y/+0UTaCCZNIBPvei+dkskhxhpURn26upW9+dC8hpmuEjMUaNlpko2yYEEDdP5O64Yu3iWgnZL6w/vyAymTJlxj2jMKpNau8V90VdZvaObT2jdfQ8KgO8P4qOBKkl0TJnKQZRvGRUefWH+R/1O+LZPWgeiK/uIuWDL3csqJbUKlw68fqYDKyNYDjR+GlIzYkcgbeecKsccDhKfdUCEQx2OudoBcMR8LzznEGOg5ei/L9c2uEey6WKm0RSoTI3O2f5UsWPZY3tzIZ5De6RVKjPw2v3V/zw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0dd40a77-eed1-4dc6-ea14-08d83b0a1ffd X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:14.7700 (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: +v+bGvLBoPwaxQ1WrakQ0AP+SC6FtEv6+ANRfZGbwUrelLJz9z9Kr77agv0KE2MXQc3g0O1efyXnKMPf4TPDlw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: 7j8BMFw4srCLUR4Wf6mUEUHWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829397; bh=KdhhZ1vvtNywxyjKf7bD7p9Ujo1hPEP5cnJWDw3yaY4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rfxvMtf1Od3q7o53njOafVSArx4e+2EANJ6Ppzr7dnZou+U3C8smx7sWwj9/B2GZ3C7 pfTH80pJftZVGfOSqMzXzKN0Hh1OyUin8e+xI555CCUr2j7+RAe6YPJQODmXy+fM0Q7NF M5wZ9fcpPVdVUWHqfw1V8CT6Uu5YPfQ/Cno= 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 (#63868): https://edk2.groups.io/g/devel/message/63868 Mute This Topic: https://groups.io/mt/76056552/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 Sun May 5 18:51:34 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+63869+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+63869+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 1596829405654123.01147908617963; Fri, 7 Aug 2020 12:43:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hfF2YY1788612xFo2qv0KOAM; Fri, 07 Aug 2020 12:43:25 -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.web12.4256.1596829404306541511 for ; Fri, 07 Aug 2020 12:43:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lz1dOpzimStkRU4ijs26Ac6YGFZ9+yvrhE6oDTKrLqaPDcbHeOKTvTY3oXLtYpOVriJiqReS28qf3W8kwYGpe3hTpul+LdDmxEfMdRdU3MBI/5XLJcJ83IOY/Sx5ofGlmVf0VoVt3CsHRLhzg/s7IJIw6PpVS9SIJsrSGE2Lug0xS1fpoWfxl1ExnPTcjyEyjczBIPkkfjHR8YH9X91hQSzlcDN+6CekvWsoq17fayfDCYoCevy7UzvTG5Zr1rxP52iFWbFy7sxZTFL0jdUaW7V+OE+2lkrkIlwZ4XwZ8Y5F8PTn7Ow6iuIQJ8nI84a0y9BySOLQ+jM9eot7+RyXKA== 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=KnDUU0zcxo3fgSGNmNHXjAmpTtSD6Fwq5u5Ew8/xWvZr7kXT4tNVQHHHQqVYoqHEk+W9+KcZQdfWP54DtTCytANvQF5C5YZM1B8FbX561dx3dyL5pMHBc70UwEIXsw8cNJ+eaix1YD5nL+kOMpskqA12fpaawrVOJnNsxuzTzcuB7f6FXu/fxFNo/5VkljGAk8gXL7iY6LtErBCKfPlvNRNv7WihJDAzVCY/YTXEH7J1Oq+IvCzeAQpmcw3O03Z2evkWjOvUK5FvRn180YMotBspNg+GH5CaMcCq6Cx/2MN2APwylL+1KV8gcZwXxV4LIu54MGSKWPS1FowS3LKlfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:22 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43:22 +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 v14 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Fri, 7 Aug 2020 14:39:12 -0500 Message-ID: <1b94a7937c6fd60471ccd4b0b88dfe9b60330664.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0024.namprd10.prod.outlook.com (2603:10b6:806:a7::29) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR10CA0024.namprd10.prod.outlook.com (2603:10b6:806:a7::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:43:22 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eefd27e2-874c-450f-4bd6-08d83b0a24e1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: Fx+i9Hq79NwjrWY92pS/I52i+klkmzkPL5NNHdED6WRAM8jvGbd2svApbXEAmEY12J89cjcNkmgBSOShq6cP3K1H2j4IJte4eP7BpnIxAAbiFLG+ldssAeu3hkKV7Rp/VqFSlqtHTQmdDP2MGCd0UAC/z3UcU06Hsq13cg+Rit7ZVRexrllDMcjrpFOk2O5qlNanmUDnBS2gaJiYPJbK2WiSyHucECH/rsowD9rFA+g2aY4SuwUfCPo/blUxefZZAAnFhpZ3IdFVea375KAnBZ4/hQWkJCYnguY3e41lNeFTHMhFVdDH9894cnrHopgc6rJiCDdEU54YAXh0vQNhPaxuQF1noG+IutO852jmiY69pYQadtQwK5K1D/A9SMnv+/alLpbGMG3TfmfbaXlfMLmi3EWL+QGjkXneLKvgYz4g4NkJBcPpqLiIoHaZERMucBg3cPUyc2lVA4/G/lAK3A== X-MS-Exchange-AntiSpam-MessageData: XADU0wUGJ+hZ1Tc0NLlKnTJsLE6l8/8xYPa0Xs48LpT0+Ob6euoPlKBl/1Zpuxhv6r/Vxb8AUf4ZjzTguKeoiYW9+GUvf8mKJaW9xcI3S2fuLDnFFQ/CQ8ER6Yv8c0MeUguuKbulfNWiIP+9wmQ7GJUoRtfEYs0yv/ik0+uxP7I07l6j8nNDcGxJZSlAr0/7NTylm1FwVB5YVn72wdZ0CAUcatC2IdVgdB70uaDwPApkwh2l0VPPfGOf0aM8hd4LeT3ZxRbXQUNLdEQOgyFe7n3CkwsrObUOv3d2sAnoE5MBNyZfAJ7O6gp7F4eGfnOy3FGkdfaUfdx5q40fElFE3c3NKX5YrCclinKndhMvi/rWCw0OWVUKmE8V6IUMq8NvvaueNDugvPcgWAoEruQCNuaDao+/Wd501f/TF1Y+fogG6XsRJYJPoow2GXH+tr2tIy2Eby7XBObfJdnp1DDYnJae22rm5G1lunfR7ILkzvGF1kZ9gE5DLZE1qcfT5Gg9jPItXiOM3VbC16DBi1GE3kW5qNGLALuthoxy2lhI8p/OaK+6bUL/JMeE+XZxqGLYSheFhVddvo2LCLPoXs0vZgikvvtgUUm2XihyQMHA8ZCkKeP7KuPLpNd/xa+PTjD+JYtXEsxJEWNEdRFUnu8lrg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eefd27e2-874c-450f-4bd6-08d83b0a24e1 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:22.8980 (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: 5xgKsSR/M/oWS/jQVhHMh9xVPlXBJoOl3Zch2yD1vmgXEJBUCTnQeP6K1kTvZ1LoniQytL+pvfuXNRqoCI3zcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: Kl3eujr7w2BphbqzQM27zPAHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829405; bh=iuX20JfpO7+0raLKw8ojoAYwRvUWida3/ZUlGXno+VQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=iohiBdNGa2ZxARbc6JBUcySakzbmeGpPr6k8KZjmZv2cfX4y1t973cbqIXP2mj3ErTI oeal6xbhJnIZQfg1uAOEfqU5aJc4rCcdxZrAXvrLlXZlGwWtfSv+z5/lT6AMdBHWSWYD3 47SCHXpkolc22GVQUJSPsJwWcd/8xsBU5fQ= 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 (#63869): https://edk2.groups.io/g/devel/message/63869 Mute This Topic: https://groups.io/mt/76056555/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 Sun May 5 18:51:34 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+63870+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+63870+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 159682941474836.86580959384037; Fri, 7 Aug 2020 12:43:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1JpgYY1788612xRDq7BR5sAT; Fri, 07 Aug 2020 12:43:34 -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.web11.4273.1596829413417679354 for ; Fri, 07 Aug 2020 12:43:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kO/eoE2acnbCFEOyllrEifsVgSBxEIc44bKlJLM6HSA5WjlTLxd1SHTSSfwnKAmKs1z9qzTMJBiq8glaf+aONIlRpjldwxr9T7QQJP6T8iwBSsbfzsYgIEXcjaSPGbgDLAAEXNlT9zyHkBhKfyjc/0M4llhDoZbQ5ZEnpBA0tWh9saoUS44t8VlBXD/OFT7O+xKDMEN13u4G2QwZEToNthijyht4340bPcnAGz62eeRxnygvrfrvxV2AWTxeJMDf0PNzkHgb/6ZfVFipb0Yy+oNAPWioWdQg46hbkdD6q0lKzxpKh8ORWqTtQxd1k/BUdGSVsZMzEidew0CpumZu0w== 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=TI6g/eWY0jGBBNuTgFPmkbiX1GxAW3a1PW1IYRGge7q+u1x52JErFFHRYRHom01puho+4PGP27x//gvrgLuORYWNzgSllv1a1VsmkrrQoS3T+tFq3Vo8dwcVy4Wvg3S0dGdTCiGbzODg77PIDg6OEH78H1EXalE/0ApLIGFwOg+ZKRUFv+dvOajROsG5A518bftt8ljeMKglfLaNtq7hWZetaDl9QJIDwHq8FZRop7aJaVJUhnG5Pj89oYQd5tKp22IJMnWsBK3i2K3sJ+omtmOwYR771t1u2tgOgveiRDYi0minPMoKHUTFOhf8hezX2/4HzM4gE33XngXMA3Xurw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:32 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43:32 +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 v14 28/46] OvmfPkg: Add support to perform SEV-ES initialization Date: Fri, 7 Aug 2020 14:39:13 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0801CA0008.namprd08.prod.outlook.com (2603:10b6:803:29::18) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0801CA0008.namprd08.prod.outlook.com (2603:10b6:803:29::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20 via Frontend Transport; Fri, 7 Aug 2020 19:43:30 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8137ddba-476b-4d0a-2a92-08d83b0a2a34 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: W4dvaDlOR36J3iU9gmFCgPNKlrDbvrIphQaMFeDwT1wsVXXkz6DaxTKFlKfIjE3GnK2S34I55ylirD7Y+sK8VMDCPg67G74TW7ILp0PQUwxAOANMI2mBZXdGZ5nzH7elIJFNA6yVLYqGGiwS4QxMvDXQxwYMYWSYlXR5J6z7Jez0OIeFDfD2m7Dmgj/yIseWYQ6qOCnrzbPASVDyac/c74Ox/MrRDRPVnMFYROneWZsdB6CULX6ySDrPuBZwfr5daK3hgpSfBKzsnCMD2HOudJHx22FiGm31JikkFiFJWOFo2RMKPm4lDcDnHdW1d/CpeyModvpALA2d3rOHR7yXbxh8ZMHXKAnWpE5zljdyobzRBRQgQp1xQmUnPa5sc1yuN5I04F7UZysN36D+zrxhEWTZazlwmwGPxIryI9Cxv/szlFxLeLRakQ7qhLh1ggHYS08E9r9+1T0M1Nm8enwoxw== X-MS-Exchange-AntiSpam-MessageData: p44qzkq650HbA3pG60ftY4GmRNevynUxA4oTghmfz/Z3LoYLAT6vCdKwMJ5kH10PyjhbS+YFbq0aPGC4KBsO7UXj0BaGVHI9ysVveVX4yy4bwEYY2FW822TgAqcmpXdamwiOcE5P1nCvoxknT4wVRUEm1YwEUKgEfX51XSqIU+GcE9RyvsC/Kqbxi1ECPfw4++dq3vF/MFiQokUVNsJzNxJSnx5gxoomdHPIt4OiQc74/9CA8l3R7MO2NxBfhFWYr1KzzKcbFuHRExVFzNHqDIN3dbbiY8h4x8sDH4af3+z80NAqjVrv8R505lhOi/AD113h4t6wbJJrsVvWSfX50c6biM1j0+GaXkiIO3H9POky4FPDWPIfwxpu1Jy4D9x2CQ2r7AoNKdOIuxZFimk/wUK2PpQE6sdou1GfjogRdwByLqHoy2ivSS2FIvY+9EYGmwjQdMaaWCVI534v+I+bsjmeX4thlGgpQn6Pn4eHkehIbUaiAQ8BWVTLKga4X1FLk6b2tA6SKPlQir0x/tXfDnkY8nz7YUCK6AdHLHeR7Dc0Lq/lv6Ky6pO0V84fHkJe1qDOtYLoUo4CFh9TFHpF25Up1fY2Vnk6y9IRBQWuklNqoqafaPD4ELBsFNfNq4i3qkIszvw5VfhvjuhqN2znPQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8137ddba-476b-4d0a-2a92-08d83b0a2a34 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:31.9207 (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: XQ2SdVob50zr4J+gAvfAn5XbI07frcl6fgeiPfsH8JjW1ySK6I3VjLwTli/hNdetcnRnL0+nUqCRsQyrCUx42g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: CtpBIzqg2gq23X42aWpgQ3iSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829414; bh=3LJPRAikNdfIzcQiHOU7bajKFjO8YrMHIK2K4cRtmrA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=F6t1IwwYsj4flofcoAdWGbCgXcQ9Ypr15jRR7FlcBHdi+u2pC1NnBgMxXjkUaXkSXLl Vs/bgWqo8GsC/p8shx1Hwz1woeA0AFvJTD1cZnr8WMEUIORrgMBqw0mjqwrh71ClRW2wu VpKKtqGNbX9F6Sw7YZA0JlEPvyk6WeFzsS8= 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 (#63870): https://edk2.groups.io/g/devel/message/63870 Mute This Topic: https://groups.io/mt/76056559/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 Sun May 5 18:51:34 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+63871+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+63871+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 1596829422525856.4093044941652; Fri, 7 Aug 2020 12:43:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uSKnYY1788612xHCIXyBNNiE; Fri, 07 Aug 2020 12:43:42 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.58]) by mx.groups.io with SMTP id smtpd.web10.4223.1596829421610048529 for ; Fri, 07 Aug 2020 12:43:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lL6GNsiRWiIJWwYvhFHg1iEJgp31/RNmRA69sjbSA3hVzfwZnhmUohXuB6DTumNoHWSkOsTEIUzxVIBvxMenJynsIHzOvlHz0lqcCA9+9gTHTo+iUQhjbQwNU6l4pXBJhLsYecQPy/69xbi18Yyk5FebLjtj3McRRdFyzHt8MIhnF1hbHGl025EJz4r5xSCGUB2nzws2hC/GLqvzS7Suq+Dx5ADvDQqNYOqC6NCwasa1p0SNEoEQlcrP6ONwZalY9O3FtnNAsFVTcEDC2lw8BqVYNZs0WID0Shgqm3N34SSLqNsCbDkNeeo+Djhf/aJKyxsmC2BSEmda25Ecm4R+bw== 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=j1WQjYJNVQ9YtFdNDYI5RxSqbCQiw4v8zViJeZFNHlg=; b=aHK4R6NGQtmSjxnpIaOL7vurAfCjZYGM1vpbdu4IKDvv+7GyzZW6cRdLG6mR4FK7O4E2cEdUPnryUQSGxW952hWvvZnjbYTiu04uo4+ACKc7YQmuRCz+AgW56j9TPnXWX7TW7B+6hqE0oiua/5V9iMYAHKxxiXMWyZK2PzOK0HQlOuvjvOkHs8JK35vZREQG0QmvcdXBHL8gpjWnNIhExBsPU4ySAxPHB/2LPsSLRo0McwBoM6X8O4D0HKO2kecgtTZ+y3H6mRDW6PR1wtPqwIsQ/ZbqmMHIbZhRJmQm1SzudhXQRaLCv6zBOObomp2pcBIVlJTh4aoMLrn0aCZFvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:40 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43:40 +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 v14 29/46] OvmfPkg: Create a GHCB page for use during Sec phase Date: Fri, 7 Aug 2020 14:39:14 -0500 Message-ID: <5e2171228c13f2530b59b0ed3a6e6b15cb3c3490.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0036.namprd02.prod.outlook.com (2603:10b6:803:2e::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0036.namprd02.prod.outlook.com (2603:10b6:803:2e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:43: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: fc55e53d-b6af-4cae-f904-08d83b0a2f12 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: nYnyGFlHMwKwjMqbOvLiByLk03RqoJlbB7fSAY9XBTOqkegK9AUG5dZVeRL2P+08G9R4BnQdzVKjPeSWsTKX0m/b8CaohPx03U8xXMDnRy6aOhc9QkB2/mYsNFRPhRpPaz2XWQCQfMLFQqHe8kAm4cNiWy/XJeH7a04lzsCgJPeVY5jCvpAUdsPBhxiMuU0zyezyHEMrOANgJ4McegH+EbeVzUMPVA5M4ksSM+I4dIYsJAasfI008hj8wktcni8fk9JbOs1Rws83tubDSChlIeK7uTobidGGLsjHzHA0i2tz15nLTb9ehBobHqXedaWSWY4h4PQCrWK4tQIly0fMd5vUbJsQ8YzsmOG5YL5T7iTwd5jRuBru6N5UyDsiV6kwKFovFYFfJ0F9yK5RWNqlJLf6GQaIB9y6ucBaz90wTWQVOueGgkbaWk9siLjiCYdIO9MwtHSTHioIuyeDLWtnBg== X-MS-Exchange-AntiSpam-MessageData: Fuee4eJb7stST4bk0PYWmTVs6gxfFvZCrjHZwEp3CtyzacsZ6MJ08TgfqeJJQ37XfQ0skuI5LaDWrOwp3QjkEiJrvkCeOuBqUyPn4YbAvmogkr/uqkdHyEm7ykipxVzznErBYKfy2fbrDxcwrGhr16JM8Xc2FsRbxLVxE1/MRAIQmqirPOUVmkIJIwYWy5/zurkX6XZ6Iq8IDYMwjKgkQIWEEqqL/bBwHDMFJ3W/NwvEoHA14ViJM/JL+WuddTfpDeDPS6I0vrq+/XPu5C2mpXkClW2P5vgn5lfGn3O3n2PP8G6KgZ8p7vQmhJ/O1kFMBPM7OYToZOzevoyj1KCTWmDsLQE1JXcZ72zqSycr8AHcFuCl3iR6GwPtxW7zRpMZrfWN78dDYkT2MclhZoHpMRpcxUFfLYQdL2RCGtv10Kq/BmUZIjBxFdk+Ofc6OoDrhKRzM98J7VdRZkkTHDJogWnaUZd8ZWCX1Hkz5a956fDasATQ2J3oLDtbTe78X8i61emTfzk/zu2ayvVC9F6mx+zRaGpJ6RQPzsOv/Yh8zX5CpyQu7EArunU9h3rQJ6zIZ3zwnSWxTq4V2mEuNhJR6e3LcqeogF2pP4hxG6K+4ScWoINIF09c2Pi/sL96IVPoymDGUNJ8jIIfbwKros/urw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc55e53d-b6af-4cae-f904-08d83b0a2f12 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:39.9938 (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: 8LYqRo71d2IETk6Gf85NQTH32ryEyJJQ60HgWKh7go38+AbYRSVLpjaK+MMoWyPpIc5pXcLSiKoDZ1aQfHrOQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: pysqdjytZfcMcDmL2OC2PNuZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829422; bh=k5YwcJZTd1jjCLI/fq3hiSNqBNxWfxxIzVHcz4BY/yk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=T8+eUF3yEOjVNEWFYWz/tanpp+oJiN5gpbZv6cVDMjrtEINzNn5oWLeAgH8jZjSMIpM qbzfEpJB9qU87ZU7sWhG1HkFMyBHQewSO5v5pu2nAF9yucYjWc2CiNgswp6E9O/TEaG09 Ig/xOkhnWu14QqzoQn4rgXhpcKnZY9zbWS4= 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 55bb8ea91a00..6abde4fd9351 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -294,6 +294,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 (#63871): https://edk2.groups.io/g/devel/message/63871 Mute This Topic: https://groups.io/mt/76056566/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 Sun May 5 18:51:34 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+63872+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+63872+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 15968294324231014.674217121455; Fri, 7 Aug 2020 12:43:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6qc6YY1788612xuLAYKugnV7; Fri, 07 Aug 2020 12:43:52 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.40]) by mx.groups.io with SMTP id smtpd.web12.4268.1596829431419869950 for ; Fri, 07 Aug 2020 12:43:51 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gok8MnGwLB14RbGoVYQfVqcXUGYvJO+gH8Xy1+SB1bnbh/6QnKCv4cY8zNgR+D5GRQ10oyU5LDuq/Z5NcPq00/AumSdvMkoHA8KaiAo9mYCJ7W2TeRy/38N9opAk1jsTG9O1Qu8Ld4R3ALxTApTHC1jHGuvOVR7C5R+qxD3ZxQAUxtR/SFk2qZn4jtNTgSAa0DGZMu8ydIV8aJR+ZKdzV7On/CoV5gknFPf2vCTwLeOK+4m3bAYukf5wEiiezrEK7h1Fu/4jbMhfR/43cedZQiKLKhryJzUUgCOg9WkUbeFbBGasq2111g969y1n1C4x/q08SnCq/pwbM7FdabXnVg== 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=ai8sfg3n4vE46quQcphNWX/4r/W71mIiWvutZylNNMZLN5EB1NKfEPcJDQ7F+9QYFzQHre8Asr9kfPD1NPFlMKojiHUczsgPjCZYD2SMyJBgDpKpSrP21nBDhRoca6/G4b0xF3dhNIuCK4CI/FHUExmkilzdtbmlB6AXiCvPbpLnehMN+y2d+KqHmFswm5ryMoSrQPOQn/EV4yqDlSHXIBf3OG+1W8z5OtzTTnucRo+/oTysI2OKVCbzhS+twEbpeIJOaQOPi3iXY3Tz8VTHNmiK2nhnbS7R8AzKxdlwJED74hW4w3onWMNSiCqdWYm1IBLQCcpP85LZmd5Zm16Uog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:49 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43:49 +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 v14 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Fri, 7 Aug 2020 14:39:15 -0500 Message-ID: <0bd30e9ca2b14309a0e53d170a87ca27c3ec4ed8.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0071.namprd05.prod.outlook.com (2603:10b6:803:41::48) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0071.namprd05.prod.outlook.com (2603:10b6:803:41::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.6 via Frontend Transport; Fri, 7 Aug 2020 19:43: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: 6769e97b-cbec-4ef0-9469-08d83b0a3495 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: iLiZ8lszZXNO0GHEgPH0+3oK/dZvkZFNITcSP7E9ZuvDLj7jZuu+W+GxRogbDjvcPnsInHDDCidDdru9r3TcFhlN5sC8oeOYV0ZS1C2ZJJqH4LzjmqlL40Ueb0LMG239ntocwFk1RdqfHwFm9KV+fAHd3injFo+Jj82Ldc5V/B3OhYJftbhfU1AfNphVGKaUSCFpGDjwq6vKUN55s+goYCtSlbwCuj9CvZmPmwij9BnSyDSd02w2YqbNr25vBwlMXWXSPClV8gDzLYlHEmgNc7LMvRy8rciz0uOLNh0/RkWZraxh+adS+B/cGK1UtXhXcNl2k70cX5WzyWuZ6SD+6E3BGDr1PkGCpdxD2Yk2lY14W583zPbq//7ZXslV3EWNLxyBVYc6Hb28u9IZFQWwoM5szfZQ8PHdjO6wGYZtOiCA8vvOMHXaajQVfDwyC9sjTPqnXwFThoLbcfwtokbUeA== X-MS-Exchange-AntiSpam-MessageData: sIbXtUhSp7c5b3jJ97wjZMy4SIIXFXOGF6JMkCbcWI+jpzqqHWbAlXqoFpF79dnJT8Lb/mYltldE2Jn9RCUxWZNIkVp13FoImmts/WjAlAU9uETQvaoGctXiAf1EbakdZ76OWk8HEZLoFMqt6x4dDKEmpcvBkEl7tU0g7H8N4uS+xRRZK3qumjxKuqyCC6birlvQf1aFQS5PV4r4gyenRYVKi7ccwGmy7kpzXEwWjCoWhpfQx0MRHMGO8THn99CG6ewVn2rxtf6YwkCThLdGnzMmMbBvJ4Y/t2ieCnTPFrw4PUswLSHJ+Dgo4kYFHIAH7NLJzvtj6ydGCZ9Uygv3umNJ163eqCCg3x4N8tcHt/FeUHeQ1EnpzHnqLFvUBuH1LFHNmL6nLXr9bEO3St2PtmUCwP4bjk4GR1MXn9a0NwseADogDYxXK1q9liuXogeJlp430XxtJMOXRx4u/4oHelfuxrPqb+JlyfbZ05oKRpPY4/OhFQdmC6heNCTICSjGueTM+tM+6GCKRCB1feVyLoCB4PvQ37hYLN7zWRUUHVJXPFRMX9QYxzye64/wv6dI+Mmms2yDejYKFHQ5B+rr9tc7X/wiRaMZMjSL6axFVo50hxxOe08RMFNd7R1+FRjbBCOQ+/gE1UDgQ5+gzvaVRg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6769e97b-cbec-4ef0-9469-08d83b0a3495 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:49.3133 (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: EtflcOXgoneyjs4GFzsfLi2EvCjZdM74HndklHRoRrTQKQ0LjNXKWGwMoT4eCLO4xsLeL7qOzjhGoIpdX7z98A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: 7Oaq1rvm0GgpjfHyxRwUKY70x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829432; bh=OtJ17tEoL8ynXnonXa550Vl61AF2bWpnRcPCd2LVrP4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Rr2moQDoH5ujIFbrcpJwO8gcbUmevXiYJ3sNkHCH4BdSJTUIkCQjP6lfgQiicGmMClB Yq6iZYF1uOC8p67WKw/S/ZMwWHB4J/gSwA0V48E5fcKGJV63hb27t8BI6jBUAVcXUBIlE WHYFX+Mb71alCwYjWq1XRd5/X6c6XlWnwM0= 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 (#63872): https://edk2.groups.io/g/devel/message/63872 Mute This Topic: https://groups.io/mt/76056568/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 Sun May 5 18:51:34 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+63873+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+63873+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 1596829441181248.123600272595; Fri, 7 Aug 2020 12:44:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id i5nvYY1788612xo0Y8IcOAyL; Fri, 07 Aug 2020 12:44:00 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.87]) by mx.groups.io with SMTP id smtpd.web11.4287.1596829439227520675 for ; Fri, 07 Aug 2020 12:43:59 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UazG/e4sDuEfWYIjbNgiOES5eqoowPwKfWtSC2kHBWtTutb4gz39Fssvm5XLFTtsSl5bYExPaso/xC9JlsFM7edWl6a7/vmkfcAayFBz/qIy/dPT5UDpJNub/qKLlf3/1HiAHLAktnPZ4DEGORn6sdzv2tDNfl5Ay0yG5V4HStXZDwTx5irepiGNtds01Y4lIiilfPqt5cDE2S0aUq9A6dGFcysATYGXA2l+E5f+KWBhEkgETfLX9bpE4cCkW6FjvT2wGlCdwjqgBDm8VJi8nLrcWq6SXdWF/qzyDoECL+eDJcdoLmpZhnlFAciv514+7uLpG/oTTGMyFnVEj368qg== 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=X5S26rE03gZo3s8C/6bwzXX3clFvtPzjPEcgmfrT6XkXgJOqN8DPCgKS8abiVH6fRoKl5xMDndV/y5KXjUMi2Qsb3NhgKWZOJvt79XbghReq36cWKo5uLanCyoew1CJ6zn1J7hRD2Gn2Mj67Uq+zvnRK0RaJ4e9Er34TtxfJNFyTDiiiTG7nYrdrqlcUkm5FYt5tMRIM7XLxBPSNAAVOemMsF8kRwChfBdXvS9yCD5sHM9I+oaxBGbvQRig3hnUJRclPLjH6jHU/8F5lJL0ZqaeFu2LAywhx3Ikh4Z7XokQ5AAJaue0dsNlGpuhcdi4uzI+tKHg2H737PhrbqwvMOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:43:57 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:43: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 Subject: [edk2-devel] [PATCH v14 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Date: Fri, 7 Aug 2020 14:39:16 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0007.namprd07.prod.outlook.com (2603:10b6:803:28::17) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0701CA0007.namprd07.prod.outlook.com (2603:10b6:803:28::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15 via Frontend Transport; Fri, 7 Aug 2020 19:43: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: 0a3fd553-286c-4474-e401-08d83b0a3989 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: Ej72lM8FhIKUlKawx1z306b1AIFIt/2gKonMSBDd6uI+ClL5FWOYGJ+DuI3UtwOE9puZzG8F+MyLEMKGi36CzxMBFloUeT8hLu7Pz049An2KfqzasqbFMq9tDPz6hjP4MPHgS+F2Sqm19Fp4/EQ1e80cb6uMLZc87veMIb7YpA2xh5r7kcM32m7w3cR9ZCCQml3Z/Y3aIA4lzo5eWUZZUIFibIHRBih4N5Uj3dUUw7kNsCSvf5N4zRRFBRQ/V4IluIntEwKPWKOXG7d1osiDELFz62E5YGSZSUPPdYjlLKsvWpJivqdVD52o72o7d5/OtcSHrslG6EV+81ZCiuCmdNTxrPy7SYoRvydH9+I/PO6RQB7WhgiOVD/EPxXPkoqd6/yX46T4eE6LV+YXRL4bvx2N2mBT43OTnmIUPaL9WfEJp+/GiaVp8bAN73O3ZK33j1/Gv0EKPlQSSiaMwLJqtg== X-MS-Exchange-AntiSpam-MessageData: 1k7zilOrByYJVCqLla2Vv6ew+G+ynS8h6w4FD29S0TWmg/yKhBO5hpkU214WEwXh+PeyXpLSc9LL2a7ycxE+gsVSUu3H1PEO9ivLDhrkJH16DGLIFRL6iJk2JAGKYK+GvLpeJkqQwYs0DaOpp6F7lR3sZ2ExQA3NroJNnMW49kBcuYhNQj71wVeLGW6P7gY89ST13siHC1GRIsSyZxBudKYn2d+AzydGN7eZHvOXavVXZWosPcCEIodIQY/9kkceeVKB6kpuI5ulap98Kzj80itaKN1I3fDIFYWiOzfm6H3ngWldwwHAD8DEezUIRyLcGOoKKkwmCveOsoC5TTmEpcm67P82+VOoITYnxP8ucI4QRSCO9tQkpNkU6OSyhQSYonVONm5OGAb65b7fKHXusT8wmh5WINkSW883Vhs2+wOhBQefFlSny5WutWdid1/AMtsDyfTGpjQ4JwBjAL6pxNs+Ixo78aZqgJncTL3okE5UJgUzuM53M0FbNgjx159p4aCEuNaomU8hMwCdPA59k6CqnJZqT9kb7zYFbRREVkz36YvVm65dl/OkGQboiyXB6Xp5vX0xCFBTGsQ82SMAz5e9fZHUTT3vipIwCN47v2ckibUXrgSC3wy4QIQ1pKFX+rE9UxxUbVCyeVTae4fAdw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a3fd553-286c-4474-e401-08d83b0a3989 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:43:57.6213 (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: GVt8XeO6rfnd/a+xixX/AJI2+oR0m6MEj8soQ9aH1IQ9OhVPqgE9RzLLuoixkANPTsU6t1j/3VZQMeLOlvu9Gg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: Q840fAQSx0iPvsxsKTEMQIFPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829440; bh=gSnuQcOEWbUeEweYXvdxfqqU5kK0YEtTHzqU+3EvZAk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=BwncDODaB0YqwSjKD0eQ3BggOkk0w1Qu/yUtRtnBmS4s7rQLbw/gGxtmNhNJF6h4GTF EShPZD4B+RyIHCHDpM8E6QwvrNG5pANVwdM/t8mV4y/3jrZPXkNOsVl3wDwTFU56+bTQO BIip3OgOF1P4MgnWjcLCtlPQJAFs5krHXbk= 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 (#63873): https://edk2.groups.io/g/devel/message/63873 Mute This Topic: https://groups.io/mt/76056571/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 Sun May 5 18:51:34 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+63874+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+63874+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 1596829448504860.2562106224829; Fri, 7 Aug 2020 12:44:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lJTrYY1788612xA7eq4Cy1BX; Fri, 07 Aug 2020 12:44:08 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.66]) by mx.groups.io with SMTP id smtpd.web12.4275.1596829447521431016 for ; Fri, 07 Aug 2020 12:44:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kna5ql7dMmEJ9054voAXw8KqcsAhJCgH03OLst3LvyAt+asiWf0nV/6xDRV7eO8uNLTrnf/8WrtQyd5Ytubpz/jx6Z86K/AZ4kBy6kaYPEoNt9Eazt58UiVgjjEnq1w5rtsCE9abkew+GfZz4k8VQT9xBuhnZwFVC6f12fMCHknkFnD/Ox+lTDVNha3jGnB43/w7RiBHtRcTmnI4JFVIW5a3GF8rO79mIQrIWrVDkLe1X0X0mN0aHo5eXARA7ED63Qs7drUB8MKLE0Sspn7T71imx3+A53QcmcHFEvjvrMRxc2J56UWO09VSW+3rxuQmNjkqI8Pz6WtjDKhWG9eBkg== 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=JuUQXRc1GYuIdTzgOnKgEyWxODAuHC6Og2aQ9TSjAiL7v1wteWdkCB39K/6mYF0MDkCesrvS+Ggn0MltjLH2kYkseadnPt4UtWSFUkqJRQjOxL+woKVS2LzHBSL2WqfMa0ECUmfXVstQGKP9tYGk2GK9mm/nffCWypX0RxUTJdFsEPsiciAqC2wJAuk0IcKV0rilB3QE7Yu8KizjnUOqkeX1rDfKrUpN51uXUWF+/3nB3gil5ktqxNApuhtnjKQo9f9rYFirz+Cr9OTIZURuVKZ3+sDNmX0rFm5z5kHn/cOZinwQazH+gyGU1E3sB0MKBjrP8O4VUDmlAgRibZwllA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:44:05 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44:05 +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 v14 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Fri, 7 Aug 2020 14:39:17 -0500 Message-ID: <53f7c2c985783a941719869ad74778e7366790dc.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0004.namprd05.prod.outlook.com (2603:10b6:803:40::17) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0004.namprd05.prod.outlook.com (2603:10b6:803:40::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 19:44:04 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3694bf85-55bc-4474-a4b4-08d83b0a3e77 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: XeG2n+m23SHI6qLQ1zSw6eLSljCPjSW/wkhtTZfeg0zGnGrdul/4Q3pzz8uTFmZG/YcCLyK8Qbxe/5sm8tQjRFFsSH7QAf1/kpnOQl2q7TOkXsg2R3sQgsSZwoU1nNE2wwQ+EIoMMfLTOFmpzc982+1bp4y9aD2RbCQOfckLTyQCqipX1pPOxiXqGc3sXko4W50kJG62jfIk3MuFj2whux3nqolXqsTm7VEKlfZx/ipcxIdFfSf5aaYIF5SY/mUTV6pd0StW3t0mCpHb7IvCrHrf2XdsysMftYK3AFilC5szDny7ece//o4FL4fQjuBoDCQREny1oXi9yr7+DbOfsbUZw3wH1UNr4/24ZqTAuBo2luJfCARSa9V8O/2XX4AlA5WGkEaBUTrbaypbn/OwT57pXA6guZPBHxY9arpdIeJbAYu6YucJ6h/b6D7+ypITt4jYd4zhck0BzVH0MlJW1A== X-MS-Exchange-AntiSpam-MessageData: jhk7cMvMor5vj8wLXa81eC99KOuW8MJozqW5DOXH4nWHLtTIvyPEozJVNNUi3Ojc5MqW52Hr5vZbgkbqbLz9oGLRR+C/sqiF2ylphqPI9ZL8RB1WXSK2ukBpH+XzeyC5x09UbzGcBahxLYmnmA5Ufs/lr3kwBVkFAfTj/VQgqUASgkt/TZYG/EQ5ZDt8cTDqdxwBGQCx/vuWEG3cGctWRRI8czd+xeSzcsgjPd/lyAFBA7pSNF8YcM/2fb3S2rxsSxE+O/L25dp5K7bS8ofrSDZWAgLuum66gW/chq7Qex3CXvBpQ/s7rNj3No33OMIJcGvDFGbi9lpE0Qw6moEgSFizoaQ2e/kfmJqcpB9i3JC5NfnOiM0LjE3pzrgnJx1HWRsjjPVirwReankyGLjXDeJpne24Etm44Rdv310q3hYqTyoaX6hSxv0QKokTZTPdCk/pUGAw7GaUMi3h/KcnDRL8tO7XfuDKWG2UBUUZ9KdeGN1L197Fj9YG7x+AYcmgJMgoMgHTuRcqY3yKvcUt7PUg/5iIKZrBOjELXKoADKMVaYYLdgU1gsWMvySraG6d7gBqznRxxK8EzxGhdT2eqx4i6DBNSGLK0Fcj5M+0J5oc70uN6wGqbBzuC7TbG7a579Oh5B+ilg0eWpmzUZo6Dg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3694bf85-55bc-4474-a4b4-08d83b0a3e77 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:05.8174 (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: rsgc2D1ESD7/LodHxXX3S/bPAb7UZYshPcImWWzqsH3Zgf7RMe8XvX6H0CRUskg29FsqEO6o6wm4lZUOxeP51w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: whNCUeP0r7KeLNGnHMLBRQAix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829448; bh=3XmHiiWiV6//gFKW+RhYqeeb4i+lpllGNkM4Y/mjU7w=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=RrhOKexYaSA4QwG3UFFSf3uaWZzSAwK7FhRs9dU3OuEJ+l6pBlbumdRlwYiU7uxd/2K SN/d2RFY+7tb+JJ6RhBEivYY0dzdmG7EvnZgjd/UdrqgBmTLj64eXTvWHPh6KM1gaJPX2 9W29FKzLC7Ewk6RQqX0GmD+zOLSr6Yx0T+E= 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 (#63874): https://edk2.groups.io/g/devel/message/63874 Mute This Topic: https://groups.io/mt/76056573/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 Sun May 5 18:51:34 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+63875+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+63875+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 1596829456536584.4082381699388; Fri, 7 Aug 2020 12:44:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YTJVYY1788612xFuFfgu7SZB; Fri, 07 Aug 2020 12:44:16 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.83]) by mx.groups.io with SMTP id smtpd.web12.4279.1596829455609703688 for ; Fri, 07 Aug 2020 12:44:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eb2qenBXISHpL4zTw95GMDvjv9XLmKoAWQJ+80XxZxhm1nS6q8Ktsw4+Adxm0M5a3tr18FlQzGZ+gaWqWv9Wravb1npOUx67PS49Fx99/zxcmATgb5u5wHfItF5clcrcLFeDP8JX9+m0VeLeXCrE44t565pxWp7nqaSyb+Hz/yqal3v8AXg84gEoLsSnT+4f51IPuvT6BXzbbmP+tI+pc712F7nDO8tA5SZltL3tMhlIBo2mQKcgwb0Aq1MNLhirVE5JHw09yoIk981Ry9eaOadkC5nZm0A0GCEZFv8FJ520i7xVj5xgoB9EM+mjKWpFEFBtQnfJrDv+bi5SKvzH+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CkUCsVMLNx44eYiVyLCG98C1A+A/KhHynEKCC72EYLo=; b=QgzKCQR0dEw4EjDJHuYcGOCuAkfuXxCmAgxuHG+SKSwUgRVGKMBGGO8uoEmgWG7sEZoEtho1wtxh5SBeZTpOvzHNQgSujBVdnwKifjpq3KIj+mAGkC3WxgZe7US4Y+OKSBRCDXVVbJ1Ho2mK29jOYgm4ww8S++mCjltjzTyuct5QkmWSqUKLa2PnNyKaWOpqVwj2Ej/KgcEQXIMJ0uaL6oJyx8d5Lp7PEzhU4iESozc4lhyb7GsDbG67TB2SYhZrGChYl3Jf/L0+bI4ivnLQ2/X9vEYJ9UDyFDhTaHWOHQM8A77XIf17Rzj1ssWX2UHO2SgyEYEAnN3D5iGhynXVqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:44:13 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44:13 +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 v14 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD Date: Fri, 7 Aug 2020 14:39:18 -0500 Message-ID: <26aea09a30e0463b18e54ae9ed900fa70f2d10ea.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0023.namprd02.prod.outlook.com (2603:10b6:803:2b::33) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0023.namprd02.prod.outlook.com (2603:10b6:803:2b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:44: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: 1eaa33f5-0e7f-4964-1d6e-08d83b0a433f X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: szB28nHYovGlmh3e//9UM9alBDk5xn/rVppoHUKnYFbM8S2FFDz44VzgruiMRYV1XdHNrYjt1AP66zEp6Xs6dmtEVA9q8dajHl2x9JsqmLTDlAYc2FUt95oXaPXal1sLN6KKN1F42AC8VCxKXptISIvfDwDwJwANkHY3GY/H/ILxJwI1ZQsRDug64sJu1P/oYqxJX76tiMSZhkgCMRtgTmwiEwk/lPac3/gr6/S/kyngJHKSiVNyMxWpJWMMd1+VUtwqxyb8Tk6JXOe1KVDi70G2n6mzB7wBe+/PAlMBaaYt0vqpEwaQ/AV7g1ERer/4wyDm/0II2VXW/cCKVjKHrdTZxZC2lGsChOMqZQpDbUH1Nl1zAJ1TPtsJT2lpDjbQQzvS7pWi2j76QinG01xeOaB19LUdcNIea4rDEKn5Zxj0SI8SeGpHAq7+FKMRgA/7aZcD/CZ+hKEBxJVi+ZJdyw== X-MS-Exchange-AntiSpam-MessageData: 6XcSgMT/O2jh5ADAFso9davG3YZAUcsd2dGI00JX1+baFlvqNMoPTjMVDk6o4xTpcmAmu2/VrdDWmUSVPLZHzTj/xmn0ie6sZxQNAxqC9aXxbDbEo1rTiCCfeoc8LtB2i9I5NVy7+OczET0vGDQGtCGLI6rZaW1PX8mcieJ1Uf+ZL4cj/UGTLI2vSz05OHTpbr73UtT3NOADf/gBKaNHnScu7t7AsbpMS1KNb3NF95csPJ1kKSuu4rv+22HqKhk1yZ1yADZ7/UrUOoDMdDA2TfUQo/zhjt4LAb2ycCM/fr1oZCOOKq0SEZMEwl68MGG/hiWabklYy0zlpg98Jm/fYVSuLQMOdNnhAUZ+xTSz+wZT8gwvNr0DyIR5byEb2WCKqOlrBI8CdxaGp5+w8z1JYBwnSLs7keQmrj6cbLzFbW9fS2z5We7jpdRcY16+Nu479ntOp44uGOuntv9qEr3Hmj2AqId1JYndHuQPmOEh/OHgYHZWeQnC/XjbMuaNXR6kdYaXtay7krD3Xs8tOrd8NYA2KmDM28q8T5cHlw37Trkf9DmPWQPlPvdjXWemceeCJXy5D9YtICu17bdCgct0qP2zTEBgm+ANvEHGB7AUZf9JmYTsMJ/EAGxa3+0nJ2egy27TmNIhTfHb0yMk4g74qA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1eaa33f5-0e7f-4964-1d6e-08d83b0a433f X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:13.8545 (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: 2QrL84B8MsXU1/JTtTHpM83h8HtOjMg53OndYWj8pZYr/8eJWYG6aJba1vNUSieJWqMsYuvSAAnMXga+uFcppQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: OjXX7jA0j3x8hQYb5UHtP8gSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829456; bh=so0zgsFtlyqD8uybswd6/Jq/6OTP5xLxvSZ03WWh3Jo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PA3OVB3S3ApRmVq+C1+JODx5HM3/trza1ODjmtnSrO1m9iZHcHEyWRUG4QxMyw9W7ef cCRkkmQYaqU3UPvmidF3NsIO0FTHYX6nMSJjJgv+Yx4k7z7sVdb3ob7fGBQywdFe3K2Zc rvJc14L9TwS8Vwbw3yMdJIDsO9u5DIQBBxQ= 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 (#63875): https://edk2.groups.io/g/devel/message/63875 Mute This Topic: https://groups.io/mt/76056576/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 Sun May 5 18:51:34 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+63876+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+63876+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 1596829464852455.39273044442314; Fri, 7 Aug 2020 12:44:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZCoVYY1788612xHaPHLd1hXX; Fri, 07 Aug 2020 12:44:24 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.63]) by mx.groups.io with SMTP id smtpd.web11.4296.1596829463594213517 for ; Fri, 07 Aug 2020 12:44:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GDPZOfeDM7wsu5FlePLkzuONJb3vV8Ug8/0J+unJuoaEzP5ZT4Yv7a/iQCrmmQphNHaNiODwemSWGNeFiXqZP6U+Od/izRFk8S5mgUiBT/M3q3bQg+f/p2KzTGKXSFuLaA2qE4lJF2/gTb3eOGvBHvaeXQZDuz1wbxltP9oPjmZTp4hoTPqElxNUNQMRdw7jHOypRJHrlrD+R+0wGxyIepuqmKQuzEyvZytVwCrZTBy0yWbjW4p6WGBrrLyM/ii+KlEdIU5+MILMpWIZQgwhRrxcgYx52gMGectzukgcHwEX1RmXbcWup+58u9gpXvHXOMvE53AjW3CHxc+9SuQV9Q== 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=gwYhJCR+1khS+M6dp5EGb743bIs1bYUxYKv8exRtr1YhDFFizN5kV19frEU5lPgw5W+ljdH1S1yzjFjkpKF0zAlVfJcbLC+1UGm/7sa4Hrr2zKTVKe614+TJoj/+ZJ9N4fHY/ujEXpNCxpA8VEsxnpcLqsWCaMjz5P69QCZK/bgsxEosEh6egRCPFFDmKD3r9oI3kniyQLz84jppv3BAFzgYz4Iei/Kdbsa310pL16ofSgoGPPI5Wel9PkCEg8oHbZ4mA59XUvxAghTuwG+mM8YHakZ5DFO4eWcapUvqpGcmY8GV9pcyHKCfrmG5ez26fII1W0jPHmO+yBEtbsjbyA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:44:22 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44:22 +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 v14 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage Date: Fri, 7 Aug 2020 14:39:19 -0500 Message-ID: <837d7c1a293469566ed3253ff1573c634d74332e.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0601CA0001.namprd06.prod.outlook.com (2603:10b6:803:2f::11) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0601CA0001.namprd06.prod.outlook.com (2603:10b6:803:2f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19: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: 7fcd2233-750b-4a68-e685-08d83b0a4831 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: PNuNaG7swDfKprCWhvMDBL1/9OQR/Q4dhtt+1Qg62jxhCPW/pOwwuPG5eou12J1ENSsQbAQE5D+uY47gBRY8+KXVN8qSU1cQLO75Qc/y5gQdIvCDLgtONQxuKfCZh1rSN25iJu5+9mj/BNcxYoM+m0QefKMsSv6jjvIRDZbb7/JPlrUivL1KP5gDjZzlpfp40khi4GfekwQU2X/BIl9NXh8imBXoKzTax1v+Hjv0Y7t3zWO/cuxVX6Uk2RrT9I3Z8G4SKj2j2Wgmt5dwLn4dHF3Bz7xVgPrq8sN3aaC2QeHPc9eUoniAV37jmcNy+WOf5lIqXbPQ9E/Y/0iwwdabLxHFWdpOyGUN+YsDqTaf2tbulq7dUrz3+ONU0U5AgJoQDNb6XosQhAm51HgARrEuO6knwuBBguq6oO9D6pnbreq0KCN7j0Yh6d/EQguKJvNbahRdjZj7ZH9NMxjajTaA0Q== X-MS-Exchange-AntiSpam-MessageData: 6ulXwYF/jsxlH1QXN9jBNKPct+8p1Zgp0WrQED6xkLOSpzmR3VFrS1kDkbWJpYERC46NBuyMM20GBwQiToIzrcc9wZoXQa1W5DMLUudty9Wnv93iLeVeJ12Dh4+DxFUkQmIslF9PqPlmRBEFy1gZmVohyTNWvWUf+ztp3hzS1NnFARG5y5b6JqmihriNcLipmAYtXrAOq8MkKHlg8QYVlSVRGbEGm3reI3I7rsc80sMtT0WelGCRxf1xWY9vPcn7ghxRisAtvyyMxvQ4DEVhBo+e28YY4AiGovBT2IPgOnppSFTuQf1mwU50JBDrl6qwPau+N5YXajg8a5cOiADd2nhSryx+gnoyoxFMsm98af6wljSru/1iHbtH0JyRopY2xw/XRgtH/7o2bTIvpDgt32DROAlEU0gNB9XClsJ31TIC1WgRr8e5uPYk9MlNqh8CKVMQFTUX50ZxCcpMI/LbnWN4b7q+ARmOpjosfXOeFOw+1UzXyTS9aaY1jOsAPaG6YYMCPL5yyPdNEO/c2v7sGMMKRaHIMy0RU9CWLcLyhXWyZmUyk//VYEtui4Zj+h7DWn4Lbbha6fJF+Q3Ge/VVPwBLnq954cUQpjN7YaJsTAWZb5cYOGZ3FSj518xa34Yk9YpaIgZLY5/O6cS8yJYGyA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fcd2233-750b-4a68-e685-08d83b0a4831 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:22.1975 (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: Xwxqa+z+Wu0I9MLfusBitv/JUflofrwjsqHaAXD7W6Gcro4QS6UUT/wYnIto9v6Pac1TaxCscFGm+2rRt9lMcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: r9rDRZuMpC1GyTr2MMttCv2zx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829464; bh=WxkSQ3K7Im17PwWtUmJTMlbSmYtga5sczUL6Bc/mvuU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ASELtD/v06H+hy091gtPieEBcXskUpjw9v01pevaaW9HVdwmjrFiZ1y6LB6JH2VQFqx 4LaTUpKVSqb9RaFmM6khc8vQ8+ko/3cuamDcriY/fU6RvbunsX51p+MDHTNy7cxVGKikV qU5J5CyLKoCFgZAz2B39VPgSvutHmy350yo= 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 (#63876): https://edk2.groups.io/g/devel/message/63876 Mute This Topic: https://groups.io/mt/76056577/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 Sun May 5 18:51:34 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+63877+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+63877+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 1596829474359526.0936113832686; Fri, 7 Aug 2020 12:44:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pY3iYY1788612xejdWEp8UHx; Fri, 07 Aug 2020 12:44:33 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.89]) by mx.groups.io with SMTP id smtpd.web10.4245.1596829472340420794 for ; Fri, 07 Aug 2020 12:44:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ENsD2TDmeiQM71h9Hr+WKV6bHGxgWjpHRTWtLWKqULKtcB/DTwXju9QtvGultVp+30muOP8XxL74MqyGHzb8Ru0IHaBIAVxojb2o8w6P0es5nRmiEAmqcPpkso4vlnyBfanWzSKfqs1Fu3pG7wRy37SaNKpF5I7UppTW2pP5POvpOVM2J3SgGgNWgXXr1I+xi6BN0tk8P1LI2na93cMCj2DS5tpOpFnwq2E7ua2IlRjgFEr2ffrFsBOPe6XpCbkeRBiKA8chTVkvMeEkaCoF2NH4LXgtdOHGu0KP6SqXCm3KFtBB0dWG85lQRgYuw+UGu74WcBv0jCwumqos2Cqthw== 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=ZOxL/RWdIp0l+Djkfphw45RqxAo0RmWfKJ6Ok8MdPjGkL7Oe+OqwkPSTBnGrDQMnIm5D9iKtO85t1YYCy04Zn95CNvns2NcMz1Rqy4aVTqIYLj1f5hivFB2xudrnlz6tV/90Zl+TL37mlmqI1t881I3qYV84cfx3SmNes4Rglmkuxl4VlQhK7P2kU+LAw7rX3Ar7x1Jx4HuNCFOlbgljRMqA6nI2FFm3bBOHQzjgiZLQxFGVkBA4lumyebzDaUSxSLn+0QLdxjnosV7+493+OIa6RZqN0lDHI/GXTLsIdv6wJoDG3lplZeSBe217RVZaCmEQ5UsgWXYqLPkIMHwKTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:44:30 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44: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 , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v14 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Fri, 7 Aug 2020 14:39:20 -0500 Message-ID: <5f4e46e8029421a5cb97bb802dd9583371d7e6c2.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.5 via Frontend Transport; Fri, 7 Aug 2020 19:44: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: a4ecd2ab-e080-4af0-dd2f-08d83b0a4cf5 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: SsJ7TeVnT6kaRLT9xxkmMviHpxvojFGk9FC/fwk0Z2SEkSfAtyzYgoWt60N9L/ggeFgXm4ceeB8kgJqeBDAdRGmg1I1i6oBrbfL21oK5PxwpKQAsCDyGv6enCtezv5yddfb4YojSjgqpk1wDFXsY4DHB+Xk4BBVWlQ9N110HXmnyVwGYbA/MS9XxJK83KGhePa9LQngeBMpD14MZ5tkYdkzFA9nZhQ5CfRJGUi7/JzudIHVWthJGDDMB0qxzW7dmchfyEl9oSOam8KOKOXghON/Br2zPNlqt76od+HcLl7mhAudTg6DjQoct7jv6C09QyIsCYLvHuPNG0y0dj9FoIsH9Up/O3zypEEA6bnGDC/DkYRrCMVBvaLMISbiBweMVFUh4MNAvsNYk9vG6na1x/ygUVXp+pRub0mpmlzcc4aU5GsQ5uKeNpgvKUGNu4gUa7OcLboX7iFBzmnyc/wZd8g== X-MS-Exchange-AntiSpam-MessageData: W0cGz94YFu7RTSeGaT0H+Q5LV8l6zibGI/oKzJd+D4Pa60dpQYaK+IDCQL6wLAMwA7H2rUZzCCH9qwYL5B6pTqzv17cQsrj4NL4085IbsY10w4VYq8vVcawBOI5u0IK9IPfqoA63h6HH8OH90fWQd8a7a85ICw/H96xEkiHUrfWeqADONpVaXptoJwP4vHqIuoEwkWCqvsTk8a+XVX+BnmgBNX5Bw6LI8ToJ48rgGT/oMPtW1LVYaNQs0ca9t2gNOIEdyRz9ln1BcFe2IVZAg54FzqoCzngN+04zuCmeIXXK0cNW3H4ZlcfKvAujCmDUM1DI35+frqfvK1t0nMl/roatsTpkOuVaV0uHAeWJ0vp+nHk+mUDzcrV4ccWeGV5R1kgtwR/PJnmeDNNtZKcSp+/B9RBksbNlHrE6mxygYSqyxqJrgWuiYelUbOywmV05oAOlyiGzvszadAkqPIEuTD70/xz/b36Bb8caYGIBi4lmRrYe52Va5atbLKJV59PXUDEvYlLm7mURn27H/ztmSGnUvhPESx4glw0GYnOYwocg6YNnwpzunvM5SZRWdJipieeERwFnSCi8kiyQ0BOwm+0nE9CgSYj36tLgA9ZD3ejuMAg1kdDiTnyRHiXUvtIWcJwVPJaB1ia4pUa8YjTgMQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4ecd2ab-e080-4af0-dd2f-08d83b0a4cf5 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:30.1487 (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: dv9L+2mUEiNgXJL+GsjsIyrRTslxyvAxegeuE6q7H5F1l4hRHOOFy+HNACu4HXpDEYQkGIw/jYZJs9nbEn+/Dw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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: kzw2xOHYGmfMavdNmqapfBXDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829473; bh=fQecM+oVZbv7BJlUOnjsK3ywar4iA5i/P76Z331YIOs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=xQGTZcX1bw/D2Rfklkl8p9F1ztN/RmHcGeGO1nL778q0yPg+JmCQmWprwhQjEX6swFs tZDZc77O7GsZSvihfWdn+fvoztGnTNJ+6PgUfYnWA1LALI/CO/mb0i76n130I+I557J/+ qgrW+ivuM/wRkJM3VravPM9l+EP8/Fh05qY= 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 (#63877): https://edk2.groups.io/g/devel/message/63877 Mute This Topic: https://groups.io/mt/76056581/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 Sun May 5 18:51:34 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+63878+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+63878+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 1596829485267452.4545092697043; Fri, 7 Aug 2020 12:44:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CAwlYY1788612xZoAmRYdHqU; Fri, 07 Aug 2020 12:44:42 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.67]) by mx.groups.io with SMTP id smtpd.web10.4249.1596829482146373899 for ; Fri, 07 Aug 2020 12:44:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mnSM9wYjpaD/HHnVT8OrJ02rLx3YiFIcWZZ9btCOMrttRixd6n3DWSk3pubzdgQLE8454zpHlbKlViMcCsZkE77nTjipRs3WLCX4clT7h3Mp1VHSxcijJY2DOVpnTPxTJYiKAe2QGbsUrBRYXpdhpD0MPncrzUqJqb5kvVrYwBTF6T8iMtDmixLSnoH7lAmgCIz/Ee5nVQMG1ugOOSUya6RYN205zd05Wb9hIr0arvMpDnyt3E079m3WwFdwMNyEs3TT5HzIFpSdDh1XzX+Y/CYZS6AnTsHXqnuy2ReLlzeri5KV3Y+o0wrVUHwGpxotslPgdEA6jI+h0xLuwpspzA== 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=C8ZWLvMBWsHwvmPsF2Lsvuop+uIX5N3KhUl51K49DPwwE047K+o+Ovrvy/SHb7Jb6gYH8UOYqMimsMsUpY2mAWJP2v4T8NRQew8q7xCBg+++ulP5pLZluNO9JGnjbTLSzIePYHohNeTnZqSj0PnaPwA3vJDV9Whrq51XpboT9fzfWIz5Y3o5XYGGgpwewGAlgIZ1U52vcSn5SbKpg98y5Ar2DMZW5Vljr38KJif2FolYjDtbjXwdx9DaRKp9O9SGmj6/iGtVo+CjRL5PC+9QyA09bqJu+HLw7bHjl+TQJTgQ6QRv1LyToSHRMhRbh1KrvOlGWQyWLkCMLtLBVRTxBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:44:38 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44: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 v14 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Date: Fri, 7 Aug 2020 14:39:21 -0500 Message-ID: <01b7fd584ff5a0ff8edfdf079f54878c8d6c18d9.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0150.namprd07.prod.outlook.com (2603:10b6:3:ee::16) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0150.namprd07.prod.outlook.com (2603:10b6:3:ee::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16 via Frontend Transport; Fri, 7 Aug 2020 19:44: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: 18cdff50-2140-415a-81c5-08d83b0a51b2 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: D7PSl3KS6+sh7DqN6lu1oIt+DyC3BYgtZiO0x7iYlujbIcmAYHMNsLVHxhxC4CnxXHVAdmCI9Uluk5OBsmXBfUrkcLFdxdADvpc4W37cUXYi90/L8/AkCz7hq0sDEGuJ+B80rD+orHYX6RaIL0invlb4uOq51Yk8BbQOYFgbtVx3xPyQBlMJhfcb8UmS2JIVwq+INzT0ON8HDnBwbO6j+fGe3V7vlxD2D+Wyu5QVuKenkKLGIYaaXKIavhBKQb2lS9DkhQZJqTbuo+6W9w9YVbQY6F8pcZrgjMiAerECzQE8gkQZHdEIcQdcc5QmNnEkHqWJQ9cd0KK6lVS2wm5MFyo3Zwc6YN55d4f6W0VK7vt9y/+Ma+8PDU/jwK7QXucLw0lD1QxG1Xto/x4lTC9FQV50gJP0rd1QXT/utsGUF4qfnMzQz3xd83ew8Bf8hqqhnjXGtjwY8yx8cEd7FZ9Fyw== X-MS-Exchange-AntiSpam-MessageData: KeTb4QNsv8MLWFhP8s9RSjlXP8p/x60xZ7/7+iheC724JePZohIniNpGutYVWH5vjsGGYPy/OLU0kB8qHnIPvB+imurwTn1cz86cNX44gBhkXqzpRF2Q6PZxsRyYP00guaCOFe5Sen3b+lQOmxnoMSt0in4Ny1xe/XBah07UFJ93FOJvM+e8VYJJSWVgT6UD7YYDmxFkGwo4ip/N8BdUsN76huHK8jt1JYj/rijRrQMOEu91dS5xXpP4R78XyF8VlvmDHdPIaYrPALGOR9tzX6J+YI4IcVqW4+ha9dn9PNMoA03h3FZF4ywN02GWuP20SUIqGdz9TUMs4sz6ZTQi32C6TpTsatF+dsdwKbjRICd1TpYYh5kWOZ3yzR5nOQmdn15pfl4I9AG1kWm+sZFUc1LoqWhnh+fGCd1Fw2gMH5V21Z+grtffIZ5voD/XnIbFI4CtuZKfZKRYzqsclzUd4NYTjyWCHz1NtL2ldxR7NwYTdb2+fMM2OvnSYpjNwjV8WmPRTZBIybNz+2rdb7onrgK4EJbrW9AQ9L0zpYDcM2EdXRbEQ10znZZe2FDz3B2yDaKp9qK9D9RIAV06kGqC/C1CNNotrnvZhM5o/Z67YOV5dCwmVlDz4QawoKkuFNJNepCDQoczvmRwK26nPhWyfA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18cdff50-2140-415a-81c5-08d83b0a51b2 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:38.1449 (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: pdESKoAiE262QlsoaVTbEA/UKOG2rKVP+Q57Faft0T4Bs1QElkpJTKvVc5AATPtJvQ+MTG+CR3NUh7VBiHGGRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: K87OKNc8ZKOTu2lPTI2SbV2Ix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829482; bh=X2alM+OdVfcpSk1yz0qaeySltxYNLvqtSXz/orhoeyQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=sj9PVl09ahUP6h02GSSeQVl1tYyTn3JD7OSd2oetzti8PtCA9ybxedIO6acN+9o7fXh 7JRRAkQnASg0Xa0MRKetMyeVqtfxkEZSQfzWf9Sqe6tKITN+2cdT3dbmHc8K9ZdH79tQi Cbmz8JYewirgr81JqrBKmgEDxC+2c4WgTAc= 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 (#63878): https://edk2.groups.io/g/devel/message/63878 Mute This Topic: https://groups.io/mt/76056587/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 Sun May 5 18:51:34 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+63879+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+63879+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 1596829489912175.8110004036481; Fri, 7 Aug 2020 12:44:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FTcBYY1788612xBM4fH0zz35; Fri, 07 Aug 2020 12:44:49 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.87]) by mx.groups.io with SMTP id smtpd.web12.4286.1596829488144217767 for ; Fri, 07 Aug 2020 12:44:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YWp9k1xRSvZ2B1OfNltEZosId1sDmZ75m53CF+8wwigd8Lr6vBdUt90qULVwqjHh9/80DO5blnhwcPEfmOQMvZtdmdwVY097AVOarQgSn5fUvU+T4HBb7JCkJPdm87XwyQPuaIK0MN52C0Beif/hOxPs7nuggSBdX6MMLhaGHql1kT/FjR++tRfMewcCQF+aCHVNlGyPMHadDwpK9LLObEMg/OMbRyWbYHGBElT9RfAriqz8se68x7g8GTyCK6gbMORD55VsGCF5ypx9FeHQqAmx6epLo+0jp7UC0I+G5C1WwjL+tPgeXbKVJ33dHxN89QGxp7eFHoKO6b3HkPuxWQ== 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=CaXYRNu33N5RE9bEXdN5pVEIFwkCPoOjb6Ks+t7qOpOrCK/RNQmkWDs45/KCU6/g32ne0vwsXoQPzRN/gFTPaCg49rOuaEULpPvAFWkGw1oyGmN8wicnDf4sb/Lm1rMnUpXzTIhVrOP2pHMICBzDBg3JlrylTnHIe1bYsEBFN9eU4U5yxcTuUb/XOmBusR3yEIj4GhBUCPFH0rKexxoc5q8wv2pKgCq6ymNKNufBZ3E0qLA3qdO1AkDm5QmLxJ3KiiSDsGnYx+mYLSj7sW1BYkApSWWJSM5xxC17cjm2auGuOT41cMds7DpHoPDB7R1A/9semgYR5gx39m10ZCUnqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:44:46 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44:46 +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 v14 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase Date: Fri, 7 Aug 2020 14:39:22 -0500 Message-ID: <728f78274d19f4fc3fda7133d41cb410f24f22eb.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0166.namprd07.prod.outlook.com (2603:10b6:3:ee::32) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0166.namprd07.prod.outlook.com (2603:10b6:3:ee::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:44:45 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 524434d0-8418-4881-e0ab-08d83b0a5673 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: oaaSzUz+wd4cM9KxwDt0bG2yjo03d+Wt+rvReu+U+yhjmVBBZ2LBj/1HjKJdLmcRESpOzQg0KuCXAwe31gjxsgHXD8wVVdOsnCu8HzS4mgB+BtlS24oLIuof7M+CFtSxUZ/18rCHf5qvtIfF/x6IRjknfBrb3I36aeHj1UI8CkM7+hGEKhs9YNJ+yKT83CXeXN5U52cpeyVAMuaABnlCTc6Wr06IvOQkBmqBbzWDo5WOWzg9HHR8TNqZABZyIAABTDUDrsaeymxw0z3GdZENF9VlkJ9UE8HzAsEsA8iatttsk5bOPhXzelyvjMMsVP/LccEApc7wVSexaVIAG/fvYrAHmOZ3ENJKshqF6rzdBfhy6/liZeFKhU0qhgs1UYRKs3phHLI/1BD+Sa5eFWkga/JS/Bsy3PlLjy2IXUVAWesOUsxjxFG2BISx+lpDiEtk5BFN+UrBrg+n7cAIp3/5vg== X-MS-Exchange-AntiSpam-MessageData: Y0l/hz0024yiKj2Mw4jp4wFeTXRQvJriDmm9zYyopTuOrPtZ//0VWZu6A/A/F/WdJ39Qvs8HBlRkRNnrJgJ0x50ShUAM68BmHRXykY0OKHgQtY2CIEEU828FWQuuYxRLC+HAcJn9NR0JOD072ZuTunDxSRYqRRv5M4kf5n43L9cXaWBnM3ys9SLkBmomV5rxSwh/XYKZSUEVbupzL0Yw7cUCcl3hsjsfF78xo/4H2bDE+FxzWqllYqAaY2OEinFhtJrjR7xqAaSLrfU21FvhPa3cCTO2pky0saueIQOAFn4tBa/YQPUK74nelCenS7kVUCAKR3MgNcLllSrcwuo/1fhnIBq+D9B0JJJIhvq7WigANjO84EEnnHc4I+92wB0ThgMJWeXkzC3/R/iGuNjVj/QhIHc2mDVdUUhT29gF7j+tIX4/XTbi5B7n7LHQtg6RJSwvQLavVhcI5yNZlc/Gecoa5ULtmoMuY5oeiaP8guskKiIqnxyUPBAUJ6Z200J/waFr9V9nuLwXj4AulKs6gmf03MapXW1z0runkyKOrZOJegG98MJCgrYMySvBGB5xq23L6oeGyNAV/p+d6hoN5mpzHNU+5hSZaqGfaF6V5AWSGWzTFvvxB7/WuSYr3BW5lMjYJ10O+5NGe/hM8KzkOQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 524434d0-8418-4881-e0ab-08d83b0a5673 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:46.1650 (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: KWFj7FN1cBohsxI+O5CGPXfE+YedYp801a2iVFEfQal82KXKCpUFs+0FaFYjmjTn4zQH5/XViwC/7I7KR6mbqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: mpBO7X3qMUlW8oYPoCKR4Yzxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829489; bh=shMe0bbMl+DsPnRN57Yirlr6e8P7eut3sq4maJXImLE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=VSCT8SXqYSOOKvfp3jxx6f+w+hiSXAI9gprutVgxkx7qoTFFdy1yr26mXTV99/JyHQP vhjzGVZlgZdiGCU09R3pg4MyxX+q51iwrIQ6zqmKGpYw6Fk360/NcXlyFgd61AKo1uZqU lZ+XzyKO0TacNy8KFVy8w4rPWg2g1NAB6pk= 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 (#63879): https://edk2.groups.io/g/devel/message/63879 Mute This Topic: https://groups.io/mt/76056589/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 Sun May 5 18:51:34 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+63880+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+63880+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 1596829497519538.0230979598176; Fri, 7 Aug 2020 12:44:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wxxPYY1788612xptszuVQ4KC; Fri, 07 Aug 2020 12:44:57 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.78]) by mx.groups.io with SMTP id smtpd.web11.4307.1596829496600690780 for ; Fri, 07 Aug 2020 12:44:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nXszT6CO26rbDvugwufLF+FitnYFFhFmUNatna3h9PWG2eIn8A8l91dynheLC8CBhL1HvEIbBAZaiBNz2vT/4yqz1lut8uz+t/+iuYnAtP+6RvwolrCjr2Izwvz8e8d3xRc9/zaM0tI0udWgDoCNmGH92xw3OowfNdgBNaApHI5h1qaPY2iZD6za+gs59m1A1XkjfgWYxQmL+sfBNXMO7JyDlflfjEjImG2enm3SkXM8nERFWLqQR/AjSONLPTY3lghfAm0B37YlR9YjIsngd/SPFO7kUItQ06FyjFPAB1SKJ9SMnS9S/V0rLJQvi+eNSLeeOdVq8Zf+1qTNXWtAig== 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=iVkszRdbZWAuaG+isRvh9/bagJKi9ZPIPZkpOED1VaDqInvF3dOGhFSh+2oVF1buuDfmi7UA+JwEkjXEyc1u/xoWSngC4OGXw2OOtncmi9Tx+w9QMeXiqB3woDqsVHZaJoZ1untDSx8uQN0O6HLTqGGOUM90IRl/YBvFW8a94JkThSkHIrW5dwQRoN90Wqitv//xv43Zj11fTIWIB3eecxFEe0Qji8mSBHy4KnFhtzTnAnwC+FyhOdISrM3g4CuDCR/2IGF53E6AUEaJOI54kFfjMwf3QMwfZp1BJwTQDOI6xJYybFQsmg5WLs84ZEOrMwIe3hZXREDRRtL15Z0Afw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:44:54 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19:44:54 +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 v14 38/46] OvmfPkg/Sec: Enable cache early to speed up booting Date: Fri, 7 Aug 2020 14:39:23 -0500 Message-ID: <7a15fb273bb19a9cb0ddfef46aad5d91d6d84042.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0018.namprd19.prod.outlook.com (2603:10b6:3:151::28) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR19CA0018.namprd19.prod.outlook.com (2603:10b6:3:151::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 19:44:53 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0af24061-6dda-4edc-b1c3-08d83b0a5b74 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: IzjxNYcC/4ZHCZzz5EkeXmDGGXwnc/bwl/Xk+6ym3KeYZvq8T9XVaAJgFRj/i6x1nXC8UWq794ix2eD0J00yr08eATHFq17YN1eSUPv1DZwAeTX1GIX579TIjGSPHtjKeGRf3LJRf6hmM8q3InnL7gL+ET6bFwc+UnvSUPlU4wOgj2XEtewSMqNF9IUJ2zwXWivdukpobGL/Tbcb9fajfP/nSbWBFA9N12pZ7q33XLwlmQB7UTY8v0dJQYZMHXD4qjFiF98kkYxC0kPr8ObjWPOKzPPW/mr4TKmmzQSnpPCDmunZ4ryjt2RN/nRxVAJlpUcosB4ZoeUfe1hFSZw89B9FkFZ8ck5SoAp0GLCAG8JT1QP6/OXg8kFCdLfLg4/h4xWs3vpkKQki3EFvhtCPqyS2thu4TP2yoW+/OvRQSeUXwxlG7LwB8VGZtFoG+kGHyo7sQfJxANnxXGJaqDM2Gg== X-MS-Exchange-AntiSpam-MessageData: yyzXl5qijsnsOAH0oiTFNwCRM1Tj3mxqPR8ykVad/CX4R/qmSHisjzUia4k5R6avyQKOyWHZ9uT5acY5FhzoDSjvcmcxteBT9Zi77SSrgW4pPFUfx2xcn8l+zyqVCwH91VBq1yZjeCd/FOYA/Ok+VqjVx9rmSF/OiZFNU4Kz64OdLB9MBtyGqmPB9TJ406HGh8CufVgySE6bSkFPPgunWmWyKy9MdvmzjMIejALIWKeBimdz4p8HL/OY+ckkF32Dc3+GQyZ0wV5URP/JjDttFmEX2KRa9/yzMduxmJB8dojrLnpnYtaEqXxbcA21Q5XXWM31pO/h6Kx3rFEhe9mlv3Zsls0CunT8zcoBjvefOIS9bWWh4cJEolvoo9zd+pnwoBoyDYA1n6XYdAOD1U3Eh8I6IC93As2Hw3EPdQUgvAqqtH6WiiHrU22hEPI7BDIms+ZpeIPsEPRcjQs2L6OpgFnaAcd9OtRzlLPZskgJmtvoLbx6CwaNjYGgXunMIURvFDDPUnc0jMmmCH/vTH2Gm+OV6IpOTRnGa1siyECT6CWbypJCoAM78T5apL0LNn/jwJNQj8tC6DpE4ix0FbXJOFDrWcarvlM/Rq8sl+JLTdiLKsQp5odcDHLAinsquFiP2ia2sxoVJo728XykAItsAQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0af24061-6dda-4edc-b1c3-08d83b0a5b74 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:44:54.4940 (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: R/36PbQdDbnCQT7UhnmG4P6R99rjC5JfpZ7GAJkNpRIpY8WprNmNEZULVX6uQYGNFPSNnH4U7uv2FgMLNlTvdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: KXTaVQtrBDCj9D5RRL1Im1xIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829497; bh=C8YaaFjJZZaXVDL1p9c7GNFV2Y2SV249NNzODoANIb4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=joBD1KXpCzjqWYb/rTxW/Kuv4gCiElHbCAHGDHRbLdP/9ojdaNNRUJXyCG82FB9QYuH tnBT+uCX98Ce1F3x6I62wg9DOrubwJHCYEl8xMo3vI6aRp1I0jI4fjLfxrY9qnKKNEsJT eaMrTXmSc5MeQOUA8BPjxTx6n7VHcOzRbwc= 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 (#63880): https://edk2.groups.io/g/devel/message/63880 Mute This Topic: https://groups.io/mt/76056590/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 Sun May 5 18:51:34 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+63881+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+63881+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 1596829505948390.2362237263925; Fri, 7 Aug 2020 12:45:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZUz3YY1788612xQD77VvyLq4; Fri, 07 Aug 2020 12:45:05 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.71]) by mx.groups.io with SMTP id smtpd.web12.4290.1596829504461146371 for ; Fri, 07 Aug 2020 12:45:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QzrkCQJPAZHd5UJAxu+OOnRMUWVbGWx+weXUJUdNputFO5A7DON4Hq+GfgDoeBDs6FR5eNwlLCdXi/CDQSKKrNqU/8Z4sVyQeOrI/Edsdnr6VVe8SBpaMjRQiCYRYgg6JrE9w1uPo/xdi/ogSUp2h5jW45P5DnIERyDGBagemV5/Opj6/6BlaArgn+JoAeEE8Qj41GN6YEpGTQQMlW4qm9UStM3mV1Wq2bLdGvsUY5D5TMmIxT3iK+klhDeJKsck55A69VD3rRIVkpYOrlZridmqeQm7yKyaMaFP3A2z0AH+OG5LzUWYmTXNS6KJ6bXS+y+1FpwU3yyA73w4lvCC2w== 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=hB6qKCZkjNmlDlAmCNP+nGnjkAKxtsl1BlPzlXzJlHSYo6q/bVGG/74wsuwW4DuqXosG5xlbkgY6tjk6aVF1Gar6JTheBqxmLAJ/QIt77/Jshx/BdM/hPMihfzj6pPAfOtACvRRGS6YThbiHDCNK6b9BbJbmQbMCQxbK923M0wquNfUV7pWPYTXSwVGwpn1HorPG63YcNkGUQ30GzNUvn9nAsnKwxvFX1+oBmbLQGbNNaosOpAxCvtE/NLUWsICty35126RoI9Jx2GFnRqshqnJHtA7MlnCeaSJkCOUIAVdIzTHftocdYIL65/t/6kMyf83ATVLz4Xf8MhHAUq1RDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1541.namprd12.prod.outlook.com (2603:10b6:910:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 19:45:02 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 19: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 Subject: [edk2-devel] [PATCH v14 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES Date: Fri, 7 Aug 2020 14:39:24 -0500 Message-ID: <90b04c686b5f7228cdad28c615465e57b63bf511.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0086.namprd12.prod.outlook.com (2603:10b6:0:57::30) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR12CA0086.namprd12.prod.outlook.com (2603:10b6:0:57::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 19:45:01 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 90619f95-2cd3-4abb-6c01-08d83b0a6030 X-MS-TrafficTypeDiagnostic: CY4PR12MB1541: 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: u9svf8U8Bl5fTx6qbWokNIH+8v3Z7vgfnj8GEwfIm/ceOqU/qb3RsFQwgjPaIOPf6E5U0HNsXBIGPlSAygkZ8MkiSb3jK3SDg7Ra3itAmECMPzfdIDhU1dMujtBf32fbA+tIVVsvKsuQfVaEkW+MEjh7IBJwFqRrvzPwKMWzfX1WdWm6sSyZMDjm9smc/g6NtqKm4GHJCZx0JgaaVgFBA7SzBKFTqaQWVW4j/VLormJbhSz/YNtNVy6+Bo3snC/XKMgY72tAbMy6GhdlR+i18LiJbVjeYFuPqi/JvdfpDTuLthlAhHT0XV/M8AGY4FkhmiZS03SE25DKj3g4mi/wP+u4QbnbLNgZ9M6YsoF3otUuxHVQ5jSNfvdkbI9KMKbwVpR4Ar/YXO4yXX60jIN58bG5OlmzwecDcYxkXjuCXJNMu1dBUYwhZHiJeqLtK2Miaa7TqycA+ybzv1albF7sXo9sptSNut8zHVszlZgYolncdHFYulYVaOga7U565/uc X-MS-Exchange-AntiSpam-MessageData: TyUBUkrzEguuAIZ4T796l9+CmyttaFoywSVOfp8VnQqwQQXgzmOEMHUCFN3Lfu9hUXYpYGvMI1PoOGkhsrMu2gQbdGHJaGSGP9HFKN7iXhyEHaM/o/QXw7z/HPu3qzq0BTOApEVmMI9L9c13nSJnqTF7DHmojH9IW0I4uRwC629I5F/E3KpotUujkUP/+OBUNNWNl9ltetFWeJ15TqqMmE3my2T+n8dBvXQnfkzrUOW8VYpPV33Qzl5mOKCUBABA1AlsssT/YtWcfX+TrCUXeB1BXdGdiVYCfnT8VAk22wf/XivGaC6x5+ZffECdYMs3rdjvNp2ZxVtdBJOvchJqqoGdtRlw0AmoalEDW0JrKHeejw+S57RuJjJTXnYf+PBoyfYLmQbmwO+vPr5slxL38omyhsbumWkx+joB0psDj+KyXPM9cvAvABzhN7PCcdCwNJDjLRCSeX1dMfKtTdH6rY0bvXndRTPgaPSnMQ/4+VxhPKOFEVUUfB81j5kIQ2HUQVSrLKkNI7oux/4compGI3irrsXYXCgsgPcmDIuoZuO/YHTGFHdEVOTkn+e8zdlwoEkcbb+5y+NhP9gMNCwu0p8bkp6IWKG7cLxPtxg3Wh1GVmav5PXSDlmHN+gp503gbJQxA/fLAwFXJRHcunoZ3g== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90619f95-2cd3-4abb-6c01-08d83b0a6030 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:45:02.4502 (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: KQpjdM0NMCyKPecoeM1+2pcz80J13841KfciJaf5y25iPv5rPassbqlhLuEq+rDJH7Zp78g6khvmkj0fDUnIPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1541 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: gPNHkxrro3OlcWs3U6feHVesx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596829505; bh=XohkpoSAKonrGqIAuVKxpIZZ1Vdt44M+Qsm3fQ4d/jM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cSz5T1VPcoa1rwaAkY/Tfhoof1/lGZc+/duzmUKPEIcSz8a5eE1PCnmTpnW3DYNrRe0 iRRe8hS4DVLd5ynLDGq2gb5rZvMgWkPvA8/gcbXFrTqjfnpVKYpBL8JC+4Evi1ZhD0fL8 EkXCZIu1Lsg5Fls+WNdg5qEBJWWer+bga4k= 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 (#63881): https://edk2.groups.io/g/devel/message/63881 Mute This Topic: https://groups.io/mt/76056597/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 Sun May 5 18:51:34 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+63882+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+63882+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 1596837253582286.64991489039915; Fri, 7 Aug 2020 14:54:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id e7hGYY1788612xlZREmDixNb; Fri, 07 Aug 2020 14:54:13 -0700 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.72]) by mx.groups.io with SMTP id smtpd.web11.6703.1596837252245180166 for ; Fri, 07 Aug 2020 14:54:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oJb9n7diZzNVOd4gEXDnSjZQAo9/L4iBy7sRHCQaXQTZYQGKBRoiXb4DtaAmU+l1l5zENbWXfg4qEK7Rol9Fvw6jzHsX2waxuHrbeRizNx8g+QBMO/1sGVeRmZ1J5WprGxW9W2eS+fArZGt3krCkT5qdMOv6J67CgKHqFsGUecyuzSAvEOeqo9/7lzMr0J15d8HkBOELOOr5zwmS7jWKFWSFSk56YjKtQW9h4keqrjpgYjDwD2A8dDBZ9Fx4aKn4BPJKJARymyDUc5XwHxfd2LUWp8rdIhRlSXiep44ghC1r+79wW2CeA+Je5x9iDEf1n7k2pXf6hRGqT4aePvLyiw== 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=fVZmLk39gw/pZNg6DUxksn6Y3SQh7K5p0GMCLygLiAqrQgGue5VSOs2STiT+BOn1foWvHhXFaCkYLzJGoOHAFKGvCIY6Hi1lqsgwsDll1JHbb5qU0xSE6InI3xrXbwMXNEkYEEFXLxu08pfq0E6o+VrfkmWawwOGjBaxkUNmCZyB1XDW373y51rYRTBgDK3dreEiYs0rg/4nA5hDCeGTtbdhhYjZtra7XJJJHzFO6aTZgnV+fplx/MdBcD35CoTZK4ECDWa0Fjtzp88lDWVsEXcssBcUSy8ZU2S06e07O/XZDfIfQL/VYkV5uRFEFaFs3i5gMk17lRjC0z7Cp0GAOA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1222.namprd12.prod.outlook.com (2603:10b6:903:3b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18; Fri, 7 Aug 2020 21:54:10 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:10 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Fri, 7 Aug 2020 16:53:53 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM6PR07CA0038.namprd07.prod.outlook.com (2603:10b6:5:74::15) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR07CA0038.namprd07.prod.outlook.com (2603:10b6:5:74::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15 via Frontend Transport; Fri, 7 Aug 2020 21:54: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: bc1b4461-1182-47d4-a924-08d83b1c6a19 X-MS-TrafficTypeDiagnostic: CY4PR12MB1222: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: p6rAzdcWCcQ5AgDg7wrUP3ri+FxoapwV0vyvjJQ2GiqD1XUAjEs763h8KRrL0Kg2tmrvIeeC2zh7WPpHoj1WE1cjf1+T29EOWxNz8xoCrJAjEc5rhSmhpv5oVXucB9dz5tRky8THqatrjpiahVMrQZObzBO/NWsfE/X9KG/nG6HI1Mv3ZqciHMFZk5F/Xbcb7eCS0VNoXgpFloPvvcbwnAFOO6Hk8g5eLI/Hs8++TjvsZ3HXdVEAzsCiDzV9GdLrmjZjGUUe3Z9bdmXUTa2fxa3B2vPiCCrwHVwybaykVd6PJ/EkYY3FEOUydTKZwaiEOLXDntpmEkXFuymxQShAgDcpCeUoSO23JFQdGUkXM/TQHrC5WiZL0v58iSt24RdYvTzXpaEOGky+HndqfgyPrTZfMS5ob37QuzS2iZwma9WeydwKMH/+63F/v/z7nIbY3X+c+ghnaalYwcSLafrWiw== X-MS-Exchange-AntiSpam-MessageData: 4sDT1zO6PstobNjLHA6pbQQAcdADXk0ULAoauR2XaIpzbWWzI6zRX6LeChETVtalFdDsbJ0/OGD7W9EKBGXN9mAN2AWNmqp02YgL7fceye+NY7VwXkbaj6pwz5jlMhNCRD2duhn0G2HnlHv7kZLNkYo9VoSOqHs3a+380GkaRXf3hLEs4bOyCnVkz0QzWFm+UG/fb1ru9BM5VnNIZ0oV2iMpThFrf4EU+YDJL58FDZulR2e3x+t0B9finX5cBGOtK+uFFg5ndsJEQRUtZtkJ7tq54EABgLe+/LTVcHHTVClre8N2qnHymRG8wnJ8vw7CasaM7dIesK8msxz28o1jF5J9ooCdX9jW09OncpbxOaRI/80xRM2Em5bVYh3utMW+dTYA9/OrzSgAyCm0LcXKM+ktXGB8Hf65r3D74KqUgZxM5uwjjNBF/CITovGUDQuMCRZg6xSQzPEzuLL4zpy0gS0QTxwoR+wuI0PlbE9zlQOFoXsJsUI6YRdhzd2o0s7jgOG3nuC/90lj3Z1vmU1rFD4HG2aqy/xjLSPPIu8uYAep46q/UsE4yipBEVNzqtJVxwCaJ1Wx4rhKPjcA2bHTvn0SGW3kd+u+lYH4VWytu16/CBlcUvzT28AuTFcwWUP0sgURRAKo6P76Wh0PZ6txsQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc1b4461-1182-47d4-a924-08d83b1c6a19 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:10.0143 (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: YB2QsWGq9aqqwdVbUXFOKpm1/8yKPSBZd5AE0AiA8Yqn8HD/SQyNRW3yj8tyoAakPlH6xsQCQGZcXZrOm7UiZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1222 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: P6kmdBBmsqSAcEjwJvo92kjOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837253; bh=Sh7MDFDthQ/x+vFRwfyvi92KcJ12CpFy7//W/LIS8+M=; h=Content-Type:Date:From:Reply-To:Subject:To; b=YDv3q+V2j0+Aq4pA/P0KO5Qi//Rn2I+iW1Ndeg+ywEqIe9HQLh8L4FMlXAMZMPXkV4J 7tdfcxijBu7Qw4M24evGTn/XpjO5LqH+OBaNQ633W39G4GLauXjBuVE+YOxka8IecpBuQ T9J0UKGnHs2Ox6I5Zlik+geesMtTYJE6zNo= 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 (#63882): https://edk2.groups.io/g/devel/message/63882 Mute This Topic: https://groups.io/mt/76058837/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 Sun May 5 18:51:34 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+63883+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+63883+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 15968372654951005.5193269691971; Fri, 7 Aug 2020 14:54:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QGDmYY1788612xozILNw9IGq; Fri, 07 Aug 2020 14:54:25 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.61]) by mx.groups.io with SMTP id smtpd.web10.6574.1596837264504456901 for ; Fri, 07 Aug 2020 14:54:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aD5qYDYaYfJo324l0jHoZ1hCRyuTF00EexoUTX0FVtT2GBZ6Da9fEoAfePkOg/EIhpLibDXNogTNTmWxNCa4AxiEiXge4UHk6Ta/VL3LyUZGQ2DgYmpSllCVngM3geUmvgkTd/DKm+Ob3aqQsjG0gYwXPpv07D2VM16dtBuKcVfbYI2pnNjP3P3fY6bjO27YTcXlFpoLIE5nMkUMEjB2yRq2Haf8OZxyYmmSJ/BALCIlRE/EizlrC69UwzqdQLvo1H18ePNr6NDGYxH+YsxvIsrAfLFPfCufW4DoABbKBeYx9YiUGs31dTZsZynZmFFWGauxzEjKNvyb4tdEOaKCcw== 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=Gpqh2BRFlNP1VgtgukPxjrzZdS8eJL51PxrvaWYusxYcFG4vDH5v3yyMzGqjZpG0jvlhSWNiK/semBGrY02KuyECSuLggp/6+o6kdUuYWjmn0L83lwURLXdZ/vWIW8jiYRMfhAfrGL4y3sGUh8+psRl5QOLejBwHLezz7irORMbZZ3hSz/gHWBF84P8m4RiSlesH/3xkfBkDiVqTEjYH2uB9WLz4Bq6pRSt1H1helwvvxGQchor4j3OyoyQ4cvf/3FlaSj97c0Ejv4fdie/yaiVG9Y39gg1K8PhY9MMlgiqlpM/XFwFAy+c2AasphIq6MoYaBCVC71iL2WOHXQYnQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1717.namprd12.prod.outlook.com (2603:10b6:903:11f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Fri, 7 Aug 2020 21:54:17 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:17 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled Date: Fri, 7 Aug 2020 16:53:54 -0500 Message-ID: <9bca729d71e7283a1d117a79baa77fa4009b2808.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR13CA0061.namprd13.prod.outlook.com (2603:10b6:5:134::38) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR13CA0061.namprd13.prod.outlook.com (2603:10b6:5:134::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.10 via Frontend Transport; Fri, 7 Aug 2020 21:54:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e41bd368-33c6-435a-b9eb-08d83b1c6ead X-MS-TrafficTypeDiagnostic: CY4PR12MB1717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: VK5IyK0RubHX/1zTXmjjJ1sWL8sBGQX/hpClJbc9NelsP8BhbaZcSuW3avhn3fQBM+stdCsDFOlAm1QJeayyDXXL5vl6pwazWq8rcqLOT8HyGGxxJipkfKmsm7GPqkNU0ugJYvAuPvmfypmsYquJaDZ09HbSyE9RfjwpOTqxXQqlgCp7zIo+YovGGT6HIK6GX30eYdxA6PeE5aCV0Lz6WH6qoRnL+k9jx885SztI3T/nXCiOJ6xkv6JVV/MgeB1cT5zNDAKF04i0ZWuNjlbs1VefnNhvSWSW5HrnHRdeu+TdaUm4IQ/V5TaB0RIUu6V1CDXPsxaeD8EZcCoKY+mBlWKzEk6WD/ddIlfbjCxZ2+i2qCNZCF7i/VtNsRbJUqGrteAruLRRjjjFzsFBk2e63PKrQPHZEFTmvQyV89TJJZcGg0jrJV4K2ewZ3AjZy5VToHGM4ylvWJlC3tXd79x6mQ== X-MS-Exchange-AntiSpam-MessageData: UXd1iXrJLSzD8zWq1ulbkwS+Ffw/igIGUjTFXqKTOxxO+PmUR8uLbH6UYzoC/qrZr7GA1vjYp04Kp7yMkTS+e0IAzt7JmmM/6nIEbXFPdr/AyQ47ebBEpyEZVND3wKMnlwpfWFC+kkdQ25PwtAqf9WWwk16GY+ib/118TCnAU0s47+koCZ1NshMvEe0SVvnG/ls+HQYF1bR68kUML0lm8ol3oTLmtn/3ePE6iJ3zhHVd+UBjaGdel0p8jmHLY22TAkwNS9ztxKHZdoHf+NobXDRgSEZdn582APJaDi769TypeFHGWYD9e/dKKAqav0lvzE4vNrEw9CDtg/M7qGuRubdKMGhEfciv+BlpOTtbMPHz2aK08ivK7y2DCRMDVcPGl57YSdUaWV2xxIjZvoW6Ck4kgYL1t8lqaYnJZ/FEdhVwI9ETYe1D06bgPNDcCbDnsF2ZrUpjFULQV2WKp7DrO/zx55JZ8uGUgZdlbn+c8DA7xFOGiCHmgADaeUCWLhygkWwz4takk1xiEdEJZru4RC+oeWVbuMMfOrdUph2conQf2DBWHNKNYLrmyPWLMkTT6ljpAo95mFtlSXr1Jg+2U1sQBILmNXwucPmeIYkHDUy/Tbav4vxlUJZEX/sY9cfUoWpcHpxgEYhnmADGFTRyvA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e41bd368-33c6-435a-b9eb-08d83b1c6ead X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:17.6646 (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: W16vLrKTk0SylgW2fslszcQYz5PBpQKiCcKEpXwN3YdusJ8//tlkudEkKGkie6i7QOu0AKieb68XKNSguACjQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1717 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: TdwWxIp1VDtIGwGEPtoo9nJpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837265; bh=aKa1Qu3W/ROgcnbiAIQIu4mE3YoBhrwg5tL1cFj+Wgo=; h=Content-Type:Date:From:Reply-To:Subject:To; b=SxHLpsJq56KJe9w1Dp5olWuibkahdvPgKXrf+1hETMRj4UBqHD0q1NSBr6ZojJUQw36 UOPbN5thVcgHBl9ZNYWqiIWx4iRtjJg3Rrh0oYAnfFMtoo4rUMd2jCEsQ4k0LLp7tqYad JwRveSQyhIXAlbnuzcIHHUaPx+gMG2U27SM= 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 (#63883): https://edk2.groups.io/g/devel/message/63883 Mute This Topic: https://groups.io/mt/76058838/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 Sun May 5 18:51:34 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+63884+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+63884+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 1596837269001398.1230940043762; Fri, 7 Aug 2020 14:54:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lofOYY1788612xLBsa3AnVv9; Fri, 07 Aug 2020 14:54:28 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.52]) by mx.groups.io with SMTP id smtpd.web12.6594.1596837267542208421 for ; Fri, 07 Aug 2020 14:54:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G1IvUeQSuw8i8nerPmiXBSwISqY+lMhOaK0W3CZpMPSrGGfS3hiFK1eKOvQvW/xeo35uavFeB50Z1hQo7tOaQrWP5qowyXAbdNi/YVUlidv4HPmgb1Qd1bhYRmlCTX5sjJMzVT87qP9NIOOiyIzyYYo69hfvDFQ9TTNdLxX6fl4lsulYrFzEYKSQey4uInS8xHhsGKF7NdycUA9Sj6VUh6n/J7ldsj2We74Fe6OpHFbrDHwXSDpI+r85b37Koo4v47fONGBpo5StR0oPBm91x6xhxcfGHO2Y4r/H33fPQPHdaN3PlNXfzz/9NOTkFUy8QZfdGVW8kj9iLvfXXygSgA== 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=DYdMEW+D/HHjalzUbbxIRCzVHN1R69Q0oQo6dq5y6T+sbIbORIKR3wvwhizich0f2L3W9laPfVlVN6gtuGqXABeW8gM47syaRhi/BeAduUBHeFoSnFrA2BKXq/72KdvovZGK5PakyH6d1pPSDMaYzuu53NW8eqSfDUv2P4Du1hGHsK6Tpg0xb/++CEUQ7fNaoXEaVigREVbzRShiyuymWPhFUYAYY4kFVBjYo8oXv4Efk908WQu6puqbrldwnB1Acw+h+y8USb2t+mOha+5Jb0+2GL/RmTQrlYylhsCA2LGFoVuUcJVuY+g/Lfg5ZGcnJIXqQwf/spldwlWky9mZZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1717.namprd12.prod.outlook.com (2603:10b6:903:11f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Fri, 7 Aug 2020 21:54:25 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:25 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 42/46] UefiCpuPkg: Allow AP booting under SEV-ES Date: Fri, 7 Aug 2020 16:53:55 -0500 Message-ID: <0f44b1d1a5406123a503b864f1f15f6c3c2cc9d7.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0040.namprd06.prod.outlook.com (2603:10b6:3:5d::26) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR06CA0040.namprd06.prod.outlook.com (2603:10b6:3:5d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 21:54: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: 25b92e32-89c3-4902-b573-08d83b1c7339 X-MS-TrafficTypeDiagnostic: CY4PR12MB1717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: UYdjC1WtLE0EWnwCy0TngLjDsackI1ovRS6S+0Pql3I5eOuagUzxr74M9XymJxM90qtVBZSeRxsRtHK3oPGObpHbzcvZayVKlcreWH4K15mUKfjSjzX6xq/uXTn7gJ2rMH2/OolfypxbEWG0fm2EDLJIfUOD8zw4M0JpJG2b07B9/lLUi9sxBvZ81uzZdoOWP+E5nPJJhLNhzPxCigOlSwquoejRrFEV0JQ9znuoBAAicufZorIqcFHBccv0jsijmvVLGPTruIvtPfpQVMuEySNN2uFdJOGiOzGKz3JHNfm+dgqYoeNqYnumhIfW3QS+Sh99W+yfXvn4/FlnOkQ/iwF1WgKS6/4O+u6StaYybSTWT22iLl9cvOOFcyW4roFMC58aVyitSi7mJWG4pW/S7EA2pr7XLDf8WIYtwWGZnFwgxfm/W/fP2Zw1xZfAhRkh5WdLiOt+vrHURJG5+kfRtA== X-MS-Exchange-AntiSpam-MessageData: Ta/lBzXZXqy58kcywQUa6XzwoCLv9zpR3LEq1L/zaIARtMWlqXGjlrZ+nDAqptOZrn/cHDSUsxKVyAApFwGkGH0zzUxSMX5CmTnKaTymmOm8SBRQMnTmWnie+HzL+AGM8XUEv98vlep1aUINhGLxxiR6cx6DTcDCGu8JGtVIh+x/JM/qKemwDFVgQw7LNY88O/M07LLpxNCNFGGfAXXW3yX7/IGa3WDG3ihcpZYCehMRAG9p9VbUmGNJujRhAB/EJ3xOZpX5WYJGaUzyJfg975asXNs2mbunfByRivGPz+JAysyBa143QH9rwFRSUnNrMhYvBnJi5rUVG4LsLGroKj6SN1jqZXUJL6OZA3nevNp8TDxZu9zBaloKdkT7FgfUxlJegbxQzjq9zXY6S5NlUoUyGmRfsGlw/rl1/fZjVyzFwyoU3abkmMdgiZUy+YiJtNx5B5BXz/Jra1tnkGqg9HLp4oYnid+0n5u0hFWEd1JHU5xDymdJdGOOywgnA3zDbgOsMHIaLYLu034EKj0QK8TT+uD76Y+1eXFUFWX9X2n3bLkuutj8Bw3TrzfKJKxYvUefbwbK5u1Fwy0ymDZORmEADv4Y1BP2RY2RK2pQzrePb31t7bauLpNOnIrQS8M/r/86pHnR2eePq31e1v8joA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25b92e32-89c3-4902-b573-08d83b1c7339 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:25.3928 (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: 0HD22nTp//7If8/CQ1UjK651nA5PJAtjK8kAarWZbqxRQ6BNfUMHyqOjRGw1vF8OnfWgH0svfX2gnzJ66y503Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1717 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: mTQyWMkhWk8oIbxbTxzJVCuDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837268; bh=5SWNRmedAt3q+oODuvQnAiHo8+hWBr/QnJPG+b5dFmM=; h=Content-Type:Date:From:Reply-To:Subject:To; b=hyucNFnOL8nCg53LqZeSqZ/J9RNbU4qy1wU9wPgj8SolCQAB3ZDW0IlTLWL7T/loC/0 JsJJozdMzyPWsGJjgzMEZp2BpKjR6aMxP27gJYMkf0Vw6yS2Y2hSGjmNbD0X29M2m37zq fzYvLSJA7MK/Imgq3XwADAcdutnGcKNx+Bk= 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 (#63884): https://edk2.groups.io/g/devel/message/63884 Mute This Topic: https://groups.io/mt/76058839/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 Sun May 5 18:51:34 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+63885+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+63885+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 1596837275647841.3600362894043; Fri, 7 Aug 2020 14:54:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9EMHYY1788612xHXoPlHwija; Fri, 07 Aug 2020 14:54:35 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.65]) by mx.groups.io with SMTP id smtpd.web10.6576.1596837274634032456 for ; Fri, 07 Aug 2020 14:54:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ocZM1cO2sBLUhxTyyWbMJIeBHM2FKodbHO2yI4pVFJbcpj6FafCNj3uZhxVv0jn20d55ILpbQklRyN3aO5IC6bpN1QkmlIMsHPP5FH7flSki4+sfC2uDD35g/A8WtMKFZz78m4CQGEsXY0KI0HYzBPLHlm6Nv2IQI4IV71lP6v5F2lmLpaKUsPtGLzVzdObf4Xvnsvbhq+oMbvuLel0qP7w8DtqSOBRR0viTJ4MT/U3XJiNhIQh6llVXb+X3BGANCgS0cqirbbXteYr/1BshqArKnnkgso2CAAx3zW3g7cixEhZ8P/VeSybKtS5pHAcKHEfG2p123eydZaSd/ERShg== 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=jPBjEGTdmv6Q7Sxgg81JUeWYfxPCjDw3PqybbLCHtONrSqJ2cJyHE8ARq7FgXsoi/RIMDBU/6l3zFTRWk2bK5KXAf3zBsVN+gilKbYrRqsgfLZHw4rDw1sWgC0/c7HtUbmyZK7SxJecVPcKQJxQpPZMdFUXZ04BD1Dtd5taVGIE6V4P2BQ/yA0ogzLx58zSqO8TS55E1Nq642cwmcNjN+h9Z2108Z1lcj38A7KuQEToK5ZF9Uq+IxLG6Gcb0f4Lx7D435tkgrW07Yhwcv4tDDN5ainYDnPDJ/ujp0ct+tZgJMvFJX0EAcZkDW2G43bUxsJe5gQ9raqND12wkzZDPhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1717.namprd12.prod.outlook.com (2603:10b6:903:11f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Fri, 7 Aug 2020 21:54:33 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:33 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector Date: Fri, 7 Aug 2020 16:53:56 -0500 Message-ID: <18d1b4fd770e53fd12aa77282dfc3ae1e54c1b4e.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR12CA0052.namprd12.prod.outlook.com (2603:10b6:3:103::14) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR12CA0052.namprd12.prod.outlook.com (2603:10b6:3:103::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 21:54: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: c42528a7-cb3a-4483-5eee-08d83b1c77be X-MS-TrafficTypeDiagnostic: CY4PR12MB1717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: /eRMe2hJpA/jAR0JOpZDQ7YprcN39u3kWqcBnXPBZ0rnAoMAB7Ok71oZB/DAjghdghmF4ImtTKeS7AaW6VH49VMHnW3Ii41Fyfen8oUXaFzl3XqvwGW3+vFwU/kdBgZ+rLzxw9N8qA/sHsUXaCQFk5J+bxqtKD2k5lsQSkpGseugSwi+npBggUkYGASVhsgjzz99B65Zkx/e1Yy47Yc+WXUv+O9i+zKYpWrupuB/KWJglwSjtPOB/UBTZuzBVwwqIBcsjiZwmeGwTxOt1eGM5APYTUaAY3o86lpADe0iNMiMCT4n6QhAhQR0CTgz0daW+aQZOD1VyRCsiwxs56vRq83iQcXS+eLYsaOhyhuKoAu7hCbFZXgcD//1dXOKqKQ7Qcl3juDA/S0VBgrKKId6zVnvD+4sXDG72/0YRzwUT8G174g38D3m12kVjydoSCdzfTd9eGwDqYfoW8fVNu0RiA== X-MS-Exchange-AntiSpam-MessageData: 7MSqnJaEc98fO+fh93HvMYpmeC2DG3y7IetMzIvfgkyRLq1vRjDYGgEltT4hQQ3taYet5/grptnK5BvVjU2rWzBnop83sPi8Lon/FMU5ySx6ed6kjVUhtG+U3A2fvPBd22PFEMVPX0xgqWO1PMpYhjL/vwm2tCNbsDgedEwabOyhsPc4n4LVgXV1Z/EyfngCSsjzKSFZfHp0Q0ZHwoRGXEplO/TA5zdwkuOK4mJLd5Ij9wu3BsTP2zB8woFyzGMTpz8kUkRxxwO/448uEN8hO7YuncvkKd331b9AhNoKmgUi+6gGErg21C1j/FSs9AkwL+AxJakSuVyxv8FKKF/QKycz2I1PoZRIydyx5J158vE46rrGaBW9YlKDR/e3dpbOyCCUMquv2iTTcBNHdGiCV+dOAu/EmVlyKzAkTiqI5oxKqliokkJKz2UC15SRjUJkgDDqAan3xO0H200eRcpkQQZCd7N5T0CG8mA0DUkIXDb/S6mZlSbE5TKz5wxkO54smUOqXxU5OWapgsAvK/x3yqp5diPscZnWY98pjEzTPECcPAg851RcvE4iV9grKS/u2FZOgHuvjHBPxtH9rbw9d6dT6J3ZIbu4qXg2+NMvOGARAWZUuudj+hDGwpshu5m8162r2g0Q4wzlyA8izMnzEw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c42528a7-cb3a-4483-5eee-08d83b1c77be X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:32.9112 (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: VZBva3ASPcH4jGa/QuRuleAjKBR2WQIEdxc2hkEEGL2BVz+q9kvbGVQH+NNu1xIHvhYBFQYOmbd5/s0Hubf+Qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1717 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: N6JSVZCWnaQObPUxepoAhLQlx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837275; bh=Arivw4cUbO7Sy/r3N6hTUEWgewHnMnwynfRq23rm2YQ=; h=Content-Type:Date:From:Reply-To:Subject:To; b=PFhx/2g/CuWstfsLX0EuD4FuEjnyiJ2fEEfzkWwtEnCFQ/v2+BlUd1AcFZ0g4xZOZpG S3FWr54pVjSwZII2fX6aHivvULdUCxDDBetLbxsNg2Y+Vog46N0d+Bm2fdFX1KFh3IJmc mkqTzG7laxt7RzR4Y4WyYwqSqOCXD+oHc3U= 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 (#63885): https://edk2.groups.io/g/devel/message/63885 Mute This Topic: https://groups.io/mt/76058842/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 Sun May 5 18:51:34 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+63886+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+63886+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 159683728799311.64146777886458; Fri, 7 Aug 2020 14:54:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6NTsYY1788612xzh6x5RKhZd; Fri, 07 Aug 2020 14:54:47 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.62]) by mx.groups.io with SMTP id smtpd.web11.6708.1596837282771828724 for ; Fri, 07 Aug 2020 14:54:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AQHaCl9CUs7wddw4fwqoYGYXkp8V5iIpAUUH4HbClk1zY4z5zici6cY8pImST4OOfi17P4Vzwt7+mnBmK+P6llqoQxTffceDFacu68f7/w6k7VepVeNW+7Tn+R0NC6nJSxKZ/plNM9tn5SnJ+GJXY+jmgvr8hquv/aH0tY6XbzOuVK8QiCGsaF/YhhKazoWk51mmZYsomeoRA4VFi0xVWUIIPkdXGR5K1AeT2Nv/bIY/kgo/A6uHp5fyOwqT2N+WY00Hr/G79I8cJbasbGDxJyEayQh76dRR8DBs1gE6lIq/Nbq8j+cSlBBld7K8MgtSDGFfd5lHit6jnYfeuwTLiw== 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=n6hnA8jmtHoOEhBgFu4j2yY+VI32d9GKfQKM/B84o9I+t2tlUAEQuPtTmWgVmgV46C5Khdoma6MvrU7meDo/54z5wwhwaO9lvl7gnVYm/oc/pkdaujk+VNtDRnFUuJR6UouXPnIIUiTIk+3aLiliQxZlLX9N7kCAjABio6/WRmUICSHdvvQyvtYuAgEzXHrD4GeW+2pWakLa2FCrmYAfF+EvK9cVH6MZBNqottuqfRXOEF68oK4utwai8e/hwjFJpvnCbQLF72c3R3eiZj/HqQTuOof3HhYF6fND/ZIsAtcdELeG6S4Hr3HpQ8F9eNgIiWR/P9zwhD/hcq6GjUrgfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1717.namprd12.prod.outlook.com (2603:10b6:903:11f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Fri, 7 Aug 2020 21:54:41 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:41 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 44/46] OvmfPkg: Move the GHCB allocations into reserved memory Date: Fri, 7 Aug 2020 16:53:57 -0500 Message-ID: <1f7624e2bdaa880ceff2b49ba73bea955b36e1db.1596829170.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR18CA0026.namprd18.prod.outlook.com (2603:10b6:5:15b::39) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR18CA0026.namprd18.prod.outlook.com (2603:10b6:5:15b::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 21:54:40 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 303d2840-872c-4521-737f-08d83b1c7cba X-MS-TrafficTypeDiagnostic: CY4PR12MB1717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: oFuK7NiYZ+Hc3aTmvtCOXlHFu+El4KcvCVVayfnqO9x1hrdJFYIv6jnzF270GuKtYw/u8PsC8TBOk4PoVFuW/x9IVigqC7eR//Fvf02WCushTU/sH6HpKtE1RakQsSI0Ssl6bFJ7+bqww/Avw2edvPUIuhTo5sTruiQuQOP7AS/G4xRSp5SqojbPinqgWyuNL8DsIDkGZNbpQ1SSfprO2yhmyno7+r/UoW3Bo3Jj7BuFx2SntQ+0P9IHrX8Gmr21NFnkAcYHaiSqZaLGS8srZtDioApgsbuvgN4LkcZuCz170CMBUUzgi3pZg/1jLNaU9AwpW+c2GoTeOOih+lRQOQ+IQr0qXQFrBFnGJCLII2ZtW0dLmJGlmGVJmb5GggmInDuJ6jGyUi5oq8lAK/FdMlrlcgTTgGiikg30Sd9f46nV3pOYAm4ck3PKixVMAwqwpEIREyZ94cv0y2GKXmII/Q== X-MS-Exchange-AntiSpam-MessageData: PlC4BVZSyIgDnjWmpS0in69APm6Ohnt20o93e5JpUpPZuU4duIBsxPpHOOGuUFcr6ZWX99rUzwOeXd6iATiwoPGIAR6lFerMQDIgEmv9tZbISHgO2bdDqOPxx/OX29aAfgAu4gd8U4eg0kCdkEm/OJrzpeZcD2rb19ZIl6MABJqhh+tkNlDkcQ8Bwlnpj3elO+a8+5Gs51A0P/YWm3MrYPNzEY7SylFcDyjrZCzCSaeR8nu16CPrfX0j/gxcFv9vGB77wWOP87jhso5vmBgdENGnu4ji4sYcnmFJxcpTojgkYhXwxSAWg2NP8RLP1TBj2JpcwlsYveo5AFxmh7cEdPfYHw/DbT7A84PUbOLfkbazuKNE+FTSaoYLfJxzC/qLj5YhQC2AWmljzeU6j6okdss9CbjY1/15/vWrKcwAWKvJxnuIMM2Ff42cjUQPUZ5bZ6DTN1L6zjQBwXiDMgQI16UrNuecSulo7DdpJl+9Yimqe6rRpCtaa4Y227Yb/97FJVeNVh18ZgMSE63i/Cf30E184LmMZ9a2qhSyyEuHfXT5wFAwruEJnlBjRk3uQ2R3O0785DhILaj0T7cJZg4QFhwx7whbnv4ZyWKFL2inIcefX0saClojTLNHKt8GH+gxny6PzFaNfCTROCCyd2Fzsw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 303d2840-872c-4521-737f-08d83b1c7cba X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:41.2511 (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: YwtyOmsvQR8Ha+prs3FXvvgnp57BXVHwWifJ9u2Y0JcinCsH9WLyvyGsmj5d+h2WCwmEg/Gdk7JMKZVR7uUK6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1717 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: GOBiU0GhTOt7Chahb9qX9MPGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837287; bh=U65IH6ZmXjbYI0nF/MgI8/igreRDNabLxljAM4Q3nUg=; h=Content-Type:Date:From:Reply-To:Subject:To; b=oUe0gTAwF/Jkyg6goTIuunl07d9RNOs80s3R1lMVeqpUMF+e58CzU5XmlTqSf+RYfqO SbXLs3gOdfC1K5cvoo5ussgXikuOxnO0V9d/QSnNKhVTAA5E83RUw2kp3B0gVS1RT7+UK hlNdTtt7yQahr0d4njgCA//JeoQ6x3H7stk= 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 (#63886): https://edk2.groups.io/g/devel/message/63886 Mute This Topic: https://groups.io/mt/76058845/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 Sun May 5 18:51:34 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+63887+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+63887+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 1596837292101269.11001340760674; Fri, 7 Aug 2020 14:54:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id J6r3YY1788612xbSPhry3jYN; Fri, 07 Aug 2020 14:54:51 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.71]) by mx.groups.io with SMTP id smtpd.web11.6709.1596837290905082265 for ; Fri, 07 Aug 2020 14:54:51 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6o9DzYqk+S2qYkb5Hzo7Sjb6zAh506gUDDjbG5mUxVTn4K5IrK3IOjxEOMnNIGNAGis0e0VZyl93PK94tbBaJV68EId0K0tT0EAw7+IRZGvsVAaB1t1GqII0RvRY+sIkb9I3CJm7+z81QlfF52GsV11QxljxClUMiG6h+hHTJ0Hk8X14RySfBxXUxPRoqjDpZbY40gKdC2PSkMUoKaTMXSjGntE5GKDriWsO7VBIlHqocEJlGo78BAqJJ+LqS71l+p+DLRPtZY4o+7abjcS0Hd7YCX53evTPKWbegHg4R4XsXQHlXgsxqXVGRF54d4rAaltmZz9g6NwozAFR6F/Hg== 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=amkAijwPVfXC+G1sj4SuLOVXOxsvmHBrZ+lDU+U+kjg=; b=kWzuXSgQenNNHNcZc5CNfIbgVOmKjetyRCnqeYA7G8dUy7XTCu1s10dFGAychvfClI+dr8UyeKwt0yWXjiQMpR32EkTf/fVYz3x/mJhQLeusJJV6MRzFNiHIr++DlkoL6hVp7wLq8mGqf8J/3Dip7cltQM2tyERi6bpjr5DQ7+Y/be2Lq7EPhbQYevuIP3Wj5p4wSeIwX4VF9YnjUD/FlzJhE2klnRvsxUEcgZGiHC05HxcqjKsKLk4GU96w8EVxrzM6Z6HrIg0vMSlchUiBYB3rpbJizQwNy0Ns3RK79aT+BtP5EHkya/MxycpXvMksE4q/Dwi8Br13LsRxVJDEUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1717.namprd12.prod.outlook.com (2603:10b6:903:11f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Fri, 7 Aug 2020 21:54:49 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:49 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Date: Fri, 7 Aug 2020 16:53:58 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR1401CA0012.namprd14.prod.outlook.com (2603:10b6:4:4a::22) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR1401CA0012.namprd14.prod.outlook.com (2603:10b6:4:4a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19 via Frontend Transport; Fri, 7 Aug 2020 21:54:48 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5594d5c3-891f-4a1c-0d29-08d83b1c817b X-MS-TrafficTypeDiagnostic: CY4PR12MB1717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: hAX7pGxHurgXMW3IwZw6jBtVPhRPC3409QNc0tAUKw+a13pvx/btnbWGyKVWoCrQKThpzqPW7BhExOvDA6C5RJvDHGldKxMfqOEiAuHHjzHOQy5MVksx8f+wizJXax7KE+fhPVJJNfYQ8s892iz5bPDcTMKyhs0OXgOwYJnqEHJUm0q/ACsx2CRKvI8pco2MMghtU8qT0ALOzuCTBqWBlaG7zGyWTJr5nYyTUSQyw10Xp2dco9y8mKFmnm7p8fYHauIIz371ZLn84rwM0zUZEyyVoQdsTpDIWxyqOgsK3pywaRpMIBQmuWbxdMMmUiQfDPBdom4J6LdIY8+O8k+qgSNTh9mS4UFlSjno//WYjymAZc7yHV0bIAEiD+WodShzsp2O7xJbKWOD8bQBYvqOGUIiSyyDbVN0POrFhAQCffpkWeoVRPGFU9L4o+SQmX2P0i5ZLn2K5L0aH3PBsCJ8oQ== X-MS-Exchange-AntiSpam-MessageData: BFu6SdH+RUIzkqUwwyOlOSD+jtSN14aLcEnevHm00JOSagFZ2DQf8B6vRCHbfI0obZIbKOxvYtKz09W7AEHeLgwHcXB/gRpuFKzUAy09uNHN1rHiOxcebQ76bwm64nN6nfUJ0YZ0jsTGc6Kal2vGfJeKu0S8AtfErSC/tme8PMXNzSE6nBpCDrKBXC8BxAJgoM49QCqN8NnXutTtJ3bQFjfXOMT23sR7K+k1CePSFecbR/421Km0gURBdwlP4bDZ9L+KLWGMGA3HjGofu1DVejYFcGuxRO63QDBrvwNJQ8vOXmUyoG1n8E+yW1BfN2TlI0+9c+7bK8RSrVrqB1nSnUWvxLiNTw3p0Iq+4qAQeHbKxNKgqWxZGc34aM9oFB1btAWBxns0dsPn/vYmA3N4b7KSccT2nuOqsWZKERNDmogsGq3N3HeOIf5vLr6I/66JE2L1XvKkGWZiOi17EskRdjx7AugpHCgKs+xGk4FQFDHqtww6BoM8EC61zzd8aYLdJd6V7fi2k3dRfSj7+TDOUHx2Q/UyxRb7NHCiXfvsJyZzqW2sIMFooXaxMRYCiSJ7q2WmzwXDtBx/dfbOk+5UqrwoH2HW8B3O6hYu3+Y7HBRZeLEONXlji118/y4KOMD4DnjpqYgawQaBrMh31r5awA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5594d5c3-891f-4a1c-0d29-08d83b1c817b X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:49.3311 (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: SJBGXqmsHIS+5eznauynKwmOZIofFMR5smwoMemme8CQYUPf4DNK8Bm/O1g7Uv9L6OI4kvUhDUSDGbB6idI0xQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1717 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: Wpk55OYbJDWrtbWRWN3AiQVMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837291; bh=BTOUKpTKYa+hAPKnoi9/sxYSkl6btX5AoWwOAwQ1qcw=; h=Content-Type:Date:From:Reply-To:Subject:To; b=w/YWOcg7fHoyViUzedwdyA4kgGEbNiog1v1cvGCXqEh/OkqdyNAOImQontKkgKfMvyR OV0DTVtH0gq+eLkBhX4jwUcbAAD2D7a/jUl+LGhPHnTlGisaRw089Bfg5JCHKN142pxSW YKtgtCSqZ52i3bGVDoQGbwmtErN2Xp7iOek= 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 +++++++- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 5 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 130 ++++++++++++++++-- 4 files changed, 179 insertions(+), 18 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b1a9d99cb3eb..02652eaae126 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 @@ -350,7 +351,10 @@ VOID IN UINTN ApTargetCState, IN UINTN PmCodeSegment, IN UINTN TopOfApStack, - IN UINTN NumberToFinish + IN UINTN NumberToFinish, + IN UINTN Pm16CodeSegment, + IN UINTN SevEsAPJumpTable, + IN UINTN WakeupBuffer ); =20 /** diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 9115ff9e3e30..2c00d72ddefe 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 + StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE, + (UINTN) &mNumberToFinish, + CpuMpData->Pm16CodeSegment, + 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/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 309d53bf3b37..7e81d24aa60f 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -226,7 +226,10 @@ SwitchToRealProcStart: SwitchToRealProcEnd: =20 ;-------------------------------------------------------------------------= ------------ -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer); +; +; The last three parameters (Pm16CodeSegment, SevEsAPJumpTable and Wakeup= Buffer) are +; specific to SEV-ES support and are not applicable on IA32. ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 6956b408d004..5d30f35b201c 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,96 @@ PM16Mode: SwitchToRealProcEnd: =20 ;-------------------------------------------------------------------------= ------------ -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: BITS 64 + cmp qword [rsp + 56], 0 ; SevEsAPJumpTable + 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 lock dec dword [rax] ; (*CountTofinish)-- - mov rsp, r9 - push rcx - push rdx =20 - lea rsi, [PmEntry] ; rsi <- The start address of transition = code + mov r10, [rsp + 48] ; Pm16CodeSegment + mov rax, [rsp + 56] ; SevEsAPJumpTable + mov rbx, [rsp + 64] ; WakeupBuffer + mov rsp, r9 ; TopOfApStack + + push rax ; Save SevEsAPJumpTable + push rbx ; Save WakeupBuffer + push r10 ; 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 +593,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 +608,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 (#63887): https://edk2.groups.io/g/devel/message/63887 Mute This Topic: https://groups.io/mt/76058847/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 Sun May 5 18:51:34 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+63888+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+63888+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 159683730016643.089059254971744; Fri, 7 Aug 2020 14:55:00 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wDHMYY1788612xe2LRyl4lVc; Fri, 07 Aug 2020 14:54:59 -0700 X-Received: from NAM04-BN3-obe.outbound.protection.outlook.com (NAM04-BN3-obe.outbound.protection.outlook.com [40.107.68.89]) by mx.groups.io with SMTP id smtpd.web12.6600.1596837298430814756 for ; Fri, 07 Aug 2020 14:54:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X/1LtXWf36N2Yzc8DJqHlwOiWxMBHiK/uMyZpTpXJkkF/brEXvCGLzOyXxTB5Y8Lal5ZbaUFa/5f4C4OmfeFvQae+WfoWx1o4adjmIhUt03Di7LzF+yJbgZDfVoLBa26K5Kbz4Rc1rmM3YdGJsDM9b911DwWyIZv5nRInvL6BSejMduZ6fRB38Wh8DfZ27cTt4qyg1W8J99cH+qGkxdJ8ocKhHsIytDFG6qg5mNZCeuZSv3zWGHbKv+Q3TzLeOtBP7BQXSvuYnpw1PcNJP3XTzS6buEmufiHOWWB/h3bgOA4+vt8H5d87lEgdVdPaBxbYMz+XSaKKdyMWbfQLAX+5Q== 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=GcS2N7I3DnjKZha8q00kILXx/HWl5ybemxo/IxYmGtk=; b=m+Lelb5u3vPUkxgByu97tdXH0xDbCHp0byDClP4rHiBnUZT4OKeSQq3XiuSGlZzSjb48LYklcokXDTcWcUujfv+NSDqYRn68qdhPu2UWi2pxN+fSsk3STQdYHvvVtWA7S0ZWa4HqLUtW9Hn5Uq4nmXLhIfepfrd74ofl/vgexXRF3XYWQLEFtG/llbbUM9uXBlicP2kCxoJuKHnYgKW3DIBDamYv+VtqqnKGRCo0IUSf/4oaxgNWwbZd8FhPSF/VwwccvXlnej/mjXrneB+oQn+ibhiMXgUDVfvrlMbJXku1b55lSNC+6xz3ouUdAjoKb1BZaZRJ930kj+J38BYVZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1717.namprd12.prod.outlook.com (2603:10b6:903:11f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.20; Fri, 7 Aug 2020 21:54:57 +0000 X-Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3239.024; Fri, 7 Aug 2020 21:54:57 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v14 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files Date: Fri, 7 Aug 2020 16:53:59 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0024.namprd20.prod.outlook.com (2603:10b6:4:16::34) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR2001CA0024.namprd20.prod.outlook.com (2603:10b6:4:16::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.18 via Frontend Transport; Fri, 7 Aug 2020 21:54: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: a329cf5b-3d00-4180-f6ae-08d83b1c8617 X-MS-TrafficTypeDiagnostic: CY4PR12MB1717: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: szLxUUqJRo6NmZAeY1VI1oVM+JR6ma0UdTdOeZscbTbiQT6m4x4N5BABv/RYOrktC1dlLpxozq010iEeRU7j3Y1bqK34QYa91YX13QBsq21BXT3z+gqjmIMvKbMAxa/b+C7J3bx1k27LgumeBsqu7gCDMvz0639K4LJLofY2y5wZtiNsHpozWpdU4slv2DAbIOG7OfxjrsDyaNcf6iF5JDBXkpKpM0jj9OgFsXj2/ptNZ+AFJNU/nCsIkkOMlN9mA+hmrdXoyboi9aeiQwvhXM06aEAYpgBr8f8kssPUOI0LczJJNg6c4FWKiKIO+M32RsFX28pnXX+Ts4Xsg1zy9+e2vvuCfSbexMbQOko8sKQj3FZlNyxrkcTxCqlkJB/w X-MS-Exchange-AntiSpam-MessageData: f2ACp8ErJH2kPcQZygISqEJ0du0gO81lJKsRMfkWUPZ6qwt1PI4W+Mp8YwPBDnPmBNO4AMsyxhhpNqVN2Q+hN0GZwZFM1kCcvlysrL3FC3KvzGXUOx2qeXMJeYftspP/0lAuY7DBDvrESIME+lauxmbunacNJKtcCozEIX5U40OjbC1dtL+IBdeWDu/FnY1ejpYgr61VKXYy6oHcMg/FIpy3jjwSmzX2VnrVi+vR0PnTLUQWXmSgeGHBZORung+nKaN9FN3MkXlBIzows9Q61zuGcjSmrxtq3HeLUbq4Zk/mYWGtpJXqMh4tYjZGwFKkvv/mpYoO1DeI44uORqo1LEPex/4K5B9l0k/ZImDEN9+AfHED21rUzOa17OcmeprJOSJuXwm1Ebs5XE2Lsc/X0yOkbqgsfR6xicD253LmA2pxzIG7UzNgdwy8vB0dWCCnhxlm4CkdlEzL1DBnuzjhThTL55kXmn4vcw52co5GEq7HKG2VTRGpIDIOUzEnkDSPAsRWJDSKmMkW1jdx2gqU/Kr2e4uUn1FeLqINflvGreaQS/nOHbj4ny6cua6UdN36EkzKnpoNsTeu+uq1cMUyb+BnBpzaQhShloICdBuTq+sWlxLfvMTN8eh0p1K3bNhE5LqDUzl4B/BtgVmoxdS5PA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a329cf5b-3d00-4180-f6ae-08d83b1c8617 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 21:54:56.9944 (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: rCR0YlLmll0fyfYa2DpTVGfVXMP9HQCvG7w3rFA2uLdTP+EqUJx8RouphqxAf7mI56xXFEuG3VctkZ34AhgN9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1717 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: uhBUULHZBrMPULHZYho111pkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596837299; bh=L+RfaEoaBLvXhbWRHzkFgPdFwdW8n/OSAvho2SLFVU0=; h=Content-Type:Date:From:Reply-To:Subject:To; b=iWGCD5md2yDAPjvhxpHbZ8rlTerftVee9Hf6/WyJapp8eN82mQZkKUUKPPigrn7Twtm 9wBPMy3CoM//P14ZVv8wtGuxczsAXUUyeFfR7C50p/e88FtVSPplNDzsZhC+VQxQeg2as DvSLoWJGWcSep5Ap+D25iCk008aXyfawMuY= 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 4c163496b1b0..f673ddd2b38c 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -441,6 +441,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 (#63888): https://edk2.groups.io/g/devel/message/63888 Mute This Topic: https://groups.io/mt/76058848/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-