x86: Populate COMMON_CPUID_INDEX_80000001 for Intel CPUs [BZ #23459]

Message ID 20180726180747.15087-1-hjl.tools@gmail.com
State New, archived
Headers

Commit Message

H.J. Lu July 26, 2018, 6:07 p.m. UTC
  [BZ #23459]
	* sysdeps/x86/cpu-features.c (get_extended_indeces): New
	function.
	(init_cpu_features): Call get_extended_indeces for both Intel
	and AMD CPUs.
---
 sysdeps/x86/cpu-features.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
  

Comments

H.J. Lu July 26, 2018, 6:48 p.m. UTC | #1
On Thu, Jul 26, 2018 at 11:07 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>         [BZ #23459]
>         * sysdeps/x86/cpu-features.c (get_extended_indeces): New
>         function.
>         (init_cpu_features): Call get_extended_indeces for both Intel
>         and AMD CPUs.
> ---
>  sysdeps/x86/cpu-features.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
> index 8108256c42..f8beb96e51 100644
> --- a/sysdeps/x86/cpu-features.c
> +++ b/sysdeps/x86/cpu-features.c
> @@ -42,6 +42,20 @@ extern void TUNABLE_CALLBACK (set_x86_shstk) (tunable_val_t *)
>  # include <cet-tunables.h>
>  #endif
>
> +static void
> +get_extended_indeces (struct cpu_features *cpu_features)
> +{
> +  unsigned int eax, ebx, ecx, edx;
> +  __cpuid (0x80000000, eax, ebx, ecx, edx);
> +  if (eax >= 0x80000001)
> +    __cpuid (0x80000001,
> +            cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
> +            cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
> +            cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
> +            cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
> +
> +}
> +
>  static void
>  get_common_indeces (struct cpu_features *cpu_features,
>                     unsigned int *family, unsigned int *model,
> @@ -224,6 +238,8 @@ init_cpu_features (struct cpu_features *cpu_features)
>        get_common_indeces (cpu_features, &family, &model, &extended_model,
>                           &stepping);
>
> +      get_extended_indeces (cpu_features);
> +
>        if (family == 0x06)
>         {
>           model += extended_model;
> @@ -338,16 +354,9 @@ init_cpu_features (struct cpu_features *cpu_features)
>        get_common_indeces (cpu_features, &family, &model, &extended_model,
>                           &stepping);
>
> -      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
> +      get_extended_indeces (cpu_features);
>
> -      unsigned int eax;
> -      __cpuid (0x80000000, eax, ebx, ecx, edx);
> -      if (eax >= 0x80000001)
> -       __cpuid (0x80000001,
> -                cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
> -                cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
> -                cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
> -                cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
> +      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
>
>        if (HAS_ARCH_FEATURE (AVX_Usable))
>         {
> --
> 2.17.1
>

enum
  {
    COMMON_CPUID_INDEX_1 = 0,
    COMMON_CPUID_INDEX_7,
    COMMON_CPUID_INDEX_80000001,        /* for AMD */

 ^^^^^^^^^^^^  This should also be removed.
    /* Keep the following line at the end.  */
    COMMON_CPUID_INDEX_MAX
  };
  
Carlos O'Donell July 26, 2018, 8:05 p.m. UTC | #2
On 07/26/2018 02:07 PM, H.J. Lu wrote:
> 	[BZ #23459]
> 	* sysdeps/x86/cpu-features.c (get_extended_indeces): New
> 	function.
> 	(init_cpu_features): Call get_extended_indeces for both Intel
> 	and AMD CPUs.
> ---

OK for 2.28 after you fix the indexes v.s indices issue.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

>  sysdeps/x86/cpu-features.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
> index 8108256c42..f8beb96e51 100644
> --- a/sysdeps/x86/cpu-features.c
> +++ b/sysdeps/x86/cpu-features.c
> @@ -42,6 +42,20 @@ extern void TUNABLE_CALLBACK (set_x86_shstk) (tunable_val_t *)
>  # include <cet-tunables.h>
>  #endif
>  
> +static void
> +get_extended_indeces (struct cpu_features *cpu_features)

get_extended_indices

or

get_extended_indexes

Your choice.

> +{
> +  unsigned int eax, ebx, ecx, edx;
> +  __cpuid (0x80000000, eax, ebx, ecx, edx);
> +  if (eax >= 0x80000001)
> +    __cpuid (0x80000001,
> +	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
> +	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
> +	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
> +	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);

OK.

> +
> +}
> +
>  static void
>  get_common_indeces (struct cpu_features *cpu_features,
>  		    unsigned int *family, unsigned int *model,
> @@ -224,6 +238,8 @@ init_cpu_features (struct cpu_features *cpu_features)
>        get_common_indeces (cpu_features, &family, &model, &extended_model,
>  			  &stepping);
>  
> +      get_extended_indeces (cpu_features);

OK (after rename).

> +
>        if (family == 0x06)
>  	{
>  	  model += extended_model;
> @@ -338,16 +354,9 @@ init_cpu_features (struct cpu_features *cpu_features)
>        get_common_indeces (cpu_features, &family, &model, &extended_model,
>  			  &stepping);
>  
> -      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
> +      get_extended_indeces (cpu_features);

OK (after rename).

>  
> -      unsigned int eax;
> -      __cpuid (0x80000000, eax, ebx, ecx, edx);
> -      if (eax >= 0x80000001)
> -	__cpuid (0x80000001,
> -		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
> -		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
> -		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
> -		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
> +      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;

OK.

>  
>        if (HAS_ARCH_FEATURE (AVX_Usable))
>  	{
>
  

Patch

diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index 8108256c42..f8beb96e51 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -42,6 +42,20 @@  extern void TUNABLE_CALLBACK (set_x86_shstk) (tunable_val_t *)
 # include <cet-tunables.h>
 #endif
 
+static void
+get_extended_indeces (struct cpu_features *cpu_features)
+{
+  unsigned int eax, ebx, ecx, edx;
+  __cpuid (0x80000000, eax, ebx, ecx, edx);
+  if (eax >= 0x80000001)
+    __cpuid (0x80000001,
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
+	     cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
+
+}
+
 static void
 get_common_indeces (struct cpu_features *cpu_features,
 		    unsigned int *family, unsigned int *model,
@@ -224,6 +238,8 @@  init_cpu_features (struct cpu_features *cpu_features)
       get_common_indeces (cpu_features, &family, &model, &extended_model,
 			  &stepping);
 
+      get_extended_indeces (cpu_features);
+
       if (family == 0x06)
 	{
 	  model += extended_model;
@@ -338,16 +354,9 @@  init_cpu_features (struct cpu_features *cpu_features)
       get_common_indeces (cpu_features, &family, &model, &extended_model,
 			  &stepping);
 
-      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
+      get_extended_indeces (cpu_features);
 
-      unsigned int eax;
-      __cpuid (0x80000000, eax, ebx, ecx, edx);
-      if (eax >= 0x80000001)
-	__cpuid (0x80000001,
-		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].eax,
-		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ebx,
-		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].ecx,
-		 cpu_features->cpuid[COMMON_CPUID_INDEX_80000001].edx);
+      ecx = cpu_features->cpuid[COMMON_CPUID_INDEX_1].ecx;
 
       if (HAS_ARCH_FEATURE (AVX_Usable))
 	{