From nobody Tue Nov 26 00:29:26 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-