From nobody Mon Jul 04 13:07:18 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id D378D8AFF96; Mon, 4 Jul 2022 13:07:18 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Lc5gV4XLDz57cm; Mon, 4 Jul 2022 13:07:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656940038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kzgqEbU4WSzfmcvSne/BieV8aGNxPUz4+LkvDRPksLA=; b=peDuaOhkKy8xK2N/PzUqL5NV//5igQV7OWWKX0OlRYaZIvs9df0i67+n2lGmHJXTy4Glwa 5JKNieAW6gkcoRcAu3Vc3DphuP8/VY9V4e/AsNx0b5O8/HtZMAf712DvvnotOp5WVKvm/v pS6pxeDEvt3yPKmKeYLxmj08PPk9f/B/Li3W14idFRLwn8ibYLzxIiLgvYe4aLd/975x0N vHC/F8YypGohQCtyfSluuP0IqZINcj1j8L7IU7uTylokLgidSmR9mY09kFIj5Eo0QdtbsU zWFcT8yJsD5YJ+6G/CP/1vZk/QtD7WftayOhzcJuqPTXI8vFjGHdPAhCaLFQAg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6205F116D2; Mon, 4 Jul 2022 13:07:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 264D7IYD056734; Mon, 4 Jul 2022 13:07:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 264D7Io1056733; Mon, 4 Jul 2022 13:07:18 GMT (envelope-from git) Date: Mon, 4 Jul 2022 13:07:18 GMT Message-Id: <202207041307.264D7Io1056733@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: de0b1239dfa4 - stable/13 - vm: Fix racy checks for swap objects List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: de0b1239dfa49011f76369551838d31c00e5daa1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656940038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kzgqEbU4WSzfmcvSne/BieV8aGNxPUz4+LkvDRPksLA=; b=BMOYR+ETgDPWfbiRsTxWr2MTtWmC+VScGOz2ZeoWBpmM9jwJStMfXbZNRgPqLbWugsseiJ onbsSYxwUPZfRvoRpumlo7xOdxIWrJ6SMtBXerYS1umt/6jUKCe89Q7TKgWshNFKvl1SFO D9i1uu63EodHPg3JuKGi5niyo7b1GaZS8ePNaQ7Gx6jZq5vcKhwNdpWdA0FloIFwN+PTm9 77cT8jc8jYj884BObgIEKsRbsAwVZ/G+CAKMvWnKKRNiUPQoK7uV/pk6z7kEriW3h0LVdF YLORn+h4n1+Umnic8ww6BmuVw9/bGnbp7TmICNUPENQN/1UNzxEFjmTE80i6Tg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656940038; a=rsa-sha256; cv=none; b=wO+fzwanbK28N9ZSbe/MTyJhvEwG4JBJk4HBGI9AmL7jgFLNN68KNFMJSGMj/caJTn27GZ Z70nqHEVGHYlJ+iH1Q44MWqRlZtmCUn9T7/py8FQQ0tdobZmMyjtn/lUP5Jm3p5DcF8y8L P0/ptuTyn1RqWTR7FvQ1QrvkAkouMBqMy6o11kGsqsQvn+Vc72ZoN0sTJG3bB9fEwFaRWg 6POuB7KEs9pW7BUGyrNAHUBUOcX+rJ/b3H9xRGrzS97RupWPi2U/bD/sgZM9egdZezTh8e 0t9S/gOlSTvyR1NzH43BYP1RfHLffsTI6o9QbjVx5hoaFL9yvr0Dr1cm1IjuhQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=de0b1239dfa49011f76369551838d31c00e5daa1 commit de0b1239dfa49011f76369551838d31c00e5daa1 Author: Mark Johnston AuthorDate: 2022-06-20 16:18:15 +0000 Commit: Mark Johnston CommitDate: 2022-07-04 13:06:55 +0000 vm: Fix racy checks for swap objects Commit 4b8365d752ef introduced the ability to dynamically register VM object types, for use by tmpfs, which creates swap-backed objects. As a part of this, checks for such objects changed from object->type == OBJT_DEFAULT || object->type == OBJT_SWAP to object->type == OBJT_DEFAULT || (object->flags & OBJ_SWAP) != 0 In particular, objects of type OBJT_DEFAULT do not have OBJ_SWAP set; the swap pager sets this flag when converting from OBJT_DEFAULT to OBJT_SWAP. A few of these checks are done without the object lock held. It turns out that this can result in false negatives since the swap pager converts objects like so: object->type = OBJT_SWAP; object->flags |= OBJ_SWAP; Fix the problem by adding explicit tests for OBJT_SWAP objects in unlocked checks. PR: 258932 Fixes: 4b8365d752ef ("Add OBJT_SWAP_TMPFS pager") Reported by: bdrewery Reviewed by: kib Sponsored by: The FreeBSD Foundation (cherry picked from commit e123264e4dc394602f9fed2f0376204b5998d815) --- sys/vm/vm_map.c | 9 ++++++--- sys/vm/vm_mmap.c | 5 ++--- sys/vm/vm_pageout.c | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index fb59c2351a5d..7373bb21705a 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2826,9 +2826,6 @@ again: continue; } - if (obj->type != OBJT_DEFAULT && - (obj->flags & OBJ_SWAP) == 0) - continue; VM_OBJECT_WLOCK(obj); if (obj->type != OBJT_DEFAULT && (obj->flags & OBJ_SWAP) == 0) { @@ -4141,7 +4138,13 @@ vm_map_copy_entry( */ size = src_entry->end - src_entry->start; if ((src_object = src_entry->object.vm_object) != NULL) { + /* + * Swap-backed objects need special handling. Note that + * this is an unlocked check, so it is possible to race + * with an OBJT_DEFAULT -> OBJT_SWAP conversion. + */ if (src_object->type == OBJT_DEFAULT || + src_object->type == OBJT_SWAP || (src_object->flags & OBJ_SWAP) != 0) { vm_map_copy_swap_object(src_entry, dst_entry, size, fork_charge); diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index adbecd01ef38..48bf364731a2 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -1356,9 +1356,8 @@ vm_mmap_vnode(struct thread *td, vm_size_t objsize, goto done; } } else { - KASSERT(obj->type == OBJT_DEFAULT || - (obj->flags & OBJ_SWAP) != 0, - ("wrong object type")); + KASSERT(obj->type == OBJT_DEFAULT || obj->type == OBJT_SWAP || + (obj->flags & OBJ_SWAP) != 0, ("wrong object type")); vm_object_reference(obj); #if VM_NRESERVLEVEL > 0 if ((obj->flags & OBJ_COLORED) == 0) { diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 36d5f3275800..74439d5884ef 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -1886,8 +1886,9 @@ vm_pageout_oom_pagecount(struct vmspace *vmspace) if ((entry->eflags & MAP_ENTRY_NEEDS_COPY) != 0 && obj->ref_count != 1) continue; - if (obj->type == OBJT_DEFAULT || obj->type == OBJT_PHYS || - obj->type == OBJT_VNODE || (obj->flags & OBJ_SWAP) != 0) + if (obj->type == OBJT_DEFAULT || obj->type == OBJT_SWAP || + obj->type == OBJT_PHYS || obj->type == OBJT_VNODE || + (obj->flags & OBJ_SWAP) != 0) res += obj->resident_page_count; } return (res);