From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.49]) by mx.groups.io with SMTP id smtpd.web11.861.1631557222462732596 for ; Mon, 13 Sep 2021 11:20:24 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=ai1Z5Rtm; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.94.49, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HLAS1zuRkJZ1uFUKnKXviiAuct4Hi3ZDHg/KC8AUm1RUS2zoGiMB6u0+mDJTv+XQvzYM5uAgnIunT5878kidIiWsBtSfCUy1w84IeT42lppB4zKwkdtD+gTiCZqW8ds4m5xu7Edo68ndhy6vn0nEWfq5i/ETrkXX/qaHj1LGm77xCxwTcZ4hbiyqn8jGEsre93MnmskOG2urdLW53vnxjk9ztq9t5L5A5q40s2ElW5G+GkQV6NsUUs8j5ecyifkMGZUiAgY0jPYSMnyxEJyQa8imOc/dL3htQ3Hpk07EMLilZ/pVIB57oI80j1wKqfNF0jIGOn/83dxwxNroS1FupQ== 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; bh=pwpi8MIvNwBm9Pg1DHPEmiNjZlZPBCjDGkzbyqzmg20=; b=e94Me02sujGPPu+EES3wzlVwNcUfemiVZ5Bp3EYR52B6CXLHCj2tuitVVUSOeRBNg8b+aizta0+xkn65LRG/idzZj/o61SsdssOfWUagk6tFueMxsFkzpWls/3yARpT7PTlDBhQXvLpRjtqzc3EhNufB65ma+s8vIhyPnQ/oj+RH4m6ZPt32frL8X8/oGn0JxkSU9ypy2Byb5J6Y/kQBGO+sibI6bxm9q4gDkozzjeYLBYBv9mDsCrg7K2hcmKbn1bLvInIbVxdZnxY+0ppnTDltIJP12wlJl/tNkdpcprr4clmxDBToLBtw7uqyl+RrGBNpNdbQ594znzoLw5bhew== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pwpi8MIvNwBm9Pg1DHPEmiNjZlZPBCjDGkzbyqzmg20=; b=ai1Z5Rtm1tcUATV7X6QcmV7gmq+QGLKjOBQQJiWTKLFa7zt4WvqCdeqqYTWqLQqKIhpf46w/ngqz+pHHfFblsy05pS9a5Mqzv4tPXhO2Iy6Gs9+AqlKmZgUzxjulwa2mQWC7XSQMi129uXf2Ja7zZR76NTx/PK/sKgIIkey4G04= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2830.namprd12.prod.outlook.com (2603:10b6:805:e0::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 18:20:22 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 18:20:22 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Michael Roth , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [PATCH v7 29/31] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Mon, 13 Sep 2021 13:19:39 -0500 Message-ID: <20210913181941.23405-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210913181941.23405-1-brijesh.singh@amd.com> References: <20210913181941.23405-1-brijesh.singh@amd.com> X-ClientProxiedBy: SA9P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::17) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9P221CA0012.NAMP221.PROD.OUTLOOK.COM (2603:10b6:806:25::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 18:20:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dc39b36f-1b0e-468c-2045-08d976e32617 X-MS-TrafficTypeDiagnostic: SN6PR12MB2830: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yk3IDdvjMyvQk2Iz3LZ6coDw+jY8ZHyWdzwMBF9b/u4c0U+gyx570cUn2beyfOG8vxnKEzqvrqbee0oE9/dTPQifFWuXLaAbknRGkRogfvxxhh2QLjdMt4g4zM/mdkhziPdqm+k3X7BRQmnUmJKmJcEgSLNn2k4vTwNb4pgguruFw62RJF8LJAxBKd6SKUWUpxivVT5of1TUhxKi3pqQx547Ccg8DGfYbXNeXqfcHDBoJAe1jv7WLPwqEbTqTudH9wASzViNNa92KpvJUDwig7m+BdOB4w5czWme/x0Hsfirmoz8KoqEF8DGPePU8ffOZtyLtmuF3hyDc4maVBQCeuyjZGEfuN8/7xgwOVQAVA5O6KPxdSJsZ4Odi8D2gUg1kDJxS2iLm8pkZ7TKqogtLYKyuARWdxaUUkCshQb+2rlU5fI2quEDOezsmdUdTM0UsVi4EgdTWwaKQmcqsXdFepEmDnnZTnywrCsUH4N/IRIDxSFScrJAMnWQQ7sQXDQfz7tVK9RcXlNcjUR6VUH+IxNCp/qgSXDz/xQYcFQQdvUw0+jR4B8d21nyijQ6ofKNpCC2kpySHWUvZQKDHAlwaEXnk80yOuBBnMrUDMZxkOXzRISq2Vs4VxfWaFbX7JI1ZkhMGI8mCADx0GGPN3pFFQCNOalRoziZd6cyKmZ/fF1me4PUvpRqJkIT2BDnh3xB23D8kpk1Jr51uKRnMbEA8g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(39860400002)(366004)(136003)(396003)(376002)(38100700002)(38350700002)(54906003)(4326008)(1076003)(186003)(6916009)(66476007)(956004)(2906002)(6666004)(66946007)(66556008)(2616005)(8936002)(83380400001)(478600001)(44832011)(8676002)(5660300002)(26005)(86362001)(316002)(6486002)(36756003)(52116002)(7696005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?67EyRxoowdcsxa15AMLLFL37LZwPQy5JXX6NFMyUELAufBbgn/eTT/y3fXyt?= =?us-ascii?Q?UdWCoiHF0uYTf3psQuoCwVhmOzTfQYN2yLYJA2KxiUOVgCKSNREC5lnYDj2u?= =?us-ascii?Q?lG1EzcVc1mW4eKKvH2ny9BYEHEiRJ0SCXdDRrxj8qdbdrNm+R3oqT7wQ/SNc?= =?us-ascii?Q?Dq5em0gf0IJ7lu+1wq7B2e6SZA+KzfV4p6s1Ja8YriFDPHgDShv+sJOPl/Jp?= =?us-ascii?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MZ+Sz?= =?us-ascii?Q?WPg0svBqLjo+e0SYN55Mdz9ymlCMvvZ0zKheGqlTJ0ehWzVYYOMnuHtnow1j?= =?us-ascii?Q?lUNur5K/Gg8Z4vQjd4R7w5Arj5Snvem6TXAQ0NB+MLC0C/P3BsNdSuI/9L6Z?= =?us-ascii?Q?lERieseToPMY3CYOjK7MKPKcac1I8V2kmpvN14KcmPAIRLTf+CGc9i6IIt4F?= =?us-ascii?Q?Eyous9wSZ47rmv0X+bMVw4Fa?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc39b36f-1b0e-468c-2045-08d976e32617 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 18:20:22.2107 (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: z7GysI4BoqGU5Hu4gtWTrZu+LFi8gComDqOYy4b76lk+efeptWxkr+kNxRLU97jUml6hUxOYCqatlO1wmDjHLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2830 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain When SEV-SNP is active, the CPUID and Secrets memory range contains the information that is used during the VM boot. The content need to be persist across the kexec boot. Mark the memory range as Reserved in the EFI map so that guest OS or firmware does not use the range as a system RAM. Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/Platform.h | 5 +++++ OvmfPkg/PlatformPei/AmdSev.c | 31 +++++++++++++++++++++++++++++ OvmfPkg/PlatformPei/MemDetect.c | 2 ++ 4 files changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index d048b692f155..0a89e1a0760e 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -112,6 +112,8 @@ [Pcd] =20 =20 [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory @@ -122,6 +124,8 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.= h index 8b1d270c2b0b..4169019b4c07 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -102,6 +102,11 @@ AmdSevInitialize ( VOID ); =20 +VOID +SevInitializeRam ( + VOID + ); + extern EFI_BOOT_MODE mBootMode; =20 extern BOOLEAN mS3Supported; diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index b71a4a7304f7..133382407bc5 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -414,3 +414,34 @@ AmdSevInitialize ( ASSERT_RETURN_ERROR (PcdStatus); =20 } + +/** + The function performs SEV specific region initialization. + + **/ +VOID +SevInitializeRam ( + VOID + ) +{ + if (MemEncryptSevSnpIsEnabled ()) { + // + // If SEV-SNP is enabled, reserve the Secrets and CPUID memory area. + // + // This memory range is given to the PSP by the hypervisor to populate + // the information used during the SNP VM boots, and it need to persis= t + // across the kexec boots. Mark it as EfiReservedMemoryType so that + // the guest firmware and OS does not use it as a system memory. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSnpSecretsBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSnpSecretsSize), + EfiReservedMemoryType + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfCpuidBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfCpuidSize), + EfiReservedMemoryType + ); + } +} diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 2c2c4641ec8a..96487b810014 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -817,6 +817,8 @@ InitializeRamRegions ( { QemuInitializeRam (); =20 + SevInitializeRam (); + if (mS3Supported && mBootMode !=3D BOOT_ON_S3_RESUME) { // // This is the memory range that will be used for PEI on S3 resume --=20 2.17.1