From owner-freebsd-threads@FreeBSD.ORG Tue Sep 21 20:13:26 2004 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 52B4716A4CE for ; Tue, 21 Sep 2004 20:13:26 +0000 (GMT) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id E63DB43D46 for ; Tue, 21 Sep 2004 20:13:25 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) i8LKDFKi022333; Tue, 21 Sep 2004 16:13:15 -0400 (EDT) Date: Tue, 21 Sep 2004 16:13:15 -0400 (EDT) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Julian Elischer In-Reply-To: <415076B0.2050401@elischer.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) cc: freebsd-threads@freebsd.org Subject: Re: Bug in kse_switchin()? X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Sep 2004 20:13:26 -0000 On Tue, 21 Sep 2004, Julian Elischer wrote: > > Andrew Belashov wrote: > > > Hello! > > > > See sys/kern/kern_kse.c > > > > In line with "suword32(&uap->tmbx->tm_lwp, td->td_tid)" kernel > > not check return value (error state). This is correct? > > > yes and no. > > You are correct. > It is never correct to "not check" however we have just looked at that > location 7 lines earlier, so we know > that the page in question is loaded and valid. This is is "prbably safe". > > Probably we should look at the error value also, even if this is true. Julian, you missed an important question below. It looks like he's trying to get this working with sparc64 and the suword32 is generating an alignment exception. Is lwpid_t 64-bit on sparc64 or is it somehow not being aligned properly within the mailbox? > > > > ---[sys/kern/kern_kse.c]-------------------------------------- > > int > > kse_switchin(struct thread *td, struct kse_switchin_args *uap) > > { > > struct kse_thr_mailbox tmbx; > > struct kse_upcall *ku; > > int error; > > > > if ((ku = td->td_upcall) == NULL || TD_CAN_UNBIND(td)) > > return (EINVAL); > > error = (uap->tmbx == NULL) ? EINVAL : 0; > > if (!error) > > error = copyin(uap->tmbx, &tmbx, sizeof(tmbx)); > > if (!error && (uap->flags & KSE_SWITCHIN_SETTMBX)) > > error = (suword(&ku->ku_mailbox->km_curthread, > > (long)uap->tmbx) != 0 ? EINVAL : 0); > > if (!error) > > error = set_mcontext(td, &tmbx.tm_context.uc_mcontext); > > if (!error) { > > suword32(&uap->tmbx->tm_lwp, td->td_tid); > > if (uap->flags & KSE_SWITCHIN_SETTMBX) { > > td->td_mailbox = uap->tmbx; > > td->td_pflags |= TDP_CAN_UNBIND; > > } > > if (td->td_proc->p_flag & P_TRACED) { > > if (tmbx.tm_dflags & TMDF_SSTEP) > > ptrace_single_step(td); > > else > > ptrace_clear_single_step(td); > > if (tmbx.tm_dflags & TMDF_SUSPEND) { > > mtx_lock_spin(&sched_lock); > > /* fuword can block, check again */ > > if (td->td_upcall) > > ku->ku_flags |= KUF_DOUPCALL; > > mtx_unlock_spin(&sched_lock); > > } > > } > > } > > return ((error == 0) ? EJUSTRETURN : error); > > } > > -------------------------------------------------------------- > > > > On FreeBSD/sparc64 suword32() in this place generate trap "memory address > > not aligned (kernel)", and kse_switchin() returning EJUSTRETURN. > > > > How it to correct? > > > > -- > > With best regards, > > Andrew Belashov. -- Dan Eischen