NetBSD Problem Report #14368
Received: (qmail 25946 invoked from network); 26 Oct 2001 22:24:09 -0000
Message-Id: <200110262224.f9QMO7200541@ficus.home>
Date: Sat, 27 Oct 2001 00:24:07 +0200 (CEST)
From: Anthony Mallet <anthony.mallet@useless-ficus.net>
Reply-To: Anthony Mallet <anthony.mallet@useless-ficus.net>
To: gnats-bugs@gnats.netbsd.org
Subject: sysmon_envsys.c deadlock
X-Send-Pr-Version: 3.95
>Number: 14368
>Category: kern
>Synopsis: sysmon_envsys.c deadlock
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: jdolecek
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Oct 26 22:25:00 +0000 2001
>Closed-Date: Sat Feb 16 10:34:16 +0000 2002
>Last-Modified: Sat Feb 16 18:19:05 +0000 2002
>Originator: Anthony Mallet
>Release: -current as of October 20
>Organization:
>Environment:
System: NetBSD ficus 1.5Y NetBSD 1.5Y (FICUS) #13: Fri Oct 26 23:43:01 CEST 2001 toto@ficus:/home/src/netbsd-current/sys/arch/i386/compile/FICUS i386
Architecture: i386
Machine: i386
>Description:
When /dev/sysmon is opened twice by two different processes, the
second process blocks infinitely, certainly because it cannot acquire the
'sysmon_envsys_lock'. That's ok.
If the first process stops *before* the second one, no more
process can gain access to /dev/sysmon. See 'How-To-Repeat' for more
details.
>How-To-Repeat:
1 launch `/usr/sbin/envstat -i 1` ( name it "A").
2 launch another `/usr/sbin/envstat -i 1` (name it "B").
2.5 see how "B" is blocked --- ok.
3 kill -INT the "A" process.
3.5 see how the "B" process does *not* gain access to sysmon.
Not ok!
4 kill -INT the "B" process.
4.5 see how *no more* process can access to susmon...
>Fix:
Dunno at this time. I can compile a kernel with LOCK_DEBUG and
symbols if it is needed.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: kern-bug-people->jdolecek
Responsible-Changed-By: jdolecek
Responsible-Changed-When: Sat Nov 17 05:20:07 PST 2001
Responsible-Changed-Why:
I'd look at this eventually.
From: Jaromir Dolecek <jdolecek@netbsd.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/14368: sysmon_envsys.c deadlock
Date: Thu, 3 Jan 2002 22:56:50 +0100 (CET)
Hi,
this should fix this - can you confirm whether it does for you too?
The problem is that the code assumes device close routine is called
for each descriptor close, which is not true.
Jaromir
XXXX
Index: sysmon_envsys.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/sysmon/sysmon_envsys.c,v
retrieving revision 1.2
diff -u -p -r1.2 sysmon_envsys.c
--- sysmon_envsys.c 2001/11/13 06:28:55 1.2
+++ sysmon_envsys.c 2002/01/03 21:51:54
@@ -69,28 +69,18 @@ u_int sysmon_envsys_next_sensor_index;
int sysmon_envsys_initialized;
struct simplelock sysmon_envsys_initialized_slock = SIMPLELOCK_INITIALIZER;
-void sysmon_envsys_init(void);
+#define SYSMON_ENVSYS_LOCK() \
+ lockmgr(&sysmon_envsys_lock, LK_EXCLUSIVE, NULL)
+#define SYSMON_ENVSYS_UNLOCK() \
+ lockmgr(&sysmon_envsys_lock, LK_RELEASE, NULL)
+
int sysmonioctl_envsys(dev_t, u_long, caddr_t, int, struct proc *);
-int sysmonioctl_wdog(dev_t, u_long, caddr_t, int, struct proc *);
struct sysmon_envsys *sysmon_envsys_find(u_int);
void sysmon_envsys_release(struct sysmon_envsys *);
/*
- * sysmon_envsys_init:
- *
- * Initialize the system monitor.
- */
-void
-sysmon_envsys_init(void)
-{
-
- lockinit(&sysmon_envsys_lock, PWAIT|PCATCH, "smenv", 0, 0);
- sysmon_envsys_initialized = 1;
-}
-
-/*
* sysmonopen_envsys:
*
* Open the system monitor device.
@@ -98,18 +88,14 @@ sysmon_envsys_init(void)
int
sysmonopen_envsys(dev_t dev, int flag, int mode, struct proc *p)
{
- int error = 0;
-
simple_lock(&sysmon_envsys_initialized_slock);
- if (sysmon_envsys_initialized == 0)
- sysmon_envsys_init();
+ if (sysmon_envsys_initialized == 0) {
+ lockinit(&sysmon_envsys_lock, PWAIT|PCATCH, "smenv", 0, 0);
+ sysmon_envsys_initialized = 1;
+ }
+ simple_unlock(&sysmon_envsys_initialized_slock);
- error = lockmgr(&sysmon_envsys_lock,
- LK_EXCLUSIVE | LK_INTERLOCK |
- ((flag & O_NONBLOCK) ? LK_NOWAIT : 0),
- &sysmon_envsys_initialized_slock);
-
- return (error);
+ return (0);
}
/*
@@ -121,7 +107,7 @@ int
sysmonclose_envsys(dev_t dev, int flag, int mode, struct proc *p)
{
- (void) lockmgr(&sysmon_envsys_lock, LK_RELEASE, NULL);
+ /* Nothing to do */
return (0);
}
@@ -181,8 +167,11 @@ sysmonioctl_envsys(dev_t dev, u_long cmd
break;
oidx = tred->sensor;
tred->sensor = SME_SENSOR_IDX(sme, tred->sensor);
- if (tred->sensor < sme->sme_nsensors)
+ if (tred->sensor < sme->sme_nsensors) {
+ SYSMON_ENVSYS_LOCK();
error = (*sme->sme_gtredata)(sme, tred);
+ SYSMON_ENVSYS_UNLOCK();
+ }
tred->sensor = oidx;
sysmon_envsys_release(sme);
break;
@@ -199,9 +188,11 @@ sysmonioctl_envsys(dev_t dev, u_long cmd
}
oidx = binfo->sensor;
binfo->sensor = SME_SENSOR_IDX(sme, binfo->sensor);
- if (binfo->sensor < sme->sme_nsensors)
+ if (binfo->sensor < sme->sme_nsensors) {
+ SYSMON_ENVSYS_LOCK();
error = (*sme->sme_streinfo)(sme, binfo);
- else
+ SYSMON_ENVSYS_UNLOCK();
+ } else
binfo->validflags = 0;
binfo->sensor = oidx;
sysmon_envsys_release(sme);
XXX
State-Changed-From-To: open->feedback
State-Changed-By: jdolecek
State-Changed-When: Thu Jan 3 13:55:11 PST 2002
State-Changed-Why:
Sent e-mail with fix, avaiting confirmation it indeed fixes the problem.
From: Jaromir Dolecek <jdolecek@netbsd.org>
To: Anthony Mallet <anthony.mallet@useless-ficus.net>
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/14368
Date: Sun, 13 Jan 2002 19:48:03 +0100 (CET)
Anthony Mallet wrote:
> I'll check your patch asap (maybe this WE).
Had you had a chance to try it yet? It's been committed to -current
meanwhile, so you need only update to newer -current.
Jaromir
From: Anthony Mallet <anthony.mallet@useless-ficus.net>
To: jdolecek@netbsd.org
Cc: gnats-bugs@netbsd.org
Subject: Re: kern/14368
Date: Fri, 15 Feb 2002 14:50:26 +0100 (CET)
Jaromir Dolecek wrote :
| Had you had a chance to try it yet? It's been committed to -current
| meanwhile, so you need only update to newer -current.
I just compiled an 1.5ZA kernel this WE, and the deadlocks have
disappeared :) Thanks a lot
(and I apologize for the late feedback on this pr)
State-Changed-From-To: feedback->closed
State-Changed-By: jdolecek
State-Changed-When: Sat Feb 16 02:34:00 PST 2002
State-Changed-Why:
Fixed, thanks for report.
From: Jaromir Dolecek <jdolecek@netbsd.org> (by way of Erik E. Fair)
To: NetBSD GNATS Problem Report Tracking System <gnats-bugs@gnats.netbsd.org>
Cc:
Subject: Re: kern/14368
Date: Sat, 16 Feb 2002 10:17:10 -0800
Anthony Mallet wrote:
> I just compiled an 1.5ZA kernel this WE, and the deadlocks have
> disappeared :) Thanks a lot
Thanks for testing it :)
> (and I apologize for the late feedback on this pr)
No problem at all.
Jaromir
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.NetBSD.org/Ports/i386/ps2.html
-= Those who would give up liberty for a little temporary safety deserve =-
-= neither liberty nor safety, and will lose both. -- Benjamin Franklin =-
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.