Skip to content

Commit 2ba3673

Browse files
jognesspmladek
authored andcommitted
printk: use atomic updates for klogd work
The per-cpu @printk_pending variable can be updated from sleepable contexts, such as: get_random_bytes() warn_unseeded_randomness() printk_deferred() defer_console_output() and can be updated from interrupt contexts, such as: handle_irq_event_percpu() __irq_wake_thread() wake_up_process() try_to_wake_up() select_task_rq() select_fallback_rq() printk_deferred() defer_console_output() and can be updated from NMI contexts, such as: vprintk() if (in_nmi()) defer_console_output() Therefore the atomic variant of the updating functions must be used. Replace __this_cpu_xchg() with this_cpu_xchg(). Replace __this_cpu_or() with this_cpu_or(). Reported-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: John Ogness <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a229327 commit 2ba3673

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/printk/printk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,7 @@ static DEFINE_PER_CPU(int, printk_pending);
32263226

32273227
static void wake_up_klogd_work_func(struct irq_work *irq_work)
32283228
{
3229-
int pending = __this_cpu_xchg(printk_pending, 0);
3229+
int pending = this_cpu_xchg(printk_pending, 0);
32303230

32313231
if (pending & PRINTK_PENDING_OUTPUT) {
32323232
/* If trylock fails, someone else is doing the printing */
@@ -3260,7 +3260,7 @@ void defer_console_output(void)
32603260
return;
32613261

32623262
preempt_disable();
3263-
__this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
3263+
this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT);
32643264
irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));
32653265
preempt_enable();
32663266
}

0 commit comments

Comments
 (0)