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

[Xen-changelog] [xen staging] x86/ucode/amd: Fold structures together



commit 6f56491911a6a11ec94db36aca791a23e3cc75b6
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Mon Mar 30 17:58:29 2020 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Wed Apr 1 14:00:12 2020 +0100

    x86/ucode/amd: Fold structures together
    
    With all the necessary cleanup now in place, fold struct 
microcode_header_amd
    into struct microcode_patch and drop the struct microcode_amd temporary
    ifdef-ary.
    
    This removes the memory allocation of struct microcode_amd which is a single
    pointer to a separately allocated object, and therefore a waste.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/cpu/microcode/amd.c | 70 ++++++++++++----------------------------
 1 file changed, 20 insertions(+), 50 deletions(-)

diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c
index 1b1f8335ef..b9ebf81e0a 100644
--- a/xen/arch/x86/cpu/microcode/amd.c
+++ b/xen/arch/x86/cpu/microcode/amd.c
@@ -37,7 +37,7 @@ struct __packed equiv_cpu_entry {
     uint16_t reserved;
 };
 
-struct __packed microcode_header_amd {
+struct microcode_patch {
     uint32_t data_code;
     uint32_t patch_id;
     uint8_t  mc_patch_data_id[2];
@@ -58,13 +58,6 @@ struct __packed microcode_header_amd {
 #define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000
 #define UCODE_UCODE_TYPE           0x00000001
 
-struct microcode_patch {
-    struct microcode_header_amd *mpb;
-};
-
-/* Temporary, until the microcode_* structure are disentangled. */
-#define microcode_amd microcode_patch
-
 struct mpbhdr {
     uint32_t type;
     uint32_t len;
@@ -73,7 +66,7 @@ struct mpbhdr {
 struct container_microcode {
     uint32_t type; /* UCODE_UCODE_TYPE */
     uint32_t len;
-    struct microcode_header_amd patch[];
+    struct microcode_patch patch[];
 };
 
 /*
@@ -178,7 +171,7 @@ static bool check_final_patch_levels(const struct 
cpu_signature *sig)
 }
 
 static enum microcode_match_result microcode_fits(
-    const struct microcode_header_amd *patch)
+    const struct microcode_patch *patch)
 {
     unsigned int cpu = smp_processor_id();
     const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
@@ -201,37 +194,31 @@ static enum microcode_match_result microcode_fits(
 
 static bool match_cpu(const struct microcode_patch *patch)
 {
-    return patch && (microcode_fits(patch->mpb) == NEW_UCODE);
+    return patch && (microcode_fits(patch) == NEW_UCODE);
 }
 
-static void free_patch(struct microcode_patch *mc_amd)
+static void free_patch(struct microcode_patch *patch)
 {
-    if ( mc_amd )
-    {
-        xfree(mc_amd->mpb);
-        xfree(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)
+    const struct microcode_patch *new, const struct microcode_patch *old)
 {
-    if ( new_header->processor_rev_id == old_header->processor_rev_id )
-        return (new_header->patch_id > old_header->patch_id) ? NEW_UCODE
-                                                             : OLD_UCODE;
+    if ( new->processor_rev_id != old->processor_rev_id )
+        return MIS_UCODE;
 
-    return MIS_UCODE;
+    return new->patch_id > old->patch_id ? NEW_UCODE : OLD_UCODE;
 }
 
 static enum microcode_match_result compare_patch(
     const struct microcode_patch *new, const struct microcode_patch *old)
 {
     /* Both patches to compare are supposed to be applicable to local CPU. */
-    ASSERT(microcode_fits(new->mpb) != MIS_UCODE);
-    ASSERT(microcode_fits(old->mpb) != MIS_UCODE);
+    ASSERT(microcode_fits(new) != MIS_UCODE);
+    ASSERT(microcode_fits(old) != MIS_UCODE);
 
-    return compare_header(new->mpb, old->mpb);
+    return compare_header(new, old);
 }
 
 static int apply_microcode(const struct microcode_patch *patch)
@@ -239,7 +226,6 @@ static int apply_microcode(const struct microcode_patch 
*patch)
     int hw_err;
     unsigned int cpu = smp_processor_id();
     struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
-    const struct microcode_header_amd *hdr;
     uint32_t rev, old_rev = sig->rev;
 
     if ( !patch )
@@ -256,9 +242,7 @@ static int apply_microcode(const struct microcode_patch 
*patch)
         return -ENXIO;
     }
 
-    hdr = patch->mpb;
-
-    hw_err = wrmsr_safe(MSR_AMD_PATCHLOADER, (unsigned long)hdr);
+    hw_err = wrmsr_safe(MSR_AMD_PATCHLOADER, (unsigned long)patch);
 
     /* get patch id after patching */
     rdmsrl(MSR_AMD_PATCHLEVEL, rev);
@@ -268,14 +252,14 @@ static int apply_microcode(const struct microcode_patch 
*patch)
      * Some processors leave the ucode blob mapping as UC after the update.
      * Flush the mapping to regain normal cacheability.
      */
-    flush_area_local(hdr, FLUSH_TLB_GLOBAL | FLUSH_ORDER(0));
+    flush_area_local(patch, FLUSH_TLB_GLOBAL | FLUSH_ORDER(0));
 
     /* check current patch id and patch's id for match */
-    if ( hw_err || (rev != hdr->patch_id) )
+    if ( hw_err || (rev != patch->patch_id) )
     {
         printk(XENLOG_ERR
                "microcode: CPU%u update rev %#x to %#x failed, result %#x\n",
-               cpu, old_rev, hdr->patch_id, rev);
+               cpu, old_rev, patch->patch_id, rev);
         return -EIO;
     }
 
@@ -388,8 +372,7 @@ static int container_fast_forward(const void *data, size_t 
size_left, size_t *of
 
 static struct microcode_patch *cpu_request_microcode(const void *buf, size_t 
size)
 {
-    struct microcode_amd *mc_amd;
-    const struct microcode_header_amd *saved = NULL;
+    const struct microcode_patch *saved = NULL;
     struct microcode_patch *patch = NULL;
     size_t offset = 0, saved_size = 0;
     int error = 0;
@@ -403,14 +386,6 @@ static struct microcode_patch *cpu_request_microcode(const 
void *buf, size_t siz
         goto out;
     }
 
-    mc_amd = xzalloc(struct microcode_amd);
-    if ( !mc_amd )
-    {
-        printk(KERN_ERR "microcode: Cannot allocate memory for microcode 
patch\n");
-        error = -ENOMEM;
-        goto out;
-    }
-
     /*
      * Multiple container file support:
      * 1. check if this container file has equiv_cpu_id match
@@ -447,7 +422,6 @@ static struct microcode_patch *cpu_request_microcode(const 
void *buf, size_t siz
         if ( error == -ENODATA )
             error = 0;
 
-        xfree(mc_amd);
         goto out;
     }
 
@@ -498,14 +472,10 @@ static struct microcode_patch 
*cpu_request_microcode(const void *buf, size_t siz
 
     if ( saved )
     {
-        mc_amd->mpb = xmemdup_bytes(saved, saved_size);
-        if ( mc_amd->mpb )
-            patch = mc_amd;
-        else
+        patch = xmemdup_bytes(saved, saved_size);
+        if ( !patch )
             error = -ENOMEM;
     }
-    else
-        free_patch(mc_amd);
 
   out:
     if ( error && !patch )
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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