Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp645486imu; Fri, 11 Jan 2019 06:43:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN7675WDjMdTtt4xGsXMeIMx7GbSj6zNDzTF8j0KvcYRFqDGnLsaX8+Av2VG+v+WFHwc1Ppg X-Received: by 2002:a17:902:5a86:: with SMTP id r6mr14384299pli.301.1547217835140; Fri, 11 Jan 2019 06:43:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547217835; cv=none; d=google.com; s=arc-20160816; b=VHYCZDBYF9KfeWl38HtC6nyWkLI9pzrqZH4Z9r7D5Oz2e0n2sXXGQAbYTqv8pZpiFV eeJSpOXvAKFNLx1jPnmfillBzCCEBPWHEH59t7HCduc+oe73BX1zyXe5HJtYsj12805D yrxNYCWuLys7226qDFX0OCxPP1y2JwheUUx0QdzxizlQ4+Zr6QtoeiLnRvFiIsa1DNe+ KnCUiGd6O6FK5Z/iObiWH/2UgfgAId5M38prvCIJ8i7oq1MtcNScJX1Sq8FyKZMc9Y2j ooqebtsR4qu4uylC8QdO7n7aW0L4nbx3oulPR+6nWxkR59nIPiY2bOIoBOxPGK4r1tPY ofMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k67JS0zGUTdVFjKitJIjjsyci/D/PP2t0BlLedBFRmA=; b=a4GabkQ0YxuH+ikCD0Gkh8+qoMPp0nBIknnoh9zHZzxWcF3E8eRYOaFhs2Fswyze3D MHm+C1bY+wf0hIuM7P7TUdRpw7k/yC9AffCx93ejUBGMB6R5P+7aIfrUOYo/JkVDnYzn +EY3VhbFUO9znbgunReLJh6bkTl9CQowlU87r6mTfLlx6xByJyw3FXEe3dPgTfIT5eBV e0XXlZmPruevrkUy8D/2hzNVR7EgAqXPEOFf+PSKLTXr/OY7FnTea2gbe5gw5RMFXafK wkt9r8ANwe/E/zqiXuvMoxpI0iYOx0AzZkwQhCSItnOUhW6aeUH3YhwoYwbOzRNajX+k nltQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jVN6tXTk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37si10368935plb.140.2019.01.11.06.43.40; Fri, 11 Jan 2019 06:43:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jVN6tXTk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403833AbfAKOlu (ORCPT + 99 others); Fri, 11 Jan 2019 09:41:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:34542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404035AbfAKOlr (ORCPT ); Fri, 11 Jan 2019 09:41:47 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D95262133F; Fri, 11 Jan 2019 14:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217706; bh=7ZiFMw1oWMcKo5JsQal74LgtHTjT4MssxNse+xau43o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jVN6tXTkUQ9K/phBm8jJ1Ik4UmIQNnIMx/RimirAocx2q6gWkWeiR9ZM1aUJ5k8uE bnUVJ7r5/AoOrQnYSD8tQEi/bxQ772Ew/2ED7m93muLC54tm3unABK1T2/4EAePqAa 08N9/slh5fjHzVCGKl58N5r40PvdYUoC6zRo8YIw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Christoph Hellwig , Logan Gunthorpe , Balbir Singh , Michal Hocko , Andrew Morton , Linus Torvalds Subject: [PATCH 4.20 12/65] mm, devm_memremap_pages: add MEMORY_DEVICE_PRIVATE support Date: Fri, 11 Jan 2019 15:14:58 +0100 Message-Id: <20190111131058.081682210@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131055.331350141@linuxfoundation.org> References: <20190111131055.331350141@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit 69324b8f48339de2f90fdf2f774687fc6c47629a upstream. In preparation for consolidating all ZONE_DEVICE enabling via devm_memremap_pages(), teach it how to handle the constraints of MEMORY_DEVICE_PRIVATE ranges. [jglisse@redhat.com: call move_pfn_range_to_zone for MEMORY_DEVICE_PRIVATE] Link: http://lkml.kernel.org/r/154275559036.76910.12434636179931292607.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams Reviewed-by: Jérôme Glisse Acked-by: Christoph Hellwig Reported-by: Logan Gunthorpe Reviewed-by: Logan Gunthorpe Cc: Balbir Singh Cc: Michal Hocko Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/memremap.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -98,9 +98,15 @@ static void devm_memremap_pages_release( - 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); @@ -187,17 +193,40 @@ void *devm_memremap_pages(struct device 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;