From patchwork Tue Sep 25 06:15:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10613435 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 3C0C114DA for ; Tue, 25 Sep 2018 06:30:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2617B29895 for ; Tue, 25 Sep 2018 06:30:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A33A298A5; Tue, 25 Sep 2018 06:30:38 +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 9948929895 for ; Tue, 25 Sep 2018 06:30:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B93478E0067; Tue, 25 Sep 2018 02:30:36 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B1BFC8E0041; Tue, 25 Sep 2018 02:30:36 -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 9E5DE8E0067; Tue, 25 Sep 2018 02:30:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id 583D48E0041 for ; Tue, 25 Sep 2018 02:30:36 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id 11-v6so4302665pgd.1 for ; Mon, 24 Sep 2018 23:30:36 -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=gIKTe070nt33soZdk3FNeSDX9JCTHChbP/lTcEMh/Qc=; b=NXT+7fCaBY8wgGsGe+FoJdSLWplScXXHuNywR1+LBnWP8H+BxcYu/EOYIYLZ6T2bSq U0otJIrAerlgaqC7Nsk3x9zYqSuJPdtUfg90vqrKhUGonkblxN8PAkzou3kwA9pqhnVs rzK9SQXRi+I1mJsUlX8sI9LP9aSmnVMh8wGex/ydE+DS1IHFqRHwT7YYhAHYBp6s2meb R4G0hdHS3fsYiVYXjxmOns5xI5t8tb/SRC+mo4blRWqkIkjRdR66ekDfOdnTjuv5ycDN QmCTtnZRzNiblg5DSEmuJOH2AzzdoLtUra4Ztoj5BWPwPeNSd3Zq6aV/x06YoY1ziZEw oUIg== 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: ABuFfoiKAF88PX5kUBhMa6BaECOXYYmO76j1OGBNILboI+p/y2oxn+D2 cXZLUl0qGlcSqMJhoxKIVAoE5SBulQzijcjJ+lQfWbHJF/a7TYW8Mn7HCT7xe2Mf0QL4fSy4+r8 g1p0G+o61uWZw+ozhko2j4A9kkb4K1qOqd8zZ+JAl3lWjc39VachCzoB36wHR5s6lRg== X-Received: by 2002:a63:f51:: with SMTP id 17-v6mr1929471pgp.100.1537857035982; Mon, 24 Sep 2018 23:30:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV62B8nUwLWl3d4/fsr8ToDsfcoCb9vwxAkwyU2nDFAT6dkup0Kzsx1iYScXBpEFhcTCxIqGu X-Received: by 2002:a63:f51:: with SMTP id 17-v6mr1929409pgp.100.1537857035053; Mon, 24 Sep 2018 23:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537857035; cv=none; d=google.com; s=arc-20160816; b=P5YT6nOSgd4mtXQYG6O3/stEX+L9XN530k8/YfUtvwu9tAnlQHHTbPqso3R0bB1cZY ar5cejmFu0p3ug7/LeYl/bNUFF4cmD7V40cr9IUUwZjGcNqEPCb0bFe9jIU3et32cxrW E4iw58F33629COGZmEo/wfyE6qKdhOetr2/+6XC1HNiqWffSTKhGC9i9TWnkZjUlsIs6 W6wpJiL0C1f0Rpu2G238RsH49NIo3Flq8hdq8RyTS8B1Vix+rH4nSGdeg4OQHp2SaHag Tsdz0GLaaIJvn+V3cAXfNg44AY/aVQ6mURnlkC7y5fCH9nvlla0c8W4DwX6QnqKiZoxT tkzg== 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=gIKTe070nt33soZdk3FNeSDX9JCTHChbP/lTcEMh/Qc=; b=cT09b6Ln3yvn4ehRAf2SureuIUGrrmFNDQEKZMUtutfS1m/YqCqIBxgcuAFrmVDVWj L1j3lUFlQw+fbCfeBYo/z2wtozNeOvPEREj8a9OrWKXv/WZLCqu0DNR5ad9+ZfpGS2n5 rxO6RuyHmA78SNSxz1EOtNRWtyK1fD5uQGT6OhvwINbkfJcYuEflZ2MUtE6Z3j388Ypb MyDbXVYm5sgq8/theXIC5wszr7RHgvuSGAj+M4SfntEDgZ+hMoZr/Z1RBtjF3lAulxK5 VMfnsrRf5LbbRpprIPpKiMthR81LOVtQ5M3hUc/g1Medq1/WCQtNLlzEu7ob8C4w/Spn GcOA== 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 69-v6si1530356pla.505.2018.09.24.23.30.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 23:30:35 -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 fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Sep 2018 23:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,301,1534834800"; d="scan'208";a="89083355" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga002.fm.intel.com with ESMTP; 24 Sep 2018 23:27:03 -0700 Subject: [PATCH v6 4/7] mm, devm_memremap_pages: Add MEMORY_DEVICE_PRIVATE support From: Dan Williams To: akpm@linux-foundation.org Cc: =?utf-8?b?SsOpcsO0bWU=?= Glisse , Christoph Hellwig , Logan Gunthorpe , Logan Gunthorpe , alexander.h.duyck@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Mon, 24 Sep 2018 23:15:15 -0700 Message-ID: <153785611587.283091.3545117308977274134.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153785609460.283091.17422092801700439095.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153785609460.283091.17422092801700439095.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. Reviewed-by: Jérôme Glisse [jglisse: call move_pfn_range_to_zone for MEMORY_DEVICE_PRIVATE] Acked-by: Christoph Hellwig Reported-by: Logan Gunthorpe Reviewed-by: Logan Gunthorpe Signed-off-by: Dan Williams --- kernel/memremap.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index fe2a9cd0b9c1..6e32fe36b460 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); @@ -232,17 +238,40 @@ 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; + + /* + * 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 { + 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) { + struct zone *zone; + + zone = &NODE_DATA(nid)->node_zones[ZONE_DEVICE]; + move_pfn_range_to_zone(zone, align_start >> PAGE_SHIFT, + align_size >> PAGE_SHIFT, altmap); } - 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, - align_size >> PAGE_SHIFT, altmap); mem_hotplug_done(); if (error) goto err_add_memory;