From patchwork Mon May 11 13:59:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11540907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB48C15AB for ; Mon, 11 May 2020 13:59:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD7D320801 for ; Mon, 11 May 2020 13:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729758AbgEKN70 (ORCPT ); Mon, 11 May 2020 09:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726068AbgEKN70 (ORCPT ); Mon, 11 May 2020 09:59:26 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2A7C061A0C; Mon, 11 May 2020 06:59:26 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 7128C2A094C From: Andrzej Pietrasiewicz To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Dmitry Torokhov , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , andrzej.p@collabora.com, kernel@collabora.com Subject: [PATCH 1/6] tty/sysrq: Remove linux,sysrq-reset-seq Date: Mon, 11 May 2020 15:59:13 +0200 Message-Id: <20200511135918.8203-2-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511135918.8203-1-andrzej.p@collabora.com> References: <20200511135918.8203-1-andrzej.p@collabora.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Nobody in the tree uses linux,sysrq-reset-seq in Device Tree source files. Remove the corresponding code. Signed-off-by: Andrzej Pietrasiewicz --- drivers/tty/sysrq.c | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 0dc3878794fd..93202fc24308 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -720,41 +720,6 @@ static void sysrq_detect_reset_sequence(struct sysrq_state *state, } } -#ifdef CONFIG_OF -static void sysrq_of_get_keyreset_config(void) -{ - u32 key; - struct device_node *np; - struct property *prop; - const __be32 *p; - - np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq"); - if (!np) { - pr_debug("No sysrq node found"); - return; - } - - /* Reset in case a __weak definition was present */ - sysrq_reset_seq_len = 0; - - of_property_for_each_u32(np, "keyset", prop, p, key) { - if (key == KEY_RESERVED || key > KEY_MAX || - sysrq_reset_seq_len == SYSRQ_KEY_RESET_MAX) - break; - - sysrq_reset_seq[sysrq_reset_seq_len++] = (unsigned short)key; - } - - /* Get reset timeout if any. */ - of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms); - - of_node_put(np); -} -#else -static void sysrq_of_get_keyreset_config(void) -{ -} -#endif static void sysrq_reinject_alt_sysrq(struct work_struct *work) { @@ -984,8 +949,6 @@ static inline void sysrq_register_handler(void) { int error; - sysrq_of_get_keyreset_config(); - error = input_register_handler(&sysrq_handler); if (error) pr_err("Failed to register input handler, error %d", error); From patchwork Mon May 11 13:59:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11540909 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB8F8913 for ; Mon, 11 May 2020 13:59:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91E4E2080C for ; Mon, 11 May 2020 13:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730169AbgEKN71 (ORCPT ); Mon, 11 May 2020 09:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730166AbgEKN70 (ORCPT ); Mon, 11 May 2020 09:59:26 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76EB1C061A0C; Mon, 11 May 2020 06:59:26 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id E301F2A095C From: Andrzej Pietrasiewicz To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Dmitry Torokhov , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , andrzej.p@collabora.com, kernel@collabora.com Subject: [PATCH 2/6] dt-bindings: input: Remove linux,sysrq-reset-seq binding Date: Mon, 11 May 2020 15:59:14 +0200 Message-Id: <20200511135918.8203-3-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511135918.8203-1-andrzej.p@collabora.com> References: <20200511135918.8203-1-andrzej.p@collabora.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Nobody in the tree uses linux,sysrq-reset-seq in Device Tree source files and there is no code depending on it. Remove the binding document. Signed-off-by: Andrzej Pietrasiewicz --- .../devicetree/bindings/input/input-reset.txt | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 Documentation/devicetree/bindings/input/input-reset.txt diff --git a/Documentation/devicetree/bindings/input/input-reset.txt b/Documentation/devicetree/bindings/input/input-reset.txt deleted file mode 100644 index 1ca6cc5ebf8e..000000000000 --- a/Documentation/devicetree/bindings/input/input-reset.txt +++ /dev/null @@ -1,33 +0,0 @@ -Input: sysrq reset sequence - -A simple binding to represent a set of keys as described in -include/uapi/linux/input.h. This is to communicate a sequence of keys to the -sysrq driver. Upon holding the keys for a specified amount of time (if -specified) the system is sync'ed and reset. - -Key sequences are global to the system but all the keys in a set must be coming -from the same input device. - -The /chosen node should contain a 'linux,sysrq-reset-seq' child node to define -a set of keys. - -Required property: -keyset: array of Linux keycodes, one keycode per cell. - -Optional property: -timeout-ms: duration keys must be pressed together in milliseconds before -generating a sysrq. If omitted the system is rebooted immediately when a valid -sequence has been recognized. - -Example: - - chosen { - linux,sysrq-reset-seq { - keyset = <0x03 - 0x04 - 0x0a>; - timeout-ms = <3000>; - }; - }; - -Would represent KEY_2, KEY_3 and KEY_9. From patchwork Mon May 11 13:59:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11540911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1354F15AB for ; Mon, 11 May 2020 13:59:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFAF2208CA for ; Mon, 11 May 2020 13:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730226AbgEKN71 (ORCPT ); Mon, 11 May 2020 09:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730180AbgEKN71 (ORCPT ); Mon, 11 May 2020 09:59:27 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6554C061A0C; Mon, 11 May 2020 06:59:26 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 63B0B2A09FA From: Andrzej Pietrasiewicz To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Dmitry Torokhov , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , andrzej.p@collabora.com, kernel@collabora.com Subject: [PATCH 3/6] tty/sysrq: Allow configurable SysRq key Date: Mon, 11 May 2020 15:59:15 +0200 Message-Id: <20200511135918.8203-4-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511135918.8203-1-andrzej.p@collabora.com> References: <20200511135918.8203-1-andrzej.p@collabora.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org There are existing machines which don't have SysRq key, e.g. chromebooks. This patch allows configuring which key acts as SysRq. The value is passed with sysrq's module parameter. Signed-off-by: Andrzej Pietrasiewicz --- drivers/tty/sysrq.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 93202fc24308..ebad9799fdc0 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -604,6 +604,7 @@ EXPORT_SYMBOL(handle_sysrq); #ifdef CONFIG_INPUT static int sysrq_reset_downtime_ms; +static unsigned short sysrq_key = KEY_SYSRQ; /* Simple translation table for the SysRq keys */ static const unsigned char sysrq_xlate[KEY_CNT] = @@ -735,10 +736,10 @@ static void sysrq_reinject_alt_sysrq(struct work_struct *work) /* Simulate press and release of Alt + SysRq */ input_inject_event(handle, EV_KEY, alt_code, 1); - input_inject_event(handle, EV_KEY, KEY_SYSRQ, 1); + input_inject_event(handle, EV_KEY, sysrq_key, 1); input_inject_event(handle, EV_SYN, SYN_REPORT, 1); - input_inject_event(handle, EV_KEY, KEY_SYSRQ, 0); + input_inject_event(handle, EV_KEY, sysrq_key, 0); input_inject_event(handle, EV_KEY, alt_code, 0); input_inject_event(handle, EV_SYN, SYN_REPORT, 1); @@ -770,6 +771,7 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq, } break; +key_sysrq: case KEY_SYSRQ: if (value == 1 && sysrq->alt != KEY_RESERVED) { sysrq->active = true; @@ -790,11 +792,15 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq, * triggering print screen function. */ if (sysrq->active) - clear_bit(KEY_SYSRQ, sysrq->handle.dev->key); + clear_bit(sysrq_key, sysrq->handle.dev->key); break; default: + /* handle non-default sysrq key */ + if (code == sysrq_key) + goto key_sysrq; + if (sysrq->active && value && value != 2) { sysrq->need_reinject = false; __handle_sysrq(sysrq_xlate[code], true); @@ -995,6 +1001,8 @@ module_param_array_named(reset_seq, sysrq_reset_seq, sysrq_reset_seq, module_param_named(sysrq_downtime_ms, sysrq_reset_downtime_ms, int, 0644); +module_param(sysrq_key, ushort, 0644); + #else static inline void sysrq_register_handler(void) From patchwork Mon May 11 13:59:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11540915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7CCB159A for ; Mon, 11 May 2020 13:59:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D971321973 for ; Mon, 11 May 2020 13:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730248AbgEKN72 (ORCPT ); Mon, 11 May 2020 09:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730214AbgEKN71 (ORCPT ); Mon, 11 May 2020 09:59:27 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 437FFC061A0C; Mon, 11 May 2020 06:59:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id D03052A0A13 From: Andrzej Pietrasiewicz To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Dmitry Torokhov , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , andrzej.p@collabora.com, kernel@collabora.com Subject: [PATCH 4/6] tty/sysrq: Extend the sysrq_key_table to cover capital letters Date: Mon, 11 May 2020 15:59:16 +0200 Message-Id: <20200511135918.8203-5-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511135918.8203-1-andrzej.p@collabora.com> References: <20200511135918.8203-1-andrzej.p@collabora.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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-, and for the newly added ones Alt-Shift-SysRq-. Signed-off-by: Andrzej Pietrasiewicz --- drivers/tty/sysrq.c | 49 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index ebad9799fdc0..ab4121a446b4 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -440,7 +440,7 @@ static struct sysrq_key_op sysrq_unrt_op = { /* Key Operations table and lock */ static DEFINE_SPINLOCK(sysrq_key_table_lock); -static struct sysrq_key_op *sysrq_key_table[36] = { +static struct sysrq_key_op *sysrq_key_table[62] = { &sysrq_loglevel_op, /* 0 */ &sysrq_loglevel_op, /* 1 */ &sysrq_loglevel_op, /* 2 */ @@ -497,6 +497,32 @@ static 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 +534,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; @@ -622,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; @@ -771,11 +801,21 @@ 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; + key_sysrq: 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. @@ -802,8 +842,13 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq, goto key_sysrq; 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) + if (c >= 'a' && c <= 'z') + c &= ~(1 << 5); /* to uppercase */ + __handle_sysrq(c, true); } break; } From patchwork Mon May 11 13:59:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11540913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FD33186E for ; Mon, 11 May 2020 13:59:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92D2520736 for ; Mon, 11 May 2020 13:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730236AbgEKN72 (ORCPT ); Mon, 11 May 2020 09:59:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730180AbgEKN71 (ORCPT ); Mon, 11 May 2020 09:59:27 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4D85C061A0C; Mon, 11 May 2020 06:59:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 451452A0A01 From: Andrzej Pietrasiewicz To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Dmitry Torokhov , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , andrzej.p@collabora.com, kernel@collabora.com Subject: [PATCH 5/6] tty/sysrq: Add configurable handler to signal a process Date: Mon, 11 May 2020 15:59:17 +0200 Message-Id: <20200511135918.8203-6-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511135918.8203-1-andrzej.p@collabora.com> References: <20200511135918.8203-1-andrzej.p@collabora.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Some userland might want to implement a policy to signal a configured process with a configured signal. This patch adds necessary kernel-side infrastructure and the newly added handler is triggered with Alt-Shift-SysRq-s. Optionally the userland can also specify the expected name of parent process of the victim. Signed-off-by: Andrzej Pietrasiewicz Reported-by: kbuild test robot --- drivers/tty/sysrq.c | 123 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index ab4121a446b4..a6e91e4ae304 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -437,6 +437,15 @@ static struct sysrq_key_op sysrq_unrt_op = { .enable_mask = SYSRQ_ENABLE_RTNICE, }; +static void sysrq_signal_configured(int key); + +static struct sysrq_key_op sysrq_signal_configured_op = { + .handler = sysrq_signal_configured, + .help_msg = "signal-configured-process(S)", + .action_msg = "Signal configured process", + .enable_mask = SYSRQ_ENABLE_SIGNAL, +}; + /* Key Operations table and lock */ static DEFINE_SPINLOCK(sysrq_key_table_lock); @@ -515,7 +524,7 @@ static struct sysrq_key_op *sysrq_key_table[62] = { NULL, /* P */ NULL, /* Q */ NULL, /* R */ - NULL, /* S */ + &sysrq_signal_configured_op, /* S */ NULL, /* T */ NULL, /* U */ NULL, /* V */ @@ -633,6 +642,10 @@ EXPORT_SYMBOL(handle_sysrq); #ifdef CONFIG_INPUT static int sysrq_reset_downtime_ms; static unsigned short sysrq_key = KEY_SYSRQ; +static char *sysrq_signalled; +static char *sysrq_signalled_parent; +static char *sysrq_signal; +static int sysrq_signal_code; /* Simple translation table for the SysRq keys */ static const unsigned char sysrq_xlate[KEY_CNT] = @@ -751,6 +764,106 @@ static void sysrq_detect_reset_sequence(struct sysrq_state *state, } } +struct signal_search { + const char *name; + int code; +}; + +static void sysrq_str_to_signal(void) +{ + static const struct signal_search signals[] = { + {"SIGHUP", SIGHUP}, + {"SIGINT", SIGINT}, + {"SIGQUIT", SIGQUIT}, + {"SIGILL", SIGILL}, + {"SIGTRAP", SIGTRAP}, + {"SIGABRT", SIGABRT}, + {"SIGIOT", SIGIOT}, + {"SIGBUS", SIGBUS}, + {"SIGFPE", SIGFPE}, + {"SIGKILL", SIGKILL}, + {"SIGUSR1", SIGUSR1}, + {"SIGSEGV", SIGSEGV}, + {"SIGUSR2", SIGUSR2}, + {"SIGPIPE", SIGPIPE}, + {"SIGALRM", SIGALRM}, + {"SIGTERM", SIGTERM}, + {"SIGSTKFLT", SIGSTKFLT}, + {"SIGCHLD", SIGCHLD}, + {"SIGCONT", SIGCONT}, + {"SIGSTOP", SIGSTOP}, + {"SIGTSTP", SIGTSTP}, + {"SIGTTIN", SIGTTIN}, + {"SIGTTOU", SIGTTOU}, + {"SIGURG", SIGURG}, + {"SIGXCPU", SIGXCPU}, + {"SIGXFSZ", SIGXFSZ}, + {"SIGVTALRM", SIGVTALRM}, + {"SIGPROF", SIGPROF}, + {"SIGWINCH", SIGWINCH}, + {"SIGIO", SIGIO}, + {"SIGPOLL", SIGPOLL}, + {"SIGPWR", SIGPWR}, + {"SIGSYS", SIGSYS}, + }; + int i; + + if (!sysrq_signal) + return; + + for (i = 0; i < ARRAY_SIZE(signals); ++i) + if (!strcmp(signals[i].name, sysrq_signal)) + break; + + if (i >= ARRAY_SIZE(signals)) { + pr_err("Unknown signal name %s", sysrq_signal); + + return; + } + + sysrq_signal_code = signals[i].code; +} + +static void sysrq_signal_configured(int key) +{ + struct task_struct *p; + + sysrq_str_to_signal(); + + if (!sysrq_signalled) { + pr_err("Unconfigured process name for %s", + sysrq_signal_configured_op.help_msg); + + return; + } + + if (!sysrq_signal_code) { + pr_err("Unconfigured signal for %s", + sysrq_signal_configured_op.help_msg); + + return; + } + + read_lock(&tasklist_lock); + for_each_process(p) { + if (p->flags & (PF_KTHREAD | PF_EXITING)) + continue; + if (is_global_init(p)) + continue; + if (strncmp(p->comm, sysrq_signalled, TASK_COMM_LEN)) + continue; + if (sysrq_signalled_parent + && strncmp(p->parent->comm, sysrq_signalled_parent, + TASK_COMM_LEN)) + continue; + + pr_err("%s: signal %d %s pid %u tgid %u\n", __func__, + sysrq_signal_code, sysrq_signalled, p->pid, p->tgid); + do_send_sig_info(sysrq_signal_code, SEND_SIG_PRIV, p, true); + } + read_unlock(&tasklist_lock); +} + static void sysrq_reinject_alt_sysrq(struct work_struct *work) { @@ -1048,8 +1161,16 @@ module_param_named(sysrq_downtime_ms, sysrq_reset_downtime_ms, int, 0644); module_param(sysrq_key, ushort, 0644); +module_param(sysrq_signalled, charp, 0644); +module_param(sysrq_signalled_parent, charp, 0644); +module_param(sysrq_signal, charp, 0644); + #else +static void sysrq_signal_configured(int key) +{ +} + static inline void sysrq_register_handler(void) { } From patchwork Mon May 11 13:59:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11540917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7892159A for ; Mon, 11 May 2020 13:59:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAADB207FF for ; Mon, 11 May 2020 13:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730249AbgEKN73 (ORCPT ); Mon, 11 May 2020 09:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730180AbgEKN72 (ORCPT ); Mon, 11 May 2020 09:59:28 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E13C061A0C; Mon, 11 May 2020 06:59:28 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id B07652A0A21 From: Andrzej Pietrasiewicz To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: Dmitry Torokhov , Rob Herring , Greg Kroah-Hartman , Jiri Slaby , andrzej.p@collabora.com, kernel@collabora.com Subject: [PATCH 6/6] tty/sysrq: Add configurable handler to execute a compound action Date: Mon, 11 May 2020 15:59:18 +0200 Message-Id: <20200511135918.8203-7-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200511135918.8203-1-andrzej.p@collabora.com> References: <20200511135918.8203-1-andrzej.p@collabora.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Some 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 Signed-off-by: Andrzej Pietrasiewicz --- drivers/tty/sysrq.c | 73 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index a6e91e4ae304..bde8de2d5b17 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -446,6 +447,15 @@ static struct sysrq_key_op sysrq_signal_configured_op = { .enable_mask = SYSRQ_ENABLE_SIGNAL, }; +static void sysrq_action_compound(int key); + +static struct sysrq_key_op sysrq_action_compound_op = { + .handler = sysrq_action_compound, + .help_msg = "execute-compound-action(C)", + .action_msg = "Execute compound action", + .enable_mask = SYSRQ_ENABLE_SIGNAL, +}; + /* Key Operations table and lock */ static DEFINE_SPINLOCK(sysrq_key_table_lock); @@ -508,7 +518,7 @@ static struct sysrq_key_op *sysrq_key_table[62] = { &sysrq_ftrace_dump_op, /* z */ NULL, /* A */ NULL, /* B */ - NULL, /* C */ + &sysrq_action_compound_op, /* C */ NULL, /* D */ NULL, /* E */ NULL, /* F */ @@ -646,6 +656,7 @@ static char *sysrq_signalled; static char *sysrq_signalled_parent; static char *sysrq_signal; static int sysrq_signal_code; +static char *sysrq_compound_action; /* Simple translation table for the SysRq keys */ static const unsigned char sysrq_xlate[KEY_CNT] = @@ -864,6 +875,61 @@ static void sysrq_signal_configured(int key) read_unlock(&tasklist_lock); } +#define SYSRQ_COMPOUND_ACTION_VALIDATE 0 +#define SYSRQ_COMPOUND_ACTION_RUN 1 + +static int sysrq_process_compound_action(int pass) +{ + const char *action = sysrq_compound_action; + struct sysrq_key_op *op_p; + int ret, delay; + + while (*action) { + op_p = __sysrq_get_key_op(*action); + if (!op_p) + return -EINVAL; + + /* Don't allow calling ourselves recursively */ + if (op_p == &sysrq_action_compound_op) + return -EINVAL; + + if (pass == SYSRQ_COMPOUND_ACTION_RUN) + __handle_sysrq(*action, false); + + if (*++action == ':') { + ret = sscanf(action++, ":%d", &delay); + if (ret < 1) /* we want at least ":[0-9]" => 1 item */ + return -EINVAL; + + while (*action >= '0' && *action <= '9') + ++action; + if (pass == SYSRQ_COMPOUND_ACTION_RUN) + mdelay(delay); + } + } + + return 0; +} + +static void sysrq_action_compound(int key) +{ + if (!sysrq_compound_action) { + pr_err("Unconfigured compound action for %s", + sysrq_action_compound_op.help_msg); + + return; + } + + if (sysrq_process_compound_action(SYSRQ_COMPOUND_ACTION_VALIDATE)) { + pr_err("Incorrect compound action %s for %s", + sysrq_compound_action, + sysrq_action_compound_op.help_msg); + + return; + } + + sysrq_process_compound_action(SYSRQ_COMPOUND_ACTION_RUN); +} static void sysrq_reinject_alt_sysrq(struct work_struct *work) { @@ -1165,12 +1231,17 @@ module_param(sysrq_signalled, charp, 0644); module_param(sysrq_signalled_parent, charp, 0644); module_param(sysrq_signal, charp, 0644); +module_param(sysrq_compound_action, charp, 0644); #else static void sysrq_signal_configured(int key) { } +static void sysrq_action_compound(int key) +{ +} + static inline void sysrq_register_handler(void) { }