Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756131AbXKGCpF (ORCPT ); Tue, 6 Nov 2007 21:45:05 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753464AbXKGCoy (ORCPT ); Tue, 6 Nov 2007 21:44:54 -0500 Received: from wa-out-1112.google.com ([209.85.146.180]:56113 "EHLO wa-out-1112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752398AbXKGCox (ORCPT ); Tue, 6 Nov 2007 21:44:53 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; b=YtvvedDmz/tR+7V4AJXUUbqi0CpRW3yGqzaZG0Qr7i9BiQddwEc0SZgsfswn/QSEGuq1iwgNoi/E/Vhf+z1k5D4yCftXlYzeqb0dn/7jfsOfzpHTCbBjdLw0cyqnkCPBQTRyrOhODRpJACzYo5cu/8Up0XN4HgOinzstfWFJ1bQ= Message-ID: <4731269B.6010509@gmail.com> Date: Wed, 07 Nov 2007 11:44:43 +0900 From: Tejun Heo User-Agent: Thunderbird 2.0.0.6 (X11/20070801) MIME-Version: 1.0 To: Peter Osterlund CC: Thomas Maier , Jens Axboe , linux-kernel , gregkh@suse.de Subject: Re: pktcdvd oops References: <20071105092018.GD5359@kernel.dk> <47302E9F.6020708@gmail.com> In-Reply-To: X-Enigmail-Version: 0.95.3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2302 Lines: 61 Peter Osterlund wrote: > On Tue, 6 Nov 2007, Thomas Maier wrote: > >> Hello, >> >> have not tested it yet, but i quess, the code mentioned by Peter >> is in pkt_new_dev() that is called by pkt_setup_dev(): >> >> /* This is safe, since we have a reference from open(). */ >> __module_get(THIS_MODULE); >> >> >> So, now, there must be checks in every sysfs operation in the module >> code, >> to ensure that the module is still loaded? > > I haven't tested it either yet. What I don't understand is this: If the > __module_get() is not safe because the module code could have already > been unloaded, how can it possibly be made safe by adding more code to > the pktcdvd module? If the module is unloaded, trying to execute its > code can't be a good thing no matter what the code does. > sysfs itself is now out of module lifespan rules. sysfs callbacks are guaranteed to stay in memory while running by sysfs node removal waiting for completion of in-flight operations before returning. In pktcdvd's case, class_destroy() call in pkt_sysfs_cleanup() will wait for all in-flight sysfs r/w ops to complete. So, even while sysfs callbacks are executing, the module beneath can die but it will stay in memory till all the callbacks return. You need to test module liveness using try_module_get() (and it can fail) if you want to grab module reference from sysfs callbacks. >> BTW: the bug report says: >> >> Steps to reproduce: >> >> modprobe pktcdvd >> echo 22:0 >/sys/class/pktcdvd/add >> >> Is there any module unload??? Why is the module not available after >> the modprobe, but the sysfs entries, generated by the module? Confused ;) > > I think the purpose of the BUG_ON in __module_get() is to catch cases > that are unsafe, even if the call would have happened to work in this > particular case. The BUG_ON is detecting valid condition here. If you rmmod pktcdvd after sysfs write has begun but before __module_get() ran, device node will be created after the module is killed and scheduled to be unloaded. Thanks. -- tejun - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/