x86: Check if CPUID_INDEX_7_ECX_1 is supported first
Checks
| Context |
Check |
Description |
| redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
| linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
| redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
Commit Message
Since bits 31 - 00 in EAX from CPUID with EAX == 7 and ECX == 0 reports
the maximum input value for supported leaf 7 sub-leaves for CPUID with
EAX == 7, check it before invoking CPUID with EAX == 7 and ECX == 1.
This fixes BZ #34565.
Comments
* H. J. Lu:
> diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
> index a453136827..0db33e0f35 100644
> --- a/sysdeps/x86/cpu-features.c
> +++ b/sysdeps/x86/cpu-features.c
> @@ -458,11 +458,13 @@ get_common_indices (struct cpu_features *cpu_features,
> cpu_features->features[CPUID_INDEX_7].cpuid.ebx,
> cpu_features->features[CPUID_INDEX_7].cpuid.ecx,
> cpu_features->features[CPUID_INDEX_7].cpuid.edx);
> - __cpuid_count (7, 1,
> - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.eax,
> - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ebx,
> - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ecx,
> - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.edx);
> + if (cpu_features->features[CPUID_INDEX_7].cpuid.eax != 0)
> + __cpuid_count
> + (7, 1,
> + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.eax,
> + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ebx,
> + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ecx,
> + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.edx);
> }
>
> if (cpu_features->basic.max_cpuid >= 0xd)
If subleaf 1 is not support, should we zero the fields?
Thanks,
Florian
On Tue, Aug 25, 2026 at 2:36 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
> > index a453136827..0db33e0f35 100644
> > --- a/sysdeps/x86/cpu-features.c
> > +++ b/sysdeps/x86/cpu-features.c
> > @@ -458,11 +458,13 @@ get_common_indices (struct cpu_features *cpu_features,
> > cpu_features->features[CPUID_INDEX_7].cpuid.ebx,
> > cpu_features->features[CPUID_INDEX_7].cpuid.ecx,
> > cpu_features->features[CPUID_INDEX_7].cpuid.edx);
> > - __cpuid_count (7, 1,
> > - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.eax,
> > - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ebx,
> > - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ecx,
> > - cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.edx);
> > + if (cpu_features->features[CPUID_INDEX_7].cpuid.eax != 0)
> > + __cpuid_count
> > + (7, 1,
> > + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.eax,
> > + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ebx,
> > + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ecx,
> > + cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.edx);
> > }
> >
> > if (cpu_features->basic.max_cpuid >= 0xd)
>
> If subleaf 1 is not support, should we zero the fields?
>
_rtld_global_ro._dl_x86_cpu_features is initialized to 0.
From 7f5f1bdc7fd97d165d1c41d7a83c426f4423cd1b Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 25 Aug 2026 09:43:26 +0800
Subject: [PATCH] x86: Check if CPUID_INDEX_7_ECX_1 is supported first
Since bits 31 - 00 in EAX from CPUID with EAX == 7 and ECX == 0 reports
the maximum input value for supported leaf 7 sub-leaves for CPUID with
EAX == 7, check it before invoking CPUID with EAX == 7 and ECX == 1.
This fixes BZ #34565.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
sysdeps/x86/cpu-features.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
@@ -458,11 +458,13 @@ get_common_indices (struct cpu_features *cpu_features,
cpu_features->features[CPUID_INDEX_7].cpuid.ebx,
cpu_features->features[CPUID_INDEX_7].cpuid.ecx,
cpu_features->features[CPUID_INDEX_7].cpuid.edx);
- __cpuid_count (7, 1,
- cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.eax,
- cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ebx,
- cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ecx,
- cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.edx);
+ if (cpu_features->features[CPUID_INDEX_7].cpuid.eax != 0)
+ __cpuid_count
+ (7, 1,
+ cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.eax,
+ cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ebx,
+ cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.ecx,
+ cpu_features->features[CPUID_INDEX_7_ECX_1].cpuid.edx);
}
if (cpu_features->basic.max_cpuid >= 0xd)
--
2.55.0