From owner-svn-src-all@freebsd.org Mon Nov 23 18:18:18 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4EFF44694E5; Mon, 23 Nov 2020 18:18:18 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CfwPk1n8sz4cfc; Mon, 23 Nov 2020 18:18:18 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2DD2910D5F; Mon, 23 Nov 2020 18:18:18 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0ANIIHKd035957; Mon, 23 Nov 2020 18:18:17 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0ANIIGU6035950; Mon, 23 Nov 2020 18:18:16 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202011231818.0ANIIGU6035950@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 23 Nov 2020 18:18:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367960 - in head/sys: amd64/linux amd64/linux32 arm64/linux compat/linux i386/linux X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head/sys: amd64/linux amd64/linux32 arm64/linux compat/linux i386/linux X-SVN-Commit-Revision: 367960 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Nov 2020 18:18:18 -0000 Author: kib Date: Mon Nov 23 18:18:16 2020 New Revision: 367960 URL: https://svnweb.freebsd.org/changeset/base/367960 Log: Linuxolator: Replace use of eventhandlers by sysent hooks. Reviewed by: markj Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27309 Modified: head/sys/amd64/linux/linux_sysvec.c head/sys/amd64/linux32/linux32_sysvec.c head/sys/arm64/linux/linux_sysvec.c head/sys/compat/linux/linux_common.c head/sys/compat/linux/linux_emul.c head/sys/compat/linux/linux_emul.h head/sys/i386/linux/linux_sysvec.c Modified: head/sys/amd64/linux/linux_sysvec.c ============================================================================== --- head/sys/amd64/linux/linux_sysvec.c Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/amd64/linux/linux_sysvec.c Mon Nov 23 18:18:16 2020 (r367960) @@ -780,6 +780,9 @@ struct sysentvec elf_linux_sysvec = { .sv_schedtail = linux_schedtail, .sv_thread_detach = linux_thread_detach, .sv_trap = linux_vsyscall, + .sv_onexec = linux_on_exec, + .sv_onexit = linux_on_exit, + .sv_ontdexit = linux_thread_dtor, }; static void Modified: head/sys/amd64/linux32/linux32_sysvec.c ============================================================================== --- head/sys/amd64/linux32/linux32_sysvec.c Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/amd64/linux32/linux32_sysvec.c Mon Nov 23 18:18:16 2020 (r367960) @@ -925,6 +925,9 @@ struct sysentvec elf_linux_sysvec = { .sv_schedtail = linux_schedtail, .sv_thread_detach = linux_thread_detach, .sv_trap = NULL, + .sv_onexec = linux_on_exec, + .sv_onexit = linux_on_exit, + .sv_ontdexit = linux_thread_dtor, }; static void Modified: head/sys/arm64/linux/linux_sysvec.c ============================================================================== --- head/sys/arm64/linux/linux_sysvec.c Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/arm64/linux/linux_sysvec.c Mon Nov 23 18:18:16 2020 (r367960) @@ -419,6 +419,9 @@ struct sysentvec elf_linux_sysvec = { .sv_schedtail = linux_schedtail, .sv_thread_detach = linux_thread_detach, .sv_trap = linux_vsyscall, + .sv_onexec = linux_on_exec, + .sv_onexit = linux_on_exit, + .sv_ontdexit = linux_thread_dtor, }; static void Modified: head/sys/compat/linux/linux_common.c ============================================================================== --- head/sys/compat/linux/linux_common.c Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/compat/linux/linux_common.c Mon Nov 23 18:18:16 2020 (r367960) @@ -34,7 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include @@ -71,10 +71,6 @@ TAILQ_HEAD(, linux_ioctl_handler_element) linux_ioctl_ struct sx linux_ioctl_sx; SX_SYSINIT(linux_ioctl, &linux_ioctl_sx, "Linux ioctl handlers"); -static eventhandler_tag linux_exec_tag; -static eventhandler_tag linux_thread_dtor_tag; -static eventhandler_tag linux_exit_tag; - static int linux_common_modevent(module_t mod, int type, void *data) { @@ -87,12 +83,6 @@ linux_common_modevent(module_t mod, int type, void *da #endif linux_dev_shm_create(); linux_osd_jail_register(); - linux_exit_tag = EVENTHANDLER_REGISTER(process_exit, - linux_proc_exit, NULL, 1000); - linux_exec_tag = EVENTHANDLER_REGISTER(process_exec, - linux_proc_exec, NULL, 1000); - linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor, - linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY); SET_FOREACH(ldhp, linux_device_handler_set) linux_device_register_handler(*ldhp); LIST_INIT(&futex_list); @@ -104,9 +94,6 @@ linux_common_modevent(module_t mod, int type, void *da 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); break; default: return (EOPNOTSUPP); Modified: head/sys/compat/linux/linux_emul.c ============================================================================== --- head/sys/compat/linux/linux_emul.c Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/compat/linux/linux_emul.c Mon Nov 23 18:18:16 2020 (r367960) @@ -199,14 +199,13 @@ linux_proc_init(struct thread *td, struct thread *newt } void -linux_proc_exit(void *arg __unused, struct proc *p) +linux_on_exit(struct proc *p) { struct linux_pemuldata *pem; struct epoll_emuldata *emd; struct thread *td = curthread; - if (__predict_false(SV_CURPROC_ABI() != SV_ABI_LINUX)) - return; + MPASS(SV_CURPROC_ABI() == SV_ABI_LINUX); LINUX_CTR3(proc_exit, "thread(%d) proc(%d) p %p", td->td_tid, p->p_pid, p); @@ -313,7 +312,7 @@ linux_common_execve(struct thread *td, struct image_ar } void -linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp) +linux_on_exec(struct proc *p, struct image_params *imgp) { struct thread *td; struct thread *othertd; @@ -322,55 +321,52 @@ linux_proc_exec(void *arg __unused, struct proc *p, st #endif td = curthread; + MPASS((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX); /* - * In a case of execing to Linux binary we create Linux - * emuldata thread entry. + * When execing to Linux binary, we create Linux emuldata + * thread entry. */ - if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) == - SV_ABI_LINUX)) { - if (SV_PROC_ABI(p) == SV_ABI_LINUX) { - /* - * Process already was under Linuxolator - * before exec. Update emuldata to reflect - * single-threaded cleaned state after exec. - */ - linux_proc_init(td, NULL, 0); - } else { - /* - * We are switching the process to Linux emulator. - */ - linux_proc_init(td, td, 0); + if (SV_PROC_ABI(p) == SV_ABI_LINUX) { + /* + * Process already was under Linuxolator + * before exec. Update emuldata to reflect + * single-threaded cleaned state after exec. + */ + linux_proc_init(td, NULL, 0); + } else { + /* + * We are switching the process to Linux emulator. + */ + linux_proc_init(td, td, 0); - /* - * Create a transient td_emuldata for all suspended - * threads, so that p->p_sysent->sv_thread_detach() == - * linux_thread_detach() can find expected but unused - * emuldata. - */ - FOREACH_THREAD_IN_PROC(td->td_proc, othertd) { - if (othertd != td) { - linux_proc_init(td, othertd, - LINUX_CLONE_THREAD); - } - } - } -#if defined(__amd64__) /* - * An IA32 executable which has executable stack will have the - * READ_IMPLIES_EXEC personality flag set automatically. + * Create a transient td_emuldata for all suspended + * threads, so that p->p_sysent->sv_thread_detach() == + * linux_thread_detach() can find expected but unused + * emuldata. */ - if (SV_PROC_FLAG(td->td_proc, SV_ILP32) && - imgp->stack_prot & VM_PROT_EXECUTE) { - pem = pem_find(p); - pem->persona |= LINUX_READ_IMPLIES_EXEC; + FOREACH_THREAD_IN_PROC(td->td_proc, othertd) { + if (othertd == td) + continue; + linux_proc_init(td, othertd, LINUX_CLONE_THREAD); } -#endif } +#if defined(__amd64__) + /* + * An IA32 executable which has executable stack will have the + * READ_IMPLIES_EXEC personality flag set automatically. + */ + if (SV_PROC_FLAG(td->td_proc, SV_ILP32) && + imgp->stack_prot & VM_PROT_EXECUTE) { + pem = pem_find(p); + pem->persona |= LINUX_READ_IMPLIES_EXEC; + } +#endif } void -linux_thread_dtor(void *arg __unused, struct thread *td) +linux_thread_dtor(struct thread *td) { struct linux_emuldata *em; Modified: head/sys/compat/linux/linux_emul.h ============================================================================== --- head/sys/compat/linux/linux_emul.h Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/compat/linux/linux_emul.h Mon Nov 23 18:18:16 2020 (r367960) @@ -52,10 +52,10 @@ struct linux_emuldata *em_find(struct thread *); int linux_exec_imgact_try(struct image_params *); void linux_proc_init(struct thread *, struct thread *, int); -void linux_proc_exit(void *, struct proc *); +void linux_on_exit(struct proc *); void linux_schedtail(struct thread *); -void linux_proc_exec(void *, struct proc *, struct image_params *); -void linux_thread_dtor(void *arg __unused, struct thread *); +void linux_on_exec(struct proc *, struct image_params *); +void linux_thread_dtor(struct thread *); void linux_thread_detach(struct thread *); int linux_common_execve(struct thread *, struct image_args *); Modified: head/sys/i386/linux/linux_sysvec.c ============================================================================== --- head/sys/i386/linux/linux_sysvec.c Mon Nov 23 17:29:25 2020 (r367959) +++ head/sys/i386/linux/linux_sysvec.c Mon Nov 23 18:18:16 2020 (r367960) @@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include @@ -104,10 +103,6 @@ static void linux_vdso_deinstall(void *param); static int linux_szplatform; const char *linux_kplatform; -static eventhandler_tag linux_exit_tag; -static eventhandler_tag linux_exec_tag; -static eventhandler_tag linux_thread_dtor_tag; - #define LINUX_T_UNKNOWN 255 static int _bsd_to_linux_trapcode[] = { LINUX_T_UNKNOWN, /* 0 */ @@ -873,6 +868,9 @@ struct sysentvec linux_sysvec = { .sv_schedtail = linux_schedtail, .sv_thread_detach = linux_thread_detach, .sv_trap = NULL, + .sv_onexec = linux_on_exec, + .sv_onexit = linux_on_exit, + .sv_ontdexit = linux_thread_dtor, }; INIT_SYSENTVEC(aout_sysvec, &linux_sysvec); @@ -907,6 +905,9 @@ struct sysentvec elf_linux_sysvec = { .sv_schedtail = linux_schedtail, .sv_thread_detach = linux_thread_detach, .sv_trap = NULL, + .sv_onexec = linux_on_exec, + .sv_onexit = linux_on_exit, + .sv_ontdexit = linux_thread_dtor, }; static void @@ -1040,12 +1041,6 @@ linux_elf_modevent(module_t mod, int type, void *data) linux_ioctl_register_handler(*lihp); LIST_INIT(&futex_list); mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF); - linux_exit_tag = EVENTHANDLER_REGISTER(process_exit, linux_proc_exit, - NULL, 1000); - linux_exec_tag = EVENTHANDLER_REGISTER(process_exec, linux_proc_exec, - NULL, 1000); - linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor, - linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY); linux_get_machine(&linux_kplatform); linux_szplatform = roundup(strlen(linux_kplatform) + 1, sizeof(char *)); @@ -1072,9 +1067,6 @@ linux_elf_modevent(module_t mod, int type, void *data) SET_FOREACH(lihp, linux_ioctl_handler_set) linux_ioctl_unregister_handler(*lihp); 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); linux_dev_shm_destroy(); linux_osd_jail_deregister(); if (bootverbose)