From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.26.1616599956611292901 for ; Wed, 24 Mar 2021 08:32:40 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=kOsLl3sT; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: , mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A7gMhpF7AauJ4xW06pXIaw64AYqUcuW2V4fjUMRFEnp7Exwgzg8RI0unNbdZ5+numCs/0ZEI2MkiUgEFsYAzOgsTd/juPnUFnj2iALZzwEHsI/3bPO/vOCBues+zhdvpMyiaGnWqW1ZyvhsfrV+XMi1ewEaIH4i9U9+Ui53CKS2K8uXnU+SlSUMVMHU9ip4/JxnzOoQfBUqj6Gqpf40WLkzxZNV8EWeiohISe9t1P6y890l5JL5j96X4AZZU/osuSEfmiI8Mz4Eeh2azix87BK5LrJMYxlt54EzY0nSVGP+W+z43AamkJznW2xpFn8H98TUy1tQlNpwoRVR1jnpUVw== 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=4Qg73KW0EWuopAVqep+xoY/+mCLOJShZs3VZeN0zSVc=; b=IJS4+NcMx0d1+S4fGivt3TDqISi+ry87bgE3kKRSL8chl5EWpVqxX3ldJZPiqw+qKImMWbOjdNezb7xqmj0DUEEjvgWAjHruEMX7/6U79SWSo6IVhbNPjSDBIiMx95SVjRwQEQtm0KNQGLOowcSP4lM4jW6wqSPCFBtOm4kXgya4LFlTdh8e0o+f+ngfd3MCmfzEDovvpwwJOJEuFiy9X0FHAXMIdG39ziBOrVUGTBU624PXOA4jnsPzHmdJ6s885+Lfcq2BDX+YBu8sfs2ROQRYxTUnlsjgKbW8ZG3sFXpYf5FsHdKbIqF9xjq6S8HXc5J+rKWrDBSnyHK6v6cw8g== 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=4Qg73KW0EWuopAVqep+xoY/+mCLOJShZs3VZeN0zSVc=; b=kOsLl3sTQbqmuf2Kyn52Ap2meRSi2qqxB91C+Lq/2h9KDjl/y0KUv4Aa6i2gFrAualhb56/0yB9G0QLaHwiIlswxIAlhzHthLddOWA9HCdqHkGZovsXw+cYS7MqL6Dgm+mMS0/n470s50ZrSGPE+UjNN4aQPWxSOL6I2uHVX37Y= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4430.namprd12.prod.outlook.com (2603:10b6:806:70::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 24 Mar 2021 15:32:38 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d%3]) with mapi id 15.20.3955.027; Wed, 24 Mar 2021 15:32:38 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io Cc: Brijesh Singh , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek Subject: [RFC PATCH 15/19] OvmfPkg/PlatformPei: Validate the system RAM when SNP is active Date: Wed, 24 Mar 2021 10:32:11 -0500 Message-Id: <20210324153215.17971-16-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210324153215.17971-1-brijesh.singh@amd.com> References: <20210324153215.17971-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) 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 SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Wed, 24 Mar 2021 15:32:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9e7f7fa1-73a3-46fe-b870-08d8eeda0de1 X-MS-TrafficTypeDiagnostic: SA0PR12MB4430: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vA/4WvO3IhA76I60mVlhr5DhRMeuDhQhV3tvvV/968qIvVto+uFS5RV4BkZPzOQ4l6P/mqEYTjlrabmrbd9yZ+17p2lRoljJUNa/63YCSMOrhbNic5wYyQNHkGkx7QkLHnXmaZiMU9bmhuI0bDXm7fFTARaJNyqaQm6zvb3PngqeA4CigeTXhL2DEAnv+iwIPt/qpQmeAR/cqIDtoyZs31FDQPIcWW60gyA8Zbs7YTlRMSKRAJPH7ZWQqSQcKRKHAzk//K1IiFhE3+YohqvQFcm4j4Huvyq6BiaDTaIU5iETCSo8xXlUl3iERDy2L83ZQLGGc8z9ijuqPRpIhCHqwGT/qWmJye/o+70wm/suXj+M6hlqAu8iSQZcQyhd7gfn35zeJEyHKvwV1GGks8g6y84Chh7eyNzEiWS93y16t8O5Fo/Rclnv4D9ty34VpF97v+rNMAiHmNTOkD1fAJghjsTu3xyXGHj3Q9njZSIVjwRomXtwWsAOaBn5ZIfN0+U+Lhuexx6rQnzrcnF2B423ioA3hQXYaSNtRRMPqLZhQmHvJLxcShy8xlvWgrNDtQFu4nGwVgP9TEt/GDADhsz2mpJr+JOdeHWN64Q2WkqPMwah/E0fTpgBJFiPVN/b7Tl9FaP77/M2ynQXWGrD0BIDhD4N1GEFSTzRULu4bkXaJIaq1ojqA3WswPPYoRcDr48xIiTYnZPud4kO6CSwSNW95JbHXn8QXsd6TBZBHsb6jeqvZNSjWaveDi0NdQoqlBV0 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)(136003)(376002)(346002)(396003)(2616005)(83380400001)(66476007)(15650500001)(4326008)(44832011)(1076003)(6486002)(2906002)(86362001)(66946007)(478600001)(316002)(66556008)(966005)(16526019)(6666004)(26005)(54906003)(6916009)(186003)(5660300002)(8676002)(45080400002)(7696005)(956004)(8936002)(38100700001)(36756003)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Wok7adkMkRSCo0JJ3/MtW390vildrHs5l0553+3EimJV/P8x2ojQd/FkfTnE?= =?us-ascii?Q?hN8MBvmbKbeil40J8y+8VP1mxb+WJEX/H1iT7A7Ia3KILcPS4ust3UrTzqsE?= =?us-ascii?Q?dLCzOInw9IXoPcyS1D8QYNtMgwvSumkSMZ3+AeHPOkEe3yuEufRuswmL67TR?= =?us-ascii?Q?bRiLGRwU6nSioAOhDPZHfpKCvLKD+JmYYElpdha9+1oftOiblakcwpiJ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WRUxyGZ/z3qfEJTCnlXGBg0Rb6n8GmhhsxPHX3?= =?us-ascii?Q?uuXOErmAS0Xa7bJ2ug9SqnGTPsRPxfao1Kb6VBxXeJIfYYEYEhQM/Ra9VOv3?= =?us-ascii?Q?COCSUCgLKHecBrdnu0O35nigvptjYyCLcYn2fXqYUNYQKS5QbniRVYDgmrO7?= =?us-ascii?Q?MagNqbBg/l3COgkEeFSke5M1CJ7UyfR7QkKs5OnKY92UXe49jhzdkYOiBYYo?= =?us-ascii?Q?GmTijsL33t9v8IgMO4IM3tZk?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e7f7fa1-73a3-46fe-b870-08d8eeda0de1 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2021 15:32:38.0220 (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: GTHwEISky9tn7OkkjSjF8nEezN0am+AQZxCT+7UCobKIJsjnBCfiyFv1L238FiN4FKqmw2aYvIiEwYTFHKvr7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4430 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 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 ========= 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 ====================== 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, we have chosen 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 Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/AmdSev.c | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 95c5ad235f..abbbef54c1 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -140,6 +140,42 @@ AmdSevEsInitialize ( AsmWriteGdtr (&Gdtr); } +/** + + 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; + } + + DEBUG ((EFI_D_INFO, "SEV-SNP is enabled.\n")); + + // + // Iterate through the system RAM and validate it. + // + for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) { + if (Hob.Raw != NULL && GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) { + ResourceHob = Hob.ResourceDescriptor; + + if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) { + MemEncryptSevSnpValidateSystemRam (ResourceHob->PhysicalStart, + EFI_SIZE_TO_PAGES (ResourceHob->ResourceLength) + ); + } + } + } +} + /** Function checks if SEV support is available, if present then it sets @@ -217,6 +253,11 @@ AmdSevInitialize ( } } + // + // Check and perform SEV-SNP initialization if required. + // + AmdSevSnpInitialize (); + // // Check and perform SEV-ES initialization if required. // -- 2.17.1