On Wed, Jun 19, 2019 at 02:34:04PM -0700, Fenghua Yu wrote:
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index efb114298cfb..4910cb421b82 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -847,6 +847,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
>               c->x86_capability[CPUID_7_0_EBX] = ebx;
>               c->x86_capability[CPUID_7_ECX] = ecx;
>               c->x86_capability[CPUID_7_EDX] = edx;
> +
> +             cpuid_count(0x00000007, 1, &eax, &ebx, &ecx, &edx);
> +             c->x86_capability[CPUID_7_1_EAX] = eax;
>       }

You need to test the sub-leaf index validity here before accessing
subleaf 1:

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 4910cb421b82..dad20bc891d5 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -848,8 +848,11 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
                c->x86_capability[CPUID_7_ECX] = ecx;
                c->x86_capability[CPUID_7_EDX] = edx;
 
-               cpuid_count(0x00000007, 1, &eax, &ebx, &ecx, &edx);
-               c->x86_capability[CPUID_7_1_EAX] = eax;
+               /* Check valid sub-leaf index before accessing it */
+               if (eax >= 1) {
+                       cpuid_count(0x00000007, 1, &eax, &ebx, &ecx, &edx);
+                       c->x86_capability[CPUID_7_1_EAX] = eax;
+               }
        }
 
        /* Extended state features: level 0x0000000d */

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

Reply via email to