x86/microcode/intel: Some trivial cleanups
Subsystems (2)
Borislav Petkov
maintainercover x86/microcode/intel: Some trivial cleanups
From: Borislav Petkov <[email protected]>
Some more or less trivial cleanups to the intel loader code which should make it a bit more clear/readable what's going on.
Borislav Petkov (4):
x86/microcode/intel: Rename get_matching_microcode x86/microcode/intel: Simplify update_match_cpu() x86/microcode/intel: Simplify get_matching_sig() x86/microcode/intel: Rename get_matching_sig()
arch/x86/include/asm/microcode_intel.h | 7 ++--- arch/x86/kernel/cpu/microcode/intel.c | 4 +-- arch/x86/kernel/cpu/microcode/intel_early.c | 10 +++---- arch/x86/kernel/cpu/microcode/intel_lib.c | 43 ++++++++++++++++------------- 4 files changed, 33 insertions(+), 31 deletions(-)
Signature · 1 line
2.3.5
Borislav Petkov
maintainerPATCH 1/4 x86/microcode/intel: Rename get_matching_microcode
From: Borislav Petkov <[email protected]>
... to has_newer_microcode() as it does exactly that: checks whether binary data @mc has newer microcode patch than the applied one. Move @mc to be the first function arg too.
--- arch/x86/include/asm/microcode_intel.h | 2 +- arch/x86/kernel/cpu/microcode/intel.c | 4 ++-- arch/x86/kernel/cpu/microcode/intel_early.c | 8 ++++---- arch/x86/kernel/cpu/microcode/intel_lib.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/include/asm/microcode_intel.h +1 -1
@@ -56,7 +56,7 @@ struct extended_sigtable {#define exttable_size (et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) -extern int get_matching_microcode (unsigned int csig,int cpf,int rev,void *mc); +extern int has_newer_microcode (void *mc,unsigned int csig,int cpf,int rev);extern int microcode_sanity_check (void *mc,int print_err);extern int get_matching_sig (unsigned int csig,int cpf,void *mc);
arch/x86/kernel/cpu/microcode/intel.c +2 -2
@@ -63,7 +63,7 @@ static int get_matching_mc(struct microcode_intel *mc_intel, int cpu) cpf = cpu_sig.pf; crev = cpu_sig.rev; -return get_matching_microcode (csig, cpf, crev, mc_intel); +return has_newer_microcode (mc_intel, csig, cpf, crev); }static int apply_microcode_intel (int cpu)
@@ -165,7 +165,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, csig = uci->cpu_sig.sig; cpf = uci->cpu_sig.pf; -if (get_matching_microcode (csig, cpf, new_rev, mc)) { +if (has_newer_microcode (mc, csig, cpf, new_rev)) {vfree (new_mc); new_rev = mc_header.rev; new_mc = mc;
arch/x86/kernel/cpu/microcode/intel_early.c +4 -4
@@ -59,10 +59,10 @@ load_microcode_early(struct microcode_intel **saved, ucode_ptr = saved[i]; mc_hdr = (struct microcode_header_intel *)ucode_ptr; - ret =get_matching_microcode (uci->cpu_sig.sig, - uci->cpu_sig.pf, - new_rev, - ucode_ptr); + ret =has_newer_microcode (ucode_ptr, + uci->cpu_sig.sig, + uci->cpu_sig.pf, + new_rev);if (!ret)continue ;
arch/x86/kernel/cpu/microcode/intel_lib.c +2 -2
@@ -154,7 +154,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc)/* * Returns 1 if update has been found, 0 otherwise. */ -int get_matching_microcode (unsigned int csig,int cpf,int new_rev,void *mc) +int has_newer_microcode (void *mc,unsigned int csig,int cpf,int new_rev) {struct microcode_header_intel *mc_hdr = mc;
@@ -163,4 +163,4 @@ int get_matching_microcode(unsigned int csig, int cpf, int new_rev, void *mc)return get_matching_sig (csig, cpf, mc); } -EXPORT_SYMBOL_GPL (get_matching_microcode); +EXPORT_SYMBOL_GPL (has_newer_microcode);
Signature · 1 line
2.3.5
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/intel: Rename get_matching_microcode
x86/microcode/intel: Rename get_matching_microcode
Commit-ID: 8de3eafc161022dd094fa009346509c712e9c4b0 Gitweb: http://git.kernel.org/tip/8de3eafc161022dd094fa009346509c712e9c4b0 Author: Borislav Petkov <[email protected]> AuthorDate: Sun, 17 May 2015 12:54:58 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 18 May 2015 09:32:36 +0200
x86/microcode/intel: Rename get_matching_microcode
... to has_newer_microcode() as it does exactly that: checks whether binary data @mc has newer microcode patch than the applied one. Move @mc to be the first function arg too.
--- arch/x86/include/asm/microcode_intel.h | 2 +- arch/x86/kernel/cpu/microcode/intel.c | 4 ++-- arch/x86/kernel/cpu/microcode/intel_early.c | 8 ++++---- arch/x86/kernel/cpu/microcode/intel_lib.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/include/asm/microcode_intel.h +1 -1
@@ -56,7 +56,7 @@ struct extended_sigtable {#define exttable_size (et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE) -extern int get_matching_microcode (unsigned int csig,int cpf,int rev,void *mc); +extern int has_newer_microcode (void *mc,unsigned int csig,int cpf,int rev);extern int microcode_sanity_check (void *mc,int print_err);extern int get_matching_sig (unsigned int csig,int cpf,void *mc);
arch/x86/kernel/cpu/microcode/intel.c +2 -2
@@ -63,7 +63,7 @@ static int get_matching_mc(struct microcode_intel *mc_intel, int cpu) cpf = cpu_sig.pf; crev = cpu_sig.rev; -return get_matching_microcode (csig, cpf, crev, mc_intel); +return has_newer_microcode (mc_intel, csig, cpf, crev); }static int apply_microcode_intel (int cpu)
@@ -165,7 +165,7 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size, csig = uci->cpu_sig.sig; cpf = uci->cpu_sig.pf; -if (get_matching_microcode (csig, cpf, new_rev, mc)) { +if (has_newer_microcode (mc, csig, cpf, new_rev)) {vfree (new_mc); new_rev = mc_header.rev; new_mc = mc;
arch/x86/kernel/cpu/microcode/intel_early.c +4 -4
@@ -59,10 +59,10 @@ load_microcode_early(struct microcode_intel **saved, ucode_ptr = saved[i]; mc_hdr = (struct microcode_header_intel *)ucode_ptr; - ret =get_matching_microcode (uci->cpu_sig.sig, - uci->cpu_sig.pf, - new_rev, - ucode_ptr); + ret =has_newer_microcode (ucode_ptr, + uci->cpu_sig.sig, + uci->cpu_sig.pf, + new_rev);if (!ret)continue ;
arch/x86/kernel/cpu/microcode/intel_lib.c +2 -2
@@ -154,7 +154,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc)/* * Returns 1 if update has been found, 0 otherwise. */ -int get_matching_microcode (unsigned int csig,int cpf,int new_rev,void *mc) +int has_newer_microcode (void *mc,unsigned int csig,int cpf,int new_rev) {struct microcode_header_intel *mc_hdr = mc;
@@ -163,4 +163,4 @@ int get_matching_microcode(unsigned int csig, int cpf, int new_rev, void *mc)return get_matching_sig (csig, cpf, mc); } -EXPORT_SYMBOL_GPL (get_matching_microcode); +EXPORT_SYMBOL_GPL (has_newer_microcode);
Borislav Petkov
maintainerPATCH 2/4 x86/microcode/intel: Simplify update_match_cpu()
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Drop unreadable macro, deconstruct compound conditional statement into single ones and return early if they match. Add comments.
There should be no functionality change resulting from this patch.
--- arch/x86/include/asm/microcode_intel.h | 3 --- arch/x86/kernel/cpu/microcode/intel_lib.c | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-)
arch/x86/include/asm/microcode_intel.h +0 -3
@@ -51,9 +51,6 @@ struct extended_sigtable { (((struct microcode_intel *)mc)->hdr.datasize ? \ ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) -#define sigmatch (s1, s2, p1, p2) \ - (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0)))) -#define exttable_size (et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)extern int has_newer_microcode (void *mc,unsigned int csig,int cpf,int rev);
arch/x86/kernel/cpu/microcode/intel_lib.c +13 -6
@@ -31,11 +31,18 @@#include <asm/processor.h> #include <asm/msr.h> -static inline int -update_match_cpu (unsigned int csig,unsigned int cpf, -unsigned int sig,unsigned int pf) +static inline bool cpu_signatures_match (unsigned int s1,unsigned int p1, +unsigned int s2,unsigned int p2) { -return (!sigmatch (sig, csig, pf, cpf)) ?0 :1 ; +if (s1 != s2) +return false; + +/* Processor flags are either both 0 ... */ +if (!p1 && !p2) +return true; + +/* ... or they intersect. */ +return p1 & p2; }int microcode_sanity_check (void *mc,int print_err)
@@ -132,7 +139,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc)int ext_sigcount, i;struct extended_signature *ext_sig; -if (update_match_cpu (csig, cpf, mc_header->sig, mc_header->pf)) +if (cpu_signatures_match (csig, cpf, mc_header->sig, mc_header->pf))return 1 ;/* Look for ext. headers: */
@@ -144,7 +151,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc) ext_sig = (void *)ext_header +EXT_HEADER_SIZE ;for (i =0 ; i < ext_sigcount; i++) { -if (update_match_cpu (csig, cpf, ext_sig->sig, ext_sig->pf)) +if (cpu_signatures_match (csig, cpf, ext_sig->sig, ext_sig->pf))return 1 ; ext_sig++; }
Signature · 1 line
2.3.5
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/intel: Simplify update_match_cpu()
x86/microcode/intel: Simplify update_match_cpu()
Commit-ID: 6b2d469f5b5dd1d39548f2e79557b9b5ffe00eb1 Gitweb: http://git.kernel.org/tip/6b2d469f5b5dd1d39548f2e79557b9b5ffe00eb1 Author: Borislav Petkov <[email protected]> AuthorDate: Sun, 17 May 2015 12:54:59 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 18 May 2015 09:32:36 +0200
x86/microcode/intel: Simplify update_match_cpu()
Drop unreadable macro, deconstruct compound conditional statement into single ones and return early if they match. Add comments.
There should be no functionality change resulting from this patch.
--- arch/x86/include/asm/microcode_intel.h | 3 --- arch/x86/kernel/cpu/microcode/intel_lib.c | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-)
arch/x86/include/asm/microcode_intel.h +0 -3
@@ -51,9 +51,6 @@ struct extended_sigtable { (((struct microcode_intel *)mc)->hdr.datasize ? \ ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATASIZE) -#define sigmatch (s1, s2, p1, p2) \ - (((s1) == (s2)) && (((p1) & (p2)) || (((p1) == 0) && ((p2) == 0)))) -#define exttable_size (et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_SIZE)extern int has_newer_microcode (void *mc,unsigned int csig,int cpf,int rev);
arch/x86/kernel/cpu/microcode/intel_lib.c +13 -6
@@ -31,11 +31,18 @@#include <asm/processor.h> #include <asm/msr.h> -static inline int -update_match_cpu (unsigned int csig,unsigned int cpf, -unsigned int sig,unsigned int pf) +static inline bool cpu_signatures_match (unsigned int s1,unsigned int p1, +unsigned int s2,unsigned int p2) { -return (!sigmatch (sig, csig, pf, cpf)) ?0 :1 ; +if (s1 != s2) +return false; + +/* Processor flags are either both 0 ... */ +if (!p1 && !p2) +return true; + +/* ... or they intersect. */ +return p1 & p2; }int microcode_sanity_check (void *mc,int print_err)
@@ -132,7 +139,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc)int ext_sigcount, i;struct extended_signature *ext_sig; -if (update_match_cpu (csig, cpf, mc_header->sig, mc_header->pf)) +if (cpu_signatures_match (csig, cpf, mc_header->sig, mc_header->pf))return 1 ;/* Look for ext. headers: */
@@ -144,7 +151,7 @@ int get_matching_sig(unsigned int csig, int cpf, void *mc) ext_sig = (void *)ext_header +EXT_HEADER_SIZE ;for (i =0 ; i < ext_sigcount; i++) { -if (update_match_cpu (csig, cpf, ext_sig->sig, ext_sig->pf)) +if (cpu_signatures_match (csig, cpf, ext_sig->sig, ext_sig->pf))return 1 ; ext_sig++; }
Borislav Petkov
maintainerPATCH 3/4 x86/microcode/intel: Simplify get_matching_sig()
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Unclutter function, make it a bit more readable, drop local variables.
No functionality change.
--- arch/x86/kernel/cpu/microcode/intel_lib.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/microcode/intel_lib.c +8 -10
@@ -133,24 +133,22 @@ EXPORT_SYMBOL_GPL(microcode_sanity_check);*/ int get_matching_sig (unsigned int csig,int cpf,void *mc) { -struct microcode_header_intel *mc_header = mc; -struct extended_sigtable *ext_header; -unsigned long total_size =get_totalsize (mc_header); -int ext_sigcount, i; +struct microcode_header_intel *mc_hdr = mc; +struct extended_sigtable *ext_hdr;struct extended_signature *ext_sig; +int i; -if (cpu_signatures_match (csig, cpf, mc_header->sig, mc_header->pf)) +if (cpu_signatures_match (csig, cpf, mc_hdr->sig, mc_hdr->pf))return 1 ;/* Look for ext. headers: */ -if (total_size <=get_datasize (mc_header) +MC_HEADER_SIZE ) +if (get_totalsize (mc_hdr) <=get_datasize (mc_hdr) +MC_HEADER_SIZE )return 0 ; - ext_header = mc +get_datasize (mc_header) +MC_HEADER_SIZE ; - ext_sigcount = ext_header->count; - ext_sig = (void *)ext_header +EXT_HEADER_SIZE ; + ext_hdr = mc +get_datasize (mc_hdr) +MC_HEADER_SIZE ; + ext_sig = (void *)ext_hdr +EXT_HEADER_SIZE ; -for (i =0 ; i < ext_sigcount; i++) { +for (i =0 ; i < ext_hdr->count; i++) {if (cpu_signatures_match (csig, cpf, ext_sig->sig, ext_sig->pf))return 1 ; ext_sig++;
Signature · 1 line
2.3.5
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/intel: Simplify get_matching_sig()
x86/microcode/intel: Simplify get_matching_sig()
Commit-ID: 9e5aed83bbd95ca2dee732f56a7a278350cef807 Gitweb: http://git.kernel.org/tip/9e5aed83bbd95ca2dee732f56a7a278350cef807 Author: Borislav Petkov <[email protected]> AuthorDate: Sun, 17 May 2015 12:55:00 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 18 May 2015 09:32:36 +0200
x86/microcode/intel: Simplify get_matching_sig()
Unclutter function, make it a bit more readable, drop local variables.
No functionality change.
--- arch/x86/kernel/cpu/microcode/intel_lib.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
arch/x86/kernel/cpu/microcode/intel_lib.c +8 -10
@@ -133,24 +133,22 @@ EXPORT_SYMBOL_GPL(microcode_sanity_check);*/ int get_matching_sig (unsigned int csig,int cpf,void *mc) { -struct microcode_header_intel *mc_header = mc; -struct extended_sigtable *ext_header; -unsigned long total_size =get_totalsize (mc_header); -int ext_sigcount, i; +struct microcode_header_intel *mc_hdr = mc; +struct extended_sigtable *ext_hdr;struct extended_signature *ext_sig; +int i; -if (cpu_signatures_match (csig, cpf, mc_header->sig, mc_header->pf)) +if (cpu_signatures_match (csig, cpf, mc_hdr->sig, mc_hdr->pf))return 1 ;/* Look for ext. headers: */ -if (total_size <=get_datasize (mc_header) +MC_HEADER_SIZE ) +if (get_totalsize (mc_hdr) <=get_datasize (mc_hdr) +MC_HEADER_SIZE )return 0 ; - ext_header = mc +get_datasize (mc_header) +MC_HEADER_SIZE ; - ext_sigcount = ext_header->count; - ext_sig = (void *)ext_header +EXT_HEADER_SIZE ; + ext_hdr = mc +get_datasize (mc_hdr) +MC_HEADER_SIZE ; + ext_sig = (void *)ext_hdr +EXT_HEADER_SIZE ; -for (i =0 ; i < ext_sigcount; i++) { +for (i =0 ; i < ext_hdr->count; i++) {if (cpu_signatures_match (csig, cpf, ext_sig->sig, ext_sig->pf))return 1 ; ext_sig++;
Borislav Petkov
maintainerPATCH 4/4 x86/microcode/intel: Rename get_matching_sig()
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
... to find_matching_signature() which is exactly what it does.
No functionality change.
--- arch/x86/include/asm/microcode_intel.h | 2 +- arch/x86/kernel/cpu/microcode/intel_early.c | 2 +- arch/x86/kernel/cpu/microcode/intel_lib.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/microcode_intel.h +1 -1
@@ -55,7 +55,7 @@ struct extended_sigtable {extern int has_newer_microcode (void *mc,unsigned int csig,int cpf,int rev);extern int microcode_sanity_check (void *mc,int print_err); -extern int get_matching_sig (unsigned int csig,int cpf,void *mc); +extern int find_matching_signature (void *mc,unsigned int csig,int cpf);#ifdef CONFIG_MICROCODE_INTEL_EARLY extern void __init load_ucode_intel_bsp (void );
arch/x86/kernel/cpu/microcode/intel_early.c +1 -1
@@ -256,7 +256,7 @@ static unsigned int _save_mc(struct microcode_intel **mc_saved, sig = mc_saved_hdr->sig; pf = mc_saved_hdr->pf; -if (!get_matching_sig (sig, pf, ucode_ptr)) +if (!find_matching_signature (ucode_ptr, sig, pf))continue ; found =1 ;
arch/x86/kernel/cpu/microcode/intel_lib.c +2 -2
@@ -131,7 +131,7 @@ EXPORT_SYMBOL_GPL(microcode_sanity_check);/* * Returns 1 if update has been found, 0 otherwise. */ -int get_matching_sig (unsigned int csig,int cpf,void *mc) +int find_matching_signature (void *mc,unsigned int csig,int cpf) {struct microcode_header_intel *mc_hdr = mc;struct extended_sigtable *ext_hdr;
@@ -166,6 +166,6 @@ int has_newer_microcode(void *mc, unsigned int csig, int cpf, int new_rev)if (mc_hdr->rev <= new_rev)return 0 ; -return get_matching_sig (csig, cpf, mc); +return find_matching_signature (mc, csig, cpf); }EXPORT_SYMBOL_GPL (has_newer_microcode);
Signature · 1 line
2.3.5
tip-bot for Borislav Petkov
merge bot[tip:x86/microcode] x86/microcode/intel: Rename get_matching_sig( )
x86/microcode/intel: Rename get_matching_sig()
Commit-ID: e774eaa9f6069b70b5208aa50539a09f41cf7e73 Gitweb: http://git.kernel.org/tip/e774eaa9f6069b70b5208aa50539a09f41cf7e73 Author: Borislav Petkov <[email protected]> AuthorDate: Sun, 17 May 2015 12:55:01 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Mon, 18 May 2015 09:32:37 +0200
x86/microcode/intel: Rename get_matching_sig()
... to find_matching_signature() which is exactly what it does.
No functionality change.
--- arch/x86/include/asm/microcode_intel.h | 2 +- arch/x86/kernel/cpu/microcode/intel_early.c | 2 +- arch/x86/kernel/cpu/microcode/intel_lib.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/microcode_intel.h +1 -1
@@ -55,7 +55,7 @@ struct extended_sigtable {extern int has_newer_microcode (void *mc,unsigned int csig,int cpf,int rev);extern int microcode_sanity_check (void *mc,int print_err); -extern int get_matching_sig (unsigned int csig,int cpf,void *mc); +extern int find_matching_signature (void *mc,unsigned int csig,int cpf);#ifdef CONFIG_MICROCODE_INTEL_EARLY extern void __init load_ucode_intel_bsp (void );
arch/x86/kernel/cpu/microcode/intel_early.c +1 -1
@@ -256,7 +256,7 @@ static unsigned int _save_mc(struct microcode_intel **mc_saved, sig = mc_saved_hdr->sig; pf = mc_saved_hdr->pf; -if (!get_matching_sig (sig, pf, ucode_ptr)) +if (!find_matching_signature (ucode_ptr, sig, pf))continue ; found =1 ;
arch/x86/kernel/cpu/microcode/intel_lib.c +2 -2
@@ -131,7 +131,7 @@ EXPORT_SYMBOL_GPL(microcode_sanity_check);/* * Returns 1 if update has been found, 0 otherwise. */ -int get_matching_sig (unsigned int csig,int cpf,void *mc) +int find_matching_signature (void *mc,unsigned int csig,int cpf) {struct microcode_header_intel *mc_hdr = mc;struct extended_sigtable *ext_hdr;
@@ -166,6 +166,6 @@ int has_newer_microcode(void *mc, unsigned int csig, int cpf, int new_rev)if (mc_hdr->rev <= new_rev)return 0 ; -return get_matching_sig (csig, cpf, mc); +return find_matching_signature (mc, csig, cpf); }EXPORT_SYMBOL_GPL (has_newer_microcode);
Quoted 2 lines · Borislav Petkov
Some more or less trivial cleanups to the intel loader code which should make it a bit more clear/readable what's going on.
Thank you!
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh