All of lore.kernel.org
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: How to prevent a module from unloading when in used
Date: Thu, 17 Jul 2014 21:17:14 -0700	[thread overview]
Message-ID: <20140718041714.GA32696@kroah.com> (raw)
In-Reply-To: <CAPrYoTG8FhZ3vQ3XnidcM714o+RtRVj9BARYuNf6mzfPoTXV4g@mail.gmail.com>

On Fri, Jul 18, 2014 at 09:43:48AM +0530, Chetan Nanda wrote:
> 
> 
> 
> On Wed, Jul 16, 2014 at 9:51 PM, Greg KH <greg@kroah.com> wrote:
> 
>     On Wed, Jul 16, 2014 at 08:57:38PM +0530, Chetan Nanda wrote:
>     >
>     >
>     >
>     > On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda <chetannanda@gmail.com>
>     wrote:
>     >
>     >
>     >
>     > ? ? On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza <john@jjdev.com>
>     wrote:
>     >
>     > ? ? ? ? On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda wrote:
>     > ? ? ? ? > A depends on B, so B is automatically loaded when A is loaded.
>     > ? ? ? ? > B module is also directly being used by the user side code via
>     misc
>     > ? ? ? ? > interface.
>     > ? ? ? ? >.
>     > ? ? ? ? > Now when I am unloading module A, via "modprobe -r A" it is
>     also
>     > ? ? ? ? unloading
>     > ? ? ? ? > the module B which is being used by the application and
>     resulting in
>     > ? ? ? ? the
>     > ? ? ? ? > kernel crash.
>     >
>     > ? ? ? ? You said that A depends on B, right? ?Why do you have A dependng
>     on B?
>     > ? ? ? ? If it A needs to have B then it makes sense that you can not
>     remove A
>     > ? ? ? ? while
>     > ? ? ? ? B is in use. ?If A doesn't need B, why not remove the dependency.
>     >
>     > ?
>     > A is calling few APIs defined by B.?
>     >
>     > But why when user space application is already using ?module B. (it has
>     already
>     > open its device fd) kernel allows to remove it.
>     >
>     > I tried with doing try_module_get() in the module's open function, it
>     prevent
>     > module B unloading but cause thread doing modprobe -r to hang
>     > Is there any other way to mark module as busy when being used by user
>     > application?
> 
>     Never use try_module_get(), that is racy.
> 
>     What is the user/kernel interface you are using, and why doesn't it
>     automatically increase the module count when userspace opens the
>     interface? ?It should all be done in a way that your module doesn't need
>     to do anything special.
> 
> 
> Hi Greg,?
> 
> Thanks for your mail.
> ?
> Module is using misc driver interface to export its functionality to
> userspace,?
> 
> Need to debug further why module count is not getting incremented automatically
> when module is open by userspace application via open system call.

Are you properly setting the .owner field of your file operations
structure to be THIS_MODULE?  If not, try fixing that up.  If you are,
try posting your code for review.

greg k-h

  reply	other threads:[~2014-07-18  4:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPrYoTHfEqU_8QRJKzY3gwF50JHB_b+QRc=u9MCM_A+mAsRw1A@mail.gmail.com>
2014-07-16 10:30 ` How to prevent a module from unloading when in used Chetan Nanda
2014-07-16 13:09   ` John de la Garza
     [not found]     ` <CAPrYoTHQFqqbskarb6RJjzZdcBiDCSFvc3uZwhOyzi5Y0a82NA@mail.gmail.com>
2014-07-16 15:27       ` Chetan Nanda
2014-07-16 16:21         ` Greg KH
2014-07-18  4:13           ` Chetan Nanda
2014-07-18  4:17             ` Greg KH [this message]
2014-07-18  6:29               ` Chetan Nanda
2014-07-21  3:39                 ` Chetan Nanda
2014-07-21  4:22                   ` Greg KH
2014-07-21  4:50                     ` Chetan Nanda
2014-07-21 18:42                       ` Greg KH
2014-07-16 17:10   ` Abhishek Sharma

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=20140718041714.GA32696@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.