From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Subject: Re: kobject_put vs module unload Date: Sat, 8 Jan 2011 15:49:49 -0800 Message-ID: <20110108234949.GA4262@suse.de> References: <20110108055621.GB10391@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org To: Mikulas Patocka Cc: Kay Sievers , linux-kernel@vger.kernel.org, dm-devel@redhat.com List-Id: dm-devel.ids On Sat, Jan 08, 2011 at 01:50:50PM -0500, Mikulas Patocka wrote: >=20 >=20 > On Sat, 8 Jan 2011, Kay Sievers wrote: >=20 > > On Sat, Jan 8, 2011 at 19:01, Mikulas Patocka = wrote: > > > On Sat, 8 Jan 2011, Kay Sievers wrote: > > >> On Sat, Jan 8, 2011 at 14:19, Mikulas Patocka wrote: > > >> > On Fri, 7 Jan 2011, Greg KH wrote: > > >> > > >> >> > 4) the reference obtained at point 1) is dropped, kobject r= eference count > > >> >> > reaches zero and the release callback is called. But that c= allback points > > >> >> > to an unloaded module and causes a crash. > > >> >> > > > >> >> > How is it solved? Am I missing something? > > >> >> > > >> >> You have the code that creates and frees the object, to not b= e in the > > >> >> module that could have been unloaded. =A0It's really just tha= t simple. > > >> > > > >> > If the whole device mapper subsystem can be a module, where ca= n I put the > > >> > code? > > >> > > > >> > I think a similar bug exists in md, it can also be unloaded as= a module > > >> > and it has "release" method in its module code. > > >> > > >> If you still have data structures hanging around, these structur= es are > > >> supposed to take a reference on the module -- and you can not un= load > > >> the module as long as this is the case. > > >> > > >> Kay > > > > > > kobject references don't increase module reference count. If kobj= ect held > > > module references, it would be a fix for this bug, but could caus= e other > > > bugs (some modules could be unloadable due to self-references to = its own > > > kobjects). > >=20 > > Sure, they don't automatically take references. It's the job of the > > driver/module, to make sure to pin the module for any data of it, > > which might be still in use. > >=20 > > Kay >=20 > A module can't unpin itself. If it does, the module can be unloaded=20 > immediatelly after module_put(THIS_MODULE) call and the function that= =20 > called module_put crashes. >=20 > A module must be unpinned by someone else. The question is: who unpin= s the=20 > module when kobject references are gone? Who ever you decide to have unpin it. Seriously, it's up to you to handle this properly, it's not something built into the kobject/driver model at all due to it being something that can be done in a number of different ways. thanks, greg k-h