Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

printk: convert byte-buffer to variable-length record buffer

- Record-based stream instead of the traditional byte stream
buffer. All records carry a 64 bit timestamp, the syslog facility
and priority in the record header.

- Records consume almost the same amount, sometimes less memory than
the traditional byte stream buffer (if printk_time is enabled). The record
header is 16 bytes long, plus some padding bytes at the end if needed.
The byte-stream buffer needed 3 chars for the syslog prefix, 15 char for
the timestamp and a newline.

- Buffer management is based on message sequence numbers. When records
need to be discarded, the reading heads move on to the next full
record. Unlike the byte-stream buffer, no old logged lines get
truncated or partly overwritten by new ones. Sequence numbers also
allow consumers of the log stream to get notified if any message in
the stream they are about to read gets discarded during the time
of reading.

- Better buffered IO support for KERN_CONT continuation lines, when printk()
is called multiple times for a single line. The use of KERN_CONT is now
mandatory to use continuation; a few places in the kernel need trivial fixes
here. The buffering could possibly be extended to per-cpu variables to allow
better thread-safety for multiple printk() invocations for a single line.

- Full-featured syslog facility value support. Different facilities
can tag their messages. All userspace-injected messages enforce a
facility value > 0 now, to be able to reliably distinguish them from
the kernel-generated messages. Independent subsystems like a
baseband processor running its own firmware, or a kernel-related
userspace process can use their own unique facility values. Multiple
independent log streams can co-exist that way in the same
buffer. All share the same global sequence number counter to ensure
proper ordering (and interleaving) and to allow the consumers of the
log to reliably correlate the events from different facilities.

Tested-by: William Douglas <william.douglas@intel.com>
Signed-off-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kay Sievers and committed by
Greg Kroah-Hartman
7ff9554b 89528127

+639 -441
+38 -17
drivers/char/mem.c
··· 810 810 static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv, 811 811 unsigned long count, loff_t pos) 812 812 { 813 - char *line, *p; 813 + char *buf, *line; 814 814 int i; 815 - ssize_t ret = -EFAULT; 815 + int level = default_message_loglevel; 816 + int facility = 1; /* LOG_USER */ 816 817 size_t len = iov_length(iv, count); 818 + ssize_t ret = len; 817 819 818 - line = kmalloc(len + 1, GFP_KERNEL); 819 - if (line == NULL) 820 + if (len > 1024) 821 + return -EINVAL; 822 + buf = kmalloc(len+1, GFP_KERNEL); 823 + if (buf == NULL) 820 824 return -ENOMEM; 821 825 822 - /* 823 - * copy all vectors into a single string, to ensure we do 824 - * not interleave our log line with other printk calls 825 - */ 826 - p = line; 826 + line = buf; 827 827 for (i = 0; i < count; i++) { 828 - if (copy_from_user(p, iv[i].iov_base, iv[i].iov_len)) 828 + if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len)) 829 829 goto out; 830 - p += iv[i].iov_len; 830 + line += iv[i].iov_len; 831 831 } 832 - p[0] = '\0'; 833 832 834 - ret = printk("%s", line); 835 - /* printk can add a prefix */ 836 - if (ret > len) 837 - ret = len; 833 + /* 834 + * Extract and skip the syslog prefix <[0-9]*>. Coming from userspace 835 + * the decimal value represents 32bit, the lower 3 bit are the log 836 + * level, the rest are the log facility. 837 + * 838 + * If no prefix or no userspace facility is specified, we 839 + * enforce LOG_USER, to be able to reliably distinguish 840 + * kernel-generated messages from userspace-injected ones. 841 + */ 842 + line = buf; 843 + if (line[0] == '<') { 844 + char *endp = NULL; 845 + 846 + i = simple_strtoul(line+1, &endp, 10); 847 + if (endp && endp[0] == '>') { 848 + level = i & 7; 849 + if (i >> 3) 850 + facility = i >> 3; 851 + endp++; 852 + len -= endp - line; 853 + line = endp; 854 + } 855 + } 856 + line[len] = '\0'; 857 + 858 + printk_emit(facility, level, NULL, 0, "%s", line); 838 859 out: 839 - kfree(line); 860 + kfree(buf); 840 861 return ret; 841 862 } 842 863
+11
include/linux/printk.h
··· 95 95 extern void printk_tick(void); 96 96 97 97 #ifdef CONFIG_PRINTK 98 + asmlinkage __printf(5, 0) 99 + int vprintk_emit(int facility, int level, 100 + const char *dict, size_t dictlen, 101 + const char *fmt, va_list args); 102 + 98 103 asmlinkage __printf(1, 0) 99 104 int vprintk(const char *fmt, va_list args); 105 + 106 + asmlinkage __printf(5, 6) __cold 107 + asmlinkage int printk_emit(int facility, int level, 108 + const char *dict, size_t dictlen, 109 + const char *fmt, ...); 110 + 100 111 asmlinkage __printf(1, 2) __cold 101 112 int printk(const char *fmt, ...); 102 113
+590 -424
kernel/printk.c
··· 54 54 { 55 55 } 56 56 57 - #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) 58 - 59 57 /* printk's without a loglevel use this.. */ 60 58 #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL 61 59 ··· 97 99 static int console_locked, console_suspended; 98 100 99 101 /* 100 - * logbuf_lock protects log_buf, log_start, log_end, con_start and logged_chars 101 - * It is also used in interesting ways to provide interlocking in 102 - * console_unlock();. 103 - */ 104 - static DEFINE_RAW_SPINLOCK(logbuf_lock); 105 - 106 - #define LOG_BUF_MASK (log_buf_len-1) 107 - #define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK]) 108 - 109 - /* 110 - * The indices into log_buf are not constrained to log_buf_len - they 111 - * must be masked before subscripting 112 - */ 113 - static unsigned log_start; /* Index into log_buf: next char to be read by syslog() */ 114 - static unsigned con_start; /* Index into log_buf: next char to be sent to consoles */ 115 - static unsigned log_end; /* Index into log_buf: most-recently-written-char + 1 */ 116 - 117 - /* 118 102 * If exclusive_console is non-NULL then only this console is to be printed to. 119 103 */ 120 104 static struct console *exclusive_console; ··· 126 146 static int console_may_schedule; 127 147 128 148 #ifdef CONFIG_PRINTK 149 + /* 150 + * The printk log buffer consists of a chain of concatenated variable 151 + * length records. Every record starts with a record header, containing 152 + * the overall length of the record. 153 + * 154 + * The heads to the first and last entry in the buffer, as well as the 155 + * sequence numbers of these both entries are maintained when messages 156 + * are stored.. 157 + * 158 + * If the heads indicate available messages, the length in the header 159 + * tells the start next message. A length == 0 for the next message 160 + * indicates a wrap-around to the beginning of the buffer. 161 + * 162 + * Every record carries the monotonic timestamp in microseconds, as well as 163 + * the standard userspace syslog level and syslog facility. The usual 164 + * kernel messages use LOG_KERN; userspace-injected messages always carry 165 + * a matching syslog facility, by default LOG_USER. The origin of every 166 + * message can be reliably determined that way. 167 + * 168 + * The human readable log message directly follows the message header. The 169 + * length of the message text is stored in the header, the stored message 170 + * is not terminated. 171 + * 172 + */ 129 173 174 + struct log { 175 + u64 ts_nsec; /* timestamp in nanoseconds */ 176 + u16 len; /* length of entire record */ 177 + u16 text_len; /* length of text buffer */ 178 + u16 dict_len; /* length of dictionary buffer */ 179 + u16 level; /* syslog level + facility */ 180 + }; 181 + 182 + /* 183 + * The logbuf_lock protects kmsg buffer, indices, counters. It is also 184 + * used in interesting ways to provide interlocking in console_unlock(); 185 + */ 186 + static DEFINE_RAW_SPINLOCK(logbuf_lock); 187 + 188 + /* cpu currently holding logbuf_lock */ 189 + static volatile unsigned int logbuf_cpu = UINT_MAX; 190 + 191 + #define LOG_LINE_MAX 1024 192 + 193 + /* record buffer */ 194 + #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) 130 195 static char __log_buf[__LOG_BUF_LEN]; 131 196 static char *log_buf = __log_buf; 132 - static int log_buf_len = __LOG_BUF_LEN; 133 - static unsigned logged_chars; /* Number of chars produced since last read+clear operation */ 134 - static int saved_console_loglevel = -1; 197 + static u32 log_buf_len = __LOG_BUF_LEN; 198 + 199 + /* index and sequence number of the first record stored in the buffer */ 200 + static u64 log_first_seq; 201 + static u32 log_first_idx; 202 + 203 + /* index and sequence number of the next record to store in the buffer */ 204 + static u64 log_next_seq; 205 + static u32 log_next_idx; 206 + 207 + /* the next printk record to read after the last 'clear' command */ 208 + static u64 clear_seq; 209 + static u32 clear_idx; 210 + 211 + /* the next printk record to read by syslog(READ) or /proc/kmsg */ 212 + static u64 syslog_seq; 213 + static u32 syslog_idx; 214 + 215 + /* human readable text of the record */ 216 + static char *log_text(const struct log *msg) 217 + { 218 + return (char *)msg + sizeof(struct log); 219 + } 220 + 221 + /* optional key/value pair dictionary attached to the record */ 222 + static char *log_dict(const struct log *msg) 223 + { 224 + return (char *)msg + sizeof(struct log) + msg->text_len; 225 + } 226 + 227 + /* get record by index; idx must point to valid msg */ 228 + static struct log *log_from_idx(u32 idx) 229 + { 230 + struct log *msg = (struct log *)(log_buf + idx); 231 + 232 + /* 233 + * A length == 0 record is the end of buffer marker. Wrap around and 234 + * read the message at the start of the buffer. 235 + */ 236 + if (!msg->len) 237 + return (struct log *)log_buf; 238 + return msg; 239 + } 240 + 241 + /* get next record; idx must point to valid msg */ 242 + static u32 log_next(u32 idx) 243 + { 244 + struct log *msg = (struct log *)(log_buf + idx); 245 + 246 + /* length == 0 indicates the end of the buffer; wrap */ 247 + /* 248 + * A length == 0 record is the end of buffer marker. Wrap around and 249 + * read the message at the start of the buffer as *this* one, and 250 + * return the one after that. 251 + */ 252 + if (!msg->len) { 253 + msg = (struct log *)log_buf; 254 + return msg->len; 255 + } 256 + return idx + msg->len; 257 + } 258 + 259 + #if !defined(CONFIG_64BIT) || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) 260 + #define LOG_ALIGN 4 261 + #else 262 + #define LOG_ALIGN 8 263 + #endif 264 + 265 + /* insert record into the buffer, discard old ones, update heads */ 266 + static void log_store(int facility, int level, 267 + const char *dict, u16 dict_len, 268 + const char *text, u16 text_len) 269 + { 270 + struct log *msg; 271 + u32 size, pad_len; 272 + 273 + /* number of '\0' padding bytes to next message */ 274 + size = sizeof(struct log) + text_len + dict_len; 275 + pad_len = (-size) & (LOG_ALIGN - 1); 276 + size += pad_len; 277 + 278 + while (log_first_seq < log_next_seq) { 279 + u32 free; 280 + 281 + if (log_next_idx > log_first_idx) 282 + free = max(log_buf_len - log_next_idx, log_first_idx); 283 + else 284 + free = log_first_idx - log_next_idx; 285 + 286 + if (free > size + sizeof(struct log)) 287 + break; 288 + 289 + /* drop old messages until we have enough contiuous space */ 290 + log_first_idx = log_next(log_first_idx); 291 + log_first_seq++; 292 + } 293 + 294 + if (log_next_idx + size + sizeof(struct log) >= log_buf_len) { 295 + /* 296 + * This message + an additional empty header does not fit 297 + * at the end of the buffer. Add an empty header with len == 0 298 + * to signify a wrap around. 299 + */ 300 + memset(log_buf + log_next_idx, 0, sizeof(struct log)); 301 + log_next_idx = 0; 302 + } 303 + 304 + /* fill message */ 305 + msg = (struct log *)(log_buf + log_next_idx); 306 + memcpy(log_text(msg), text, text_len); 307 + msg->text_len = text_len; 308 + memcpy(log_dict(msg), dict, dict_len); 309 + msg->dict_len = dict_len; 310 + msg->level = (facility << 3) | (level & 7); 311 + msg->ts_nsec = local_clock(); 312 + memset(log_dict(msg) + dict_len, 0, pad_len); 313 + msg->len = sizeof(struct log) + text_len + dict_len + pad_len; 314 + 315 + /* insert message */ 316 + log_next_idx += msg->len; 317 + log_next_seq++; 318 + } 135 319 136 320 #ifdef CONFIG_KEXEC 137 321 /* ··· 309 165 void log_buf_kexec_setup(void) 310 166 { 311 167 VMCOREINFO_SYMBOL(log_buf); 312 - VMCOREINFO_SYMBOL(log_end); 313 168 VMCOREINFO_SYMBOL(log_buf_len); 314 - VMCOREINFO_SYMBOL(logged_chars); 169 + VMCOREINFO_SYMBOL(log_first_idx); 170 + VMCOREINFO_SYMBOL(log_next_idx); 315 171 } 316 172 #endif 317 173 ··· 335 191 void __init setup_log_buf(int early) 336 192 { 337 193 unsigned long flags; 338 - unsigned start, dest_idx, offset; 339 194 char *new_log_buf; 340 195 int free; 341 196 ··· 362 219 log_buf_len = new_log_buf_len; 363 220 log_buf = new_log_buf; 364 221 new_log_buf_len = 0; 365 - free = __LOG_BUF_LEN - log_end; 366 - 367 - offset = start = min(con_start, log_start); 368 - dest_idx = 0; 369 - while (start != log_end) { 370 - unsigned log_idx_mask = start & (__LOG_BUF_LEN - 1); 371 - 372 - log_buf[dest_idx] = __log_buf[log_idx_mask]; 373 - start++; 374 - dest_idx++; 375 - } 376 - log_start -= offset; 377 - con_start -= offset; 378 - log_end -= offset; 222 + free = __LOG_BUF_LEN - log_next_idx; 223 + memcpy(log_buf, __log_buf, __LOG_BUF_LEN); 379 224 raw_spin_unlock_irqrestore(&logbuf_lock, flags); 380 225 381 226 pr_info("log_buf_len: %d\n", log_buf_len); ··· 463 332 return 0; 464 333 } 465 334 335 + #if defined(CONFIG_PRINTK_TIME) 336 + static bool printk_time = 1; 337 + #else 338 + static bool printk_time; 339 + #endif 340 + module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR); 341 + 342 + static int syslog_print_line(u32 idx, char *text, size_t size) 343 + { 344 + struct log *msg; 345 + size_t len; 346 + 347 + msg = log_from_idx(idx); 348 + if (!text) { 349 + /* calculate length only */ 350 + len = 3; 351 + 352 + if (msg->level > 9) 353 + len++; 354 + if (msg->level > 99) 355 + len++; 356 + 357 + if (printk_time) 358 + len += 15; 359 + 360 + len += msg->text_len; 361 + len++; 362 + return len; 363 + } 364 + 365 + len = sprintf(text, "<%u>", msg->level); 366 + 367 + if (printk_time) { 368 + unsigned long long t = msg->ts_nsec; 369 + unsigned long rem_ns = do_div(t, 1000000000); 370 + 371 + len += sprintf(text + len, "[%5lu.%06lu] ", 372 + (unsigned long) t, rem_ns / 1000); 373 + } 374 + 375 + if (len + msg->text_len > size) 376 + return -EINVAL; 377 + memcpy(text + len, log_text(msg), msg->text_len); 378 + len += msg->text_len; 379 + text[len++] = '\n'; 380 + return len; 381 + } 382 + 383 + static int syslog_print(char __user *buf, int size) 384 + { 385 + char *text; 386 + int len; 387 + 388 + text = kmalloc(LOG_LINE_MAX, GFP_KERNEL); 389 + if (!text) 390 + return -ENOMEM; 391 + 392 + raw_spin_lock_irq(&logbuf_lock); 393 + if (syslog_seq < log_first_seq) { 394 + /* messages are gone, move to first one */ 395 + syslog_seq = log_first_seq; 396 + syslog_idx = log_first_idx; 397 + } 398 + len = syslog_print_line(syslog_idx, text, LOG_LINE_MAX); 399 + syslog_idx = log_next(syslog_idx); 400 + syslog_seq++; 401 + raw_spin_unlock_irq(&logbuf_lock); 402 + 403 + if (len > 0 && copy_to_user(buf, text, len)) 404 + len = -EFAULT; 405 + 406 + kfree(text); 407 + return len; 408 + } 409 + 410 + static int syslog_print_all(char __user *buf, int size, bool clear) 411 + { 412 + char *text; 413 + int len = 0; 414 + 415 + text = kmalloc(LOG_LINE_MAX, GFP_KERNEL); 416 + if (!text) 417 + return -ENOMEM; 418 + 419 + raw_spin_lock_irq(&logbuf_lock); 420 + if (buf) { 421 + u64 next_seq; 422 + u64 seq; 423 + u32 idx; 424 + 425 + if (clear_seq < log_first_seq) { 426 + /* messages are gone, move to first available one */ 427 + clear_seq = log_first_seq; 428 + clear_idx = log_first_idx; 429 + } 430 + 431 + /* 432 + * Find first record that fits, including all following records, 433 + * into the user-provided buffer for this dump. 434 + */ 435 + seq = clear_seq; 436 + idx = clear_idx; 437 + while (seq < log_next_seq) { 438 + len += syslog_print_line(idx, NULL, 0); 439 + idx = log_next(idx); 440 + seq++; 441 + } 442 + seq = clear_seq; 443 + idx = clear_idx; 444 + while (len > size && seq < log_next_seq) { 445 + len -= syslog_print_line(idx, NULL, 0); 446 + idx = log_next(idx); 447 + seq++; 448 + } 449 + 450 + /* last message in this dump */ 451 + next_seq = log_next_seq; 452 + 453 + len = 0; 454 + while (len >= 0 && seq < next_seq) { 455 + int textlen; 456 + 457 + textlen = syslog_print_line(idx, text, LOG_LINE_MAX); 458 + if (textlen < 0) { 459 + len = textlen; 460 + break; 461 + } 462 + idx = log_next(idx); 463 + seq++; 464 + 465 + raw_spin_unlock_irq(&logbuf_lock); 466 + if (copy_to_user(buf + len, text, textlen)) 467 + len = -EFAULT; 468 + else 469 + len += textlen; 470 + raw_spin_lock_irq(&logbuf_lock); 471 + 472 + if (seq < log_first_seq) { 473 + /* messages are gone, move to next one */ 474 + seq = log_first_seq; 475 + idx = log_first_idx; 476 + } 477 + } 478 + } 479 + 480 + if (clear) { 481 + clear_seq = log_next_seq; 482 + clear_idx = log_next_idx; 483 + } 484 + raw_spin_unlock_irq(&logbuf_lock); 485 + 486 + kfree(text); 487 + return len; 488 + } 489 + 466 490 int do_syslog(int type, char __user *buf, int len, bool from_file) 467 491 { 468 - unsigned i, j, limit, count; 469 - int do_clear = 0; 470 - char c; 492 + bool clear = false; 493 + static int saved_console_loglevel = -1; 471 494 int error; 472 495 473 496 error = check_syslog_permissions(type, from_file); ··· 649 364 goto out; 650 365 } 651 366 error = wait_event_interruptible(log_wait, 652 - (log_start - log_end)); 367 + syslog_seq != log_next_seq); 653 368 if (error) 654 369 goto out; 655 - i = 0; 656 - raw_spin_lock_irq(&logbuf_lock); 657 - while (!error && (log_start != log_end) && i < len) { 658 - c = LOG_BUF(log_start); 659 - log_start++; 660 - raw_spin_unlock_irq(&logbuf_lock); 661 - error = __put_user(c,buf); 662 - buf++; 663 - i++; 664 - cond_resched(); 665 - raw_spin_lock_irq(&logbuf_lock); 666 - } 667 - raw_spin_unlock_irq(&logbuf_lock); 668 - if (!error) 669 - error = i; 370 + error = syslog_print(buf, len); 670 371 break; 671 372 /* Read/clear last kernel messages */ 672 373 case SYSLOG_ACTION_READ_CLEAR: 673 - do_clear = 1; 374 + clear = true; 674 375 /* FALL THRU */ 675 376 /* Read last kernel messages */ 676 377 case SYSLOG_ACTION_READ_ALL: ··· 670 399 error = -EFAULT; 671 400 goto out; 672 401 } 673 - count = len; 674 - if (count > log_buf_len) 675 - count = log_buf_len; 676 - raw_spin_lock_irq(&logbuf_lock); 677 - if (count > logged_chars) 678 - count = logged_chars; 679 - if (do_clear) 680 - logged_chars = 0; 681 - limit = log_end; 682 - /* 683 - * __put_user() could sleep, and while we sleep 684 - * printk() could overwrite the messages 685 - * we try to copy to user space. Therefore 686 - * the messages are copied in reverse. <manfreds> 687 - */ 688 - for (i = 0; i < count && !error; i++) { 689 - j = limit-1-i; 690 - if (j + log_buf_len < log_end) 691 - break; 692 - c = LOG_BUF(j); 693 - raw_spin_unlock_irq(&logbuf_lock); 694 - error = __put_user(c,&buf[count-1-i]); 695 - cond_resched(); 696 - raw_spin_lock_irq(&logbuf_lock); 697 - } 698 - raw_spin_unlock_irq(&logbuf_lock); 699 - if (error) 700 - break; 701 - error = i; 702 - if (i != count) { 703 - int offset = count-error; 704 - /* buffer overflow during copy, correct user buffer. */ 705 - for (i = 0; i < error; i++) { 706 - if (__get_user(c,&buf[i+offset]) || 707 - __put_user(c,&buf[i])) { 708 - error = -EFAULT; 709 - break; 710 - } 711 - cond_resched(); 712 - } 713 - } 402 + error = syslog_print_all(buf, len, clear); 714 403 break; 715 404 /* Clear ring buffer */ 716 405 case SYSLOG_ACTION_CLEAR: 717 - logged_chars = 0; 718 - break; 406 + syslog_print_all(NULL, 0, true); 719 407 /* Disable logging to console */ 720 408 case SYSLOG_ACTION_CONSOLE_OFF: 721 409 if (saved_console_loglevel == -1) ··· 702 472 break; 703 473 /* Number of chars in the log buffer */ 704 474 case SYSLOG_ACTION_SIZE_UNREAD: 705 - error = log_end - log_start; 475 + raw_spin_lock_irq(&logbuf_lock); 476 + if (syslog_seq < log_first_seq) { 477 + /* messages are gone, move to first one */ 478 + syslog_seq = log_first_seq; 479 + syslog_idx = log_first_idx; 480 + } 481 + if (from_file) { 482 + /* 483 + * Short-cut for poll(/"proc/kmsg") which simply checks 484 + * for pending data, not the size; return the count of 485 + * records, not the length. 486 + */ 487 + error = log_next_idx - syslog_idx; 488 + } else { 489 + u64 seq; 490 + u32 idx; 491 + 492 + error = 0; 493 + seq = syslog_seq; 494 + idx = syslog_idx; 495 + while (seq < log_next_seq) { 496 + error += syslog_print_line(idx, NULL, 0); 497 + idx = log_next(idx); 498 + seq++; 499 + } 500 + } 501 + raw_spin_unlock_irq(&logbuf_lock); 706 502 break; 707 503 /* Size of the log buffer */ 708 504 case SYSLOG_ACTION_SIZE_BUFFER: ··· 757 501 { 758 502 syslog_data[0] = log_buf; 759 503 syslog_data[1] = log_buf + log_buf_len; 760 - syslog_data[2] = log_buf + log_end - 761 - (logged_chars < log_buf_len ? logged_chars : log_buf_len); 762 - syslog_data[3] = log_buf + log_end; 504 + syslog_data[2] = log_buf + log_first_idx; 505 + syslog_data[3] = log_buf + log_next_idx; 763 506 } 764 507 #endif /* CONFIG_KGDB_KDB */ 765 - 766 - /* 767 - * Call the console drivers on a range of log_buf 768 - */ 769 - static void __call_console_drivers(unsigned start, unsigned end) 770 - { 771 - struct console *con; 772 - 773 - for_each_console(con) { 774 - if (exclusive_console && con != exclusive_console) 775 - continue; 776 - if ((con->flags & CON_ENABLED) && con->write && 777 - (cpu_online(smp_processor_id()) || 778 - (con->flags & CON_ANYTIME))) 779 - con->write(con, &LOG_BUF(start), end - start); 780 - } 781 - } 782 508 783 509 static bool __read_mostly ignore_loglevel; 784 510 ··· 778 540 "print all kernel messages to the console."); 779 541 780 542 /* 781 - * Write out chars from start to end - 1 inclusive 782 - */ 783 - static void _call_console_drivers(unsigned start, 784 - unsigned end, int msg_log_level) 785 - { 786 - trace_console(&LOG_BUF(0), start, end, log_buf_len); 787 - 788 - if ((msg_log_level < console_loglevel || ignore_loglevel) && 789 - console_drivers && start != end) { 790 - if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) { 791 - /* wrapped write */ 792 - __call_console_drivers(start & LOG_BUF_MASK, 793 - log_buf_len); 794 - __call_console_drivers(0, end & LOG_BUF_MASK); 795 - } else { 796 - __call_console_drivers(start, end); 797 - } 798 - } 799 - } 800 - 801 - /* 802 - * Parse the syslog header <[0-9]*>. The decimal value represents 32bit, the 803 - * lower 3 bit are the log level, the rest are the log facility. In case 804 - * userspace passes usual userspace syslog messages to /dev/kmsg or 805 - * /dev/ttyprintk, the log prefix might contain the facility. Printk needs 806 - * to extract the correct log level for in-kernel processing, and not mangle 807 - * the original value. 808 - * 809 - * If a prefix is found, the length of the prefix is returned. If 'level' is 810 - * passed, it will be filled in with the log level without a possible facility 811 - * value. If 'special' is passed, the special printk prefix chars are accepted 812 - * and returned. If no valid header is found, 0 is returned and the passed 813 - * variables are not touched. 814 - */ 815 - static size_t log_prefix(const char *p, unsigned int *level, char *special) 816 - { 817 - unsigned int lev = 0; 818 - char sp = '\0'; 819 - size_t len; 820 - 821 - if (p[0] != '<' || !p[1]) 822 - return 0; 823 - if (p[2] == '>') { 824 - /* usual single digit level number or special char */ 825 - switch (p[1]) { 826 - case '0' ... '7': 827 - lev = p[1] - '0'; 828 - break; 829 - case 'c': /* KERN_CONT */ 830 - case 'd': /* KERN_DEFAULT */ 831 - sp = p[1]; 832 - break; 833 - default: 834 - return 0; 835 - } 836 - len = 3; 837 - } else { 838 - /* multi digit including the level and facility number */ 839 - char *endp = NULL; 840 - 841 - lev = (simple_strtoul(&p[1], &endp, 10) & 7); 842 - if (endp == NULL || endp[0] != '>') 843 - return 0; 844 - len = (endp + 1) - p; 845 - } 846 - 847 - /* do not accept special char if not asked for */ 848 - if (sp && !special) 849 - return 0; 850 - 851 - if (special) { 852 - *special = sp; 853 - /* return special char, do not touch level */ 854 - if (sp) 855 - return len; 856 - } 857 - 858 - if (level) 859 - *level = lev; 860 - return len; 861 - } 862 - 863 - /* 864 543 * Call the console drivers, asking them to write out 865 544 * log_buf[start] to log_buf[end - 1]. 866 545 * The console_lock must be held. 867 546 */ 868 - static void call_console_drivers(unsigned start, unsigned end) 547 + static void call_console_drivers(int level, const char *text, size_t len) 869 548 { 870 - unsigned cur_index, start_print; 871 - static int msg_level = -1; 549 + struct console *con; 872 550 873 - BUG_ON(((int)(start - end)) > 0); 551 + trace_console(text, 0, len, len); 874 552 875 - cur_index = start; 876 - start_print = start; 877 - while (cur_index != end) { 878 - if (msg_level < 0 && ((end - cur_index) > 2)) { 879 - /* strip log prefix */ 880 - cur_index += log_prefix(&LOG_BUF(cur_index), &msg_level, NULL); 881 - start_print = cur_index; 882 - } 883 - while (cur_index != end) { 884 - char c = LOG_BUF(cur_index); 553 + if (level >= console_loglevel && !ignore_loglevel) 554 + return; 555 + if (!console_drivers) 556 + return; 885 557 886 - cur_index++; 887 - if (c == '\n') { 888 - if (msg_level < 0) { 889 - /* 890 - * printk() has already given us loglevel tags in 891 - * the buffer. This code is here in case the 892 - * log buffer has wrapped right round and scribbled 893 - * on those tags 894 - */ 895 - msg_level = default_message_loglevel; 896 - } 897 - _call_console_drivers(start_print, cur_index, msg_level); 898 - msg_level = -1; 899 - start_print = cur_index; 900 - break; 901 - } 902 - } 558 + for_each_console(con) { 559 + if (exclusive_console && con != exclusive_console) 560 + continue; 561 + if (!(con->flags & CON_ENABLED)) 562 + continue; 563 + if (!con->write) 564 + continue; 565 + if (!cpu_online(smp_processor_id()) && 566 + !(con->flags & CON_ANYTIME)) 567 + continue; 568 + con->write(con, text, len); 903 569 } 904 - _call_console_drivers(start_print, end, msg_level); 905 - } 906 - 907 - static void emit_log_char(char c) 908 - { 909 - LOG_BUF(log_end) = c; 910 - log_end++; 911 - if (log_end - log_start > log_buf_len) 912 - log_start = log_end - log_buf_len; 913 - if (log_end - con_start > log_buf_len) 914 - con_start = log_end - log_buf_len; 915 - if (logged_chars < log_buf_len) 916 - logged_chars++; 917 570 } 918 571 919 572 /* ··· 829 700 sema_init(&console_sem, 1); 830 701 } 831 702 832 - #if defined(CONFIG_PRINTK_TIME) 833 - static bool printk_time = 1; 834 - #else 835 - static bool printk_time = 0; 836 - #endif 837 - module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR); 838 - 839 - static bool always_kmsg_dump; 840 - module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR); 841 - 842 703 /* Check if we have any console registered that can be called early in boot. */ 843 704 static int have_callable_console(void) 844 705 { ··· 840 721 841 722 return 0; 842 723 } 843 - 844 - /** 845 - * printk - print a kernel message 846 - * @fmt: format string 847 - * 848 - * This is printk(). It can be called from any context. We want it to work. 849 - * 850 - * We try to grab the console_lock. If we succeed, it's easy - we log the output and 851 - * call the console drivers. If we fail to get the semaphore we place the output 852 - * into the log buffer and return. The current holder of the console_sem will 853 - * notice the new output in console_unlock(); and will send it to the 854 - * consoles before releasing the lock. 855 - * 856 - * One effect of this deferred printing is that code which calls printk() and 857 - * then changes console_loglevel may break. This is because console_loglevel 858 - * is inspected when the actual printing occurs. 859 - * 860 - * See also: 861 - * printf(3) 862 - * 863 - * See the vsnprintf() documentation for format string extensions over C99. 864 - */ 865 - 866 - asmlinkage int printk(const char *fmt, ...) 867 - { 868 - va_list args; 869 - int r; 870 - 871 - #ifdef CONFIG_KGDB_KDB 872 - if (unlikely(kdb_trap_printk)) { 873 - va_start(args, fmt); 874 - r = vkdb_printf(fmt, args); 875 - va_end(args); 876 - return r; 877 - } 878 - #endif 879 - va_start(args, fmt); 880 - r = vprintk(fmt, args); 881 - va_end(args); 882 - 883 - return r; 884 - } 885 - 886 - /* cpu currently holding logbuf_lock */ 887 - static volatile unsigned int printk_cpu = UINT_MAX; 888 724 889 725 /* 890 726 * Can we actually use the console at this time on this cpu? ··· 884 810 retval = 0; 885 811 } 886 812 } 887 - printk_cpu = UINT_MAX; 813 + logbuf_cpu = UINT_MAX; 888 814 if (wake) 889 815 up(&console_sem); 890 816 raw_spin_unlock(&logbuf_lock); 891 817 return retval; 892 818 } 893 - static const char recursion_bug_msg [] = 894 - KERN_CRIT "BUG: recent printk recursion!\n"; 895 - static int recursion_bug; 896 - static int new_text_line = 1; 897 - static char printk_buf[1024]; 898 819 899 820 int printk_delay_msec __read_mostly; 900 821 ··· 905 836 } 906 837 } 907 838 908 - asmlinkage int vprintk(const char *fmt, va_list args) 839 + asmlinkage int vprintk_emit(int facility, int level, 840 + const char *dict, size_t dictlen, 841 + const char *fmt, va_list args) 909 842 { 910 - int printed_len = 0; 911 - int current_log_level = default_message_loglevel; 843 + static int recursion_bug; 844 + static char buf[LOG_LINE_MAX]; 845 + static size_t buflen; 846 + static int buflevel; 847 + static char textbuf[LOG_LINE_MAX]; 848 + char *text = textbuf; 849 + size_t textlen; 912 850 unsigned long flags; 913 851 int this_cpu; 914 - char *p; 915 - size_t plen; 916 - char special; 852 + bool newline = false; 853 + bool cont = false; 854 + int printed_len = 0; 917 855 918 856 boot_delay_msec(); 919 857 printk_delay(); ··· 932 856 /* 933 857 * Ouch, printk recursed into itself! 934 858 */ 935 - if (unlikely(printk_cpu == this_cpu)) { 859 + if (unlikely(logbuf_cpu == this_cpu)) { 936 860 /* 937 861 * If a crash is occurring during printk() on this CPU, 938 862 * then try to get the crash message out but make sure ··· 949 873 950 874 lockdep_off(); 951 875 raw_spin_lock(&logbuf_lock); 952 - printk_cpu = this_cpu; 876 + logbuf_cpu = this_cpu; 953 877 954 878 if (recursion_bug) { 879 + static const char recursion_msg[] = 880 + "BUG: recent printk recursion!"; 881 + 955 882 recursion_bug = 0; 956 - strcpy(printk_buf, recursion_bug_msg); 957 - printed_len = strlen(recursion_bug_msg); 958 - } 959 - /* Emit the output into the temporary buffer */ 960 - printed_len += vscnprintf(printk_buf + printed_len, 961 - sizeof(printk_buf) - printed_len, fmt, args); 962 - 963 - p = printk_buf; 964 - 965 - /* Read log level and handle special printk prefix */ 966 - plen = log_prefix(p, &current_log_level, &special); 967 - if (plen) { 968 - p += plen; 969 - 970 - switch (special) { 971 - case 'c': /* Strip <c> KERN_CONT, continue line */ 972 - plen = 0; 973 - break; 974 - case 'd': /* Strip <d> KERN_DEFAULT, start new line */ 975 - plen = 0; 976 - default: 977 - if (!new_text_line) { 978 - emit_log_char('\n'); 979 - new_text_line = 1; 980 - } 981 - } 883 + printed_len += strlen(recursion_msg); 884 + /* emit KERN_CRIT message */ 885 + log_store(0, 2, NULL, 0, recursion_msg, printed_len); 982 886 } 983 887 984 888 /* 985 - * Copy the output into log_buf. If the caller didn't provide 986 - * the appropriate log prefix, we insert them here 889 + * The printf needs to come first; we need the syslog 890 + * prefix which might be passed-in as a parameter. 987 891 */ 988 - for (; *p; p++) { 989 - if (new_text_line) { 990 - new_text_line = 0; 892 + textlen = vscnprintf(text, sizeof(textbuf), fmt, args); 991 893 992 - if (plen) { 993 - /* Copy original log prefix */ 994 - int i; 894 + /* mark and strip a trailing newline */ 895 + if (textlen && text[textlen-1] == '\n') { 896 + textlen--; 897 + newline = true; 898 + } 995 899 996 - for (i = 0; i < plen; i++) 997 - emit_log_char(printk_buf[i]); 998 - printed_len += plen; 999 - } else { 1000 - /* Add log prefix */ 1001 - emit_log_char('<'); 1002 - emit_log_char(current_log_level + '0'); 1003 - emit_log_char('>'); 1004 - printed_len += 3; 1005 - } 1006 - 1007 - if (printk_time) { 1008 - /* Add the current time stamp */ 1009 - char tbuf[50], *tp; 1010 - unsigned tlen; 1011 - unsigned long long t; 1012 - unsigned long nanosec_rem; 1013 - 1014 - t = cpu_clock(printk_cpu); 1015 - nanosec_rem = do_div(t, 1000000000); 1016 - tlen = sprintf(tbuf, "[%5lu.%06lu] ", 1017 - (unsigned long) t, 1018 - nanosec_rem / 1000); 1019 - 1020 - for (tp = tbuf; tp < tbuf + tlen; tp++) 1021 - emit_log_char(*tp); 1022 - printed_len += tlen; 1023 - } 1024 - 1025 - if (!*p) 1026 - break; 900 + /* strip syslog prefix and extract log level or flags */ 901 + if (text[0] == '<' && text[1] && text[2] == '>') { 902 + switch (text[1]) { 903 + case '0' ... '7': 904 + if (level == -1) 905 + level = text[1] - '0'; 906 + text += 3; 907 + textlen -= 3; 908 + break; 909 + case 'c': /* KERN_CONT */ 910 + cont = true; 911 + case 'd': /* KERN_DEFAULT */ 912 + text += 3; 913 + textlen -= 3; 914 + break; 1027 915 } 916 + } 1028 917 1029 - emit_log_char(*p); 1030 - if (*p == '\n') 1031 - new_text_line = 1; 918 + if (buflen && (!cont || dict)) { 919 + /* no continuation; flush existing buffer */ 920 + log_store(facility, buflevel, NULL, 0, buf, buflen); 921 + printed_len += buflen; 922 + buflen = 0; 923 + } 924 + 925 + if (buflen == 0) { 926 + /* remember level for first message in the buffer */ 927 + if (level == -1) 928 + buflevel = default_message_loglevel; 929 + else 930 + buflevel = level; 931 + } 932 + 933 + if (buflen || !newline) { 934 + /* append to existing buffer, or buffer until next message */ 935 + if (buflen + textlen > sizeof(buf)) 936 + textlen = sizeof(buf) - buflen; 937 + memcpy(buf + buflen, text, textlen); 938 + buflen += textlen; 939 + } 940 + 941 + if (newline) { 942 + /* end of line; flush buffer */ 943 + if (buflen) { 944 + log_store(facility, buflevel, 945 + dict, dictlen, buf, buflen); 946 + printed_len += buflen; 947 + buflen = 0; 948 + } else { 949 + log_store(facility, buflevel, 950 + dict, dictlen, text, textlen); 951 + printed_len += textlen; 952 + } 1032 953 } 1033 954 1034 955 /* 1035 - * Try to acquire and then immediately release the 1036 - * console semaphore. The release will do all the 1037 - * actual magic (print out buffers, wake up klogd, 1038 - * etc). 956 + * Try to acquire and then immediately release the console semaphore. 957 + * The release will print out buffers and wake up /dev/kmsg and syslog() 958 + * users. 1039 959 * 1040 - * The console_trylock_for_printk() function 1041 - * will release 'logbuf_lock' regardless of whether it 1042 - * actually gets the semaphore or not. 960 + * The console_trylock_for_printk() function will release 'logbuf_lock' 961 + * regardless of whether it actually gets the console semaphore or not. 1043 962 */ 1044 963 if (console_trylock_for_printk(this_cpu)) 1045 964 console_unlock(); ··· 1045 974 1046 975 return printed_len; 1047 976 } 1048 - EXPORT_SYMBOL(printk); 977 + EXPORT_SYMBOL(vprintk_emit); 978 + 979 + asmlinkage int vprintk(const char *fmt, va_list args) 980 + { 981 + return vprintk_emit(0, -1, NULL, 0, fmt, args); 982 + } 1049 983 EXPORT_SYMBOL(vprintk); 1050 984 985 + asmlinkage int printk_emit(int facility, int level, 986 + const char *dict, size_t dictlen, 987 + const char *fmt, ...) 988 + { 989 + va_list args; 990 + int r; 991 + 992 + va_start(args, fmt); 993 + r = vprintk_emit(facility, level, dict, dictlen, fmt, args); 994 + va_end(args); 995 + 996 + return r; 997 + } 998 + EXPORT_SYMBOL(printk_emit); 999 + 1000 + /** 1001 + * printk - print a kernel message 1002 + * @fmt: format string 1003 + * 1004 + * This is printk(). It can be called from any context. We want it to work. 1005 + * 1006 + * We try to grab the console_lock. If we succeed, it's easy - we log the 1007 + * output and call the console drivers. If we fail to get the semaphore, we 1008 + * place the output into the log buffer and return. The current holder of 1009 + * the console_sem will notice the new output in console_unlock(); and will 1010 + * send it to the consoles before releasing the lock. 1011 + * 1012 + * One effect of this deferred printing is that code which calls printk() and 1013 + * then changes console_loglevel may break. This is because console_loglevel 1014 + * is inspected when the actual printing occurs. 1015 + * 1016 + * See also: 1017 + * printf(3) 1018 + * 1019 + * See the vsnprintf() documentation for format string extensions over C99. 1020 + */ 1021 + asmlinkage int printk(const char *fmt, ...) 1022 + { 1023 + va_list args; 1024 + int r; 1025 + 1026 + #ifdef CONFIG_KGDB_KDB 1027 + if (unlikely(kdb_trap_printk)) { 1028 + va_start(args, fmt); 1029 + r = vkdb_printf(fmt, args); 1030 + va_end(args); 1031 + return r; 1032 + } 1033 + #endif 1034 + va_start(args, fmt); 1035 + r = vprintk_emit(0, -1, NULL, 0, fmt, args); 1036 + va_end(args); 1037 + 1038 + return r; 1039 + } 1040 + EXPORT_SYMBOL(printk); 1051 1041 #else 1052 1042 1053 - static void call_console_drivers(unsigned start, unsigned end) 1043 + static void call_console_drivers(int level, const char *text, size_t len) 1054 1044 { 1055 1045 } 1056 1046 ··· 1349 1217 } 1350 1218 1351 1219 /* 1352 - * Delayed printk facility, for scheduler-internal messages: 1220 + * Delayed printk version, for scheduler-internal messages: 1353 1221 */ 1354 1222 #define PRINTK_BUF_SIZE 512 1355 1223 ··· 1385 1253 this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP); 1386 1254 } 1387 1255 1256 + /* the next printk record to write to the console */ 1257 + static u64 console_seq; 1258 + static u32 console_idx; 1259 + 1388 1260 /** 1389 1261 * console_unlock - unlock the console system 1390 1262 * ··· 1399 1263 * by printk(). If this is the case, console_unlock(); emits 1400 1264 * the output prior to releasing the lock. 1401 1265 * 1402 - * If there is output waiting for klogd, we wake it up. 1266 + * If there is output waiting, we wake it /dev/kmsg and syslog() users. 1403 1267 * 1404 1268 * console_unlock(); may be called from any context. 1405 1269 */ 1406 1270 void console_unlock(void) 1407 1271 { 1272 + static u64 seen_seq; 1408 1273 unsigned long flags; 1409 - unsigned _con_start, _log_end; 1410 - unsigned wake_klogd = 0, retry = 0; 1274 + bool wake_klogd = false; 1275 + bool retry; 1411 1276 1412 1277 if (console_suspended) { 1413 1278 up(&console_sem); ··· 1418 1281 console_may_schedule = 0; 1419 1282 1420 1283 again: 1421 - for ( ; ; ) { 1284 + for (;;) { 1285 + struct log *msg; 1286 + static char text[LOG_LINE_MAX]; 1287 + size_t len; 1288 + int level; 1289 + 1422 1290 raw_spin_lock_irqsave(&logbuf_lock, flags); 1423 - wake_klogd |= log_start - log_end; 1424 - if (con_start == log_end) 1425 - break; /* Nothing to print */ 1426 - _con_start = con_start; 1427 - _log_end = log_end; 1428 - con_start = log_end; /* Flush */ 1291 + if (seen_seq != log_next_seq) { 1292 + wake_klogd = true; 1293 + seen_seq = log_next_seq; 1294 + } 1295 + 1296 + if (console_seq < log_first_seq) { 1297 + /* messages are gone, move to first one */ 1298 + console_seq = log_first_seq; 1299 + console_idx = log_first_idx; 1300 + } 1301 + 1302 + if (console_seq == log_next_seq) 1303 + break; 1304 + 1305 + msg = log_from_idx(console_idx); 1306 + level = msg->level & 7; 1307 + len = msg->text_len; 1308 + if (len+1 >= sizeof(text)) 1309 + len = sizeof(text)-1; 1310 + memcpy(text, log_text(msg), len); 1311 + text[len++] = '\n'; 1312 + 1313 + console_idx = log_next(console_idx); 1314 + console_seq++; 1429 1315 raw_spin_unlock(&logbuf_lock); 1316 + 1430 1317 stop_critical_timings(); /* don't trace print latency */ 1431 - call_console_drivers(_con_start, _log_end); 1318 + call_console_drivers(level, text, len); 1432 1319 start_critical_timings(); 1433 1320 local_irq_restore(flags); 1434 1321 } ··· 1473 1312 * flush, no worries. 1474 1313 */ 1475 1314 raw_spin_lock(&logbuf_lock); 1476 - if (con_start != log_end) 1477 - retry = 1; 1315 + retry = console_seq != log_next_seq; 1478 1316 raw_spin_unlock_irqrestore(&logbuf_lock, flags); 1479 1317 1480 1318 if (retry && console_trylock()) ··· 1709 1549 * for us. 1710 1550 */ 1711 1551 raw_spin_lock_irqsave(&logbuf_lock, flags); 1712 - con_start = log_start; 1552 + console_seq = syslog_seq; 1553 + console_idx = syslog_idx; 1713 1554 raw_spin_unlock_irqrestore(&logbuf_lock, flags); 1714 1555 /* 1715 1556 * We're about to replay the log buffer. Only do this to the ··· 1919 1758 } 1920 1759 EXPORT_SYMBOL_GPL(kmsg_dump_unregister); 1921 1760 1761 + static bool always_kmsg_dump; 1762 + module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR); 1763 + 1922 1764 /** 1923 1765 * kmsg_dump - dump kernel log to kernel message dumpers. 1924 1766 * @reason: the reason (oops, panic etc) for dumping ··· 1931 1767 */ 1932 1768 void kmsg_dump(enum kmsg_dump_reason reason) 1933 1769 { 1934 - unsigned long end; 1935 - unsigned chars; 1770 + u64 idx; 1936 1771 struct kmsg_dumper *dumper; 1937 1772 const char *s1, *s2; 1938 1773 unsigned long l1, l2; ··· 1943 1780 /* Theoretically, the log could move on after we do this, but 1944 1781 there's not a lot we can do about that. The new messages 1945 1782 will overwrite the start of what we dump. */ 1783 + 1946 1784 raw_spin_lock_irqsave(&logbuf_lock, flags); 1947 - end = log_end & LOG_BUF_MASK; 1948 - chars = logged_chars; 1949 - raw_spin_unlock_irqrestore(&logbuf_lock, flags); 1785 + if (syslog_seq < log_first_seq) 1786 + idx = syslog_idx; 1787 + else 1788 + idx = log_first_idx; 1950 1789 1951 - if (chars > end) { 1952 - s1 = log_buf + log_buf_len - chars + end; 1953 - l1 = chars - end; 1790 + if (idx > log_next_idx) { 1791 + s1 = log_buf; 1792 + l1 = log_next_idx; 1954 1793 1955 - s2 = log_buf; 1956 - l2 = end; 1794 + s2 = log_buf + idx; 1795 + l2 = log_buf_len - idx; 1957 1796 } else { 1958 1797 s1 = ""; 1959 1798 l1 = 0; 1960 1799 1961 - s2 = log_buf + end - chars; 1962 - l2 = chars; 1800 + s2 = log_buf + idx; 1801 + l2 = log_next_idx - idx; 1963 1802 } 1803 + raw_spin_unlock_irqrestore(&logbuf_lock, flags); 1964 1804 1965 1805 rcu_read_lock(); 1966 1806 list_for_each_entry_rcu(dumper, &dump_list, list)