Lines 195-200
static int __init control_devkmsg(char *str)
Link Here
|
195 |
} |
195 |
} |
196 |
__setup("printk.devkmsg=", control_devkmsg); |
196 |
__setup("printk.devkmsg=", control_devkmsg); |
197 |
|
197 |
|
|
|
198 |
#if !defined(CONFIG_PREEMPT_RT) |
199 |
DEFINE_STATIC_KEY_FALSE(force_printkthreads_key); |
200 |
|
201 |
static int __init setup_forced_printkthreads(char *arg) |
202 |
{ |
203 |
static_branch_enable(&force_printkthreads_key); |
204 |
return 0; |
205 |
} |
206 |
early_param("threadprintk", setup_forced_printkthreads); |
207 |
#endif |
208 |
|
198 |
char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE] = "ratelimit"; |
209 |
char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE] = "ratelimit"; |
199 |
#if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) |
210 |
#if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) |
200 |
int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, |
211 |
int devkmsg_sysctl_set_loglvl(struct ctl_table *table, int write, |
Lines 282-287
EXPORT_SYMBOL(console_list_unlock);
Link Here
|
282 |
* Return: A cookie to pass to console_srcu_read_unlock(). |
293 |
* Return: A cookie to pass to console_srcu_read_unlock(). |
283 |
*/ |
294 |
*/ |
284 |
int console_srcu_read_lock(void) |
295 |
int console_srcu_read_lock(void) |
|
|
296 |
__acquires(&console_srcu) |
285 |
{ |
297 |
{ |
286 |
return srcu_read_lock_nmisafe(&console_srcu); |
298 |
return srcu_read_lock_nmisafe(&console_srcu); |
287 |
} |
299 |
} |
Lines 295-300
EXPORT_SYMBOL(console_srcu_read_lock);
Link Here
|
295 |
* Counterpart to console_srcu_read_lock() |
307 |
* Counterpart to console_srcu_read_lock() |
296 |
*/ |
308 |
*/ |
297 |
void console_srcu_read_unlock(int cookie) |
309 |
void console_srcu_read_unlock(int cookie) |
|
|
310 |
__releases(&console_srcu) |
298 |
{ |
311 |
{ |
299 |
srcu_read_unlock_nmisafe(&console_srcu, cookie); |
312 |
srcu_read_unlock_nmisafe(&console_srcu, cookie); |
300 |
} |
313 |
} |
Lines 461-474
static int console_msg_format = MSG_FORMAT_DEFAULT;
Link Here
|
461 |
/* syslog_lock protects syslog_* variables and write access to clear_seq. */ |
474 |
/* syslog_lock protects syslog_* variables and write access to clear_seq. */ |
462 |
static DEFINE_MUTEX(syslog_lock); |
475 |
static DEFINE_MUTEX(syslog_lock); |
463 |
|
476 |
|
464 |
#ifdef CONFIG_PRINTK |
|
|
465 |
/* |
477 |
/* |
466 |
* During panic, heavy printk by other CPUs can delay the |
478 |
* Specifies if a legacy console is registered. If legacy consoles are |
467 |
* panic and risk deadlock on console resources. |
479 |
* present, it is necessary to perform the console lock/unlock dance |
|
|
480 |
* whenever console flushing should occur. |
468 |
*/ |
481 |
*/ |
469 |
static int __read_mostly suppress_panic_printk; |
482 |
bool have_legacy_console; |
470 |
|
483 |
|
|
|
484 |
/* |
485 |
* Specifies if an nbcon console is registered. If nbcon consoles are present, |
486 |
* synchronous printing of legacy consoles will not occur during panic until |
487 |
* the backtrace has been stored to the ringbuffer. |
488 |
*/ |
489 |
static bool have_nbcon_console; |
490 |
|
491 |
/* |
492 |
* Specifies if a boot console is registered. If boot consoles are present, |
493 |
* nbcon consoles cannot print simultaneously and must be synchronized by |
494 |
* the console lock. This is because boot consoles and nbcon consoles may |
495 |
* have mapped the same hardware. |
496 |
*/ |
497 |
bool have_boot_console; |
498 |
|
499 |
#ifdef CONFIG_PRINTK |
471 |
DECLARE_WAIT_QUEUE_HEAD(log_wait); |
500 |
DECLARE_WAIT_QUEUE_HEAD(log_wait); |
|
|
501 |
|
502 |
static DECLARE_WAIT_QUEUE_HEAD(legacy_wait); |
503 |
|
472 |
/* All 3 protected by @syslog_lock. */ |
504 |
/* All 3 protected by @syslog_lock. */ |
473 |
/* the next printk record to read by syslog(READ) or /proc/kmsg */ |
505 |
/* the next printk record to read by syslog(READ) or /proc/kmsg */ |
474 |
static u64 syslog_seq; |
506 |
static u64 syslog_seq; |
Lines 1867-1873
static bool console_waiter;
Link Here
|
1867 |
* there may be a waiter spinning (like a spinlock). Also it must be |
1899 |
* there may be a waiter spinning (like a spinlock). Also it must be |
1868 |
* ready to hand over the lock at the end of the section. |
1900 |
* ready to hand over the lock at the end of the section. |
1869 |
*/ |
1901 |
*/ |
1870 |
static void console_lock_spinning_enable(void) |
1902 |
void console_lock_spinning_enable(void) |
1871 |
{ |
1903 |
{ |
1872 |
/* |
1904 |
/* |
1873 |
* Do not use spinning in panic(). The panic CPU wants to keep the lock. |
1905 |
* Do not use spinning in panic(). The panic CPU wants to keep the lock. |
Lines 1906-1912
static void console_lock_spinning_enable(void)
Link Here
|
1906 |
* |
1938 |
* |
1907 |
* Return: 1 if the lock rights were passed, 0 otherwise. |
1939 |
* Return: 1 if the lock rights were passed, 0 otherwise. |
1908 |
*/ |
1940 |
*/ |
1909 |
static int console_lock_spinning_disable_and_check(int cookie) |
1941 |
int console_lock_spinning_disable_and_check(int cookie) |
1910 |
{ |
1942 |
{ |
1911 |
int waiter; |
1943 |
int waiter; |
1912 |
|
1944 |
|
Lines 2311-2365
int vprintk_store(int facility, int level,
Link Here
|
2311 |
return ret; |
2343 |
return ret; |
2312 |
} |
2344 |
} |
2313 |
|
2345 |
|
|
|
2346 |
static bool legacy_allow_panic_sync; |
2347 |
|
2348 |
/* |
2349 |
* This acts as a one-way switch to allow legacy consoles to print from |
2350 |
* the printk() caller context on a panic CPU. It also attempts to flush |
2351 |
* the legacy consoles in this context. |
2352 |
*/ |
2353 |
void printk_legacy_allow_panic_sync(void) |
2354 |
{ |
2355 |
legacy_allow_panic_sync = true; |
2356 |
|
2357 |
if (printing_via_unlock && !in_nmi()) { |
2358 |
if (console_trylock()) |
2359 |
console_unlock(); |
2360 |
} |
2361 |
} |
2362 |
|
2314 |
asmlinkage int vprintk_emit(int facility, int level, |
2363 |
asmlinkage int vprintk_emit(int facility, int level, |
2315 |
const struct dev_printk_info *dev_info, |
2364 |
const struct dev_printk_info *dev_info, |
2316 |
const char *fmt, va_list args) |
2365 |
const char *fmt, va_list args) |
2317 |
{ |
2366 |
{ |
|
|
2367 |
bool do_trylock_unlock = printing_via_unlock && |
2368 |
!force_printkthreads(); |
2318 |
int printed_len; |
2369 |
int printed_len; |
2319 |
bool in_sched = false; |
|
|
2320 |
|
2370 |
|
2321 |
/* Suppress unimportant messages after panic happens */ |
2371 |
/* Suppress unimportant messages after panic happens */ |
2322 |
if (unlikely(suppress_printk)) |
2372 |
if (unlikely(suppress_printk)) |
2323 |
return 0; |
2373 |
return 0; |
2324 |
|
2374 |
|
2325 |
if (unlikely(suppress_panic_printk) && |
2375 |
/* |
2326 |
atomic_read(&panic_cpu) != raw_smp_processor_id()) |
2376 |
* The messages on the panic CPU are the most important. If |
|
|
2377 |
* non-panic CPUs are generating any messages, they will be |
2378 |
* silently dropped. |
2379 |
*/ |
2380 |
if (other_cpu_in_panic()) |
2327 |
return 0; |
2381 |
return 0; |
2328 |
|
2382 |
|
2329 |
if (level == LOGLEVEL_SCHED) { |
2383 |
if (level == LOGLEVEL_SCHED) { |
2330 |
level = LOGLEVEL_DEFAULT; |
2384 |
level = LOGLEVEL_DEFAULT; |
2331 |
in_sched = true; |
2385 |
/* If called from the scheduler, we can not call up(). */ |
|
|
2386 |
do_trylock_unlock = false; |
2332 |
} |
2387 |
} |
2333 |
|
2388 |
|
2334 |
printk_delay(level); |
2389 |
printk_delay(level); |
2335 |
|
2390 |
|
2336 |
printed_len = vprintk_store(facility, level, dev_info, fmt, args); |
2391 |
printed_len = vprintk_store(facility, level, dev_info, fmt, args); |
2337 |
|
2392 |
|
2338 |
/* If called from the scheduler, we can not call up(). */ |
2393 |
if (have_nbcon_console && !have_boot_console) { |
2339 |
if (!in_sched) { |
2394 |
bool is_panic_context = this_cpu_in_panic(); |
|
|
2395 |
|
2396 |
/* |
2397 |
* In panic, the legacy consoles are not allowed to print from |
2398 |
* the printk calling context unless explicitly allowed. This |
2399 |
* gives the safe nbcon consoles a chance to print out all the |
2400 |
* panic messages first. This restriction only applies if |
2401 |
* there are nbcon consoles registered. |
2402 |
*/ |
2403 |
if (is_panic_context) |
2404 |
do_trylock_unlock &= legacy_allow_panic_sync; |
2405 |
|
2406 |
/* |
2407 |
* There are situations where nbcon atomic printing should |
2408 |
* happen in the printk() caller context: |
2409 |
* |
2410 |
* - When this CPU is in panic. |
2411 |
* |
2412 |
* - When booting, before the printing threads have been |
2413 |
* started. |
2414 |
* |
2415 |
* - During shutdown, since the printing threads may not get |
2416 |
* a chance to print the final messages. |
2417 |
* |
2418 |
* Note that if boot consoles are registered, the console |
2419 |
* lock/unlock dance must be relied upon instead because nbcon |
2420 |
* consoles cannot print simultaneously with boot consoles. |
2421 |
*/ |
2422 |
if (is_panic_context || |
2423 |
!printk_threads_enabled || |
2424 |
(system_state > SYSTEM_RUNNING)) { |
2425 |
nbcon_atomic_flush_pending(); |
2426 |
} |
2427 |
} |
2428 |
|
2429 |
nbcon_wake_threads(); |
2430 |
|
2431 |
if (do_trylock_unlock) { |
2340 |
/* |
2432 |
/* |
2341 |
* The caller may be holding system-critical or |
2433 |
* The caller may be holding system-critical or |
2342 |
* timing-sensitive locks. Disable preemption during |
2434 |
* timing-sensitive locks. Disable preemption during |
2343 |
* printing of all remaining records to all consoles so that |
2435 |
* printing of all remaining records to all consoles so that |
2344 |
* this context can return as soon as possible. Hopefully |
2436 |
* this context can return as soon as possible. Hopefully |
2345 |
* another printk() caller will take over the printing. |
2437 |
* another printk() caller will take over the printing. |
|
|
2438 |
* |
2439 |
* Also, nbcon_get_default_prio() requires migration disabled. |
2346 |
*/ |
2440 |
*/ |
2347 |
preempt_disable(); |
2441 |
preempt_disable(); |
|
|
2442 |
|
2348 |
/* |
2443 |
/* |
2349 |
* Try to acquire and then immediately release the console |
2444 |
* Try to acquire and then immediately release the console |
2350 |
* semaphore. The release will print out buffers. With the |
2445 |
* semaphore. The release will print out buffers. With the |
2351 |
* spinning variant, this context tries to take over the |
2446 |
* spinning variant, this context tries to take over the |
2352 |
* printing from another printing context. |
2447 |
* printing from another printing context. |
|
|
2448 |
* |
2449 |
* Skip it in EMERGENCY priority. The console will be |
2450 |
* explicitly flushed when exiting the emergency section. |
2353 |
*/ |
2451 |
*/ |
2354 |
if (console_trylock_spinning()) |
2452 |
if (nbcon_get_default_prio() != NBCON_PRIO_EMERGENCY) { |
2355 |
console_unlock(); |
2453 |
if (console_trylock_spinning()) |
|
|
2454 |
console_unlock(); |
2455 |
} |
2456 |
|
2356 |
preempt_enable(); |
2457 |
preempt_enable(); |
2357 |
} |
2458 |
} |
2358 |
|
2459 |
|
2359 |
if (in_sched) |
2460 |
if (do_trylock_unlock) |
2360 |
defer_console_output(); |
|
|
2361 |
else |
2362 |
wake_up_klogd(); |
2461 |
wake_up_klogd(); |
|
|
2462 |
else |
2463 |
defer_console_output(); |
2363 |
|
2464 |
|
2364 |
return printed_len; |
2465 |
return printed_len; |
2365 |
} |
2466 |
} |
Lines 2387-2392
EXPORT_SYMBOL(_printk);
Link Here
|
2387 |
static bool pr_flush(int timeout_ms, bool reset_on_progress); |
2488 |
static bool pr_flush(int timeout_ms, bool reset_on_progress); |
2388 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress); |
2489 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress); |
2389 |
|
2490 |
|
|
|
2491 |
static struct task_struct *nbcon_legacy_kthread; |
2492 |
|
2493 |
static inline void wake_up_legacy_kthread(void) |
2494 |
{ |
2495 |
if (nbcon_legacy_kthread) |
2496 |
wake_up_interruptible(&legacy_wait); |
2497 |
} |
2498 |
|
2390 |
#else /* CONFIG_PRINTK */ |
2499 |
#else /* CONFIG_PRINTK */ |
2391 |
|
2500 |
|
2392 |
#define printk_time false |
2501 |
#define printk_time false |
Lines 2400-2405
static u64 syslog_seq;
Link Here
|
2400 |
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } |
2509 |
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } |
2401 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } |
2510 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } |
2402 |
|
2511 |
|
|
|
2512 |
static inline void nbcon_legacy_kthread_create(void) { } |
2513 |
static inline void wake_up_legacy_kthread(void) { } |
2403 |
#endif /* CONFIG_PRINTK */ |
2514 |
#endif /* CONFIG_PRINTK */ |
2404 |
|
2515 |
|
2405 |
#ifdef CONFIG_EARLY_PRINTK |
2516 |
#ifdef CONFIG_EARLY_PRINTK |
Lines 2615-2620
void suspend_console(void)
Link Here
|
2615 |
void resume_console(void) |
2726 |
void resume_console(void) |
2616 |
{ |
2727 |
{ |
2617 |
struct console *con; |
2728 |
struct console *con; |
|
|
2729 |
short flags; |
2730 |
int cookie; |
2618 |
|
2731 |
|
2619 |
if (!console_suspend_enabled) |
2732 |
if (!console_suspend_enabled) |
2620 |
return; |
2733 |
return; |
Lines 2631-2636
void resume_console(void)
Link Here
|
2631 |
*/ |
2744 |
*/ |
2632 |
synchronize_srcu(&console_srcu); |
2745 |
synchronize_srcu(&console_srcu); |
2633 |
|
2746 |
|
|
|
2747 |
/* |
2748 |
* Since this runs in task context, wake the threaded printers |
2749 |
* directly rather than scheduling irq_work to do it. |
2750 |
*/ |
2751 |
cookie = console_srcu_read_lock(); |
2752 |
for_each_console_srcu(con) { |
2753 |
flags = console_srcu_read_flags(con); |
2754 |
if (flags & CON_NBCON) |
2755 |
nbcon_kthread_wake(con); |
2756 |
} |
2757 |
console_srcu_read_unlock(cookie); |
2758 |
|
2759 |
wake_up_legacy_kthread(); |
2760 |
|
2634 |
pr_flush(1000, true); |
2761 |
pr_flush(1000, true); |
2635 |
} |
2762 |
} |
2636 |
|
2763 |
|
Lines 2645-2651
void resume_console(void)
Link Here
|
2645 |
*/ |
2772 |
*/ |
2646 |
static int console_cpu_notify(unsigned int cpu) |
2773 |
static int console_cpu_notify(unsigned int cpu) |
2647 |
{ |
2774 |
{ |
2648 |
if (!cpuhp_tasks_frozen) { |
2775 |
if (!cpuhp_tasks_frozen && printing_via_unlock && |
|
|
2776 |
!force_printkthreads()) { |
2649 |
/* If trylock fails, someone else is doing the printing */ |
2777 |
/* If trylock fails, someone else is doing the printing */ |
2650 |
if (console_trylock()) |
2778 |
if (console_trylock()) |
2651 |
console_unlock(); |
2779 |
console_unlock(); |
Lines 2702-2737
int is_console_locked(void)
Link Here
|
2702 |
} |
2830 |
} |
2703 |
EXPORT_SYMBOL(is_console_locked); |
2831 |
EXPORT_SYMBOL(is_console_locked); |
2704 |
|
2832 |
|
2705 |
/* |
|
|
2706 |
* Check if the given console is currently capable and allowed to print |
2707 |
* records. |
2708 |
* |
2709 |
* Requires the console_srcu_read_lock. |
2710 |
*/ |
2711 |
static inline bool console_is_usable(struct console *con) |
2712 |
{ |
2713 |
short flags = console_srcu_read_flags(con); |
2714 |
|
2715 |
if (!(flags & CON_ENABLED)) |
2716 |
return false; |
2717 |
|
2718 |
if ((flags & CON_SUSPENDED)) |
2719 |
return false; |
2720 |
|
2721 |
if (!con->write) |
2722 |
return false; |
2723 |
|
2724 |
/* |
2725 |
* Console drivers may assume that per-cpu resources have been |
2726 |
* allocated. So unless they're explicitly marked as being able to |
2727 |
* cope (CON_ANYTIME) don't call them until this CPU is officially up. |
2728 |
*/ |
2729 |
if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) |
2730 |
return false; |
2731 |
|
2732 |
return true; |
2733 |
} |
2734 |
|
2735 |
static void __console_unlock(void) |
2833 |
static void __console_unlock(void) |
2736 |
{ |
2834 |
{ |
2737 |
console_locked = 0; |
2835 |
console_locked = 0; |
Lines 2741-2770
static void __console_unlock(void)
Link Here
|
2741 |
#ifdef CONFIG_PRINTK |
2839 |
#ifdef CONFIG_PRINTK |
2742 |
|
2840 |
|
2743 |
/* |
2841 |
/* |
2744 |
* Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". This |
2842 |
* Prepend the message in @pmsg->pbufs->outbuf with the message in |
2745 |
* is achieved by shifting the existing message over and inserting the dropped |
2843 |
* @pmsg->pbufs->scratchbuf. This is achieved by shifting the existing message |
2746 |
* message. |
2844 |
* over and inserting the scratchbuf message. |
2747 |
* |
2845 |
* |
2748 |
* @pmsg is the printk message to prepend. |
2846 |
* @pmsg is the printk message to prepend. |
2749 |
* |
2847 |
* |
2750 |
* @dropped is the dropped count to report in the dropped message. |
2848 |
* @len is the length of the message in @pmsg->pbufs->scratchbuf. |
2751 |
* |
2849 |
* |
2752 |
* If the message text in @pmsg->pbufs->outbuf does not have enough space for |
2850 |
* If the message text in @pmsg->pbufs->outbuf does not have enough space for |
2753 |
* the dropped message, the message text will be sufficiently truncated. |
2851 |
* the scratchbuf message, the message text will be sufficiently truncated. |
2754 |
* |
2852 |
* |
2755 |
* If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. |
2853 |
* If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. |
2756 |
*/ |
2854 |
*/ |
2757 |
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) |
2855 |
static void __console_prepend_scratch(struct printk_message *pmsg, size_t len) |
2758 |
{ |
2856 |
{ |
2759 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2857 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2760 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
|
|
2761 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
2858 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
2762 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2859 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2763 |
char *outbuf = &pbufs->outbuf[0]; |
2860 |
char *outbuf = &pbufs->outbuf[0]; |
2764 |
size_t len; |
|
|
2765 |
|
2766 |
len = scnprintf(scratchbuf, scratchbuf_sz, |
2767 |
"** %lu printk messages dropped **\n", dropped); |
2768 |
|
2861 |
|
2769 |
/* |
2862 |
/* |
2770 |
* Make sure outbuf is sufficiently large before prepending. |
2863 |
* Make sure outbuf is sufficiently large before prepending. |
Lines 2786-2791
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped)
Link Here
|
2786 |
pmsg->outbuf_len += len; |
2879 |
pmsg->outbuf_len += len; |
2787 |
} |
2880 |
} |
2788 |
|
2881 |
|
|
|
2882 |
/* |
2883 |
* Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". |
2884 |
* @pmsg->outbuf_len is updated appropriately. |
2885 |
* |
2886 |
* @pmsg is the printk message to prepend. |
2887 |
* |
2888 |
* @dropped is the dropped count to report in the dropped message. |
2889 |
*/ |
2890 |
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) |
2891 |
{ |
2892 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2893 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2894 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2895 |
size_t len; |
2896 |
|
2897 |
len = scnprintf(scratchbuf, scratchbuf_sz, |
2898 |
"** %lu printk messages dropped **\n", dropped); |
2899 |
|
2900 |
__console_prepend_scratch(pmsg, len); |
2901 |
} |
2902 |
|
2903 |
/* |
2904 |
* Prepend the message in @pmsg->pbufs->outbuf with a "replay message". |
2905 |
* @pmsg->outbuf_len is updated appropriately. |
2906 |
* |
2907 |
* @pmsg is the printk message to prepend. |
2908 |
*/ |
2909 |
void console_prepend_replay(struct printk_message *pmsg) |
2910 |
{ |
2911 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2912 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2913 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2914 |
size_t len; |
2915 |
|
2916 |
len = scnprintf(scratchbuf, scratchbuf_sz, |
2917 |
"** replaying previous printk message **\n"); |
2918 |
|
2919 |
__console_prepend_scratch(pmsg, len); |
2920 |
} |
2921 |
|
2789 |
/* |
2922 |
/* |
2790 |
* Read and format the specified record (or a later record if the specified |
2923 |
* Read and format the specified record (or a later record if the specified |
2791 |
* record is not available). |
2924 |
* record is not available). |
Lines 2808-2815
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped)
Link Here
|
2808 |
bool printk_get_next_message(struct printk_message *pmsg, u64 seq, |
2941 |
bool printk_get_next_message(struct printk_message *pmsg, u64 seq, |
2809 |
bool is_extended, bool may_suppress) |
2942 |
bool is_extended, bool may_suppress) |
2810 |
{ |
2943 |
{ |
2811 |
static int panic_console_dropped; |
|
|
2812 |
|
2813 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2944 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2814 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2945 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2815 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
2946 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
Lines 2837-2853
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
Link Here
|
2837 |
pmsg->seq = r.info->seq; |
2968 |
pmsg->seq = r.info->seq; |
2838 |
pmsg->dropped = r.info->seq - seq; |
2969 |
pmsg->dropped = r.info->seq - seq; |
2839 |
|
2970 |
|
2840 |
/* |
|
|
2841 |
* Check for dropped messages in panic here so that printk |
2842 |
* suppression can occur as early as possible if necessary. |
2843 |
*/ |
2844 |
if (pmsg->dropped && |
2845 |
panic_in_progress() && |
2846 |
panic_console_dropped++ > 10) { |
2847 |
suppress_panic_printk = 1; |
2848 |
pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\n"); |
2849 |
} |
2850 |
|
2851 |
/* Skip record that has level above the console loglevel. */ |
2971 |
/* Skip record that has level above the console loglevel. */ |
2852 |
if (may_suppress && suppress_message_printing(r.info->level)) |
2972 |
if (may_suppress && suppress_message_printing(r.info->level)) |
2853 |
goto out; |
2973 |
goto out; |
Lines 2864-2869
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
Link Here
|
2864 |
return true; |
2984 |
return true; |
2865 |
} |
2985 |
} |
2866 |
|
2986 |
|
|
|
2987 |
/* |
2988 |
* Legacy console printing from printk() caller context does not respect |
2989 |
* raw_spinlock/spinlock nesting. For !PREEMPT_RT the lockdep warning is a |
2990 |
* false positive. For PREEMPT_RT the false positive condition does not |
2991 |
* occur. |
2992 |
* |
2993 |
* This map is used to establish LD_WAIT_SLEEP context for the console write |
2994 |
* callbacks when legacy printing to avoid false positive lockdep complaints, |
2995 |
* thus allowing lockdep to continue to function for real issues. |
2996 |
*/ |
2997 |
#ifdef CONFIG_PREEMPT_RT |
2998 |
static inline void printk_legacy_lock_map_acquire_try(void) { } |
2999 |
static inline void printk_legacy_lock_map_release(void) { } |
3000 |
#else |
3001 |
static DEFINE_WAIT_OVERRIDE_MAP(printk_legacy_map, LD_WAIT_SLEEP); |
3002 |
|
3003 |
static inline void printk_legacy_lock_map_acquire_try(void) |
3004 |
{ |
3005 |
lock_map_acquire_try(&printk_legacy_map); |
3006 |
} |
3007 |
|
3008 |
static inline void printk_legacy_lock_map_release(void) |
3009 |
{ |
3010 |
lock_map_release(&printk_legacy_map); |
3011 |
} |
3012 |
#endif /* CONFIG_PREEMPT_RT */ |
3013 |
|
2867 |
/* |
3014 |
/* |
2868 |
* Used as the printk buffers for non-panic, serialized console printing. |
3015 |
* Used as the printk buffers for non-panic, serialized console printing. |
2869 |
* This is for legacy (!CON_NBCON) as well as all boot (CON_BOOT) consoles. |
3016 |
* This is for legacy (!CON_NBCON) as well as all boot (CON_BOOT) consoles. |
Lines 2913-2943
static bool console_emit_next_record(struct console *con, bool *handover, int co
Link Here
|
2913 |
con->dropped = 0; |
3060 |
con->dropped = 0; |
2914 |
} |
3061 |
} |
2915 |
|
3062 |
|
2916 |
/* |
|
|
2917 |
* While actively printing out messages, if another printk() |
2918 |
* were to occur on another CPU, it may wait for this one to |
2919 |
* finish. This task can not be preempted if there is a |
2920 |
* waiter waiting to take over. |
2921 |
* |
2922 |
* Interrupts are disabled because the hand over to a waiter |
2923 |
* must not be interrupted until the hand over is completed |
2924 |
* (@console_waiter is cleared). |
2925 |
*/ |
2926 |
printk_safe_enter_irqsave(flags); |
2927 |
console_lock_spinning_enable(); |
2928 |
|
2929 |
/* Do not trace print latency. */ |
2930 |
stop_critical_timings(); |
2931 |
|
2932 |
/* Write everything out to the hardware. */ |
3063 |
/* Write everything out to the hardware. */ |
2933 |
con->write(con, outbuf, pmsg.outbuf_len); |
|
|
2934 |
|
3064 |
|
2935 |
start_critical_timings(); |
3065 |
if (force_printkthreads()) { |
|
|
3066 |
/* |
3067 |
* With forced threading this function is either in a thread |
3068 |
* or panic context. So there is no need for concern about |
3069 |
* printk reentrance, handovers, or lockdep complaints. |
3070 |
*/ |
2936 |
|
3071 |
|
2937 |
con->seq = pmsg.seq + 1; |
3072 |
con->write(con, outbuf, pmsg.outbuf_len); |
|
|
3073 |
con->seq = pmsg.seq + 1; |
3074 |
} else { |
3075 |
/* |
3076 |
* While actively printing out messages, if another printk() |
3077 |
* were to occur on another CPU, it may wait for this one to |
3078 |
* finish. This task can not be preempted if there is a |
3079 |
* waiter waiting to take over. |
3080 |
* |
3081 |
* Interrupts are disabled because the hand over to a waiter |
3082 |
* must not be interrupted until the hand over is completed |
3083 |
* (@console_waiter is cleared). |
3084 |
*/ |
3085 |
printk_safe_enter_irqsave(flags); |
3086 |
console_lock_spinning_enable(); |
2938 |
|
3087 |
|
2939 |
*handover = console_lock_spinning_disable_and_check(cookie); |
3088 |
/* Do not trace print latency. */ |
2940 |
printk_safe_exit_irqrestore(flags); |
3089 |
stop_critical_timings(); |
|
|
3090 |
|
3091 |
printk_legacy_lock_map_acquire_try(); |
3092 |
con->write(con, outbuf, pmsg.outbuf_len); |
3093 |
printk_legacy_lock_map_release(); |
3094 |
|
3095 |
start_critical_timings(); |
3096 |
|
3097 |
con->seq = pmsg.seq + 1; |
3098 |
|
3099 |
*handover = console_lock_spinning_disable_and_check(cookie); |
3100 |
printk_safe_exit_irqrestore(flags); |
3101 |
} |
2941 |
skip: |
3102 |
skip: |
2942 |
return true; |
3103 |
return true; |
2943 |
} |
3104 |
} |
Lines 2990-3002
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
2990 |
|
3151 |
|
2991 |
cookie = console_srcu_read_lock(); |
3152 |
cookie = console_srcu_read_lock(); |
2992 |
for_each_console_srcu(con) { |
3153 |
for_each_console_srcu(con) { |
|
|
3154 |
short flags = console_srcu_read_flags(con); |
3155 |
u64 printk_seq; |
2993 |
bool progress; |
3156 |
bool progress; |
2994 |
|
3157 |
|
2995 |
if (!console_is_usable(con)) |
3158 |
/* |
|
|
3159 |
* console_flush_all() is only for legacy consoles, |
3160 |
* unless the nbcon console has no kthread printer. |
3161 |
*/ |
3162 |
if ((flags & CON_NBCON) && con->kthread) |
3163 |
continue; |
3164 |
|
3165 |
if (!console_is_usable(con, flags, !do_cond_resched)) |
2996 |
continue; |
3166 |
continue; |
2997 |
any_usable = true; |
3167 |
any_usable = true; |
2998 |
|
3168 |
|
2999 |
progress = console_emit_next_record(con, handover, cookie); |
3169 |
if (flags & CON_NBCON) { |
|
|
3170 |
progress = nbcon_legacy_emit_next_record(con, handover, cookie, |
3171 |
!do_cond_resched); |
3172 |
printk_seq = nbcon_seq_read(con); |
3173 |
} else { |
3174 |
progress = console_emit_next_record(con, handover, cookie); |
3175 |
printk_seq = con->seq; |
3176 |
} |
3000 |
|
3177 |
|
3001 |
/* |
3178 |
/* |
3002 |
* If a handover has occurred, the SRCU read lock |
3179 |
* If a handover has occurred, the SRCU read lock |
Lines 3006-3013
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
3006 |
return false; |
3183 |
return false; |
3007 |
|
3184 |
|
3008 |
/* Track the next of the highest seq flushed. */ |
3185 |
/* Track the next of the highest seq flushed. */ |
3009 |
if (con->seq > *next_seq) |
3186 |
if (printk_seq > *next_seq) |
3010 |
*next_seq = con->seq; |
3187 |
*next_seq = printk_seq; |
3011 |
|
3188 |
|
3012 |
if (!progress) |
3189 |
if (!progress) |
3013 |
continue; |
3190 |
continue; |
Lines 3030-3048
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
3030 |
return false; |
3207 |
return false; |
3031 |
} |
3208 |
} |
3032 |
|
3209 |
|
3033 |
/** |
3210 |
static void console_flush_and_unlock(void) |
3034 |
* console_unlock - unblock the console subsystem from printing |
|
|
3035 |
* |
3036 |
* Releases the console_lock which the caller holds to block printing of |
3037 |
* the console subsystem. |
3038 |
* |
3039 |
* While the console_lock was held, console output may have been buffered |
3040 |
* by printk(). If this is the case, console_unlock(); emits |
3041 |
* the output prior to releasing the lock. |
3042 |
* |
3043 |
* console_unlock(); may be called from any context. |
3044 |
*/ |
3045 |
void console_unlock(void) |
3046 |
{ |
3211 |
{ |
3047 |
bool do_cond_resched; |
3212 |
bool do_cond_resched; |
3048 |
bool handover; |
3213 |
bool handover; |
Lines 3086-3091
void console_unlock(void)
Link Here
|
3086 |
*/ |
3251 |
*/ |
3087 |
} while (prb_read_valid(prb, next_seq, NULL) && console_trylock()); |
3252 |
} while (prb_read_valid(prb, next_seq, NULL) && console_trylock()); |
3088 |
} |
3253 |
} |
|
|
3254 |
|
3255 |
/** |
3256 |
* console_unlock - unblock the console subsystem from printing |
3257 |
* |
3258 |
* Releases the console_lock which the caller holds to block printing of |
3259 |
* the console subsystem. |
3260 |
* |
3261 |
* While the console_lock was held, console output may have been buffered |
3262 |
* by printk(). If this is the case, console_unlock(); emits |
3263 |
* the output prior to releasing the lock. |
3264 |
* |
3265 |
* console_unlock(); may be called from any context. |
3266 |
*/ |
3267 |
void console_unlock(void) |
3268 |
{ |
3269 |
/* |
3270 |
* Forced threading relies on kthread and atomic consoles for |
3271 |
* printing. It never attempts to print from console_unlock(). |
3272 |
*/ |
3273 |
if (force_printkthreads()) { |
3274 |
__console_unlock(); |
3275 |
return; |
3276 |
} |
3277 |
|
3278 |
console_flush_and_unlock(); |
3279 |
} |
3089 |
EXPORT_SYMBOL(console_unlock); |
3280 |
EXPORT_SYMBOL(console_unlock); |
3090 |
|
3281 |
|
3091 |
/** |
3282 |
/** |
Lines 3219-3225
void console_flush_on_panic(enum con_flush_mode mode)
Link Here
|
3219 |
console_srcu_read_unlock(cookie); |
3410 |
console_srcu_read_unlock(cookie); |
3220 |
} |
3411 |
} |
3221 |
|
3412 |
|
3222 |
console_flush_all(false, &next_seq, &handover); |
3413 |
nbcon_atomic_flush_pending(); |
|
|
3414 |
|
3415 |
if (printing_via_unlock) |
3416 |
console_flush_all(false, &next_seq, &handover); |
3223 |
} |
3417 |
} |
3224 |
|
3418 |
|
3225 |
/* |
3419 |
/* |
Lines 3276-3288
EXPORT_SYMBOL(console_stop);
Link Here
|
3276 |
|
3470 |
|
3277 |
void console_start(struct console *console) |
3471 |
void console_start(struct console *console) |
3278 |
{ |
3472 |
{ |
|
|
3473 |
short flags; |
3474 |
|
3279 |
console_list_lock(); |
3475 |
console_list_lock(); |
3280 |
console_srcu_write_flags(console, console->flags | CON_ENABLED); |
3476 |
console_srcu_write_flags(console, console->flags | CON_ENABLED); |
|
|
3477 |
flags = console->flags; |
3281 |
console_list_unlock(); |
3478 |
console_list_unlock(); |
|
|
3479 |
|
3480 |
/* |
3481 |
* Ensure that all SRCU list walks have completed. The related |
3482 |
* printing context must be able to see it is enabled so that |
3483 |
* it is guaranteed to wake up and resume printing. |
3484 |
*/ |
3485 |
synchronize_srcu(&console_srcu); |
3486 |
|
3487 |
if (flags & CON_NBCON) |
3488 |
nbcon_kthread_wake(console); |
3489 |
else |
3490 |
wake_up_legacy_kthread(); |
3491 |
|
3282 |
__pr_flush(console, 1000, true); |
3492 |
__pr_flush(console, 1000, true); |
3283 |
} |
3493 |
} |
3284 |
EXPORT_SYMBOL(console_start); |
3494 |
EXPORT_SYMBOL(console_start); |
3285 |
|
3495 |
|
|
|
3496 |
#ifdef CONFIG_PRINTK |
3497 |
static bool printer_should_wake(void) |
3498 |
{ |
3499 |
bool available = false; |
3500 |
struct console *con; |
3501 |
int cookie; |
3502 |
|
3503 |
if (kthread_should_stop()) |
3504 |
return true; |
3505 |
|
3506 |
cookie = console_srcu_read_lock(); |
3507 |
for_each_console_srcu(con) { |
3508 |
short flags = console_srcu_read_flags(con); |
3509 |
u64 printk_seq; |
3510 |
|
3511 |
/* |
3512 |
* The legacy printer thread is only for legacy consoles, |
3513 |
* unless the nbcon console has no kthread printer. |
3514 |
*/ |
3515 |
if ((flags & CON_NBCON) && con->kthread) |
3516 |
continue; |
3517 |
|
3518 |
if (!console_is_usable(con, flags, true)) |
3519 |
continue; |
3520 |
|
3521 |
if (flags & CON_NBCON) { |
3522 |
printk_seq = nbcon_seq_read(con); |
3523 |
} else { |
3524 |
/* |
3525 |
* It is safe to read @seq because only this |
3526 |
* thread context updates @seq. |
3527 |
*/ |
3528 |
printk_seq = con->seq; |
3529 |
} |
3530 |
|
3531 |
if (prb_read_valid(prb, printk_seq, NULL)) { |
3532 |
available = true; |
3533 |
break; |
3534 |
} |
3535 |
} |
3536 |
console_srcu_read_unlock(cookie); |
3537 |
|
3538 |
return available; |
3539 |
} |
3540 |
|
3541 |
static int nbcon_legacy_kthread_func(void *unused) |
3542 |
{ |
3543 |
int error; |
3544 |
|
3545 |
for (;;) { |
3546 |
error = wait_event_interruptible(legacy_wait, printer_should_wake()); |
3547 |
|
3548 |
if (kthread_should_stop()) |
3549 |
break; |
3550 |
|
3551 |
if (error) |
3552 |
continue; |
3553 |
|
3554 |
console_lock(); |
3555 |
console_flush_and_unlock(); |
3556 |
} |
3557 |
|
3558 |
return 0; |
3559 |
} |
3560 |
|
3561 |
void nbcon_legacy_kthread_create(void) |
3562 |
{ |
3563 |
struct task_struct *kt; |
3564 |
|
3565 |
lockdep_assert_held(&console_mutex); |
3566 |
|
3567 |
if (!force_printkthreads()) |
3568 |
return; |
3569 |
|
3570 |
if (!printk_threads_enabled || nbcon_legacy_kthread) |
3571 |
return; |
3572 |
|
3573 |
kt = kthread_run(nbcon_legacy_kthread_func, NULL, "pr/legacy"); |
3574 |
if (IS_ERR(kt)) { |
3575 |
pr_err("unable to start legacy printing thread\n"); |
3576 |
return; |
3577 |
} |
3578 |
|
3579 |
nbcon_legacy_kthread = kt; |
3580 |
|
3581 |
/* |
3582 |
* It is important that console printing threads are scheduled |
3583 |
* shortly after a printk call and with generous runtime budgets. |
3584 |
*/ |
3585 |
sched_set_normal(nbcon_legacy_kthread, -20); |
3586 |
} |
3587 |
#endif /* CONFIG_PRINTK */ |
3588 |
|
3286 |
static int __read_mostly keep_bootcon; |
3589 |
static int __read_mostly keep_bootcon; |
3287 |
|
3590 |
|
3288 |
static int __init keep_bootcon_setup(char *str) |
3591 |
static int __init keep_bootcon_setup(char *str) |
Lines 3366-3371
static void try_enable_default_console(struct console *newcon)
Link Here
|
3366 |
newcon->flags |= CON_CONSDEV; |
3669 |
newcon->flags |= CON_CONSDEV; |
3367 |
} |
3670 |
} |
3368 |
|
3671 |
|
|
|
3672 |
/* Set @newcon->seq to the first record this console should print. */ |
3369 |
static void console_init_seq(struct console *newcon, bool bootcon_registered) |
3673 |
static void console_init_seq(struct console *newcon, bool bootcon_registered) |
3370 |
{ |
3674 |
{ |
3371 |
struct console *con; |
3675 |
struct console *con; |
Lines 3414-3424
static void console_init_seq(struct console *newcon, bool bootcon_registered)
Link Here
|
3414 |
|
3718 |
|
3415 |
newcon->seq = prb_next_seq(prb); |
3719 |
newcon->seq = prb_next_seq(prb); |
3416 |
for_each_console(con) { |
3720 |
for_each_console(con) { |
3417 |
if ((con->flags & CON_BOOT) && |
3721 |
u64 seq; |
3418 |
(con->flags & CON_ENABLED) && |
3722 |
|
3419 |
con->seq < newcon->seq) { |
3723 |
if (!((con->flags & CON_BOOT) && |
3420 |
newcon->seq = con->seq; |
3724 |
(con->flags & CON_ENABLED))) { |
|
|
3725 |
continue; |
3421 |
} |
3726 |
} |
|
|
3727 |
|
3728 |
if (con->flags & CON_NBCON) |
3729 |
seq = nbcon_seq_read(con); |
3730 |
else |
3731 |
seq = con->seq; |
3732 |
|
3733 |
if (seq < newcon->seq) |
3734 |
newcon->seq = seq; |
3422 |
} |
3735 |
} |
3423 |
} |
3736 |
} |
3424 |
|
3737 |
|
Lines 3456-3461
void register_console(struct console *newcon)
Link Here
|
3456 |
struct console *con; |
3769 |
struct console *con; |
3457 |
bool bootcon_registered = false; |
3770 |
bool bootcon_registered = false; |
3458 |
bool realcon_registered = false; |
3771 |
bool realcon_registered = false; |
|
|
3772 |
unsigned long flags; |
3459 |
int err; |
3773 |
int err; |
3460 |
|
3774 |
|
3461 |
console_list_lock(); |
3775 |
console_list_lock(); |
Lines 3535-3543
void register_console(struct console *newcon)
Link Here
|
3535 |
newcon->dropped = 0; |
3849 |
newcon->dropped = 0; |
3536 |
console_init_seq(newcon, bootcon_registered); |
3850 |
console_init_seq(newcon, bootcon_registered); |
3537 |
|
3851 |
|
3538 |
if (newcon->flags & CON_NBCON) |
3852 |
if (newcon->flags & CON_NBCON) { |
|
|
3853 |
have_nbcon_console = true; |
3539 |
nbcon_init(newcon); |
3854 |
nbcon_init(newcon); |
3540 |
|
3855 |
|
|
|
3856 |
/* |
3857 |
* nbcon consoles have their own sequence counter. The legacy |
3858 |
* sequence counter is reset so that it is clear it is not |
3859 |
* being used. |
3860 |
*/ |
3861 |
nbcon_seq_force(newcon, newcon->seq); |
3862 |
newcon->seq = 0; |
3863 |
} else { |
3864 |
have_legacy_console = true; |
3865 |
nbcon_legacy_kthread_create(); |
3866 |
} |
3867 |
|
3868 |
if (newcon->flags & CON_BOOT) |
3869 |
have_boot_console = true; |
3870 |
|
3871 |
/* |
3872 |
* If another context is actively using the hardware of this new |
3873 |
* console, it will not be aware of the nbcon synchronization. This |
3874 |
* is a risk that two contexts could access the hardware |
3875 |
* simultaneously if this new console is used for atomic printing |
3876 |
* and the other context is still using the hardware. |
3877 |
* |
3878 |
* Use the driver synchronization to ensure that the hardware is not |
3879 |
* in use while this new console transitions to being registered. |
3880 |
*/ |
3881 |
if ((newcon->flags & CON_NBCON) && newcon->write_atomic) |
3882 |
newcon->device_lock(newcon, &flags); |
3883 |
|
3541 |
/* |
3884 |
/* |
3542 |
* Put this console in the list - keep the |
3885 |
* Put this console in the list - keep the |
3543 |
* preferred driver at the head of the list. |
3886 |
* preferred driver at the head of the list. |
Lines 3562-3567
void register_console(struct console *newcon)
Link Here
|
3562 |
* register_console() completes. |
3905 |
* register_console() completes. |
3563 |
*/ |
3906 |
*/ |
3564 |
|
3907 |
|
|
|
3908 |
/* This new console is now registered. */ |
3909 |
if ((newcon->flags & CON_NBCON) && newcon->write_atomic) |
3910 |
newcon->device_unlock(newcon, flags); |
3911 |
|
3565 |
console_sysfs_notify(); |
3912 |
console_sysfs_notify(); |
3566 |
|
3913 |
|
3567 |
/* |
3914 |
/* |
Lines 3590-3595
EXPORT_SYMBOL(register_console);
Link Here
|
3590 |
/* Must be called under console_list_lock(). */ |
3937 |
/* Must be called under console_list_lock(). */ |
3591 |
static int unregister_console_locked(struct console *console) |
3938 |
static int unregister_console_locked(struct console *console) |
3592 |
{ |
3939 |
{ |
|
|
3940 |
bool is_boot_con = (console->flags & CON_BOOT); |
3941 |
bool found_legacy_con = false; |
3942 |
bool found_nbcon_con = false; |
3943 |
bool found_boot_con = false; |
3944 |
struct console *c; |
3593 |
int res; |
3945 |
int res; |
3594 |
|
3946 |
|
3595 |
lockdep_assert_console_list_lock_held(); |
3947 |
lockdep_assert_console_list_lock_held(); |
Lines 3637-3642
static int unregister_console_locked(struct console *console)
Link Here
|
3637 |
if (console->exit) |
3989 |
if (console->exit) |
3638 |
res = console->exit(console); |
3990 |
res = console->exit(console); |
3639 |
|
3991 |
|
|
|
3992 |
/* |
3993 |
* With this console gone, the global flags tracking registered |
3994 |
* console types may have changed. Update them. |
3995 |
*/ |
3996 |
for_each_console(c) { |
3997 |
if (c->flags & CON_BOOT) |
3998 |
found_boot_con = true; |
3999 |
|
4000 |
if (c->flags & CON_NBCON) |
4001 |
found_nbcon_con = true; |
4002 |
else |
4003 |
found_legacy_con = true; |
4004 |
} |
4005 |
if (!found_boot_con) |
4006 |
have_boot_console = found_boot_con; |
4007 |
if (!found_legacy_con) |
4008 |
have_legacy_console = found_legacy_con; |
4009 |
if (!found_nbcon_con) |
4010 |
have_nbcon_console = found_nbcon_con; |
4011 |
|
4012 |
/* |
4013 |
* When the last boot console unregisters, start up the |
4014 |
* printing threads. |
4015 |
*/ |
4016 |
if (is_boot_con && !have_boot_console) { |
4017 |
for_each_console(c) |
4018 |
nbcon_kthread_create(c); |
4019 |
} |
4020 |
|
4021 |
#ifdef CONFIG_PRINTK |
4022 |
if (!printing_via_unlock && nbcon_legacy_kthread) { |
4023 |
kthread_stop(nbcon_legacy_kthread); |
4024 |
nbcon_legacy_kthread = NULL; |
4025 |
} |
4026 |
#endif |
4027 |
|
3640 |
return res; |
4028 |
return res; |
3641 |
} |
4029 |
} |
3642 |
|
4030 |
|
Lines 3795-3817
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3795 |
|
4183 |
|
3796 |
seq = prb_next_reserve_seq(prb); |
4184 |
seq = prb_next_reserve_seq(prb); |
3797 |
|
4185 |
|
3798 |
/* Flush the consoles so that records up to @seq are printed. */ |
4186 |
/* |
3799 |
console_lock(); |
4187 |
* Flush the consoles so that records up to @seq are printed. |
3800 |
console_unlock(); |
4188 |
* Otherwise this function will just wait for the threaded printers |
|
|
4189 |
* to print up to @seq. |
4190 |
*/ |
4191 |
if (printing_via_unlock && !force_printkthreads()) { |
4192 |
console_lock(); |
4193 |
console_unlock(); |
4194 |
} |
3801 |
|
4195 |
|
3802 |
for (;;) { |
4196 |
for (;;) { |
3803 |
unsigned long begin_jiffies; |
4197 |
unsigned long begin_jiffies; |
3804 |
unsigned long slept_jiffies; |
4198 |
unsigned long slept_jiffies; |
|
|
4199 |
bool use_console_lock = printing_via_unlock; |
4200 |
|
4201 |
/* |
4202 |
* Ensure the compiler does not optimize @use_console_lock to |
4203 |
* be @printing_via_unlock since the latter can change at any |
4204 |
* time. |
4205 |
*/ |
4206 |
barrier(); |
3805 |
|
4207 |
|
3806 |
diff = 0; |
4208 |
diff = 0; |
3807 |
|
4209 |
|
3808 |
/* |
4210 |
if (use_console_lock) { |
3809 |
* Hold the console_lock to guarantee safe access to |
4211 |
/* |
3810 |
* console->seq. Releasing console_lock flushes more |
4212 |
* Hold the console_lock to guarantee safe access to |
3811 |
* records in case @seq is still not printed on all |
4213 |
* console->seq. Releasing console_lock flushes more |
3812 |
* usable consoles. |
4214 |
* records in case @seq is still not printed on all |
3813 |
*/ |
4215 |
* usable consoles. |
3814 |
console_lock(); |
4216 |
*/ |
|
|
4217 |
console_lock(); |
4218 |
} |
3815 |
|
4219 |
|
3816 |
cookie = console_srcu_read_lock(); |
4220 |
cookie = console_srcu_read_lock(); |
3817 |
for_each_console_srcu(c) { |
4221 |
for_each_console_srcu(c) { |
Lines 3825-3836
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3825 |
* that they make forward progress, so only increment |
4229 |
* that they make forward progress, so only increment |
3826 |
* @diff for usable consoles. |
4230 |
* @diff for usable consoles. |
3827 |
*/ |
4231 |
*/ |
3828 |
if (!console_is_usable(c)) |
4232 |
if (!console_is_usable(c, flags, true) && |
|
|
4233 |
!console_is_usable(c, flags, false)) { |
3829 |
continue; |
4234 |
continue; |
|
|
4235 |
} |
3830 |
|
4236 |
|
3831 |
if (flags & CON_NBCON) { |
4237 |
if (flags & CON_NBCON) { |
3832 |
printk_seq = nbcon_seq_read(c); |
4238 |
printk_seq = nbcon_seq_read(c); |
3833 |
} else { |
4239 |
} else { |
|
|
4240 |
WARN_ON_ONCE(!use_console_lock); |
3834 |
printk_seq = c->seq; |
4241 |
printk_seq = c->seq; |
3835 |
} |
4242 |
} |
3836 |
|
4243 |
|
Lines 3842-3848
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3842 |
if (diff != last_diff && reset_on_progress) |
4249 |
if (diff != last_diff && reset_on_progress) |
3843 |
remaining_jiffies = timeout_jiffies; |
4250 |
remaining_jiffies = timeout_jiffies; |
3844 |
|
4251 |
|
3845 |
console_unlock(); |
4252 |
if (use_console_lock) |
|
|
4253 |
console_unlock(); |
3846 |
|
4254 |
|
3847 |
/* Note: @diff is 0 if there are no usable consoles. */ |
4255 |
/* Note: @diff is 0 if there are no usable consoles. */ |
3848 |
if (diff == 0 || remaining_jiffies == 0) |
4256 |
if (diff == 0 || remaining_jiffies == 0) |
Lines 3894-3902
static void wake_up_klogd_work_func(struct irq_work *irq_work)
Link Here
|
3894 |
int pending = this_cpu_xchg(printk_pending, 0); |
4302 |
int pending = this_cpu_xchg(printk_pending, 0); |
3895 |
|
4303 |
|
3896 |
if (pending & PRINTK_PENDING_OUTPUT) { |
4304 |
if (pending & PRINTK_PENDING_OUTPUT) { |
3897 |
/* If trylock fails, someone else is doing the printing */ |
4305 |
if (force_printkthreads()) { |
3898 |
if (console_trylock()) |
4306 |
wake_up_legacy_kthread(); |
3899 |
console_unlock(); |
4307 |
} else { |
|
|
4308 |
/* |
4309 |
* If trylock fails, some other context |
4310 |
* will do the printing. |
4311 |
*/ |
4312 |
if (console_trylock()) |
4313 |
console_unlock(); |
4314 |
} |
3900 |
} |
4315 |
} |
3901 |
|
4316 |
|
3902 |
if (pending & PRINTK_PENDING_WAKEUP) |
4317 |
if (pending & PRINTK_PENDING_WAKEUP) |
Lines 3912-3917
static void __wake_up_klogd(int val)
Link Here
|
3912 |
return; |
4327 |
return; |
3913 |
|
4328 |
|
3914 |
preempt_disable(); |
4329 |
preempt_disable(); |
|
|
4330 |
|
3915 |
/* |
4331 |
/* |
3916 |
* Guarantee any new records can be seen by tasks preparing to wait |
4332 |
* Guarantee any new records can be seen by tasks preparing to wait |
3917 |
* before this context checks if the wait queue is empty. |
4333 |
* before this context checks if the wait queue is empty. |
Lines 3923-3933
static void __wake_up_klogd(int val)
Link Here
|
3923 |
* |
4339 |
* |
3924 |
* This pairs with devkmsg_read:A and syslog_print:A. |
4340 |
* This pairs with devkmsg_read:A and syslog_print:A. |
3925 |
*/ |
4341 |
*/ |
3926 |
if (wq_has_sleeper(&log_wait) || /* LMM(__wake_up_klogd:A) */ |
4342 |
if (!wq_has_sleeper(&log_wait)) /* LMM(__wake_up_klogd:A) */ |
3927 |
(val & PRINTK_PENDING_OUTPUT)) { |
4343 |
val &= ~PRINTK_PENDING_WAKEUP; |
|
|
4344 |
|
4345 |
/* |
4346 |
* Simple read is safe. register_console() would flush a newly |
4347 |
* registered legacy console when writing the message about it |
4348 |
* being enabled. |
4349 |
*/ |
4350 |
if (!printing_via_unlock) |
4351 |
val &= ~PRINTK_PENDING_OUTPUT; |
4352 |
|
4353 |
if (val) { |
3928 |
this_cpu_or(printk_pending, val); |
4354 |
this_cpu_or(printk_pending, val); |
3929 |
irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); |
4355 |
irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); |
3930 |
} |
4356 |
} |
|
|
4357 |
|
3931 |
preempt_enable(); |
4358 |
preempt_enable(); |
3932 |
} |
4359 |
} |
3933 |
|
4360 |
|
Lines 3969-3974
void defer_console_output(void)
Link Here
|
3969 |
|
4396 |
|
3970 |
void printk_trigger_flush(void) |
4397 |
void printk_trigger_flush(void) |
3971 |
{ |
4398 |
{ |
|
|
4399 |
nbcon_wake_threads(); |
3972 |
defer_console_output(); |
4400 |
defer_console_output(); |
3973 |
} |
4401 |
} |
3974 |
|
4402 |
|