Bug 104382

Summary: From 1.19.6 on, X treats every device as an input device
Product: xorg Reporter: andreaskem
Component: Server/GeneralAssignee: Xorg Project Team <xorg-team>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: major    
Priority: medium CC: andyrtr, krinpaus, lordheavym, nick.diego, peter.hutterer
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description andreaskem 2017-12-24 11:04:29 UTC
Dear X team,

On the Arch Linux bug tracker, a user reported that the latest X server release 1.19.6 freezes the machine for them immediately after entering startx:

https://bugs.archlinux.org/task/56804

Apparently, 1.19.6 started to treat pretty much everything like an input device. On my machine:

$ grep 'Adding input device' /var/log/Xorg.0.log
[    20.574] (II) config/udev: Adding input device Power Button (/dev/input/event4)
[    20.674] (II) config/udev: Adding input device Video Bus (/dev/input/event1)
[    20.714] (II) config/udev: Adding input device Power Button (/dev/input/event2)
[    20.734] (II) config/udev: Adding input device Lid Switch (/dev/input/event3)
[    20.736] (II) config/udev: Adding input device HD-Audio Generic HDMI/DP,pcm=3 (/dev/input/event8)
[    20.738] (II) config/udev: Adding input device Microsoft Comfort Optical Mouse 1000 (/dev/input/event7)
[    20.890] (II) config/udev: Adding input device Microsoft Comfort Optical Mouse 1000 (/dev/input/mouse0)
[    20.891] (II) config/udev: Adding input device HDA Digital PCBeep (/dev/input/event9)
[    20.892] (II) config/udev: Adding input device HD-Audio Generic Mic (/dev/input/event10)
[    20.893] (II) config/udev: Adding input device HD-Audio Generic Headphone (/dev/input/event11)
[    20.895] (II) config/udev: Adding input device AT Translated Set 2 keyboard (/dev/input/event0)
[    20.927] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/event12)
[    20.971] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/mouse1)
[    20.972] (II) config/udev: Adding input device TPPS/2 IBM TrackPoint (/dev/input/event13)
[    21.021] (II) config/udev: Adding input device TPPS/2 IBM TrackPoint (/dev/input/mouse2)
[    21.068] (II) config/udev: Adding input device PC Speaker (/dev/input/event5)
[    21.069] (II) config/udev: Adding input device (unnamed) (/dev/ttyS0)
[    21.069] (II) config/udev: Adding input device (unnamed) (/dev/ttyS1)
[    21.070] (II) config/udev: Adding input device (unnamed) (/dev/ttyS2)
[    21.071] (II) config/udev: Adding input device (unnamed) (/dev/ttyS3)
[    21.072] (II) config/udev: Adding input device ThinkPad Extra Buttons (/dev/input/event6)
[    21.100] (II) config/udev: Adding input device (unnamed) (/dev/input/mice)
[    21.100] (II) config/udev: Adding input device (unnamed) (/dev/console)
[    21.101] (II) config/udev: Adding input device (unnamed) (/dev/ptmx)
[    21.101] (II) config/udev: Adding input device (unnamed) (/dev/tty)
[    21.102] (II) config/udev: Adding input device (unnamed) (/dev/tty0)
[    21.102] (II) config/udev: Adding input device (unnamed) (/dev/tty1)

Looking at the changelog for .6, an obvious candidate change that might have caused this is:
[xserver] config/udev: consider ID_INPUT_FOO=0 as 'unset'
https://cgit.freedesktop.org/xorg/xserver/commit/config/udev.c?h=server-1.19-branch&id=5a5b6d6cca469521daa6ac9087f3589b7489ab55

This commit changed the logic for identifying input devices by their udev attributes:

-    if (!udev_device_get_property_value(udev_device, "ID_INPUT")) {
+    value = udev_device_get_property_value(udev_device, "ID_INPUT");
+    if (value && !strcmp(value, "0")) {

The current code is therefore:

    value = udev_device_get_property_value(udev_device, "ID_INPUT");
    if (value && !strcmp(value, "0")) {
        LogMessageVerb(X_INFO, 10,
                       "config/udev: ignoring device %s without "
                       "property ID_INPUT set\n", path);
        return;
    }

Thus, a value == NULL will no longer return early. In effect, every device that does not have an ID_INPUT property set at all will be treated like an input device. The original bug reporter had a configuration for using libinput which was consequently applied to *all* devices including /dev/tty*, leading to major issues including a complete system freeze:

[ 22.002] (II) config/udev: Adding input device (unnamed) (/dev/ttyS0)
[ 22.002] (**) (unnamed): Applying InputClass "touchpad"
[ 22.002] (II) Using input driver 'libinput' for '(unnamed)'
[ 22.002] (EE) systemd-logind: failed to take device /dev/ttyS0: No such device
[ 22.002] (**) (unnamed): always reports core events
[ 22.002] (**) Option "Device" "/dev/ttyS0"
[ 22.002] (**) Option "_source" "server/udev"
[ 22.002] (II) ttyS0 - failed to create input device '/dev/ttyS0'.
[ 22.002] (EE) libinput: (unnamed): Failed to create a device for /dev/ttyS0
[ 22.002] (EE) PreInit returned 2 for "(unnamed)"
[ 22.002] (II) UnloadModule: "libinput"
...
[ 43.389] (EE) systemd-logind: failed to take device /dev/tty: Connection was disconnected before a reply was received
...
[ 43.389] (EE) systemd-logind: failed to take device /dev/tty0: Connection is closed
...
[ 43.390] (EE) xf86OpenSerial: Cannot open device /dev/tty0
Permission denied
...

The fix would appear to be very simple:

-    if (value && !strcmp(value, "0")) {
+    if (!value || !strcmp(value, "0")) {

Thank you for your support,

Andreas
Comment 1 Peter Hutterer 2018-01-05 01:59:01 UTC
https://patchwork.freedesktop.org/patch/196090/
Comment 2 Peter Hutterer 2018-01-08 21:52:20 UTC
merged as dbfbe58b94..a309323328  master -> master

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.