From patchwork Thu Oct 19 14:22:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10017229 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 D581C60224 for ; Thu, 19 Oct 2017 14:23:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D10DA28CEC for ; Thu, 19 Oct 2017 14:23:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5A5828D7E; Thu, 19 Oct 2017 14:23:33 +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 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 622CA28CEC for ; Thu, 19 Oct 2017 14:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754982AbdJSOXb (ORCPT ); Thu, 19 Oct 2017 10:23:31 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:38941 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754972AbdJSOX0 (ORCPT ); Thu, 19 Oct 2017 10:23:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/ZZVKzwLUNTzW3kJMm6sfr0GcTF6cuEry16rQDiWOuc=; b=hpgCDe9fl5Pni/LS8dBUTbdtj mVTdF/8GQCEMDXRb69emR8hIZzNzz0XkQDwANjZSOSmlOiggjSSw+HbnnXA4CPniSeC1kwGl77CS8 cUsMNYkGQ6G43W4EaquN0vkW2cr9HZA+iyTWDzPirY+tAD3ACygO+0d18hfhBZMLGfPVoPt3yQ2rD FBlCDY+h6VZ4JbAkME3qYxoYJDTXHA71f5vcWi1yPgXxlWlkfor1uspXWxtNTln9l2c1HoN/Meihp 2Xf5FGlaj6ksqBdorR57zmoLnqCPGL0cyUJwermBZJiYdHAbYk7VK5PWN9Rz3c73p/u/z2b05sWRY ZyVzv13BQ==; Received: from clnet-p099-196.ikbnet.co.at ([83.175.99.196] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1e5BjJ-0004pX-Iv; Thu, 19 Oct 2017 14:23:25 +0000 From: Christoph Hellwig To: stable@vger.kernel.org Cc: linux-xfs@vger.kernel.org, "Darrick J . Wong" Subject: [PATCH 09/16] xfs: handle racy AIO in xfs_reflink_end_cow Date: Thu, 19 Oct 2017 16:22:52 +0200 Message-Id: <20171019142259.20082-10-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171019142259.20082-1-hch@lst.de> References: <20171019142259.20082-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 commit e12199f85d0ad1b04ce6c425ad93cd847fe930bb upstream. If we got two AIO writes into a COW area the second one might not have any COW extents left to convert. Handle that case gracefully instead of triggering an assert or accessing beyond the bounds of the extent list. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_reflink.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 0015c19c7455..17d3c964a2a2 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -767,7 +767,13 @@ xfs_reflink_end_cow( /* If there is a hole at end_fsb - 1 go to the previous extent */ if (eof || got.br_startoff > end_fsb) { - ASSERT(idx > 0); + /* + * In case of racing, overlapping AIO writes no COW extents + * might be left by the time I/O completes for the loser of + * the race. In that case we are done. + */ + if (idx <= 0) + goto out_cancel; xfs_bmbt_get_all(xfs_iext_get_ext(ifp, --idx), &got); } @@ -841,6 +847,7 @@ xfs_reflink_end_cow( out_defer: xfs_defer_cancel(&dfops); +out_cancel: xfs_trans_cancel(tp); xfs_iunlock(ip, XFS_ILOCK_EXCL); out: