Skip to content

Commit 07a22b6

Browse files
committed
Revert "printk: add functions to prefer direct printing"
This reverts commit 2bb2b7b. The testing of 5.19 release candidates revealed missing synchronization between early and regular console functionality. It would be possible to start the console kthreads later as a workaround. But it is clear that console lock serialized console drivers between each other. It opens a big area of possible problems that were not considered by people involved in the development and review. printk() is crucial for debugging kernel issues and console output is very important part of it. The number of consoles is huge and a proper review would take some time. As a result it need to be reverted for 5.19. Link: https://lore.kernel.org/r/YrBdjVwBOVgLfHyb@alley Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20220623145157.21938-7-pmladek@suse.com
1 parent 5831788 commit 07a22b6

File tree

9 files changed

+2
-78
lines changed

9 files changed

+2
-78
lines changed

drivers/tty/sysrq.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ void __handle_sysrq(int key, bool check_mask)
578578

579579
rcu_sysrq_start();
580580
rcu_read_lock();
581-
printk_prefer_direct_enter();
582581
/*
583582
* Raise the apparent loglevel to maximum so that the sysrq header
584583
* is shown to provide the user with positive feedback. We do not
@@ -620,7 +619,6 @@ void __handle_sysrq(int key, bool check_mask)
620619
pr_cont("\n");
621620
console_loglevel = orig_log_level;
622621
}
623-
printk_prefer_direct_exit();
624622
rcu_read_unlock();
625623
rcu_sysrq_end();
626624

include/linux/printk.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ extern void __printk_safe_exit(void);
170170
#define printk_deferred_enter __printk_safe_enter
171171
#define printk_deferred_exit __printk_safe_exit
172172

173-
extern void printk_prefer_direct_enter(void);
174-
extern void printk_prefer_direct_exit(void);
175-
176173
extern bool pr_flush(int timeout_ms, bool reset_on_progress);
177174

178175
/*
@@ -225,14 +222,6 @@ static inline void printk_deferred_exit(void)
225222
{
226223
}
227224

228-
static inline void printk_prefer_direct_enter(void)
229-
{
230-
}
231-
232-
static inline void printk_prefer_direct_exit(void)
233-
{
234-
}
235-
236225
static inline bool pr_flush(int timeout_ms, bool reset_on_progress)
237226
{
238227
return true;

kernel/hung_task.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
127127
* complain:
128128
*/
129129
if (sysctl_hung_task_warnings) {
130-
printk_prefer_direct_enter();
131-
132130
if (sysctl_hung_task_warnings > 0)
133131
sysctl_hung_task_warnings--;
134132
pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n",
@@ -144,8 +142,6 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
144142

145143
if (sysctl_hung_task_all_cpu_backtrace)
146144
hung_task_show_all_bt = true;
147-
148-
printk_prefer_direct_exit();
149145
}
150146

151147
touch_nmi_watchdog();
@@ -208,17 +204,12 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
208204
}
209205
unlock:
210206
rcu_read_unlock();
211-
if (hung_task_show_lock) {
212-
printk_prefer_direct_enter();
207+
if (hung_task_show_lock)
213208
debug_show_all_locks();
214-
printk_prefer_direct_exit();
215-
}
216209

217210
if (hung_task_show_all_bt) {
218211
hung_task_show_all_bt = false;
219-
printk_prefer_direct_enter();
220212
trigger_all_cpu_backtrace();
221-
printk_prefer_direct_exit();
222213
}
223214

224215
if (hung_task_call_panic)

kernel/panic.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,6 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
579579
{
580580
disable_trace_on_warning();
581581

582-
printk_prefer_direct_enter();
583-
584582
if (file)
585583
pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS\n",
586584
raw_smp_processor_id(), current->pid, file, line,
@@ -610,8 +608,6 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
610608

611609
/* Just a warning, don't kill lockdep. */
612610
add_taint(taint, LOCKDEP_STILL_OK);
613-
614-
printk_prefer_direct_exit();
615611
}
616612

617613
#ifndef __WARN_FLAGS

kernel/printk/printk.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -362,34 +362,6 @@ static int console_msg_format = MSG_FORMAT_DEFAULT;
362362
static DEFINE_MUTEX(syslog_lock);
363363

364364
#ifdef CONFIG_PRINTK
365-
static atomic_t printk_prefer_direct = ATOMIC_INIT(0);
366-
367-
/**
368-
* printk_prefer_direct_enter - cause printk() calls to attempt direct
369-
* printing to all enabled consoles
370-
*
371-
* Since it is not possible to call into the console printing code from any
372-
* context, there is no guarantee that direct printing will occur.
373-
*
374-
* This globally effects all printk() callers.
375-
*
376-
* Context: Any context.
377-
*/
378-
void printk_prefer_direct_enter(void)
379-
{
380-
atomic_inc(&printk_prefer_direct);
381-
}
382-
383-
/**
384-
* printk_prefer_direct_exit - restore printk() behavior
385-
*
386-
* Context: Any context.
387-
*/
388-
void printk_prefer_direct_exit(void)
389-
{
390-
WARN_ON(atomic_dec_if_positive(&printk_prefer_direct) < 0);
391-
}
392-
393365
DECLARE_WAIT_QUEUE_HEAD(log_wait);
394366
/* All 3 protected by @syslog_lock. */
395367
/* the next printk record to read by syslog(READ) or /proc/kmsg */

kernel/rcu/tree_stall.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,6 @@ static void print_cpu_stall(unsigned long gps)
647647
* See Documentation/RCU/stallwarn.rst for info on how to debug
648648
* RCU CPU stall warnings.
649649
*/
650-
printk_prefer_direct_enter();
651650
trace_rcu_stall_warning(rcu_state.name, TPS("SelfDetected"));
652651
pr_err("INFO: %s self-detected stall on CPU\n", rcu_state.name);
653652
raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
@@ -685,7 +684,6 @@ static void print_cpu_stall(unsigned long gps)
685684
*/
686685
set_tsk_need_resched(current);
687686
set_preempt_need_resched();
688-
printk_prefer_direct_exit();
689687
}
690688

691689
static void check_cpu_stall(struct rcu_data *rdp)

kernel/reboot.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,9 @@ static int __orderly_reboot(void)
447447
ret = run_cmd(reboot_cmd);
448448

449449
if (ret) {
450-
printk_prefer_direct_enter();
451450
pr_warn("Failed to start orderly reboot: forcing the issue\n");
452451
emergency_sync();
453452
kernel_restart(NULL);
454-
printk_prefer_direct_exit();
455453
}
456454

457455
return ret;
@@ -464,7 +462,6 @@ static int __orderly_poweroff(bool force)
464462
ret = run_cmd(poweroff_cmd);
465463

466464
if (ret && force) {
467-
printk_prefer_direct_enter();
468465
pr_warn("Failed to start orderly shutdown: forcing the issue\n");
469466

470467
/*
@@ -474,7 +471,6 @@ static int __orderly_poweroff(bool force)
474471
*/
475472
emergency_sync();
476473
kernel_power_off();
477-
printk_prefer_direct_exit();
478474
}
479475

480476
return ret;
@@ -532,8 +528,6 @@ EXPORT_SYMBOL_GPL(orderly_reboot);
532528
*/
533529
static void hw_failure_emergency_poweroff_func(struct work_struct *work)
534530
{
535-
printk_prefer_direct_enter();
536-
537531
/*
538532
* We have reached here after the emergency shutdown waiting period has
539533
* expired. This means orderly_poweroff has not been able to shut off
@@ -550,8 +544,6 @@ static void hw_failure_emergency_poweroff_func(struct work_struct *work)
550544
*/
551545
pr_emerg("Hardware protection shutdown failed. Trying emergency restart\n");
552546
emergency_restart();
553-
554-
printk_prefer_direct_exit();
555547
}
556548

557549
static DECLARE_DELAYED_WORK(hw_failure_emergency_poweroff_work,
@@ -590,22 +582,18 @@ void hw_protection_shutdown(const char *reason, int ms_until_forced)
590582
{
591583
static atomic_t allow_proceed = ATOMIC_INIT(1);
592584

593-
printk_prefer_direct_enter();
594-
595585
pr_emerg("HARDWARE PROTECTION shutdown (%s)\n", reason);
596586

597587
/* Shutdown should be initiated only once. */
598588
if (!atomic_dec_and_test(&allow_proceed))
599-
goto out;
589+
return;
600590

601591
/*
602592
* Queue a backup emergency shutdown in the event of
603593
* orderly_poweroff failure
604594
*/
605595
hw_failure_emergency_poweroff(ms_until_forced);
606596
orderly_poweroff(true);
607-
out:
608-
printk_prefer_direct_exit();
609597
}
610598
EXPORT_SYMBOL_GPL(hw_protection_shutdown);
611599

kernel/watchdog.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
424424
/* Start period for the next softlockup warning. */
425425
update_report_ts();
426426

427-
printk_prefer_direct_enter();
428-
429427
pr_emerg("BUG: soft lockup - CPU#%d stuck for %us! [%s:%d]\n",
430428
smp_processor_id(), duration,
431429
current->comm, task_pid_nr(current));
@@ -444,8 +442,6 @@ static enum hrtimer_restart watchdog_timer_fn(struct hrtimer *hrtimer)
444442
add_taint(TAINT_SOFTLOCKUP, LOCKDEP_STILL_OK);
445443
if (softlockup_panic)
446444
panic("softlockup: hung tasks");
447-
448-
printk_prefer_direct_exit();
449445
}
450446

451447
return HRTIMER_RESTART;

kernel/watchdog_hld.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ static void watchdog_overflow_callback(struct perf_event *event,
135135
if (__this_cpu_read(hard_watchdog_warn) == true)
136136
return;
137137

138-
printk_prefer_direct_enter();
139-
140138
pr_emerg("Watchdog detected hard LOCKUP on cpu %d\n",
141139
this_cpu);
142140
print_modules();
@@ -157,8 +155,6 @@ static void watchdog_overflow_callback(struct perf_event *event,
157155
if (hardlockup_panic)
158156
nmi_panic(regs, "Hard LOCKUP");
159157

160-
printk_prefer_direct_exit();
161-
162158
__this_cpu_write(hard_watchdog_warn, true);
163159
return;
164160
}

0 commit comments

Comments
 (0)