From nobody Sat Feb 7 06:55:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+82581+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634962478472540.0791900836051; Fri, 22 Oct 2021 21:14:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ix8MYY1788612xtzL4zsviiZ; Fri, 22 Oct 2021 21:14:38 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.48]) by mx.groups.io with SMTP id smtpd.web08.2776.1634962477536889480 for ; Fri, 22 Oct 2021 21:14:37 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QFn1vv4VFW0uWf1KPqbR9LwdhbAKDdaO09ffAG4FVBzHdAAaIKHfZvw1KlOENF/Ay99eXUxTsm01YTZinF1vSpb7x7kkQ7pjdy22M47dezLis8Uves6TJ1zjjEbTPEaaW4mhcVh0R3gfgwaqqQwcbt+MbLpvIl7AjDN/0Io4FmsWhrm20tQBeOxncx3aHlNvEzbpP374WrfoZwz/9e0TF4LXhaj7vgVUTUM+FsSCvu0F9pvNeVSWW5WVCuJZLsgl2fJJ/iyUqgTImD5WMLWD7aZfcHNz9m4AOf8PhQEGtcxsdZcQC9apKQecsXU6nMpBwZpSdP4jCyPTHbCb9Yrxwg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Q78Y9dUTMjc1Mm3ohrlMeD11Wx1hYFU9rEyg7kTg4Eg=; b=FkIQU1Zmwlso8Bujf6t6KEZLgXwZwHlF+UXcxpybhOP5Al13IrP9e0SW6DAmvGWw/iullWk0btu8Va3KtyTw15ZQJymUVoNoAsg+aTC6TYXS3Sb4mZUjoTGllazPqTmF/A+6qd5p5mMa68sGwLvLqrr+nguFgDhA9+LS8v2TvEKqX7FT4ocY4Mhhf22H4SZzbOAyKXHEPIPMPgrWEPVX/YpPyYAVBEJWS4ZEQYtpsxPtoyAMjnP8NbRbAOe7oftkvKnPazq78HlIjefT+eAw84DLAaakoOh2K6e62Y/J4c8I7creMz+pi6RbTN89zLx9bg53XybztC2Mj/GbJp8JCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from DM6PR01CA0018.prod.exchangelabs.com (2603:10b6:5:296::23) by MN2PR12MB4144.namprd12.prod.outlook.com (2603:10b6:208:15f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sat, 23 Oct 2021 04:14:33 +0000 X-Received: from DM6NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:5:296:cafe::11) by DM6PR01CA0018.outlook.office365.com (2603:10b6:5:296::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 04:14:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+82581+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT004.mail.protection.outlook.com (10.13.172.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4628.16 via Frontend Transport; Sat, 23 Oct 2021 04:14:32 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Fri, 22 Oct 2021 23:14:29 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [edk2-devel] [PATCH v11 16/32] OvmfPkg/BaseMemEncryptSevLib: skip the pre-validated system RAM Date: Fri, 22 Oct 2021 23:13:33 -0500 Message-ID: <20211023041349.1263726-17-brijesh.singh@amd.com> In-Reply-To: <20211023041349.1263726-1-brijesh.singh@amd.com> References: <20211023041349.1263726-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 35d2fad0-f980-4fa3-f48e-08d995db9dc4 X-MS-TrafficTypeDiagnostic: MN2PR12MB4144: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: iG2PPUSK+91JYmc1xpkkUCF6A9A2+VG/T7VlSpTKaJeuBxX85hmBhfGGPd1CTcbLeeCvS6SxEZiuohVZET5sFD5YBSGtEoGv1qEV3mU8DpSR/KTQe0jfkRM4pmj+osaF3oMVtEteo9aubm6GUC4rKTLecV0LDUFqZifZcojHkGceJcGi5sl0CPzwQGjp5C+Ny+RJu1PS7c6CnmwHlQETyNGuQe5WcgeXt+mgWPWA3OSjpAvSqL6LdwcSva1MHiaRLYvb7MIt8InyhpXsryGpe4lYBGPKOyT2mbtwEAfyr+HlVfRkNFPwishG0BoiZLUjv8nSyYUD1kn7J8RdIvHjRi2yDWuDBpqCeG0LaMplmkGUoJT0LFkLr0b/Mm+cTiOpdGq5dXV5KQfdTTbWBNDen72WwDSZiRlo6/O+sJiSER2GbO+WpelPh9TCHFtFM9yEmgWD1EUJrjShHhtkmJM1Z//1BmJYOREPVpeYJ9IIt+x0DGBKqtucC8nhfkYH1ZNJ2NoIdmN2OtwqPOkKh6uXwq91xKJae7FAILs6uk2GAoxT/7U6BGkEZE/caoHqRoEi0ijkETTx1m0gs0oG6OOeGXOFwD33yphVN7KpPdgNE4Z8cIEdVq++AGOXyV7gPlE6stvjXcqfJoQQ+PuAQd1FDfKX8GYu1TzwjdVz9hbKyBUWuiqVS1itu+SvDtJeXOpz/fHYbGvrW7zWSw5v6FpF4yysBnmIrBq3qmvl2rmmtvN69+peuXv51Ie/uyL4oMmeaXHOt+UFC80cr6WHqCAi++jpVLQW0WjQ7EopZJTyN2unVvgQwMcPzuHFlyynwHvIk0OlJK40ou4J3XYZ3F4L/SpmWB5dKyN7LYQK2cp4SB4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 04:14:32.6143 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 35d2fad0-f980-4fa3-f48e-08d995db9dc4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4144 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,brijesh.singh@amd.com X-Gm-Message-State: Ppn6qwKH5mwMVgpCF1BUhfaax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634962478; bh=gn4FxY0+m0AVJ6MsI1vIiJbN9aDwtvNfHQX+Bc9w6uE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=TmZbC7w/0Ffc6sFrwtnHh8OlTJTvclDoGcA5vnundJwYqODtvbbuJCFnNI6ojUemZxB C2GiGov/cUIKLNdVNRIsYkEX5VWjmktgRr+53gqIwAqC9m4+choTbOsvqJ10F27nt+t+x B2WRymTsnCEakg+H3hGTgcnlWgpeFZkHuiU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634962479116100064 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MemEncryptSevSnpPreValidateSystemRam() is used for pre-validating the system RAM. As the boot progress, each phase validates a fixed region of the RAM. In the PEI phase, the PlatformPei detects all the available RAM and calls to pre-validate the detected system RAM. While validating the system RAM in PEI phase, we must skip previously validated system RAM to avoid the double validation. 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 Acked-by: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../PeiMemEncryptSevLib.inf | 2 + .../X64/PeiSnpSystemRamValidate.c | 66 ++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b= /OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf index 0402e49a1028..49d5bd1beff1 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf @@ -58,3 +58,5 @@ [FeaturePcd] =20 [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValida= te.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c index 64aab7f45b6d..cea7ecf96563 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c @@ -14,6 +14,45 @@ =20 #include "SnpPageStateChange.h" =20 +typedef struct { + UINT64 StartAddress; + UINT64 EndAddress; +} SNP_PRE_VALIDATED_RANGE; + +STATIC SNP_PRE_VALIDATED_RANGE mPreValidatedRange[] =3D { + // The below address range was part of the SEV OVMF metadata, and range + // should be pre-validated by the Hypervisor. + { + FixedPcdGet32 (PcdOvmfSecPageTablesBase), + FixedPcdGet32 (PcdOvmfPeiMemFvBase), + }, +}; + +STATIC +BOOLEAN +DetectPreValidatedOverLap ( + IN PHYSICAL_ADDRESS StartAddress, + IN PHYSICAL_ADDRESS EndAddress, + OUT SNP_PRE_VALIDATED_RANGE *OverlapRange + ) +{ + UINTN i; + + // + // Check if the specified address range exist in pre-validated array. + // + for (i =3D 0; i < ARRAY_SIZE (mPreValidatedRange); i++) { + if ((mPreValidatedRange[i].StartAddress < EndAddress) && + (StartAddress < mPreValidatedRange[i].EndAddress)) { + OverlapRange->StartAddress =3D mPreValidatedRange[i].StartAddress; + OverlapRange->EndAddress =3D mPreValidatedRange[i].EndAddress; + return TRUE; + } + } + + return FALSE; +} + /** Pre-validate the system RAM when SEV-SNP is enabled in the guest VM. =20 @@ -28,9 +67,34 @@ MemEncryptSevSnpPreValidateSystemRam ( IN UINTN NumPages ) { + PHYSICAL_ADDRESS EndAddress; + SNP_PRE_VALIDATED_RANGE OverlapRange; + if (!MemEncryptSevSnpIsEnabled ()) { return; } =20 - InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); + EndAddress =3D BaseAddress + EFI_PAGES_TO_SIZE (NumPages); + + while (BaseAddress < EndAddress) { + // + // Check if the range overlaps with the pre-validated ranges. + // + if (DetectPreValidatedOverLap (BaseAddress, EndAddress, &OverlapRange)= ) { + // Validate the non-overlap regions. + if (BaseAddress < OverlapRange.StartAddress) { + NumPages =3D EFI_SIZE_TO_PAGES (OverlapRange.StartAddress - BaseAd= dress); + + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TR= UE); + } + + BaseAddress =3D OverlapRange.EndAddress; + continue; + } + + // Validate the remaining pages. + NumPages =3D EFI_SIZE_TO_PAGES (EndAddress - BaseAddress); + InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE); + BaseAddress =3D EndAddress; + } } --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82581): https://edk2.groups.io/g/devel/message/82581 Mute This Topic: https://groups.io/mt/86530730/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-