From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43C22C28CC0 for ; Thu, 30 May 2019 03:13:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 146F624526 for ; Thu, 30 May 2019 03:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185983; bh=s9nAbxXhx0OfYa9n7VHi49AdWW/fvxIXefqFeauvzgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nz9BfosucGHyA4zNj1aVgyfFBn5EtDUATzZOU+SM9tC3FD5q7Hxp7kpFoijJe1RXO LWE0C2EW0bCoTfA15RHM3bDElFQq+lsjAJZEm7nxHcMoTCO7sImqydJBH0qS6dJnry 7gN5g12/YGdVPgrajvO5BtN8tkoV/D3q0RdAJQOo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729321AbfE3DNB (ORCPT ); Wed, 29 May 2019 23:13:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:57024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729315AbfE3DNB (ORCPT ); Wed, 29 May 2019 23:13:01 -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 662E521BE2; Thu, 30 May 2019 03:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185980; bh=s9nAbxXhx0OfYa9n7VHi49AdWW/fvxIXefqFeauvzgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vK+BBf6RojGeoUdqwF6Sjuqx+yCu3y3LbmjmUdGKIjoG84jIFflzH5ETT98HVNbTn /yTgeM029q3qV81I9GBwehmzhLN02TZXvyLQzd4ywtjqzhaIZULbPgkDNJPjjK7uiA oeqrsSXxBr6APYqhjf7M62gcraqiJJM1Yghdpgyo= 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.0 003/346] ext4: wait for outstanding dio during truncate in nojournal mode Date: Wed, 29 May 2019 20:01:16 -0700 Message-Id: <20190530030540.580600723@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.363386121@linuxfoundation.org> References: <20190530030540.363386121@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -5632,20 +5632,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);