Skip to content

Commit b520410

Browse files
committed
Merge tag 'printk-for-6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk updates from Petr Mladek: - Initialize pointer hashing using the system workqueue. It avoids taking locks in printk()/vsprintf() code path - Misc code clean up * tag 'printk-for-6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: printk: Mark __printk percpu data ready __ro_after_init printk: Remove bogus comment vs. boot consoles printk: Remove write only variable nr_ext_console_drivers printk: Declare log_wait properly printk: Make pr_flush() static lib/vsprintf: Initialize vsprintf's pointer hash once the random core is ready. lib/vsprintf: Remove static_branch_likely() from __ptr_to_hashval(). lib/vnsprintf: add const modifier for param 'bitmap'
2 parents adf4bfc + c77ae0b commit b520410

File tree

5 files changed

+35
-47
lines changed

5 files changed

+35
-47
lines changed

fs/proc/kmsg.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include <asm/io.h>
1919

20-
extern wait_queue_head_t log_wait;
21-
2220
static int kmsg_open(struct inode * inode, struct file * file)
2321
{
2422
return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC);

include/linux/printk.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ extern void __printk_safe_exit(void);
169169
#define printk_deferred_enter __printk_safe_enter
170170
#define printk_deferred_exit __printk_safe_exit
171171

172-
extern bool pr_flush(int timeout_ms, bool reset_on_progress);
173-
174172
/*
175173
* Please don't use printk_ratelimit(), because it shares ratelimiting state
176174
* with all other unrelated printk_ratelimit() callsites. Instead use
@@ -221,11 +219,6 @@ static inline void printk_deferred_exit(void)
221219
{
222220
}
223221

224-
static inline bool pr_flush(int timeout_ms, bool reset_on_progress)
225-
{
226-
return true;
227-
}
228-
229222
static inline int printk_ratelimit(void)
230223
{
231224
return 0;

include/linux/syslog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef _LINUX_SYSLOG_H
99
#define _LINUX_SYSLOG_H
1010

11+
#include <linux/wait.h>
12+
1113
/* Close the log. Currently a NOP. */
1214
#define SYSLOG_ACTION_CLOSE 0
1315
/* Open the log. Currently a NOP. */
@@ -35,5 +37,6 @@
3537
#define SYSLOG_FROM_PROC 1
3638

3739
int do_syslog(int type, char __user *buf, int count, int source);
40+
extern wait_queue_head_t log_wait;
3841

3942
#endif /* _LINUX_SYSLOG_H */

kernel/printk/printk.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write,
220220
}
221221
#endif /* CONFIG_PRINTK && CONFIG_SYSCTL */
222222

223-
/* Number of registered extended console drivers. */
224-
static int nr_ext_console_drivers;
225-
226223
/*
227224
* Helper macros to handle lockdep when locking/unlocking console_sem. We use
228225
* macros instead of functions so that _RET_IP_ contains useful information.
@@ -433,7 +430,7 @@ static struct printk_ringbuffer *prb = &printk_rb_static;
433430
* per_cpu_areas are initialised. This variable is set to true when
434431
* it's safe to access per-CPU data.
435432
*/
436-
static bool __printk_percpu_data_ready __read_mostly;
433+
static bool __printk_percpu_data_ready __ro_after_init;
437434

438435
bool printk_percpu_data_ready(void)
439436
{
@@ -2296,6 +2293,7 @@ asmlinkage __visible int _printk(const char *fmt, ...)
22962293
}
22972294
EXPORT_SYMBOL(_printk);
22982295

2296+
static bool pr_flush(int timeout_ms, bool reset_on_progress);
22992297
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress);
23002298

23012299
#else /* CONFIG_PRINTK */
@@ -2330,6 +2328,7 @@ static void call_console_driver(struct console *con, const char *text, size_t le
23302328
{
23312329
}
23322330
static bool suppress_message_printing(int level) { return false; }
2331+
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; }
23332332
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; }
23342333

23352334
#endif /* CONFIG_PRINTK */
@@ -3186,9 +3185,6 @@ void register_console(struct console *newcon)
31863185
console_drivers->next = newcon;
31873186
}
31883187

3189-
if (newcon->flags & CON_EXTENDED)
3190-
nr_ext_console_drivers++;
3191-
31923188
newcon->dropped = 0;
31933189
if (newcon->flags & CON_PRINTBUFFER) {
31943190
/* Get a consistent copy of @syslog_seq. */
@@ -3213,9 +3209,6 @@ void register_console(struct console *newcon)
32133209
if (bootcon_enabled &&
32143210
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
32153211
!keep_bootcon) {
3216-
/* We need to iterate through all boot consoles, to make
3217-
* sure we print everything out, before we unregister them.
3218-
*/
32193212
for_each_console(con)
32203213
if (con->flags & CON_BOOT)
32213214
unregister_console(con);
@@ -3254,9 +3247,6 @@ int unregister_console(struct console *console)
32543247
if (res)
32553248
goto out_disable_unlock;
32563249

3257-
if (console->flags & CON_EXTENDED)
3258-
nr_ext_console_drivers--;
3259-
32603250
/*
32613251
* If this isn't the last console and it has CON_CONSDEV set, we
32623252
* need to set it on the next preferred console.
@@ -3438,11 +3428,10 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
34383428
* Context: Process context. May sleep while acquiring console lock.
34393429
* Return: true if all enabled printers are caught up.
34403430
*/
3441-
bool pr_flush(int timeout_ms, bool reset_on_progress)
3431+
static bool pr_flush(int timeout_ms, bool reset_on_progress)
34423432
{
34433433
return __pr_flush(NULL, timeout_ms, reset_on_progress);
34443434
}
3445-
EXPORT_SYMBOL(pr_flush);
34463435

34473436
/*
34483437
* Delayed printk version, for scheduler-internal messages:

lib/vsprintf.c

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -750,37 +750,42 @@ static int __init debug_boot_weak_hash_enable(char *str)
750750
}
751751
early_param("debug_boot_weak_hash", debug_boot_weak_hash_enable);
752752

753-
static DEFINE_STATIC_KEY_FALSE(filled_random_ptr_key);
753+
static bool filled_random_ptr_key __read_mostly;
754+
static siphash_key_t ptr_key __read_mostly;
755+
static void fill_ptr_key_workfn(struct work_struct *work);
756+
static DECLARE_DELAYED_WORK(fill_ptr_key_work, fill_ptr_key_workfn);
754757

755-
static void enable_ptr_key_workfn(struct work_struct *work)
758+
static void fill_ptr_key_workfn(struct work_struct *work)
756759
{
757-
static_branch_enable(&filled_random_ptr_key);
760+
if (!rng_is_initialized()) {
761+
queue_delayed_work(system_unbound_wq, &fill_ptr_key_work, HZ * 2);
762+
return;
763+
}
764+
765+
get_random_bytes(&ptr_key, sizeof(ptr_key));
766+
767+
/* Pairs with smp_rmb() before reading ptr_key. */
768+
smp_wmb();
769+
WRITE_ONCE(filled_random_ptr_key, true);
770+
}
771+
772+
static int __init vsprintf_init_hashval(void)
773+
{
774+
fill_ptr_key_workfn(NULL);
775+
return 0;
758776
}
777+
subsys_initcall(vsprintf_init_hashval)
759778

760779
/* Maps a pointer to a 32 bit unique identifier. */
761780
static inline int __ptr_to_hashval(const void *ptr, unsigned long *hashval_out)
762781
{
763-
static siphash_key_t ptr_key __read_mostly;
764782
unsigned long hashval;
765783

766-
if (!static_branch_likely(&filled_random_ptr_key)) {
767-
static bool filled = false;
768-
static DEFINE_SPINLOCK(filling);
769-
static DECLARE_WORK(enable_ptr_key_work, enable_ptr_key_workfn);
770-
unsigned long flags;
771-
772-
if (!system_unbound_wq || !rng_is_initialized() ||
773-
!spin_trylock_irqsave(&filling, flags))
774-
return -EAGAIN;
775-
776-
if (!filled) {
777-
get_random_bytes(&ptr_key, sizeof(ptr_key));
778-
queue_work(system_unbound_wq, &enable_ptr_key_work);
779-
filled = true;
780-
}
781-
spin_unlock_irqrestore(&filling, flags);
782-
}
784+
if (!READ_ONCE(filled_random_ptr_key))
785+
return -EBUSY;
783786

787+
/* Pairs with smp_wmb() after writing ptr_key. */
788+
smp_rmb();
784789

785790
#ifdef CONFIG_64BIT
786791
hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key);
@@ -1189,7 +1194,7 @@ char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
11891194
}
11901195

11911196
static noinline_for_stack
1192-
char *bitmap_string(char *buf, char *end, unsigned long *bitmap,
1197+
char *bitmap_string(char *buf, char *end, const unsigned long *bitmap,
11931198
struct printf_spec spec, const char *fmt)
11941199
{
11951200
const int CHUNKSZ = 32;
@@ -1233,7 +1238,7 @@ char *bitmap_string(char *buf, char *end, unsigned long *bitmap,
12331238
}
12341239

12351240
static noinline_for_stack
1236-
char *bitmap_list_string(char *buf, char *end, unsigned long *bitmap,
1241+
char *bitmap_list_string(char *buf, char *end, const unsigned long *bitmap,
12371242
struct printf_spec spec, const char *fmt)
12381243
{
12391244
int nr_bits = max_t(int, spec.field_width, 0);

0 commit comments

Comments
 (0)