Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4427269ioa; Wed, 27 Apr 2022 03:44:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzErX79ELOYXhWcIThzksBpMw09fAmOE6ZAKBOk0TS/gqoiG7C8sU0yT6R8hDyBj8Vm20CO X-Received: by 2002:a17:902:704b:b0:15c:42fb:e5b with SMTP id h11-20020a170902704b00b0015c42fb0e5bmr25702787plt.79.1651056287618; Wed, 27 Apr 2022 03:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651056287; cv=none; d=google.com; s=arc-20160816; b=zRbCsZH8OU2bIoOxsLt+ID7AsdHMI5b6xBDoua/0LFviNrp9qQ+bJPd6cKOCwpa1HH ktDfJ/0vA3xzRCxOQ+A/srQTHX/keBR1lKWHys+MAZEdfjobEYRpJQ+6kGAXTNVIcN8J emI1ZwbqMn9kAeauP9ocxatofvh3ioJFSuGt3UUEnpXSHM08dtY0Tw0yWQ4UpRHMDsbj OsLDcvQeW5qn4xLP1R2MuEw/ziZekYHqCTN/XO8/gharNo+yi61+RjMCKaF2qzFkHWm1 rX/ilqOllTVOaClrlRtkmXrAO7I01XToU/mE5ki4HqvXVGWa1rWnNBt5yMr5HAqLZ2/O CH0w== 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=xlefOqH3lXzFjBU4F1qclRk6Y2PPsqIjE7bFWkx7L18=; b=rzsjQQWBE3evL1G7eBTjqfdYwV4Z6oGEMBmzE72/rGwZxY/T8pZDMXDfXc4ObM7hld z3IURwaTlIEUbLgcTHlvGPVyRk/MXEDbhRivzCHef2APxOUn9rGS6SPI8c3iXNPrpbcZ mOXdM8oYJDbCebI7Uzjl+G0dpmb5QsbXj0KRjQvrJuAiWturFYpDYO0ErpnHEu8aOiYc J2OkwsMgyEKq6Ohxr0vrmLBRhLLCLQqS2VUBYRHEi+LkcDdS13hz71YFuhfLS/aTxHgA TG5TOxMaUFPqKeOTTTyCoiFKcv6sPdAKUCnMbOb1epB6U2oz3/DNKQUuuFl+yrumhMch rDIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uXg0V+yB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id q85-20020a632a58000000b003aa33b302b2si1097013pgq.434.2022.04.27.03.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:44:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uXg0V+yB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 4AC27404AC7; Wed, 27 Apr 2022 02:53:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354308AbiDZTKE (ORCPT + 99 others); Tue, 26 Apr 2022 15:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353864AbiDZTGL (ORCPT ); Tue, 26 Apr 2022 15:06:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5818319ADA4; Tue, 26 Apr 2022 12:02:56 -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 E91196199A; Tue, 26 Apr 2022 19:02:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A742C385AD; Tue, 26 Apr 2022 19:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650999775; bh=7GAuG015USrv20+qpuwNBVLPVFfXyP5uE6MrbuBZcTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uXg0V+yBiipAVpOqDSHidd5gM3LxYxPNTwjWe8/4t55t62H8/gne7F76pXJZ5N8Y8 a1BayaJuKRpQGL3zbqpet0NJu6HuDYWMj+8Kl75z+aRgVAZeS7k4y8hw9XmzKdcykk WcZkfRGH6bA9pXzTCJbXjW3m6KkAdOGg+IlNkgLHUweftP6sAy9XzlBvpQlyp+4hJX Mh/5Ky4DaiIdHl7G3UQTqwrkeITeHwlc/GLtLb7IWuo1JkNtj1Kelqzo3NaksWfNx0 sEKZ5v9NgmxowUqp/a2cP0H5wKFOBYbhRYJ/Shtl82+eEGUt3GLAexGtp1lvO1SnzH wUhsuuB9Wn8CA== 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 4.19 4/6] cifs: destage any unwritten data to the server before calling copychunk_write Date: Tue, 26 Apr 2022 15:02:47 -0400 Message-Id: <20220426190251.2351817-4-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220426190251.2351817-1-sashal@kernel.org> References: <20220426190251.2351817-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 61955a7c838b..cc34a28aecbc 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1144,9 +1144,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