eal/x86: check OS support for AVX and AVX512 state
PATCH 1/1 eal/x86: check OS support for AVX and AVX512 state
rte_cpu_get_flag_enabled() reads only the CPUID feature bits. CPUID tells what the CPU implements, not what the OS enables. If the OS does not enable the related state components in XCR0, the first AVX or AVX512 instruction raises #UD.
CPUID can report AVX512 while XCR0 has no AVX512 state. Old kernels without AVX512 state support leave XCR0 at 0x7. A kernel booted with clearcpuid=avx512f removes the AVX512 state from XCR0, but CPUID still reports AVX512F. Similarly, gather_data_sampling=force removes the AVX state.
On such a system, the rte_net_crc constructor selects the AVX512 code from CPUID alone. The dynamic loader runs this constructor before main(), so the application gets SIGILL before EAL can parse any argument.
For the AVX-class and AVX512-class flags, also read XCR0 with XGETBV. Report the flag only when the OS has enabled the related state. Use XGETBV only when CPUID reports OSXSAVE, because the instruction faults otherwise.
This change also affects rte_cpu_is_supported(). If DPDK is built for AVX512 and the OS does not enable AVX512 state, EAL can now stop with an error that names the missing flag. This is possible only if no AVX512 instruction executes before rte_eal_init(), for example in a constructor.
--- lib/eal/include/generic/rte_cpuflags.h | 3 + lib/eal/x86/rte_cpuflags.c | 102 ++++++++++++++++++++----- 2 files changed, 86 insertions(+), 19 deletions(-)
lib/eal/include/generic/rte_cpuflags.h +3 -0
@@ -63,6 +63,9 @@ rte_cpu_get_flag_name(enum rte_cpu_flag_t feature);/** * Function for checking a CPU flag availability * +* A flag is available only if the CPU implements the feature +* and the OS enables the feature for use. +* * @param feature * CPU flag to query CPU for * @return
lib/eal/x86/rte_cpuflags.c +83 -19
168 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 25 lines · Dragos Tarcatu
rte_cpu_get_flag_enabled()reads only the CPUID feature bits. CPUID tells what the CPU implements, not what the OS enables. If the OS does not enable the related state components in XCR0, the first AVX or AVX512 instruction raises #UD.CPUID can report AVX512 while XCR0 has no AVX512 state. Old kernels without AVX512 state support leave XCR0 at
0x7. A kernel booted with clearcpuid=avx512f removes the AVX512 state from XCR0, but CPUID still reports AVX512F. Similarly, gather_data_sampling=force removes the AVX state.On such a system, the
rte_net_crcconstructor selects the AVX512 code from CPUID alone. The dynamic loader runs this constructor beforemain(), so the application gets SIGILL before EAL can parse any argument.For the AVX-class and AVX512-class flags, also read XCR0 with XGETBV. Report the flag only when the OS has enabled the related state. Use XGETBV only when CPUID reports OSXSAVE, because the instruction faults otherwise.
This change also affects
rte_cpu_is_supported(). If DPDK is built for AVX512 and the OS does not enable AVX512 state, EAL can now stop with an error that names the missing flag. This is possible only if no AVX512 instruction executes beforerte_eal_init(), for example in a constructor.
Quoted 8 lines
Fixes 3934bb741354 ("eal/x86: identify AVX512 CPU flag") Cc:Signed-off-by Dragos Tarcatu <[email protected]> ---
lib/eal/include/generic/rte_cpuflags.h| 3 +lib/eal/x86/rte_cpuflags.c
| 102 ++++++++++++++++++++----- 2 files changed, 86 insertions(+), 19 deletions(-)
Tested this using two "x86-generic" builds from test-meson-builds.sh, one with this patch and one without. The test app from the one without the patch gives illegal instruction on an initializer for avx512 crc, while the one with runs successfully.
Code looks correct to me also.
Quoted 34 lines · Bruce Richardson
Quoted 25 lines · Dragos Tarcatu
rte_cpu_get_flag_enabled()reads only the CPUID feature bits. CPUID tells what the CPU implements, not what the OS enables. If the OS does not enable the related state components in XCR0, the first AVX or AVX512 instruction raises #UD.CPUID can report AVX512 while XCR0 has no AVX512 state. Old kernels without AVX512 state support leave XCR0 at
0x7. A kernel booted with clearcpuid=avx512f removes the AVX512 state from XCR0, but CPUID still reports AVX512F. Similarly, gather_data_sampling=force removes the AVX state.On such a system, the
rte_net_crcconstructor selects the AVX512 code from CPUID alone. The dynamic loader runs this constructor beforemain(), so the application gets SIGILL before EAL can parse any argument.For the AVX-class and AVX512-class flags, also read XCR0 with XGETBV. Report the flag only when the OS has enabled the related state. Use XGETBV only when CPUID reports OSXSAVE, because the instruction faults otherwise.
This change also affects
rte_cpu_is_supported(). If DPDK is built for AVX512 and the OS does not enable AVX512 state, EAL can now stop with an error that names the missing flag. This is possible only if no AVX512 instruction executes beforerte_eal_init(), for example in a constructor.Quoted 8 lines
Fixes 3934bb741354 ("eal/x86: identify AVX512 CPU flag") Cc:Signed-off-by Dragos Tarcatu <[email protected]> ---
lib/eal/include/generic/rte_cpuflags.h| 3 +lib/eal/x86/rte_cpuflags.c
| 102 ++++++++++++++++++++----- 2 files changed, 86 insertions(+), 19 deletions(-)
Quoted 4 lines
Tested this using two "x86-generic" builds from
test-meson-builds.sh, one with this patch and one without. The test app from the one without the patch gives illegal instruction on an initializer for avx512 crc, while the one with runs successfully.
Just for clarification, the test was run on a system where I'd passed clearcpuid=avx512f to the kernel (as described above in the commit log message).
Quoted 6 lines
Code looks correct to me also.
Tested-by Bruce Richardson <[email protected]>Acked-by Bruce Richardson <[email protected]>
David Marchand
AppliedQuoted 27 lines · Bruce Richardson
Quoted 25 lines · Dragos Tarcatu
rte_cpu_get_flag_enabled()reads only the CPUID feature bits. CPUID tells what the CPU implements, not what the OS enables. If the OS does not enable the related state components in XCR0, the first AVX or AVX512 instruction raises #UD.CPUID can report AVX512 while XCR0 has no AVX512 state. Old kernels without AVX512 state support leave XCR0 at
0x7. A kernel booted with clearcpuid=avx512f removes the AVX512 state from XCR0, but CPUID still reports AVX512F. Similarly, gather_data_sampling=force removes the AVX state.On such a system, the
rte_net_crcconstructor selects the AVX512 code from CPUID alone. The dynamic loader runs this constructor beforemain(), so the application gets SIGILL before EAL can parse any argument.For the AVX-class and AVX512-class flags, also read XCR0 with XGETBV. Report the flag only when the OS has enabled the related state. Use XGETBV only when CPUID reports OSXSAVE, because the instruction faults otherwise.
This change also affects
rte_cpu_is_supported(). If DPDK is built for AVX512 and the OS does not enable AVX512 state, EAL can now stop with an error that names the missing flag. This is possible only if no AVX512 instruction executes beforerte_eal_init(), for example in a constructor.
Quoted 6 lines
Quoted 4 lines
Fixes 3934bb741354 ("eal/x86: identify AVX512 CPU flag") Cc:Signed-off-by Dragos Tarcatu <[email protected]> ---Tested-by Bruce Richardson <[email protected]>Acked-by Bruce Richardson <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand