From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.58]) by mx.groups.io with SMTP id smtpd.web12.5444.1625057671286204443 for ; Wed, 30 Jun 2021 05:54:31 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=s5AZ6C//; 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.223.58, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=czSw7muZl67NOefeu7aph9lAbCxxDHF3qLa2bXNLTk7/HaGsAaw9shC+lQRTuU+4USip7z7VrRR0Xk4hU6GLlg24hoh0xQiOMecGMUSt4EV/W5slmlwLCTFFYQIYRrtDqsfJNMCEfwojjw81Gz3EcaF5IqDi1U0/3YqIW84agZ5gIfJAftlZLXTsT2saPDLvwxrzLx/PnV9keDC9ApP9neUNwFCLLwiB+lVJcs4Xhvsxwhb6Ie4i9nOw9wPI9HhfspdJKs6FNF1D2hedldTe0qiXjlHtfs5JXDatm9/y5h40cK/d6PzalhYFO/2fSyq65Bjf20yEbK0zuXAc+0lNOg== 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=k8PA7SKKahmuKpHvarLKbC7f/Zd8MKgYAF2Vu7dDjZ0=; b=SMqtR5C8iY9e+hK7Tof8Kftvu+Kye+hCw0oAnw7A6EJU1OeyHYna8X9oRHiGxPi4m6TbD1+uepSrNieNKJfdNCfiVEMbA+oPGe+p3KbzEWjjv9U0VYMDX59umssn6Y1SMEfwNJfyxdAW22S9cdodrqWz7pxu+92eATzWybGV53WJQf0SkkcnRKrofTmSoLD47YTqF5M388k2lqXKJWE9fPW003JNfRS1GYhkxXlXL7UG+6+URgyp2dLVOTmQNrrCFi07hscGvXjK5HOCPezI+Mi+C4UBYecsc6GYAf0IQnqFsPztnxhj7HTiT2Sa0ffknGyVGgmF7oy7eM1tmOjkwA== 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=k8PA7SKKahmuKpHvarLKbC7f/Zd8MKgYAF2Vu7dDjZ0=; b=s5AZ6C//xk5b5PrKwX4xL513+nf+zmPc4sWvz91X1uLkpDwqEjrcg4ne9ReEtm2EjMke1RsdVMMYoDmd4U6H2EzzO5m4RYjPIBak4n7uYpIedwQwd+MBhoKXyLvGIqJI48dRDAZrljUFiZ8Po1YVAd/Xx2L44MfLn2v+l3bVsD0= 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:29 +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:29 +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 19/28] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Wed, 30 Jun 2021 07:53:12 -0500 Message-ID: <20210630125321.30278-20-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:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 61715c85-5abc-45d5-681e-08d93bc6323b X-MS-TrafficTypeDiagnostic: DM5PR1201MB0076: 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: b2/lOgF4kPNjAhu7pG/or7oOm8+wOtyejg5eKxmCWhBvfafxFNRF3Lup6YkCL5eF6bEntSvbCXKN7eTj7AvlqNq0plDOAEzmp8wIStZd9+0oYJzwCW/5JHUq70mOCddOhm0YxG7ql3VRkXZWlba88E849dSj28NILwb+CikalWiEwaKfcomNwIEF0OajE7dmK/UHGHOmj0m9EnHApOu/dVVyEcki9lemHcbvRapdnhimzwcWx+zgU0C9UhkhggWxdXLkuq25rXgX6qBy6X2JGgPGmUYcWa/VRxDdRAknmNZO4czD71AhMPd3ghkJYFbbzJBI2D9tf+WRiH6S9WfQW5SdFhH3DYNm/NlRqxkK484lzqCaUJqO6P/RBv2cAzQME3u+Vx5T5ENbgbJsLcVeRoH015JXpXPBEDC3rqGMO1FTcABYWwW7pVmb2poOTcT3GsA7dPE8PTDh80y7Z9zJedfyqrnsAQpmnI5GsUftPrj5Aba7dkhKfEALuZ2H+byPEBM6rpbYR3d9dpmqadou63ESB261T8I1Pq1bSceGxcdzdSMfih1GnMEhsvF6iVXmo/4yX1eePwQ6AC7tXYsJqjpcygDrQdGBUeNoc3VoiXKH0IywZHGAhOchN5BenWL38JQzHZko0cG9uZsCXvkREwyAtSt4Pc/FZZgw3ar3VKJRK5+VXfvnVC0kvHJrSJSp+LFJJGA/LZj458NI3AvWTY4uAvfkoTVKa1aMrtj9jg3jkaoBzmyHcnWMJG559Ff2Dj3BoLB3wurx6iOIOO8x3Ty4y35VVH5mi4Lghsj3jg46XGPHrNwgHcIdYu/4352l 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)(45080400002)(8676002)(16526019)(15650500001)(8936002)(6666004)(2616005)(4326008)(956004)(38350700002)(38100700002)(478600001)(186003)(6486002)(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?JSp+jHFxkQdPzbjw6zh23eUa+ZIxWpx5uiqamMW2V1fvwGIznQVE5XIZZFSe?= =?us-ascii?Q?0UI/UHLPJqbiONHhP4oJGrAKFGylNHFWmIza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?= =?us-ascii?Q?ZqmsUj1T1OagdC4ayPNWh1crS6BQxqSDJPbz62uHebZ9Xd4ySOh7ufPG21EA?= =?us-ascii?Q?xd6EdWMfVzj0KdoIDW7R+4TKP/5EBxyI/b3i0FzQrcqDPkjoASEm69FKT2Lx?= =?us-ascii?Q?Q4PiEbNwbfkEStv2DPY5vFV1OP33ANO7Dpbm0lSr9+v49+xVhzGzucLNEXCt?= =?us-ascii?Q?U3hMy6vzgHpBRzIx43cMlab4Yo7dxewn69g09aqrivQRx/oeNDiQArJyvlma?= =?us-ascii?Q?CntyXyLB34zGvHRs4fbmIWl5+Rn/OLoJqunqxsjZA9Qdbk+APxtJeMwFlZjs?= =?us-ascii?Q?5RDTWLPrD4Lztk5Frn6sush2JEMA1CheHzeRjLUgwAX7q+1e6jfKZOLKzSWS?= =?us-ascii?Q?Ccj46VGRHpIk88VczyJ9+CUY?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61715c85-5abc-45d5-681e-08d93bc6323b 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:29.5036 (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: FhNAETactBrpRmAil5RqR0IG2o67J1iYb1hPp1D4vWkofV13oUWn8zetMPwxMAP0zUG+NkS2m0tiIVahvlMhzw== 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 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 | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index de876fdb478e..391e7bbb7dbd 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -23,6 +23,40 @@ =20 #include "Platform.h" =20 +/** + Initialize SEV-SNP support if running as an SEV-SNP guest. + +**/ +STATIC +VOID +AmdSevSnpInitialize ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + + if (!MemEncryptSevSnpIsEnabled ()) { + return; + } + + // + // 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) + ); + } + } + } +} + /** Handle an SEV-SNP/GHCB protocol check failure. =20 @@ -240,6 +274,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 AmdSevEsInitialize().= This + // 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 // --=20 2.17.1