From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.42]) by mx.groups.io with SMTP id smtpd.web10.104851.1674833361597075566 for ; Fri, 27 Jan 2023 07:29:21 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=pZinePO0; 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.94.42, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V2iFTnvNmkBP3zWGtGdEzpwc0zdsvFi88rnyLct2QgBomXWTInkdohvpsKDOnPNfrgQa09mmhrKaVNO/7G1I5d1IFsm0U5pxMzHl+FVLsfDQtg9RZu6XP+9rMdDqVUjFlpdwiH9nAVnM2EVcRwHJ2oRdZ25K3vjTa8hf+YjUgIJtVxBDnFAVTCgNK6VtVdMqn7g1YQG1fDXpVM/I5e21PRSCxC5EOT3U2M92pS5zoWOkz9bf7t1emd6Q1XEz24FRwgmip9g3SQBS/j1DQ7etLU7Xnw0TeU/d5A526pGaWpyZ10DiYCRILWpOYTnrWSQGsJWZkg6sJZNjEhLKIy3hVw== 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=gsl+Gv5AFO4RJHbZkJ8fU0ne/GK1y8fH7xSJaUDp5BY=; b=NQdbM0fCiEKMrvTtPNxtszbmsEQPJMthjbdfj+0rTeqRsxixTJGHvrPDSFVtaiD8e52DOPGjtZl/jwP3nJV1RLIlQsp47IpiC3TdqZxNIy61WaVLT3ofNb3tjtxPK1uayStVg47nLhQP3LpEu9aR1QqfXr+4aD+t6gMz/bJpbAjMhhrNPLindtX0RmECpb1S9jf1NLLeRFBoczrW4KxfEh/Urrr+M0UQUlBV5sw3XTRaCf9sehbJgh01ctHLWa8HI5YPQVl2i4X7K56Excx/5vZo+tqZjITTc5Pu/mjKRTvqT1X10SrVTPY6FO9RXPDJY88eW3xWG9kuo1xFsfksYA== 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=gsl+Gv5AFO4RJHbZkJ8fU0ne/GK1y8fH7xSJaUDp5BY=; b=pZinePO0b5rFt4NK/pqyGntbpT3kLyWZx43Y7j4m9IRp6WrdJRnYxnmY7Cn++ItQ4USxbx03ZyBclq+sX5fhEoM8opmGqrBSffTgfU+fx/8srSSglM/1KaJTVscW3SE/8xb2aubosaab19f+vHw5SIaH3xMMCeVrdf4ERH3lr4E= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by BL1PR12MB5874.namprd12.prod.outlook.com (2603:10b6:208:396::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.22; Fri, 27 Jan 2023 15:29:17 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::6cc0:9c7a:bd00:441c]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::6cc0:9c7a:bd00:441c%7]) with mapi id 15.20.6043.022; Fri, 27 Jan 2023 15:29:17 +0000 Message-ID: <3e8ea9e2-502b-4cd3-3b02-74a42d62f7ec@amd.com> Date: Fri, 27 Jan 2023 09:29:14 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2] OvmfPkg: Create additional PML1 entries for large SEV-SNP VMs To: Mikolaj Lisik , devel@edk2.groups.io Cc: pedro.falcato@gmail.com, erdemaktas@google.com, jejb@linux.ibm.com, jiewen.yao@intel.com, min.m.xu@intel.com, michael.roth@amd.com References: From: "Lendacky, Thomas" In-Reply-To: X-ClientProxiedBy: DM6PR02CA0119.namprd02.prod.outlook.com (2603:10b6:5:1b4::21) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|BL1PR12MB5874:EE_ X-MS-Office365-Filtering-Correlation-Id: 725ad18c-f9e3-4019-df14-08db007b4046 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JKE0iz725JJVkn8DFmDShVKdRbU0SiMU6hv4RdEWSZosk9CM8KKwDoewaH0hdaYWLtZuAYPlYGQvcGIRGHf7n9q02f69SzPbbbPQeUfoRkjxNYLdfp3xrUg77Xu8r/4Tmuuo/YcgzwAFfiya0Zpm/kZYzfAFktzJITWb1qidNRhsfb/zmw5ZeMBebsdhUIabe0z4wRes9JzKEd8u+QCo+CAO71FG9cbp+D+I+cx/t2pEBVh4gKl4JWsTgjI7PkEFNoQw1WFFT8RtXN+DltXf4VM0v6zxH06C8ZNxY8IPCKlHXCmdYqDlo7/dN2kMNsLVF0dM7biSvu1SK5rBi1csU3Wi6DeJ1LPQi46gP3UeBXxzfHP9z2ZZ6fIzvl6MY/nEa1yafj7RdhLfevUmoFyPWyrhcPM+ORxZX5wAMtqS8A4oC67KQjS9GVXAllvNJzBchv/jaMbJnU2m6i12gNpvUqAsqgy/Qgb+hr87JX56qj3gp7VHUDhS6y8CKgg2KmPHt4WaXv49wwcVD0NbFGqoYBEfCn9V0pR2Gw58RFiTr7PkRntNscss8JDo3WWpPE+cCvvLxnFnixvUFZSSKXXgCnSo4p4IucGtA4QNuoQOtfm7ds+zbhteWRLzsa7kgYDcb/cwrxDjC2x7R1Qz3r3dnFoHdO/C6m3hFyokDMIV5S2gYM05ldqeNCqjwERCbbpoP+7Kz2pd1yAJx6pJDjlAwppekdKFM6b1ZMAYwmt/MZU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(376002)(136003)(396003)(346002)(366004)(39860400002)(451199018)(41300700001)(26005)(6666004)(8936002)(86362001)(316002)(66556008)(83380400001)(31696002)(36756003)(4326008)(38100700002)(66946007)(8676002)(19627235002)(66476007)(6512007)(2616005)(186003)(53546011)(6486002)(478600001)(6506007)(31686004)(2906002)(5660300002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VUlUMndZWHNRL1ByNWlhZGpwK0hMMzlIVE43MCtjalhudElQaXk4MkNoOXdH?= =?utf-8?B?RHpWL25ESWpoTEJ2MGYrR25KVklFT1FkZlhlWjg5dTVmdVdnRUFMaUJ0cDUz?= =?utf-8?B?NVFzTFVWZXRwY3pVNnllTUtGOWJzZm82MjVmWCt5aE5ncUxLZENKVTlHWVFQ?= =?utf-8?B?QWt0V3huTzFWeWMzallBUTZYY25HUTltQytVQTFmZXluck82eWs2WnZqUTM1?= =?utf-8?B?VEMyQWlqTFVybEhBNzVTR1ZmaUhRekU0Q2pGMWdScnJ1cWwzWWVFSmhEWnpS?= =?utf-8?B?NWE1VXViNXRWbktYUU1HZSs1RnRoenRvbFdOWDRuc1ZESTB4VEVqVUNKcnBo?= =?utf-8?B?aU51T1F0d1FRaj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rossTenant-Network-Message-Id: 725ad18c-f9e3-4019-df14-08db007b4046 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2023 15:29:17.0681 (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: Djdas75xSzI4YTCcY5qDN4nO4vfGrP9VlgCh/kCtAjjcWP8jOLeB+/1tMzd5yHL4mCLO6jjsOhQOWEVhbta3Dw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5874 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/26/23 14:26, Mikolaj Lisik wrote: > Edk2 was failing, rather than creating more PML4 entries, when they > weren't present in the initial memory acceptance flow. Because of that > VMs with more than 512G memory were crashing. This code fixes that. > > This change affects only SEV-SNP VMs. > > The code was tested by successfully booting a 512G SEV-SNP VM. > > Signed-off-by: Mikolaj Lisik Acked-by: Tom Lendacky > --- > .../X64/PeiDxeVirtualMemory.c | 26 ++++++++++++------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c > index b9c0a5b25a..75c2c36bb4 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c > @@ -548,6 +548,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( > PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; > PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; > UINT64 PgTableMask; > + UINT64 *NewPageTable; > UINT64 AddressEncMask; > BOOLEAN IsWpEnabled; > RETURN_STATUS Status; > @@ -602,15 +603,22 @@ InternalMemEncryptSevCreateIdentityMap1G ( > PageMapLevel4Entry = (VOID *)(Cr3BaseAddress & ~PgTableMask); > PageMapLevel4Entry += PML4_OFFSET (PhysicalAddress); > if (!PageMapLevel4Entry->Bits.Present) { > - DEBUG (( > - DEBUG_ERROR, > - "%a:%a: bad PML4 for Physical=0x%Lx\n", > - gEfiCallerBaseName, > - __FUNCTION__, > - PhysicalAddress > - )); > - Status = RETURN_NO_MAPPING; > - goto Done; > + NewPageTable = AllocatePageTableMemory (1); > + if (NewPageTable == NULL) { > + DEBUG (( > + DEBUG_ERROR, > + "%a:%a: failed to allocate a new PML4 entry\n", > + gEfiCallerBaseName, > + __FUNCTION__ > + )); > + Status = RETURN_NO_MAPPING; > + goto Done; > + } > + SetMem (NewPageTable, EFI_PAGE_SIZE, 0); > + PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)NewPageTable | AddressEncMask; > + PageMapLevel4Entry->Bits.MustBeZero = 0; > + PageMapLevel4Entry->Bits.ReadWrite = 1; > + PageMapLevel4Entry->Bits.Present = 1; > } > > PageDirectory1GEntry = (VOID *)(