From patchwork Fri Jan 26 02:05:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10185023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AB33D60211 for ; Fri, 26 Jan 2018 02:15:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92C6F28CB7 for ; Fri, 26 Jan 2018 02:15:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86F7628CBF; Fri, 26 Jan 2018 02:15:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D884728CB7 for ; Fri, 26 Jan 2018 02:15:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751441AbeAZCPW (ORCPT ); Thu, 25 Jan 2018 21:15:22 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47952 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751426AbeAZCPV (ORCPT ); Thu, 25 Jan 2018 21:15:21 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0Q2F4iD152761 for ; Fri, 26 Jan 2018 02:15:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=QB5O6HQCc5iV5Gpay+kZpIyIZkaSTARpKMW8oviai10=; b=XPsB5s+vRN6bDjSihldXu+suP9I8Iq+8E744Y6jlfFb22J1cwmv8V/iK/JAJWjD+uNwR NkyIJKoybJ1vHfRr7BAFYMxJELgVvNLnjscmiJxGahYdDKISvMb5mToIjegxWVrDNLkZ dADFivyFCaroL0K39czL/zd/7lnLG+l8WMUj2YFiKHTSI9HDfNc8OmNZx9LS5U+LJS3b jU6gbW9Cr+WVxurvTMpwookf1KWKjJC+ULdoZQwHXoAZsxMayybJYmNonCusfRm6rpUM O54mX11u3ZQBRBXUkyt+bUROq5R7bToHRjWR58G1IZLwu9qogSVDFQVOWYPxbQSn1j5y Jw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2fqucqr035-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 26 Jan 2018 02:15:20 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0Q25K7D015078 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 26 Jan 2018 02:05:20 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0Q25KjR010707 for ; Fri, 26 Jan 2018 02:05:20 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Jan 2018 18:05:19 -0800 Subject: [PATCH 5/6] xfs: skip CoW writes past EOF when writeback races with truncate From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 25 Jan 2018 18:05:18 -0800 Message-ID: <151693231885.7395.533058591055949677.stgit@magnolia> In-Reply-To: <151693228803.7395.12526880865470882359.stgit@magnolia> References: <151693228803.7395.12526880865470882359.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8785 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801260025 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Every so often we blow the ASSERT(type != XFS_IO_COW) in xfs_map_blocks when running fsstress, as we do in generic/269. The cause of this is writeback racing with truncate -- writeback doesn't take the iolock, so truncate can sneak in to decrease i_size and truncate page cache while writeback is gathering buffer heads to schedule writeout. If we hit this race on a block that has a CoW mapping, we'll get a valid imap from the CoW fork but the reduced i_size trims the mapping to zero length (which makes it invalid), so we call xfs_map_blocks to try again. This doesn't do much anyway, since any mapping we get out of that will also be invalid, so we might as well skip the assert and just stop. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_aops.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 2e094c7..2ebc42e 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -390,6 +390,19 @@ xfs_map_blocks( if (XFS_FORCED_SHUTDOWN(mp)) return -EIO; + /* + * Apparently truncate can race with writeback since writeback doesn't + * take the iolock and truncate decreases the file size before it + * starts truncating the pages between new_size and old_size. + * Therefore, we can end up in the situation where writeback gets a + * CoW fork mapping but the truncate makes the mapping invalid and we + * end up in here trying to get a new mapping. Bail out here so that + * we simply never get a valid mapping and so we drop the write + * altogether. The page truncation will kill the contents anyway. + */ + if (type == XFS_IO_COW && offset > i_size_read(inode)) + return 0; + ASSERT(type != XFS_IO_COW); if (type == XFS_IO_UNWRITTEN) bmapi_flags |= XFS_BMAPI_IGSTATE;