From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.50]) by mx.groups.io with SMTP id smtpd.web11.5565.1595366648927729549 for ; Tue, 21 Jul 2020 14:24:09 -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=SqTXdGr3; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.50, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TdkBfQmhgBfyL4COPN3kE8GxIizN/IVCFXaX1R3yvvnGcZxGFRKXlmrFTcUN7rRW15/x/9WSF46/dDTShcqCK4Bv9pKHwuWiMfJkw5SeRyQxepn7rNy74fpC+9nf7G3zhjt4E5H5v/mGpFJyY9V+b9YRt1/JIVafY1WGrBI1FCQtPWTsuOAyDC5VKTqTtHg6yrBYss3zKqr/IcrFiGgd4EhM7DnayH8JJcCfRnEZ2PIQ5dxV9oQIK0QxLgWpC4qcej0GtihDe+Nh1ftglCNLe9wavWyXXSD/Yvgrurc6ksVO0pIe+tqVSYB7+SZyrFQudzvKvgC+QdacDEPlC39TOA== 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=nGS49fBqKG3mGwSdZRfZtCar0i0NYFegA+mxHG9TsN/GHtRQtXq6R5c6CefcGkBqz1ywtB6YqvyJsCSzFakWBK2MOJHSevlFOAEzf9RM9IKZUjXTWX1fjgX2xWI0pt1qdeIdLbY17QQyQNx/l0LIKOc0gumjkQ0UILa1r1oZNGTPFRIttycZzdtJPV2f3OFOyhyeVBx0EtS20eYojR1Iwunoh0DaTUCFIf66M5OZTFborA4BnH0tk2dzMdaBSf9badBHzNBlPoUswQUo84JMTbJAemFi4ZcszJbOVfkJUQ15wLVwTLOpALZbvLvSuJYqMOWd5ItAkhxi0mVkiWPnCQ== 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=SqTXdGr3C89IYcDZiu81e6WlsrIYIjTZCbAdQjCQ3Vsqrbk+QvN9iXsSaRyuJxq4TvdPFtrAUeMljwo8quXD/IiVWkjjnFc3chCsbTO6FHZzj4TSNtbxsiA6c8ceBcG9j8Omqibb+W8mkE9TgwYVISG9JyOTUgLFij0VBJsyzvM= 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 CY4PR12MB1606.namprd12.prod.outlook.com (2603:10b6:910:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Tue, 21 Jul 2020 21:24:07 +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.3216.020; Tue, 21 Jul 2020 21:24: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: [PATCH v11 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Tue, 21 Jul 2020 16:19:09 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 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) 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 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.3239.1 via Frontend Transport; Tue, 21 Jul 2020 21:24:06 +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: 593da76b-8967-4499-4618-08d82dbc6660 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: 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: HKYcW5qYuKCRcAvt2HOe/CpyAxNvzz1UDKM/YoIERH7BwQjkG8Qroo+wyKfHK+n08+tKAh0N4UI/1Ir6nS9gIIiV42ySAQKDRpdQUuxhdQwKY6O1/L2ZoGWmaxGMGowttTyLcAeSVTh8Gi6t34NRZB5RMZ5v/W2302mm0TKmqaCTkwvJz6IcT/s+DMH4FDZPilk5GI6wFrure/NnOnbENwa9OrkHrSRiVNnT4fJPFvJMW0zuViSPvVdzidfeN1aC2UMV7bFFEMLWw75C6p8FwwhEXfld5FOJwq4aL/kMsY0b4pRiheuoa3p6mdeMivB1KnptdjfhxZ1XSuXVzscuJ02mrO27rc5A+1B0a+y0zccaRmlMETFjfcxYqWjDvOeRSc9ysGe5ph5MYHI0H5t6kD6ssj/ilDP/7YK41xWLShdXYZfK0vyDOXgYVP4mf4R9SUwmGYnu1PuzduEvH3mh0w== 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)(396003)(366004)(346002)(39860400002)(136003)(966005)(83380400001)(5660300002)(6486002)(8676002)(52116002)(8936002)(7696005)(86362001)(478600001)(26005)(2616005)(956004)(316002)(186003)(4326008)(54906003)(6916009)(66946007)(66556008)(2906002)(66476007)(16526019)(36756003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: okrBRf1xJtE8Fc3N+SUCmOl70/wv6uU3hxJkV1zbzzs5LyaTfnveF9gZKhEILJmjD43FYcCZWW5uwwMfKkSQFGupnei1y33ksng7qN7YkNwin/QIKnH1h4APn37wMerCTiAnm4bBxnqYRW2vJqk4IM4ENADk8/6BjV8iLJ3GFb4Ws9LIK+ATp7U66msUDhCqe2I0HtQHv5xdNIV5CVDWDUzdlJnELMyS97whl/LC2RRwyGKYEMMG1BQB3drCQ1Ds3znfTwDn0AA+rx9Ib9VpTSjrAqEAEJymJEVOV3G1NwwHEatbRqQ03jai8LbaXm1lzvR6B5ehOfWQxiNHoCSx1bXlty4eUzPDTDz7FFqSYF8UaO0bp/WkraORuuZ55j6B7LuUsfcz43x/cqoU7WgJr+Woohr2DVJ15Fs2vsUHJE/Lkx/pHCuE0W32YcA0Qw7ptLVChHOYIstMNIChakZgVpOp637KyvNCZVDubbrHqi0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 593da76b-8967-4499-4618-08d82dbc6660 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:24:06.9001 (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: C8hhBjCRNuDUVTvnTZO0ZZD3lD2+Krg+l3546tLl+UxQf9Z0fqt+3b6+KFx7T0MVFmuxALAexD07yLqvt5PeJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 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