From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.51]) by mx.groups.io with SMTP id smtpd.web10.1665.1685750187264810481 for ; Fri, 02 Jun 2023 16:56:27 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=oJaNGk0u; 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.243.51, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T49kBhR1Q1rRkV/MZzXhaZvIaOJylNd2KDoP2+sn/vzRvkOMr0nyUlU2Xh7NxR2ie6BN7EJE2T5n0spQj1/T4ivompZuMU7YyWu0hXiTSw6UdB4mLHAMb8ShjcjAPiXcq8omwKHYgw6oJpenlHA/2BqRUAuQndqgHIoFfVHrc709wFpJhuIWkLgysIQ4MpokVUj1sNkC7PzAT6gmwHqCkK2gs1lw4kOnBx/pI2Hai404KHfuXJH2IDmjEYNK7cNqMu+0EszgZfiKmbGvg+tYbJB+sj+q94HqWO/5hUZVa+qdJobGH2MUUzE6qiTYhWhzVp8guvpT16bd3F26iM47Fg== 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=dpeh7aj0EGPgamS2+sXpEl0/daigZqMPh9IoHtU+rOc=; b=YTtxCFbr1TGIF5QFGgPQY/9mm2h1SpyOgx2xxH0GCASD8zj80UhIAgE22gyAyRnYXGY8U8qH36YADyKAZgQx5UBPIu7LM6KU5gmvtzOP6hoIqKatoi6hf0ZcQltAKrWN25DXaIa0nih9ziRCqh55IMl2ddPNCYsrhaL8IX1cw2f2McFBOhvs+Wo/snR5FLDgXLuTG6Libmx7cc6DS9vzUf7mnwC1AmKyDkHkCKIekTU0wcgri66+GjYtU5/F4Ft1pDiaZMCLtT4qYGLo1ASuIf5t0XQnCob03VJrPeOkUl45WyB/tNcBv9XH873ppwGmifpq3Ws7kVh/rtd0zcXplA== 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=dpeh7aj0EGPgamS2+sXpEl0/daigZqMPh9IoHtU+rOc=; b=oJaNGk0ukSzb04tq05CsqYvYUAYAWVsS2thP765QpQq9KrNvMVycfgHVp3sDc/q9tVHSmZTTz4sJQh9fKm/ghM/Ek3UJzJ0vo2Cl76fl+La203cd0eyadCBuZyAiqeNc47BlxfHKXysldzXr1/SbRWfdJfH1QFNLa8D1yPwjlI8= 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 PH7PR12MB8124.namprd12.prod.outlook.com (2603:10b6:510:2ba::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Fri, 2 Jun 2023 23:56:24 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::61f6:a95e:c41e:bb25]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::61f6:a95e:c41e:bb25%3]) with mapi id 15.20.6455.026; Fri, 2 Jun 2023 23:56:24 +0000 Message-ID: Date: Fri, 2 Jun 2023 18:56:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [edk2-devel] [PATCH v2] OvmfPkg: Create additional PML1 entries for large SEV-SNP VMs To: Ard Biesheuvel , devel@edk2.groups.io Cc: Mikolaj Lisik , Gerd Hoffmann , 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: <9d9d8bb2-ac6f-0339-738e-44c6d50f286b@amd.com> From: "Lendacky, Thomas" In-Reply-To: X-ClientProxiedBy: SA9PR13CA0038.namprd13.prod.outlook.com (2603:10b6:806:22::13) 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_|PH7PR12MB8124:EE_ X-MS-Office365-Filtering-Correlation-Id: e825150f-bf93-4cae-66da-08db63c4f865 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hB8syIN/39ccchVBn8/FmT78ipQEF5dLh/o/gwwcg82BzGYB7hoMkZQnlz7Rv/eR62fhiF0PLa+doaXFhc6Z4JAVNZV7k63FCjn/iZHjN3fBAaNqo6UVI/yHj8aY7YghGP/GGzISN85ewgCTsePKbwIURkK8PotH5UPCxgng9CB4fy5Zgcwoz+MXsPDromtELY9fcumDA4ccEMwIUSWIz4COxmGh288E4y3qS2W8a25kioApzSCPmUpbBOb388SsLwsEzVTRdn2R3NbefRrG5dKqqGIZ/negmOYkNxhyp+8SvFN4VO02iobLoSh1xskhe3wZ3huLyya+JBIu0DkQZBYhL+KUN8lYX7xhWvRBcn5x/1mL0uFMKjv0i49HoIg8IGxpEfX+G0Bu1B36+wG3QdsmVHn1vvHgDOCvQKTdjrUrulzXdGHFCUsScfdsTjs7KtuAPX/cCaHov9aYPscPDw0jwBcOegeWYjIqb4yxfPVysUjVajhrek4p5caTAAWIcgxlXZOkz7VRuAaIaPguO+JyxlAIgMhfOfONLVL3TGyUYYSJsSioCCH23sVjyaULQ3qcfyHiDX4+jG7/JRtU5lps/L6lhvw+li7X8tsdtFr+S2qNdERokBk//hfYA8fX 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:(13230028)(4636009)(366004)(346002)(39860400002)(396003)(376002)(136003)(451199021)(19627235002)(54906003)(8936002)(66899021)(478600001)(5660300002)(66946007)(8676002)(36756003)(2906002)(31696002)(86362001)(66476007)(66556008)(316002)(4326008)(38100700002)(41300700001)(2616005)(966005)(186003)(6512007)(6506007)(6666004)(26005)(53546011)(6486002)(31686004)(83380400001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?VGJzaEs0eEh6N2RELzJWZjRQT3Nwdkw1b0xDSzhjYjRmNzY4ZnpSZWFDQk1p?= =?utf-8?B?QVRWUytRTEc4aFFweHdlV0oydTR6SzZNVGJCcS9EQlczbnFDMDI5OE8ydm9h?= =?utf-8?B?SEZIRUJPdHVNenF4VC9HK3RIbDN5TThPd2VPTjdiK1ErdGZCVnVmT2RHS0tY?= =?utf-8?B?b1ZsTElEMVZQbXE5eFIwZi9laVl0NEEyWGFNbEhXWnBRMU84VWxNd1pFbzRI?= =?utf-8?B?RGp3K3JYekFuN3poaGprdW9sWXpyQ1BmSiszSTVQQnRobnBUQXlyQk1aRG51?= =?utf-8?B?cHdSc2ZqdUZtbmhiVFlwQlVFQVpCMFJDM2lJTU91YTZBWVdZdmo3a2gwSGtC?= =?utf-8?B?WG1NQllRQkpvM3RqSmxSUlZzdGNHd2V1clU1RUkvbmlnK3JJMkFvY0hXRDdn?= =?utf-8?B?N0ZPSVVnU2NjZm5sSEZPNU1FakV3Ni8wMjZ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hET09iaEd1bnJHSklJUjVwRGV4dUtj?= =?utf-8?B?aVlHQmNmeDllMTNiaXRaQWExQ1VkdENtNjMralpyUVhTTjRHR3ZzOEFyN1FF?= =?utf-8?B?djhWOXYxZG1PSU5lZnpOMCtvK0grM1ZLNnM0eGs1eGozM3IrcXR0L1FodCty?= =?utf-8?B?dTdMUkpUbzFGMVBJR2pTdVNSVlZmVngvc3JHdktXVERjL2RTdWFsZFg5ZlVj?= =?utf-8?B?VEplNm9meWU2U3BPaFdzcDEvakloV2thYmxaOE16WmxSYXloWk1vc1Vyakpi?= =?utf-8?B?S2RUTmJVWCtZOHBZZ09TeTVCdUtMQVRtQnc3bTJmT013ajFzcVREUWdIdDFy?= =?utf-8?B?QlFEMWRtdXVyRkhDeFR5T3g1VFVmWVQxQTl0VHJacUNicW82RHNhc0M3NWI2?= =?utf-8?B?dzdJUjFnbE1rKzZkeUxQOEwvdG5GcENkL2NReXdnM1huSUtvVGpzNUtQSEZS?= =?utf-8?B?ZitqRFN5b2tSMFpjRC9QelovVllNUHJmKzJzZGxTbzZFRHlMRHBudjF0R2Vp?= =?utf-8?B?WllTUENYKzc2dmNKdzk3L1NONTlyZTVjUGwyMThSQTVLd0Y5Yzh2TGhQWmJt?= =?utf-8?B?U1RnSzdRcHRzNHliZ2c2UkwrbnpTSkNQdTdIYjhrQ0lWaEVWT1l6QXZMWWdW?= =?utf-8?B?Um5NdnQySTVKZDhldWFlQUowc0wyMEltZ2RqM1ZISVM3Q29UZWZQQzYrdnJq?= =?utf-8?B?SGxIcHJyWGhneWtDcFVST1Z5cXpxckptZTRFYm5iTnVXQ3RhZmxITHB1amhF?= =?utf-8?Q?zfO2kA8Xg52E+W+qA2FPvs7yc?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e825150f-bf93-4cae-66da-08db63c4f865 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 23:56:23.7164 (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: BYdZDy1J3X+kCIeAFWo3/jtZ03Tx3S20CYKnCPfulZhLsG/1H2wwVUsVFIq3b0+fZNAw30kOc0ima1ub0skZDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8124 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/2/23 17:49, Ard Biesheuvel wrote: > On Fri, 2 Jun 2023 at 23:20, Lendacky, Thomas via groups.io > wrote: >> >> 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 >> >> I don't see where this was merged. Both Gerd and I acked it back in >> January, was there a problem with it? >> > > I wasn't cc'ed. Ah, I hadn't noticed that you weren't cc'd... > > I've queued this up now. Thanks, Ard! Tom > > > >> >>> --- >>> .../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 *)( >> >> >> >> >>