From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 12 16:19:57 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 6AEFE106566B for ; Mon, 12 Jan 2009 16:19:57 +0000 (UTC) (envelope-from bsd.quest@googlemail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.179]) by mx1.freebsd.org (Postfix) with ESMTP id 3B2648FC0C for ; Mon, 12 Jan 2009 16:19:57 +0000 (UTC) (envelope-from bsd.quest@googlemail.com) Received: by wa-out-1112.google.com with SMTP id m34so6026385wag.27 for ; Mon, 12 Jan 2009 08:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type:references; bh=Osj3nkQ3D5E6SVddrMO66+D4LTmuDDSumGRWQDKw9l4=; b=s95N7k9Fgdpdl4Yxz5G61KBF26Js5fyaPz8PsoME6zzBKTIwCqv7cxTWg08rxdlcZy UMnbc4IPf2FT6bcjifXuO45nmk09jvOhIIAWG4DO+OCNlfcsWZTY9M627M75tcWANEyU 47mQgBaqdgkCO+fs4QH5/vXq8vojazkAwowqI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:references; b=xUSNVSjiEqP/0PRGk0l8RUWe3THNCGqK/CUkWth0BL0UWuYuOvo5dPLWE/EKJ1C9cI NIqCSewxQLCWWFKe4N+meLJnGJMtaXt3pxxIguOxqW9ggI8MLRWOgT2bRTI5doyUx3Mg nhoPQiNGox7ujL4d9+CwHJHMa3noNAlO0fdZw= Received: by 10.114.159.5 with SMTP id h5mr19405517wae.190.1231777196908; Mon, 12 Jan 2009 08:19:56 -0800 (PST) Received: by 10.114.202.10 with HTTP; Mon, 12 Jan 2009 08:19:56 -0800 (PST) Message-ID: <671bb5fc0901120819q65969961v723807bcb7ad5a96@mail.gmail.com> Date: Mon, 12 Jan 2009 17:19:56 +0100 From: "Alexej Sokolov" To: "Mateusz Guzik" In-Reply-To: <20090112141029.GA31108@skucha> MIME-Version: 1.0 References: <20090112134726.GA2988@debian.samsung.router> <20090112141029.GA31108@skucha> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org 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 16:19:57 -0000 2009/1/12 Mateusz Guzik > On Mon, Jan 12, 2009 at 02:47:26PM +0100, 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); > > > > > > Acutally it panics even on loading. :) Thanks, a lot. Yes, in this case the different processes try to lock and unlock the same mutex. Stupid mistake! But... > > > Mutexes have owners. It panics on loading because processes cannot > return to userland with locks held. i am not sure about it. Some time ago i implemented a charecter device with two syscalls: write, read. "write" lock the mutex and "read" unlock it. The user space programm opens device, then mekes "write" (mutex will held in kernel), goes back to user space, then makes "read" (mutex will unlocked in kernel) and it all run without panic. If needed i can post the source code. > It panics on unloading (in your > case) because curproc != my_mtx's owner. > > -- > Mateusz Guzik > Thanks, Alexej