From owner-svn-src-all@freebsd.org Fri Jan 24 19:42:54 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 149CA1FA009; Fri, 24 Jan 2020 19:42:54 +0000 (UTC) (envelope-from kib@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 4848gd6grkz4SVN; Fri, 24 Jan 2020 19:42:53 +0000 (UTC) (envelope-from kib@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 C5C1F2C48E; Fri, 24 Jan 2020 19:42:53 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00OJgrT2050298; Fri, 24 Jan 2020 19:42:53 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00OJgrxY050297; Fri, 24 Jan 2020 19:42:53 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202001241942.00OJgrxY050297@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 24 Jan 2020 19:42:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357091 - head/sys/vm X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/vm X-SVN-Commit-Revision: 357091 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: Fri, 24 Jan 2020 19:42:54 -0000 Author: kib Date: Fri Jan 24 19:42:53 2020 New Revision: 357091 URL: https://svnweb.freebsd.org/changeset/base/357091 Log: Handle a race of collapse with a retrying fault. Both vm_object_scan_all_shadowed() and vm_object_collapse_scan() might observe an invalid page left in the default backing object by the fault handler that retried. Check for the condition and refuse to collapse. Reported and tested by: pho Reviewed by: jeff Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D23331 Modified: head/sys/vm/vm_object.c Modified: head/sys/vm/vm_object.c ============================================================================== --- head/sys/vm/vm_object.c Fri Jan 24 17:24:02 2020 (r357090) +++ head/sys/vm/vm_object.c Fri Jan 24 19:42:53 2020 (r357091) @@ -1700,14 +1700,25 @@ vm_object_scan_all_shadowed(vm_object_t object) if (new_pindex >= object->size) break; - /* - * If the backing object page is busy a grandparent or older - * page may still be undergoing CoW. It is not safe to - * collapse the backing object until it is quiesced. - */ - if (p != NULL && vm_page_busied(p)) - return (false); + if (p != NULL) { + /* + * If the backing object page is busy a + * grandparent or older page may still be + * undergoing CoW. It is not safe to collapse + * the backing object until it is quiesced. + */ + if (vm_page_tryxbusy(p) == 0) + return (false); + /* + * We raced with the fault handler that left + * newly allocated invalid page on the object + * queue and retried. + */ + if (!vm_page_all_valid(p)) + goto unbusy_ret; + } + /* * See if the parent has the page or if the parent's object * pager has the page. If the parent has the page but the page @@ -1717,15 +1728,24 @@ vm_object_scan_all_shadowed(vm_object_t object) * object and we might as well give up now. */ pp = vm_page_lookup(object, new_pindex); + /* - * The valid check here is stable due to object lock being - * required to clear valid and initiate paging. + * The valid check here is stable due to object lock + * being required to clear valid and initiate paging. + * Busy of p disallows fault handler to validate pp. */ if ((pp == NULL || vm_page_none_valid(pp)) && !vm_pager_has_page(object, new_pindex, NULL, NULL)) - return (false); + goto unbusy_ret; + if (p != NULL) + vm_page_xunbusy(p); } return (true); + +unbusy_ret: + if (p != NULL) + vm_page_xunbusy(p); + return (false); } static void @@ -1769,6 +1789,14 @@ vm_object_collapse_scan(vm_object_t object) swap_pager_freespace(backing_object, p->pindex, 1); + KASSERT(!pmap_page_is_mapped(p), + ("freeing mapped page %p", p)); + if (vm_page_remove(p)) + vm_page_free(p); + continue; + } + + if (!vm_page_all_valid(p)) { KASSERT(!pmap_page_is_mapped(p), ("freeing mapped page %p", p)); if (vm_page_remove(p))