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

[Xen-devel] [PATCH 5/6] x86/ucode: Alter ops->free_patch() to free the entire patch



The data layout for struct microcode_patch is extremely poor, and
unnecessarily complicated.  Almost all of it is opaque to core.c, with the
exception of free_patch().

Move the responsibility for freeing the patch into the free_patch() hook,
which will allow each driver to do a better job.  Take the opportunity to make
the hooks idempotent.

No practical change in behaviour.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/arch/x86/cpu/microcode/amd.c     | 17 ++++++++++++-----
 xen/arch/x86/cpu/microcode/core.c    |  3 +--
 xen/arch/x86/cpu/microcode/intel.c   |  8 ++++++--
 xen/arch/x86/cpu/microcode/private.h |  2 +-
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c
index 768fbcf322..77e582c8e1 100644
--- a/xen/arch/x86/cpu/microcode/amd.c
+++ b/xen/arch/x86/cpu/microcode/amd.c
@@ -180,10 +180,8 @@ static bool match_cpu(const struct microcode_patch *patch)
     return patch && (microcode_fits(patch->mc_amd) == NEW_UCODE);
 }
 
-static void free_patch(void *mc)
+static void free_mc_amd(struct microcode_amd *mc_amd)
 {
-    struct microcode_amd *mc_amd = mc;
-
     if ( mc_amd )
     {
         xfree(mc_amd->equiv_cpu_table);
@@ -192,6 +190,15 @@ static void free_patch(void *mc)
     }
 }
 
+static void free_patch(struct microcode_patch *patch)
+{
+    if ( patch )
+    {
+        free_mc_amd(patch->mc_amd);
+        xfree(patch);
+    }
+}
+
 static enum microcode_match_result compare_header(
     const struct microcode_header_amd *new_header,
     const struct microcode_header_amd *old_header)
@@ -564,12 +571,12 @@ static struct microcode_patch 
*cpu_request_microcode(const void *buf,
             patch->mc_amd = mc_amd;
         else
         {
-            free_patch(mc_amd);
+            free_mc_amd(mc_amd);
             error = -ENOMEM;
         }
     }
     else
-        free_patch(mc_amd);
+        free_mc_amd(mc_amd);
 
   out:
     if ( error && !patch )
diff --git a/xen/arch/x86/cpu/microcode/core.c 
b/xen/arch/x86/cpu/microcode/core.c
index 61e4b9b7ab..30017e3e0f 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -245,8 +245,7 @@ static struct microcode_patch *parse_blob(const char *buf, 
size_t len)
 
 static void microcode_free_patch(struct microcode_patch *microcode_patch)
 {
-    microcode_ops->free_patch(microcode_patch->mc);
-    xfree(microcode_patch);
+    microcode_ops->free_patch(microcode_patch);
 }
 
 /* Return true if cache gets updated. Otherwise, return false */
diff --git a/xen/arch/x86/cpu/microcode/intel.c 
b/xen/arch/x86/cpu/microcode/intel.c
index 48544e8d6d..0e6ba50048 100644
--- a/xen/arch/x86/cpu/microcode/intel.c
+++ b/xen/arch/x86/cpu/microcode/intel.c
@@ -248,9 +248,13 @@ static bool match_cpu(const struct microcode_patch *patch)
     return microcode_update_match(&patch->mc_intel->hdr) == NEW_UCODE;
 }
 
-static void free_patch(void *mc)
+static void free_patch(struct microcode_patch *patch)
 {
-    xfree(mc);
+    if ( patch )
+    {
+        xfree(patch->mc_intel);
+        xfree(patch);
+    }
 }
 
 static enum microcode_match_result compare_patch(
diff --git a/xen/arch/x86/cpu/microcode/private.h 
b/xen/arch/x86/cpu/microcode/private.h
index c32ddc8d19..897d32a8e9 100644
--- a/xen/arch/x86/cpu/microcode/private.h
+++ b/xen/arch/x86/cpu/microcode/private.h
@@ -26,7 +26,7 @@ struct microcode_ops {
     int (*apply_microcode)(const struct microcode_patch *patch);
     int (*start_update)(void);
     void (*end_update_percpu)(void);
-    void (*free_patch)(void *mc);
+    void (*free_patch)(struct microcode_patch *patch);
     bool (*match_cpu)(const struct microcode_patch *patch);
     enum microcode_match_result (*compare_patch)(
         const struct microcode_patch *new, const struct microcode_patch *old);
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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