Skip to contentSkip to conversation

New way to track mce notifier chain actions

RFC PATCH Superseded Tony Luck 8 participants 63 messages Feb 12, 2020 – Apr 20, 2020

Subsystems (11)
lore
Share & tools
lore

Tony Luck

author maintainer
#0 lore raw

cover New way to track mce notifier chain actions

This is just a skeleton of how it might look. Several issues arose while looking at this ... not all directly related to the problem at hand.

Parts 1 & 2 are just cleanup. CEC should follow the same rules as everyone else who wants to be on the mce notifier chain. No real reason for it to have direct hooks into mce/core.c

Part 3 adds a field to struct mce, and defines the BIT fields for each class of notifier. All EDAC drivers share the same BIT since only one of them should be active.

Part 4 is where things are interesting and need a great deal more thought. A bunch of things on the chain return NOTIFY_STOP which prevents anything else on the chain from being run. For the moment I ignored that semantic and added code everywhere to set the BIT even though nobody else will see it. This is because I think at least some of them should NOT be NOTIFY_STOP.

Part 5 is currently written to always call __print_mce() for debugging. The "if (1 || ...)" obviously doesn't want the "1" (though I'd like to add some /sys knob to flip a switch to force printing for systems where something weird is happening and logs are being lost).

Tony Luck (5):
x86/mce: Rename "first" function as "early"
x86/mce: Convert corrected error collector to use mce notifier x86/mce: Add new "handled" field to "struct mce" x86/mce: Fix all mce notifiers to update the mce->handled bitmask x86/mce: Change default mce logger to check mce->handled

 arch/x86/include/asm/mce.h           | 15 ++++----
 arch/x86/include/uapi/asm/mce.h      |  9 +++++
 arch/x86/kernel/cpu/mce/core.c       | 53 +++++++---------------------
 arch/x86/kernel/cpu/mce/dev-mcelog.c |  1 +
 drivers/acpi/acpi_extlog.c           |  1 +
 drivers/acpi/nfit/mce.c              |  1 +
 drivers/edac/i7core_edac.c           |  1 +
 drivers/edac/mce_amd.c               |  5 ++-
 drivers/edac/pnd2_edac.c             |  1 +
 drivers/edac/sb_edac.c               |  1 +
 drivers/edac/skx_common.c            |  1 +
 drivers/ras/cec.c                    | 29 +++++++++++++++
 12 files changed, 69 insertions(+), 49 deletions(-)
Signature · 1 line
2.21.1
author maintainer
#1 lore raw

PATCH 1/5 x86/mce: Rename "first" function as "early"

It isn't going to be first on the notifier chain when we move the CEC code to be a normal user of the notifier chain.

Fix the enum for the MCE_PRIO symbols to list them in reverse order so that the compiler can give them numbers from low to high priority. Add an entry for MCE_PRIO_CEC as the highest priority.

---
 arch/x86/include/asm/mce.h     | 15 ++++++++-------
 arch/x86/kernel/cpu/mce/core.c | 10 +++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/mce.h +8 -7
index 4359b955e0b7..6f17cc618d5e 100644
@@ -143,13 +143,14 @@ struct mce_log_buffer {
 };
 
 enum mce_notifier_prios {
-	MCE_PRIO_FIRST		= INT_MAX,
-	MCE_PRIO_UC		= INT_MAX - 1,
-	MCE_PRIO_EXTLOG		= INT_MAX - 2,
-	MCE_PRIO_NFIT		= INT_MAX - 3,
-	MCE_PRIO_EDAC		= INT_MAX - 4,
-	MCE_PRIO_MCELOG		= 1,
-	MCE_PRIO_LOWEST		= 0,
+	MCE_PRIO_LOWEST,
+	MCE_PRIO_MCELOG,
+	MCE_PRIO_EDAC,
+	MCE_PRIO_NFIT,
+	MCE_PRIO_EXTLOG,
+	MCE_PRIO_UC,
+	MCE_PRIO_EARLY,
+	MCE_PRIO_CEC
 };
 
 struct notifier_block;
arch/x86/kernel/cpu/mce/core.c +5 -5
index 2c4f949611e4..3366807d8e58 100644
@@ -557,7 +557,7 @@ static bool cec_add_mce(struct mce *m)
 	return false;
 }
 
-static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
+static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
 	struct mce *m = (struct mce *)data;
@@ -578,9 +578,9 @@ static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
 	return NOTIFY_DONE;
 }
 
-static struct notifier_block first_nb = {
-	.notifier_call	= mce_first_notifier,
-	.priority	= MCE_PRIO_FIRST,
+static struct notifier_block early_nb = {
+	.notifier_call	= mce_early_notifier,
+	.priority	= MCE_PRIO_EARLY,
 };
 
 static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
@@ -2028,7 +2028,7 @@ __setup("mce", mcheck_enable);
 int __init mcheck_init(void)
 {
 	mcheck_intel_therm_init();
-	mce_register_decode_chain(&first_nb);
+	mce_register_decode_chain(&early_nb);
 	mce_register_decode_chain(&mce_uc_nb);
 	mce_register_decode_chain(&mce_default_nb);
 	mcheck_vendor_init_severity();
Signature · 1 line
2.21.1
author maintainer
#15 lore raw

PATCH 5/5 x86/mce: Change default mce logger to check mce->handled

In reply to Tony Luck

Instead of keeping count of how many handlers are registered on the mce chain and printing if we are below some magic value. Look at the mce->handled to see if anyone claims to have handled/logged this error.

[debug to always print in this version]

---
 arch/x86/kernel/cpu/mce/core.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/mce/core.c +4 -16
index ce7a78872f8f..5b73df383300 100644
@@ -156,29 +156,17 @@ void mce_log(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_log);
 
-/*
- * We run the default notifier if we have only the UC, the first and the
- * default notifier registered. I.e., the mandatory NUM_DEFAULT_NOTIFIERS
- * notifiers registered on the chain.
- */
-#define NUM_DEFAULT_NOTIFIERS	3
-static atomic_t num_notifiers;
-
 void mce_register_decode_chain(struct notifier_block *nb)
 {
 	if (WARN_ON(nb->priority > MCE_PRIO_MCELOG && nb->priority < MCE_PRIO_EDAC))
 		return;
 
-	atomic_inc(&num_notifiers);
-
 	blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_register_decode_chain);
 
 void mce_unregister_decode_chain(struct notifier_block *nb)
 {
-	atomic_dec(&num_notifiers);
-
 	blocking_notifier_chain_unregister(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
@@ -261,6 +249,8 @@ static void __print_mce(struct mce *m)
 	}
 
 	pr_cont("\n");
+	if (m->handled)
+		pr_emerg(HW_ERR "handled = %x\n", m->handled);
 	/*
 	 * Note this output is parsed by external tools and old fields
 	 * should not be changed.
@@ -600,10 +590,8 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (atomic_read(&num_notifiers) > NUM_DEFAULT_NOTIFIERS)
-		return NOTIFY_DONE;
-
-	__print_mce(m);
+	if (1 || !m->handled)
+		__print_mce(m);
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.21.1
author maintainer
#2 lore raw

PATCH 2/5 x86/mce: Convert corrected error collector to use mce notifier

In reply to Tony Luck

The CEC code has its claws in a couple of routines in mce/core.c

Convert it to just register itself on the normal mce notifier chain.

---
 arch/x86/kernel/cpu/mce/core.c | 19 -------------------
 drivers/ras/cec.c              | 26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 19 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -19
index 3366807d8e58..06240cbe6f3e 100644
@@ -542,21 +542,6 @@ bool mce_is_correctable(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_is_correctable);
 
-static bool cec_add_mce(struct mce *m)
-{
-	if (!m)
-		return false;
-
-	/* We eat only correctable DRAM errors with usable addresses. */
-	if (mce_is_memory_error(m) &&
-	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return true;
-
-	return false;
-}
-
 static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
@@ -565,9 +550,6 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (cec_add_mce(m))
-		return NOTIFY_STOP;
-
 	/* Emit the trace record: */
 	trace_mce_record(m);
 
@@ -2588,7 +2570,6 @@ static int __init mcheck_late_init(void)
 		static_branch_inc(&mcsafe_key);
 
 	mcheck_debugfs_init();
-	cec_init();
 
 	/*
 	 * Flush out everything that has been logged during early boot, now that
drivers/ras/cec.c +26 -0
index c09cf55e2d20..d7f6718cbf8d 100644
@@ -527,6 +527,29 @@ static int __init create_debugfs_nodes(void)
 	return 1;
 }
 
+static int cec_notifier(struct notifier_block *nb, unsigned long val,
+			void *data)
+{
+	struct mce *m = (struct mce *)data;
+
+	if (!m)
+		return NOTIFY_DONE;
+
+	/* We eat only correctable DRAM errors with usable addresses. */
+	if (mce_is_memory_error(m) &&
+	    mce_is_correctable(m)  &&
+	    mce_usable_address(m))
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
+			return NOTIFY_STOP;
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block cec_nb = {
+	.notifier_call	= cec_notifier,
+	.priority	= MCE_PRIO_CEC,
+};
+
 void __init cec_init(void)
 {
 	if (ce_arr.disabled)
@@ -546,8 +569,11 @@ void __init cec_init(void)
 	INIT_DELAYED_WORK(&cec_work, cec_work_fn);
 	schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL);
 
+	mce_register_decode_chain(&cec_nb);
+
 	pr_info("Correctable Errors collector initialized.\n");
 }
+late_initcall(cec_init);
 
 int __init parse_cec_param(char *str)
 {
Signature · 1 line
2.21.1
author maintainer
#7 lore raw

PATCH 4/5 x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->handled so that the default handler on the end of the machine check chain can see what has been done.

[!!! What to do about NOTIFY_STOP ... any handler that returns this value short-circuits calling subsequent entries on the chain. In some cases this may be the right thing to do ... but it others we really want to keep calling other functions on the chain]

---
 arch/x86/kernel/cpu/mce/core.c       | 4 +++-
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 1 +
 drivers/acpi/acpi_extlog.c           | 1 +
 drivers/acpi/nfit/mce.c              | 1 +
 drivers/edac/i7core_edac.c           | 1 +
 drivers/edac/mce_amd.c               | 5 ++++-
 drivers/edac/pnd2_edac.c             | 1 +
 drivers/edac/sb_edac.c               | 1 +
 drivers/edac/skx_common.c            | 1 +
 drivers/ras/cec.c                    | 7 +++++--
 10 files changed, 19 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -1
index 06240cbe6f3e..ce7a78872f8f 100644
@@ -579,8 +579,10 @@ static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
 		return NOTIFY_DONE;
 
 	pfn = mce->addr >> PAGE_SHIFT;
-	if (!memory_failure(pfn, 0))
+	if (!memory_failure(pfn, 0)) {
 		set_mce_nospec(pfn);
+		mce->handled |= MCE_HANDLED_UC;
+	}
 
 	return NOTIFY_OK;
 }
arch/x86/kernel/cpu/mce/dev-mcelog.c +1 -0
index 7c8958dee103..83d83c210ab9 100644
@@ -67,6 +67,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 unlock:
 	mutex_unlock(&mce_chrdev_read_mutex);
 
+	mce->handled |= MCE_HANDLED_MCELOG;
 	return NOTIFY_OK;
 }
 
drivers/acpi/acpi_extlog.c +1 -0
index 8596a106a933..f7617831ee74 100644
@@ -176,6 +176,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	}
 
 out:
+	mce->handled |= MCE_HANDLED_EXTLOG;
 	return NOTIFY_STOP;
 }
 
drivers/acpi/nfit/mce.c +1 -0
index f0ae48515b48..c81c879610d6 100644
@@ -76,6 +76,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
 			 */
 			acpi_nfit_ars_rescan(acpi_desc, 0);
 		}
+		mce->handled |= MCE_HANDLED_NFIT;
 		break;
 	}
 
drivers/edac/i7core_edac.c +1 -0
index b3135b208f9a..727d444e0ac0 100644
@@ -1834,6 +1834,7 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	i7core_check_error(mci, mce);
 
 	/* Advise mcelog that the errors were handled */
+	mce->handled |= MCE_HANDLED_EDAC;
 	return NOTIFY_STOP;
 }
 
drivers/edac/mce_amd.c +4 -1
index ea980c556f2e..693b0c00b714 100644
@@ -1067,8 +1067,10 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
-	if (ignore_mce(m))
+	if (ignore_mce(m)) {
+		m->handled |= MCE_HANDLED_EDAC;
 		return NOTIFY_STOP;
+	}
 
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
@@ -1170,6 +1172,7 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
  err_code:
 	amd_decode_err_code(m->status & 0xffff);
 
+	m->handled |= MCE_HANDLED_EDAC;
 	return NOTIFY_STOP;
 }
 
drivers/edac/pnd2_edac.c +1 -0
index 933f7722b893..6c2dee16f4e9 100644
@@ -1429,6 +1429,7 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	pnd2_mce_output_error(mci, mce, &daddr);
 
 	/* Advice mcelog that the error were handled */
+	mce->handled |= MCE_HANDLED_EDAC;
 	return NOTIFY_STOP;
 }
 
drivers/edac/sb_edac.c +1 -0
index 4957e8ee1879..93dd92f8c9bd 100644
@@ -3183,6 +3183,7 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	sbridge_mce_output_error(mci, mce);
 
 	/* Advice mcelog that the error were handled */
+	mce->handled |= MCE_HANDLED_EDAC;
 	return NOTIFY_STOP;
 }
 
drivers/edac/skx_common.c +1 -0
index 99bbaf629b8d..1501c8aeb980 100644
@@ -616,6 +616,7 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	skx_mce_output_error(mci, mce, &res);
 
+	mce->handled |= MCE_HANDLED_EDAC;
 	return NOTIFY_DONE;
 }
 
drivers/ras/cec.c +5 -2
index d7f6718cbf8d..a993ffacfe9d 100644
@@ -538,9 +538,12 @@ static int cec_notifier(struct notifier_block *nb, unsigned long val,
 	/* We eat only correctable DRAM errors with usable addresses. */
 	if (mce_is_memory_error(m) &&
 	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
+	    mce_usable_address(m)) {
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT)) {
+			m->handled |= MCE_HANDLED_CEC;
 			return NOTIFY_STOP;
+		}
+	}
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.21.1
author maintainer
#3 lore raw

PATCH 3/5 x86/mce: Add new "handled" field to "struct mce"

In reply to Tony Luck

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

The default handler at the end of the chain can use this information to decide whether to print to the console log.

---
 arch/x86/include/uapi/asm/mce.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/include/uapi/asm/mce.h +9 -0
index 955c2a2e1cf9..99ca07f7b078 100644
@@ -35,8 +35,17 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u32 handled;		/* Bitmap of logging/handling actions */
 };
 
+/* handled flag bits */
+#define	MCE_HANDLED_CEC		BIT(0)
+#define	MCE_HANDLED_UC		BIT(1)
+#define	MCE_HANDLED_EXTLOG	BIT(2)
+#define	MCE_HANDLED_NFIT	BIT(3)
+#define	MCE_HANDLED_EDAC	BIT(4)
+#define	MCE_HANDLED_MCELOG	BIT(5)
+
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
 #define MCE_GET_LOG_LEN      _IOR('M', 2, int)
 #define MCE_GETCLEAR_FLAGS   _IOR('M', 3, int)
Signature · 1 line
2.21.1
author maintainer
#19 lore raw
In reply to Tony Luck
Quoted 6 lines · Tony Luck

Part 4 is where things are interesting and need a great deal more thought. A bunch of things on the chain return NOTIFY_STOP which prevents anything else on the chain from being run. For the moment I ignored that semantic and added code everywhere to set the BIT even though nobody else will see it. This is because I think at least some of them should NOT be NOTIFY_STOP.

NOTIFY_STOP is just one mechanism for preventing every function on the mce chain from reporting an error.

The other bit I'd like to reconsider is edac_get_report_status(). Back in the day we seemed to be paranoid about reporting the same error more than once via all the different reporting mechanisms.

Since then I've had to track down numerous "Why didn't this error get reported?" questions that frequently resolved to "It was reported, but not in the place that you expected".

So now my attitude is "Let's just log it everywhere in so that whatever log the user is checking, they'll find the error".

-Tony

#20 lore raw
Quoted 16 lines · Tony
Quoted 6 lines · Tony Luck

Part 4 is where things are interesting and need a great deal more thought. A bunch of things on the chain return NOTIFY_STOP which prevents anything else on the chain from being run. For the moment I ignored that semantic and added code everywhere to set the BIT even though nobody else will see it. This is because I think at least some of them should NOT be NOTIFY_STOP.

NOTIFY_STOP is just one mechanism for preventing every function on the mce chain from reporting an error.

The other bit I'd like to reconsider is edac_get_report_status(). Back in the day we seemed to be paranoid about reporting the same error more than once via all the different reporting mechanisms.

Quoted 6 lines

Since then I've had to track down numerous "Why didn't this error get reported?" questions that frequently resolved to "It was reported, but not in the place that you expected".

So now my attitude is "Let's just log it everywhere in so that whatever log the user is checking, they'll find the error"

I HATE notifier chains for exceptions, and I REALLY HATE NOTIFY_STOP. I don't suppose we could rig something up so that they are simply notifiers (for MCE and, eventually, for everything) and just outright prevent them from modifying the processing?

As an example that particularly bothers me, do_debug():

        if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
                                                        SIGTRAP) == NOTIFY_STOP)
                goto exit;

There is all kind of garbage hidden in there, and it's mostly somewhere between slightly buggy and violently buggy. All this crap should be open-coded.

maintainer
#21 lore raw
Quoted 4 lines · Andy Lutomirski

I HATE notifier chains for exceptions, and I REALLY HATE NOTIFY_STOP. I don't suppose we could rig something up so that they are simply notifiers (for MCE and, eventually, for everything) and just outright prevent them from modifying the processing?

As in: they all get executed unconditionally and there's no NOTIFY_STOP and if they're not interested in the notification, they simply return early?

Hohumm, sounds nicer.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#22 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 4 lines · Andy Lutomirski

I HATE notifier chains for exceptions, and I REALLY HATE NOTIFY_STOP. I don't suppose we could rig something up so that they are simply notifiers (for MCE and, eventually, for everything) and just outright prevent them from modifying the processing?

Quoted 6 lines

As in: they all get executed unconditionally and there's no NOTIFY_STOP and if they're not interested in the notification, they simply return early?

Hohumm, sounds nicer.

Exactly :)

Quoted 5 lines
Signature · 4 lines
Regards/Gruss,
   Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#4 lore raw

Re: [PATCH 3/5] x86/mce: Add new "handled" field to "struct mce"

In reply to Tony Luck
Quoted 26 lines · Tony Luck

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

The default handler at the end of the chain can use this information to decide whether to print to the console log.

---
 arch/x86/include/uapi/asm/mce.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/include/uapi/asm/mce.h +2 -0
index 955c2a2e1cf9..99ca07f7b078 100644
@@ -35,8 +35,17 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u32 handled;		/* Bitmap of logging/handling actions */
 };
 
+/* handled flag bits */

arch/x86/include/uapi/asm/mce.h struct mce { · line 51

Quoted 10 lines
arch/x86/include/uapi/asm/mce.h +7 -0
+#define	MCE_HANDLED_CEC		BIT(0)
+#define	MCE_HANDLED_UC		BIT(1)
+#define	MCE_HANDLED_EXTLOG	BIT(2)
+#define	MCE_HANDLED_NFIT	BIT(3)
+#define	MCE_HANDLED_EDAC	BIT(4)
+#define	MCE_HANDLED_MCELOG	BIT(5)
+
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
 #define MCE_GET_LOG_LEN      _IOR('M', 2, int)
 #define MCE_GETCLEAR_FLAGS   _IOR('M', 3, int)

Not sure if this should be exposed to user. I don't think it has any business poking its nose into how the MCE was handled. Or maybe it does but I cannot think of a good example ATM.

If not, this could be

	...
	void *private;
};

which userspace can't make any assumptions about. And we can put whatever we need in there...

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#8 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Tony Luck
Quoted 8 lines · Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->handled so that the default handler on the end of the machine check chain can see what has been done.

[!!! What to do about NOTIFY_STOP ... any handler that returns this value short-circuits calling subsequent entries on the chain. In some cases this may be the right thing to do ... but it others we really want to keep calling other functions on the chain]

Yes, we can kill that NOTIFY_STOP thing in the mce code since it is nasty.

Then, from the looks of it, there should be a function at the end of the chain which decides whether to print or not, just by looking at ->handled.

For example, it should not print MCE_HANDLED_CEC or MCE_HANDLED_EDAC, etc cases. The assumption for the latter being that EDAC does its own printing. Which then makes me wonder whether MCE_HANDLED_EDAC is enough.

Because this one bit would basically determine whether the error gets printed or not. Which would mean that all EDAC drivers should print it...

All I'm saying is, we should think about modalities like that.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#16 lore raw

Re: [PATCH 5/5] x86/mce: Change default mce logger to check mce->handled

In reply to Tony Luck
Quoted 17 lines · Tony Luck

Instead of keeping count of how many handlers are registered on the mce chain and printing if we are below some magic value. Look at the mce->handled to see if anyone claims to have handled/logged this error.

[debug to always print in this version]

---
 arch/x86/kernel/cpu/mce/core.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -0
index ce7a78872f8f..5b73df383300 100644
@@ -156,29 +156,17 @@ void mce_log(struct mce *m)
 }

arch/x86/kernel/cpu/mce/core.c void mce_log(struct mce *m) · line 166

Quoted 10 lines
arch/x86/kernel/cpu/mce/core.c +0 -8
 EXPORT_SYMBOL_GPL(mce_log);
 
-/*
- * We run the default notifier if we have only the UC, the first and the
- * default notifier registered. I.e., the mandatory NUM_DEFAULT_NOTIFIERS
- * notifiers registered on the chain.
- */
-#define NUM_DEFAULT_NOTIFIERS	3
-static atomic_t num_notifiers;
-

I definitely like where this is going.

Another thing: what do we do if we have to deviate from that sequantial path through the notifiers? What if notifier A gets to look at an error, then another notifier B needs to look at it and then the information obtained from the second notifier B, is needed by the first notifier A again to inspect the error a *second* time.

I don't think there's a case like that now but I'm just playing the devil's advocate here. Because a use case like that would break our simplistic, sequential assembly line of MCE decoding.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#5 lore raw

Re: [PATCH 3/5] x86/mce: Add new "handled" field to "struct mce"

In reply to Borislav Petkov
Quoted 42 lines · Borislav Petkov
Quoted 26 lines · Tony Luck

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

The default handler at the end of the chain can use this information to decide whether to print to the console log.

---
 arch/x86/include/uapi/asm/mce.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/include/uapi/asm/mce.h +2 -0
index 955c2a2e1cf9..99ca07f7b078 100644
@@ -35,8 +35,17 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u32 handled;		/* Bitmap of logging/handling actions */
 };
 
+/* handled flag bits */

arch/x86/include/uapi/asm/mce.h struct mce { · line 51

Quoted 10 lines
arch/x86/include/uapi/asm/mce.h +7 -0
+#define	MCE_HANDLED_CEC		BIT(0)
+#define	MCE_HANDLED_UC		BIT(1)
+#define	MCE_HANDLED_EXTLOG	BIT(2)
+#define	MCE_HANDLED_NFIT	BIT(3)
+#define	MCE_HANDLED_EDAC	BIT(4)
+#define	MCE_HANDLED_MCELOG	BIT(5)
+
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
 #define MCE_GET_LOG_LEN      _IOR('M', 2, int)
 #define MCE_GETCLEAR_FLAGS   _IOR('M', 3, int)

Not sure if this should be exposed to user. I don't think it has any business poking its nose into how the MCE was handled. Or maybe it does but I cannot think of a good example ATM.

Quoted 8 lines

If not, this could be

	...
	void *private;
};

which userspace can't make any assumptions about. And we can put whatever we need in there...

I can see various ways to spin this:

1) It is useful to user mode. The mcelog(8) daemon (or other consumer of "struct mce") gets a record of where to look for logs from this record. This could reduce the anxiety about logging the same item multiple times. Its a bit weird though because each entity logging only sees who came before them, not who came after.
2) Not useful
2a) Keep it in the structure, but clear it in copies shown to user 2b) Make a *private to point to such things (but that really
complicates allocation of struct mce ... right now we just have local copies on kernel stack)
2c) Make a wrapper structure:
struct kernel_mce {
struct mce mce;
u32 handled;
... other hidden stuff ...
};

-Tony

author maintainer
#9 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Borislav Petkov
Quoted 5 lines · Borislav Petkov
Quoted 4 lines · Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->handled so that the default handler on the end of the machine check chain can see what has been done.

Quoted 7 lines
Quoted 4 lines

[!!! What to do about NOTIFY_STOP ... any handler that returns this value short-circuits calling subsequent entries on the chain. In some cases this may be the right thing to do ... but it others we really want to keep calling other functions on the chain]

Yes, we can kill that NOTIFY_STOP thing in the mce code since it is nasty.

Well, there are places where we want to keep NOTIFY_STOP.

1) Default case for CEC. We want it to "hide" the corrected error. That was one of the main goals for CEC. We've discussed cases where CEC shouldn't hide (when internal threshold exceeded and it tries to take a page offline ... probably something related to CMCI storms ... though we didn't really come to any conclusion)
2) Errata. Perhaps a vendor/platform specific function at the head of the notify chain that weeds out errors that should never have been reported.

Quoted 3 lines

Then, from the looks of it, there should be a function at the end of the chain which decides whether to print or not, just by looking at ->handled.

That's there now. See mce_default_notifier()

Quoted 3 lines

For example, it should not print MCE_HANDLED_CEC or MCE_HANDLED_EDAC, etc cases. The assumption for the latter being that EDAC does its own printing. Which then makes me wonder whether MCE_HANDLED_EDAC is enough.

But may need some refining.

Quoted 3 lines

Because this one bit would basically determine whether the error gets printed or not. Which would mean that all EDAC drivers should print it...

Alternative wording "An EDAC driver should only set the bit if it printed something useful about the error."

-Tony

#10 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

Quoted 12 lines · Tony
Quoted 10 lines · Borislav Petkov
Quoted 8 lines · Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->handled so that the default handler on the end of the machine check chain can see what has been done.

[!!! What to do about NOTIFY_STOP ... any handler that returns this value short-circuits calling subsequent entries on the chain. In some cases this may be the right thing to do ... but it others we really want to keep calling other functions on the chain]

Quoted 4 lines
Quoted 2 lines

Yes, we can kill that NOTIFY_STOP thing in the mce code since it is nasty.

Well, there are places where we want to keep NOTIFY_STOP.

I very very strongly disagree.

Quoted 6 lines

1) Default case for CEC. We want it to "hide" the corrected error. That was one of the main goals for CEC. We've discussed cases where CEC shouldn't hide (when internal threshold exceeded and it tries to take a page offline ... probably something related to CMCI storms ... though we didn't really come to any conclusion)

Then put this logic in do_machine_check() or in some sensible place that it calls via some ops structure or directly. Don't hide it in some incomprehensible, possibly nondeterministic place in a notifier chain.

Quoted 3 lines

2) Errata. Perhaps a vendor/platform specific function at the head of the notify chain that weeds out errors that should never have been reported.

No, do this before the notifier chain please.

AMA Capital Management, LLC

author maintainer
#17 lore raw

Re: [PATCH 5/5] x86/mce: Change default mce logger to check mce->handled

In reply to Borislav Petkov
Quoted 1 line · Borislav Petkov

I definitely like where this is going.

Thanks.

Quoted 5 lines

Another thing: what do we do if we have to deviate from that sequantial path through the notifiers? What if notifier A gets to look at an error, then another notifier B needs to look at it and then the information obtained from the second notifier B, is needed by the first notifier A again to inspect the error a *second* time.

That's pretty hard with a chain. I think folks will have a conniptions if we invent an error return from a notifier chain function that means "Go back and start over". Though if we did it would make the "handled" field useful for functions that didn't want to redo ... they'd just check if "their" bit in handled was already set.

Still, seems like a terrible idea.

Quoted 3 lines

I don't think there's a case like that now but I'm just playing the devil's advocate here. Because a use case like that would break our simplistic, sequential assembly line of MCE decoding.

If some driver really wants multiple bites at an error on the chain it could register more than one handler with different priorities. In which case we should have "enum" names for the highest and lowest priorities so such a driver can go "first" or "last" (though such a thing would be dependent on whether some other driver was attempting to add a "first" or "last" entry on the chain).

-Tony

author maintainer
#11 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Andy Lutomirski
Quoted 27 lines · Andy Lutomirski
Quoted 12 lines · Tony
Quoted 10 lines · Borislav Petkov
Quoted 8 lines · Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->handled so that the default handler on the end of the machine check chain can see what has been done.

[!!! What to do about NOTIFY_STOP ... any handler that returns this value short-circuits calling subsequent entries on the chain. In some cases this may be the right thing to do ... but it others we really want to keep calling other functions on the chain]

Quoted 4 lines
Quoted 2 lines

Yes, we can kill that NOTIFY_STOP thing in the mce code since it is nasty.

Well, there are places where we want to keep NOTIFY_STOP.

I very very strongly disagree.

Quoted 6 lines

1) Default case for CEC. We want it to "hide" the corrected error. That was one of the main goals for CEC. We've discussed cases where CEC shouldn't hide (when internal threshold exceeded and it tries to take a page offline ... probably something related to CMCI storms ... though we didn't really come to any conclusion)

Quoted 4 lines

Then put this logic in do_machine_check() or in some sensible place that it calls via some ops structure or directly. Don't hide it in some incomprehensible, possibly nondeterministic place in a notifier chain.

I could make the EDAC driver (and others on the chain) check to see if CEC already handled the error record:

		if (mce->handled & MCE_HANDLED_CEC)
			return NOTIFY_DONE;

Then everyone on the chain still sees the error ... just some of them make informed decisions based on what functions earlier in the chain did with the error record.

Quoted 5 lines
Quoted 3 lines

2) Errata. Perhaps a vendor/platform specific function at the head of the notify chain that weeds out errors that should never have been reported.

No, do this before the notifier chain please.

Ok. We don't have code that does this yet. If we need some, I'll make sure to do the weed out before it gets to the notifier.

-Tony

#13 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Andy Lutomirski
Quoted 13 lines · Andy Lutomirski
Quoted 12 lines · Tony
Quoted 10 lines · Borislav Petkov
Quoted 8 lines · Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->handled so that the default handler on the end of the machine check chain can see what has been done.

[!!! What to do about NOTIFY_STOP ... any handler that returns this value short-circuits calling subsequent entries on the chain. In some cases this may be the right thing to do ... but it others we really want to keep calling other functions on the chain]

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Yes, we can kill that NOTIFY_STOP thing in the mce code since it is nasty.

Well, there are places where we want to keep NOTIFY_STOP.

I very very strongly disagree.

Ack. The unholy mess of cpu hotplug notifiers and the at least 50 bugs which were unearthed by converting them to a comprehensible and symmetric state machine have documented the insanity of notifiers nicely.

Quoted 11 lines
Quoted 5 lines

1) Default case for CEC. We want it to "hide" the corrected error. That was one of the main goals for CEC. We've discussed cases where CEC shouldn't hide (when internal threshold exceeded and it tries to take a page offline ... probably something related to CMCI storms ... though we didn't really come to any conclusion)

Then put this logic in do_machine_check() or in some sensible place that it calls via some ops structure or directly. Don't hide it in some incomprehensible, possibly nondeterministic place in a notifier chain.

Quoted 5 lines
Quoted 3 lines

2) Errata. Perhaps a vendor/platform specific function at the head of the notify chain that weeds out errors that should never have been reported.

No, do this before the notifier chain please.

Right. The amount of possible handlers is really not huge.

So having a well defined flow of explicit calls including the handling of magic workarounds in a central place makes tons of sense.

Thanks,

tglx

maintainer
#6 lore raw

Re: [PATCH 3/5] x86/mce: Add new "handled" field to "struct mce"

In reply to Luck, Tony
Quoted 5 lines · Tony

1) It is useful to user mode. The mcelog(8) daemon (or other consumer of "struct mce") gets a record of where to look for logs from this record. This could reduce the anxiety about logging the same item multiple times. Its a bit weird though because each entity logging only sees who came before them, not who came after.

Err, doesn't mcelog get the error shoved down through /dev/mcelog? IOW, why would it even have to look?

Ditto for other consumers which read the tracepoint...

Quoted 2 lines

2) Not useful
2a) Keep it in the structure, but clear it in copies shown to user

Yah, also ok.

Quoted 3 lines

2b) Make a *private to point to such things (but that really
complicates allocation of struct mce ... right now we just have local copies on kernel stack)

Yeah..

Quoted 6 lines
	2c) Make a wrapper structure:
		struct kernel_mce {
			struct mce mce;
			u32 handled;
			... other hidden stuff ...
		};

That too.

2a) sounds really simple to me and I like simple. And if we ever end up needing more fields, we'll just add another one and keep clearing it on copy to user.

And just to make our lives easier, we can do

	u64 kflags;

and put the handled stuff there but still have a 64-bit value for future flags.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#14 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Luck, Tony
Quoted 6 lines · Tony
Quoted 3 lines

Because this one bit would basically determine whether the error gets printed or not. Which would mean that all EDAC drivers should print it...

Alternative wording "An EDAC driver should only set the bit if it printed something useful about the error."

ACK.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#12 lore raw

Re: [PATCH 4/5] x86/mce: Fix all mce notifiers to update the mce->handled bitmask

In reply to Luck, Tony
Quoted 2 lines · Tony

Ok. We don't have code that does this yet. If we need some, I'll make sure to do the weed out before it gets to the notifier.

... which would make running the CEC hook *before* running the notifiers the easiest thing. Hacking in "did-CEC-handle-it" logic in the rest of the chain is just going to be painful so the best would be IMO: if the CEC decided to consume it, it won't even go down the notifiers.

Just like the added crap^W value firmware-first thing does and we should learn from it. :-)

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#18 lore raw

Re: [PATCH 5/5] x86/mce: Change default mce logger to check mce->handled

In reply to Luck, Tony
Quoted 1 line · Tony

That's pretty hard with a chain. I think folks will have a conniptions

LOL. And they do already for other things so let's spare them :-)

Quoted 6 lines

if we invent an error return from a notifier chain function that means "Go back and start over". Though if we did it would make the "handled" field useful for functions that didn't want to redo ... they'd just check if "their" bit in handled was already set.

Still, seems like a terrible idea.

Yap.

Quoted 7 lines

If some driver really wants multiple bites at an error on the chain it could register more than one handler with different priorities. In which case we should have "enum" names for the highest and lowest priorities so such a driver can go "first" or "last" (though such a thing would be dependent on whether some other driver was attempting to add a "first" or "last" entry on the chain).

Yap, makes sense. I'm fine with us even having a possible way to do this, *if* someone decides she wants it.

Ok, thanks!

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#39 lore raw

PATCH v2 5/7 x86/mce: Change default mce logger to check mce->kflags

In reply to Tony Luck

Instead of keeping count of how many handlers are registered on the mce chain and printing if we are below some magic value. Look at the mce->kflags to see if anyone claims to have handled/logged this error.

---
 arch/x86/kernel/cpu/mce/core.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/mce/core.c +4 -16
index d3d11d1e52b3..066d3903ef97 100644
@@ -156,29 +156,17 @@ void mce_log(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_log);
 
-/*
- * We run the default notifier if we have only the UC, the first and the
- * default notifier registered. I.e., the mandatory NUM_DEFAULT_NOTIFIERS
- * notifiers registered on the chain.
- */
-#define NUM_DEFAULT_NOTIFIERS	3
-static atomic_t num_notifiers;
-
 void mce_register_decode_chain(struct notifier_block *nb)
 {
 	if (WARN_ON(nb->priority > MCE_PRIO_MCELOG && nb->priority < MCE_PRIO_EDAC))
 		return;
 
-	atomic_inc(&num_notifiers);
-
 	blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_register_decode_chain);
 
 void mce_unregister_decode_chain(struct notifier_block *nb)
 {
-	atomic_dec(&num_notifiers);
-
 	blocking_notifier_chain_unregister(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
@@ -261,6 +249,8 @@ static void __print_mce(struct mce *m)
 	}
 
 	pr_cont("\n");
+	if (m->kflags)
+		pr_emerg(HW_ERR "kflags = 0x%llx\n", m->kflags);
 	/*
 	 * Note this output is parsed by external tools and old fields
 	 * should not be changed.
@@ -600,10 +590,8 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (atomic_read(&num_notifiers) > NUM_DEFAULT_NOTIFIERS)
-		return NOTIFY_DONE;
-
-	__print_mce(m);
+	if (!m->kflags)
+		__print_mce(m);
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.21.1
author maintainer
#36 lore raw

PATCH v2 4/7 x86/mce: Fix all mce notifiers to update the mce->kflags bitmask

In reply to Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->kflags so that the default handler on the end of the machine check chain can see what has been done.

Get rid of NOTIFY_STOP (well almost ... mce_amd.c is currently using it to filter out some GART TLB errors ... need to deal with that later).

Make the EDAC and dev-mcelog handlers skip over errors already processed by CEC.

---
 arch/x86/kernel/cpu/mce/core.c       | 4 +++-
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 5 +++++
 drivers/acpi/acpi_extlog.c           | 5 +++--
 drivers/acpi/nfit/mce.c              | 1 +
 drivers/edac/i7core_edac.c           | 5 +++--
 drivers/edac/mce_amd.c               | 9 +++++++--
 drivers/edac/pnd2_edac.c             | 5 +++--
 drivers/edac/sb_edac.c               | 5 ++++-
 drivers/edac/skx_common.c            | 4 ++++
 drivers/ras/cec.c                    | 9 ++++++---
 10 files changed, 39 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -1
index 06240cbe6f3e..d3d11d1e52b3 100644
@@ -579,8 +579,10 @@ static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
 		return NOTIFY_DONE;
 
 	pfn = mce->addr >> PAGE_SHIFT;
-	if (!memory_failure(pfn, 0))
+	if (!memory_failure(pfn, 0)) {
 		set_mce_nospec(pfn);
+		mce->kflags |= MCE_HANDLED_UC;
+	}
 
 	return NOTIFY_OK;
 }
arch/x86/kernel/cpu/mce/dev-mcelog.c +5 -0
index 7c8958dee103..f1bf7535ead7 100644
@@ -43,6 +43,9 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 	struct mce *mce = (struct mce *)data;
 	unsigned int entry;
 
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	mutex_lock(&mce_chrdev_read_mutex);
 
 	entry = mcelog.next;
@@ -60,6 +63,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 
 	memcpy(mcelog.entry + entry, mce, sizeof(struct mce));
 	mcelog.entry[entry].finished = 1;
+	mcelog.entry[entry].kflags = 0;
 
 	/* wake processes polling /dev/mcelog */
 	wake_up_interruptible(&mce_chrdev_wait);
@@ -67,6 +71,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 unlock:
 	mutex_unlock(&mce_chrdev_read_mutex);
 
+	mce->kflags |= MCE_HANDLED_MCELOG;
 	return NOTIFY_OK;
 }
 
drivers/acpi/acpi_extlog.c +3 -2
index 8596a106a933..9cc3c1f92db5 100644
@@ -146,7 +146,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	static u32 err_seq;
 
 	estatus = extlog_elog_entry_check(cpu, bank);
-	if (estatus == NULL)
+	if (estatus == NULL || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	memcpy(elog_buf, (void *)estatus, ELOG_ENTRY_LEN);
@@ -176,7 +176,8 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	}
 
 out:
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EXTLOG;
+	return NOTIFY_OK;
 }
 
 static bool __init extlog_get_l1addr(void)
drivers/acpi/nfit/mce.c +1 -0
index f0ae48515b48..ee8d9973f60b 100644
@@ -76,6 +76,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
 			 */
 			acpi_nfit_ars_rescan(acpi_desc, 0);
 		}
+		mce->kflags |= MCE_HANDLED_NFIT;
 		break;
 	}
 
drivers/edac/i7core_edac.c +3 -2
index b3135b208f9a..5860ca41185c 100644
@@ -1815,7 +1815,7 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 
 	i7_dev = get_i7core_dev(mce->socketid);
-	if (!i7_dev)
+	if (!i7_dev || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	mci = i7_dev->mci;
@@ -1834,7 +1834,8 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	i7core_check_error(mci, mce);
 
 	/* Advise mcelog that the errors were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block i7_mce_dec = {
drivers/edac/mce_amd.c +7 -2
index ea980c556f2e..e31e4db64e1b 100644
@@ -1067,8 +1067,12 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
-	if (ignore_mce(m))
+	if (ignore_mce(m)) {
+		m->kflags |= MCE_HANDLED_EDAC;
 		return NOTIFY_STOP;
+	}
+	if (m->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
 
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
@@ -1170,7 +1174,8 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
  err_code:
 	amd_decode_err_code(m->status & 0xffff);
 
-	return NOTIFY_STOP;
+	m->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block amd_mce_dec_nb = {
drivers/edac/pnd2_edac.c +3 -2
index 933f7722b893..77ad315c7e8d 100644
@@ -1400,7 +1400,7 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 		return NOTIFY_DONE;
 
 	mci = pnd2_mci;
-	if (!mci)
+	if (!mci || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	/*
@@ -1429,7 +1429,8 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	pnd2_mce_output_error(mci, mce, &daddr);
 
 	/* Advice mcelog that the error were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block pnd2_mce_dec = {
drivers/edac/sb_edac.c +4 -1
index 4957e8ee1879..6e17f601ea63 100644
@@ -3136,6 +3136,8 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
 		return NOTIFY_DONE;
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
 
 	/*
 	 * Just let mcelog handle it if the error is
@@ -3183,7 +3185,8 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	sbridge_mce_output_error(mci, mce);
 
 	/* Advice mcelog that the error were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block sbridge_mce_dec = {
drivers/edac/skx_common.c +4 -0
index 99bbaf629b8d..6f08a12f6b11 100644
@@ -577,6 +577,9 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
 		return NOTIFY_DONE;
 
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	/* ignore unless this is memory related with an address */
 	if ((mce->status & 0xefff) >> 7 != 1 || !(mce->status & MCI_STATUS_ADDRV))
 		return NOTIFY_DONE;
@@ -616,6 +619,7 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	skx_mce_output_error(mci, mce, &res);
 
+	mce->kflags |= MCE_HANDLED_EDAC;
 	return NOTIFY_DONE;
 }
 
drivers/ras/cec.c +6 -3
index d7f6718cbf8d..e061962d3c58 100644
@@ -538,9 +538,12 @@ static int cec_notifier(struct notifier_block *nb, unsigned long val,
 	/* We eat only correctable DRAM errors with usable addresses. */
 	if (mce_is_memory_error(m) &&
 	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return NOTIFY_STOP;
+	    mce_usable_address(m)) {
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT)) {
+			m->kflags |= MCE_HANDLED_CEC;
+			return NOTIFY_OK;
+		}
+	}
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.21.1
author maintainer
#24 lore raw

PATCH v2 1/7 x86/mce: Rename "first" function as "early"

In reply to Tony Luck

It isn't going to be first on the notifier chain when we move the CEC code to be a normal user of the notifier chain.

Fix the enum for the MCE_PRIO symbols to list them in reverse order so that the compiler can give them numbers from low to high priority. Add an entry for MCE_PRIO_CEC as the highest priority.

---
 arch/x86/include/asm/mce.h     | 15 ++++++++-------
 arch/x86/kernel/cpu/mce/core.c | 10 +++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)
arch/x86/include/asm/mce.h +8 -7
index 4359b955e0b7..6f17cc618d5e 100644
@@ -143,13 +143,14 @@ struct mce_log_buffer {
 };
 
 enum mce_notifier_prios {
-	MCE_PRIO_FIRST		= INT_MAX,
-	MCE_PRIO_UC		= INT_MAX - 1,
-	MCE_PRIO_EXTLOG		= INT_MAX - 2,
-	MCE_PRIO_NFIT		= INT_MAX - 3,
-	MCE_PRIO_EDAC		= INT_MAX - 4,
-	MCE_PRIO_MCELOG		= 1,
-	MCE_PRIO_LOWEST		= 0,
+	MCE_PRIO_LOWEST,
+	MCE_PRIO_MCELOG,
+	MCE_PRIO_EDAC,
+	MCE_PRIO_NFIT,
+	MCE_PRIO_EXTLOG,
+	MCE_PRIO_UC,
+	MCE_PRIO_EARLY,
+	MCE_PRIO_CEC
 };
 
 struct notifier_block;
arch/x86/kernel/cpu/mce/core.c +5 -5
index 2c4f949611e4..3366807d8e58 100644
@@ -557,7 +557,7 @@ static bool cec_add_mce(struct mce *m)
 	return false;
 }
 
-static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
+static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
 	struct mce *m = (struct mce *)data;
@@ -578,9 +578,9 @@ static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
 	return NOTIFY_DONE;
 }
 
-static struct notifier_block first_nb = {
-	.notifier_call	= mce_first_notifier,
-	.priority	= MCE_PRIO_FIRST,
+static struct notifier_block early_nb = {
+	.notifier_call	= mce_early_notifier,
+	.priority	= MCE_PRIO_EARLY,
 };
 
 static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
@@ -2028,7 +2028,7 @@ __setup("mce", mcheck_enable);
 int __init mcheck_init(void)
 {
 	mcheck_intel_therm_init();
-	mce_register_decode_chain(&first_nb);
+	mce_register_decode_chain(&early_nb);
 	mce_register_decode_chain(&mce_uc_nb);
 	mce_register_decode_chain(&mce_default_nb);
 	mcheck_vendor_init_severity();
Signature · 1 line
2.21.1
author maintainer
#47 lore raw

PATCH v2 7/7 x86/mce: Drop the EDAC report status checks

In reply to Tony Luck

When we added acpi_extlog we were worried that the same error would be reported more than once by different subsystems. But in the ensuing years I've seen complaints that people could not find an error log (because this mechanism suppressed the log they were looking for).

Rip it all out. People are smart enough to notice the same address from different reporting mechanisms.

---
 drivers/acpi/acpi_extlog.c | 14 ---------
 drivers/edac/edac_mc.c     | 61 --------------------------------------
 drivers/edac/pnd2_edac.c   |  3 --
 drivers/edac/sb_edac.c     |  4 ---
 drivers/edac/skx_common.c  |  3 --
 include/linux/edac.h       |  8 -----
 6 files changed, 93 deletions(-)
drivers/acpi/acpi_extlog.c +0 -14
index 9cc3c1f92db5..f138e12b7b82 100644
@@ -42,8 +42,6 @@ struct extlog_l1_head {
 	u8  rev1[12];
 };
 
-static int old_edac_report_status;
-
 static u8 extlog_dsm_uuid[] __initdata = "663E35AF-CC10-41A4-88EA-5470AF055295";
 
 /* L1 table related physical address */
@@ -229,11 +227,6 @@ static int __init extlog_init(void)
 	if (!(cap & MCG_ELOG_P) || !extlog_get_l1addr())
 		return -ENODEV;
 
-	if (edac_get_report_status() == EDAC_REPORTING_FORCE) {
-		pr_warn("Not loading eMCA, error reporting force-enabled through EDAC.\n");
-		return -EPERM;
-	}
-
 	rc = -EINVAL;
 	/* get L1 header to fetch necessary information */
 	l1_hdr_size = sizeof(struct extlog_l1_head);
@@ -281,12 +274,6 @@ static int __init extlog_init(void)
 	if (elog_buf == NULL)
 		goto err_release_elog;
 
-	/*
-	 * eMCA event report method has higher priority than EDAC method,
-	 * unless EDAC event report method is mandatory.
-	 */
-	old_edac_report_status = edac_get_report_status();
-	edac_set_report_status(EDAC_REPORTING_DISABLED);
 	mce_register_decode_chain(&extlog_mce_dec);
 	/* enable OS to be involved to take over management from BIOS */
 	((struct extlog_l1_head *)extlog_l1_addr)->flags |= FLAG_OS_OPTIN;
@@ -308,7 +295,6 @@ static int __init extlog_init(void)
 
 static void __exit extlog_exit(void)
 {
-	edac_set_report_status(old_edac_report_status);
 	mce_unregister_decode_chain(&extlog_mce_dec);
 	((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
 	if (extlog_l1_addr)
drivers/edac/edac_mc.c +0 -61

73 lines not on this page · raw message

drivers/edac/pnd2_edac.c +0 -3
index 77ad315c7e8d..bfb6c88ebb28 100644
@@ -1396,9 +1396,6 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	struct dram_addr daddr;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
-
 	mci = pnd2_mci;
 	if (!mci || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
drivers/edac/sb_edac.c +0 -4
index 6e17f601ea63..898f567d5d89 100644
@@ -3134,8 +3134,6 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
 	if (mce->kflags & MCE_HANDLED_CEC)
 		return NOTIFY_DONE;
 
@@ -3526,8 +3524,6 @@ static int __init sbridge_init(void)
 
 	if (rc >= 0) {
 		mce_register_decode_chain(&sbridge_mce_dec);
-		if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-			sbridge_printk(KERN_WARNING, "Loading driver, error reporting disabled.\n");
 		return 0;
 	}
 
drivers/edac/skx_common.c +0 -3
index 6f08a12f6b11..423d33aef54f 100644
@@ -574,9 +574,6 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
-
 	if (mce->kflags & MCE_HANDLED_CEC)
 		return NOTIFY_DONE;
 
include/linux/edac.h +0 -8
index cc31b9742684..bd770e31ced6 100644
@@ -31,14 +31,6 @@ struct device;
 extern int edac_op_state;
 
 struct bus_type *edac_get_sysfs_subsys(void);
-int edac_get_report_status(void);
-void edac_set_report_status(int new);
-
-enum {
-	EDAC_REPORTING_ENABLED,
-	EDAC_REPORTING_DISABLED,
-	EDAC_REPORTING_FORCE
-};
 
 static inline void opstate_init(void)
 {
Signature · 1 line
2.21.1
author maintainer
#45 lore raw

PATCH v2 6/7 x86/mce: Add mce=print_all option

In reply to Tony Luck

Sometimes, when logs are getting lost, it's nice to just have everything dumped to the serial console.

---
 arch/x86/kernel/cpu/mce/core.c     | 7 ++++++-
 arch/x86/kernel/cpu/mce/internal.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/core.c +6 -1
index 066d3903ef97..22925fd5e189 100644
@@ -590,7 +590,7 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (!m->kflags)
+	if (mca_cfg.print_all || !m->kflags)
 		__print_mce(m);
 
 	return NOTIFY_DONE;
@@ -1950,6 +1950,7 @@ void mce_disable_bank(int bank)
  * mce=no_cmci Disables CMCI
  * mce=no_lmce Disables LMCE
  * mce=dont_log_ce Clears corrected events silently, no log created for CEs.
+ * mce=print_all Print all machine check logs to console
  * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
  * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
  *	monarchtimeout is how long to wait for other CPUs on machine
@@ -1978,6 +1979,8 @@ static int __init mcheck_enable(char *str)
 		cfg->lmce_disabled = 1;
 	else if (!strcmp(str, "dont_log_ce"))
 		cfg->dont_log_ce = true;
+	else if (!strcmp(str, "print_all"))
+		cfg->print_all = true;
 	else if (!strcmp(str, "ignore_ce"))
 		cfg->ignore_ce = true;
 	else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
@@ -2244,6 +2247,7 @@ static ssize_t store_int_with_restart(struct device *s,
 static DEVICE_INT_ATTR(tolerant, 0644, mca_cfg.tolerant);
 static DEVICE_INT_ATTR(monarch_timeout, 0644, mca_cfg.monarch_timeout);
 static DEVICE_BOOL_ATTR(dont_log_ce, 0644, mca_cfg.dont_log_ce);
+static DEVICE_BOOL_ATTR(print_all, 0644, mca_cfg.print_all);
 
 static struct dev_ext_attribute dev_attr_check_interval = {
 	__ATTR(check_interval, 0644, device_show_int, store_int_with_restart),
@@ -2268,6 +2272,7 @@ static struct device_attribute *mce_device_attrs[] = {
 #endif
 	&dev_attr_monarch_timeout.attr,
 	&dev_attr_dont_log_ce.attr,
+	&dev_attr_print_all.attr,
 	&dev_attr_ignore_ce.attr,
 	&dev_attr_cmci_disabled.attr,
 	NULL
arch/x86/kernel/cpu/mce/internal.h +1 -0
index b785c0d0b590..bf09b8aa8184 100644
@@ -114,6 +114,7 @@ struct mca_config {
 	bool dont_log_ce;
 	bool cmci_disabled;
 	bool ignore_ce;
+	bool print_all;
 
 	__u64 lmce_disabled		: 1,
 	      disabled			: 1,
Signature · 1 line
2.21.1
author maintainer
#28 lore raw

PATCH v2 3/7 x86/mce: Add new "kflags" field to "struct mce"

In reply to Tony Luck

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

The default handler at the end of the chain can use this information to decide whether to print to the console log.

Boris suggested a generic name and leaving plenty of spare bits for possible future use.

---
 arch/x86/include/uapi/asm/mce.h | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/include/uapi/asm/mce.h +9 -0
index 955c2a2e1cf9..f8395812520b 100644
@@ -35,8 +35,17 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u64 kflags;		/* Internal kernel use. See below */
 };
 
+/* kflags flag bits for logging etc. */
+#define	MCE_HANDLED_CEC		BIT(0)
+#define	MCE_HANDLED_UC		BIT(1)
+#define	MCE_HANDLED_EXTLOG	BIT(2)
+#define	MCE_HANDLED_NFIT	BIT(3)
+#define	MCE_HANDLED_EDAC	BIT(4)
+#define	MCE_HANDLED_MCELOG	BIT(5)
+
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
 #define MCE_GET_LOG_LEN      _IOR('M', 2, int)
 #define MCE_GETCLEAR_FLAGS   _IOR('M', 3, int)
Signature · 1 line
2.21.1
author maintainer
#26 lore raw

PATCH v2 2/7 x86/mce: Convert corrected error collector to use mce notifier

In reply to Tony Luck

The CEC code has its claws in a couple of routines in mce/core.c

Convert it to just register itself on the normal mce notifier chain.

---
 arch/x86/kernel/cpu/mce/core.c | 19 -------------------
 drivers/ras/cec.c              | 26 ++++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 19 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -19
index 3366807d8e58..06240cbe6f3e 100644
@@ -542,21 +542,6 @@ bool mce_is_correctable(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_is_correctable);
 
-static bool cec_add_mce(struct mce *m)
-{
-	if (!m)
-		return false;
-
-	/* We eat only correctable DRAM errors with usable addresses. */
-	if (mce_is_memory_error(m) &&
-	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return true;
-
-	return false;
-}
-
 static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
@@ -565,9 +550,6 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (cec_add_mce(m))
-		return NOTIFY_STOP;
-
 	/* Emit the trace record: */
 	trace_mce_record(m);
 
@@ -2588,7 +2570,6 @@ static int __init mcheck_late_init(void)
 		static_branch_inc(&mcsafe_key);
 
 	mcheck_debugfs_init();
-	cec_init();
 
 	/*
 	 * Flush out everything that has been logged during early boot, now that
drivers/ras/cec.c +26 -0
index c09cf55e2d20..d7f6718cbf8d 100644
@@ -527,6 +527,29 @@ static int __init create_debugfs_nodes(void)
 	return 1;
 }
 
+static int cec_notifier(struct notifier_block *nb, unsigned long val,
+			void *data)
+{
+	struct mce *m = (struct mce *)data;
+
+	if (!m)
+		return NOTIFY_DONE;
+
+	/* We eat only correctable DRAM errors with usable addresses. */
+	if (mce_is_memory_error(m) &&
+	    mce_is_correctable(m)  &&
+	    mce_usable_address(m))
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
+			return NOTIFY_STOP;
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block cec_nb = {
+	.notifier_call	= cec_notifier,
+	.priority	= MCE_PRIO_CEC,
+};
+
 void __init cec_init(void)
 {
 	if (ce_arr.disabled)
@@ -546,8 +569,11 @@ void __init cec_init(void)
 	INIT_DELAYED_WORK(&cec_work, cec_work_fn);
 	schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL);
 
+	mce_register_decode_chain(&cec_nb);
+
 	pr_info("Correctable Errors collector initialized.\n");
 }
+late_initcall(cec_init);
 
 int __init parse_cec_param(char *str)
 {
Signature · 1 line
2.21.1
author maintainer
#23 lore raw

v2 cover New way to track mce notifier chain actions

In reply to Tony Luck

Parts 1 & 2 are just cleanup. CEC should follow the same rules as everyone else who wants to be on the mce notifier chain. No real reason for it to have direct hooks into mce/core.c
[No substantive change since RFC version 1, but note that
I have kept the change to make CEC a "normal" user of the mce notifier chain. Result is a few checks for if (mce->kflags & MCE_HANDLED_CEC) in EDAC etc. drivers.]

Part 3 adds a field to struct mce, and defines the BIT fields for each class of notifier. All EDAC drivers share the same BIT since only one of them should be active.
[Boris: Changed name of new field to "kflags" and made
it __u64, so plenty of space for possible future other uses]

Part 4 Re-done since draft based on Luto and Tglx comments that
we should kill of all usage of NOTIFY_STOP. This patch now gets rid of all but one. That's an AMD case where it looks like they don't want to decode some particular errors on a specific platform. The right fix for that is to take Luto's advice and filter out before that item gets to the notifier chain. We even already have a filter function (filter_mce) to do that! But that change needs to be handled by someone with the appropriate h/w.

Part 5 Now just checks for mce->kflags in the default handler at
the end of the chain to decide whether to print.

Part 6 NEW - add mce=print_all option to override default and
print everything to the console. Intended for debug, or desperation scenarios where other logs are lost.

Part 7 NEW - Delete the code that tries to make sure only one
out of acpi_extlog and the current loaded EDAC driver deals with an error.

Tony Luck (7):
x86/mce: Rename "first" function as "early"
x86/mce: Convert corrected error collector to use mce notifier x86/mce: Add new "kflags" field to "struct mce" x86/mce: Fix all mce notifiers to update the mce->kflags bitmask x86/mce: Change default mce logger to check mce->kflags x86/mce: Add mce=print_all option
x86/mce: Drop the EDAC report status checks

 arch/x86/include/asm/mce.h           | 15 +++----
 arch/x86/include/uapi/asm/mce.h      |  9 ++++
 arch/x86/kernel/cpu/mce/core.c       | 58 ++++++++------------------
 arch/x86/kernel/cpu/mce/dev-mcelog.c |  5 +++
 arch/x86/kernel/cpu/mce/internal.h   |  1 +
 drivers/acpi/acpi_extlog.c           | 19 ++-------
 drivers/acpi/nfit/mce.c              |  1 +
 drivers/edac/edac_mc.c               | 61 ----------------------------
 drivers/edac/i7core_edac.c           |  5 ++-
 drivers/edac/mce_amd.c               |  9 +++-
 drivers/edac/pnd2_edac.c             |  8 ++--
 drivers/edac/sb_edac.c               |  7 ++--
 drivers/edac/skx_common.c            |  3 +-
 drivers/ras/cec.c                    | 29 +++++++++++++
 include/linux/edac.h                 |  8 ----
 15 files changed, 91 insertions(+), 147 deletions(-)

base-commit: b19e8c68470385dd2c5440876591fddb02c8c402

Signature · 1 line
2.21.1
maintainer
#37 lore raw

Re: [PATCH v2 4/7] x86/mce: Fix all mce notifiers to update the mce->kflags bitmask

In reply to Tony Luck
Quoted 7 lines · Tony Luck

If the handler took any action to log or deal with the error, set a bit int mce->kflags so that the default handler on the end of the machine check chain can see what has been done.

Get rid of NOTIFY_STOP (well almost ... mce_amd.c is currently using it to filter out some GART TLB errors ... need to deal with that later).

Here's me dealing with it :-)

Btw, no need to resend with it - I'm already queueing it all locally here along with more rework ontop and send it all once done.

Thx.

---
From 3eee69c7cf32578aafe050051d0406a1e6fbacbb Mon Sep 17 00:00:00 2001
From: Borislav Petkov <[email protected]>
Date: Tue, 7 Apr 2020 09:55:10 +0200
Subject: [PATCH] x86/mce/amd, edac: Remove report_gart_errors

... because no one should be interested in spurious MCEs anyway. Make the filtering unconditional and move it to amd_filter_mce().

---
 arch/x86/include/asm/mce.h    |  3 ++-
 arch/x86/kernel/cpu/mce/amd.c |  9 +++++++--
 drivers/edac/amd64_edac.c     |  8 --------
 drivers/edac/mce_amd.c        | 24 ------------------------
 drivers/edac/mce_amd.h        |  2 --
 5 files changed, 9 insertions(+), 37 deletions(-)
arch/x86/include/asm/mce.h +2 -1
index f9cea081c05b..83b6ddafa032 100644
@@ -127,6 +127,8 @@
 #define MSR_AMD64_SMCA_MCx_DEADDR(x)	(MSR_AMD64_SMCA_MC0_DEADDR + 0x10*(x))
 #define MSR_AMD64_SMCA_MCx_MISCy(x, y)	((MSR_AMD64_SMCA_MC0_MISC1 + y) + (0x10*(x)))
 
+#define XEC(x, mask)			(((x) >> 16) & mask)
+
 /*
  * This structure contains all data related to the MCE log.  Also
  * carries a signature to make it easier to find from external
@@ -347,5 +349,4 @@ umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr)	{ return
 #endif
 
 static inline void mce_hygon_feature_init(struct cpuinfo_x86 *c)	{ return mce_amd_feature_init(c); }
-
 #endif /* _ASM_X86_MCE_H */
arch/x86/kernel/cpu/mce/amd.c +7 -2
index 15c87b87b901..ea3cf714b7ad 100644
@@ -577,14 +577,19 @@ bool amd_filter_mce(struct mce *m)
 {
 	enum smca_bank_types bank_type = smca_get_bank_type(m->bank);
 	struct cpuinfo_x86 *c = &boot_cpu_data;
-	u8 xec = (m->status >> 16) & 0x3F;
 
 	/* See Family 17h Models 10h-2Fh Erratum #1114. */
 	if (c->x86 == 0x17 &&
 	    c->x86_model >= 0x10 && c->x86_model <= 0x2F &&
-	    bank_type == SMCA_IF && xec == 10)
+	    bank_type == SMCA_IF && XEC(m->status, 0x3f) == 10)
 		return true;
 
+	/* NB GART TLB error reporting is disabled by default. */
+	if (c->x86 < 0x17) {
+		if (m->bank == 4 && XEC(m->status, 0x1f) == 0x5)
+			return true;
+	}
+
 	return false;
 }
 
drivers/edac/amd64_edac.c +0 -8
index f91f3bc1e0b2..6bdc5bb8c8bc 100644
@@ -4,9 +4,6 @@
 
 static struct edac_pci_ctl_info *pci_ctl;
 
-static int report_gart_errors;
-module_param(report_gart_errors, int, 0644);
-
 /*
  * Set by command line parameter. If BIOS has enabled the ECC, this override is
  * cleared to prevent re-enabling the hardware by this driver.
@@ -3681,9 +3678,6 @@ static int __init amd64_edac_init(void)
 	}
 
 	/* register stuff with EDAC MCE */
-	if (report_gart_errors)
-		amd_report_gart_errors(true);
-
 	if (boot_cpu_data.x86 >= 0x17)
 		amd_register_ecc_decoder(decode_umc_error);
 	else
@@ -3718,8 +3712,6 @@ static void __exit amd64_edac_exit(void)
 		edac_pci_release_generic_ctl(pci_ctl);
 
 	/* unregister from EDAC MCE */
-	amd_report_gart_errors(false);
-
 	if (boot_cpu_data.x86 >= 0x17)
 		amd_unregister_ecc_decoder(decode_umc_error);
 	else
drivers/edac/mce_amd.c +0 -24
index 8874b7722b2f..e58644d9c92b 100644
@@ -10,15 +10,8 @@ static struct amd_decoder_ops fam_ops;
 
 static u8 xec_mask	 = 0xf;
 
-static bool report_gart_errors;
 static void (*decode_dram_ecc)(int node_id, struct mce *m);
 
-void amd_report_gart_errors(bool v)
-{
-	report_gart_errors = v;
-}
-EXPORT_SYMBOL_GPL(amd_report_gart_errors);
-
 void amd_register_ecc_decoder(void (*f)(int, struct mce *))
 {
 	decode_dram_ecc = f;
@@ -1030,20 +1023,6 @@ static inline void amd_decode_err_code(u16 ec)
 	pr_cont("\n");
 }
 
-/*
- * Filter out unwanted MCE signatures here.
- */
-static bool ignore_mce(struct mce *m)
-{
-	/*
-	 * NB GART TLB error reporting is disabled by default.
-	 */
-	if (m->bank == 4 && XEC(m->status, 0x1f) == 0x5 && !report_gart_errors)
-		return true;
-
-	return false;
-}
-
 static const char *decode_error_status(struct mce *m)
 {
 	if (m->status & MCI_STATUS_UC) {
@@ -1067,9 +1046,6 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
-	if (ignore_mce(m))
-		return NOTIFY_STOP;
-
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
 	pr_emerg(HW_ERR "CPU:%d (%x:%x:%x) MC%d_STATUS[%s|%s|%s|%s|%s",
drivers/edac/mce_amd.h +0 -2
index 4e9c5e596c6c..4811b18d9606 100644
@@ -7,7 +7,6 @@
 #include <asm/mce.h>
 
 #define EC(x)				((x) & 0xffff)
-#define XEC(x, mask)			(((x) >> 16) & mask)
 
 #define LOW_SYNDROME(x)			(((x) >> 15) & 0xff)
 #define HIGH_SYNDROME(x)		(((x) >> 24) & 0xff)
@@ -77,7 +76,6 @@ struct amd_decoder_ops {
 	bool (*mc2_mce)(u16, u8);
 };
 
-void amd_report_gart_errors(bool);
 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
 void amd_unregister_ecc_decoder(void (*f)(int, struct mce *));
 
Signature · 7 lines
2.21.0

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#40 lore raw

Re: [PATCH v2 5/7] x86/mce: Change default mce logger to check mce->kflags

In reply to Tony Luck

arch/x86/kernel/cpu/mce/core.c static void __print_mce(struct mce *m) · line 253

Quoted 6 lines · Tony Luck
arch/x86/kernel/cpu/mce/core.c +2 -0
@@ -261,6 +249,8 @@ static void __print_mce(struct mce *m)
 	}
 
 	pr_cont("\n");
+	if (m->kflags)
+		pr_emerg(HW_ERR "kflags = 0x%llx\n", m->kflags);

I've zapped that hunk. I'd like to avoid exposing those kflags to luserspace in any shape or form for now.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer
#49 lore raw

v3 cover New way to track mce notifier chain actions

In reply to Tony Luck

From: Borislav Petkov <[email protected]>

Hi all,

here's what I have. I'd like to keep mce.kflags hidden for now.

The last patch is something tglx spotted yesterday and fixing that with the MCE flags is pretty easy - was boxing with a wrapper struct around struct mce and that gets really ugly.

Tony, I'm open to suggestions how to test it - I probably don't have an access to such box which can trigger read errors on nvdimms or what was the use case?

Thx.

Borislav Petkov (2):
x86/mce/amd, edac: Remove report_gart_errors x86/mce: Fixup exception only for the correct MCEs

Tony Luck (7):
x86/mce: Rename "first" function as "early"
x86/mce: Convert the CEC to use the MCE notifier x86/mce: Add a struct mce.kflags field
x86/mce: Fix all mce notifiers to update the mce->kflags bitmask x86/mce: Change default MCE logger to check mce->kflags x86/mce: Add mce=print_all option
EDAC: Drop the EDAC report status checks

 arch/x86/include/asm/mce.h           | 28 +++++++----
 arch/x86/include/uapi/asm/mce.h      |  1 +
 arch/x86/kernel/cpu/mce/amd.c        |  9 +++-
 arch/x86/kernel/cpu/mce/core.c       | 72 +++++++++++-----------------
 arch/x86/kernel/cpu/mce/dev-mcelog.c |  5 ++
 arch/x86/kernel/cpu/mce/internal.h   |  1 +
 arch/x86/kernel/cpu/mce/severity.c   |  6 ++-
 drivers/acpi/acpi_extlog.c           | 19 ++------
 drivers/acpi/nfit/mce.c              |  1 +
 drivers/edac/amd64_edac.c            |  8 ----
 drivers/edac/edac_mc.c               | 61 -----------------------
 drivers/edac/i7core_edac.c           |  5 +-
 drivers/edac/mce_amd.c               | 28 ++---------
 drivers/edac/mce_amd.h               |  2 -
 drivers/edac/pnd2_edac.c             |  8 ++--
 drivers/edac/sb_edac.c               |  7 ++-
 drivers/edac/skx_common.c            |  3 +-
 drivers/ras/cec.c                    | 33 ++++++++++++-
 include/linux/edac.h                 |  8 ----
 include/linux/ras.h                  |  5 --
 20 files changed, 118 insertions(+), 192 deletions(-)
Signature · 1 line
2.21.0
maintainer
#50 lore raw

PATCH v3 1/9 x86/mce/amd, edac: Remove report_gart_errors

From: Borislav Petkov <[email protected]>

... because no one should be interested in spurious MCEs anyway. Make the filtering unconditional and move it to amd_filter_mce().

---
 arch/x86/include/asm/mce.h    |  3 ++-
 arch/x86/kernel/cpu/mce/amd.c |  9 +++++++--
 drivers/edac/amd64_edac.c     |  8 --------
 drivers/edac/mce_amd.c        | 24 ------------------------
 drivers/edac/mce_amd.h        |  2 --
 5 files changed, 9 insertions(+), 37 deletions(-)
arch/x86/include/asm/mce.h +2 -1
index f9cea081c05b..83b6ddafa032 100644
@@ -127,6 +127,8 @@
 #define MSR_AMD64_SMCA_MCx_DEADDR(x)	(MSR_AMD64_SMCA_MC0_DEADDR + 0x10*(x))
 #define MSR_AMD64_SMCA_MCx_MISCy(x, y)	((MSR_AMD64_SMCA_MC0_MISC1 + y) + (0x10*(x)))
 
+#define XEC(x, mask)			(((x) >> 16) & mask)
+
 /*
  * This structure contains all data related to the MCE log.  Also
  * carries a signature to make it easier to find from external
@@ -347,5 +349,4 @@ umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr)	{ return
 #endif
 
 static inline void mce_hygon_feature_init(struct cpuinfo_x86 *c)	{ return mce_amd_feature_init(c); }
-
 #endif /* _ASM_X86_MCE_H */
arch/x86/kernel/cpu/mce/amd.c +7 -2
index 15c87b87b901..ea3cf714b7ad 100644
@@ -577,14 +577,19 @@ bool amd_filter_mce(struct mce *m)
 {
 	enum smca_bank_types bank_type = smca_get_bank_type(m->bank);
 	struct cpuinfo_x86 *c = &boot_cpu_data;
-	u8 xec = (m->status >> 16) & 0x3F;
 
 	/* See Family 17h Models 10h-2Fh Erratum #1114. */
 	if (c->x86 == 0x17 &&
 	    c->x86_model >= 0x10 && c->x86_model <= 0x2F &&
-	    bank_type == SMCA_IF && xec == 10)
+	    bank_type == SMCA_IF && XEC(m->status, 0x3f) == 10)
 		return true;
 
+	/* NB GART TLB error reporting is disabled by default. */
+	if (c->x86 < 0x17) {
+		if (m->bank == 4 && XEC(m->status, 0x1f) == 0x5)
+			return true;
+	}
+
 	return false;
 }
 
drivers/edac/amd64_edac.c +0 -8
index f91f3bc1e0b2..6bdc5bb8c8bc 100644
@@ -4,9 +4,6 @@
 
 static struct edac_pci_ctl_info *pci_ctl;
 
-static int report_gart_errors;
-module_param(report_gart_errors, int, 0644);
-
 /*
  * Set by command line parameter. If BIOS has enabled the ECC, this override is
  * cleared to prevent re-enabling the hardware by this driver.
@@ -3681,9 +3678,6 @@ static int __init amd64_edac_init(void)
 	}
 
 	/* register stuff with EDAC MCE */
-	if (report_gart_errors)
-		amd_report_gart_errors(true);
-
 	if (boot_cpu_data.x86 >= 0x17)
 		amd_register_ecc_decoder(decode_umc_error);
 	else
@@ -3718,8 +3712,6 @@ static void __exit amd64_edac_exit(void)
 		edac_pci_release_generic_ctl(pci_ctl);
 
 	/* unregister from EDAC MCE */
-	amd_report_gart_errors(false);
-
 	if (boot_cpu_data.x86 >= 0x17)
 		amd_unregister_ecc_decoder(decode_umc_error);
 	else
drivers/edac/mce_amd.c +0 -24
index 8874b7722b2f..e58644d9c92b 100644
@@ -10,15 +10,8 @@ static struct amd_decoder_ops fam_ops;
 
 static u8 xec_mask	 = 0xf;
 
-static bool report_gart_errors;
 static void (*decode_dram_ecc)(int node_id, struct mce *m);
 
-void amd_report_gart_errors(bool v)
-{
-	report_gart_errors = v;
-}
-EXPORT_SYMBOL_GPL(amd_report_gart_errors);
-
 void amd_register_ecc_decoder(void (*f)(int, struct mce *))
 {
 	decode_dram_ecc = f;
@@ -1030,20 +1023,6 @@ static inline void amd_decode_err_code(u16 ec)
 	pr_cont("\n");
 }
 
-/*
- * Filter out unwanted MCE signatures here.
- */
-static bool ignore_mce(struct mce *m)
-{
-	/*
-	 * NB GART TLB error reporting is disabled by default.
-	 */
-	if (m->bank == 4 && XEC(m->status, 0x1f) == 0x5 && !report_gart_errors)
-		return true;
-
-	return false;
-}
-
 static const char *decode_error_status(struct mce *m)
 {
 	if (m->status & MCI_STATUS_UC) {
@@ -1067,9 +1046,6 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
-	if (ignore_mce(m))
-		return NOTIFY_STOP;
-
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
 	pr_emerg(HW_ERR "CPU:%d (%x:%x:%x) MC%d_STATUS[%s|%s|%s|%s|%s",
drivers/edac/mce_amd.h +0 -2
index 4e9c5e596c6c..4811b18d9606 100644
@@ -7,7 +7,6 @@
 #include <asm/mce.h>
 
 #define EC(x)				((x) & 0xffff)
-#define XEC(x, mask)			(((x) >> 16) & mask)
 
 #define LOW_SYNDROME(x)			(((x) >> 15) & 0xff)
 #define HIGH_SYNDROME(x)		(((x) >> 24) & 0xff)
@@ -77,7 +76,6 @@ struct amd_decoder_ops {
 	bool (*mc2_mce)(u16, u8);
 };
 
-void amd_report_gart_errors(bool);
 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
 void amd_unregister_ecc_decoder(void (*f)(int, struct mce *));
 
Signature · 1 line
2.21.0
maintainer
#52 lore raw

PATCH v3 2/9 x86/mce: Rename "first" function as "early"

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

It isn't going to be first on the notifier chain when the CEC is moved to be a normal user of the notifier chain.

Fix the enum for the MCE_PRIO symbols to list them in reverse order so that the compiler can give them numbers from low to high priority. Add an entry for MCE_PRIO_CEC as the highest priority.

[ bp: Use passive voice, add comments. ]

---
 arch/x86/include/asm/mce.h     | 16 +++++++++-------
 arch/x86/kernel/cpu/mce/core.c | 10 +++++-----
 2 files changed, 14 insertions(+), 12 deletions(-)
arch/x86/include/asm/mce.h +9 -7
index 83b6ddafa032..689ac6e9c65f 100644
@@ -144,14 +144,16 @@ struct mce_log_buffer {
 	struct mce entry[];
 };
 
+/* Highest last */
 enum mce_notifier_prios {
-	MCE_PRIO_FIRST		= INT_MAX,
-	MCE_PRIO_UC		= INT_MAX - 1,
-	MCE_PRIO_EXTLOG		= INT_MAX - 2,
-	MCE_PRIO_NFIT		= INT_MAX - 3,
-	MCE_PRIO_EDAC		= INT_MAX - 4,
-	MCE_PRIO_MCELOG		= 1,
-	MCE_PRIO_LOWEST		= 0,
+	MCE_PRIO_LOWEST,
+	MCE_PRIO_MCELOG,
+	MCE_PRIO_EDAC,
+	MCE_PRIO_NFIT,
+	MCE_PRIO_EXTLOG,
+	MCE_PRIO_UC,
+	MCE_PRIO_EARLY,
+	MCE_PRIO_CEC
 };
 
 struct notifier_block;
arch/x86/kernel/cpu/mce/core.c +5 -5
index a6009efdfe2b..43b1519ad4e5 100644
@@ -559,7 +559,7 @@ static bool cec_add_mce(struct mce *m)
 	return false;
 }
 
-static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
+static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
 	struct mce *m = (struct mce *)data;
@@ -580,9 +580,9 @@ static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
 	return NOTIFY_DONE;
 }
 
-static struct notifier_block first_nb = {
-	.notifier_call	= mce_first_notifier,
-	.priority	= MCE_PRIO_FIRST,
+static struct notifier_block early_nb = {
+	.notifier_call	= mce_early_notifier,
+	.priority	= MCE_PRIO_EARLY,
 };
 
 static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
@@ -2041,7 +2041,7 @@ __setup("mce", mcheck_enable);
 int __init mcheck_init(void)
 {
 	mcheck_intel_therm_init();
-	mce_register_decode_chain(&first_nb);
+	mce_register_decode_chain(&early_nb);
 	mce_register_decode_chain(&mce_uc_nb);
 	mce_register_decode_chain(&mce_default_nb);
 	mcheck_vendor_init_severity();
Signature · 1 line
2.21.0
maintainer
#57 lore raw

PATCH v3 7/9 x86/mce: Add mce=print_all option

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

Sometimes, when logs are getting lost, it's nice to just have everything dumped to the serial console.

---
 arch/x86/kernel/cpu/mce/core.c     | 7 ++++++-
 arch/x86/kernel/cpu/mce/internal.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/core.c +6 -1
index fc879b6669d5..4efe6c128887 100644
@@ -591,7 +591,7 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (!m->kflags)
+	if (mca_cfg.print_all || !m->kflags)
 		__print_mce(m);
 
 	return NOTIFY_DONE;
@@ -1962,6 +1962,7 @@ void mce_disable_bank(int bank)
  * mce=no_cmci Disables CMCI
  * mce=no_lmce Disables LMCE
  * mce=dont_log_ce Clears corrected events silently, no log created for CEs.
+ * mce=print_all Print all machine check logs to console
  * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
  * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
  *	monarchtimeout is how long to wait for other CPUs on machine
@@ -1990,6 +1991,8 @@ static int __init mcheck_enable(char *str)
 		cfg->lmce_disabled = 1;
 	else if (!strcmp(str, "dont_log_ce"))
 		cfg->dont_log_ce = true;
+	else if (!strcmp(str, "print_all"))
+		cfg->print_all = true;
 	else if (!strcmp(str, "ignore_ce"))
 		cfg->ignore_ce = true;
 	else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
@@ -2256,6 +2259,7 @@ static ssize_t store_int_with_restart(struct device *s,
 static DEVICE_INT_ATTR(tolerant, 0644, mca_cfg.tolerant);
 static DEVICE_INT_ATTR(monarch_timeout, 0644, mca_cfg.monarch_timeout);
 static DEVICE_BOOL_ATTR(dont_log_ce, 0644, mca_cfg.dont_log_ce);
+static DEVICE_BOOL_ATTR(print_all, 0644, mca_cfg.print_all);
 
 static struct dev_ext_attribute dev_attr_check_interval = {
 	__ATTR(check_interval, 0644, device_show_int, store_int_with_restart),
@@ -2280,6 +2284,7 @@ static struct device_attribute *mce_device_attrs[] = {
 #endif
 	&dev_attr_monarch_timeout.attr,
 	&dev_attr_dont_log_ce.attr,
+	&dev_attr_print_all.attr,
 	&dev_attr_ignore_ce.attr,
 	&dev_attr_cmci_disabled.attr,
 	NULL
arch/x86/kernel/cpu/mce/internal.h +1 -0
index 74a01829c4f4..55f5c7b755f2 100644
@@ -119,6 +119,7 @@ struct mca_config {
 	bool dont_log_ce;
 	bool cmci_disabled;
 	bool ignore_ce;
+	bool print_all;
 
 	__u64 lmce_disabled		: 1,
 	      disabled			: 1,
Signature · 1 line
2.21.0
maintainer
#59 lore raw

PATCH v3 9/9 x86/mce: Fixup exception only for the correct MCEs

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

The severity grading code returns IN_KERNEL_RECOV error context for errors which have happened in kernel space but from which the kernel can recover. Whether the recovery can happen is determined by the exception table entry having as handler ex_handler_fault() and which has been declared at build time using _ASM_EXTABLE_FAULT().

IN_KERNEL_RECOV is used in mce_severity_intel() to lookup the corresponding error severity in the severities table.

However, the mapping back from error severity to whether the error is IN_KERNEL_RECOV is ambiguous and in the very paranoid case - which might not be possible right now - but be better safe than sorry later, an exception fixup could be attempted for another MCE whose address is in the exception table and has the proper severity. Which would be unfortunate, to say the least.

Therefore, mark such MCEs explicitly as MCE_IN_KERNEL_RECOV so that the recovery attempt is done only for them.

Document the whole handling, while at it, as it is not trivial.

---
 arch/x86/include/asm/mce.h         |  1 +
 arch/x86/kernel/cpu/mce/core.c     | 15 +++++++++++++--
 arch/x86/kernel/cpu/mce/severity.c |  6 +++++-
 3 files changed, 19 insertions(+), 3 deletions(-)
arch/x86/include/asm/mce.h +1 -0
index 5f04a24f30ea..c598aaab071b 100644
@@ -136,6 +136,7 @@
 #define	MCE_HANDLED_NFIT	BIT_ULL(3)
 #define	MCE_HANDLED_EDAC	BIT_ULL(4)
 #define	MCE_HANDLED_MCELOG	BIT_ULL(5)
+#define MCE_IN_KERNEL_RECOV	BIT_ULL(6)
 
 /*
  * This structure contains all data related to the MCE log.  Also
arch/x86/kernel/cpu/mce/core.c +13 -2
index 4efe6c128887..02e1f165f148 100644
@@ -1331,8 +1331,19 @@ void notrace do_machine_check(struct pt_regs *regs, long error_code)
 		local_irq_disable();
 		ist_end_non_atomic();
 	} else {
-		if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0))
-			mce_panic("Failed kernel mode recovery", &m, msg);
+		/*
+		 * Handle an MCE which has happened in kernel space but from
+		 * which the kernel can recover: ex_has_fault_handler() has
+		 * already verified that the rIP at which the error happened is
+		 * a rIP from which the kernel can recover (by jumping to
+		 * recovery code specified in _ASM_EXTABLE_FAULT()) and the
+		 * corresponding exception handler which would do that is the
+		 * proper one.
+		 */
+		if (m.kflags & MCE_IN_KERNEL_RECOV) {
+			if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0))
+				mce_panic("Failed kernel mode recovery", &m, msg);
+		}
 	}
 
 out_ist:
arch/x86/kernel/cpu/mce/severity.c +5 -1
index 87bcdc6dc2f0..e1da619add19 100644
@@ -213,8 +213,12 @@ static int error_context(struct mce *m)
 {
 	if ((m->cs & 3) == 3)
 		return IN_USER;
-	if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip))
+
+	if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip)) {
+		m->kflags |= MCE_IN_KERNEL_RECOV;
 		return IN_KERNEL_RECOV;
+	}
+
 	return IN_KERNEL;
 }
 
Signature · 1 line
2.21.0
maintainer
#55 lore raw

PATCH v3 5/9 x86/mce: Fix all mce notifiers to update the mce->kflags bitmask

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

If the handler took any action to log or deal with the error, set a bit in mce->kflags so that the default handler on the end of the machine check chain can see what has been done.

Get rid of NOTIFY_STOP returns. Make the EDAC and dev-mcelog handlers skip over errors already processed by CEC.

---
 arch/x86/kernel/cpu/mce/core.c       | 4 +++-
 arch/x86/kernel/cpu/mce/dev-mcelog.c | 5 +++++
 drivers/acpi/acpi_extlog.c           | 5 +++--
 drivers/acpi/nfit/mce.c              | 1 +
 drivers/edac/i7core_edac.c           | 5 +++--
 drivers/edac/mce_amd.c               | 6 +++++-
 drivers/edac/pnd2_edac.c             | 5 +++--
 drivers/edac/sb_edac.c               | 5 ++++-
 drivers/edac/skx_common.c            | 4 ++++
 drivers/ras/cec.c                    | 9 ++++++---
 10 files changed, 37 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -1
index b033b3589630..5666a48a4bc9 100644
@@ -581,8 +581,10 @@ static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
 		return NOTIFY_DONE;
 
 	pfn = mce->addr >> PAGE_SHIFT;
-	if (!memory_failure(pfn, 0))
+	if (!memory_failure(pfn, 0)) {
 		set_mce_nospec(pfn);
+		mce->kflags |= MCE_HANDLED_UC;
+	}
 
 	return NOTIFY_OK;
 }
arch/x86/kernel/cpu/mce/dev-mcelog.c +5 -0
index d089567a9ce8..c033e7ea9e3c 100644
@@ -39,6 +39,9 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 	struct mce *mce = (struct mce *)data;
 	unsigned int entry;
 
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	mutex_lock(&mce_chrdev_read_mutex);
 
 	entry = mcelog->next;
@@ -56,6 +59,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 
 	memcpy(mcelog->entry + entry, mce, sizeof(struct mce));
 	mcelog->entry[entry].finished = 1;
+	mcelog->entry[entry].kflags = 0;
 
 	/* wake processes polling /dev/mcelog */
 	wake_up_interruptible(&mce_chrdev_wait);
@@ -63,6 +67,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 unlock:
 	mutex_unlock(&mce_chrdev_read_mutex);
 
+	mce->kflags |= MCE_HANDLED_MCELOG;
 	return NOTIFY_OK;
 }
 
drivers/acpi/acpi_extlog.c +3 -2
index 8596a106a933..9cc3c1f92db5 100644
@@ -146,7 +146,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	static u32 err_seq;
 
 	estatus = extlog_elog_entry_check(cpu, bank);
-	if (estatus == NULL)
+	if (estatus == NULL || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	memcpy(elog_buf, (void *)estatus, ELOG_ENTRY_LEN);
@@ -176,7 +176,8 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	}
 
 out:
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EXTLOG;
+	return NOTIFY_OK;
 }
 
 static bool __init extlog_get_l1addr(void)
drivers/acpi/nfit/mce.c +1 -0
index f0ae48515b48..ee8d9973f60b 100644
@@ -76,6 +76,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
 			 */
 			acpi_nfit_ars_rescan(acpi_desc, 0);
 		}
+		mce->kflags |= MCE_HANDLED_NFIT;
 		break;
 	}
 
drivers/edac/i7core_edac.c +3 -2
index b3135b208f9a..5860ca41185c 100644
@@ -1815,7 +1815,7 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 
 	i7_dev = get_i7core_dev(mce->socketid);
-	if (!i7_dev)
+	if (!i7_dev || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	mci = i7_dev->mci;
@@ -1834,7 +1834,8 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	i7core_check_error(mci, mce);
 
 	/* Advise mcelog that the errors were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block i7_mce_dec = {
drivers/edac/mce_amd.c +5 -1
index e58644d9c92b..2b5401db56ad 100644
@@ -1046,6 +1046,9 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
+	if (m->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
 	pr_emerg(HW_ERR "CPU:%d (%x:%x:%x) MC%d_STATUS[%s|%s|%s|%s|%s",
@@ -1146,7 +1149,8 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
  err_code:
 	amd_decode_err_code(m->status & 0xffff);
 
-	return NOTIFY_STOP;
+	m->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block amd_mce_dec_nb = {
drivers/edac/pnd2_edac.c +3 -2
index bc47328eb485..1929a5dc8f94 100644
@@ -1400,7 +1400,7 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 		return NOTIFY_DONE;
 
 	mci = pnd2_mci;
-	if (!mci)
+	if (!mci || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	/*
@@ -1429,7 +1429,8 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	pnd2_mce_output_error(mci, mce, &daddr);
 
 	/* Advice mcelog that the error were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block pnd2_mce_dec = {
drivers/edac/sb_edac.c +4 -1
index 7d51c82be62b..f790f7d08688 100644
@@ -3136,6 +3136,8 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
 		return NOTIFY_DONE;
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
 
 	/*
 	 * Just let mcelog handle it if the error is
@@ -3183,7 +3185,8 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	sbridge_mce_output_error(mci, mce);
 
 	/* Advice mcelog that the error were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block sbridge_mce_dec = {
drivers/edac/skx_common.c +4 -0
index 99bbaf629b8d..6f08a12f6b11 100644
@@ -577,6 +577,9 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
 		return NOTIFY_DONE;
 
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	/* ignore unless this is memory related with an address */
 	if ((mce->status & 0xefff) >> 7 != 1 || !(mce->status & MCI_STATUS_ADDRV))
 		return NOTIFY_DONE;
@@ -616,6 +619,7 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	skx_mce_output_error(mci, mce, &res);
 
+	mce->kflags |= MCE_HANDLED_EDAC;
 	return NOTIFY_DONE;
 }
 
drivers/ras/cec.c +6 -3
index 6b42040bf956..569d9ad2c594 100644
@@ -538,9 +538,12 @@ static int cec_notifier(struct notifier_block *nb, unsigned long val,
 	/* We eat only correctable DRAM errors with usable addresses. */
 	if (mce_is_memory_error(m) &&
 	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return NOTIFY_STOP;
+	    mce_usable_address(m)) {
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT)) {
+			m->kflags |= MCE_HANDLED_CEC;
+			return NOTIFY_OK;
+		}
+	}
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.21.0
maintainer
#56 lore raw

PATCH v3 6/9 x86/mce: Change default MCE logger to check mce->kflags

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

Instead of keeping count of how many handlers are registered on the MCE notifier chain and printing if below some magic value, look at mce->kflags to see if anyone claims to have handled/logged this error.

[ bp: Do not print ->kflags in __print_mce(). ]

---
 arch/x86/kernel/cpu/mce/core.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -16
index 5666a48a4bc9..fc879b6669d5 100644
@@ -158,29 +158,17 @@ void mce_log(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_log);
 
-/*
- * We run the default notifier if we have only the UC, the first and the
- * default notifier registered. I.e., the mandatory NUM_DEFAULT_NOTIFIERS
- * notifiers registered on the chain.
- */
-#define NUM_DEFAULT_NOTIFIERS	3
-static atomic_t num_notifiers;
-
 void mce_register_decode_chain(struct notifier_block *nb)
 {
 	if (WARN_ON(nb->priority > MCE_PRIO_MCELOG && nb->priority < MCE_PRIO_EDAC))
 		return;
 
-	atomic_inc(&num_notifiers);
-
 	blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_register_decode_chain);
 
 void mce_unregister_decode_chain(struct notifier_block *nb)
 {
-	atomic_dec(&num_notifiers);
-
 	blocking_notifier_chain_unregister(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
@@ -263,6 +251,7 @@ static void __print_mce(struct mce *m)
 	}
 
 	pr_cont("\n");
+
 	/*
 	 * Note this output is parsed by external tools and old fields
 	 * should not be changed.
@@ -602,10 +591,8 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (atomic_read(&num_notifiers) > NUM_DEFAULT_NOTIFIERS)
-		return NOTIFY_DONE;
-
-	__print_mce(m);
+	if (!m->kflags)
+		__print_mce(m);
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.21.0
maintainer
#58 lore raw

PATCH v3 8/9 EDAC: Drop the EDAC report status checks

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

When acpi_extlog was added, we were worried that the same error would be reported more than once by different subsystems. But in the ensuing years I've seen complaints that people could not find an error log (because this mechanism suppressed the log they were looking for).

Rip it all out. People are smart enough to notice the same address from different reporting mechanisms.

---
 drivers/acpi/acpi_extlog.c | 14 ---------
 drivers/edac/edac_mc.c     | 61 --------------------------------------
 drivers/edac/pnd2_edac.c   |  3 --
 drivers/edac/sb_edac.c     |  4 ---
 drivers/edac/skx_common.c  |  3 --
 include/linux/edac.h       |  8 -----
 6 files changed, 93 deletions(-)
drivers/acpi/acpi_extlog.c +0 -14
index 9cc3c1f92db5..f138e12b7b82 100644
@@ -42,8 +42,6 @@ struct extlog_l1_head {
 	u8  rev1[12];
 };
 
-static int old_edac_report_status;
-
 static u8 extlog_dsm_uuid[] __initdata = "663E35AF-CC10-41A4-88EA-5470AF055295";
 
 /* L1 table related physical address */
@@ -229,11 +227,6 @@ static int __init extlog_init(void)
 	if (!(cap & MCG_ELOG_P) || !extlog_get_l1addr())
 		return -ENODEV;
 
-	if (edac_get_report_status() == EDAC_REPORTING_FORCE) {
-		pr_warn("Not loading eMCA, error reporting force-enabled through EDAC.\n");
-		return -EPERM;
-	}
-
 	rc = -EINVAL;
 	/* get L1 header to fetch necessary information */
 	l1_hdr_size = sizeof(struct extlog_l1_head);
@@ -281,12 +274,6 @@ static int __init extlog_init(void)
 	if (elog_buf == NULL)
 		goto err_release_elog;
 
-	/*
-	 * eMCA event report method has higher priority than EDAC method,
-	 * unless EDAC event report method is mandatory.
-	 */
-	old_edac_report_status = edac_get_report_status();
-	edac_set_report_status(EDAC_REPORTING_DISABLED);
 	mce_register_decode_chain(&extlog_mce_dec);
 	/* enable OS to be involved to take over management from BIOS */
 	((struct extlog_l1_head *)extlog_l1_addr)->flags |= FLAG_OS_OPTIN;
@@ -308,7 +295,6 @@ static int __init extlog_init(void)
 
 static void __exit extlog_exit(void)
 {
-	edac_set_report_status(old_edac_report_status);
 	mce_unregister_decode_chain(&extlog_mce_dec);
 	((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
 	if (extlog_l1_addr)
drivers/edac/edac_mc.c +0 -61

73 lines not on this page · raw message

drivers/edac/pnd2_edac.c +0 -3
index 1929a5dc8f94..c1f2e6deb021 100644
@@ -1396,9 +1396,6 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	struct dram_addr daddr;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
-
 	mci = pnd2_mci;
 	if (!mci || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
drivers/edac/sb_edac.c +0 -4
index f790f7d08688..d414698ca324 100644
@@ -3134,8 +3134,6 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
 	if (mce->kflags & MCE_HANDLED_CEC)
 		return NOTIFY_DONE;
 
@@ -3526,8 +3524,6 @@ static int __init sbridge_init(void)
 
 	if (rc >= 0) {
 		mce_register_decode_chain(&sbridge_mce_dec);
-		if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-			sbridge_printk(KERN_WARNING, "Loading driver, error reporting disabled.\n");
 		return 0;
 	}
 
drivers/edac/skx_common.c +0 -3
index 6f08a12f6b11..423d33aef54f 100644
@@ -574,9 +574,6 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
-
 	if (mce->kflags & MCE_HANDLED_CEC)
 		return NOTIFY_DONE;
 
include/linux/edac.h +0 -8
index 0f20b986b0ab..6eb7d55d7c3d 100644
@@ -31,14 +31,6 @@ struct device;
 extern int edac_op_state;
 
 struct bus_type *edac_get_sysfs_subsys(void);
-int edac_get_report_status(void);
-void edac_set_report_status(int new);
-
-enum {
-	EDAC_REPORTING_ENABLED,
-	EDAC_REPORTING_DISABLED,
-	EDAC_REPORTING_FORCE
-};
 
 static inline void opstate_init(void)
 {
Signature · 1 line
2.21.0
maintainer
#53 lore raw

PATCH v3 3/9 x86/mce: Convert the CEC to use the MCE notifier

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

The CEC code has its claws in a couple of routines in mce/core.c. Convert it to just register itself on the normal MCE notifier chain.

[ bp: Make cec_add_elem() and cec_init() static. ]

---
 arch/x86/kernel/cpu/mce/core.c | 19 -------------------
 drivers/ras/cec.c              | 30 ++++++++++++++++++++++++++++--
 include/linux/ras.h            |  5 -----
 3 files changed, 28 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -19
index 43b1519ad4e5..b033b3589630 100644
@@ -544,21 +544,6 @@ bool mce_is_correctable(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_is_correctable);
 
-static bool cec_add_mce(struct mce *m)
-{
-	if (!m)
-		return false;
-
-	/* We eat only correctable DRAM errors with usable addresses. */
-	if (mce_is_memory_error(m) &&
-	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return true;
-
-	return false;
-}
-
 static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
@@ -567,9 +552,6 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (cec_add_mce(m))
-		return NOTIFY_STOP;
-
 	/* Emit the trace record: */
 	trace_mce_record(m);
 
@@ -2612,7 +2594,6 @@ static int __init mcheck_late_init(void)
 		static_branch_inc(&mcsafe_key);
 
 	mcheck_debugfs_init();
-	cec_init();
 
 	/*
 	 * Flush out everything that has been logged during early boot, now that
drivers/ras/cec.c +28 -2
index c09cf55e2d20..6b42040bf956 100644
@@ -309,7 +309,7 @@ static bool sanity_check(struct ce_array *ca)
 	return ret;
 }
 
-int cec_add_elem(u64 pfn)
+static int cec_add_elem(u64 pfn)
 {
 	struct ce_array *ca = &ce_arr;
 	unsigned int to = 0;
@@ -527,7 +527,30 @@ static int __init create_debugfs_nodes(void)
 	return 1;
 }
 
-void __init cec_init(void)
+static int cec_notifier(struct notifier_block *nb, unsigned long val,
+			void *data)
+{
+	struct mce *m = (struct mce *)data;
+
+	if (!m)
+		return NOTIFY_DONE;
+
+	/* We eat only correctable DRAM errors with usable addresses. */
+	if (mce_is_memory_error(m) &&
+	    mce_is_correctable(m)  &&
+	    mce_usable_address(m))
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
+			return NOTIFY_STOP;
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block cec_nb = {
+	.notifier_call	= cec_notifier,
+	.priority	= MCE_PRIO_CEC,
+};
+
+static void __init cec_init(void)
 {
 	if (ce_arr.disabled)
 		return;
@@ -546,8 +569,11 @@ void __init cec_init(void)
 	INIT_DELAYED_WORK(&cec_work, cec_work_fn);
 	schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL);
 
+	mce_register_decode_chain(&cec_nb);
+
 	pr_info("Correctable Errors collector initialized.\n");
 }
+late_initcall(cec_init);
 
 int __init parse_cec_param(char *str)
 {
include/linux/ras.h +0 -5
index 7c3debb47c87..1f4048bf2674 100644
@@ -17,12 +17,7 @@ static inline int ras_add_daemon_trace(void) { return 0; }
 #endif
 
 #ifdef CONFIG_RAS_CEC
-void __init cec_init(void);
 int __init parse_cec_param(char *str);
-int cec_add_elem(u64 pfn);
-#else
-static inline void __init cec_init(void)	{ }
-static inline int cec_add_elem(u64 pfn)		{ return -ENODEV; }
 #endif
 
 #ifdef CONFIG_RAS
Signature · 1 line
2.21.0
maintainer
#54 lore raw

PATCH v3 4/9 x86/mce: Add a struct mce.kflags field

In reply to Borislav Petkov

From: Tony Luck <[email protected]>

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

The default handler at the end of the chain can use this information to decide whether to print to the console log.

Boris suggested a generic name and leaving plenty of spare bits for possible future use.

[ bp: Move flag bits to the internal mce.h header and use BIT_ULL(). ]

---
 arch/x86/include/asm/mce.h      | 8 ++++++++
 arch/x86/include/uapi/asm/mce.h | 1 +
 2 files changed, 9 insertions(+)
arch/x86/include/asm/mce.h +8 -0
index 689ac6e9c65f..5f04a24f30ea 100644
@@ -129,6 +129,14 @@
 
 #define XEC(x, mask)			(((x) >> 16) & mask)
 
+/* mce.kflags flag bits for logging etc. */
+#define	MCE_HANDLED_CEC		BIT_ULL(0)
+#define	MCE_HANDLED_UC		BIT_ULL(1)
+#define	MCE_HANDLED_EXTLOG	BIT_ULL(2)
+#define	MCE_HANDLED_NFIT	BIT_ULL(3)
+#define	MCE_HANDLED_EDAC	BIT_ULL(4)
+#define	MCE_HANDLED_MCELOG	BIT_ULL(5)
+
 /*
  * This structure contains all data related to the MCE log.  Also
  * carries a signature to make it easier to find from external
arch/x86/include/uapi/asm/mce.h +1 -0
index 955c2a2e1cf9..5b59d80f1d4e 100644
@@ -35,6 +35,7 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u64 kflags;		/* Internal kernel use. See below */
 };
 
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
Signature · 1 line
2.21.0
author maintainer
#41 lore raw

RE: [PATCH v2 5/7] x86/mce: Change default mce logger to check mce->kflags

In reply to Borislav Petkov
Quoted 5 lines

arch/x86/kernel/cpu/mce/core.c static void __print_mce(struct mce *m) · line 253

Quoted 2 lines
arch/x86/kernel/cpu/mce/core.c +2 -0
+	if (m->kflags)
+		pr_emerg(HW_ERR "kflags = 0x%llx\n", m->kflags);

I've zapped that hunk. I'd like to avoid exposing those kflags to luserspace in any shape or form for now.

Sure. It was useful while I was debugging. But I'm sure all the bugs are gone now :-)

-Tony

maintainer
#42 lore raw

Re: [PATCH v2 5/7] x86/mce: Change default mce logger to check mce->kflags

Quoted 8 lines · Tony
Quoted 5 lines

arch/x86/kernel/cpu/mce/core.c static void __print_mce(struct mce *m) · line 253

Quoted 2 lines
arch/x86/kernel/cpu/mce/core.c +2 -0
+	if (m->kflags)
+		pr_emerg(HW_ERR "kflags = 0x%llx\n", m->kflags);

I've zapped that hunk. I'd like to avoid exposing those kflags to luserspace in any shape or form for now.

Sure. It was useful while I was debugging. But I'm sure all the bugs are gone now :-)

Do you need it for debugging?

If yes, it should be really clear that it is a debugging print and nothing should rely on it. We could do a cmdline-param controllable debugging scheme which tools cannot mistakenly start using and it becomes an ABI, all of a sudden.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#43 lore raw

RE: [PATCH v2 5/7] x86/mce: Change default mce logger to check mce->kflags

Quoted 4 lines
Quoted 2 lines

Sure. It was useful while I was debugging. But I'm sure all the bugs are gone now :-)

Do you need it for debugging?

I doubt it. It was handy to see that CEC/EDAC/MCELOG had correctly set their own bits while I was testing.

If I ever need to see it again, I can put a printk() back in.

-Tony

author maintainer Tested-by on the v3 series
#61 lore raw
In reply to Borislav Petkov
Quoted 7 lines

The last patch is something tglx spotted yesterday and fixing that with the MCE flags is pretty easy - was boxing with a wrapper struct around struct mce and that gets really ugly.

Tony, I'm open to suggestions how to test it - I probably don't have an access to such box which can trigger read errors on nvdimms or what was the use case?

It passes my smoke tests (uncorrectable error consumed by application and uncorrectable error consumed by mcsafe_memcpy()).

-Tony

maintainer
#62 lore raw
Quoted 2 lines · Tony

It passes my smoke tests (uncorrectable error consumed by application and uncorrectable error consumed by mcsafe_memcpy()).

That, of course, is even better, thanks for testing!

Quoted 1 line

Thx, I'll queue the whole pile next week.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
merge bot Applied
#27 lore raw

[tip: ras/core] x86/mce: Convert the CEC to use the MCE notifier

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     9554bfe403bdfc084823df8695a01f28c680af61
Gitweb:        https://git.kernel.org/tip/9554bfe403bdfc084823df8695a01f28c680af61
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:15 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:58:08 +02:00

x86/mce: Convert the CEC to use the MCE notifier

The CEC code has its claws in a couple of routines in mce/core.c. Convert it to just register itself on the normal MCE notifier chain.

[ bp: Make cec_add_elem() and cec_init() static. ]

---
 arch/x86/kernel/cpu/mce/core.c | 19 -------------------
 drivers/ras/cec.c              | 30 ++++++++++++++++++++++++++++--
 include/linux/ras.h            |  5 -----
 3 files changed, 28 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/mce/core.c +0 -19
index 43b1519..b033b35 100644
@@ -544,21 +544,6 @@ bool mce_is_correctable(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_is_correctable);
 
-static bool cec_add_mce(struct mce *m)
-{
-	if (!m)
-		return false;
-
-	/* We eat only correctable DRAM errors with usable addresses. */
-	if (mce_is_memory_error(m) &&
-	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return true;
-
-	return false;
-}
-
 static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
@@ -567,9 +552,6 @@ static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (cec_add_mce(m))
-		return NOTIFY_STOP;
-
 	/* Emit the trace record: */
 	trace_mce_record(m);
 
@@ -2612,7 +2594,6 @@ static int __init mcheck_late_init(void)
 		static_branch_inc(&mcsafe_key);
 
 	mcheck_debugfs_init();
-	cec_init();
 
 	/*
 	 * Flush out everything that has been logged during early boot, now that
drivers/ras/cec.c +28 -2
index c09cf55..6b42040 100644
@@ -309,7 +309,7 @@ static bool sanity_check(struct ce_array *ca)
 	return ret;
 }
 
-int cec_add_elem(u64 pfn)
+static int cec_add_elem(u64 pfn)
 {
 	struct ce_array *ca = &ce_arr;
 	unsigned int to = 0;
@@ -527,7 +527,30 @@ err:
 	return 1;
 }
 
-void __init cec_init(void)
+static int cec_notifier(struct notifier_block *nb, unsigned long val,
+			void *data)
+{
+	struct mce *m = (struct mce *)data;
+
+	if (!m)
+		return NOTIFY_DONE;
+
+	/* We eat only correctable DRAM errors with usable addresses. */
+	if (mce_is_memory_error(m) &&
+	    mce_is_correctable(m)  &&
+	    mce_usable_address(m))
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
+			return NOTIFY_STOP;
+
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block cec_nb = {
+	.notifier_call	= cec_notifier,
+	.priority	= MCE_PRIO_CEC,
+};
+
+static void __init cec_init(void)
 {
 	if (ce_arr.disabled)
 		return;
@@ -546,8 +569,11 @@ void __init cec_init(void)
 	INIT_DELAYED_WORK(&cec_work, cec_work_fn);
 	schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL);
 
+	mce_register_decode_chain(&cec_nb);
+
 	pr_info("Correctable Errors collector initialized.\n");
 }
+late_initcall(cec_init);
 
 int __init parse_cec_param(char *str)
 {
include/linux/ras.h +0 -5
index 7c3debb..1f4048b 100644
@@ -17,12 +17,7 @@ static inline int ras_add_daemon_trace(void) { return 0; }
 #endif
 
 #ifdef CONFIG_RAS_CEC
-void __init cec_init(void);
 int __init parse_cec_param(char *str);
-int cec_add_elem(u64 pfn);
-#else
-static inline void __init cec_init(void)	{ }
-static inline int cec_add_elem(u64 pfn)		{ return -ENODEV; }
 #endif
 
 #ifdef CONFIG_RAS
merge bot Applied
#25 lore raw

[tip: ras/core] x86/mce: Rename "first" function as "early"

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     c9c6d216ed28be6e2c91e3651af169eca284813a
Gitweb:        https://git.kernel.org/tip/c9c6d216ed28be6e2c91e3651af169eca284813a
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:14 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:55:01 +02:00

x86/mce: Rename "first" function as "early"

It isn't going to be first on the notifier chain when the CEC is moved to be a normal user of the notifier chain.

Fix the enum for the MCE_PRIO symbols to list them in reverse order so that the compiler can give them numbers from low to high priority. Add an entry for MCE_PRIO_CEC as the highest priority.

[ bp: Use passive voice, add comments. ]

---
 arch/x86/include/asm/mce.h     | 16 +++++++++-------
 arch/x86/kernel/cpu/mce/core.c | 10 +++++-----
 2 files changed, 14 insertions(+), 12 deletions(-)
arch/x86/include/asm/mce.h +9 -7
index 83b6dda..689ac6e 100644
@@ -144,14 +144,16 @@ struct mce_log_buffer {
 	struct mce entry[];
 };
 
+/* Highest last */
 enum mce_notifier_prios {
-	MCE_PRIO_FIRST		= INT_MAX,
-	MCE_PRIO_UC		= INT_MAX - 1,
-	MCE_PRIO_EXTLOG		= INT_MAX - 2,
-	MCE_PRIO_NFIT		= INT_MAX - 3,
-	MCE_PRIO_EDAC		= INT_MAX - 4,
-	MCE_PRIO_MCELOG		= 1,
-	MCE_PRIO_LOWEST		= 0,
+	MCE_PRIO_LOWEST,
+	MCE_PRIO_MCELOG,
+	MCE_PRIO_EDAC,
+	MCE_PRIO_NFIT,
+	MCE_PRIO_EXTLOG,
+	MCE_PRIO_UC,
+	MCE_PRIO_EARLY,
+	MCE_PRIO_CEC
 };
 
 struct notifier_block;
arch/x86/kernel/cpu/mce/core.c +5 -5
index a6009ef..43b1519 100644
@@ -559,7 +559,7 @@ static bool cec_add_mce(struct mce *m)
 	return false;
 }
 
-static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
+static int mce_early_notifier(struct notifier_block *nb, unsigned long val,
 			      void *data)
 {
 	struct mce *m = (struct mce *)data;
@@ -580,9 +580,9 @@ static int mce_first_notifier(struct notifier_block *nb, unsigned long val,
 	return NOTIFY_DONE;
 }
 
-static struct notifier_block first_nb = {
-	.notifier_call	= mce_first_notifier,
-	.priority	= MCE_PRIO_FIRST,
+static struct notifier_block early_nb = {
+	.notifier_call	= mce_early_notifier,
+	.priority	= MCE_PRIO_EARLY,
 };
 
 static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
@@ -2041,7 +2041,7 @@ __setup("mce", mcheck_enable);
 int __init mcheck_init(void)
 {
 	mcheck_intel_therm_init();
-	mce_register_decode_chain(&first_nb);
+	mce_register_decode_chain(&early_nb);
 	mce_register_decode_chain(&mce_uc_nb);
 	mce_register_decode_chain(&mce_default_nb);
 	mcheck_vendor_init_severity();
#60 lore raw

[tip: ras/core] x86/mce: Fixup exception only for the correct MCEs

In reply to Borislav Petkov
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     1df73b2131e3b33d518609769636b41ce00212de
Gitweb:        https://git.kernel.org/tip/1df73b2131e3b33d518609769636b41ce00212de
Author:        Borislav Petkov <[email protected]>
AuthorDate:    Tue, 07 Apr 2020 13:49:58 +02:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 16:01:49 +02:00

x86/mce: Fixup exception only for the correct MCEs

The severity grading code returns IN_KERNEL_RECOV error context for errors which have happened in kernel space but from which the kernel can recover. Whether the recovery can happen is determined by the exception table entry having as handler ex_handler_fault() and which has been declared at build time using _ASM_EXTABLE_FAULT().

IN_KERNEL_RECOV is used in mce_severity_intel() to lookup the corresponding error severity in the severities table.

However, the mapping back from error severity to whether the error is IN_KERNEL_RECOV is ambiguous and in the very paranoid case - which might not be possible right now - but be better safe than sorry later, an exception fixup could be attempted for another MCE whose address is in the exception table and has the proper severity. Which would be unfortunate, to say the least.

Therefore, mark such MCEs explicitly as MCE_IN_KERNEL_RECOV so that the recovery attempt is done only for them.

Document the whole handling, while at it, as it is not trivial.

---
 arch/x86/include/asm/mce.h         |  1 +
 arch/x86/kernel/cpu/mce/core.c     | 15 +++++++++++++--
 arch/x86/kernel/cpu/mce/severity.c |  6 +++++-
 3 files changed, 19 insertions(+), 3 deletions(-)
arch/x86/include/asm/mce.h +1 -0
index 5f04a24..c598aaa 100644
@@ -136,6 +136,7 @@
 #define	MCE_HANDLED_NFIT	BIT_ULL(3)
 #define	MCE_HANDLED_EDAC	BIT_ULL(4)
 #define	MCE_HANDLED_MCELOG	BIT_ULL(5)
+#define MCE_IN_KERNEL_RECOV	BIT_ULL(6)
 
 /*
  * This structure contains all data related to the MCE log.  Also
arch/x86/kernel/cpu/mce/core.c +13 -2
index 4efe6c1..02e1f16 100644
@@ -1331,8 +1331,19 @@ void notrace do_machine_check(struct pt_regs *regs, long error_code)
 		local_irq_disable();
 		ist_end_non_atomic();
 	} else {
-		if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0))
-			mce_panic("Failed kernel mode recovery", &m, msg);
+		/*
+		 * Handle an MCE which has happened in kernel space but from
+		 * which the kernel can recover: ex_has_fault_handler() has
+		 * already verified that the rIP at which the error happened is
+		 * a rIP from which the kernel can recover (by jumping to
+		 * recovery code specified in _ASM_EXTABLE_FAULT()) and the
+		 * corresponding exception handler which would do that is the
+		 * proper one.
+		 */
+		if (m.kflags & MCE_IN_KERNEL_RECOV) {
+			if (!fixup_exception(regs, X86_TRAP_MC, error_code, 0))
+				mce_panic("Failed kernel mode recovery", &m, msg);
+		}
 	}
 
 out_ist:
arch/x86/kernel/cpu/mce/severity.c +5 -1
index 87bcdc6..e1da619 100644
@@ -213,8 +213,12 @@ static int error_context(struct mce *m)
 {
 	if ((m->cs & 3) == 3)
 		return IN_USER;
-	if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip))
+
+	if (mc_recoverable(m->mcgstatus) && ex_has_fault_handler(m->ip)) {
+		m->kflags |= MCE_IN_KERNEL_RECOV;
 		return IN_KERNEL_RECOV;
+	}
+
 	return IN_KERNEL;
 }
 
merge bot Applied
#44 lore raw

[tip: ras/core] x86/mce: Change default MCE logger to check mce->kflags

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     925946cfa715a5a71639528f82b98e58f14dd4cb
Gitweb:        https://git.kernel.org/tip/925946cfa715a5a71639528f82b98e58f14dd4cb
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:18 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:59:57 +02:00

x86/mce: Change default MCE logger to check mce->kflags

Instead of keeping count of how many handlers are registered on the MCE notifier chain and printing if below some magic value, look at mce->kflags to see if anyone claims to have handled/logged this error.

[ bp: Do not print ->kflags in __print_mce(). ]

---
 arch/x86/kernel/cpu/mce/core.c | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -16
index 5666a48..fc879b6 100644
@@ -158,29 +158,17 @@ void mce_log(struct mce *m)
 }
 EXPORT_SYMBOL_GPL(mce_log);
 
-/*
- * We run the default notifier if we have only the UC, the first and the
- * default notifier registered. I.e., the mandatory NUM_DEFAULT_NOTIFIERS
- * notifiers registered on the chain.
- */
-#define NUM_DEFAULT_NOTIFIERS	3
-static atomic_t num_notifiers;
-
 void mce_register_decode_chain(struct notifier_block *nb)
 {
 	if (WARN_ON(nb->priority > MCE_PRIO_MCELOG && nb->priority < MCE_PRIO_EDAC))
 		return;
 
-	atomic_inc(&num_notifiers);
-
 	blocking_notifier_chain_register(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_register_decode_chain);
 
 void mce_unregister_decode_chain(struct notifier_block *nb)
 {
-	atomic_dec(&num_notifiers);
-
 	blocking_notifier_chain_unregister(&x86_mce_decoder_chain, nb);
 }
 EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
@@ -263,6 +251,7 @@ static void __print_mce(struct mce *m)
 	}
 
 	pr_cont("\n");
+
 	/*
 	 * Note this output is parsed by external tools and old fields
 	 * should not be changed.
@@ -602,10 +591,8 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (atomic_read(&num_notifiers) > NUM_DEFAULT_NOTIFIERS)
-		return NOTIFY_DONE;
-
-	__print_mce(m);
+	if (!m->kflags)
+		__print_mce(m);
 
 	return NOTIFY_DONE;
 }
merge bot Applied
#46 lore raw

[tip: ras/core] x86/mce: Add mce=print_all option

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     43505646941bee217b91d064756975aa1ab6ee3b
Gitweb:        https://git.kernel.org/tip/43505646941bee217b91d064756975aa1ab6ee3b
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:19 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 16:00:30 +02:00

x86/mce: Add mce=print_all option

Sometimes, when logs are getting lost, it's nice to just have everything dumped to the serial console.

---
 arch/x86/kernel/cpu/mce/core.c     | 7 ++++++-
 arch/x86/kernel/cpu/mce/internal.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/mce/core.c +6 -1
index fc879b6..4efe6c1 100644
@@ -591,7 +591,7 @@ static int mce_default_notifier(struct notifier_block *nb, unsigned long val,
 	if (!m)
 		return NOTIFY_DONE;
 
-	if (!m->kflags)
+	if (mca_cfg.print_all || !m->kflags)
 		__print_mce(m);
 
 	return NOTIFY_DONE;
@@ -1962,6 +1962,7 @@ void mce_disable_bank(int bank)
  * mce=no_cmci Disables CMCI
  * mce=no_lmce Disables LMCE
  * mce=dont_log_ce Clears corrected events silently, no log created for CEs.
+ * mce=print_all Print all machine check logs to console
  * mce=ignore_ce Disables polling and CMCI, corrected events are not cleared.
  * mce=TOLERANCELEVEL[,monarchtimeout] (number, see above)
  *	monarchtimeout is how long to wait for other CPUs on machine
@@ -1990,6 +1991,8 @@ static int __init mcheck_enable(char *str)
 		cfg->lmce_disabled = 1;
 	else if (!strcmp(str, "dont_log_ce"))
 		cfg->dont_log_ce = true;
+	else if (!strcmp(str, "print_all"))
+		cfg->print_all = true;
 	else if (!strcmp(str, "ignore_ce"))
 		cfg->ignore_ce = true;
 	else if (!strcmp(str, "bootlog") || !strcmp(str, "nobootlog"))
@@ -2256,6 +2259,7 @@ static ssize_t store_int_with_restart(struct device *s,
 static DEVICE_INT_ATTR(tolerant, 0644, mca_cfg.tolerant);
 static DEVICE_INT_ATTR(monarch_timeout, 0644, mca_cfg.monarch_timeout);
 static DEVICE_BOOL_ATTR(dont_log_ce, 0644, mca_cfg.dont_log_ce);
+static DEVICE_BOOL_ATTR(print_all, 0644, mca_cfg.print_all);
 
 static struct dev_ext_attribute dev_attr_check_interval = {
 	__ATTR(check_interval, 0644, device_show_int, store_int_with_restart),
@@ -2280,6 +2284,7 @@ static struct device_attribute *mce_device_attrs[] = {
 #endif
 	&dev_attr_monarch_timeout.attr,
 	&dev_attr_dont_log_ce.attr,
+	&dev_attr_print_all.attr,
 	&dev_attr_ignore_ce.attr,
 	&dev_attr_cmci_disabled.attr,
 	NULL
arch/x86/kernel/cpu/mce/internal.h +1 -0
index 74a0182..55f5c7b 100644
@@ -119,6 +119,7 @@ struct mca_config {
 	bool dont_log_ce;
 	bool cmci_disabled;
 	bool ignore_ce;
+	bool print_all;
 
 	__u64 lmce_disabled		: 1,
 	      disabled			: 1,
#51 lore raw

[tip: ras/core] x86/mce/amd, edac: Remove report_gart_errors

In reply to Borislav Petkov
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     3e0fdec858d82c829774f271e88b5ceb17051551
Gitweb:        https://git.kernel.org/tip/3e0fdec858d82c829774f271e88b5ceb17051551
Author:        Borislav Petkov <[email protected]>
AuthorDate:    Tue, 07 Apr 2020 09:55:10 +02:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:53:46 +02:00

x86/mce/amd, edac: Remove report_gart_errors

... because no one should be interested in spurious MCEs anyway. Make the filtering unconditional and move it to amd_filter_mce().

---
 arch/x86/include/asm/mce.h    |  3 ++-
 arch/x86/kernel/cpu/mce/amd.c |  9 +++++++--
 drivers/edac/amd64_edac.c     |  8 --------
 drivers/edac/mce_amd.c        | 24 ------------------------
 drivers/edac/mce_amd.h        |  2 --
 5 files changed, 9 insertions(+), 37 deletions(-)
arch/x86/include/asm/mce.h +2 -1
index f9cea08..83b6dda 100644
@@ -127,6 +127,8 @@
 #define MSR_AMD64_SMCA_MCx_DEADDR(x)	(MSR_AMD64_SMCA_MC0_DEADDR + 0x10*(x))
 #define MSR_AMD64_SMCA_MCx_MISCy(x, y)	((MSR_AMD64_SMCA_MC0_MISC1 + y) + (0x10*(x)))
 
+#define XEC(x, mask)			(((x) >> 16) & mask)
+
 /*
  * This structure contains all data related to the MCE log.  Also
  * carries a signature to make it easier to find from external
@@ -347,5 +349,4 @@ umc_normaddr_to_sysaddr(u64 norm_addr, u16 nid, u8 umc, u64 *sys_addr)	{ return 
 #endif
 
 static inline void mce_hygon_feature_init(struct cpuinfo_x86 *c)	{ return mce_amd_feature_init(c); }
-
 #endif /* _ASM_X86_MCE_H */
arch/x86/kernel/cpu/mce/amd.c +7 -2
index 15c87b8..ea3cf71 100644
@@ -577,14 +577,19 @@ bool amd_filter_mce(struct mce *m)
 {
 	enum smca_bank_types bank_type = smca_get_bank_type(m->bank);
 	struct cpuinfo_x86 *c = &boot_cpu_data;
-	u8 xec = (m->status >> 16) & 0x3F;
 
 	/* See Family 17h Models 10h-2Fh Erratum #1114. */
 	if (c->x86 == 0x17 &&
 	    c->x86_model >= 0x10 && c->x86_model <= 0x2F &&
-	    bank_type == SMCA_IF && xec == 10)
+	    bank_type == SMCA_IF && XEC(m->status, 0x3f) == 10)
 		return true;
 
+	/* NB GART TLB error reporting is disabled by default. */
+	if (c->x86 < 0x17) {
+		if (m->bank == 4 && XEC(m->status, 0x1f) == 0x5)
+			return true;
+	}
+
 	return false;
 }
 
drivers/edac/amd64_edac.c +0 -8
index f91f3bc..6bdc5bb 100644
@@ -4,9 +4,6 @@
 
 static struct edac_pci_ctl_info *pci_ctl;
 
-static int report_gart_errors;
-module_param(report_gart_errors, int, 0644);
-
 /*
  * Set by command line parameter. If BIOS has enabled the ECC, this override is
  * cleared to prevent re-enabling the hardware by this driver.
@@ -3681,9 +3678,6 @@ static int __init amd64_edac_init(void)
 	}
 
 	/* register stuff with EDAC MCE */
-	if (report_gart_errors)
-		amd_report_gart_errors(true);
-
 	if (boot_cpu_data.x86 >= 0x17)
 		amd_register_ecc_decoder(decode_umc_error);
 	else
@@ -3718,8 +3712,6 @@ static void __exit amd64_edac_exit(void)
 		edac_pci_release_generic_ctl(pci_ctl);
 
 	/* unregister from EDAC MCE */
-	amd_report_gart_errors(false);
-
 	if (boot_cpu_data.x86 >= 0x17)
 		amd_unregister_ecc_decoder(decode_umc_error);
 	else
drivers/edac/mce_amd.c +0 -24
index 8874b77..e58644d 100644
@@ -10,15 +10,8 @@ static struct amd_decoder_ops fam_ops;
 
 static u8 xec_mask	 = 0xf;
 
-static bool report_gart_errors;
 static void (*decode_dram_ecc)(int node_id, struct mce *m);
 
-void amd_report_gart_errors(bool v)
-{
-	report_gart_errors = v;
-}
-EXPORT_SYMBOL_GPL(amd_report_gart_errors);
-
 void amd_register_ecc_decoder(void (*f)(int, struct mce *))
 {
 	decode_dram_ecc = f;
@@ -1030,20 +1023,6 @@ static inline void amd_decode_err_code(u16 ec)
 	pr_cont("\n");
 }
 
-/*
- * Filter out unwanted MCE signatures here.
- */
-static bool ignore_mce(struct mce *m)
-{
-	/*
-	 * NB GART TLB error reporting is disabled by default.
-	 */
-	if (m->bank == 4 && XEC(m->status, 0x1f) == 0x5 && !report_gart_errors)
-		return true;
-
-	return false;
-}
-
 static const char *decode_error_status(struct mce *m)
 {
 	if (m->status & MCI_STATUS_UC) {
@@ -1067,9 +1046,6 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
-	if (ignore_mce(m))
-		return NOTIFY_STOP;
-
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
 	pr_emerg(HW_ERR "CPU:%d (%x:%x:%x) MC%d_STATUS[%s|%s|%s|%s|%s",
drivers/edac/mce_amd.h +0 -2
index 4e9c5e5..4811b18 100644
@@ -7,7 +7,6 @@
 #include <asm/mce.h>
 
 #define EC(x)				((x) & 0xffff)
-#define XEC(x, mask)			(((x) >> 16) & mask)
 
 #define LOW_SYNDROME(x)			(((x) >> 15) & 0xff)
 #define HIGH_SYNDROME(x)		(((x) >> 24) & 0xff)
@@ -77,7 +76,6 @@ struct amd_decoder_ops {
 	bool (*mc2_mce)(u16, u8);
 };
 
-void amd_report_gart_errors(bool);
 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
 void amd_unregister_ecc_decoder(void (*f)(int, struct mce *));
 
merge bot Applied
#38 lore raw

[tip: ras/core] x86/mce: Fix all mce notifiers to update the mce->kflags bitmask

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     23ba710a0864108910c7531dc4c73ef65eca5568
Gitweb:        https://git.kernel.org/tip/23ba710a0864108910c7531dc4c73ef65eca5568
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:17 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:59:26 +02:00

x86/mce: Fix all mce notifiers to update the mce->kflags bitmask

If the handler took any action to log or deal with the error, set a bit in mce->kflags so that the default handler on the end of the machine check chain can see what has been done.

Get rid of NOTIFY_STOP returns. Make the EDAC and dev-mcelog handlers skip over errors already processed by CEC.

---
 arch/x86/kernel/cpu/mce/core.c       |  4 +++-
 arch/x86/kernel/cpu/mce/dev-mcelog.c |  5 +++++
 drivers/acpi/acpi_extlog.c           |  5 +++--
 drivers/acpi/nfit/mce.c              |  1 +
 drivers/edac/i7core_edac.c           |  5 +++--
 drivers/edac/mce_amd.c               |  6 +++++-
 drivers/edac/pnd2_edac.c             |  5 +++--
 drivers/edac/sb_edac.c               |  5 ++++-
 drivers/edac/skx_common.c            |  4 ++++
 drivers/ras/cec.c                    |  9 ++++++---
 10 files changed, 37 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/mce/core.c +3 -1
index b033b35..5666a48 100644
@@ -581,8 +581,10 @@ static int uc_decode_notifier(struct notifier_block *nb, unsigned long val,
 		return NOTIFY_DONE;
 
 	pfn = mce->addr >> PAGE_SHIFT;
-	if (!memory_failure(pfn, 0))
+	if (!memory_failure(pfn, 0)) {
 		set_mce_nospec(pfn);
+		mce->kflags |= MCE_HANDLED_UC;
+	}
 
 	return NOTIFY_OK;
 }
arch/x86/kernel/cpu/mce/dev-mcelog.c +5 -0
index d089567..c033e7e 100644
@@ -39,6 +39,9 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 	struct mce *mce = (struct mce *)data;
 	unsigned int entry;
 
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	mutex_lock(&mce_chrdev_read_mutex);
 
 	entry = mcelog->next;
@@ -56,6 +59,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 
 	memcpy(mcelog->entry + entry, mce, sizeof(struct mce));
 	mcelog->entry[entry].finished = 1;
+	mcelog->entry[entry].kflags = 0;
 
 	/* wake processes polling /dev/mcelog */
 	wake_up_interruptible(&mce_chrdev_wait);
@@ -63,6 +67,7 @@ static int dev_mce_log(struct notifier_block *nb, unsigned long val,
 unlock:
 	mutex_unlock(&mce_chrdev_read_mutex);
 
+	mce->kflags |= MCE_HANDLED_MCELOG;
 	return NOTIFY_OK;
 }
 
drivers/acpi/acpi_extlog.c +3 -2
index 8596a10..9cc3c1f 100644
@@ -146,7 +146,7 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	static u32 err_seq;
 
 	estatus = extlog_elog_entry_check(cpu, bank);
-	if (estatus == NULL)
+	if (estatus == NULL || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	memcpy(elog_buf, (void *)estatus, ELOG_ENTRY_LEN);
@@ -176,7 +176,8 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
 	}
 
 out:
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EXTLOG;
+	return NOTIFY_OK;
 }
 
 static bool __init extlog_get_l1addr(void)
drivers/acpi/nfit/mce.c +1 -0
index f0ae485..ee8d997 100644
@@ -76,6 +76,7 @@ static int nfit_handle_mce(struct notifier_block *nb, unsigned long val,
 			 */
 			acpi_nfit_ars_rescan(acpi_desc, 0);
 		}
+		mce->kflags |= MCE_HANDLED_NFIT;
 		break;
 	}
 
drivers/edac/i7core_edac.c +3 -2
index b3135b2..5860ca4 100644
@@ -1815,7 +1815,7 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 
 	i7_dev = get_i7core_dev(mce->socketid);
-	if (!i7_dev)
+	if (!i7_dev || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	mci = i7_dev->mci;
@@ -1834,7 +1834,8 @@ static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
 	i7core_check_error(mci, mce);
 
 	/* Advise mcelog that the errors were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block i7_mce_dec = {
drivers/edac/mce_amd.c +5 -1
index e58644d..2b5401d 100644
@@ -1046,6 +1046,9 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
 	unsigned int fam = x86_family(m->cpuid);
 	int ecc;
 
+	if (m->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	pr_emerg(HW_ERR "%s\n", decode_error_status(m));
 
 	pr_emerg(HW_ERR "CPU:%d (%x:%x:%x) MC%d_STATUS[%s|%s|%s|%s|%s",
@@ -1146,7 +1149,8 @@ amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
  err_code:
 	amd_decode_err_code(m->status & 0xffff);
 
-	return NOTIFY_STOP;
+	m->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block amd_mce_dec_nb = {
drivers/edac/pnd2_edac.c +3 -2
index bc47328..1929a5d 100644
@@ -1400,7 +1400,7 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 		return NOTIFY_DONE;
 
 	mci = pnd2_mci;
-	if (!mci)
+	if (!mci || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
 
 	/*
@@ -1429,7 +1429,8 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	pnd2_mce_output_error(mci, mce, &daddr);
 
 	/* Advice mcelog that the error were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block pnd2_mce_dec = {
drivers/edac/sb_edac.c +4 -1
index 7d51c82..f790f7d 100644
@@ -3136,6 +3136,8 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
 		return NOTIFY_DONE;
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
 
 	/*
 	 * Just let mcelog handle it if the error is
@@ -3183,7 +3185,8 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	sbridge_mce_output_error(mci, mce);
 
 	/* Advice mcelog that the error were handled */
-	return NOTIFY_STOP;
+	mce->kflags |= MCE_HANDLED_EDAC;
+	return NOTIFY_OK;
 }
 
 static struct notifier_block sbridge_mce_dec = {
drivers/edac/skx_common.c +4 -0
index 99bbaf6..6f08a12 100644
@@ -577,6 +577,9 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
 		return NOTIFY_DONE;
 
+	if (mce->kflags & MCE_HANDLED_CEC)
+		return NOTIFY_DONE;
+
 	/* ignore unless this is memory related with an address */
 	if ((mce->status & 0xefff) >> 7 != 1 || !(mce->status & MCI_STATUS_ADDRV))
 		return NOTIFY_DONE;
@@ -616,6 +619,7 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 
 	skx_mce_output_error(mci, mce, &res);
 
+	mce->kflags |= MCE_HANDLED_EDAC;
 	return NOTIFY_DONE;
 }
 
drivers/ras/cec.c +6 -3
index 6b42040..569d9ad 100644
@@ -538,9 +538,12 @@ static int cec_notifier(struct notifier_block *nb, unsigned long val,
 	/* We eat only correctable DRAM errors with usable addresses. */
 	if (mce_is_memory_error(m) &&
 	    mce_is_correctable(m)  &&
-	    mce_usable_address(m))
-		if (!cec_add_elem(m->addr >> PAGE_SHIFT))
-			return NOTIFY_STOP;
+	    mce_usable_address(m)) {
+		if (!cec_add_elem(m->addr >> PAGE_SHIFT)) {
+			m->kflags |= MCE_HANDLED_CEC;
+			return NOTIFY_OK;
+		}
+	}
 
 	return NOTIFY_DONE;
 }
merge bot Applied
#48 lore raw

[tip: ras/core] EDAC: Drop the EDAC report status checks

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     7fc0b9b995f222646ece8d5bca528060c098ee88
Gitweb:        https://git.kernel.org/tip/7fc0b9b995f222646ece8d5bca528060c098ee88
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:20 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 16:01:01 +02:00

EDAC: Drop the EDAC report status checks

When acpi_extlog was added, we were worried that the same error would be reported more than once by different subsystems. But in the ensuing years I've seen complaints that people could not find an error log (because this mechanism suppressed the log they were looking for).

Rip it all out. People are smart enough to notice the same address from different reporting mechanisms.

---
 drivers/acpi/acpi_extlog.c | 14 +--------
 drivers/edac/edac_mc.c     | 61 +-------------------------------------
 drivers/edac/pnd2_edac.c   |  3 +--
 drivers/edac/sb_edac.c     |  4 +--
 drivers/edac/skx_common.c  |  3 +--
 include/linux/edac.h       |  8 +-----
 6 files changed, 93 deletions(-)
drivers/acpi/acpi_extlog.c +0 -14
index 9cc3c1f..f138e12 100644
@@ -42,8 +42,6 @@ struct extlog_l1_head {
 	u8  rev1[12];
 };
 
-static int old_edac_report_status;
-
 static u8 extlog_dsm_uuid[] __initdata = "663E35AF-CC10-41A4-88EA-5470AF055295";
 
 /* L1 table related physical address */
@@ -229,11 +227,6 @@ static int __init extlog_init(void)
 	if (!(cap & MCG_ELOG_P) || !extlog_get_l1addr())
 		return -ENODEV;
 
-	if (edac_get_report_status() == EDAC_REPORTING_FORCE) {
-		pr_warn("Not loading eMCA, error reporting force-enabled through EDAC.\n");
-		return -EPERM;
-	}
-
 	rc = -EINVAL;
 	/* get L1 header to fetch necessary information */
 	l1_hdr_size = sizeof(struct extlog_l1_head);
@@ -281,12 +274,6 @@ static int __init extlog_init(void)
 	if (elog_buf == NULL)
 		goto err_release_elog;
 
-	/*
-	 * eMCA event report method has higher priority than EDAC method,
-	 * unless EDAC event report method is mandatory.
-	 */
-	old_edac_report_status = edac_get_report_status();
-	edac_set_report_status(EDAC_REPORTING_DISABLED);
 	mce_register_decode_chain(&extlog_mce_dec);
 	/* enable OS to be involved to take over management from BIOS */
 	((struct extlog_l1_head *)extlog_l1_addr)->flags |= FLAG_OS_OPTIN;
@@ -308,7 +295,6 @@ err:
 
 static void __exit extlog_exit(void)
 {
-	edac_set_report_status(old_edac_report_status);
 	mce_unregister_decode_chain(&extlog_mce_dec);
 	((struct extlog_l1_head *)extlog_l1_addr)->flags &= ~FLAG_OS_OPTIN;
 	if (extlog_l1_addr)
drivers/edac/edac_mc.c +0 -61

73 lines not on this page · raw message

drivers/edac/pnd2_edac.c +0 -3
index 1929a5d..c1f2e6d 100644
@@ -1396,9 +1396,6 @@ static int pnd2_mce_check_error(struct notifier_block *nb, unsigned long val, vo
 	struct dram_addr daddr;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
-
 	mci = pnd2_mci;
 	if (!mci || (mce->kflags & MCE_HANDLED_CEC))
 		return NOTIFY_DONE;
drivers/edac/sb_edac.c +0 -4
index f790f7d..d414698 100644
@@ -3134,8 +3134,6 @@ static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
 	if (mce->kflags & MCE_HANDLED_CEC)
 		return NOTIFY_DONE;
 
@@ -3526,8 +3524,6 @@ static int __init sbridge_init(void)
 
 	if (rc >= 0) {
 		mce_register_decode_chain(&sbridge_mce_dec);
-		if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-			sbridge_printk(KERN_WARNING, "Loading driver, error reporting disabled.\n");
 		return 0;
 	}
 
drivers/edac/skx_common.c +0 -3
index 6f08a12..423d33a 100644
@@ -574,9 +574,6 @@ int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
 	struct mem_ctl_info *mci;
 	char *type;
 
-	if (edac_get_report_status() == EDAC_REPORTING_DISABLED)
-		return NOTIFY_DONE;
-
 	if (mce->kflags & MCE_HANDLED_CEC)
 		return NOTIFY_DONE;
 
include/linux/edac.h +0 -8
index 0f20b98..6eb7d55 100644
@@ -31,14 +31,6 @@ struct device;
 extern int edac_op_state;
 
 struct bus_type *edac_get_sysfs_subsys(void);
-int edac_get_report_status(void);
-void edac_set_report_status(int new);
-
-enum {
-	EDAC_REPORTING_ENABLED,
-	EDAC_REPORTING_DISABLED,
-	EDAC_REPORTING_FORCE
-};
 
 static inline void opstate_init(void)
 {
merge bot Applied
#29 lore raw

[tip: ras/core] x86/mce: Add a struct mce.kflags field

In reply to Tony Luck
The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     1de08dccd383482a3e88845d3554094d338f5ff9
Gitweb:        https://git.kernel.org/tip/1de08dccd383482a3e88845d3554094d338f5ff9
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:16 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:58:43 +02:00

x86/mce: Add a struct mce.kflags field

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

The default handler at the end of the chain can use this information to decide whether to print to the console log.

Boris suggested a generic name and leaving plenty of spare bits for possible future use.

[ bp: Move flag bits to the internal mce.h header and use BIT_ULL(). ]

---
 arch/x86/include/asm/mce.h      | 8 ++++++++
 arch/x86/include/uapi/asm/mce.h | 1 +
 2 files changed, 9 insertions(+)
arch/x86/include/asm/mce.h +8 -0
index 689ac6e..5f04a24 100644
@@ -129,6 +129,14 @@
 
 #define XEC(x, mask)			(((x) >> 16) & mask)
 
+/* mce.kflags flag bits for logging etc. */
+#define	MCE_HANDLED_CEC		BIT_ULL(0)
+#define	MCE_HANDLED_UC		BIT_ULL(1)
+#define	MCE_HANDLED_EXTLOG	BIT_ULL(2)
+#define	MCE_HANDLED_NFIT	BIT_ULL(3)
+#define	MCE_HANDLED_EDAC	BIT_ULL(4)
+#define	MCE_HANDLED_MCELOG	BIT_ULL(5)
+
 /*
  * This structure contains all data related to the MCE log.  Also
  * carries a signature to make it easier to find from external
arch/x86/include/uapi/asm/mce.h +1 -0
index 955c2a2..5b59d80 100644
@@ -35,6 +35,7 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u64 kflags;		/* Internal kernel use. See below */
 };
 
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
author maintainer
#30 lore raw

RE: [tip: ras/core] x86/mce: Add a struct mce.kflags field

arch/x86/include/uapi/asm/mce.h struct mce { · line 39

Quoted 10 lines
arch/x86/include/uapi/asm/mce.h +1 -0
index 955c2a2..5b59d80 100644
@@ -35,6 +35,7 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
+	__u64 kflags;		/* Internal kernel use. See below */
 };

Minor nit. You moved the #defines for the kflags bits to internal.h (which was a good thing), but left the "See below" comment here.

-Tony

#31 lore raw

Re: [tip: ras/core] x86/mce: Add a struct mce.kflags field

Quoted 2 lines · Tony

Minor nit. You moved the #defines for the kflags bits to internal.h (which was a good thing), but left the "See below" comment here.

Yeah, can't rebase anymore but I'd take a fix ontop.

;-)

Signature · 4 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg
author maintainer
#32 lore raw

PATCH 1/1 x86/mce: Drop bogus comment about mce.kflags

The bit definitions for kflags are for internal use only. A late edit moved them from uapi/asm/mce.h to the internal x86 <asm/mce.h>, but the comment saying "See below" was accidentally left here.

Delete "See below". Just labelling this field as internal kernel use is sufficient.

Fixes 1de08dccd383 ("x86/mce: Add a struct mce.kflags field")
---
 arch/x86/include/uapi/asm/mce.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/uapi/asm/mce.h +1 -1
index 5b59d80f1d4e..db9adc081c5a 100644
@@ -35,7 +35,7 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
-	__u64 kflags;		/* Internal kernel use. See below */
+	__u64 kflags;		/* Internal kernel use */
 };
 
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
Signature · 1 line
2.21.1
merge bot Applied
#33 lore raw

[tip: ras/core] x86/mce: Drop bogus comment about mce.kflags

The following commit has been merged into the ras/core branch of tip:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     f82cdff1aa7f6dcf6625c7219342a6e5c977098d
Gitweb:        https://git.kernel.org/tip/f82cdff1aa7f6dcf6625c7219342a6e5c977098d
Author:        Tony Luck <[email protected]>
AuthorDate:    Wed, 15 Apr 2020 12:58:26 -07:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Fri, 17 Apr 2020 11:12:21 +02:00

x86/mce: Drop bogus comment about mce.kflags

The bit definitions for kflags are for internal use only. A late edit moved them from uapi/asm/mce.h to the internal x86 <asm/mce.h>, but the comment saying "See below" was accidentally left here.

Delete "See below". Just labelling this field as internal kernel use is sufficient.

Fixes 1de08dccd383 ("x86/mce: Add a struct mce.kflags field")
---
 arch/x86/include/uapi/asm/mce.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/uapi/asm/mce.h +1 -1
index 5b59d80..db9adc0 100644
@@ -35,7 +35,7 @@ struct mce {
 	__u64 ipid;		/* MCA_IPID MSR: only valid on SMCA systems */
 	__u64 ppin;		/* Protected Processor Inventory Number */
 	__u32 microcode;	/* Microcode revision */
-	__u64 kflags;		/* Internal kernel use. See below */
+	__u64 kflags;		/* Internal kernel use */
 };
 
 #define MCE_GET_RECORD_LEN   _IOR('M', 1, int)
#34 lore raw

Re: [tip: ras/core] x86/mce: Add a struct mce.kflags field

In reply to tip-bot2 for Tony Luck
Quoted 16 lines · On Wed, Apr 15, 2020 at 09:49:48AM -0000, tip-bot2 for Tony Luck wrote:

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     1de08dccd383482a3e88845d3554094d338f5ff9
Gitweb:        https://git.kernel.org/tip/1de08dccd383482a3e88845d3554094d338f5ff9
Author:        Tony Luck <[email protected]>
AuthorDate:    Fri, 14 Feb 2020 14:27:16 -08:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Tue, 14 Apr 2020 15:58:43 +02:00

x86/mce: Add a struct mce.kflags field

There can be many different subsystems register on the mce handler chain. Add a new bitmask field and define values so that handlers can indicate whether they took any action to log or otherwise handle an error.

Quoted 7 lines

The default handler at the end of the chain can use this information to decide whether to print to the console log.

Boris suggested a generic name and leaving plenty of spare bits for possible future use.

[ bp: Move flag bits to the internal mce.h header and use BIT_ULL(). ]

Err, how can you add a new field to an uapi structure and not break things?

#35 lore raw

Re: [tip: ras/core] x86/mce: Add a struct mce.kflags field

Quoted 2 lines · Christoph Hellwig

Err, how can you add a new field to an uapi structure and not break things?

By adding it to the end of the structure. The mcelog tool gets the record length first, before doing anything with the records.

Signature · 4 lines
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg