From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.87]) by mx.groups.io with SMTP id smtpd.web11.1850.1596134956915801813 for ; Thu, 30 Jul 2020 11:49:17 -0700 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=qV/d3lKh; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.87, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C6PsMusWorVD8mneuNZfnjJzj1f2g2BFD8v+O3ZUFxaJT2T0afUY406TmFqURHQUa5fJj0MYVcY9yI5oLGXZWSMuNGalSSWevVwJlX05DW68BVkZ7TOmfVCtv5DOX/lgv6l6bHkJMLJ1SphQD9r8ELj/mKISBhp5yhbBfTkA8m0l4eqU/9vZEcGaJKNz9GmxqyEv23S+J1NRbVslbjMhiR7Vi0IirJ6sh+1glcu5ZY8S5tNDVuzKbP9O+gXj8m9XQMCTJt1vLPMGa5dQAn+xChWGxUdyP/WQVZ4ZTvJEhcgphYuKRNcFcPOCZKdxObXWd7n9sNxqnFpSrCI2lKd5Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LKE7+qHjsZIcvRUcMZufAvxligKtvF8CIKEGq/A8VMQ=; b=BtkMzoRCEZtvG24vLCGKxLd2O8xFN+qUjDJfDj1FHsMA6EGX+tdClvuVumJg2BMCD0jJ92FvaFOHZzAPN2qNJCR8vDM/K/AW+FWy6N5foV2uVGCqKj9gErrH48jeM2/Gmkzcxiqzh7sAHPUZFrZLIs6JtC5pvBziR41R5WFW4YXT0T1TovbuG5snsMhiKzEqkLV/BhQ15noOUGQgmu+BV0p3fCHLj7NbOGl6TXZmZYxYsVksBCBzFYsffrGj5FZW6qPKUUGgn70L+7jXYzjBni3gamLtgujopvqIpESW/xjRCNHD7LbPsgJDacM/q+baom/0zZkNI13gSXUDG+W9pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=qV/d3lKhg6P9jN14kbS0bt0429/iehg9Fl3ZiEamDFhLSFrrK+7p4RxY96L+/+m7XAnfLyPIQwup+KFdXmF0kJXtKZr3gw00lt8OlcpgbMhjw28ASutJ7wDXgiWGRy0MA1RsQDr9zCuHA1U1s1TPQPXip5E4YP1QXfYDTWHhOfs= 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 DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1867.namprd12.prod.outlook.com (2603:10b6:3:10d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:49:15 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3239.020; Thu, 30 Jul 2020 18:49:15 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [PATCH v13 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Thu, 30 Jul 2020 13:43:44 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0047.namprd04.prod.outlook.com (2603:10b6:3:12b::33) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) 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 DM5PR04CA0047.namprd04.prod.outlook.com (2603:10b6:3:12b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:49:13 +0000 X-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: eaf6b8c0-8629-4b1f-c963-08d834b941c9 X-MS-TrafficTypeDiagnostic: DM5PR12MB1867: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XXn8/ch4IePM6y96SBtwCQVjYZgOlSmz63A3+DrE/isjk0di+qQkCjAXN+GA49Bm8lumpGkSiMi56nwYMts3HDuBWzWcCm339a09l4X8G86PHhueqLE2oL1CiyV6fgdretr9XQaeiYwgp+ksrPPkUyGQQpxTC+3acS8e1bSeAPt572LdNxO+xY6GTpKcADri1K1iczSD4h5TmOTjRCSGzFe0PWnP/RyJU/N9HUK8KY06thlpCz1lG91dxUH1bb0AUImF9N98X242fvgAQpjw0V50Gd0jqnx8VFHGjQbYav47ln4eu5SDvXA5yWEug/4kjvwY8CyGfZPCoiI1q7XeahaFK3r6LIrKdhWkSF0WX9dxCChIYI5APd9ywyGjeCuiaZc3Lw8T1WS8Vg3va5WgR/pFv9/HVFT1jEiYdR6gXWwjlkQuI7swbOPVTq4hOvNihHrZiWOe0zjS7Op0GmtL5g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(376002)(136003)(396003)(39860400002)(346002)(316002)(7696005)(52116002)(54906003)(16526019)(186003)(956004)(2616005)(26005)(966005)(4326008)(478600001)(86362001)(66556008)(6916009)(6486002)(36756003)(66946007)(66476007)(8676002)(8936002)(5660300002)(6666004)(83380400001)(2906002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: XHkijrc+4tAeuozeMs/hzHZEH9n3Z25p+fNimC+lh+tmzm4LV28RaFTHtQfvZ98lF+vZTZxnHLjPrNpf6lAT1bAF+yDyeCKRlZyPKiSd/GjoVH3fCAgQ8wKRhDjbDKqpmVjKEy86hPGVCONHc/hqQkq/NEAFI63smEiEsS0JKaE7GYG8nt7/xkWdmvu7qrXi4Ml042ifEzoS0IJO+P2z1i55Ew+8H4nhvyKndDbHt8UpmhY9onRYLcnt/pLxsUqHbNpUQFFpRd6QACSTI6rhKHP+/mJf0MPT8fayiJCGUHDuGB9jafWoT/12f5lNqZphUcWmDtYEUjize/WeRoKD2oSqWyqxtMDmeSjtn+wiq135/qhVi2H9qcrHvaMRpbCbTMLgA11OFMpUAyFzYl5cgp9dHPu69mLBQpfd1rvu8WuBliaVcrcfJcui8voxV3LZizQrc8159kG807QUaI/vXzRot482UDPaQ/rtVCpHCdO+oXVIQYU13Hz9i6JEXvxS3Wbc9TRcZ9vds6t2Jpv7Xwm5gErBfcWJdE1IYMxB0RikZcxoLibyObYN5++BnbiyZIs1N10kb5I4kGEYTS1NXCtowSN7VTG2nxka88reuNaUI/dYSVunhwHp4D6sB1KKoAAaG5+nQShHVYTJJFx9rA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eaf6b8c0-8629-4b1f-c963-08d834b941c9 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:49:15.4780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: emJSG/phPZmwjdDNjjQLNeSuVGpv2UubUxaUCzxamN2oGWxgoLSBphXBIWk/XH4SSXn2XeG7bp7I+sY6Etpowg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1867 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