From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=Zp381sZZ; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.66, mailfrom: thomas.lendacky@amd.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LKE7+qHjsZIcvRUcMZufAvxligKtvF8CIKEGq/A8VMQ=; b=Zp381sZZiHdX96RhJiiosY1l2zcv8KBE36T9xb+qW93itV2hxt/0sHxpLbBErXURlBILNCYbr+6KdhJwJOjRb57KlLPrLEvZqGsGbMT9HSTpP8fimS9xVgomyqih0i9/A3jjF5NCmFXeTefDPODSCjkmEFMau2lL77tdREMKhKc= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; 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 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: [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> X-Mailer: git-send-email 2.27.0 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) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 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-Mailer: git-send-email 2.27.0 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: BCL:0; X-Microsoft-Antispam-Message-Info: XeG2n+m23SHI6qLQ1zSw6eLSljCPjSW/wkhtTZfeg0zGnGrdul/4Q3pzz8uTFmZG/YcCLyK8Qbxe/5sm8tQjRFFsSH7QAf1/kpnOQl2q7TOkXsg2R3sQgsSZwoU1nNE2wwQ+EIoMMfLTOFmpzc982+1bp4y9aD2RbCQOfckLTyQCqipX1pPOxiXqGc3sXko4W50kJG62jfIk3MuFj2whux3nqolXqsTm7VEKlfZx/ipcxIdFfSf5aaYIF5SY/mUTV6pd0StW3t0mCpHb7IvCrHrf2XdsysMftYK3AFilC5szDny7ece//o4FL4fQjuBoDCQREny1oXi9yr7+DbOfsbUZw3wH1UNr4/24ZqTAuBo2luJfCARSa9V8O/2XX4AlA5WGkEaBUTrbaypbn/OwT57pXA6guZPBHxY9arpdIeJbAYu6YucJ6h/b6D7+ypITt4jYd4zhck0BzVH0MlJW1A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(136003)(366004)(39860400002)(346002)(396003)(4326008)(66946007)(6486002)(2906002)(66556008)(66476007)(5660300002)(966005)(478600001)(8676002)(7696005)(26005)(8936002)(16526019)(186003)(86362001)(956004)(6916009)(36756003)(2616005)(6666004)(52116002)(316002)(54906003)(83380400001)(136400200001);DIR:OUT;SFP:1101; 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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