public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Aleksa Sarai <cyphar@cyphar.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: module_put_and_exit() and free_module()
Date: Wed, 09 Sep 2015 04:13:26 +0930	[thread overview]
Message-ID: <87h9n44ur5.fsf@rustcorp.com.au> (raw)
In-Reply-To: <CAOviyagW+P9sWMyG9gWo3GDBh=NxBP4kOQCYAja_UR2+7is6GQ@mail.gmail.com>

Aleksa Sarai <cyphar@cyphar.com> 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.

      reply	other threads:[~2015-09-08 18:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-05 14:13 module_put_and_exit() and free_module() Aleksa Sarai
2015-09-08 18:43 ` Rusty Russell [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h9n44ur5.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=cyphar@cyphar.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox