ps/2 mouse stop responding in X, up to system crash

Hi!

Problem in short: In my usage scenario of X and mouse I got mouse stops working. If restart X session, functionality restores, if without restarting X plug in USB mouse, it moves the cursor, but after some time, or after plug-out system crushes.

I'm running
Code:
FreeBSD bsd15 15.0-RELEASE-p4 FreeBSD 15.0-RELEASE-p4 releng/15.0-n281010-8ef0ed690df2 GENERIC amd64
on Dell Latitude E6420. Here is ALPS Touchpad, that sadly still not recognized by psm(4).
So I've managed to configured it -- PS/2 mouse -- as close to expectations, as possible.

Related configs:
/etc/rc.conf
Code:
moused_enable="YES"
moused_flags="-3 -V"
This emulates third (middle button), and virtual scrolling, that I do not understand where and how to be used.

Resolution and acceleration, make it close to touchpad feeling, psm(4):
/boot/device.hints
Code:
hint.psm.0.flags="0x24"

Here I may say, that in conosole I have no problems. Problems arise in Xorg.
Xorg-related config:
/usr/local/etc/X11/xorg.conf.d/30-alps.conf
Code:
Section "InputClass"
        Identifier      "alps-as-mouse"
        Driver          "libinput"
        MatchProduct    "Generic PS/2 mouse"
        MatchIsPointer  "true"
        Option "ScrollMethod" "button"
        Option "NaturalScrolling" "true"
EndSection

Until there all feels ok, except that it's not touchpad, thus now edge scrolling and other things, but it can be used.
One thing is very annoing: tapping (mouse clicking) with palm, whet I typing text, Very annoying. For touchpad,
especially, synaptics, there is syndaemon, that listening for keypresses and disables tapping for a while. Moreover, in
linux (I mean Debian, do not know other defaults), for example, for years there defaults do not enable tapping, only physical keys.

Anyway, there no widespread tool for my case, when touchpad is detected as PS/2 mouse.
But I found a simple script for such task here
https://superuser.com/questions/1284275/disable-mouse-when-keyboard-key-is-pressed-in-linux
I adopted code for sh(1). With some experimenting code in my case it looks like this:
Code:
#!/usr/bin/env sh

DEBUG=0
PID_FILE="/tmp/mouseswd-sh.pid"

# start delay
SDELAY=1
# mouse off delay
MDELAY=1.5

#mouse
MNAME="Generic PS/2 mouse"
MID=$(xinput list --id-only "$MNAME")

#keyboard
KBNAME="AT keyboard"
KBID=$(xinput list --id-only "$KBNAME")

# key codes
LCTRL=37
RCTRL=105
LSHIFT=50
RSHIFT=62
LALT=64
RALT=108
LWIN=133
RWIN=134
MENU=135
VOLUP=123
VOLDOWN=122
VOLMUTE=121

wait_and_enable()
{
    sleep $MDELAY
    if [ "x$DEBUG" = "x1" ]
    then echo "Enabling mouse"
    fi
    xinput enable $MID
}

polite_exit()
{
    kill $(jobs -s) 2>/dev/null
    kill $(jobs -p) 2>/dev/null
    xinput enable $MID
    rm $PID_FILE

    if [ $# -gt 0 ]
    then
    echo Exiting by signal $1
    else
    echo Exiting ...
    fi
 
    exit
}

debug_on()
{
    DEBUG=1
}

debug_off()
{
    DEBUG=0
}

debug_toggle()
{
    DEBUG=$(($DEBUG^1))
}

readcmds()
{
    echo start readcmds...
 
    while read -p "Command:" c
    do
    echo got command $c
    case $c in
        "d"|"D")
        debug_toggle ;;
        "l"|"L")
        jobs -l ;;
        "s"|"S")
        xinput ;;
        "f"|"F")
        kill -USR1 `jobs -p`;;
    esac

    done
}



### main

trap debug_on USR1
trap debug_off USR2
trap "polite_exit 0"  EXIT
trap "polite_exit 1"  HUP
trap "polite_exit 2"  INT
trap "polite_exit 3"  QUIT
trap "polite_exit 9"  KILL
trap "polite_exit 15" TERM


#my PID
PID=$$
echo My pid is $PID
echo $PID > "$PID_FILE"

#pause
echo Wait a little...
sleep $SDELAY
echo Start

xinput test $KBID | while  read key event code
do
    if [ $DEBUG -eq 1 ]
    then
    echo got $key -- $event -- $code
    fi
  
    case $code in
    $LCTRL|$RCTRL|$LSHIFT|$RSHIFT|$LALT|$RALT|$LWIN|$RWIN|$MENU|$VOLUP|$VOLDOWN|$VOLMUTE)
        if [ $DEBUG -eq 1 ]
        then echo "modifier key $code"
        fi
        : ;;
    *)
        if [ $DEBUG -eq 1 ]
        then
        echo "other key  $code, disbling mouse"
        echo current jobs: $(jobs -p)
        #echo xinput job: $(pgrep -lf xinput)
        fi
        xinput disable $MID
        kill $(jobs -p) 2> /dev/null
        (wait_and_enable)& ;;
    esac
done

This code listens to key presses, disables mouse by xinput for a while. It does the job.

But there another problem: after some random time -- it may be a day, or an hour -- mouse stops working (in X).
Sympthoms:
* mouse cursor do not move
* in xinput output all devices enabled, like this
Code:
 taras@bsd15:~ % xinput
⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                  id=4    [slave  pointer  (2)]
⎜   ↳ System mouse                                id=7    [slave  pointer  (2)]
⎜   ↳ Generic PS/2 mouse                          id=11    [slave  pointer  (2)]
⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard                 id=5    [slave  keyboard (3)]
    ↳ System keyboard multiplexer                 id=6    [slave  keyboard (3)]
    ↳ Power Button                                id=8    [slave  keyboard (3)]
    ↳ Sleep Button                                id=9    [slave  keyboard (3)]
    ↳ AT keyboard                                 id=10    [slave  keyboard (3)]
    ↳ ACPI video extension                        id=12    [slave  keyboard (3)]
    ↳ ACPI video extension                        id=13    [slave  keyboard (3)]
* in Xorg.0.log
Code:
  1013.462] (II) event6  - Generic PS/2 mouse: device is a pointer
[  1017.749] (II) event6  - Generic PS/2 mouse: device removed
[  1019.553] (II) event6  - Generic PS/2 mouse: is tagged by udev as: Mouse
[  1019.558] (II) event6  - Generic PS/2 mouse: device is a pointer
[  1021.038] (II) event6  - Generic PS/2 mouse: device removed
[  1025.939] (II) event6  - Generic PS/2 mouse: not tagged as supported input device
[  1025.939] (II) event6  - not using input device '/dev/input/event6'.
[  1025.939] [dix] couldn't enable device 11
[  1027.403] [dix] couldn't enable device 11
[  1047.147] [dix] couldn't enable device 11
[  1065.241] [dix] couldn't enable device 11
[  1072.174] [dix] couldn't enable device 11
[  1078.280] [dix] couldn't enable device 11
Upper "II" messages -- normal work of that script, enabling and disabling mouse. "[dix]" messages indicates a problem.

At this time mouse works good in vtys, if switching to by Alt-Fx.
If now I restart X session, e.g. by logging off, I see working mouse already in Lightdm, and of course, later in logged session.
But if I do not want to exit X session and try to connect USB mouse to finish my work, It works some time,
but after some time, or (maybe, only if) USB mouse unplugged, system crashes, writing /var/crash/vmcore.N.
Usually there current process is moused, but not always.

Can you suggest something to cope with it? Debug output it steel greek to me. Maybe it's time to post it to some mailing list? I'm still not familiar with lists.

P.S. Of course, I'm curious, if problem is solely X-related, or X-port in FreeBSD related, or FreeBSD related. In linux touchpad working, so no such harsh use of on/off scenario.... But maybe I test that....
 
Does your situation change if you change sysctl kern.evdev.rcpt_mask (default: 12)?

I have below in my /etc/sysctl.conf and tried one by one to be uncommented when this sysctl with evdev support is introduced.
In this example, using 13 for it to allow my ELECOM HUGE PLUS trackball to work.

Code:
## evdev event generation settings for keyboards and mice.
## Set correlated bits to enable.
## The value is defined in sys/dev/evdev/evdev.h as
##    #define    EVDEV_RCPT_SYSMOUSE    (1<<0)
##    #define    EVDEV_RCPT_KBDMUX    (1<<1)
##    #define    EVDEV_RCPT_HW_MOUSE    (1<<2)
##    #define    EVDEV_RCPT_HW_KBD    (1<<3)
##    extern int evdev_rcpt_mask;
## respectively.
#
# kern.evdev.rcpt_mask=1    # bit0 (1<<0), via sysmouse
# kern.evdev.rcpt_mask=2    # bit1 (1<<1), via kbdmux
# kern.evdev.rcpt_mask=4    # bit2 (1<<2), direct USB mouse (ums)
# kern.evdev.rcpt_mask=8    # bit3 (1<<3), direct keyboard (atkbd and ukbd)
# kern.evdev.rcpt_mask=5    # Both bit2 and 0 (sysmouse and ums, no kbd)
# kern.evdev.rcpt_mask=6    # Both bit2 and 1 (ums and kbdmux)
# kern.evdev.rcpt_mask=7    # Bits2, 1, and 0 (ums, kbdmux and sysmouse)
# kern.evdev.rcpt_mask=9    # Bits3 and 0 (direct keyboard and sysmouse)
# kern.evdev.rcpt_mask=10    # Both bit3 and 1 (direct kbd and kbdmux)
# kern.evdev.rcpt_mask=11    # Bits3, 1, and 0 (HW kbd, kbdmux, sysmouse)
# kern.evdev.rcpt_mask=12    # Both bit3 and 2 (direct kbd and ums) default
kern.evdev.rcpt_mask=13    # Bits 3, 2 and 0 (HW kbd, ums and sysmouse)
# kern.evdev.rcpt_mask=14    # Bits 3, 2 and 1 (HW kbd, ums and kbdmux)
# kern.evdev.rcpt_mask=15    # All 4 bits
 
Does your situation change if you change sysctl kern.evdev.rcpt_mask (default: 12)?

I have below in my /etc/sysctl.conf and tried one by one to be uncommented when this sysctl with evdev support is introduced.
In this example, using 13 for it to allow my ELECOM HUGE PLUS trackball to work.

Code:
## evdev event generation settings for keyboards and mice.
## Set correlated bits to enable.
## The value is defined in sys/dev/evdev/evdev.h as
##    #define    EVDEV_RCPT_SYSMOUSE    (1<<0)
##    #define    EVDEV_RCPT_KBDMUX    (1<<1)
##    #define    EVDEV_RCPT_HW_MOUSE    (1<<2)
##    #define    EVDEV_RCPT_HW_KBD    (1<<3)
##    extern int evdev_rcpt_mask;
## respectively.
#
# kern.evdev.rcpt_mask=1    # bit0 (1<<0), via sysmouse
# kern.evdev.rcpt_mask=2    # bit1 (1<<1), via kbdmux
# kern.evdev.rcpt_mask=4    # bit2 (1<<2), direct USB mouse (ums)
# kern.evdev.rcpt_mask=8    # bit3 (1<<3), direct keyboard (atkbd and ukbd)
# kern.evdev.rcpt_mask=5    # Both bit2 and 0 (sysmouse and ums, no kbd)
# kern.evdev.rcpt_mask=6    # Both bit2 and 1 (ums and kbdmux)
# kern.evdev.rcpt_mask=7    # Bits2, 1, and 0 (ums, kbdmux and sysmouse)
# kern.evdev.rcpt_mask=9    # Bits3 and 0 (direct keyboard and sysmouse)
# kern.evdev.rcpt_mask=10    # Both bit3 and 1 (direct kbd and kbdmux)
# kern.evdev.rcpt_mask=11    # Bits3, 1, and 0 (HW kbd, kbdmux, sysmouse)
# kern.evdev.rcpt_mask=12    # Both bit3 and 2 (direct kbd and ums) default
kern.evdev.rcpt_mask=13    # Bits 3, 2 and 0 (HW kbd, ums and sysmouse)
# kern.evdev.rcpt_mask=14    # Bits 3, 2 and 1 (HW kbd, ums and kbdmux)
# kern.evdev.rcpt_mask=15    # All 4 bits
While I'm switching it on and of now, my "device 11" get's failed. :-) Look's like setting this bits can't avoid that.
But enabling sysmouse allows my to continue to write this answer.
Enabling sysmouse along with hw_mouse lead to bad expirience -- mouse events doubles, so pointer moves too fast.
I'll think about it in slightly other way: disabliing ps mouse, but enabling sysmouse.
 
Is the PS/2 mouse a real PS/2 mouse? With a USB/PS/2 converter plug, it's possible that the port has not enough power to feed a optical USB mouse and loses connection.
What's the reason to use PS/2?
 
Is the PS/2 mouse a real PS/2 mouse? With a USB/PS/2 converter plug, it's possible that the port has not enough power to feed a optical USB mouse and loses connection.
What's the reason to use PS/2?
No. As I have written, I have ALPS touchpad, than connected as PS/2 device. It consists of joistick, three buttons under it (under keyboard), and touchpad with two physical buttons. But as it not detected as touchpad, but as PS/2 mouse, it works like mouse with two buttons. (interesting, read later post, -- sysmouse can use middle, 2nd button)
 
Does your situation change if you change sysctl kern.evdev.rcpt_mask (default: 12)?

I have below in my /etc/sysctl.conf and tried one by one to be uncommented when this sysctl with evdev support is introduced.
In this example, using 13 for it to allow my ELECOM HUGE PLUS trackball to work.

Code:
## evdev event generation settings for keyboards and mice.
## Set correlated bits to enable.
## The value is defined in sys/dev/evdev/evdev.h as
##    #define    EVDEV_RCPT_SYSMOUSE    (1<<0)
##    #define    EVDEV_RCPT_KBDMUX    (1<<1)
##    #define    EVDEV_RCPT_HW_MOUSE    (1<<2)
##    #define    EVDEV_RCPT_HW_KBD    (1<<3)
##    extern int evdev_rcpt_mask;
## respectively.
#
# kern.evdev.rcpt_mask=1    # bit0 (1<<0), via sysmouse
# kern.evdev.rcpt_mask=2    # bit1 (1<<1), via kbdmux
# kern.evdev.rcpt_mask=4    # bit2 (1<<2), direct USB mouse (ums)
# kern.evdev.rcpt_mask=8    # bit3 (1<<3), direct keyboard (atkbd and ukbd)
# kern.evdev.rcpt_mask=5    # Both bit2 and 0 (sysmouse and ums, no kbd)
# kern.evdev.rcpt_mask=6    # Both bit2 and 1 (ums and kbdmux)
# kern.evdev.rcpt_mask=7    # Bits2, 1, and 0 (ums, kbdmux and sysmouse)
# kern.evdev.rcpt_mask=9    # Bits3 and 0 (direct keyboard and sysmouse)
# kern.evdev.rcpt_mask=10    # Both bit3 and 1 (direct kbd and kbdmux)
# kern.evdev.rcpt_mask=11    # Bits3, 1, and 0 (HW kbd, kbdmux, sysmouse)
# kern.evdev.rcpt_mask=12    # Both bit3 and 2 (direct kbd and ums) default
kern.evdev.rcpt_mask=13    # Bits 3, 2 and 0 (HW kbd, ums and sysmouse)
# kern.evdev.rcpt_mask=14    # Bits 3, 2 and 1 (HW kbd, ums and kbdmux)
# kern.evdev.rcpt_mask=15    # All 4 bits
First bonus of using sysmouse: that "Generic PS/2 mouse" may use two buttons, so for button scrolling by default 3rd (right) button used. Sysmouse by default use 2nd (center) button. Interesting.
 
so no I setup all for using sysmouse:
/etc/sysctl.conf
Code:
#hw keyboard and sysmouse
kern.evdev.rcpt_mask=9

One more xorg config file:
/usr/local/etc/X11/xorg.conf.d/31-alps-sysmouse.conf
Code:
Section "InputClass"
        Identifier      "alps-as-mouse"
        Driver          "libinput"
        MatchProduct    "System mouse"
        MatchIsPointer  "true"
        #Option "ScrollMethod" "button"
        Option "NaturalScrolling" "true"
EndSection

As I said, sysmouse use by default 2nd button for scroling. It's good. And, surprisingly, I can not disable it, to see, if 2nd button can be used alone (on ps/2 variant it silent).

Keep tesing...
 
Does your situation change if you change sysctl kern.evdev.rcpt_mask (default: 12)?

I have below in my /etc/sysctl.conf and tried one by one to be uncommented when this sysctl with evdev support is introduced.
In this example, using 13 for it to allow my ELECOM HUGE PLUS trackball to work.

Code:
## evdev event generation settings for keyboards and mice.
## Set correlated bits to enable.
## The value is defined in sys/dev/evdev/evdev.h as
##    #define    EVDEV_RCPT_SYSMOUSE    (1<<0)
##    #define    EVDEV_RCPT_KBDMUX    (1<<1)
##    #define    EVDEV_RCPT_HW_MOUSE    (1<<2)
##    #define    EVDEV_RCPT_HW_KBD    (1<<3)
##    extern int evdev_rcpt_mask;
## respectively.
#
# kern.evdev.rcpt_mask=1    # bit0 (1<<0), via sysmouse
# kern.evdev.rcpt_mask=2    # bit1 (1<<1), via kbdmux
# kern.evdev.rcpt_mask=4    # bit2 (1<<2), direct USB mouse (ums)
# kern.evdev.rcpt_mask=8    # bit3 (1<<3), direct keyboard (atkbd and ukbd)
# kern.evdev.rcpt_mask=5    # Both bit2 and 0 (sysmouse and ums, no kbd)
# kern.evdev.rcpt_mask=6    # Both bit2 and 1 (ums and kbdmux)
# kern.evdev.rcpt_mask=7    # Bits2, 1, and 0 (ums, kbdmux and sysmouse)
# kern.evdev.rcpt_mask=9    # Bits3 and 0 (direct keyboard and sysmouse)
# kern.evdev.rcpt_mask=10    # Both bit3 and 1 (direct kbd and kbdmux)
# kern.evdev.rcpt_mask=11    # Bits3, 1, and 0 (HW kbd, kbdmux, sysmouse)
# kern.evdev.rcpt_mask=12    # Both bit3 and 2 (direct kbd and ums) default
kern.evdev.rcpt_mask=13    # Bits 3, 2 and 0 (HW kbd, ums and sysmouse)
# kern.evdev.rcpt_mask=14    # Bits 3, 2 and 1 (HW kbd, ums and kbdmux)
# kern.evdev.rcpt_mask=15    # All 4 bits
Offtopic, but as comment to your rcpt_mask examples. Whet I experimenting with it, and set it to "14", therefore enabling both HW keboard and kbdmux, all works good generally, but xscreensaver, when really lock session, in login windows password string receives input from two keyboards, so input doubles. When running alone, /usr/local/bin/xscreensaver-hacks/xscreensaver-auth, it works normal. Be warned.
 
While I still cannot artificially (running script enabling-disabling input device) reproduce failure, today sysmouse(4) failed too:

/var/log/Xorg.0.log
Code:
[  2061.191] (II) event1  - System mouse: is tagged by udev as: Mouse
[  2061.192] (II) event1  - System mouse: device is a pointer
[  2063.430] (II) event1  - System mouse: device removed
[  2065.730] (II) event1  - System mouse: is tagged by udev as: Mouse
[  2065.732] (II) event1  - System mouse: device is a pointer
[  2066.681] (II) event1  - System mouse: device removed
[  2076.138] (II) event1  - System mouse: not tagged as supported input device
[  2076.138] (II) event1  - not using input device '/dev/input/event1'.
[  2076.139] [dix] couldn't enable device 7
[  2089.097] [dix] couldn't enable device 7
[  2094.499] [dix] couldn't enable device 7
[  7886.051] [dix] couldn't enable device 7
[  7888.203] [dix] couldn't enable device 7

It's the same, as with PS/2 mouse
/var/log/Xorg.0.log
Code:
[ 21031.981] (II) event6  - Generic PS/2 mouse: device removed
[ 21033.122] (II) event6  - Generic PS/2 mouse: is tagged by udev as: Mouse
[ 21033.125] (II) event6  - Generic PS/2 mouse: device is a pointer
[ 21033.731] (II) event6  - Generic PS/2 mouse: device removed
[ 21039.176] (II) event6  - Generic PS/2 mouse: not tagged as supported input device
[ 21039.176] (II) event6  - not using input device '/dev/input/event6'.
[ 21039.176] [dix] couldn't enable device 11
[ 21042.227] [dix] couldn't enable device 11
[ 21046.911] [dix] couldn't enable device 11

Except that this time plugging/unplugging usb mouse do not lead to system crash.

Remaining question: is it problem of Xorg(1) or underlying moused(8)
Keep watching.
 
Back
Top