diff options
| author | Jonathan T. Looney <jtl@FreeBSD.org> | 2025-10-07 12:58:05 +0000 |
|---|---|---|
| committer | Jonathan T. Looney <jtl@FreeBSD.org> | 2025-10-08 19:12:35 +0000 |
| commit | 55c28005f544282b984ae0e15dacd0c108d8ab12 (patch) | |
| tree | 7692cd975d4530e11ebf6cd88130caabb37dc9b5 | |
| parent | 0d14826de7d9d72e91f1d396120f1456102bccf4 (diff) | |
x86: support sending non-fatal MCA messages to syslog
Currently, all MCA messages are logged to the console. However, this
can have performance implications which can turn a storm of correctable
errors into a disruptive event.
Provide an option to direct non-fatal messages to syslog. Note that
we will always log to the console for fatal errors.
Reviewed by: markj
MFC after: 2 weeks
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D12278
| -rw-r--r-- | sys/x86/x86/mca.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/sys/x86/x86/mca.c b/sys/x86/x86/mca.c index a167854e8bbb..735efe307215 100644 --- a/sys/x86/x86/mca.c +++ b/sys/x86/x86/mca.c @@ -50,6 +50,7 @@ #include <sys/sched.h> #include <sys/smp.h> #include <sys/sysctl.h> +#include <sys/syslog.h> #include <sys/systm.h> #include <sys/taskqueue.h> #include <machine/intr_machdep.h> @@ -136,6 +137,11 @@ SYSCTL_INT(_hw_mca, OID_AUTO, fake_bank, CTLFLAG_RW, "Bank to use for artificial MCAs (testing purpose only)"); #endif +static bool mca_uselog = false; +SYSCTL_BOOL(_hw_mca, OID_AUTO, uselog, CTLFLAG_RWTUN, &mca_uselog, 0, + "Should the system send non-fatal machine check errors to the log " + "(instead of the console)?"); + static STAILQ_HEAD(, mca_internal) mca_freelist; static int mca_freecount; static STAILQ_HEAD(, mca_internal) mca_records; @@ -477,7 +483,7 @@ mca_mute(const struct mca_record *rec) /* Dump details about a single machine check. */ static void -mca_log(enum scan_mode mode, const struct mca_record *rec) +mca_log(enum scan_mode mode, const struct mca_record *rec, bool fatal) { int error, numskipped; uint16_t mca_error; @@ -711,7 +717,8 @@ mca_log(enum scan_mode mode, const struct mca_record *rec) event_type)); event_type = MCA_T_UNKNOWN; } - if (!uncor) { + numskipped = 0; + if (!fatal && !uncor) { /* * Update statistics and check the rate limit for * correctable errors. The rate limit is only applied @@ -732,17 +739,31 @@ mca_log(enum scan_mode mode, const struct mca_record *rec) numskipped = mca_log_skipped; mca_log_skipped = 0; mtx_unlock_spin(&mca_lock); + } + + error = sbuf_finish(&sb); + if (fatal || !mca_uselog) { if (numskipped > 0) printf("MCA: %d events skipped due to rate limit\n", numskipped); + if (error) + printf("MCA: error logging message (sbuf error %d)\n", + error); + else + sbuf_putbuf(&sb); + } else { + if (numskipped > 0) + log(LOG_ERR, + "MCA: %d events skipped due to rate limit\n", + numskipped); + if (error) + log(LOG_ERR, + "MCA: error logging message (sbuf error %d)\n", + error); + else + log(uncor ? LOG_CRIT : LOG_ERR, "%s", sbuf_data(&sb)); } - error = sbuf_finish(&sb); - if (error) - printf("MCA: error logging message (sbuf error %d)\n", error); - else - sbuf_putbuf(&sb); - done: sbuf_delete(&sb); if (using_shared_buf) @@ -907,7 +928,7 @@ mca_record_entry(enum scan_mode mode, const struct mca_record *record) if (rec == NULL) { mtx_unlock_spin(&mca_lock); printf("MCA: Unable to allocate space for an event.\n"); - mca_log(mode, record); + mca_log(mode, record, false); return; } STAILQ_REMOVE_HEAD(&mca_freelist, link); @@ -1064,7 +1085,7 @@ mca_scan(enum scan_mode mode, bool *recoverablep) if (*recoverablep) mca_record_entry(mode, &rec); else - mca_log(mode, &rec); + mca_log(mode, &rec, true); } #ifdef DEV_APIC @@ -1148,7 +1169,7 @@ mca_process_records(enum scan_mode mode) mtx_unlock_spin(&mca_lock); STAILQ_FOREACH(mca, &tmplist, link) - mca_log(mode, &mca->rec); + mca_log(mode, &mca->rec, false); mtx_lock_spin(&mca_lock); while ((mca = STAILQ_FIRST(&tmplist)) != NULL) { |
