From nobody Mon Feb 9 18:44:32 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+84546+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639020509821721.0382739198822; Wed, 8 Dec 2021 19:28:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id v5zfYY1788612x7iTeKuxntC; Wed, 08 Dec 2021 19:28:29 -0800 X-Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.70]) by mx.groups.io with SMTP id smtpd.web11.6926.1639020508070053888 for ; Wed, 08 Dec 2021 19:28:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bHaJ4+8gJS3ypT+rX/ZC0rNNWeUouCMEMplb7mWEI7topF20pb3AWwlHUJsn/LwUV+BdwcP2+QhHk97/nZQE51BEUyVlzzGn9eHEMemn0miZtcl0Y6OzQ3M2PE/QMMLQYZAFIpXLGKPG8pmLcrNnCAMKqPR6r5ezqE+yVedUiHuD/HFUyhOUaaKtR6EdgwefVAJN0cXGpP0tXBakA1irP/iYn2Guc5X3Y1+sP5Ctc7F0R192vBN0N3myDmQ4z2P0gSfDXOtvzTmfjlzOk9+awJFOQtj7hCh2q8A5as2/tgkM2fGGD2JmqCwUtqRUx2QGJdc6CU1ycSRfO0o4ZEHThw== 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=M++kr5DN/B2FTyRoR63HI0w7bzxmLkn7Y5lJWqyMeHU=; b=bojjtZw6VS9e1UZaDv3M41A74JCAOQ1rUuMtjzxP1l/lRJIMnrxknujkqiMt1R6SUZ0KNFDEYWyjxSajnLyEAlDUW+DLV2+VGwCfcS93AlLIN6bqRQBTCkqETDMnLcflC+RelPuHavNd9/cwABBzv5MmHcXU52sXDHawSUWwXo1KddHayrkAvERQ9M9JOwEoA3Ov4il7T29Lpn4hDK7gn0zVC9g22vRj7/BizOFLCgauLtCnencm/zuNc6EVZ+1+L6QL/F54WXzzQEp/dpaeyAlU9sCFLE5OEeChvrxCpdrI0SimwfdqS9Rf2rkNLvpm7RvA2/77R2Cx9OLi4qu3yA== 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 MWHPR1201CA0018.namprd12.prod.outlook.com (2603:10b6:301:4a::28) by BY5PR12MB4259.namprd12.prod.outlook.com (2603:10b6:a03:202::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Thu, 9 Dec 2021 03:28:25 +0000 X-Received: from CO1NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:301:4a:cafe::6f) by MWHPR1201CA0018.outlook.office365.com (2603:10b6:301:4a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:28:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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+84546+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=SATLEXMB03.amd.com; X-Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT015.mail.protection.outlook.com (10.13.175.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:25 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 8 Dec 2021 21:28:23 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v14 07/32] OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase Date: Wed, 8 Dec 2021 21:27:35 -0600 Message-ID: <20211209032800.3802995-8-brijesh.singh@amd.com> In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca7890d9-29b9-4b80-a227-08d9bac3f5c8 X-MS-TrafficTypeDiagnostic: BY5PR12MB4259:EE_ 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: 7iYzt24YN0iW5r0+ru95SOQJPz+Ha1C8RHdk0F8tGlMxc/zZ0xKynkgIR8Mulz3bAj9Vr5YSHK+vVpTCCkVRZ0e2+KrTcR9KpRsHrD4NUmijOK3KAsyjQg21fwJXk4oBV3KU4pQhVflIvKvnw90M3OjK6UsPCuP89jgCqdSwBpXDOpM3W0gCQjZK7je9AVGWrl/UCUXsFUU2RSoO1K0lt4pTiaSs3JP676avxGJidTbgLmXA6Poa2/Pc7N41c/8Kabb9YwQ2FASmbwXvvJxRkR1+pSMCNLX+q2dSHdhZQfhi3Knrs41m37y1OErpbnCq+z0Ttg7WB6sbWhgKtzSD4JHmkvkETGC9jWnVu9LN4yLKFzacq1TolcRUO/dxQwJl8YohzPiP7jDdaAwFvIGxbep71RjpfktsRqOfkASAJ+FhfQquGP8StDRpgWiUYuj3J2v6GGvpPKTQlC7NpHtwuyIezhReUu7vx9A+rgga+CYtS7FvqUaG29mZ1vY351isNtZrakU8TgjjWSMOE8ZZJ5NRqncyOg7YcvUezDf5WjyVM9Etc1oz/elhWig2Bb3/4fkdueTKnJUVLxYLADdbVtHGM+MlrYB6j3dgYT6T7D68HsW1F0dJj0mcV9ux/8FhTGMRR1pRTCAZwV+5D9QjW5zTNNYGlLq6aXyS34ylwJX4es7hUAR6WyYD9CcilXiEBRCBsw+pLZgjp3dNrHA7wtN4e8yjrZ8+4wVKtyMtvVXc7rpUHMcKcv6vudQnsSai27GtrCQPccUmG0NMCmt9xbi8Mq5aHpV6+sFEP5BaxORs7XQet4zkRbi61i/A0i3QE37NWyBD9jGYFzlYPFooACAalzR+rIWKkY1cIfnFUMhja6+zRKUlR0SPclnhnVu/ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:25.2964 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca7890d9-29b9-4b80-a227-08d9bac3f5c8 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4259 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: aBj5fPsWKzkxlYe282dl7zaqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639020509; bh=BxsblESWl+It5JIWC96f71VBRNHr1WXFQPtkYsVKeQU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=HC5SDD8QNWS6KROxMwhI8lrGp36tmEDEZOaUBv9GmaSK5M4MkuiOhE8esPQS1n40TkE A7C78YmMyLkEU3oPKsspXIkEn7Nz1pc+qb0ZXHSdp3QZuhgLjKnZCn/g2w2AORxqKHHK6 eb4iJpRe+pmFRWiO9CsSV811G2v220KTSR0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639020510717100004 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 An SEV-SNP guest requires that private memory (aka pages mapped encrypted) must be validated before being accessed. The validation process consist of the following sequence: 1) Set the memory encryption attribute in the page table (aka C-bit). Note: If the processor is in non-PAE mode, then all the memory accesses are considered private. 2) Add the memory range as private in the RMP table. This can be performed using the Page State Change VMGEXIT defined in the GHCB specification. 3) Use the PVALIDATE instruction to set the Validated Bit in the RMP table. During the guest creation time, the VMM encrypts the OVMF_CODE.fd using the SEV-SNP firmware provided LAUNCH_UPDATE_DATA command. In addition to encrypting the content, the command also validates the memory region. This allows us to execute the code without going through the validation sequence. During execution, the reset vector need to access some data pages (such as page tables, SevESWorkarea, Sec stack). The data pages are accessed as private memory. The data pages are not part of the OVMF_CODE.fd, so they were not validated during the guest creation. There are two approaches we can take to validate the data pages before the access: a) Enhance the OVMF reset vector code to validate the pages as described above (go through step 2 - 3). OR b) Validate the pages during the guest creation time. The SEV firmware provides a command which can be used by the VMM to validate the pages without affecting the measurement of the launch. Approach #b seems much simpler; it does not require any changes to the OVMF reset vector code. Update the OVMF metadata with the list of regions that must be pre-validated by the VMM before the boot. 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: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/ResetVector/ResetVector.inf | 1 + OvmfPkg/ResetVector/ResetVector.nasmb | 13 +++++++++++++ OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 1c5d84184ed7..a4154ca90c28 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -57,6 +57,7 @@ [Pcd] [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index fbaeab5f5168..cc364748b592 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -107,6 +107,19 @@ %define SEV_SNP_SECRETS_SIZE (FixedPcdGet32 (PcdOvmfSnpSecretsSize)) %define CPUID_BASE (FixedPcdGet32 (PcdOvmfCpuidBase)) %define CPUID_SIZE (FixedPcdGet32 (PcdOvmfCpuidSize)) + %define SNP_SEC_MEM_BASE_DESC_1 (FixedPcdGet32 (PcdOvmfSecPageTablesBase= )) + %define SNP_SEC_MEM_SIZE_DESC_1 (FixedPcdGet32 (PcdOvmfSecGhcbBase) - SN= P_SEC_MEM_BASE_DESC_1) + ; + ; The PcdOvmfSecGhcbBase reserves two GHCB pages. The first page is used + ; as GHCB shared page and second is used for bookkeeping to support the + ; nested GHCB in SEC phase. The bookkeeping page is mapped private. The = VMM + ; does not need to validate the shared page but it need to validate the + ; bookkeeping page. + ; + %define SNP_SEC_MEM_BASE_DESC_2 (GHCB_BASE + 0x1000) + %define SNP_SEC_MEM_SIZE_DESC_2 (SEV_SNP_SECRETS_BASE - SNP_SEC_MEM_BASE= _DESC_2) + %define SNP_SEC_MEM_BASE_DESC_3 (CPUID_BASE + CPUID_SIZE) + %define SNP_SEC_MEM_SIZE_DESC_3 (FixedPcdGet32 (PcdOvmfPeiMemFvBase) - S= NP_SEC_MEM_BASE_DESC_3) =20 %include "X64/IntelTdxMetadata.asm" %include "Ia32/Flat32ToFlat64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index 0cc12ad3473f..d03fc6d45175 100644 --- a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -43,6 +43,16 @@ _DescriptorSev: DD OVMF_SEV_METADATA_VERSION ; Version DD (OvmfSevGuidedStructureEnd - _DescriptorSev - 16) / 12 ; Number of se= ctions =20 +; Region need to be pre-validated by the hypervisor +PreValidate1: + DD SNP_SEC_MEM_BASE_DESC_1 + DD SNP_SEC_MEM_SIZE_DESC_1 + DD OVMF_SECTION_TYPE_SNP_SEC_MEM +PreValidate2: + DD SNP_SEC_MEM_BASE_DESC_2 + DD SNP_SEC_MEM_SIZE_DESC_2 + DD OVMF_SECTION_TYPE_SNP_SEC_MEM + ; SEV-SNP Secrets page SevSnpSecrets: DD SEV_SNP_SECRETS_BASE @@ -55,5 +65,10 @@ CpuidSec: DD CPUID_SIZE DD OVMF_SECTION_TYPE_CPUID =20 +; Region need to be pre-validated by the hypervisor +PreValidate3: + DD SNP_SEC_MEM_BASE_DESC_3 + DD SNP_SEC_MEM_SIZE_DESC_3 + DD OVMF_SECTION_TYPE_SNP_SEC_MEM OvmfSevGuidedStructureEnd: ALIGN 16 --=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 (#84546): https://edk2.groups.io/g/devel/message/84546 Mute This Topic: https://groups.io/mt/87605528/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-