aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>2016-09-01 19:15:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-09-01 20:52:01 -0400
commit19feeff18bbfde659baa58c2346f15a24d7c405e (patch)
tree46d008dc821260a189a47d541287f02331550831 /kernel/printk
parent7e932159901183283cd82d797bc9a7c681e48e9c (diff)
printk/nmi: avoid direct printk()-s from __printk_nmi_flush()
__printk_nmi_flush() can be called from nmi_panic(), therefore it has to test whether it's executed in NMI context and thus must route the messages through deferred printk() or via direct printk(). This is to avoid potential deadlocks, as described in commit cf9b1106c81c ("printk/nmi: flush NMI messages on the system panic"). However there remain two places where __printk_nmi_flush() does unconditional direct printk() calls: - pr_err("printk_nmi_flush: internal error ...") - pr_cont("\n") Factor out print_nmi_seq_line() parts into a new printk_nmi_flush_line() function, which takes care of in_nmi(), and use it in __printk_nmi_flush() for printing and error-reporting. Link: http://lkml.kernel.org/r/20160830161354.581-1-sergey.senozhatsky@gmail.com Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Petr Mladek <pmladek@suse.com> Cc: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/printk')
-rw-r--r--kernel/printk/nmi.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/kernel/printk/nmi.c b/kernel/printk/nmi.c
index b69eb8a2876f..16bab471c7e2 100644
--- a/kernel/printk/nmi.c
+++ b/kernel/printk/nmi.c
@@ -99,27 +99,33 @@ again:
99 return add; 99 return add;
100} 100}
101 101
102/* 102static void printk_nmi_flush_line(const char *text, int len)
103 * printk one line from the temporary buffer from @start index until
104 * and including the @end index.
105 */
106static void print_nmi_seq_line(struct nmi_seq_buf *s, int start, int end)
107{ 103{
108 const char *buf = s->buffer + start;
109
110 /* 104 /*
111 * The buffers are flushed in NMI only on panic. The messages must 105 * The buffers are flushed in NMI only on panic. The messages must
112 * go only into the ring buffer at this stage. Consoles will get 106 * go only into the ring buffer at this stage. Consoles will get
113 * explicitly called later when a crashdump is not generated. 107 * explicitly called later when a crashdump is not generated.
114 */ 108 */
115 if (in_nmi()) 109 if (in_nmi())
116 printk_deferred("%.*s", (end - start) + 1, buf); 110 printk_deferred("%.*s", len, text);
117 else 111 else
118 printk("%.*s", (end - start) + 1, buf); 112 printk("%.*s", len, text);
119 113
120} 114}
121 115
122/* 116/*
117 * printk one line from the temporary buffer from @start index until
118 * and including the @end index.
119 */
120static void printk_nmi_flush_seq_line(struct nmi_seq_buf *s,
121 int start, int end)
122{
123 const char *buf = s->buffer + start;
124
125 printk_nmi_flush_line(buf, (end - start) + 1);
126}
127
128/*
123 * Flush data from the associated per_CPU buffer. The function 129 * Flush data from the associated per_CPU buffer. The function
124 * can be called either via IRQ work or independently. 130 * can be called either via IRQ work or independently.
125 */ 131 */
@@ -150,9 +156,11 @@ more:
150 * the buffer an unexpected way. If we printed something then 156 * the buffer an unexpected way. If we printed something then
151 * @len must only increase. 157 * @len must only increase.
152 */ 158 */
153 if (i && i >= len) 159 if (i && i >= len) {
154 pr_err("printk_nmi_flush: internal error: i=%d >= len=%zu\n", 160 const char *msg = "printk_nmi_flush: internal error\n";
155 i, len); 161
162 printk_nmi_flush_line(msg, strlen(msg));
163 }
156 164
157 if (!len) 165 if (!len)
158 goto out; /* Someone else has already flushed the buffer. */ 166 goto out; /* Someone else has already flushed the buffer. */
@@ -166,14 +174,14 @@ more:
166 /* Print line by line. */ 174 /* Print line by line. */
167 for (; i < size; i++) { 175 for (; i < size; i++) {
168 if (s->buffer[i] == '\n') { 176 if (s->buffer[i] == '\n') {
169 print_nmi_seq_line(s, last_i, i); 177 printk_nmi_flush_seq_line(s, last_i, i);
170 last_i = i + 1; 178 last_i = i + 1;
171 } 179 }
172 } 180 }
173 /* Check if there was a partial line. */ 181 /* Check if there was a partial line. */
174 if (last_i < size) { 182 if (last_i < size) {
175 print_nmi_seq_line(s, last_i, size - 1); 183 printk_nmi_flush_seq_line(s, last_i, size - 1);
176 pr_cont("\n"); 184 printk_nmi_flush_line("\n", strlen("\n"));
177 } 185 }
178 186
179 /* 187 /*