Skip to contentSkip to conversation

x86, mce, severities: Add AMD severities function

PATCH Superseded Aravind Gopalakrishnan 4 participants 16 messages Mar 16, 2015 – Mar 20, 2015 x86

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, mce, severities: Add AMD severities function

Add a severities function that caters to AMD processors. This allows us to do some vendor specific work within the function if necessary.

Also, introduce a vendor flag bitfield which contains vendor specific flags. The severities code uses this to define error scope based on the prescence of the flags field.

This is based off of work by Boris Petkov.

Testing details:
Tested the patch for any regressions on F15hM0h-0fh (Orochi) and F15hM60h-6fh (Carrizo) and it works fine.

---
 arch/x86/include/asm/mce.h                |  6 ++++
 arch/x86/kernel/cpu/mcheck/mce-severity.c | 52 +++++++++++++++++++++++++++++++
 arch/x86/kernel/cpu/mcheck/mce.c          |  9 ++++++
 3 files changed, 67 insertions(+)
arch/x86/include/asm/mce.h +6 -0
index fd38a23..b574fbf 100644
@@ -116,6 +116,12 @@ struct mca_config {
 	u32 rip_msr;
 };
 
+struct mce_vendor_flags {
+	__u64		overflow_recov	: 1, /* cpuid_ebx(80000007) */
+			__reserved_0	: 63;
+};
+extern struct mce_vendor_flags mce_flags;
+
 extern struct mca_config mca_cfg;
 extern void mce_register_decode_chain(struct notifier_block *nb);
 extern void mce_unregister_decode_chain(struct notifier_block *nb);
arch/x86/kernel/cpu/mcheck/mce-severity.c +52 -0

64 lines not on this page · raw message

arch/x86/kernel/cpu/mcheck/mce.c +9 -0
index 17ad025..680cfb2 100644
@@ -65,6 +65,7 @@ static DEFINE_MUTEX(mce_chrdev_read_mutex);
 DEFINE_PER_CPU(unsigned, mce_exception_count);
 
 struct mce_bank *mce_banks __read_mostly;
+struct mce_vendor_flags mce_flags __read_mostly;
 
 struct mca_config mca_cfg __read_mostly = {
 	.bootlog  = -1,
@@ -1532,6 +1533,13 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
 		 if (c->x86 == 6 && cfg->banks > 0)
 			mce_banks[0].ctl = 0;
 
+		/*
+		 * overflow_recov is supported for F15h Models 00h-0fh
+		 * even though we don't have cpuid bit for this
+		 */
+		if (c->x86 == 0x15 && c->x86_model <= 0xf)
+			mce_flags.overflow_recov = 1;
+
 		 /*
 		  * Turn off MC4_MISC thresholding banks on those models since
 		  * they're not supported there.
@@ -1637,6 +1645,7 @@ static void __mcheck_cpu_init_vendor(struct cpuinfo_x86 *c)
 		break;
 	case X86_VENDOR_AMD:
 		mce_amd_feature_init(c);
+		mce_flags.overflow_recov = cpuid_ebx(0x80000007) & 0x1;
 		break;
 	default:
 		break;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · Aravind Gopalakrishnan

Add a severities function that caters to AMD processors. This allows us to do some vendor specific work within the function if necessary.

Also, introduce a vendor flag bitfield which contains vendor specific flags. The severities code uses this to define error scope based on the prescence of the flags field.

So it would be nice to see actual use of this new facility, within the same patch series?

Thanks,

Ingo

maintainer
#2 lore raw
Quoted 2 lines · Ingo Molnar

So it would be nice to see actual use of this new facility, within the same patch series?

All AMD hardware will use this. It is basically a much cleaner, nicer and *actually* *readable* severities grading function replacing the default one on AMD.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#3 lore raw
Quoted 7 lines · Borislav Petkov
Quoted 2 lines · Ingo Molnar

So it would be nice to see actual use of this new facility, within the same patch series?

All AMD hardware will use this. It is basically a much cleaner, nicer and *actually* *readable* severities grading function replacing the default one on AMD.

Ok, fine with me!

Ingo

maintainer
#4 lore raw
In reply to Aravind Gopalakrishnan
Quoted 14 lines · Aravind Gopalakrishnan
arch/x86/kernel/cpu/mcheck/mce-severity.c +14 -0
+/* keeping amd_mce_severity in sync with AMD error scope heirarchy table */
+static int amd_mce_severity(struct mce *m, enum context ctx)
+{
+	/* Processor Context Corrupt, no need to fumble too much, die! */
+	if (m->status & MCI_STATUS_PCC)
+		return MCE_PANIC_SEVERITY;
+
+	if (m->status & MCI_STATUS_UC) {
+		/*
+		 * On older systems, where overflow_recov flag is not
+		 * present, we should simply PANIC if Overflow occurs.
+		 * If overflow_recov flag set, then SW can try
+		 * to at least kill process to salvage systen operation.
+		 */

arch/x86/kernel/cpu/mcheck/mce-severity.c static int error_context(struct mce *m) · line 212

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce-severity.c +10 -0
+
+		/* at least one error was not logged */
+		if (m->status & MCI_STATUS_OVER && !mce_flags.overflow_recov)
+				return MCE_PANIC_SEVERITY;
+
+		/* software can try to contain */
+		if (!(m->mcgstatus & MCG_STATUS_RIPV) &&
+		      mce_flags.overflow_recov) {
+			if (ctx == IN_KERNEL)
+				return MCE_PANIC_SEVERITY;

we're testing mce_flags.overflow_recov twice here, perhaps do instead:

	/*
	 * < Comment about overflow recovery bit>
	 */
	if (mce_flags.overflow_recov) {
		if (!(m->mcgstatus & MCG_STATUS_RIPV) && (ctx == IN_KERNEL))
			return MCE_PANIC_SEVERITY;
	} else {
		if (m->status & MCI_STATUS_OVER)
			return MCE_PANIC_SEVERITY;
	}
Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#5 lore raw
Quoted 27 lines · Borislav Petkov
Quoted 14 lines · Aravind Gopalakrishnan
arch/x86/kernel/cpu/mcheck/mce-severity.c +14 -0
+/* keeping amd_mce_severity in sync with AMD error scope heirarchy table */
+static int amd_mce_severity(struct mce *m, enum context ctx)
+{
+	/* Processor Context Corrupt, no need to fumble too much, die! */
+	if (m->status & MCI_STATUS_PCC)
+		return MCE_PANIC_SEVERITY;
+
+	if (m->status & MCI_STATUS_UC) {
+		/*
+		 * On older systems, where overflow_recov flag is not
+		 * present, we should simply PANIC if Overflow occurs.
+		 * If overflow_recov flag set, then SW can try
+		 * to at least kill process to salvage systen operation.
+		 */

arch/x86/kernel/cpu/mcheck/mce-severity.c static int error_context(struct mce *m) · line 212

Quoted 10 lines
arch/x86/kernel/cpu/mcheck/mce-severity.c +10 -0
+
+		/* at least one error was not logged */
+		if (m->status & MCI_STATUS_OVER && !mce_flags.overflow_recov)
+				return MCE_PANIC_SEVERITY;
+
+		/* software can try to contain */
+		if (!(m->mcgstatus & MCG_STATUS_RIPV) &&
+		      mce_flags.overflow_recov) {
+			if (ctx == IN_KERNEL)
+				return MCE_PANIC_SEVERITY;

we're testing mce_flags.overflow_recov twice here, perhaps do instead:

Quoted 6 lines
	/*
	 * < Comment about overflow recovery bit>
	 */
	if (mce_flags.overflow_recov) {
		if (!(m->mcgstatus & MCG_STATUS_RIPV) && (ctx == IN_KERNEL))
			return MCE_PANIC_SEVERITY;

return MCE_AR_SEVERITY if ctx == IN_USER also needs to be within this block here. Will do that and resend.

Quoted 5 lines
	} else {
		if (m->status & MCI_STATUS_OVER)
			return MCE_PANIC_SEVERITY;
	}

Thanks,
-Aravind

maintainer
#6 lore raw
Quoted 2 lines · Aravind Gopalakrishnan

return MCE_AR_SEVERITY if ctx == IN_USER also needs to be within this block here. Will do that and resend.

Right, but please wait a couple of days for people to take a look first.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#7 lore raw

One other thought. Instead of the run-time test to see if this is an AMD processor on every call to this function, would it be cleaner to:

1) Rename existing mce_severity() function to mce_severity_intel()
2) Declare a function pointer named mce_severity.
3) Assign that pointer to the _intel() or _amd() function in mce_init()

-Tony ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

maintainer
#8 lore raw
Quoted 6 lines · Tony

One other thought. Instead of the run-time test to see if this is an AMD processor on every call to this function, would it be cleaner to:

1) Rename existing mce_severity() function to mce_severity_intel()
2) Declare a function pointer named mce_severity.
3) Assign that pointer to the _intel() or _amd() function in mce_init()

Yes, of course. We do that (or at least pretty close) in other paths too.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#9 lore raw
Quoted 11 lines · Borislav Petkov
Quoted 6 lines · Tony

One other thought. Instead of the run-time test to see if this is an AMD processor on every call to this function, would it be cleaner to:

1) Rename existing mce_severity() function to mce_severity_intel()
2) Declare a function pointer named mce_severity.
3) Assign that pointer to the _intel() or _amd() function in mce_init()

Yes, of course. We do that (or at least pretty close) in other paths too.

Ok, I'll work on this and prepend the changes to the current version of the patch. Would you prefer the changes be in a separate patch or lump it in along with current version?

Thanks,
-Aravind.

maintainer
#10 lore raw
Quoted 3 lines · Aravind Gopalakrishnan

Ok, I'll work on this and prepend the changes to the current version of the patch. Would you prefer the changes be in a separate patch or lump it in along with current version?

It would be best if what Tony suggested comes ontop of your patch with his Suggested-by: tag. This ordering should be also the easiest wrt functionality and bisectability.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#11 lore raw
Quoted 9 lines · Borislav Petkov
Quoted 3 lines · Aravind Gopalakrishnan

Ok, I'll work on this and prepend the changes to the current version of the patch. Would you prefer the changes be in a separate patch or lump it in along with current version?

It would be best if what Tony suggested comes ontop of your patch with his Suggested-by: tag. This ordering should be also the easiest wrt functionality and bisectability.

Ok, I'll have it ready and send out a V2 by tomorrow if there are no other comments/reviews.

Thanks,
-Aravind.

#12 lore raw
Quoted 8 lines
Quoted 5 lines

It would be best if what Tony suggested comes ontop of your patch with his Suggested-by: tag. This ordering should be also the easiest wrt functionality and bisectability.

Ok, I'll have it ready and send out a V2 by tomorrow if there are no other comments/reviews.

Fame & glory ... whatever. Just be sure to make the _intel() and _amd() severity functions "static" ... so you'll need something like this in mce-severity.c

void mce_vendor_severity_init(void)
{
.... assign mce_severity here
}

-Tony ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#13 lore raw
Quoted 7 lines · Tony
Quoted 7 lines
Quoted 5 lines

It would be best if what Tony suggested comes ontop of your patch with his Suggested-by: tag. This ordering should be also the easiest wrt functionality and bisectability.

Ok, I'll have it ready and send out a V2 by tomorrow if there are no other comments/reviews.

Quoted 9 lines

Fame & glory ... whatever. Just be sure to make the _intel() and _amd() severity functions "static" ... so you'll need something like this in mce-severity.c

void mce_vendor_severity_init(void)
{
.... assign mce_severity here
}

Ok, Here's how I have it currently:
void __init mcheck_vendor_init_severity(void)

{
        struct cpuinfo_x86 *c = &boot_cpu_data;

        switch (c->x86_vendor) {
        case X86_VENDOR_INTEL:
                mce_severity = mce_severity_intel;
                break;
        case X86_VENDOR_AMD:
                mce_severity = mce_severity_amd;
                break;
        default:
                break;
        }
}

And I call this from mcheck_init().
I tested the above bits on AMD and the severities grading works fine.

Should we also come up with a '_default' function to assign to mce_severity function pointer? Something like-
static int mce_severity_default(struct mce *m, int tolerant,
char **msg, bool is_excp)

{
        pr_err("CPU#%d: No vendor specific severities grader assigned.
                Implementing default grader\n", smp_processor_id());

        if (m->status & MCI_STATUS_PCC || m->status & MCI_STATUS_OVER)
                return MCE_PANIC_SEVERITY;

        if (m->status & MCI_STATUS_UC)
                return MCE_UC_SEVERITY;

        return MCE_KEEP_SEVERITY;
}

int (*mce_severity) (struct mce *m, int tolerant, char **msg, bool is_excp) =

                    mce_severity_default;

How much of grading should '_default' do if at all?

Thanks,
-Aravind.

maintainer
#14 lore raw
Quoted 16 lines · Aravind Gopalakrishnan

Ok, Here's how I have it currently:
void __init mcheck_vendor_init_severity(void)

{
        struct cpuinfo_x86 *c = &boot_cpu_data;

        switch (c->x86_vendor) {
        case X86_VENDOR_INTEL:
                mce_severity = mce_severity_intel;
                break;
        case X86_VENDOR_AMD:
                mce_severity = mce_severity_amd;
                break;
        default:
                break;
        }
}
Quoted 5 lines

And I call this from mcheck_init().
I tested the above bits on AMD and the severities grading works fine.

Should we also come up with a '_default' function to assign to mce_severity function pointer?

I think that should be

	default:
		WARN_ONCE("WTF?!");
		break;

above.

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#15 lore raw
Quoted 11 lines
Quoted 5 lines

And I call this from mcheck_init().
I tested the above bits on AMD and the severities grading works fine.

Should we also come up with a '_default' function to assign to mce_severity function pointer?

I think that should be

	default:
		WARN_ONCE("WTF?!");
		break;

mcheck_init() is called unconditionally from setup_arch(). So if anyone is still using a Cyrix, Transmeta or other non-Intel, non-Amd processor we'd trip this WARN_ON.

I think you can have a default severity function that just does:

	return MCE_PANIC_SEVERITY;

just to avoid the unpleasant thought that we might jump through a NULL pointer if we did somehow end up in do_machine_check() on another vendors cpu.

-Tony ���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�