From owner-svn-src-head@freebsd.org Wed Jul 22 04:33:30 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 787859A7483; Wed, 22 Jul 2015 04:33:30 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wi0-x22a.google.com (mail-wi0-x22a.google.com [IPv6:2a00:1450:400c:c05::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0E5F71880; Wed, 22 Jul 2015 04:33:30 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by wicgb10 with SMTP id gb10so80229138wic.1; Tue, 21 Jul 2015 21:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=7TkvldLazH70cyUIWhYxtCjKvOEgqF4TtLBxqR0BpU8=; b=r0P9G1Ft4f8kPuJo+HpjfBaBocKwlXAx2Y8ySTMGY9MnLbdPc9HlovDSpJMY0/US5W hMOA0mYlfXN+iKe+vhJtcx1UOUUIgyuALc1mwEqikvXLsrQvz5CU0BfrlYNjGMTsZSfk aW4dDvH0qRengcVl2zgpYtwCnDB3IeO2UM0NFRCIOZ1CuCbMRdPNScGYflE9gamoU6a+ nqwbapAPFfAGKuxQ2OL++WGlZqPcR4Y7BcvLqq+uUsOQsc4j9d7iN/raltwEkycV7y3O 7hW6nq1VubhPffgQQAUEMfdbSR8YCDiLCnWMW9XwIVkjyHnvXEJYQc6cUvTdyEqvx29Q 2yqA== X-Received: by 10.180.211.98 with SMTP id nb2mr32079096wic.91.1437539608603; Tue, 21 Jul 2015 21:33:28 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by smtp.gmail.com with ESMTPSA id r8sm14690846wiz.5.2015.07.21.21.33.26 (version=TLS1_2 cipher=AES128-SHA256 bits=128/128); Tue, 21 Jul 2015 21:33:26 -0700 (PDT) Date: Wed, 22 Jul 2015 06:33:24 +0200 From: Mateusz Guzik To: John Baldwin Cc: Adrian Chadd , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Subject: Re: svn commit: r285125 - in head/sys: kern sys Message-ID: <20150722043323.GA23614@dft-labs.eu> References: <201507040654.t646sGO7044196@repo.freebsd.org> <20150721083922.GB6736@dft-labs.eu> <3863130.vz23U50G0A@ralph.baldwin.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <3863130.vz23U50G0A@ralph.baldwin.cx> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jul 2015 04:33:30 -0000 On Tue, Jul 21, 2015 at 11:50:12AM -0700, John Baldwin wrote: > On Tuesday, July 21, 2015 10:39:22 AM Mateusz Guzik wrote: > > Cc'ing jhb@ who made relevant changes to rmlocks > > > > On Mon, Jul 20, 2015 at 11:21:30PM -0700, Adrian Chadd wrote: > > > this happend whilst doing 'sysctl -vmstat 1' in one window, 'top' in > > > another window, and 'kldunload uhci' as root: > > > > > > Unread portion of the kernel message buffer: > > > uhci5: detached > > > panic: sleepq_add: td 0xc75d06a0 to sleep on wchan 0xc0b3e8e4 with > > > sleeping prohibited > > > > > [..] > > > > > #10 0xc06a882c in kassert_panic (fmt=) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_shutdown.c:634 > > > #11 0xc06f449b in sleepq_add (wchan=0xc0b3e8e4, wmesg= > > out>, flags=, queue=) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/subr_sleepqueue.c:308 > > > #12 0xc06b167b in _sx_xlock_hard (sx=0xc0b3e8e4, tid= > > out>, opts=, file=0x0, line=18) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_sx.c:697 > > > #13 0xc06b0841 in _sx_xlock (sx=0xc0b3e8e4, opts= > > out>, file=0xc09f2d35 > > > "/usr/home/adrian/work/freebsd/head/src/sys/kern/kern_rmlock.c", > > > line=411) at sx.h:154 > > > #14 0xc06a4510 in _rm_rlock (rm=0xc0b3e8cc, tracker=0xeaa61ad0, > > > trylock=) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_rmlock.c:411 > > > #15 0xc06a4e2d in _rm_rlock_debug (rm=0xc0b3e8cc, tracker=0xeaa61ad0, > > > trylock=0) at /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_rmlock.c:665 > > > #16 0xc06b5da4 in sysctl_root_handler_locked (oid=0xc0a6ee20, > > > arg1=, arg2=, req= > > optimized out>, tracker=0xeaa61ad0) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_sysctl.c:170 > > > #17 0xc06b5531 in sysctl_root (arg1=, arg2= > > optimized out>) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_sysctl.c:1692 > > > #18 0xc06b5ac2 in userland_sysctl (td=, > > > name=, namelen=2, old=, > > > oldlenp=, inkernel=, > > > new=, newlen=, retval=0x12, > > > flags=) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_sysctl.c:1797 > > > #19 0xc06b5908 in sys___sysctl (uap=0xeaa61ca8) at > > > /usr/home/adrian/work/freebsd/head/src/sys/kern/kern_sysctl.c:1724 > > > #20 0xc096aaee in syscall (frame=) at subr_syscall.c:133 > > > #21 0xc0955c5c in Xint0x80_syscall () at > > > /usr/home/adrian/work/freebsd/head/src/sys/i386/i386/exception.s:278 > > > > rmlock(9) states: > > Sleepable read-mostly locks are created by passing RM_SLEEPABLE to > > rm_init_flags(). Unlike normal read-mostly locks, sleepable read-mostly > > locks follow the same lock ordering rules as sx(9) locks. Sleepable > > read-mostly locks do not propagate priority to writers, but they do > > propagate priority to readers. Writers are permitted to sleep while > > holding a read-mostly lock, but readers are not. Unlike other sleepable > > locks such as sx(9) locks, readers must use try operations on other > > sleepable locks to avoid sleeping. > > > > May be that's my bad English, but I read that: > > rm_rlock(...); > > /* can't sleep here */ > > rm_runlock(...); > > That is correct. > > > Turns out it's the rm_rlock itself which must not sleep and you have to > > rm_try_rlock instead. > > Hmm, I think instead, the THREAD_NO_SLEEPING in rm_rlock() just needs to > be moved. Or rather, rm_rlock_hard() needs to do THREAD_SLEEPING_OK > around the sx_xlock and then THREAD_NO_SLEEPING afterwards. Something > like this: > > Index: kern/kern_rmlock.c > =================================================================== > --- kern/kern_rmlock.c (revision 284344) > +++ kern/kern_rmlock.c (working copy) > @@ -407,9 +407,11 @@ > return (0); > } > } else { > - if (rm->lock_object.lo_flags & LO_SLEEPABLE) > + if (rm->lock_object.lo_flags & LO_SLEEPABLE) { > + THREAD_SLEEPING_OK(); > sx_xlock(&rm->rm_lock_sx); > - else > + THREAD_NO_SLEEPING(); > + } else > mtx_lock(&rm->rm_lock_mtx); > } > Works for me, I was reluctant to do this myself, hence the "wrapper" approach. Thanks. -- Mateusz Guzik