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 [40.107.244.57]) by mx.groups.io with SMTP id smtpd.web08.15126.1634672413851366881 for ; Tue, 19 Oct 2021 12:40:14 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=eBB0FXO4; 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.244.57, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bc35ZdOXhOwo6teo/XLZHEaDOaDnm7/qbg3nCl/bHOzCGJdnzaUPUMQ7tdC68FCUr7WB8+828zDvsCsbW3ARHzFASk10mIpjTsJbumC9p0ijcrsL5MSi6a/llWd2Iz1Zr/1JT2O7/4FfK/cUg4NEcqb2zqvtMXTKi9aVZOUxYCpTJaVDxvg1pEe8r5WGt1gkA8r7nMB9VogL8K/6ejh62Zl2oNbwxJ91GREsZ3lXzKKOQ7akQkjUPPnqjyx9cUVwxDfayVz6HGGGOO3FEMULAPd9uwxNMJatUmoJ///cykLxAB0MUPdDqG6g3P7zYcN7rEQaBJc16Fzd1HBmMi6dRQ== 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=j1UKaOoNA671+/1mrEk+xj+2jQ6wSXyKAxpndqoji1M=; b=V31wLE7tiRVrY3ovfFADDs5bB9SJwi8Csnrs/3bRF4jlIOedUL8sKZhBEzGOcY3GTEeV+drG3TBLGwojIfy+o2yPss04INzxI6i3UD2xnCApTjNjoF0XYqc3hqnUV+Bc8PYJa5/Af5gt8LZmr3r1CpoIkIHfTXa4xHvDHFU3lF3RT8CvOPRCR63WL/nJYfRHUctFgCmteN3dJQvUOOgvqOGjsFm+f4kxGsEV7gdwU08B+b0rQr6qTA3zHAoM+6vMRvJudzFBsN0mmkY+cDXxwfbXCHit74N4nUrOzYOzR4keZ40+U9e9kQq+k+KmAp7NVbZMM1TzWsqAeURS4O/e4A== 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=j1UKaOoNA671+/1mrEk+xj+2jQ6wSXyKAxpndqoji1M=; b=eBB0FXO4DgXV1M4+65PQ1U48UMqYujSiNsxBcOSOKF0lYtDR/86uhcpBPY32qYDugoMQrGNPerEKit23wD8Fnoa1tp3blLunaepmTvWOACSAkAc8IwHcVjl0LCWz+A0w8JNbMz/NVsRc9aAiI67ufVAT0uw14d8BookzH4ROiJY= Received: from MWHPR14CA0065.namprd14.prod.outlook.com (2603:10b6:300:81::27) by BL0PR12MB2418.namprd12.prod.outlook.com (2603:10b6:207:4d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 19:40:10 +0000 Received: from CO1NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:300:81:cafe::c) by MWHPR14CA0065.outlook.office365.com (2603:10b6:300:81::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:10 +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 CO1NAM11FT004.mail.protection.outlook.com (10.13.175.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:10 +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.15; Tue, 19 Oct 2021 14:40:05 -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 v10 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Tue, 19 Oct 2021 14:39:21 -0500 Message-ID: <20211019193934.1052465-20-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-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: 0a6a88a9-ee24-4cbd-edbb-08d993384320 X-MS-TrafficTypeDiagnostic: BL0PR12MB2418: 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: +gScF+I3PVp8mBavtjzqVFfhlqak+ScMZR718BTXkMRbH2MUYBhrRaL8kTL12rvUiioGzlVYBapl1wvqGl/s4RvMBnQoeFNH8xkM18ROALi49aMuXY6f2UFDJmxTvw7BnhfrqQUxkTVJdW/QYnR4UJ7r6azTHFbMiKkt4aLQWe1VqjIacuYUn7ygKtSVb3oCzhRoFAfKQ1XM+facA4tiDD7HGcmGKPw6pAiasy2TvEaMhkvEuS69waX1EeuoEBnpseykjeNbHRfHZRYnrpMOyIer7hmqPLCwltoXW/zEGkympN++JRQuxg8XqvSw4hKf1R9wri3gFqta8bqONbQ7DVyqK21UjkTgCohqzO/Grne8j98k7wavI5DrBWirDPR4/GGqLKMsionSkHNhXp4oM3x5B4K+eMiFC+xRoZYjIS8YZ4VrpxEa1OlVd39XA9Ko8zqER+jQATcX55e+kxjy0SmbM9gDRiNiyqoDNG9lv0sAwvnTiV68gEVuOxUZmpM9nI4DoQZJkh7JQrc4ITNcv+knjYbRG4m08f+wHMGiuyD1jJimOHZrwpYUk1F8UEFHLFWTGjvq/yQJRtZ7bckp3rl2jMcThJqAuhTtMPd/qsvhAb8I6Op4tLATwyfaL1Zva+zCrPycY05QQJtqI6RUNDDi077Pdn9Huh8DXlmp9sRXezOixmhCC/XSh8EvaDKxqU5qzy67HIXbmt9BFwJSwMkmVivyMHwbeBUWBurheaxDIRa2UWBPnBOHso5W9qZic9SH3T9h/ON1gIKgmwD0oNAPh9GvQkZoWYbXTJCf/4aAok7DlLtySFMxLDoasBnT 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)(44832011)(426003)(336012)(7696005)(1076003)(6666004)(36860700001)(8676002)(15650500001)(508600001)(356005)(186003)(81166007)(2616005)(83380400001)(5660300002)(316002)(26005)(82310400003)(47076005)(6916009)(70206006)(70586007)(8936002)(54906003)(16526019)(45080400002)(36756003)(966005)(86362001)(2906002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:10.1599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a6a88a9-ee24-4cbd-edbb-08d993384320 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: CO1NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2418 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 Acked-by: Gerd Hoffmann 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