random(4) related panic: sleeping without a mutex

Mark Murray markm at FreeBSD.ORG
Sun Apr 11 17:00:19 PDT 2004


"Simon L. Nielsen" writes:
> I getting the following panic on my Soekris Net4801 box right after init
> has been started:
> 
> Mounting root from ufs:/dev/ad0s1a
> start_init: trying /sbin/init
> panic: sleeping without a mutex
> at line 144 in file /data/nanobsd/src/sys/kern/kern_synch.c
> Debugger("panic")
> Stopped at      Debugger+0x45:  xchgl   %ebx,in_Debugger.0

Could you please try the enclosed patch?

M
--
Mark Murray
iumop ap!sdn w,I idlaH
-------------- next part --------------
Index: randomdev.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/random/randomdev.c,v
retrieving revision 1.49
diff -u -d -r1.49 randomdev.c
--- randomdev.c	9 Apr 2004 15:47:09 -0000	1.49
+++ randomdev.c	11 Apr 2004 19:08:03 -0000
@@ -103,25 +103,28 @@
 {
 	int c, error = 0;
 
+	mtx_lock(&random_systat.lock);
+
 	/* Blocking logic */
 	while (!random_systat.seeded && !error) {
 		if (flag & IO_NDELAY)
 			error = EWOULDBLOCK;
 		else
-			error = tsleep(&random_systat,
+			error = msleep(&random_systat, &random_systat.lock,
 			    PUSER | PCATCH, "block", 0);
 	}
 
 	/* The actual read */
 	if (!error) {
-		mtx_lock(&random_systat.lock);
 		while (uio->uio_resid > 0 && !error) {
 			c = MIN(uio->uio_resid, PAGE_SIZE);
 			c = (*random_systat.read)(random_buf, c);
 			error = uiomove(random_buf, c, uio);
 		}
-		mtx_unlock(&random_systat.lock);
 	}
+
+	mtx_unlock(&random_systat.lock);
+
 	return (error);
 }
 


More information about the freebsd-current mailing list