From a286a3099c87bf015063bac0f10cec70b261fac7 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 20 Sep 2018 13:29:43 +0000 Subject: [PATCH] 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) --- sys/amd64/amd64/support.S | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index bc849b21d96..33ffec1ff5f 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -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