Hi Laszlo
Thanks for the reminder.

Hi William
I try to your answer below. Feel free to let me know if you have more question.

For more detail information on how we protect SMRAM, please refer to 
https://www.gitbook.com/book/edk2-docs/a-tour-beyond-bios-memory-protection-in-uefi-bios/details


Thank you
Yao Jiewen


From: Laszlo Ersek [mailto:ler...@redhat.com]
Sent: Friday, March 24, 2017 11:58 PM
To: William Tambe <tambewill...@gmail.com>; Yao, Jiewen <jiewen....@intel.com>
Cc: edk2-devel@lists.01.org
Subject: Re: [edk2] Page Table initialization and update in SMM mode

Jiewen,

On 03/22/17 15:14, William Tambe wrote:
> Dear all,
>
> When building OVMF with SMM_REQUIRE:
>
> - Would you know where in the code base the Page Table set in the Cr3
> register is initialized during boot ?
[Jiewen] UefiCpuPkg\PiSmmCpuDxeSmm\MpService.c: InitializeMpServiceData()

  //
  // Create page tables
  //
  Cr3 = SmmInitPageTable ();


>
> - Where does it get updated when a new page needs to be allocated or freed ?
[Jiewen] We do not update page table on allocation/free.

Instead PiSmmCpu driver updates page table once, after ready to lock.
UefiCpuPkg\PiSmmCpuDxeSmm\PiSmmCpuDxeSmm.c: PerformRemainingTasks()


    //
    // Create a mix of 2MB and 4KB page table. Update some memory ranges absent 
and execute-disable.
    //
    InitPaging ();

    //
    // Mark critical region to be read-only in page table
    //
    SetMemMapAttributes ();

    //
    // For outside SMRAM, we only map SMM communication buffer or MMIO.
    //
    SetUefiMemMapAttributes ();

    //
    // Set page table itself to be read-only
    //
    SetPageTableAttributes ();


>
> - Or is there a hook I can register myself to in order to get a chance to
> review an entry to be added or removed from the Page Tables ?
[Jiewen] You can register a ready to boot event in your SMM driver and dump 
page table, which is the final page table in SMM.
(That is what our internal test case does. :))



can you please help answer these questions? I seem to remember that we
discussed code around this when we were looking into the SMM stack
overflow experienced with OVMF:

509f8425b75d UefiCpuPkg: change PcdCpuSmmStackGuard default to TRUE
0d0c245dfb14 OvmfPkg: set SMM stack size to 16KB

William: I suggest to check out the following files:

UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c
UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c

and/or to grep the code for "PcdCpuSmmStackGuard", to get a feel for
what to investigate.

Thanks
Laszlo
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to