Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp940363pxb; Wed, 6 Apr 2022 04:54:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0icRZoc493tztL0fBB7AEk26uWrn9lrOVUqh1g5TyrMfOudnfoNJ62wWXnVseUqHQ6NZd X-Received: by 2002:a17:90a:294f:b0:1ca:aa69:4f01 with SMTP id x15-20020a17090a294f00b001caaa694f01mr9521531pjf.169.1649246090378; Wed, 06 Apr 2022 04:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649246090; cv=none; d=google.com; s=arc-20160816; b=CY4fsFJfcFx/0DAZyCWJyomgVqDKpL35ueC9WQYa116n8TWxa6+3mh6bhNFMSM6teJ JQx7Rjrq0LD/dNFZGiKugzfpwMufPdIcZOC1Try+8089fvd7xZfbB3+CBWWLpADHVjHv 2i6OMZQa2g3wic9jLx60vgzvMo1BBN3jssWsBm+3I8uVuRiRADrVPsZNRD4snrYniryR bgxVMw0JaZaU36JdAfx5jDxJLBT78NrBFf1uoW3DNwhXuOR1si2b4Kns/98v64wgMN1q G1bk4gfxRO8ElCBrjMFRoMruwvZ9G4+HIm9B/2nYzXP95anWaJ0RMOSUY9xtilSYyJT2 7W5g== 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=dKNCL4PBqXZR/X7Fz9Ejw4QX4AEbTWiksvgzCbI9yeI=; b=T7nuhxtzpZtctiCb0UHGtuTH8YkRT/ELRBlRWWTgZKhnwr3rbfaNOLf9vqaLYv7KiJ WdwoPieZBFzVAMrNSiETaFbRd6Ujye5et7AgU8YpztrAP9UjCQgX+Dln4llQdMupT3s1 ZF1jK28jFlGhXxwK+UPcZ9JgSzFMyRYbeuTumPvz23q711v1gTqPwdKA5zkAztb2037y suGzlDfe4WvbR6h3OcDSovZSwtKV3zn4dtrvGlLwqzcWobR1Orwhv7EEPomMPBnmXbi2 TpUHmGU0xYwt1MP+P/WzSewWx/GfYi80R/oDqnySjn+c4KmLR4t1OrNn76rJgeVqEhGZ 6DmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jXw9+tCk; 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=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j2-20020a17090276c200b00153b2d1649bsi14195170plt.163.2022.04.06.04.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:54:50 -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=@linuxfoundation.org header.s=korg header.b=jXw9+tCk; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF8353221EB; Wed, 6 Apr 2022 03:16:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbiDEHoh (ORCPT + 99 others); Tue, 5 Apr 2022 03:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbiDEHoR (ORCPT ); Tue, 5 Apr 2022 03:44:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D243995482; Tue, 5 Apr 2022 00:40:39 -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 5A977B81B92; Tue, 5 Apr 2022 07:40:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B51C8C340EE; Tue, 5 Apr 2022 07:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144437; bh=Fb4riB0jEURomykj+1J8g5qsThUapKp//UiRoyJN0MM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jXw9+tCks2dFhMp9GTqXiEq3P1IvbjaiiEy3Hc1nzLhm0pIh9kwiHXTx7eWWVmfXO zg7oSm/nCRQiC3JlHGU/XogHCp5IdrFH1GyZXMuTqTAD/2EQjTLEjO/W2vXD9edMsF GwPXybsRUPypZjAHON4p87lzWQbT3pZS0TSEGR2o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoli Feng , kernel test robot , Ronnie Sahlberg , Steve French Subject: [PATCH 5.17 0043/1126] cifs: truncate the inode and mapping when we simulate fcollapse Date: Tue, 5 Apr 2022 09:13:10 +0200 Message-Id: <20220405070408.823275754@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 commit 84330d41efb12bc227899e54dbdbe7d9590cb2b7 upstream. RHBZ:1997367 When we collapse a range in smb3_collapse_range() we must make sure we update the inode size and pagecache accordingly. If not, both inode size and pagecahce may be stale until it is refreshed. This can be demonstrated for the inode size by running : xfs_io -i -f -c "truncate 320k" -c "fcollapse 64k 128k" -c "fiemap -v" \ /mnt/testfile where we can see the result of stale data in the fiemap output. The third line of the output is wrong, all this data should be truncated. EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..127]: hole 128 1: [128..383]: 128..383 256 0x1 2: [384..639]: hole 256 And the correct output, when the inode size has been updated correctly should look like this: EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..127]: hole 128 1: [128..383]: 128..383 256 0x1 Reported-by: Xiaoli Feng Reported-by: kernel test robot Cc: stable@vger.kernel.org Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -25,6 +25,7 @@ #include "smb2glob.h" #include "cifs_ioctl.h" #include "smbdirect.h" +#include "fscache.h" #include "fs_context.h" /* Change credits for different ops and return the total number of credits */ @@ -3887,29 +3888,38 @@ static long smb3_collapse_range(struct f { int rc; unsigned int xid; + struct inode *inode; struct cifsFileInfo *cfile = file->private_data; + struct cifsInodeInfo *cifsi; __le64 eof; xid = get_xid(); - if (off >= i_size_read(file->f_inode) || - off + len >= i_size_read(file->f_inode)) { + inode = d_inode(cfile->dentry); + cifsi = CIFS_I(inode); + + if (off >= i_size_read(inode) || + off + len >= i_size_read(inode)) { rc = -EINVAL; goto out; } rc = smb2_copychunk_range(xid, cfile, cfile, off + len, - i_size_read(file->f_inode) - off - len, off); + i_size_read(inode) - off - len, off); if (rc < 0) goto out; - eof = cpu_to_le64(i_size_read(file->f_inode) - len); + eof = cpu_to_le64(i_size_read(inode) - len); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, &eof); if (rc < 0) goto out; rc = 0; + + cifsi->server_eof = i_size_read(inode) - len; + truncate_setsize(inode, cifsi->server_eof); + fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof); out: free_xid(xid); return rc;