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 347-352
static bool panic_in_progress(void)
Link Here
|
347 |
return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID); |
360 |
return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID); |
348 |
} |
361 |
} |
349 |
|
362 |
|
|
|
363 |
/* Return true if a panic is in progress on the current CPU. */ |
364 |
bool this_cpu_in_panic(void) |
365 |
{ |
366 |
/* |
367 |
* We can use raw_smp_processor_id() here because it is impossible for |
368 |
* the task to be migrated to the panic_cpu, or away from it. If |
369 |
* panic_cpu has already been set, and we're not currently executing on |
370 |
* that CPU, then we never will be. |
371 |
*/ |
372 |
return unlikely(atomic_read(&panic_cpu) == raw_smp_processor_id()); |
373 |
} |
374 |
|
375 |
/* |
376 |
* Return true if a panic is in progress on a remote CPU. |
377 |
* |
378 |
* On true, the local CPU should immediately release any printing resources |
379 |
* that may be needed by the panic CPU. |
380 |
*/ |
381 |
bool other_cpu_in_panic(void) |
382 |
{ |
383 |
return (panic_in_progress() && !this_cpu_in_panic()); |
384 |
} |
385 |
|
350 |
/* |
386 |
/* |
351 |
* This is used for debugging the mess that is the VT code by |
387 |
* This is used for debugging the mess that is the VT code by |
352 |
* keeping track if we have the console semaphore held. It's |
388 |
* keeping track if we have the console semaphore held. It's |
Lines 438-451
static int console_msg_format = MSG_FORMAT_DEFAULT;
Link Here
|
438 |
/* syslog_lock protects syslog_* variables and write access to clear_seq. */ |
474 |
/* syslog_lock protects syslog_* variables and write access to clear_seq. */ |
439 |
static DEFINE_MUTEX(syslog_lock); |
475 |
static DEFINE_MUTEX(syslog_lock); |
440 |
|
476 |
|
441 |
#ifdef CONFIG_PRINTK |
|
|
442 |
/* |
477 |
/* |
443 |
* During panic, heavy printk by other CPUs can delay the |
478 |
* Specifies if a legacy console is registered. If legacy consoles are |
444 |
* panic and risk deadlock on console resources. |
479 |
* present, it is necessary to perform the console_lock/console_unlock dance |
|
|
480 |
* whenever console flushing should occur. |
445 |
*/ |
481 |
*/ |
446 |
static int __read_mostly suppress_panic_printk; |
482 |
bool have_legacy_console; |
447 |
|
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 |
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 |
448 |
DECLARE_WAIT_QUEUE_HEAD(log_wait); |
500 |
DECLARE_WAIT_QUEUE_HEAD(log_wait); |
|
|
501 |
|
502 |
static DECLARE_WAIT_QUEUE_HEAD(legacy_wait); |
503 |
|
449 |
/* All 3 protected by @syslog_lock. */ |
504 |
/* All 3 protected by @syslog_lock. */ |
450 |
/* 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 */ |
451 |
static u64 syslog_seq; |
506 |
static u64 syslog_seq; |
Lines 1844-1855
static bool console_waiter;
Link Here
|
1844 |
* 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 |
1845 |
* 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. |
1846 |
*/ |
1901 |
*/ |
1847 |
static void console_lock_spinning_enable(void) |
1902 |
void console_lock_spinning_enable(void) |
1848 |
{ |
1903 |
{ |
|
|
1904 |
/* |
1905 |
* Do not use spinning in panic(). The panic CPU wants to keep the lock. |
1906 |
* Non-panic CPUs abandon the flush anyway. |
1907 |
* |
1908 |
* Just keep the lockdep annotation. The panic-CPU should avoid |
1909 |
* taking console_owner_lock because it might cause a deadlock. |
1910 |
* This looks like the easiest way how to prevent false lockdep |
1911 |
* reports without handling races a lockless way. |
1912 |
*/ |
1913 |
if (panic_in_progress()) |
1914 |
goto lockdep; |
1915 |
|
1849 |
raw_spin_lock(&console_owner_lock); |
1916 |
raw_spin_lock(&console_owner_lock); |
1850 |
console_owner = current; |
1917 |
console_owner = current; |
1851 |
raw_spin_unlock(&console_owner_lock); |
1918 |
raw_spin_unlock(&console_owner_lock); |
1852 |
|
1919 |
|
|
|
1920 |
lockdep: |
1853 |
/* The waiter may spin on us after setting console_owner */ |
1921 |
/* The waiter may spin on us after setting console_owner */ |
1854 |
spin_acquire(&console_owner_dep_map, 0, 0, _THIS_IP_); |
1922 |
spin_acquire(&console_owner_dep_map, 0, 0, _THIS_IP_); |
1855 |
} |
1923 |
} |
Lines 1870-1879
static void console_lock_spinning_enable(void)
Link Here
|
1870 |
* |
1938 |
* |
1871 |
* Return: 1 if the lock rights were passed, 0 otherwise. |
1939 |
* Return: 1 if the lock rights were passed, 0 otherwise. |
1872 |
*/ |
1940 |
*/ |
1873 |
static int console_lock_spinning_disable_and_check(int cookie) |
1941 |
int console_lock_spinning_disable_and_check(int cookie) |
1874 |
{ |
1942 |
{ |
1875 |
int waiter; |
1943 |
int waiter; |
1876 |
|
1944 |
|
|
|
1945 |
/* |
1946 |
* Ignore spinning waiters during panic() because they might get stopped |
1947 |
* or blocked at any time, |
1948 |
* |
1949 |
* It is safe because nobody is allowed to start spinning during panic |
1950 |
* in the first place. If there has been a waiter then non panic CPUs |
1951 |
* might stay spinning. They would get stopped anyway. The panic context |
1952 |
* will never start spinning and an interrupted spin on panic CPU will |
1953 |
* never continue. |
1954 |
*/ |
1955 |
if (panic_in_progress()) { |
1956 |
/* Keep lockdep happy. */ |
1957 |
spin_release(&console_owner_dep_map, _THIS_IP_); |
1958 |
return 0; |
1959 |
} |
1960 |
|
1877 |
raw_spin_lock(&console_owner_lock); |
1961 |
raw_spin_lock(&console_owner_lock); |
1878 |
waiter = READ_ONCE(console_waiter); |
1962 |
waiter = READ_ONCE(console_waiter); |
1879 |
console_owner = NULL; |
1963 |
console_owner = NULL; |
Lines 2259-2313
int vprintk_store(int facility, int level,
Link Here
|
2259 |
return ret; |
2343 |
return ret; |
2260 |
} |
2344 |
} |
2261 |
|
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. |
2351 |
*/ |
2352 |
void printk_legacy_allow_panic_sync(void) |
2353 |
{ |
2354 |
legacy_allow_panic_sync = true; |
2355 |
} |
2356 |
|
2262 |
asmlinkage int vprintk_emit(int facility, int level, |
2357 |
asmlinkage int vprintk_emit(int facility, int level, |
2263 |
const struct dev_printk_info *dev_info, |
2358 |
const struct dev_printk_info *dev_info, |
2264 |
const char *fmt, va_list args) |
2359 |
const char *fmt, va_list args) |
2265 |
{ |
2360 |
{ |
|
|
2361 |
bool do_trylock_unlock = printing_via_unlock && |
2362 |
!force_printkthreads(); |
2266 |
int printed_len; |
2363 |
int printed_len; |
2267 |
bool in_sched = false; |
|
|
2268 |
|
2364 |
|
2269 |
/* Suppress unimportant messages after panic happens */ |
2365 |
/* Suppress unimportant messages after panic happens */ |
2270 |
if (unlikely(suppress_printk)) |
2366 |
if (unlikely(suppress_printk)) |
2271 |
return 0; |
2367 |
return 0; |
2272 |
|
2368 |
|
2273 |
if (unlikely(suppress_panic_printk) && |
2369 |
/* |
2274 |
atomic_read(&panic_cpu) != raw_smp_processor_id()) |
2370 |
* The messages on the panic CPU are the most important. If |
|
|
2371 |
* non-panic CPUs are generating any messages, they will be |
2372 |
* silently dropped. |
2373 |
*/ |
2374 |
if (other_cpu_in_panic()) |
2275 |
return 0; |
2375 |
return 0; |
2276 |
|
2376 |
|
2277 |
if (level == LOGLEVEL_SCHED) { |
2377 |
if (level == LOGLEVEL_SCHED) { |
2278 |
level = LOGLEVEL_DEFAULT; |
2378 |
level = LOGLEVEL_DEFAULT; |
2279 |
in_sched = true; |
2379 |
/* If called from the scheduler, we can not call up(). */ |
|
|
2380 |
do_trylock_unlock = false; |
2280 |
} |
2381 |
} |
2281 |
|
2382 |
|
2282 |
printk_delay(level); |
2383 |
printk_delay(level); |
2283 |
|
2384 |
|
2284 |
printed_len = vprintk_store(facility, level, dev_info, fmt, args); |
2385 |
printed_len = vprintk_store(facility, level, dev_info, fmt, args); |
2285 |
|
2386 |
|
2286 |
/* If called from the scheduler, we can not call up(). */ |
2387 |
if (!have_boot_console && have_nbcon_console) { |
2287 |
if (!in_sched) { |
2388 |
bool is_panic_context = this_cpu_in_panic(); |
|
|
2389 |
|
2390 |
/* |
2391 |
* In panic, the legacy consoles are not allowed to print from |
2392 |
* the printk calling context unless explicitly allowed. This |
2393 |
* gives the safe nbcon consoles a chance to print out all the |
2394 |
* panic messages first. This restriction only applies if |
2395 |
* there are nbcon consoles registered. |
2396 |
*/ |
2397 |
if (is_panic_context) |
2398 |
do_trylock_unlock &= legacy_allow_panic_sync; |
2399 |
|
2400 |
/* |
2401 |
* There are situations where nbcon atomic printing should |
2402 |
* happen in the printk() caller context: |
2403 |
* |
2404 |
* - When this CPU is in panic. |
2405 |
* |
2406 |
* - When booting, before the printing threads have been |
2407 |
* started. |
2408 |
* |
2409 |
* - During shutdown, since the printing threads may not get |
2410 |
* a chance to print the final messages. |
2411 |
* |
2412 |
* Note that if boot consoles are registered, the |
2413 |
* console_lock/console_unlock dance must be relied upon |
2414 |
* instead because nbcon consoles cannot print simultaneously |
2415 |
* with boot consoles. |
2416 |
*/ |
2417 |
if (is_panic_context || |
2418 |
!printk_threads_enabled || |
2419 |
(system_state > SYSTEM_RUNNING)) { |
2420 |
nbcon_atomic_flush_all(); |
2421 |
} |
2422 |
} |
2423 |
|
2424 |
nbcon_wake_threads(); |
2425 |
|
2426 |
if (do_trylock_unlock) { |
2288 |
/* |
2427 |
/* |
2289 |
* The caller may be holding system-critical or |
2428 |
* The caller may be holding system-critical or |
2290 |
* timing-sensitive locks. Disable preemption during |
2429 |
* timing-sensitive locks. Disable preemption during |
2291 |
* printing of all remaining records to all consoles so that |
2430 |
* printing of all remaining records to all consoles so that |
2292 |
* this context can return as soon as possible. Hopefully |
2431 |
* this context can return as soon as possible. Hopefully |
2293 |
* 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. |
2294 |
*/ |
2435 |
*/ |
2295 |
preempt_disable(); |
2436 |
preempt_disable(); |
|
|
2437 |
|
2296 |
/* |
2438 |
/* |
2297 |
* Try to acquire and then immediately release the console |
2439 |
* Do not emit for EMERGENCY priority. The console will be |
2298 |
* semaphore. The release will print out buffers. With the |
2440 |
* explicitly flushed when exiting the emergency section. |
2299 |
* spinning variant, this context tries to take over the |
|
|
2300 |
* printing from another printing context. |
2301 |
*/ |
2441 |
*/ |
2302 |
if (console_trylock_spinning()) |
2442 |
if (nbcon_get_default_prio() == NBCON_PRIO_EMERGENCY) { |
2303 |
console_unlock(); |
2443 |
do_trylock_unlock = false; |
|
|
2444 |
} else { |
2445 |
/* |
2446 |
* Try to acquire and then immediately release the |
2447 |
* console semaphore. The release will print out |
2448 |
* buffers. With the spinning variant, this context |
2449 |
* tries to take over the printing from another |
2450 |
* printing context. |
2451 |
*/ |
2452 |
if (console_trylock_spinning()) |
2453 |
console_unlock(); |
2454 |
} |
2455 |
|
2304 |
preempt_enable(); |
2456 |
preempt_enable(); |
2305 |
} |
2457 |
} |
2306 |
|
2458 |
|
2307 |
if (in_sched) |
2459 |
if (do_trylock_unlock) |
2308 |
defer_console_output(); |
|
|
2309 |
else |
2310 |
wake_up_klogd(); |
2460 |
wake_up_klogd(); |
|
|
2461 |
else |
2462 |
defer_console_output(); |
2311 |
|
2463 |
|
2312 |
return printed_len; |
2464 |
return printed_len; |
2313 |
} |
2465 |
} |
Lines 2335-2340
EXPORT_SYMBOL(_printk);
Link Here
|
2335 |
static bool pr_flush(int timeout_ms, bool reset_on_progress); |
2487 |
static bool pr_flush(int timeout_ms, bool reset_on_progress); |
2336 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress); |
2488 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress); |
2337 |
|
2489 |
|
|
|
2490 |
static struct task_struct *nbcon_legacy_kthread; |
2491 |
|
2492 |
static inline void wake_up_legacy_kthread(void) |
2493 |
{ |
2494 |
if (nbcon_legacy_kthread) |
2495 |
wake_up_interruptible(&legacy_wait); |
2496 |
} |
2497 |
|
2338 |
#else /* CONFIG_PRINTK */ |
2498 |
#else /* CONFIG_PRINTK */ |
2339 |
|
2499 |
|
2340 |
#define printk_time false |
2500 |
#define printk_time false |
Lines 2348-2353
static u64 syslog_seq;
Link Here
|
2348 |
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } |
2508 |
static bool pr_flush(int timeout_ms, bool reset_on_progress) { return true; } |
2349 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } |
2509 |
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progress) { return true; } |
2350 |
|
2510 |
|
|
|
2511 |
static inline void nbcon_legacy_kthread_create(void) { } |
2512 |
static inline void wake_up_legacy_kthread(void) { } |
2351 |
#endif /* CONFIG_PRINTK */ |
2513 |
#endif /* CONFIG_PRINTK */ |
2352 |
|
2514 |
|
2353 |
#ifdef CONFIG_EARLY_PRINTK |
2515 |
#ifdef CONFIG_EARLY_PRINTK |
Lines 2563-2568
void suspend_console(void)
Link Here
|
2563 |
void resume_console(void) |
2725 |
void resume_console(void) |
2564 |
{ |
2726 |
{ |
2565 |
struct console *con; |
2727 |
struct console *con; |
|
|
2728 |
short flags; |
2729 |
int cookie; |
2566 |
|
2730 |
|
2567 |
if (!console_suspend_enabled) |
2731 |
if (!console_suspend_enabled) |
2568 |
return; |
2732 |
return; |
Lines 2579-2584
void resume_console(void)
Link Here
|
2579 |
*/ |
2743 |
*/ |
2580 |
synchronize_srcu(&console_srcu); |
2744 |
synchronize_srcu(&console_srcu); |
2581 |
|
2745 |
|
|
|
2746 |
/* |
2747 |
* Since this runs in task context, wake the threaded printers |
2748 |
* directly rather than scheduling irq_work to do it. |
2749 |
*/ |
2750 |
cookie = console_srcu_read_lock(); |
2751 |
for_each_console_srcu(con) { |
2752 |
flags = console_srcu_read_flags(con); |
2753 |
if (flags & CON_NBCON) |
2754 |
nbcon_kthread_wake(con); |
2755 |
} |
2756 |
console_srcu_read_unlock(cookie); |
2757 |
|
2758 |
wake_up_legacy_kthread(); |
2759 |
|
2582 |
pr_flush(1000, true); |
2760 |
pr_flush(1000, true); |
2583 |
} |
2761 |
} |
2584 |
|
2762 |
|
Lines 2593-2599
void resume_console(void)
Link Here
|
2593 |
*/ |
2771 |
*/ |
2594 |
static int console_cpu_notify(unsigned int cpu) |
2772 |
static int console_cpu_notify(unsigned int cpu) |
2595 |
{ |
2773 |
{ |
2596 |
if (!cpuhp_tasks_frozen) { |
2774 |
if (!cpuhp_tasks_frozen && printing_via_unlock && |
|
|
2775 |
!force_printkthreads()) { |
2597 |
/* If trylock fails, someone else is doing the printing */ |
2776 |
/* If trylock fails, someone else is doing the printing */ |
2598 |
if (console_trylock()) |
2777 |
if (console_trylock()) |
2599 |
console_unlock(); |
2778 |
console_unlock(); |
Lines 2601-2626
static int console_cpu_notify(unsigned int cpu)
Link Here
|
2601 |
return 0; |
2780 |
return 0; |
2602 |
} |
2781 |
} |
2603 |
|
2782 |
|
2604 |
/* |
|
|
2605 |
* Return true if a panic is in progress on a remote CPU. |
2606 |
* |
2607 |
* On true, the local CPU should immediately release any printing resources |
2608 |
* that may be needed by the panic CPU. |
2609 |
*/ |
2610 |
bool other_cpu_in_panic(void) |
2611 |
{ |
2612 |
if (!panic_in_progress()) |
2613 |
return false; |
2614 |
|
2615 |
/* |
2616 |
* We can use raw_smp_processor_id() here because it is impossible for |
2617 |
* the task to be migrated to the panic_cpu, or away from it. If |
2618 |
* panic_cpu has already been set, and we're not currently executing on |
2619 |
* that CPU, then we never will be. |
2620 |
*/ |
2621 |
return atomic_read(&panic_cpu) != raw_smp_processor_id(); |
2622 |
} |
2623 |
|
2624 |
/** |
2783 |
/** |
2625 |
* console_lock - block the console subsystem from printing |
2784 |
* console_lock - block the console subsystem from printing |
2626 |
* |
2785 |
* |
Lines 2670-2705
int is_console_locked(void)
Link Here
|
2670 |
} |
2829 |
} |
2671 |
EXPORT_SYMBOL(is_console_locked); |
2830 |
EXPORT_SYMBOL(is_console_locked); |
2672 |
|
2831 |
|
2673 |
/* |
|
|
2674 |
* Check if the given console is currently capable and allowed to print |
2675 |
* records. |
2676 |
* |
2677 |
* Requires the console_srcu_read_lock. |
2678 |
*/ |
2679 |
static inline bool console_is_usable(struct console *con) |
2680 |
{ |
2681 |
short flags = console_srcu_read_flags(con); |
2682 |
|
2683 |
if (!(flags & CON_ENABLED)) |
2684 |
return false; |
2685 |
|
2686 |
if ((flags & CON_SUSPENDED)) |
2687 |
return false; |
2688 |
|
2689 |
if (!con->write) |
2690 |
return false; |
2691 |
|
2692 |
/* |
2693 |
* Console drivers may assume that per-cpu resources have been |
2694 |
* allocated. So unless they're explicitly marked as being able to |
2695 |
* cope (CON_ANYTIME) don't call them until this CPU is officially up. |
2696 |
*/ |
2697 |
if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) |
2698 |
return false; |
2699 |
|
2700 |
return true; |
2701 |
} |
2702 |
|
2703 |
static void __console_unlock(void) |
2832 |
static void __console_unlock(void) |
2704 |
{ |
2833 |
{ |
2705 |
console_locked = 0; |
2834 |
console_locked = 0; |
Lines 2776-2783
void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped)
Link Here
|
2776 |
bool printk_get_next_message(struct printk_message *pmsg, u64 seq, |
2905 |
bool printk_get_next_message(struct printk_message *pmsg, u64 seq, |
2777 |
bool is_extended, bool may_suppress) |
2906 |
bool is_extended, bool may_suppress) |
2778 |
{ |
2907 |
{ |
2779 |
static int panic_console_dropped; |
|
|
2780 |
|
2781 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2908 |
struct printk_buffers *pbufs = pmsg->pbufs; |
2782 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2909 |
const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); |
2783 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
2910 |
const size_t outbuf_sz = sizeof(pbufs->outbuf); |
Lines 2805-2821
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
Link Here
|
2805 |
pmsg->seq = r.info->seq; |
2932 |
pmsg->seq = r.info->seq; |
2806 |
pmsg->dropped = r.info->seq - seq; |
2933 |
pmsg->dropped = r.info->seq - seq; |
2807 |
|
2934 |
|
2808 |
/* |
|
|
2809 |
* Check for dropped messages in panic here so that printk |
2810 |
* suppression can occur as early as possible if necessary. |
2811 |
*/ |
2812 |
if (pmsg->dropped && |
2813 |
panic_in_progress() && |
2814 |
panic_console_dropped++ > 10) { |
2815 |
suppress_panic_printk = 1; |
2816 |
pr_warn_once("Too many dropped messages. Suppress messages on non-panic CPUs to prevent livelock.\n"); |
2817 |
} |
2818 |
|
2819 |
/* Skip record that has level above the console loglevel. */ |
2935 |
/* Skip record that has level above the console loglevel. */ |
2820 |
if (may_suppress && suppress_message_printing(r.info->level)) |
2936 |
if (may_suppress && suppress_message_printing(r.info->level)) |
2821 |
goto out; |
2937 |
goto out; |
Lines 2832-2837
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
Link Here
|
2832 |
return true; |
2948 |
return true; |
2833 |
} |
2949 |
} |
2834 |
|
2950 |
|
|
|
2951 |
/* |
2952 |
* Legacy console printing from printk() caller context does not respect |
2953 |
* raw_spinlock/spinlock nesting. For !PREEMPT_RT the lockdep warning is a |
2954 |
* false positive. For PREEMPT_RT the false positive condition does not |
2955 |
* occur. |
2956 |
* |
2957 |
* This map is used to establish LD_WAIT_SLEEP context for the console write |
2958 |
* callbacks when legacy printing to avoid false positive lockdep complaints, |
2959 |
* thus allowing lockdep to continue to function for real issues. |
2960 |
*/ |
2961 |
#ifdef CONFIG_PREEMPT_RT |
2962 |
static inline void printk_legacy_lock_map_acquire_try(void) { } |
2963 |
static inline void printk_legacy_lock_map_release(void) { } |
2964 |
#else |
2965 |
DEFINE_WAIT_OVERRIDE_MAP(printk_legacy_map, LD_WAIT_SLEEP); |
2966 |
|
2967 |
static inline void printk_legacy_lock_map_acquire_try(void) |
2968 |
{ |
2969 |
lock_map_acquire_try(&printk_legacy_map); |
2970 |
} |
2971 |
|
2972 |
static inline void printk_legacy_lock_map_release(void) |
2973 |
{ |
2974 |
lock_map_release(&printk_legacy_map); |
2975 |
} |
2976 |
#endif /* CONFIG_PREEMPT_RT */ |
2977 |
|
2835 |
/* |
2978 |
/* |
2836 |
* Used as the printk buffers for non-panic, serialized console printing. |
2979 |
* Used as the printk buffers for non-panic, serialized console printing. |
2837 |
* This is for legacy (!CON_NBCON) as well as all boot (CON_BOOT) consoles. |
2980 |
* This is for legacy (!CON_NBCON) as well as all boot (CON_BOOT) consoles. |
Lines 2881-2911
static bool console_emit_next_record(struct console *con, bool *handover, int co
Link Here
|
2881 |
con->dropped = 0; |
3024 |
con->dropped = 0; |
2882 |
} |
3025 |
} |
2883 |
|
3026 |
|
2884 |
/* |
|
|
2885 |
* While actively printing out messages, if another printk() |
2886 |
* were to occur on another CPU, it may wait for this one to |
2887 |
* finish. This task can not be preempted if there is a |
2888 |
* waiter waiting to take over. |
2889 |
* |
2890 |
* Interrupts are disabled because the hand over to a waiter |
2891 |
* must not be interrupted until the hand over is completed |
2892 |
* (@console_waiter is cleared). |
2893 |
*/ |
2894 |
printk_safe_enter_irqsave(flags); |
2895 |
console_lock_spinning_enable(); |
2896 |
|
2897 |
/* Do not trace print latency. */ |
2898 |
stop_critical_timings(); |
2899 |
|
2900 |
/* Write everything out to the hardware. */ |
3027 |
/* Write everything out to the hardware. */ |
2901 |
con->write(con, outbuf, pmsg.outbuf_len); |
|
|
2902 |
|
3028 |
|
2903 |
start_critical_timings(); |
3029 |
if (force_printkthreads()) { |
|
|
3030 |
/* |
3031 |
* With forced threading this function is either in a thread |
3032 |
* or panic context. So there is no need for concern about |
3033 |
* printk reentrance, handovers, or lockdep complaints. |
3034 |
*/ |
2904 |
|
3035 |
|
2905 |
con->seq = pmsg.seq + 1; |
3036 |
con->write(con, outbuf, pmsg.outbuf_len); |
|
|
3037 |
con->seq = pmsg.seq + 1; |
3038 |
} else { |
3039 |
/* |
3040 |
* While actively printing out messages, if another printk() |
3041 |
* were to occur on another CPU, it may wait for this one to |
3042 |
* finish. This task can not be preempted if there is a |
3043 |
* waiter waiting to take over. |
3044 |
* |
3045 |
* Interrupts are disabled because the hand over to a waiter |
3046 |
* must not be interrupted until the hand over is completed |
3047 |
* (@console_waiter is cleared). |
3048 |
*/ |
3049 |
printk_safe_enter_irqsave(flags); |
3050 |
console_lock_spinning_enable(); |
2906 |
|
3051 |
|
2907 |
*handover = console_lock_spinning_disable_and_check(cookie); |
3052 |
/* Do not trace print latency. */ |
2908 |
printk_safe_exit_irqrestore(flags); |
3053 |
stop_critical_timings(); |
|
|
3054 |
|
3055 |
printk_legacy_lock_map_acquire_try(); |
3056 |
con->write(con, outbuf, pmsg.outbuf_len); |
3057 |
printk_legacy_lock_map_release(); |
3058 |
|
3059 |
start_critical_timings(); |
3060 |
|
3061 |
con->seq = pmsg.seq + 1; |
3062 |
|
3063 |
*handover = console_lock_spinning_disable_and_check(cookie); |
3064 |
printk_safe_exit_irqrestore(flags); |
3065 |
} |
2909 |
skip: |
3066 |
skip: |
2910 |
return true; |
3067 |
return true; |
2911 |
} |
3068 |
} |
Lines 2958-2970
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
2958 |
|
3115 |
|
2959 |
cookie = console_srcu_read_lock(); |
3116 |
cookie = console_srcu_read_lock(); |
2960 |
for_each_console_srcu(con) { |
3117 |
for_each_console_srcu(con) { |
|
|
3118 |
short flags = console_srcu_read_flags(con); |
3119 |
u64 printk_seq; |
2961 |
bool progress; |
3120 |
bool progress; |
2962 |
|
3121 |
|
2963 |
if (!console_is_usable(con)) |
3122 |
/* |
|
|
3123 |
* console_flush_all() is only for legacy consoles, |
3124 |
* unless the nbcon console has no kthread printer. |
3125 |
*/ |
3126 |
if ((flags & CON_NBCON) && con->kthread) |
3127 |
continue; |
3128 |
|
3129 |
if (!console_is_usable(con, flags, !do_cond_resched)) |
2964 |
continue; |
3130 |
continue; |
2965 |
any_usable = true; |
3131 |
any_usable = true; |
2966 |
|
3132 |
|
2967 |
progress = console_emit_next_record(con, handover, cookie); |
3133 |
if (flags & CON_NBCON) { |
|
|
3134 |
progress = nbcon_legacy_emit_next_record(con, handover, cookie, |
3135 |
!do_cond_resched); |
3136 |
printk_seq = nbcon_seq_read(con); |
3137 |
} else { |
3138 |
progress = console_emit_next_record(con, handover, cookie); |
3139 |
|
3140 |
printk_seq = con->seq; |
3141 |
} |
2968 |
|
3142 |
|
2969 |
/* |
3143 |
/* |
2970 |
* If a handover has occurred, the SRCU read lock |
3144 |
* If a handover has occurred, the SRCU read lock |
Lines 2974-2981
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
2974 |
return false; |
3148 |
return false; |
2975 |
|
3149 |
|
2976 |
/* Track the next of the highest seq flushed. */ |
3150 |
/* Track the next of the highest seq flushed. */ |
2977 |
if (con->seq > *next_seq) |
3151 |
if (printk_seq > *next_seq) |
2978 |
*next_seq = con->seq; |
3152 |
*next_seq = printk_seq; |
2979 |
|
3153 |
|
2980 |
if (!progress) |
3154 |
if (!progress) |
2981 |
continue; |
3155 |
continue; |
Lines 2998-3016
static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove
Link Here
|
2998 |
return false; |
3172 |
return false; |
2999 |
} |
3173 |
} |
3000 |
|
3174 |
|
3001 |
/** |
3175 |
static void console_flush_and_unlock(void) |
3002 |
* console_unlock - unblock the console subsystem from printing |
|
|
3003 |
* |
3004 |
* Releases the console_lock which the caller holds to block printing of |
3005 |
* the console subsystem. |
3006 |
* |
3007 |
* While the console_lock was held, console output may have been buffered |
3008 |
* by printk(). If this is the case, console_unlock(); emits |
3009 |
* the output prior to releasing the lock. |
3010 |
* |
3011 |
* console_unlock(); may be called from any context. |
3012 |
*/ |
3013 |
void console_unlock(void) |
3014 |
{ |
3176 |
{ |
3015 |
bool do_cond_resched; |
3177 |
bool do_cond_resched; |
3016 |
bool handover; |
3178 |
bool handover; |
Lines 3054-3059
void console_unlock(void)
Link Here
|
3054 |
*/ |
3216 |
*/ |
3055 |
} while (prb_read_valid(prb, next_seq, NULL) && console_trylock()); |
3217 |
} while (prb_read_valid(prb, next_seq, NULL) && console_trylock()); |
3056 |
} |
3218 |
} |
|
|
3219 |
|
3220 |
/** |
3221 |
* console_unlock - unblock the console subsystem from printing |
3222 |
* |
3223 |
* Releases the console_lock which the caller holds to block printing of |
3224 |
* the console subsystem. |
3225 |
* |
3226 |
* While the console_lock was held, console output may have been buffered |
3227 |
* by printk(). If this is the case, console_unlock(); emits |
3228 |
* the output prior to releasing the lock. |
3229 |
* |
3230 |
* console_unlock(); may be called from any context. |
3231 |
*/ |
3232 |
void console_unlock(void) |
3233 |
{ |
3234 |
/* |
3235 |
* Forced threading relies on kthread and atomic consoles for |
3236 |
* printing. It never attempts to print from console_unlock(). |
3237 |
*/ |
3238 |
if (force_printkthreads()) { |
3239 |
__console_unlock(); |
3240 |
return; |
3241 |
} |
3242 |
|
3243 |
console_flush_and_unlock(); |
3244 |
} |
3057 |
EXPORT_SYMBOL(console_unlock); |
3245 |
EXPORT_SYMBOL(console_unlock); |
3058 |
|
3246 |
|
3059 |
/** |
3247 |
/** |
Lines 3187-3193
void console_flush_on_panic(enum con_flush_mode mode)
Link Here
|
3187 |
console_srcu_read_unlock(cookie); |
3375 |
console_srcu_read_unlock(cookie); |
3188 |
} |
3376 |
} |
3189 |
|
3377 |
|
3190 |
console_flush_all(false, &next_seq, &handover); |
3378 |
nbcon_atomic_flush_all(); |
|
|
3379 |
|
3380 |
if (printing_via_unlock) |
3381 |
console_flush_all(false, &next_seq, &handover); |
3191 |
} |
3382 |
} |
3192 |
|
3383 |
|
3193 |
/* |
3384 |
/* |
Lines 3244-3256
EXPORT_SYMBOL(console_stop);
Link Here
|
3244 |
|
3435 |
|
3245 |
void console_start(struct console *console) |
3436 |
void console_start(struct console *console) |
3246 |
{ |
3437 |
{ |
|
|
3438 |
short flags; |
3439 |
|
3247 |
console_list_lock(); |
3440 |
console_list_lock(); |
3248 |
console_srcu_write_flags(console, console->flags | CON_ENABLED); |
3441 |
console_srcu_write_flags(console, console->flags | CON_ENABLED); |
|
|
3442 |
flags = console->flags; |
3249 |
console_list_unlock(); |
3443 |
console_list_unlock(); |
|
|
3444 |
|
3445 |
/* |
3446 |
* Ensure that all SRCU list walks have completed. The related |
3447 |
* printing context must be able to see it is enabled so that |
3448 |
* it is guaranteed to wake up and resume printing. |
3449 |
*/ |
3450 |
synchronize_srcu(&console_srcu); |
3451 |
|
3452 |
if (flags & CON_NBCON) |
3453 |
nbcon_kthread_wake(console); |
3454 |
else |
3455 |
wake_up_legacy_kthread(); |
3456 |
|
3250 |
__pr_flush(console, 1000, true); |
3457 |
__pr_flush(console, 1000, true); |
3251 |
} |
3458 |
} |
3252 |
EXPORT_SYMBOL(console_start); |
3459 |
EXPORT_SYMBOL(console_start); |
3253 |
|
3460 |
|
|
|
3461 |
#ifdef CONFIG_PRINTK |
3462 |
static bool printer_should_wake(void) |
3463 |
{ |
3464 |
bool available = false; |
3465 |
struct console *con; |
3466 |
int cookie; |
3467 |
|
3468 |
if (kthread_should_stop()) |
3469 |
return true; |
3470 |
|
3471 |
cookie = console_srcu_read_lock(); |
3472 |
for_each_console_srcu(con) { |
3473 |
short flags = console_srcu_read_flags(con); |
3474 |
u64 printk_seq; |
3475 |
|
3476 |
/* |
3477 |
* The legacy printer thread is only for legacy consoles, |
3478 |
* unless the nbcon console has no kthread printer. |
3479 |
*/ |
3480 |
if ((flags & CON_NBCON) && con->kthread) |
3481 |
continue; |
3482 |
|
3483 |
if (!console_is_usable(con, flags, true)) |
3484 |
continue; |
3485 |
|
3486 |
if (flags & CON_NBCON) { |
3487 |
printk_seq = nbcon_seq_read(con); |
3488 |
} else { |
3489 |
/* |
3490 |
* It is safe to read @seq because only this |
3491 |
* thread context updates @seq. |
3492 |
*/ |
3493 |
printk_seq = con->seq; |
3494 |
} |
3495 |
|
3496 |
if (prb_read_valid(prb, printk_seq, NULL)) { |
3497 |
available = true; |
3498 |
break; |
3499 |
} |
3500 |
} |
3501 |
console_srcu_read_unlock(cookie); |
3502 |
|
3503 |
return available; |
3504 |
} |
3505 |
|
3506 |
static int nbcon_legacy_kthread_func(void *unused) |
3507 |
{ |
3508 |
int error; |
3509 |
|
3510 |
for (;;) { |
3511 |
error = wait_event_interruptible(legacy_wait, printer_should_wake()); |
3512 |
|
3513 |
if (kthread_should_stop()) |
3514 |
break; |
3515 |
|
3516 |
if (error) |
3517 |
continue; |
3518 |
|
3519 |
console_lock(); |
3520 |
console_flush_and_unlock(); |
3521 |
} |
3522 |
|
3523 |
return 0; |
3524 |
} |
3525 |
|
3526 |
void nbcon_legacy_kthread_create(void) |
3527 |
{ |
3528 |
struct task_struct *kt; |
3529 |
|
3530 |
lockdep_assert_held(&console_mutex); |
3531 |
|
3532 |
if (!force_printkthreads()) |
3533 |
return; |
3534 |
|
3535 |
if (!printk_threads_enabled || nbcon_legacy_kthread) |
3536 |
return; |
3537 |
|
3538 |
kt = kthread_run(nbcon_legacy_kthread_func, NULL, "pr/legacy"); |
3539 |
if (IS_ERR(kt)) { |
3540 |
pr_err("unable to start legacy printing thread\n"); |
3541 |
return; |
3542 |
} |
3543 |
|
3544 |
nbcon_legacy_kthread = kt; |
3545 |
|
3546 |
/* |
3547 |
* It is important that console printing threads are scheduled |
3548 |
* shortly after a printk call and with generous runtime budgets. |
3549 |
*/ |
3550 |
sched_set_normal(nbcon_legacy_kthread, -20); |
3551 |
} |
3552 |
#endif /* CONFIG_PRINTK */ |
3553 |
|
3254 |
static int __read_mostly keep_bootcon; |
3554 |
static int __read_mostly keep_bootcon; |
3255 |
|
3555 |
|
3256 |
static int __init keep_bootcon_setup(char *str) |
3556 |
static int __init keep_bootcon_setup(char *str) |
Lines 3382-3392
static void console_init_seq(struct console *newcon, bool bootcon_registered)
Link Here
|
3382 |
|
3682 |
|
3383 |
newcon->seq = prb_next_seq(prb); |
3683 |
newcon->seq = prb_next_seq(prb); |
3384 |
for_each_console(con) { |
3684 |
for_each_console(con) { |
3385 |
if ((con->flags & CON_BOOT) && |
3685 |
u64 seq; |
3386 |
(con->flags & CON_ENABLED) && |
3686 |
|
3387 |
con->seq < newcon->seq) { |
3687 |
if (!((con->flags & CON_BOOT) && |
3388 |
newcon->seq = con->seq; |
3688 |
(con->flags & CON_ENABLED))) { |
|
|
3689 |
continue; |
3389 |
} |
3690 |
} |
|
|
3691 |
|
3692 |
if (con->flags & CON_NBCON) |
3693 |
seq = nbcon_seq_read(con); |
3694 |
else |
3695 |
seq = con->seq; |
3696 |
|
3697 |
if (seq < newcon->seq) |
3698 |
newcon->seq = seq; |
3390 |
} |
3699 |
} |
3391 |
} |
3700 |
} |
3392 |
|
3701 |
|
Lines 3503-3510
void register_console(struct console *newcon)
Link Here
|
3503 |
newcon->dropped = 0; |
3812 |
newcon->dropped = 0; |
3504 |
console_init_seq(newcon, bootcon_registered); |
3813 |
console_init_seq(newcon, bootcon_registered); |
3505 |
|
3814 |
|
3506 |
if (newcon->flags & CON_NBCON) |
3815 |
if (newcon->flags & CON_NBCON) { |
|
|
3816 |
have_nbcon_console = true; |
3507 |
nbcon_init(newcon); |
3817 |
nbcon_init(newcon); |
|
|
3818 |
} else { |
3819 |
have_legacy_console = true; |
3820 |
nbcon_legacy_kthread_create(); |
3821 |
} |
3822 |
|
3823 |
if (newcon->flags & CON_BOOT) |
3824 |
have_boot_console = true; |
3508 |
|
3825 |
|
3509 |
/* |
3826 |
/* |
3510 |
* Put this console in the list - keep the |
3827 |
* Put this console in the list - keep the |
Lines 3558-3563
EXPORT_SYMBOL(register_console);
Link Here
|
3558 |
/* Must be called under console_list_lock(). */ |
3875 |
/* Must be called under console_list_lock(). */ |
3559 |
static int unregister_console_locked(struct console *console) |
3876 |
static int unregister_console_locked(struct console *console) |
3560 |
{ |
3877 |
{ |
|
|
3878 |
bool is_boot_con = (console->flags & CON_BOOT); |
3879 |
bool found_legacy_con = false; |
3880 |
bool found_nbcon_con = false; |
3881 |
bool found_boot_con = false; |
3882 |
struct console *c; |
3561 |
int res; |
3883 |
int res; |
3562 |
|
3884 |
|
3563 |
lockdep_assert_console_list_lock_held(); |
3885 |
lockdep_assert_console_list_lock_held(); |
Lines 3605-3610
static int unregister_console_locked(struct console *console)
Link Here
|
3605 |
if (console->exit) |
3927 |
if (console->exit) |
3606 |
res = console->exit(console); |
3928 |
res = console->exit(console); |
3607 |
|
3929 |
|
|
|
3930 |
/* |
3931 |
* With this console gone, the global flags tracking registered |
3932 |
* console types may have changed. Update them. |
3933 |
*/ |
3934 |
for_each_console(c) { |
3935 |
if (c->flags & CON_BOOT) |
3936 |
found_boot_con = true; |
3937 |
|
3938 |
if (c->flags & CON_NBCON) |
3939 |
found_nbcon_con = true; |
3940 |
else |
3941 |
found_legacy_con = true; |
3942 |
} |
3943 |
if (!found_boot_con) |
3944 |
have_boot_console = false; |
3945 |
if (!found_legacy_con) |
3946 |
have_legacy_console = false; |
3947 |
if (!found_nbcon_con) |
3948 |
have_nbcon_console = false; |
3949 |
|
3950 |
/* |
3951 |
* When the last boot console unregisters, start up the |
3952 |
* printing threads. |
3953 |
*/ |
3954 |
if (is_boot_con && !have_boot_console) { |
3955 |
for_each_console(c) |
3956 |
nbcon_kthread_create(c); |
3957 |
} |
3958 |
|
3959 |
#ifdef CONFIG_PRINTK |
3960 |
if (!printing_via_unlock && nbcon_legacy_kthread) { |
3961 |
kthread_stop(nbcon_legacy_kthread); |
3962 |
nbcon_legacy_kthread = NULL; |
3963 |
} |
3964 |
#endif |
3965 |
|
3608 |
return res; |
3966 |
return res; |
3609 |
} |
3967 |
} |
3610 |
|
3968 |
|
Lines 3755-3785
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3755 |
u64 last_diff = 0; |
4113 |
u64 last_diff = 0; |
3756 |
u64 printk_seq; |
4114 |
u64 printk_seq; |
3757 |
short flags; |
4115 |
short flags; |
|
|
4116 |
bool locked; |
3758 |
int cookie; |
4117 |
int cookie; |
3759 |
u64 diff; |
4118 |
u64 diff; |
3760 |
u64 seq; |
4119 |
u64 seq; |
3761 |
|
4120 |
|
3762 |
might_sleep(); |
4121 |
might_sleep(); |
3763 |
|
4122 |
|
3764 |
seq = prb_next_seq(prb); |
4123 |
seq = prb_next_reserve_seq(prb); |
3765 |
|
4124 |
|
3766 |
/* Flush the consoles so that records up to @seq are printed. */ |
4125 |
/* |
3767 |
console_lock(); |
4126 |
* Flush the consoles so that records up to @seq are printed. |
3768 |
console_unlock(); |
4127 |
* Otherwise this function will just wait for the threaded printers |
|
|
4128 |
* to print up to @seq. |
4129 |
*/ |
4130 |
if (printing_via_unlock && !force_printkthreads()) { |
4131 |
console_lock(); |
4132 |
console_unlock(); |
4133 |
} |
3769 |
|
4134 |
|
3770 |
for (;;) { |
4135 |
for (;;) { |
3771 |
unsigned long begin_jiffies; |
4136 |
unsigned long begin_jiffies; |
3772 |
unsigned long slept_jiffies; |
4137 |
unsigned long slept_jiffies; |
3773 |
|
4138 |
|
|
|
4139 |
locked = false; |
3774 |
diff = 0; |
4140 |
diff = 0; |
3775 |
|
4141 |
|
3776 |
/* |
4142 |
if (printing_via_unlock) { |
3777 |
* Hold the console_lock to guarantee safe access to |
4143 |
/* |
3778 |
* console->seq. Releasing console_lock flushes more |
4144 |
* Hold the console_lock to guarantee safe access to |
3779 |
* records in case @seq is still not printed on all |
4145 |
* console->seq. Releasing console_lock flushes more |
3780 |
* usable consoles. |
4146 |
* records in case @seq is still not printed on all |
3781 |
*/ |
4147 |
* usable consoles. |
3782 |
console_lock(); |
4148 |
*/ |
|
|
4149 |
console_lock(); |
4150 |
locked = true; |
4151 |
} |
3783 |
|
4152 |
|
3784 |
cookie = console_srcu_read_lock(); |
4153 |
cookie = console_srcu_read_lock(); |
3785 |
for_each_console_srcu(c) { |
4154 |
for_each_console_srcu(c) { |
Lines 3793-3804
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3793 |
* that they make forward progress, so only increment |
4162 |
* that they make forward progress, so only increment |
3794 |
* @diff for usable consoles. |
4163 |
* @diff for usable consoles. |
3795 |
*/ |
4164 |
*/ |
3796 |
if (!console_is_usable(c)) |
4165 |
if (!console_is_usable(c, flags, true) && |
|
|
4166 |
!console_is_usable(c, flags, false)) { |
3797 |
continue; |
4167 |
continue; |
|
|
4168 |
} |
3798 |
|
4169 |
|
3799 |
if (flags & CON_NBCON) { |
4170 |
if (flags & CON_NBCON) { |
3800 |
printk_seq = nbcon_seq_read(c); |
4171 |
printk_seq = nbcon_seq_read(c); |
3801 |
} else { |
4172 |
} else { |
|
|
4173 |
WARN_ON_ONCE(!locked); |
3802 |
printk_seq = c->seq; |
4174 |
printk_seq = c->seq; |
3803 |
} |
4175 |
} |
3804 |
|
4176 |
|
Lines 3810-3816
static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre
Link Here
|
3810 |
if (diff != last_diff && reset_on_progress) |
4182 |
if (diff != last_diff && reset_on_progress) |
3811 |
remaining_jiffies = timeout_jiffies; |
4183 |
remaining_jiffies = timeout_jiffies; |
3812 |
|
4184 |
|
3813 |
console_unlock(); |
4185 |
if (locked) |
|
|
4186 |
console_unlock(); |
3814 |
|
4187 |
|
3815 |
/* Note: @diff is 0 if there are no usable consoles. */ |
4188 |
/* Note: @diff is 0 if there are no usable consoles. */ |
3816 |
if (diff == 0 || remaining_jiffies == 0) |
4189 |
if (diff == 0 || remaining_jiffies == 0) |
Lines 3862-3870
static void wake_up_klogd_work_func(struct irq_work *irq_work)
Link Here
|
3862 |
int pending = this_cpu_xchg(printk_pending, 0); |
4235 |
int pending = this_cpu_xchg(printk_pending, 0); |
3863 |
|
4236 |
|
3864 |
if (pending & PRINTK_PENDING_OUTPUT) { |
4237 |
if (pending & PRINTK_PENDING_OUTPUT) { |
3865 |
/* If trylock fails, someone else is doing the printing */ |
4238 |
if (force_printkthreads()) { |
3866 |
if (console_trylock()) |
4239 |
wake_up_legacy_kthread(); |
3867 |
console_unlock(); |
4240 |
} else { |
|
|
4241 |
/* |
4242 |
* If trylock fails, some other context |
4243 |
* will do the printing. |
4244 |
*/ |
4245 |
if (console_trylock()) |
4246 |
console_unlock(); |
4247 |
} |
3868 |
} |
4248 |
} |
3869 |
|
4249 |
|
3870 |
if (pending & PRINTK_PENDING_WAKEUP) |
4250 |
if (pending & PRINTK_PENDING_WAKEUP) |
Lines 3932-3942
void defer_console_output(void)
Link Here
|
3932 |
* New messages may have been added directly to the ringbuffer |
4312 |
* New messages may have been added directly to the ringbuffer |
3933 |
* using vprintk_store(), so wake any waiters as well. |
4313 |
* using vprintk_store(), so wake any waiters as well. |
3934 |
*/ |
4314 |
*/ |
3935 |
__wake_up_klogd(PRINTK_PENDING_WAKEUP | PRINTK_PENDING_OUTPUT); |
4315 |
int val = PRINTK_PENDING_WAKEUP; |
|
|
4316 |
|
4317 |
if (printing_via_unlock) |
4318 |
val |= PRINTK_PENDING_OUTPUT; |
4319 |
__wake_up_klogd(val); |
3936 |
} |
4320 |
} |
3937 |
|
4321 |
|
3938 |
void printk_trigger_flush(void) |
4322 |
void printk_trigger_flush(void) |
3939 |
{ |
4323 |
{ |
|
|
4324 |
nbcon_wake_threads(); |
3940 |
defer_console_output(); |
4325 |
defer_console_output(); |
3941 |
} |
4326 |
} |
3942 |
|
4327 |
|