kernel: update to 2.6.34
[qi-bootmenu-system.git] / sources / patches / kernel-printk-verbosity.patch
blobdb6774dac32b74a5e2392afa3dbb1ff82b5877b2
1 From 7ef1a4f3e45f798054db68af33933dbee4bf5b37 Mon Sep 17 00:00:00 2001
2 From: Marc Andre Tanner <mat@brain-dump.org>
3 Date: Fri, 28 Aug 2009 22:39:27 +0200
4 Subject: [PATCH 1/5] printk: introduce CONFIG_PRINTK_VERBOSITY
6 Introduce a config option which allows to selectively compile out
7 printk messages based on a specified verbosity level.
9 Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>
10 ---
11 init/Kconfig | 29 +++++++++++++++++++++++++++++
12 1 files changed, 29 insertions(+), 0 deletions(-)
14 diff --git a/init/Kconfig b/init/Kconfig
15 index 3f7e609..549ed95 100644
16 --- a/init/Kconfig
17 +++ b/init/Kconfig
18 @@ -833,6 +833,35 @@ config PRINTK
19 very difficult to diagnose system problems, saying N here is
20 strongly discouraged.
22 +config PRINTK_VERBOSITY
23 + int "Printk compile time verbosity"
24 + depends on EMBEDDED && PRINTK
25 + range 0 7
26 + default 0
27 + help
29 + Select the maximum printk verbosity level to be compiled into
30 + the kernel.
32 + Messages above the specified verbosity level are removed from
33 + the kernel at compile time. This reduces the kernel image size
34 + at the cost of a calmer kernel.
36 + Possible verbosity levels are listed below. Note that messages
37 + without an explicit loglevel will be classified as KERN_WARNING.
39 + 0 Disable this feature and compile all messages in.
41 + 1 KERN_ALERT /* action must be taken immediately */
42 + 2 KERN_CRIT /* critical conditions */
43 + 3 KERN_ERR /* error conditions */
44 + 4 KERN_WARNING /* warning conditions */
45 + 5 KERN_NOTICE /* normal but significant condition */
46 + 6 KERN_INFO /* informational */
47 + 7 KERN_DEBUG /* debug-level messages */
49 + If unsure, just move on and leave this option alone.
51 config BUG
52 bool "BUG() support" if EMBEDDED
53 default y
54 --
55 1.6.5
57 From a69888dc31967d3b4a90dd8bfa92b5d4fb4e511e Mon Sep 17 00:00:00 2001
58 From: Marc Andre Tanner <mat@brain-dump.org>
59 Date: Fri, 28 Aug 2009 23:21:44 +0200
60 Subject: [PATCH 2/5] printk: move printk to the end of the file
62 A later patch will #undef printk because the macro would otherwise
63 conflict with the function definition. Moving the printk function
64 to the end of the file makes sure that the macro is expanded within
65 the rest of the file.
67 Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>
68 ---
69 kernel/printk.c | 72 ++++++++++++++++++++++++++++--------------------------
70 1 files changed, 37 insertions(+), 35 deletions(-)
72 diff --git a/kernel/printk.c b/kernel/printk.c
73 index b4d97b5..5455d41 100644
74 --- a/kernel/printk.c
75 +++ b/kernel/printk.c
76 @@ -551,40 +551,6 @@ static int have_callable_console(void)
77 return 0;
80 -/**
81 - * printk - print a kernel message
82 - * @fmt: format string
83 - *
84 - * This is printk(). It can be called from any context. We want it to work.
85 - *
86 - * We try to grab the console_sem. If we succeed, it's easy - we log the output and
87 - * call the console drivers. If we fail to get the semaphore we place the output
88 - * into the log buffer and return. The current holder of the console_sem will
89 - * notice the new output in release_console_sem() and will send it to the
90 - * consoles before releasing the semaphore.
91 - *
92 - * One effect of this deferred printing is that code which calls printk() and
93 - * then changes console_loglevel may break. This is because console_loglevel
94 - * is inspected when the actual printing occurs.
95 - *
96 - * See also:
97 - * printf(3)
98 - *
99 - * See the vsnprintf() documentation for format string extensions over C99.
100 - */
102 -asmlinkage int printk(const char *fmt, ...)
104 - va_list args;
105 - int r;
107 - va_start(args, fmt);
108 - r = vprintk(fmt, args);
109 - va_end(args);
111 - return r;
114 /* cpu currently holding logbuf_lock */
115 static volatile unsigned int printk_cpu = UINT_MAX;
117 @@ -770,7 +736,6 @@ out_restore_irqs:
118 preempt_enable();
119 return printed_len;
121 -EXPORT_SYMBOL(printk);
122 EXPORT_SYMBOL(vprintk);
124 #else
125 @@ -1337,3 +1302,40 @@ bool printk_timed_ratelimit(unsigned long *caller_jiffies,
127 EXPORT_SYMBOL(printk_timed_ratelimit);
128 #endif
130 +#ifdef CONFIG_PRINTK
131 +/**
132 + * printk - print a kernel message
133 + * @fmt: format string
135 + * This is printk(). It can be called from any context. We want it to work.
137 + * We try to grab the console_sem. If we succeed, it's easy - we log the output and
138 + * call the console drivers. If we fail to get the semaphore we place the output
139 + * into the log buffer and return. The current holder of the console_sem will
140 + * notice the new output in release_console_sem() and will send it to the
141 + * consoles before releasing the semaphore.
143 + * One effect of this deferred printing is that code which calls printk() and
144 + * then changes console_loglevel may break. This is because console_loglevel
145 + * is inspected when the actual printing occurs.
147 + * See also:
148 + * printf(3)
150 + * See the vsnprintf() documentation for format string extensions over C99.
151 + */
153 +asmlinkage int printk(const char *fmt, ...)
155 + va_list args;
156 + int r;
158 + va_start(args, fmt);
159 + r = vprintk(fmt, args);
160 + va_end(args);
162 + return r;
164 +EXPORT_SYMBOL(printk);
165 +#endif
167 1.6.5
169 From 9c1a51f00116d1763720dd270b691539845b97f1 Mon Sep 17 00:00:00 2001
170 From: Marc Andre Tanner <mat@brain-dump.org>
171 Date: Fri, 28 Aug 2009 23:11:05 +0200
172 Subject: [PATCH 3/5] printk: introduce printk_unfiltered as an alias to printk
174 The standard printk function will be wrapped by a macro which
175 filters out messages above a certain verbosity level. Because
176 this might not be desired in certain situations we provide an
177 unfiltered variant.
179 Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>
181 include/linux/kernel.h | 5 +++++
182 kernel/printk.c | 23 +++++++++++++++++++++++
183 2 files changed, 28 insertions(+), 0 deletions(-)
185 diff --git a/include/linux/kernel.h b/include/linux/kernel.h
186 index d6320a3..c2b3047 100644
187 --- a/include/linux/kernel.h
188 +++ b/include/linux/kernel.h
189 @@ -239,6 +239,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
190 __attribute__ ((format (printf, 1, 0)));
191 asmlinkage int printk(const char * fmt, ...)
192 __attribute__ ((format (printf, 1, 2))) __cold;
193 +asmlinkage int printk_unfiltered(const char *fmt, ...)
194 + __attribute__ ((format (printf, 1, 2))) __cold;
196 extern struct ratelimit_state printk_ratelimit_state;
197 extern int printk_ratelimit(void);
198 @@ -265,6 +267,9 @@ static inline int vprintk(const char *s, va_list args) { return 0; }
199 static inline int printk(const char *s, ...)
200 __attribute__ ((format (printf, 1, 2)));
201 static inline int __cold printk(const char *s, ...) { return 0; }
202 +static inline int printk_unfiltered(const char *s, ...)
203 + __attribute__ ((format (printf, 1, 2)));
204 +static inline int __cold printk_unfiltered(const char *s, ...) { return 0; }
205 static inline int printk_ratelimit(void) { return 0; }
206 static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
207 unsigned int interval_msec) \
208 diff --git a/kernel/printk.c b/kernel/printk.c
209 index 5455d41..0a2f654 100644
210 --- a/kernel/printk.c
211 +++ b/kernel/printk.c
212 @@ -1310,6 +1310,11 @@ EXPORT_SYMBOL(printk_timed_ratelimit);
214 * This is printk(). It can be called from any context. We want it to work.
216 + * Note that depending on the kernel configuration printk might be wrapped by
217 + * a macro which will filter out messages above a certain verbosity level.
218 + * In cases where it's important that the message will get through independenly
219 + * of the configuration setting printk_unfiltered should be used instead.
221 * We try to grab the console_sem. If we succeed, it's easy - we log the output and
222 * call the console drivers. If we fail to get the semaphore we place the output
223 * into the log buffer and return. The current holder of the console_sem will
224 @@ -1326,6 +1331,14 @@ EXPORT_SYMBOL(printk_timed_ratelimit);
225 * See the vsnprintf() documentation for format string extensions over C99.
229 + * We need to #undef the printk macro from <linux/kernel.h> because
230 + * it would otherwise conflict with the function implementation.
231 + */
232 +#ifdef printk
233 +# undef printk
234 +#endif
236 asmlinkage int printk(const char *fmt, ...)
238 va_list args;
239 @@ -1338,4 +1351,14 @@ asmlinkage int printk(const char *fmt, ...)
240 return r;
242 EXPORT_SYMBOL(printk);
245 + * Because printk might be wrapped by a macro which will filter out messages
246 + * above a certain verbosity level we provide an unfiltered variant for use
247 + * cases where the filtering isn't desired.
248 + */
250 +asmlinkage int printk_unfiltered(const char *fmt, ...)
251 + __attribute__((alias("printk")));
252 +EXPORT_SYMBOL(printk_unfiltered);
253 #endif
255 1.6.5
257 From 908f3bb6376436466c63034225e6097587e816f7 Mon Sep 17 00:00:00 2001
258 From: Marc Andre Tanner <mat@brain-dump.org>
259 Date: Fri, 28 Aug 2009 23:48:37 +0200
260 Subject: [PATCH 4/5] char/mem: replace printk with printk_unfiltered
262 We don't want to filter user space data which comes from /dev/kmsg.
264 Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>
266 drivers/char/mem.c | 2 +-
267 1 files changed, 1 insertions(+), 1 deletions(-)
269 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
270 index afa8813..ba48b82 100644
271 --- a/drivers/char/mem.c
272 +++ b/drivers/char/mem.c
273 @@ -850,7 +850,7 @@ static ssize_t kmsg_write(struct file * file, const char __user * buf,
274 ret = -EFAULT;
275 if (!copy_from_user(tmp, buf, count)) {
276 tmp[count] = 0;
277 - ret = printk("%s", tmp);
278 + ret = printk_unfiltered("%s", tmp);
279 if (ret > count)
280 /* printk can add a prefix */
281 ret = count;
283 1.6.5
285 From bb701ec53e1a65176d22e16560cddcfbb7a7e25e Mon Sep 17 00:00:00 2001
286 From: Marc Andre Tanner <mat@brain-dump.org>
287 Date: Sat, 29 Aug 2009 00:10:50 +0200
288 Subject: [PATCH] printk: provide a filtering macro for printk
290 The macro filters out printk messages based on a configurable verbosity
291 level (CONFIG_PRINTK_VERBOSITY).
293 Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>
295 include/linux/kernel.h | 34 ++++++++++++++++++++++++++++++++++
296 1 files changed, 34 insertions(+), 0 deletions(-)
298 diff --git a/include/linux/kernel.h b/include/linux/kernel.h
299 index a2c8d5b..3f7f0cf 100644
300 --- a/include/linux/kernel.h
301 +++ b/include/linux/kernel.h
302 @@ -268,6 +268,40 @@ asmlinkage int printk(const char * fmt, ...)
303 asmlinkage int printk_unfiltered(const char *fmt, ...)
304 __attribute__ ((format (printf, 1, 2))) __cold;
306 +#if defined(CONFIG_PRINTK_VERBOSITY) && CONFIG_PRINTK_VERBOSITY > 0
308 + * The idea here is to wrap the actual printk function with a macro which
309 + * will filter out all messages above a certain verbosity level. Because
310 + * the if condition evaluates to a constant expression the compiler will be
311 + * able to eliminate it and the resulting kernel image will be smaller.
312 + */
314 +/* Return the printk log level or if none was specified the default message
315 + * logleve which is 4.
316 + */
318 +#define PRINTK_LOGLEVEL(fmt) ( \
319 + (((const char *)(fmt))[0] == '<' && \
320 + ((const char *)(fmt))[1] >= '0' && \
321 + ((const char *)(fmt))[1] <= '9' \
322 + ) ? ((const char *)(fmt))[1] - '0' : 4 \
325 +#define PRINTK_FILTER(fmt) ( \
326 + PRINTK_LOGLEVEL((fmt)) <= CONFIG_PRINTK_VERBOSITY \
329 +/* Check if the whole construct evaluates to a constant expression and if so
330 + * filter it according to CONFIG_PRINTK_VERBOSITY
331 + */
333 +#define printk(fmt, ...) ( \
334 + (!(fmt) || !__builtin_constant_p(PRINTK_FILTER((fmt))) || PRINTK_FILTER((fmt))) ? \
335 + printk((fmt), ##__VA_ARGS__) : 0 \
338 +#endif /* CONFIG_PRINTK_VERBOSITY */
340 extern int __printk_ratelimit(const char *func);
341 #define printk_ratelimit() __printk_ratelimit(__func__)
342 extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
344 1.6.5