Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp607529pxb; Wed, 3 Nov 2021 09:21:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx5fNCALHUOym8h6J3PqnQnv99yPwV2TqqDyk+TERiA9pflUhGCxxDfr2B330aKX6sgxAj X-Received: by 2002:a50:e606:: with SMTP id y6mr34597974edm.270.1635956512229; Wed, 03 Nov 2021 09:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635956512; cv=none; d=google.com; s=arc-20160816; b=N/bBzorlJrSPeoX8n2reibt6rDnr5pEU4HwDpMTgwOOomH5CbWg75wUXaqGby9yolW AdlkvH/gSa2yi6imhnpYmYazVacoUzBOYBfdnb5PN1XhamEMPHk13g4Ip9up7JIvDdEr bm7u/+NOIGJJ7YT0EJnQ+gMOrG3HZjxwaxPi0/6rDEwl6dhzqmAixpi5hk9JdsvJwOLi /hAMT9R2s6d9VedtSrYVTXQRIOtzpTaWQfAM34Rvs2UyHg/13dCCqdNjgk6hBSjlFQm2 72pLDfsvEl0hjxa71vCx1bM5927E4UE5WucTz9rhnXmtyooLtzk46jdcZg5TSt6ngdjf zM0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=iCjeVfYz6wETfwEJAV/+3b2DLqRhaehr248C/uHKQL0=; b=Q3Mmxu68gFnxH+lVe1NDNLxMCpkfTES02QwD4M0FLXLLD8OVa4KlBJH8iukG8jiQjv 9w66LPmb6UTiVAL18svPjgmnvA6edL9INuzXeYX2bDy4c6w/qAbsNgGYgfHs0LDHU1YU HH2MtWuXuP+xLKgzgEr16F6fLvf+zVy5n9AGqTF9puzF+NlYKo98cbTTNqqeRykL3RlT PBO9aRKu9eWYJTuF/lp6x99YeFLiUv4XjJmPwbYO099dY0oMSliGhLiv6BKvrHrW7sSj sPjXTLiJeNBOGArK9+jv2jylK5C8GPxDTihjf+I/pjQh/3kRy/S6c7CgfsBo7+Tzpxu5 X+WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=qDB1TnGZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si4495250ejo.92.2021.11.03.09.21.26; Wed, 03 Nov 2021 09:21:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=qDB1TnGZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232804AbhKCQWU (ORCPT + 99 others); Wed, 3 Nov 2021 12:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232644AbhKCQWT (ORCPT ); Wed, 3 Nov 2021 12:22:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0978C061714; Wed, 3 Nov 2021 09:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To: Subject:Sender:Reply-To:Content-ID:Content-Description; bh=iCjeVfYz6wETfwEJAV/+3b2DLqRhaehr248C/uHKQL0=; b=qDB1TnGZpRw6Es4mZr5vFts/Zx s3hRcJ2FRewMCSAkiGT0Z/ZIzw1FnyADnp7UDsJodzRL7Iipjm5v/yZ7/BFtDcehTuX1zcK5MpeeC 52lubav5q79QwLMoAs20afijkqvaZo94HeJDfLqqtmQRXhTc27qhZbV+7jvkYnoVZBrGlldMvSZqp +fpxYeF4fxg9ZbX688787ueCmw3slJsSL0yH8fFTzRKaUYJNHgjgKJIakDFqzNdSIJZ8GyfTEAlRn rF5AyExLArBc88N01KIdsNKKnlfsxl+GMGA9MTz6KVi0A/4Qbg06n/zlAUVE0DETkz6ssIHuyH0jX S1TJgiqA==; Received: from [2601:1c0:6280:3f0::aa0b] by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1miIzD-005jYV-Ma; Wed, 03 Nov 2021 16:19:39 +0000 Subject: Re: [RFC] tty/sysrq: Add alternative SysRq key To: Andrzej Pietrasiewicz , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Cc: Greg Kroah-Hartman , Dmitry Torokhov , Jiri Slaby , kernel@collabora.com References: <20211103155438.11167-1-andrzej.p@collabora.com> From: Randy Dunlap Message-ID: Date: Wed, 3 Nov 2021 09:19:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20211103155438.11167-1-andrzej.p@collabora.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/3/21 8:54 AM, Andrzej Pietrasiewicz wrote: > There exist machines which don't have SysRq key at all, e.g. chromebooks. > > This patch allows configuring an alternative key to act as SysRq. Devices > which declare KEY_SYSRQ in their 'keybit' bitmap continue using KEY_SYSRQ, > but other devices use the alternative SysRq key instead, by default F10. > Which key is actually used can be modified with sysrq's module parameter. > > Signed-off-by: Andrzej Pietrasiewicz > --- > I'd like to resurrect an old thread regarding supporting alternative SysRq > key for machines which don't have a physical SysRq key at all. > > The old thread: > > https://www.spinics.net/lists/linux-input/msg67982.html > > I'm resending this patch, rebased onto v5.15. > > Any (new) thoughts about it? > Hi, Did you test it with this patch? > > drivers/tty/sysrq.c | 28 +++++++++++++++++++++++++--- > 1 file changed, 25 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c > index c911196ac893..6dd288e53ce9 100644 > --- a/drivers/tty/sysrq.c > +++ b/drivers/tty/sysrq.c > @@ -634,6 +634,7 @@ EXPORT_SYMBOL(handle_sysrq); > > #ifdef CONFIG_INPUT > static int sysrq_reset_downtime_ms; > +static unsigned short alternative_sysrq_key = KEY_F10; > > /* Simple translation table for the SysRq keys */ > static const unsigned char sysrq_xlate[KEY_CNT] = > @@ -653,6 +654,7 @@ struct sysrq_state { > unsigned int alt_use; > unsigned int shift; > unsigned int shift_use; > + unsigned short sys That line appears to need an ending ';'. Or maybe that line was truncated since 'sys' isn't used anywhere in this patch. > bool active; > bool need_reinject; > bool reinjecting; > @@ -802,10 +804,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->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->sysrq_key, 0); > input_inject_event(handle, EV_KEY, alt_code, 0); > input_inject_event(handle, EV_SYN, SYN_REPORT, 1); > > @@ -845,6 +847,7 @@ static bool sysrq_handle_keypress(struct sysrq_state *sysrq, > sysrq->shift = code; > break; > > +key_sysrq: > case KEY_SYSRQ: > if (value == 1 && sysrq->alt != KEY_RESERVED) { > sysrq->active = true; > @@ -867,11 +870,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->sysrq_key, sysrq->handle.dev->key); > > break; > > default: > + /* handle non-default sysrq key */ > + if (code == sysrq->sysrq_key) > + goto key_sysrq; > + > if (sysrq->active && value && value != 2) { > unsigned char c = sysrq_xlate[code]; > > @@ -970,6 +977,14 @@ static int sysrq_connect(struct input_handler *handler, > sysrq->handle.private = sysrq; > timer_setup(&sysrq->keyreset_timer, sysrq_do_reset, 0); > > + if (test_bit(KEY_SYSRQ, dev->keybit)) { > + sysrq->sysrq_key = KEY_SYSRQ; > + pr_info("%s: using default sysrq key [%x]\n", dev->name, KEY_SYSRQ); > + } else { > + sysrq->sysrq_key = alternative_sysrq_key; > + pr_info("%s: Using alternative sysrq key: [%x]\n", dev->name, sysrq->sysrq_key); > + } > + > error = input_register_handle(&sysrq->handle); > if (error) { > pr_err("Failed to register input sysrq handler, error %d\n", > @@ -1078,6 +1093,13 @@ 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(alternative_sysrq_key, ushort, 0644); > +MODULE_PARM_DESC(alternative_sysrq_key, > + "Alternative SysRq key for input devices that don't have SysRq key. F10 by default.\n" > + "Example\n" > + "Using F9 as SysRq:\n" > + "sysrq.alternative_sysrq_key=0x43\n"); > + > #else > > static inline void sysrq_register_handler(void) > -- ~Randy