2022-10-19 20:36:26

by Jason Andryuk

[permalink] [raw]
Subject: [PATCH] Input: xen-kbdfront - drop keys to shrink modalias

xen kbdfront registers itself as being able to deliver *any* key since
it doesn't know what keys the backend may produce.

Unfortunately, the generated modalias gets too large and uevent creation
fails with -ENOMEM.

This can lead to gdm not using the keyboard since there is no seat
associated [1] and the debian installer crashing [2].

Trim the ranges of key capabilities by removing some BTN_* ranges.
While doing this, some neighboring undefined ranges are removed to trim
it further.

This removes:
BTN_DPAD_UP(0x220)..BTN_DPAD_RIGHT(0x223)
Empty space 0x224..0x229

Emtpy space 0x2bd..0x2bf
BTN_TRIGGER_HAPPY(0x2c0)..BTN_TRIGGER_HAPPY40(0x2e7)
Empty space 0x2e8..0x2ff

The modalias shrinks from 2082 to 1754 bytes.

[1] https://github.com/systemd/systemd/issues/22944
[2] https://lore.kernel.org/xen-devel/[email protected]/T/

Cc: Phillip Susi <[email protected]>
Cc: [email protected]
Signed-off-by: Jason Andryuk <[email protected]>
---
drivers/input/misc/xen-kbdfront.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
index 8d8ebdc2039b..23f37211be78 100644
--- a/drivers/input/misc/xen-kbdfront.c
+++ b/drivers/input/misc/xen-kbdfront.c
@@ -256,7 +256,14 @@ static int xenkbd_probe(struct xenbus_device *dev,
__set_bit(EV_KEY, kbd->evbit);
for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
__set_bit(i, kbd->keybit);
- for (i = KEY_OK; i < KEY_MAX; i++)
+ /* In theory we want to go KEY_OK..KEY_MAX, but that grows the
+ * modalias line too long. KEY_KBD_LCD_MENU5 is the last
+ * defined non-button key. There is a gap of buttons from
+ * BTN_DPAD_UP..BTN_DPAD_RIGHT and KEY_ALS_TOGGLE is the next
+ * defined. */
+ for (i = KEY_OK; i < BTN_DPAD_UP; i++)
+ __set_bit(i, kbd->keybit);
+ for (i = KEY_ALS_TOGGLE; i <= KEY_KBD_LCD_MENU5; i++)
__set_bit(i, kbd->keybit);

ret = input_register_device(kbd);
--
2.37.3


2022-10-20 08:36:56

by Mattijs Korpershoek

[permalink] [raw]
Subject: Re: [PATCH] Input: xen-kbdfront - drop keys to shrink modalias

On Wed, Oct 19, 2022 at 16:14, Jason Andryuk <[email protected]> wrote:

> xen kbdfront registers itself as being able to deliver *any* key since
> it doesn't know what keys the backend may produce.
>
> Unfortunately, the generated modalias gets too large and uevent creation
> fails with -ENOMEM.
>
> This can lead to gdm not using the keyboard since there is no seat
> associated [1] and the debian installer crashing [2].
>
> Trim the ranges of key capabilities by removing some BTN_* ranges.
> While doing this, some neighboring undefined ranges are removed to trim
> it further.
>
> This removes:
> BTN_DPAD_UP(0x220)..BTN_DPAD_RIGHT(0x223)
> Empty space 0x224..0x229
>
> Emtpy space 0x2bd..0x2bf
> BTN_TRIGGER_HAPPY(0x2c0)..BTN_TRIGGER_HAPPY40(0x2e7)
> Empty space 0x2e8..0x2ff
>
> The modalias shrinks from 2082 to 1754 bytes.
>
> [1] https://github.com/systemd/systemd/issues/22944
> [2] https://lore.kernel.org/xen-devel/[email protected]/T/
>
> Cc: Phillip Susi <[email protected]>
> Cc: [email protected]
> Signed-off-by: Jason Andryuk <[email protected]>

Reviewed-by: Mattijs Korpershoek <[email protected]>

> ---
> drivers/input/misc/xen-kbdfront.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> index 8d8ebdc2039b..23f37211be78 100644
> --- a/drivers/input/misc/xen-kbdfront.c
> +++ b/drivers/input/misc/xen-kbdfront.c
> @@ -256,7 +256,14 @@ static int xenkbd_probe(struct xenbus_device *dev,
> __set_bit(EV_KEY, kbd->evbit);
> for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
> __set_bit(i, kbd->keybit);
> - for (i = KEY_OK; i < KEY_MAX; i++)
> + /* In theory we want to go KEY_OK..KEY_MAX, but that grows the
> + * modalias line too long. KEY_KBD_LCD_MENU5 is the last
> + * defined non-button key. There is a gap of buttons from
> + * BTN_DPAD_UP..BTN_DPAD_RIGHT and KEY_ALS_TOGGLE is the next
> + * defined. */
> + for (i = KEY_OK; i < BTN_DPAD_UP; i++)
> + __set_bit(i, kbd->keybit);
> + for (i = KEY_ALS_TOGGLE; i <= KEY_KBD_LCD_MENU5; i++)
> __set_bit(i, kbd->keybit);
>
> ret = input_register_device(kbd);
> --
> 2.37.3

2022-10-20 12:50:18

by Jason Andryuk

[permalink] [raw]
Subject: Re: [PATCH] Input: xen-kbdfront - drop keys to shrink modalias

On Thu, Oct 20, 2022 at 4:31 AM Mattijs Korpershoek
<[email protected]> wrote:
>
> On Wed, Oct 19, 2022 at 16:14, Jason Andryuk <[email protected]> wrote:
>
> > xen kbdfront registers itself as being able to deliver *any* key since
> > it doesn't know what keys the backend may produce.
> >
> > Unfortunately, the generated modalias gets too large and uevent creation
> > fails with -ENOMEM.
> >
> > This can lead to gdm not using the keyboard since there is no seat
> > associated [1] and the debian installer crashing [2].
> >
> > Trim the ranges of key capabilities by removing some BTN_* ranges.
> > While doing this, some neighboring undefined ranges are removed to trim
> > it further.
> >
> > This removes:
> > BTN_DPAD_UP(0x220)..BTN_DPAD_RIGHT(0x223)
> > Empty space 0x224..0x229
> >
> > Emtpy space 0x2bd..0x2bf
> > BTN_TRIGGER_HAPPY(0x2c0)..BTN_TRIGGER_HAPPY40(0x2e7)
> > Empty space 0x2e8..0x2ff
> >
> > The modalias shrinks from 2082 to 1754 bytes.
> >
> > [1] https://github.com/systemd/systemd/issues/22944
> > [2] https://lore.kernel.org/xen-devel/[email protected]/T/
> >
> > Cc: Phillip Susi <[email protected]>
> > Cc: [email protected]
> > Signed-off-by: Jason Andryuk <[email protected]>
>
> Reviewed-by: Mattijs Korpershoek <[email protected]>

This patch doesn't work and needs to be withdrawn. My gdm/udev
workaround was still active when I tested, so that is why I had a
working keyboard. Sorry about that.

Now the question is, which additional keys can be omitted to trim the
modalias to an acceptable size?

Regards,
Jason

> > ---
> > drivers/input/misc/xen-kbdfront.c | 9 ++++++++-
> > 1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> > index 8d8ebdc2039b..23f37211be78 100644
> > --- a/drivers/input/misc/xen-kbdfront.c
> > +++ b/drivers/input/misc/xen-kbdfront.c
> > @@ -256,7 +256,14 @@ static int xenkbd_probe(struct xenbus_device *dev,
> > __set_bit(EV_KEY, kbd->evbit);
> > for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
> > __set_bit(i, kbd->keybit);
> > - for (i = KEY_OK; i < KEY_MAX; i++)
> > + /* In theory we want to go KEY_OK..KEY_MAX, but that grows the
> > + * modalias line too long. KEY_KBD_LCD_MENU5 is the last
> > + * defined non-button key. There is a gap of buttons from
> > + * BTN_DPAD_UP..BTN_DPAD_RIGHT and KEY_ALS_TOGGLE is the next
> > + * defined. */
> > + for (i = KEY_OK; i < BTN_DPAD_UP; i++)
> > + __set_bit(i, kbd->keybit);
> > + for (i = KEY_ALS_TOGGLE; i <= KEY_KBD_LCD_MENU5; i++)
> > __set_bit(i, kbd->keybit);
> >
> > ret = input_register_device(kbd);
> > --
> > 2.37.3

2022-10-20 13:45:08

by Jason Andryuk

[permalink] [raw]
Subject: Re: [PATCH] Input: xen-kbdfront - drop keys to shrink modalias

On Thu, Oct 20, 2022 at 8:21 AM Jason Andryuk <[email protected]> wrote:
>
> On Thu, Oct 20, 2022 at 4:31 AM Mattijs Korpershoek
> <[email protected]> wrote:
> >
> > On Wed, Oct 19, 2022 at 16:14, Jason Andryuk <[email protected]> wrote:
> >
> > > xen kbdfront registers itself as being able to deliver *any* key since
> > > it doesn't know what keys the backend may produce.
> > >
> > > Unfortunately, the generated modalias gets too large and uevent creation
> > > fails with -ENOMEM.
> > >
> > > This can lead to gdm not using the keyboard since there is no seat
> > > associated [1] and the debian installer crashing [2].
> > >
> > > Trim the ranges of key capabilities by removing some BTN_* ranges.
> > > While doing this, some neighboring undefined ranges are removed to trim
> > > it further.
> > >
> > > This removes:
> > > BTN_DPAD_UP(0x220)..BTN_DPAD_RIGHT(0x223)
> > > Empty space 0x224..0x229
> > >
> > > Emtpy space 0x2bd..0x2bf
> > > BTN_TRIGGER_HAPPY(0x2c0)..BTN_TRIGGER_HAPPY40(0x2e7)
> > > Empty space 0x2e8..0x2ff
> > >
> > > The modalias shrinks from 2082 to 1754 bytes.
> > >
> > > [1] https://github.com/systemd/systemd/issues/22944
> > > [2] https://lore.kernel.org/xen-devel/[email protected]/T/
> > >
> > > Cc: Phillip Susi <[email protected]>
> > > Cc: [email protected]
> > > Signed-off-by: Jason Andryuk <[email protected]>
> >
> > Reviewed-by: Mattijs Korpershoek <[email protected]>
>
> This patch doesn't work and needs to be withdrawn. My gdm/udev
> workaround was still active when I tested, so that is why I had a
> working keyboard. Sorry about that.
>
> Now the question is, which additional keys can be omitted to trim the
> modalias to an acceptable size?
>
> Regards,
> Jason
>
> > > ---
> > > drivers/input/misc/xen-kbdfront.c | 9 ++++++++-
> > > 1 file changed, 8 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/input/misc/xen-kbdfront.c b/drivers/input/misc/xen-kbdfront.c
> > > index 8d8ebdc2039b..23f37211be78 100644
> > > --- a/drivers/input/misc/xen-kbdfront.c
> > > +++ b/drivers/input/misc/xen-kbdfront.c
> > > @@ -256,7 +256,14 @@ static int xenkbd_probe(struct xenbus_device *dev,
> > > __set_bit(EV_KEY, kbd->evbit);
> > > for (i = KEY_ESC; i < KEY_UNKNOWN; i++)
> > > __set_bit(i, kbd->keybit);
> > > - for (i = KEY_OK; i < KEY_MAX; i++)
> > > + /* In theory we want to go KEY_OK..KEY_MAX, but that grows the
> > > + * modalias line too long. KEY_KBD_LCD_MENU5 is the last
> > > + * defined non-button key. There is a gap of buttons from
> > > + * BTN_DPAD_UP..BTN_DPAD_RIGHT and KEY_ALS_TOGGLE is the next
> > > + * defined. */
> > > + for (i = KEY_OK; i < BTN_DPAD_UP; i++)
> > > + __set_bit(i, kbd->keybit);
> > > + for (i = KEY_ALS_TOGGLE; i <= KEY_KBD_LCD_MENU5; i++)

Changing the upper bound to KEY_BRIGHTNESS_MENU works. That trims out
KEY_MACRO* and KEY_KBD_LCD_MENU*.

Something has to get trimmed out to bring the size down. These are
probably less common and okay to remove, but I'm just guessing.

Regards,
Jason