Skip to content

Commit a4f9876

Browse files
jognesspmladek
authored andcommitted
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 <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 996e966 commit a4f9876

File tree

4 files changed

+14
-74
lines changed

4 files changed

+14
-74
lines changed

arch/powerpc/xmon/xmon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,9 +3017,9 @@ dump_log_buf(void)
30173017
catch_memory_errors = 1;
30183018
sync();
30193019

3020-
kmsg_dump_rewind_nolock(&iter);
3020+
kmsg_dump_rewind(&iter);
30213021
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)) {
30233023
buf[len] = '\0';
30243024
printf("%s", buf);
30253025
}

include/linux/kmsg_dump.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,12 @@ struct kmsg_dumper {
5757
#ifdef CONFIG_PRINTK
5858
void kmsg_dump(enum kmsg_dump_reason reason);
5959

60-
bool kmsg_dump_get_line_nolock(struct kmsg_dump_iter *iter, bool syslog,
61-
char *line, size_t size, size_t *len);
62-
6360
bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
6461
char *line, size_t size, size_t *len);
6562

6663
bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
6764
char *buf, size_t size, size_t *len_out);
6865

69-
void kmsg_dump_rewind_nolock(struct kmsg_dump_iter *iter);
70-
7166
void kmsg_dump_rewind(struct kmsg_dump_iter *iter);
7267

7368
int kmsg_dump_register(struct kmsg_dumper *dumper);
@@ -80,13 +75,6 @@ static inline void kmsg_dump(enum kmsg_dump_reason reason)
8075
{
8176
}
8277

83-
static inline bool kmsg_dump_get_line_nolock(struct kmsg_dump_iter *iter,
84-
bool syslog, const char *line,
85-
size_t size, size_t *len)
86-
{
87-
return false;
88-
}
89-
9078
static inline bool kmsg_dump_get_line(struct kmsg_dump_iter *iter, bool syslog,
9179
const char *line, size_t size, size_t *len)
9280
{
@@ -99,10 +87,6 @@ static inline bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog
9987
return false;
10088
}
10189

102-
static inline void kmsg_dump_rewind_nolock(struct kmsg_dump_iter *iter)
103-
{
104-
}
105-
10690
static inline void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
10791
{
10892
}

kernel/debug/kdb/kdb_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,8 +2126,8 @@ static int kdb_dmesg(int argc, const char **argv)
21262126
kdb_set(2, setargs);
21272127
}
21282128

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))
21312131
n++;
21322132

21332133
if (lines < 0) {
@@ -2159,8 +2159,8 @@ static int kdb_dmesg(int argc, const char **argv)
21592159
if (skip >= n || skip < 0)
21602160
return 0;
21612161

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)) {
21642164
if (skip) {
21652165
skip--;
21662166
continue;

kernel/printk/printk.c

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,7 +3373,7 @@ void kmsg_dump(enum kmsg_dump_reason reason)
33733373
}
33743374

33753375
/**
3376-
* kmsg_dump_get_line_nolock - retrieve one kmsg log line (unlocked version)
3376+
* kmsg_dump_get_line - retrieve one kmsg log line
33773377
* @iter: kmsg dump iterator
33783378
* @syslog: include the "<4>" prefixes
33793379
* @line: buffer to copy the line to
@@ -3388,22 +3388,22 @@ void kmsg_dump(enum kmsg_dump_reason reason)
33883388
*
33893389
* A return value of FALSE indicates that there are no more records to
33903390
* read.
3391-
*
3392-
* The function is similar to kmsg_dump_get_line(), but grabs no locks.
33933391
*/
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)
33963394
{
33973395
u64 min_seq = latched_seq_read_nolock(&clear_seq);
33983396
struct printk_info info;
33993397
unsigned int line_count;
34003398
struct printk_record r;
3399+
unsigned long flags;
34013400
size_t l = 0;
34023401
bool ret = false;
34033402

34043403
if (iter->cur_seq < min_seq)
34053404
iter->cur_seq = min_seq;
34063405

3406+
printk_safe_enter_irqsave(flags);
34073407
prb_rec_init_rd(&r, &info, line, size);
34083408

34093409
/* Read text or count text lines? */
@@ -3424,40 +3424,11 @@ bool kmsg_dump_get_line_nolock(struct kmsg_dump_iter *iter, bool syslog,
34243424
iter->cur_seq = r.info->seq + 1;
34253425
ret = true;
34263426
out:
3427+
printk_safe_exit_irqrestore(flags);
34273428
if (len)
34283429
*len = l;
34293430
return ret;
34303431
}
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-
return ret;
3460-
}
34613432
EXPORT_SYMBOL_GPL(kmsg_dump_get_line);
34623433

34633434
/**
@@ -3550,22 +3521,6 @@ bool kmsg_dump_get_buffer(struct kmsg_dump_iter *iter, bool syslog,
35503521
}
35513522
EXPORT_SYMBOL_GPL(kmsg_dump_get_buffer);
35523523

3553-
/**
3554-
* kmsg_dump_rewind_nolock - reset the iterator (unlocked version)
3555-
* @iter: kmsg dump iterator
3556-
*
3557-
* Reset the dumper's iterator so that kmsg_dump_get_line() and
3558-
* kmsg_dump_get_buffer() can be called again and used multiple
3559-
* times within the same dumper.dump() callback.
3560-
*
3561-
* The function is similar to kmsg_dump_rewind(), but grabs no locks.
3562-
*/
3563-
void kmsg_dump_rewind_nolock(struct kmsg_dump_iter *iter)
3564-
{
3565-
iter->cur_seq = latched_seq_read_nolock(&clear_seq);
3566-
iter->next_seq = prb_next_seq(prb);
3567-
}
3568-
35693524
/**
35703525
* kmsg_dump_rewind - reset the iterator
35713526
* @iter: kmsg dump iterator
@@ -3579,7 +3534,8 @@ void kmsg_dump_rewind(struct kmsg_dump_iter *iter)
35793534
unsigned long flags;
35803535

35813536
printk_safe_enter_irqsave(flags);
3582-
kmsg_dump_rewind_nolock(iter);
3537+
iter->cur_seq = latched_seq_read_nolock(&clear_seq);
3538+
iter->next_seq = prb_next_seq(prb);
35833539
printk_safe_exit_irqrestore(flags);
35843540
}
35853541
EXPORT_SYMBOL_GPL(kmsg_dump_rewind);

0 commit comments

Comments
 (0)