From patchwork Tue Jun 19 06:04:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10473325 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 CF2E160383 for ; Tue, 19 Jun 2018 06:15:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D064728C14 for ; Tue, 19 Jun 2018 06:15:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C546528C2B; Tue, 19 Jun 2018 06:15:08 +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 5335828C14 for ; Tue, 19 Jun 2018 06:15:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4CD26B000C; Tue, 19 Jun 2018 02:15:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DD5AB6B000D; Tue, 19 Jun 2018 02:15: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 BD7ED6B000E; Tue, 19 Jun 2018 02:15:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id 783D26B000C for ; Tue, 19 Jun 2018 02:15:06 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id o19-v6so6102444pgn.14 for ; Mon, 18 Jun 2018 23:15: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=rx6KAT4z9eNYiwjSQCyuQ5nopogxm3rTiTVeu2aYpnI=; b=pYOqhOH9UG9pgTkJIF3XAR+C6mfG2GTea1EqoYnfTIdrhfF7DNCB1okMX5gQ1ax51T TsNPTC4cnQ5NmdvFSc+TebRrsgqzpy/81JvMHz0FtazNPSmd7Llbvhnt0enKlDvdbKAe CgfUe/E+7+NJnD/LrWFQVD/QmIZH+kUcNfPS13eZ6gbI5/jf11Ypotzc6BNYtpBX9BcX 6z2bNpAmIscbVkC0o5XXwAjJLOQ46NkLSjwP2aUVF1Qz7rtrssw1imDcVtUoAvm6sggb P6QTuif4VtVLthcdcVS9lXt5IshJvgi0GHli7w/VZuaIEEVXDBRKkhKeKM3PddbqnClY +5CQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 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: APt69E3KNy65AhRryJhqijW71sQ/7ERkh6Q3dfXflKK8UIQOt8L8OrAg uz3mOC8mqyaxgV1fps9iFRcpaXuNxP9NC5wW5WMBuRLFensw4fMuo8M/EJGKDBjCL+wY0VhEvKm y+VbyaJKcaSCfmsLP+0gXk7pUY+Ngwdh8kwIeWu7A6pIrk2OdZSlNsOZLs09x50hrSQ== X-Received: by 2002:a17:902:bd8f:: with SMTP id q15-v6mr17591941pls.161.1529388906199; Mon, 18 Jun 2018 23:15:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK7mTYKBupz2CDd1B+JJdyNg6RaMm6BAR2eG6+HklmwjOAYCf+EpXh1Dbqe39tmyRT6BV2o X-Received: by 2002:a17:902:bd8f:: with SMTP id q15-v6mr17591910pls.161.1529388905546; Mon, 18 Jun 2018 23:15:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529388905; cv=none; d=google.com; s=arc-20160816; b=rT7h1NzTWBaR6ELejjybz2I3+VwKZriFejDak38HPxoHh0/AEISKohfnklTNjAxQNO yz+1ncNk4jXAphIT6NxND+73/kx066ttCo4nWo7jWBUr8zc4rAk/fvNombUGb62lObFn wbVF3PaOt1e/a2w9P91wRsGIWqPnJYaUTVC3EjDrFA2gHVdemHLpsMBlHw3vZJ5aAr92 1p6M6ua1JMau/ZjuZVXXEZLXlCPGw5C3xqX+CC9RaGWfOAPY290HcXR5EqQYWHPcLkja NZSU3rp7nolqT2tDBhbIhHWDos0QOE2aZB29xiUNFUcd2zgPOpV8/4oBFYwMSQGk5VBQ sWPw== 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=rx6KAT4z9eNYiwjSQCyuQ5nopogxm3rTiTVeu2aYpnI=; b=D+pxbBj5np5mxQhGhiOU9T5nLQTPZZ6g9l3TGMWVObuaVFMjJlF+rP/LESCrGnj46g ya8FfIaUbJOizMEr4t/MnJBEnVq2c3MVGdVqtyDEl3436K6hLMYdWLgv8+YKImpwurne YqAEHgRnGGl3dNZ9oG/nEbnaUKE7iyfdeUQKU1zQcqIW86zqKKOmV4C8gXeagvK3eBFO QOEzGly68ZVK1M5GrqO1n8pYjGVtm/9RiXD8VtyCCduEWabCJ7Gd8/3FjQvrL6RHGdmP WDgi5h654XIhWd1rRHJmSuLg6o3ggYRPg24Pou1ip6s1DtVweVtqoQO9UuF8RzTi/HhH aazA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id z10-v6si11873907pgv.1.2018.06.18.23.15.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 23:15:05 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 as permitted sender) client-ip=134.134.136.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.24 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 orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jun 2018 23:15:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,242,1526367600"; d="scan'208";a="50078936" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga007.jf.intel.com with ESMTP; 18 Jun 2018 23:14:56 -0700 Subject: [PATCH v3 4/8] 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 , linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 18 Jun 2018 23:04:59 -0700 Message-ID: <152938829976.17797.11139256105673921009.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152938827880.17797.439879736804291936.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152938827880.17797.439879736804291936.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 --- kernel/memremap.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index 92b8d7057321..16141b608b63 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -131,8 +131,13 @@ 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); + 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); mem_hotplug_done(); untrack_pfn(NULL, PHYS_PFN(align_start), align_size); @@ -216,11 +221,32 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap, goto err_pfn_remap; mem_hotplug_begin(); - 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 = 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;