From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752599AbbIHSoY (ORCPT ); Tue, 8 Sep 2015 14:44:24 -0400 Received: from ozlabs.org ([103.22.144.67]:60979 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752015AbbIHSoW (ORCPT ); Tue, 8 Sep 2015 14:44:22 -0400 From: Rusty Russell To: Aleksa Sarai Cc: linux-kernel@vger.kernel.org Subject: Re: module_put_and_exit() and free_module() In-Reply-To: References: User-Agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Wed, 09 Sep 2015 04:13:26 +0930 Message-ID: <87h9n44ur5.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Aleksa Sarai writes: >>>From my understanding, module_put_and_exit() can be used inside a > module to (from within the module) kill itself. However, it doesn't > seem to properly free the modules references (and internal > bookkeeping) since module_put_and_exit() doesn't call free_module(). > And attempting to remove the module after loading it and it running > module_put_and_exit() causes any attempt to remove the module to fail > with EBUSY. It's not a general mechanism! It's for kernel threads which want to decrement module use counts as they exit: if they did this in the module there would be a moment where they are still running but the module could be unloaded. > Am I missing something here? Is the purpose of module_put_and_exit() > different, or does module_put() cause the module references to get > reaped later? If that's the case, why do you get EBUSY when trying to > remove the module (surely you should get an ENOENT)? Is it even safe > to attempt to remove a module from within itself? module_put() simply controls the reference count. Module removal only succeeds if the reference count is 0. I would guess that you called module_put_and_exit() without a thread, and oopsed. Cheers, Rusty.