From ad16acfadb9196e6d3f626287de2461710b871bb Mon Sep 17 00:00:00 2001 From: yuripv Date: Fri, 18 Oct 2019 12:25:33 +0000 Subject: [PATCH] linux: futex_mtx should follow futex_list Move futex_mtx to linux_common.ko for amd64 and aarch64 along with respective list/mutex init/destroy. PR: 240989 Reported by: Alex S --- sys/amd64/linux/linux_sysvec.c | 4 ---- sys/amd64/linux32/linux32_sysvec.c | 4 ---- sys/arm64/linux/linux_sysvec.c | 4 ---- sys/compat/linux/linux.c | 1 + sys/compat/linux/linux.h | 1 + sys/compat/linux/linux_common.c | 4 ++++ sys/compat/linux/linux_futex.c | 1 - sys/compat/linux/linux_futex.h | 2 -- sys/i386/linux/linux_sysvec.c | 1 - 9 files changed, 6 insertions(+), 16 deletions(-) diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index 368b5196fba4..5bfdacac8454 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -75,7 +75,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -865,8 +864,6 @@ linux64_elf_modevent(module_t mod, int type, void *data) if (error == 0) { SET_FOREACH(lihp, linux_ioctl_handler_set) linux_ioctl_register_handler(*lihp); - LIST_INIT(&futex_list); - mtx_init(&futex_mtx, "ftllk64", NULL, MTX_DEF); stclohz = (stathz ? stathz : hz); if (bootverbose) printf("Linux x86-64 ELF exec handler installed\n"); @@ -887,7 +884,6 @@ linux64_elf_modevent(module_t mod, int type, void *data) if (error == 0) { SET_FOREACH(lihp, linux_ioctl_handler_set) linux_ioctl_unregister_handler(*lihp); - mtx_destroy(&futex_mtx); if (bootverbose) printf("Linux ELF exec handler removed\n"); } else diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index d49be15d04f8..a7d886f0c42a 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -81,7 +81,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -1023,8 +1022,6 @@ linux_elf_modevent(module_t mod, int type, void *data) if (error == 0) { SET_FOREACH(lihp, linux_ioctl_handler_set) linux32_ioctl_register_handler(*lihp); - LIST_INIT(&futex_list); - mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF); stclohz = (stathz ? stathz : hz); if (bootverbose) printf("Linux ELF exec handler installed\n"); @@ -1045,7 +1042,6 @@ linux_elf_modevent(module_t mod, int type, void *data) if (error == 0) { SET_FOREACH(lihp, linux_ioctl_handler_set) linux32_ioctl_unregister_handler(*lihp); - mtx_destroy(&futex_mtx); if (bootverbose) printf("Linux ELF exec handler removed\n"); } else diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c index f34538cc207a..7c0cc7153a2d 100644 --- a/sys/arm64/linux/linux_sysvec.c +++ b/sys/arm64/linux/linux_sysvec.c @@ -51,7 +51,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -494,8 +493,6 @@ linux64_elf_modevent(module_t mod, int type, void *data) if (error == 0) { SET_FOREACH(lihp, linux_ioctl_handler_set) linux_ioctl_register_handler(*lihp); - LIST_INIT(&futex_list); - mtx_init(&futex_mtx, "ftllk64", NULL, MTX_DEF); stclohz = (stathz ? stathz : hz); if (bootverbose) printf("Linux arm64 ELF exec handler installed\n"); @@ -515,7 +512,6 @@ linux64_elf_modevent(module_t mod, int type, void *data) if (error == 0) { SET_FOREACH(lihp, linux_ioctl_handler_set) linux_ioctl_unregister_handler(*lihp); - mtx_destroy(&futex_mtx); if (bootverbose) printf("Linux ELF exec handler removed\n"); } else diff --git a/sys/compat/linux/linux.c b/sys/compat/linux/linux.c index f88ca47cef42..fa1e8f315f9e 100644 --- a/sys/compat/linux/linux.c +++ b/sys/compat/linux/linux.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include struct futex_list futex_list; +struct mtx futex_mtx; /* protects the futex list */ CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ); diff --git a/sys/compat/linux/linux.h b/sys/compat/linux/linux.h index 2be398ba5b05..2959c1dfe320 100644 --- a/sys/compat/linux/linux.h +++ b/sys/compat/linux/linux.h @@ -141,5 +141,6 @@ int linux_to_bsd_signal(int sig); int bsd_to_linux_signal(int sig); extern LIST_HEAD(futex_list, futex) futex_list; +extern struct mtx futex_mtx; #endif /* _LINUX_MI_H_ */ diff --git a/sys/compat/linux/linux_common.c b/sys/compat/linux/linux_common.c index 52b1562cb19e..2bb11c279761 100644 --- a/sys/compat/linux/linux_common.c +++ b/sys/compat/linux/linux_common.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -76,11 +77,14 @@ linux_common_modevent(module_t mod, int type, void *data) linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY); SET_FOREACH(ldhp, linux_device_handler_set) linux_device_register_handler(*ldhp); + LIST_INIT(&futex_list); + mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF); break; case MOD_UNLOAD: linux_osd_jail_deregister(); SET_FOREACH(ldhp, linux_device_handler_set) linux_device_unregister_handler(*ldhp); + mtx_destroy(&futex_mtx); EVENTHANDLER_DEREGISTER(process_exit, linux_exit_tag); EVENTHANDLER_DEREGISTER(process_exec, linux_exec_tag); EVENTHANDLER_DEREGISTER(thread_dtor, linux_thread_dtor_tag); diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index 831e990cc7eb..4f42081156b5 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -224,7 +224,6 @@ struct futex { #define FUTEX_ASSERT_LOCKED(f) mtx_assert(&(f)->f_lck, MA_OWNED) #define FUTEX_ASSERT_UNLOCKED(f) mtx_assert(&(f)->f_lck, MA_NOTOWNED) -struct mtx futex_mtx; /* protects the futex list */ #define FUTEXES_LOCK do { \ mtx_lock(&futex_mtx); \ LIN_SDT_PROBE1(locks, futex_mtx, \ diff --git a/sys/compat/linux/linux_futex.h b/sys/compat/linux/linux_futex.h index 6dd1075bd368..bf546538c981 100644 --- a/sys/compat/linux/linux_futex.h +++ b/sys/compat/linux/linux_futex.h @@ -38,8 +38,6 @@ #ifndef _LINUX_FUTEX_H #define _LINUX_FUTEX_H -extern struct mtx futex_mtx; - #define LINUX_FUTEX_WAIT 0 #define LINUX_FUTEX_WAKE 1 #define LINUX_FUTEX_FD 2 /* unused */ diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 26b78c2e93d4..5d1c11c57dab 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -67,7 +67,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include