From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.53]) by mx.groups.io with SMTP id smtpd.web11.983.1589925154464670122 for ; Tue, 19 May 2020 14:52:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=GyJhHBjx; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.53, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QGSrsBhpKVzdHoPmt49i83wtxVgr7ff/4lz8b4aYEE/JK8TG4Q+ktFB/76ZPdGkL0fLO9F6hCsj6BKokOtWFyoRV+dnsQldqwPFzaLGtFqAee9vPwtB1+e7LHy+mSphLU34rMFlZxwhdkSJnw3xk1By+ic4y+RlUEHOAuFILDWB3QPxPiGmh3JYyjA4xe44+00ZwnueVE1HVjN5KbqmT1RRCbCDrmH7HIuc1VqOQxWBdvlzhrxtcqpvx/3+CxkVNnSKrghhLYsQzudRU4TiBN+15WTZz0BEw5rgz/un+ZEy8/+HrP5A4xrQ+vqd5g+4rM/RTZCw2U8dg1EbFz96hRw== 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=0b1LbnyzWL6MhHhbC6SyUam6dJ1XU7uVcJRYFhYCqSA=; b=MR5eP2doZq2+GpA14v1iHFzcl7QQgu5dly3ytmnKPAg8ZZ2MEqB9gNXoLyh3I9rnuxrc7F/zeZBnBm7jZpS3eOvDaN/rI9LLYM8n9OdgaWGNXEnee7655BgS8fW5Yig22qUe1rNXStTjrDcx4ij0moXTAke/cQ44P9kivTEFVs2vnELvGByr5q655VArYRReJrkb2LVe703OPVLd3essNG67Y0ZWESr0UHvv31sveg9Ytu4av/w8Yw4H7xx9BqqGU9Hwz+LVOyCH+lSQZ7/DFXyUd+rjSA5ceByIxFkGzRXHQqHpJ+PQTrfDtgFRXolBCm+B/+EBO/Al5B5MBg5pPA== 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=0b1LbnyzWL6MhHhbC6SyUam6dJ1XU7uVcJRYFhYCqSA=; b=GyJhHBjx3D+jz5eQ7RZ4OpRoqGgDp+YcN0m1RCLFboJ5C77IPnhC5hqw18ciFLhBlTWAbzpeaPCeEoq3baUNd4Jkk/7HOZB9XaKJXJGPPUtM4SeUY5KDHsyEHTlHR4Tzqo0Pfnm+rA++CZAezQR2pCc6eiTBgT6QBM+KQf/MOhU= 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:31 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:31 +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 , Ard Biesheuvel , Anthony Perard , Julien Grall Subject: [PATCH v8 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Tue, 19 May 2020 16:51:03 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) 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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52:03 +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: faa9d040-0f44-4461-11cc-08d7fc3ede03 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZZmfqWyqVkZz8EpQ5vbo5tQnjCtmh/N2sVC9ZSUmG7d//+oKX9kMwGkE9bteXzFIUCe1d3udDMjRSyt55KUjymnu+IdO7EuHDzSxHSFhxC3RJcu8r+wpXAcPkcZIrlMss3pzsmfMF0FkAXkBp5uw/BH5rnqB88mcBbQLq8p7b0UzkPw3xp0iQBVaO7Z+ebAdvUCRcDPjHZApO5ewbNDPKWl4zLlmojN/f/ull1O0hmFMCz5I+G5tE6eu6yYhMuRfZy8z7hvGuj0BoVGMNlMtYUgqJFHYYdBB/qBdtsu+uVHIFZFIgTiW/4l6QlutMnuxkMUheff0tilYK24BRYGQgMxZOS6kAJ2yZ2MwUR+ejvmvkmY2Be7yDrpzfYlxpZCvcgIdEZZwrAGiKnbfeQm4xpWe5QqrY8iq48vN9SlfDJUY3xklJckgMEKksas+wcujTcDa1843x+xvr6uwnopOlYLodXoXv3eP7OiiVlIVFm1NuX/FXZHN8+n/Tfg1ZbqPdFSs5vzwSXdaScc5gHOEHdjbEQqXifEbNsSf8jAHF5ezkYfn5tL9DYMcFGDsfSV5VAWZP08C238XkV3I/3O3sw== 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)(376002)(39860400002)(136003)(346002)(396003)(366004)(316002)(86362001)(2906002)(54906003)(7696005)(52116002)(2616005)(956004)(66946007)(66476007)(66556008)(36756003)(26005)(16526019)(186003)(7416002)(4326008)(8676002)(5660300002)(966005)(6486002)(8936002)(6916009)(478600001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vu7191C+K1SrqICoQ9cZgOWIr9jUnPKWKa5PM8fgFQ2kzajjJLTxEn7B8/YRvhry9/PD7TtszxiaoESe4Sr8AjK5tTMj8sT3xiNrUleuw2erpXnsV7lOsxxVtMdWPpFwO4Y67Iw0WpxbuqBhqQWiaMcROIxayoiycSvkzKtPsT9a4aMYl1qMfU+/CPnmOt7PLcDHpKU9UP9kxQFAdmQdK5FlEh5ERYavzTGz0hBixqBhxEy5by9N84ODEnuRSMiUVsOfo6TkZYUGomnuUJhn80fLbb5rJ0CfmHDN41F8qkuigBuWRzw10NKaLb/UpVklpDEFEdx/JYbicSPRiGkYQuhIMSsbxrQ5fz8thocxeGwfzy26AftlPmB+0GQwZScNHEA/fM8A4LnnqhRvfByu+8A01ARj9rTd6hlfgp913Ae+LDKil3VlAZqE3L8G0Q1cJjj6AkVO/MRR5nU6zvu+k0BNC5OpMhsoqRDDlZ3XffU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: faa9d040-0f44-4461-11cc-08d7fc3ede03 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:04.0758 (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: o6DAh+YumBr/rxXsiY/x2gTHh+Z29+vPePIK/Va6hruNmYtuTR7e9bWvXCZUJxGOcZnoxXLE2mIpx8OPptEKCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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 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/PlatformPei.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 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.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 the + // work area. We ought to prevent DXE from serving allocation requests + // such that they would overlap the work area. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase), + (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize), + mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData + ); + } +#endif } } -- 2.17.1