diff mbox series

[RFC,v7,02/21] um: add os init and exit calls

Message ID 184f5b2c6a0c399edf519d27989519a35ab90700.1601960644.git.thehajime@gmail.com
State Not Applicable
Headers show
Series [RFC,v7,01/21] um: split build in kernel and host parts | expand

Commit Message

Hajime Tazaki Oct. 6, 2020, 9:44 a.m. UTC
From: Octavian Purdila <tavi@cs.pub.ro>

These calls are added in preparation for moving some of the code from
the kernel to the host build.

Signed-off-by: Octavian Purdila <tavi@cs.pub.ro>
---
 arch/um/include/shared/init.h | 14 ++++----------
 arch/um/kernel/reboot.c       |  5 +++++
 arch/um/kernel/um_arch.c      | 11 +++++++++++
 3 files changed, 20 insertions(+), 10 deletions(-)

Comments

Johannes Berg Oct. 7, 2020, 3:13 p.m. UTC | #1
On Tue, 2020-10-06 at 18:44 +0900, Hajime Tazaki wrote:
> 
> -#define __define_initcall(level,fn) \
> -	static initcall_t __initcall_##fn __used \
> -	__attribute__((__section__(".initcall" level ".init"))) = fn
> -
> -/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
> - * make them run first.
> - */
> -#define __initcall(fn) __define_initcall("1", fn)
> +#undef __uml_exit_call
> +#define __uml_exit_call		__used __section(os_exitcalls)

Doesn't that break calling of sigio_cleanup and remove_umid_dir?

After all,

> +void __weak os_exitcalls(void)
> +{
> +}

This does nothing so far.

Also, why the __weak?

johannes
Hajime Tazaki Oct. 8, 2020, 1:18 p.m. UTC | #2
On Thu, 08 Oct 2020 00:13:02 +0900,
Johannes Berg wrote:
> 
> On Tue, 2020-10-06 at 18:44 +0900, Hajime Tazaki wrote:
> > 
> > -#define __define_initcall(level,fn) \
> > -	static initcall_t __initcall_##fn __used \
> > -	__attribute__((__section__(".initcall" level ".init"))) = fn
> > -
> > -/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
> > - * make them run first.
> > - */
> > -#define __initcall(fn) __define_initcall("1", fn)
> > +#undef __uml_exit_call
> > +#define __uml_exit_call		__used __section(os_exitcalls)
> 
> Doesn't that break calling of sigio_cleanup and remove_umid_dir?

Without the patch 04/21 um: host: implement os_initcalls and
os_exitcalls, yes you're right.

> After all,
> 
> > +void __weak os_exitcalls(void)
> > +{
> > +}
> 
> This does nothing so far.
> 
> Also, why the __weak?

The intention is to define os_exitcalls() under tools/um so that the
actual exitcalls is located in different ELF sections (we defined
multiple __uml_exit_call for __UM_HOST__ and ! __UM_HOST__).  Thus
uml_cleanup() must see the symbol but give the place where actual
function is defined at tools/um.  Thus, this is __weak symbol-ed.

-- Hajime
diff mbox series

Patch

diff --git a/arch/um/include/shared/init.h b/arch/um/include/shared/init.h
index c66de434a983..d09308330ca5 100644
--- a/arch/um/include/shared/init.h
+++ b/arch/um/include/shared/init.h
@@ -109,19 +109,13 @@  extern struct uml_param __uml_setup_start, __uml_setup_end;
 
 #ifdef __UM_HOST__
 
-#define __define_initcall(level,fn) \
-	static initcall_t __initcall_##fn __used \
-	__attribute__((__section__(".initcall" level ".init"))) = fn
-
-/* Userspace initcalls shouldn't depend on anything in the kernel, so we'll
- * make them run first.
- */
-#define __initcall(fn) __define_initcall("1", fn)
+#undef __uml_exit_call
+#define __uml_exit_call		__used __section(os_exitcalls)
+#define __init_call		__used __section(os_initcalls)
 
+#define __initcall(fn) static initcall_t __initcall_##fn __init_call = fn
 #define __exitcall(fn) static exitcall_t __exitcall_##fn __exit_call = fn
 
-#define __init_call	__used __section(.initcall.init)
-
 #endif
 
 #endif /* _LINUX_UML_INIT_H */
diff --git a/arch/um/kernel/reboot.c b/arch/um/kernel/reboot.c
index 48c0610d506e..5420aec411f4 100644
--- a/arch/um/kernel/reboot.c
+++ b/arch/um/kernel/reboot.c
@@ -35,10 +35,15 @@  static void kill_off_processes(void)
 	read_unlock(&tasklist_lock);
 }
 
+void __weak os_exitcalls(void)
+{
+}
+
 void uml_cleanup(void)
 {
 	kmalloc_ok = 0;
 	do_uml_exitcalls();
+	os_exitcalls();
 	kill_off_processes();
 }
 
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 00141e70de56..e2cb76c03b25 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -377,3 +377,14 @@  void *text_poke(void *addr, const void *opcode, size_t len)
 void text_poke_sync(void)
 {
 }
+
+int __weak os_initcalls(void)
+{
+	return 0;
+}
+
+int __init run_os_initcalls(void)
+{
+	return os_initcalls();
+}
+early_initcall(run_os_initcalls);