Skip to content

Commit 34767e5

Browse files
committed
Merge branch 'for-6.13-force-console' into for-linus
2 parents a961ec4 + da115c4 commit 34767e5

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

drivers/tty/sysrq.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ static void __sysrq_put_key_op(u8 key, const struct sysrq_key_op *op_p)
582582
void __handle_sysrq(u8 key, bool check_mask)
583583
{
584584
const struct sysrq_key_op *op_p;
585-
int orig_log_level;
586585
int orig_suppress_printk;
587586
int i;
588587

@@ -592,13 +591,12 @@ void __handle_sysrq(u8 key, bool check_mask)
592591
rcu_sysrq_start();
593592
rcu_read_lock();
594593
/*
595-
* Raise the apparent loglevel to maximum so that the sysrq header
596-
* is shown to provide the user with positive feedback. We do not
597-
* simply emit this at KERN_EMERG as that would change message
598-
* routing in the consumers of /proc/kmsg.
594+
* Enter in the force_console context so that sysrq header is shown to
595+
* provide the user with positive feedback. We do not simply emit this
596+
* at KERN_EMERG as that would change message routing in the consumers
597+
* of /proc/kmsg.
599598
*/
600-
orig_log_level = console_loglevel;
601-
console_loglevel = CONSOLE_LOGLEVEL_DEFAULT;
599+
printk_force_console_enter();
602600

603601
op_p = __sysrq_get_key_op(key);
604602
if (op_p) {
@@ -608,11 +606,11 @@ void __handle_sysrq(u8 key, bool check_mask)
608606
*/
609607
if (!check_mask || sysrq_on_mask(op_p->enable_mask)) {
610608
pr_info("%s\n", op_p->action_msg);
611-
console_loglevel = orig_log_level;
609+
printk_force_console_exit();
612610
op_p->handler(key);
613611
} else {
614612
pr_info("This sysrq operation is disabled.\n");
615-
console_loglevel = orig_log_level;
613+
printk_force_console_exit();
616614
}
617615
} else {
618616
pr_info("HELP : ");
@@ -630,7 +628,7 @@ void __handle_sysrq(u8 key, bool check_mask)
630628
}
631629
}
632630
pr_cont("\n");
633-
console_loglevel = orig_log_level;
631+
printk_force_console_exit();
634632
}
635633
rcu_read_unlock();
636634
rcu_sysrq_end();

include/linux/printk.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...);
166166
extern void __printk_deferred_enter(void);
167167
extern void __printk_deferred_exit(void);
168168

169+
extern void printk_force_console_enter(void);
170+
extern void printk_force_console_exit(void);
171+
169172
/*
170173
* The printk_deferred_enter/exit macros are available only as a hack for
171174
* some code paths that need to defer all printk console printing. Interrupts
@@ -229,6 +232,14 @@ static inline void printk_deferred_exit(void)
229232
{
230233
}
231234

235+
static inline void printk_force_console_enter(void)
236+
{
237+
}
238+
239+
static inline void printk_force_console_exit(void)
240+
{
241+
}
242+
232243
static inline int printk_ratelimit(void)
233244
{
234245
return 0;

kernel/printk/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ int devkmsg_sysctl_set_loglvl(const struct ctl_table *table, int write,
5353

5454
/* Flags for a single printk record. */
5555
enum printk_info_flags {
56+
/* always show on console, ignore console_loglevel */
57+
LOG_FORCE_CON = 1,
5658
LOG_NEWLINE = 2, /* text ended with a newline */
5759
LOG_CONT = 8, /* text is a fragment of a continuation line */
5860
};
@@ -90,6 +92,7 @@ bool printk_percpu_data_ready(void);
9092

9193
void defer_console_output(void);
9294
bool is_printk_legacy_deferred(void);
95+
bool is_printk_force_console(void);
9396

9497
u16 printk_parse_prefix(const char *text, int *level,
9598
enum printk_info_flags *flags);

kernel/printk/printk.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,11 @@ static void boot_delay_msec(int level)
13371337
{
13381338
unsigned long long k;
13391339
unsigned long timeout;
1340+
bool suppress = !is_printk_force_console() &&
1341+
suppress_message_printing(level);
13401342

1341-
if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING)
1342-
|| suppress_message_printing(level)) {
1343+
if ((boot_delay == 0 || system_state >= SYSTEM_RUNNING) || suppress)
13431344
return;
1344-
}
13451345

13461346
k = (unsigned long long)loops_per_msec * boot_delay;
13471347

@@ -2291,13 +2291,19 @@ int vprintk_store(int facility, int level,
22912291
if (dev_info)
22922292
flags |= LOG_NEWLINE;
22932293

2294+
if (is_printk_force_console())
2295+
flags |= LOG_FORCE_CON;
2296+
22942297
if (flags & LOG_CONT) {
22952298
prb_rec_init_wr(&r, reserve_size);
22962299
if (prb_reserve_in_last(&e, prb, &r, caller_id, PRINTKRB_RECORD_MAX)) {
22972300
text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size,
22982301
facility, &flags, fmt, args);
22992302
r.info->text_len += text_len;
23002303

2304+
if (flags & LOG_FORCE_CON)
2305+
r.info->flags |= LOG_FORCE_CON;
2306+
23012307
if (flags & LOG_NEWLINE) {
23022308
r.info->flags |= LOG_NEWLINE;
23032309
prb_final_commit(&e);
@@ -2965,6 +2971,7 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
29652971
struct printk_info info;
29662972
struct printk_record r;
29672973
size_t len = 0;
2974+
bool force_con;
29682975

29692976
/*
29702977
* Formatting extended messages requires a separate buffer, so use the
@@ -2983,9 +2990,13 @@ bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
29832990

29842991
pmsg->seq = r.info->seq;
29852992
pmsg->dropped = r.info->seq - seq;
2993+
force_con = r.info->flags & LOG_FORCE_CON;
29862994

2987-
/* Skip record that has level above the console loglevel. */
2988-
if (may_suppress && suppress_message_printing(r.info->level))
2995+
/*
2996+
* Skip records that are not forced to be printed on consoles and that
2997+
* has level above the console loglevel.
2998+
*/
2999+
if (!force_con && may_suppress && suppress_message_printing(r.info->level))
29893000
goto out;
29903001

29913002
if (is_extended) {

kernel/printk/printk_safe.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212

1313
#include "internal.h"
1414

15+
/* Context where printk messages are never suppressed */
16+
static atomic_t force_con;
17+
18+
void printk_force_console_enter(void)
19+
{
20+
atomic_inc(&force_con);
21+
}
22+
23+
void printk_force_console_exit(void)
24+
{
25+
atomic_dec(&force_con);
26+
}
27+
28+
bool is_printk_force_console(void)
29+
{
30+
return atomic_read(&force_con);
31+
}
32+
1533
static DEFINE_PER_CPU(int, printk_context);
1634

1735
/* Can be preempted by NMI. */

0 commit comments

Comments
 (0)