Skip to contentSkip to conversation

Add configurable handler to execute a compound action

PATCH In review Andrzej Pietrasiewicz 3 participants 13 messages Aug 18, 2020 – Oct 3, 2020

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

v3 cover Add configurable handler to execute a compound action

This is a follow-up of this thread:

https://www.spinics.net/lists/linux-input/msg68446.html

It only touches DRM (dri-devel) in such a way that it changes the help message of sysrq_drm_fb_helper_restore_op, otherwise it is unrelated to DRM.

Patch 2/2 adds a configurable handler to execute a compound action.

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

ws:1000c

or

r:100eis:1000ub

An example of userspace that wants to perform a compound action is Chrome OS, where SysRq-X (pressed for the second time within a certain time period from the first time) causes showing the locked tasks, syncing, waiting a 1000 ms delay and crashing the system.

Since all the slots in the sysrq_key_table[] are already taken or reserved, patch 1/2 extends it to cover also capital letter versions.

v2..v3:
- eliminated compile error in !CONFIG_INPUT case (kernel test robot)

v1..v2:
- used toupper() instead of opencoding it (Jiri Slaby)
- updated help message of sysrq_drm_fb_helper_restore_op (Jiri Slaby)
- used unsigned int for specifying delays (Jiri Slaby)
- improved printed messages formatting (Jiri Slaby)

Andrzej Pietrasiewicz (2):
tty/sysrq: Extend the sysrq_key_table to cover capital letters tty/sysrq: Add configurable handler to execute a compound action

 Documentation/admin-guide/sysrq.rst |  11 +++
 drivers/gpu/drm/drm_fb_helper.c     |   2 +-
 drivers/tty/sysrq.c                 | 129 +++++++++++++++++++++++++++-
 include/linux/sysrq.h               |   1 +
 4 files changed, 140 insertions(+), 3 deletions(-)

base-commit: 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v3 1/2 tty/sysrq: Extend the sysrq_key_table to cover capital letters

All slots in sysrq_key_table[] are either used, reserved or at least commented with their intended use. This patch adds capital letter versions available, which means adding 26 more entries.

For already existing SysRq operations the user presses Alt-SysRq-<key>, and for the newly added ones Alt-Shift-SysRq-<key>.

---
 Documentation/admin-guide/sysrq.rst |  2 ++
 drivers/gpu/drm/drm_fb_helper.c     |  2 +-
 drivers/tty/sysrq.c                 | 49 +++++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 3 deletions(-)
Documentation/admin-guide/sysrq.rst +2 -0
index e6424d8c5846..67dfa4c29093 100644
@@ -79,6 +79,8 @@ On all
 
 		echo t > /proc/sysrq-trigger
 
+The :kbd:`<command key>` is case sensitive.
+
 What are the 'command' keys?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
drivers/gpu/drm/drm_fb_helper.c +1 -1
index 8697554ccd41..1543d9d10970 100644
@@ -325,7 +325,7 @@ static void drm_fb_helper_sysrq(int dummy1)
 
 static const struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
 	.handler = drm_fb_helper_sysrq,
-	.help_msg = "force-fb(V)",
+	.help_msg = "force-fb(v)",
 	.action_msg = "Restore framebuffer console",
 };
 #else
drivers/tty/sysrq.c +47 -2

96 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH v3 2/2 tty/sysrq: Add configurable handler to execute a compound action

In reply to Andrzej Pietrasiewicz

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

ws:1000c

or

r:100eis:1000ub

---
 Documentation/admin-guide/sysrq.rst |  9 ++++
 drivers/tty/sysrq.c                 | 82 ++++++++++++++++++++++++++++-
 include/linux/sysrq.h               |  1 +
 3 files changed, 91 insertions(+), 1 deletion(-)
Documentation/admin-guide/sysrq.rst +9 -0
index 67dfa4c29093..80bdd8bf9636 100644
@@ -32,6 +32,7 @@ to 1. Here is the list of possible values in /proc/sys/kernel/sysrq:
          64 =  0x40 - enable signalling of processes (term, kill, oom-kill)
         128 =  0x80 - allow reboot/poweroff
         256 = 0x100 - allow nicing of all RT tasks
+        512 = 0x200 - allow compound action
 
 You can set the value in the file by the following command::
 
@@ -148,6 +149,14 @@ Command	    Function
 
 ``z``	    Dump the ftrace buffer
 
+``C``	    Execute a predefined, compound action. The action is defined with
+	    sysrq.sysrq_compound_action module parameter, whose value contains known
+	    command keys (except ``C`` to prevent recursion). The command keys can
+	    be optionally followed by a colon and a number of milliseconds to wait
+	    after executing the last action. For example:
+
+	    sysrq.sysrq_compound_action=r:100eis:1000ub
+
 ``0``-``9`` Sets the console log level, controlling which kernel messages
             will be printed to your console. (``0``, for example would make
             it so that only emergency messages like PANICs or OOPSes would
drivers/tty/sysrq.c +81 -1

120 lines not on this page · raw message

include/linux/sysrq.h +1 -0
index 3a582ec7a2f1..6df4442f12a9 100644
@@ -28,6 +28,7 @@
 #define SYSRQ_ENABLE_SIGNAL	0x0040
 #define SYSRQ_ENABLE_BOOT	0x0080
 #define SYSRQ_ENABLE_RTNICE	0x0100
+#define SYSRQ_ENABLE_COMPOUND	0x0200
 
 struct sysrq_key_op {
 	void (* const handler)(int);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Re: [PATCH v3 2/2] tty/sysrq: Add configurable handler to execute a compound action

Quoted 9 lines · Andrzej Pietrasiewicz

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

Quoted 5 lines

ws:1000c

or

r:100eis:1000ub

A macro language for sysrq commands, who would have thought...

Anyway, _why_ would userland want to do something so crazy as this? What is the use-case here?

thanks,

greg k-h

#4 lore raw

Re: [PATCH v3 2/2] tty/sysrq: Add configurable handler to execute a compound action

Hi,

W dniu 02.10.2020 o 14:54, Greg Kroah-Hartman pisze:

Quoted 12 lines · Andrzej Pietrasiewicz
Quoted 11 lines

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

ws:1000c

Quoted 9 lines
Quoted 3 lines

or

r:100eis:1000ub

A macro language for sysrq commands, who would have thought...

Anyway, _why_ would userland want to do something so crazy as this? What is the use-case here?

A use-case is Chromebooks which do want to execute 'w', 's', wait 1000ms and then 'c' under one key combination. Having that supported upstream brings us one little step closer to those machines running upstream kernel.

Another argument for such a "macro language" is when a machine's system keeps degrading over time, possibly degrading (relatively) fast. "Raising Elephants Is So Utterly Boring" consists of 6 actions, each of which requires pressing several keys. The user might be unable to complete all the 6 steps, while a "macro" requires user's involvement for carrying out just one step.

Regards,

Andrzej

#5 lore raw

Re: [PATCH v3 2/2] tty/sysrq: Add configurable handler to execute a compound action

Quoted 21 lines · Andrzej Pietrasiewicz

Hi,

W dniu 02.10.2020 o 14:54, Greg Kroah-Hartman pisze:

Quoted 18 lines · Andrzej Pietrasiewicz
Quoted 9 lines

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

Quoted 5 lines

ws:1000c

or

r:100eis:1000ub

A macro language for sysrq commands, who would have thought...

Quoted 8 lines
Quoted 3 lines

Anyway, _why_ would userland want to do something so crazy as this? What is the use-case here?

A use-case is Chromebooks which do want to execute 'w', 's', wait 1000ms and then 'c' under one key combination. Having that supported upstream brings us one little step closer to those machines running upstream kernel.

Who is causing that to "execute"? Some daemon/program?

Quoted 6 lines

Another argument for such a "macro language" is when a machine's system keeps degrading over time, possibly degrading (relatively) fast. "Raising Elephants Is So Utterly Boring" consists of 6 actions, each of which requires pressing several keys. The user might be unable to complete all the 6 steps, while a "macro" requires user's involvement for carrying out just one step.

So you want to "preload" some commands ahead of time, for when you get in trouble?

These should just be debugging / last resort types of things, how regular are they being used in your systems?

thanks,

greg k-h

#6 lore raw

Re: [PATCH v3 2/2] tty/sysrq: Add configurable handler to execute a compound action

Hi,

W dniu 02.10.2020 o 16:02, Greg Kroah-Hartman pisze:

Quoted 26 lines · Andrzej Pietrasiewicz
Quoted 25 lines

Hi,

W dniu 02.10.2020 o 14:54, Greg Kroah-Hartman pisze:

Quoted 21 lines · Andrzej Pietrasiewicz
Quoted 9 lines

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

Quoted 5 lines

ws:1000c

or

r:100eis:1000ub

A macro language for sysrq commands, who would have thought...

Anyway, _why_ would userland want to do something so crazy as this? What is the use-case here?

Quoted 6 lines
Quoted 4 lines

A use-case is Chromebooks which do want to execute 'w', 's', wait 1000ms and then 'c' under one key combination. Having that supported upstream brings us one little step closer to those machines running upstream kernel.

Who is causing that to "execute"? Some daemon/program?

No, as far as I know they patch the kernel to change the behavior of Sysrq-x combination, so the "execution" is triggered by the user.

Quoted 10 lines
Quoted 7 lines

Another argument for such a "macro language" is when a machine's system keeps degrading over time, possibly degrading (relatively) fast. "Raising Elephants Is So Utterly Boring" consists of 6 actions, each of which requires pressing several keys. The user might be unable to complete all the 6 steps, while a "macro" requires user's involvement for carrying out just one step.

So you want to "preload" some commands ahead of time, for when you get in trouble

It can be said this way, yes.

Quoted 4 lines

These should just be debugging / last resort types of things, how regular are they being used in your systems?

The "REISUB" itself is a kind of a last resort thing.

It is true that it's not a very frequent situation, but does its being rare preclude having such a function in the kernel?

While preparing this patch I wanted it to be flexible, but perhaps it is too flexible for some reason? If the permissions of the module_param's sysfs entry were changed to 0444 would it be better? Then the compound action would still be configurable but only at boot time rather than at boot time _and_ runtime.

Regards,

Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Re: [PATCH v3 2/2] tty/sysrq: Add configurable handler to execute a compound action

Quoted 34 lines · Andrzej Pietrasiewicz

Hi,

W dniu 02.10.2020 o 16:02, Greg Kroah-Hartman pisze:

Quoted 31 lines · Andrzej Pietrasiewicz
Quoted 29 lines

Hi,

W dniu 02.10.2020 o 14:54, Greg Kroah-Hartman pisze:

Quoted 12 lines · Andrzej Pietrasiewicz
Quoted 11 lines

Userland might want to execute e.g. 'w' (show blocked tasks), followed by 's' (sync), followed by 1000 ms delay and then followed by 'c' (crash) upon a single magic SysRq. Or one might want to execute the famous "Raising Elephants Is So Utterly Boring" action. This patch adds a configurable handler, triggered with 'C', for this exact purpose. The user specifies the composition of the compound action using syntax similar to getopt, where each letter corresponds to an individual action and a colon followed by a number corresponds to a delay of that many milliseconds, e.g.:

ws:1000c

Quoted 9 lines
Quoted 3 lines

or

r:100eis:1000ub

A macro language for sysrq commands, who would have thought...

Anyway, _why_ would userland want to do something so crazy as this? What is the use-case here?

A use-case is Chromebooks which do want to execute 'w', 's', wait 1000ms and then 'c' under one key combination. Having that supported upstream brings us one little step closer to those machines running upstream kernel.

Quoted 4 lines
Quoted 1 line

Who is causing that to "execute"? Some daemon/program?

No, as far as I know they patch the kernel to change the behavior of Sysrq-x combination, so the "execution" is triggered by the user.

So this isn't coming from the chromeos team, so there is no guarantee that they will switch to this if it is merged?

Quoted 18 lines
Quoted 9 lines
Quoted 6 lines

Another argument for such a "macro language" is when a machine's system keeps degrading over time, possibly degrading (relatively) fast. "Raising Elephants Is So Utterly Boring" consists of 6 actions, each of which requires pressing several keys. The user might be unable to complete all the 6 steps, while a "macro" requires user's involvement for carrying out just one step.

So you want to "preload" some commands ahead of time, for when you get in trouble

It can be said this way, yes.

Quoted 4 lines

These should just be debugging / last resort types of things, how regular are they being used in your systems?

The "REISUB" itself is a kind of a last resort thing.

Quoted 8 lines

It is true that it's not a very frequent situation, but does its being rare preclude having such a function in the kernel?

While preparing this patch I wanted it to be flexible, but perhaps it is too flexible for some reason? If the permissions of the module_param's sysfs entry were changed to 0444 would it be better? Then the compound action would still be configurable but only at boot time rather than at boot time _and_ runtime.

I don't have an issue with it happening at runtime and boot time, just that this is adding additional complexity to the kernel (parsers are fun!) for no real-world user.

thanks,

greg k-h

#8 lore raw
In reply to Andrzej Pietrasiewicz
Quoted 3 lines · Andrzej Pietrasiewicz

This is a follow-up of this thread:

https://www.spinics.net/lists/linux-input/msg68446.html

lore.kernel.org is easier to pull stuff from :)

Anyway, what ever happened to this series? Is there a newer one somewhere?

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

W dniu 02.10.2020 o 14:33, Andrzej Pietrasiewicz pisze:

Quoted 11 lines

W dniu 02.10.2020 o 14:31, Greg Kroah-Hartman pisze:

Quoted 10 lines · Andrzej Pietrasiewicz
Quoted 3 lines

This is a follow-up of this thread:

https://www.spinics.net/lists/linux-input/msg68446.html

lore.kernel.org is easier to pull stuff from :)

Anyway, what ever happened to this series?  Is there a newer one somewhere?

Quoted 8 lines
Quoted 4 lines

thanks,

greg k-h

https://lkml.org/lkml/2020/8/18/440

Andrzej

Sorry about confusion.

This is the same thing, so there is nothing newer.

Andrzej

Acked-by
#11 lore raw
Quoted 17 lines · Andrzej Pietrasiewicz

W dniu 02.10.2020 o 14:33, Andrzej Pietrasiewicz pisze:

Quoted 16 lines

W dniu 02.10.2020 o 14:31, Greg Kroah-Hartman pisze:

Quoted 14 lines · Andrzej Pietrasiewicz
Quoted 3 lines

This is a follow-up of this thread:

https://www.spinics.net/lists/linux-input/msg68446.html

lore.kernel.org is easier to pull stuff from :)

Anyway, what ever happened to this series?  Is there a newer one somewhere?

thanks,

greg k-h

Quoted 7 lines
Quoted 3 lines

https://lkml.org/lkml/2020/8/18/440

Andrzej

Sorry about confusion.

This is the same thing, so there is nothing newer.

Maybe split out the s/V/v/ in drm so I can pick that up? Alternatively

Cheers, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Andrzej Pietrasiewicz

W dniu 02.10.2020 o 14:33, Andrzej Pietrasiewicz pisze:

Quoted 18 lines

W dniu 02.10.2020 o 14:31, Greg Kroah-Hartman pisze:

Quoted 5 lines · Andrzej Pietrasiewicz
Quoted 3 lines

This is a follow-up of this thread:

https://www.spinics.net/lists/linux-input/msg68446.html

Quoted 9 lines

lore.kernel.org is easier to pull stuff from :)

Anyway, what ever happened to this series?  Is there a newer one somewhere?

thanks,

greg k-h

https://lkml.org/lkml/2020/8/18/440

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Andrzej

Sorry about confusion.

This is the same thing, so there is nothing newer.

Maybe split out the s/V/v/ in drm so I can pick that up? Alternatively

I'll take the first patch now, the second one is a bit more odd...

thanks for the ack.

greg k-h