From nobody Wed Feb 11 05:59:59 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+81909+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 1634144282994839.2907585362218; Wed, 13 Oct 2021 09:58:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id F3mNYY1788612xdTR6NLEH5l; Wed, 13 Oct 2021 09:58:02 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.49]) by mx.groups.io with SMTP id smtpd.web08.116.1634144279775917405 for ; Wed, 13 Oct 2021 09:58:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=emjEUcP1g9Rizh/C0Omq2/haEUE7QbtuBvMX8EoC21MpZRYUlcVmwqhpLZVr4Y7cd6Xnf1RMtYFfCM9VIt1UHNWaCoFBLY/xvMzp7hYmp7GhaMXP1/Vlql5XBBjjXU9pCVxFFkTKVZ2YqNai7vBV+nXTtfEh4DAQ09MPZPIL8Z1urPG/P3bviksP2ujB01T7koAXrZpr7qn1Rf/OjYlZsb3dbZlVtV6gcLi+3SLvOo9hCfu5n2NsPf45+l5u6PI9y68fd1SxQapYL8mlgLIDLy6thjak9IPdrHqOj/9DP25wW9mxWyhXyjO2TyOoPifQZaYV0q0q9v127Py9gxFThw== 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=v2Fx/75x/6c3x7A0PMVXdx4dTicA/iU+wOD3TCG65II=; b=n+AbagRybidcIWKsBxM2vyJiNXgDuQV/NCze0KZzhGVACFbpc+9xaHVAB9x52VYpp08CPkF6MyyKW2FQ5DFBtUuIZFN/ZPj/ucIoU6nw/HsVoWgjiCD/9wvPhEYV2ZdY+Iz6d/uXeMd36zVTJ5MENAXZIcYHAI9RGGk5LubcyFT1RZJJDs5i77W/GzxMO8SxRIYXjwKzL7h0aWhIRgELeugO8eic6gEL1c8ztuk2nHp0zJyts7nAKD0kYcZkWZFWYOPNxSIGTFcYAOU7YeQZOReqW47obzdU2yuMIcWkFgYCl0r2sc3LH5yTzc55x98hWx0gp7ncA7ECF+NruHR+TA== 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 MWHPR11CA0013.namprd11.prod.outlook.com (2603:10b6:301:1::23) by MWHPR12MB1472.namprd12.prod.outlook.com (2603:10b6:301:11::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:57:56 +0000 X-Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::4b) by MWHPR11CA0013.outlook.office365.com (2603:10b6:301:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +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+81909+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 CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +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.8; Wed, 13 Oct 2021 11:57:50 -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 v9 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Wed, 13 Oct 2021 11:57:00 -0500 Message-ID: <20211013165713.727815-20-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7319f39-ed91-4e09-388d-08d98e6a9ae7 X-MS-TrafficTypeDiagnostic: MWHPR12MB1472: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: qbltPvTJ7+/UWyOJCF7XCLocLfkrZTNWwzRFllzv5l/9miPsT7T+7AM/AMckk7rN5cCWLKDx4LXtYOkJH9RkOB+4MknriMBWq5Y/dONY+JjCZYZkqH+BslO8ZLwRTvq5+NW9AHIYsff6VXfEArqzsxr01bAJJE2wjKwH3qspb7gZFXRA04oQ3cnIaF7ef8xE31GHVoSzasDLZGKXK/QXX3ufvKxx/8BNANdlcCe6LOhWwVJBV9yRfBOZJSJhAaoQ2pklENa0f6gYVgFjfG40J7zPpWzsDGFHmRHNkCVdVRZO7k2gCVGbR9WU7LBu1JyEHsiZKFXqSxg1t34V6mykvS0PcVy0oXHCqG3InKH622jjaiyF4vxrmUYeLDWYWcVlsYeT8gEPQHvLZgArqbnKZ4jRjJaqLqintmnd3oAA4nSdvQtGHdWhp/b2xvKesvCGSL9UZjlMAbfOp5oWa4xCzKBd0ws+jbYaUv0wcPm+iR2J3rxdIccTCGVcg9OGYfZHGVOQNQKb+5R0hYiF1g9pt459X3vreLIQQ2uwOBGyclVHsqjpZPheyP9cDp4gmnxLtvOLBvH/HNDLPkUKwfic8qczCb3EHxyeJKPhfB47zPltAU3+sFeB37q0reJGiBTcR2J1at419WOR3HxCB02gocKLlhNsoXtAaTtEAvh9VUv8FwTxrcZc14rNd3dmWbC0uF3ZWZuRCryrejAZkhyY9Il/UAgjVkPiupWVTSDFa2lFss9RNili0/OzaYPPFgN0fiIXMGs/Y77q8n4m4VorGvnULL382tbnivcHsOHzIYyFzOMydyYvkgr7+pzw0iwZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.4700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7319f39-ed91-4e09-388d-08d98e6a9ae7 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: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1472 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: tKIT14GoNwV2OrMex16FA7Lfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144282; bh=3H/p40XkY+cnoBrAwp/PolJbLFcYvV4ZOW6MXaw3aNo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PZV7FRI5GNqxB9abyfp74Kg2vRGQiSr5B6gIt8RzvI9zAuk6yk1df77Wuttp61v+j9A oN+uf0YiexeYzfUk7E32CMjBp+HcgPvY9MeAUNZ4PBQ8p7EdfM23GsVEarSRPyNt+ZMaa /+1PBCSDwjlkVJjPqXUAUlOXgIgTdp3Dex0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144283263100021 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 When SEV-SNP is active, a memory region mapped encrypted in the page table must be validated before access. There are two approaches that can be taken to validate the system RAM detected during the PEI phase: 1) Validate on-demand OR 2) Validate before access On-demand =3D=3D=3D=3D=3D=3D=3D=3D=3D If memory is not validated before access, it will cause a #VC exception with the page-not-validated error code. The VC exception handler can perform the validation steps. The pages that have been validated will need to be tracked to avoid the double validation scenarios. The range of memory that has not been validated will need to be communicated to the OS through the recently introduced unaccepted memory type https://github.com/microsoft/mu_basecore/pull/66, so that OS can validate those ranges before using them. Validate before access =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Since the PEI phase detects all the available system RAM, use the MemEncryptSevSnpValidateSystemRam() function to pre-validate the system RAM in the PEI phase. For now, choose option 2 due to the dependency and the complexity of the on-demand 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 Signed-off-by: Brijesh Singh Acked-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/AmdSev.c | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index de876fdb478e..391e7bbb7dbd 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -23,6 +23,40 @@ =20 #include "Platform.h" =20 +/** + Initialize SEV-SNP support if running as an SEV-SNP guest. + +**/ +STATIC +VOID +AmdSevSnpInitialize ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + // + // Iterate through the system RAM and validate it. + // + for (Hob.Raw =3D GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw =3D GET_= NEXT_HOB (Hob)) { + if (Hob.Raw !=3D NULL && GET_HOB_TYPE (Hob) =3D=3D EFI_HOB_TYPE_RESOUR= CE_DESCRIPTOR) { + ResourceHob =3D Hob.ResourceDescriptor; + + if (ResourceHob->ResourceType =3D=3D EFI_RESOURCE_SYSTEM_MEMORY) { + MemEncryptSevSnpPreValidateSystemRam ( + ResourceHob->PhysicalStart, + EFI_SIZE_TO_PAGES ((UINTN) ResourceHob->ResourceLength) + ); + } + } + } +} + /** Handle an SEV-SNP/GHCB protocol check failure. =20 @@ -240,6 +274,14 @@ AmdSevInitialize ( return; } =20 + // + // Check and perform SEV-SNP initialization if required. This need to be + // done before the GHCB page is made shared in the AmdSevEsInitialize().= This + // is because the system RAM must be validated before it is made shared. + // The AmdSevSnpInitialize() validates the system RAM. + // + AmdSevSnpInitialize (); + // // Set Memory Encryption Mask PCD // --=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 (#81909): https://edk2.groups.io/g/devel/message/81909 Mute This Topic: https://groups.io/mt/86292907/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-