linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/amd_nb: Two fixes
@ 2016-06-16 17:13 Borislav Petkov
  2016-06-16 17:13 ` [PATCH 1/2] x86/amd_nb: Return negative value when no northbridges Borislav Petkov
  2016-06-16 17:13 ` [PATCH 2/2] x86/amd_nb: Cleanup init path Borislav Petkov
  0 siblings, 2 replies; 5+ messages in thread
From: Borislav Petkov @ 2016-06-16 17:13 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Tony Battersby, LKML

From: Borislav Petkov <bp@suse.de>

Hi,

the first one is CC:stable so please queue it for tip:x86/urgent when
you get a chance. The second one is a simple cleanup and can go in 4.8.

Thanks.

Borislav Petkov (2):
  x86/amd_nb: Return negative value when no northbridges
  x86/amd_nb: Cleanup init path

 arch/x86/kernel/amd_nb.c | 41 ++++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 25 deletions(-)

-- 
2.7.3

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

* [PATCH 1/2] x86/amd_nb: Return negative value when no northbridges
  2016-06-16 17:13 [PATCH 0/2] x86/amd_nb: Two fixes Borislav Petkov
@ 2016-06-16 17:13 ` Borislav Petkov
  2016-07-01  7:40   ` [tip:x86/urgent] x86/amd_nb: Fix boot crash on non-AMD systems tip-bot for Borislav Petkov
  2016-06-16 17:13 ` [PATCH 2/2] x86/amd_nb: Cleanup init path Borislav Petkov
  1 sibling, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2016-06-16 17:13 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Tony Battersby, LKML

From: Borislav Petkov <bp@suse.de>

AMD northbridges users call amd_cache_northbridges() and it returns
a negative value to signal that we weren't able to cache/detect any
northbridges on the system.

At least, it should do so as all its callers expect it to do so. But it
does return a negative value only when kmalloc fails.

Fix it to return -ENODEV if there are no NBs cached as otherwise, amd_nb
users like amd64_edac, for example, which relies on it to know whether
it should load or not, gets loaded on systems like Intel Xeons where it
shouldn't.

Reported-and-tested-by: Tony Battersby <tonyb@cybernetics.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/5761BEB0.9000807@cybernetics.com
---
 arch/x86/kernel/amd_nb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index a147e676fc7b..e991d5c8bb3a 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -71,8 +71,8 @@ int amd_cache_northbridges(void)
 	while ((misc = next_northbridge(misc, amd_nb_misc_ids)) != NULL)
 		i++;
 
-	if (i == 0)
-		return 0;
+	if (!i)
+		return -ENODEV;
 
 	nb = kzalloc(i * sizeof(struct amd_northbridge), GFP_KERNEL);
 	if (!nb)
-- 
2.7.3

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

* [PATCH 2/2] x86/amd_nb: Cleanup init path
  2016-06-16 17:13 [PATCH 0/2] x86/amd_nb: Two fixes Borislav Petkov
  2016-06-16 17:13 ` [PATCH 1/2] x86/amd_nb: Return negative value when no northbridges Borislav Petkov
@ 2016-06-16 17:13 ` Borislav Petkov
  2016-07-01  7:46   ` [tip:x86/cpu] x86/amd_nb: Clean up " tip-bot for Borislav Petkov
  1 sibling, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2016-06-16 17:13 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Tony Battersby, LKML

From: Borislav Petkov <bp@suse.de>

The initcall had unnecessary pr_notice() messages which are useless
noise on distro kernels.

Also, push the GART init error message where it belongs, *after* the
check whether the current hw we're loaded on, supports GART at all.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/amd_nb.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index e991d5c8bb3a..e45ec2b4e15e 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -219,24 +219,22 @@ int amd_set_subcaches(int cpu, unsigned long mask)
 	return 0;
 }
 
-static int amd_cache_gart(void)
+static void amd_cache_gart(void)
 {
 	u16 i;
 
-       if (!amd_nb_has_feature(AMD_NB_GART))
-               return 0;
-
-       flush_words = kmalloc(amd_nb_num() * sizeof(u32), GFP_KERNEL);
-       if (!flush_words) {
-               amd_northbridges.flags &= ~AMD_NB_GART;
-               return -ENOMEM;
-       }
+	if (!amd_nb_has_feature(AMD_NB_GART))
+		return;
 
-       for (i = 0; i != amd_nb_num(); i++)
-               pci_read_config_dword(node_to_amd_nb(i)->misc, 0x9c,
-                                     &flush_words[i]);
+	flush_words = kmalloc(amd_nb_num() * sizeof(u32), GFP_KERNEL);
+	if (!flush_words) {
+		amd_northbridges.flags &= ~AMD_NB_GART;
+		pr_notice("Cannot initialize GART flush words, GART support disabled\n");
+		return;
+	}
 
-       return 0;
+	for (i = 0; i != amd_nb_num(); i++)
+		pci_read_config_dword(node_to_amd_nb(i)->misc, 0x9c, &flush_words[i]);
 }
 
 void amd_flush_garts(void)
@@ -278,17 +276,10 @@ EXPORT_SYMBOL_GPL(amd_flush_garts);
 
 static __init int init_amd_nbs(void)
 {
-	int err = 0;
+	amd_cache_northbridges();
+	amd_cache_gart();
 
-	err = amd_cache_northbridges();
-
-	if (err < 0)
-		pr_notice("Cannot enumerate AMD northbridges\n");
-
-	if (amd_cache_gart() < 0)
-		pr_notice("Cannot initialize GART flush words, GART support disabled\n");
-
-	return err;
+	return 0;
 }
 
 /* This has to go after the PCI subsystem */
-- 
2.7.3

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

* [tip:x86/urgent] x86/amd_nb: Fix boot crash on non-AMD systems
  2016-06-16 17:13 ` [PATCH 1/2] x86/amd_nb: Return negative value when no northbridges Borislav Petkov
@ 2016-07-01  7:40   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Borislav Petkov @ 2016-07-01  7:40 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: bp, tonyb, linux-kernel, peterz, stable, torvalds, mingo, tglx, hpa

Commit-ID:  1ead852dd88779eda12cb09cc894a03d9abfe1ec
Gitweb:     http://git.kernel.org/tip/1ead852dd88779eda12cb09cc894a03d9abfe1ec
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Thu, 16 Jun 2016 19:13:49 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 1 Jul 2016 09:35:35 +0200

x86/amd_nb: Fix boot crash on non-AMD systems

Fix boot crash that triggers if this driver is built into a kernel and
run on non-AMD systems.

AMD northbridges users call amd_cache_northbridges() and it returns
a negative value to signal that we weren't able to cache/detect any
northbridges on the system.

At least, it should do so as all its callers expect it to do so. But it
does return a negative value only when kmalloc() fails.

Fix it to return -ENODEV if there are no NBs cached as otherwise, amd_nb
users like amd64_edac, for example, which relies on it to know whether
it should load or not, gets loaded on systems like Intel Xeons where it
shouldn't.

Reported-and-tested-by: Tony Battersby <tonyb@cybernetics.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1466097230-5333-2-git-send-email-bp@alien8.de
Link: https://lkml.kernel.org/r/5761BEB0.9000807@cybernetics.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/amd_nb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index a147e67..e991d5c 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -71,8 +71,8 @@ int amd_cache_northbridges(void)
 	while ((misc = next_northbridge(misc, amd_nb_misc_ids)) != NULL)
 		i++;
 
-	if (i == 0)
-		return 0;
+	if (!i)
+		return -ENODEV;
 
 	nb = kzalloc(i * sizeof(struct amd_northbridge), GFP_KERNEL);
 	if (!nb)

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

* [tip:x86/cpu] x86/amd_nb: Clean up init path
  2016-06-16 17:13 ` [PATCH 2/2] x86/amd_nb: Cleanup init path Borislav Petkov
@ 2016-07-01  7:46   ` tip-bot for Borislav Petkov
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Borislav Petkov @ 2016-07-01  7:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, hpa, mingo, bp, tglx, linux-kernel, tonyb, torvalds

Commit-ID:  09c6c30e72ce6892b21e6cf76b4508ad82a38636
Gitweb:     http://git.kernel.org/tip/09c6c30e72ce6892b21e6cf76b4508ad82a38636
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Thu, 16 Jun 2016 19:13:50 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 1 Jul 2016 09:36:12 +0200

x86/amd_nb: Clean up init path

The initcall had unnecessary pr_notice() messages which are useless
noise on distro kernels.

Also, push the GART init error message where it belongs, *after* the
check whether the current hw we're loaded on, supports GART at all.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tony Battersby <tonyb@cybernetics.com>
Link: http://lkml.kernel.org/r/1466097230-5333-3-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/amd_nb.c | 37 ++++++++++++++-----------------------
 1 file changed, 14 insertions(+), 23 deletions(-)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index e991d5c..e45ec2b 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -219,24 +219,22 @@ int amd_set_subcaches(int cpu, unsigned long mask)
 	return 0;
 }
 
-static int amd_cache_gart(void)
+static void amd_cache_gart(void)
 {
 	u16 i;
 
-       if (!amd_nb_has_feature(AMD_NB_GART))
-               return 0;
-
-       flush_words = kmalloc(amd_nb_num() * sizeof(u32), GFP_KERNEL);
-       if (!flush_words) {
-               amd_northbridges.flags &= ~AMD_NB_GART;
-               return -ENOMEM;
-       }
+	if (!amd_nb_has_feature(AMD_NB_GART))
+		return;
 
-       for (i = 0; i != amd_nb_num(); i++)
-               pci_read_config_dword(node_to_amd_nb(i)->misc, 0x9c,
-                                     &flush_words[i]);
+	flush_words = kmalloc(amd_nb_num() * sizeof(u32), GFP_KERNEL);
+	if (!flush_words) {
+		amd_northbridges.flags &= ~AMD_NB_GART;
+		pr_notice("Cannot initialize GART flush words, GART support disabled\n");
+		return;
+	}
 
-       return 0;
+	for (i = 0; i != amd_nb_num(); i++)
+		pci_read_config_dword(node_to_amd_nb(i)->misc, 0x9c, &flush_words[i]);
 }
 
 void amd_flush_garts(void)
@@ -278,17 +276,10 @@ EXPORT_SYMBOL_GPL(amd_flush_garts);
 
 static __init int init_amd_nbs(void)
 {
-	int err = 0;
+	amd_cache_northbridges();
+	amd_cache_gart();
 
-	err = amd_cache_northbridges();
-
-	if (err < 0)
-		pr_notice("Cannot enumerate AMD northbridges\n");
-
-	if (amd_cache_gart() < 0)
-		pr_notice("Cannot initialize GART flush words, GART support disabled\n");
-
-	return err;
+	return 0;
 }
 
 /* This has to go after the PCI subsystem */

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

end of thread, other threads:[~2016-07-01  8:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 17:13 [PATCH 0/2] x86/amd_nb: Two fixes Borislav Petkov
2016-06-16 17:13 ` [PATCH 1/2] x86/amd_nb: Return negative value when no northbridges Borislav Petkov
2016-07-01  7:40   ` [tip:x86/urgent] x86/amd_nb: Fix boot crash on non-AMD systems tip-bot for Borislav Petkov
2016-06-16 17:13 ` [PATCH 2/2] x86/amd_nb: Cleanup init path Borislav Petkov
2016-07-01  7:46   ` [tip:x86/cpu] x86/amd_nb: Clean up " tip-bot for Borislav Petkov

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