public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org,
	"Filipe Manana" <fdmanana@suse.com>,
	"Марк Коренберг" <socketpair@gmail.com>,
	"David Sterba" <dsterba@suse.com>
Subject: Re: [PATCH for 5.15.x] btrfs: fix lost file sync on direct IO write with nowait and dsync iocb
Date: Mon, 7 Nov 2022 13:22:07 +0100	[thread overview]
Message-ID: <Y2j4bx15xkJx42Kh@kroah.com> (raw)
In-Reply-To: <3046b907b319071aef61d0a1b3dfaf0f71f2c9aa.1667582440.git.fdmanana@suse.com>

On Mon, Nov 07, 2022 at 09:41:35AM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> commit 8184620ae21213d51eaf2e0bd4186baacb928172 upstream.
> 
> When doing a direct IO write using a iocb with nowait and dsync set, we
> end up not syncing the file once the write completes.
> 
> This is because we tell iomap to not call generic_write_sync(), which
> would result in calling btrfs_sync_file(), in order to avoid a deadlock
> since iomap can call it while we are holding the inode's lock and
> btrfs_sync_file() needs to acquire the inode's lock. The deadlock happens
> only if the write happens synchronously, when iomap_dio_rw() calls
> iomap_dio_complete() before it returns. Instead we do the sync ourselves
> at btrfs_do_write_iter().
> 
> For a nowait write however we can end up not doing the sync ourselves at
> at btrfs_do_write_iter() because the write could have been queued, and
> therefore we get -EIOCBQUEUED returned from iomap in such case. That makes
> us skip the sync call at btrfs_do_write_iter(), as we don't do it for
> any error returned from btrfs_direct_write(). We can't simply do the call
> even if -EIOCBQUEUED is returned, since that would block the task waiting
> for IO, both for the data since there are bios still in progress as well
> as potentially blocking when joining a log transaction and when syncing
> the log (writing log trees, super blocks, etc).
> 
> So let iomap do the sync call itself and in order to avoid deadlocks for
> the case of synchronous writes (without nowait), use __iomap_dio_rw() and
> have ourselves call iomap_dio_complete() after unlocking the inode.
> 
> A test case will later be sent for fstests, after this is fixed in Linus'
> tree.
> 
> Fixes: 51bd9563b678 ("btrfs: fix deadlock due to page faults during direct IO reads and writes")
> Reported-by: Марк Коренберг <socketpair@gmail.com>
> Link: https://lore.kernel.org/linux-btrfs/CAEmTpZGRKbzc16fWPvxbr6AfFsQoLmz-Lcg-7OgJOZDboJ+SGQ@mail.gmail.com/
> CC: stable@vger.kernel.org # 6.0+
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
> 
> The commit in the Fixes tag was backported to 5.15 stable releases, so
> this patch is meant for 5.15.x and was tested on top of 5.15.77.

Now queued up, thanks.

greg k-h

      reply	other threads:[~2022-11-07 12:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07  9:41 [PATCH for 5.15.x] btrfs: fix lost file sync on direct IO write with nowait and dsync iocb fdmanana
2022-11-07 12:22 ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2j4bx15xkJx42Kh@kroah.com \
    --to=greg@kroah.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@kernel.org \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=socketpair@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox