Page MenuHomeFreeBSD

fix: efirt: use compiler ms_abi for EFI runtime calls on amd64
Needs ReviewPublic

Authored by guest-seuros on Wed, Mar 4, 10:37 PM.
Tags
None
Referenced Files
F146772733: D55662.diff
Thu, Mar 5, 11:39 AM
F146769911: D55662.id.diff
Thu, Mar 5, 11:05 AM
F146767351: D55662.id173157.diff
Thu, Mar 5, 10:31 AM
F146754375: D55662.id173157.diff
Thu, Mar 5, 7:52 AM
Subscribers

Details

Summary

The assembly trampoline in efi_rt_arch_call had a stack alignment bug for 5-argument EFI calls (GetVariable, SetVariable):

it computed max(N,4)*8 = 40 bytes of stack space, leaving RSP 8-byte aligned instead of the 16 required by the MS x64 ABI.

Firmware compiled with SSE (for example coreboot/EDK2) uses MOVAPS for callee-saved XMM register spills, causing #GP on every GetVariable/SetVariable call.

Replaced the assembly ABI conversion with efi_rt_dispatch(). The assembly trampoline is kept only for fault recovery, delegating the actual call to the C function.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 71188
Build 68071: arc lint + arc unit

Event Timeline

guest-seuros held this revision as a draft.

Could you try the patch below instead?

diff --git a/sys/amd64/amd64/efirt_support.S b/sys/amd64/amd64/efirt_support.S
index 98063ad561aa..54578f573750 100644
--- a/sys/amd64/amd64/efirt_support.S
+++ b/sys/amd64/amd64/efirt_support.S
@@ -58,6 +58,7 @@ ENTRY(efi_rt_arch_call)
 	cmovbl	%eax, %ecx
 	shll	$3, %ecx
 	subq	%rcx, %rsp
+	andq	$~0xf, %rsp
 
 	cmpl	$0, %ebx
 	jz	1f