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.84]) by mx.groups.io with SMTP id smtpd.web12.21050.1594737498874057781 for ; Tue, 14 Jul 2020 07:38:19 -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=16MpgpD3; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.84, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S+jhBlpWsQZt5JCwisIbZ8nmsmipDDMPWAMTX9OYknB92j6YyCRTXe6cK+aw96itwgvGxcsOBBMna3cf9LqzPMFUj4qBSIyO8YRZjA0aBzGl56JRu+4YocN4rv79wMgxEhawA291/fjmSsJadOuMlirba/VeNmziBQR3t3Mfea2uOvspppg6WGx99Xd+FkCDc+O4xZ+ss9ToSe2SfvNWBa6WVvRqVrffkuDmuU86xmq7NYE1TAnaszkyBGfbRFBjX7nspIZRAi9jxLnOuOY0uc+SLJjX1kdFlJj7gKbT0/TCGzrSvxlD0yoUL5ifSa4XXdRqW29HHiG3nqRvBbqRwQ== 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=JMMyOUSzLpgKCkP2EJsbCGKWGY0ptEMbl6UsuG9Wkrqk0BxAhdrEXjDn4PNHSR6tguQ5NexzxutMw/bwAjvIwFc8anGAbDlICRId9VEsUU5adVaVRwwOXutnndAB5G2liYogUpy1Jh7OU/82/Ez2qUbGprCttYWzCMxCyeHEaNTFDOEw/l2NKTrAFpPKU/nDo+i2qQb61lC4DfYXJOcbt0rYHQzZubR5FRRzpc987pqJhcf7MEpA+Hv9GC15iY8VaY5S89YtxCzAwy127pc97dyAR08r/koMwec6nEACPhjQFM9tJqhkH3k/Vy5lmo+QJoTbveerNsMOnLLTy8TZKg== 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=16MpgpD34O+Lp+CMqtVw2rP1qfqY+z1Yto1lCJQOJAFP1JaY6s9YIhcW7b+C77Mxtt0uXDzRnGfQMMVJ68w31RKKinuL3FNM8TnVgIInKQ9TkPNzGEBXB1kdDFxX2pS3N9q/3EusJpLT+lVGGAjiFcafva7O/wENDimG4OHeYL8= 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 DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:17 +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.3174.026; Tue, 14 Jul 2020 14:38:17 +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 v10 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Tue, 14 Jul 2020 09:37:42 -0500 Message-ID: <1c1874d966a84ac5be778df4ce682dd33821fd49.1594736896.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) 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 DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:16 +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: 2d6f8ab4-dd7f-4098-0144-08d828038c24 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: 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: bzQfgKRpds+n+nbOekdfeduqxjW4MJJDseG7ADH2AHfRvRsidDD8dYuFWdT8krto3AV611qIZE70iDErBux8yxIwitlHrwMszhIjequ0nnp3nDeFXJfBvyiu/RaRrQYHTkAN487NgnMO346OT5W8ahnVKKIVnlQKeQ/V0Afp+7lFbUt0svwCqFm+IcCUnaosKtWbQ9CS01wFzMLI9K9XcLZKBw0QY7KKjUOpt59DRnAPxyfgFWBvZICzLPP2DrKABDWRHCoiZ1XYtp+twORs4bQ99ntA5KMLjyCsr+UtyGGvVyKC7PcblSeBJtpIl0Wud9O4b5SUfKIlkStPpaBCQNK7xCIzLYesp5xhyIE6UrN7aOTykRpRXxBBen9+1/Z2jzv9D1xIV18hzBg2t7ki0vMoKOh3yeFV+QKwyl0DoTR2YFrc6TaxLW5YJ+UDk4W7WaWZicThgMj1SKKUuo5s9Q== 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)(346002)(136003)(39860400002)(366004)(376002)(396003)(7416002)(4326008)(316002)(66476007)(2616005)(6916009)(36756003)(2906002)(66556008)(66946007)(54906003)(52116002)(7696005)(6486002)(956004)(8676002)(86362001)(5660300002)(6666004)(186003)(966005)(16526019)(26005)(83380400001)(478600001)(8936002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ZQEOGmTkH+YsV34daRhJ+7cWq82pBxsuiehYElct57Fh4Sg29RONe9IF9Jl6PngczQRB3M0N+SHAyDEXecXkVRgWTYqu0BbAosyYp3CCCPQ7g5hv5K2DQZMMOjaimDoi4xQy7z2vlpxQ9KiugmA4nj5j/z2ERcZZAYKamrQWTF5kcim27PtvbvYDL+vh18CxMKwq0qAcBY/VI4s0C7qmzX+ZvuayzyYeaCfLbFvBs3LjGFqD7oxoXNBr5UZQPiLLAaTREW7bEYQbPK/53+rLy37PBz3woBxlpVShTrMgSQofjCoXt2ApNDKgYTJHxKBZmUmZ1Q/uVEV5kxDDAZNFy3fV0cWTh2w+QwGRujksgM6in5+hBhyiaM4aVv+cUTdeYOqQGYLUD9fjEeqiIAO00x+9+K3/uV/vBBknzkSATcpZ2QjTx+FntRGW1IVx3CgXHDeXySwfDpYGaMXTHEA/Dqglvt1bYcygb6YEjc+1qQs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d6f8ab4-dd7f-4098-0144-08d828038c24 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:17.6876 (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: w71ah+DR4+Yl3wXA48krJQLVOyG3P0YvsCXpx9ZIkTszE3jFio5q/dePKlySSwkm27iE/6s3vvrspw/T4K3IRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 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