Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp295407imm; Thu, 5 Jul 2018 00:01:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpciK/+mT0OP13gjl9JIkWqqvR9j9Ik7WN7vhD2jDwXCpZvnlI7QRZuoMennW9RzLfVbXdGf X-Received: by 2002:a62:5582:: with SMTP id j124-v6mr5177425pfb.20.1530774093522; Thu, 05 Jul 2018 00:01:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530774093; cv=none; d=google.com; s=arc-20160816; b=qaT05zCxMYzghU5IcLPiX8FVb92kK3tRrLDKoNdgAOIAepaPs6ufiI0vJUJfmHWcxT 1X/9/H2WuYmoI9nPksUEEuzU/3Aj+fpEezCdjimZ4wO4GL3l8AQGqSX5SUlnCiUGnQji ZqSC+NeJ38uZ1ka/C6T7iTtpmGxligGwlLSoJyU33P7q97HnmDpZfz8Cm1dlCaLe0kdW qt/5TpHBmDSV41kOW1XE3oIsNBz4CquxYeXhk6CXirPuGZ8+iG6uhlA9fF9msaNmSx4y 8wAW5KZRyCtDXRckAOrF2gdQLmZ/tQhp5UmZ48S9PsUyAlC8nhvgmBcr48tavvKY2XH9 LXCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=FToy+dbWZrTIvFACi5xJ51HBAb7iF3l6xdgS2vcCHY8=; b=ohN6xRVqMgtmGnh0pEY9Mb6VQcl0gotYfnlQEPrXRN/9Wqh05T/ylM1oxaAKaQ2YYm E2sEPMHTQZR0pMJ9ZDhBpkDVRACTGyrKfQ0suGGqvVh3XhbEEUZOWba6wjptZimYdRYd vSBIDVsPzS1Ppwin3EPdonLtIZwkrlmiBsSw+RnA0gA41TEKfGCVxOF1dQdV9FNGpLhO uKItxkGEkVbg4Pw0OIMQCWQnWvCWSChbDXFAw3rMQHKNeR84fQhBCneov249+nErytHd jFWVqbLoWHshpQC9eqadr3fnH3cKoJdTAIsFzQfGHiwLhANuu2c0NTz4HeCCEKLvsywc 1kug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z2-v6si4681329pgp.681.2018.07.05.00.01.18; Thu, 05 Jul 2018 00:01:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753639AbeGEHAH (ORCPT + 99 others); Thu, 5 Jul 2018 03:00:07 -0400 Received: from mga04.intel.com ([192.55.52.120]:44111 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753620AbeGEHAF (ORCPT ); Thu, 5 Jul 2018 03:00:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jul 2018 00:00:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,311,1526367600"; d="scan'208";a="64302407" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga002.fm.intel.com with ESMTP; 05 Jul 2018 00:00:05 -0700 Subject: [PATCH 12/13] device-dax: Initialize the memmap in the background From: Dan Williams To: akpm@linux-foundation.org Cc: Dave Jiang , Ross Zwisler , Vishal Verma , hch@lst.de, linux-nvdimm@lists.01.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Wed, 04 Jul 2018 23:50:07 -0700 Message-ID: <153077340620.40830.18398670365019815228.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153077334130.40830.2714147692560185329.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153077334130.40830.2714147692560185329.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Given that the nd_dax shares device data with nd_pfn devices, arrange for the nd_pfn memmap_async_state instance to be registered by the devm_memremap_pages() call in the dax-pmem driver. Then, provide the generic dev_pagemap instance to the device-dax driver so that it can utilize memmap_sync() before dax-mapping pfns. Cc: Dave Jiang Cc: Ross Zwisler Cc: Vishal Verma Signed-off-by: Dan Williams --- drivers/dax/dax-private.h | 2 ++ drivers/dax/device-dax.h | 2 +- drivers/dax/device.c | 16 +++++++++++++++- drivers/dax/pmem.c | 5 ++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index b6fc4f04636d..35bda544b334 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -25,6 +25,7 @@ * @align: allocation and mapping alignment for child dax devices * @res: physical address range of the region * @pfn_flags: identify whether the pfns are paged back or not + * @pgmap: backing page map for the device address range */ struct dax_region { int id; @@ -35,6 +36,7 @@ struct dax_region { unsigned int align; struct resource res; unsigned long pfn_flags; + struct dev_pagemap *pgmap; }; /** diff --git a/drivers/dax/device-dax.h b/drivers/dax/device-dax.h index 688b051750bd..1a2da8072a6e 100644 --- a/drivers/dax/device-dax.h +++ b/drivers/dax/device-dax.h @@ -19,7 +19,7 @@ struct dax_region; void dax_region_put(struct dax_region *dax_region); struct dax_region *alloc_dax_region(struct device *parent, int region_id, struct resource *res, unsigned int align, - void *addr, unsigned long flags); + void *addr, struct dev_pagemap *pgmap, unsigned long flags); struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, int id, struct resource *res, int count); #endif /* __DEVICE_DAX_H__ */ diff --git a/drivers/dax/device.c b/drivers/dax/device.c index de2f8297a210..2802d21a6e26 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -10,6 +10,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ +#include #include #include #include @@ -101,7 +102,7 @@ static void dax_region_unregister(void *region) struct dax_region *alloc_dax_region(struct device *parent, int region_id, struct resource *res, unsigned int align, void *addr, - unsigned long pfn_flags) + struct dev_pagemap *pgmap, unsigned long pfn_flags) { struct dax_region *dax_region; @@ -130,6 +131,7 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id, dax_region->id = region_id; ida_init(&dax_region->ida); dax_region->align = align; + dax_region->pgmap = pgmap; dax_region->dev = parent; dax_region->base = addr; if (sysfs_create_groups(&parent->kobj, dax_region_attribute_groups)) { @@ -244,6 +246,15 @@ __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, return -1; } +static void dax_pfn_sync(struct dax_region *dax_region, pfn_t pfn, + unsigned long size) +{ + struct dev_pagemap *pgmap = dax_region->pgmap; + struct memmap_async_state *async = pgmap->async; + + memmap_sync(pfn, PHYS_PFN(size), async); +} + static int __dev_dax_pte_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) { struct device *dev = &dev_dax->dev; @@ -273,6 +284,7 @@ static int __dev_dax_pte_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) } pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); + dax_pfn_sync(dax_region, pfn, PAGE_SIZE); rc = vm_insert_mixed(vmf->vma, vmf->address, pfn); @@ -328,6 +340,7 @@ static int __dev_dax_pmd_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) } pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); + dax_pfn_sync(dax_region, pfn, PMD_SIZE); return vmf_insert_pfn_pmd(vmf->vma, vmf->address, vmf->pmd, pfn, vmf->flags & FAULT_FLAG_WRITE); @@ -379,6 +392,7 @@ static int __dev_dax_pud_fault(struct dev_dax *dev_dax, struct vm_fault *vmf) } pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); + dax_pfn_sync(dax_region, pfn, PUD_SIZE); return vmf_insert_pfn_pud(vmf->vma, vmf->address, vmf->pud, pfn, vmf->flags & FAULT_FLAG_WRITE); diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index 54cba20c8ba6..a05be7a03d02 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -11,6 +11,7 @@ * General Public License for more details. */ #include +#include #include #include #include @@ -110,6 +111,7 @@ static int dax_pmem_probe(struct device *dev) return rc; dax_pmem->pgmap.ref = &dax_pmem->ref; + dax_pmem->pgmap.async = &nd_pfn->async; addr = devm_memremap_pages(dev, &dax_pmem->pgmap, dax_pmem_percpu_kill); if (IS_ERR(addr)) return PTR_ERR(addr); @@ -123,7 +125,8 @@ static int dax_pmem_probe(struct device *dev) return -EINVAL; dax_region = alloc_dax_region(dev, region_id, &res, - le32_to_cpu(pfn_sb->align), addr, PFN_DEV|PFN_MAP); + le32_to_cpu(pfn_sb->align), addr, &dax_pmem->pgmap, + PFN_DEV|PFN_MAP); if (!dax_region) return -ENOMEM;