We were doing a fresh CPUID for every single bit in every single output
register. Do it once and then harvest *all* the bits we want.

We were also doing the max_level check with a new CPUID invocation for
every single bit. Stop that too.

Signed-off-by: David Woodhouse <d...@amazon.co.uk>
---
Spotted this in my travels; it offended me.

 arch/x86/kernel/cpu/scattered.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index df11f5d..26c15fb 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -23,8 +23,8 @@ static const struct cpuid_bit cpuid_bits[] = {
        { X86_FEATURE_EPB,              CPUID_ECX,  3, 0x00000006, 0 },
        { X86_FEATURE_CAT_L3,           CPUID_EBX,  1, 0x00000010, 0 },
        { X86_FEATURE_CAT_L2,           CPUID_EBX,  2, 0x00000010, 0 },
-       { X86_FEATURE_CDP_L3,           CPUID_ECX,  2, 0x00000010, 1 },
        { X86_FEATURE_MBA,              CPUID_EBX,  3, 0x00000010, 0 },
+       { X86_FEATURE_CDP_L3,           CPUID_ECX,  2, 0x00000010, 1 },
        { X86_FEATURE_HW_PSTATE,        CPUID_EDX,  7, 0x80000007, 0 },
        { X86_FEATURE_CPB,              CPUID_EDX,  9, 0x80000007, 0 },
        { X86_FEATURE_PROC_FEEDBACK,    CPUID_EDX, 11, 0x80000007, 0 },
@@ -38,20 +38,35 @@ void init_scattered_cpuid_features(struct cpuinfo_x86 *c)
        u32 regs[4];
        const struct cpuid_bit *cb;
 
+       /* Max level for basic CPUID leaves */
+       max_level = cpuid_eax(0);
+
        for (cb = cpuid_bits; cb->feature; cb++) {
 
+               /* Are we on to extended CPUID leaves yet? */
+               if (cb->level >= 0x80000000 && max_level < 0x80000000) {
+                       max_level = cpuid_eax(0x80000000);
+                       if (max_level < 0x80000000 || max_level > 0x8000ffff) {
+                               /* No extended leaves are supported */
+                               break;
+                       }
+               }
+
                /* Verify that the level is valid */
-               max_level = cpuid_eax(cb->level & 0xffff0000);
-               if (max_level < cb->level ||
-                   max_level > (cb->level | 0xffff))
+               if (cb->level > max_level)
                        continue;
 
                cpuid_count(cb->level, cb->sub_leaf, &regs[CPUID_EAX],
                            &regs[CPUID_EBX], &regs[CPUID_ECX],
                            &regs[CPUID_EDX]);
 
-               if (regs[cb->reg] & (1 << cb->bit))
-                       set_cpu_cap(c, cb->feature);
+               do {
+                       if (regs[cb->reg] & (1 << cb->bit))
+                               set_cpu_cap(c, cb->feature);
+
+               } while (cb[1].level == cb[0].level &&
+                        cb[1].sub_leaf == cb[0].sub_leaf &&
+                        cb++);
        }
 }
 
-- 
2.7.4

Reply via email to