Re: [PATCH v3 1/3] init / kthread: add module_long_probe_init() and module_long_probe_exit()

From: Tetsuo Handa
Date: Tue Aug 12 2014 - 19:00:13 EST


Luis R. Rodriguez wrote:
> Tetsuo bisected and found that commit 786235ee \"kthread: make
> kthread_create() killable\" modified kthread_create() to bail as
> soon as SIGKILL is received.

I just wrote commit 786235ee. It is not Tetsuo who bisected it.

> @@ -128,4 +129,38 @@ bool queue_kthread_work(struct kthread_worker *worker,
> void flush_kthread_work(struct kthread_work *work);
> void flush_kthread_worker(struct kthread_worker *worker);
>
> +#ifndef MODULE
> +
> +#define module_long_probe_init(x) __initcall(x);
> +#define module_long_probe_exit(x) __exitcall(x);
> +
> +#else
> +/* To be used by modules which can take over 30 seconds at probe */
> +#define module_long_probe_init(initfn) \\
> + static struct task_struct *__init_thread; \\
> + static int _long_probe_##initfn(void *arg) \\
> + { \\
> + return initfn(); \\
> + } \\
> + static inline __init int __long_probe_##initfn(void) \\
> + { \\
> + __init_thread = kthread_run(_long_probe_##initfn,\\
> + NULL, \\
> + #initfn); \\
> + if (IS_ERR(__init_thread)) \\
> + return PTR_ERR(__init_thread); \\
> + return 0; \\
> + } \\
> + module_init(__long_probe_##initfn);
> +/* To be used by modules that require module_long_probe_init() */
> +#define module_long_probe_exit(exitfn) \\
> + static inline void __long_probe_##exitfn(void) \\
> + { \\
> + exitfn(); \\

exitfn() must not be called if initfn() failed or has not
completed yet. You need a bool variable for indicating that
we are ready to call exitfn().

Also, subsequent userspace operations may fail if
we return to userspace before initfn() completes
(e.g. device nodes are not created yet).

> + if (__init_thread) \\
> + kthread_stop(__init_thread); \\

We can\'t use kthread_stop() here because we have to
wait for initfn() to succeed before exitfn() is called.

> + } \\
> + module_exit(__long_probe_##exitfn);
> +#endif /* MODULE */
> +
> #endif /* _LINUX_KTHREAD_H */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/