2020-08-18 11:33:01

by Andrzej Pietrasiewicz

[permalink] [raw]
Subject: [PATCH v3 0/2] 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
--
2.17.1


2020-08-18 11:35:09

by Andrzej Pietrasiewicz

[permalink] [raw]
Subject: [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>.

Signed-off-by: Andrzej Pietrasiewicz <[email protected]>
---
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(-)

diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guide/sysrq.rst
index e6424d8c5846..67dfa4c29093 100644
--- a/Documentation/admin-guide/sysrq.rst
+++ b/Documentation/admin-guide/sysrq.rst
@@ -79,6 +79,8 @@ On all

echo t > /proc/sysrq-trigger

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

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 8697554ccd41..1543d9d10970 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -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
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index a8e39b2cdd55..959f9e121cc6 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -19,6 +19,7 @@
#include <linux/sched/rt.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>
+#include <linux/ctype.h>
#include <linux/interrupt.h>
#include <linux/mm.h>
#include <linux/fs.h>
@@ -440,7 +441,7 @@ static const struct sysrq_key_op sysrq_unrt_op = {
/* Key Operations table and lock */
static DEFINE_SPINLOCK(sysrq_key_table_lock);

-static const struct sysrq_key_op *sysrq_key_table[36] = {
+static const struct sysrq_key_op *sysrq_key_table[62] = {
&sysrq_loglevel_op, /* 0 */
&sysrq_loglevel_op, /* 1 */
&sysrq_loglevel_op, /* 2 */
@@ -497,6 +498,32 @@ static const struct sysrq_key_op *sysrq_key_table[36] = {
/* y: May be registered on sparc64 for global register dump */
NULL, /* y */
&sysrq_ftrace_dump_op, /* z */
+ NULL, /* A */
+ NULL, /* B */
+ NULL, /* C */
+ NULL, /* D */
+ NULL, /* E */
+ NULL, /* F */
+ NULL, /* G */
+ NULL, /* H */
+ NULL, /* I */
+ NULL, /* J */
+ NULL, /* K */
+ NULL, /* L */
+ NULL, /* M */
+ NULL, /* N */
+ NULL, /* O */
+ NULL, /* P */
+ NULL, /* Q */
+ NULL, /* R */
+ NULL, /* S */
+ NULL, /* T */
+ NULL, /* U */
+ NULL, /* V */
+ NULL, /* W */
+ NULL, /* X */
+ NULL, /* Y */
+ NULL, /* Z */
};

/* key2index calculation, -1 on invalid index */
@@ -508,6 +535,8 @@ static int sysrq_key_table_key2index(int key)
retval = key - '0';
else if ((key >= 'a') && (key <= 'z'))
retval = key + 10 - 'a';
+ else if ((key >= 'A') && (key <= 'Z'))
+ retval = key + 36 - 'A';
else
retval = -1;
return retval;
@@ -621,6 +650,8 @@ struct sysrq_state {
unsigned long key_down[BITS_TO_LONGS(KEY_CNT)];
unsigned int alt;
unsigned int alt_use;
+ unsigned int shift;
+ unsigned int shift_use;
bool active;
bool need_reinject;
bool reinjecting;
@@ -805,10 +836,20 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq,
}
break;

+ case KEY_LEFTSHIFT:
+ case KEY_RIGHTSHIFT:
+ if (!value)
+ sysrq->shift = KEY_RESERVED;
+ else if (value != 2)
+ sysrq->shift = code;
+ break;
+
case KEY_SYSRQ:
if (value == 1 && sysrq->alt != KEY_RESERVED) {
sysrq->active = true;
sysrq->alt_use = sysrq->alt;
+ /* either RESERVED (for released) or actual code */
+ sysrq->shift_use = sysrq->shift;
/*
* If nothing else will be pressed we'll need
* to re-inject Alt-SysRq keysroke.
@@ -831,8 +872,12 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq,

default:
if (sysrq->active && value && value != 2) {
+ unsigned char c = sysrq_xlate[code];
+
sysrq->need_reinject = false;
- __handle_sysrq(sysrq_xlate[code], true);
+ if (sysrq->shift_use != KEY_RESERVED)
+ c = toupper(c);
+ __handle_sysrq(c, true);
}
break;
}
--
2.17.1

2020-10-02 12:35:44

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v3 0/2] Add configurable handler to execute a compound action

On Tue, Aug 18, 2020 at 01:28:23PM +0200, Andrzej Pietrasiewicz wrote:
> 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

2020-10-02 12:36:56

by Andrzej Pietrasiewicz

[permalink] [raw]
Subject: Re: [PATCH v3 0/2] Add configurable handler to execute a compound action

W dniu 02.10.2020 o 14:31, Greg Kroah-Hartman pisze:
> On Tue, Aug 18, 2020 at 01:28:23PM +0200, Andrzej Pietrasiewicz wrote:
>> 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
>

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

Andrzej

2020-10-02 12:39:12

by Andrzej Pietrasiewicz

[permalink] [raw]
Subject: Re: [PATCH v3 0/2] Add configurable handler to execute a compound action

W dniu 02.10.2020 o 14:33, Andrzej Pietrasiewicz pisze:
> W dniu 02.10.2020 o 14:31, Greg Kroah-Hartman pisze:
>> On Tue, Aug 18, 2020 at 01:28:23PM +0200, Andrzej Pietrasiewicz wrote:
>>> 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
>>
>
> https://lkml.org/lkml/2020/8/18/440
>
> Andrzej

Sorry about confusion.

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

Andrzej

2020-10-02 12:46:58

by Daniel Vetter

[permalink] [raw]
Subject: Re: [PATCH v3 0/2] Add configurable handler to execute a compound action

On Fri, Oct 02, 2020 at 02:36:33PM +0200, Andrzej Pietrasiewicz wrote:
> W dniu 02.10.2020 o?14:33, Andrzej Pietrasiewicz pisze:
> > W dniu 02.10.2020 o?14:31, Greg Kroah-Hartman pisze:
> > > On Tue, Aug 18, 2020 at 01:28:23PM +0200, Andrzej Pietrasiewicz wrote:
> > > > 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
> > >
> >
> > 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
Acked-by: Daniel Vetter <[email protected]> if Greg takes it all.

Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

2020-10-02 12:57:13

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v3 0/2] Add configurable handler to execute a compound action

On Fri, Oct 02, 2020 at 02:45:29PM +0200, Daniel Vetter wrote:
> On Fri, Oct 02, 2020 at 02:36:33PM +0200, Andrzej Pietrasiewicz wrote:
> > W dniu 02.10.2020 o?14:33, Andrzej Pietrasiewicz pisze:
> > > W dniu 02.10.2020 o?14:31, Greg Kroah-Hartman pisze:
> > > > On Tue, Aug 18, 2020 at 01:28:23PM +0200, Andrzej Pietrasiewicz wrote:
> > > > > 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
> > > >
> > >
> > > 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
> Acked-by: Daniel Vetter <[email protected]> if Greg takes it all.

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

thanks for the ack.

greg k-h