Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4448113ioa; Wed, 27 Apr 2022 04:12:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNezpGG0ZKh1rCSNWV6K9OxjjIggd0BOl/is8d5llq8bOX/spcp0GCk5xt6ODDCAJpq9LV X-Received: by 2002:a17:90a:ea18:b0:1da:4630:513d with SMTP id w24-20020a17090aea1800b001da4630513dmr1524326pjy.237.1651057975331; Wed, 27 Apr 2022 04:12:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651057975; cv=none; d=google.com; s=arc-20160816; b=FkujSbb2dhQFMgTjLzGcAE2A5n2ZQM/jif1RH+2L2QF0ANDSe+/qfv8VjLpNJvV9Jx BGbcYOIuScaQLqb0HRTLA5KMcEuSVqZz7k+7vAovSgpluSlL0N4wkfsfX20avJlS6PHD N/5OGKZgeyQyzEcEJnPKJ4LlPKprgmmMa1pWE0T50kP7sRCAdKVRg+Z7eJXgTJj1hixv be2nNv7JpqTCmqNTaTefmNOXawfDTeKrZAxe/x6x/23HeUha+eigrja0tUXH02HsPXkz sp8wddacAiRFSjDfL3XQZStwPa4WCzYal+5hRYo6AdzSWCmeAd6KbWNgZJRT/bRoz9IK M13g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H3qves/WadJlBam9+P3agb/z0l11fP5hB2rLAgYohxI=; b=lsxAyUo1kqJ+NKW3L0XMjtECTf6kZe203J7Ddr/SUK/yYpOewn7eUJzxJZBxIforCM r64t2iQ/9zySMtu49L1d5DlD95zHNptJzMxvhWEA4nuON6cw8iZmQQyLhSMz7M3Pjg2i +QLFSS5RI+aYn7bTY0R1C/lmaGjmS2NWXH64IAKDFErra/nqS+UHFfo+aqEREQDPwL2u OvOIZM/rDUgiLP47lAfnwUEA6xHY89YSsIhoFaGy/5IqljnV5rbWXxk89+b54hdqfIPh hkBZ0766kXrXQq5diFuBwTCywg55iB+0+3SuB0xImvUTY/fNeNYrnR7pbqWGpt4YlbSg 3ipg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U4R1oAaa; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e25-20020a62ee19000000b004fa843103dbsi1058227pfi.193.2022.04.27.04.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:12:55 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U4R1oAaa; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DB0042FA3D3; Wed, 27 Apr 2022 03:06:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353839AbiDZTGA (ORCPT + 99 others); Tue, 26 Apr 2022 15:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353581AbiDZTFS (ORCPT ); Tue, 26 Apr 2022 15:05:18 -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 2C57719980B; Tue, 26 Apr 2022 12:02:10 -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 E54FEB8224A; Tue, 26 Apr 2022 19:02:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95CE5C385AF; Tue, 26 Apr 2022 19:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650999727; bh=xZZ2i1Rlmt1chjOQcZ+PBoeIkXNP2liprcvgy86RiRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U4R1oAaatDF0AbaBReudTiZuTFQUtsrhqM5jMUIi/7r2PgLeaKzKL59wUGvdeCzK2 GJdTSReQvN87gz1Nrii4WIESlHUikEQTgjm4GEq9JXx3Krvtx0lBBhRWHRLgkbNfRT s7gec9HoMTYsem05wfoEVOpkyjJM5qria9CAcVh2JmQx8fYNw6oMFzsB5pqKTnk7CS X7hnsW2bcRi66IupQGZYucbZjToVty2xpGV09Ecbbf3k7Mien47PYVyIZAfC6XuD3v nZxL6OwkzkVPf4fYqmFKKjPTfO418n+/AmWTWcj0uWgjsTihb8q8qRmtnkXBrinGzS KoPg1DjNVvXnQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ronnie Sahlberg , Xiaoli Feng , Steve French , Sasha Levin , sfrench@samba.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org Subject: [PATCH AUTOSEL 5.17 16/22] cifs: destage any unwritten data to the server before calling copychunk_write Date: Tue, 26 Apr 2022 15:01:39 -0400 Message-Id: <20220426190145.2351135-16-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220426190145.2351135-1-sashal@kernel.org> References: <20220426190145.2351135-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 5d120cd8bc78..13080d6a140b 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1861,9 +1861,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