From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.49]) by mx.groups.io with SMTP id smtpd.web08.116.1634144279775917405 for ; Wed, 13 Oct 2021 09:58:00 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=bVa1jxi4; 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.236.49, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=emjEUcP1g9Rizh/C0Omq2/haEUE7QbtuBvMX8EoC21MpZRYUlcVmwqhpLZVr4Y7cd6Xnf1RMtYFfCM9VIt1UHNWaCoFBLY/xvMzp7hYmp7GhaMXP1/Vlql5XBBjjXU9pCVxFFkTKVZ2YqNai7vBV+nXTtfEh4DAQ09MPZPIL8Z1urPG/P3bviksP2ujB01T7koAXrZpr7qn1Rf/OjYlZsb3dbZlVtV6gcLi+3SLvOo9hCfu5n2NsPf45+l5u6PI9y68fd1SxQapYL8mlgLIDLy6thjak9IPdrHqOj/9DP25wW9mxWyhXyjO2TyOoPifQZaYV0q0q9v127Py9gxFThw== 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=v2Fx/75x/6c3x7A0PMVXdx4dTicA/iU+wOD3TCG65II=; b=n+AbagRybidcIWKsBxM2vyJiNXgDuQV/NCze0KZzhGVACFbpc+9xaHVAB9x52VYpp08CPkF6MyyKW2FQ5DFBtUuIZFN/ZPj/ucIoU6nw/HsVoWgjiCD/9wvPhEYV2ZdY+Iz6d/uXeMd36zVTJ5MENAXZIcYHAI9RGGk5LubcyFT1RZJJDs5i77W/GzxMO8SxRIYXjwKzL7h0aWhIRgELeugO8eic6gEL1c8ztuk2nHp0zJyts7nAKD0kYcZkWZFWYOPNxSIGTFcYAOU7YeQZOReqW47obzdU2yuMIcWkFgYCl0r2sc3LH5yTzc55x98hWx0gp7ncA7ECF+NruHR+TA== 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 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=v2Fx/75x/6c3x7A0PMVXdx4dTicA/iU+wOD3TCG65II=; b=bVa1jxi4lFJBVjAhNUYfRLKK1telWiByJyxS34wyW9K8D6yO4FxuY3emHbnlG2FsiWcx+9D8Q2gVjN1OWml84bc8QrtbJV6Ejys94zwoK6QbWImmY2Sb4n+otO7v460o9x0eY69S8xCyn4wKwJPOHumpUWSrfyIn0jCBwwKO0eA= Received: from MWHPR11CA0013.namprd11.prod.outlook.com (2603:10b6:301:1::23) by MWHPR12MB1472.namprd12.prod.outlook.com (2603:10b6:301:11::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.25; Wed, 13 Oct 2021 16:57:56 +0000 Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::4b) by MWHPR11CA0013.outlook.office365.com (2603:10b6:301:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +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 (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; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:57:56 +0000 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.8; Wed, 13 Oct 2021 11:57:50 -0500 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v9 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Wed, 13 Oct 2021 11:57:00 -0500 Message-ID: <20211013165713.727815-20-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com 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: a7319f39-ed91-4e09-388d-08d98e6a9ae7 X-MS-TrafficTypeDiagnostic: MWHPR12MB1472: 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: BCL:0; X-Microsoft-Antispam-Message-Info: qbltPvTJ7+/UWyOJCF7XCLocLfkrZTNWwzRFllzv5l/9miPsT7T+7AM/AMckk7rN5cCWLKDx4LXtYOkJH9RkOB+4MknriMBWq5Y/dONY+JjCZYZkqH+BslO8ZLwRTvq5+NW9AHIYsff6VXfEArqzsxr01bAJJE2wjKwH3qspb7gZFXRA04oQ3cnIaF7ef8xE31GHVoSzasDLZGKXK/QXX3ufvKxx/8BNANdlcCe6LOhWwVJBV9yRfBOZJSJhAaoQ2pklENa0f6gYVgFjfG40J7zPpWzsDGFHmRHNkCVdVRZO7k2gCVGbR9WU7LBu1JyEHsiZKFXqSxg1t34V6mykvS0PcVy0oXHCqG3InKH622jjaiyF4vxrmUYeLDWYWcVlsYeT8gEPQHvLZgArqbnKZ4jRjJaqLqintmnd3oAA4nSdvQtGHdWhp/b2xvKesvCGSL9UZjlMAbfOp5oWa4xCzKBd0ws+jbYaUv0wcPm+iR2J3rxdIccTCGVcg9OGYfZHGVOQNQKb+5R0hYiF1g9pt459X3vreLIQQ2uwOBGyclVHsqjpZPheyP9cDp4gmnxLtvOLBvH/HNDLPkUKwfic8qczCb3EHxyeJKPhfB47zPltAU3+sFeB37q0reJGiBTcR2J1at419WOR3HxCB02gocKLlhNsoXtAaTtEAvh9VUv8FwTxrcZc14rNd3dmWbC0uF3ZWZuRCryrejAZkhyY9Il/UAgjVkPiupWVTSDFa2lFss9RNili0/OzaYPPFgN0fiIXMGs/Y77q8n4m4VorGvnULL382tbnivcHsOHzIYyFzOMydyYvkgr7+pzw0iwZ X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(1076003)(356005)(47076005)(6666004)(54906003)(45080400002)(5660300002)(7696005)(70586007)(86362001)(966005)(83380400001)(4326008)(2616005)(81166007)(336012)(316002)(36756003)(15650500001)(508600001)(186003)(36860700001)(2906002)(70206006)(26005)(44832011)(426003)(8676002)(8936002)(16526019)(6916009)(82310400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:57:56.4700 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7319f39-ed91-4e09-388d-08d98e6a9ae7 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: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1472 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: 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: Jiewen Yao 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.25.1