From patchwork Thu Dec 7 15:08:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10099369 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 9A42A60325 for ; Thu, 7 Dec 2017 15:08:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86ED7294AF for ; Thu, 7 Dec 2017 15:08:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A5B129722; Thu, 7 Dec 2017 15:08:50 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D2B37294AF for ; Thu, 7 Dec 2017 15:08:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E51752218E957; Thu, 7 Dec 2017 07:04:15 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=batv+66a8023ffb5c76db3fb6+5219+infradead.org+hch@bombadil.srs.infradead.org; receiver=linux-nvdimm@lists.01.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id DC0342217CE54 for ; Thu, 7 Dec 2017 07:04:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gvpDkAAN9TP5/A1YFLPEuHBpn6UHvkUJqcYP/7O1AMA=; b=FPBhbTrrt8RPKvnwHtucL++dm hH8C43FnOfJthvX4x9H5e2nLHt0y38hd9KFG6hguPD3QxtkbTXi97bU2mNUfAShGukntoWHJAx3sg /Tb8hS6V95XuNG4Lcu+TqoVPo9bojqZAWLSJtzlxhE5c6G4LUog/YCriSdLmEebbepBKZD6e6r4n8 Km3F2brXHppo8nSwwFn8NCFfW/Ngy68EFidEd0NYXngZxKkQiZe0jF3vHJsZJ/0jJD9qCDKs3vuBZ OqvoEAEA3Cgqf8nV3MEKzn9AgqihhVQxTTPOT/29mnmSl1gaNOfy+iuDG69RSmrk7HVdWn/9q8Aud BJ6e0FWjg==; Received: from [38.126.112.130] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1eMxmz-0007Ya-M7; Thu, 07 Dec 2017 15:08:41 +0000 From: Christoph Hellwig To: Dan Williams Subject: [PATCH 05/14] mm: better abstract out dev_pagemap offset calculation Date: Thu, 7 Dec 2017 07:08:31 -0800 Message-Id: <20171207150840.28409-6-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207150840.28409-1-hch@lst.de> References: <20171207150840.28409-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , linux-nvdimm@lists.01.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Add a helper that looks up the altmap (or later dev_pagemap) and returns the offset. Signed-off-by: Christoph Hellwig Reviewed-by: Logan Gunthorpe --- arch/powerpc/mm/mem.c | 9 +++------ arch/x86/mm/init_64.c | 6 +----- include/linux/memremap.h | 8 ++++++-- kernel/memremap.c | 21 +++++++++++++-------- mm/memory_hotplug.c | 7 +------ 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index 4362b86ef84c..c7cf396fdabc 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -152,18 +152,15 @@ int arch_remove_memory(u64 start, u64 size) { unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; - struct vmem_altmap *altmap; struct page *page; int ret; /* - * If we have an altmap then we need to skip over any reserved PFNs - * when querying the zone. + * If we have a device page map then we need to skip over any reserved + * PFNs when querying the zone. */ page = pfn_to_page(start_pfn); - altmap = to_vmem_altmap((unsigned long) page); - if (altmap) - page += vmem_altmap_offset(altmap); + page += dev_pagemap_offset(page); ret = __remove_pages(page_zone(page), start_pfn, nr_pages); if (ret) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index f5e51b941d19..4f79ee1ef501 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1134,14 +1134,10 @@ int __ref arch_remove_memory(u64 start, u64 size) unsigned long start_pfn = start >> PAGE_SHIFT; unsigned long nr_pages = size >> PAGE_SHIFT; struct page *page = pfn_to_page(start_pfn); - struct vmem_altmap *altmap; struct zone *zone; int ret; - /* With altmap the first mapped page is offset from @start */ - altmap = to_vmem_altmap((unsigned long) page); - if (altmap) - page += vmem_altmap_offset(altmap); + page += dev_pagemap_offset(page); zone = page_zone(page); ret = __remove_pages(zone, start_pfn, nr_pages); WARN_ON_ONCE(ret); diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 054397a9414f..d221f4c0ccac 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -26,8 +26,6 @@ struct vmem_altmap { unsigned long alloc; }; -unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); - #ifdef CONFIG_ZONE_DEVICE struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start); #else @@ -140,6 +138,7 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn, static inline bool is_zone_device_page(const struct page *page); int dev_pagemap_add_pages(unsigned long phys_start_pfn, unsigned nr_pages); bool dev_pagemap_free_pages(struct page *page, unsigned nr_pages); +unsigned long dev_pagemap_offset(struct page *page); #else static inline void *devm_memremap_pages(struct device *dev, struct resource *res, struct percpu_ref *ref, @@ -170,6 +169,11 @@ static inline bool dev_pagemap_free_pages(struct page *page, unsigned nr_pages) { return false; } + +static inline unsigned long dev_pagemap_offset(struct page *page) +{ + return 0; +} #endif /* CONFIG_ZONE_DEVICE */ #if defined(CONFIG_DEVICE_PRIVATE) || defined(CONFIG_DEVICE_PUBLIC) diff --git a/kernel/memremap.c b/kernel/memremap.c index c86bcd63e2cd..91a5fc1146b5 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -248,6 +248,17 @@ int device_private_entry_fault(struct vm_area_struct *vma, EXPORT_SYMBOL(device_private_entry_fault); #endif /* CONFIG_DEVICE_PRIVATE */ +static unsigned long __dev_pagemap_offset(struct vmem_altmap *pgmap) +{ + /* number of pfns from base where pfn_to_page() is valid */ + return pgmap ? (pgmap->reserve + pgmap->free) : 0; +} + +unsigned long dev_pagemap_offset(struct page *page) +{ + return __dev_pagemap_offset(to_vmem_altmap((uintptr_t)page)); +} + static void pgmap_radix_release(struct resource *res) { unsigned long pgoff, order; @@ -269,7 +280,7 @@ static unsigned long pfn_first(struct page_map *page_map) pfn = res->start >> PAGE_SHIFT; if (altmap) - pfn += vmem_altmap_offset(altmap); + pfn += __dev_pagemap_offset(altmap); return pfn; } @@ -464,12 +475,6 @@ void *devm_memremap_pages(struct device *dev, struct resource *res, } EXPORT_SYMBOL(devm_memremap_pages); -unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) -{ - /* number of pfns from base where pfn_to_page() is valid */ - return altmap->reserve + altmap->free; -} - int dev_pagemap_add_pages(unsigned long phys_start_pfn, unsigned nr_pages) { struct vmem_altmap *pgmap; @@ -479,7 +484,7 @@ int dev_pagemap_add_pages(unsigned long phys_start_pfn, unsigned nr_pages) return 0; if (pgmap->base_pfn != phys_start_pfn || - vmem_altmap_offset(pgmap) > nr_pages) { + __dev_pagemap_offset(pgmap) > nr_pages) { pr_warn_once("memory add fail, invalid map\n"); return -EINVAL; } diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 3e7c728f97e3..a7a719f057dc 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -565,12 +565,7 @@ int __remove_pages(struct zone *zone, unsigned long phys_start_pfn, /* In the ZONE_DEVICE case device driver owns the memory region */ if (is_dev_zone(zone)) { - struct page *page = pfn_to_page(phys_start_pfn); - struct vmem_altmap *altmap; - - altmap = to_vmem_altmap((unsigned long) page); - if (altmap) - map_offset = vmem_altmap_offset(altmap); + map_offset = dev_pagemap_offset(pfn_to_page(phys_start_pfn)); } else { resource_size_t start, size;