Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3139660pxj; Mon, 10 May 2021 20:11:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcm83JltQyM4R+bRNFP5gindEF3CRAcU8bvR7+ubBRj4ppnDlZuzuNscTxFePQBKguPnci X-Received: by 2002:a02:77d6:: with SMTP id g205mr25096123jac.48.1620702666669; Mon, 10 May 2021 20:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620702666; cv=none; d=google.com; s=arc-20160816; b=t0V0Sr/vr+EU765pKF7Q+08+L5ePMOGmev51r6SVux+NPiXJRTK+h/t80AReetU4v6 9DiqmdQ8NEv2q781SkF5/h3qt4VqalVWQwSXNBNUZ4h9Ytv4Y/G7YlcOzaq8Qs5gB8nT 1u1NdGFgkqWYSvOVqZdV3DADB3K+h+S8myvGIyk0GD+x5xOY9HgFCbaf/alnDPJg5jHv LmmQaTgtSFkfK6hhSSpoGnuMqRrc3GeumGPtte5jAHwxFF5vHBdC6OJuik69HMae2ZGw BweN/ZjOKP95npvc1PGGd8ozb8rM2U5LSNNgbv3jxTxr2S2WZaOTryOv56rzfEuz5EVk B6BQ== 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=UJB2lBSxGoUHpwsRqh56a2/K+dCkZkxvcTUSc5wdWQc=; b=UXeW4kVF0n7sCe0QncSNrgj6bUNMSWN17lmI3JwfSNXVtBRIzAymMBbsZXdsbWHZDU MyvjSyYRSo0ZLJ/PWNVstY65LvYiuFlcBBQy1P11mXxz6XBWvWC43hcNCRoPUy4sLlAJ 8Hse/Hz2V9BgWpOF1D0JwcZ/8YYlYa5DRETKWFHOmpIbzfYsmYY3zlNZj8U1KpJS9cZD d6aBnkWQUPEbIwfR8cqZqDFI7iv4GtAUeLgKXfKqLdKOKFkejFvBEqFcTzdTvrmLbcQ8 SAx7f7Ml9JWif3F8y4glqPP0ZiidrR7wke+bwvDIUS9KKme434HHyww+nflw+/DrbVxS gySw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si19412304ilq.55.2021.05.10.20.10.54; Mon, 10 May 2021 20:11:06 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbhEKDLF (ORCPT + 99 others); Mon, 10 May 2021 23:11:05 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:41042 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230073AbhEKDLD (ORCPT ); Mon, 10 May 2021 23:11:03 -0400 IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AL1sJuqlyOBPkiE8rq/LbWix1V/PpDfLK3DAb?= =?us-ascii?q?v31ZSRFFG/Fxl6iV/cjzsiWE8Qr5OUtQ4exoV5PwIk80maQb3WBVB8bHYOCEgh?= =?us-ascii?q?rPEGgB1/qB/9SIIUSXnYQxuZuIMZIOb+EYZmIbsS+V2meF+q4bsby6Gb6T9Jvj?= =?us-ascii?q?5kYoXQd3cLth8gs8Lg6aF3d9TA5ACYFRLuvn2uN34yqnZW8Mbtm2Ql0MX+34rd?= =?us-ascii?q?XNk578JTEcARpP0njysRqYrK79DwOD3goTFxdGwbIZ+2DDlADjooWP2svLsSPh?= =?us-ascii?q?6w=3D=3D?= X-IronPort-AV: E=Sophos;i="5.82,290,1613404800"; d="scan'208";a="108110523" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 May 2021 11:09:53 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 4B5A04D0BA79; Tue, 11 May 2021 11:09:50 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 11 May 2021 11:09:51 +0800 Received: from G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 11 May 2021 11:09:48 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 11 May 2021 11:09:47 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , Goldwyn Rodrigues , Ritesh Harjani Subject: [PATCH v5 2/7] fsdax: Replace mmap entry in case of CoW Date: Tue, 11 May 2021 11:09:28 +0800 Message-ID: <20210511030933.3080921-3-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511030933.3080921-1-ruansy.fnst@fujitsu.com> References: <20210511030933.3080921-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: 4B5A04D0BA79.AFFA0 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 --- fs/dax.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index f0249bb1d46a..ef0e564e7904 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -722,6 +722,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 @@ -729,16 +733,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)) @@ -750,7 +757,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); @@ -774,6 +781,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; } @@ -1109,8 +1119,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); @@ -1137,8 +1146,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); @@ -1448,6 +1457,7 @@ static vm_fault_t dax_fault_actor(struct vm_fault *vmf, pfn_t *pfnp, bool write = vmf->flags & FAULT_FLAG_WRITE; bool sync = dax_fault_is_synchronous(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; @@ -1470,8 +1480,15 @@ static vm_fault_t dax_fault_actor(struct vm_fault *vmf, pfn_t *pfnp, 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.31.1