public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Tips for module_init() dependencies
@ 2009-10-15 13:01 Gregory Haskins
  2009-10-15 15:45 ` Daniel Walker
  0 siblings, 1 reply; 10+ messages in thread
From: Gregory Haskins @ 2009-10-15 13:01 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

Hi All,

General question about the best-practices for dealing with intermodule
initialization dependencies.

The problem I am seeing arises when two features are enabled as built-in
but are available also as modules.

For instance, say I have feature "foo" and "bar".

Foo may do:

---------

static int foostate;

foo()
{
	/* do something with foostate */
}
EXPORT_SYMBOL_GPL(foo);

foo_init()
{
	foostate = 0;
}

module_init(foo_init);

--------------

likewise, bar may do

--------------

bar_init()
{
	foo();
}

module_init(bar_init);

--------------

If I build this system with

CONFIG_FOO=m
CONFIG_BAR=m

everything works, because modprobe will ensure that foo loads first

However:

CONFIG_FOO=y
CONFIG_BAR=y

may break, because the kernel seems to have no concept of
interdependency between foo_init() and bar_init(), and therefore
bar_init() may call foo() before foo_init() has executed.

There are various ways to solve this problem, such as deferring calling
foo() with a workqueue or something, but I was wondering if there was a
better/standard way to do this that I am missing?

The problem I am having specifically is that I am trying to call
configfs_register_subsystem() in a module_init(), but this breaks when
built into the kernel based on sheer bad luck that configfs gets
initialized after me.  To date I have worked around this by forcing my
code to only support built-in, and using late_initcall() instead or
module_init.  This works, but it only means I am putting the problem off
(code that depends on *me* has to use similar tricks, etc.

Any suggestions appreciated.

Kind Regards,
-Greg



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 267 bytes --]

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

* Re: Tips for module_init() dependencies
  2009-10-15 13:01 Tips for module_init() dependencies Gregory Haskins
@ 2009-10-15 15:45 ` Daniel Walker
  2009-10-15 15:58   ` Gregory Haskins
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Walker @ 2009-10-15 15:45 UTC (permalink / raw)
  To: Gregory Haskins; +Cc: linux-kernel@vger.kernel.org

On Thu, 2009-10-15 at 09:01 -0400, Gregory Haskins wrote:

> may break, because the kernel seems to have no concept of
> interdependency between foo_init() and bar_init(), and therefore
> bar_init() may call foo() before foo_init() has executed.
> 
> There are various ways to solve this problem, such as deferring calling
> foo() with a workqueue or something, but I was wondering if there was a
> better/standard way to do this that I am missing?
> 
> The problem I am having specifically is that I am trying to call
> configfs_register_subsystem() in a module_init(), but this breaks when
> built into the kernel based on sheer bad luck that configfs gets
> initialized after me.  To date I have worked around this by forcing my
> code to only support built-in, and using late_initcall() instead or
> module_init.  This works, but it only means I am putting the problem off
> (code that depends on *me* has to use similar tricks, etc.

You can't modify the build order so your module get "builtin" after
configfs?

Daniel 


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

* Re: Tips for module_init() dependencies
  2009-10-15 15:45 ` Daniel Walker
@ 2009-10-15 15:58   ` Gregory Haskins
  2009-10-15 16:06     ` Randy Dunlap
  2009-10-15 16:12     ` Daniel Walker
  0 siblings, 2 replies; 10+ messages in thread
From: Gregory Haskins @ 2009-10-15 15:58 UTC (permalink / raw)
  To: Daniel Walker; +Cc: linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]

Daniel Walker wrote:
> On Thu, 2009-10-15 at 09:01 -0400, Gregory Haskins wrote:
> 
>> may break, because the kernel seems to have no concept of
>> interdependency between foo_init() and bar_init(), and therefore
>> bar_init() may call foo() before foo_init() has executed.
>>
>> There are various ways to solve this problem, such as deferring calling
>> foo() with a workqueue or something, but I was wondering if there was a
>> better/standard way to do this that I am missing?
>>
>> The problem I am having specifically is that I am trying to call
>> configfs_register_subsystem() in a module_init(), but this breaks when
>> built into the kernel based on sheer bad luck that configfs gets
>> initialized after me.  To date I have worked around this by forcing my
>> code to only support built-in, and using late_initcall() instead or
>> module_init.  This works, but it only means I am putting the problem off
>> (code that depends on *me* has to use similar tricks, etc.
> 
> You can't modify the build order so your module get "builtin" after
> configfs?
> 

Hi Daniel,

Possibly.

A) Any suggestions on how? Can I express this in Kconfig or something
(i.e. "depends on FOO").  I currently have "select FOO" in the BAR
object, but this doesn't seem to be sufficient to describe the relationship.

B) Do I have to make the entire chain follow suit? (I have C deps on B,
B deps on A kind of scenarios)

Kind Regards,
-Greg



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 267 bytes --]

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

* Re: Tips for module_init() dependencies
  2009-10-15 15:58   ` Gregory Haskins
@ 2009-10-15 16:06     ` Randy Dunlap
  2009-10-15 16:13       ` Gregory Haskins
  2009-10-15 16:12     ` Daniel Walker
  1 sibling, 1 reply; 10+ messages in thread
From: Randy Dunlap @ 2009-10-15 16:06 UTC (permalink / raw)
  To: Gregory Haskins; +Cc: Daniel Walker, linux-kernel@vger.kernel.org

On Thu, 15 Oct 2009 11:58:19 -0400 Gregory Haskins wrote:

> Daniel Walker wrote:
> > On Thu, 2009-10-15 at 09:01 -0400, Gregory Haskins wrote:
> > 
> >> may break, because the kernel seems to have no concept of
> >> interdependency between foo_init() and bar_init(), and therefore
> >> bar_init() may call foo() before foo_init() has executed.
> >>
> >> There are various ways to solve this problem, such as deferring calling
> >> foo() with a workqueue or something, but I was wondering if there was a
> >> better/standard way to do this that I am missing?
> >>
> >> The problem I am having specifically is that I am trying to call
> >> configfs_register_subsystem() in a module_init(), but this breaks when
> >> built into the kernel based on sheer bad luck that configfs gets
> >> initialized after me.  To date I have worked around this by forcing my
> >> code to only support built-in, and using late_initcall() instead or
> >> module_init.  This works, but it only means I am putting the problem off
> >> (code that depends on *me* has to use similar tricks, etc.
> > 
> > You can't modify the build order so your module get "builtin" after
> > configfs?
> > 
> 
> Hi Daniel,
> 
> Possibly.
> 
> A) Any suggestions on how? Can I express this in Kconfig or something
> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
> object, but this doesn't seem to be sufficient to describe the relationship.

Not in Kconfig, only in Makefile(s).
and please put #comments in them explaining the ordering requirements/needs.

> B) Do I have to make the entire chain follow suit? (I have C deps on B,
> B deps on A kind of scenarios)
> 
> Kind Regards,
> -Greg


---
~Randy

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

* Re: Tips for module_init() dependencies
  2009-10-15 15:58   ` Gregory Haskins
  2009-10-15 16:06     ` Randy Dunlap
@ 2009-10-15 16:12     ` Daniel Walker
  2009-10-15 16:17       ` Gregory Haskins
  1 sibling, 1 reply; 10+ messages in thread
From: Daniel Walker @ 2009-10-15 16:12 UTC (permalink / raw)
  To: Gregory Haskins; +Cc: linux-kernel@vger.kernel.org

On Thu, 2009-10-15 at 11:58 -0400, Gregory Haskins wrote:

> Hi Daniel,
> 
> Possibly.
> 
> A) Any suggestions on how? Can I express this in Kconfig or something
> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
> object, but this doesn't seem to be sufficient to describe the relationship.
> 
> B) Do I have to make the entire chain follow suit? (I have C deps on B,
> B deps on A kind of scenarios)

Yeah, what Randy said .. As far as I know it should be just a build
order issue .. In the make file when you specify your new module along
with all the others where you put it is actually important .. In
fs/Makefile you have this line,

obj-$(CONFIG_CONFIGFS_FS)       += configfs/

and I would guess you want yours after that line if your adding to that
makefile.

Daniel


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

* Re: Tips for module_init() dependencies
  2009-10-15 16:06     ` Randy Dunlap
@ 2009-10-15 16:13       ` Gregory Haskins
  2009-10-15 16:18         ` Randy Dunlap
  0 siblings, 1 reply; 10+ messages in thread
From: Gregory Haskins @ 2009-10-15 16:13 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Daniel Walker, linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1764 bytes --]

Randy Dunlap wrote:
> On Thu, 15 Oct 2009 11:58:19 -0400 Gregory Haskins wrote:
> 
>> Daniel Walker wrote:
>>> On Thu, 2009-10-15 at 09:01 -0400, Gregory Haskins wrote:
>>>
>>>> may break, because the kernel seems to have no concept of
>>>> interdependency between foo_init() and bar_init(), and therefore
>>>> bar_init() may call foo() before foo_init() has executed.
>>>>
>>>> There are various ways to solve this problem, such as deferring calling
>>>> foo() with a workqueue or something, but I was wondering if there was a
>>>> better/standard way to do this that I am missing?
>>>>
>>>> The problem I am having specifically is that I am trying to call
>>>> configfs_register_subsystem() in a module_init(), but this breaks when
>>>> built into the kernel based on sheer bad luck that configfs gets
>>>> initialized after me.  To date I have worked around this by forcing my
>>>> code to only support built-in, and using late_initcall() instead or
>>>> module_init.  This works, but it only means I am putting the problem off
>>>> (code that depends on *me* has to use similar tricks, etc.
>>> You can't modify the build order so your module get "builtin" after
>>> configfs?
>>>
>> Hi Daniel,
>>
>> Possibly.
>>
>> A) Any suggestions on how? Can I express this in Kconfig or something
>> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
>> object, but this doesn't seem to be sufficient to describe the relationship.
> 
> Not in Kconfig, only in Makefile(s).
> and please put #comments in them explaining the ordering requirements/needs.

Hi Randy,

Something like this?

----------

# cat drivers/bar/Makefile

bar.o: foo.o
obj-$CONFIG_BAR += bar.o

----------

?

Kind Regards,
-Greg


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 267 bytes --]

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

* Re: Tips for module_init() dependencies
  2009-10-15 16:12     ` Daniel Walker
@ 2009-10-15 16:17       ` Gregory Haskins
  2009-10-15 16:21         ` Daniel Walker
  0 siblings, 1 reply; 10+ messages in thread
From: Gregory Haskins @ 2009-10-15 16:17 UTC (permalink / raw)
  To: Daniel Walker; +Cc: linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1197 bytes --]

Daniel Walker wrote:
> On Thu, 2009-10-15 at 11:58 -0400, Gregory Haskins wrote:
> 
>> Hi Daniel,
>>
>> Possibly.
>>
>> A) Any suggestions on how? Can I express this in Kconfig or something
>> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
>> object, but this doesn't seem to be sufficient to describe the relationship.
>>
>> B) Do I have to make the entire chain follow suit? (I have C deps on B,
>> B deps on A kind of scenarios)
> 
> Yeah, what Randy said .. As far as I know it should be just a build
> order issue .. In the make file when you specify your new module along
> with all the others where you put it is actually important .. In
> fs/Makefile you have this line,
> 
> obj-$(CONFIG_CONFIGFS_FS)       += configfs/
> 
> and I would guess you want yours after that line if your adding to that
> makefile.

Right, that makes sense.  However, the problem is that these
dependencies might not have anything to do with ./fs per se and
therefore would not necessarily be in the ./fs Makefile.  But I think
the Makefile dependency idea in general is the right approach, so I will
experiment with this suggestion.

Kind Regards,
-Greg



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 267 bytes --]

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

* Re: Tips for module_init() dependencies
  2009-10-15 16:13       ` Gregory Haskins
@ 2009-10-15 16:18         ` Randy Dunlap
  0 siblings, 0 replies; 10+ messages in thread
From: Randy Dunlap @ 2009-10-15 16:18 UTC (permalink / raw)
  To: Gregory Haskins; +Cc: Daniel Walker, linux-kernel@vger.kernel.org

On Thu, 15 Oct 2009 12:13:30 -0400 Gregory Haskins wrote:

> Randy Dunlap wrote:
> > On Thu, 15 Oct 2009 11:58:19 -0400 Gregory Haskins wrote:
> > 
> >> Daniel Walker wrote:
> >>> On Thu, 2009-10-15 at 09:01 -0400, Gregory Haskins wrote:
> >>>
> >>>> may break, because the kernel seems to have no concept of
> >>>> interdependency between foo_init() and bar_init(), and therefore
> >>>> bar_init() may call foo() before foo_init() has executed.
> >>>>
> >>>> There are various ways to solve this problem, such as deferring calling
> >>>> foo() with a workqueue or something, but I was wondering if there was a
> >>>> better/standard way to do this that I am missing?
> >>>>
> >>>> The problem I am having specifically is that I am trying to call
> >>>> configfs_register_subsystem() in a module_init(), but this breaks when
> >>>> built into the kernel based on sheer bad luck that configfs gets
> >>>> initialized after me.  To date I have worked around this by forcing my
> >>>> code to only support built-in, and using late_initcall() instead or
> >>>> module_init.  This works, but it only means I am putting the problem off
> >>>> (code that depends on *me* has to use similar tricks, etc.
> >>> You can't modify the build order so your module get "builtin" after
> >>> configfs?
> >>>
> >> Hi Daniel,
> >>
> >> Possibly.
> >>
> >> A) Any suggestions on how? Can I express this in Kconfig or something
> >> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
> >> object, but this doesn't seem to be sufficient to describe the relationship.
> > 
> > Not in Kconfig, only in Makefile(s).
> > and please put #comments in them explaining the ordering requirements/needs.
> 
> Hi Randy,
> 
> Something like this?
> 
> ----------
> 
> # cat drivers/bar/Makefile
> 
> bar.o: foo.o
> obj-$CONFIG_BAR += bar.o
> 
> ----------
> 
> ?

Just the order that they are listed in, either within one Makefile
or the order that a parent Makefile lists them, so:

obj-$CONFIG_FOO += foo.o
obj-$CONFIG_BAR += bar.o

That will fix the load/init ordering.  You may also need to specify
build dependencies in Kconfig file(s).


---
~Randy

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

* Re: Tips for module_init() dependencies
  2009-10-15 16:17       ` Gregory Haskins
@ 2009-10-15 16:21         ` Daniel Walker
  2009-10-15 16:50           ` Gregory Haskins
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Walker @ 2009-10-15 16:21 UTC (permalink / raw)
  To: Gregory Haskins; +Cc: linux-kernel@vger.kernel.org

On Thu, 2009-10-15 at 12:17 -0400, Gregory Haskins wrote:
> Daniel Walker wrote:
> > On Thu, 2009-10-15 at 11:58 -0400, Gregory Haskins wrote:
> > 
> >> Hi Daniel,
> >>
> >> Possibly.
> >>
> >> A) Any suggestions on how? Can I express this in Kconfig or something
> >> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
> >> object, but this doesn't seem to be sufficient to describe the relationship.
> >>
> >> B) Do I have to make the entire chain follow suit? (I have C deps on B,
> >> B deps on A kind of scenarios)
> > 
> > Yeah, what Randy said .. As far as I know it should be just a build
> > order issue .. In the make file when you specify your new module along
> > with all the others where you put it is actually important .. In
> > fs/Makefile you have this line,
> > 
> > obj-$(CONFIG_CONFIGFS_FS)       += configfs/
> > 
> > and I would guess you want yours after that line if your adding to that
> > makefile.
> 
> Right, that makes sense.  However, the problem is that these
> dependencies might not have anything to do with ./fs per se and
> therefore would not necessarily be in the ./fs Makefile.  But I think
> the Makefile dependency idea in general is the right approach, so I will
> experiment with this suggestion.

I think the order for the core stuff is,

kernel/ mm/ fs/ ipc/ security/ crypto/ block/

and that all comes before drivers/ , so your adding to kernel/ or mm/ ?

Daniel


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

* Re: Tips for module_init() dependencies
  2009-10-15 16:21         ` Daniel Walker
@ 2009-10-15 16:50           ` Gregory Haskins
  0 siblings, 0 replies; 10+ messages in thread
From: Gregory Haskins @ 2009-10-15 16:50 UTC (permalink / raw)
  To: Daniel Walker; +Cc: linux-kernel@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 1591 bytes --]

Daniel Walker wrote:
> On Thu, 2009-10-15 at 12:17 -0400, Gregory Haskins wrote:
>> Daniel Walker wrote:
>>> On Thu, 2009-10-15 at 11:58 -0400, Gregory Haskins wrote:
>>>
>>>> Hi Daniel,
>>>>
>>>> Possibly.
>>>>
>>>> A) Any suggestions on how? Can I express this in Kconfig or something
>>>> (i.e. "depends on FOO").  I currently have "select FOO" in the BAR
>>>> object, but this doesn't seem to be sufficient to describe the relationship.
>>>>
>>>> B) Do I have to make the entire chain follow suit? (I have C deps on B,
>>>> B deps on A kind of scenarios)
>>> Yeah, what Randy said .. As far as I know it should be just a build
>>> order issue .. In the make file when you specify your new module along
>>> with all the others where you put it is actually important .. In
>>> fs/Makefile you have this line,
>>>
>>> obj-$(CONFIG_CONFIGFS_FS)       += configfs/
>>>
>>> and I would guess you want yours after that line if your adding to that
>>> makefile.
>> Right, that makes sense.  However, the problem is that these
>> dependencies might not have anything to do with ./fs per se and
>> therefore would not necessarily be in the ./fs Makefile.  But I think
>> the Makefile dependency idea in general is the right approach, so I will
>> experiment with this suggestion.
> 
> I think the order for the core stuff is,
> 
> kernel/ mm/ fs/ ipc/ security/ crypto/ block/
> 
> and that all comes before drivers/ , so your adding to kernel/ or mm/ ?
> 
> Daniel
> 

Its currently in kernel, though I am not married to this location per se.

-Greg



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 267 bytes --]

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

end of thread, other threads:[~2009-10-15 16:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-15 13:01 Tips for module_init() dependencies Gregory Haskins
2009-10-15 15:45 ` Daniel Walker
2009-10-15 15:58   ` Gregory Haskins
2009-10-15 16:06     ` Randy Dunlap
2009-10-15 16:13       ` Gregory Haskins
2009-10-15 16:18         ` Randy Dunlap
2009-10-15 16:12     ` Daniel Walker
2009-10-15 16:17       ` Gregory Haskins
2009-10-15 16:21         ` Daniel Walker
2009-10-15 16:50           ` Gregory Haskins

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