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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2B9EC4332F for ; Mon, 7 Nov 2022 12:22:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbiKGMWN (ORCPT ); Mon, 7 Nov 2022 07:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232024AbiKGMWM (ORCPT ); Mon, 7 Nov 2022 07:22:12 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF498D62; Mon, 7 Nov 2022 04:22:11 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 11E815C0185; Mon, 7 Nov 2022 07:22:11 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 07 Nov 2022 07:22:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1667823731; x= 1667910131; bh=XvW4y+OvD3m2wCaNiof4U12PyYREji7eszG/mpI1LJg=; b=d XvlOoXdkOt9jxdzFm/kSPsHuEJuybuMgQW6wLPlscY6S5UrS/kYnkx1c6ayyTBXs /DPh6uP2/Sha6g/j3EsZpJ91X+Dy/T1PrLzLIbZ47mk4kSVQhLwZapUxiZQjBWKN ywNnsXwRBw7VbeuaOmkiz4k6RBEn8tkSvWGFrJ5qVqortCg/tvbWzVTxbg3rs8/h PoOl5Pk6XHK5Ii/LHSbMYm4b7kesM7GaNhHqDwZWST3sJ26DMyweNfjVln27Wuoc iIxauQttHip5yxyV0PCTScnfjs+bQ8BdKwYF0nDGUaZEX6I2blugluLjk+yfpcJI tmg43KmDVrYpCbjDbVSrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1667823731; x= 1667910131; bh=XvW4y+OvD3m2wCaNiof4U12PyYREji7eszG/mpI1LJg=; b=w meYzvu4h+miaHQgps7+s+bM5+JX9pnBCo32ruyLkrUlfm4LWbs4Cd76V0Qc4+l3i eELSgmiwtfaKYOtD2NcHVCG6Txxs3Vvbk9ppOSQV9ANAtHoax76mMbpq95VT/8ET onY7Jv2qXHiWzMagw7Pxt20azD8pTVbX36rcpzff4rSv4rJDtUn2S4K5nP1Qze9B Bg00/nvOamcgqcFGTveFmr3DHIfIS3bz20Rk/Tt1JYyg5HVouzKy9YsGKSuv3JJT Dky9mxtztmtqQr8nQX5gLXfyFEHMZXWQ5t4VGG5T7SdXg1rhPRfmGCSBsdreUx6q g6c6MsXrp3k4vDVgKPZLQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvdekgdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtjeenucfhrhhomhepifhrvghg ucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheqnecuggftrfgrthhtvghrnhepleekhe ejjeeiheejvdetheejveekudegueeigfefudefgfffhfefteeuieekudefnecuffhomhgr ihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehgrhgvgheskhhrohgrhhdrtghomh X-ME-Proxy: Feedback-ID: i787e41f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Nov 2022 07:22:10 -0500 (EST) Date: Mon, 7 Nov 2022 13:22:07 +0100 From: Greg KH To: fdmanana@kernel.org Cc: linux-btrfs@vger.kernel.org, stable@vger.kernel.org, Filipe Manana , =?utf-8?B?0JzQsNGA0Log0JrQvtGA0LXQvdCx0LXRgNCz?= , David Sterba Subject: Re: [PATCH for 5.15.x] btrfs: fix lost file sync on direct IO write with nowait and dsync iocb Message-ID: References: <3046b907b319071aef61d0a1b3dfaf0f71f2c9aa.1667582440.git.fdmanana@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3046b907b319071aef61d0a1b3dfaf0f71f2c9aa.1667582440.git.fdmanana@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Mon, Nov 07, 2022 at 09:41:35AM +0000, fdmanana@kernel.org wrote: > From: Filipe Manana > > 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: Марк Коренберг > 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 > Signed-off-by: David Sterba > --- > > 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