From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (NAM02-BN1-obe.outbound.protection.outlook.com [40.107.212.72]) by mx.groups.io with SMTP id smtpd.web09.45.1622070715669955813 for ; Wed, 26 May 2021 16:11:56 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=3c73YCgJ; 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.212.72, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oU0uqtVs1wN0BihaowiHnqT3Xz+OXUNFszeVyhr6iUCZXyHzb2M2Pb0hDyHbGY05pJTee89VQIGAcujuCW4X1Q1rd9u36J2olR8Cy3I5STqmTLLmaAMj7rO/PTUFHZpEafTEC+VTCKFkn8j4cLoyslDMJMVNdT2FwPADhigHQeHAM9u27Q0EMmPEzIeBgZMLQSes2AXJR4sLoNwBcntvy4E/+nWEMUU1wejZoJIhyRvsd7AsOygBD7Tl5g7ES/9mG/xU4GuSdC1dBcKM+8k88fZCHXU2LnGHnirGIpygr4Ci8b7k0ItmYSQiIN7k0mm02fG+YM7qLSNlAJn3qhsoGQ== 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=NHTLMeIvSnebvEmPbUqN3RKVBW2XvrpLAsa2/DXv4DQ=; b=Byqipwbekda/FdgSueXjB3KF/GM9bAXJA8hw80WVyZE/5iTehcx/zQlxAMQw3SjwgeP5blspOtku+f7ASFrn8kLTHqQbOUcdInCzrFq4gQy/nRVrDqvSA5/+Shi2wISFgb8cBkit0D5oOnhPmFt1iesqm5IJYZD+KSkpYqLh8tm3LT1m5EZ+aXbqXxYdXWJywpa1RSdozL3uogOl7n0QzSG1rpA6NPxCNiMmFenuyJp1KuAvkubRfEJVWRiS65EigtKnN2JwCYAXmhjJfzcD4CkK13wJEO8BNExHlRMG87pZSADeSmoq9cIC5Fm788ilYUNlS0Ay3U2GuAjO0gBGKw== 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=NHTLMeIvSnebvEmPbUqN3RKVBW2XvrpLAsa2/DXv4DQ=; b=3c73YCgJqHmF8wa82icAxVhF28HB6RII2ewaqZLN3u2B+TZh3cuodwelGv38hLjmenvyMtvYTeMviJ3s48wmEL/huKzpFfduOSq6cx2cYoBtDGAyLHWY7hzDeA/U6bSSBOQ9cuwL45R+//55Ly5sfEKw8vUoyqGm7jkfexl4Dlc= 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 SN6PR12MB2782.namprd12.prod.outlook.com (2603:10b6:805:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.28; Wed, 26 May 2021 23:11:52 +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:52 +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 17/22] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Wed, 26 May 2021 18:11:13 -0500 Message-ID: <20210526231118.12946-18-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:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af729a4a-1d8b-4464-b7db-08d9209ba569 X-MS-TrafficTypeDiagnostic: SN6PR12MB2782: 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: Q4hHFWR4WSvwbl2Uy5UnOAL+rfdPCqHpDVvg6smbXDEBWrnIsChqTvPooZaAmSx4oZMH1Li/qnNUuMWH7qjXXUT9OJKWrCG7qDMtWtVFt6FBbh0ONcRg+uk3BMrQAi4BdLuzh3ZLup2d7DRK7kgnVM+bnMeH/aP0+jJld/X+JAly6WlN3iFBA9glkCXS+iCNkJga1UR7Xggnd+p22euMw3K+cDqksEmWSeiMFeilTQi4qm4aCb9ycJn4fNt64M72xyh9KV22xVdhTUdosduZj/YTfYZqbINnDXO0QWPIpDiC5K4xXyDVioucYtYZ124a42TpUhUSNRFypVWK0j+U6PltmZ3DWYhEFwxhq2dLFnEF8vWh36JxzuTgb3gtRLkockNZVyaoi3tXIgxLTKBNTwvqhxI8hyp8Wair+HiAQdIYfQqOsE19dv2B/mZ9ocBJM6c5okULGUdHUu1ZY8yGU1S/cKzhEmDRWXTUtafvYmmlIiN/4ArOdwhu9cBeWDFPDW0BO0vG2wFm3JhppxnO0z/WwEa4lthtyjdZqYsD8SN1xjaL7ec2LzyJeGM4iVHdc4n6Ef7WHPAlHPG39SVSrjEsVjd+fxOsT1OKbeKcKSydLIjqo/SkVLzJDHtgcnhih5CWojvztFDdf9rr+zFnC3oQi6YhPKbRP9sWQfSxrcFDYmVVwOHAf89KWDB10ySbpz7Q4p889g+UG1qjLTynlPT58Fbju4zAuikOl6iuAZgoD3R2+qNnQaW3ZmwAUFIUDXOUY+hSOQlAmaTOYTXKRpF/RiaEvMvSm1eVj2XZEnM= 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)(366004)(39860400002)(346002)(396003)(376002)(136003)(26005)(316002)(5660300002)(8676002)(45080400002)(83380400001)(186003)(38350700002)(16526019)(478600001)(54906003)(36756003)(4326008)(86362001)(6666004)(7416002)(15650500001)(2616005)(110136005)(44832011)(2906002)(52116002)(66476007)(66556008)(7696005)(921005)(6486002)(8936002)(38100700002)(66946007)(1076003)(956004)(966005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?/k/sDAlQEMSqYMuSELNbWPepg5al7yHNQ4IpStZ+EdoEhehdmQsLKhwmQq9D?= =?us-ascii?Q?ksgMsAIv4eWLbYDnMAgNa4h1JaMSJylD+eIesCoVL9bsvyx99mfeQhcGkDVB?= =?us-ascii?Q?a9HOZ+gRyXkj7n/VysbkDkD3821xnVnH+6xYZyr71grouOneMgUfYkDc1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HK/zp46CX4e4WBOUwxAaLeUp1Pw7Dcl2Jnlv2W?= =?us-ascii?Q?eX/3Xx+JphhEU+45SqpiniFKN8+tPFUftQZorCS5iMsDutGLTVzqIE2l6b5g?= =?us-ascii?Q?XHoZ7J0hjosU9DJ+7288QAb0ccX4UVMr2GavlyeC5yztMVUiZDu8IJoIOf+1?= =?us-ascii?Q?AOLrXaRj4Y7y2PbCNLvmTA4GdQUCT2XgkMzKlvb82jcemf9FY5171FYYYghU?= =?us-ascii?Q?dsuJTDQfdfYUrkU1CqIXWLrs2n+Y5OwB+KiSTXs0KUA25XOUlt3Osdo22HfS?= =?us-ascii?Q?t8ix5vuFthLjVjNh6m8/jnyf?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: af729a4a-1d8b-4464-b7db-08d9209ba569 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:51.8423 (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: ocMoojU2y1leK3SGl6YYUErkq1T5xv1LvNkk1XAQeS6AuC1FvVSCtuCrowOjEhay1f2WqmdVuc1gGbSwgLSQHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2782 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain 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: 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/PlatformPei/AmdSev.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 54b07622b4dd..9a20165db79e 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -34,7 +34,9 @@ AmdSevSnpInitialize ( VOID ) { - RETURN_STATUS PcdStatus; + RETURN_STATUS PcdStatus; + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; =20 if (!MemEncryptSevSnpIsEnabled ()) { return; @@ -42,6 +44,22 @@ AmdSevSnpInitialize ( =20 PcdStatus =3D PcdSetBoolS (PcdSevSnpIsEnabled, TRUE); ASSERT_RETURN_ERROR (PcdStatus); + + // + // 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) + ); + } + } + } } =20 /** @@ -204,6 +222,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 current page table. T= his + // 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 // @@ -264,9 +290,4 @@ AmdSevInitialize ( // Check and perform SEV-ES initialization if required. // AmdSevEsInitialize (); - - // - // Check and perform SEV-SNP initialization if required. - // - AmdSevSnpInitialize (); } --=20 2.17.1