Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1391352rwb; Thu, 1 Dec 2022 17:04:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7WX2hhOAnM8RkGxhRyEbDljQVOII2OhyGkEiiMWc8fUcmZkhusbUdA5Bn0nRYDE5tYCZ2N X-Received: by 2002:a17:906:b2c6:b0:78d:20f7:1294 with SMTP id cf6-20020a170906b2c600b0078d20f71294mr60361125ejb.442.1669943039938; Thu, 01 Dec 2022 17:03:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669943039; cv=none; d=google.com; s=arc-20160816; b=Yh7gQnYfm12ugOUTTD//byjVsd6UhXHSTjpFgSon8sCqvb1Lf2xG7YITzYQ0uZ8ODu 4pxdQfwQn6u5jL7h5O5WNdvw4AibGzDmK1CWABGio2W1uwfoX9vvICcjFmEhh2W35sp6 Iphmg1f6ZCOejGIcKi10ldikmGC1f9G5dYkxnSl6qKocNYT+IbunALOMFT7cgVRNZ+8V D6CIGPQuNLLbdlcoAefZ7hdoFwqeg8IAJ5Ca3BsqutOWk1tiLZLL+a6EDXr1pQejtxA9 MxngIUcjGWzmU9Pvh3Vkl+vt2Xz465PIlOVU9dlrTy+5Xyxxl2fEtkiR46WzGzZSx8Vg XOlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EBIlf6YtCQ4O78vH/b5iIMIvZkEnaRM4W/1cBsySCrg=; b=PjcARdmT0UpqwI1OtAaibmlIOjk6d87hbIw41RGVioEAQG1yRweijwvl6PdFeBxtyB 5AU8BbnO3NyweEp3YWmOaXHCOCn2D093Qe/Dq2Of3VExLfVWWe4J3rICaMVXbecb5QVN 3DvNpv9vcUahwHpTkErEa+0d2iVcALLL/V92l8t5VSNOOeClz2PUBXj+0t5yCiMgMbN6 QJJfGyyjbtRjVojgsuroyKLEcMu/6YOrwCHxuHJIwBt6sjWihyZWUcmXktXxdHonn3tG V6Rs8Ei6MEcYFFKWnPW8tQJWidOioi5f43hzcUovPXXFAg99czXdwzWoDlK8a/f3RIC1 Kuyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AFNa4HAU; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt5-20020a170907728500b007ae6aa9e875si5612893ejc.370.2022.12.01.17.03.39; Thu, 01 Dec 2022 17:03:59 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=AFNa4HAU; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbiLBAFz (ORCPT + 81 others); Thu, 1 Dec 2022 19:05:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231452AbiLBAFs (ORCPT ); Thu, 1 Dec 2022 19:05:48 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBE09C82DB; Thu, 1 Dec 2022 16:05:41 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 18DBCCE1D5D; Fri, 2 Dec 2022 00:05:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3BD4CC43150; Fri, 2 Dec 2022 00:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669939538; bh=L6gBULzhRK7OzgCLtfjp0tObT6lwTFeGydXQwDKFfuk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AFNa4HAUVNlhARyuZW89QcJfCEhpDVZfAximztn5gJjqfia5fU6wXOGMwYoXNV/Da jEvzG7bmCGisu0B1vC6cD8ExXWesbkPElbPgWH0zLaAaP6B0+2c3wkIF716fqgQ9LP ur7HipbKaPkCTeNGCRja0aJzLcUranYd//32/Y3xLg6bBPG6K9Zjqd7aIvh2mDIhEt euqq0i9vXsBR69y1Kh+lkVlHPc1qMOKRKh1DHLpLmy4TYgU4aQEZ5757mMs2fM+WeX fWuVjeh30Th6ETK6FTOqZoOIDs+2H8+EHy5ZigvF0aqv1Mgmap+PINku4SGCDDB+1g 3NQnfLfSBfY4Q== Date: Thu, 1 Dec 2022 16:05:37 -0800 From: "Darrick J. Wong" To: Shiyang Ruan Cc: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, nvdimm@lists.linux.dev, linux-fsdevel@vger.kernel.org, david@fromorbit.com, dan.j.williams@intel.com, akpm@linux-foundation.org Subject: Re: [PATCH v2 5/8] fsdax: dedupe: iter two files at the same time Message-ID: References: <1669908538-55-1-git-send-email-ruansy.fnst@fujitsu.com> <1669908701-93-1-git-send-email-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1669908701-93-1-git-send-email-ruansy.fnst@fujitsu.com> X-Spam-Status: No, score=-7.1 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 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 On Thu, Dec 01, 2022 at 03:31:41PM +0000, Shiyang Ruan wrote: > The iomap_iter() on a range of one file may loop more than once. In > this case, the inner dst_iter can update its iomap but the outer > src_iter can't. This may cause the wrong remapping in filesystem. Let > them called at the same time. > > Signed-off-by: Shiyang Ruan Thank you for adding that explanation, it makes the problem much more obvious. :) Reviewed-by: Darrick J. Wong --D > --- > fs/dax.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/fs/dax.c b/fs/dax.c > index f1eb59bee0b5..354be56750c2 100644 > --- a/fs/dax.c > +++ b/fs/dax.c > @@ -1964,15 +1964,15 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, > .len = len, > .flags = IOMAP_DAX, > }; > - int ret; > + int ret, compared = 0; > > - while ((ret = iomap_iter(&src_iter, ops)) > 0) { > - while ((ret = iomap_iter(&dst_iter, ops)) > 0) { > - dst_iter.processed = dax_range_compare_iter(&src_iter, > - &dst_iter, len, same); > - } > - if (ret <= 0) > - src_iter.processed = ret; > + while ((ret = iomap_iter(&src_iter, ops)) > 0 && > + (ret = iomap_iter(&dst_iter, ops)) > 0) { > + compared = dax_range_compare_iter(&src_iter, &dst_iter, len, > + same); > + if (compared < 0) > + return ret; > + src_iter.processed = dst_iter.processed = compared; > } > return ret; > } > -- > 2.38.1 >