From patchwork Mon Jul 16 17:01:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10527277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19E8B60348 for ; Mon, 16 Jul 2018 17:11:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0425B28D83 for ; Mon, 16 Jul 2018 17:11:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED06028D8F; Mon, 16 Jul 2018 17:11:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7134828D80 for ; Mon, 16 Jul 2018 17:11:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 399C96B0279; Mon, 16 Jul 2018 13:11:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 34A026B027A; Mon, 16 Jul 2018 13:11:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EB0B6B027B; Mon, 16 Jul 2018 13:11:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id CEC3E6B0279 for ; Mon, 16 Jul 2018 13:11:24 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id e7-v6so5425936pfe.10 for ; Mon, 16 Jul 2018 10:11:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=tJmMKYXPn1EYAOv7aaafMuarfGiP4UKgQ7/JSySdPMk=; b=bPxyZiT2YlT/DYngWCnQ2jr5UQMquSBHmmMX4/G6xx/NhiL41nHlMkPUa+D3gii2L/ b4mB1svSbhsm051x9eUUmvJbRFiEyvUo8y7wuzeSDmO0j/uySDbEzycT8/RUZskRteFB pG4RVS+r/0k0UT8LCPuO4W53sHaFi64rVVwVGhm1eDUarRZiuujmgYHRMy2QHDPxyxzr dt76XGYOTNUj/19kPO2V12wNHv9Cmhcl8IoUwcRDsRMOEn5pCgMah9y4ICRqfzMYAjFf VjXmVHGgE4U6vFXA05P1Ne9Q5s0QF3dasOsGZCdCb+0iVYPE2ZX6fE11b3pxlNvQ0r1M 0P+w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlHwDpFY62xiDjkXNUlegOYA7fbfaf928A4l2QzS2/bsJpPXVtZM AceSnpnwFc0L/++mYRx8bkGB2GTsvHCxNnFdzFAOD/OBvYxAkgeDRo9LofRspOtBBSxCshq3fiq 71w27di1rfEvlGFy9AzmFl9A8bRN7gseyZwSVrl65eZJWaJAyT3DmGF93/xVAO5d3Ng== X-Received: by 2002:a62:a119:: with SMTP id b25-v6mr18588626pff.163.1531761084526; Mon, 16 Jul 2018 10:11:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdCvmu2mUW8GMKFHRieSw+yfqK7XkibpUXL3+c3cEpnZtX2c+AK681L6BEPmH2nIrBKL3Bu X-Received: by 2002:a62:a119:: with SMTP id b25-v6mr18588572pff.163.1531761083788; Mon, 16 Jul 2018 10:11:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531761083; cv=none; d=google.com; s=arc-20160816; b=c2g5Okjfs8qsEX4t/T7W6tdpyddAmQN81eTUUAYHIO3TUh1mmq2PXh6IpX0TaALEku agd8JEEsmg9hZ7fAiS70MLx4043+tNOzyeEo2ie2YdeGDmBmFIS+YObPK3KWMPMue3Md T8IrMdx+Lvhh6bdGjgjnBwjZvrq9QIEKgAV85rF78SpLS0BYOU9+FowFaXLlkA6jBKSK z8ZbfrUXSGcT4hmiKdO6DxwOjvlVzGrJZ9vkxE8AzohwvMfQ5qbKZlrXcuDWRj9W1+dA utNuABKi3Pvi7KH6WRk/UeN2zU8RSd4coSIe8N2tHHAV+HaNOsRSXurJxDYwOFGrfrlJ sWMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject :arc-authentication-results; bh=tJmMKYXPn1EYAOv7aaafMuarfGiP4UKgQ7/JSySdPMk=; b=fhx0x07iJKcnR0nRnp58bOUQz5/5zFF19KuKmzVL5TaPjdc908IPepF+NEMXmquGkM 5mb+epulA6+2sZn+ZS9A+OvZoW/KRTrMybSxFPAigEsQq1YWH14BKnUz3puWT61AxTzj 9BqKZlri0xPBmB+9ytZkRvfCLRy+FnkGIm9OCaZbU0cvIkPwZ8gwGfwHtkjBKL4AHz9e s9G/a55W+PLeqptKpqdzmZdkvl+wjq/VkLQELtWvvKYRIN7TSPmMuvHRPs0LSoUynwqY /2LRBi3hux/ocWo+XV0T6NO5k/sxCF1BobxadtvsXFgsYbCldOe+zW3Df3RVSO7PQmgL mb7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id j189-v6si22800381pgd.498.2018.07.16.10.11.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 10:11:23 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2018 10:11:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,362,1526367600"; d="scan'208";a="71837080" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004.fm.intel.com with ESMTP; 16 Jul 2018 10:11:22 -0700 Subject: [PATCH v2 12/14] libnvdimm, pmem: Initialize the memmap in the background From: Dan Williams To: akpm@linux-foundation.org Cc: Ross Zwisler , Vishal Verma , Dave Jiang , hch@lst.de, linux-mm@kvack.org, jack@suse.cz, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Mon, 16 Jul 2018 10:01:25 -0700 Message-ID: <153176048517.12695.1997102156305453692.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153176041838.12695.3365448145295112857.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153176041838.12695.3365448145295112857.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP Arrange for the pmem driver to call memmap_sync() when it is asked to produce a valid pfn. The infrastructure is housed in the 'nd_pfn' device which implies that the async init support only exists for platform defined persistent memory, not the legacy / debug memmap=ss!nn facility. Another reason to restrict the capability to the 'nd_pfn' device case is that nd_pfn devices have sysfs infrastructure to communicate the memmap initialization state to userspace. The sysfs publication of memmap init state is saved for a later patch. Cc: Ross Zwisler Cc: Vishal Verma Cc: Dave Jiang Signed-off-by: Dan Williams --- drivers/nvdimm/nd.h | 2 ++ drivers/nvdimm/pmem.c | 16 ++++++++++++---- drivers/nvdimm/pmem.h | 1 + tools/testing/nvdimm/pmem-dax.c | 7 ++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 32e0364b48b9..ee4f76fb0cb5 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -12,6 +12,7 @@ */ #ifndef __ND_H__ #define __ND_H__ +#include #include #include #include @@ -208,6 +209,7 @@ struct nd_pfn { unsigned long npfns; enum nd_pfn_mode mode; struct nd_pfn_sb *pfn_sb; + struct memmap_async_state async; struct nd_namespace_common *ndns; }; diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index c430536320a5..a1158181adc2 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -228,8 +229,13 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, PFN_PHYS(nr_pages)))) return -EIO; *kaddr = pmem->virt_addr + offset; - if (pfn) + if (pfn) { + struct dev_pagemap *pgmap = &pmem->pgmap; + struct memmap_async_state *async = pgmap->async; + *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); + memmap_sync(*pfn, nr_pages, async); + } /* * If badblocks are present, limit known good range to the @@ -310,13 +316,15 @@ static void fsdax_pagefree(struct page *page, void *data) wake_up_var(&page->_refcount); } -static int setup_pagemap_fsdax(struct device *dev, struct dev_pagemap *pgmap) +static int setup_pagemap_fsdax(struct device *dev, struct dev_pagemap *pgmap, + struct memmap_async_state *async) { dev_pagemap_get_ops(); if (devm_add_action_or_reset(dev, pmem_release_pgmap_ops, pgmap)) return -ENOMEM; pgmap->type = MEMORY_DEVICE_FS_DAX; pgmap->page_free = fsdax_pagefree; + pgmap->async = async; return 0; } @@ -379,7 +387,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pfn_flags = PFN_DEV; pmem->pgmap.ref = &q->q_usage_counter; if (is_nd_pfn(dev)) { - if (setup_pagemap_fsdax(dev, &pmem->pgmap)) + if (setup_pagemap_fsdax(dev, &pmem->pgmap, &nd_pfn->async)) return -ENOMEM; addr = devm_memremap_pages(dev, &pmem->pgmap, pmem_freeze_queue); @@ -393,7 +401,7 @@ static int pmem_attach_disk(struct device *dev, } else if (pmem_should_map_pages(dev)) { memcpy(&pmem->pgmap.res, &nsio->res, sizeof(pmem->pgmap.res)); pmem->pgmap.altmap_valid = false; - if (setup_pagemap_fsdax(dev, &pmem->pgmap)) + if (setup_pagemap_fsdax(dev, &pmem->pgmap, NULL)) return -ENOMEM; addr = devm_memremap_pages(dev, &pmem->pgmap, pmem_freeze_queue); diff --git a/drivers/nvdimm/pmem.h b/drivers/nvdimm/pmem.h index a64ebc78b5df..93d226ea1006 100644 --- a/drivers/nvdimm/pmem.h +++ b/drivers/nvdimm/pmem.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef __NVDIMM_PMEM_H__ #define __NVDIMM_PMEM_H__ +#include #include #include #include diff --git a/tools/testing/nvdimm/pmem-dax.c b/tools/testing/nvdimm/pmem-dax.c index d4cb5281b30e..63151b75615c 100644 --- a/tools/testing/nvdimm/pmem-dax.c +++ b/tools/testing/nvdimm/pmem-dax.c @@ -42,8 +42,13 @@ long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, } *kaddr = pmem->virt_addr + offset; - if (pfn) + if (pfn) { + struct dev_pagemap *pgmap = &pmem->pgmap; + struct memmap_async_state *async = pgmap->async; + *pfn = phys_to_pfn_t(pmem->phys_addr + offset, pmem->pfn_flags); + memmap_sync(*pfn, nr_pages, async); + } /* * If badblocks are present, limit known good range to the