<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 18, 2014 at 9:47 AM, Greg KH <span dir="ltr"><<a href="mailto:greg@kroah.com" target="_blank">greg@kroah.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Jul 18, 2014 at 09:43:48AM +0530, Chetan Nanda wrote:<br>
><br>
><br>
><br>
> On Wed, Jul 16, 2014 at 9:51 PM, Greg KH <<a href="mailto:greg@kroah.com">greg@kroah.com</a>> wrote:<br>
><br>
> On Wed, Jul 16, 2014 at 08:57:38PM +0530, Chetan Nanda wrote:<br>
> ><br>
> ><br>
> ><br>
> > On Wed, Jul 16, 2014 at 8:49 PM, Chetan Nanda <<a href="mailto:chetannanda@gmail.com">chetannanda@gmail.com</a>><br>
> wrote:<br>
> ><br>
> ><br>
> ><br>
> > On Wed, Jul 16, 2014 at 6:39 PM, John de la Garza <<a href="mailto:john@jjdev.com">john@jjdev.com</a>><br>
> wrote:<br>
> ><br>
> > On Wed, Jul 16, 2014 at 04:00:18PM +0530, Chetan Nanda wrote:<br>
> > > A depends on B, so B is automatically loaded when A is loaded.<br>
> > > B module is also directly being used by the user side code via<br>
> misc<br>
> > > interface.<br>
> > >.<br>
> > > Now when I am unloading module A, via "modprobe -r A" it is<br>
> also<br>
> > unloading<br>
> > > the module B which is being used by the application and<br>
> resulting in<br>
> > the<br>
> > > kernel crash.<br>
> ><br>
> > You said that A depends on B, right? Why do you have A dependng<br>
> on B?<br>
> > If it A needs to have B then it makes sense that you can not<br>
> remove A<br>
> > while<br>
> > B is in use. If A doesn't need B, why not remove the dependency.<br>
> ><br>
> > <br>
> > A is calling few APIs defined by B. <br>
> ><br>
> > But why when user space application is already using module B. (it has<br>
> already<br>
> > open its device fd) kernel allows to remove it.<br>
> ><br>
> > I tried with doing try_module_get() in the module's open function, it<br>
> prevent<br>
> > module B unloading but cause thread doing modprobe -r to hang<br>
> > Is there any other way to mark module as busy when being used by user<br>
> > application?<br>
><br>
> Never use try_module_get(), that is racy.<br>
><br>
> What is the user/kernel interface you are using, and why doesn't it<br>
> automatically increase the module count when userspace opens the<br>
> interface? It should all be done in a way that your module doesn't need<br>
> to do anything special.<br>
><br>
><br>
> Hi Greg, <br>
><br>
> Thanks for your mail.<br>
> <br>
> Module is using misc driver interface to export its functionality to<br>
> userspace, <br>
><br>
> Need to debug further why module count is not getting incremented automatically<br>
> when module is open by userspace application via open system call.<br>
<br>
</div></div>Are you properly setting the .owner field of your file operations<br>
structure to be THIS_MODULE? If not, try fixing that up. If you are,<br>
try posting your code for review.<br>
<br>
greg k-h<br>
</blockquote></div><br></div><div class="gmail_extra">Hi Greg,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks for the hint, indeed that was the issue, .owner field was not set in file operation structure.</div>
<div class="gmail_extra">After setting that, 'modprobe -r A' is hanging. As the module B in use and can't be removed. </div><div class="gmail_extra"><br></div><div class="gmail_extra">I am using busybox on embedded Linux, I think this could be a modprobe utility issue.</div>
<div class="gmail_extra">Ideally modprobe should not try to remove the module in used. </div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks,</div><div class="gmail_extra">Chetan Nanda</div></div>