git: 28a66fc3da34 - main - Do not call FreeBSD-ABI specific code for all ABIs

Konstantin Belousov kib at FreeBSD.org
Wed Jul 7 11:12:32 UTC 2021


The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=28a66fc3da3460850520389971e1194f5327f560

commit 28a66fc3da3460850520389971e1194f5327f560
Author:     Konstantin Belousov <kib at FreeBSD.org>
AuthorDate: 2021-07-01 18:00:29 +0000
Commit:     Konstantin Belousov <kib at FreeBSD.org>
CommitDate: 2021-07-07 11:12:07 +0000

    Do not call FreeBSD-ABI specific code for all ABIs
    
    Use sysentvec hooks to only call umtx_thread_exit/umtx_exec, which handle
    robust mutexes, for native FreeBSD ABI.  Similarly, there is no sense
    in calling sigfastblock_clear() for non-native ABIs.
    
    Requested by:   dchagin
    Reviewed by:    dchagin, markj (previous version)
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 weeks
    Differential revision:  https://reviews.freebsd.org/D30987
---
 sys/amd64/amd64/elf_machdep.c       | 4 ++++
 sys/arm/arm/elf_machdep.c           | 2 ++
 sys/arm64/arm64/elf32_machdep.c     | 2 ++
 sys/arm64/arm64/elf_machdep.c       | 2 ++
 sys/compat/ia32/ia32_sysvec.c       | 2 ++
 sys/i386/i386/elf_machdep.c         | 2 ++
 sys/kern/imgact_aout.c              | 4 ++++
 sys/kern/kern_exec.c                | 9 +++++++--
 sys/kern/kern_exit.c                | 8 +++++++-
 sys/mips/mips/elf_machdep.c         | 2 ++
 sys/powerpc/powerpc/elf32_machdep.c | 2 ++
 sys/powerpc/powerpc/elf64_machdep.c | 4 ++++
 sys/riscv/riscv/elf_machdep.c       | 2 ++
 sys/sys/sysent.h                    | 3 +++
 14 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/sys/amd64/amd64/elf_machdep.c b/sys/amd64/amd64/elf_machdep.c
index a7cef2a8d92a..80f7d1d8cefa 100644
--- a/sys/amd64/amd64/elf_machdep.c
+++ b/sys/amd64/amd64/elf_machdep.c
@@ -85,6 +85,8 @@ struct sysentvec elf64_freebsd_sysvec_la48 = {
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
 	.sv_stackgap	= elf64_stackgap,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 
 struct sysentvec elf64_freebsd_sysvec_la57 = {
@@ -123,6 +125,8 @@ struct sysentvec elf64_freebsd_sysvec_la57 = {
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
 	.sv_stackgap	= elf64_stackgap,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 
 static void
diff --git a/sys/arm/arm/elf_machdep.c b/sys/arm/arm/elf_machdep.c
index c67cd225a1af..64e347ce7649 100644
--- a/sys/arm/arm/elf_machdep.c
+++ b/sys/arm/arm/elf_machdep.c
@@ -100,6 +100,8 @@ struct sysentvec elf32_freebsd_sysvec = {
 	.sv_trap	= NULL,
 	.sv_hwcap	= &elf_hwcap,
 	.sv_hwcap2	= &elf_hwcap2,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec);
 
diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c
index 5321e12d74e9..206413b45172 100644
--- a/sys/arm64/arm64/elf32_machdep.c
+++ b/sys/arm64/arm64/elf32_machdep.c
@@ -112,6 +112,8 @@ static struct sysentvec elf32_freebsd_sysvec = {
 	.sv_schedtail	= NULL,
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec);
 
diff --git a/sys/arm64/arm64/elf_machdep.c b/sys/arm64/arm64/elf_machdep.c
index 82ecdf894911..eafaf4150dff 100644
--- a/sys/arm64/arm64/elf_machdep.c
+++ b/sys/arm64/arm64/elf_machdep.c
@@ -95,6 +95,8 @@ static struct sysentvec elf64_freebsd_sysvec = {
 	.sv_trap	= NULL,
 	.sv_hwcap	= &elf_hwcap,
 	.sv_hwcap2	= &elf_hwcap2,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf64_sysvec, &elf64_freebsd_sysvec);
 
diff --git a/sys/compat/ia32/ia32_sysvec.c b/sys/compat/ia32/ia32_sysvec.c
index 2b019e3b0323..df8a36a34810 100644
--- a/sys/compat/ia32/ia32_sysvec.c
+++ b/sys/compat/ia32/ia32_sysvec.c
@@ -131,6 +131,8 @@ struct sysentvec ia32_freebsd_sysvec = {
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
 	.sv_stackgap	= elf32_stackgap,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf_ia32_sysvec, &ia32_freebsd_sysvec);
 
diff --git a/sys/i386/i386/elf_machdep.c b/sys/i386/i386/elf_machdep.c
index cb7b5617715c..5858c8382e33 100644
--- a/sys/i386/i386/elf_machdep.c
+++ b/sys/i386/i386/elf_machdep.c
@@ -86,6 +86,8 @@ struct sysentvec elf32_freebsd_sysvec = {
 	.sv_schedtail	= NULL,
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec);
 
diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c
index 3255ef169f70..9e7455e14e1d 100644
--- a/sys/kern/imgact_aout.c
+++ b/sys/kern/imgact_aout.c
@@ -101,6 +101,8 @@ struct sysentvec aout_sysvec = {
 	.sv_schedtail	= NULL,
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
+	.sv_onexec_old = exec_onexec_old,
+	.sv_onexit =  exit_onexit,
 };
 
 #elif defined(__amd64__)
@@ -137,6 +139,8 @@ struct sysentvec aout_sysvec = {
 	.sv_set_syscall_retval = ia32_set_syscall_retval,
 	.sv_fetch_syscall_args = ia32_fetch_syscall_args,
 	.sv_syscallnames = freebsd32_syscallnames,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 #else
 #error "Port me"
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 763196a593e4..edb4ad1af3c1 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1040,6 +1040,13 @@ exec_unmap_first_page(struct image_params *imgp)
 	}
 }
 
+void
+exec_onexec_old(struct thread *td)
+{
+	sigfastblock_clear(td);
+	umtx_exec(td->td_proc);
+}
+
 /*
  * Destroy old address space, and allocate a new stack.
  *	The new stack is only sgrowsiz large because it is grown
@@ -1062,8 +1069,6 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv)
 	imgp->vmspace_destroyed = 1;
 	imgp->sysent = sv;
 
-	sigfastblock_clear(td);
-	umtx_exec(p);
 	if (p->p_sysent->sv_onexec_old != NULL)
 		p->p_sysent->sv_onexec_old(td);
 	itimers_exec(p);
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 515c2d4e6397..bfd25366b49c 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -195,6 +195,13 @@ proc_clear_orphan(struct proc *p)
 	p->p_treeflag &= ~P_TREE_ORPHANED;
 }
 
+void
+exit_onexit(struct proc *p)
+{
+	MPASS(p->p_numthreads == 1);
+	umtx_thread_exit(FIRST_THREAD_IN_PROC(p));
+}
+
 /*
  * exit -- death of process.
  */
@@ -370,7 +377,6 @@ exit1(struct thread *td, int rval, int signo)
 
 	PROC_UNLOCK(p);
 
-	umtx_thread_exit(td);
 	if (p->p_sysent->sv_onexit != NULL)
 		p->p_sysent->sv_onexit(p);
 	seltdfini(td);
diff --git a/sys/mips/mips/elf_machdep.c b/sys/mips/mips/elf_machdep.c
index 9df6d1d36436..c6a45f71107b 100644
--- a/sys/mips/mips/elf_machdep.c
+++ b/sys/mips/mips/elf_machdep.c
@@ -91,6 +91,8 @@ static struct sysentvec elf_freebsd_sysvec = {
 	.sv_schedtail	= NULL,
 	.sv_thread_detach = NULL,
 	.sv_trap	= NULL,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 
 static __ElfN(Brandinfo) freebsd_brand_info = {
diff --git a/sys/powerpc/powerpc/elf32_machdep.c b/sys/powerpc/powerpc/elf32_machdep.c
index 2c4928f7d9df..341352fdd589 100644
--- a/sys/powerpc/powerpc/elf32_machdep.c
+++ b/sys/powerpc/powerpc/elf32_machdep.c
@@ -134,6 +134,8 @@ struct sysentvec elf32_freebsd_sysvec = {
 	.sv_trap	= NULL,
 	.sv_hwcap	= &cpu_features,
 	.sv_hwcap2	= &cpu_features2,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf32_sysvec, &elf32_freebsd_sysvec);
 
diff --git a/sys/powerpc/powerpc/elf64_machdep.c b/sys/powerpc/powerpc/elf64_machdep.c
index 38f76c158793..dca1ec6bb535 100644
--- a/sys/powerpc/powerpc/elf64_machdep.c
+++ b/sys/powerpc/powerpc/elf64_machdep.c
@@ -96,6 +96,8 @@ struct sysentvec elf64_freebsd_sysvec_v1 = {
 	.sv_trap	= NULL,
 	.sv_hwcap	= &cpu_features,
 	.sv_hwcap2	= &cpu_features2,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 
 struct sysentvec elf64_freebsd_sysvec_v2 = {
@@ -135,6 +137,8 @@ struct sysentvec elf64_freebsd_sysvec_v2 = {
 	.sv_trap	= NULL,
 	.sv_hwcap	= &cpu_features,
 	.sv_hwcap2	= &cpu_features2,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 
 static boolean_t ppc64_elfv1_header_match(struct image_params *params,
diff --git a/sys/riscv/riscv/elf_machdep.c b/sys/riscv/riscv/elf_machdep.c
index 2a355a977800..8cb1355708d2 100644
--- a/sys/riscv/riscv/elf_machdep.c
+++ b/sys/riscv/riscv/elf_machdep.c
@@ -99,6 +99,8 @@ struct sysentvec elf64_freebsd_sysvec = {
 	.sv_trap	= NULL,
 	.sv_hwcap	= &elf_hwcap,
 	.sv_machine_arch = riscv_machine_arch,
+	.sv_onexec_old	= exec_onexec_old,
+	.sv_onexit	= exit_onexit,
 };
 INIT_SYSENTVEC(elf64_sysvec, &elf64_freebsd_sysvec);
 
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index 869c140c06f5..f0bb084d59dc 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -322,6 +322,9 @@ void exec_sysvec_init(void *param);
 void exec_sysvec_init_secondary(struct sysentvec *sv, struct sysentvec *sv2);
 void exec_inittk(void);
 
+void exit_onexit(struct proc *p);
+void exec_onexec_old(struct thread *td);
+
 #define INIT_SYSENTVEC(name, sv)					\
     SYSINIT(name, SI_SUB_EXEC, SI_ORDER_ANY,				\
 	(sysinit_cfunc_t)exec_sysvec_init, sv);


More information about the dev-commits-src-main mailing list