From owner-svn-src-all@freebsd.org Mon May 27 11:22:05 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 199CF15C02BD; Mon, 27 May 2019 11:22:05 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 49C008F6C7; Mon, 27 May 2019 11:22:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id x4RBLtZV043479 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 27 May 2019 14:21:58 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x4RBLtZV043479 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id x4RBLtxk043478; Mon, 27 May 2019 14:21:55 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 27 May 2019 14:21:55 +0300 From: Konstantin Belousov To: Alexey Dokuchaev Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r232071 - head/sys/vm Message-ID: <20190527112155.GZ2748@kib.kiev.ua> References: <201202232107.q1NL7GHi023139@svn.freebsd.org> <20190527095256.GA52203@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190527095256.GA52203@FreeBSD.org> User-Agent: Mutt/1.11.4 (2019-03-13) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 May 2019 11:22:05 -0000 On Mon, May 27, 2019 at 09:52:56AM +0000, Alexey Dokuchaev wrote: > On Thu, Feb 23, 2012 at 09:07:16PM +0000, Konstantin Belousov wrote: > > New Revision: 232071 > > URL: http://svn.freebsd.org/changeset/base/232071 > > > > Log: > > Account the writeable shared mappings backed by file in the vnode > > v_writecount. Keep the amount of the virtual address space used by > > the mappings in the new vm_object un_pager.vnp.writemappings > > counter. The vnode v_writecount is incremented when writemappings gets > > non-zero value, and decremented when writemappings is returned to > > zero. > > > > Writeable shared vnode-backed mappings are accounted for in vm_mmap(), > > and vm_map_insert() is instructed to set MAP_ENTRY_VN_WRITECNT flag on > > the created map entry. During deferred map entry deallocation, > > vm_map_process_deferred() checks for MAP_ENTRY_VN_WRITECOUNT and > > decrements writemappings for the vm object. > > > > Now, the writeable mount cannot be demoted to read-only while > > writeable shared mappings of the vnodes from the mount point > > exist. Also, execve(2) fails for such files with ETXTBUSY, as it > > should be. > > > > ... > > Modified: head/sys/vm/vnode_pager.c > > ============================================================================== > > --- head/sys/vm/vnode_pager.c Thu Feb 23 20:58:52 2012 (r232070) > > +++ head/sys/vm/vnode_pager.c Thu Feb 23 21:07:16 2012 (r232071) > > @@ -1215,3 +1222,81 @@ vnode_pager_undirty_pages(vm_page_t *ma, > > } > > VM_OBJECT_UNLOCK(obj); > > } > > + > > +void > > +vnode_pager_update_writecount(vm_object_t object, vm_offset_t start, > > + vm_offset_t end) > > So, it is first `start, then `end', but below... > > > +{ > > + struct vnode *vp; > > + vm_ooffset_t old_wm; > > + > > + ... > > +} > > + > > +void > > +vnode_pager_release_writecount(vm_object_t object, vm_offset_t start, > > + vm_offset_t end) > > +{ > > + struct vnode *vp; > > + struct mount *mp; > > + vm_offset_t inc; > > + int vfslocked; > > + > > + VM_OBJECT_LOCK(object); > > + > > + /* > > + * First, recheck the object type to account for the race when > > + * the vnode is reclaimed. > > + */ > > + if (object->type != OBJT_VNODE) { > > + VM_OBJECT_UNLOCK(object); > > + return; > > + } > > + > > + /* > > + * Optimize for the case when writemappings is not going to > > + * zero. > > + */ > > + inc = end - start; > > + if (object->un_pager.vnp.writemappings != inc) { > > + object->un_pager.vnp.writemappings -= inc; > > + VM_OBJECT_UNLOCK(object); > > + return; > > + } > > + > > + vp = object->handle; > > + vhold(vp); > > + VM_OBJECT_UNLOCK(object); > > + vfslocked = VFS_LOCK_GIANT(vp->v_mount); > > + mp = NULL; > > + vn_start_write(vp, &mp, V_WAIT); > > + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); > > + > > + /* > > + * Decrement the object's writemappings, by swapping the start > > + * and end arguments for vnode_pager_update_writecount(). If > > + * there was not a race with vnode reclaimation, then the > > + * vnode's v_writecount is decremented. > > + */ > > + vnode_pager_update_writecount(object, end, start); > > ... here, first `end' is passed, then `start'. Is this intentional? Did you read the comment right before the call ? > > PVS Studio complains: > > /usr/src/sys/vm/vnode_pager.c:1584:1: warning: V764 Possible > incorrect order of arguments passed to 'vnode_pager_update_writecount' > function: 'end' and 'start'. > > > + VOP_UNLOCK(vp, 0); > > + vdrop(vp); > > + if (mp != NULL) > > + vn_finished_write(mp); > > + VFS_UNLOCK_GIANT(vfslocked); > > +}