diff options
author | Dave Chinner <dchinner@redhat.com> | 2011-01-11 19:35:42 -0500 |
---|---|---|
committer | Alex Elder <aelder@sgi.com> | 2011-01-12 09:46:41 -0500 |
commit | 73efe4a4ddf8eb2b1cc7039e8a66a23a424961af (patch) | |
tree | 1c3eed2bed48cf62a476cf0b34e66211ae29d00f /fs/xfs/support | |
parent | 65a84a0f7567ea244e5246e642920260cfc2744a (diff) |
xfs: prevent NMI timeouts in cmn_err
We currently have a global error message buffer in cmn_err that is
protected by a spin lock that disables interrupts. Recently there
have been reports of NMI timeouts occurring when the console is
being flooded by SCSI error reports due to cmn_err() getting stuck
trying to print to the console while holding this lock (i.e. with
interrupts disabled). The NMI watchdog is seeing this CPU as
non-responding and so is triggering a panic. While the trigger for
the reported case is SCSI errors, pretty much anything that spams
the kernel log could cause this to occur.
Realistically the only reason that we have the intemediate message
buffer is to prepend the correct kernel log level prefix to the log
message. The only reason we have the lock is to protect the global
message buffer and the only reason the message buffer is global is
to keep it off the stack. Hence if we can avoid needing a global
message buffer we avoid needing the lock, and we can do this with a
small amount of cleanup and some preprocessor tricks:
1. clean up xfs_cmn_err() panic mask functionality to avoid
needing debug code in xfs_cmn_err()
2. remove the couple of "!" message prefixes that still exist that
the existing cmn_err() code steps over.
3. redefine CE_* levels directly to KERN_*
4. redefine cmn_err() and friends to use printk() directly
via variable argument length macros.
By doing this, we can completely remove the cmn_err() code and the
lock that is causing the problems, and rely solely on printk()
serialisation to ensure that we don't get garbled messages.
A series of followup patches is really needed to clean up all the
cmn_err() calls and related messages properly, but that results in a
series that is not easily back portable to enterprise kernels. Hence
this initial fix is only to address the direct problem in the lowest
impact way possible.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs/xfs/support')
-rw-r--r-- | fs/xfs/support/debug.c | 109 | ||||
-rw-r--r-- | fs/xfs/support/debug.h | 25 |
2 files changed, 66 insertions, 68 deletions
diff --git a/fs/xfs/support/debug.c b/fs/xfs/support/debug.c index 86162e5f9a21..e6cf955ec0fc 100644 --- a/fs/xfs/support/debug.c +++ b/fs/xfs/support/debug.c | |||
@@ -25,80 +25,71 @@ | |||
25 | #include "xfs_mount.h" | 25 | #include "xfs_mount.h" |
26 | #include "xfs_error.h" | 26 | #include "xfs_error.h" |
27 | 27 | ||
28 | static char message[1024]; /* keep it off the stack */ | ||
29 | static DEFINE_SPINLOCK(xfs_err_lock); | ||
30 | |||
31 | /* Translate from CE_FOO to KERN_FOO, err_level(CE_FOO) == KERN_FOO */ | ||
32 | #define XFS_MAX_ERR_LEVEL 7 | ||
33 | #define XFS_ERR_MASK ((1 << 3) - 1) | ||
34 | static const char * const err_level[XFS_MAX_ERR_LEVEL+1] = | ||
35 | {KERN_EMERG, KERN_ALERT, KERN_CRIT, | ||
36 | KERN_ERR, KERN_WARNING, KERN_NOTICE, | ||
37 | KERN_INFO, KERN_DEBUG}; | ||
38 | |||
39 | void | 28 | void |
40 | cmn_err(register int level, char *fmt, ...) | 29 | cmn_err( |
30 | const char *lvl, | ||
31 | const char *fmt, | ||
32 | ...) | ||
41 | { | 33 | { |
42 | char *fp = fmt; | 34 | struct va_format vaf; |
43 | int len; | 35 | va_list args; |
44 | ulong flags; | 36 | |
45 | va_list ap; | 37 | va_start(args, fmt); |
46 | 38 | vaf.fmt = fmt; | |
47 | level &= XFS_ERR_MASK; | 39 | vaf.va = &args; |
48 | if (level > XFS_MAX_ERR_LEVEL) | 40 | |
49 | level = XFS_MAX_ERR_LEVEL; | 41 | printk("%s%pV", lvl, &vaf); |
50 | spin_lock_irqsave(&xfs_err_lock,flags); | 42 | va_end(args); |
51 | va_start(ap, fmt); | 43 | |
52 | if (*fmt == '!') fp++; | 44 | BUG_ON(strncmp(lvl, KERN_EMERG, strlen(KERN_EMERG)) == 0); |
53 | len = vsnprintf(message, sizeof(message), fp, ap); | ||
54 | if (len >= sizeof(message)) | ||
55 | len = sizeof(message) - 1; | ||
56 | if (message[len-1] == '\n') | ||
57 | message[len-1] = 0; | ||
58 | printk("%s%s\n", err_level[level], message); | ||
59 | va_end(ap); | ||
60 | spin_unlock_irqrestore(&xfs_err_lock,flags); | ||
61 | BUG_ON(level == CE_PANIC); | ||
62 | } | 45 | } |
63 | 46 | ||
64 | void | 47 | void |
65 | xfs_fs_vcmn_err( | 48 | xfs_fs_cmn_err( |
66 | int level, | 49 | const char *lvl, |
67 | struct xfs_mount *mp, | 50 | struct xfs_mount *mp, |
68 | char *fmt, | 51 | const char *fmt, |
69 | va_list ap) | 52 | ...) |
70 | { | 53 | { |
71 | unsigned long flags; | 54 | struct va_format vaf; |
72 | int len = 0; | 55 | va_list args; |
73 | 56 | ||
74 | level &= XFS_ERR_MASK; | 57 | va_start(args, fmt); |
75 | if (level > XFS_MAX_ERR_LEVEL) | 58 | vaf.fmt = fmt; |
76 | level = XFS_MAX_ERR_LEVEL; | 59 | vaf.va = &args; |
77 | 60 | ||
78 | spin_lock_irqsave(&xfs_err_lock,flags); | 61 | printk("%sFilesystem %s: %pV", lvl, mp->m_fsname, &vaf); |
62 | va_end(args); | ||
79 | 63 | ||
80 | if (mp) { | 64 | BUG_ON(strncmp(lvl, KERN_EMERG, strlen(KERN_EMERG)) == 0); |
81 | len = sprintf(message, "Filesystem \"%s\": ", mp->m_fsname); | 65 | } |
66 | |||
67 | /* All callers to xfs_cmn_err use CE_ALERT, so don't bother testing lvl */ | ||
68 | void | ||
69 | xfs_cmn_err( | ||
70 | int panic_tag, | ||
71 | const char *lvl, | ||
72 | struct xfs_mount *mp, | ||
73 | const char *fmt, | ||
74 | ...) | ||
75 | { | ||
76 | struct va_format vaf; | ||
77 | va_list args; | ||
78 | int panic = 0; | ||
82 | 79 | ||
83 | /* | 80 | if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) { |
84 | * Skip the printk if we can't print anything useful | 81 | printk(KERN_ALERT "XFS: Transforming an alert into a BUG."); |
85 | * due to an over-long device name. | 82 | panic = 1; |
86 | */ | ||
87 | if (len >= sizeof(message)) | ||
88 | goto out; | ||
89 | } | 83 | } |
90 | 84 | ||
91 | len = vsnprintf(message + len, sizeof(message) - len, fmt, ap); | 85 | va_start(args, fmt); |
92 | if (len >= sizeof(message)) | 86 | vaf.fmt = fmt; |
93 | len = sizeof(message) - 1; | 87 | vaf.va = &args; |
94 | if (message[len-1] == '\n') | ||
95 | message[len-1] = 0; | ||
96 | 88 | ||
97 | printk("%s%s\n", err_level[level], message); | 89 | printk(KERN_ALERT "Filesystem %s: %pV", mp->m_fsname, &vaf); |
98 | out: | 90 | va_end(args); |
99 | spin_unlock_irqrestore(&xfs_err_lock,flags); | ||
100 | 91 | ||
101 | BUG_ON(level == CE_PANIC); | 92 | BUG_ON(panic); |
102 | } | 93 | } |
103 | 94 | ||
104 | void | 95 | void |
diff --git a/fs/xfs/support/debug.h b/fs/xfs/support/debug.h index d2d20462fd4f..05699f67d475 100644 --- a/fs/xfs/support/debug.h +++ b/fs/xfs/support/debug.h | |||
@@ -20,15 +20,22 @@ | |||
20 | 20 | ||
21 | #include <stdarg.h> | 21 | #include <stdarg.h> |
22 | 22 | ||
23 | #define CE_DEBUG 7 /* debug */ | 23 | struct xfs_mount; |
24 | #define CE_CONT 6 /* continuation */ | 24 | |
25 | #define CE_NOTE 5 /* notice */ | 25 | #define CE_DEBUG KERN_DEBUG |
26 | #define CE_WARN 4 /* warning */ | 26 | #define CE_CONT KERN_INFO |
27 | #define CE_ALERT 1 /* alert */ | 27 | #define CE_NOTE KERN_NOTICE |
28 | #define CE_PANIC 0 /* panic */ | 28 | #define CE_WARN KERN_WARNING |
29 | 29 | #define CE_ALERT KERN_ALERT | |
30 | extern void cmn_err(int, char *, ...) | 30 | #define CE_PANIC KERN_EMERG |
31 | __attribute__ ((format (printf, 2, 3))); | 31 | |
32 | void cmn_err(const char *lvl, const char *fmt, ...) | ||
33 | __attribute__ ((format (printf, 2, 3))); | ||
34 | void xfs_fs_cmn_err( const char *lvl, struct xfs_mount *mp, | ||
35 | const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); | ||
36 | void xfs_cmn_err( int panic_tag, const char *lvl, struct xfs_mount *mp, | ||
37 | const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); | ||
38 | |||
32 | extern void assfail(char *expr, char *f, int l); | 39 | extern void assfail(char *expr, char *f, int l); |
33 | 40 | ||
34 | #define ASSERT_ALWAYS(expr) \ | 41 | #define ASSERT_ALWAYS(expr) \ |