From patchwork Thu Sep 13 02:22:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10598655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6855915E2 for ; Thu, 13 Sep 2018 02:34:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56F312992E for ; Thu, 13 Sep 2018 02:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B03929BB3; Thu, 13 Sep 2018 02:34:18 +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=ham 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 C48672992E for ; Thu, 13 Sep 2018 02:34:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1F498E0005; Wed, 12 Sep 2018 22:34:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ECDF78E0001; Wed, 12 Sep 2018 22:34:06 -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 DE4228E0005; Wed, 12 Sep 2018 22:34:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 9F2848E0001 for ; Wed, 12 Sep 2018 22:34:06 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id e8-v6so1934558plt.4 for ; Wed, 12 Sep 2018 19:34:06 -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=SGo2IAwqRk4co9gf20yhkPbTMH5IfgL39BU9td7HbqM=; b=QRhtJjrbYw7L7xNafSn0ZfS0pqrKRsBGfjZoV+4iR0inhQr5gZ21iSnFgOIrJEthn+ Oovafi3kW6CuJOcYMpmbis77um7jl9jtiN5f9M5iauLQhagiqyfsmu/6VmYV6CU0JIrO DM9sdBJxB5ag9B+GBcToBNIMRZLasLKJZUJrz92HRfhoJRExWsV0ABKSg2TjNhj+d9jM slmv056HO1PDuTklG2j5mQMjdGIJkYDjQUR2LMpdRUCAS4aLKkbJD8p0DJadFnT44rM8 ylbnLWCEMW95SR+ITsu0mGiRYOyo/6RR56uxvixwlsmJVrygC7CCCJsg01vRScR5NeTD QMcg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 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: APzg51A/bQiMSGpoPt8ZEip1n2nZJKwsskjAcnWIOoDsGQCO3IZ5GPB+ yYtbQ/FlbBnLH57LfmZbCFbmXORJV4MHG8EKjtP+m3wxIzR9f1s6GYofYblWaRWE7Z1L7NMX85H rHsFOZ03lgjOC5siM0Xregl8DIytERn3VZiVOfwjJbZ7fEWDCRSjeswa5C0P+x3Wrzg== X-Received: by 2002:a63:fa0c:: with SMTP id y12-v6mr5035541pgh.177.1536806046324; Wed, 12 Sep 2018 19:34:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZpIt4WXRRhHlr/Tv9XKhXFcAYQqxhvankrFOUM7pDDdbhpCw/Y4I0YSOzYL3JihOu4wAt7 X-Received: by 2002:a63:fa0c:: with SMTP id y12-v6mr5035511pgh.177.1536806045422; Wed, 12 Sep 2018 19:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536806045; cv=none; d=google.com; s=arc-20160816; b=nxOSitXRnJpcXD6/qFKvxlKTPPiGPwemb9cPN/6sibZiYYZEOBOg7UJsXFoaLJpvT2 uSy9LOfiwvNah0JMoN8EmFkD9yvNXWBAR9EwzNlKG6f40c2PR1rHDGUBhgM+EUoT6II/ BOU0d+ouILyHuk5PsB5ncDmb20CsReUc52MZYr/GkNqV+U7b/m4q1sX57kPxX5dnJ3Ni qrqESKdcIS8HlRPuu56OFQkVQMq4qgjGovvqFWaJJyZmXP6SdI3zsjEUKXT8+32uzfVE 7KkEijg7kTxW00/RWeG7s/550zghJxOjhw04UdOKriyVWu3tlfLieyQZseIEGg/N+90l mYxg== 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; bh=SGo2IAwqRk4co9gf20yhkPbTMH5IfgL39BU9td7HbqM=; b=REPF2OxtiRA2QUr66LaMELINmNTeaYnjDzRGRcqIYKxx6X9tv4JBT0DXQPFafopPOv nid89Yl2p7Hau2Gv8keqsVTSlzxNS04IGNzeCYhQcE6dmyeU0igqRPQZpnwKlr6U0tn8 1RUzKErDosK4BepdQf0YXNdeRNLPB3vjtJhoBwe/OLLpISJxbrWPuXrXAtSEAWYK60hb OufiAam/szFHkIIFSC9gz4IlhZAGALZ2BlwAGefc/CWTcNr6OKtfa/msdjJV8qQaHBjs bWWhp3ZMP7WbmucoAt+/B2vYSYJYinLsf7NuEviukfs9PcS6EsriOBBW5+UO89Ize0aA 2iDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id c126-v6si2721165pfa.130.2018.09.12.19.34.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 19:34:05 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 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 orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 19:34:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,367,1531810800"; d="scan'208";a="88310273" 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; 12 Sep 2018 19:34:04 -0700 Subject: [PATCH v5 4/7] mm, devm_memremap_pages: Add MEMORY_DEVICE_PRIVATE support From: Dan Williams To: akpm@linux-foundation.org Cc: Christoph Hellwig , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Logan Gunthorpe , Logan Gunthorpe , alexander.h.duyck@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Wed, 12 Sep 2018 19:22:22 -0700 Message-ID: <153680534246.453305.10522027577023444732.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153680531988.453305.8080706591516037706.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153680531988.453305.8080706591516037706.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 In preparation for consolidating all ZONE_DEVICE enabling via devm_memremap_pages(), teach it how to handle the constraints of MEMORY_DEVICE_PRIVATE ranges. Cc: Christoph Hellwig Cc: "Jérôme Glisse" Reported-by: Logan Gunthorpe Reviewed-by: Logan Gunthorpe Signed-off-by: Dan Williams Acked-by: Christoph Hellwig Reviewed-by: Jérôme Glisse Reported-by: Logan Gunthorpe Reviewed-by: Logan Gunthorpe Signed-off-by: Dan Williams --- kernel/memremap.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index ab5eb570d28d..3234a771e63a 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -132,9 +132,15 @@ static void devm_memremap_pages_release(void *data) - align_start; mem_hotplug_begin(); - arch_remove_memory(align_start, align_size, pgmap->altmap_valid ? - &pgmap->altmap : NULL); - kasan_remove_zero_shadow(__va(align_start), align_size); + if (pgmap->type == MEMORY_DEVICE_PRIVATE) { + pfn = align_start >> PAGE_SHIFT; + __remove_pages(page_zone(pfn_to_page(pfn)), pfn, + align_size >> PAGE_SHIFT, NULL); + } else { + arch_remove_memory(align_start, align_size, + pgmap->altmap_valid ? &pgmap->altmap : NULL); + kasan_remove_zero_shadow(__va(align_start), align_size); + } mem_hotplug_done(); untrack_pfn(NULL, PHYS_PFN(align_start), align_size); @@ -234,17 +240,38 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap, goto err_pfn_remap; mem_hotplug_begin(); - error = kasan_add_zero_shadow(__va(align_start), align_size); - if (error) { - mem_hotplug_done(); - goto err_kasan; - } - error = arch_add_memory(nid, align_start, align_size, altmap, false); - if (!error) - move_pfn_range_to_zone(&NODE_DATA(nid)->node_zones[ZONE_DEVICE], - align_start >> PAGE_SHIFT, + /* + * For device private memory we call add_pages() as we only need to + * allocate and initialize struct page for the device memory. More- + * over the device memory is un-accessible thus we do not want to + * create a linear mapping for the memory like arch_add_memory() + * would do. + * + * For all other device memory types, which are accessible by + * the CPU, we do want the linear mapping and thus use + * arch_add_memory(). + */ + if (pgmap->type == MEMORY_DEVICE_PRIVATE) { + error = add_pages(nid, align_start >> PAGE_SHIFT, + align_size >> PAGE_SHIFT, NULL, false); + } else { + struct zone *zone; + + error = kasan_add_zero_shadow(__va(align_start), align_size); + if (error) { + mem_hotplug_done(); + goto err_kasan; + } + + error = arch_add_memory(nid, align_start, align_size, altmap, + false); + zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE]; + if (!error) + move_pfn_range_to_zone(zone, align_start >> PAGE_SHIFT, align_size >> PAGE_SHIFT, altmap); + } + mem_hotplug_done(); if (error) goto err_add_memory;