Skip to content

Commit 8c00682

Browse files
kuqin12apop5
authored andcommitted
QemuQ35Pkg: Disable paging at SMM init entry and re-enable once it is done.
System would hang in debug builds on attempting SmmRelocation from QemuQ35Pkg's PlatformPei. INFO - PlatformPei: OnMpServices2Available INFO - SmmRelocationInit Start INFO - SmmRelocationInit - SmmRelocationSize: 0x0000A000 INFO - SmmRelocationInit - SmmRelocationStart: 0x7F000000 INFO - SmmRelocationInit - SmmStackSize: 0x00001000 INFO - SmmRelocationInit - SmmStacks: 0x7EAF6000 Paging was enabled, and as best we can tell, when attempting to init the AP's, a page fault would be triggered and hang the system. Follow the MpInitLib's implementation of disabling Paging during the Ap Smm relocation to prevent triggering of page faults and hanging the system.
1 parent 28684b0 commit 8c00682

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Platforms/QemuQ35Pkg/Library/SmmRelocationLib/Ia32/SmmInit.nasm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ global ASM_PFX(SmmStartup)
9494

9595
BITS 16
9696
ASM_PFX(SmmStartup):
97+
mov eax, strict dword 0 ; source operand will be patched
98+
ASM_PFX(gPatchSmmInitCr0):
99+
btr eax, 31 ; Clear CR0.PG
100+
mov cr0, eax
97101
mov eax, 0x80000001 ; read capability
98102
cpuid
99103
mov ebx, edx ; rdmsr will change edx. keep it in ebx.
@@ -106,14 +110,11 @@ o32 lgdt [cs:ebp + (ASM_PFX(gcSmmInitGdtr) - ASM_PFX(SmmStartup))]
106110
mov eax, strict dword 0 ; source operand will be patched
107111
ASM_PFX(gPatchSmmInitCr4):
108112
mov cr4, eax
109-
mov ecx, 0xc0000080 ; IA32_EFER MSR
110-
rdmsr
111-
or eax, ebx ; set NXE bit if NX is available
112-
wrmsr
113-
mov eax, strict dword 0 ; source operand will be patched
114-
ASM_PFX(gPatchSmmInitCr0):
113+
; mov ecx, 0xc0000080 ; IA32_EFER MSR
114+
; rdmsr
115+
; or eax, ebx ; set NXE bit if NX is available
116+
; wrmsr
115117
mov di, PROTECT_MODE_DS
116-
mov cr0, eax
117118
jmp PROTECT_MODE_CS : dword @32bit
118119

119120
BITS 32
@@ -125,6 +126,9 @@ BITS 32
125126
mov ss, edi
126127
mov esp, strict dword 0 ; source operand will be patched
127128
ASM_PFX(gPatchSmmInitStack):
129+
mov eax, cr0
130+
bts eax, 31
131+
mov cr0, eax
128132
call ASM_PFX(SmmInitHandler)
129133
StuffRsb32
130134
rsm

Platforms/QemuQ35Pkg/Library/SmmRelocationLib/SmmRelocationLib.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ SmmRelocateBases (
206206
//
207207
CopyMem (U8Ptr, gcSmmInitTemplate, gcSmmInitSize);
208208

209+
// RemoveNxProtection ((EFI_PHYSICAL_ADDRESS)((UINTN)SmmStartup & ~(EFI_PAGE_SIZE - 1)), EFI_PAGE_SIZE * 2);
210+
209211
//
210212
// Retrieve the local APIC ID of current processor
211213
//

0 commit comments

Comments
 (0)