Improved Retpoline Code Staged Ahead Of Linux 5.16
These Linux Retpoline patches are the work covered earlier this month on Phoronix around rewriting the Retpoline rewrite code.
The new code ensures that the Retpolines are rewritten to indirect instructions for cases where Retpoline is not enable, and rewriting to indirect LFENCE for the AMD Retpoline handling where size allows by the compiler. The x86 BPF code is also updated to match the behavior of the rest of the kernel around Retpolines -- previously the BPF code wasn't checking the X86_FEATURE_RETPOLINE flags but unconditionally emitting a thunk call. With the rewritten code it also makes running with the "spectre_v2=off" boot option closer to the kernel image if building the kernel without the RETPOLINE Kconfig option enabled. The exciting part is a possible (small) performance improvement by removing an indirection from the code.
The set of Retpoline improvement patches as of yesterday are now in TIP's objtool/core ahead of the Linux 5.16 merge window.