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