From nobody Sat Nov 20 16:37:45 2021 X-Original-To: dev-commits-src-main@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 5760A188D2EA; Sat, 20 Nov 2021 16:37:49 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HxK2h4QBbz3Gph; Sat, 20 Nov 2021 16:37:48 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qv1-xf2c.google.com with SMTP id gu12so9271002qvb.6; Sat, 20 Nov 2021 08:37:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=h50BEeSeNdcwaZXT2fj+RhtrJiAQRuVFhBNnxkI7WJg=; b=bDuHuc6oLALBN/I8LRrjztRuGXHo3267o7ebQV1h+5Jq/0tmWMU7yabpZQhsuKm7nS RTIaWnPBemegPibYdrUTNVXt5FA3t87Nu8YoP9XBvH8oG927mwr+lk3cgOK17zmxy1Fo 2pGS3pHTtAGu7t+75MvqE2ZuBFTfRerjk0YNOWKR/UQeOJS9Fcw+bZtvP7bdiNbRhLEt bF6aTh1DNmsqaoAtXXS6w61IHeGg/IsRClvQudtvdf0UXnvJVJ1yDackzTteUYYwiXL7 WK7kRWvEAPaxirWaky5nL6soRz+DHmp13OJr7uc/5fhmV+3X15j4HtINyheBu9pRQI9p 7Rog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=h50BEeSeNdcwaZXT2fj+RhtrJiAQRuVFhBNnxkI7WJg=; b=Fjct2usQt+hpe6YKJ0OjKd3u4yHgTDXWwgBbLq73xiJn8lN+2AdnfCqGt6zxqC6IYi ohRy8Cab2Q/JdT/9E9Na658TNWzOa81V/CGCwBxSO19lQdehFVQ/r7OTD65vmW7zakeQ qrN9rB0K5oi4X421cAezFbSIidIY+lhIqqiiuQ7VRmw9rQ0jjRio0PQn+tJZhfNzq2Mx w9ywgTxkZBzM5HVJdFs5c/OIUwIgY26spTFvRRCbYSPOFxzfqrQtDgZKOv+Tn++5DzfA TVWxKc7XgJ8PLfJuMAY4HOsLTHdwQIev8bxiysdcSQFEOhfR1wkLKLNUt9IqSVitgRZz LvHg== X-Gm-Message-State: AOAM531IPF+G4OfO/us5F3YHgP1BXvRZLoL7tFqlSPhl/KFMxxZhYN5e 1p7LA5a9PYmFlnXWfzynIEuW+5zXeyk= X-Google-Smtp-Source: ABdhPJxBD1YlOP+sfzZdxc5EPKdD+i5+Wop4qerVHYf+IMHaCfwWfahp+dskXfSk2h/69eKJ6paw6Q== X-Received: by 2002:a05:6214:c28:: with SMTP id a8mr83348561qvd.24.1637426267982; Sat, 20 Nov 2021 08:37:47 -0800 (PST) Received: from nuc ([142.126.186.191]) by smtp.gmail.com with ESMTPSA id w10sm1666089qtj.37.2021.11.20.08.37.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Nov 2021 08:37:47 -0800 (PST) Sender: Mark Johnston Date: Sat, 20 Nov 2021 11:37:45 -0500 From: Mark Johnston To: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 705a6ee2b611 - main - zfs: Fix a deadlock between page busy and the teardown lock Message-ID: References: <202111201636.1AKGalc6016791@gitrepo.freebsd.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202111201636.1AKGalc6016791@gitrepo.freebsd.org> X-Rspamd-Queue-Id: 4HxK2h4QBbz3Gph X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20210112 header.b=bDuHuc6o; dmarc=none; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::f2c as permitted sender) smtp.mailfrom=markjdb@gmail.com X-Spamd-Result: default: False [-0.11 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20210112]; NEURAL_HAM_MEDIUM(-0.41)[-0.413]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_COUNT_THREE(0.00)[3]; MID_RHS_NOT_FQDN(0.50)[]; DKIM_TRACE(0.00)[gmail.com:+]; NEURAL_SPAM_LONG(1.00)[1.000]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::f2c:from]; NEURAL_HAM_SHORT(-0.99)[-0.993]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; RCVD_TLS_ALL(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-ThisMailContainsUnwantedMimeParts: N On Sat, Nov 20, 2021 at 04:36:47PM +0000, Mark Johnston wrote: > The branch main has been updated by markj: > > URL: https://cgit.FreeBSD.org/src/commit/?id=705a6ee2b6112c3a653b2bd68f961a8b5b8071a4 > > commit 705a6ee2b6112c3a653b2bd68f961a8b5b8071a4 > Author: Mark Johnston > AuthorDate: 2021-11-20 16:21:25 +0000 > Commit: Mark Johnston > CommitDate: 2021-11-20 16:21:25 +0000 > > zfs: Fix a deadlock between page busy and the teardown lock > > When rolling back a dataset, ZFS has to purge file data resident in the > system page cache. To do this, it loops over all vnodes for the > mountpoint and calls vn_pages_remove() to purge pages associated with > the vnode's VM object. Each page is thus exclusively busied while the > dataset's teardown write lock is held. > > When handling a page fault on a mapped ZFS file, FreeBSD's page fault > handler busies newly allocated pages and then uses VOP_GETPAGES to fill > them. The ZFS getpages VOP acquires the teardown read lock with vnode > pages already busied. This represents a lock order reversal which can > lead to deadlock. > > To break the deadlock, observe that zfs_rezget() need only purge those > pages marked valid, and that pages busied by the page fault handler are, > by definition, invalid. Furthermore, ZFS pages always transition from > invalid to valid with the teardown lock held, and ZFS never creates > partially valid pages. Thus, zfs_rezget() can use the new > vn_pages_remove_valid() to skip over pages busied by the fault handler. I'll get this merged upstream once the new KPI is available in stable/13, but didn't see a reason to hold off committing directly.