Re: The killing of ideal_nops[]

From: Peter Zijlstra
Date: Wed Mar 10 2021 - 05:23:55 EST


On Wed, Mar 10, 2021 at 11:03:10AM +0100, Peter Zijlstra wrote:
> -void __init arch_init_ideal_nops(void)
> -{
> - switch (boot_cpu_data.x86_vendor) {
> - case X86_VENDOR_INTEL:
> - /*
> - * Due to a decoder implementation quirk, some
> - * specific Intel CPUs actually perform better with
> - * the "k8_nops" than with the SDM-recommended NOPs.
> - */
> - if (boot_cpu_data.x86 == 6 &&
> - boot_cpu_data.x86_model >= 0x0f &&
> - boot_cpu_data.x86_model != 0x1c &&
> - boot_cpu_data.x86_model != 0x26 &&
> - boot_cpu_data.x86_model != 0x27 &&
> - boot_cpu_data.x86_model < 0x30) {
> - ideal_nops = k8_nops;
> - } else if (boot_cpu_has(X86_FEATURE_NOPL)) {
> - ideal_nops = p6_nops;
> - } else {
> -#ifdef CONFIG_X86_64
> - ideal_nops = k8_nops;
> -#else
> - ideal_nops = intel_nops;
> -#endif
> - }
> - break;
> -
> - case X86_VENDOR_HYGON:
> - ideal_nops = p6_nops;
> - return;
> -
> - case X86_VENDOR_AMD:
> - if (boot_cpu_data.x86 > 0xf) {
> - ideal_nops = p6_nops;
> - return;
> - }
> -
> - fallthrough;
> -
> - default:
> -#ifdef CONFIG_X86_64
> - ideal_nops = k8_nops;
> -#else
> - if (boot_cpu_has(X86_FEATURE_K8))
> - ideal_nops = k8_nops;
> - else if (boot_cpu_has(X86_FEATURE_K7))
> - ideal_nops = k7_nops;
> - else
> - ideal_nops = intel_nops;
> -#endif
> - }
> -}

After this FEATURE_NOPL is unused except for required-features for
x86_64. FEATURE_K8 is only used for PTI and FEATURE_K7 is unused.

AFAICT this negatively affects lots of 32bit (DONTCARE) and 32bit on
64bit CPUs (CARELESS) and early AMD (K8) which is from 2003 and almost
2 decades old by now (SHRUG).

Everything x86_64 since AMD K10 (2007) was using p6_nops.

And per FEATURE_NOPL being required for x86_64, all those CPUs can use
p6_nops. So stop caring about NOPs, simplify things and get on with life
:-)