linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] x86/microcode/intel: Some trivial cleanups
@ 2015-05-17 10:54 Borislav Petkov
  2015-05-17 10:54 ` [PATCH 1/4] x86/microcode/intel: Rename get_matching_microcode Borislav Petkov
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Borislav Petkov @ 2015-05-17 10:54 UTC (permalink / raw)
  To: X86 ML; +Cc: Quentin Casasnovas, LKML

From: Borislav Petkov <bp@suse.de>

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(-)

-- 
2.3.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] x86/microcode/intel: Rename get_matching_microcode
  2015-05-17 10:54 [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Borislav Petkov
@ 2015-05-17 10:54 ` Borislav Petkov
  2015-05-18  9:10   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
  2015-05-17 10:54 ` [PATCH 2/4] x86/microcode/intel: Simplify update_match_cpu() Borislav Petkov
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2015-05-17 10:54 UTC (permalink / raw)
  To: X86 ML; +Cc: Quentin Casasnovas, LKML

From: Borislav Petkov <bp@suse.de>

... 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.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 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(-)

diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h
index 3564299863f0..8e87e6fe98b5 100644
--- a/arch/x86/include/asm/microcode_intel.h
+++ b/arch/x86/include/asm/microcode_intel.h
@@ -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);
 
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index e20d4e58cd89..969dc17eb1b4 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -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;
diff --git a/arch/x86/kernel/cpu/microcode/intel_early.c b/arch/x86/kernel/cpu/microcode/intel_early.c
index ccd474a7a59e..5f828268357d 100644
--- a/arch/x86/kernel/cpu/microcode/intel_early.c
+++ b/arch/x86/kernel/cpu/microcode/intel_early.c
@@ -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;
 
diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index 7de293726923..425f8e29b795 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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);
-- 
2.3.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/4] x86/microcode/intel: Simplify update_match_cpu()
  2015-05-17 10:54 [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Borislav Petkov
  2015-05-17 10:54 ` [PATCH 1/4] x86/microcode/intel: Rename get_matching_microcode Borislav Petkov
@ 2015-05-17 10:54 ` Borislav Petkov
  2015-05-18  9:10   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
  2015-05-17 10:55 ` [PATCH 3/4] x86/microcode/intel: Simplify get_matching_sig() Borislav Petkov
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2015-05-17 10:54 UTC (permalink / raw)
  To: X86 ML; +Cc: Quentin Casasnovas, LKML

From: Borislav Petkov <bp@suse.de>

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.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/include/asm/microcode_intel.h    |  3 ---
 arch/x86/kernel/cpu/microcode/intel_lib.c | 19 +++++++++++++------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h
index 8e87e6fe98b5..45a318f677be 100644
--- a/arch/x86/include/asm/microcode_intel.h
+++ b/arch/x86/include/asm/microcode_intel.h
@@ -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);
diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index 425f8e29b795..1ffe507931af 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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++;
 	}
-- 
2.3.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/4] x86/microcode/intel: Simplify get_matching_sig()
  2015-05-17 10:54 [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Borislav Petkov
  2015-05-17 10:54 ` [PATCH 1/4] x86/microcode/intel: Rename get_matching_microcode Borislav Petkov
  2015-05-17 10:54 ` [PATCH 2/4] x86/microcode/intel: Simplify update_match_cpu() Borislav Petkov
@ 2015-05-17 10:55 ` Borislav Petkov
  2015-05-18  9:11   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
  2015-05-17 10:55 ` [PATCH 4/4] x86/microcode/intel: Rename get_matching_sig() Borislav Petkov
  2015-05-21  1:42 ` [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Henrique de Moraes Holschuh
  4 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2015-05-17 10:55 UTC (permalink / raw)
  To: X86 ML; +Cc: Quentin Casasnovas, LKML

From: Borislav Petkov <bp@suse.de>

Unclutter function, make it a bit more readable, drop local variables.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/cpu/microcode/intel_lib.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index 1ffe507931af..def9c935f3f9 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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++;
-- 
2.3.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/4] x86/microcode/intel: Rename get_matching_sig()
  2015-05-17 10:54 [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Borislav Petkov
                   ` (2 preceding siblings ...)
  2015-05-17 10:55 ` [PATCH 3/4] x86/microcode/intel: Simplify get_matching_sig() Borislav Petkov
@ 2015-05-17 10:55 ` Borislav Petkov
  2015-05-18  9:11   ` [tip:x86/microcode] x86/microcode/intel: Rename get_matching_sig( ) tip-bot for Borislav Petkov
  2015-05-21  1:42 ` [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Henrique de Moraes Holschuh
  4 siblings, 1 reply; 10+ messages in thread
From: Borislav Petkov @ 2015-05-17 10:55 UTC (permalink / raw)
  To: X86 ML; +Cc: Quentin Casasnovas, LKML

From: Borislav Petkov <bp@suse.de>

... to find_matching_signature() which is exactly what it does.

No functionality change.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 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(-)

diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h
index 45a318f677be..7991c606125d 100644
--- a/arch/x86/include/asm/microcode_intel.h
+++ b/arch/x86/include/asm/microcode_intel.h
@@ -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);
diff --git a/arch/x86/kernel/cpu/microcode/intel_early.c b/arch/x86/kernel/cpu/microcode/intel_early.c
index 5f828268357d..10dff3f3f686 100644
--- a/arch/x86/kernel/cpu/microcode/intel_early.c
+++ b/arch/x86/kernel/cpu/microcode/intel_early.c
@@ -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;
diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index def9c935f3f9..1883d252ff7d 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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);
-- 
2.3.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [tip:x86/microcode] x86/microcode/intel: Rename get_matching_microcode
  2015-05-17 10:54 ` [PATCH 1/4] x86/microcode/intel: Rename get_matching_microcode Borislav Petkov
@ 2015-05-18  9:10   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for Borislav Petkov @ 2015-05-18  9:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: bp, hpa, linux-kernel, peterz, torvalds, mingo, quentin.casasnovas, tglx

Commit-ID:  8de3eafc161022dd094fa009346509c712e9c4b0
Gitweb:     http://git.kernel.org/tip/8de3eafc161022dd094fa009346509c712e9c4b0
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Sun, 17 May 2015 12:54:58 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431860101-14847-2-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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(-)

diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h
index 3564299..8e87e6f 100644
--- a/arch/x86/include/asm/microcode_intel.h
+++ b/arch/x86/include/asm/microcode_intel.h
@@ -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);
 
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index e20d4e5..969dc17 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -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;
diff --git a/arch/x86/kernel/cpu/microcode/intel_early.c b/arch/x86/kernel/cpu/microcode/intel_early.c
index ccd474a..5f82826 100644
--- a/arch/x86/kernel/cpu/microcode/intel_early.c
+++ b/arch/x86/kernel/cpu/microcode/intel_early.c
@@ -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;
 
diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index 7de2937..425f8e2 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [tip:x86/microcode] x86/microcode/intel: Simplify update_match_cpu()
  2015-05-17 10:54 ` [PATCH 2/4] x86/microcode/intel: Simplify update_match_cpu() Borislav Petkov
@ 2015-05-18  9:10   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for Borislav Petkov @ 2015-05-18  9:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: quentin.casasnovas, linux-kernel, torvalds, bp, tglx, peterz, mingo, hpa

Commit-ID:  6b2d469f5b5dd1d39548f2e79557b9b5ffe00eb1
Gitweb:     http://git.kernel.org/tip/6b2d469f5b5dd1d39548f2e79557b9b5ffe00eb1
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Sun, 17 May 2015 12:54:59 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431860101-14847-3-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/microcode_intel.h    |  3 ---
 arch/x86/kernel/cpu/microcode/intel_lib.c | 19 +++++++++++++------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h
index 8e87e6f..45a318f 100644
--- a/arch/x86/include/asm/microcode_intel.h
+++ b/arch/x86/include/asm/microcode_intel.h
@@ -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);
diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index 425f8e2..1ffe507 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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++;
 	}

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [tip:x86/microcode] x86/microcode/intel: Simplify get_matching_sig()
  2015-05-17 10:55 ` [PATCH 3/4] x86/microcode/intel: Simplify get_matching_sig() Borislav Petkov
@ 2015-05-18  9:11   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for Borislav Petkov @ 2015-05-18  9:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, tglx, bp, quentin.casasnovas, mingo, peterz, torvalds, linux-kernel

Commit-ID:  9e5aed83bbd95ca2dee732f56a7a278350cef807
Gitweb:     http://git.kernel.org/tip/9e5aed83bbd95ca2dee732f56a7a278350cef807
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Sun, 17 May 2015 12:55:00 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431860101-14847-4-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/cpu/microcode/intel_lib.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index 1ffe507..def9c93 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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++;

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [tip:x86/microcode] x86/microcode/intel: Rename get_matching_sig( )
  2015-05-17 10:55 ` [PATCH 4/4] x86/microcode/intel: Rename get_matching_sig() Borislav Petkov
@ 2015-05-18  9:11   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 10+ messages in thread
From: tip-bot for Borislav Petkov @ 2015-05-18  9:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, peterz, hpa, tglx, bp, quentin.casasnovas, linux-kernel, torvalds

Commit-ID:  e774eaa9f6069b70b5208aa50539a09f41cf7e73
Gitweb:     http://git.kernel.org/tip/e774eaa9f6069b70b5208aa50539a09f41cf7e73
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Sun, 17 May 2015 12:55:01 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
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.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1431860101-14847-5-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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(-)

diff --git a/arch/x86/include/asm/microcode_intel.h b/arch/x86/include/asm/microcode_intel.h
index 45a318f..7991c60 100644
--- a/arch/x86/include/asm/microcode_intel.h
+++ b/arch/x86/include/asm/microcode_intel.h
@@ -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);
diff --git a/arch/x86/kernel/cpu/microcode/intel_early.c b/arch/x86/kernel/cpu/microcode/intel_early.c
index 5f82826..10dff3f 100644
--- a/arch/x86/kernel/cpu/microcode/intel_early.c
+++ b/arch/x86/kernel/cpu/microcode/intel_early.c
@@ -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;
diff --git a/arch/x86/kernel/cpu/microcode/intel_lib.c b/arch/x86/kernel/cpu/microcode/intel_lib.c
index def9c93..1883d25 100644
--- a/arch/x86/kernel/cpu/microcode/intel_lib.c
+++ b/arch/x86/kernel/cpu/microcode/intel_lib.c
@@ -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);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] x86/microcode/intel: Some trivial cleanups
  2015-05-17 10:54 [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Borislav Petkov
                   ` (3 preceding siblings ...)
  2015-05-17 10:55 ` [PATCH 4/4] x86/microcode/intel: Rename get_matching_sig() Borislav Petkov
@ 2015-05-21  1:42 ` Henrique de Moraes Holschuh
  4 siblings, 0 replies; 10+ messages in thread
From: Henrique de Moraes Holschuh @ 2015-05-21  1:42 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, Quentin Casasnovas, LKML

On Sun, 17 May 2015, Borislav Petkov wrote:
> 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!

Happy-kudos-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>

-- 
  "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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-05-21  1:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-17 10:54 [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Borislav Petkov
2015-05-17 10:54 ` [PATCH 1/4] x86/microcode/intel: Rename get_matching_microcode Borislav Petkov
2015-05-18  9:10   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
2015-05-17 10:54 ` [PATCH 2/4] x86/microcode/intel: Simplify update_match_cpu() Borislav Petkov
2015-05-18  9:10   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
2015-05-17 10:55 ` [PATCH 3/4] x86/microcode/intel: Simplify get_matching_sig() Borislav Petkov
2015-05-18  9:11   ` [tip:x86/microcode] " tip-bot for Borislav Petkov
2015-05-17 10:55 ` [PATCH 4/4] x86/microcode/intel: Rename get_matching_sig() Borislav Petkov
2015-05-18  9:11   ` [tip:x86/microcode] x86/microcode/intel: Rename get_matching_sig( ) tip-bot for Borislav Petkov
2015-05-21  1:42 ` [PATCH 0/4] x86/microcode/intel: Some trivial cleanups Henrique de Moraes Holschuh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).