NetBSD Problem Report #47142

From wiz@yt.nih.at  Tue Oct 30 17:02:13 2012
Return-Path: <wiz@yt.nih.at>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id E594B63CAFB
	for <gnats-bugs@gnats.netbsd.org>; Tue, 30 Oct 2012 17:02:12 +0000 (UTC)
Message-Id: <20121030170058.9018939FEA1@yt.nih.at>
Date: Tue, 30 Oct 2012 18:00:58 +0100 (CET)
From: Thomas Klausner <wiz@NetBSD.org>
Reply-To: Thomas Klausner <wiz@NetBSD.org>
To: gnats-bugs@gnats.NetBSD.org
Subject: usbhidctl vs. SDL et al.
X-Send-Pr-Version: 3.95

>Number:         47142
>Category:       kern
>Synopsis:       usbhidctl vs. SDL et al.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 30 17:05:00 +0000 2012
>Last-Modified:  Wed Sep 30 10:05:00 +0000 2015
>Originator:     Thomas Klausner
>Release:        NetBSD 6.99.14
>Organization:
Curiosity is the very basis of education and if you tell me that 
curiosity killed the cat, I say only that the cat died nobly.
- Arnold Edinborough
>Environment:


System: NetBSD yt.nih.at 6.99.14 NetBSD 6.99.14 (YT) #27: Sat Oct 20 15:01:54 CEST 2012 wiz@yt.nih.at:/archive/cvs/src/sys/arch/amd64/compile/obj/YT amd64
Architecture: x86_64
Machine: amd64
>Description:
Programs using SDL and some others would hang during startup.
I've tracked it down to the reason that usbhidctl is started together with
my X session (.xinitrc). If that is still running, SDL hangs when trying
to access /dev/uhid0. Such a program can't even be killed with -9.

When I kill usbhidctl first, SDL-using programs start fine.

When I kill usbhidctl after starting an SDL-using programs (which hangs
trying to access /dev/uhid0), I get a kernel panic.
I don't see the panic, since I'm in X, but in the next boot's log I see
Oct 16 21:28:41 yt savecore: reboot after panic: 836 1835 1834 1833 1832 1831 1830 1829 1828 1827 1826 1825 1824 1823 1822 1821 1820 1819 1818 1817 1816 1815

-rw-------   1 root  wheel  8292230744 Oct 16 21:35 netbsd.2.core.gz
-rw-------   1 root  wheel      372043 Oct 16 21:35 netbsd.2.gz
exist, but netbsd.2.gz looks too small to be useful (separate issue).

This leaves me with some questions:
Why is /dev/uhid0 blocked when usbhidctl is active?
Why does SDL care, and not just try opening non-blocking?
Why can't I kill -9 such programs?
Why do I get a kernel panic (see above)?
>How-To-Repeat:
cat > .usbhidconf << EOF
Consumer:Play/Pause     1       mpc toggle
Consumer:Scan_Next_Track        1       mpc next
Consumer:Scan_Previous_Track    1       mpc prev
Consumer:Volume_Up      1       mixerctl -w outputs.master2++
Consumer:Volume_Down    1       mixerctl -w outputs.master2--
Consumer:Mute   1       mixerctl -w outputs.master7.mute--
EOF

usbhidctl -f 0 -c $(pwd)/.usbhidconf
cd /usr/pkgsrc/games/monsterz
make install
monsterz

(other SDL-using programs should be fine too)
>Fix:
Yes, please.

>Audit-Trail:
From: Kooda <kooda@upyum.com>
To: gnats-bugs@NetBSD.org
Cc: Youbi <youbidou@singularity.fr>
Subject: Re: kern/47142
Date: Thu, 13 Dec 2012 23:42:30 +0100

 Hello,

 I have a similar issue under netbsd-6, I use usbhidaction to use the
 multimedia keys of my usb keyboald and when I start a program that tries
 to use the uhid device, for example VisualBoyAdvance, it just freezes
 and I can’t kill it.

 If I kill usbhidaction, the program that was trying to use the device
 comes back to life and everything works well.

 But it’s not that simple… When I later quit the program and try to
 restart usbhidaction, it reports a “device busy” error. Then if I try to
 replug the keyboard then the system reboots instantly.

 -- 
 Envoyé depuis ma GameBoy.

From: Thomas Klausner <wiz@NetBSD.org>
To: gnats-admin@netbsd.org
Cc: 
Subject: Re: kern/47142: usbhidctl vs. SDL et al.
Date: Wed, 30 Sep 2015 09:47:51 +0200

 The problem seems to be:

 usbhidaction is in uhidread.
 At that point it has both the sc_access_lock and sc_lock.

 mame is in uhidopen.
 It tries to get sc_access_lock for even finding out if it can access
 the device, but hangs since uhidread has it locked.

  Thomas

From: Thomas Klausner <wiz@NetBSD.org>
To: NetBSD bugtracking <gnats-bugs@NetBSD.org>
Cc: 
Subject: Re: kern/47142: usbhidctl vs. SDL et al.
Date: Wed, 30 Sep 2015 12:01:19 +0200

 --RYJh/3oyKhIjGcML
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 mrg suggested the attached diff.

 With that diff, mame starts fine when usbhidaction is already running,
 but the multimedia keys on my keyboard afterwards don't work (even
 though the usbhidaction process is still running).
  Thomas

 --RYJh/3oyKhIjGcML
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="uhid.diff"

 Index: uhid.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/usb/uhid.c,v
 retrieving revision 1.94
 diff -u -r1.94 uhid.c
 --- uhid.c	20 Mar 2015 03:04:48 -0000	1.94
 +++ uhid.c	30 Sep 2015 10:00:15 -0000
 @@ -316,28 +316,22 @@
  	if (sc->sc_dying)
  		return ENXIO;

 -	mutex_enter(&sc->sc_access_lock);
 -
  	/*
  	 * uhid interrupts aren't enabled yet, so setup sc_q now, as
  	 * long as they're not already allocated.
  	 */
  	if (sc->sc_hdev.sc_state & UHIDEV_OPEN) {
 -		mutex_exit(&sc->sc_access_lock);
  		return EBUSY;
  	}
  	if (clalloc(&sc->sc_q, UHID_BSIZE, 0) == -1) {
 -		mutex_exit(&sc->sc_access_lock);
  		return ENOMEM;
  	}

  	error = uhidev_open(&sc->sc_hdev);
  	if (error) {
  		clfree(&sc->sc_q);
 -		mutex_exit(&sc->sc_access_lock);
  		return error;
  	}
 -	mutex_exit(&sc->sc_access_lock);

  	sc->sc_obuf = malloc(sc->sc_osize, M_USBDEV, M_WAITOK);
  	sc->sc_state &= ~UHID_IMMED;

 --RYJh/3oyKhIjGcML--

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.