From owner-svn-src-stable-9@FreeBSD.ORG Thu Jul 11 19:18:13 2013 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E4C4157D; Thu, 11 Jul 2013 19:18:13 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id BAE201043; Thu, 11 Jul 2013 19:18:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r6BJIDiS088389; Thu, 11 Jul 2013 19:18:13 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r6BJIDR7088388; Thu, 11 Jul 2013 19:18:13 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201307111918.r6BJIDR7088388@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Thu, 11 Jul 2013 19:18:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r253218 - stable/9/sys/fs/ext2fs X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jul 2013 19:18:14 -0000 Author: pfg Date: Thu Jul 11 19:18:13 2013 New Revision: 253218 URL: http://svnweb.freebsd.org/changeset/base/253218 Log: MFC r253050: Enhancement when writing an entire block of a file (from UFS r231313). This change first attempts the uiomove() to the newly allocated (and dirty) buffer and only zeros it if the uiomove() fails. The effect is to eliminate the gratuitous zeroing of the buffer in the usual case where the uiomove() successfully fills it. Modified: stable/9/sys/fs/ext2fs/ext2_vnops.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/fs/ (props changed) Modified: stable/9/sys/fs/ext2fs/ext2_vnops.c ============================================================================== --- stable/9/sys/fs/ext2fs/ext2_vnops.c Thu Jul 11 19:09:31 2013 (r253217) +++ stable/9/sys/fs/ext2fs/ext2_vnops.c Thu Jul 11 19:18:13 2013 (r253218) @@ -1817,15 +1817,6 @@ ext2_write(struct vop_write_args *ap) if (error != 0) break; - /* - * If the buffer is not valid and we did not clear garbage - * out above, we have to do so here even though the write - * covers the entire buffer in order to avoid a mmap()/write - * race where another process may see the garbage prior to - * the uiomove() for a write replacing it. - */ - if ((bp->b_flags & B_CACHE) == 0 && fs->e2fs_bsize <= xfersize) - vfs_bio_clrbuf(bp); if ((ioflag & (IO_SYNC|IO_INVAL)) == (IO_SYNC|IO_INVAL)) bp->b_flags |= B_NOCACHE; if (uio->uio_offset + xfersize > ip->i_size) @@ -1836,6 +1827,26 @@ ext2_write(struct vop_write_args *ap) error = uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio); + /* + * If the buffer is not already filled and we encounter an + * error while trying to fill it, we have to clear out any + * garbage data from the pages instantiated for the buffer. + * If we do not, a failed uiomove() during a write can leave + * the prior contents of the pages exposed to a userland mmap. + * + * Note that we need only clear buffers with a transfer size + * equal to the block size because buffers with a shorter + * transfer size were cleared above by the call to ext2_balloc() + * with the BA_CLRBUF flag set. + * + * If the source region for uiomove identically mmaps the + * buffer, uiomove() performed the NOP copy, and the buffer + * content remains valid because the page fault handler + * validated the pages. + */ + if (error != 0 && (bp->b_flags & B_CACHE) == 0 && + fs->e2fs_bsize == xfersize) + vfs_bio_clrbuf(bp); if (ioflag & (IO_VMIO|IO_DIRECT)) { bp->b_flags |= B_RELBUF; }