All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mce: Do feature check earlier
@ 2017-03-15 17:30 Yazen Ghannam
  2017-03-18 10:56 ` Borislav Petkov
  2017-03-18 12:06 ` [tip:ras/core] x86/mce: Init some CPU features early tip-bot for Yazen Ghannam
  0 siblings, 2 replies; 3+ messages in thread
From: Yazen Ghannam @ 2017-03-15 17:30 UTC (permalink / raw)
  To: linux-edac; +Cc: Yazen Ghannam, Tony Luck, Borislav Petkov, x86, linux-kernel

We may miss some information when errors are logged during boot before the
feature flags are set. For example, on SMCA systems we will not log the
MCA_IPID and MCA_SYND registers and we won't mask MCA_ADDR appropriately.

Move the feature checks before generic init. The rest of the vendor feature
initialization will still happen after generic init.

Signed-off-by: Yazen Ghannam <Yazen.Ghannam@amd.com>
---
 arch/x86/kernel/cpu/mcheck/mce.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 177472a..d1f675b 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1702,14 +1702,9 @@ static int __mcheck_cpu_ancient_init(struct cpuinfo_x86 *c)
 	return 0;
 }
 
-static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
+static void __mcheck_cpu_init_feature_early(struct cpuinfo_x86 *c)
 {
 	switch (c->x86_vendor) {
-	case X86_VENDOR_INTEL:
-		mce_intel_feature_init(c);
-		mce_adjust_timer = cmci_intel_adjust_timer;
-		break;
-
 	case X86_VENDOR_AMD: {
 		mce_flags.overflow_recov = !!cpu_has(c, X86_FEATURE_OVERFLOW_RECOV);
 		mce_flags.succor	 = !!cpu_has(c, X86_FEATURE_SUCCOR);
@@ -1724,7 +1719,6 @@ static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
 			msr_ops.addr	= smca_addr_reg;
 			msr_ops.misc	= smca_misc_reg;
 		}
-		mce_amd_feature_init(c);
 
 		break;
 		}
@@ -1734,6 +1728,24 @@ static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
 	}
 }
 
+static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
+{
+	switch (c->x86_vendor) {
+	case X86_VENDOR_INTEL:
+		mce_intel_feature_init(c);
+		mce_adjust_timer = cmci_intel_adjust_timer;
+		break;
+
+	case X86_VENDOR_AMD: {
+		mce_amd_feature_init(c);
+		break;
+		}
+
+	default:
+		break;
+	}
+}
+
 static void __mcheck_cpu_clear_vendor(struct cpuinfo_x86 *c)
 {
 	switch (c->x86_vendor) {
@@ -1812,6 +1824,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
 
 	machine_check_vector = do_machine_check;
 
+	__mcheck_cpu_init_feature_early(c);
 	__mcheck_cpu_init_generic();
 	__mcheck_cpu_init_vendor(c);
 	__mcheck_cpu_init_clear_banks();
-- 
2.7.4

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

* Re: [PATCH] x86/mce: Do feature check earlier
  2017-03-15 17:30 [PATCH] x86/mce: Do feature check earlier Yazen Ghannam
@ 2017-03-18 10:56 ` Borislav Petkov
  2017-03-18 12:06 ` [tip:ras/core] x86/mce: Init some CPU features early tip-bot for Yazen Ghannam
  1 sibling, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2017-03-18 10:56 UTC (permalink / raw)
  To: Yazen Ghannam; +Cc: linux-edac, Tony Luck, x86, linux-kernel

On Wed, Mar 15, 2017 at 12:30:55PM -0500, Yazen Ghannam wrote:
> We may miss some information when errors are logged during boot before the
> feature flags are set. For example, on SMCA systems we will not log the
> MCA_IPID and MCA_SYND registers and we won't mask MCA_ADDR appropriately.

That paragraph really needs to explain what the problem is more
thoroughly. "We may miss some info" is not enough. I've done it for
you now but please take care to do this in the future.

A good way to structure your commit message is this:

 "The current state of affairs is A. This is a problem (because of B).
 In order to fix this, we should do C."

and then you go and fill in A, B and C. Depending on the issue, that
format won't always fit but it works most of the time. The general idea
is to describe the problem sufficiently so that a reader staring at this
months or even years from now can still understand what the issue was.

It is really important to have those things documented because when we
go and change the code in the future, we'd get a continuous picture of
why we did the things the way we did them then and to be able to change
them again.

Thanks.

---
>From 41492678b23bb87319bc409e1ee513a10f38a6c2 Mon Sep 17 00:00:00 2001
From: Yazen Ghannam <Yazen.Ghannam@amd.com>
Date: Wed, 15 Mar 2017 12:30:55 -0500
Subject: [PATCH] x86/mce: Init some CPU features early

When we poll the MCA banks in __mcheck_cpu_init_generic() for leftover
errors logged during boot or from the previous boot, we need to have
detected CPU features sufficiently so that the reading out and handling
of those early errors is done correctly.

If we don't do it, we may miss some information/get incomplete errors
logged. For example, on SMCA systems we will not log the MCA_IPID and
MCA_SYND registers and we won't mask MCA_ADDR appropriately.

For that, do a subset of the basic feature detection early while the
rest happens in its usual place in __mcheck_cpu_init_vendor().

Signed-off-by: Yazen Ghannam <Yazen.Ghannam@amd.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Cc: x86-ml <x86@kernel.org>
Link: http://lkml.kernel.org/r/1489599055-20756-1-git-send-email-Yazen.Ghannam@amd.com
[ Massage commit message and simplify. ]
Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/cpu/mcheck/mce.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 177472ace838..5e365a2fabe5 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1702,30 +1702,35 @@ static int __mcheck_cpu_ancient_init(struct cpuinfo_x86 *c)
 	return 0;
 }
 
-static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
+/*
+ * Init basic CPU features needed for early decoding of MCEs.
+ */
+static void __mcheck_cpu_init_early(struct cpuinfo_x86 *c)
 {
-	switch (c->x86_vendor) {
-	case X86_VENDOR_INTEL:
-		mce_intel_feature_init(c);
-		mce_adjust_timer = cmci_intel_adjust_timer;
-		break;
-
-	case X86_VENDOR_AMD: {
+	if (c->x86_vendor == X86_VENDOR_AMD) {
 		mce_flags.overflow_recov = !!cpu_has(c, X86_FEATURE_OVERFLOW_RECOV);
 		mce_flags.succor	 = !!cpu_has(c, X86_FEATURE_SUCCOR);
 		mce_flags.smca		 = !!cpu_has(c, X86_FEATURE_SMCA);
 
-		/*
-		 * Install proper ops for Scalable MCA enabled processors
-		 */
 		if (mce_flags.smca) {
 			msr_ops.ctl	= smca_ctl_reg;
 			msr_ops.status	= smca_status_reg;
 			msr_ops.addr	= smca_addr_reg;
 			msr_ops.misc	= smca_misc_reg;
 		}
-		mce_amd_feature_init(c);
+	}
+}
 
+static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
+{
+	switch (c->x86_vendor) {
+	case X86_VENDOR_INTEL:
+		mce_intel_feature_init(c);
+		mce_adjust_timer = cmci_intel_adjust_timer;
+		break;
+
+	case X86_VENDOR_AMD: {
+		mce_amd_feature_init(c);
 		break;
 		}
 
@@ -1812,6 +1817,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
 
 	machine_check_vector = do_machine_check;
 
+	__mcheck_cpu_init_early(c);
 	__mcheck_cpu_init_generic();
 	__mcheck_cpu_init_vendor(c);
 	__mcheck_cpu_init_clear_banks();
-- 
2.11.0

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

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

* [tip:ras/core] x86/mce: Init some CPU features early
  2017-03-15 17:30 [PATCH] x86/mce: Do feature check earlier Yazen Ghannam
  2017-03-18 10:56 ` Borislav Petkov
@ 2017-03-18 12:06 ` tip-bot for Yazen Ghannam
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Yazen Ghannam @ 2017-03-18 12:06 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, bp, hpa, tglx, linux-kernel, x86, linux-edac, tony.luck,
	Yazen.Ghannam

Commit-ID:  5204bf17031b69fa5faa4dc80a9dc1e2446d74f9
Gitweb:     http://git.kernel.org/tip/5204bf17031b69fa5faa4dc80a9dc1e2446d74f9
Author:     Yazen Ghannam <Yazen.Ghannam@amd.com>
AuthorDate: Wed, 15 Mar 2017 12:30:55 -0500
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 18 Mar 2017 13:03:44 +0100

x86/mce: Init some CPU features early

When the MCA banks in __mcheck_cpu_init_generic() are polled for leftover
errors logged during boot or from the previous boot, its required to have
CPU features detected sufficiently so that the reading out and handling of
those early errors is done correctly.

If those features are not available, the decoding may miss some information
and get incomplete errors logged. For example, on SMCA systems the MCA_IPID
and MCA_SYND registers are not logged and MCA_ADDR is not masked
appropriately.

To cure that, do a subset of the basic feature detection early while the
rest happens in its usual place in __mcheck_cpu_init_vendor().

Signed-off-by: Yazen Ghannam <Yazen.Ghannam@amd.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Cc: x86-ml <x86@kernel.org>
Link: http://lkml.kernel.org/r/1489599055-20756-1-git-send-email-Yazen.Ghannam@amd.com
[ Massage commit message and simplify. ]
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/cpu/mcheck/mce.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 177472a..5e365a2 100644
--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -1702,30 +1702,35 @@ static int __mcheck_cpu_ancient_init(struct cpuinfo_x86 *c)
 	return 0;
 }
 
-static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
+/*
+ * Init basic CPU features needed for early decoding of MCEs.
+ */
+static void __mcheck_cpu_init_early(struct cpuinfo_x86 *c)
 {
-	switch (c->x86_vendor) {
-	case X86_VENDOR_INTEL:
-		mce_intel_feature_init(c);
-		mce_adjust_timer = cmci_intel_adjust_timer;
-		break;
-
-	case X86_VENDOR_AMD: {
+	if (c->x86_vendor == X86_VENDOR_AMD) {
 		mce_flags.overflow_recov = !!cpu_has(c, X86_FEATURE_OVERFLOW_RECOV);
 		mce_flags.succor	 = !!cpu_has(c, X86_FEATURE_SUCCOR);
 		mce_flags.smca		 = !!cpu_has(c, X86_FEATURE_SMCA);
 
-		/*
-		 * Install proper ops for Scalable MCA enabled processors
-		 */
 		if (mce_flags.smca) {
 			msr_ops.ctl	= smca_ctl_reg;
 			msr_ops.status	= smca_status_reg;
 			msr_ops.addr	= smca_addr_reg;
 			msr_ops.misc	= smca_misc_reg;
 		}
-		mce_amd_feature_init(c);
+	}
+}
 
+static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
+{
+	switch (c->x86_vendor) {
+	case X86_VENDOR_INTEL:
+		mce_intel_feature_init(c);
+		mce_adjust_timer = cmci_intel_adjust_timer;
+		break;
+
+	case X86_VENDOR_AMD: {
+		mce_amd_feature_init(c);
 		break;
 		}
 
@@ -1812,6 +1817,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
 
 	machine_check_vector = do_machine_check;
 
+	__mcheck_cpu_init_early(c);
 	__mcheck_cpu_init_generic();
 	__mcheck_cpu_init_vendor(c);
 	__mcheck_cpu_init_clear_banks();

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

end of thread, other threads:[~2017-03-18 12:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-15 17:30 [PATCH] x86/mce: Do feature check earlier Yazen Ghannam
2017-03-18 10:56 ` Borislav Petkov
2017-03-18 12:06 ` [tip:ras/core] x86/mce: Init some CPU features early tip-bot for Yazen Ghannam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.