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.43]) by mx.groups.io with SMTP id smtpd.web09.424.1636738834432429812 for ; Fri, 12 Nov 2021 09:40:34 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=VbWAelk0; 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.43, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Be3cbodpt53piprZIkLaj8xkXsxbyfREX3NNwc1bO5s55Z1H2K42F8D6Zw4nyYQ/4O35/QPZlqyScVOQ4WCcS9PCrP0bMcIsYw/QR/z7puaWQ9B/XHh2GXotpG1XGnxWJmR4OWfiRbyzeQvqywxkP28PFQGh0/EddH9EqcKZOsBhKbK8BjMezbmjsJ8su/G1ZACZ+A2939BVC0qsOmgMDtu6K2vc96LMMQV8gQ6M4pQcZW0UQBv8izmNy19OihiJjIihIdtygE2C30jHycaCpCKctUa8JiSRgXjqsw/mqv+UfETjbG7TXwsuGQVvV5szil1GZ+37GaLVX2hgkqfcJA== 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=7v3Ssg5FAgrAD2wIsUowjWXP6Sqp6dADoZYx64HAPCY=; b=bx8yl24OG61od/AskR1nMves1VKXYXv6GTrknMPPO72lPLbBwcAw209NrTaCoo/BVf40H2jhb7gi5coSPpp6onrLM4I0W9lDpEqDWKuRPq5mVUhrrdh6Sqk5kjl7HjcncOmgNmhxT/tFEs/AbBFTLO9RAS5aqxw/D7EwQcFTjS1WfVAppaGYsT/w0795WpxMDxNAV/nEhsk0go6WoXYIrXBh3EsEClDIWOI9ulF5dKMhSAERxIF+fSA8n0w28FT4Q+3bmct5/myub3yDKMN1JscmjqNWMdOBX96rYVXftoFxwwBlR4x6tmYR+4Zn3RxHRkMF1WptNh6gJ8ElP2a3wg== 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=7v3Ssg5FAgrAD2wIsUowjWXP6Sqp6dADoZYx64HAPCY=; b=VbWAelk043Cgbat9eIWeUn6nDLPIbN5aCXCPCdhAE/JNsxxIowU7hK12UfyVLGeUWnp5pUOpqqU6HwkpkvdMgghptJl6RKSqLY8nSPZzpvZY5u12JxIJFR2FbFr2JtmQWEetGTX5LJGPuA9/16LxKl6Lzfzf/jl7w+A6s4qFPNo= Received: from BN0PR04CA0104.namprd04.prod.outlook.com (2603:10b6:408:ec::19) by DM6PR12MB4500.namprd12.prod.outlook.com (2603:10b6:5:28f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.17; Fri, 12 Nov 2021 17:40:32 +0000 Received: from BN8NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ec:cafe::64) by BN0PR04CA0104.outlook.office365.com (2603:10b6:408:ec::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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 BN8NAM11FT036.mail.protection.outlook.com (10.13.177.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:32 +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.2375.17; Fri, 12 Nov 2021 11:40:31 -0600 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v13 19/32] OvmfPkg/PlatformPei: validate the system RAM when SNP is active Date: Fri, 12 Nov 2021 11:39:46 -0600 Message-ID: <20211112173959.2505972-20-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211112173959.2505972-1-brijesh.singh@amd.com> References: <20211112173959.2505972-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6fe2564-9338-4894-cbb2-08d9a60386d4 X-MS-TrafficTypeDiagnostic: DM6PR12MB4500: 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: R43VWucf5AbxpL2dqXsGVbK2CSm4g3gjRo/xniGeQan6FIFD4CQ4MyxSi7aHeQx7wnyzR9vCMABaEWAsXyCHtrZe2sIi8tHUgXDR5ztz2q1NGlI/14FvN1srfQ5ovamuqbjjX95sKgh/bVqMuHKbJwkTDKmYzowGD0ZTAuE110bFyPw0uTrasLekDl2ooG+YAthj3gYomRMz/RI8fQxqKeE9HhvfULR5pSOYQBcdEv159cLVFe8M4sme9dRS7XGipT2ONG8UEMDM87OPNyoNKF+cbDA2kAEa2KfYIoiK7LU4NYzYtMM4AVsHFHKvp7O09TiwCZmvm6U5NXsxwcdUIgVieLtrfoKRP16Uf9DAtaKxw07WWWKVMvNz2RXP3g8OiDSyE0ZMldywACTcrpSuxUuNM5fp33DGkqNdBwYIGTf5Mb8ql0b1M0AOOZbro0kSgTZot6lNQ9I+nir090FDB4gF78/VtxAj9LQIseCDG1PsD2/MjzyTDpDw1gJl4MslvApQ0eZV/vNm3VWJhn9TkPMqiGQE4la+UpWHQ5ctFKVvb/MZBEv97aI120WslvdaawaE65i2ixNdl7hHalTle+F/1oj8vQdrFiFx6udnZCZB7BH7BCmv7f+5WaYY1pih2Zk80ZOZ/CzBSpWia6+kkyzRgI1CJ/mIOzLPWESxAy1r2kXc0hcUsut4+CYxS6GiCHBIWIjgYQ4PDLQ2hf76ue5LOIpFROO5IyxNg2lNza7rJFPUOkAUtVWjjSDc5RGfjB2IHzUjwvoj+FhlaOuULx+qfWlcH5toVEqDh5RnsRpCwn86ORm+WMmgOzTsAOUt 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)(7696005)(186003)(15650500001)(16526019)(966005)(4326008)(47076005)(83380400001)(45080400002)(426003)(6666004)(2616005)(8936002)(2906002)(44832011)(1076003)(36860700001)(26005)(8676002)(508600001)(36756003)(336012)(54906003)(6916009)(316002)(356005)(70586007)(70206006)(82310400003)(86362001)(5660300002)(81166007)(7416002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:32.6401 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6fe2564-9338-4894-cbb2-08d9a60386d4 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: BN8NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4500 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 ba69f581893b..e1504831bec0 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 @@ -236,6 +270,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