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 98C98ECE582 for ; Tue, 10 Sep 2024 09:48:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12BE68D004F; Tue, 10 Sep 2024 05:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DD3E8D0002; Tue, 10 Sep 2024 05:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E97C68D004F; Tue, 10 Sep 2024 05:48:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CC0AA8D0002 for ; Tue, 10 Sep 2024 05:48:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 74CDF12098B for ; Tue, 10 Sep 2024 09:48:25 +0000 (UTC) X-FDA: 82548353370.02.48C47F4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id AAA94C0003 for ; Tue, 10 Sep 2024 09:48:23 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=Zd5EB+Ad; spf=pass (imf10.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=1725961652; 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=zx3hKzd4q25RExXuZwpgGHh7KODueeIwVyn+bKxgpdI=; b=2rzHt/CNVlQyMZtA1a5amrAp1x2G9DrbIv+19MYscrn0fzWqhDqZbpzmTCev8+iKP+hePb YJH00Oy3+RJjH0P0pin+4tHIDJQev+dYc3qVUQ9l2lg1zgz+RCfC8yEUrauk6N+qlzztiP YKYZbjqWRx9/DEnOWXqvCZn0WRE8Z+0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=Zd5EB+Ad; spf=pass (imf10.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725961652; a=rsa-sha256; cv=none; b=4cKbL+1QOgPS5kLa+tjUI+jX83SJwsEnioSRVe/j2mKe2VWN4ekGRT8zZ/Fea+VxQLCTdO 4EXC6FVviXI09Ou8SGMTmn0i82ie+2+9iqPw/JAUQQc1266r+tiszATX47ZZHZOoRJsLBQ 2Y+lXuAVefhfnCMfbL1FyGVKoPGXghQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5315E5C063C; Tue, 10 Sep 2024 09:48:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00D3AC4CEC3; Tue, 10 Sep 2024 09:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725961702; bh=lE1oT+5iF23iWkrP70v4jhMMFk1xlq9XOb4tqwTficM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zd5EB+AdnwX73g+zjq0CRV+4Pc2/EeMXqioocaSUyuO0ziV9ftFPF/xH3VUcV2vzW P8I6N/96YH/vKjusl3gkFlr1LqfUzuIvzn5UNL+Yyux2AQ/gxCR5ItB7ivgc9pW7xm DmQqA7eZGZy4vAnny66fBb+Pg9+U6epVeuXDLu6I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Howells , Steve French , Zhang Xiaoxu , Pavel Shilovsky , Paulo Alcantara , Shyam Prasad N , Rohith Surabattula , Jeff Layton , linux-cifs@vger.kernel.org, linux-mm@kvack.org, Sasha Levin Subject: [PATCH 6.10 159/375] cifs: Fix FALLOC_FL_ZERO_RANGE to preflush buffered part of target region Date: Tue, 10 Sep 2024 11:29:16 +0200 Message-ID: <20240910092627.818785133@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092622.245959861@linuxfoundation.org> References: <20240910092622.245959861@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: AAA94C0003 X-Stat-Signature: qr785g8wzp8g64csudikaabsd9tm8o3m X-HE-Tag: 1725961703-367174 X-HE-Meta: U2FsdGVkX1+O5LcMThxgM6FlpMEwUDJYY/tKRO0wU2P58Ld0SFIKLrN4l0S2n7iRNRrTp8rjyp+AiWtNfyOgkE+8vOlrfMiqrJulJlrt65GdXr2Ml0aVIIvsjkmWMEwVfZLglkFcJX5mT9XYLvswCshPDUXXD8U04di0bwlHLulIbNOivBL5r5XxrYDCF7bu52GmNwIdhCvFKXpx5fkdqZK8wFAiY4BcH/bVPxGQZE1pUJkrqoifnnanga8Rb3zX1dCOncJjp2ENuEmsa4gJpkEH+dLfRS6RIuhbiR0CDLKaXyeX0s9l99eQ3KXdM9H1Q68ZwWcpQAW762dBNi4uMH2HK0Hb/7aR1ZtOxpB7CABW7HEaRmaF89QTnJPICDWjsndnTenBF6mtt4v+3sXq5UXA+MlY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BFJOhoA5xPlOgCA39EvquaU0TbsdIImevuDXDCI6PL/RqVR9DXtmLJ4VZiLOqzDvarQVCau0ZCf+8rw6n+adNiw== 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.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Howells [ Upstream commit 91d1dfae464987aaf6c79ff51d8674880fb3be77 ] Under certain conditions, the range to be cleared by FALLOC_FL_ZERO_RANGE may only be buffered locally and not yet have been flushed to the server. For example: xfs_io -f -t -c "pwrite -S 0x41 0 4k" \ -c "pwrite -S 0x42 4k 4k" \ -c "fzero 0 4k" \ -c "pread -v 0 8k" /xfstest.test/foo will write two 4KiB blocks of data, which get buffered in the pagecache, and then fallocate() is used to clear the first 4KiB block on the server - but we don't flush the data first, which means the EOF position on the server is wrong, and so the FSCTL_SET_ZERO_DATA RPC fails (and xfs_io ignores the error), but then when we try to read it, we see the old data. Fix this by preflushing any part of the target region that above the server's idea of the EOF position to force the server to update its EOF position. Note, however, that we don't want to simply expand the file by moving the EOF before doing the FSCTL_SET_ZERO_DATA[*] because someone else might see the zeroed region or if the RPC fails we then have to try to clean it up or risk getting corruption. [*] And we have to move the EOF first otherwise FSCTL_SET_ZERO_DATA won't do what we want. This fixes the generic/008 xfstest. [!] Note: A better way to do this might be to split the operation into two parts: we only do FSCTL_SET_ZERO_DATA for the part of the range below the server's EOF and then, if that worked, invalidate the buffered pages for the part above the range. Fixes: 6b69040247e1 ("cifs/smb3: Fix data inconsistent when zero file range") Signed-off-by: David Howells cc: Steve French cc: Zhang Xiaoxu cc: Pavel Shilovsky cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/smb/client/smb2ops.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 42352f70b01c..1d6e8eacdd74 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3219,13 +3219,15 @@ static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon, } static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, - loff_t offset, loff_t len, bool keep_size) + unsigned long long offset, unsigned long long len, + bool keep_size) { struct cifs_ses *ses = tcon->ses; struct inode *inode = file_inode(file); struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *cfile = file->private_data; - unsigned long long new_size; + struct netfs_inode *ictx = netfs_inode(inode); + unsigned long long i_size, new_size, remote_size; long rc; unsigned int xid; @@ -3237,6 +3239,16 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, inode_lock(inode); filemap_invalidate_lock(inode->i_mapping); + i_size = i_size_read(inode); + remote_size = ictx->remote_i_size; + if (offset + len >= remote_size && offset < i_size) { + unsigned long long top = umin(offset + len, i_size); + + rc = filemap_write_and_wait_range(inode->i_mapping, offset, top - 1); + if (rc < 0) + goto zero_range_exit; + } + /* * We zero the range through ioctl, so we need remove the page caches * first, otherwise the data may be inconsistent with the server. -- 2.43.0