mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Possible spinlock recursion in search_module_extables() ?
@ 2006-06-19 10:31 Chuck Ebbert
  2006-11-08 17:42 ` Jeff Layton
  0 siblings, 1 reply; 3+ messages in thread
From: Chuck Ebbert @ 2006-06-19 10:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Linus Torvalds

Looking at this code:

const struct exception_table_entry *search_exception_tables(unsigned long addr)
{
        const struct exception_table_entry *e;

        e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
        if (!e)
                e = search_module_extables(addr);
        return e;
}

const struct exception_table_entry *search_module_extables(unsigned long addr)
{
        unsigned long flags;
        const struct exception_table_entry *e = NULL;
        struct module *mod;

        spin_lock_irqsave(&modlist_lock, flags);
        list_for_each_entry(mod, &modules, list) {
                if (mod->num_exentries == 0)
                        continue;

                e = search_extable(mod->extable,
                                   mod->extable + mod->num_exentries - 1,
                                   addr);
                if (e)
                        break;
        }
        spin_unlock_irqrestore(&modlist_lock, flags);

        /* Now, if we found one, we are running inside it now, hence
           we cannot unload the module, hence no refcnt needed. */
        return e;
}


search_module_extables() takes a spinlock.  If some kind of fault occurs
while it's holding that lock (module list corrupted etc.,) won't it be
re-entered while looking for its own fault handler?  If so, would this
be a possible fix?

const struct exception_table_entry *search_exception_tables(unsigned long addr)
{
        const struct exception_table_entry *e;

        if (core_kernel_text(addr))
                e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
        else
                e = search_module_extables(addr);

        return e;
}
-- 
Chuck
 "You can't read a newspaper if you can't read."  --George W. Bush

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

* Re: Possible spinlock recursion in search_module_extables() ?
  2006-06-19 10:31 Possible spinlock recursion in search_module_extables() ? Chuck Ebbert
@ 2006-11-08 17:42 ` Jeff Layton
  2006-11-08 18:56   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Layton @ 2006-11-08 17:42 UTC (permalink / raw)
  To: Chuck Ebbert; +Cc: linux-kernel, Andrew Morton, Linus Torvalds

On Mon, 2006-06-19 at 06:31 -0400, Chuck Ebbert wrote:
> Looking at this code:
> 
> const struct exception_table_entry *search_exception_tables(unsigned long addr)
> {
>         const struct exception_table_entry *e;
> 
>         e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
>         if (!e)
>                 e = search_module_extables(addr);
>         return e;
> }
> 
> const struct exception_table_entry *search_module_extables(unsigned long addr)
> {
>         unsigned long flags;
>         const struct exception_table_entry *e = NULL;
>         struct module *mod;
> 
>         spin_lock_irqsave(&modlist_lock, flags);
>         list_for_each_entry(mod, &modules, list) {
>                 if (mod->num_exentries == 0)
>                         continue;
> 
>                 e = search_extable(mod->extable,
>                                    mod->extable + mod->num_exentries - 1,
>                                    addr);
>                 if (e)
>                         break;
>         }
>         spin_unlock_irqrestore(&modlist_lock, flags);
> 
>         /* Now, if we found one, we are running inside it now, hence
>            we cannot unload the module, hence no refcnt needed. */
>         return e;
> }
> 
> 
> search_module_extables() takes a spinlock.  If some kind of fault occurs
> while it's holding that lock (module list corrupted etc.,) won't it be
> re-entered while looking for its own fault handler?  If so, would this
> be a possible fix?
> 
> const struct exception_table_entry *search_exception_tables(unsigned long addr)
> {
>         const struct exception_table_entry *e;
> 
>         if (core_kernel_text(addr))
>                 e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
>         else
>                 e = search_module_extables(addr);
> 
>         return e;
> }

I seem to be able to reliably trigger this spinlock recursion problem
with systemtap on a RHEL4 kernel. The patch suggested above does seem to
correct it, but I'm not familiar enough with extables to know whether
the approach here is correct.

-- Jeff





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

* Re: Possible spinlock recursion in search_module_extables() ?
  2006-11-08 17:42 ` Jeff Layton
@ 2006-11-08 18:56   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2006-11-08 18:56 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Chuck Ebbert, linux-kernel, Linus Torvalds

On Wed, 08 Nov 2006 12:42:17 -0500
Jeff Layton <jlayton@redhat.com> wrote:

> On Mon, 2006-06-19 at 06:31 -0400, Chuck Ebbert wrote:
> > Looking at this code:
> > 
> > const struct exception_table_entry *search_exception_tables(unsigned long addr)
> > {
> >         const struct exception_table_entry *e;
> > 
> >         e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
> >         if (!e)
> >                 e = search_module_extables(addr);
> >         return e;
> > }
> > 
> > const struct exception_table_entry *search_module_extables(unsigned long addr)
> > {
> >         unsigned long flags;
> >         const struct exception_table_entry *e = NULL;
> >         struct module *mod;
> > 
> >         spin_lock_irqsave(&modlist_lock, flags);
> >         list_for_each_entry(mod, &modules, list) {
> >                 if (mod->num_exentries == 0)
> >                         continue;
> > 
> >                 e = search_extable(mod->extable,
> >                                    mod->extable + mod->num_exentries - 1,
> >                                    addr);
> >                 if (e)
> >                         break;
> >         }
> >         spin_unlock_irqrestore(&modlist_lock, flags);
> > 
> >         /* Now, if we found one, we are running inside it now, hence
> >            we cannot unload the module, hence no refcnt needed. */
> >         return e;
> > }
> > 
> > 
> > search_module_extables() takes a spinlock.  If some kind of fault occurs
> > while it's holding that lock (module list corrupted etc.,) won't it be
> > re-entered while looking for its own fault handler?  If so, would this
> > be a possible fix?
> > 
> > const struct exception_table_entry *search_exception_tables(unsigned long addr)
> > {
> >         const struct exception_table_entry *e;
> > 
> >         if (core_kernel_text(addr))
> >                 e = search_extable(__start___ex_table, __stop___ex_table-1, addr);
> >         else
> >                 e = search_module_extables(addr);
> > 
> >         return e;
> > }
> 
> I seem to be able to reliably trigger this spinlock recursion problem
> with systemtap on a RHEL4 kernel. The patch suggested above does seem to
> correct it, but I'm not familiar enough with extables to know whether
> the approach here is correct.
> 

It'll still deadlock if we take an oops from a module, won't it?

The usual way of fixing this sort of thing is to play games with
oops_in_progress.


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

end of thread, other threads:[~2006-11-08 19:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-19 10:31 Possible spinlock recursion in search_module_extables() ? Chuck Ebbert
2006-11-08 17:42 ` Jeff Layton
2006-11-08 18:56   ` Andrew Morton

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

all inboxes | Powered by JetHome®