From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 12 14:58:07 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A202A106568B for ; Mon, 12 Jan 2009 14:58:07 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe04.swip.net [212.247.154.97]) by mx1.freebsd.org (Postfix) with ESMTP id 39A868FC16 for ; Mon, 12 Jan 2009 14:58:06 +0000 (UTC) (envelope-from hselasky@c2i.net) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.0 c=1 a=A61yHLuv1KAA:10 a=nklthdr5v5AUSfVrlghuJA==:17 a=OqVvdz0Z2B-PgFpi5JkA:9 a=PmvdemeyjeGrU5oe2RcA:7 a=pTnRiqneiQoNfUxOZOVBSMkRs7gA:4 a=LY0hPdMaydYA:10 Received: from [62.113.132.62] (account mc467741@c2i.net [62.113.132.62] verified) by mailfe04.swip.net (CommuniGate Pro SMTP 5.2.6) with ESMTPA id 1178393361; Mon, 12 Jan 2009 14:58:04 +0100 From: Hans Petter Selasky To: freebsd-hackers@freebsd.org, Alexej Sokolov Date: Mon, 12 Jan 2009 15:00:20 +0100 User-Agent: KMail/1.9.7 References: <20090112134726.GA2988@debian.samsung.router> In-Reply-To: <20090112134726.GA2988@debian.samsung.router> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200901121500.21657.hselasky@c2i.net> Cc: Subject: Re: panic by unlocking of mutex in KLD 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: Mon, 12 Jan 2009 14:58:08 -0000 On Monday 12 January 2009, Alexej Sokolov wrote: > Hello, > > by unloading of folowing module I have kernel panic. > > I would like to get any explanation about my mistake. > > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > #include > > > struct mtx my_mtx; > > > /* Load handler */ > static int > load(struct module *mod, int cmd, void *arg) > { > int error = 0; > switch(cmd) { > case MOD_LOAD: > printf("Start! Addres of mutex = 0x%X \n", > &my_mtx); > mtx_init(&my_mtx, "My mutex name", "My mutex > type", MTX_DEF); > > mtx_lock(&my_mtx); > break; > case MOD_UNLOAD: > printf("Stop! Addres of mutex = 0x%X \n", > &my_mtx); > mtx_unlock(&my_mtx); > break; > default: > error = EOPNOTSUPP; > break; > } > > return (error); > } > > /* Module structure */ > static moduledata_t mod_data = { > "mymod", > load, > NULL > }; > MODULE_VERSION (kld, 1); > DECLARE_MODULE (kld, mod_data, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); > > > Thanx Hi, You cannot do like this. Remember, two different threads are doing the load/unload. The mutex is associated with a thread. Print out "curthread" aswell and you will see. The mutex can only be unlocked by the same thread that locked it. --HPS