Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Feb 2002 12:40:38 -0800
From:      Julian Elischer <julian@vicor-nb.com>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        Matthew Dillon <dillon@apollo.backplane.com>, arch@FreeBSD.org
Subject:   Patch for ucred
Message-ID:  <3C76ACC6.2BB699CF@vicor-nb.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------A019902EE9583F50659DADDA
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Here's my compromise patch:
--------------A019902EE9583F50659DADDA
Content-Type: text/plain; charset=us-ascii;
 name="cred.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="cred.diff"

Index: kern/subr_trap.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_trap.c,v
retrieving revision 1.208
diff -u -r1.208 subr_trap.c
--- kern/subr_trap.c	17 Feb 2002 01:09:55 -0000	1.208
+++ kern/subr_trap.c	22 Feb 2002 20:36:45 -0000
@@ -131,7 +131,6 @@
 #endif
 
 	KASSERT(TRAPF_USERMODE(framep), ("ast in kernel mode"));
-	KASSERT(td->td_ucred == NULL, ("leaked ucred"));
 #ifdef WITNESS
 	if (witness_list(td))
 		panic("Returning to user mode with mutex(s) held");
@@ -161,6 +160,13 @@
 			p->p_stats->p_prof.pr_ticks = 0;
 		}
 		mtx_unlock_spin(&sched_lock);
+
+#ifdef DIAGNOSTIC
+		if (td->td_ucred)
+			panic("ast:thread got a cred before reaching AST");
+		td->td_cred = td->td_ucred_cache;
+		td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 		if (td->td_ucred != p->p_ucred) 
 			cred_update_thread(td);
 		if (flags & KEF_OWEUPC && sflag & PS_PROFIL)
@@ -187,12 +193,13 @@
 		}
 
 		userret(td, framep, sticks);
-#ifdef	INVARIANTS
-		mtx_lock(&Giant);
-		crfree(td->td_ucred);
-		mtx_unlock(&Giant);
+#ifdef DIAGNOSTIC
+		if (td->td_ucred_cache)
+			panic("ast:thread already has cached ucred");
+		td->td_ucred_cache = td->td_ucred;
 		td->td_ucred = NULL;
-#endif
+#endif /* DIAGNOSTIC */
+
 		s = cpu_critical_enter();
 	}
 	mtx_assert(&Giant, MA_NOTOWNED);
Index: kern/kern_fork.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_fork.c,v
retrieving revision 1.133
diff -u -r1.133 kern_fork.c
--- kern/kern_fork.c	22 Feb 2002 13:31:59 -0000	1.133
+++ kern/kern_fork.c	22 Feb 2002 20:36:45 -0000
@@ -477,6 +477,9 @@
 	PROC_LOCK(p1);
 	p2->p_ucred = crhold(p1->p_ucred);
 	td2->td_ucred = crhold(p2->p_ucred);	/* XXXKSE */
+#ifdef	DIAGNOSTIC
+	td2->td_ucred_cache = NULL;
+#endif
 
 	if (p2->p_args)
 		p2->p_args->ar_ref++;
@@ -802,12 +805,12 @@
 		kthread_exit(0);
 	}
 	PROC_UNLOCK(p);
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("fork_exit:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+       	td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 	mtx_assert(&Giant, MA_NOTOWNED);
 }
 
Index: sys/proc.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/proc.h,v
retrieving revision 1.204
diff -u -r1.204 proc.h
--- sys/proc.h	22 Feb 2002 13:32:01 -0000	1.204
+++ sys/proc.h	22 Feb 2002 20:36:45 -0000
@@ -272,6 +272,11 @@
 #define	td_endcopy td_pcb
 
 	struct ucred	*td_ucred;	/* (k) Reference to credentials. */
+#ifdef DIAGNOSTIC
+	struct ucred	*td_ucred_cache; /* (k) hide cred here for DIAGNOSTIC */
+#else
+	void 		*td_dontuse;	/* keep the size the same if not DIAG */
+#endif
 	struct pcb	*td_pcb;	/* (k) Kernel VA of pcb and kstack. */
 	struct callout	td_slpcallout;	/* (h) Callout for sleep. */
 	struct trapframe *td_frame;	/* (k) */
Index: alpha/alpha/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/alpha/alpha/trap.c,v
retrieving revision 1.83
diff -u -r1.83 trap.c
--- alpha/alpha/trap.c	19 Feb 2002 03:13:39 -0000	1.83
+++ alpha/alpha/trap.c	22 Feb 2002 20:36:46 -0000
@@ -297,7 +297,12 @@
 	if (user)  {
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = framep;
-		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+		if (td->td_ucred)
+			panic("trap: thread got a cred while in userspace");
+		td->td_cred = td->td_ucred_cache;
+		td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 		if (td->td_ucred != p->p_ucred)
 			cred_update_thread(td);
 	} else {
@@ -625,12 +630,12 @@
 		framep->tf_regs[FRAME_SP] = alpha_pal_rdusp();
 		userret(td, framep, sticks);
 		mtx_assert(&Giant, MA_NOTOWNED);
-#ifdef	INVARIANTS
-		mtx_lock(&Giant);
-		crfree(td->td_ucred);
-		mtx_unlock(&Giant);
+#ifdef DIAGNOSTIC
+		if (td->td_ucred_cache)
+			panic("trap: thread already has cached ucred");
+		td->td_ucred_cache = td->td_ucred;
 		td->td_ucred = NULL;
-#endif
+#endif /* DIAGNOSTIC */
 	}
 	return;
 
@@ -699,7 +704,12 @@
 	td->td_frame = framep;
 	opc = framep->tf_regs[FRAME_PC] - 4;
 	sticks = td->td_kse->ke_sticks;
-	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+	if (td->td_ucred)
+		panic("syscall:thread got a cred while in userspace");
+	td->td_cred = td->td_ucred_cache;
+	td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 	if (td->td_ucred != p->p_ucred)
 		cred_update_thread(td);
 
@@ -822,12 +832,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("syscall:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
 	td->td_ucred = NULL;
-#endif
+#endif /* DIAGNOSTIC */
 #ifdef WITNESS
 	if (witness_list(td)) {
 		panic("system call %s returning with mutex(s) held\n",
Index: i386/i386/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/trap.c,v
retrieving revision 1.212
diff -u -r1.212 trap.c
--- i386/i386/trap.c	17 Feb 2002 01:09:54 -0000	1.212
+++ i386/i386/trap.c	22 Feb 2002 20:36:46 -0000
@@ -255,7 +255,12 @@
 
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = &frame;
-		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+		if (td->td_ucred)
+			panic("trap:thread got a cred while userspace");
+		td->td_cred = td->td_ucred_cache;
+		td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 		if (td->td_ucred != p->p_ucred) 
 			cred_update_thread(td);
 
@@ -643,12 +648,12 @@
 	userret(td, &frame, sticks);
 	mtx_assert(&Giant, MA_NOTOWNED);
 userout:
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("trap:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+        td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 out:
 	return;
 }
@@ -954,7 +959,12 @@
 
 	sticks = td->td_kse->ke_sticks;
 	td->td_frame = &frame;
-	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+	if (td->td_ucred)
+		panic("trap:thread got a cred while userspace");
+	td->td_cred = td->td_ucred_cache;
+	td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 	if (td->td_ucred != p->p_ucred) 
 		cred_update_thread(td);
 	params = (caddr_t)frame.tf_esp + sizeof(int);
@@ -1099,12 +1109,13 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("syscall:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+        td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
+
 #ifdef WITNESS
 	if (witness_list(td)) {
 		panic("system call %s returning with mutex(s) held\n",
Index: ia64/ia64/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/ia64/ia64/trap.c,v
retrieving revision 1.43
diff -u -r1.43 trap.c
--- ia64/ia64/trap.c	19 Feb 2002 03:16:50 -0000	1.43
+++ ia64/ia64/trap.c	22 Feb 2002 20:36:46 -0000
@@ -323,7 +323,12 @@
 	if (user) {
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = framep;
-		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+		if (td->td_ucred)
+			panic("trap:thread got a cred while userspace");
+		td->td_cred = td->td_ucred_cache;
+		td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 		if (td->td_ucred != p->p_ucred)
 			cred_update_thread(td);
 	} else {
@@ -708,12 +713,12 @@
 	if (user) {
 		userret(td, framep, sticks);
 		mtx_assert(&Giant, MA_NOTOWNED);
-#ifdef	INVARIANTS
-		mtx_lock(&Giant);
-		crfree(td->td_ucred);
-		mtx_unlock(&Giant);
-		td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+		if (td->td_ucred_cache)
+			panic("trap:thread already has cached ucred");
+		td->td_ucred_cache = td->td_ucred;
+        	td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 	}
 	return;
 
@@ -758,7 +763,12 @@
 
 	td->td_frame = framep;
 	sticks = td->td_kse->ke_sticks;
-	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+	if (td->td_ucred)
+		panic("trap:thread got a cred while userspace");
+	td->td_cred = td->td_ucred_cache;
+	td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 	if (td->td_ucred != p->p_ucred)
 		cred_update_thread(td);
 
@@ -865,12 +875,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("trap:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+       	td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 #ifdef WITNESS
 	if (witness_list(td)) {
 		panic("system call %s returning with mutex(s) held\n",
Index: powerpc/powerpc/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/powerpc/powerpc/trap.c,v
retrieving revision 1.7
diff -u -r1.7 trap.c
--- powerpc/powerpc/trap.c	19 Feb 2002 03:27:08 -0000	1.7
+++ powerpc/powerpc/trap.c	22 Feb 2002 20:36:46 -0000
@@ -226,7 +226,12 @@
 	if (user) {
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = frame;
-		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+		if (td->td_ucred)
+			panic("trap:thread got a cred while userspace");
+		td->td_cred = td->td_ucred_cache;
+		td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 		if (td->td_ucred != p->p_ucred)
 			cred_update_thread(td);
 
@@ -288,6 +293,7 @@
 		default:
 			trap_fatal(frame);
 		}
+		/* NOTREACHED */
 	}
 	if (sig != 0) {
 		if (p->p_sysent->sv_transtrap != NULL)
@@ -296,12 +302,12 @@
 	}
 	userret(td, frame, sticks);
 	mtx_assert(&Giant, MA_NOTOWNED);
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("trap:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+       	td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 }
 
 void
Index: sparc64/sparc64/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/sparc64/sparc64/trap.c,v
retrieving revision 1.23
diff -u -r1.23 trap.c
--- sparc64/sparc64/trap.c	19 Feb 2002 03:23:28 -0000	1.23
+++ sparc64/sparc64/trap.c	22 Feb 2002 20:36:46 -0000
@@ -175,7 +175,12 @@
 	if ((type & T_KERNEL) == 0) {
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = tf;
-		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+		if (td->td_ucred)
+			panic("trap:thread got a cred while userspace");
+		td->td_cred = td->td_ucred_cache;
+		td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 		if (td->td_ucred != p->p_ucred)
 			cred_update_thread(td);
  	} else {
@@ -379,12 +384,12 @@
 user:
 	userret(td, tf, sticks);
 	mtx_assert(&Giant, MA_NOTOWNED);
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("trap:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+       	td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 out:
 	CTR1(KTR_TRAP, "trap: td=%p return", td);
 	return;
@@ -540,7 +545,12 @@
 
 	sticks = td->td_kse->ke_sticks;
 	td->td_frame = tf;
-	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
+#ifdef DIAGNOSTIC
+	if (td->td_ucred)
+		panic("syscall:thread got a cred while userspace");
+	td->td_cred = td->td_ucred_cache;
+	td->td_ucred_cache = NULL;
+#endif /* DIAGNOSTIC */
 	if (td->td_ucred != p->p_ucred)
 		cred_update_thread(td);
 	code = tf->tf_global[1];
@@ -677,12 +687,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
-#ifdef	INVARIANTS
-	mtx_lock(&Giant);
-	crfree(td->td_ucred);
-	mtx_unlock(&Giant);
-	td->td_ucred = NULL;
-#endif
+#ifdef DIAGNOSTIC
+	if (td->td_ucred_cache)
+		panic("syscall:thread already has cached ucred");
+	td->td_ucred_cache = td->td_ucred;
+       	td->td_ucred = NULL;
+#endif /* DIAGNOSTIC */
 #ifdef WITNESS
 	if (witness_list(td)) {
 		panic("system call %s returning with mutex(s) held\n",

--------------A019902EE9583F50659DADDA--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C76ACC6.2BB699CF>