Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp54951pxb; Sun, 15 Aug 2021 23:07:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9wqGVjaU3yaFJHIknmq6+vvobiUgnjBiZ0OxU0Ynxf/5x8srLgHyrSyxoHzf3W5brGs7y X-Received: by 2002:a05:6602:2dc8:: with SMTP id l8mr11933906iow.179.1629094028231; Sun, 15 Aug 2021 23:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629094028; cv=none; d=google.com; s=arc-20160816; b=sjlTSAS8rDVynb/bVuJspV5tMbhxAIqOTH/t5z6tUEyUOpkN1Rg1i44JzbNmx6vcTw GRV2upisXeZEpxlrWADaxUNwjwPAkGA7LZZMddL9+F+PG6ZCXkEF2DZ32vI9Hu0CHgKG hytEo3EDzT6s/r7+h8NmtzscDAJ7g55Kayib9VOeZaFWU9V4mUX1+8MCCvf+W78zW5/d gkvCn3uOKp+biFhdK2bt1tgk/x/7P0eMOvrPubyQqj1hcpzI7nM9I9g5YR3usprSufKa FeY5ERC5UCrXZpzFI3lARuh5D2fwnjGoW0lB7kE4b7Ic4pVvLTUyTHlfuevar+m702LA 5ryg== 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 :ironport-hdrordr; bh=aE6w6AZvKsLnDPYfygZtvAP3eAADXXvyh2H2ZXa7SxA=; b=tj3U9pnhRudwmeVTTF8YPq81tjHz2fb7TZk9mDKzsH3FiD9uBORs8TRbqNa8JYhs9T MpuwUVFyhjJXQbJ5ckAL90ztmcbazIN5tRyI9rUmatCkcOGU14G7yLRt1nxzkwn5svnF oqmUPLs1DLMuHGZ+Ja7VXGm0CJpSlKu2b0BxfJADpERU3CI+TRIIwsdQVipzbk0hpS2z Ztoj9SD+e59QrBGWQly/kclY8Mcd25WoOMCyfTPyGTkn+tAtuDhgHKPgRlE8YSnQerKI QZ9BBFlgohWXO40oZbIBaueByMuCW0IdCTO0dwKd5ClcunN7dbfHTOmqvKyKgQ7WJ+rK thOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g7si13542629iov.41.2021.08.15.23.06.57; Sun, 15 Aug 2021 23:07:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233487AbhHPGFW (ORCPT + 99 others); Mon, 16 Aug 2021 02:05:22 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:38875 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233459AbhHPGFN (ORCPT ); Mon, 16 Aug 2021 02:05:13 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AbwXmpKCae25mMHLlHemQ55DYdb4zR+YMi2TD?= =?us-ascii?q?tnoBLSC9F/b0qynAppomPGDP4gr5NEtApTniAtjkfZq/z+8X3WB5B97LMzUO01?= =?us-ascii?q?HYTr2Kg7GD/xTQXwX69sN4kZxrarVCDrTLZmRSvILX5xaZHr8brOW6zA=3D=3D?= X-IronPort-AV: E=Sophos;i="5.84,324,1620662400"; d="scan'208";a="112944872" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Aug 2021 14:04:35 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id E15804D0D829; Mon, 16 Aug 2021 14:04:32 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 16 Aug 2021 14:04:24 +0800 Received: from G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.85) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 16 Aug 2021 14:04:23 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD09.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Mon, 16 Aug 2021 14:04:20 +0800 From: Shiyang Ruan To: , , CC: , , , , , , , , , Goldwyn Rodrigues , Ritesh Harjani Subject: [PATCH v7 3/8] fsdax: Replace mmap entry in case of CoW Date: Mon, 16 Aug 2021 14:03:54 +0800 Message-ID: <20210816060359.1442450-4-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210816060359.1442450-1-ruansy.fnst@fujitsu.com> References: <20210816060359.1442450-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: E15804D0D829.A0B84 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Spam-Status: No Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We replace the existing entry to the newly allocated one in case of CoW. Also, we mark the entry as PAGECACHE_TAG_TOWRITE so writeback marks this entry as writeprotected. This helps us snapshots so new write pagefaults after snapshots trigger a CoW. Signed-off-by: Goldwyn Rodrigues Signed-off-by: Shiyang Ruan Reviewed-by: Christoph Hellwig Reviewed-by: Ritesh Harjani Reviewed-by: Darrick J. Wong --- fs/dax.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 697a7b7bb96f..e49ba68cc7e4 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -734,6 +734,10 @@ static int copy_cow_page_dax(struct block_device *bdev, struct dax_device *dax_d return 0; } +/* DAX Insert Flag: The state of the entry we insert */ +#define DAX_IF_DIRTY (1 << 0) +#define DAX_IF_COW (1 << 1) + /* * By this point grab_mapping_entry() has ensured that we have a locked entry * of the appropriate size so we don't have to worry about downgrading PMDs to @@ -741,16 +745,19 @@ static int copy_cow_page_dax(struct block_device *bdev, struct dax_device *dax_d * already in the tree, we will skip the insertion and just dirty the PMD as * appropriate. */ -static void *dax_insert_entry(struct xa_state *xas, - struct address_space *mapping, struct vm_fault *vmf, - void *entry, pfn_t pfn, unsigned long flags, bool dirty) +static void *dax_insert_entry(struct xa_state *xas, struct vm_fault *vmf, + void *entry, pfn_t pfn, unsigned long flags, + unsigned int insert_flags) { + struct address_space *mapping = vmf->vma->vm_file->f_mapping; void *new_entry = dax_make_entry(pfn, flags); + bool dirty = insert_flags & DAX_IF_DIRTY; + bool cow = insert_flags & DAX_IF_COW; if (dirty) __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); - if (dax_is_zero_entry(entry) && !(flags & DAX_ZERO_PAGE)) { + if (cow || (dax_is_zero_entry(entry) && !(flags & DAX_ZERO_PAGE))) { unsigned long index = xas->xa_index; /* we are replacing a zero page with block mapping */ if (dax_is_pmd_entry(entry)) @@ -762,7 +769,7 @@ static void *dax_insert_entry(struct xa_state *xas, xas_reset(xas); xas_lock_irq(xas); - if (dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) { + if (cow || dax_is_zero_entry(entry) || dax_is_empty_entry(entry)) { void *old; dax_disassociate_entry(entry, mapping, false); @@ -786,6 +793,9 @@ static void *dax_insert_entry(struct xa_state *xas, if (dirty) xas_set_mark(xas, PAGECACHE_TAG_DIRTY); + if (cow) + xas_set_mark(xas, PAGECACHE_TAG_TOWRITE); + xas_unlock_irq(xas); return entry; } @@ -1121,8 +1131,7 @@ static vm_fault_t dax_load_hole(struct xa_state *xas, pfn_t pfn = pfn_to_pfn_t(my_zero_pfn(vaddr)); vm_fault_t ret; - *entry = dax_insert_entry(xas, mapping, vmf, *entry, pfn, - DAX_ZERO_PAGE, false); + *entry = dax_insert_entry(xas, vmf, *entry, pfn, DAX_ZERO_PAGE, 0); ret = vmf_insert_mixed(vmf->vma, vaddr, pfn); trace_dax_load_hole(inode, vmf, ret); @@ -1149,8 +1158,8 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, goto fallback; pfn = page_to_pfn_t(zero_page); - *entry = dax_insert_entry(xas, mapping, vmf, *entry, pfn, - DAX_PMD | DAX_ZERO_PAGE, false); + *entry = dax_insert_entry(xas, vmf, *entry, pfn, + DAX_PMD | DAX_ZERO_PAGE, 0); if (arch_needs_pgtable_deposit()) { pgtable = pte_alloc_one(vma->vm_mm); @@ -1461,6 +1470,7 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, bool write = vmf->flags & FAULT_FLAG_WRITE; bool sync = dax_fault_is_synchronous(iter->flags, vmf->vma, iomap); unsigned long entry_flags = pmd ? DAX_PMD : 0; + unsigned int insert_flags = 0; int err = 0; pfn_t pfn; void *kaddr; @@ -1485,8 +1495,15 @@ static vm_fault_t dax_fault_iter(struct vm_fault *vmf, if (err) return pmd ? VM_FAULT_FALLBACK : dax_fault_return(err); - *entry = dax_insert_entry(xas, mapping, vmf, *entry, pfn, entry_flags, - write && !sync); + if (write) { + if (!sync) + insert_flags |= DAX_IF_DIRTY; + if (iomap->flags & IOMAP_F_SHARED) + insert_flags |= DAX_IF_COW; + } + + *entry = dax_insert_entry(xas, vmf, *entry, pfn, entry_flags, + insert_flags); if (write && srcmap->addr != IOMAP_HOLE && srcmap->addr != iomap->addr) { -- 2.32.0