Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 97364 - depmod does not consider kernel symbols first when building dependency.
Summary: depmod does not consider kernel symbols first when building dependency.
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High trivial
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-28 20:08 UTC by Ben Gardiner
Modified: 2005-06-29 23:01 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Gardiner 2005-06-28 20:08:23 UTC
Depmod, when building its symbol dependecies, will search for any source of
required symbols for a given module. This behaviour can lead to 'ghost'
dependecy loops. For example: adeos.ko needs printk, rtai_hal.ko needs various
symbols from adeos.ko, but provides its own printk. Depmod's current behaviour
is to report the apparent loop and spit out the dependency for anything not
associated with the two troublemakers. 

Reproducible: Always
Steps to Reproduce:
1.
2.
3.
Comment 1 Ben Gardiner 2005-06-28 20:13:22 UTC
The problem can be fixed by applying the following patch to 3.0-r2:
*** depmod.c~   Wed Jun 29 07:04:43 2005
--- depmod.c    Wed Jun 29 07:06:10 2005
***************
*** 100,107 ****
        strcpy(new->name, name);

        hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
!       new->next = symbolhash[hash];
!       symbolhash[hash] = new;
  }

  static int print_unknown;
--- 100,116 ----
        strcpy(new->name, name);

        hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
!       /*BG: ensure the symbols from the kernel are always found first*/
!       if(!(symbolhash[hash]) || symbolhash[hash]->owner)
!       {
!               new->next = symbolhash[hash];
!               symbolhash[hash] = new;
!       }
!       else
!       {
!               new->next = symbolhash[hash]->next;
!               symbolhash[hash]->next = new;
!       }
  }

  static int print_unknown;
Comment 2 SpanKY gentoo-dev 2005-06-28 21:25:59 UTC
this applies cleanly to 3.2-pre7 it looks like
Comment 3 Rusty Russell 2005-06-29 18:16:42 UTC
Note: real bug is that rtai_hal exports printk.  That's just *stupid*.  How is
the kernel supposed to know which one to use?  Certainly it's an interesting
potential for modules mugging other modules.

However, "fix" of inserting in second place in hash is not correct either: that
will only work for a single symbol in each hash bucket.  Right fix is probably
to do search on insert of symbol, complain about broken module, and not to add
the symbol.  IIRC there are some modules which export the same symbols as other
modules (a dubious practice, but sometimes neccessary), so you may want to
suppress this unless it's a core kernel symbol being overridden.

Please try this instead.
Comment 4 Ben Gardiner 2005-06-29 19:42:54 UTC
Rusty, I didn't think I'd actually have to defend this to the author of
depmod... I love depmod - couldn't live without it :) So hear goes:

rtai_hal exports printk because it is meant to override the kernel's printk
(IIRC) so that any modules operating in its real-time domain can print kernel
messages without fear of race. 

RTAI isn't what you would call a 'desktop' patch, but it is useful when you are
building systems that need to meet real-time contraints and you don't want to
shell out large for something like RTLinux. So I can't agree that it is stupid.
I guess the reason this 'problem' has never popped up before is that users of
RTAI are using insmod for modules, which will work with the above combination of
rtai_hal and adeos.

That aside, what I saw as the problem was that depmod wouldn't build the
dependency list for the modules because it saw a loop that wasn't there - the
kernel provided the culprit symbol all along.

I apologize for using the word 'fixed' when it is clearly a workaround. It
seemed to me that since insmod'ing the modules resulted in no catastrophies then
depmod should be able to prepare a dep list so that modprobe could do the same.
I simply exploited the fact that the symbol search was done linearly from the
hash-point.

If there is a rule stating that modules cannot export symbols already exported
by the kernel, then rejecting those modules whose symbols override the kernel's
 is the go, for sure; however, you are then relegating (at least) the users of
rtai to the realm of insmod forever. Which probably isn't a big deal, since it
seems like they are happy there - and I'll be content forever patching depmod as
the releases roll in. :)

Would you accept the following?
1. implementing the search for duplicate symbols prior to the addition of the
symbol to the hash-table.
2. adding a strictness level: 
  2-don't allow any duplication of symbols 
  1-allow modules to duplicate symbols from other modules (default)
  0-level 1 and allow modules to duplicate symbols from the kernel.
Comment 5 Rusty Russell 2005-06-29 20:11:33 UTC
> rtai_hal exports printk because it is meant to override the kernel's printk
> (IIRC) so that any modules operating in its real-time domain can print kernel
> messages without fear of race. 

But (1) all the internal printks are not overridden,
(2) overriding symbols is undefined behavior, and
(3) if you don't consider rtai_hal to be a dependency then it won't be
automatically loaded by all other modules which you seem to want.

The correct solution is either that rtai_hal needs to export an entry point from
the real printk which allows it to override it, or to use some other name in
modules which need real-time behavior.

Sorry,
Rusty.
Comment 6 Ben Gardiner 2005-06-29 23:01:27 UTC
Ok, I buy it.
I'll move the problem to the RTAI people.