amd64: move fusufault after all users

A lot of function have the following check:
        cmpq    %rax,%rdi                       /* verify address is valid */
        ja      fusufault

The label is present earlier in kernel .text, which means this is a jump
backwards. Absent any information in branch predictor, the cpu predicts it
as taken. Since it is almost never taken in practice, this results in a
completely avoidable misprediction.

Move it past all consumers, so that it is predicted as not taken.

Approved by:	re (kib)
This commit is contained in:
Mateusz Guzik 2018-09-20 13:29:43 +00:00
parent 482a81508c
commit a286a3099c

View File

@ -755,16 +755,6 @@ ENTRY(fubyte_smap)
ret
END(fubyte_smap)
ALIGN_TEXT
/* Fault entry clears PSL.AC */
fusufault:
movq PCPU(CURPCB),%rcx
xorl %eax,%eax
movq %rax,PCB_ONFAULT(%rcx)
decq %rax
POP_FRAME_POINTER
ret
/*
* Store a 64-bit word, a 32-bit word, a 16-bit word, or an 8-bit byte to
* user memory.
@ -916,6 +906,16 @@ ENTRY(subyte_smap)
ret
END(subyte_smap)
ALIGN_TEXT
/* Fault entry clears PSL.AC */
fusufault:
movq PCPU(CURPCB),%rcx
xorl %eax,%eax
movq %rax,PCB_ONFAULT(%rcx)
decq %rax
POP_FRAME_POINTER
ret
/*
* copyinstr(from, to, maxlen, int *lencopied)
* %rdi, %rsi, %rdx, %rcx