Linux 5.1 Getting A Minor Spectre V2 Retpolines Optimization For Select Instances
The x86/build updates for Linux 5.1 brings a change to raise the limit for generating indirect calls from switch cases.
The actual commit explains, "Recent work on XDP from Björn and Magnus additionally found that manually transforming the XDP return code switch statement with more than 5 cases into if-else combination would result in a considerable speedup in XDP layer due to avoidance of indirect calls in CONFIG_RETPOLINE enabled builds. On i40e driver with XDP prog attached, a 20-26% speedup has been observed."
With the newest Linux Git code, the CFLAGS specifies a threshold of 20 now rather than 4~5 to avoid generating these expensive indirect jumps subject to Retpolines. This is only relevant on x86/x86_64 and when using the GCC compiler with the Linux kernel but in select switch cases should help in generating faster code.