From owner-svn-src-head@freebsd.org Mon Mar 20 05:15:56 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9F91DD13A30; Mon, 20 Mar 2017 05:15:56 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6C6581DBD; Mon, 20 Mar 2017 05:15:56 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2K5FtMc032281; Mon, 20 Mar 2017 05:15:55 GMT (envelope-from alc@FreeBSD.org) Received: (from alc@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2K5Ft9g032280; Mon, 20 Mar 2017 05:15:55 GMT (envelope-from alc@FreeBSD.org) Message-Id: <201703200515.v2K5Ft9g032280@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: alc set sender to alc@FreeBSD.org using -f From: Alan Cox Date: Mon, 20 Mar 2017 05:15:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315621 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Mar 2017 05:15:56 -0000 Author: alc Date: Mon Mar 20 05:15:55 2017 New Revision: 315621 URL: https://svnweb.freebsd.org/changeset/base/315621 Log: Use IDX_TO_OFF(), not ptoa(), when converting the difference between two vm_pindex_t's into a vm_ooffset_t. The length given to shm_dotruncate() must never be negative. Assert this. Tidy up a comment. Reviewed by: kib MFC after: 1 week Modified: head/sys/kern/uipc_shm.c Modified: head/sys/kern/uipc_shm.c ============================================================================== --- head/sys/kern/uipc_shm.c Mon Mar 20 05:12:27 2017 (r315620) +++ head/sys/kern/uipc_shm.c Mon Mar 20 05:15:55 2017 (r315621) @@ -418,6 +418,7 @@ shm_dotruncate(struct shmfd *shmfd, off_ vm_ooffset_t delta; int base, rv; + KASSERT(length >= 0, ("shm_dotruncate: length < 0")); object = shmfd->shm_object; VM_OBJECT_WLOCK(object); if (length == shmfd->shm_size) { @@ -486,7 +487,7 @@ retry: vm_pager_page_unswapped(m); } } - delta = ptoa(object->size - nobjsize); + delta = IDX_TO_OFF(object->size - nobjsize); /* Toss in memory pages. */ if (nobjsize < object->size) @@ -501,8 +502,8 @@ retry: swap_release_by_cred(delta, object->cred); object->charge -= delta; } else { - /* Attempt to reserve the swap */ - delta = ptoa(nobjsize - object->size); + /* Try to reserve additional swap space. */ + delta = IDX_TO_OFF(nobjsize - object->size); if (!swap_reserve_by_cred(delta, object->cred)) { VM_OBJECT_WUNLOCK(object); return (ENOMEM);