Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2339492ybz; Thu, 23 Apr 2020 16:19:13 -0700 (PDT) X-Google-Smtp-Source: APiQypIDTPwxwduabQZ9nZj8vOsa2OSSvCDRf3VQKb9WGsbuv26H5EzciVgTr5ZqenL2mA64dqif X-Received: by 2002:a17:906:2b89:: with SMTP id m9mr4573416ejg.302.1587683952893; Thu, 23 Apr 2020 16:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683952; cv=none; d=google.com; s=arc-20160816; b=LPZQxlg2sT/WJDTQftuwUg66FecY1fgRw0a8QWfV+tgqkWBPhYyoTZSHpl1nZJRmGV AoEVw8wQyObM9UhhK1M3ob8nREY2HQtt0/zuPGPT5deAKXufN1BgZI1K1jVlkaXjzNNW YJGMOCF2/kjGv58nbeyGcuY/dPdSj0vynpUckO0JuF5bTyjjFGOb5a4/nQpB06XMXcdh HXcepPxIqjaywOClTlNWboxN+x/dp/X8TVhErlmQZRv32LB3T3NMw2Zsh9b5oFA24Vzd GL7HAkVK3g7BKOxm+pCfWMHZ3sF4mZou7KJdu9ZLHMoNvgQN9Zu7fK1dy3vHKQAzayWU 06+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=WeCuTmPJ81D0UHyEgGvvBNlCxCmqe0jPsMBySJ/FdO8=; b=HfWJ2ebqbA7lb8Mxt96zL9pkMIbgEX7z8nPeWoVNpftwhQOLNQsHhnokxOh4TUpeE/ rzZ+iN3b2EQCkghHU2JOe2AiojSSTa34hpl6jP2ZPdWLsOBRh1RQqEqDJcECVHO5BE/3 RswU98bRw2Vzw2p76Ads0fSbXDWGYyO8SA1qarBJ6Zi9rLD35qUpMPoIbidWpMg31zUP qX/vOIroKzHUXv1ICmr67UeZ/EDcpxOEviKB/GiR/zhtzy7flyDqOOUMYVgMmgBI6htn iK9nlQSRTDnVTJKjmJUwsuZ8VMlUFrRgR1DYKH6/0B+Mr3YVvqhJr+8VgIrAmUefV1jT 4xkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o12si2101615edv.257.2020.04.23.16.18.49; Thu, 23 Apr 2020 16:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgDWXGn (ORCPT + 99 others); Thu, 23 Apr 2020 19:06:43 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:48164 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727968AbgDWXG1 (ORCPT ); Thu, 23 Apr 2020 19:06:27 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvI-0004Zf-Ev; Fri, 24 Apr 2020 00:06:24 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvH-00E6fK-Rr; Fri, 24 Apr 2020 00:06:23 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Jan Kara" , "Theodore Ts'o" Date: Fri, 24 Apr 2020 00:04:02 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 015/245] ext4: move unlocked dio protection from ext4_alloc_file_blocks() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit 17048e8a083fec7ad841d88ef0812707fbc7e39f upstream. Currently ext4_alloc_file_blocks() was handling protection against unlocked DIO. However we now need to sometimes call it under i_mmap_sem and sometimes not and DIO protection ranks above it (although strictly speaking this cannot currently create any deadlocks). Also ext4_zero_range() was actually getting & releasing unlocked DIO protection twice in some cases. Luckily it didn't introduce any real bug but it was a land mine waiting to be stepped on. So move DIO protection out from ext4_alloc_file_blocks() into the two callsites. Signed-off-by: Jan Kara Signed-off-by: Theodore Ts'o Signed-off-by: Ben Hutchings --- fs/ext4/extents.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4707,10 +4707,6 @@ static int ext4_alloc_file_blocks(struct if (len <= EXT_UNWRITTEN_MAX_LEN) flags |= EXT4_GET_BLOCKS_NO_NORMALIZE; - /* Wait all existing dio workers, newcomers will block on i_mutex */ - ext4_inode_block_unlocked_dio(inode); - inode_dio_wait(inode); - /* * credits to insert 1 extent into extent tree */ @@ -4760,8 +4756,6 @@ retry: goto retry; } - ext4_inode_resume_unlocked_dio(inode); - return ret > 0 ? ret2 : ret; } @@ -4836,6 +4830,10 @@ static long ext4_zero_range(struct file if (mode & FALLOC_FL_KEEP_SIZE) flags |= EXT4_GET_BLOCKS_KEEP_SIZE; + /* Wait all existing dio workers, newcomers will block on i_mutex */ + ext4_inode_block_unlocked_dio(inode); + inode_dio_wait(inode); + /* Preallocate the range including the unaligned edges */ if (partial_begin || partial_end) { ret = ext4_alloc_file_blocks(file, @@ -4844,7 +4842,7 @@ static long ext4_zero_range(struct file round_down(offset, 1 << blkbits)) >> blkbits, new_size, flags, mode); if (ret) - goto out_mutex; + goto out_dio; } @@ -4853,10 +4851,6 @@ static long ext4_zero_range(struct file flags |= (EXT4_GET_BLOCKS_CONVERT_UNWRITTEN | EXT4_EX_NOCACHE); - /* Wait all existing dio workers, newcomers will block on i_mutex */ - ext4_inode_block_unlocked_dio(inode); - inode_dio_wait(inode); - /* * Prevent page faults from reinstantiating pages we have * released from page cache. @@ -4985,8 +4979,13 @@ long ext4_fallocate(struct file *file, i goto out; } + /* Wait all existing dio workers, newcomers will block on i_mutex */ + ext4_inode_block_unlocked_dio(inode); + inode_dio_wait(inode); + ret = ext4_alloc_file_blocks(file, lblk, max_blocks, new_size, flags, mode); + ext4_inode_resume_unlocked_dio(inode); if (ret) goto out;