public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Is try_module_get buggy?
@ 2008-01-12  4:35 rmingming
  2008-01-17  3:09 ` Rusty Russell
  0 siblings, 1 reply; 3+ messages in thread
From: rmingming @ 2008-01-12  4:35 UTC (permalink / raw)
  To: linux-kernel

Hi,
 I have a problem about the try_module_get function, I don't know if someone
removed the module just AFTER line 372, then what happens? Because in this
situation, the variable module will be incorrect, and module_is_live
function will lead to unpredicatable behaviour.

368 static inline int try_module_get(struct module *module)
369 {
370         int ret = 1;
371
372         if (module) {
373                 unsigned int cpu = get_cpu();
374                 if (likely(module_is_live(module)))
375                         local_inc(&module->ref[cpu].count);
376                 else
377                         ret = 0;
378                 put_cpu();
379         }
380         return ret;
381 }

Best wishes to all,
rmingming

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is try_module_get buggy?
  2008-01-12  4:35 Is try_module_get buggy? rmingming
@ 2008-01-17  3:09 ` Rusty Russell
  2008-01-23 14:34   ` rmingming
  0 siblings, 1 reply; 3+ messages in thread
From: Rusty Russell @ 2008-01-17  3:09 UTC (permalink / raw)
  To: rmingming; +Cc: linux-kernel

On Saturday 12 January 2008 15:35:27 rmingming wrote:
> Hi,
>  I have a problem about the try_module_get function, I don't know if
> someone removed the module just AFTER line 372, then what happens? Because
> in this situation, the variable module will be incorrect, and
> module_is_live function will lead to unpredicatable behaviour.
>
> 368 static inline int try_module_get(struct module *module)
> 369 {
> 370         int ret = 1;
> 371
> 372         if (module) {
> 373                 unsigned int cpu = get_cpu();
> 374                 if (likely(module_is_live(module)))
> 375                         local_inc(&module->ref[cpu].count);
> 376                 else
> 377                         ret = 0;
> 378                 put_cpu();
> 379         }
> 380         return ret;
> 381 }

Hi rminming,

try_module_get is designed to ensure that you don't call a function inside a 
module without a reference.  Like any reference function, it cannot handle 
the case where the argument is invalid (or invalidated partway through the 
call).

In this case, the module pointer is usually inside a registered structure.  
The pointer will be valid until the structure is unregistered, which the 
calling code presumably prevents while it's doing a lookup.

Hope that clarifies,
Rusty.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is try_module_get buggy?
  2008-01-17  3:09 ` Rusty Russell
@ 2008-01-23 14:34   ` rmingming
  0 siblings, 0 replies; 3+ messages in thread
From: rmingming @ 2008-01-23 14:34 UTC (permalink / raw)
  To: linux-kernel

> Hi rminming,
>
> try_module_get is designed to ensure that you don't call a function inside a
> module without a reference.  Like any reference function, it cannot handle
> the case where the argument is invalid (or invalidated partway through the
> call).
>
> In this case, the module pointer is usually inside a registered structure.
> The pointer will be valid until the structure is unregistered, which the
> calling code presumably prevents while it's doing a lookup.
>
> Hope that clarifies,
> Rusty.
>

Hi Rusty,

Thank you so much!
I think you mean that this situation can really happen, because this
is a reference function, but it is so seldom, and the common result of
this situation is a kernel oops, it's not very important. Am I right?

Sorry about later reply, thanks again.
Best wishes,

rmingming

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-23 14:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-12  4:35 Is try_module_get buggy? rmingming
2008-01-17  3:09 ` Rusty Russell
2008-01-23 14:34   ` rmingming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox