Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3346274pxv; Sun, 4 Jul 2021 16:10:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXRz3BbRzO8JeBvP4TLmM1kUgMToKNoYUuDZ3fspLTPI6lOJUCJxE5YQzDAoKaEFUx9IAn X-Received: by 2002:a02:cb49:: with SMTP id k9mr9595950jap.95.1625440243754; Sun, 04 Jul 2021 16:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440243; cv=none; d=google.com; s=arc-20160816; b=hXAheoMjr+PLKdY4WYUaFpxBVuMpzlhbvummRfPKxiNb5Bu2k1D9HJmf5y/RTIa16G N1hnuJvgcwuNi7rFFhUbIIAcOzlVEnOkAFxfZYQ4fsEsbaj3YJb04S05zIEUkWVb0Xn2 usU+dJ160wHxAaNOrRfKjAXpp7Z5F/zIOmtd1kqEvYE9Pe513ShKxA4PFUetAXfPKrL3 O/60ezUhl/v3TQv0B/qio57ebMs23QMNZOQJul1x3rP13ntFEOQeU0J1TsLyD9Ldl6o4 RMRhDIxRAw0pErERLsW1t6hPfXPL2zqZiEoyjKl1U1+n5+lbzfXkG1qnpy/ErKXEUiZ2 KMRA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SfC/2b8rFkcmQe0/Pw5krDIE2es4mjxUwQP/jV5dqpw=; b=Grpvs8BI00FPT0YdXhKwwp9r/tmEagWUtGLq6REbqnbaB2cwZDU94EQhPYvOMn2v1j w9m8HaiCulSJGeK5s5phB2WNLWyLwJziXqUCpfEpIvqE5E0oGOMgEOgfR3sswbNRfylZ POlurapdOrwzygOa/nK97uNYUhkVjBwQ/SzXgHKcfPxCrYZ5zKZMqjSBqkx5BbpMKgwz Cfy3ZW8W/pGvBGcQ3Hm722EDW63BrsMoOGhzuKiXR33tg8V9eyfJFBXQSKUgRD+fJSgp lIxwtE5NJOPU7ucQOsMp84t/X7U2DCyLlxH0kJQiXpKjJYOmEtu/F7ZMAX5Iwdrew+YV +wZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u6WdjNDV; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si13537557ilu.88.2021.07.04.16.10.31; Sun, 04 Jul 2021 16:10:43 -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=@kernel.org header.s=k20201202 header.b=u6WdjNDV; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229794AbhGDXMY (ORCPT + 99 others); Sun, 4 Jul 2021 19:12:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:48260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232473AbhGDXKf (ORCPT ); Sun, 4 Jul 2021 19:10:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2FC4B6194A; Sun, 4 Jul 2021 23:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440074; bh=1jx+7YcbvDAyXame2rw2X+13M9LGtpeVrZ1GJRkwhn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u6WdjNDVAxOqQjmBZh6bEYRZtQzpST8TDUBtCzJGMr7h9XDNdXiCpaMP8pNjUpv4m TCFT9muGbAU9K7p9EbUy+jM7NE3mnAhIwCu4fOd5QrpSGZwCEGAoS/SLk5vNpn8CVE GWRk42Vanp4RfGwuMBPaYE1QZ7jfOlEiCbeMQZc4o0N1J6wFYCxz3a8Q1KzU67bHeB 5J5crl3/S0lpvmfIRp3QjAZ094speLmz0mBPmto5mabxH+6W9C/ECu56wI407CmqWw YVF1nsVKiUMOgccwC3LK4Cktv1sTlKDel3q+diSsPbvrHCmBT6TkokBPKEC8Uo17sF IG/0KeYO58MBA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qu Wenruo , Ritesh Harjani , Anand Jain , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.12 73/80] btrfs: don't clear page extent mapped if we're not invalidating the full page Date: Sun, 4 Jul 2021 19:06:09 -0400 Message-Id: <20210704230616.1489200-73-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230616.1489200-1-sashal@kernel.org> References: <20210704230616.1489200-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 d29451b839fb..454573a61132 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