[edk2-devel] [PATCH v2 05/17] MdePkg/BaseLib AARCH64: Make asm files BTI compatible

Ard Biesheuvel posted 17 patches 1 year, 6 months ago
There is a newer version of this series
[edk2-devel] [PATCH v2 05/17] MdePkg/BaseLib AARCH64: Make asm files BTI compatible
Posted by Ard Biesheuvel 1 year, 6 months ago
Add the BTI instructions and the associated note to make the AArch64 asm
objects compatible with BTI enforcement.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S      | 1 +
 MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S  | 1 +
 MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S   | 1 +
 MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S | 1 +
 MdePkg/Library/BaseLib/AArch64/MemoryFence.S        | 1 +
 MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S    | 2 ++
 MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S | 1 +
 MdePkg/Library/BaseLib/AArch64/SwitchStack.S        | 2 ++
 8 files changed, 10 insertions(+)

diff --git a/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S b/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S
index 7524fb18820c2fa3..24a1ac371884bb1d 100644
--- a/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S
+++ b/MdePkg/Library/BaseLib/AArch64/CpuBreakpoint.S
@@ -27,5 +27,6 @@ GCC_ASM_EXPORT(CpuBreakpoint)
 #  );
 #
 ASM_PFX(CpuBreakpoint):
+    AARCH64_BTI(c)
     svc   0xdbdb    // Superviser exception. Takes 16bit arg -> Armv7 had 'swi' here.
     ret
diff --git a/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S b/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S
index f0faf16b06a3fcae..3f562461614ad294 100644
--- a/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S
+++ b/MdePkg/Library/BaseLib/AArch64/DisableInterrupts.S
@@ -26,5 +26,6 @@ GCC_ASM_EXPORT(DisableInterrupts)
 #  );
 #
 ASM_PFX(DisableInterrupts):
+   AARCH64_BTI(c)
    msr  daifset, #DAIF_WR_IRQ_BIT
    ret
diff --git a/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S b/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S
index 97eeb13fbe5d2145..0f1377f51c7e88f7 100644
--- a/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S
+++ b/MdePkg/Library/BaseLib/AArch64/EnableInterrupts.S
@@ -26,5 +26,6 @@ GCC_ASM_EXPORT(EnableInterrupts)
 #  );
 #
 ASM_PFX(EnableInterrupts):
+    AARCH64_BTI(c)
     msr  daifclr, #DAIF_WR_IRQ_BIT
     ret
diff --git a/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S b/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S
index bf8b829bb2b1749d..26787a5b9bddcd7e 100644
--- a/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S
+++ b/MdePkg/Library/BaseLib/AArch64/GetInterruptsState.S
@@ -33,6 +33,7 @@ GCC_ASM_EXPORT(GetInterruptState)
 # );
 #
 ASM_PFX(GetInterruptState):
+    AARCH64_BTI(c)
     mrs    x0, daif
     tst    x0, #DAIF_RD_IRQ_BIT   // Check IRQ mask; set Z=1 if clear/unmasked
     cset   w0, eq                 // if Z=1 (eq) return 1, else 0
diff --git a/MdePkg/Library/BaseLib/AArch64/MemoryFence.S b/MdePkg/Library/BaseLib/AArch64/MemoryFence.S
index e553bd2dc9fcf63f..ad5b92a9a72bd65c 100644
--- a/MdePkg/Library/BaseLib/AArch64/MemoryFence.S
+++ b/MdePkg/Library/BaseLib/AArch64/MemoryFence.S
@@ -28,6 +28,7 @@ GCC_ASM_EXPORT(MemoryFence)
 #  );
 #
 ASM_PFX(MemoryFence):
+    AARCH64_BTI(c)
     // System wide Data Memory Barrier.
     dmb sy
     ret
diff --git a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S b/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S
index 1d5cfbf64470452f..0d902d94d31c4a35 100644
--- a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S
+++ b/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S
@@ -46,6 +46,7 @@ GCC_ASM_EXPORT(InternalLongJump)
 #  );
 #
 ASM_PFX(SetJump):
+        AARCH64_BTI(c)
         mov     x16, sp // use IP0 so save SP
 #define REG_PAIR(REG1, REG2, OFFS)      stp REG1, REG2, [x0, OFFS]
 #define REG_ONE(REG1, OFFS)             str REG1, [x0, OFFS]
@@ -75,6 +76,7 @@ ASM_PFX(SetJump):
 #  );
 #
 ASM_PFX(InternalLongJump):
+        AARCH64_BTI(c)
 #define REG_PAIR(REG1, REG2, OFFS)      ldp REG1, REG2, [x0, OFFS]
 #define REG_ONE(REG1, OFFS)             ldr REG1, [x0, OFFS]
         GPR_LAYOUT
diff --git a/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S b/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S
index a20d6aed0cdd5284..248ee01e52c27367 100644
--- a/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S
+++ b/MdePkg/Library/BaseLib/AArch64/SpeculationBarrier.S
@@ -28,6 +28,7 @@ GCC_ASM_EXPORT(SpeculationBarrier)
 #  );
 #
 ASM_PFX(SpeculationBarrier):
+    AARCH64_BTI(c)
     dsb  sy
     isb
     ret
diff --git a/MdePkg/Library/BaseLib/AArch64/SwitchStack.S b/MdePkg/Library/BaseLib/AArch64/SwitchStack.S
index f3bce6a09bc2d555..837c65b45e73024e 100644
--- a/MdePkg/Library/BaseLib/AArch64/SwitchStack.S
+++ b/MdePkg/Library/BaseLib/AArch64/SwitchStack.S
@@ -35,6 +35,7 @@ GCC_ASM_EXPORT(CpuPause)
 #  );
 #
 ASM_PFX(InternalSwitchStackAsm):
+    AARCH64_BTI(c)
     mov   x29, #0
     mov   x30, x0
     mov   sp, x3
@@ -57,6 +58,7 @@ ASM_PFX(InternalSwitchStackAsm):
 #  )
 #
 ASM_PFX(CpuPause):
+    AARCH64_BTI(c)
     nop
     nop
     nop
-- 
2.39.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101929): https://edk2.groups.io/g/devel/message/101929
Mute This Topic: https://groups.io/mt/97879286/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-