Bug 7034 - modprobe misunderstands some modaliases and fails to load
Summary: modprobe misunderstands some modaliases and fails to load
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.21.x
Hardware: PC Linux
: P5 major
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-17 18:52 UTC by BitJam
Modified: 2014-05-02 04:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
busybox .config via "busybox bbconfig" (27.07 KB, text/plain)
2014-04-19 14:52 UTC, BitJam
Details
Debug output from modprobe command (807 bytes, text/plain)
2014-04-19 19:42 UTC, BitJam
Details
modules.dep.bb created by busybox (59.69 KB, text/plain)
2014-04-19 19:50 UTC, BitJam
Details

Note You need to log in before you can comment on or make changes to this bug.
Description BitJam 2014-04-17 18:52:35 UTC
When using mdev hotplugging or automatic hardware detection, modprobe must load modules by modalias instead of just by module name.  Most of the time this works but there are occasional failures that lead (in my case) to systems not booting.

For example, with the normal Linux modprobe, the following command will load the pata_via module:

modprobe pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a

but the busybox modprobe does nothing.  The vast majority of modules do get loaded correctly so this is not a generic problem with a missing modules.dep.bb.

grep pata_via modules.dep.bb | sed 's/ /\n/g':

live/pata_via.ko
pci:v00001106d00009001sv*sd*bc*sc*i*
pci:v00001106d0000C409sv*sd*bc*sc*i*
pci:v00001106d00005324sv*sd*bc*sc*i*
pci:v00001106d00003164sv*sd*bc*sc*i*
pci:v00001106d00001571sv*sd*bc*sc*i*
pci:v00001106d00000581sv*sd*bc*sc*i*
pci:v00001106d00000571sv*sd*bc*sc*i*
pci:v00001106d00000415sv*sd*bc*sc*i*

The entry that should have matched but did not is: pci:v00001106d00000571sv*sd*bc*sc*i*

This is the same modalias information used by working versions of modprobe.

The reason I gave this report a high priority is because it's a show-stopper bug for using busybox in generic live systems with automatic hardware detection but it only fails on some systems.  Intermittent failures are often worse than total failures.  Most of the time it works as expected so the bug is not replicated on any of my test systems and may in general be hard to catch during testing.  Also, the cause of the problem was not clear.  I had assumed modprobe was working and I was not calling it correctly.

My work-around is to use a standalone kmod program.  Since I already need to use libc, the addition of kmod and its lib only adds about 80K (compressed).

I hope the information here will make it easy to track down and fix the bug.  I don't have time to delve into your code now.   I have other examples of failures with other modules but this is the only example I have with complete modalias information.
Comment 1 Denys Vlasenko 2014-04-19 10:15:04 UTC
Please attach your .config
(In particular, I need to know whether CONFIG_MODPROBE_SMALL is selected).
Comment 2 Denys Vlasenko 2014-04-19 13:00:10 UTC
Ah, you are talking about modules.dep.bb, it means you are using
CONFIG_MODPROBE_SMALL=y

I am trying to reproduce this bug.
This is on Fedora 18 machine:
I built current git with CONFIG_MODPROBE_SMALL=y.
Ran "busybox depmod", it generated /lib/modules/3.10.11/modules.dep.bb
and I do have an entry there for pata_via:

kernel/drivers/ata/pata_via.ko pci:v00001106d00009001sv*sd*bc*sc*i* pci:v00001106d0000C409sv*sd*bc*sc*i* pci:v00001106d00005324sv*sd*bc*sc*i* pci:v00001106d00003164sv*sd*bc*sc*i* pci:v00001106d00001571sv*sd*bc*sc*i* pci:v00001106d00000581sv*sd*bc*sc*i* pci:v00001106d00000571sv*sd*bc*sc*i* pci:v00001106d00000415sv*sd*bc*sc*i*     

Now I enable debugging in modprobe_small.c:

#if 0   <============ HERE changed to 0
# define dbg1_error_msg(...) ((void)0)
# define dbg2_error_msg(...) ((void)0)
#else
# define dbg1_error_msg(...) bb_error_msg(__VA_ARGS__)
# define dbg2_error_msg(...) bb_error_msg(__VA_ARGS__)
#endif

and I try to modprobe the alias which doesn't work for you:

# ./busybox modprobe pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a
modprobe: loading modules.dep.bb
modprobe: process_module('pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a','(null)')
modprobe: already_loaded:0 is_rmmod:0
modprobe: process_module('pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a'): options:'(null)'
modprobe: find_alias('pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a')
modprobe: found alias 'pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a' in module 'kernel/drivers/ata/pata_via.ko'
modprobe: load_module('kernel/drivers/ata/pata_via.ko','(null)')
modprobe: load_module:0

As you see, it works for me.
In particular, the match triggered here:

                /* Does matching substring exist? */
                for (s = desc; *s; s += strlen(s) + 1) {
                        /* Aliases in module bodies can be defined with
                         * shell patterns. Example:
                         * "pci:v000010DEd000000D9sv*sd*bc*sc*i*".
                         * Plain strcmp() won't catch that */
                        if (fnmatch(s, alias, 0) == 0) {
                                dbg1_error_msg("found alias '%s' in module '%s'",
                                                alias, modinfo[i].pathname);
                                result = &modinfo[i];
                                break;
                        }
                }

Please enable debugging in modprobe_small.c, run modprobe and tell me what it says.
Please try current git.
Please attach your modules.dep.bb.
Comment 3 BitJam 2014-04-19 14:52:30 UTC
Created attachment 5342 [details]
busybox .config via "busybox bbconfig"

Yes, CONFIG_MODPROBE_SMALL is selected.  I did not think this would matter since the strings involved are the same whether this is selected or not.  

I provided the relevant line from modules.dep.bb which AFAIK is only created when CONFIG_MODPROBE_SMALL is set.
Comment 4 Denys Vlasenko 2014-04-19 16:39:09 UTC
(In reply to comment #3)
> Created attachment 5342 [details]
> busybox .config via "busybox bbconfig"
> 
> Yes, CONFIG_MODPROBE_SMALL is selected.  I did not think this would matter
> since the strings involved are the same whether this is selected or not.  
> 
> I provided the relevant line from modules.dep.bb which AFAIK is only created
> when CONFIG_MODPROBE_SMALL is set.

It works for me with your .config and with modules.dep.bb containing just one line:

kernel/drivers/ata/pata_via.ko pci:v00001106d00009001sv*sd*bc*sc*i* pci:v00001106d0000C409sv*sd*bc*sc*i* pci:v00001106d00005324sv*sd*bc*sc*i* pci:v00001106d00
003164sv*sd*bc*sc*i* pci:v00001106d00001571sv*sd*bc*sc*i* pci:v00001106d00000581sv*sd*bc*sc*i* pci:v00001106d00000571sv*sd*bc*sc*i* pci:v00001106d00000415sv*s
d*bc*sc*i*

(all on one line)

Please enable debugging in modprobe_small.c, run modprobe and tell me what it
says.
Please try current git.
Please attach your modules.dep.bb. Not one line. Entire file.
Comment 5 BitJam 2014-04-19 16:47:10 UTC
I will do those things but I can't do them instantly.  I had already moved on to kmod.  I compile busybox on a different system, etc.
Comment 6 BitJam 2014-04-19 19:42:47 UTC
Created attachment 5348 [details]
Debug output from modprobe command

The alias matches ata_generic.ko and the search seems to end there.  Should we not be using this module?

I will also attach modules.dep.bb.
Comment 7 BitJam 2014-04-19 19:50:06 UTC
Created attachment 5354 [details]
modules.dep.bb created by busybox
Comment 8 BitJam 2014-04-19 20:34:50 UTC
I believe this was with a recent Debian kernel.  

$ file vmlinuz
vmlinuz: Linux kernel x86 boot executable bzImage, version 3.12-0.bpo.1-686-pae (debian-kernel@lists.debian.org) #1 SMP De, RO-rootFS, swap_dev 0x2, Normal VGA

We did not maintain the directory structure under /lib/modules/*/.   Could this be contributing to the problem?
Comment 9 BitJam 2014-04-20 02:41:02 UTC
The problem still exits when I use the current git sources.  The debug messages look the same but I didn't diff them.  It stops after matching ata_generic.ko.
Comment 10 Denys Vlasenko 2014-04-21 15:06:26 UTC
Aha, it's a dup of 627.
I think I have a fix for that.

Please try current git, it has this commit:

commit 07e5555a8f7469f6f45cacd7fc188816ae644f74
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Mon Apr 21 16:59:36 2014 +0200

    modprobe-small: (un)load all modules which match the alias, not only first one

    Closes 627 and 7034.

    Commonly seen case is (un)loading of an alias
    which matches ata_generic and a more specific ata module.

    For example:

    modprobe [-r] pci:v00008086d00007010sv00000000sd00000000bc01sc01i80
    (ata_generic and pata_acpi)

    modprobe [-r] pci:v00001106d00000571sv00001509sd00009022bc01sc01i8a
    (ata_generic and pata_via)
Comment 11 BitJam 2014-04-21 16:41:26 UTC
I will try it.  BTW: I did not see bug 627 when I did a search for "modprobe".