From nobody Tue Dec 30 15:11:18 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7473C4332F for ; Tue, 14 Nov 2023 12:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232742AbjKNMmE (ORCPT ); Tue, 14 Nov 2023 07:42:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjKNMmD (ORCPT ); Tue, 14 Nov 2023 07:42:03 -0500 Received: from harvie.cz (harvie.cz [77.87.242.242]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94BC1130; Tue, 14 Nov 2023 04:42:00 -0800 (PST) Received: from anemophobia.amit.cz (unknown [31.30.84.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by harvie.cz (Postfix) with ESMTPSA id B0038180064; Tue, 14 Nov 2023 13:41:59 +0100 (CET) From: Tomas Mudrunka To: gregkh@linuxfoundation.org Cc: corbet@lwn.net, jirislaby@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, tomas.mudrunka@gmail.com Subject: [PATCH v5] /proc/sysrq-trigger: accept multiple keys at once Date: Tue, 14 Nov 2023 13:41:52 +0100 Message-ID: <20231114124152.97010-1-tomas.mudrunka@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <2023111454-hypertext-anymore-f2a6@gregkh> References: <2023111454-hypertext-anymore-f2a6@gregkh> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Tomas Mudrunka --- 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(-) diff --git a/Documentation/admin-guide/sysrq.rst b/Documentation/admin-guid= e/sysrq.rst index 51906e473..9d46a33e5 100644 --- a/Documentation/admin-guide/sysrq.rst +++ b/Documentation/admin-guide/sysrq.rst @@ -79,6 +79,10 @@ On all =20 echo t > /proc/sysrq-trigger =20 + Alternatively write key combo prepended by underscore. e.g.:: + + echo _reisub > /proc/sysrq-trigger + The :kbd:`` is case sensitive. =20 What are the 'command' keys? diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 6b4a28bcf..ad07bc812 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -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 interpret= ed. */ static ssize_t write_sysrq_trigger(struct file *file, const char __user *b= uf, size_t count, loff_t *ppos) { - if (count) { + bool bulk =3D false; + size_t i; + + for (i =3D 0; i < count; i++) { char c; =20 - if (get_user(c, buf)) + if (get_user(c, buf + i)) return -EFAULT; - __handle_sysrq(c, false); + + if (c =3D=3D '_') + bulk =3D true; + else + __handle_sysrq(c, false); + + if (!bulk) + break; } =20 return count; --=20 2.42.1