public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Dong, Eric" <eric.dong@intel.com>
To: "Wang, Jian J" <jian.j.wang@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Yao, Jiewen" <jiewen.yao@intel.com>,
	"Ni, Ruiyu" <ruiyu.ni@intel.com>,
	Laszlo Ersek <lersek@redhat.com>
Subject: Re: [PATCH 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Enable NXE if it's supported
Date: Tue, 16 Jan 2018 14:02:50 +0000	[thread overview]
Message-ID: <ED077930C258884BBCB450DB737E66224AA8AEDE@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20180115085433.25008-5-jian.j.wang@intel.com>

Reviewed-by: Eric Dong <eric.dong@intel.com>

> -----Original Message-----
> From: Wang, Jian J
> Sent: Monday, January 15, 2018 4:55 PM
> To: edk2-devel@lists.01.org
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>;
> Dong, Eric <eric.dong@intel.com>; Laszlo Ersek <lersek@redhat.com>
> Subject: [PATCH 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Enable NXE if it's
> supported
> 
> If PcdDxeNxMemoryProtectionPolicy is set to enable protection for memory
> of EfiBootServicesCode, EfiConventionalMemory, the BIOS will hang at a
> page fault exception triggered by PiSmmCpuDxeSmm.
> 
> The root cause is that PiSmmCpuDxeSmm will access default SMM RAM
> starting at 0x30000 which is marked as non-executable, but NX feature was
> not enabled during SMM initialization. Accessing memory which has invalid
> attributes set will cause page fault exception. This patch fixes it by checking
> NX capability in cpuid and enable NXE in EFER MSR if it's available.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
> ---
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm | 14 ++++++++++++++
> UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm  | 12 +++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
> b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
> index d9df3626c7..db172f108a 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmInit.nasm
> @@ -42,6 +42,11 @@ ASM_PFX(gcSmiInitGdtr):
> 
>  global ASM_PFX(SmmStartup)
>  ASM_PFX(SmmStartup):
> +    DB      0x66
> +    mov     eax, 0x80000001             ; read capability
> +    cpuid
> +    DB      0x66
> +    mov     ebx, edx                    ; rdmsr will change edx. keep it in ebx.
>      DB      0x66, 0xb8
>  ASM_PFX(gSmmCr3): DD 0
>      mov     cr3, eax
> @@ -50,6 +55,15 @@ ASM_PFX(gSmmCr3): DD 0
>      DB      0x66, 0xb8
>  ASM_PFX(gSmmCr4): DD 0
>      mov     cr4, eax
> +    DB      0x66
> +    mov     ecx, 0xc0000080             ; IA32_EFER MSR
> +    rdmsr
> +    DB      0x66
> +    test    ebx, BIT20                  ; check NXE capability
> +    jz      .1
> +    or      ah, BIT3                    ; set NXE bit
> +    wrmsr
> +.1:
>      DB      0x66, 0xb8
>  ASM_PFX(gSmmCr0): DD 0
>      DB      0xbf, PROTECT_MODE_DS, 0    ; mov di, PROTECT_MODE_DS
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm
> b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm
> index 9d05e2cb05..2a3a1141c3 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmInit.nasm
> @@ -42,6 +42,11 @@ ASM_PFX(gcSmiInitGdtr):
> 
>  global ASM_PFX(SmmStartup)
>  ASM_PFX(SmmStartup):
> +    DB      0x66
> +    mov     eax, 0x80000001             ; read capability
> +    cpuid
> +    DB      0x66
> +    mov     ebx, edx                    ; rdmsr will change edx. keep it in ebx.
>      DB      0x66, 0xb8                   ; mov eax, imm32
>  ASM_PFX(gSmmCr3): DD 0
>      mov     cr3, rax
> @@ -54,7 +59,12 @@ ASM_PFX(gSmmCr4): DD 0
>      DB      0x66
>      mov     ecx, 0xc0000080             ; IA32_EFER MSR
>      rdmsr
> -    or      ah, 1                       ; set LME bit
> +    or      ah, BIT0                    ; set LME bit
> +    DB      0x66
> +    test    ebx, BIT20                  ; check NXE capability
> +    jz      .1
> +    or      ah, BIT3                    ; set NXE bit
> +.1:
>      wrmsr
>      DB      0x66, 0xb8                   ; mov eax, imm32
>  ASM_PFX(gSmmCr0): DD 0
> --
> 2.15.1.windows.2



  reply	other threads:[~2018-01-16 13:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15  8:54 [PATCH 0/6] Fix issues caused by NX memory protection Jian J Wang
2018-01-15  8:54 ` [PATCH 1/6] UefiCpuPkg/MpInitLib: split wake up buffer into two parts Jian J Wang
2018-01-18  6:53   ` Dong, Eric
2018-01-27 16:17   ` Laszlo Ersek
2018-01-28 21:43     ` Laszlo Ersek
2018-01-29  1:06       ` Wang, Jian J
2018-01-29 15:50         ` Laszlo Ersek
2018-01-15  8:54 ` [PATCH 2/6] UefiCpuPkg/CpuExceptionHandlerLib: alloc code memory for exception handlers Jian J Wang
2018-01-16 14:02   ` Dong, Eric
2018-01-15  8:54 ` [PATCH 3/6] UefiCpuPkg/CpuDxe: clear NX attr for page directory Jian J Wang
2018-01-16 14:02   ` Dong, Eric
2018-01-15  8:54 ` [PATCH 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Enable NXE if it's supported Jian J Wang
2018-01-16 14:02   ` Dong, Eric [this message]
2018-01-28 22:46   ` Laszlo Ersek
2018-01-29  9:02     ` Wang, Jian J
2018-01-29 19:48       ` Laszlo Ersek
2018-01-30 13:09         ` Laszlo Ersek
2018-02-01  1:08         ` Wang, Jian J
2018-01-15  8:54 ` [PATCH 5/6] MdeModulePkg/PiSmmCore: remove NX attr for SMM RAM Jian J Wang
2018-01-15 10:18   ` Zeng, Star
2018-01-15  8:54 ` [PATCH 6/6] MdeModulePkg/BootScriptExecutorDxe: remove NX attr for FfsBuffer Jian J Wang
2018-01-15 10:18   ` Zeng, Star

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=ED077930C258884BBCB450DB737E66224AA8AEDE@shsmsx102.ccr.corp.intel.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