Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Feb 2002 14:05:02 -0800
From:      Julian Elischer <julian@elischer.org>
To:        jhb@freebsd.org, bde@freebsd.org, current@freebsd.org
Subject:   ucred holding patch, BDE version
Message-ID:  <20020212021249.74C139F3FA@okeeffe.bestweb.net>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

--Boundary_(ID_dSrd7tGZA8RKg/kjSIaytA)
Content-type: text/plain; charset=iso-8859-2
Content-transfer-encoding: 7BIT

here is the BDE version ready to commit.
Extended to other architectures.

Bruce, John, comments?

As I was adding a prototype to ucred.h I stripped the __Ps of the others in that
section
(in the spirit of "change it when editing it anyhow"

-- 
+------------------------------------+       ______ _  __
|   __--_|\  Julian Elischer         |       \     U \/ / hard at work in 
|  /       \ julian@elischer.org     +------>x   USA    \ a very strange
| (   OZ    )                                \___   ___ | country !
+- X_.---._/    presently in San Francisco       \_/   \\
          v

--Boundary_(ID_dSrd7tGZA8RKg/kjSIaytA)
Content-type: text/plain; charset=iso-8859-2; name=thediff
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=thediff

? i386/conf/LINT
? modules/netgraph/ksocket/ng_ksocket.kld
? modules/netgraph/ksocket/ng_ksocket.ko
Index: alpha/alpha/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/alpha/alpha/trap.c,v
retrieving revision 1.82
diff -u -r1.82 trap.c
--- alpha/alpha/trap.c	15 Jan 2002 14:17:07 -0000	1.82
+++ alpha/alpha/trap.c	11 Feb 2002 21:59:32 -0000
@@ -298,9 +298,8 @@
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = framep;
 		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-		PROC_LOCK(p);
-		td->td_ucred = crhold(p->p_ucred);
-		PROC_UNLOCK(p);
+		if (td->td_ucred != p->p_ucred) 
+			aquire_ucred(td, p);
 	} else {
 		sticks = 0;		/* XXX bogus -Wuninitialized warning */
 		KASSERT(cold || td->td_ucred != NULL,
@@ -626,10 +625,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);
 		td->td_ucred = NULL;
+#endif
 	}
 	return;
 
@@ -699,9 +700,8 @@
 	opc = framep->tf_regs[FRAME_PC] - 4;
 	sticks = td->td_kse->ke_sticks;
 	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-	PROC_LOCK(p);
-	td->td_ucred = crhold(p->p_ucred);
-	PROC_UNLOCK(p);
+	if (td->td_ucred != p->p_ucred) 
+		aquire_ucred(td, p);
 
 #ifdef DIAGNOSTIC
 	alpha_fpstate_check(td);
@@ -822,10 +822,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
+#ifdef	INVARIANTS
 	mtx_lock(&Giant);
 	crfree(td->td_ucred);
 	mtx_unlock(&Giant);
 	td->td_ucred = NULL;
+#endif
 #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.211
diff -u -r1.211 trap.c
--- i386/i386/trap.c	10 Jan 2002 11:49:54 -0000	1.211
+++ i386/i386/trap.c	11 Feb 2002 21:59:42 -0000
@@ -256,9 +256,8 @@
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = &frame;
 		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-		PROC_LOCK(p);
-		td->td_ucred = crhold(p->p_ucred);
-		PROC_UNLOCK(p);
+		if (td->td_ucred != p->p_ucred) 
+			aquire_ucred(td, p);
 
 		switch (type) {
 		case T_PRIVINFLT:	/* privileged instruction fault */
@@ -644,10 +643,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
 out:
 	return;
 }
@@ -954,9 +955,8 @@
 	sticks = td->td_kse->ke_sticks;
 	td->td_frame = &frame;
 	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-	PROC_LOCK(p);
-	td->td_ucred = crhold(p->p_ucred);
-	PROC_UNLOCK(p);
+	if (td->td_ucred != p->p_ucred) 
+		aquire_ucred(td, p);
 	params = (caddr_t)frame.tf_esp + sizeof(int);
 	code = frame.tf_eax;
 	orig_tf_eflags = frame.tf_eflags;
@@ -1099,10 +1099,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
+#ifdef	INVARIANTS
 	mtx_lock(&Giant);
 	crfree(td->td_ucred);
 	mtx_unlock(&Giant);
 	td->td_ucred = NULL;
+#endif
 #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.42
diff -u -r1.42 trap.c
--- ia64/ia64/trap.c	19 Nov 2001 08:06:56 -0000	1.42
+++ ia64/ia64/trap.c	11 Feb 2002 21:59:46 -0000
@@ -324,9 +324,8 @@
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = framep;
 		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-		PROC_LOCK(p);
-		td->td_ucred = crhold(p->p_ucred);
-		PROC_UNLOCK(p);
+		if (td->td_ucred != p->p_ucred) 
+			aquire_ucred(td, p);
 	} else {
 		sticks = 0;		/* XXX bogus -Wuninitialized warning */
 		KASSERT(cold || td->td_ucred != NULL,
@@ -709,10 +708,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
 	}
 	return;
 
@@ -758,9 +759,8 @@
 	td->td_frame = framep;
 	sticks = td->td_kse->ke_sticks;
 	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-	PROC_LOCK(p);
-	td->td_ucred = crhold(p->p_ucred);
-	PROC_UNLOCK(p);
+	if (td->td_ucred != p->p_ucred) 
+		aquire_ucred(td, p);
 
 	/*
 	 * Skip past the break instruction. Remember old address in case
@@ -865,10 +865,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
+#ifdef	INVARIANTS
 	mtx_lock(&Giant);
 	crfree(td->td_ucred);
 	mtx_unlock(&Giant);
 	td->td_ucred = NULL;
+#endif
 #ifdef WITNESS
 	if (witness_list(td)) {
 		panic("system call %s returning with mutex(s) held\n",
Index: kern/subr_trap.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_trap.c,v
retrieving revision 1.207
diff -u -r1.207 subr_trap.c
--- kern/subr_trap.c	11 Feb 2002 20:37:53 -0000	1.207
+++ kern/subr_trap.c	11 Feb 2002 21:59:47 -0000
@@ -56,6 +56,24 @@
 #include <machine/pcb.h>
 
 /*
+ * small routine to swap a thread's current ucred for the correct one
+ * taken from the process
+ */
+void
+aquire_ucred(struct thread *td, struct proc *p)
+{
+	if (td->td_ucred != NULL) {
+		mtx_lock(&Giant);
+		crfree(td->td_ucred);
+		mtx_unlock(&Giant);
+		td->td_ucred = NULL;
+	}
+	PROC_LOCK(p);
+	td->td_ucred = crhold(p->p_ucred);
+	PROC_UNLOCK(p);
+}
+
+/*
  * Define the code needed before returning to user mode, for
  * trap and syscall.
  *
@@ -161,9 +179,8 @@
 			p->p_stats->p_prof.pr_ticks = 0;
 		}
 		mtx_unlock_spin(&sched_lock);
-		PROC_LOCK(p);
-		td->td_ucred = crhold(p->p_ucred);
-		PROC_UNLOCK(p);
+		if (td->td_ucred != p->p_ucred) 
+			aquire_ucred(td, p);
 		if (flags & KEF_OWEUPC && sflag & PS_PROFIL)
 			addupc_task(ke, p->p_stats->p_prof.pr_addr, prticks);
 		if (sflag & PS_ALRMPEND) {
@@ -188,10 +205,12 @@
 		}
 
 		userret(td, framep, sticks);
+#ifdef	INVARIANTS
 		mtx_lock(&Giant);
 		crfree(td->td_ucred);
 		mtx_unlock(&Giant);
 		td->td_ucred = NULL;
+#endif
 		s = cpu_critical_enter();
 	}
 	mtx_assert(&Giant, MA_NOTOWNED);
Index: powerpc/powerpc/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/powerpc/powerpc/trap.c,v
retrieving revision 1.5
diff -u -r1.5 trap.c
--- powerpc/powerpc/trap.c	5 Nov 2001 00:49:03 -0000	1.5
+++ powerpc/powerpc/trap.c	11 Feb 2002 21:59:54 -0000
@@ -227,9 +227,8 @@
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = frame;
 		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-		PROC_LOCK(p);
-		td->td_ucred = crhold(p->p_ucred);
-		PROC_UNLOCK(p);
+		if (td->td_ucred != p->p_ucred) 
+			aquire_ucred(td, p);
 
 		/* User Mode Traps */
 		switch (type) {
@@ -297,10 +296,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
 }
 
 void
Index: sparc64/sparc64/trap.c
===================================================================
RCS file: /home/ncvs/src/sys/sparc64/sparc64/trap.c,v
retrieving revision 1.22
diff -u -r1.22 trap.c
--- sparc64/sparc64/trap.c	1 Jan 2002 20:26:46 -0000	1.22
+++ sparc64/sparc64/trap.c	11 Feb 2002 21:59:56 -0000
@@ -176,9 +176,8 @@
 		sticks = td->td_kse->ke_sticks;
 		td->td_frame = tf;
 		KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-		PROC_LOCK(p);
-		td->td_ucred = crhold(p->p_ucred);
-		PROC_UNLOCK(p);
+		if (td->td_ucred != p->p_ucred) 
+			aquire_ucred(td, p);
  	} else {
  		sticks = 0;
 if ((type & ~T_KERNEL) != T_BREAKPOINT)
@@ -380,10 +379,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
 out:
 	CTR1(KTR_TRAP, "trap: td=%p return", td);
 	return;
@@ -540,9 +541,8 @@
 	sticks = td->td_kse->ke_sticks;
 	td->td_frame = tf;
 	KASSERT(td->td_ucred == NULL, ("already have a ucred"));
-	PROC_LOCK(p);
-	td->td_ucred = crhold(p->p_ucred);
-	PROC_UNLOCK(p);	
+	if (td->td_ucred != p->p_ucred) 
+		aquire_ucred(td, p);
 	code = tf->tf_global[1];
 
 	/*
@@ -677,10 +677,12 @@
 	 */
 	STOPEVENT(p, S_SCX, code);
 
+#ifdef	INVARIANTS
 	mtx_lock(&Giant);
 	crfree(td->td_ucred);
 	mtx_unlock(&Giant);
 	td->td_ucred = NULL;
+#endif
 #ifdef WITNESS
 	if (witness_list(td)) {
 		panic("system call %s returning with mutex(s) held\n",
Index: sys/ucred.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/ucred.h,v
retrieving revision 1.26
diff -u -r1.26 ucred.h
--- sys/ucred.h	11 Oct 2001 23:38:17 -0000	1.26
+++ sys/ucred.h	11 Feb 2002 21:59:56 -0000
@@ -81,21 +81,23 @@
 };
 
 #ifdef _KERNEL
+struct proc; 	/* needed for aquire_ucred prototype */
+struct thread; 	/* needed for aquire_ucred prototype */
 
-
-void		change_egid __P((struct ucred *newcred, gid_t egid));
-void		change_euid __P((struct ucred *newcred, uid_t euid));
-void		change_rgid __P((struct ucred *newcred, gid_t rgid));
-void		change_ruid __P((struct ucred *newcred, uid_t ruid));
-void		change_svgid __P((struct ucred *newcred, gid_t svgid));
-void		change_svuid __P((struct ucred *newcred, uid_t svuid));
-void		crcopy __P((struct ucred *dest, struct ucred *src));
-struct ucred	*crdup __P((struct ucred *cr));
-void		crfree __P((struct ucred *cr));
-struct ucred	*crget __P((void));
-struct ucred	*crhold __P((struct ucred *cr));
-int		crshared __P((struct ucred *cr));
-int		groupmember __P((gid_t gid, struct ucred *cred));
+void		aquire_ucred(struct thread *td, struct proc *p);
+void		change_egid (struct ucred *newcred, gid_t egid);
+void		change_euid (struct ucred *newcred, uid_t euid);
+void		change_rgid (struct ucred *newcred, gid_t rgid);
+void		change_ruid (struct ucred *newcred, uid_t ruid);
+void		change_svgid (struct ucred *newcred, gid_t svgid);
+void		change_svuid (struct ucred *newcred, uid_t svuid);
+void		crcopy (struct ucred *dest, struct ucred *src);
+struct ucred	*crdup (struct ucred *cr);
+void		crfree (struct ucred *cr);
+struct ucred	*crget (void);
+struct ucred	*crhold (struct ucred *cr);
+int		crshared (struct ucred *cr);
+int		groupmember (gid_t gid, struct ucred *cred);
 #endif /* _KERNEL */
 
 #endif /* !_SYS_UCRED_H_ */

--Boundary_(ID_dSrd7tGZA8RKg/kjSIaytA)--

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

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




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