Linux 5.1 Getting A Minor Spectre V2 Retpolines Optimization For Select Instances
As the latest on the Spectre/Meltdown front for the Linux kernel, the in-development Linux 5.1 kernel is bringing an optimization for Retpolines "return trampolines" so GCC will generate more efficient code on x86/x86_64 in its mitigations against Spectre Variant Two.
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.
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.
20 Comments