From owner-svn-src-all@freebsd.org Tue Apr 28 13:51:42 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 237082BA011; Tue, 28 Apr 2020 13:51:42 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49BNNZ03DPz3GDj; Tue, 28 Apr 2020 13:51:42 +0000 (UTC) (envelope-from markj@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F13282528F; Tue, 28 Apr 2020 13:51:41 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03SDpfWl028430; Tue, 28 Apr 2020 13:51:41 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03SDpfv7028428; Tue, 28 Apr 2020 13:51:41 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202004281351.03SDpfv7028428@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Tue, 28 Apr 2020 13:51:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360436 - head/sys/vm X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/vm X-SVN-Commit-Revision: 360436 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Tue, 28 Apr 2020 13:51:42 -0000 Author: markj Date: Tue Apr 28 13:51:41 2020 New Revision: 360436 URL: https://svnweb.freebsd.org/changeset/base/360436 Log: Re-check for wirings after busying the page in vm_page_release_locked(). A concurrent unlocked lookup can wire the page after vm_page_release_locked() releases the last wiring, in which case vm_page_release_locked() must not free the page. Once the xbusy lock is acquired, that, the object lock and the fact that the page is unmapped ensure that the wire count cannot increase, so re-check for new wirings after the page is xbusied. Update the comment above vm_page_wired() to reflect the new synchronization rules. Reported by: glebius Reviewed by: alc, jeff, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24592 Modified: head/sys/vm/vm_page.c head/sys/vm/vm_page.h Modified: head/sys/vm/vm_page.c ============================================================================== --- head/sys/vm/vm_page.c Tue Apr 28 13:28:58 2020 (r360435) +++ head/sys/vm/vm_page.c Tue Apr 28 13:51:41 2020 (r360436) @@ -4165,7 +4165,16 @@ vm_page_release_locked(vm_page_t m, int flags) if ((flags & VPR_TRYFREE) != 0 && (m->object->ref_count == 0 || !pmap_page_is_mapped(m)) && m->dirty == 0 && vm_page_tryxbusy(m)) { - vm_page_free(m); + /* + * An unlocked lookup may have wired the page before the + * busy lock was acquired, in which case the page must + * not be freed. + */ + if (__predict_true(!vm_page_wired(m))) { + vm_page_free(m); + return; + } + vm_page_xunbusy(m); } else { vm_page_release_toq(m, PQ_INACTIVE, flags != 0); } Modified: head/sys/vm/vm_page.h ============================================================================== --- head/sys/vm/vm_page.h Tue Apr 28 13:28:58 2020 (r360435) +++ head/sys/vm/vm_page.h Tue Apr 28 13:51:41 2020 (r360436) @@ -958,8 +958,8 @@ vm_page_drop(vm_page_t m, u_int val) * * Perform a racy check to determine whether a reference prevents the page * from being reclaimable. If the page's object is locked, and the page is - * unmapped and unbusied or exclusively busied by the current thread, no - * new wirings may be created. + * unmapped and exclusively busied by the current thread, no new wirings + * may be created. */ static inline bool vm_page_wired(vm_page_t m)