Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp312680ybi; Wed, 29 May 2019 22:03:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqydnp86jtinZW0PNZ9xyN2RmTti/jFp6wHLDervFqmGnr+CYlewN3if2ddyAVnxEeLEJjfN X-Received: by 2002:a62:4c5:: with SMTP id 188mr1865102pfe.19.1559192609275; Wed, 29 May 2019 22:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559192609; cv=none; d=google.com; s=arc-20160816; b=H8Nzig1m/gK/FIe0GqJAgXSbVgtmC0OGIfPEBTaINhi89sBCvIawYCKwl45nItqWjw PUhV9T69UahT7RrJLyizo1AKPr4pkDqa7RJ0YMC5FGCygfpylMLYI6nRPsgoRC/vEu6t YA1bOCKJ7F1P7oWpUE7aQXd4n2uRIM/zboFOMNID2L+eZVO9d/NySqL81EISJGCLhCUh i/AvV8K71+9cF2mi4d/JATGwe91AXew2A246BjJVBLpqPhzvp6SmEyeKE6gP/iwnNQ5a pouHHhGfdOwtVdA3JI6XDU7VP1oxUjFJOT9ccZQuwhY3EVwByx98CglTXhKp1hJoHK4L gUew== 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=vrFzarBZXK74BEZms0RLZ24WvhXnhKKBkYvS3862pPQ=; b=fQfsg3ZhPz39GBd4a5TXWeivJcr1dGB1kY8jk55G4zJcF7ocy46smCvHhrKPMpbZxy Tz2ov0KSrGJz3LfPQtG+PxL18WdanU4tirYW3YEPhMGY0g4xk/2HLEYisS4aUIvOYYeK qIEs/+RYl3jcVfn081A1mIiXxeNO2zW7qFycTqWxExh5XT9onc8ZIb5QkwknBOhdc4IG XMnmQZizIw6d6kRVhwSY9wmj+OW+9MpEvGQ8M6yhHBdbwnyFfeuKCbOqlTjnyjQ0cRp9 sgBqbNYkwrlUqi9t1ykUrC9xoOKms/L1aj/spqkhFC0lCheCscX9yhH+jfjp9K81Jgaq FAGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jEGlzhz5; 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 u21si1800051pjx.58.2019.05.29.22.03.12; Wed, 29 May 2019 22:03:29 -0700 (PDT) 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=jEGlzhz5; 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 S1728748AbfE3E7x (ORCPT + 99 others); Thu, 30 May 2019 00:59:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:44640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727655AbfE3DJf (ORCPT ); Wed, 29 May 2019 23:09:35 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 229B32447A; Thu, 30 May 2019 03:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185775; bh=TFD9QtOmrEADc49mR+g0tRg0jNoao5ZKTnu6JPQhWPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEGlzhz5o/PXVMvaGWj6W0H+Kp1LERZciywV/GOfUagdjlyahvEIHLiNpMvGPilxT zLL+xSIUvMbpokU0or1WBiY4ITJ79oUxJiVBhKH8UrP8d3+dmrkMxLyRegPHKjKmwX FsjO27jbKf5HRrX7x7GQQAqNFMSjFWorKocQjcqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ira Weiny , Jan Kara , Theodore Tso Subject: [PATCH 5.1 003/405] ext4: wait for outstanding dio during truncate in nojournal mode Date: Wed, 29 May 2019 20:00:01 -0700 Message-Id: <20190530030540.513497665@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.291644921@linuxfoundation.org> References: <20190530030540.291644921@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Jan Kara commit 82a25b027ca48d7ef197295846b352345853dfa8 upstream. We didn't wait for outstanding direct IO during truncate in nojournal mode (as we skip orphan handling in that case). This can lead to fs corruption or stale data exposure if truncate ends up freeing blocks and these get reallocated before direct IO finishes. Fix the condition determining whether the wait is necessary. CC: stable@vger.kernel.org Fixes: 1c9114f9c0f1 ("ext4: serialize unlocked dio reads with truncate") Reviewed-by: Ira Weiny Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5624,20 +5624,17 @@ int ext4_setattr(struct dentry *dentry, goto err_out; } } - if (!shrink) + if (!shrink) { pagecache_isize_extended(inode, oldsize, inode->i_size); - - /* - * Blocks are going to be removed from the inode. Wait - * for dio in flight. Temporarily disable - * dioread_nolock to prevent livelock. - */ - if (orphan) { - if (!ext4_should_journal_data(inode)) { - inode_dio_wait(inode); - } else - ext4_wait_for_tail_page_commit(inode); + } else { + /* + * Blocks are going to be removed from the inode. Wait + * for dio in flight. + */ + inode_dio_wait(inode); } + if (orphan && ext4_should_journal_data(inode)) + ext4_wait_for_tail_page_commit(inode); down_write(&EXT4_I(inode)->i_mmap_sem); rc = ext4_break_layouts(inode);