Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Aug 2002 03:51:44 -0700 (PDT)
From:      Jonathan Mini <mini@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 16255 for review
Message-ID:  <200208191051.g7JApiB6072812@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208191051.g7JApiB6072812>