From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com [40.107.237.50]) by mx.groups.io with SMTP id smtpd.web11.5551.1625057652530537586 for ; Wed, 30 Jun 2021 05:54:12 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=ziPFSwOt; 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.237.50, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ASy2n9Awjbq5N57PaBstqdQTTeVaFQTIKqL3W7rkKKo74VKa99ZLttSOtWdowhNaNdJEMpvBmz6WlDINQNzjYcDtCvIAYqnGARERVVMFHhacWh+aTzATbe49JeuQV4B1GdvD2BI40nKhA/gu+u57lY2bdsQherlM34sg234v0hxAh+rSg1oGRBZCIFeK/+0/2eHrd4vXOgejDEnluLZN3UhraYttVmpwVQRVkCBbEE3gUlsUiVcsenLb8o7nad+f+ILzqtvRE805xYspMb4wfFWHHvq9YHzT7rvuuL8LVZ84R/Hm4yTWUT9jMw6ONnZwy37eUYuVM8yLMP0p+jrlKg== 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-SenderADCheck; bh=EyF469i1fK36kxEkwQaUTvsnVLjjCxsukAs2dbStmIQ=; b=gbJULeAxLCm2oAn8SZe46HZXxCAmKGF78Jf+4E624TfJrLH26bRDGRREruc6L98hDSKI6hFNGuWY1JugFWdLo2FmafAWeiZ7q6Vj/byQrfpzI9lfU0c4yaJRb2dOmCsDRgUI/YK2O6DuGD34M7b0Y+B8VcoVbfijuHJ3sa85wlUA4tBqBo2H3zIs/zRMqYpavdF72QM4TSmJ/XjnODAtOxuvMsT0NzXpc+InPZZENKQ3ulzHsey/1sBq4KTK8UDkcmL7OYULLnddvCbS9HVJZRVrCFbeMny9oa1tMByHYltjoTCyFc9kzbH9Z5fM+g9L+Gt4p+i9T5XrM0bYYTBY8A== 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=EyF469i1fK36kxEkwQaUTvsnVLjjCxsukAs2dbStmIQ=; b=ziPFSwOtkmWIQGtjMsQQoaXstjUnJXFyTbD2sZw/kjagxQ66u0Jf+ONQHNTKlveBULNE+SbkI0YNuy65UxiH22zdPMSmm9Nu6wRzdOHa8OLLoKtRG+nwIvPLKDYqbWCtA9SCgoO2uau0GM1R3rAFQ8c2psXduxKna5QL486GO98= 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 DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) by DM5PR1201MB0076.namprd12.prod.outlook.com (2603:10b6:4:55::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Wed, 30 Jun 2021 12:54:10 +0000 Received: from DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b]) by DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b%5]) with mapi id 15.20.4264.026; Wed, 30 Jun 2021 12:54:10 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney , Liming Gao , Zhiguang Liu , Michael Roth , Brijesh Singh Subject: [RFC PATCH v5 07/28] OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase Date: Wed, 30 Jun 2021 07:53:00 -0500 Message-ID: <20210630125321.30278-8-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210630125321.30278-1-brijesh.singh@amd.com> References: <20210630125321.30278-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) To DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SA9PR13CA0018.namprd13.prod.outlook.com (2603:10b6:806:21::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.14 via Frontend Transport; Wed, 30 Jun 2021 12:54:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bc4a15c8-ac72-4c11-7901-08d93bc6278f X-MS-TrafficTypeDiagnostic: DM5PR1201MB0076: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6jj6fVi1+X+LC7vk3jiNa1/4uOAyd556Mdex0Zhv9pEVh6WCWDFme3nFB27hbJt0RwXu/BrT+QgCvL1JAb7Fx/qYvVTV6QwxY3xpNzNYeHaNaiIpg5bmDVlKpuCXVa7YR43sUMy7q50DzPWvqnKRDshDB5BAfnwE1nXmpNOW5sW+dzIou6DooiB9R/VpiQTAnGjzf9GNyW3ZgbjAqRqhOqaRQr6uFws2vCwasS3Q+KfWZqvnqeeqXA6JJyGekN0MVDzU1FSQA00j1zjNKT6zsiEIw0dQiyRQxopwjJk2bjpwv1a4acBCoLUCB91HkxHoW38d5KVM9bh/mT4MuFS0VJ0kmrZBQo7AjS3eLEkuhweDRfINKeIpZb5tnHYGmwA0oZ97co6YVTDJZTW6wrSCN9Pg+t94Cud13vqGwUINgyt7AAjexXsRgZihfSo4G3R0+Unl8p2/aMcJ+vuA7RGQ7VBBGUCkEOhya+bk4+VdLu8z1FeNWkfG7gdvje2ju3hsHzHZUPMq4LGsieE94HwgbbABSyXH+L0Y4sESlDS/XlYEKAZyLJ2Tr81ndUUyPm3tXwhnzaK4izA7dsyMhHRFS3ksFIn2hbLDk2lGoourjy31GbGkfvV4hL6YiZRoi/Se/ZoObN3yDsjbgDgCj3gzu/UnedaTH+eeucbCDvDvBXRA+cj666l26YutDXRS5fzwl3kpe3sDGTguvP8QbjqD9n2iRtdylWksMORBHtVbzQNEjMB2nymsHobC7b1cipEvodEBlzycYzVk/tNdmatwL4RDiQYaWRYwdJSv5UdCbMZW7wVttNZMy8K48u6B1AJFsoazsuKQ7RH79kNR1pnaCA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB2714.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(346002)(39860400002)(396003)(7696005)(1076003)(8676002)(16526019)(15650500001)(8936002)(6666004)(2616005)(4326008)(956004)(38350700002)(38100700002)(478600001)(186003)(6486002)(19627235002)(66556008)(66476007)(26005)(7416002)(316002)(966005)(86362001)(66946007)(52116002)(36756003)(54906003)(5660300002)(2906002)(6916009)(44832011)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wPP9TYRJnLlBWzU7VQ4GNrNMGaxMVNXU78HYB3e09Ij41xGHxsHQsH7g1heM?= =?us-ascii?Q?u4W1eYThae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A/VYadKAuGCxic?= =?us-ascii?Q?F411iGanjPfNkTAoDngKWHBqAn4yVYnjjTNPMvYdgaKHJ7eEELsn1GwkTbhz?= =?us-ascii?Q?9Alpk2C8PZPrnp7FewofJPI3yZgU4PRW/TCRayjPVQccSKmXDBcrQ6U3ZpyH?= =?us-ascii?Q?gAlwatrvTOQe5F7ey+Fo1zm+UExarS1NUYbzW6a9bOfdvJ1th6zliXihYKhe?= =?us-ascii?Q?t1Va8OC1Zay1BbwLQAOqONDUo3Fw+vSzwbaTz1UIDAyNlr/4t9+EhboeNdu3?= =?us-ascii?Q?hooEunEK3BTNWYA6hUtbOXj08utX2g4ELEOAFenM6bV+r1hBlWeW2fiSd1+P?= =?us-ascii?Q?PsGpwTjYytB4GourZAEFyTHkdOR1L1unlG0lAS73RMoOtZC8L6hv+cLWf4tK?= =?us-ascii?Q?N0jIh6WdL97TgkluMOTy7oZy?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc4a15c8-ac72-4c11-7901-08d93bc6278f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jun 2021 12:54:10.3842 (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: 76RWez9wnEl3l6mSOIiVX6ks5qr3kdRCt7aYNxg6C+338Wd3tnuMRM0W2LCQojB0JSVn1QWrX5Y1alxzzJnZKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0076 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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. Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas Signed-off-by: Brijesh Singh --- OvmfPkg/OvmfPkg.dec | 5 +++++ OvmfPkg/OvmfPkgX64.fdf | 8 +++++++- OvmfPkg/ResetVector/ResetVector.inf | 2 ++ OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 5 +++++ OvmfPkg/ResetVector/ResetVector.nasmb | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 93f759534ade..d0ec14ca2318 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -334,6 +334,11 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidBase|0|UINT32|0x49 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidSize|0|UINT32|0x50 =20 + ## The start and end of pre-validated memory region by the hypervisor + # through the SEV-SNP firmware. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart|0x0|UIN= T32|0x51 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd|0x0|UINT3= 2|0x52 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x1= 0 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 3e257aaf72bd..6bce3369e10d 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -105,7 +105,13 @@ [FD.MEMFD] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase|gUefiOvmfPkgTokenSpaceGuid.= PcdOvmfDxeMemFvSize FV =3D DXEFV =20 -##########################################################################= ###### +##########################################################################= ################ +# +# The range of the pages pre-validated through the SEV-SNP firmware. +# +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart =3D $= (MEMFD_BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase +SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd =3D $(M= EMFD_BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase +##########################################################################= ################ =20 [FV.SECFV] FvNameGuid =3D 763BED0D-DE9F-48F5-81F1-3E90E1B1A015 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 9a95d8687345..32206855193f 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -51,3 +51,5 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe= ctor/Ia16/ResetVectorVtf0.asm index ecf1dbcc2caf..c5a062e69b26 100644 --- a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -57,9 +57,14 @@ guidedStructureStart: ; SEV-SNP boot block GUID and provide the GPA to the PSP to populate ; the memory area with the required information.. ; +; In order to boot the SEV-SNP guest the hypervisor must pre-validated t= he +; memory range from SNP_HV_VALIDATED_START to SNP_HV_VALIDATED_END. +; ; GUID (SEV-SNP boot block): bd39c0c2-2f8e-4243-83e8-1b74cebcb7d9 ; sevSnpBootBlockStart: + DD SNP_HV_VALIDATED_START + DD SNP_HV_VALIDATED_END DD SNP_SECRETS_BASE DD SNP_SECRETS_SIZE DD SNP_CPUID_BASE diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 247f4eb0dc5e..645e949845f9 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -93,5 +93,7 @@ %define SNP_CPUID_SIZE FixedPcdGet32 (PcdOvmfSnpCpuidSize) %define SNP_SECRETS_BASE FixedPcdGet32 (PcdOvmfSnpSecretsBase) %define SNP_SECRETS_SIZE FixedPcdGet32 (PcdOvmfSnpSecretsSize) + %define SNP_HV_VALIDATED_START FixedPcdGet32 (PcdOvmfSnpHypervisorPreVal= idatedStart) + %define SNP_HV_VALIDATED_END FixedPcdGet32 (PcdOvmfSnpHypervisorPreValid= atedEnd) %include "Ia16/ResetVectorVtf0.asm" =20 --=20 2.17.1