Skip to contentSkip to conversation

/proc/sysrq-trigger: accept multiple keys at once

PATCH Superseded Tomas Mudrunka 4 participants 21 messages Nov 13, 2023 – Nov 20, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

---
 drivers/tty/sysrq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/sysrq.c +4 -2
index 6b4a28bcf..bc5a679f6 100644
@@ -1154,10 +1154,12 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf+i))
 			return -EFAULT;
 		__handle_sysrq(c, false);
 	}
Signature · 1 line
2.42.1
#1 lore raw
Quoted 17 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

---
 drivers/tty/sysrq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/sysrq.c +0 -0
index 6b4a28bcf..bc5a679f6 100644
@@ -1154,10 +1154,12 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1162

Quoted 10 lines
drivers/tty/sysrq.c +4 -2
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf+i))

What did you just break where people would send a string and only relied on the first character being checked? This might not be ok to do.

Also, no documentation update?

thanks,

greg k-h

#2 lore raw
Quoted 2 lines · po 13. 11. 2023 v 19:33 Greg Kroah-Hartman <[email protected]> wrote:

What did you just break where people would send a string and only relied on the first character being checked? This might not be ok to do.

It truly might not be ok. But i hope you will not consider me impolite if i open further discussion. Is this actual use case for some people? I understand that it might be, but currently i can only think about this being done by mistake, rather than on purpose... are you aware of any software actually leveraging this feature?

Please also note that there is really good use case for this. if i do the REISUB bash loop as suggested, the bash will be killed during E or I and the rest of emergency procedure will not finish. Therefore i really think it makes sense to be able to pass whole sysrq batch to the kernel at once.

In case you are sure that this is a bad idea, i can suggest alternative approach. only activate the "bulk mode" when first character is '_' (underscore).
User would then be able to do
echo _reisub > /proc/sysrq-trigger

Would you prefer if i do it this way? In my opinion it does introduce little unnecessary complexity, to fix something that might arguably not be actual issue. I mean... we still have /dev/null in case people need to discard some extra characters. :-)
But if you think it's better to stay on safe side, i think it's viable option as well...

Quoted 1 line

Also, no documentation update?

Will fix this one in v2.

Quoted 3 lines

thanks,

greg k-h

#3 lore raw
Quoted 6 lines · Tomáš Mudruňka
Quoted 2 lines · po 13. 11. 2023 v 19:33 Greg Kroah-Hartman <[email protected]> wrote:

What did you just break where people would send a string and only relied on the first character being checked? This might not be ok to do.

It truly might not be ok. But i hope you will not consider me impolite if i open further discussion. Is this actual use case for some people?

It might be, we can't start doing different functionality just because we were previously ignoring all the other characters. Especially for a user/kernel api that is allowed to reboot the machine :)

Quoted 3 lines

I understand that it might be, but currently i can only think about this being done by mistake, rather than on purpose... are you aware of any software actually leveraging this feature?

I'm not, but there is a lot of userspace software out there...

Quoted 12 lines

Please also note that there is really good use case for this. if i do the REISUB bash loop as suggested, the bash will be killed during E or I and the rest of emergency procedure will not finish. Therefore i really think it makes sense to be able to pass whole sysrq batch to the kernel at once.

In case you are sure that this is a bad idea, i can suggest alternative approach. only activate the "bulk mode" when first character is '_' (underscore).
User would then be able to do
echo _reisub > /proc/sysrq-trigger

Quoted 6 lines

Would you prefer if i do it this way? In my opinion it does introduce little unnecessary complexity, to fix something that might arguably not be actual issue. I mean... we still have /dev/null in case people need to discard some extra characters. :-)
But if you think it's better to stay on safe side, i think it's viable option as well...

I think you are only going to be able to do this "mode switch" method as we can't potentially break existing systems. Your change should prevent that from happening, so at a quick glance, yes, this seems like the only way forward if this is needed at all (an independent question...)

thanks,

greg k-h

#4 lore raw

PATCH v2 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
 Documentation/admin-guide/sysrq.rst |  4 ++++
 drivers/tty/sysrq.c                 | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
Documentation/admin-guide/sysrq.rst +4 -0
index 51906e473..9d46a33e5 100644
@@ -79,6 +79,10 @@ On all
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively write key combo prepended by underscore. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +14 -3
index 6b4a28bcf..3455e6dd3 100644
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	char bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf+i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
maintainer
#5 lore raw
Quoted 37 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
  Documentation/admin-guide/sysrq.rst |  4 ++++
  drivers/tty/sysrq.c                 | 17 ++++++++++++++---
  2 files changed, 18 insertions(+), 3 deletions(-)
Documentation/admin-guide/sysrq.rst +4 -0
index 51906e473..9d46a33e5 100644
@@ -79,6 +79,10 @@ On all
 
  		echo t > /proc/sysrq-trigger
 
+	Alternatively write key combo prepended by underscore. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
  The :kbd:`<command key>` is case sensitive.
 
  What are the 'command' keys?
drivers/tty/sysrq.c +0 -0
index 6b4a28bcf..3455e6dd3 100644

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1158

Quoted 10 lines
drivers/tty/sysrq.c +2 -1
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
  #ifdef CONFIG_PROC_FS
  /*
   * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
   */
  static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
  				   size_t count, loff_t *ppos)
  {
-	if (count) {
+	char bulk = false;

bool

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1164

Quoted 7 lines
drivers/tty/sysrq.c +4 -1
+	size_t i;
+
+	for (i = 0; i < count; i++) {
  		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf+i))

spaces around +

Quoted 13 lines
drivers/tty/sysrq.c +8 -1
  			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
  	}
 
  	return count;
Signature · 2 lines
js
suse labs
#6 lore raw

PATCH v3 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
 Documentation/admin-guide/sysrq.rst |  4 ++++
 drivers/tty/sysrq.c                 | 19 +++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +4 -0
index 51906e473..9d46a33e5 100644
@@ -79,6 +79,10 @@ On all
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively write key combo prepended by underscore. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +15 -4
index 6b4a28bcf..367028b1e 100644
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
-		char c;
+	char bulk = false;
+	size_t i;
 
-		if (get_user(c, buf))
+	for (i = 0; i < count; i++) {
+		bool c;
+
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
maintainer
#7 lore raw
Quoted 6 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

Quoted 7 lines

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---

What has changed in v2, v3?

Quoted 30 lines
  Documentation/admin-guide/sysrq.rst |  4 ++++
  drivers/tty/sysrq.c                 | 19 +++++++++++++++----
  2 files changed, 19 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +4 -0
index 51906e473..9d46a33e5 100644
@@ -79,6 +79,10 @@ On all
 
  		echo t > /proc/sysrq-trigger
 
+	Alternatively write key combo prepended by underscore. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
  The :kbd:`<command key>` is case sensitive.
 
  What are the 'command' keys?
drivers/tty/sysrq.c +1 -0
index 6b4a28bcf..367028b1e 100644
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
  #ifdef CONFIG_PROC_FS
  /*
   * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
   */
  static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1162

Quoted 10 lines
drivers/tty/sysrq.c +4 -3
  				   size_t count, loff_t *ppos)
  {
-	if (count) {
-		char c;
+	char bulk = false;
+	size_t i;
 
-		if (get_user(c, buf))
+	for (i = 0; i < count; i++) {
+		bool c;

bool c?

Signature · 2 lines
js
suse labs
#8 lore raw

PATCH v4 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
 Documentation/admin-guide/sysrq.rst |  4 ++++
 drivers/tty/sysrq.c                 | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
Documentation/admin-guide/sysrq.rst +4 -0
index 51906e473..9d46a33e5 100644
@@ -79,6 +79,10 @@ On all
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively write key combo prepended by underscore. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +14 -3
index 6b4a28bcf..ad07bc812 100644
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
maintainer
#9 lore raw
Quoted 11 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

Quoted 6 lines
---
 Documentation/admin-guide/sysrq.rst |  4 ++++
 drivers/tty/sysrq.c                 | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

#10 lore raw

PATCH v5 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

 Documentation/admin-guide/sysrq.rst |  4 ++++
 drivers/tty/sysrq.c                 | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
Documentation/admin-guide/sysrq.rst +4 -0
index 51906e473..9d46a33e5 100644
@@ -79,6 +79,10 @@ On all
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively write key combo prepended by underscore. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +14 -3
index 6b4a28bcf..ad07bc812 100644
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
#11 lore raw

PATCH v6 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

 Documentation/admin-guide/sysrq.rst | 11 ++++++++++-
 drivers/tty/sysrq.c                 | 17 ++++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +10 -1
index 51906e473..e7a82cba7 100644
@@ -75,10 +75,19 @@ On other
 	submit a patch to be included in this section.
 
 On all
-	Write a character to /proc/sysrq-trigger.  e.g.::
+	Write single character to /proc/sysrq-trigger.
+	Only first character is interpreted, rest of string is ignored.
+	However it is not reccomended to write any extra characters
+	as the behavior is undefined and might change in the future versions.
+	e.g.::
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively write multiple keys combo prepended by underscore.
+	All characters are interpreted this way. e.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +14 -3
index 6b4a28bcf..ad07bc812 100644
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
maintainer
#12 lore raw
Quoted 28 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

  Documentation/admin-guide/sysrq.rst | 11 ++++++++++-
  drivers/tty/sysrq.c                 | 17 ++++++++++++++---
  2 files changed, 24 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +0 -0
index 51906e473..e7a82cba7 100644

Documentation/admin-guide/sysrq.rst On other · line 78

Quoted 5 lines
Documentation/admin-guide/sysrq.rst +1 -1
@@ -75,10 +75,19 @@ On other
  	submit a patch to be included in this section.
 
  On all
-	Write a character to /proc/sysrq-trigger.  e.g.::
+	Write single character to /proc/sysrq-trigger.

a single

Documentation/admin-guide/sysrq.rst On other · line 79

Quoted 1 line
Documentation/admin-guide/sysrq.rst +1 -0
+	Only first character is interpreted, rest of string is ignored.

the first; the rest of the string

Documentation/admin-guide/sysrq.rst On other · line 80

Quoted 1 line
Documentation/admin-guide/sysrq.rst +1 -0
+	However it is not reccomended to write any extra characters

However, <- comma
recommended

Documentation/admin-guide/sysrq.rst On other · line 82

Quoted 2 lines
Documentation/admin-guide/sysrq.rst +2 -0
+	as the behavior is undefined and might change in the future versions.
+	e.g.::

Even the original was lowercase. But it should be "E.g.::", right -- Greg/Jon?

Documentation/admin-guide/sysrq.rst On other · line 86

Quoted 4 lines
Documentation/admin-guide/sysrq.rst +1 -0
  		echo t > /proc/sysrq-trigger
 
+	Alternatively write multiple keys combo prepended by underscore.

Alternatively, <- comma
s/keys/characters/
an underscore

Documentation/admin-guide/sysrq.rst On other · line 87

Quoted 1 line
Documentation/admin-guide/sysrq.rst +1 -0
+	All characters are interpreted this way. e.g.::

This way, all characters are interpreted. (IMO this has a different meaning, but natives would have to tell us.)

Quoted 11 lines
Documentation/admin-guide/sysrq.rst +3 -0
+
+		echo _reisub > /proc/sysrq-trigger
+
  The :kbd:`<command key>` is case sensitive.
 
  What are the 'command' keys?
drivers/tty/sysrq.c +0 -0
index 6b4a28bcf..ad07bc812 100644

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1153

Quoted 4 lines
drivers/tty/sysrq.c +1 -0
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
  #ifdef CONFIG_PROC_FS
  /*
   * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.

If the first character written is

thanks,

Signature · 2 lines
js
suse labs
reviewer
#13 lore raw
Quoted 42 lines · Jiri Slaby
Quoted 28 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

  Documentation/admin-guide/sysrq.rst | 11 ++++++++++- drivers/tty/sysrq.c                 | 17 ++++++++++++++---

  2 files changed, 24 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +0 -0
index 51906e473..e7a82cba7 100644
@@ -75,10 +75,19 @@ On other
Quoted 4 lines

      submit a patch to be included in this section. On all
-    Write a character to /proc/sysrq-trigger.  e.g.::
+    Write single character to /proc/sysrq-trigger.

a single

Quoted 1 line

+    Only first character is interpreted, rest of string is ignored.

the first; the rest of the string

Quoted 1 line

+    However it is not reccomended to write any extra characters

Quoted 8 lines

However, <- comma
recommended

Quoted 2 lines

+    as the behavior is undefined and might change in the future versions. +    e.g.::

Even the original was lowercase. But it should be "E.g.::", right -- Greg/Jon?

or Randy?
Yes, you are correct.
All of your recommendations look good.
Thanks.

Quoted 29 lines
Quoted 2 lines

            echo t > /proc/sysrq-trigger
  +    Alternatively write multiple keys combo prepended by underscore.

Alternatively, <- comma
s/keys/characters/
an underscore

Quoted 1 line

+    All characters are interpreted this way. e.g.::

This way, all characters are interpreted. (IMO this has a different meaning, but natives would have to tell us.)

Quoted 10 lines
Documentation/admin-guide/sysrq.rst +3 -0
+
+        echo _reisub > /proc/sysrq-trigger
+

  The :kbd:<command key> is case sensitive.
    What are the 'command' keys?

drivers/tty/sysrq.c +0 -0
index 6b4a28bcf..ad07bc812 100644

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1153

Quoted 4 lines
drivers/tty/sysrq.c +1 -0
@@ -1150,16 +1150,27 @@ EXPORT_SYMBOL(unregister_sysrq_key);
   #ifdef CONFIG_PROC_FS
   /*
    * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * If first character in write is underscore, all characters are interpreted.

If the first character written is

thanks,

Signature · 1 line
~Randy
maintainer
#14 lore raw
Quoted 7 lines · Randy Dunlap
Quoted 5 lines
Quoted 2 lines

+    as the behavior is undefined and might change in the future versions. +    e.g.::

Even the original was lowercase. But it should be "E.g.::", right -- Greg/Jon?

or Randy?

Sure, thanks for stepping in.

Signature · 2 lines
js
suse labs
#15 lore raw

PATCH v7 1/1 /proc/sysrq-trigger: accept multiple keys at once

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
 Documentation/admin-guide/sysrq.rst | 11 ++++++++++-
 drivers/tty/sysrq.c                 | 18 +++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +10 -1
index 51906e473..fbe79d314 100644
@@ -75,10 +75,19 @@ On other
 	submit a patch to be included in this section.
 
 On all
-	Write a character to /proc/sysrq-trigger.  e.g.::
+	Write single character to /proc/sysrq-trigger.
+	Only the first character is processed, the rest of string is ignored.
+	However, it is not recommended to write any extra characters
+	as the behavior is undefined and might change in the future versions.
+	E.g.::
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively, write multiple characters prepended by underscore.
+	This way, all characters will be processed. E.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +15 -3
index 6b4a28bcf..5411351e4 100644
@@ -1150,16 +1150,28 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * Normally only the first character written is processed.
+ * If first character is underscore, all characters are processed.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
#16 lore raw

PATCH v8 1/1 /proc/sysrq-trigger: accept multiple keys at once

In reply to Jiri Slaby

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V7 -> V8: Added this list of changes
V6 -> V7: Fixed english in documentation
V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

 Documentation/admin-guide/sysrq.rst | 11 ++++++++++-
 drivers/tty/sysrq.c                 | 18 +++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +10 -1
index 51906e473..fbe79d314 100644
@@ -75,10 +75,19 @@ On other
 	submit a patch to be included in this section.
 
 On all
-	Write a character to /proc/sysrq-trigger.  e.g.::
+	Write single character to /proc/sysrq-trigger.
+	Only the first character is processed, the rest of string is ignored.
+	However, it is not recommended to write any extra characters
+	as the behavior is undefined and might change in the future versions.
+	E.g.::
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively, write multiple characters prepended by underscore.
+	This way, all characters will be processed. E.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +15 -3
index 6b4a28bcf..5411351e4 100644
@@ -1150,16 +1150,28 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * Normally only the first character written is processed.
+ * If first character is underscore, all characters are processed.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
#17 lore raw

PATCH v9 1/1 /proc/sysrq-trigger: accept multiple keys at once

In reply to Jiri Slaby

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V8 -> V9: Fixed english bit more
V7 -> V8: Added this list of changes
V6 -> V7: Fixed english in documentation
V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

 Documentation/admin-guide/sysrq.rst | 11 ++++++++++-
 drivers/tty/sysrq.c                 | 18 +++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +10 -1
index 51906e473..0042fa26b 100644
@@ -75,10 +75,19 @@ On other
 	submit a patch to be included in this section.
 
 On all
-	Write a character to /proc/sysrq-trigger.  e.g.::
+	Write a single character to /proc/sysrq-trigger.
+	Only the first character is processed, the rest of string is ignored.
+	However, it is not recommended to write any extra characters
+	as the behavior is undefined and might change in the future versions.
+	E.g.::
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively, write multiple characters prepended by underscore.
+	This way, all characters will be processed. E.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +15 -3
index 6b4a28bcf..5411351e4 100644
@@ -1150,16 +1150,28 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * Normally only the first character written is processed.
+ * If first character is underscore, all characters are processed.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
maintainer
#18 lore raw
Quoted 6 lines · Tomas Mudrunka

Just for convenience.
This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

Quoted 8 lines

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V8 -> V9: Fixed english bit more

Please check my comments to v6 more carefully once again. Plus:

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1153

Quoted 7 lines
drivers/tty/sysrq.c +1 -0
@@ -1150,16 +1150,28 @@ EXPORT_SYMBOL(unregister_sysrq_key);
  #ifdef CONFIG_PROC_FS
  /*
   * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * Normally only the first character written is processed.

Normally, <-- comma

drivers/tty/sysrq.c EXPORT_SYMBOL(unregister_sysrq_key); · line 1154

Quoted 1 line
drivers/tty/sysrq.c +1 -0
+ * If first character is underscore, all characters are processed.

the first
an underscore

Maybe it would make sense to prepend "However, " to this very sentence?

thanks,

Signature · 2 lines
js
suse labs
#19 lore raw

PATCH v10 1/1 /proc/sysrq-trigger: accept multiple keys at once

This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace (eg. bash or ssh) can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

---
V9 -> V10: More english fixes
V8 -> V9: Fixed english bit more
V7 -> V8: Added this list of changes
V6 -> V7: Fixed english in documentation
V5 -> V6: Documentation now has notice about undefined behavior V4 -> V5: Added this list of changes
V3 -> V4: Bulk is now bool instead of char (and fixed typo) V2 -> V3: Fixed code styling (and introduced typo)
V1 -> V2: Bulk mode only activated by underscore now, added docs

 Documentation/admin-guide/sysrq.rst | 11 ++++++++++-
 drivers/tty/sysrq.c                 | 19 ++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)
Documentation/admin-guide/sysrq.rst +10 -1
index 51906e473..2f2e5bd44 100644
@@ -75,10 +75,19 @@ On other
 	submit a patch to be included in this section.
 
 On all
-	Write a character to /proc/sysrq-trigger.  e.g.::
+	Write a single character to /proc/sysrq-trigger.
+	Only the first character is processed, the rest of the string is
+	ignored. However, it is not recommended to write any extra characters
+	as the behavior is undefined and might change in the future versions.
+	E.g.::
 
 		echo t > /proc/sysrq-trigger
 
+	Alternatively, write multiple characters prepended by underscore.
+	This way, all characters will be processed. E.g.::
+
+		echo _reisub > /proc/sysrq-trigger
+
 The :kbd:`<command key>` is case sensitive.
 
 What are the 'command' keys?
drivers/tty/sysrq.c +16 -3
index 6b4a28bcf..02217e3c9 100644
@@ -1150,16 +1150,29 @@ EXPORT_SYMBOL(unregister_sysrq_key);
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ * Normally, only the first character written is processed.
+ * However, if the first character is an underscore,
+ * all characters are processed.
  */
 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
 				   size_t count, loff_t *ppos)
 {
-	if (count) {
+	bool bulk = false;
+	size_t i;
+
+	for (i = 0; i < count; i++) {
 		char c;
 
-		if (get_user(c, buf))
+		if (get_user(c, buf + i))
 			return -EFAULT;
-		__handle_sysrq(c, false);
+
+		if (c == '_')
+			bulk = true;
+		else
+			__handle_sysrq(c, false);
+
+		if (!bulk)
+			break;
 	}
 
 	return count;
Signature · 1 line
2.42.1
maintainer Reviewed-by on v10 1/1
#20 lore raw
Quoted 11 lines · Tomas Mudrunka

This way we can do:
echo _reisub > /proc/sysrq-trigger
Instead of:
for i in r e i s u b; do echo "$i" > /proc/sysrq-trigger; done;

This can be very useful when trying to execute sysrq combo remotely or from userspace. When sending keys in multiple separate writes, userspace (eg. bash or ssh) can be killed before whole combo is completed. Therefore putting all keys in single write is more robust approach.

thanks,

Signature · 2 lines
js
suse labs