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 AD16DECE582 for ; Tue, 10 Sep 2024 10:08:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EE3B8D0052; Tue, 10 Sep 2024 06:08:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 278258D0002; Tue, 10 Sep 2024 06:08:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 118498D0052; Tue, 10 Sep 2024 06:08:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E40708D0002 for ; Tue, 10 Sep 2024 06:08:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 57CE381436 for ; Tue, 10 Sep 2024 10:08:40 +0000 (UTC) X-FDA: 82548404400.15.5F2B268 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf04.hostedemail.com (Postfix) with ESMTP id A12AF4000D for ; Tue, 10 Sep 2024 10:08:37 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b="MY/puQK8"; spf=pass (imf04.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 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=1725962866; 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=9niOHhKnbRBROdDik1sV4vnPUrODpC97H0rAGplMiSE=; b=d8HGtyfTbesC/ZUNIXTo2fo7IeIvr4d/OYF3a5tr/5IYpWqUhbV2sE/zuiqa8Lx/iaPWZr m+K4fh6eYZQIsbnN8lkNPlvKZRZWF51KJVBtqaihPD11kCg/xnf8NAKmwuaSt0nO+UjlNb ZsokvSUoswB4yyilpc40iCg/xPSax3U= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b="MY/puQK8"; spf=pass (imf04.hostedemail.com: domain of gregkh@linuxfoundation.org designates 147.75.193.91 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=1725962866; a=rsa-sha256; cv=none; b=U8IVPTdKOxlc3roEAlT9voiYImkzNs9032eip1CnTwv+ETPjKOI6Kezb45lwDqoOquB2KN 6qC4w5mEmD/eBw/WXV5AQBaNEhlsBfwPYKSRGl4fgJ/fZDTIDszp9yNMvSdQcEDoR5jT0/ KMPUvzzt+CDdGFaV3vNEiF0uQhFbTTA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6157CA4451D; Tue, 10 Sep 2024 10:08:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B14FDC4CEC3; Tue, 10 Sep 2024 10:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725962916; bh=tAE2+XoFiNgHteoUTtc7fp/JUHaErHH1wQ23bYs4q3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MY/puQK89+QMB1+LH/TUoH7Dk60iaMaA8Mb70UXcf2I0RW7J6jsDWG9Awune8KooM dHFiX/xgoy/5exc+/gtnpgR9T2RZ+JWoaFdt3HGUMqX7yXv4kMUgK9XENqR01ADsJO 5KD3xS3tl9YF/WZo9hUCY58BOgGBfH/6kejIJgwk= 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.1 073/192] cifs: Fix FALLOC_FL_ZERO_RANGE to preflush buffered part of target region Date: Tue, 10 Sep 2024 11:31:37 +0200 Message-ID: <20240910092601.000270539@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092557.876094467@linuxfoundation.org> References: <20240910092557.876094467@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: A12AF4000D X-Stat-Signature: r8rry65kyxns1d4tpoys6m4n5ws8diwg X-HE-Tag: 1725962917-929675 X-HE-Meta: U2FsdGVkX19oTyVLVV1M0CvUo6B4nkxS/QmXYOgTRxk+3w2Nj0geWPIaMvncJVilUO08MOIxyIqiRiCiBCK2L2L1G1LAZy3byjqK5jct2r74OFZxCvPRvPetBlliKu+lWOaUXKT3A2hk8lRcTLyiMjSBb9xU39DyUR+xI/1DxELh6PcNt0dcBqcWERwanBb3vkr8JLg+hrQGLc+MnItpsYzne50hbWe1RMW2Jc2VQcGA1xNRG8iipnjbYATnjUW/APobTDgumm1Xrru+pW+p1Vpqty6QJ3N+raB+g5BtnLRpoPy3bdT3O54kCmMPzA0QtH/U/nonB0vz4ZjI4ecTLkTOXd4yHlg1mPICAyM85NTuqCxdE27XbUX0mqn80KykWWV1WRcTKpN6IFCwpvqeEq6soaPFnBRO21T2j3rD49FlZj6HjlXaxDZTLV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g/6dpwFGcBWPRS6Iu8N64lqlv4pJ5f8DZw3wThcuHQRkuqUJxkj2Ns= 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.1-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 2291081653a8..5e9478f31d47 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3443,13 +3443,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; __le64 eof; @@ -3462,6 +3464,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