From owner-cvs-src@FreeBSD.ORG Mon Jul 23 15:30:24 2007 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F1CBB16A468; Mon, 23 Jul 2007 15:30:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail6.speedfactory.net [66.23.216.219]) by mx1.freebsd.org (Postfix) with ESMTP id 6465313C46A; Mon, 23 Jul 2007 15:30:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.7b8) with ESMTP id 198455241 for multiple; Mon, 23 Jul 2007 11:38:55 -0400 Received: from localhost.corp.yahoo.com (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.13.8/8.13.8) with ESMTP id l6NFUD3N000170; Mon, 23 Jul 2007 11:30:13 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: Andrew Thompson Date: Mon, 23 Jul 2007 10:50:50 -0400 User-Agent: KMail/1.9.6 References: <200707222053.l6MKrS6v040649@repoman.freebsd.org> In-Reply-To: <200707222053.l6MKrS6v040649@repoman.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200707231050.51004.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Mon, 23 Jul 2007 11:30:13 -0400 (EDT) X-Virus-Scanned: ClamAV 0.88.3/3742/Mon Jul 23 07:31:24 2007 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=1653887525 Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org Subject: Re: cvs commit: src/sys/compat/ndis subr_ntoskrnl.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jul 2007 15:30:24 -0000 On Sunday 22 July 2007 04:53:28 pm Andrew Thompson wrote: > thompsa 2007-07-22 20:53:28 UTC > > FreeBSD src repository > > Modified files: > sys/compat/ndis subr_ntoskrnl.c > Log: > ndis will signal the kthread to exit and then sleep on the proc pointer to > be woken up by kthread_exit. This is racey and in some cases the kthread will > exit before ndis gets around to sleep so it will be stuck indefinitely. This > change reuses the kq_exit variable to indicate that the thread has gone and > will loop on tsleep with a timeout waiting for it. If the kthread has already > exited then it will not sleep at all. As long as you use a lock you are ok. That is: foo_detach() { mtx_lock(&lock); please_die = 1; msleep(&proc, &lock, ..., 0); mtx_unlock(&lock); } foo_main() { mtx_lock(&lock); while (!please_die) { do_stuff(); } mtx_unlock(&lock); kthread_exit(0); } works fine. If you try to do this: foo_detach() { mtx_lock(&lock); please_die = 1; while (!dead_yet) msleep(&proc, &lock, ... , hz/10); mtx_unlock(&lock); } foo_main() { mtx_lock(&lock); while (!please_die) { do_stuff(); } dead_yet = 1; mtx_unlock(&lock); kthread_exit(0); } and foo_main() can be unloaded (it's part of a module) then you are still racey and can panic on kldunload if you foo_main() is preempted after the mtx_unlock() but before the kthread_exit() and foo_detach() completes and returns to kldunload() which unmaps the module. I think you didn't make the race worse though, as the old code was missing the lock and only used tsleep() before. -- John Baldwin