From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.25051.1592245852109014167 for ; Mon, 15 Jun 2020 11:30:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=CxYXWVkP; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: garrett.kirkendall@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uqa3FBuUtKOUM/o9g5J1vg39s8Rv41bBdpMLBpalTxbgLM4tl2HSXlS0kNTU4ClpzLWWqcgD+9bc0Z/9Nt1Ww0A3biCgnN6vkJOiyfTWCs11ubpzdoNqgJ80zPqWn8fKCPiYb5MSvyqb4wjOGkx7EF3O+Q10EHRhfkpXtiFSbEZwLiNqbrCmf7ES7CGbCMV8hB6sw18iaO/RLeA/5A/W0T93zmTpS0T62qRNGnf51hCWiJY9riQDjlQts0j0KL+X77xzfEJlz7bizPSnTZYitVNwpafsFCtetUIkhwdOpXPATlIBNWf4ScMO4/siuebmk/vt0LoqGNVZpZdb7fAkyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QZrxmedJDL0wM+Pqp12QCnktTs/w8SnpkwyR//p7e1E=; b=DJXOv1CrJ+HyEqML6fAQuzgPHGhteyu3izdSlZxKOCQyeA60FizvaD9AXm7xtwUqOCNdW1uAtXDb4fxhqoCTQODVMOnzm3NOmep7JJqpGvSKL1klqIirb3R8l6PYxKt4lCq/LRwu6W0m3dks6ksi5wR8MNJlv48HkP3UAXphqWZ34PbW3jULvBieYWdh4HEwPbO7yeTOYRgC7YyBB2l4nZicSZ9CLaViJr1aRUfBMeSmh4c6E8slul1k3JtkpGBvWOuAKmtaqcYf2HpgSqvojRoyLKQ966ooswa2L+V+nv8NS66vW9tPHURAc+fNGCww5iPgApWawFzkFtd1XhMkxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QZrxmedJDL0wM+Pqp12QCnktTs/w8SnpkwyR//p7e1E=; b=CxYXWVkPwXQ3rBI/+fziGLHrtS/aNQEBFDqizAoo0+5wUVE/07dr+jzn99hnqVhC1WqiAo3FsfIs2nEWJn9KicIM4oCLFjsUYdsppZkPXqz86vlLLcOHtsCOMmIUES+fLFwwByuPh0SZIpSM0prqLkYBUBo7wHrC9oe5n9aoyrQ= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from SN1PR12MB2352.namprd12.prod.outlook.com (2603:10b6:802:25::13) by SN1PR12MB2495.namprd12.prod.outlook.com (2603:10b6:802:32::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.24; Mon, 15 Jun 2020 18:30:51 +0000 Received: from SN1PR12MB2352.namprd12.prod.outlook.com ([fe80::156e:ce6d:a148:274e]) by SN1PR12MB2352.namprd12.prod.outlook.com ([fe80::156e:ce6d:a148:274e%7]) with mapi id 15.20.3088.025; Mon, 15 Jun 2020 18:30:51 +0000 From: "Kirkendall, Garrett" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Laszlo Ersek Subject: [PATCH v1 2/2] UefiCpuPkg: PiSmmCpuDxeSmm skip MSR_IA32_MISC_ENABLE manipulation on AMD Date: Mon, 15 Jun 2020 13:30:29 -0500 Message-Id: <20200615183029.4577-3-Garrett.Kirkendall@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200615183029.4577-1-Garrett.Kirkendall@amd.com> References: <20200615183029.4577-1-Garrett.Kirkendall@amd.com> X-ClientProxiedBy: SA9PR03CA0020.namprd03.prod.outlook.com (2603:10b6:806:20::25) To SN1PR12MB2352.namprd12.prod.outlook.com (2603:10b6:802:25::13) Return-Path: Garrett.Kirkendall@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from biosdev-01.amd.com (165.204.78.2) by SA9PR03CA0020.namprd03.prod.outlook.com (2603:10b6:806:20::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.27 via Frontend Transport; Mon, 15 Jun 2020 18:30:51 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.78.2] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 55f62374-a785-4050-11b4-08d8115a3b77 X-MS-TrafficTypeDiagnostic: SN1PR12MB2495: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2150; X-Forefront-PRVS: 04359FAD81 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P/5jhf3g6czMb9ow3hBNEG+V2ALUzMEizs/IbfvEby81k8olTjMWK8u4EIH3lOx8Q4PhTH0c+0pR2DrOWZl4WavzJ8xiAM4DHLHHoWMwSGifJFw1mLhvwsq97ecrpfs3nwOA5Bnz2gz++1zI0hQxyQX98IuDKR8NU4+3U97rgwwZgDuKxuE48SKJGfhLIsERK5MEIT9og2UdDDb4WcpPvQN7Z8SNc3LIO7d52cNHNLdY28aZ/1TSdF+5suiCxadLFlheQdLrkK+FHAbAU4Qhv6L77CA8dIw51G3XkuvjxHLC0mXDxziqzUhvsDNN7LIk1DqLZZJMovuGFVShUVh/ew== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN1PR12MB2352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(6029001)(4636009)(39860400002)(396003)(136003)(346002)(376002)(366004)(36756003)(6916009)(19627235002)(478600001)(6666004)(4326008)(83380400001)(8676002)(316002)(8936002)(2616005)(956004)(54906003)(86362001)(66476007)(66556008)(66946007)(1076003)(6486002)(16526019)(7696005)(52116002)(26005)(5660300002)(2906002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7RlXyQsW34JRAbD3TGjzdSppeVr5j3esZMu82sGt8JEM8J+iCptfzXIGEbcQclmOXIvMHCdaY0Gmh9dLegTU6XacDwGw/me7YgqTmR8jAU5Nc7PqL3VywoL5Myn1z40DeBRX6LUq9j0gDqHMxRQ4No+sYqh7hMAkifypP0iWqy265v0A6x9HqYBvxo1VqFjE10+uCT1lpDPnhP/J7XN0QTbSXcxlary11I1i4BFJMxGvpftYbFOc9KEPrvhUixa92Px6mj+dLxbmWZk4XAi7Yy6HIu7C3VYGNYDkasuH2jj8bfsvIowSQ8QREDrEVoG7ixBOCNChPNxJziQiTXbHA/t6cZIv4hEWAJDt+Kwp0vn252RPyEsoEje2I2eUDsngHrirFvkqwypjbTtesTsugQYfCS+uJIQDel6Ca/r9RkZvZ6Stvw6lQHxG8ervlJcV48FXrc/GCLP+p5h6n5y+i3U7sTM7z03ZxQ+1Sjvg+L4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55f62374-a785-4050-11b4-08d8115a3b77 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2020 18:30:51.7122 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ceLpXr/qCuW5ugbj9SzBHO37EIvVpfHeZ7Xlx6TMJ4Il/UpxgfbNvbGmDhSL0tlzi8hXlByKRNtTo3lEB6Cf+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2495 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain AMD does not support MSR_IA32_MISC_ENABLE. Accessing that register causes and exception on AMD processors. If Execution Disable is supported, and if the processor is an AMD processor skip manipulating MSR_IA32_MISC_ENABLE[34] XD Disable bit. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Garrett Kirkendall --- 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(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h b/UefiCpuPkg/Pi= SmmCpuDxeSmm/SmmProfileInternal.h index 43f6935cf9dc..0f6e0c9c98ad 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h @@ -2,6 +2,7 @@ SMM profile internal header file.=0D =0D Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2020, AMD Incorporated. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -13,6 +14,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D #include =0D =0D #include "SmmProfileArch.h"=0D @@ -99,6 +101,7 @@ extern SMM_S3_RESUME_STATE *mSmmS3ResumeState; extern UINTN gSmiExceptionHandlers[];=0D extern BOOLEAN mXdSupported;=0D X86_ASSEMBLY_PATCH_LABEL gPatchXdSupported;=0D +X86_ASSEMBLY_PATCH_LABEL gPatchMsrIA32MiscEnableSupported;=0D extern UINTN *mPFEntryCount;=0D extern UINT64 (*mLastPFEntryValue)[MAX_PF_ENTRY_COUNT];= =0D extern UINT64 *(*mLastPFEntryPointer)[MAX_PF_ENTRY_COUN= T];=0D diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDx= eSmm/SmmProfile.c index c47b5573e366..146600e6c3b4 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c @@ -2,7 +2,7 @@ Enable SMM profile.=0D =0D Copyright (c) 2012 - 2019, Intel Corporation. All rights reserved.
=0D -Copyright (c) 2017, AMD Incorporated. All rights reserved.
=0D +Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -1015,6 +1015,13 @@ CheckFeatureSupported ( mXdSupported =3D FALSE;=0D PatchInstructionX86 (gPatchXdSupported, mXdSupported, 1);=0D }=0D +=0D + if (StandardSignatureIsAuthenticAMD()) {=0D + //=0D + // AMD processors do not support MSR_IA32_MISC_ENABLE=0D + //=0D + PatchInstructionX86 (gPatchMsrIA32MiscEnableSupported, FALSE, 1);=0D + }=0D }=0D =0D if (mBtsSupported) {=0D diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm b/UefiCpuPkg/PiSm= mCpuDxeSmm/Ia32/SmiEntry.nasm index f96de9bdeb43..e4ef5899f274 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.nasm @@ -1,5 +1,6 @@ ;-------------------------------------------------------------------------= ----- ;=0D ; Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
=0D +; Copyright (c) 2020, AMD Incorporated. All rights reserved.
=0D ; SPDX-License-Identifier: BSD-2-Clause-Patent=0D ;=0D ; Module Name:=0D @@ -59,6 +60,7 @@ global ASM_PFX(gPatchSmiStack) global ASM_PFX(gPatchSmbase)=0D extern ASM_PFX(mXdSupported)=0D global ASM_PFX(gPatchXdSupported)=0D +global ASM_PFX(gPatchMsrIA32MiscEnableSupported)=0D extern ASM_PFX(gSmiHandlerIdtr)=0D =0D extern ASM_PFX(mCetSupported)=0D @@ -153,17 +155,30 @@ ASM_PFX(gPatchSmiCr3): ASM_PFX(gPatchXdSupported):=0D cmp al, 0=0D jz @SkipXd=0D +=0D +; Clear XD Disable bit if supported=0D + mov al, strict byte 1 ; source operand may be patched=0D +ASM_PFX(gPatchMsrIA32MiscEnableSupported):=0D + cmp al, 1=0D + jz MsrIA32MiscEnableSupported=0D +=0D +; MSR_IA32_MISC_ENABLE not supported=0D + xor edx, edx=0D + push edx=0D + jmp EnableNxe=0D +=0D ;=0D ; Check XD disable bit=0D ;=0D +MsrIA32MiscEnableSupported:=0D mov ecx, MSR_IA32_MISC_ENABLE=0D rdmsr=0D push edx ; save MSR_IA32_MISC_ENABLE[63-32]= =0D test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]=0D - jz .5=0D + jz EnableNxe=0D and dx, 0xFFFB ; clear XD Disable bit if it is set= =0D wrmsr=0D -.5:=0D +EnableNxe:=0D mov ecx, MSR_EFER=0D rdmsr=0D or ax, MSR_EFER_XD ; enable NXE=0D diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm b/UefiCpuPkg/PiSmm= CpuDxeSmm/X64/SmiEntry.nasm index 8bfba55b5d08..5a4678c7aa63 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.nasm @@ -1,5 +1,6 @@ ;-------------------------------------------------------------------------= ----- ;=0D ; Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
=0D +; Copyright (c) 2020, AMD Incorporated. All rights reserved.
=0D ; SPDX-License-Identifier: BSD-2-Clause-Patent=0D ;=0D ; Module Name:=0D @@ -67,6 +68,7 @@ extern ASM_PFX(CpuSmmDebugExit) global ASM_PFX(gPatchSmbase)=0D extern ASM_PFX(mXdSupported)=0D global ASM_PFX(gPatchXdSupported)=0D +global ASM_PFX(gPatchMsrIA32MiscEnableSupported)=0D global ASM_PFX(gPatchSmiStack)=0D global ASM_PFX(gPatchSmiCr3)=0D global ASM_PFX(gPatch5LevelPagingNeeded)=0D @@ -152,18 +154,32 @@ SkipEnable5LevelPaging: ASM_PFX(gPatchXdSupported):=0D cmp al, 0=0D jz @SkipXd=0D +=0D +; Clear XD Disable bit if supported=0D + mov al, strict byte 1 ; source operand may be patched=0D +ASM_PFX(gPatchMsrIA32MiscEnableSupported):=0D + cmp al, 1=0D + jz MsrIA32MiscEnableSupported=0D +=0D +; MSR_IA32_MISC_ENABLE not supported=0D + sub esp, 4=0D + xor rdx, rdx=0D + push rdx=0D + jmp EnableNxe=0D +=0D ;=0D ; Check XD disable bit=0D ;=0D +MsrIA32MiscEnableSupported:=0D mov ecx, MSR_IA32_MISC_ENABLE=0D rdmsr=0D sub esp, 4=0D push rdx ; save MSR_IA32_MISC_ENABLE[63-32]= =0D test edx, BIT2 ; MSR_IA32_MISC_ENABLE[34]=0D - jz .0=0D + jz EnableNxe=0D and dx, 0xFFFB ; clear XD Disable bit if it is set= =0D wrmsr=0D -.0:=0D +EnableNxe:=0D mov ecx, MSR_EFER=0D rdmsr=0D or ax, MSR_EFER_XD ; enable NXE=0D --=20 2.27.0