Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp614178ybg; Wed, 23 Oct 2019 03:13:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoC+yT4gNCZYhpJiAcbSNvdTEcNEax9cfuPpAaWLreoxvqGt4+3ZriGuyApr7/JwDfrkyz X-Received: by 2002:a50:ac3c:: with SMTP id v57mr7122772edc.300.1571825633459; Wed, 23 Oct 2019 03:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571825633; cv=none; d=google.com; s=arc-20160816; b=kWYrJvqj0LW7bo213pta2i81TFaeHs2QkVOLsDI1wNPFdZdu6KiK7IG/UnLd+4nQP7 O5DwDsguLoF+Jw8JXoSkVlXD7CoagqSXaPekQ/MJpx05CHPgClQAlICUohcqHLewmDHy U7k3YWSZTzcpmhlwU1g6PqQtm7MIXWacRCupR5ys8o73CcxJUPo7CxVB3Ne6C9i3WKht HJpRdaqq4R32ci+P/tP6VTHrcwILpkaWZ9lEWDuNOXtO2dpGo5ebTWc6t8jlLdyKVoAh eWyRUbvatsQOx4SC4k6GShWUKd6oNDeLAA+DRql5bH/G+0qIxFxwTqfSFC7CTgWlfX7H j/lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=u/JJfj5UCucEgZ1HT5YmSO7z7+4ytGahSLO8+3xBQlI=; b=oEvNwzoTadlBPmmWI4wIDvFDSXxWhDqukb2tVfX+B461b5ZRHUiDRGyYjIDRkumMb0 WKqgfCma572tKbYNcnXEX/S8hiMo4UAgB1oH5AL6Y2i9IWjsK5rv0j9pSnyX5bspeTQN 21mpxHQw/+xEz355OKBGs6pId6U6gDva8ymcOBMIWACl07OAt+ydva/0B9f/fksgGVSh Nc6voqF+X/6yvDvRESoY2yh09v28G4HjF7acBXMXM2q8jmUcvQQ46hTXS1LpPwXekESJ 3ob9v5GjB/dX3BOcfJqXsEwy/iE991Jtprn7HnH2TmXOyfGKuYdTvpWQSk8enawesIlQ N8/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=zTe9+cj7; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 s52si9118203edd.65.2019.10.23.03.13.27; Wed, 23 Oct 2019 03:13:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=zTe9+cj7; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391065AbfJWKLq (ORCPT + 99 others); Wed, 23 Oct 2019 06:11:46 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39565 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390980AbfJWKLq (ORCPT ); Wed, 23 Oct 2019 06:11:46 -0400 Received: by mail-pf1-f195.google.com with SMTP id v4so12630114pff.6 for ; Wed, 23 Oct 2019 03:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mbobrowski-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=u/JJfj5UCucEgZ1HT5YmSO7z7+4ytGahSLO8+3xBQlI=; b=zTe9+cj7KqcrGF1xNdawr9cqizWjoo62iqFQs0WN6/IQxvRPq1feLRdoHi60og98C5 JYmt134fHesenLSvKkhEQfAfF2915td09xSrxFZiIyvAAtkgjrP59uWfgeObFhUgr47P 0JPpByTtA4seUmFVc+gEWC0QELydJWr4f3KbE2IvU3ngTlyF8amHLNCK+k/LN3eS/bjQ 1YMnglz634vVJShIWeW6flse75fXhMc2AJ95j/TbUAqxr8Vic9FlplHucpPpLqgxxaba kaN/6WVuKU5xQHAd7IJrctxbPsHaEKmbWqmwWnOqQ0vArjT6Ww2FXLD3mHG9Jsu6CLt7 k1yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=u/JJfj5UCucEgZ1HT5YmSO7z7+4ytGahSLO8+3xBQlI=; b=ZuZh6dh2rLfBq520aIqI/b7jPLgKn91Ng1yec3LYHzKTX+w7mnAJ5qPngmC5UpQs0v uSRRfzLVQNh1Hyui0pN862auQKPz5bEOO84QHOLVYBWViDDXZL9PMAxFgqk/IeGAPVpa rMb9V/NrHDLiqRWDisGupDARzmDP0zvJATGbIcKFGejUslrhIe2eCINQWK03MsSLOIXN HvoKxRzmOTULVZieU6zWSeJlG/CZLzmTu1QZanx9Op9/qYyQXgOxckyS2abpz1xKg1Jh /jfyYcoNYgeeUjr7Xd+4fPEzXvOiODV3TJz43VweuSrc/ZPAQI+c4RF6h1AkOVvnaMWB IS7w== X-Gm-Message-State: APjAAAWAneYcT4gOQ46z1qJ7frHNGsXDTYMkZHLwypW0ahV6VZhWscQp c3+vnTevJfV/XNf5tKAeEbcu X-Received: by 2002:aa7:9aa2:: with SMTP id x2mr9729165pfi.103.1571825505035; Wed, 23 Oct 2019 03:11:45 -0700 (PDT) Received: from bobrowski ([110.232.114.101]) by smtp.gmail.com with ESMTPSA id k17sm30781107pgh.30.2019.10.23.03.11.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 03:11:44 -0700 (PDT) Date: Wed, 23 Oct 2019 21:11:38 +1100 From: Matthew Bobrowski To: Jan Kara Cc: "Theodore Y. Ts'o" , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@infradead.org, david@fromorbit.com, darrick.wong@oracle.com Subject: Re: [PATCH v5 00/12] ext4: port direct I/O to iomap infrastructure Message-ID: <20191023101138.GA6725@bobrowski> References: <20191021133111.GA4675@mit.edu> <20191021194330.GJ25184@quack2.suse.cz> <20191023023519.GA16505@bobrowski> <20191023100153.GB22307@quack2.suse.cz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="jRHKVT23PllUwdXP" Content-Disposition: inline In-Reply-To: <20191023100153.GB22307@quack2.suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Oct 23, 2019 at 12:01:53PM +0200, Jan Kara wrote: > On Wed 23-10-19 13:35:19, Matthew Bobrowski wrote: > > On Mon, Oct 21, 2019 at 09:43:30PM +0200, Jan Kara wrote: > > > On Mon 21-10-19 09:31:12, Theodore Y. Ts'o wrote: > > > > Hi Matthew, thanks for your work on this patch series! > > > > > > > > I applied it against 4c3, and ran a quick test run on it, and found > > > > the following locking problem. To reproduce: > > > > > > > > kvm-xfstests -c nojournal generic/113 > > > > > > > > generic/113 [09:27:19][ 5.841937] run fstests generic/113 at 2019-10-21 09:27:19 > > > > [ 7.959477] > > > > [ 7.959798] ============================================ > > > > [ 7.960518] WARNING: possible recursive locking detected > > > > [ 7.961225] 5.4.0-rc3-xfstests-00012-g7fe6ea084e48 #1238 Not tainted > > > > [ 7.961991] -------------------------------------------- > > > > [ 7.962569] aio-stress/1516 is trying to acquire lock: > > > > [ 7.963129] ffff9fd4791148c8 (&sb->s_type->i_mutex_key#12){++++}, at: __generic_file_fsync+0x3e/0xb0 > > > > [ 7.964109] > > > > [ 7.964109] but task is already holding lock: > > > > [ 7.964740] ffff9fd4791148c8 (&sb->s_type->i_mutex_key#12){++++}, at: ext4_dio_write_iter+0x15b/0x430 > > > > > > This is going to be a tricky one. With iomap, the inode locking is handled > > > by the filesystem while calling generic_write_sync() is done by > > > iomap_dio_rw(). I would really prefer to avoid tweaking iomap_dio_rw() not > > > to call generic_write_sync(). So we need to remove inode_lock from > > > __generic_file_fsync() (used from ext4_sync_file()). This locking is mostly > > > for legacy purposes and we don't need this in ext4 AFAICT - but removing > > > the lock from __generic_file_fsync() would mean auditing all legacy > > > filesystems that use this to make sure flushing inode & its metadata buffer > > > list while it is possibly changing cannot result in something unexpected. I > > > don't want to clutter this series with it so we are left with > > > reimplementing __generic_file_fsync() inside ext4 without inode_lock. Not > > > too bad but not great either. Thoughts? > > > > So, I just looked at this on my lunch break and I think the simplest > > approach would be to just transfer the necessary chunks of code from > > within __generic_file_fsync() into ext4_sync_file() for !journal cases, > > minus the inode lock, and minus calling into __generic_file_fsync(). I > > don't forsee this causing any issues, but feel free to correct me if I'm > > wrong. > > Yes, that's what I'd suggest as well. In fact when doing that you can share > file_write_and_wait_range() call with the one already in ext4_sync_file() > use for other cases. Similarly with file_check_and_advance_wb_err(). So the > copied bit will be really only: > > ret = sync_mapping_buffers(inode->i_mapping); > if (!(inode->i_state & I_DIRTY_ALL)) > goto out; > if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) > goto out; > > err = sync_inode_metadata(inode, 1); > if (ret == 0) > ret = err; > > > If this is deemed to be OK, then I will go ahead and include this as a > > separate patch in my series. > > Yes, please. Heh! I just finished writing and testing it and exactly what I've done (attached). Anyway, I will include it in v6. :) ---- --jRHKVT23PllUwdXP Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-ext4-update-ext4_sync_file-to-not-use-__generic_file.patch" From 4c82edb34324f91788c941956954d4e7e1886c2c Mon Sep 17 00:00:00 2001 From: Matthew Bobrowski Date: Wed, 23 Oct 2019 17:43:23 +1100 Subject: [PATCH 1/2] ext4: update ext4_sync_file() to not use __generic_file_fsync() When the filesystem is created without a journal, we eventually call into __generic_file_fsync() in order to write out all the modified in-core data to the permanent storage device. This function happens to try and obtain an inode_lock() while synchronizing the files buffer and it's associated metadata. Generally, this is fine, however it becomes a problem when there is higher level code that has already obtained an inode_lock() as this leads to a recursive lock situation. This case is especially true when porting across direct I/O to iomap infrastructure as we obtain an inode_lock() early on in the I/O within ext4_dio_write_iter() and hold it until the I/O has been completed. Consequently, to not run into this specific issue, we move away from calling into __generic_file_fsync() and perform the necessary synchronization tasks within ext4_sync_file(). Signed-off-by: Matthew Bobrowski --- fs/ext4/fsync.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index 5508baa11bb6..9e11868e82f9 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c @@ -116,8 +116,21 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) goto out; } + ret = file_write_and_wait_range(file, start, end); + if (ret) + return ret; + if (!journal) { - ret = __generic_file_fsync(file, start, end, datasync); + ret = sync_mapping_buffers(inode->i_mapping); + if (!(inode->i_state & I_DIRTY_ALL)) + goto out; + if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) + goto out; + + err = sync_inode_metadata(inode, 1); + if (!ret) + ret = err; + if (!ret) ret = ext4_sync_parent(inode); if (test_opt(inode->i_sb, BARRIER)) @@ -125,9 +138,6 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync) goto out; } - ret = file_write_and_wait_range(file, start, end); - if (ret) - return ret; /* * data=writeback,ordered: * The caller's filemap_fdatawrite()/wait will sync the data. -- 2.20.1 --jRHKVT23PllUwdXP--