From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.41.1622070706274569273 for ; Wed, 26 May 2021 16:11:47 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=VBNvk5vc; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: , mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ti1MXDLYYzCro67SZ1I34SapsvbYgFVv2yEyWVbwnBcoGVOLsUzyUKcmE9I1TrjcKgRT6Nz+IYM8bIDs/5P2eZU10TLJgKFJu4eibtiednYfyu1Sx7GLget0pL6FnEmvK1QcVI6kkn1b5lVtRgnNBT/hGUG9H9vbGbmivl4P6a/Le8QVvqq2ESj5oENY1p3wYsyZH7Q8SzOf2rfJaijtej4+qRNXZc8RajegUYVNbMHQnF4F16otbues50DvZvS+RxNnIe73iKO1jtOSTpQSrK6y/5uznx3vAvEYDT+ZsYsWcQNaQgGWf5eBh/z7CScpfbscQ8PyCNNWSPqdmjvUew== 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=ed4gOqlBLaaXfQhL5HyEJ8JMnY70SgJWTuToJ1IHAjo=; b=iRb0OUQm76fpFC1mdAMnunfqCMhlacdqNd5slRRQoPvq10REZ2E1sQ1FmLbbmTdvzYOKISYcC1Lyr//v20uPH7h7UphSb1ufDhldRBl1T7DziqEjHhx4lCwtcVjdlaRwcGqSMH/5VELJiGYU7R4sS8nkGxo+FZD6wdNVzKDtRKGzt2fhW5cZfIOclwZ41Jmcrvc3kkqrnrqS65yNgi2rMg6FDba45/THjPuzebmeR2/H01jZg6E4rnLi1WZTNhQKvLQkZv99wK1KhHulzREYotTC4P93gMy9yk6Oeo3i1aM9Hu1Pr9gs5vsA/oQLHGxPHFmOm882zGxM+FSC3HFcnA== 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=ed4gOqlBLaaXfQhL5HyEJ8JMnY70SgJWTuToJ1IHAjo=; b=VBNvk5vcnGVg6pe2yZmPzcE1HiY4c4U8ptnffdFbB329+AF1ZOXCtKMgbuR1BcHnzd877eCwwVF02ZYVQpXMlf0QfqSXJDLkf2IwDiJnRfXGqAIx5SwqrNfVPwNl17+cqMZZDaciHRbe9R9FWmerXPzdc2rk7+/KMSuG+uPTmfs= Authentication-Results: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23; Wed, 26 May 2021 23:11:42 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4150.023; Wed, 26 May 2021 23:11:42 +0000 From: "Brijesh Singh" To: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel Subject: [PATCH RFC v3 07/22] OvmfPkg/ResetVector: validate the data pages used in SEC phase Date: Wed, 26 May 2021 18:11:03 -0500 Message-ID: <20210526231118.12946-8-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526231118.12946-1-brijesh.singh@amd.com> References: <20210526231118.12946-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) 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 SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21 via Frontend Transport; Wed, 26 May 2021 23:11:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff522322-2ffc-45e5-8e53-08d9209b9fcc X-MS-TrafficTypeDiagnostic: SN6PR12MB2718: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gHp3q8q+qEmzCUTDl6ZI3+1UUohmaHDeSx4VjlnBue/SOuS1lwzvK+OtwxjChZLHDeytUbYbswpshi7yp9tG2+h+3uRaDhwTBUDCRdAFYNFX68/44Il/A10xlUvTdxK+5Ff/DvXZF5ZL21A/g9qcw+uAN1XNW9mfdhxQYKgJ4jBX3OLUo+T1+VhZxWPTSj6uamodBC/Yq4mA9DCeMIlDei4Pkg9BK7JepTe15hCByBtKoxQnAIhkFpl/N/zaz4JdlAPbL1LZbkUxAFauG/FYLouGHLRIsKdb7ycFJv1kOWzvU8oUnCT7eYnGKN6V9QVC5A2e7bX43OxWM4yQbZpg348r0Rk/gDZWgPdV++vwOKC14GCAGEQVW0kZJ4/TXqt67p8JYwzqgLorXT/Ze9im4LnljTjbZzTXEeez8J5USSxOgSfBZoBW8ZXDamUSOPHVIU4fFv0yea0dt29aB5RmY2H28H2RbXnujYp1LbFOfAAekzzrgMwiNDy/9Ku2cY4uLbtuJos7+4Y6lIEO8Ht3woedA2l1vrmybqvYAK8mr3OpG1kLg5OxGwAymE/v9xMvNidgrYkuwnIviNf8bML4kMbzxP1w+L1bOGumLG9fVC2RKLs7RPEvio/ieHr0NS3KszrUHRKuv/tD8J0TEr0zs2hFG4kfno588I440IIOpWs/V181Gt7hjQqqkozfh4yVj8oZwQmlSFrA+qIfzhDwCw1X9zgBHO+SuBS5cLYFWT+S5JwQreERwTQBQImjqrqI6VLtS9UkAXldZoI5++YaQRshvWl37eJ++RL9hPd11kQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(136003)(366004)(346002)(396003)(376002)(6486002)(26005)(2616005)(6666004)(478600001)(956004)(66476007)(36756003)(1076003)(8676002)(7696005)(52116002)(8936002)(44832011)(86362001)(38100700002)(38350700002)(83380400001)(54906003)(2906002)(921005)(4326008)(186003)(66946007)(15650500001)(7416002)(5660300002)(316002)(19627235002)(66556008)(966005)(110136005)(16526019);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?cUVNuOckDrU4moyM4Vlmml88zJnrG+vshaJ6C7R+MMVYZ6FmT4a9FzB8/KHa?= =?us-ascii?Q?DgzDoJ/4u7Gcr78fesChBARYjiGRYhIyBg70jy20Yfn1U+ad3D0J06DsP8av?= =?us-ascii?Q?Z6f3L4wDh5lUlcpvRzYRCEjRjHckkKsLTQ/3EM486PnUUMWeUJsiichRg6LA?= =?us-ascii?Q?ua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82R/kkZ22BLkg2aXwVA3lcbXuPqJA?= =?us-ascii?Q?oYuTgBuPytLpOlsAXYMmwtr3Os0C5BqFyXCRR6xbqKn+GSnJeWdfxL7xT3m7?= =?us-ascii?Q?VvNLHZZ2bJOVbG2g+Y3tTyMRtNs8/FIS73XN8+KEk9g2Xy96sDjsVnfvnuNs?= =?us-ascii?Q?tPk7W0ZGNrfS2BUCGEx/9GQAoOdm/H0b+o3b5i7QMMv969K0veH3MzGnfecL?= =?us-ascii?Q?QutJKRjDja3WrKVHwos/tuMHTbvUdHzVKTinYaIXaItUIkaAEHxbyUhyj/Iq?= =?us-ascii?Q?RLBRPUaP6Nt1c+PuPijQY3mJ?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff522322-2ffc-45e5-8e53-08d9209b9fcc X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 23:11:42.4527 (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: e7X3dPovhDgDiWdE3b2nY5BPfrA2zinyciM6qD9bf63YtOcSjKjZjTQZNMaYIlhWi2Eh73ZK7vbbYHL/NTDNkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2718 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 | 9 ++++++++- OvmfPkg/ResetVector/ResetVector.inf | 2 ++ OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 5 +++++ OvmfPkg/ResetVector/ResetVector.nasmb | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index fdb5dacdc7fa..e00f8159f317 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -327,6 +327,11 @@ [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidBase|0x0|UINT32|0x47 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidSize|0x0|UINT32|0x48 =20 + ## The start and end of pre-validated memory region by the hypervisor + # through the SEV-SNP firmware. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart|0x0|UIN= T32|0x49 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd|0x0|UINT3= 2|0x50 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x1= 0 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 1300af666c49..4c59001fb750 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -105,7 +105,14 @@ [FD.MEMFD] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase|gUefiOvmfPkgTokenSpaceGuid.= PcdOvmfDxeMemFvSize FV =3D DXEFV =20 -##########################################################################= ###### +##########################################################################= ################ +# +# The range of the pages pre-validated through the SEV-SNP firmware while = creating SEV-SNP guest +# +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 8e52265602c3..2a75e909c769 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -49,3 +49,5 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidSize gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedStart + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpHypervisorPreValidatedEnd diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe= ctor/Ia16/ResetVectorVtf0.asm index 05c7e32f46a0..769dd0bccfd9 100644 --- a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -55,11 +55,16 @@ guidedStructureStart: ; the BIOS at a RAM area defined by SEV_SNP_CPUID_BASE. A hypervisor wil= l ; locate this information using the SEV-SNP boot block GUID. ; +; 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_CPUID_BASE DD SNP_CPUID_SIZE + DD SNP_HV_VALIDATED_START + DD SNP_HV_VALIDATED_END DW sevSnpBootBlockEnd - sevSnpBootBlockStart DB 0xC2, 0xC0, 0x39, 0xBD, 0x8e, 0x2F, 0x43, 0x42 DB 0x83, 0xE8, 0x1B, 0x74, 0xCE, 0xBC, 0xB7, 0xD9 diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 36739096e7e1..465038e39de3 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -92,5 +92,7 @@ %define SEV_LAUNCH_SECRET_SIZE FixedPcdGet32 (PcdSevLaunchSecretSize) %define SNP_CPUID_BASE FixedPcdGet32 (PcdOvmfSnpCpuidBase) %define SNP_CPUID_SIZE FixedPcdGet32 (PcdOvmfSnpCpuidSize) + %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