devtmpfs: fix placement of complete() call
PATCH 1/2 devtmpfs: fix placement of complete() call
Calling complete() from within the __init function is wrong - theoretically, the init process could proceed all the way to freeing the init mem before the devtmpfsd thread gets to execute the return instruction in devtmpfs_setup().
In practice, it seems to be harmless as gcc inlines devtmpfs_setup() into devtmpfsd(). So the calls of the __init functions init_chdir() etc. actually happen from devtmpfs_setup(), but the __ref on that one silences modpost (it's all right, because those calls happen before the complete()). But it does make the __init annotation of the setup function moot, which we'll fix in a subsequent patch.
--- drivers/base/devtmpfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/devtmpfs.c +1 -1
@@ -419,7 +419,6 @@ static int __init devtmpfs_setup(void *p)init_chroot ("." ); out: *(int *)p = err; -complete (&setup_done);return err; }
@@ -432,6 +431,7 @@ static int __ref devtmpfsd(void *p) {int err =devtmpfs_setup (p); +complete (&setup_done);if (err)return err;devtmpfs_work_loop ();
Signature · 1 line
2.29.2
PATCH 2/2 devtmpfs: actually reclaim some init memory
Currently gcc seems to inline devtmpfs_setup() into devtmpfsd(), so its memory footprint isn't reclaimed as intended. Mark it noinline to make sure it gets put in .init.text.
While here, setup_done can also be put in .init.data: After complete() releases the internal spinlock, the completion object is never touched again by that thread, and the waiting thread doesn't proceed until it observes ->done while holding that spinlock.
This is now the same pattern as for kthreadd_done in init/main.c:complete() is done in a __ref function, while the corresponding wait_for_completion() is in an __init function.
--- drivers/base/devtmpfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/devtmpfs.c +2 -2
@@ -371,7 +371,7 @@ int __init devtmpfs_mount(void)return err; } -static DECLARE_COMPLETION (setup_done); +static __initdata DECLARE_COMPLETION (setup_done);static int handle (const char *name,umode_t mode,kuid_t uid,kgid_t gid,struct device *dev)
@@ -405,7 +405,7 @@ static void __noreturn devtmpfs_work_loop(void) } } -static int __init devtmpfs_setup (void *p) +static noinline int __init devtmpfs_setup(void *p) {int err;
Signature · 1 line
2.29.2
Re: [PATCH 2/2] devtmpfs: actually reclaim some init memory
Quoted 4 lines · Rasmus Villemoes
Currently gcc seems to inline
devtmpfs_setup()intodevtmpfsd(), so its memory footprint isn't reclaimed as intended. Mark it noinline to make sure it gets put in .init.text.
Quoted 8 lines
While here,
setup_donecan also be put in .init.data: Aftercomplete()releases the internal spinlock, the completion object is never touched again by that thread, and the waiting thread doesn't proceed until it observes ->done while holding that spinlock.This is now the same pattern as for
kthreadd_doneininit/main.c:complete()is done in a__reffunction, while the correspondingwait_for_completion()is in an__initfunction.
I'm not sure if this matters in any way, but it does look fine to me:
Looks fine:
Quoted 4 lines · Rasmus Villemoes
Calling
complete()from within the__initfunction is wrong - theoretically, the init process could proceed all the way to freeing the init mem before the devtmpfsd thread gets to execute the return instruction indevtmpfs_setup().
Greg, ping? Also for the other one.
Greg Kroah-Hartman
maintainerQuoted 7 lines · Rasmus Villemoes
Quoted 4 lines · Rasmus Villemoes
Calling
complete()from within the__initfunction is wrong - theoretically, the init process could proceed all the way to freeing the init mem before the devtmpfsd thread gets to execute the return instruction indevtmpfs_setup().Greg, ping? Also for the other one.
I'll pick this up for my tree, give me a chance to catch up, there's no rush with this one :)
thanks,
greg k-h