From owner-p4-projects Mon Aug 19 3:51:56 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9AB4137B401; Mon, 19 Aug 2002 03:51:45 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2EA3837B400 for ; Mon, 19 Aug 2002 03:51:45 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id D525E43E6E for ; Mon, 19 Aug 2002 03:51:44 -0700 (PDT) (envelope-from mini@freebsd.org) Received: from freefall.freebsd.org (perforce@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7JApiJU072822 for ; Mon, 19 Aug 2002 03:51:44 -0700 (PDT) (envelope-from mini@freebsd.org) Received: (from perforce@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7JApiB6072812 for perforce@freebsd.org; Mon, 19 Aug 2002 03:51:44 -0700 (PDT) Date: Mon, 19 Aug 2002 03:51:44 -0700 (PDT) Message-Id: <200208191051.g7JApiB6072812@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to mini@freebsd.org using -f From: Jonathan Mini Subject: PERFORCE change 16255 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://people.freebsd.org/~peter/p4db/chv.cgi?CH=16255 Change 16255 by mini@mini_stylus on 2002/08/19 03:51:13 Set the ucontext_t to the UTS when performing an upcall. Affected files ... .. //depot/projects/kse/sys/kern/kern_thread.c#87 edit .. //depot/projects/kse/sys/sys/kse.h#17 edit Differences ... ==== //depot/projects/kse/sys/kern/kern_thread.c#87 (text+ko) ==== @@ -438,14 +438,11 @@ /* * Set up the upcall pcb in either a given thread or a new one * if none given. Use the upcall for the given KSE - * XXXKSE possibly fix cpu_set_upcall() to not need td->td_kse set. */ struct thread * thread_schedule_upcall(struct thread *td, struct kse *ke) { struct thread *td2; - caddr_t ucp; - ucontext_t uc; mtx_assert(&sched_lock, MA_OWNED); if (ke->ke_tdspare != NULL) { @@ -459,17 +456,16 @@ CTR3(KTR_PROC, "thread_schedule_upcall: thread %p (pid %d, %s)", td, td->td_proc->p_pid, td->td_proc->p_comm); thread_link(td2, ke->ke_ksegrp); - ucp = (caddr_t)ke->ke_mailbox + - offsetof(struct kse_mailbox, km_context); - copyin(ucp, &uc, sizeof(ucontext_t)); /* - * XXX: It is somewhat bogus to ignore the error - * if copyin fails here, but the end result will be - * that the process will crash from bogus state information, - * which is what we want. + * The user context for this thread is selected when we choose + * a KSE and return to userland on it. All we need do here is + * note that the thread exists in order to perform an upcall. + * + * Since selecting a KSE to perform the upcall involves locking + * that KSE's context to our upcall, its best to wait until the + * last possible moment before grabbing a KSE. We do this in + * userret(). */ - thread_setcontext(td2, &uc); - suword(ucp + offsetof(ucontext_t, uc_busy), 1); td2->td_ucred = crhold(td->td_ucred); td2->td_flags = TDF_UNBOUND|TDF_UPCALLING; td2->td_priority = td->td_priority; @@ -493,6 +489,8 @@ struct thread *td, struct trapframe *frame) { int error = 0; + caddr_t ucp; + ucontext_t uc; if (ke->ke_tdspare == NULL) { ke->ke_tdspare = thread_alloc(); @@ -575,39 +573,37 @@ if (td->td_flags & TDF_UPCALLING) { CTR3(KTR_PROC, "userret: upcall thread %p (pid %d, %s)", td, p->p_pid, p->p_comm); -#if 0 /* - * Make sure that it has the correct frame loaded. - * While we know that we are on the same KSEGRP - * as we were created on, we could very easily - * have come in on another KSE. We therefore need - * to do the copy of the frame after the last - * possible switch() (the one above). + * There is no more work to do and we are going to ride + * this thead/KSE up to userland. */ - bcopy(ke->ke_frame, frame, sizeof(struct trapframe)); /* - * Decide what we are sending to the user - * upcall sets one argument. The address of the mbox. + * Set user/machine context to the UTS. */ - cpu_set_args(td, ke); + ucp = (caddr_t)ke->ke_mailbox + + offsetof(struct kse_mailbox, km_context); + if (copyin(ucp, &uc, sizeof(ucontext_t)) != 0) + /* + * If copyin() fails here, act as if it had + * read nothing but nulls. This will cause + * the process to crash from the bogus state + * information. + */ + bzero(&uc, sizeof(ucontext_t)); + thread_setcontext(td, &uc); + /* Mark the context busy (XXXSMP: must be atomic). */ + suword(ucp + offsetof(ucontext_t, uc_busy), 1); /* - * There is no more work to do and we are going to ride - * this thead/KSE up to userland. Make sure the user's - * pointer to the thread mailbox is cleared before we - * re-enter the kernel next time for any reason.. - * We might as well do it here. + * Make sure the user's pointer to the thread + * mailbox is cleared before we re-enter the kernel + * next time for any reason.. */ td->td_flags &= ~TDF_UPCALLING; /* Hmmmm. */ error = suword((caddr_t)td->td_kse->ke_mailbox + offsetof(struct kse_mailbox, km_curthread), 0); -#else - /* - * We are returning to the UTS. - */ -#endif } /* * Stop any chance that we may be separated from ==== //depot/projects/kse/sys/sys/kse.h#17 (text+ko) ==== To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message