Push KERNEL_LOCK/UNLOCK in trapsignal()
Taken from a larger diff from claudio@, this reduces the lock dances in MD code and put it where we should focus our effort in kern/kern_sig.c. ok? Index: kern/kern_sig.c === RCS file: /cvs/src/sys/kern/kern_sig.c,v retrieving revision 1.258 diff -u -p -r1.258 kern_sig.c --- kern/kern_sig.c 15 Jun 2020 13:18:33 - 1.258 +++ kern/kern_sig.c 18 Aug 2020 09:34:11 - @@ -802,6 +802,7 @@ trapsignal(struct proc *p, int signum, u struct sigacts *ps = pr->ps_sigacts; int mask; + KERNEL_LOCK(); switch (signum) { case SIGILL: case SIGBUS: @@ -842,6 +843,7 @@ trapsignal(struct proc *p, int signum, u sigexit(p, signum); ptsignal(p, signum, STHREAD); } + KERNEL_UNLOCK(); } /* Index: arch/alpha/alpha/trap.c === RCS file: /cvs/src/sys/arch/alpha/alpha/trap.c,v retrieving revision 1.88 diff -u -p -r1.88 trap.c --- arch/alpha/alpha/trap.c 6 Sep 2019 12:22:01 - 1.88 +++ arch/alpha/alpha/trap.c 18 Aug 2020 09:18:54 - @@ -488,9 +488,7 @@ do_fault: printtrap(a0, a1, a2, entry, framep, 1, user); #endif sv.sival_ptr = v; - KERNEL_LOCK(); trapsignal(p, i, ucode, typ, sv); - KERNEL_UNLOCK(); out: if (user) { /* Do any deferred user pmap operations. */ Index: arch/amd64/amd64/trap.c === RCS file: /cvs/src/sys/arch/amd64/amd64/trap.c,v retrieving revision 1.79 diff -u -p -r1.79 trap.c --- arch/amd64/amd64/trap.c 21 Jan 2020 03:06:39 - 1.79 +++ arch/amd64/amd64/trap.c 18 Aug 2020 09:18:54 - @@ -391,9 +391,7 @@ usertrap(struct trapframe *frame) } sv.sival_ptr = (void *)frame->tf_rip; - KERNEL_LOCK(); trapsignal(p, sig, type, code, sv); - KERNEL_UNLOCK(); out: userret(p); Index: arch/arm/arm/fault.c === RCS file: /cvs/src/sys/arch/arm/arm/fault.c,v retrieving revision 1.39 diff -u -p -r1.39 fault.c --- arch/arm/arm/fault.c6 Sep 2019 12:22:01 - 1.39 +++ arch/arm/arm/fault.c18 Aug 2020 09:18:54 - @@ -373,9 +373,7 @@ data_abort_handler(trapframe_t *tf) sd.trap = fsr; do_trapsignal: sv.sival_int = sd.addr; - KERNEL_LOCK(); trapsignal(p, sd.signo, sd.trap, sd.code, sv); - KERNEL_UNLOCK(); out: /* If returning to user mode, make sure to invoke userret() */ if (user) @@ -596,13 +594,9 @@ prefetch_abort_handler(trapframe_t *tf) printf("UVM: pid %d (%s), uid %d killed: " "out of swap\n", p->p_p->ps_pid, p->p_p->ps_comm, p->p_ucred ? (int)p->p_ucred->cr_uid : -1); - KERNEL_LOCK(); trapsignal(p, SIGKILL, 0, SEGV_MAPERR, sv); - KERNEL_UNLOCK(); } else { - KERNEL_LOCK(); trapsignal(p, SIGSEGV, 0, SEGV_MAPERR, sv); - KERNEL_UNLOCK(); } out: Index: arch/arm/arm/undefined.c === RCS file: /cvs/src/sys/arch/arm/arm/undefined.c,v retrieving revision 1.13 diff -u -p -r1.13 undefined.c --- arch/arm/arm/undefined.c13 Mar 2019 09:28:21 - 1.13 +++ arch/arm/arm/undefined.c18 Aug 2020 09:18:54 - @@ -113,9 +113,7 @@ gdb_trapper(u_int addr, u_int insn, stru if (insn == GDB_BREAKPOINT || insn == GDB5_BREAKPOINT) { if (code == FAULT_USER) { sv.sival_int = addr; - KERNEL_LOCK(); trapsignal(p, SIGTRAP, 0, TRAP_BRKPT, sv); - KERNEL_UNLOCK(); return 0; } } @@ -174,9 +172,7 @@ undefinedinstruction(trapframe_t *frame) if (__predict_false((fault_pc & 3) != 0)) { /* Give the user an illegal instruction signal. */ sv.sival_int = (u_int32_t) fault_pc; - KERNEL_LOCK(); trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv); - KERNEL_UNLOCK(); userret(p); return; } @@ -260,9 +256,7 @@ undefinedinstruction(trapframe_t *frame) } sv.sival_int = frame->tf_pc; - KERNEL_LOCK(); trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv); - KERNEL_UNLOCK(); } if ((fault_code & FAULT_USER) == 0) Index: arch/arm64/arm64/trap.c === RCS file: /cvs/src/sys/arch/arm64/arm64/trap.c,v retrieving revision 1.28 diff -u -p -r1.28 trap.c --- arch/arm64/arm64/trap.c 17 Aug 2020 08:09:03 - 1.28 +++ arch/arm64/arm64/trap.c
Re: Push KERNEL_LOCK/UNLOCK in trapsignal()
> Date: Tue, 18 Aug 2020 11:52:17 +0200 > From: Martin Pieuchot > > Taken from a larger diff from claudio@, this reduces the lock dances in > MD code and put it where we should focus our effort in kern/kern_sig.c. > > ok? Agreed. ok kettenis@ > Index: kern/kern_sig.c > === > RCS file: /cvs/src/sys/kern/kern_sig.c,v > retrieving revision 1.258 > diff -u -p -r1.258 kern_sig.c > --- kern/kern_sig.c 15 Jun 2020 13:18:33 - 1.258 > +++ kern/kern_sig.c 18 Aug 2020 09:34:11 - > @@ -802,6 +802,7 @@ trapsignal(struct proc *p, int signum, u > struct sigacts *ps = pr->ps_sigacts; > int mask; > > + KERNEL_LOCK(); > switch (signum) { > case SIGILL: > case SIGBUS: > @@ -842,6 +843,7 @@ trapsignal(struct proc *p, int signum, u > sigexit(p, signum); > ptsignal(p, signum, STHREAD); > } > + KERNEL_UNLOCK(); > } > > /* > Index: arch/alpha/alpha/trap.c > === > RCS file: /cvs/src/sys/arch/alpha/alpha/trap.c,v > retrieving revision 1.88 > diff -u -p -r1.88 trap.c > --- arch/alpha/alpha/trap.c 6 Sep 2019 12:22:01 - 1.88 > +++ arch/alpha/alpha/trap.c 18 Aug 2020 09:18:54 - > @@ -488,9 +488,7 @@ do_fault: > printtrap(a0, a1, a2, entry, framep, 1, user); > #endif > sv.sival_ptr = v; > - KERNEL_LOCK(); > trapsignal(p, i, ucode, typ, sv); > - KERNEL_UNLOCK(); > out: > if (user) { > /* Do any deferred user pmap operations. */ > Index: arch/amd64/amd64/trap.c > === > RCS file: /cvs/src/sys/arch/amd64/amd64/trap.c,v > retrieving revision 1.79 > diff -u -p -r1.79 trap.c > --- arch/amd64/amd64/trap.c 21 Jan 2020 03:06:39 - 1.79 > +++ arch/amd64/amd64/trap.c 18 Aug 2020 09:18:54 - > @@ -391,9 +391,7 @@ usertrap(struct trapframe *frame) > } > > sv.sival_ptr = (void *)frame->tf_rip; > - KERNEL_LOCK(); > trapsignal(p, sig, type, code, sv); > - KERNEL_UNLOCK(); > > out: > userret(p); > Index: arch/arm/arm/fault.c > === > RCS file: /cvs/src/sys/arch/arm/arm/fault.c,v > retrieving revision 1.39 > diff -u -p -r1.39 fault.c > --- arch/arm/arm/fault.c 6 Sep 2019 12:22:01 - 1.39 > +++ arch/arm/arm/fault.c 18 Aug 2020 09:18:54 - > @@ -373,9 +373,7 @@ data_abort_handler(trapframe_t *tf) > sd.trap = fsr; > do_trapsignal: > sv.sival_int = sd.addr; > - KERNEL_LOCK(); > trapsignal(p, sd.signo, sd.trap, sd.code, sv); > - KERNEL_UNLOCK(); > out: > /* If returning to user mode, make sure to invoke userret() */ > if (user) > @@ -596,13 +594,9 @@ prefetch_abort_handler(trapframe_t *tf) > printf("UVM: pid %d (%s), uid %d killed: " > "out of swap\n", p->p_p->ps_pid, p->p_p->ps_comm, > p->p_ucred ? (int)p->p_ucred->cr_uid : -1); > - KERNEL_LOCK(); > trapsignal(p, SIGKILL, 0, SEGV_MAPERR, sv); > - KERNEL_UNLOCK(); > } else { > - KERNEL_LOCK(); > trapsignal(p, SIGSEGV, 0, SEGV_MAPERR, sv); > - KERNEL_UNLOCK(); > } > > out: > Index: arch/arm/arm/undefined.c > === > RCS file: /cvs/src/sys/arch/arm/arm/undefined.c,v > retrieving revision 1.13 > diff -u -p -r1.13 undefined.c > --- arch/arm/arm/undefined.c 13 Mar 2019 09:28:21 - 1.13 > +++ arch/arm/arm/undefined.c 18 Aug 2020 09:18:54 - > @@ -113,9 +113,7 @@ gdb_trapper(u_int addr, u_int insn, stru > if (insn == GDB_BREAKPOINT || insn == GDB5_BREAKPOINT) { > if (code == FAULT_USER) { > sv.sival_int = addr; > - KERNEL_LOCK(); > trapsignal(p, SIGTRAP, 0, TRAP_BRKPT, sv); > - KERNEL_UNLOCK(); > return 0; > } > } > @@ -174,9 +172,7 @@ undefinedinstruction(trapframe_t *frame) > if (__predict_false((fault_pc & 3) != 0)) { > /* Give the user an illegal instruction signal. */ > sv.sival_int = (u_int32_t) fault_pc; > - KERNEL_LOCK(); > trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv); > - KERNEL_UNLOCK(); > userret(p); > return; > } > @@ -260,9 +256,7 @@ undefinedinstruction(trapframe_t *frame) > } > > sv.sival_int = frame->tf_pc; > - KERNEL_LOCK(); > trapsignal(p, SIGILL, 0, ILL_ILLOPC, sv); > - KERNEL_UNLOCK(); > } > > if ((fault_code & FAULT_USER) == 0) > Index: arch/arm64/arm64/trap.c > ==