From owner-freebsd-hackers@FreeBSD.ORG Tue May 22 09:18:13 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 1B53116A421 for ; Tue, 22 May 2007 09:18:13 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id CFB1C13C465 for ; Tue, 22 May 2007 09:18:12 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 340A82084; Tue, 22 May 2007 11:18:09 +0200 (CEST) X-Spam-Tests: AWL X-Spam-Learn: disabled X-Spam-Score: 0.0/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on tim.des.no Received: from dwp.des.no (des.no [80.203.243.180]) by smtp.des.no (Postfix) with ESMTP id 1A6362083; Tue, 22 May 2007 11:18:09 +0200 (CEST) Received: by dwp.des.no (Postfix, from userid 1001) id F275957A6; Tue, 22 May 2007 11:18:08 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Lawrence Stewart References: <4649349D.4060101@room52.net> <200705150847.38838.marc.loerner@hob.de> <46499491.2010205@room52.net> <46515DE0.20209@room52.net> <86sl9qtpd1.fsf@dwp.des.no> <4652AD8C.7000605@room52.net> Date: Tue, 22 May 2007 11:18:08 +0200 In-Reply-To: <4652AD8C.7000605@room52.net> (Lawrence Stewart's message of "Tue\, 22 May 2007 18\:45\:00 +1000") Message-ID: <86r6p9md2n.fsf@dwp.des.no> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org Subject: Re: Writing a plain text file to disk from kernel space X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 May 2007 09:18:13 -0000 Lawrence Stewart writes: > After further investigation, it turns out that the pfil input hook I'm > using, which catches packets as they traverse up the network stack, > has no problems, and will happily write to the file using the > kio_write function. However, in the pfil output hook, a call to > kio_write causes a hard reset, with the following text shown on tty0: > > Sleeping thread (tid 100069, pid 613) owns a non-sleepable lock > panic: sleeping thread This is a panic, not a hard reset. Since you are writing kernel code, I assume you have KDB/DDB in your kernel and know how to use it. > If I comment out the kio_write code and put a printf instead, there > are no such problems, so it seems the kio_write function is doing > something that is upsetting the kernel, but only when called from a > function that is acting as a pfil output hook? Strikes me as odd > behaviour. I don't understand which thread the error is in relation > to, why that thread is sleeping or which lock it is referring to. kio_write probably blocks waiting for the write to complete. You can't do that while holding a non-sleepable lock. > I tried wrapping the call to kio_write in a mutex, in case there was a > race condition caused by multiple threads trying to write to the file > at the one time, but that hasn't made a difference at all. It complains about sleeping with a non-sleepable lock held, and your solution is to add another non-sleepable lock? DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no