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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 419C2C4345F for ; Tue, 30 Apr 2024 10:51:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5AA56B0085; Tue, 30 Apr 2024 06:51:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0B676B0087; Tue, 30 Apr 2024 06:51:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF9E66B0088; Tue, 30 Apr 2024 06:51:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9601D6B0085 for ; Tue, 30 Apr 2024 06:51:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 49979A10FD for ; Tue, 30 Apr 2024 10:51:54 +0000 (UTC) X-FDA: 82065882948.20.ECF811E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id 78B521C0017 for ; Tue, 30 Apr 2024 10:51:51 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=oTgqEuHg; spf=pass (imf18.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714474311; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gRY8nx73LExEf2aHaBmW7sV9oAUrSsQuwf/TYI/drJo=; b=47izLAvv7t+P/o15JGj4Y3bhcgzIOIperrrgeeVsc8XNEDPuR4/I5FXd0NTkQ8n73TxGCW bVPXikaapY3E1/6XABnjw+IqoCibjhoJ7++W+dqf9/SdCOTRW4BAROc84F2tQski4FMNhQ veAq+j36eG9E+izxGcYZ+gh9518pAlw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714474311; a=rsa-sha256; cv=none; b=Ci1wsnvju5KnamB8YsL0kj/Xw/GeKraclRzIBh8/zsobQY4C82Rk9FCH+zUy75Dzldftre 3YS4eoROQxieJB3HqnDVrTIJuhSLfQta2Scuqi0tSlgRbwnGf2PTdkcifIzOuMGxomQVaV TljdPh7q+YJRHmHlygna19qnyCKqZDk= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=oTgqEuHg; spf=pass (imf18.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4B5EA6143F; Tue, 30 Apr 2024 10:51:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5788EC4AF18; Tue, 30 Apr 2024 10:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714474309; bh=EqxWaXJkaKi6EmeJ/uq2stp+6OiNQwCUC8ehr0Ve1Ww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oTgqEuHgqQKdUci1Z3du65415M3GJ2TVlGxYZfvpPUKLshBl6qKVOcxYk5o3+hZEe mWLr+NFj5WD7vWLX3sIjMxcZyd3TmFgb5xbQWVGrpuiABOigLaqyH3dO05hIAki7/a b0/2sOxS15AAryy15gc/F9THApVMUTySCFlDObTg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, kernel test robot , David Howells , Jeffrey Layton , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , Marc Dionne , netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, v9fs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, Christian Brauner , Sasha Levin Subject: [PATCH 6.8 119/228] netfs: Fix the pre-flush when appending to a file in writethrough mode Date: Tue, 30 Apr 2024 12:38:17 +0200 Message-ID: <20240430103107.242045835@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103103.806426847@linuxfoundation.org> References: <20240430103103.806426847@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: 1pgbnsmthzsmuizqqys4zdatj6tomkwx X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 78B521C0017 X-HE-Tag: 1714474311-477386 X-HE-Meta: U2FsdGVkX19HR2VHRLlzxpdBXbgi8kLb738vVJMn+i8Ybk6Cf5yOrk5NXaXP1PfKMyTbH9G2CtT6/QhkOXkmKmxPzhSJXkrJnfW6eJTc+FB9Eq2yXRDLJSi6lZdJXss6Of3hdpxEuyErJu95diRvO/7FFugypdgUeT79jE6L+h2iuGF2X64zSStRR4xLPPZQCdFjfbLjpIUzucmtsUULfj7Wzj+c5mtwVpl+HBXh+8BUfQuOoP71QxHM1tOqfWdOgpiLjibKkGN0+6pyiSJsRcNvmOlBS1GLOGVigopl7CW1YlYo9gekKOlHGUzd64afUJCT5x7BSAd0Pswsn+GVGL+KZWhFpzZXkzaC+SB+ZF2ZVdpOuchjhezJmqqCoK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VHrMOgc/p6R4JPi7en2p+6Gfg4azRHe34yvrRN+Blmwemb2/ugB5lf1ZNLtV0vBdr5bevDu1XmPOGBHk9wFMOva40crRpWuCIClh+5qZrK40jlExU+P1ErYKhPRQwZVAM/dwCuAfx3nw4ydIpW9qU9CPpLSQdWBudDs5RI+1xjstciXQWSAXOA4TYEkMpVbH0z5IhrOQ9lWlJOZxDNn8yYECg5U02/64/VJ624LJIEPSsXO8h3djsuTzH6DTE+DSh/RjvfKTRmYkfq6JTZVERbL1Y5B2vgaP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 6.8-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Howells [ Upstream commit c97f59e276d4e93480f29a70accbd0d7273cf3f5 ] In netfs_perform_write(), when the file is marked NETFS_ICTX_WRITETHROUGH or O_*SYNC or RWF_*SYNC was specified, write-through caching is performed on a buffered file. When setting up for write-through, we flush any conflicting writes in the region and wait for the write to complete, failing if there's a write error to return. The issue arises if we're writing at or above the EOF position because we skip the flush and - more importantly - the wait. This becomes a problem if there's a partial folio at the end of the file that is being written out and we want to make a write to it too. Both the already-running write and the write we start both want to clear the writeback mark, but whoever is second causes a warning looking something like: ------------[ cut here ]------------ R=00000012: folio 11 is not under writeback WARNING: CPU: 34 PID: 654 at fs/netfs/write_collect.c:105 ... CPU: 34 PID: 654 Comm: kworker/u386:27 Tainted: G S ... ... Workqueue: events_unbound netfs_write_collection_worker ... RIP: 0010:netfs_writeback_lookup_folio Fix this by making the flush-and-wait unconditional. It will do nothing if there are no folios in the pagecache and will return quickly if there are no folios in the region specified. Further, move the WBC attachment above the flush call as the flush is going to attach a WBC and detach it again if it is not present - and since we need one anyway we might as well share it. Fixes: 41d8e7673a77 ("netfs: Implement a write-through caching option") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202404161031.468b84f-oliver.sang@intel.com Signed-off-by: David Howells Link: https://lore.kernel.org/r/2150448.1714130115@warthog.procyon.org.uk Reviewed-by: Jeffrey Layton cc: Eric Van Hensbergen cc: Latchesar Ionkov cc: Dominique Martinet cc: Christian Schoenebeck cc: Marc Dionne cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org cc: v9fs@lists.linux.dev cc: linux-afs@lists.infradead.org cc: linux-cifs@vger.kernel.org Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/netfs/buffered_write.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index 8f13ca8fbc74d..267b622d923b1 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -172,15 +172,14 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter, if (unlikely(test_bit(NETFS_ICTX_WRITETHROUGH, &ctx->flags) || iocb->ki_flags & (IOCB_DSYNC | IOCB_SYNC)) ) { - if (pos < i_size_read(inode)) { - ret = filemap_write_and_wait_range(mapping, pos, pos + iter->count); - if (ret < 0) { - goto out; - } - } - wbc_attach_fdatawrite_inode(&wbc, mapping->host); + ret = filemap_write_and_wait_range(mapping, pos, pos + iter->count); + if (ret < 0) { + wbc_detach_inode(&wbc); + goto out; + } + wreq = netfs_begin_writethrough(iocb, iter->count); if (IS_ERR(wreq)) { wbc_detach_inode(&wbc); -- 2.43.0