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-468
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 |
|
|
|
477 |
/* |
478 |
* Specifies if a legacy console is registered. If legacy consoles are |
479 |
* present, it is necessary to perform the console lock/unlock dance |
480 |
* whenever console flushing should occur. |
481 |
*/ |
482 |
bool have_legacy_console; |
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 |
|
464 |
#ifdef CONFIG_PRINTK |
499 |
#ifdef CONFIG_PRINTK |
465 |
DECLARE_WAIT_QUEUE_HEAD(log_wait); |
500 |
DECLARE_WAIT_QUEUE_HEAD(log_wait); |
|
|
501 |
|
502 |
static DECLARE_WAIT_QUEUE_HEAD(legacy_wait); |
503 |
|
466 |
/* All 3 protected by @syslog_lock. */ |
504 |
/* All 3 protected by @syslog_lock. */ |
467 |
/* 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 */ |
468 |
static u64 syslog_seq; |
506 |
static u64 syslog_seq; |
Lines 1850-1856
static bool console_waiter;
Link Here
|
1850 |
* there may be a waiter spinning (like a spinlock). Also it must be |
1888 |
* there may be a waiter spinning (like a spinlock). Also it must be |
1851 |
* ready to hand over the lock at the end of the section. |
1889 |
* ready to hand over the lock at the end of the section. |
1852 |
*/ |
1890 |
*/ |
1853 |
static void console_lock_spinning_enable(void) |
1891 |
void console_lock_spinning_enable(void) |
1854 |
{ |
1892 |
{ |
1855 |
/* |
1893 |
/* |
1856 |
* Do not use spinning in panic(). The panic CPU wants to keep the lock. |
1894 |
* Do not use spinning in panic(). The panic CPU wants to keep the lock. |
Lines 1889-1895
static void console_lock_spinning_enable(void)
Link Here
|
1889 |
* |
1927 |
* |
1890 |
* Return: 1 if the lock rights were passed, 0 otherwise. |
1928 |
* Return: 1 if the lock rights were passed, 0 otherwise. |
1891 |
*/ |
1929 |
*/ |
1892 |
static int console_lock_spinning_disable_and_check(int cookie) |
1930 |
int console_lock_spinning_disable_and_check(int cookie) |
1893 |
{ |
1931 |
{ |
1894 |
int waiter; |
1932 |
int waiter; |
1895 |
|
1933 |
|
Lines 2300-2311
int vprintk_store(int facility, int level,
Link Here
|
2300 |
return ret; |
2338 |
return ret; |
2301 |
} |
2339 |
} |
2302 |
|
2340 |
|
|
|
2341 |
static bool legacy_allow_panic_sync; |
2342 |
|
2343 |
/* |
2344 |
* This acts as a one-way switch to allow legacy consoles to print from |
2345 |
* the printk() caller context on a panic CPU. It also attempts to flush |
2346 |
* the legacy consoles in this context. |
2347 |
*/ |
2348 |
void printk_legacy_allow_panic_sync(void) |
2349 |
{ |
2350 |
legacy_allow_panic_sync = true; |
2351 |
|
2352 |
if (printing_via_unlock && !in_nmi()) { |
2353 |
if (console_trylock()) |
2354 |
console_unlock(); |
2355 |
} |
2356 |
} |
2357 |
|
2303 |
asmlinkage int vprintk_emit(int facility, int level, |
2358 |
asmlinkage int vprintk_emit(int facility, int level, |
2304 |
const struct dev_printk_info *dev_info, |
2359 |
const struct dev_printk_info *dev_info, |
2305 |
const char *fmt, va_list args) |
2360 |
const char *fmt, va_list args) |
2306 |
{ |
2361 |
{ |
|
|
2362 |
bool do_trylock_unlock = printing_via_unlock && |
2363 |
!force_printkthreads(); |
2307 |
int printed_len; |
2364 |
int printed_len; |
2308 |
bool in_sched = false; |
|
|
2309 |
|
2365 |
|
2310 |
/* Suppress unimportant messages after panic happens */ |
2366 |
/* Suppress unimportant messages after panic happens */ |
2311 |
if (unlikely(suppress_printk)) |
2367 |
if (unlikely(suppress_printk)) |
Lines 2321-2358
asmlinkage int vprintk_emit(int facility, int level,
Link Here
|
2321 |
|
2377 |
|
2322 |
if (level == LOGLEVEL_SCHED) { |
2378 |
if (level == LOGLEVEL_SCHED) { |
2323 |
level = LOGLEVEL_DEFAULT; |
2379 |
level = LOGLEVEL_DEFAULT; |
2324 |
in_sched = true; |
2380 |
/* If called from the scheduler, we can not call up(). */ |
|
|
2381 |
do_trylock_unlock = false; |
2325 |
} |
2382 |
} |
2326 |
|
2383 |
|
2327 |
printk_delay(level); |
2384 |
printk_delay(level); |
2328 |
|
2385 |
|
2329 |
printed_len = vprintk_store(facility, level, dev_info, fmt, args); |
2386 |
printed_len = vprintk_store(facility, level, dev_info, fmt, args); |
2330 |
|
2387 |
|
2331 |
/* If called from the scheduler, we can not call up(). */ |
2388 |
if (have_nbcon_console && !have_boot_console) { |
2332 |
if (!in_sched) { |
2389 |
bool is_panic_context = this_cpu_in_panic(); |
|
|
2390 |
|
2391 |
/* |
2392 |
* In panic, the legacy consoles are not allowed to print from |
2393 |
* the printk calling context unless explicitly allowed. This |
2394 |
* gives the safe nbcon consoles a chance to print out all the |
2395 |
* panic messages first. This restriction only applies if |
2396 |
* there are nbcon consoles registered. |
2397 |
*/ |
2398 |
if (is_panic_context) |
2399 |
do_trylock_unlock &= legacy_allow_panic_sync; |
2400 |
|
2401 |
/* |
2402 |
* There are situations where nbcon atomic printing should |
2403 |
* happen in the printk() caller context: |
2404 |
* |
2405 |
* - When this CPU is in panic. |
2406 |
* |
2407 |
* - When booting, before the printing threads have been |
2408 |
* started. |
2409 |
* |
2410 |
* - During shutdown, since the printing threads may not get |
2411 |
* a chance to print the final messages. |
2412 |
* |
2413 |
* Note that if boot consoles are registered, the console |
2414 |
* lock/unlock dance must be relied upon instead because nbcon |
2415 |
* consoles cannot print simultaneously with boot consoles. |
2416 |
*/ |
2417 |
if (is_panic_context || |
2418 |
!printk_threads_enabled || |
2419 |
(system_state > SYSTEM_RUNNING)) { |
2420 |
nbcon_atomic_flush_pending(); |
2421 |
} |
2422 |
} |
2423 |
|
2424 |
nbcon_wake_threads(); |
2425 |
|
2426 |
if (do_trylock_unlock) { |
2333 |
/* |
2427 |
/* |
2334 |
* The caller may be holding system-critical or |
2428 |
* The caller may be holding system-critical or |
2335 |
* timing-sensitive locks. Disable preemption during |
2429 |
* timing-sensitive locks. Disable preemption during |
2336 |
* printing of all remaining records to all consoles so that |
2430 |
* printing of all remaining records to all consoles so that |
2337 |
* this context can return as soon as possible. Hopefully |
2431 |
* this context can return as soon as possible. Hopefully |
2338 |
* another printk() caller will take over the printing. |
2432 |
* another printk() caller will take over the printing. |
|
|
2433 |
* |
2434 |
* Also, nbcon_get_default_prio() requires migration disabled. |
2339 |
*/ |
2435 |
*/ |
2340 |
preempt_disable(); |
2436 |
preempt_disable(); |
|
|
2437 |
|
2341 |
/* |
2438 |
/* |
2342 |
* Try to acquire and then immediately release the console |
2439 |
* Try to acquire and then immediately release the console |
2343 |
* semaphore. The release will print out buffers. With the |
2440 |
* semaphore. The release will print out buffers. With the |
2344 |
* spinning variant, this context tries to take over the |
2441 |
* spinning variant, this context tries to take over the |
2345 |
* printing from another printing context. |
2442 |
* printing from another printing context. |
|
|
2443 |
* |
2444 |
* Skip it in EMERGENCY priority. The console will be |
2445 |
* explicitly flushed when exiting the emergency section. |
2346 |
*/ |
2446 |
*/ |
2347 |
if (console_trylock_spinning()) |
2447 |
if (nbcon_get_default_prio() != NBCON_PRIO_EMERGENCY) { |
2348 |
console_unlock(); |
2448 |
if (console_trylock_spinning()) |
|
|
2449 |
console_unlock(); |
2450 |
} |
2451 |
|
2349 |
preempt_enable(); |
2452 |
preempt_enable(); |
2350 |
} |
2453 |
} |
2351 |
|
2454 |
|
2352 |
if (in_sched) |
2455 |
if (do_trylock_unlock) |
2353 |
defer_console_output(); |
|
|
2354 |
else |
2355 |
wake_up_klogd(); |
2456 |
wake_up_klogd(); |
|
|
2457 |
else |
2458 |
defer_console_output(); |
2356 |
|
2459 |
|
2357 |
return printed_len; |
2460 |
return printed_len; |
2358 |
} |
2461 |
} |
Lines 2380-2385
EXPORT_SYMBOL(_printk);
Link Here
|
2380 |
static bool pr_flush(int timeout_ms, bool reset_on_progress); |
2483 |
static bool pr_flush(int timeout_ms, bool reset_on_progress); |
2381 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress); |
2484 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress); |
2382 |
|
2485 |
|
|
|
2486 |
static struct task_struct *nbcon_legacy_kthread; |
2487 |
|
2488 |
static inline void wake_up_legacy_kthread(void) |
2489 |
{ |
2490 |
if (nbcon_legacy_kthread) |
2491 |
wake_up_interruptible(&legacy_wait); |
2492 |
} |
2493 |
|
2383 |
#else /* CONFIG_PRINTK */ |
2494 |
#else /* CONFIG_PRINTK */ |
2384 |
|
2495 |
|
2385 |
#define printk_time false |
2496 |
#define printk_time false |
Lines 2393-2398
static u64 syslog_seq;
Link Here
|
2393 |
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } |
2504 |
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } |
2394 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } |
2505 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } |
2395 |
|
2506 |
|
|
|
2507 |
static inline void nbcon_legacy_kthread_create(void) { } |
2508 |
static inline void wake_up_legacy_kthread(void) { } |
2396 |
#endif /* CONFIG_PRINTK */ |
2509 |
#endif /* CONFIG_PRINTK */ |
2397 |
|
2510 |
|
2398 |
#ifdef CONFIG_EARLY_PRINTK |
2511 |
#ifdef CONFIG_EARLY_PRINTK |
Lines 2608-2613
void suspend_console(void)
Link Here
|
2608 |
void resume_console(void) |
2721 |
void resume_console(void) |
2609 |
{ |
2722 |
{ |
2610 |
struct console *con; |
2723 |
struct console *con; |
|
|
2724 |
short flags; |
2725 |
int cookie; |
2611 |
|
2726 |
|
2612 |
if (!console_suspend_enabled) |
2727 |
if (!console_suspend_enabled) |
2613 |
return; |
2728 |
return; |
Lines 2624-2629
void resume_console(void)
Link Here
|
2624 |
*/ |
2739 |
*/ |
2625 |
synchronize_srcu(&console_srcu); |
2740 |
synchronize_srcu(&console_srcu); |
2626 |
|
2741 |
|
|
|
2742 |
/* |
2743 |
* Since this runs in task context, wake the threaded printers |
2744 |
* directly rather than scheduling irq_work to do it. |
2745 |
*/ |
2746 |
cookie = console_srcu_read_lock(); |
2747 |
for_each_console_srcu(con) { |
2748 |
flags = console_srcu_read_flags(con); |
2749 |
if (flags & CON_NBCON) |
2750 |
nbcon_kthread_wake(con); |
2751 |
} |
2752 |
console_srcu_read_unlock(cookie); |
2753 |
|
2754 |
wake_up_legacy_kthread(); |
2755 |
|
2627 |
pr_flush(1000, true); |
2756 |
pr_flush(1000, true); |
2628 |
} |
2757 |
} |
2629 |
|
2758 |
|
Lines 2638-2644
void resume_console(void)
Link Here
|
2638 |
*/ |
2767 |
*/ |
2639 |
static int console_cpu_notify(unsigned int cpu) |
2768 |
static int console_cpu_notify(unsigned int cpu) |
2640 |
{ |
2769 |
{ |
2641 |
if (!cpuhp_tasks_frozen) { |
2770 |
if (!cpuhp_tasks_frozen && printing_via_unlock && |
|
|
2771 |
!force_printkthreads()) { |
2642 |
/* If trylock fails, someone else is doing the printing */ |
2772 |
/* If trylock fails, someone else is doing the printing */ |
2643 |
if (console_trylock()) |
2773 |
if (console_trylock()) |
2644 |
console_unlock(); |
2774 |
console_unlock(); |
Lines 2695-2730
int is_console_locked(void)
Link Here
|
2695 |
} |
2825 |
} |
2696 |
EXPORT_SYMBOL(is_console_locked); |
2826 |
EXPORT_SYMBOL(is_console_locked); |
2697 |
|
2827 |
|
2698 |
/* |
|
|
2699 |
* Check if the given console is currently capable and allowed to print |
2700 |
* records. |
2701 |
* |
2702 |
* Requires the console_srcu_read_lock. |
2703 |
*/ |
2704 |
static inline bool console_is_usable(struct console *con) |
2705 |
{ |
2706 |
short flags = console_srcu_read_flags(con); |
2707 |
|
2708 |
if (!(flags & CON_ENABLED)) |
2709 |
return false; |
2710 |
|
2711 |
if ((flags & CON_SUSPENDED)) |
2712 |
return false; |
2713 |
|
2714 |
if (!con->write) |
2715 |
return false; |
2716 |
|
2717 |
/* |
2718 |
* Console drivers may assume that per-cpu resources have been |
2719 |
* allocated. So unless they're explicitly marked as being able to |
2720 |
* cope (CON_ANYTIME) don't call them until this CPU is officially up. |
2721 |
*/ |
2722 |
if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) |
2723 |
return false; |
2724 |
|
2725 |
return true; |
2726 |
} |
2727 |
|
2728 |
static void __console_unlock(void) |
2828 |
static void __console_unlock(void) |
2729 |
{ |
2829 |
{ |
2730 |
console_locked = 0; |
2830 |
console_locked = 0; |
Lines 2734-2763
static void __console_unlock(void)
Link Here
|
2734 |
#ifdef CONFIG_PRINTK |
2834 |
#ifdef CONFIG_PRINTK |
2735 |
|
2835 |
|
2736 |
/* |
2836 |
/* |
2737 |
* Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". This |
2837 |
* Prepend the message in @pmsg->pbufs->outbuf with the message in |
2738 |
* is achieved by shifting the existing message over and inserting the dropped |
2838 |
* @pmsg->pbufs->scratchbuf. This is achieved by shifting the existing message |
2739 |
* message. |
2839 |
* over and inserting the scratchbuf message. |
2740 |
* |
2840 |
* |
2741 |
* @pmsg is the printk message to prepend. |
2841 |
* @pmsg is the printk message to prepend. |
2742 |
* |
2842 |
* |
2743 |
* @dropped is the dropped count to report in the dropped message. |
2843 |
* @len is the length of the message in @pmsg->pbufs->scratchbuf. |
2744 |
* |
2844 |
* |
2745 |
* If the message text in @pmsg->pbufs->outbuf does not have enough space for |
2845 |
* If the message text in @pmsg->pbufs->outbuf does not have enough space for |
2746 |
* the dropped message, the message text will be sufficiently truncated. |
2846 |
* the scratchbuf message, the message text will be sufficiently truncated. |
2747 |
* |
2847 |
* |
2748 |
* If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. |
2848 |
* If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. |
2749 |
*/ |
2849 |
*/ |
2750 |
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) |
2850 |
static void __console_prepend_scratch(struct printk_message *pmsg, size_t len) |
2751 |
{ |
2851 |
{ |
2752 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2852 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2753 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
|
|
2754 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
2853 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
2755 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2854 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2756 |
char *outbuf = &pbufs->outbuf[0]; |
2855 |
char *outbuf = &pbufs->outbuf[0]; |
2757 |
size_t len; |
|
|
2758 |
|
2759 |
len = scnprintf(scratchbuf, scratchbuf_sz, |
2760 |
"** %lu printk messages dropped **\n", dropped); |
2761 |
|
2856 |
|
2762 |
/* |
2857 |
/* |
2763 |
* Make sure outbuf is sufficiently large before prepending. |
2858 |
* Make sure outbuf is sufficiently large before prepending. |
Lines 2779-2784
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped)
Link Here
|
2779 |
pmsg->outbuf_len += len; |
2874 |
pmsg->outbuf_len += len; |
2780 |
} |
2875 |
} |
2781 |
|
2876 |
|
|
|
2877 |
/* |
2878 |
* Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". |
2879 |
* @pmsg->outbuf_len is updated appropriately. |
2880 |
* |
2881 |
* @pmsg is the printk message to prepend. |
2882 |
* |
2883 |
* @dropped is the dropped count to report in the dropped message. |
2884 |
*/ |
2885 |
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) |
2886 |
{ |
2887 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2888 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2889 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2890 |
size_t len; |
2891 |
|
2892 |
len = scnprintf(scratchbuf, scratchbuf_sz, |
2893 |
"** %lu printk messages dropped **\n", dropped); |
2894 |
|
2895 |
__console_prepend_scratch(pmsg, len); |
2896 |
} |
2897 |
|
2898 |
/* |
2899 |
* Prepend the message in @pmsg->pbufs->outbuf with a "replay message". |
2900 |
* @pmsg->outbuf_len is updated appropriately. |
2901 |
* |
2902 |
* @pmsg is the printk message to prepend. |
2903 |
*/ |
2904 |
void console_prepend_replay(struct printk_message *pmsg) |
2905 |
{ |
2906 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2907 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2908 |
char *scratchbuf = &pbufs->scratchbuf[0]; |
2909 |
size_t len; |
2910 |
|
2911 |
len = scnprintf(scratchbuf, scratchbuf_sz, |
2912 |
"** replaying previous printk message **\n"); |
2913 |
|
2914 |
__console_prepend_scratch(pmsg, len); |
2915 |
} |
2916 |
|
2782 |
/* |
2917 |
/* |
2783 |
* Read and format the specified record (or a later record if the specified |
2918 |
* Read and format the specified record (or a later record if the specified |
2784 |
* record is not available). |
2919 |
* record is not available). |
Lines 2844-2849
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
Link Here
|
2844 |
return true; |
2979 |
return true; |
2845 |
} |
2980 |
} |
2846 |
|
2981 |
|
|
|
2982 |
/* |
2983 |
* Legacy console printing from printk() caller context does not respect |
2984 |
* raw_spinlock/spinlock nesting. For !PREEMPT_RT the lockdep warning is a |
2985 |
* false positive. For PREEMPT_RT the false positive condition does not |
2986 |
* occur. |
2987 |
* |
2988 |
* This map is used to establish LD_WAIT_SLEEP context for the console write |
2989 |
* callbacks when legacy printing to avoid false positive lockdep complaints, |
2990 |
* thus allowing lockdep to continue to function for real issues. |
2991 |
*/ |
2992 |
#ifdef CONFIG_PREEMPT_RT |
2993 |
static inline void printk_legacy_lock_map_acquire_try(void) { } |
2994 |
static inline void printk_legacy_lock_map_release(void) { } |
2995 |
#else |
2996 |
static DEFINE_WAIT_OVERRIDE_MAP(printk_legacy_map, LD_WAIT_SLEEP); |
2997 |
|
2998 |
static inline void printk_legacy_lock_map_acquire_try(void) |
2999 |
{ |
3000 |
lock_map_acquire_try(&printk_legacy_map); |
3001 |
} |
3002 |
|
3003 |
static inline void printk_legacy_lock_map_release(void) |
3004 |
{ |
3005 |
lock_map_release(&printk_legacy_map); |
3006 |
} |
3007 |
#endif /* CONFIG_PREEMPT_RT */ |
3008 |
|
2847 |
/* |
3009 |
/* |
2848 |
* Used as the printk buffers for non-panic, serialized console printing. |
3010 |
* Used as the printk buffers for non-panic, serialized console printing. |
2849 |
* This is for legacy (!CON_NBCON) as well as all boot (CON_BOOT) consoles. |
3011 |
* This is for legacy (!CON_NBCON) as well as all boot (CON_BOOT) consoles. |
Lines 2893-2923
static bool console_emit_next_record(struct console *con, bool *handover, int co
Link Here
|
2893 |
con->dropped = 0; |
3055 |
con->dropped = 0; |
2894 |
} |
3056 |
} |
2895 |
|
3057 |
|
2896 |
/* |
|
|
2897 |
* While actively printing out messages, if another printk() |
2898 |
* were to occur on another CPU, it may wait for this one to |
2899 |
* finish. This task can not be preempted if there is a |
2900 |
* waiter waiting to take over. |
2901 |
* |
2902 |
* Interrupts are disabled because the hand over to a waiter |
2903 |
* must not be interrupted until the hand over is completed |
2904 |
* (@console_waiter is cleared). |
2905 |
*/ |
2906 |
printk_safe_enter_irqsave(flags); |
2907 |
console_lock_spinning_enable(); |
2908 |
|
2909 |
/* Do not trace print latency. */ |
2910 |
stop_critical_timings(); |
2911 |
|
2912 |
/* Write everything out to the hardware. */ |
3058 |
/* Write everything out to the hardware. */ |
2913 |
con->write(con, outbuf, pmsg.outbuf_len); |
|
|
2914 |
|
3059 |
|
2915 |
start_critical_timings(); |
3060 |
if (force_printkthreads()) { |
|
|
3061 |
/* |
3062 |
* With forced threading this function is either in a thread |
3063 |
* or panic context. So there is no need for concern about |
3064 |
* printk reentrance, handovers, or lockdep complaints. |
3065 |
*/ |
2916 |
|
3066 |
|
2917 |
con->seq = pmsg.seq + 1; |
3067 |
con->write(con, outbuf, pmsg.outbuf_len); |
|
|
3068 |
con->seq = pmsg.seq + 1; |
3069 |
} else { |
3070 |
/* |
3071 |
* While actively printing out messages, if another printk() |
3072 |
* were to occur on another CPU, it may wait for this one to |
3073 |
* finish. This task can not be preempted if there is a |
3074 |
* waiter waiting to take over. |
3075 |
* |
3076 |
* Interrupts are disabled because the hand over to a waiter |
3077 |
* must not be interrupted until the hand over is completed |
3078 |
* (@console_waiter is cleared). |
3079 |
*/ |
3080 |
printk_safe_enter_irqsave(flags); |
3081 |
console_lock_spinning_enable(); |
2918 |
|
3082 |
|
2919 |
*handover = console_lock_spinning_disable_and_check(cookie); |
3083 |
/* Do not trace print latency. */ |
2920 |
printk_safe_exit_irqrestore(flags); |
3084 |
stop_critical_timings(); |
|
|
3085 |
|
3086 |
printk_legacy_lock_map_acquire_try(); |
3087 |
con->write(con, outbuf, pmsg.outbuf_len); |
3088 |
printk_legacy_lock_map_release(); |
3089 |
|
3090 |
start_critical_timings(); |
3091 |
|
3092 |
con->seq = pmsg.seq + 1; |
3093 |
|
3094 |
*handover = console_lock_spinning_disable_and_check(cookie); |
3095 |
printk_safe_exit_irqrestore(flags); |
3096 |
} |
2921 |
skip: |
3097 |
skip: |
2922 |
return true; |
3098 |
return true; |
2923 |
} |
3099 |
} |
Lines 2970-2982
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
2970 |
|
3146 |
|
2971 |
cookie = console_srcu_read_lock(); |
3147 |
cookie = console_srcu_read_lock(); |
2972 |
for_each_console_srcu(con) { |
3148 |
for_each_console_srcu(con) { |
|
|
3149 |
short flags = console_srcu_read_flags(con); |
3150 |
u64 printk_seq; |
2973 |
bool progress; |
3151 |
bool progress; |
2974 |
|
3152 |
|
2975 |
if (!console_is_usable(con)) |
3153 |
/* |
|
|
3154 |
* console_flush_all() is only for legacy consoles, |
3155 |
* unless the nbcon console has no kthread printer. |
3156 |
*/ |
3157 |
if ((flags & CON_NBCON) && con->kthread) |
3158 |
continue; |
3159 |
|
3160 |
if (!console_is_usable(con, flags, !do_cond_resched)) |
2976 |
continue; |
3161 |
continue; |
2977 |
any_usable = true; |
3162 |
any_usable = true; |
2978 |
|
3163 |
|
2979 |
progress = console_emit_next_record(con, handover, cookie); |
3164 |
if (flags & CON_NBCON) { |
|
|
3165 |
progress = nbcon_legacy_emit_next_record(con, handover, cookie, |
3166 |
!do_cond_resched); |
3167 |
printk_seq = nbcon_seq_read(con); |
3168 |
} else { |
3169 |
progress = console_emit_next_record(con, handover, cookie); |
3170 |
printk_seq = con->seq; |
3171 |
} |
2980 |
|
3172 |
|
2981 |
/* |
3173 |
/* |
2982 |
* If a handover has occurred, the SRCU read lock |
3174 |
* If a handover has occurred, the SRCU read lock |
Lines 2986-2993
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
2986 |
return false; |
3178 |
return false; |
2987 |
|
3179 |
|
2988 |
/* Track the next of the highest seq flushed. */ |
3180 |
/* Track the next of the highest seq flushed. */ |
2989 |
if (con->seq > *next_seq) |
3181 |
if (printk_seq > *next_seq) |
2990 |
*next_seq = con->seq; |
3182 |
*next_seq = printk_seq; |
2991 |
|
3183 |
|
2992 |
if (!progress) |
3184 |
if (!progress) |
2993 |
continue; |
3185 |
continue; |
Lines 3010-3028
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
3010 |
return false; |
3202 |
return false; |
3011 |
} |
3203 |
} |
3012 |
|
3204 |
|
3013 |
/** |
3205 |
static void console_flush_and_unlock(void) |
3014 |
* console_unlock - unblock the console subsystem from printing |
|
|
3015 |
* |
3016 |
* Releases the console_lock which the caller holds to block printing of |
3017 |
* the console subsystem. |
3018 |
* |
3019 |
* While the console_lock was held, console output may have been buffered |
3020 |
* by printk(). If this is the case, console_unlock(); emits |
3021 |
* the output prior to releasing the lock. |
3022 |
* |
3023 |
* console_unlock(); may be called from any context. |
3024 |
*/ |
3025 |
void console_unlock(void) |
3026 |
{ |
3206 |
{ |
3027 |
bool do_cond_resched; |
3207 |
bool do_cond_resched; |
3028 |
bool handover; |
3208 |
bool handover; |
Lines 3066-3071
void console_unlock(void)
Link Here
|
3066 |
*/ |
3246 |
*/ |
3067 |
} while (prb_read_valid(prb, next_seq, NULL) && console_trylock()); |
3247 |
} while (prb_read_valid(prb, next_seq, NULL) && console_trylock()); |
3068 |
} |
3248 |
} |
|
|
3249 |
|
3250 |
/** |
3251 |
* console_unlock - unblock the console subsystem from printing |
3252 |
* |
3253 |
* Releases the console_lock which the caller holds to block printing of |
3254 |
* the console subsystem. |
3255 |
* |
3256 |
* While the console_lock was held, console output may have been buffered |
3257 |
* by printk(). If this is the case, console_unlock(); emits |
3258 |
* the output prior to releasing the lock. |
3259 |
* |
3260 |
* console_unlock(); may be called from any context. |
3261 |
*/ |
3262 |
void console_unlock(void) |
3263 |
{ |
3264 |
/* |
3265 |
* Forced threading relies on kthread and atomic consoles for |
3266 |
* printing. It never attempts to print from console_unlock(). |
3267 |
*/ |
3268 |
if (force_printkthreads()) { |
3269 |
__console_unlock(); |
3270 |
return; |
3271 |
} |
3272 |
|
3273 |
console_flush_and_unlock(); |
3274 |
} |
3069 |
EXPORT_SYMBOL(console_unlock); |
3275 |
EXPORT_SYMBOL(console_unlock); |
3070 |
|
3276 |
|
3071 |
/** |
3277 |
/** |
Lines 3199-3205
void console_flush_on_panic(enum con_flush_mode mode)
Link Here
|
3199 |
console_srcu_read_unlock(cookie); |
3405 |
console_srcu_read_unlock(cookie); |
3200 |
} |
3406 |
} |
3201 |
|
3407 |
|
3202 |
console_flush_all(false, &next_seq, &handover); |
3408 |
nbcon_atomic_flush_pending(); |
|
|
3409 |
|
3410 |
if (printing_via_unlock) |
3411 |
console_flush_all(false, &next_seq, &handover); |
3203 |
} |
3412 |
} |
3204 |
|
3413 |
|
3205 |
/* |
3414 |
/* |
Lines 3256-3268
EXPORT_SYMBOL(console_stop);
Link Here
|
3256 |
|
3465 |
|
3257 |
void console_start(struct console *console) |
3466 |
void console_start(struct console *console) |
3258 |
{ |
3467 |
{ |
|
|
3468 |
short flags; |
3469 |
|
3259 |
console_list_lock(); |
3470 |
console_list_lock(); |
3260 |
console_srcu_write_flags(console, console->flags | CON_ENABLED); |
3471 |
console_srcu_write_flags(console, console->flags | CON_ENABLED); |
|
|
3472 |
flags = console->flags; |
3261 |
console_list_unlock(); |
3473 |
console_list_unlock(); |
|
|
3474 |
|
3475 |
/* |
3476 |
* Ensure that all SRCU list walks have completed. The related |
3477 |
* printing context must be able to see it is enabled so that |
3478 |
* it is guaranteed to wake up and resume printing. |
3479 |
*/ |
3480 |
synchronize_srcu(&console_srcu); |
3481 |
|
3482 |
if (flags & CON_NBCON) |
3483 |
nbcon_kthread_wake(console); |
3484 |
else |
3485 |
wake_up_legacy_kthread(); |
3486 |
|
3262 |
__pr_flush(console, 1000, true); |
3487 |
__pr_flush(console, 1000, true); |
3263 |
} |
3488 |
} |
3264 |
EXPORT_SYMBOL(console_start); |
3489 |
EXPORT_SYMBOL(console_start); |
3265 |
|
3490 |
|
|
|
3491 |
#ifdef CONFIG_PRINTK |
3492 |
static bool printer_should_wake(void) |
3493 |
{ |
3494 |
bool available = false; |
3495 |
struct console *con; |
3496 |
int cookie; |
3497 |
|
3498 |
if (kthread_should_stop()) |
3499 |
return true; |
3500 |
|
3501 |
cookie = console_srcu_read_lock(); |
3502 |
for_each_console_srcu(con) { |
3503 |
short flags = console_srcu_read_flags(con); |
3504 |
u64 printk_seq; |
3505 |
|
3506 |
/* |
3507 |
* The legacy printer thread is only for legacy consoles, |
3508 |
* unless the nbcon console has no kthread printer. |
3509 |
*/ |
3510 |
if ((flags & CON_NBCON) && con->kthread) |
3511 |
continue; |
3512 |
|
3513 |
if (!console_is_usable(con, flags, true)) |
3514 |
continue; |
3515 |
|
3516 |
if (flags & CON_NBCON) { |
3517 |
printk_seq = nbcon_seq_read(con); |
3518 |
} else { |
3519 |
/* |
3520 |
* It is safe to read @seq because only this |
3521 |
* thread context updates @seq. |
3522 |
*/ |
3523 |
printk_seq = con->seq; |
3524 |
} |
3525 |
|
3526 |
if (prb_read_valid(prb, printk_seq, NULL)) { |
3527 |
available = true; |
3528 |
break; |
3529 |
} |
3530 |
} |
3531 |
console_srcu_read_unlock(cookie); |
3532 |
|
3533 |
return available; |
3534 |
} |
3535 |
|
3536 |
static int nbcon_legacy_kthread_func(void *unused) |
3537 |
{ |
3538 |
int error; |
3539 |
|
3540 |
for (;;) { |
3541 |
error = wait_event_interruptible(legacy_wait, printer_should_wake()); |
3542 |
|
3543 |
if (kthread_should_stop()) |
3544 |
break; |
3545 |
|
3546 |
if (error) |
3547 |
continue; |
3548 |
|
3549 |
console_lock(); |
3550 |
console_flush_and_unlock(); |
3551 |
} |
3552 |
|
3553 |
return 0; |
3554 |
} |
3555 |
|
3556 |
void nbcon_legacy_kthread_create(void) |
3557 |
{ |
3558 |
struct task_struct *kt; |
3559 |
|
3560 |
lockdep_assert_held(&console_mutex); |
3561 |
|
3562 |
if (!force_printkthreads()) |
3563 |
return; |
3564 |
|
3565 |
if (!printk_threads_enabled || nbcon_legacy_kthread) |
3566 |
return; |
3567 |
|
3568 |
kt = kthread_run(nbcon_legacy_kthread_func, NULL, "pr/legacy"); |
3569 |
if (IS_ERR(kt)) { |
3570 |
pr_err("unable to start legacy printing thread\n"); |
3571 |
return; |
3572 |
} |
3573 |
|
3574 |
nbcon_legacy_kthread = kt; |
3575 |
|
3576 |
/* |
3577 |
* It is important that console printing threads are scheduled |
3578 |
* shortly after a printk call and with generous runtime budgets. |
3579 |
*/ |
3580 |
sched_set_normal(nbcon_legacy_kthread, -20); |
3581 |
} |
3582 |
#endif /* CONFIG_PRINTK */ |
3583 |
|
3266 |
static int __read_mostly keep_bootcon; |
3584 |
static int __read_mostly keep_bootcon; |
3267 |
|
3585 |
|
3268 |
static int __init keep_bootcon_setup(char *str) |
3586 |
static int __init keep_bootcon_setup(char *str) |
Lines 3361-3379
static void try_enable_default_console(struct console *newcon)
Link Here
|
3361 |
newcon->flags |= CON_CONSDEV; |
3679 |
newcon->flags |= CON_CONSDEV; |
3362 |
} |
3680 |
} |
3363 |
|
3681 |
|
3364 |
static void console_init_seq(struct console *newcon, bool bootcon_registered) |
3682 |
/* Return the starting sequence number for a newly registered console. */ |
|
|
3683 |
static u64 get_init_console_seq(struct console *newcon, bool bootcon_registered) |
3365 |
{ |
3684 |
{ |
3366 |
struct console *con; |
3685 |
struct console *con; |
3367 |
bool handover; |
3686 |
bool handover; |
|
|
3687 |
u64 init_seq; |
3368 |
|
3688 |
|
3369 |
if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) { |
3689 |
if (newcon->flags & (CON_PRINTBUFFER | CON_BOOT)) { |
3370 |
/* Get a consistent copy of @syslog_seq. */ |
3690 |
/* Get a consistent copy of @syslog_seq. */ |
3371 |
mutex_lock(&syslog_lock); |
3691 |
mutex_lock(&syslog_lock); |
3372 |
newcon->seq = syslog_seq; |
3692 |
init_seq = syslog_seq; |
3373 |
mutex_unlock(&syslog_lock); |
3693 |
mutex_unlock(&syslog_lock); |
3374 |
} else { |
3694 |
} else { |
3375 |
/* Begin with next message added to ringbuffer. */ |
3695 |
/* Begin with next message added to ringbuffer. */ |
3376 |
newcon->seq = prb_next_seq(prb); |
3696 |
init_seq = prb_next_seq(prb); |
3377 |
|
3697 |
|
3378 |
/* |
3698 |
/* |
3379 |
* If any enabled boot consoles are due to be unregistered |
3699 |
* If any enabled boot consoles are due to be unregistered |
Lines 3394-3400
static void console_init_seq(struct console *newcon, bool bootcon_registered)
Link Here
|
3394 |
* Flush all consoles and set the console to start at |
3714 |
* Flush all consoles and set the console to start at |
3395 |
* the next unprinted sequence number. |
3715 |
* the next unprinted sequence number. |
3396 |
*/ |
3716 |
*/ |
3397 |
if (!console_flush_all(true, &newcon->seq, &handover)) { |
3717 |
if (!console_flush_all(true, &init_seq, &handover)) { |
3398 |
/* |
3718 |
/* |
3399 |
* Flushing failed. Just choose the lowest |
3719 |
* Flushing failed. Just choose the lowest |
3400 |
* sequence of the enabled boot consoles. |
3720 |
* sequence of the enabled boot consoles. |
Lines 3407-3425
static void console_init_seq(struct console *newcon, bool bootcon_registered)
Link Here
|
3407 |
if (handover) |
3727 |
if (handover) |
3408 |
console_lock(); |
3728 |
console_lock(); |
3409 |
|
3729 |
|
3410 |
newcon->seq = prb_next_seq(prb); |
3730 |
init_seq = prb_next_seq(prb); |
3411 |
for_each_console(con) { |
3731 |
for_each_console(con) { |
3412 |
if ((con->flags & CON_BOOT) && |
3732 |
u64 seq; |
3413 |
(con->flags & CON_ENABLED) && |
3733 |
|
3414 |
con->seq < newcon->seq) { |
3734 |
if (!(con->flags & CON_BOOT) || |
3415 |
newcon->seq = con->seq; |
3735 |
!(con->flags & CON_ENABLED)) { |
|
|
3736 |
continue; |
3416 |
} |
3737 |
} |
|
|
3738 |
|
3739 |
if (con->flags & CON_NBCON) |
3740 |
seq = nbcon_seq_read(con); |
3741 |
else |
3742 |
seq = con->seq; |
3743 |
|
3744 |
if (seq < init_seq) |
3745 |
init_seq = seq; |
3417 |
} |
3746 |
} |
3418 |
} |
3747 |
} |
3419 |
|
3748 |
|
3420 |
console_unlock(); |
3749 |
console_unlock(); |
3421 |
} |
3750 |
} |
3422 |
} |
3751 |
} |
|
|
3752 |
|
3753 |
return init_seq; |
3423 |
} |
3754 |
} |
3424 |
|
3755 |
|
3425 |
#define console_first() \ |
3756 |
#define console_first() \ |
Lines 3451-3456
void register_console(struct console *newcon)
Link Here
|
3451 |
struct console *con; |
3782 |
struct console *con; |
3452 |
bool bootcon_registered = false; |
3783 |
bool bootcon_registered = false; |
3453 |
bool realcon_registered = false; |
3784 |
bool realcon_registered = false; |
|
|
3785 |
unsigned long flags; |
3786 |
u64 init_seq; |
3454 |
int err; |
3787 |
int err; |
3455 |
|
3788 |
|
3456 |
console_list_lock(); |
3789 |
console_list_lock(); |
Lines 3528-3537
void register_console(struct console *newcon)
Link Here
|
3528 |
} |
3861 |
} |
3529 |
|
3862 |
|
3530 |
newcon->dropped = 0; |
3863 |
newcon->dropped = 0; |
3531 |
console_init_seq(newcon, bootcon_registered); |
3864 |
init_seq = get_init_console_seq(newcon, bootcon_registered); |
3532 |
|
3865 |
|
3533 |
if (newcon->flags & CON_NBCON) |
3866 |
if (newcon->flags & CON_NBCON) { |
3534 |
nbcon_init(newcon); |
3867 |
have_nbcon_console = true; |
|
|
3868 |
nbcon_init(newcon, init_seq); |
3869 |
} else { |
3870 |
have_legacy_console = true; |
3871 |
newcon->seq = init_seq; |
3872 |
nbcon_legacy_kthread_create(); |
3873 |
} |
3874 |
|
3875 |
if (newcon->flags & CON_BOOT) |
3876 |
have_boot_console = true; |
3877 |
|
3878 |
/* |
3879 |
* If another context is actively using the hardware of this new |
3880 |
* console, it will not be aware of the nbcon synchronization. This |
3881 |
* is a risk that two contexts could access the hardware |
3882 |
* simultaneously if this new console is used for atomic printing |
3883 |
* and the other context is still using the hardware. |
3884 |
* |
3885 |
* Use the driver synchronization to ensure that the hardware is not |
3886 |
* in use while this new console transitions to being registered. |
3887 |
*/ |
3888 |
if ((newcon->flags & CON_NBCON) && newcon->write_atomic) |
3889 |
newcon->device_lock(newcon, &flags); |
3535 |
|
3890 |
|
3536 |
/* |
3891 |
/* |
3537 |
* Put this console in the list - keep the |
3892 |
* Put this console in the list - keep the |
Lines 3557-3562
void register_console(struct console *newcon)
Link Here
|
3557 |
* register_console() completes. |
3912 |
* register_console() completes. |
3558 |
*/ |
3913 |
*/ |
3559 |
|
3914 |
|
|
|
3915 |
/* This new console is now registered. */ |
3916 |
if ((newcon->flags & CON_NBCON) && newcon->write_atomic) |
3917 |
newcon->device_unlock(newcon, flags); |
3918 |
|
3560 |
console_sysfs_notify(); |
3919 |
console_sysfs_notify(); |
3561 |
|
3920 |
|
3562 |
/* |
3921 |
/* |
Lines 3585-3590
EXPORT_SYMBOL(register_console);
Link Here
|
3585 |
/* Must be called under console_list_lock(). */ |
3944 |
/* Must be called under console_list_lock(). */ |
3586 |
static int unregister_console_locked(struct console *console) |
3945 |
static int unregister_console_locked(struct console *console) |
3587 |
{ |
3946 |
{ |
|
|
3947 |
bool is_boot_con = (console->flags & CON_BOOT); |
3948 |
bool found_legacy_con = false; |
3949 |
bool found_nbcon_con = false; |
3950 |
bool found_boot_con = false; |
3951 |
unsigned long flags; |
3952 |
struct console *c; |
3588 |
int res; |
3953 |
int res; |
3589 |
|
3954 |
|
3590 |
lockdep_assert_console_list_lock_held(); |
3955 |
lockdep_assert_console_list_lock_held(); |
Lines 3603-3610
static int unregister_console_locked(struct console *console)
Link Here
|
3603 |
if (!console_is_registered_locked(console)) |
3968 |
if (!console_is_registered_locked(console)) |
3604 |
return -ENODEV; |
3969 |
return -ENODEV; |
3605 |
|
3970 |
|
|
|
3971 |
/* |
3972 |
* Use the driver synchronization to ensure that the hardware is not |
3973 |
* in use while this console transitions to being unregistered. |
3974 |
*/ |
3975 |
if ((console->flags & CON_NBCON) && console->write_atomic) |
3976 |
console->device_lock(console, &flags); |
3977 |
|
3606 |
hlist_del_init_rcu(&console->node); |
3978 |
hlist_del_init_rcu(&console->node); |
3607 |
|
3979 |
|
|
|
3980 |
if ((console->flags & CON_NBCON) && console->write_atomic) |
3981 |
console->device_unlock(console, flags); |
3982 |
|
3608 |
/* |
3983 |
/* |
3609 |
* <HISTORICAL> |
3984 |
* <HISTORICAL> |
3610 |
* If this isn't the last console and it has CON_CONSDEV set, we |
3985 |
* If this isn't the last console and it has CON_CONSDEV set, we |
Lines 3632-3637
static int unregister_console_locked(struct console *console)
Link Here
|
3632 |
if (console->exit) |
4007 |
if (console->exit) |
3633 |
res = console->exit(console); |
4008 |
res = console->exit(console); |
3634 |
|
4009 |
|
|
|
4010 |
/* |
4011 |
* With this console gone, the global flags tracking registered |
4012 |
* console types may have changed. Update them. |
4013 |
*/ |
4014 |
for_each_console(c) { |
4015 |
if (c->flags & CON_BOOT) |
4016 |
found_boot_con = true; |
4017 |
|
4018 |
if (c->flags & CON_NBCON) |
4019 |
found_nbcon_con = true; |
4020 |
else |
4021 |
found_legacy_con = true; |
4022 |
} |
4023 |
if (!found_boot_con) |
4024 |
have_boot_console = found_boot_con; |
4025 |
if (!found_legacy_con) |
4026 |
have_legacy_console = found_legacy_con; |
4027 |
if (!found_nbcon_con) |
4028 |
have_nbcon_console = found_nbcon_con; |
4029 |
|
4030 |
/* |
4031 |
* When the last boot console unregisters, start up the |
4032 |
* printing threads. |
4033 |
*/ |
4034 |
if (is_boot_con && !have_boot_console) { |
4035 |
for_each_console(c) |
4036 |
nbcon_kthread_create(c); |
4037 |
} |
4038 |
|
4039 |
#ifdef CONFIG_PRINTK |
4040 |
if (!printing_via_unlock && nbcon_legacy_kthread) { |
4041 |
kthread_stop(nbcon_legacy_kthread); |
4042 |
nbcon_legacy_kthread = NULL; |
4043 |
} |
4044 |
#endif |
4045 |
|
3635 |
return res; |
4046 |
return res; |
3636 |
} |
4047 |
} |
3637 |
|
4048 |
|
Lines 3790-3812
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3790 |
|
4201 |
|
3791 |
seq = prb_next_reserve_seq(prb); |
4202 |
seq = prb_next_reserve_seq(prb); |
3792 |
|
4203 |
|
3793 |
/* Flush the consoles so that records up to @seq are printed. */ |
4204 |
/* |
3794 |
console_lock(); |
4205 |
* Flush the consoles so that records up to @seq are printed. |
3795 |
console_unlock(); |
4206 |
* Otherwise this function will just wait for the threaded printers |
|
|
4207 |
* to print up to @seq. |
4208 |
*/ |
4209 |
if (printing_via_unlock && !force_printkthreads()) { |
4210 |
console_lock(); |
4211 |
console_unlock(); |
4212 |
} |
3796 |
|
4213 |
|
3797 |
for (;;) { |
4214 |
for (;;) { |
3798 |
unsigned long begin_jiffies; |
4215 |
unsigned long begin_jiffies; |
3799 |
unsigned long slept_jiffies; |
4216 |
unsigned long slept_jiffies; |
|
|
4217 |
bool use_console_lock = printing_via_unlock; |
4218 |
|
4219 |
/* |
4220 |
* Ensure the compiler does not optimize @use_console_lock to |
4221 |
* be @printing_via_unlock since the latter can change at any |
4222 |
* time. |
4223 |
*/ |
4224 |
barrier(); |
3800 |
|
4225 |
|
3801 |
diff = 0; |
4226 |
diff = 0; |
3802 |
|
4227 |
|
3803 |
/* |
4228 |
if (use_console_lock) { |
3804 |
* Hold the console_lock to guarantee safe access to |
4229 |
/* |
3805 |
* console->seq. Releasing console_lock flushes more |
4230 |
* Hold the console_lock to guarantee safe access to |
3806 |
* records in case @seq is still not printed on all |
4231 |
* console->seq. Releasing console_lock flushes more |
3807 |
* usable consoles. |
4232 |
* records in case @seq is still not printed on all |
3808 |
*/ |
4233 |
* usable consoles. |
3809 |
console_lock(); |
4234 |
*/ |
|
|
4235 |
console_lock(); |
4236 |
} |
3810 |
|
4237 |
|
3811 |
cookie = console_srcu_read_lock(); |
4238 |
cookie = console_srcu_read_lock(); |
3812 |
for_each_console_srcu(c) { |
4239 |
for_each_console_srcu(c) { |
Lines 3820-3831
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3820 |
* that they make forward progress, so only increment |
4247 |
* that they make forward progress, so only increment |
3821 |
* @diff for usable consoles. |
4248 |
* @diff for usable consoles. |
3822 |
*/ |
4249 |
*/ |
3823 |
if (!console_is_usable(c)) |
4250 |
if (!console_is_usable(c, flags, true) && |
|
|
4251 |
!console_is_usable(c, flags, false)) { |
3824 |
continue; |
4252 |
continue; |
|
|
4253 |
} |
3825 |
|
4254 |
|
3826 |
if (flags & CON_NBCON) { |
4255 |
if (flags & CON_NBCON) { |
3827 |
printk_seq = nbcon_seq_read(c); |
4256 |
printk_seq = nbcon_seq_read(c); |
3828 |
} else { |
4257 |
} else { |
|
|
4258 |
WARN_ON_ONCE(!use_console_lock); |
3829 |
printk_seq = c->seq; |
4259 |
printk_seq = c->seq; |
3830 |
} |
4260 |
} |
3831 |
|
4261 |
|
Lines 3837-3843
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3837 |
if (diff != last_diff && reset_on_progress) |
4267 |
if (diff != last_diff && reset_on_progress) |
3838 |
remaining_jiffies = timeout_jiffies; |
4268 |
remaining_jiffies = timeout_jiffies; |
3839 |
|
4269 |
|
3840 |
console_unlock(); |
4270 |
if (use_console_lock) |
|
|
4271 |
console_unlock(); |
3841 |
|
4272 |
|
3842 |
/* Note: @diff is 0 if there are no usable consoles. */ |
4273 |
/* Note: @diff is 0 if there are no usable consoles. */ |
3843 |
if (diff == 0 || remaining_jiffies == 0) |
4274 |
if (diff == 0 || remaining_jiffies == 0) |
Lines 3889-3897
static void wake_up_klogd_work_func(struct irq_work *irq_work)
Link Here
|
3889 |
int pending = this_cpu_xchg(printk_pending, 0); |
4320 |
int pending = this_cpu_xchg(printk_pending, 0); |
3890 |
|
4321 |
|
3891 |
if (pending & PRINTK_PENDING_OUTPUT) { |
4322 |
if (pending & PRINTK_PENDING_OUTPUT) { |
3892 |
/* If trylock fails, someone else is doing the printing */ |
4323 |
if (force_printkthreads()) { |
3893 |
if (console_trylock()) |
4324 |
wake_up_legacy_kthread(); |
3894 |
console_unlock(); |
4325 |
} else { |
|
|
4326 |
/* |
4327 |
* If trylock fails, some other context |
4328 |
* will do the printing. |
4329 |
*/ |
4330 |
if (console_trylock()) |
4331 |
console_unlock(); |
4332 |
} |
3895 |
} |
4333 |
} |
3896 |
|
4334 |
|
3897 |
if (pending & PRINTK_PENDING_WAKEUP) |
4335 |
if (pending & PRINTK_PENDING_WAKEUP) |
Lines 3907-3912
static void __wake_up_klogd(int val)
Link Here
|
3907 |
return; |
4345 |
return; |
3908 |
|
4346 |
|
3909 |
preempt_disable(); |
4347 |
preempt_disable(); |
|
|
4348 |
|
3910 |
/* |
4349 |
/* |
3911 |
* Guarantee any new records can be seen by tasks preparing to wait |
4350 |
* Guarantee any new records can be seen by tasks preparing to wait |
3912 |
* before this context checks if the wait queue is empty. |
4351 |
* before this context checks if the wait queue is empty. |
Lines 3918-3928
static void __wake_up_klogd(int val)
Link Here
|
3918 |
* |
4357 |
* |
3919 |
* This pairs with devkmsg_read:A and syslog_print:A. |
4358 |
* This pairs with devkmsg_read:A and syslog_print:A. |
3920 |
*/ |
4359 |
*/ |
3921 |
if (wq_has_sleeper(&log_wait) || /* LMM(__wake_up_klogd:A) */ |
4360 |
if (!wq_has_sleeper(&log_wait)) /* LMM(__wake_up_klogd:A) */ |
3922 |
(val & PRINTK_PENDING_OUTPUT)) { |
4361 |
val &= ~PRINTK_PENDING_WAKEUP; |
|
|
4362 |
|
4363 |
/* |
4364 |
* Simple read is safe. register_console() would flush a newly |
4365 |
* registered legacy console when writing the message about it |
4366 |
* being enabled. |
4367 |
*/ |
4368 |
if (!printing_via_unlock) |
4369 |
val &= ~PRINTK_PENDING_OUTPUT; |
4370 |
|
4371 |
if (val) { |
3923 |
this_cpu_or(printk_pending, val); |
4372 |
this_cpu_or(printk_pending, val); |
3924 |
irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); |
4373 |
irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); |
3925 |
} |
4374 |
} |
|
|
4375 |
|
3926 |
preempt_enable(); |
4376 |
preempt_enable(); |
3927 |
} |
4377 |
} |
3928 |
|
4378 |
|
Lines 3964-3969
void defer_console_output(void)
Link Here
|
3964 |
|
4414 |
|
3965 |
void printk_trigger_flush(void) |
4415 |
void printk_trigger_flush(void) |
3966 |
{ |
4416 |
{ |
|
|
4417 |
nbcon_wake_threads(); |
3967 |
defer_console_output(); |
4418 |
defer_console_output(); |
3968 |
} |
4419 |
} |
3969 |
|
4420 |
|