Skip to content

Commit 8c4e93c

Browse files
pmladekKAGA-KOKO
authored andcommitted
printk: Prepare for nested printk_nmi_enter()
There is plenty of space in the printk_context variable. Reserve one byte there for the NMI context to be on the safe side. It should never overflow. The BUG_ON(in_nmi() == NMI_MASK) in nmi_enter() will trigger much earlier. Signed-off-by: Petr Mladek <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 1ed0948 commit 8c4e93c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

kernel/printk/internal.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
#ifdef CONFIG_PRINTK
88

9-
#define PRINTK_SAFE_CONTEXT_MASK 0x3fffffff
10-
#define PRINTK_NMI_DIRECT_CONTEXT_MASK 0x40000000
11-
#define PRINTK_NMI_CONTEXT_MASK 0x80000000
9+
#define PRINTK_SAFE_CONTEXT_MASK 0x007ffffff
10+
#define PRINTK_NMI_DIRECT_CONTEXT_MASK 0x008000000
11+
#define PRINTK_NMI_CONTEXT_MASK 0xff0000000
12+
13+
#define PRINTK_NMI_CONTEXT_OFFSET 0x010000000
1214

1315
extern raw_spinlock_t logbuf_lock;
1416

kernel/printk/printk_safe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ static __printf(1, 0) int vprintk_nmi(const char *fmt, va_list args)
295295

296296
void notrace printk_nmi_enter(void)
297297
{
298-
this_cpu_or(printk_context, PRINTK_NMI_CONTEXT_MASK);
298+
this_cpu_add(printk_context, PRINTK_NMI_CONTEXT_OFFSET);
299299
}
300300

301301
void notrace printk_nmi_exit(void)
302302
{
303-
this_cpu_and(printk_context, ~PRINTK_NMI_CONTEXT_MASK);
303+
this_cpu_sub(printk_context, PRINTK_NMI_CONTEXT_OFFSET);
304304
}
305305

306306
/*

0 commit comments

Comments
 (0)