Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Mar 2017 09:22:53 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r315064 - in stable/11/sys: fs/nfsserver kern sys ufs/ffs
Message-ID:  <201703110922.v2B9Mr9K061927@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Mar 11 09:22:53 2017
New Revision: 315064
URL: https://svnweb.freebsd.org/changeset/base/315064

Log:
  MFC r314253:
  Do not leak mount references for dying threads.

Modified:
  stable/11/sys/fs/nfsserver/nfs_nfsdkrpc.c
  stable/11/sys/kern/kern_exit.c
  stable/11/sys/kern/kern_thread.c
  stable/11/sys/kern/subr_trap.c
  stable/11/sys/sys/proc.h
  stable/11/sys/sys/systm.h
  stable/11/sys/ufs/ffs/ffs_softdep.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/fs/nfsserver/nfs_nfsdkrpc.c
==============================================================================
--- stable/11/sys/fs/nfsserver/nfs_nfsdkrpc.c	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/fs/nfsserver/nfs_nfsdkrpc.c	Sat Mar 11 09:22:53 2017	(r315064)
@@ -300,8 +300,7 @@ nfssvc_program(struct svc_req *rqst, SVC
 	svc_freereq(rqst);
 
 out:
-	if (softdep_ast_cleanup != NULL)
-		softdep_ast_cleanup();
+	td_softdep_cleanup(curthread);
 	NFSEXITCODE(0);
 }
 

Modified: stable/11/sys/kern/kern_exit.c
==============================================================================
--- stable/11/sys/kern/kern_exit.c	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/kern/kern_exit.c	Sat Mar 11 09:22:53 2017	(r315064)
@@ -207,8 +207,7 @@ exit1(struct thread *td, int rval, int s
 	/*
 	 * Deref SU mp, since the thread does not return to userspace.
 	 */
-	if (softdep_ast_cleanup != NULL)
-		softdep_ast_cleanup();
+	td_softdep_cleanup(td);
 
 	/*
 	 * MUST abort all other threads before proceeding past here.

Modified: stable/11/sys/kern/kern_thread.c
==============================================================================
--- stable/11/sys/kern/kern_thread.c	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/kern/kern_thread.c	Sat Mar 11 09:22:53 2017	(r315064)
@@ -192,6 +192,8 @@ thread_dtor(void *mem, int size, void *a
 #endif
 	/* Free all OSD associated to this thread. */
 	osd_thread_exit(td);
+	td_softdep_cleanup(td);
+	MPASS(td->td_su == NULL);
 
 	EVENTHANDLER_INVOKE(thread_dtor, td);
 	tid_free(td->td_tid);

Modified: stable/11/sys/kern/subr_trap.c
==============================================================================
--- stable/11/sys/kern/subr_trap.c	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/kern/subr_trap.c	Sat Mar 11 09:22:53 2017	(r315064)
@@ -86,7 +86,7 @@ __FBSDID("$FreeBSD$");
 
 #include <security/mac/mac_framework.h>
 
-void (*softdep_ast_cleanup)(void);
+void (*softdep_ast_cleanup)(struct thread *);
 
 /*
  * Define the code needed before returning to user mode, for trap and
@@ -128,8 +128,8 @@ userret(struct thread *td, struct trapfr
 #ifdef KTRACE
 	KTRUSERRET(td);
 #endif
-	if (softdep_ast_cleanup != NULL)
-		softdep_ast_cleanup();
+	td_softdep_cleanup(td);
+	MPASS(td->td_su == NULL);
 
 	/*
 	 * If this thread tickled GEOM, we need to wait for the giggling to

Modified: stable/11/sys/sys/proc.h
==============================================================================
--- stable/11/sys/sys/proc.h	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/sys/proc.h	Sat Mar 11 09:22:53 2017	(r315064)
@@ -1106,6 +1106,15 @@ td_get_sched(struct thread *td)
 	return ((struct td_sched *)&td[1]);
 }
 
+extern void (*softdep_ast_cleanup)(struct thread *);
+static __inline void
+td_softdep_cleanup(struct thread *td)
+{
+
+	if (td->td_su != NULL && softdep_ast_cleanup != NULL)
+		softdep_ast_cleanup(td);
+}
+
 #endif	/* _KERNEL */
 
 #endif	/* !_SYS_PROC_H_ */

Modified: stable/11/sys/sys/systm.h
==============================================================================
--- stable/11/sys/sys/systm.h	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/sys/systm.h	Sat Mar 11 09:22:53 2017	(r315064)
@@ -444,8 +444,6 @@ void free_unr(struct unrhdr *uh, u_int i
 
 void	intr_prof_stack_use(struct thread *td, struct trapframe *frame);
 
-extern void (*softdep_ast_cleanup)(void);
-
 void counted_warning(unsigned *counter, const char *msg);
 
 #endif /* !_SYS_SYSTM_H_ */

Modified: stable/11/sys/ufs/ffs/ffs_softdep.c
==============================================================================
--- stable/11/sys/ufs/ffs/ffs_softdep.c	Sat Mar 11 08:40:59 2017	(r315063)
+++ stable/11/sys/ufs/ffs/ffs_softdep.c	Sat Mar 11 09:22:53 2017	(r315064)
@@ -902,7 +902,7 @@ static	int pagedep_find(struct pagedep_h
 static	void pause_timer(void *);
 static	int request_cleanup(struct mount *, int);
 static	void schedule_cleanup(struct mount *);
-static void softdep_ast_cleanup_proc(void);
+static void softdep_ast_cleanup_proc(struct thread *);
 static	int process_worklist_item(struct mount *, int, int);
 static	void process_removes(struct vnode *);
 static	void process_truncates(struct vnode *);
@@ -13437,15 +13437,13 @@ schedule_cleanup(struct mount *mp)
 }
 
 static void
-softdep_ast_cleanup_proc(void)
+softdep_ast_cleanup_proc(struct thread *td)
 {
-	struct thread *td;
 	struct mount *mp;
 	struct ufsmount *ump;
 	int error;
 	bool req;
 
-	td = curthread;
 	while ((mp = td->td_su) != NULL) {
 		td->td_su = NULL;
 		error = vfs_busy(mp, MBF_NOWAIT);
@@ -13483,6 +13481,10 @@ softdep_ast_cleanup_proc(void)
 		}
 		vfs_unbusy(mp);
 	}
+	if ((mp = td->td_su) != NULL) {
+		td->td_su = NULL;
+		vfs_rel(mp);
+	}
 }
 
 /*



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