Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2833634pxv; Mon, 12 Jul 2021 03:05:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyohAx/Kw56YsKgRDJ8HNHLEPep11c181aSCaEGzViMr7LCS+MY/wtw5JIsDWXzawawnDfB X-Received: by 2002:a05:6602:134f:: with SMTP id i15mr39344513iov.143.1626084322171; Mon, 12 Jul 2021 03:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084322; cv=none; d=google.com; s=arc-20160816; b=YE3uYI5tadA2FxidJkenXoYVXJyh6d8zzC8x41DdC9Lo5glMHvjLJBr4NeQycZwMXy Oshv+IChtdCsf//dk0YJ9qtS+0VAlP6DkjM/8eEyZNp3ee0Ux5TA8qeT6nxsTVtvbnHm jfI48qvDFHD8yfIew7JCQDi/41ymEcWa25APo3qYEllPNve4rDMjE7ydSz9kd9rDnAZN INddWcyAJvP5LeG8tkRo079XBUE8et489Rap9OP5NEvijtLRL8qb7LRjyGYzkUBr15AQ Nn+hyb4UWQIMcYBtMz/GiARBrf96/j80SzeK4ivSLubuUIFIcVZ1XbUpPxmDLWRgEuBm FRJQ== 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=fQ1pNMGXuqyNG7QKkhgYcvuA4rjnh+aMb/AQ4xyYvM0=; b=sVl92Aqv9ATcKnhlbdCXLNazLWhemx7Qd5u3hYPU7HENUBRxxYz/GJFwm8t7IxU8dy xHKJs/pKBGuwG45XNM8I7wryFVJykDcYRwEVIvoHU9sGLStiRLAXs2jeOmSiQfAlFaTF R4/GB+LwP7Vc6EYPSMKX/bMSWkxWnTAd66BblpZoiwC6L77CEk6BO6/KDUH9xOzSu4Wr 7xcXZ4cSqQ9YwXguh9Pk3L8/Kshk5Zvs+JidPOBGHdVQD1KhY/dL7oU58OfkfaUkDEqT 4rh2raGNUU4mDchohU5pgpVWhX18A35ZJokdbXKiZe0GL1pkQIFQ/Ge9e/fHS2nHsa7W 6oeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IQMaebmj; 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 v9si20384861ilu.9.2021.07.12.03.05.10; Mon, 12 Jul 2021 03:05:22 -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=IQMaebmj; 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 S1346905AbhGLHbN (ORCPT + 99 others); Mon, 12 Jul 2021 03:31:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:39920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241822AbhGLHEG (ORCPT ); Mon, 12 Jul 2021 03:04:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 59724611C2; Mon, 12 Jul 2021 07:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626073278; bh=ntd7N4ODXfPVCqUQ2oiN/qWeyj26zTtzAKpfs5+tdR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IQMaebmjUb1xlhW3EhVRLVmMovroRQs1E6AGzSfM/eGm/9oFGl1FTlIhGBuhd9jzT uWmF4sNE9CeshVLPMJu+1/2hb0F18qxPr5VhExqhB9du5Hlyb2xfH+x8U7dBvbjUsQ XF+aBde13RFL9u+NvcdeUE6XK+ZhjFUF7dcALPO4= 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.12 187/700] btrfs: dont clear page extent mapped if were not invalidating the full page Date: Mon, 12 Jul 2021 08:04:30 +0200 Message-Id: <20210712060953.221916070@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060924.797321836@linuxfoundation.org> References: <20210712060924.797321836@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 3e7173c7660d..1b22ded1a799 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8386,7 +8386,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