public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: Garrett Kirkendall <Garrett.Kirkendall@amd.com>, devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>
Subject: Re: [PATCH v5 4/4] UefiCpuPkg: PiSmmCpuDxeSmm skip MSR_IA32_MISC_ENABLE manipulation on AMD
Date: Fri, 19 Jun 2020 22:26:50 +0200	[thread overview]
Message-ID: <dcfe4164-c021-7ddc-2891-fffc9b1c279d@redhat.com> (raw)
In-Reply-To: <20200619165629.9545-5-Garrett.Kirkendall@amd.com>

On 06/19/20 18:56, Garrett Kirkendall wrote:
> AMD does not support MSR_IA32_MISC_ENABLE.  Accessing that register
> causes and exception on AMD processors.  If Execution Disable is
> supported, but if the processor is an AMD processor, skip manipulating
> MSR_IA32_MISC_ENABLE[34] XD Disable bit.
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Signed-off-by: Garrett Kirkendall <garrett.kirkendall@amd.com>
> ---
> 
> Notes:
>     Tested on Intel hardware with Laszlo Ersek's help
>     
>     (1) downloaded two Linux images from provided links.
>     (2) Test using a 32-bit guest on an Intel host (standing in your edk2 tree, with the patches applied):
>     
>     $ build -a IA32 -b DEBUG -p OvmfPkg/OvmfPkgIa32.dsc -t GCC5 -D SMM_REQUIRE
>     
>     $ qemu-system-i386 \
>         -cpu coreduo,-nx \
>         -machine q35,smm=on,accel=kvm \
>         -m 4096 \
>         -smp 4 \
>         -global driver=cfi.pflash01,property=secure,value=on \
>         -drive if=pflash,format=raw,unit=0,readonly=on,file=Build/OvmfIa32/DEBUG_GCC5/FV/OVMF_CODE.fd \
>         -drive if=pflash,format=raw,unit=1,snapshot=on,file=Build/OvmfIa32/DEBUG_GCC5/FV/OVMF_VARS.fd \
>         -drive id=hdd,if=none,format=qcow2,snapshot=on,file=fedora-30-efi-systemd-i686.qcow2 \
>         -device virtio-scsi-pci,id=scsi0 \
>         -device scsi-hd,drive=hdd,bus=scsi0.0,bootindex=1
>     
>     (Once you get a login prompt, feel free to interrupt QEMU with Ctrl-C.)
>     
>     (3) Test using a 64-bit guest on an Intel host:
>     
>     $ build -a IA32 -a X64 -b DEBUG -p OvmfPkg/OvmfPkgIa32X64.dsc -t GCC5 -D SMM_REQUIRE
>     
>     $ qemu-system-x86_64 \
>         -cpu host \
>         -machine q35,smm=on,accel=kvm \
>         -m 4096 \
>         -smp 4 \
>         -global driver=cfi.pflash01,property=secure,value=on \
>         -drive if=pflash,format=raw,unit=0,readonly=on,file=Build/Ovmf3264/DEBUG_GCC5/FV/OVMF_CODE.fd \
>         -drive if=pflash,format=raw,unit=1,snapshot=on,file=Build/Ovmf3264/DEBUG_GCC5/FV/OVMF_VARS.fd \
>         -drive id=hdd,if=none,format=qcow2,snapshot=on,file=fedora-31-efi-grub2-x86_64.qcow2 \
>         -device virtio-scsi-pci,id=scsi0 \
>         -device scsi-hd,drive=hdd,bus=scsi0.0,bootindex=1
>     
>     Tested on real AMD Hardware
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h |  3 +++
>  UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c         |  9 ++++++++-
>  UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm   | 19 +++++++++++++++++--
>  UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm    | 20 ++++++++++++++++++--
>  4 files changed, 46 insertions(+), 5 deletions(-)

This patch is identical to v2, therefore my R-b still applies:

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

I've also run test (4), as described here:

  https://edk2.groups.io/g/devel/message/61344
  http://mid.mail-archive.com/5f2fd5a9-2107-503a-406b-de08529dcb56@redhat.com

so, for patch#4:

Tested-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo

> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> index 43f6935cf9dc..993360a8a8c1 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
> @@ -2,6 +2,7 @@
>  SMM profile internal header file.
>  
>  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>  
>  **/
> @@ -13,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/UefiRuntimeServicesTableLib.h>
>  #include <Library/DxeServicesTableLib.h>
>  #include <Library/CpuLib.h>
> +#include <Library/UefiCpuLib.h>
>  #include <IndustryStandard/Acpi.h>
>  
>  #include "SmmProfileArch.h"
> @@ -99,6 +101,7 @@ extern SMM_S3_RESUME_STATE       *mSmmS3ResumeState;
>  extern UINTN                     gSmiExceptionHandlers[];
>  extern BOOLEAN                   mXdSupported;
>  X86_ASSEMBLY_PATCH_LABEL         gPatchXdSupported;
> +X86_ASSEMBLY_PATCH_LABEL         gPatchMsrIa32MiscEnableSupported;
>  extern UINTN                     *mPFEntryCount;
>  extern UINT64                    (*mLastPFEntryValue)[MAX_PF_ENTRY_COUNT];
>  extern UINT64                    *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUNT];
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> index c47b5573e366..d7ed9ab7a770 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
> @@ -2,7 +2,7 @@
>  Enable SMM profile.
>  
>  Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.<BR>
> -Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
> +Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
>  
>  SPDX-License-Identifier: BSD-2-Clause-Patent
>  
> @@ -1015,6 +1015,13 @@ CheckFeatureSupported (
>        mXdSupported = FALSE;
>        PatchInstructionX86 (gPatchXdSupported, mXdSupported, 1);
>      }
> +
> +    if (StandardSignatureIsAuthenticAMD ()) {
> +      //
> +      // AMD processors do not support MSR_IA32_MISC_ENABLE
> +      //
> +      PatchInstructionX86 (gPatchMsrIa32MiscEnableSupported, FALSE, 1);
> +    }
>    }
>  
>    if (mBtsSupported) {
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm
> index f96de9bdeb43..167f5e14dbd4 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm
> @@ -1,5 +1,6 @@
>  ;------------------------------------------------------------------------------ ;
>  ; Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
> +; Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
>  ; SPDX-License-Identifier: BSD-2-Clause-Patent
>  ;
>  ; Module Name:
> @@ -59,6 +60,7 @@ global ASM_PFX(gPatchSmiStack)
>  global ASM_PFX(gPatchSmbase)
>  extern ASM_PFX(mXdSupported)
>  global ASM_PFX(gPatchXdSupported)
> +global ASM_PFX(gPatchMsrIa32MiscEnableSupported)
>  extern ASM_PFX(gSmiHandlerIdtr)
>  
>  extern ASM_PFX(mCetSupported)
> @@ -153,17 +155,30 @@ ASM_PFX(gPatchSmiCr3):
>  ASM_PFX(gPatchXdSupported):
>      cmp     al, 0
>      jz      @SkipXd
> +
> +; If MSR_IA32_MISC_ENABLE is supported, clear XD Disable bit
> +    mov     al, strict byte 1           ; source operand may be patched
> +ASM_PFX(gPatchMsrIa32MiscEnableSupported):
> +    cmp     al, 1
> +    jz      MsrIa32MiscEnableSupported
> +
> +; MSR_IA32_MISC_ENABLE not supported
> +    xor     edx, edx
> +    push    edx                         ; don't try to restore the XD Disable bit just before RSM
> +    jmp     EnableNxe
> +
>  ;
>  ; Check XD disable bit
>  ;
> +MsrIa32MiscEnableSupported:
>      mov     ecx, MSR_IA32_MISC_ENABLE
>      rdmsr
>      push    edx                        ; save MSR_IA32_MISC_ENABLE[63-32]
>      test    edx, BIT2                  ; MSR_IA32_MISC_ENABLE[34]
> -    jz      .5
> +    jz      EnableNxe
>      and     dx, 0xFFFB                 ; clear XD Disable bit if it is set
>      wrmsr
> -.5:
> +EnableNxe:
>      mov     ecx, MSR_EFER
>      rdmsr
>      or      ax, MSR_EFER_XD             ; enable NXE
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm
> index 8bfba55b5d08..0e154e5db949 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm
> @@ -1,5 +1,6 @@
>  ;------------------------------------------------------------------------------ ;
>  ; Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
> +; Copyright (c) 2020, AMD Incorporated. All rights reserved.<BR>
>  ; SPDX-License-Identifier: BSD-2-Clause-Patent
>  ;
>  ; Module Name:
> @@ -67,6 +68,7 @@ extern ASM_PFX(CpuSmmDebugExit)
>  global ASM_PFX(gPatchSmbase)
>  extern ASM_PFX(mXdSupported)
>  global ASM_PFX(gPatchXdSupported)
> +global ASM_PFX(gPatchMsrIa32MiscEnableSupported)
>  global ASM_PFX(gPatchSmiStack)
>  global ASM_PFX(gPatchSmiCr3)
>  global ASM_PFX(gPatch5LevelPagingNeeded)
> @@ -152,18 +154,32 @@ SkipEnable5LevelPaging:
>  ASM_PFX(gPatchXdSupported):
>      cmp     al, 0
>      jz      @SkipXd
> +
> +; If MSR_IA32_MISC_ENABLE is supported, clear XD Disable bit
> +    mov     al, strict byte 1           ; source operand may be patched
> +ASM_PFX(gPatchMsrIa32MiscEnableSupported):
> +    cmp     al, 1
> +    jz      MsrIa32MiscEnableSupported
> +
> +; MSR_IA32_MISC_ENABLE not supported
> +    sub     esp, 4
> +    xor     rdx, rdx
> +    push    rdx                         ; don't try to restore the XD Disable bit just before RSM
> +    jmp     EnableNxe
> +
>  ;
>  ; Check XD disable bit
>  ;
> +MsrIa32MiscEnableSupported:
>      mov     ecx, MSR_IA32_MISC_ENABLE
>      rdmsr
>      sub     esp, 4
>      push    rdx                        ; save MSR_IA32_MISC_ENABLE[63-32]
>      test    edx, BIT2                  ; MSR_IA32_MISC_ENABLE[34]
> -    jz      .0
> +    jz      EnableNxe
>      and     dx, 0xFFFB                 ; clear XD Disable bit if it is set
>      wrmsr
> -.0:
> +EnableNxe:
>      mov     ecx, MSR_EFER
>      rdmsr
>      or      ax, MSR_EFER_XD            ; enable NXE
> 


      reply	other threads:[~2020-06-19 20:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 16:56 [PATCH v5 0/4] AMD processor MSR_IA32_MISC_ENABLE Kirkendall, Garrett
2020-06-19 16:56 ` [PATCH v5 1/4] PcAtChipsetPkg: PcAtChipsetPkg.dsc add UefiCpuLib LibraryClass Kirkendall, Garrett
2020-06-22  2:50   ` [edk2-devel] " Guomin Jiang
2020-06-19 16:56 ` [PATCH v5 2/4] SourceLevelDebugPkg: SourceLevelDebugPkg.dsc " Kirkendall, Garrett
2020-06-19 16:56 ` [PATCH v5 3/4] UefiCpuPkg: Move StandardSignatureIsAuthenticAMD to BaseUefiCpuLib Kirkendall, Garrett
2020-06-19 16:56 ` [PATCH v5 4/4] UefiCpuPkg: PiSmmCpuDxeSmm skip MSR_IA32_MISC_ENABLE manipulation on AMD Kirkendall, Garrett
2020-06-19 20:26   ` Laszlo Ersek [this message]

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=dcfe4164-c021-7ddc-2891-fffc9b1c279d@redhat.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