libgcc: Enable AArch64 SVE2 features only if SVE is enabled [PR126935]

Message ID PAXPR08MB6782AF810F529C5750959D9183692@PAXPR08MB6782.eurprd08.prod.outlook.com
State Accepted
Delegated to: Kyrill Tkachov
Headers
Series libgcc: Enable AArch64 SVE2 features only if SVE is enabled [PR126935] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed

Commit Message

Wilco Dijkstra Nov. 3, 2026, 2:56 p.m. UTC
  Linux kernels before 6.12 may set SVE2 features without SVE in some cases.
Clear affected SVE2 features if SVE is not enabled.

Passes regress, OK for commit?

libgcc:

	* config/aarch64/cpuinfo.c (__init_cpu_features_constructor):
	Clear SVE2 features if SVE is not enabled.

---
  

Comments

Tamar Christina Nov. 3, 2026, 7:31 p.m. UTC | #1
> -----Original Message-----
> From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
> Sent: 03 November 2026 14:56
> To: gcc-patches mailing list <gcc-patches@gcc.gnu.org>
> Cc: Kyrylo Tkachov <ktkachov@nvidia.com>; Alex Coplan
> <Alex.Coplan@arm.com>; Alice Carlotti <Alice.Carlotti@arm.com>; Tamar
> Christina <Tamar.Christina@arm.com>; Richard Earnshaw
> <Richard.Earnshaw@arm.com>; Andrea Pinski
> <andrew.pinski@oss.qualcomm.com>
> Subject: libgcc: Enable AArch64 SVE2 features only if SVE is enabled
> [PR126935]
> 
> 
> Linux kernels before 6.12 may set SVE2 features without SVE in some cases.
> Clear affected SVE2 features if SVE is not enabled.
> 
> Passes regress, OK for commit?

OK.

Thanks,
Tamar.

> 
> libgcc:
> 
> 	* config/aarch64/cpuinfo.c (__init_cpu_features_constructor):
> 	Clear SVE2 features if SVE is not enabled.
> 
> ---
> 
> diff --git a/libgcc/config/aarch64/cpuinfo.c b/libgcc/config/aarch64/cpuinfo.c
> index
> 93d9491f7a488e7da890d9f3f942e1c5cc4bf834..fbc8ea01bc678709d1881
> 2f1810895d53f279a14 100644
> --- a/libgcc/config/aarch64/cpuinfo.c
> +++ b/libgcc/config/aarch64/cpuinfo.c
> @@ -124,6 +124,14 @@ __init_cpu_features_constructor (unsigned long
> hwcap,
>    unsigned long hwcap4 __attribute__ ((unused)) = 0;
>    if ((hwcap & _IFUNC_ARG_HWCAP) && arg->_size >=
> __IFUNC_ARG_SIZE_HWCAP4)
>      hwcap4 = arg->_hwcap4;
> +
> +  /* Kernels before 6.12 may set some SVE2 features without SVE
> (PR126935).
> +     Workaround this by clearing such features if SVE is not enabled.  */
> +  if (!(hwcap & HWCAP_SVE))
> +    hwcap2 &= ~(HWCAP2_SVE2 | HWCAP2_SVEPMULL |
> HWCAP2_SVEBITPERM
> +		| HWCAP2_SVESHA3 | HWCAP2_SVESM4 |
> HWCAP2_SVEF32MM
> +		| HWCAP2_SVEF64MM);
> +
>    if (hwcap & HWCAP_CRC32)
>      setCPUFeature(FEAT_CRC);
>    if (hwcap & HWCAP_PMULL)
  

Patch

diff --git a/libgcc/config/aarch64/cpuinfo.c b/libgcc/config/aarch64/cpuinfo.c
index 93d9491f7a488e7da890d9f3f942e1c5cc4bf834..fbc8ea01bc678709d18812f1810895d53f279a14 100644
--- a/libgcc/config/aarch64/cpuinfo.c
+++ b/libgcc/config/aarch64/cpuinfo.c
@@ -124,6 +124,14 @@  __init_cpu_features_constructor (unsigned long hwcap,
   unsigned long hwcap4 __attribute__ ((unused)) = 0;
   if ((hwcap & _IFUNC_ARG_HWCAP) && arg->_size >= __IFUNC_ARG_SIZE_HWCAP4)
     hwcap4 = arg->_hwcap4;
+
+  /* Kernels before 6.12 may set some SVE2 features without SVE (PR126935).
+     Workaround this by clearing such features if SVE is not enabled.  */
+  if (!(hwcap & HWCAP_SVE))
+    hwcap2 &= ~(HWCAP2_SVE2 | HWCAP2_SVEPMULL | HWCAP2_SVEBITPERM
+		| HWCAP2_SVESHA3 | HWCAP2_SVESM4 | HWCAP2_SVEF32MM
+		| HWCAP2_SVEF64MM);
+
   if (hwcap & HWCAP_CRC32)
     setCPUFeature(FEAT_CRC);
   if (hwcap & HWCAP_PMULL)