From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFFB2C433E4 for ; Fri, 7 Aug 2020 13:14:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 72E462224D for ; Fri, 7 Aug 2020 13:14:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72E462224D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1FEDA8D00A7; Fri, 7 Aug 2020 09:14:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D7D38D003B; Fri, 7 Aug 2020 09:14:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 116D58D00A7; Fri, 7 Aug 2020 09:14:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id ED53F8D003B for ; Fri, 7 Aug 2020 09:13:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A0FF9181AEF10 for ; Fri, 7 Aug 2020 13:13:59 +0000 (UTC) X-FDA: 77123815398.10.cork65_330fd8426fc0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id 7E1FD16A07F for ; Fri, 7 Aug 2020 13:13:59 +0000 (UTC) X-HE-Tag: cork65_330fd8426fc0 X-Filterd-Recvd-Size: 5880 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Fri, 7 Aug 2020 13:13:58 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.75,445,1589212800"; d="scan'208";a="97774925" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Aug 2020 21:13:48 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 6F1EC4CE34F1; Fri, 7 Aug 2020 21:13:44 +0800 (CST) Received: from G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 7 Aug 2020 21:13:40 +0800 Received: from localhost.localdomain (10.167.225.141) by G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 7 Aug 2020 21:13:38 +0800 From: Shiyang Ruan To: , , CC: , , , , , , , , , Goldwyn Rodrigues Subject: [RFC PATCH 3/8] fsdax: introduce dax_copy_edges() for COW Date: Fri, 7 Aug 2020 21:13:31 +0800 Message-ID: <20200807131336.318774-4-ruansy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200807131336.318774-1-ruansy.fnst@cn.fujitsu.com> References: <20200807131336.318774-1-ruansy.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-yoursite-MailScanner-ID: 6F1EC4CE34F1.ACA37 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com X-Rspamd-Queue-Id: 7E1FD16A07F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add address output in dax_iomap_pfn() in order to perform a memcpy() in C= oW case. Since this function both output address and pfn, rename it to dax_iomap_direct_access(). dax_copy_edges() is a helper functions performs a copy from one part of the device to another for data not page aligned. Signed-off-by: Goldwyn Rodrigues Signed-off-by: Shiyang Ruan --- fs/dax.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 47380f75ef38..308678c58d4d 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1043,8 +1043,8 @@ static sector_t dax_iomap_sector(struct iomap *ioma= p, loff_t pos) return (iomap->addr + (pos & PAGE_MASK) - iomap->offset) >> 9; } =20 -static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size, - pfn_t *pfnp) +static int dax_iomap_direct_access(struct iomap *iomap, loff_t pos, size= _t size, + pfn_t *pfnp, void **addr) { const sector_t sector =3D dax_iomap_sector(iomap, pos); pgoff_t pgoff; @@ -1055,12 +1055,14 @@ static int dax_iomap_pfn(struct iomap *iomap, lof= f_t pos, size_t size, if (rc) return rc; id =3D dax_read_lock(); - length =3D dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size), - NULL, pfnp); + length =3D dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size), add= r, + pfnp); if (length < 0) { rc =3D length; goto out; } + if (!pfnp) + goto out_check_addr; rc =3D -EINVAL; if (PFN_PHYS(length) < size) goto out; @@ -1070,11 +1072,59 @@ static int dax_iomap_pfn(struct iomap *iomap, lof= f_t pos, size_t size, if (length > 1 && !pfn_t_devmap(*pfnp)) goto out; rc =3D 0; + +out_check_addr: + if (!addr) + goto out; + if (!*addr) + rc =3D -EFAULT; out: dax_read_unlock(id); return rc; } =20 +/* + * dax_copy_edges - Copies the part of the pages not included in + * the write, but required for CoW because + * offset/offset+length are not page aligned. + */ +static int dax_copy_edges(loff_t pos, loff_t length, struct iomap *srcma= p, + void *daddr, bool pmd) +{ + size_t page_size =3D pmd ? PMD_SIZE : PAGE_SIZE; + loff_t offset =3D pos & (page_size - 1); + size_t size =3D ALIGN(offset + length, page_size); + loff_t end =3D pos + length; + loff_t pg_end =3D round_up(end, page_size); + void *saddr =3D 0; + int ret =3D 0; + + ret =3D dax_iomap_direct_access(srcmap, pos, size, NULL, &saddr); + if (ret) + return ret; + /* + * Copy the first part of the page + * Note: we pass offset as length + */ + if (offset) { + if (saddr) + ret =3D memcpy_mcsafe(daddr, saddr, offset); + else + memset(daddr, 0, offset); + } + + /* Copy the last part of the range */ + if (end < pg_end) { + if (saddr) + ret =3D memcpy_mcsafe(daddr + offset + length, + saddr + offset + length, pg_end - end); + else + memset(daddr + offset + length, 0, + pg_end - end); + } + return ret; +} + /* * The user has performed a load from a hole in the file. Allocating a = new * page in the file would cause excessive storage usage for workloads wi= th @@ -1394,7 +1444,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fau= lt *vmf, pfn_t *pfnp, count_memcg_event_mm(vma->vm_mm, PGMAJFAULT); major =3D VM_FAULT_MAJOR; } - error =3D dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn); + error =3D dax_iomap_direct_access(&iomap, pos, PAGE_SIZE, &pfn, + NULL); if (error < 0) goto error_finish_iomap; =20 @@ -1612,7 +1663,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fau= lt *vmf, pfn_t *pfnp, =20 switch (iomap.type) { case IOMAP_MAPPED: - error =3D dax_iomap_pfn(&iomap, pos, PMD_SIZE, &pfn); + error =3D dax_iomap_direct_access(&iomap, pos, PMD_SIZE, &pfn, + NULL); if (error < 0) goto finish_iomap; =20 --=20 2.27.0