From patchwork Tue Aug 27 15:47:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13779734 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E113BC54731 for ; Tue, 27 Aug 2024 15:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E3CF6B008C; Tue, 27 Aug 2024 11:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 793866B0092; Tue, 27 Aug 2024 11:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 682AD6B0093; Tue, 27 Aug 2024 11:47:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4B6C26B008C for ; Tue, 27 Aug 2024 11:47:54 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 17B46160B37 for ; Tue, 27 Aug 2024 15:47:54 +0000 (UTC) X-FDA: 82498456068.07.D04B03E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 64D484000E for ; Tue, 27 Aug 2024 15:47:51 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UV7JSSec; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724773584; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=DWBRfGjoLyD8v0ummSlyJMhm9Y7pJVqza2oUVXSgR2s=; b=Pc62zBmKIsgwbvvwgq+lVD8o+p9+3y8j5PqokPPTJ+RaC9D1sM1fqenDQX5nPIGjNdwLz0 zt+lU/zHQMrJj9tAlMR0cngBNOlt942xDKQCLmlkHII7s4o9SfK/JQUxhte++kstQIYWYY 0Hi0xl9AkKy/oVWIf7UARNF4beG6M3w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724773584; a=rsa-sha256; cv=none; b=WnfnPG4EOeVzQrpFDF7zpy2+ZDZU9Jev4h3qrtDjoL36pLSX71TgujGmmh6m/p6oDC1sJZ otsMAmB+D0c5En5+RTldXb5GuS3Cpb1w0rS9RHqn2Ou3tV19Dzhrg1DsxJZdlP6Q8ZsYqa lDs07RPc1N+dPnfXlZq3Ak4Ik2Og9Mc= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UV7JSSec; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724773670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DWBRfGjoLyD8v0ummSlyJMhm9Y7pJVqza2oUVXSgR2s=; b=UV7JSSecBhApxrFbDlItH28YLXe6721gvr4YOCGIt6zYHcqQ3cPlBkKzkLkj4rpXufkJPf CBlEXSVAMrCUe84m7VoQN2Vo9Lq6TmL6ncHbgem5PVbqRUZPHzLru3HCauEKKXouhZ/TvJ xYyXAMoXE8CPAIsoT9ZBSvYrF9QcwWM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-cxr-aK1BMeO3_XGtL99SmQ-1; Tue, 27 Aug 2024 11:47:46 -0400 X-MC-Unique: cxr-aK1BMeO3_XGtL99SmQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8F84D1955F56; Tue, 27 Aug 2024 15:47:44 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 67F811955F1B; Tue, 27 Aug 2024 15:47:41 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: Steve French cc: dhowells@redhat.com, Paulo Alcantara , Shyam Prasad N , Rohith Surabattula , Matthew Wilcox , Jeff Layton , linux-cifs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cifs: Fix copy offload to flush destination region MIME-Version: 1.0 Content-ID: <861651.1724773660.1@warthog.procyon.org.uk> Date: Tue, 27 Aug 2024 16:47:40 +0100 Message-ID: <861652.1724773660@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 64D484000E X-Stat-Signature: 5hq887m3hcyyr746s1toisqi5y6gjkhy X-HE-Tag: 1724773671-39809 X-HE-Meta: U2FsdGVkX1+Vbzl9LePEuYLwS1aFqUBQSv/76C1r40t+T7MCJksLPzx8JgCbCs4MCTgGASfeYuMTrpuWafNjTueR/G9/v8beo+MLga+tJaJFzpp5Y6bjthPiGGcco4oAw/SyiwOLIxzN0l28i44i/YrQ2cRbnfZvtG3/5K5t4glS1K1Epw2HnSijN+IwC7+Y1d4EZipdE3lAkYomjK5teWmk5byc8edF7Zmw0CayLQ7bomxVpl0x5g30E/n8vfXx83YTZ2TBOWs6TkUow2VH9NUhxQ5tSticrCgLRfxnZvBcDjDE/mokEQ+iumQd9MaNzovQlMzFbV5JbK4ZNNkRjL8aK6sdezDSQHsmQr28joejRg/vtc893yGs/RDm2NYTBDip/JrSLL4C/oMEZ+Ze1cBX1JqSdoBgpMojso1PYhkLU8D4mRqrYrtTqpZVnJI41Rn8pxeuh2o7ensg24gHKGaJdC/kColDtWygQgJyhOAIOZ8biUuNQDqTuJ1ytC2VWvwc9sXr5v/TjZyiZZ0506ctPPpjRV48MT3pLCylytRuLxebMmXngFxMQFG5qbsagGsDwUu5Zl1GBReOoPnk2KukkudMxLtuLtr//dvYTNXIbqUzIXscQPZXdgSbzsaKf/aGulTHm9mzWLrPYQzb0Eo/yKKKcQHRSMTjMk6Pqz82mhep9PNmwcHEcAHNsuWTOroW5wuy4JjD3XjyE6as0CvXtL5U919zaj5Z8+PcLD3wyqQd5aOLkcQrqTaKt9NziPw9aMrrMQIJsuD68LopfgAdhV2EGoneg0V6gJsryILk/i8SNTL8CRF94a5PCXM8IZgu4kKub6f3oACx/bphbJsEd2Qt9YnXL75QN94onW8fY6Tz9C6qJo0AtuPOkKajbTeXnigLWgX6KUL7H1caWzbCcpzUkTPqo06p3rUrN28BvJL0PjInu3Lu+P/zqJAaMjRnjGyHWnCFCtDWw+x FHL9lRaa 6j64Tn/1zMSuzKPVmgmHmjhD5uBLyBUk+9OiEkjUFB++FwsAYqTrUBBGGielldNtCeBWU4FZfIiIDYWol+pyHRwE7nFc0Wbhi8+jHgDFJZL+sLDrVBJHLZW9B/fdoU9Z2UA5W3SyOzApwVAtw4wqI0yH+sm6U5rEf6aPL+rWwzquAXsq/bmJKr9dfoArUertJHpF+jxlBG3+FCTB4zmbz9ZhF/CQRg6/0IDdJMMAXmRzA6ENbsFtvUDhOatQpoD4WyXUseq49cgSRD4kcNtgHGrEEnU3bk2pX63GIwWryhX4uq6py2ey5wyAEKLp5MP3uHuwr1PhDFWNuA7BTVpaRZT5z4E8E5iCcJRNRcxcAFzBhGD3T96ON7VhF9wt0sBc26iLM4HSyRulqLFR4oLjVcpbjuXdHx68HiYdijHC1l1mYmqo/I+YvczNSsySGba9RusMSjimpeH2bPJI/tMQ6HK7oCT78MfWqiPgA2PrVqtMyZoujinObfqvxvcKLg9pUJkTmHv+/UaWMpP2VWXdln3Fa2BrkX/IoWBU8hSqXX2So7AnI5FSJ/UuifsXiXteY0qzl/ifeQnBHp99k9qJ6Ado5T6zPoO8vsOWUX6x+5u0R5en8OdDX9an9QXpGz+ornw/1H55LUFMBOWFwo7XqTE87OQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix cifs_file_copychunk_range() to flush the destination region before invalidating it to avoid potential loss of data should the copy fail, in whole or in part, in some way. Fixes: 7b2404a886f8 ("cifs: Fix flushing, invalidation and file size with copy_file_range()") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Matthew Wilcox cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/cifsfs.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index d89485235425..2a2523c93944 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1341,7 +1341,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, struct cifsFileInfo *smb_file_target; struct cifs_tcon *src_tcon; struct cifs_tcon *target_tcon; - unsigned long long destend, fstart, fend; ssize_t rc; cifs_dbg(FYI, "copychunk range\n"); @@ -1391,25 +1390,13 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, goto unlock; } - destend = destoff + len - 1; - - /* Flush the folios at either end of the destination range to prevent - * accidental loss of dirty data outside of the range. + /* Flush and invalidate all the folios in the destination region. If + * the copy was successful, then some of the flush is extra overhead, + * but we need to allow for the copy failing in some way (eg. ENOSPC). */ - fstart = destoff; - fend = destend; - - rc = cifs_flush_folio(target_inode, destoff, &fstart, &fend, true); + rc = filemap_invalidate_inode(target_inode, true, destoff, destoff + len - 1); if (rc) goto unlock; - rc = cifs_flush_folio(target_inode, destend, &fstart, &fend, false); - if (rc) - goto unlock; - if (fend > target_cifsi->netfs.zero_point) - target_cifsi->netfs.zero_point = fend + 1; - - /* Discard all the folios that overlap the destination region. */ - truncate_inode_pages_range(&target_inode->i_data, fstart, fend); fscache_invalidate(cifs_inode_cookie(target_inode), NULL, i_size_read(target_inode), 0);