public inbox for linux-input@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ned T. Crigler" <crigler@gmail.com>
To: Peter Seiderer <ps.report@gmx.net>
Cc: Christian Heusel <christian@heusel.eu>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	regressions@lists.linux.dev, Jeff LaBundy <jeff@labundy.com>,
	Benjamin Tissoires <bentiss@kernel.org>
Subject: Re: [REGRESSION] disabling and re-enabling magic sysrq fails after kernel 6.11
Date: Sun, 27 Oct 2024 10:02:24 -0700	[thread overview]
Message-ID: <Zx5yIEZwT5SxzCTx@xavtug> (raw)
In-Reply-To: <20241027163744.2d396c61@gmx.net>

Hi Peter, Christian,

On Sun, Oct 27, 2024 at 04:37:44PM +0100, Peter Seiderer wrote:
> Hello Ned, Christian, *,
> 
> On Sun, 27 Oct 2024 15:06:09 +0100, Christian Heusel <christian@heusel.eu> wrote:
> 
> > On 24/10/26 07:15PM, Ned T. Crigler wrote:
> > > Hi,
> >
> > Hey Ned,
> >
> > > It looks like starting with kernel 6.11, disabling and re-enabling
> > > magic
> > > sysrq fails with these errors in dmesg:
> > >
> > > kernel: input: input_handler_check_methods: only one event processing
> > > method can be defined (sysrq)
> > > kernel: sysrq: Failed to register input handler, error -22
> > >
> > > after doing:
> > >
> > > # echo 0 > /proc/sys/kernel/sysrq
> > > # echo 438 > /proc/sys/kernel/sysrq
> > > # echo 0 > /proc/sys/kernel/sysrq
> > > # echo 438 > /proc/sys/kernel/sysrq
> > > # echo 0 > /proc/sys/kernel/sysrq
> > > # echo 438 > /proc/sys/kernel/sysrq
> >
> > I have found that this issue is also present in the latest mainline
> > release and bisected it to the following commit:
> >
> >     d469647bafd9 ("Input: simplify event handling logic")
> >
> 
> After the mentioned commit a call sysrq_register_handler() -->
> input_register_handler(&sysrq_handler) with sysrq_handler.filter set
> will result in sysrq_handler.events set to input_handler_events_filter,
> see drivers/input/input.c (line 2607 to 2608):
> 
> 2596 int input_register_handler(struct input_handler *handler)
> 2597 {
> 2598         struct input_dev *dev;
> 2599         int error;
> 2600
> 2601         error = input_handler_check_methods(handler);
> 2602         if (error)
> 2603                 return error;
> 2604
> 2605         INIT_LIST_HEAD(&handler->h_list);
> 2606
> 2607         if (handler->filter)
> 2608                 handler->events = input_handler_events_filter;
> 2609         else if (handler->event)
> 2610                 handler->events = input_handler_events_default;
> 2611         else if (!handler->events)
> 2612                 handler->events = input_handler_events_null;
> 
> So the second call will fail at the check 'input_handler_check_methods(handler)'
> which only allows one method to be set, see drivers/input/input.c:
> 
> 2517 static int input_handler_check_methods(const struct input_handler *handler)
> 2518 {
> 2519         int count = 0;
> 2520
> 2521         if (handler->filter)
> 2522                 count++;
> 2523         if (handler->events)
> 2524                 count++;
> 2525         if (handler->event)
> 2526                 count++;
> 2527
> 2528         if (count > 1) {
> 2529                 pr_err("%s: only one event processing method can be defined      (%s)\n",
> 2530                        __func__, handler->name);
> 2531                 return -EINVAL;
> 2532         }
> 2533
> 2534         return 0;
> 2535 }
> 
> 
> A quick fix/hack for the sysrq case:
> 
> --- a/drivers/tty/sysrq.c
> +++ b/drivers/tty/sysrq.c
> @@ -1045,7 +1045,7 @@ static inline void sysrq_register_handler(void)
>         int error;
> 
>         sysrq_of_get_keyreset_config();
> -
> +       sysrq_handler.events = NULL;
>         error = input_register_handler(&sysrq_handler);
>         if (error)
>                 pr_err("Failed to register input handler, error %d", error);
> lines 1-13/13 (END)
> 
> Regards,
> Peter
> 

Thanks for tracking this down. It seems messy that the mentioned commit
changes input_register_handler to overwrite ->events for an internal purpose,
and callers may expect it to be unchanged, as sysrq does here by reusing
sysrq_handler.

-- 
Ned T. Crigler

> 
> > The additional authors / maintainers have been added to the recipients
> > lists.
> >
> > I hope I didn't overlook any pending fixes.
> >
> > > --
> > > Ned T. Crigler
> >
> > Cheers,
> > Chris
> 

  reply	other threads:[~2024-10-27 17:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-27  2:15 [REGRESSION] disabling and re-enabling magic sysrq fails after kernel 6.11 Ned T. Crigler
2024-10-27 14:06 ` Christian Heusel
2024-10-27 15:37   ` Peter Seiderer
2024-10-27 17:02     ` Ned T. Crigler [this message]
2024-10-28  5:30       ` Dmitry Torokhov
2024-10-28  8:38         ` Peter Seiderer
2024-10-29  0:58         ` Ned T. Crigler
2024-11-04 12:06         ` Christian Heusel
2024-11-05  5:43           ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zx5yIEZwT5SxzCTx@xavtug \
    --to=crigler@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=christian@heusel.eu \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jeff@labundy.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ps.report@gmx.net \
    --cc=regressions@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox