Sorry for the late reply :)

On 2018/11/16 1:22, Borislav Petkov wrote:
>> @@ -640,7 +641,7 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *c)
>>              /* Do cpuid(op) loop to find out num_cache_leaves */
>>              cpuid_count(op, i, &eax, &ebx, &ecx, &edx);
>>              cache_eax.full = eax;
>> -    } while (cache_eax.split.type != CTYPE_NULL);
>> +    } while (cache_eax.split.type != CTYPE_NULL && i != CTYPE_MAX);
> i is an int and CTYPE_MAX is enum _cache_type. Huh?

How about define CTYPE_MAX like this:
#define CTYPE_MAX  4

> This works by chance because CTYPE_MAX is 4 and the termination CPUID
> leaf is the 4th too.

It will return CTYPE_NULL when accessing the 4th CPUID leaf in most of
the cases, but in certain case it will not. So I think it's better to
restrict the maximum CPUID access times to 4 for kernel robustness.

-- 
Regards,
Pu Wen

Reply via email to