From nobody Tue Dec 16 04:04:18 2025 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 4C30EC32771 for ; Mon, 26 Sep 2022 11:40:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238227AbiIZLkC (ORCPT ); Mon, 26 Sep 2022 07:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238254AbiIZLin (ORCPT ); Mon, 26 Sep 2022 07:38:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85CF9DF53; Mon, 26 Sep 2022 03:44:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D28DF604F5; Mon, 26 Sep 2022 10:43:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C24A7C433C1; Mon, 26 Sep 2022 10:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188983; bh=RPY5zWmkon6xdL9dtCBQBZz/2MPROkphoiQZMo9BrOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UeYcUcJhh43DS02EyOmrDdV2ltIIaF9HpMKr+CatEu+JVD5PEZceNoNC19jn7NRSF LrbCAu6xjB1//jwf1Fk5YSWTQyYBQj22U/0rr+B/9oLKoEbu9tVO7uHIYWaRMOKpuP UtFp0dyEGay1N81e78+TIN18F73VkV9Ocsx4HsOg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 5.19 008/207] smb3: Move the flush out of smb2_copychunk_range() into its callers Date: Mon, 26 Sep 2022 12:09:57 +0200 Message-Id: <20220926100806.856190602@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: David Howells [ Upstream commit c3a72bb213209adfe981a4a92ea5746a778323e4 ] Move the flush out of smb2_copychunk_range() into its callers. This will allow the pagecache to be invalidated between the flush and the operation in smb3_collapse_range() and smb3_insert_range(). Signed-off-by: David Howells cc: Ronnie Sahlberg Signed-off-by: Steve French Stable-dep-of: fa30a81f255a ("smb3: fix temporary data corruption in collap= se range") Signed-off-by: Sasha Levin --- fs/cifs/cifsfs.c | 2 ++ fs/cifs/smb2ops.c | 20 ++++++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 8f2e003e0590..2b51f0cbf4d2 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1203,6 +1203,8 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, =20 cifs_dbg(FYI, "copychunk range\n"); =20 + filemap_write_and_wait(src_inode->i_mapping); + if (!src_file->private_data || !dst_file->private_data) { rc =3D -EBADF; cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index e8a8daa82ed7..ef8cb7fbabeb 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1886,17 +1886,8 @@ smb2_copychunk_range(const unsigned int xid, int chunks_copied =3D 0; bool chunk_sizes_updated =3D false; ssize_t bytes_written, total_bytes_written =3D 0; - struct inode *inode; =20 pcchunk =3D kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); - - /* - * We need to flush all unwritten data before we can send the - * copychunk ioctl to the server. - */ - inode =3D d_inode(trgtfile->dentry); - filemap_write_and_wait(inode->i_mapping); - if (pcchunk =3D=3D NULL) return -ENOMEM; =20 @@ -3977,6 +3968,8 @@ static long smb3_collapse_range(struct file *file, st= ruct cifs_tcon *tcon, goto out; } =20 + filemap_write_and_wait(inode->i_mapping); + rc =3D smb2_copychunk_range(xid, cfile, cfile, off + len, i_size_read(inode) - off - len, off); if (rc < 0) @@ -4004,18 +3997,21 @@ static long smb3_insert_range(struct file *file, st= ruct cifs_tcon *tcon, int rc; unsigned int xid; struct cifsFileInfo *cfile =3D file->private_data; + struct inode *inode =3D file_inode(file); __le64 eof; __u64 count; =20 xid =3D get_xid(); =20 - if (off >=3D i_size_read(file->f_inode)) { + if (off >=3D i_size_read(inode)) { rc =3D -EINVAL; goto out; } =20 - count =3D i_size_read(file->f_inode) - off; - eof =3D cpu_to_le64(i_size_read(file->f_inode) + len); + count =3D i_size_read(inode) - off; + eof =3D cpu_to_le64(i_size_read(inode) + len); + + filemap_write_and_wait(inode->i_mapping); =20 rc =3D SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, &eof); --=20 2.35.1