Subject: uvm_vnp_setsize
To: None <chuq@chuq.com>
From: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
List: tech-kern
Date: 09/29/2005 19:41:30
hi,

i think that uvm_vnp_setsize can leave pages past eof
if another thread faults on the file in the mean time.

is there any problem if set v_size earlier as the following patch?

YAMAMOTO Takashi

Index: uvm_vnode.c
===================================================================
--- uvm_vnode.c	(revision 1266)
+++ uvm_vnode.c	(working copy)
@@ -441,6 +441,7 @@ uvm_vnp_setsize(struct vnode *vp, voff_t
 {
 	struct uvm_object *uobj = &vp->v_uobj;
 	voff_t pgend = round_page(newsize);
+	voff_t oldsize;
 	UVMHIST_FUNC("uvm_vnp_setsize"); UVMHIST_CALLED(ubchist);
 
 	simple_lock(&uobj->vmobjlock);
@@ -452,12 +453,13 @@ uvm_vnp_setsize(struct vnode *vp, voff_t
 	 * toss some pages...
 	 */
 
-	if (vp->v_size > pgend && vp->v_size != VSIZENOTSET) {
+	oldsize = vp->v_size;
+	vp->v_size = newsize;
+	if (oldsize > pgend && oldsize != VSIZENOTSET) {
 		(void) uvn_put(uobj, pgend, 0, PGO_FREE | PGO_SYNCIO);
 	} else {
 		simple_unlock(&uobj->vmobjlock);
 	}
-	vp->v_size = newsize;
 }
 
 /*