Skip to content

Commit 3496d1c

Browse files
Peter Zijlstrabp3tk0v
authored andcommitted
x86/nospec: Shorten RESET_CALL_DEPTH
RESET_CALL_DEPTH is a pretty fat monster and blows up UNTRAIN_RET to 20 bytes: 19: 48 c7 c0 80 00 00 00 mov $0x80,%rax 20: 48 c1 e0 38 shl $0x38,%rax 24: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0 29: R_X86_64_32S pcpu_hot+0x10 Shrink it by 4 bytes: 0: 31 c0 xor %eax,%eax 2: 48 0f ba e8 3f bts $0x3f,%rax 7: 65 48 89 04 25 00 00 00 00 mov %rax,%gs:0x0 Shrink RESET_CALL_DEPTH_FROM_CALL by 5 bytes by only setting %al, the other bits are shifted out (the same could be done for RESET_CALL_DEPTH, but the XOR+BTS sequence has less dependencies due to the zeroing). Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230515093020.729622326@infradead.org
1 parent df25edb commit 3496d1c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/x86/include/asm/nospec-branch.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
movq $-1, PER_CPU_VAR(pcpu_hot + X86_call_depth);
8585

8686
#define RESET_CALL_DEPTH \
87-
mov $0x80, %rax; \
88-
shl $56, %rax; \
87+
xor %eax, %eax; \
88+
bts $63, %rax; \
8989
movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth);
9090

9191
#define RESET_CALL_DEPTH_FROM_CALL \
92-
mov $0xfc, %rax; \
92+
movb $0xfc, %al; \
9393
shl $56, %rax; \
9494
movq %rax, PER_CPU_VAR(pcpu_hot + X86_call_depth); \
9595
CALL_THUNKS_DEBUG_INC_CALLS

0 commit comments

Comments
 (0)