From nobody Mon Jun 20 17:00:33 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 4B0B78778A4; Mon, 20 Jun 2022 17:00:34 +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 4LRbW54pwSz3DN0; Mon, 20 Jun 2022 17:00:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655744433; 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=dEjps/H1pu4rgPXiWvXyqhqlDxyjkSw2RQrOc4lDfeo=; b=rPYYw++z+opnUw9r4hYaHSKCM/mlSl8bYnIAvnW/0XBa+pI1zokO9+Il4pbDw5TRv26fgD CgxSD/PlccIksW0xAMiWc4h760VU8uAn3xWZBooQwZ0W/EiB3q2/u4Dmr0b17WFGJ2LJzX 8jqrO+bqmjuFXxAYsOYkyq8uPaRiR3OnqD1/ZjOvN6phvaCApEiQ8dSS4JP6Z6bUtVPlQX SqpeZIvUgjRF6RAaRMb+iq9gbcAuhLWYb7Zpt6Y899Pmvq6j1/n4DiXiGooRaOebz5Gxy7 c72fM3zHsRIEA+6hu2E6KsZHOjet4BOnD0W3pAPqJnyN+71EodZETJaitqXSGw== 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 7162920D65; Mon, 20 Jun 2022 17:00:33 +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 25KH0X1S049851; Mon, 20 Jun 2022 17:00:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25KH0XH2049850; Mon, 20 Jun 2022 17:00:33 GMT (envelope-from git) Date: Mon, 20 Jun 2022 17:00:33 GMT Message-Id: <202206201700.25KH0XH2049850@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: e123264e4dc3 - main - 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/main X-Git-Reftype: branch X-Git-Commit: e123264e4dc394602f9fed2f0376204b5998d815 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655744433; 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=dEjps/H1pu4rgPXiWvXyqhqlDxyjkSw2RQrOc4lDfeo=; b=XlGbBRXW7e56YekCXCBbuOfEeJQuum4QocOQF7M3lFicXfaj4y7W5STZ7IoAcT9wpJir1c 5rxK5BKHAvOQxZda99+HkQMF+vAGOLU1XF4RpIsVfZeDVK7C0cffh6vAkU9zRbK1iKty4C OJSFnLOo/hZg1xQIqczz4sv0Ppwk1luW0OWaCtbpTN9SlwqfTh9Q13g1DEp2Pt+f0r5bB3 eimpLCXXYMqGbxyXl/Qc8spDRNcrMbz4IBJ9UYRoMWkE+qFmKHwS5FIvRhiQtm0385LIjU OKTqc3rxRGEY4QjMnST1+lvDHmHbgKW1w05Fc35PMRwEtKQfV9p3cPla8YFhCQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655744433; a=rsa-sha256; cv=none; b=ousEqff9EpIf9qpd7DupSDTQF4MtZLLvbrRvI3VpdjeD+9FjzzvHLsYAkk/EQCOuzyOWTO x7RD/wWLMAX2ziIzPGWoxAd8etgxR0N9CPQz939SgkrclXx9dulVpDyt+swHNwgZfAGRI/ TCSYQpQWlTdNzEHzpr1cSGgTrEmGEDjleRSqmCWZYsFdfHGgpY1gPSsk1lwE/Be4deUwsr tIerqimvjBDq0PRgb1xHTrpxhb97QIYeIGv8EzMyulSFaQg67xzK4MXgeWwiC/nU8as4BI jqvebUs/clOO5aYVDPdMUTLDPBARY7rpvVr2d9l9ZcQ/mc1KG+0G3WGeowDSUw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e123264e4dc394602f9fed2f0376204b5998d815 commit e123264e4dc394602f9fed2f0376204b5998d815 Author: Mark Johnston AuthorDate: 2022-06-20 16:18:15 +0000 Commit: Mark Johnston CommitDate: 2022-06-20 16:48:14 +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 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35470 --- 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 1842b6e1a314..93182051abb7 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2824,9 +2824,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) { @@ -4139,7 +4136,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 db9a32d1c9bc..5f27b550b78d 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -1368,9 +1368,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);