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.89]) by mx.groups.io with SMTP id smtpd.web10.4245.1596829472340420794 for ; Fri, 07 Aug 2020 12:44:32 -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=DcyQqjUN; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.89, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ENsD2TDmeiQM71h9Hr+WKV6bHGxgWjpHRTWtLWKqULKtcB/DTwXju9QtvGultVp+30muOP8XxL74MqyGHzb8Ru0IHaBIAVxojb2o8w6P0es5nRmiEAmqcPpkso4vlnyBfanWzSKfqs1Fu3pG7wRy37SaNKpF5I7UppTW2pP5POvpOVM2J3SgGgNWgXXr1I+xi6BN0tk8P1LI2na93cMCj2DS5tpOpFnwq2E7ua2IlRjgFEr2ffrFsBOPe6XpCbkeRBiKA8chTVkvMeEkaCoF2NH4LXgtdOHGu0KP6SqXCm3KFtBB0dWG85lQRgYuw+UGu74WcBv0jCwumqos2Cqthw== 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=JkyhLOofvIbow8VdM+XsfKiaUSck6a3v3S8jdpNjfQo=; b=ZOxL/RWdIp0l+Djkfphw45RqxAo0RmWfKJ6Ok8MdPjGkL7Oe+OqwkPSTBnGrDQMnIm5D9iKtO85t1YYCy04Zn95CNvns2NcMz1Rqy4aVTqIYLj1f5hivFB2xudrnlz6tV/90Zl+TL37mlmqI1t881I3qYV84cfx3SmNes4Rglmkuxl4VlQhK7P2kU+LAw7rX3Ar7x1Jx4HuNCFOlbgljRMqA6nI2FFm3bBOHQzjgiZLQxFGVkBA4lumyebzDaUSxSLn+0QLdxjnosV7+493+OIa6RZqN0lDHI/GXTLsIdv6wJoDG3lplZeSBe217RVZaCmEQ5UsgWXYqLPkIMHwKTw== 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=JkyhLOofvIbow8VdM+XsfKiaUSck6a3v3S8jdpNjfQo=; b=DcyQqjUNhGLXuVbxvkby40kbDygIDRTTy6jf2JOcRH56mYJfhu+Ad6mubWCetw0GEQ8p7krhskJRx7Dq+hPc6CsQsv1L+C2ZGOM8z37X6MjNUwpZa/Y7V5UtVC1M+UVgTHRbUMrNaEwZvn7n8D+2DIhSYZf/sQa4pbtVS1z+VlQ= 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:30 +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:30 +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 , Anthony Perard , Julien Grall Subject: [PATCH v14 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Fri, 7 Aug 2020 14:39:20 -0500 Message-ID: <5f4e46e8029421a5cb97bb802dd9583371d7e6c2.1596829170.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) 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 SN4PR0501CA0104.namprd05.prod.outlook.com (2603:10b6:803:42::21) 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:29 +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: a4ecd2ab-e080-4af0-dd2f-08d83b0a4cf5 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SsJ7TeVnT6kaRLT9xxkmMviHpxvojFGk9FC/fwk0Z2SEkSfAtyzYgoWt60N9L/ggeFgXm4ceeB8kgJqeBDAdRGmg1I1i6oBrbfL21oK5PxwpKQAsCDyGv6enCtezv5yddfb4YojSjgqpk1wDFXsY4DHB+Xk4BBVWlQ9N110HXmnyVwGYbA/MS9XxJK83KGhePa9LQngeBMpD14MZ5tkYdkzFA9nZhQ5CfRJGUi7/JzudIHVWthJGDDMB0qxzW7dmchfyEl9oSOam8KOKOXghON/Br2zPNlqt76od+HcLl7mhAudTg6DjQoct7jv6C09QyIsCYLvHuPNG0y0dj9FoIsH9Up/O3zypEEA6bnGDC/DkYRrCMVBvaLMISbiBweMVFUh4MNAvsNYk9vG6na1x/ygUVXp+pRub0mpmlzcc4aU5GsQ5uKeNpgvKUGNu4gUa7OcLboX7iFBzmnyc/wZd8g== 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)(7416002)(6916009)(36756003)(2616005)(6666004)(52116002)(316002)(54906003)(83380400001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: W0cGz94YFu7RTSeGaT0H+Q5LV8l6zibGI/oKzJd+D4Pa60dpQYaK+IDCQL6wLAMwA7H2rUZzCCH9qwYL5B6pTqzv17cQsrj4NL4085IbsY10w4VYq8vVcawBOI5u0IK9IPfqoA63h6HH8OH90fWQd8a7a85ICw/H96xEkiHUrfWeqADONpVaXptoJwP4vHqIuoEwkWCqvsTk8a+XVX+BnmgBNX5Bw6LI8ToJ48rgGT/oMPtW1LVYaNQs0ca9t2gNOIEdyRz9ln1BcFe2IVZAg54FzqoCzngN+04zuCmeIXXK0cNW3H4ZlcfKvAujCmDUM1DI35+frqfvK1t0nMl/roatsTpkOuVaV0uHAeWJ0vp+nHk+mUDzcrV4ccWeGV5R1kgtwR/PJnmeDNNtZKcSp+/B9RBksbNlHrE6mxygYSqyxqJrgWuiYelUbOywmV05oAOlyiGzvszadAkqPIEuTD70/xz/b36Bb8caYGIBi4lmRrYe52Va5atbLKJV59PXUDEvYlLm7mURn27H/ztmSGnUvhPESx4glw0GYnOYwocg6YNnwpzunvM5SZRWdJipieeERwFnSCi8kiyQ0BOwm+0nE9CgSYj36tLgA9ZD3ejuMAg1kdDiTnyRHiXUvtIWcJwVPJaB1ia4pUa8YjTgMQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4ecd2ab-e080-4af0-dd2f-08d83b0a4cf5 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:30.1487 (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: dv9L+2mUEiNgXJL+GsjsIyrRTslxyvAxegeuE6q7H5F1l4hRHOOFy+HNACu4HXpDEYQkGIw/jYZJs9nbEn+/Dw== 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 Protect the SEV-ES work area memory used by an SEV-ES guest. Regarding the lifecycle of the SEV-ES memory area: PcdSevEsWorkArea (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the SEV-ES area is initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If SEV-ES is enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with either an AcpiNVS (S3 enabled) or BootServicesData (S3 disabled) memory allocation HOB, in PEI. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/MemDetect.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 4742e1bdf42b..c53be2f4925c 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -118,6 +118,8 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 6b5fee166b5d..ffbbef891a11 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -940,5 +940,25 @@ InitializeRamRegions ( ); } } + +#ifdef MDE_CPU_X64 + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the SEV-ES work area. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + // If S3 is unsupported, then various drivers might still write to t= he + // work area. We ought to prevent DXE from serving allocation reques= ts + // such that they would overlap the work area. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase)= , + (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize), + mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData + ); + } +#endif } } --=20 2.27.0