From patchwork Wed Jul 11 05:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10518775 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 7597B6032C for ; Wed, 11 Jul 2018 05:25:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6783F28DAA for ; Wed, 11 Jul 2018 05:25:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BCC128DBF; Wed, 11 Jul 2018 05:25:00 +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 014A628DAA for ; Wed, 11 Jul 2018 05:24:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCADC6B000D; Wed, 11 Jul 2018 01:24:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B7B9B6B000E; Wed, 11 Jul 2018 01:24:57 -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 A93286B0010; Wed, 11 Jul 2018 01:24:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 6A8986B000D for ; Wed, 11 Jul 2018 01:24:57 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id f5-v6so13959394plf.18 for ; Tue, 10 Jul 2018 22:24:57 -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=BpyorMuohQHKf3eHa+nEkUkvpbO8Tv95Y1J48qvbLYPnpYD6c2UrZT/ui6WdyU81Km TT2onaEiAW82poDN7FK6MSw0CxFX1PR9uuBNPSTG3cnhQqlBNZZ4KR8hfBI7tVCSJ4Nt cBvvBAQbxwosT2WMpRmOpQtk+eXRZwFyMRI4lc8Hjp3LMlQNWi3XNmfpAGp2pVNENmPs Hza9r5kAIGex/jpaF9MPj/FpsHJSZenhq/Zn7VRKuD17vdtCAw5s6Uz1E1MVGwSHQvnj 2wS6m2QKTdl1Vd18RFnxJ7ApWIWlHp97fykGfVPfG0p6fY0RsYL2IhbmJ0wx0O1l+o75 kdoA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 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: APt69E1vYCr5kvceV3fhchSV0j+aQ8IQg9liDH/+SX/KDsU+IRsVvnLP xWdSKA8LF5bgvsZ+lD3VGj/EtV73A4JUzmlV+oXE3OF3lHzTR7vDhPG7HvAuk1EmLodnZustqpV lJHswMLtPtH8rj1JyKdkIFfPK3Bw4W8rp1dLlTSU9OslmYC6fVk1MXmGk1t+Nd2FJhQ== X-Received: by 2002:a63:b047:: with SMTP id z7-v6mr25492226pgo.335.1531286697131; Tue, 10 Jul 2018 22:24:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcb6yjZW5TZ/jQKSwoO85zALFkUEjcfis1jODEqhqUDIUxAgJ5YDX3qG/NYnZ6mV2V/jKz0 X-Received: by 2002:a63:b047:: with SMTP id z7-v6mr25492206pgo.335.1531286696436; Tue, 10 Jul 2018 22:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531286696; cv=none; d=google.com; s=arc-20160816; b=G8++lG49NMTKR1mMpNCZH3CfoTGpJkZl0rh+YXlIzztyOeh3eKWWnmmH1d0stVfPKQ 9BsHk+Dv2ISuZXYq8dF0G+37rBWVqiKp7Y8P/Rl1LC+4rsS2l2izMef95XMLbw1q6SrF vQ0siwRHg+i+o0Tre6C8vaqbLDqE8+A9FAgqTEhKbrLBHGFTyDSfmj2Rx9yTNy1mBum9 71A+/jnKcQUitjy+EBHCSwDIfNjpOoEjW/CQJYe32z+kV2yLgTTxHXn9+6aZjw/xqHTq Bun2Ec84NpWwEUh0r/cL6yMESMl8IfN+1cjDgIJs7d4AQhyDOgpRj5t1G/C4dJTqyb5O iPMA== 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=MMu7kkoaZNMEeuwL1+G4AiOUj+vYC9OP1+wteaalKJG4NNmpWve5WilSPgl1LE4pZN DxiDzpqisHsYQ3+YS1KhWP9sM96CTd6jcvsNfT13Aj8fJ2PXoa0BYMH0Hd6ORPk9nGaf bm/aNkvlXUQrUpZQ79Hoy5CvdvvLacUseKgj7Fqys9C3j+E4oYRuGXaXxZGBxKkcaaLD wfGqRAB5ux0QOTlrr91EH1jF2VoMhGK4bo/QLAKMJcBTWHLgwmlBdSgoB6SgvY0USYzA VLQD2RSxSrooeUGNSnJp1w7U1ljbVwC+p4z0p3SPUf471k3N9EZW5z3PU80YRwO1ULLk qoNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id f12-v6si10071680pgg.653.2018.07.10.22.24.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jul 2018 22:24:56 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 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 orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2018 22:24:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,337,1526367600"; d="scan'208";a="55976090" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga008.jf.intel.com with ESMTP; 10 Jul 2018 22:24:55 -0700 Subject: [PATCH v4 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: Tue, 10 Jul 2018 22:14:58 -0700 Message-ID: <153128609821.2928.3933342405618012271.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153128607743.2928.4465435789810433432.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153128607743.2928.4465435789810433432.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;