[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] x86/match-cpu: Improvements to x86_match_cpu()



commit 826a13acd72dd4fb9397e48810ed9ff63b0ba091
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Fri Jul 18 13:44:11 2025 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Mon Jul 21 12:40:11 2025 +0100

    x86/match-cpu: Improvements to x86_match_cpu()
    
    Xen's use of struct x86_cpu_id is a bit different to Linux's, so we can
    simplify the loop termination condition.  Leave a comment explaining Xen's
    assumptions.
    
    Switch to Xen style, as we've properly deviated from Linux, and switch to 
the
    new vendor/family/model names.
    
    No practical change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/cpu/common.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index f221b9497c..6ea16edc69 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -1007,19 +1007,26 @@ void cpu_uninit(unsigned int cpu)
 
 const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id table[])
 {
-       const struct x86_cpu_id *m;
-       const struct cpuinfo_x86 *c = &boot_cpu_data;
+    const struct x86_cpu_id *m;
+    const struct cpuinfo_x86 *c = &boot_cpu_data;
 
-       for (m = table; m->vendor | m->family | m->model | m->feature; m++) {
-               if (c->x86_vendor != m->vendor)
-                       continue;
-               if (c->x86 != m->family)
-                       continue;
-               if (c->x86_model != m->model)
-                       continue;
-               if (!cpu_has(c, m->feature))
-                       continue;
-               return m;
-       }
-       return NULL;
+    /*
+     * Although derived from Linux originally, Xen has no valid rows where
+     * ->vendor is zero, so used this in place of checking all metadata.
+     */
+    for ( m = table; m->vendor; m++ )
+    {
+        if ( c->vendor != m->vendor )
+            continue;
+        if ( c->family != m->family )
+            continue;
+        if ( c->model != m->model )
+            continue;
+        if ( !cpu_has(c, m->feature) )
+            continue;
+
+        return m;
+    }
+
+    return NULL;
 }
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.