Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp813287rwb; Thu, 1 Dec 2022 08:40:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6eY361pbZaRki7OX7AOKb3EYQ6aTrHyRfzgmvtvjcgvBlndqdZ9qQwC/QTDOiQSCTq3Ku2 X-Received: by 2002:a17:906:a884:b0:7bd:15a6:27e8 with SMTP id ha4-20020a170906a88400b007bd15a627e8mr26073881ejb.78.1669912820727; Thu, 01 Dec 2022 08:40:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669912820; cv=none; d=google.com; s=arc-20160816; b=Q0DWBRvERhZIQ/QgKgLo0xLbxyzNNCeEGFNPp0q6Ga6kWW3w5bzLkrYvWmoVCFN9kf eZMkENvOxywKc+7+M4eSIahXr8YX1MF9KOqo+b7877wg5Pwo1klAUJpgjIh+O8j9ksT7 DLhNx4AZCdgaKoy4NOlOHw0Sc3eczQ0Zcaz7XhFoWQ4t66UasW//jNfLEZwfg/xuEocu 6vHcLdTaiTDwL8snCI1Bjwt1Vb/HQHclWqYD6zwyergeJJ7J6QeNOnk2/fkO0j/zH4st VXePlMSOdS1thgRV+G1CAK21Cp0qOFA10EtKudcyeplSY5nR0Gz5MXn/3bRz/Xq80mrS 62JQ== 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=m1VWc3XpLe8H0b9P+wA0eyV/tWD/uP5wJYraz73drqA=; b=XBBr4qAwyTAPoxuvmN/vT6YhDnCwoDnziGeMuMzIHB/2KceZqDurpxHbdXvavIaKI6 xkw3OOfTO5VHH47+SnqJbv0Rzdq3DnVG+V1hx5FgsB489L3Xu6/AtthdhrncfcxRE74N G2OhbV2jnQ6yBSOnVVzDlKeOFR8y5reAnH/phUcUnIzT9nnwbkXaoDstsUr3d5n5g+4Y iYhF6jdh1/NMxs1skoAtFl/XBiI/rVrKMtQI1fCPVUlWHcFvmn2k1NZ9idR7IDhhu8ht 30K5/nOSmoIYYzwj+eRlDRxWPUXNfYnUjeW7KSIj8vqkk7e6hyNGhAtUA5+BxilfsKfK Ks7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vNU6OPAB; 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 sg39-20020a170907a42700b007ae2dfe8b76si4654769ejc.76.2022.12.01.08.39.59; Thu, 01 Dec 2022 08:40:20 -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=vNU6OPAB; 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 S229481AbiLAQRd (ORCPT + 83 others); Thu, 1 Dec 2022 11:17:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232225AbiLAQRZ (ORCPT ); Thu, 1 Dec 2022 11:17:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EFE6BB7D7; Thu, 1 Dec 2022 08:17:18 -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 ams.source.kernel.org (Postfix) with ESMTPS id BB017B81F8A; Thu, 1 Dec 2022 16:17:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63631C433C1; Thu, 1 Dec 2022 16:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669911435; bh=xEUa0q1V/GeuhlVvbRVjNYe9PdAEmhY+C71nTUjdMVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vNU6OPABKKc+65PXc3d8NgpN3RZX0rAXLRxEytiZIHpxUsPNvmuoT6sAmN2B/Afkj qFzvPQQsag2/oGaStn/+BPaDQvIshVzRzmYOzrbPHCXBdnZ1TkkzPetuNQbvTNd1vB H7w3P6xXbwE3tEgxOUk5L902I14ChkDxX4hrzo+24bc53Efn3MWkGsw/pdrKYJ1W81 2nIYcilIGAJFzlZNNISEFXmD3NwmLAF7H8N8S4MlcCalqRkRBIbhy/8SDie73xrbEz hALH6HKvcb7vFOC6XOESVJDj7gw05C1Emr6vPP8kBt3pmizLcFHXnjz9myigd42+I3 ICjVH5KGaPh9Q== Date: Thu, 1 Dec 2022 08:17:14 -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 2/8] fsdax: invalidate pages when CoW Message-ID: References: <1669908538-55-1-git-send-email-ruansy.fnst@fujitsu.com> <1669908538-55-3-git-send-email-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1669908538-55-3-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:28:52PM +0000, Shiyang Ruan wrote: > CoW changes the share state of a dax page, but the share count of the > page isn't updated. The next time access this page, it should have been > a newly accessed, but old association exists. So, we need to clear the > share state when CoW happens, in both dax_iomap_rw() and > dax_zero_iter(). > > Signed-off-by: Shiyang Ruan Looks ok, Reviewed-by: Darrick J. Wong --D > --- > fs/dax.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/fs/dax.c b/fs/dax.c > index 85b81963ea31..482dda85ccaf 100644 > --- a/fs/dax.c > +++ b/fs/dax.c > @@ -1264,6 +1264,15 @@ static s64 dax_zero_iter(struct iomap_iter *iter, bool *did_zero) > if (srcmap->type == IOMAP_HOLE || srcmap->type == IOMAP_UNWRITTEN) > return length; > > + /* > + * invalidate the pages whose sharing state is to be changed > + * because of CoW. > + */ > + if (iomap->flags & IOMAP_F_SHARED) > + invalidate_inode_pages2_range(iter->inode->i_mapping, > + pos >> PAGE_SHIFT, > + (pos + length - 1) >> PAGE_SHIFT); > + > do { > unsigned offset = offset_in_page(pos); > unsigned size = min_t(u64, PAGE_SIZE - offset, length); > @@ -1324,12 +1333,13 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi, > struct iov_iter *iter) > { > const struct iomap *iomap = &iomi->iomap; > - const struct iomap *srcmap = &iomi->srcmap; > + const struct iomap *srcmap = iomap_iter_srcmap(iomi); > loff_t length = iomap_length(iomi); > loff_t pos = iomi->pos; > struct dax_device *dax_dev = iomap->dax_dev; > loff_t end = pos + length, done = 0; > bool write = iov_iter_rw(iter) == WRITE; > + bool cow = write && iomap->flags & IOMAP_F_SHARED; > ssize_t ret = 0; > size_t xfer; > int id; > @@ -1356,7 +1366,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi, > * into page tables. We have to tear down these mappings so that data > * written by write(2) is visible in mmap. > */ > - if (iomap->flags & IOMAP_F_NEW) { > + if (iomap->flags & IOMAP_F_NEW || cow) { > invalidate_inode_pages2_range(iomi->inode->i_mapping, > pos >> PAGE_SHIFT, > (end - 1) >> PAGE_SHIFT); > @@ -1390,8 +1400,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi, > break; > } > > - if (write && > - srcmap->type != IOMAP_HOLE && srcmap->addr != iomap->addr) { > + if (cow) { > ret = dax_iomap_cow_copy(pos, length, PAGE_SIZE, srcmap, > kaddr); > if (ret) > -- > 2.38.1 >