From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.504.1587577397852627360 for ; Wed, 22 Apr 2020 10:43:18 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=ZIlj/Ump; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=POdiEBVo/32SnULFs2QG3EB+oMZh6x4vAXPAH7nBJHpPQZ4Dn6izgjyBtQTeoWUsACORzaywMBnWefTjvf6Afh3AK8InSQaZD+qOxP4JYDhm/zd9QLPA9GoGWHwDejZ+okd3dW+LRWKn4q7Le6GpDqAnDE0JeYCB8csW5yP7Cdb1/4+r8k7iR/hUrEdBv8OPpZ8qI0Qt8IWcVCcOq4Cprx9xEbZvkDNtFebmPQAzk66yyNSwoo2btW4ol76LgKqKuvtSKV+bare5bHJVDum8WYAO/GNE/oSNPHkQvEeifUbw74mvkqwdFMCQe586TZBhUpWYUWslnPRW7Jw3JOnC8Q== 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=bhYNcWe9Dmh6ZVNNV+RLaBP3kJL4aqhaTuiWyDwt+ts=; b=b+rwb2ClcaUCZs6mQTPoyUBryWVl3JZLvlj/enSViv+U+vUoDpTQr4ackrz6ivpxdpdYn4pS2iuZKTnryBJPzROq2ajOeuPTHz4e/q0IA1EyAvl/s5A+OGmh0xlhAFDZoa8huR9oD2PKxn3BuWfmhesG/R9oVCf1m5sYYJidI/W0GnIU9P5GA+GESGXLETSgKKfWgHHVzWP3bEQT0P0vutfa6XDUoGuu6DMB9Zzkj39s7Aki5HkDl8QcBDDKj+mYyh8QKzGIVb4RxLPdqpVJLOnLtHnaP4gXGId+SkTrdK2dLU8iuhM3zmFxmCsc9LSeLc5IcyajxDPiiukolr1HiQ== 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=bhYNcWe9Dmh6ZVNNV+RLaBP3kJL4aqhaTuiWyDwt+ts=; b=ZIlj/Umpl9fm9zCPVkdHvbj3ZC9iBdaPnsvWBUpOoPq8/QLmDZ5J7YJKNaaNLqPOsVZJuO7hTdibW8t3WkkxiGWp4CG9XXzvXd+4zSHoLuwkoq+bHgi+vs0J4ytgykp5q+vY6mK0VLPs5YK88o2zCEEGL7Q+YEjDOYf566JUdfY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB3673.namprd12.prod.outlook.com (2603:10b6:5:1c5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.29; Wed, 22 Apr 2020 17:43:16 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 17:43:16 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [PATCH v7 31/43] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Wed, 22 Apr 2020 12:41:46 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Wed, 22 Apr 2020 17:42:46 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 023e6061-b2ec-4f98-7b1d-08d7e6e491f6 X-MS-TrafficTypeDiagnostic: DM6PR12MB3673:|DM6PR12MB3673: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 03818C953D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3163.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(16526019)(186003)(8936002)(8676002)(956004)(4326008)(316002)(6916009)(86362001)(2616005)(36756003)(26005)(52116002)(7696005)(5660300002)(2906002)(478600001)(81156014)(966005)(66556008)(66946007)(66476007)(6486002)(54906003)(136400200001);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ihMLy7wAPPHgzggiCVhW0UhlV/t3pnDufkjPwzIgfnyqWbXJtHaEgNtedCebTcEb5wHpBDlV+RQEwp/H75wgr752MJr4mRTfaD12xYjPAhCxrPvAlgZ0uOgytrE3UaMlLFkTZS3V8eIutyukzGearFbitc4CyQc7GVSUuyLhnrD2dvMlSIWvE5LwTd/hUnD5n+KuKFMJ+u9/sC+G6/xDkF1GMQ/cZB8YQIxN+v5loPN2Q9bU1Fs4ppI+UC0TBOqacWFsm0+rwP02hdQgVDQ7PH3C4AMRJOxpJ4c/8ZOfxn1GROS2xWUghi+hHz01kukptlgDLcpfe7O1Ol5I/P1weKa5Zbg6VRWefPaVJo2S0k+a5AB9uxp808tZ72XHirNmye7B51OVqWWJ4Nm0K/lJdrUAvHqHrX9PbJNKi48oaONjIdVw9SH0GU594ceoSwkWAD586S9f/qJI3vMZaOaotfzvmRDCNex4XTlonrzmhDTtEAmv5UW0B1nrGcObMLoJwA4m0dgugxaqKzIdhPihYsQ6XduFIiwtRIV8aaDXZ5wQOvlCBlcU5Bkly1CWVlZ3rKexnBoRrEDuGhbH+5sRsg== X-MS-Exchange-AntiSpam-MessageData: tf5T9U7jCLWjhsgulyRnDVBS4+S7YlD5Z7BiFgwqi3KmaPfEa2kuhFN70j+p5UD38d7CrqYhRtyLImK8+zubfq9B3f2rT8vvGSN07gFMz0KbY2SrHAX6938JCvwF79n7X7j7Z1fnnm0lXpm0dpiCoA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 023e6061-b2ec-4f98-7b1d-08d7e6e491f6 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:47.3415 (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: ctRftQu5ALa20Bzzxa6uREhVOCzepPs8RDEzqyhffhPsefc7SMb6Tc2Uh1wNRtw4Hj1Sn6j48P/X5D+549HIyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3673 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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; if (!MemEncryptSevEsIsEnabled ()) { return; @@ -83,6 +85,22 @@ AmdSevEsInitialize ( (UINT64)GhcbPageCount, GhcbBase)); AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); + + // + // 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 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 = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN) Gdtr.Limit + 1)); + ASSERT (Gdt != NULL); + + CopyMem (Gdt, (VOID *) Gdtr.Base, Gdtr.Limit + 1); + Gdtr.Base = (UINTN) Gdt; + AsmWriteGdtr (&Gdtr); } /** -- 2.17.1