Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2746115imj; Mon, 11 Feb 2019 07:53:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IY+gO7yCivl6GRn+jg2L+oA5QDji2RoTK9X15RCsI5HIGMIr7O/4ybjgvgA+BL+GKqt9kOx X-Received: by 2002:a63:d047:: with SMTP id s7mr24472024pgi.311.1549900394032; Mon, 11 Feb 2019 07:53:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549900394; cv=none; d=google.com; s=arc-20160816; b=A7oK+qtfAq2oRtRBCsRKyxp/wipU6DBut+TzROxscGHxbOj5yvFrdJbpjOeiRPGL2+ eTKqY2KBiC+3wOTTeidNBdaf56wLsfVgkXEnhx/S+qbBC9MHSO65859ZIlxJ4lSIJfAf 70fRSbtdUwkEFphm7IDS0Xj4fDDopLTidGQsrlff6+qTKWj9zXxm+1kG+nnbWo3rwGPp 5S1t0GPNXdYtfDHp23ZX+6Ow/RsStTpFc/G7v8ewRF1swJsrOcBd026NKfStFK8I/YBR C6X9hBbDXusdyZ6XjYCvGQ+SngF/1POkel9H0dVHGqPLkI3+V/u1xMsJHQwelu8AW+DQ Kmuw== 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=6vuZSjm+smbKtgbWr8e3ezR+HXi75fK39FAZksY3XG4=; b=Ajs1tdBYu1TvPGb1OepCac7gDhssZpufneSLCJqXJ5Hauq+hFSKw5e/Fjn/Fwba6O3 HAgTEFPAMPPobYWEZKflVyb2J3hSQUrCAc1+qeGfGRfR2FTQ7FbTLrZreOQv5dqIFVkA VuRpkRFyHI4aA7rL+YkbTOcV+EYgmpRUrLDfZPlx9DPSQmgUydmyPeX7yqHRV0XNLP/Z fT/sGmnrBwxxUlLV3ywnZnuDxnFkFKDWm3CYmoHEP7ku1HK9DZ227nEB1VMtuufQF9nE SnUDJqa6rvUfJ0loqH4SPMsd9fNUGQ01Ake9Q8Ohe2TghlQeE3mKy/6ycxyqDhkSO18w Qaag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wNXMknxg; 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 n4si8699178pgv.512.2019.02.11.07.52.57; Mon, 11 Feb 2019 07:53:14 -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=wNXMknxg; 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 S1731490AbfBKOhg (ORCPT + 99 others); Mon, 11 Feb 2019 09:37:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:46938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730864AbfBKOhd (ORCPT ); Mon, 11 Feb 2019 09:37:33 -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 CF0B920700; Mon, 11 Feb 2019 14:37:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895852; bh=rp6SeT7cAw2aFGUMNNoH7aaBxC7cm9kDAI+OYoaCCdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wNXMknxgy4azwNjx6cLoLGhlryM5++DIh0F6NXrXDTsYusIC61dsWOQXuZZVjsq1R 5JBXdcltdRygp0d1I46VSLmKb1DcPeipuuBUMG8OuIFjbiMX/CtT5FKMyhOmcamIs1 63tTw9YJaw8xpFf/vP0VgT4V/3aS9ifbqXcF3Meo= 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.20 313/352] xfs: eof trim writeback mapping as soon as it is cached Date: Mon, 11 Feb 2019 15:19:00 +0100 Message-Id: <20190211141906.755066751@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@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.20-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; }