Skip to contentSkip to conversation

sysrq: Restore original console_loglevel when sysrq disabled

PATCH In review Petr Mladek 4 participants 6 messages Jan 11, 2019 – Jan 14, 2019 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sysrq: Restore original console_loglevel when sysrq disabled

The sysrq header line is printed with an increased loglevel to provide users some positive feedback.

The original loglevel is not restored when the sysrq operation is disabled. This bug was introduced in 2.6.12 (pre-git-history) by the commit ("Allow admin to enable only some of the Magic-Sysrq functions").

---
 drivers/tty/sysrq.c | 1 +
 1 file changed, 1 insertion(+)
drivers/tty/sysrq.c +1 -0
index 1f03078ec352..2e4e184cfaa6 100644
@@ -553,6 +553,7 @@ void __handle_sysrq(int key, bool check_mask)
 			op_p->handler(key);
 		} else {
 			pr_cont("This sysrq operation is disabled.\n");
+			console_loglevel = orig_log_level;
 		}
 	} else {
 		pr_cont("HELP : ");
Signature · 1 line
2.13.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Petr Mladek

The sysrq header line is printed with an increased loglevel to provide users some positive feedback.

The original loglevel is not restored when the sysrq operation is disabled. This bug was introduced in 2.6.12 (pre-git-history) by the commit ("Allow admin to enable only some of the Magic-Sysrq functions").

Good find, and the patch looks OK to me. A small comment below. FWIW,

---

A side note (nitpick, etc.); it's Friday night in here, I'm enjoying my beer; so maybe I'm wrong about the whole thing.

drivers/tty/sysrq.c void __handle_sysrq(int key, bool check_mask) · line 557

Quoted 6 lines
drivers/tty/sysrq.c +1 -0
@@ -553,6 +553,7 @@ void __handle_sysrq(int key, bool check_mask)
 			op_p->handler(key);
 		} else {
 			pr_cont("This sysrq operation is disabled.\n");
+			console_loglevel = orig_log_level;
 		}

This looks a bit racy.

When we do

	printk("FOO\n");
	console_loglevel = XYZ;

We don't have any real guarantees that printk("FOO\n") will print anything straight ahead. It is possible that console_sem is already locked and the owner is preempted, so by the time the console_sem owner picks up that FOO\n messages, console_loglevel is back to orig_log_level and suppress_message_printing() will just tell us to skip the message.

Do we need pr_cont() there? Maybe we can just have a normal pr_err() which would always tell that "key" sysrq is disabled? (we also would need to change the error message a bit).

	-ss
#2 lore raw
Quoted 10 lines · Sergey Senozhatsky
Quoted 7 lines · Petr Mladek

The sysrq header line is printed with an increased loglevel to provide users some positive feedback.

The original loglevel is not restored when the sysrq operation is disabled. This bug was introduced in 2.6.12 (pre-git-history) by the commit ("Allow admin to enable only some of the Magic-Sysrq functions").

Quoted 3 lines

Good find, and the patch looks OK to me. A small comment below. FWIW,

Thanks.

Quoted 25 lines

A side note (nitpick, etc.); it's Friday night in here, I'm enjoying my beer; so maybe I'm wrong about the whole thing.

drivers/tty/sysrq.c void __handle_sysrq(int key, bool check_mask) · line 557

Quoted 6 lines
drivers/tty/sysrq.c +1 -0
@@ -553,6 +553,7 @@ void __handle_sysrq(int key, bool check_mask)
 			op_p->handler(key);
 		} else {
 			pr_cont("This sysrq operation is disabled.\n");
+			console_loglevel = orig_log_level;
 		}

This looks a bit racy.

When we do

	printk("FOO\n");
	console_loglevel = XYZ;

We don't have any real guarantees that printk("FOO\n") will print anything straight ahead. It is possible that console_sem is already locked and the owner is preempted, so by the time the console_sem owner picks up that FOO\n messages, console_loglevel is back to orig_log_level and suppress_message_printing() will just tell us to skip the message.

Quoted 3 lines

Do we need pr_cont() there? Maybe we can just have a normal pr_err() which would always tell that "key" sysrq is disabled? (we also would need to change the error message a bit).

The same problem is with the sysrq header line. It uses the trick with console_loglevel by intention. We want to show it but it is not really an error message, see the commit fb144adc517d9ebe8fd ("sysrq: add commentary on why we use the console loglevel over using KERN_EMERG").

Best Regards,
Petr

PS: I am going to resend this patch as part of a patchset. I was working on one more fix. It looked independent and questionable. I wanted to send it as RFC separately but there is a clash in the end...

#3 lore raw
Quoted 3 lines · Petr Mladek

The same problem is with the sysrq header line. It uses the trick with console_loglevel by intention. We want to show it but it is not really an error message

May be.

I usually see it as an "error".

My case:
systemd sets sysrq on every boot to /lib/sysctl.d/50-default.conf
kernel.sysrq value, which I usually set to 1. But after every systemd package update I have to edit 50-default.conf again, because somebody concluded that overwriting /lib/sysctl.d/50-default.conf during package update was the right thing to do. So, occasionally, when I need to do sysrq all I get is "This sysrq operation is disabled" error. So I swear a lot, reboot the box, change the sysrq mask and try to reproduce the problem. /* I became familiar with "sysrq_always_enabled=1" just
recently. */

"This sysrq operation is disabled" is always bad news and is always not what I want to see.

	-ss
#4 lore raw
Quoted 21 lines · Sergey Senozhatsky
Quoted 3 lines · Petr Mladek

The same problem is with the sysrq header line. It uses the trick with console_loglevel by intention. We want to show it but it is not really an error message

May be.

I usually see it as an "error".

My case:
systemd sets sysrq on every boot to /lib/sysctl.d/50-default.conf
kernel.sysrq value, which I usually set to 1. But after every systemd package update I have to edit 50-default.conf again, because somebody concluded that overwriting /lib/sysctl.d/50-default.conf during package update was the right thing to do. So, occasionally, when I need to do sysrq all I get is "This sysrq operation is disabled" error. So I swear a lot, reboot the box, change the sysrq mask and try to reproduce the problem. /* I became familiar with "sysrq_always_enabled=1" just
recently. */

Quoted 2 lines

"This sysrq operation is disabled" is always bad news and is always not what I want to see.

It is a matter of taste and I do not have strong opinion about it. Anyway, changing the string should be a separate patch.

Best Regards,
Petr

Reviewed-by
#5 lore raw
In reply to Sergey Senozhatsky
Quoted 42 lines · On Fri, 11 Jan 2019 22:07:29 +0900 Sergey Senozhatsky…
Quoted 7 lines · Petr Mladek

The sysrq header line is printed with an increased loglevel to provide users some positive feedback.

The original loglevel is not restored when the sysrq operation is disabled. This bug was introduced in 2.6.12 (pre-git-history) by the commit ("Allow admin to enable only some of the Magic-Sysrq functions").

Good find, and the patch looks OK to me. A small comment below. FWIW,

---

A side note (nitpick, etc.); it's Friday night in here, I'm enjoying my beer; so maybe I'm wrong about the whole thing.

drivers/tty/sysrq.c void __handle_sysrq(int key, bool check_mask) · line 557

Quoted 6 lines
drivers/tty/sysrq.c +1 -0
@@ -553,6 +553,7 @@ void __handle_sysrq(int key, bool check_mask)
 			op_p->handler(key);
 		} else {
 			pr_cont("This sysrq operation is disabled.\n");
+			console_loglevel = orig_log_level;
 		}  

This looks a bit racy.

When we do

	printk("FOO\n");
	console_loglevel = XYZ;

We don't have any real guarantees that printk("FOO\n") will print anything straight ahead. It is possible that console_sem is already locked and the owner is preempted, so by the time the console_sem owner picks up that FOO\n messages, console_loglevel is back to orig_log_level and suppress_message_printing() will just tell us to skip the message.

Quoted 4 lines

Do we need pr_cont() there? Maybe we can just have a normal pr_err() which would always tell that "key" sysrq is disabled? (we also would need to change the error message a bit).

All this is for another patch and another discussion. This current patch keeps with what is there and fixes a missing reset of console_loglevel.

-- Steve