From: Dave Hansen <haveblue@us.ibm.com>
To: Horst von Brand <brand@jupiter.cs.uni-dortmund.de>,
linux-kernel@vger.kernel.org
Subject: Re: Revealing unload_lock to everyone
Date: Fri, 01 Feb 2002 07:35:15 -0800 [thread overview]
Message-ID: <3C5AB5B3.7050908@us.ibm.com> (raw)
In-Reply-To: <200202011010.g11AAIIZ008097@tigger.cs.uni-dortmund.de>
Horst von Brand wrote:
> Dave Hansen <haveblue@us.ibm.com> said:
>
>>This came up in a conversation about ieee1394_core.c. In 2.5.3, the BKL
>>is used to protect a module from being unloaded. The code looks like
this:
>>
>> lock_kernel();
>> read_lock(&ieee1394_chardevs_lock);
>> file_ops = ieee1394_chardevs[blocknum].file_ops;
>> module = ieee1394_chardevs[blocknum].module;
>> read_unlock(&ieee1394_chardevs_lock);
>> ...
>> INCREF(module);
>> unlock_kernel();
>>
>>
>>The question is, how can we keep the module from being unloaded between
>>the file_ops assignment, and the INCREF. Do we have a general purpose
>>way, other than the BKL, to keep a module from being unloaded? There is
>>unload_lock, but it is static to module.c. We can always make it
>>global, but is there a better solution?
>>
>
> Move the INCREF() up?
>
This is really perverse, but here is why that doesn't work:
module not loaded
INCREF(module); /* this fails, no module loaded*/
interrupt, blah, blah, blah
now module is loaded by insmod or something
module = ieee1394_chardevs[blocknum].module;
module now set, but no refcnt bump has been done because it's newly loaded.
module removed
try to set something which went with the module
*BAM*
So, instead, we used try_mod_inc_count() instead of the local INCREF()
#define and return failure if try_mod_inc_count() fails. Thanks to
Keith Ownens for pointing me to try_mod_inc_count().
--
Dave Hansen
haveblue@us.ibm.com
next parent reply other threads:[~2002-02-01 15:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200202011010.g11AAIIZ008097@tigger.cs.uni-dortmund.de>
2002-02-01 15:35 ` Dave Hansen [this message]
2002-01-31 23:58 Revealing unload_lock to everyone Dave Hansen
2002-02-01 1:02 ` Keith Owens
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=3C5AB5B3.7050908@us.ibm.com \
--to=haveblue@us.ibm.com \
--cc=brand@jupiter.cs.uni-dortmund.de \
--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