Currently, the AArch64 implementation of LongJump() avoids using the RET
instruction to perform the jump, even though the target address is held
in the link register X30, as the nature of a long jump implies that the
ordinary return address prediction machinery will not be able to make a
correct prediction.

However, LongJump() is rarely used, and the return stack will be out of
sync in any case, so this optimization has little value in practice, and
given that indirect calls other than function returns require a BTI
landing pad at the call site, this optimization is not compatible with
BTI. So let's just use RET instead.

Signed-off-by: Ard Biesheuvel <a...@kernel.org>
---
 MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S 
b/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S
index deefdf526b95ca93..1d5cfbf64470452f 100644
--- a/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S
+++ b/MdePkg/Library/BaseLib/AArch64/SetJumpLongJump.S
@@ -85,7 +85,6 @@ ASM_PFX(InternalLongJump):
         cmp     w1, #0
         mov     w0, #1
         csel    w0, w1, w0, ne
-        // use br not ret, as ret is guaranteed to mispredict
-        br      x30
+        ret
 
 ASM_FUNCTION_REMOVE_IF_UNREFERENCED
-- 
2.39.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101928): https://edk2.groups.io/g/devel/message/101928
Mute This Topic: https://groups.io/mt/97879285/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to