Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2677497imj; Mon, 11 Feb 2019 06:54:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IaW2vMlVt/gt+ld6e5/9UJyrHUpDc6S2r0NwTovj4YqamWcYXYJBhRBq4wBkcdizQ37B+Oo X-Received: by 2002:a17:902:ba8b:: with SMTP id k11mr37818545pls.177.1549896868485; Mon, 11 Feb 2019 06:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549896868; cv=none; d=google.com; s=arc-20160816; b=gmQkD7mrvjSlacaMLJypCjv50F7EMVW5q6IuB2+csRCpRfLEljIzVJjYRJWiIs88YB HEy+eQQqS/VzIPaMiuKR42+FwogD0KH6n6FxWijdXJexm2Oaw5LzdXIkr5QS7jrX9qb2 nPIYc21F7JBNtpf8AymzbQ5IZ0yhYadsLZ8j3k0qyvOZjyvL0KyA1g5B0Cm1BvWnZQDP bFQAlQX/Gai16UQeWPi/LA7UkJzEIgVrzHcSWoGewMr9Oj+xqWW4eqU0o+R0u8XEjYFg YJ14y0kKkIWwpi2Q4k4RIrV9FySumCU4A990Uaf+BXPmfMRz7baAFuDNM/ESLnc07PG9 HkNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+U9OyCv22s+VgGI6n0CTTmNbtIRhqz04n9W3Q8oQH/U=; b=evcHuXqfz5fqvbqZVzFdElMhGPnAOtBxgdheAj804POXaty+/CU7AUiHpsb90LbNaY WWB51aYFZSH4FfflRPq9aVzzrTBt0nKOcv15RqLUFoUU2UjsuLWS0Ic2y2X85w5QwQxr itdyRlBrzgdcHbSVYJXrXs5BDV9T16xhShZVOp7wpmvmzblnlqDxkr9mswAgzpqxTs8c fvpfYkDuDbnZTuObr9qG9EFrC9b1oHh6cpK6DWfFVSlCiq6/LtlQ+9CFjxenM6MDnz2T Q68O+DMygNUIpR2QT9Y2nxz1xHjzSpwNgnLZu+QqA4rhfVcMfqNboI3nStBcXYN0EmPp /JRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D8atYaVr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si9839333pls.154.2019.02.11.06.54.12; Mon, 11 Feb 2019 06:54:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D8atYaVr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387997AbfBKOwF (ORCPT + 99 others); Mon, 11 Feb 2019 09:52:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:38114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731856AbfBKOv6 (ORCPT ); Mon, 11 Feb 2019 09:51:58 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 17B8E2081B; Mon, 11 Feb 2019 14:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896716; bh=F/cKX5tdTUsyy/V5i5nf1CBM48GIj0K3TuM/0YGb0Co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D8atYaVr1B9tfAXH236QMo84+nm1ufs+2QeXzVodHzkch/p9Bjob8+RuFuvLR3tu6 eTqYp15NusvSdS66y24X+6eQsNTVklOg9wW6Vn7Eh/Gqw2Y3T7mWEavlv57XdZewtb IdhEaX2PxoxQHEwMWWNEyFYfQjEtYvKLqZiJ0srI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , Allison Henderson , Christoph Hellwig , "Darrick J. Wong" Subject: [PATCH 4.19 277/313] xfs: eof trim writeback mapping as soon as it is cached Date: Mon, 11 Feb 2019 15:19:17 +0100 Message-Id: <20190211141911.768148956@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Brian Foster commit aa6ee4ab69293969867ab09b57546d226ace3d7a upstream. The cached writeback mapping is EOF trimmed to try and avoid races between post-eof block management and writeback that result in sending cached data to a stale location. The cached mapping is currently trimmed on the validation check, which leaves a race window between the time the mapping is cached and when it is trimmed against the current inode size. For example, if a new mapping is cached by delalloc conversion on a blocksize == page size fs, we could cycle various locks, perform memory allocations, etc. in the writeback codepath before the associated mapping is eventually trimmed to i_size. This leaves enough time for a post-eof truncate and file append before the cached mapping is trimmed. The former event essentially invalidates a range of the cached mapping and the latter bumps the inode size such the trim on the next writepage event won't trim all of the invalid blocks. fstest generic/464 reproduces this scenario occasionally and causes a lost writeback and stale delalloc blocks warning on inode inactivation. To work around this problem, trim the cached writeback mapping as soon as it is cached in addition to on subsequent validation checks. This is a minor tweak to tighten the race window as much as possible until a proper invalidation mechanism is available. Fixes: 40214d128e07 ("xfs: trim writepage mapping to within eof") Cc: # v4.14+ Signed-off-by: Brian Foster Reviewed-by: Allison Henderson Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_aops.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -449,6 +449,7 @@ xfs_map_blocks( } wpc->imap = imap; + xfs_trim_extent_eof(&wpc->imap, ip); trace_xfs_map_blocks_found(ip, offset, count, wpc->io_type, &imap); return 0; allocate_blocks: @@ -459,6 +460,7 @@ allocate_blocks: ASSERT(whichfork == XFS_COW_FORK || cow_fsb == NULLFILEOFF || imap.br_startoff + imap.br_blockcount <= cow_fsb); wpc->imap = imap; + xfs_trim_extent_eof(&wpc->imap, ip); trace_xfs_map_blocks_alloc(ip, offset, count, wpc->io_type, &imap); return 0; }