From nobody Tue Feb 10 15:29:40 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+82365+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 16346724082291000.9559778664844; Tue, 19 Oct 2021 12:40:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TNcyYY1788612xxO1pFVGoqc; Tue, 19 Oct 2021 12:40:07 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.51]) by mx.groups.io with SMTP id smtpd.web11.14914.1634672406946685215 for ; Tue, 19 Oct 2021 12:40:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CnNzfC7H4jrG4LZGAhjGOk4sLNyzuGW2RVW2z4/r2rjFzWTmIT1as2HawbNTnWuyeq4uWIoXfrhKQP51PdHZaxJQbsIELqV0be2AeIWvkVLOrzm9rH37O7797JJT/fRKXzkmg0Sv0vh6zvSqSq7HrlEDB1xljsrjv7XYyH3RH/fR+pI0LMHVZV4LJ1BRyP4uRTAlzUxiq1tDMc8kM2XXg1RLuDIaKVGnTSBlDRFFIEok++Pxyx7J6CAEuNqG2WQMZRW5fSJLlu4g/7MljwEpu1ebB/YRqeEDDhg1CoaQjuR5WNNALnLuUXTBTSa0nU7wAgO7uPc38gDZaLtEaXJQKw== 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=XgEXyfme94W9Y78ncf0IbCAAb8OiVuyf4Q7q8S2QyqM=; b=dvW9tzxz4f3ruAS3pgDl2qAW99ouQ09S9NwupvpIvJT6h9GbtHRWQABF3qsLpNiEABEBACGMg+qNZf2gUYV3Wmyft9AU4A5Vul0MpAtGvQLRRgxici5QqTKkagYUig5Xz2tfXyN16YziCuLuKCUEcUvYud04bMfSJHs1vbmmRP9s1uOhDdDepn+U6GqeCizXlNtaEqEnGLvXkD2SwbuvtrGUHPO1zXVaCACe3/nRFg7aHZ0fG+2nrHzoiBd/8hoElklQbdiPvIqvn86lCNvFz+OwYZafl+Paaq0Fz5Xb39sJ3KF5KQacnQyeUhdsPC+sFGjEVaaQ3wa9C9mb2fObcA== 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 MWHPR14CA0058.namprd14.prod.outlook.com (2603:10b6:300:81::20) by MN2PR12MB3229.namprd12.prod.outlook.com (2603:10b6:208:102::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 19:40:02 +0000 X-Received: from CO1NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:300:81:cafe::bd) by MWHPR14CA0058.outlook.office365.com (2603:10b6:300:81::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:02 +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+82365+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 CO1NAM11FT004.mail.protection.outlook.com (10.13.175.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:01 +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; Tue, 19 Oct 2021 14:39:55 -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 Subject: [edk2-devel] [PATCH v10 07/32] OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase Date: Tue, 19 Oct 2021 14:39:09 -0500 Message-ID: <20211019193934.1052465-8-brijesh.singh@amd.com> In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-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: 2251d3de-7371-4015-2cae-08d993383e14 X-MS-TrafficTypeDiagnostic: MN2PR12MB3229: 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: mRlmxgGlWm5k3fOCosiMHK4t2pchy7160dkLGvGCoIKHAUTawQsD4WCRow0OQ7FRtQAgQiYwOAIJ/BkoVczf3t0PvTc9++0O4uGu3vGms+bS3G+ulvrnb5kAS5TH3E59ozo9hAtapATz/Gg58h+WBbXi49ol5ouqnXKfo9b9vCffGOUSX+atNiDMkU4UyDSYR7hkDHf/cW38khwJ821spJDgEGGCE3zbEyKyr0snNgZpqv8/eKliEBmuxaYmglWj9nXccNRqye2OwTnAMpn3izBtjPAwGJNco9tjZKmUpwQMFhA9KprTCyVZETh585O3IsYDBvU0+Csk2eV+p3bcwayhILyLtJ/jXfufvwu4PlXbv3xlj1g6015TuMovCN2pNGEagCekMCxOfFd5foSYw84eOAoSMC0+O5HzrDt6OpkIwWbzCcFnOtbXErSuekqzkDzC1oEz01PlITP6lKDuw88R6o57TI99HXjOzXxx8HmvH5uYfSdRZMzQ1clS/Vyf3e/cRYtoVkOTLbRYqRB2+ZDlQDc0d9HTRx6dtPdeJkLJ7RrzWryu1nFA9wwMbebJahejBf1wtSY2C8GRgMaztMF3uFObh2uPKypiVi2TWnFOafh6+992/8+wX/FeEP3vZlF3PAMDKPCFIGH9mBrb6N+Ve42GVbN/KXE7O+BTblh2/2MqX14+kWZpU2ZaRnFICR6Wmwvw+lo65tOy5NI9sOYzQnKu+RCDRp+lAXvTwFEiV2xC+/G6BgK1t5NVsB42gu5FgGvW+aN14PQggNAoS+eu5X7FCz7GQnY3VrYjqNj2zZUDMrRLjy3EXN1Myt6b X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:01.6848 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2251d3de-7371-4015-2cae-08d993383e14 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: CO1NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3229 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: Fdfj0Fm5MiQJ84FwOHpNfa2hx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634672407; bh=wontr/1bRmyWFvJt/LBwsXUlHF3dt/3NtrPaoTOYimo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=lVoVckDOnxyoONPKMnwS0cwYT2kqY300wk+14r5LyG7acWFLXM0Qq0DZDKesfwp8OuK q6W8LFeku60Kck0eDlQCdgFb9FbeO2ANQHoDz69gv1TNrM6cBTfDTkgvjY326YzGT7Lhw 5uvaNA4eZryJW+zHHG3iz9WCYR0R9KyO0Xk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634672408914100001 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 4cb81a3233f0..278776a0b02e 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -48,6 +48,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 1c411a42f1b3..a7831eee23af 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -82,6 +82,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) %include "Ia32/Flat32ToFlat64.asm" %include "Ia32/AmdSev.asm" %include "Ia32/PageTables64.asm" diff --git a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm b/OvmfPkg/ResetVec= tor/X64/OvmfSevMetadata.asm index 38cc8809a7fb..b869b24e7c1f 100644 --- a/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm +++ b/OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm @@ -43,6 +43,16 @@ _Descriptor: DD OVMF_SEV_METADATA_VERSION ; Version DD (OvmfSevGuidedStructureEnd - _Descriptor - 16) / 12 ; Number of secti= ons =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 (#82365): https://edk2.groups.io/g/devel/message/82365 Mute This Topic: https://groups.io/mt/86448799/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-