From owner-freebsd-hackers@freebsd.org Wed Apr 12 18:53:45 2017 Return-Path: Delivered-To: freebsd-hackers@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 9ED29D3BB1A for ; Wed, 12 Apr 2017 18:53:45 +0000 (UTC) (envelope-from torek@elf.torek.net) Received: from elf.torek.net (mail.torek.net [96.90.199.121]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "elf.torek.net", Issuer "elf.torek.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 8A0E1B29 for ; Wed, 12 Apr 2017 18:53:44 +0000 (UTC) (envelope-from torek@elf.torek.net) Received: from elf.torek.net (localhost [127.0.0.1]) by elf.torek.net (8.15.2/8.15.2) with ESMTPS id v3CIrgrQ055169 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 12 Apr 2017 11:53:43 -0700 (PDT) (envelope-from torek@elf.torek.net) Received: (from torek@localhost) by elf.torek.net (8.15.2/8.15.2/Submit) id v3CIrg5d055158; Wed, 12 Apr 2017 11:53:42 -0700 (PDT) (envelope-from torek) Date: Wed, 12 Apr 2017 11:53:42 -0700 (PDT) From: Chris Torek Message-Id: <201704121853.v3CIrg5d055158@elf.torek.net> To: ablacktshirt@gmail.com, imp@bsdimp.com Subject: Re: Understanding the FreeBSD locking mechanism Cc: ed@nuxi.nl, freebsd-hackers@freebsd.org, rysto32@gmail.com In-Reply-To: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (elf.torek.net [127.0.0.1]); Wed, 12 Apr 2017 11:53:43 -0700 (PDT) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Apr 2017 18:53:45 -0000 >> If you obtain the locks in the other order -- i.e., if you grab >> the PROC_STATLOCK first, then try to lock PROC_LOCK -- you are >> trying to take a spin-type mutex while holding a default mutex, >Is this a typo? I guess you mean something like "you are trying >to take a blocking mutex while holding spin-type mutex". Yes, or rather brain-o (swapping words) -- these most often happen if I am interrupted while composing a message :-) >I think I get your point: if you take a spin-type mutex, you >already disable interrupt, which in effect means that no other >code can preempt you. Under this circumstance, if you continue to >take a blocking mutex, you may get blocked. Since you already >disable interrupt and nobody can interrupt/preempt you, you are blocked >on that CPU, not being able to do anything, which is pretty much a >"deadlock" (actually this is not a deadlock, but, it is similar) Right. It *may* deadlock, and it is definitely not good -- and the INVARIANTS kernel will check and panic. Chris