From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.769.1686246512782157885 for ; Thu, 08 Jun 2023 10:48:32 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EuGJ1JaL; spf=pass (domain: kernel.org, ip: 139.178.84.217, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2041E64FFB for ; Thu, 8 Jun 2023 17:48:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1159AC433A7 for ; Thu, 8 Jun 2023 17:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686246511; bh=zqzJtFqTNpeQ2qsXG+FFEG2FgO1bZ86t2kbnQi7AgvM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EuGJ1JaLQDPC21TZWosJUTOpSUK/wsrpJn0VOMThE5Cr1InYgRSOD8R2uq2pe6WBr bgt/xCuHxr+KwAkvx6HSib9HUBj65o5VqeCVIwWMICkeeydoTGdUB+fSkGb8wVTnDv vDcNSercS9lJAzJTMF3JiHnt2e9W4TdbujsjlTC0g9VZYvG68mFpZjtuAi2pjeb4dh Nfo0i6jeaffitsjcsoplW4OnnS4Srj2Jsubr4LHPEsrGoSXhjJhFUnI2XYKSXJv40h CSzYL0cahxyLXFoCc4MXXiIq+BlZe/yzplfeqhv179KvoIuIvVLk/Hi4kPCNGH7/no a9F5V7BStMbvg== Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-4f619c2ba18so1088224e87.1 for ; Thu, 08 Jun 2023 10:48:30 -0700 (PDT) X-Gm-Message-State: AC+VfDx8h5I4fYi7g5fRhuPuLq9sdTNSiBoR/4xTYi2mV8pWfHKDjUsQ uy+befjxnTrFdw+liI52z5ZQ6FiZGE0Oys/4KiU= X-Google-Smtp-Source: ACHHUZ4nCB8065g7tv79uRkgFvIj6DP/iuFAItb/ZY4OSscfSYR38e4hnnWF9+xzDooIIEJ7LzNuH2nLFe/tDkwK+4M= X-Received: by 2002:a2e:97d8:0:b0:2af:3147:86c8 with SMTP id m24-20020a2e97d8000000b002af314786c8mr3717015ljj.16.1686246509086; Thu, 08 Jun 2023 10:48:29 -0700 (PDT) MIME-Version: 1.0 References: <20230608172323.9096-1-ardb@kernel.org> <20230608172323.9096-3-ardb@kernel.org> <90e33c93-8965-dd26-15ed-8f6f2c5c3745@linux.microsoft.com> In-Reply-To: <90e33c93-8965-dd26-15ed-8f6f2c5c3745@linux.microsoft.com> From: "Ard Biesheuvel" Date: Thu, 8 Jun 2023 19:48:17 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel] [PATCH 2/2] UefiCpuPkg/CpuMpPei X64: Reallocate page tables in permanent DRAM To: Oliver Smith-Denny Cc: devel@edk2.groups.io, Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Dun Tan , Liming Gao , "Kinney, Michael D" , Michael Kubacki , Eric Dong , Rahul Kumar , Kun Qin Content-Type: text/plain; charset="UTF-8" On Thu, 8 Jun 2023 at 19:39, Oliver Smith-Denny wrote: > > On 6/8/2023 10:23 AM, Ard Biesheuvel wrote: > > Currently, we rely on the logic in DXE IPL to create new page tables > > from scratch when executing in X64 mode, which means that we run with > > the initial page tables all throughout PEI, and never enable protections > > such as the CPU stack guard, even though the logic is already in place > > for IA32. > > > > So let's enable the existing logic for X64 as well. This will permit us > > to apply stricter memory permissions to code and data allocations, as > > well as the stack, when executing in PEI. It also makes the DxeIpl logic > > redundant, and should allow us to make the PcdDxeIplBuildPageTables > > feature PCD limited to IA32 DxeIpl loading the x64 DXE core. > > > > When running in long mode, use the same logic that DxeIpl uses to > > determine the size of the address space, whether or not to use 1 GB leaf > > entries and whether or not to use 5 level paging. Note that in long > > mode, PEI is entered with paging enabled, and given that switching > > between 4 and 5 levels of paging is not currently supported without > > dropping out of 64-bit mode temporarily, all we can do is carry on > > without changing the number of levels. > > > > I certainly agree with extending the ability to have memory protections > in PEI (and trying to unify across x86 and ARM (and beyond :)). > > A few things I am trying to understand: > > Does ARM today rebuild the page table in DxeIpl? Or is it using an > earlier built page table? > No. Most platforms run without any page tables until the permanent memory is installed, at which point it essentially maps what the platform describes as device memory and as normal memory. > If I understand your proposal correctly, with the addition of this > patch, you are suggesting we can drop creating new page tables in DxeIpl > and use only one page table throughout. Yes. > Again, I like the idea of having > mapped memory protections that continue through, but do you have > concerns that we may end up with garbage from PEI in DXE in the page > table? For OEMs, they may not control PEI and therefore be at the whim > of another's PEI page table. Would you envision the GCD gets built from > the existing page table or that the GCD gets built according to resource > descriptor HOBs and DxeCore ensures that the page table reflects what > the HOBs indicated? > If there is a reason to start with a clean slate when DxeIpl hands over to DXE core, I'd prefer that to be a conscious decision rather than a consequence of the X64 vs IA32 legacy. I think you can make a case for priming the GCD map based on resource descriptors rather than current mappings, with the exception of DXE core itself and the DXE mode stack. But I'd like to understand better what we think might be wrong with the page tables as PEI leaves them.