Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp819460pxb; Thu, 25 Feb 2021 16:29:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9/BPaqR897kljQPrm6iZNFrHQ4GIhySYzV8rlKsodMMyYPytDz6qUiQwaVWdgP2qYKlcw X-Received: by 2002:a50:9d0b:: with SMTP id v11mr582715ede.308.1614299364017; Thu, 25 Feb 2021 16:29:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614299364; cv=none; d=google.com; s=arc-20160816; b=o4bWvgDrTiOPTDDdkb3oEp/ZDCnkSt/UcQNKlp2p5+nzSJWDJZ1PMGWFroFdu9bDx2 hjG3SURFrNV1tOOClnjJE9RxPsTR8T+Exfzf8cgC9W/TE7nYw2y8H4GizlPh08tTWw1B d5q9yoxb88EskKzX4tTsYS4l5PxnTwPIjV8rxqG5Lt/06X4U6kS4jUrVBAAP2gXYQDhs M/bt/4UwbxmH20ggDvD8k0Pu5UwVcO0caQfA/zNVm9h/VHFEiq2RmAXYcYdQnf5ZJAGG cmN9iWChK5U1HJb59XuL289YRL9AhQFVbFdb82hAQSQ6nEHkVME5XsJ4cH53dYqP741i XPbA== 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; bh=ELx7rj8edyJtNR1BRXg126eu4G82TJlShri9CUH7fr8=; b=WKjWPiryZaU0EcDV1Ps0hHYfSQwnDEXKDVzdT8CZhrdR2KscwNRUHpyXRO9IcI3HxZ E9fII3H7TgTnaooNmwOpmi7nz8iIwN0BB2MkTx1PnBpwgPS5atflsBJdL3lgxkz23wmg m2KMUP8o6ad+kkIZXQHsw8xco2iB/OU8lxW3aHbc1eCTJGs7lPh9v32nwz84FkSWOtoP wA+nt03HrZKqr+z0wgiMCOWPGhthvmSIc8BIlNNTD2uMwjf+U8NSSUvt/YTpCBr/Byo2 AWwG0agofFckvhRnDJUDXX1QqpjXdm44/ZzEGoSa7XdTxJZjxtDXpZv1eV4BHsBb5Gbk em0g== 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 o9si4295609eju.695.2021.02.25.16.29.01; Thu, 25 Feb 2021 16:29:24 -0800 (PST) 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 S232970AbhBZAZc (ORCPT + 99 others); Thu, 25 Feb 2021 19:25:32 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:27913 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232918AbhBZAZP (ORCPT ); Thu, 25 Feb 2021 19:25:15 -0500 X-IronPort-AV: E=Sophos;i="5.81,207,1610380800"; d="scan'208";a="104882827" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Feb 2021 08:21:06 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id E5C474CE7781; Fri, 26 Feb 2021 08:21:05 +0800 (CST) Received: from G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 26 Feb 2021 08:20:56 +0800 Received: from irides.mr.mr.mr (10.167.225.141) by G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 26 Feb 2021 08:20:55 +0800 From: Shiyang Ruan To: , , , CC: , , , , , , , , , , Goldwyn Rodrigues Subject: [PATCH v2 05/10] fsdax: Replace mmap entry in case of CoW Date: Fri, 26 Feb 2021 08:20:25 +0800 Message-ID: <20210226002030.653855-6-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210226002030.653855-1-ruansy.fnst@fujitsu.com> References: <20210226002030.653855-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: E5C474CE7781.A3704 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 --- fs/dax.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 748dfb89fb41..ec4b733e0b59 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -722,6 +722,9 @@ static int copy_cow_page_dax(struct block_device *bdev, struct dax_device *dax_d return 0; } +#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 +732,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 +756,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 +780,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; } @@ -1100,8 +1109,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); @@ -1403,6 +1411,7 @@ static vm_fault_t dax_fault_actor(struct vm_fault *vmf, pfn_t *pfnp, loff_t pos = (loff_t)xas->xa_offset << PAGE_SHIFT; bool write = vmf->flags & FAULT_FLAG_WRITE; bool sync = dax_fault_is_synchronous(flags, vmf->vma, iomap); + unsigned int insert_flags = 0; vm_fault_t ret = 0; int err = 0; pfn_t pfn; @@ -1426,8 +1435,14 @@ static vm_fault_t dax_fault_actor(struct vm_fault *vmf, pfn_t *pfnp, if (err) goto error_fault; - entry = dax_insert_entry(xas, mapping, vmf, entry, pfn, 0, - 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, 0, insert_flags); if (write && srcmap->addr != iomap->addr) { err = dax_iomap_cow_copy(pos, size, size, srcmap, kaddr, false); @@ -1571,8 +1586,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); -- 2.30.1