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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'printk-for-6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux

Pull printk updates from Petr Mladek:

- Prevent possible deadlocks, caused by the lock serializing per-CPU
backtraces, by entering the deferred printk context

- Enforce the right casting in LOG_BUF_LEN_MAX definition

* tag 'printk-for-6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux:
printk: Defer legacy printing when holding printk_cpu_sync
printk: Remove redundant deferred check in vprintk()
printk: Fix signed integer overflow when defining LOG_BUF_LEN_MAX

+18 -11
+6
kernel/printk/internal.h
··· 338 338 void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped); 339 339 void console_prepend_replay(struct printk_message *pmsg); 340 340 #endif 341 + 342 + #ifdef CONFIG_SMP 343 + bool is_printk_cpu_sync_owner(void); 344 + #else 345 + static inline bool is_printk_cpu_sync_owner(void) { return false; } 346 + #endif
+6 -1
kernel/printk/printk.c
··· 523 523 /* record buffer */ 524 524 #define LOG_ALIGN __alignof__(unsigned long) 525 525 #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) 526 - #define LOG_BUF_LEN_MAX (u32)(1 << 31) 526 + #define LOG_BUF_LEN_MAX ((u32)1 << 31) 527 527 static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN); 528 528 static char *log_buf = __log_buf; 529 529 static u32 log_buf_len = __LOG_BUF_LEN; ··· 4921 4921 #ifdef CONFIG_SMP 4922 4922 static atomic_t printk_cpu_sync_owner = ATOMIC_INIT(-1); 4923 4923 static atomic_t printk_cpu_sync_nested = ATOMIC_INIT(0); 4924 + 4925 + bool is_printk_cpu_sync_owner(void) 4926 + { 4927 + return (atomic_read(&printk_cpu_sync_owner) == raw_smp_processor_id()); 4928 + } 4924 4929 4925 4930 /** 4926 4931 * __printk_cpu_sync_wait() - Busy wait until the printk cpu-reentrant
+6 -10
kernel/printk/printk_safe.c
··· 61 61 /* 62 62 * The per-CPU variable @printk_context can be read safely in any 63 63 * context. CPU migration is always disabled when set. 64 + * 65 + * A context holding the printk_cpu_sync must not spin waiting for 66 + * another CPU. For legacy printing, it could be the console_lock 67 + * or the port lock. 64 68 */ 65 69 return (force_legacy_kthread() || 66 70 this_cpu_read(printk_context) || 67 - in_nmi()); 71 + in_nmi() || 72 + is_printk_cpu_sync_owner()); 68 73 } 69 74 70 75 asmlinkage int vprintk(const char *fmt, va_list args) ··· 79 74 if (unlikely(kdb_trap_printk && kdb_printf_cpu < 0)) 80 75 return vkdb_printf(KDB_MSGSRC_PRINTK, fmt, args); 81 76 #endif 82 - 83 - /* 84 - * Use the main logbuf even in NMI. But avoid calling console 85 - * drivers that might have their own locks. 86 - */ 87 - if (is_printk_legacy_deferred()) 88 - return vprintk_deferred(fmt, args); 89 - 90 - /* No obstacles. */ 91 77 return vprintk_default(fmt, args); 92 78 } 93 79 EXPORT_SYMBOL(vprintk);