Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1688539iob; Thu, 5 May 2022 06:32:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy49/p7LxFvIb6F1/gdSBcqKt80V+s4IRdOk37JCdSkqmRgWPCn4hH+pppB7WOFnGemTQj6 X-Received: by 2002:a17:907:7205:b0:6f5:3f1:927e with SMTP id dr5-20020a170907720500b006f503f1927emr1567480ejc.739.1651757530379; Thu, 05 May 2022 06:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651757530; cv=none; d=google.com; s=arc-20160816; b=x4glyporhHuXVXza/LCKjJ6aJ8WaXYwnMSbRdQ2VygHhdodN3/uuxC2sjEqe5lhHFQ ZTlMnqHKAuAhqYFAxN0KLFZh7YtkN4c177/w7KOuBF47jPkXnxHqOul1wYkUeyD+8sYG Yg3fXgDUwoS4nWwG5uxY5O1z2e5gHU4Vc4hfDu3i8Vv+f5CyJvkvb0v0zzm/vYDWhXBS HETpTd0Vply+lvhUNHlpkTNiy4M0g1VfuJQuVjmjKflky/Ztp8EBY84s0dAvQh1iTtaU 8clqq8UhvTWFGe64IgMD8PxK9fMfxxrCFW2+rBFkGYCdR+cuzPBvaOF0QMYxSnNknyn9 f5Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Iu8w7kFfrRpMbLRlNXLcp3/ZOJjIr2yuN28Orr9lf3U=; b=TSsYtYvPSqBQ9Raiu0aSoagCzH/7R++nT2eIwVpuP8/DSB/UAn2q4PfSUotlEu1FiM 8UDOj6il7M8qUbG8nOkQigrW2mck20Ao2iyR0SwSGJdhiVIKV3HpKxXXoU96pwYAj/eN NPwMhuEt1tlUpvQGBAICPIOEvKavBfiSQVtdo8lILoRkXuRIAwG4e9NWeSw9KoZ246dX uRLooPrPiMwTixZB/bNhRB/Kur060jvfHEwIYL45K4OAAwF7BM/B772VmEd2dDdP58Vt DG4ILlcx46T8bK6dIhGjWyMuMSF1Eq87eDqd9ZAV48cMUA1KjcQtUbC6fGOfm19Q+BdK MSgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TNVAOVbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb7-20020a170907924700b006df76385d22si2029764ejb.450.2022.05.05.06.31.45; Thu, 05 May 2022 06:32:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TNVAOVbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359420AbiEDRoQ (ORCPT + 99 others); Wed, 4 May 2022 13:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355953AbiEDRI5 (ORCPT ); Wed, 4 May 2022 13:08:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5898E49F97; Wed, 4 May 2022 09:54: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 ams.source.kernel.org (Postfix) with ESMTPS id DD9BCB82792; Wed, 4 May 2022 16:54:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9151DC385A5; Wed, 4 May 2022 16:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683282; bh=Gzzt0waAa8K+0dMB3qQiJ0MfV9GnsZLefeXzHn4bzdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TNVAOVbbIfHFdXpklG10n0aJObAaGZehHqDQP+3rTVeZBd1aebXhOFC1JtimsDitQ kul06CfHTPoacbiDlQydvAxAzustIO17ItYnixtTnJX0UG+IWY+5Q7Mv3d0H8Ufwef tZCL59mwNkiVZI7P3qiz7Hk3doZuF1w/om/B5T68= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoli Feng , Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 5.15 135/177] cifs: destage any unwritten data to the server before calling copychunk_write Date: Wed, 4 May 2022 18:45:28 +0200 Message-Id: <20220504153105.277538828@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ronnie Sahlberg [ Upstream commit f5d0f921ea362636e4a2efb7c38d1ead373a8700 ] because the copychunk_write might cover a region of the file that has not yet been sent to the server and thus fail. A simple way to reproduce this is: truncate -s 0 /mnt/testfile; strace -f -o x -ttT xfs_io -i -f -c 'pwrite 0k 128k' -c 'fcollapse 16k 24k' /mnt/testfile the issue is that the 'pwrite 0k 128k' becomes rearranged on the wire with the 'fcollapse 16k 24k' due to write-back caching. fcollapse is implemented in cifs.ko as a SMB2 IOCTL(COPYCHUNK_WRITE) call and it will fail serverside since the file is still 0b in size serverside until the writes have been destaged. To avoid this we must ensure that we destage any unwritten data to the server before calling COPYCHUNK_WRITE. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1997373 Reported-by: Xiaoli Feng Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/smb2ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index db3ead52ec7c..0c1af2dd9069 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1849,9 +1849,17 @@ smb2_copychunk_range(const unsigned int xid, int chunks_copied = 0; bool chunk_sizes_updated = false; ssize_t bytes_written, total_bytes_written = 0; + struct inode *inode; pcchunk = 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 = d_inode(trgtfile->dentry); + filemap_write_and_wait(inode->i_mapping); + if (pcchunk == NULL) return -ENOMEM; -- 2.35.1