From e43257aa7d91ebc2bb46d0dcb2eb4ef51bbfc745 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 1 Apr 2004 20:56:44 +0000 Subject: [PATCH] Finish fixing up Alpha to work with an MP safe ptrace(): - ptrace_single_step() is no longer called with the proc lock held, so don't try to unlock it and then relock it. - Push Giant down into proc_rwmem() instead of forcing all the consumers (including Alpha breakpoint support) to explicitly wrap calls to proc_rwmem() with Giant. Tested by: kensmith --- sys/alpha/alpha/machdep.c | 9 +++------ sys/kern/sys_process.c | 16 ++++++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c index cff99c398e5..b374cbfb0d2 100644 --- a/sys/alpha/alpha/machdep.c +++ b/sys/alpha/alpha/machdep.c @@ -1914,10 +1914,9 @@ ptrace_single_step(struct thread *td) if (td->td_md.md_flags & (MDTD_STEP1|MDTD_STEP2)) panic("ptrace_single_step: step breakpoints not removed"); - PROC_UNLOCK(td->td_proc); error = ptrace_read_int(td, pc, &ins.bits); if (error) - goto err; + return (error); switch (ins.branch_format.opcode) { @@ -1957,20 +1956,18 @@ ptrace_single_step(struct thread *td) td->td_md.md_sstep[0].addr = addr[0]; error = ptrace_set_bpt(td, &td->td_md.md_sstep[0]); if (error) - goto err; + return (error); if (count == 2) { td->td_md.md_sstep[1].addr = addr[1]; error = ptrace_set_bpt(td, &td->td_md.md_sstep[1]); if (error) { ptrace_clear_bpt(td, &td->td_md.md_sstep[0]); - goto err; + return (error); } td->td_md.md_flags |= MDTD_STEP2; } else td->td_md.md_flags |= MDTD_STEP1; -err: - PROC_LOCK(td->td_proc); return (error); } diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index dcfad3d0cca..a43e7b0a089 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -154,18 +154,21 @@ proc_rwmem(struct proc *p, struct uio *uio) vm_prot_t reqprot; int error, writing; - GIANT_REQUIRED; - + mtx_lock(&Giant); /* * if the vmspace is in the midst of being deallocated or the * process is exiting, don't try to grab anything. The page table * usage in that process can be messed up. */ vm = p->p_vmspace; - if ((p->p_flag & P_WEXIT)) + if ((p->p_flag & P_WEXIT)) { + mtx_unlock(&Giant); return (EFAULT); - if (vm->vm_refcnt < 1) + } + if (vm->vm_refcnt < 1) { + mtx_unlock(&Giant); return (EFAULT); + } ++vm->vm_refcnt; /* * The map we want... @@ -274,6 +277,7 @@ proc_rwmem(struct proc *p, struct uio *uio) } while (error == 0 && uio->uio_resid > 0); vmspace_free(vm); + mtx_unlock(&Giant); return (error); } @@ -602,9 +606,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) uio.uio_segflg = UIO_SYSSPACE; /* i.e.: the uap */ uio.uio_rw = write ? UIO_WRITE : UIO_READ; uio.uio_td = td; - mtx_lock(&Giant); error = proc_rwmem(p, &uio); - mtx_unlock(&Giant); if (uio.uio_resid != 0) { /* * XXX proc_rwmem() doesn't currently return ENOSPC, @@ -645,9 +647,7 @@ kern_ptrace(struct thread *td, int req, pid_t pid, void *addr, int data) default: return (EINVAL); } - mtx_lock(&Giant); error = proc_rwmem(p, &uio); - mtx_unlock(&Giant); piod->piod_len -= uio.uio_resid; return (error);