Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2723277pxv; Sun, 11 Jul 2021 23:53:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLIb0pNuIyo6zpNciLpD84swyHgW/tjTzrxQC/Qs/hfmKppWiX6c3KP1anSsRz/h06vBtE X-Received: by 2002:a05:6402:503:: with SMTP id m3mr23112343edv.183.1626072811438; Sun, 11 Jul 2021 23:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072811; cv=none; d=google.com; s=arc-20160816; b=DiJIqMZ4SNQ7TKm6L3VQ28b7IbjQL56VrS+doWn9ZbjG9sl4qwMFj0p1JkxsE7Q6FE fj6Yp12TDoDNgQeKmh8WvRoAxFixOU0MAtdevxmJX1HOkmuWk9GN8fnxqk66zrwec1al X2NbcSSLkydx65hIJ9T0nMsLkTP5/qwFTUpFtITVtHdy+89q58AucH50hbp0V6bH8hIw G7uAxRQRrPdclYovdMAhb6ca3u/f93BXHOvhkoUJvf5qqKf2xSGCtMZePKFWx8LbgERZ wnVwLO96yo+oHIN3bE65udfyHWWuzfxFohIBBKrCzTPnw00NLO+J6uCfqKqfdbdeQm8v nnbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=60IOkmRwuF+TrQsbC4vq9iHXNaUVhbWKUNE7VPCcd/c=; b=Z4pt+MmU9y/7dYqcHy1NECmWLPs4BHVL4sRgSWBbi9cBqum+AU9ssQ+K5Vvosqaz9Q Sz9Td5//ml4s+uOs48mFza5IYSUcK7D3V71HgKduzOP06ctrt41VPJ3r4gwyQ02SZnb8 5xzMRGc/meUv/NvBBEEp3swNO8YtzZgK0fL5J98981QmqyeWAbAPE9esimC59YSpykJC 3k6Ju51ZuMdX6/AkkY5beTMkMHQOY/RReObE0+Tfb3MK0cMe6073D+Avrnxoh0KcBZhs 0OZ0RRCTU1+yjEstPHw13+B0Ov88eXSqZ+oukrW7oENJr8x1h6Bq7lm5zkYDP+a9SEDd kRxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0nFbj287; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si16614910edy.2.2021.07.11.23.53.08; Sun, 11 Jul 2021 23:53:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0nFbj287; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240311AbhGLGu4 (ORCPT + 99 others); Mon, 12 Jul 2021 02:50:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:33150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237935AbhGLGjq (ORCPT ); Mon, 12 Jul 2021 02:39:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B467611AD; Mon, 12 Jul 2021 06:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071747; bh=GlfDKcO4IErOnM+8k+Luy7qZxQgsMyBm+JYjVL2R3Gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0nFbj2870BV0P8i+xoKbXh81fuFR8kd0XHlrNtVWcvXuRzcHjHjIy73qU1/H885Xp F68ecbUDic1kPcy3BG5IP4Cpo65Q5j4NB0GzUUG1ijW5eAh1FggwXHmMVA7xLAuBXM GhDUu/lvE1AZxK1oh5GTpp5xwarYE4HXImWwzllM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba , Sasha Levin , Ritesh Harjani , Anand Jain Subject: [PATCH 5.10 159/593] btrfs: dont clear page extent mapped if were not invalidating the full page Date: Mon, 12 Jul 2021 08:05:19 +0200 Message-Id: <20210712060900.537539015@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo [ Upstream commit bcd77455d590eaa0422a5e84ae852007cfce574a ] [BUG] With current btrfs subpage rw support, the following script can lead to fs hang: $ mkfs.btrfs -f -s 4k $dev $ mount $dev -o nospace_cache $mnt $ fsstress -w -n 100 -p 1 -s 1608140256 -v -d $mnt The fs will hang at btrfs_start_ordered_extent(). [CAUSE] In above test case, btrfs_invalidate() will be called with the following parameters: offset = 0 length = 53248 page dirty = 1 subpage dirty bitmap = 0x2000 Since @offset is 0, btrfs_invalidate() will try to invalidate the full page, and finally call clear_page_extent_mapped() which will detach subpage structure from the page. And since the page no longer has subpage structure, the subpage dirty bitmap will be cleared, preventing the dirty range from being written back, thus no way to wake up the ordered extent. [FIX] Just follow other filesystems, only to invalidate the page if the range covers the full page. There are cases like truncate_setsize() which can call btrfs_invalidatepage() with offset == 0 and length != 0 for the last page of an inode. Although the old code will still try to invalidate the full page, we are still safe to just wait for ordered extent to finish. So it shouldn't cause extra problems. Tested-by: Ritesh Harjani # [ppc64] Tested-by: Anand Jain # [aarch64] Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a03d3bad2139..4f21b8fbfd4b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8213,7 +8213,19 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, */ wait_on_page_writeback(page); - if (offset) { + /* + * For subpage case, we have call sites like + * btrfs_punch_hole_lock_range() which passes range not aligned to + * sectorsize. + * If the range doesn't cover the full page, we don't need to and + * shouldn't clear page extent mapped, as page->private can still + * record subpage dirty bits for other part of the range. + * + * For cases that can invalidate the full even the range doesn't + * cover the full page, like invalidating the last page, we're + * still safe to wait for ordered extent to finish. + */ + if (!(offset == 0 && length == PAGE_SIZE)) { btrfs_releasepage(page, GFP_NOFS); return; } -- 2.30.2