public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zhiguang Liu" <zhiguang.liu@intel.com>
To: "kraxel@redhat.com" <kraxel@redhat.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Ni, Ray" <ray.ni@intel.com>,
	"Kumar, Rahul R" <rahul.r.kumar@intel.com>,
	"Dong, Eric" <eric.dong@intel.com>,
	"Zeng, Star" <star.zeng@intel.com>,
	"Wu, Jiaxin" <jiaxin.wu@intel.com>
Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging
Date: Wed, 18 Jan 2023 09:12:09 +0000	[thread overview]
Message-ID: <PH0PR11MB5048B6E3A213BB7471BFA03E90C79@PH0PR11MB5048.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20230118085350.bv7s7spmmhkr4ozj@sirius.home.kraxel.org>

Hi Gerd,

Let's check the code in InitPaging.
If 5LevelPaging is disabled, Pml5 points to a local variable. Pml5[1] shouldn't be used.

     UINT64    Pml5Entry;
     UINT64    *Pml5;
     if (!Enable5LevelPaging) {
        Pml5Entry = (UINTN)mSmmProfileCr3 | IA32_PG_P;
        Pml5      = &Pml5Entry;

However, if NumberOfPml5Entries is larger than 1, below code will access Pml5[1], which may cause unexpected future code flow.

    for (Pml5Index = 0; Pml5Index < NumberOfPml5Entries; Pml5Index++) {
        if ((Pml5[Pml5Index] & IA32_PG_P) == 0) {

Could this can answer your question? Please let me know if you still have concern.

And for the CpuPageTableLib, I think the API don't provide the interface to split 2MB-page page table into 4KB-page, which is the function wants to do.

Thanks
Zhiguang


> -----Original Message-----
> From: kraxel@redhat.com <kraxel@redhat.com>
> Sent: Wednesday, January 18, 2023 4:54 PM
> To: devel@edk2.groups.io; Liu, Zhiguang <zhiguang.liu@intel.com>
> Cc: Ni, Ray <ray.ni@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>;
> Dong, Eric <eric.dong@intel.com>; Zeng, Star <star.zeng@intel.com>; Wu,
> Jiaxin <jiaxin.wu@intel.com>
> Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg: Fix SMM code hangs when
> InitPaging
> 
> On Wed, Jan 18, 2023 at 01:13:43AM +0000, Zhiguang Liu wrote:
> > Thanks all for reviewing, and I will send a new version to address the comment.
> >
> > As for Gerd's question, let me explain.
> > Let's see one example, that the CPU has SizeOfMemorySpace >48, but the CPU
> doesn't enable 5 level paging.
> > The purpose of the current function InitPaging is to modify existing
> > page table. To use the same logic to handle both 5 level and 4 level
> > paging, for 4 level paging, the logic will create a false 5 level
> > paging entry to treat it like a 5 level page table.
> 
> Yes.  Same for 3-level paging btw.  There are always page tables for 5 levels, but
> the higher levels might be unused.
> 
> > This way, the
> > number of 5 level paging should always be one. If we use
> > SizeOfMemorySpace to calculate the 5 level paging entry count, we will
> > get number more than one.  However, as I just mentioned, we only
> > create one false 5 level paging entry, system may hang when we try to
> > access the second 5 level paging entry.
> 
> If 5-level paging is turned off the CPU should not see what you are doing with
> the page tables for the second (and higher) 5-level entry.
> 
> So, limiting the number of 5-level entries does make sense.  Higher entries are
> not used, so it's pointless work.
> 
> But that doesn't answer the question:  Why does that fix the system hanging?  I
> just can't see a reason for that when looking through the InitPaging code.  I
> suspect this might hide a bug somewhere else.
> 
> Related:  We got UefiCpuPkg/Library/CpuPageTableLib last year, can this be
> used instead?
> 
> take care,
>   Gerd


  reply	other threads:[~2023-01-18  9:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04  5:41 [PATCH] UefiCpuPkg: Fix SMM code hangs when InitPaging Zhiguang Liu
2023-01-12 12:11 ` [edk2-devel] " Zeng, Star
2023-01-17  8:44   ` Wu, Jiaxin
2023-01-17  9:01 ` Ni, Ray
2023-01-17  9:02 ` Ni, Ray
2023-01-17 12:13   ` Gerd Hoffmann
2023-01-17 12:48     ` [edk2-devel] " Ni, Ray
2023-01-18  1:13       ` Zhiguang Liu
2023-01-18  8:53         ` Gerd Hoffmann
2023-01-18  9:12           ` Zhiguang Liu [this message]
2023-01-18 10:10             ` Gerd Hoffmann
2023-01-18 15:27               ` Ni, Ray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PH0PR11MB5048B6E3A213BB7471BFA03E90C79@PH0PR11MB5048.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox