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

printk: kmsg_dump: remove _nolock() variants

kmsg_dump_rewind() and kmsg_dump_get_line() are lockless, so there is
no need for _nolock() variants. Remove these functions and switch all
callers of the _nolock() variants.

The functions without _nolock() were chosen because they are already
exported to kernel modules.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210303101528.29901-15-john.ogness@linutronix.de

authored by

John Ogness and committed by
Petr Mladek
a4f98765 996e9666

+14 -74
+2 -2
arch/powerpc/xmon/xmon.c
··· 3017 3017 catch_memory_errors = 1; 3018 3018 sync(); 3019 3019 3020 - kmsg_dump_rewind_nolock(&iter); 3020 + kmsg_dump_rewind(&iter); 3021 3021 xmon_start_pagination(); 3022 - while (kmsg_dump_get_line_nolock(&iter, false, buf, sizeof(buf), &len)) { 3022 + while (kmsg_dump_get_line(&iter, false, buf, sizeof(buf), &len)) { 3023 3023 buf[len] = '\0'; 3024 3024 printf("%s", buf); 3025 3025 }
-16
include/linux/kmsg_dump.h
··· 57 57 #ifdef CONFIG_PRINTK 58 58 void kmsg_dump(enum kmsg_dump_reason reason); 59 59 60 - bool kmsg_dump_get_line_nolock(struct kmsg_dump_iter *iter, bool syslog, 61 - char *line, size_t size, size_t *len); 62 - 63 60 bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, 64 61 char *line, size_t size, size_t *len); 65 62 66 63 bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog, 67 64 char *buf, size_t size, size_t *len_out); 68 - 69 - void kmsg_dump_rewind_nolock(struct kmsg_dump_iter *iter); 70 65 71 66 void kmsg_dump_rewind(struct kmsg_dump_iter *iter); 72 67 ··· 75 80 { 76 81 } 77 82 78 - static inline bool kmsg_dump_get_line_nolock(struct kmsg_dump_iter *iter, 79 - bool syslog, const char *line, 80 - size_t size, size_t *len) 81 - { 82 - return false; 83 - } 84 - 85 83 static inline bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, 86 84 const char *line, size_t size, size_t *len) 87 85 { ··· 85 97 char *buf, size_t size, size_t *len) 86 98 { 87 99 return false; 88 - } 89 - 90 - static inline void kmsg_dump_rewind_nolock(struct kmsg_dump_iter *iter) 91 - { 92 100 } 93 101 94 102 static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
+4 -4
kernel/debug/kdb/kdb_main.c
··· 2126 2126 kdb_set(2, setargs); 2127 2127 } 2128 2128 2129 - kmsg_dump_rewind_nolock(&iter); 2130 - while (kmsg_dump_get_line_nolock(&iter, 1, NULL, 0, NULL)) 2129 + kmsg_dump_rewind(&iter); 2130 + while (kmsg_dump_get_line(&iter, 1, NULL, 0, NULL)) 2131 2131 n++; 2132 2132 2133 2133 if (lines < 0) { ··· 2159 2159 if (skip >= n || skip < 0) 2160 2160 return 0; 2161 2161 2162 - kmsg_dump_rewind_nolock(&iter); 2163 - while (kmsg_dump_get_line_nolock(&iter, 1, buf, sizeof(buf), &len)) { 2162 + kmsg_dump_rewind(&iter); 2163 + while (kmsg_dump_get_line(&iter, 1, buf, sizeof(buf), &len)) { 2164 2164 if (skip) { 2165 2165 skip--; 2166 2166 continue;
+8 -52
kernel/printk/printk.c
··· 3373 3373 } 3374 3374 3375 3375 /** 3376 - * kmsg_dump_get_line_nolock - retrieve one kmsg log line (unlocked version) 3376 + * kmsg_dump_get_line - retrieve one kmsg log line 3377 3377 * @iter: kmsg dump iterator 3378 3378 * @syslog: include the "<4>" prefixes 3379 3379 * @line: buffer to copy the line to ··· 3388 3388 * 3389 3389 * A return value of FALSE indicates that there are no more records to 3390 3390 * read. 3391 - * 3392 - * The function is similar to kmsg_dump_get_line(), but grabs no locks. 3393 3391 */ 3394 - bool kmsg_dump_get_line_nolock(struct kmsg_dump_iter *iter, bool syslog, 3395 - char *line, size_t size, size_t *len) 3392 + bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, 3393 + char *line, size_t size, size_t *len) 3396 3394 { 3397 3395 u64 min_seq = latched_seq_read_nolock(&clear_seq); 3398 3396 struct printk_info info; 3399 3397 unsigned int line_count; 3400 3398 struct printk_record r; 3399 + unsigned long flags; 3401 3400 size_t l = 0; 3402 3401 bool ret = false; 3403 3402 3404 3403 if (iter->cur_seq < min_seq) 3405 3404 iter->cur_seq = min_seq; 3406 3405 3406 + printk_safe_enter_irqsave(flags); 3407 3407 prb_rec_init_rd(&r, &info, line, size); 3408 3408 3409 3409 /* Read text or count text lines? */ ··· 3424 3424 iter->cur_seq = r.info->seq + 1; 3425 3425 ret = true; 3426 3426 out: 3427 + printk_safe_exit_irqrestore(flags); 3427 3428 if (len) 3428 3429 *len = l; 3429 - return ret; 3430 - } 3431 - 3432 - /** 3433 - * kmsg_dump_get_line - retrieve one kmsg log line 3434 - * @iter: kmsg dump iterator 3435 - * @syslog: include the "<4>" prefixes 3436 - * @line: buffer to copy the line to 3437 - * @size: maximum size of the buffer 3438 - * @len: length of line placed into buffer 3439 - * 3440 - * Start at the beginning of the kmsg buffer, with the oldest kmsg 3441 - * record, and copy one record into the provided buffer. 3442 - * 3443 - * Consecutive calls will return the next available record moving 3444 - * towards the end of the buffer with the youngest messages. 3445 - * 3446 - * A return value of FALSE indicates that there are no more records to 3447 - * read. 3448 - */ 3449 - bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog, 3450 - char *line, size_t size, size_t *len) 3451 - { 3452 - unsigned long flags; 3453 - bool ret; 3454 - 3455 - printk_safe_enter_irqsave(flags); 3456 - ret = kmsg_dump_get_line_nolock(iter, syslog, line, size, len); 3457 - printk_safe_exit_irqrestore(flags); 3458 - 3459 3430 return ret; 3460 3431 } 3461 3432 EXPORT_SYMBOL_GPL(kmsg_dump_get_line); ··· 3522 3551 EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer); 3523 3552 3524 3553 /** 3525 - * kmsg_dump_rewind_nolock - reset the iterator (unlocked version) 3526 - * @iter: kmsg dump iterator 3527 - * 3528 - * Reset the dumper's iterator so that kmsg_dump_get_line() and 3529 - * kmsg_dump_get_buffer() can be called again and used multiple 3530 - * times within the same dumper.dump() callback. 3531 - * 3532 - * The function is similar to kmsg_dump_rewind(), but grabs no locks. 3533 - */ 3534 - void kmsg_dump_rewind_nolock(struct kmsg_dump_iter *iter) 3535 - { 3536 - iter->cur_seq = latched_seq_read_nolock(&clear_seq); 3537 - iter->next_seq = prb_next_seq(prb); 3538 - } 3539 - 3540 - /** 3541 3554 * kmsg_dump_rewind - reset the iterator 3542 3555 * @iter: kmsg dump iterator 3543 3556 * ··· 3534 3579 unsigned long flags; 3535 3580 3536 3581 printk_safe_enter_irqsave(flags); 3537 - kmsg_dump_rewind_nolock(iter); 3582 + iter->cur_seq = latched_seq_read_nolock(&clear_seq); 3583 + iter->next_seq = prb_next_seq(prb); 3538 3584 printk_safe_exit_irqrestore(flags); 3539 3585 } 3540 3586 EXPORT_SYMBOL_GPL(kmsg_dump_rewind);