From patchwork Tue Nov 20 23:12:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10691419 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 A70A313AD for ; Tue, 20 Nov 2018 23:25:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 943B92AC4E for ; Tue, 20 Nov 2018 23:25:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 888402AC59; Tue, 20 Nov 2018 23:25:25 +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 209B52AC4E for ; Tue, 20 Nov 2018 23:25:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E9A36B2288; Tue, 20 Nov 2018 18:25:24 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2985D6B228A; Tue, 20 Nov 2018 18:25:24 -0500 (EST) 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 188A66B228B; Tue, 20 Nov 2018 18:25:24 -0500 (EST) 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 C35D66B2288 for ; Tue, 20 Nov 2018 18:25:23 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id w19-v6so4271576plq.1 for ; Tue, 20 Nov 2018 15:25:23 -0800 (PST) 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=6XY87GS25BjorPYyiWdG92m1QskRUveSCPEiDigVeVQ=; b=J0EoBHcYlFjfdTrUytR7wmTnAYsk54m4FxrMpk/FqydHtax2fWbS9gh1ZBgZimxbz/ CnJKai7xW1r2C2gP1oPPNifs+jACVPPnMxnqQ6l8vLP0JOYQuJpSjavknf+2ZNdvm9ES lSZRkTXbWLl0PZlfVxiqx5HuzM8W7rY4M8LJTPXW8YDl6DBEvX47Oez7xkLhMkaUn7m6 7FiqA9qeWzuhmTAY/9P0CVSzjIZueS+umpLwfjW8wMymgwrx8pDt07rtHxhV1N5dCc1f 0QLaH+jh/5uzLp7YnWvilUEpv6pRdkf+tj5FjiKit99VmkjRPx7VjU5TA6YFFU1QeiTQ HepQ== 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: AA+aEWYXs9fHqyq4AwpUaAwAl4xPZ61N3tMr3R5El+43k8sXfGn/ygOw KEki3G4mZ4MMuy+rfsb6plb6wOX44UiwLV4Dmj/XczFYDsNCpNXGi1uQ3EeWswKlzstu5qfOPk0 Z+K9RN/PllfsUA9mQr91nv/MCTPKnoSmJkL/AHOJbDoQg2R5f5cUdA8a6KyA3txdlmA== X-Received: by 2002:a63:314c:: with SMTP id x73mr3790650pgx.323.1542756323432; Tue, 20 Nov 2018 15:25:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/WwFgmcE1R6Ufaz0fd78N2pcxXhJLkeMavzHhXHeuFYcukq1V3xlIwbW8vwJb6hGuOnURen X-Received: by 2002:a63:314c:: with SMTP id x73mr3790603pgx.323.1542756322506; Tue, 20 Nov 2018 15:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756322; cv=none; d=google.com; s=arc-20160816; b=f2ewQH5VJPiqmjSBW9Hgi2ybB1nmJM98FVcU7ddLZ6ECAjsrs2D1fKRkM/CLdIkdAX +ErbVDa1sRw3vzXwLiq01JsMHRWaqgGOwg4mffpq3ND4PALI5PvM82CGcbJ7EYAxNmfV NLcmKVkFZzAyc948lilf+K60gdhsq3ISEa5RNysRmXHtc5Xr5tnbGJ5kRsJo5PwQWlt7 iJxXERb1k4e1X0iocEpq1nB/f4sraDaWyYj8jPa34B3Lhm78GJfyIcTYb1CuawaMAcZ3 kE9FFk1z0yFUXC4mfXW0bF64EDLg5xLYbj9roevJOAkzM2KgGBRFvfkbeCinn5D23u/b /LXQ== 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=6XY87GS25BjorPYyiWdG92m1QskRUveSCPEiDigVeVQ=; b=PxFdyiNH3DGmWCm7yOTbwFHNDlxjHXpAxmz3PlQveTWtnxR7l0PEHX3lVPkJ2yVhhJ C3OtYoJ52F0F5kDY+kBn7YzovBkldIvZhSTEc0UwFBXHvg6HGdTcyq9dD0v2SX0+bpag 4cytumENZhO73qSCRiUERigsoFG/gPf5+Dd+v2uANtdSpAH0tgJPVnkW0VANqhRxiPjw D6Iu0HzBeWwxRPF4j1nN40h8lHPZlri0vZhGFwL0duxe1rGY6GCwOfmd0pmKvK7be+4I KnvZFz1rcWAx14OUmby1htBWETU2ZBPJOxA6cJ6//JN3iA20Iax1bVaPqjfttbI2TYJY 1l+Q== 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 bi6si28276432plb.279.2018.11.20.15.25.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:22 -0800 (PST) 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 fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 15:25:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="107958492" 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; 20 Nov 2018 15:25:21 -0800 Subject: [PATCH v8 1/7] mm, devm_memremap_pages: Mark devm_memremap_pages() EXPORT_SYMBOL_GPL From: Dan Williams To: akpm@linux-foundation.org Cc: Michal Hocko , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Christoph Hellwig , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:12:54 -0800 Message-ID: <154275557457.76910.16923571232582744134.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 devm_memremap_pages() is a facility that can create struct page entries for any arbitrary range and give drivers the ability to subvert core aspects of page management. Specifically the facility is tightly integrated with the kernel's memory hotplug functionality. It injects an altmap argument deep into the architecture specific vmemmap implementation to allow allocating from specific reserved pages, and it has Linux specific assumptions about page structure reference counting relative to get_user_pages() and get_user_pages_fast(). It was an oversight and a mistake that this was not marked EXPORT_SYMBOL_GPL from the outset. Again, devm_memremap_pagex() exposes and relies upon core kernel internal assumptions and will continue to evolve along with 'struct page', memory hotplug, and support for new memory types / topologies. Only an in-kernel GPL-only driver is expected to keep up with this ongoing evolution. This interface, and functionality derived from this interface, is not suitable for kernel-external drivers. Cc: Michal Hocko Cc: "Jérôme Glisse" Reviewed-by: Christoph Hellwig Signed-off-by: Dan Williams Acked-by: Michal Hocko --- kernel/memremap.c | 2 +- tools/testing/nvdimm/test/iomap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index 9eced2cc9f94..61dbcaa95530 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -233,7 +233,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) err_array: return ERR_PTR(error); } -EXPORT_SYMBOL(devm_memremap_pages); +EXPORT_SYMBOL_GPL(devm_memremap_pages); unsigned long vmem_altmap_offset(struct vmem_altmap *altmap) { diff --git a/tools/testing/nvdimm/test/iomap.c b/tools/testing/nvdimm/test/iomap.c index ff9d3a5825e1..ed18a0cbc0c8 100644 --- a/tools/testing/nvdimm/test/iomap.c +++ b/tools/testing/nvdimm/test/iomap.c @@ -113,7 +113,7 @@ void *__wrap_devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) return nfit_res->buf + offset - nfit_res->res.start; return devm_memremap_pages(dev, pgmap); } -EXPORT_SYMBOL(__wrap_devm_memremap_pages); +EXPORT_SYMBOL_GPL(__wrap_devm_memremap_pages); pfn_t __wrap_phys_to_pfn_t(phys_addr_t addr, unsigned long flags) { From patchwork Tue Nov 20 23:13:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10691425 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 E85E713AD for ; Tue, 20 Nov 2018 23:25:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D565E2AC4E for ; Tue, 20 Nov 2018 23:25:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9C1E2AC59; Tue, 20 Nov 2018 23:25:30 +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 62ABA2AC4E for ; Tue, 20 Nov 2018 23:25:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F1DE6B228A; Tue, 20 Nov 2018 18:25:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7A1416B228C; Tue, 20 Nov 2018 18:25:29 -0500 (EST) 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 6B8606B228D; Tue, 20 Nov 2018 18:25:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 252C26B228A for ; Tue, 20 Nov 2018 18:25:29 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id 89so4178574ple.19 for ; Tue, 20 Nov 2018 15:25:29 -0800 (PST) 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=aithbZX/wGkNS/bT9Ci8jPPiYgNzv1raTXrEw0rFYDo=; b=B060Xd+byzAxwY+9d3OjVLZSb7evfaQjl1MHeRXp39X6uWo3PLVHYy6oN74qes6MLE S+PP40qnwdsaKRyCtoQ+oz5INCSTrtfB8BLjNv39ChMiXxJo60DjsFq1WcqVV3XUThxD qs076YOi+SRc/vPrfgwn4uiHWuLpVktEm8Oud3JwLwtw8sNJvodd5W7XyZ3TJ9m0Urvj oNMY7qaZxbznElNmai7nPnjR0SUnYChPJ+SAamJepaxWE+ZUSYql/aHi6YMjE3nRPhZN 5MI8bEPpodDurZXu3XAOnO9LpH2FKHxC2zP2utjXOz34JMqj8qDu77UxBu2cYQDMW9Hv S47g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 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: AA+aEWZ1CKMxiiEyu85QeMl7NXE9Y8Xi6Rizio7U7RKgS1V3ZzqJJZ0r JmnoJegsBLD1/YWoUsRNNttaOMsCJXII+hAy5SzGogsKmu09L4gwBt6xW73Oeb/365q2ZKuB6pV 0YfgkgTEENRXWax5wY0Vvu5g6f3dldPjRaP54h26aa4BDaiRr1BSBioI+SN+VWhIXMQ== X-Received: by 2002:a17:902:8c98:: with SMTP id t24mr4315292plo.130.1542756328791; Tue, 20 Nov 2018 15:25:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/VHQGiIvbObGLKP5OTJBsvWAQ7lxo67s1Wi6bgncJWK6kvQdZrIPlHvc23R08ktDjjujAbw X-Received: by 2002:a17:902:8c98:: with SMTP id t24mr4315252plo.130.1542756328133; Tue, 20 Nov 2018 15:25:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756328; cv=none; d=google.com; s=arc-20160816; b=koo4fZA+Yqu5X44491QJRduvag+mfXGIXafpXCCdBXkd0/F3h+S1miMuNQ/UkGQ9ol FfOsUjqn6fRi4omKiVicobuGJlBFtlYF2jGw8vJEVEAQ4oSZVSKNgd+zbOOmekJd6m5u H/uBQI1zozsC4UelBYo2WGmIn4infm9k4Kvlci/ihwIKgdpfbj8vGu2xbpEhOA7EPzIb fw8Pvbr6VCj0cjoz75ot+3sADn34L+ddz2HSUgDZPSm5kzjzTLGtdsxTIuxGztmiDtYf uj2zIXhH787kRppfBZqm6z43Gkxi3ggFoy8+RZKO09z6o/cPxr2TkSIQRP2y8aBsT7jN JGFg== 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=aithbZX/wGkNS/bT9Ci8jPPiYgNzv1raTXrEw0rFYDo=; b=ulIG13hHiNXqy0bvEPzJz7DOeN4+UZ4VjbI/HLXdD83zv9BWDgYJowMPBd6qr/YWwA ehFUz2ZJt6I8Lzuzha2aNswhv3J0Ah97XMxVEeP9Sxmt0ZMMTUtdQHevaQZ1jvpjx1Y0 MsrqPag2/9vhLOlfk7QeDaB5Klg72wMib0WO/kGXLKggopol068Opj6LA6XFcYdyYjvi Sd4vqpjo12Wr/8u2zB+34q1cj1MOKF3lNldSw27p05K6asCdwioXgfXtqOs29tYkHikw kxU9ievkv0D/xK8309Hb1SHtlJCc+flAnCks5Amc7TnPES7LyN0sdPtEWNCuKEYxngrB CM5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id z1si13048299plo.202.2018.11.20.15.25.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:28 -0800 (PST) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.65 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 fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 15:25:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="281654735" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga005.fm.intel.com with ESMTP; 20 Nov 2018 15:25:27 -0800 Subject: [PATCH v8 2/7] mm, devm_memremap_pages: Kill mapping "System RAM" support From: Dan Williams To: akpm@linux-foundation.org Cc: =?utf-8?b?SsOpcsO0bWU=?= Glisse , Christoph Hellwig , Logan Gunthorpe , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:13:00 -0800 Message-ID: <154275557997.76910.14689813630968180480.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 Given the fact that devm_memremap_pages() requires a percpu_ref that is torn down by devm_memremap_pages_release() the current support for mapping RAM is broken. Support for remapping "System RAM" has been broken since the beginning and there is no existing user of this this code path, so just kill the support and make it an explicit error. This cleanup also simplifies a follow-on patch to fix the error path when setting a devm release action for devm_memremap_pages_release() fails. Reviewed-by: "Jérôme Glisse" Reviewed-by: Christoph Hellwig Reviewed-by: Logan Gunthorpe Signed-off-by: Dan Williams --- kernel/memremap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/memremap.c b/kernel/memremap.c index 61dbcaa95530..99d14940acfa 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -167,15 +167,12 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) is_ram = region_intersects(align_start, align_size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE); - if (is_ram == REGION_MIXED) { - WARN_ONCE(1, "%s attempted on mixed region %pr\n", - __func__, res); + if (is_ram != REGION_DISJOINT) { + WARN_ONCE(1, "%s attempted on %s region %pr\n", __func__, + is_ram == REGION_MIXED ? "mixed" : "ram", res); return ERR_PTR(-ENXIO); } - if (is_ram == REGION_INTERSECTS) - return __va(res->start); - if (!pgmap->ref) return ERR_PTR(-EINVAL); From patchwork Tue Nov 20 23:13:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10691429 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 3ED8913AD for ; Tue, 20 Nov 2018 23:25:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 298B52AC4E for ; Tue, 20 Nov 2018 23:25:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DE182AC59; Tue, 20 Nov 2018 23:25:37 +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 4699D2AC4E for ; Tue, 20 Nov 2018 23:25:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D4BC6B228C; Tue, 20 Nov 2018 18:25:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3B44B6B228E; Tue, 20 Nov 2018 18:25:35 -0500 (EST) 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 2C13B6B228F; Tue, 20 Nov 2018 18:25:35 -0500 (EST) 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 D548F6B228C for ; Tue, 20 Nov 2018 18:25:34 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id d23so4180879plj.22 for ; Tue, 20 Nov 2018 15:25:34 -0800 (PST) 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=NsZ5vZBBgdz/fjm886SEH5+N6KZDvFSijWd+3bC8f0E=; b=FgB0U8DhmwSTaSYyWHCPo1LE6+BZvFlVhQ/6eaxngPM+i7wTM4Bsji8OQY0cVoC+bO 3RuuRtQSPR1hYBPjCpGIvQRsqFUriYnJvEg8YknI26O2SQ/S3pXEKnN1T9TyKKzi017R h4vpnrvnIsDKmEyWKlrVP3kpe95pxfEZvlwr8PUNhuiVZWzod+fIe+q6ljhD2Pqy5Prs 2oVNTLBXYHLJ7SVJMvAdi0IM5Le2iVu+/9Lbzx7JovzoBuYl9huva5efYXdkkliXKkYq Hi6dI8J1T3IkQsaxb/TGiju8jU3tv9Fc2Njao2esHrNEHfXjqcdZGODm62x/AXBRCOBy v3FA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 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: AA+aEWZshk+Ge3OkNsvy1YJsS9qatOHBqa5CNrxPH2Sm/tzj4O1Lp1oV d3Qq4b/LoKRRuab+j0I7sYUtg5SvUfLDdHiF4GywjTCMhRqnHmewKdEaCsznsuDBLbVFRXwxdxs 0H9v5WRuZkftL6v1P5lDiSQu1qCBoeXcLBCHcp7A4CQGiMBRWGtdQV+sVaHtLRBJFBQ== X-Received: by 2002:a17:902:c5:: with SMTP id a63mr4090483pla.267.1542756334477; Tue, 20 Nov 2018 15:25:34 -0800 (PST) X-Google-Smtp-Source: AFSGD/W52uRDet+IH857CJwdDCqjtKSuXgYICSSbGvNuH9NH8A7vWrNpIdZsZsUNRtxnhhzlush2 X-Received: by 2002:a17:902:c5:: with SMTP id a63mr4090414pla.267.1542756333384; Tue, 20 Nov 2018 15:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756333; cv=none; d=google.com; s=arc-20160816; b=Vx9jO3ikfqt0v0UVRGQaVlHnvIfCsvkXIMoRbko+yuYZAdlkoqja+gPcoBV4/xV9dQ j+UHJisTH9j413n+XrOhcgdoG8rDDKwVndq65Pq4FVg3/ygiCvxUaGliNMK8vO2ZWN4l 3CQeDR11kHV23o6g32D0hviDtDd91WOmHS2k9SfOKVk3XAFfU1s3Sy3B3TOEKEnFa5nk f1AaFaO7i6XMwPQQCC+cpC3NUwFghHQvao551clYSnhG1SnB7Vt8vWLipLmZ9y2GamV/ MRKjF5PxDmRsXpKGQ/UVpZWyEbfQfi97dCnl1K/1Piv8cK2Z7U62eN0mlUO1/sxX7dew Y9kg== 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=NsZ5vZBBgdz/fjm886SEH5+N6KZDvFSijWd+3bC8f0E=; b=C94WsfVMzSXDJ+epgE7ZHWhpc1VMX6eVLTL/iO8g+YwzIRR5fFId3rXC1SY8VkaJRo 4Puk+BzGUppNUJ6uOuk6CYCrT7q7l8z7WNYhhOSpXckR5rbPGoHsCLbRWgGfWtfYKBxK SCWLcRoihFEIIqyfgEs6jARw01WSnLbxoIPMdKYkclaTPGbQJvZjA7V25RxE9NWqKew9 +jvREJ2BMfZFdMDGCy8m1XUcGBtf6aEx0tHjTGS/Gze61LhekCQFV23jCO2g/+Y25qqj cgWajYCc4U8IT5QWef35NfDBWrjfMelKCzU7wQ7kx27PdlBxVIB9aiWVS46OiisfAGjs bHFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id i5si47054503pgn.243.2018.11.20.15.25.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:33 -0800 (PST) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 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 orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 15:25:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="110209179" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga002.jf.intel.com with ESMTP; 20 Nov 2018 15:25:32 -0800 Subject: [PATCH v8 3/7] mm, devm_memremap_pages: Fix shutdown handling From: Dan Williams To: akpm@linux-foundation.org Cc: stable@vger.kernel.org, =?utf-8?b?SsOpcsO0bWU=?= Glisse , Logan Gunthorpe , Logan Gunthorpe , Christoph Hellwig , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:13:05 -0800 Message-ID: <154275558526.76910.7535251937849268605.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 The last step before devm_memremap_pages() returns success is to allocate a release action, devm_memremap_pages_release(), to tear the entire setup down. However, the result from devm_add_action() is not checked. Checking the error from devm_add_action() is not enough. The api currently relies on the fact that the percpu_ref it is using is killed by the time the devm_memremap_pages_release() is run. Rather than continue this awkward situation, offload the responsibility of killing the percpu_ref to devm_memremap_pages_release() directly. This allows devm_memremap_pages() to do the right thing relative to init failures and shutdown. Without this change we could fail to register the teardown of devm_memremap_pages(). The likelihood of hitting this failure is tiny as small memory allocations almost always succeed. However, the impact of the failure is large given any future reconfiguration, or disable/enable, of an nvdimm namespace will fail forever as subsequent calls to devm_memremap_pages() will fail to setup the pgmap_radix since there will be stale entries for the physical address range. An argument could be made to require that the ->kill() operation be set in the @pgmap arg rather than passed in separately. However, it helps code readability, tracking the lifetime of a given instance, to be able to grep the kill routine directly at the devm_memremap_pages() call site. Cc: Fixes: e8d513483300 ("memremap: change devm_memremap_pages interface...") Reviewed-by: "Jérôme Glisse" Reported-by: Logan Gunthorpe Reviewed-by: Logan Gunthorpe Reviewed-by: Christoph Hellwig Signed-off-by: Dan Williams --- drivers/dax/pmem.c | 14 +++----------- drivers/nvdimm/pmem.c | 13 +++++-------- include/linux/memremap.h | 2 ++ kernel/memremap.c | 30 ++++++++++++++---------------- tools/testing/nvdimm/test/iomap.c | 15 ++++++++++++++- 5 files changed, 38 insertions(+), 36 deletions(-) diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index 99e2aace8078..2c1f459c0c63 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -48,9 +48,8 @@ static void dax_pmem_percpu_exit(void *data) percpu_ref_exit(ref); } -static void dax_pmem_percpu_kill(void *data) +static void dax_pmem_percpu_kill(struct percpu_ref *ref) { - struct percpu_ref *ref = data; struct dax_pmem *dax_pmem = to_dax_pmem(ref); dev_dbg(dax_pmem->dev, "trace\n"); @@ -112,17 +111,10 @@ static int dax_pmem_probe(struct device *dev) } dax_pmem->pgmap.ref = &dax_pmem->ref; + dax_pmem->pgmap.kill = dax_pmem_percpu_kill; addr = devm_memremap_pages(dev, &dax_pmem->pgmap); - if (IS_ERR(addr)) { - devm_remove_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref); - percpu_ref_exit(&dax_pmem->ref); + if (IS_ERR(addr)) return PTR_ERR(addr); - } - - rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill, - &dax_pmem->ref); - if (rc) - return rc; /* adjust the dax_region resource to the start of data */ memcpy(&res, &dax_pmem->pgmap.res, sizeof(res)); diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index f7019294740c..bc2f700feef8 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -309,8 +309,11 @@ static void pmem_release_queue(void *q) blk_cleanup_queue(q); } -static void pmem_freeze_queue(void *q) +static void pmem_freeze_queue(struct percpu_ref *ref) { + struct request_queue *q; + + q = container_of(ref, typeof(*q), q_usage_counter); blk_freeze_queue_start(q); } @@ -402,6 +405,7 @@ static int pmem_attach_disk(struct device *dev, pmem->pfn_flags = PFN_DEV; pmem->pgmap.ref = &q->q_usage_counter; + pmem->pgmap.kill = pmem_freeze_queue; if (is_nd_pfn(dev)) { if (setup_pagemap_fsdax(dev, &pmem->pgmap)) return -ENOMEM; @@ -427,13 +431,6 @@ static int pmem_attach_disk(struct device *dev, memcpy(&bb_res, &nsio->res, sizeof(bb_res)); } - /* - * At release time the queue must be frozen before - * devm_memremap_pages is unwound - */ - if (devm_add_action_or_reset(dev, pmem_freeze_queue, q)) - return -ENOMEM; - if (IS_ERR(addr)) return PTR_ERR(addr); pmem->virt_addr = addr; diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 0ac69ddf5fc4..55db66b3716f 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -111,6 +111,7 @@ typedef void (*dev_page_free_t)(struct page *page, void *data); * @altmap: pre-allocated/reserved memory for vmemmap allocations * @res: physical address range covered by @ref * @ref: reference count that pins the devm_memremap_pages() mapping + * @kill: callback to transition @ref to the dead state * @dev: host device of the mapping for debug * @data: private data pointer for page_free() * @type: memory type: see MEMORY_* in memory_hotplug.h @@ -122,6 +123,7 @@ struct dev_pagemap { bool altmap_valid; struct resource res; struct percpu_ref *ref; + void (*kill)(struct percpu_ref *ref); struct device *dev; void *data; enum memory_type type; diff --git a/kernel/memremap.c b/kernel/memremap.c index 99d14940acfa..5e45f0c327a5 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -88,14 +88,10 @@ static void devm_memremap_pages_release(void *data) resource_size_t align_start, align_size; unsigned long pfn; + pgmap->kill(pgmap->ref); for_each_device_pfn(pfn, pgmap) put_page(pfn_to_page(pfn)); - if (percpu_ref_tryget_live(pgmap->ref)) { - dev_WARN(dev, "%s: page mapping is still live!\n", __func__); - percpu_ref_put(pgmap->ref); - } - /* pages are dead and unused, undo the arch mapping */ align_start = res->start & ~(SECTION_SIZE - 1); align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) @@ -116,7 +112,7 @@ static void devm_memremap_pages_release(void *data) /** * devm_memremap_pages - remap and provide memmap backing for the given resource * @dev: hosting device for @res - * @pgmap: pointer to a struct dev_pgmap + * @pgmap: pointer to a struct dev_pagemap * * Notes: * 1/ At a minimum the res, ref and type members of @pgmap must be initialized @@ -125,11 +121,8 @@ static void devm_memremap_pages_release(void *data) * 2/ The altmap field may optionally be initialized, in which case altmap_valid * must be set to true * - * 3/ pgmap.ref must be 'live' on entry and 'dead' before devm_memunmap_pages() - * time (or devm release event). The expected order of events is that ref has - * been through percpu_ref_kill() before devm_memremap_pages_release(). The - * wait for the completion of all references being dropped and - * percpu_ref_exit() must occur after devm_memremap_pages_release(). + * 3/ pgmap->ref must be 'live' on entry and will be killed at + * devm_memremap_pages_release() time, or if this routine fails. * * 4/ res is expected to be a host memory range that could feasibly be * treated as a "System RAM" range, i.e. not a device mmio range, but @@ -145,6 +138,9 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) pgprot_t pgprot = PAGE_KERNEL; int error, nid, is_ram; + if (!pgmap->ref || !pgmap->kill) + return ERR_PTR(-EINVAL); + align_start = res->start & ~(SECTION_SIZE - 1); align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) - align_start; @@ -170,12 +166,10 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) if (is_ram != REGION_DISJOINT) { WARN_ONCE(1, "%s attempted on %s region %pr\n", __func__, is_ram == REGION_MIXED ? "mixed" : "ram", res); - return ERR_PTR(-ENXIO); + error = -ENXIO; + goto err_array; } - if (!pgmap->ref) - return ERR_PTR(-EINVAL); - pgmap->dev = dev; error = xa_err(xa_store_range(&pgmap_array, PHYS_PFN(res->start), @@ -217,7 +211,10 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) align_size >> PAGE_SHIFT, pgmap); percpu_ref_get_many(pgmap->ref, pfn_end(pgmap) - pfn_first(pgmap)); - devm_add_action(dev, devm_memremap_pages_release, pgmap); + error = devm_add_action_or_reset(dev, devm_memremap_pages_release, + pgmap); + if (error) + return ERR_PTR(error); return __va(res->start); @@ -228,6 +225,7 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) err_pfn_remap: pgmap_array_delete(res); err_array: + pgmap->kill(pgmap->ref); return ERR_PTR(error); } EXPORT_SYMBOL_GPL(devm_memremap_pages); diff --git a/tools/testing/nvdimm/test/iomap.c b/tools/testing/nvdimm/test/iomap.c index ed18a0cbc0c8..c6635fee27d8 100644 --- a/tools/testing/nvdimm/test/iomap.c +++ b/tools/testing/nvdimm/test/iomap.c @@ -104,13 +104,26 @@ void *__wrap_devm_memremap(struct device *dev, resource_size_t offset, } EXPORT_SYMBOL(__wrap_devm_memremap); +static void nfit_test_kill(void *_pgmap) +{ + struct dev_pagemap *pgmap = _pgmap; + + pgmap->kill(pgmap->ref); +} + void *__wrap_devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) { resource_size_t offset = pgmap->res.start; struct nfit_test_resource *nfit_res = get_nfit_res(offset); - if (nfit_res) + if (nfit_res) { + int rc; + + rc = devm_add_action_or_reset(dev, nfit_test_kill, pgmap); + if (rc) + return ERR_PTR(rc); return nfit_res->buf + offset - nfit_res->res.start; + } return devm_memremap_pages(dev, pgmap); } EXPORT_SYMBOL_GPL(__wrap_devm_memremap_pages); From patchwork Tue Nov 20 23:13:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10691433 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 88FB013AD for ; Tue, 20 Nov 2018 23:25:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74FA92AC4E for ; Tue, 20 Nov 2018 23:25:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 690A92AC59; Tue, 20 Nov 2018 23:25:41 +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 DEA602AC4E for ; Tue, 20 Nov 2018 23:25:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CFCDA6B228E; Tue, 20 Nov 2018 18:25:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CD3166B2290; Tue, 20 Nov 2018 18:25:39 -0500 (EST) 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 BE8026B2291; Tue, 20 Nov 2018 18:25:39 -0500 (EST) 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 785406B228E for ; Tue, 20 Nov 2018 18:25:39 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id m13so4283862pls.15 for ; Tue, 20 Nov 2018 15:25:39 -0800 (PST) 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=yyixc6IwTRlo7HnHFCbTt02hp0EiiBvQlPqautOxqSk=; b=st2TD8vLaUvfaNtrOpQ9qSDnZtAnc6V1aQlTb6+87jGKBEJwfYBDCwtWgzlhsy/IOh QHuHA0W2c+1nBq+1cVIcbf0eZ2xlKXDow5RmYZMIKNLd9ous6jNqR+e/MVupOxiy8QQV 8xrPTrPVdxLmbKI391Ai7l3VcbBArwvzvFMxbq3gb6tiDmOlp3oN0cMvCr3AUQc/66G5 1U5FKN11hY9zZPNLt3mZjomYayHhgsjy1k/vP9K8AC7Z5gW5NVtiqPgfOsyO9ZhLKcw4 Zod2/2bb6cQz03HxKw0v6ae1adx9KqLz+/7E13EjiRPAkyrE2Q8GyM5glLXGOLIsg4mQ Z/Lw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 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: AGRZ1gIuU1PezxZeT8UDxz7pL5pE5s+a2l/NTEq3XycJP+Eglkrhfogm E7EsyEWWqATK/nUJIlMlIIoahl04Lmeo+IzrPxdnPw79DdX4Gc/JGHEO3EXQh0VplWIQhh2qJsc 0eLZxjVmj/sZwdGiEPACj0H5uLnbtyt/omxXW8e5mzJAC3UgEz5eMP/6hVRfzYoR7WA== X-Received: by 2002:a62:d148:: with SMTP id t8mr4399645pfl.52.1542756339130; Tue, 20 Nov 2018 15:25:39 -0800 (PST) X-Google-Smtp-Source: AJdET5dX2BvcQ4QdQgb3+b2ctbSEjYwakoaHriF8hp51ObR8w6ZXG1a6je7x2/qCmAa1b5x0BpKv X-Received: by 2002:a62:d148:: with SMTP id t8mr4399603pfl.52.1542756338451; Tue, 20 Nov 2018 15:25:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756338; cv=none; d=google.com; s=arc-20160816; b=SG+9UEO4yW6rQm7nPb7jae0OJQSAP4NQlPGXdJbX7jnlTmKWEsSZjVhvMJtCL3DhR+ fbFmxyR2CXpxeLMpQ7DR1MGOiySMZraOuUjhx1T5S+O+C7u0AZPXAK0/kR/tOfYlF9Bn zY6Tt0L+BAZtreQdcbwTU7B+wjlEzvE3ZqsrtZY1aa3BFzDi2g6i8340dGIbUc8Wn//y 4ApQL13kkyouLEtEyIq0fAAK40mMs6W642uYCBOuFVBLkrs9UucuWB33fdc7hWrO8J+1 0sHxXXMb5qP3IUokczXjWkS3V7EXUr+lqF8AC1qrvK4QPwAj2fnZHXnNP/MPYRxWhvYW +RLA== 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=yyixc6IwTRlo7HnHFCbTt02hp0EiiBvQlPqautOxqSk=; b=sLvwFgIfm9PLWb4kiXrzHhQueoB+9jgemDhwl1ROHdOdDHGrJuxzeI+W9f3obYzFgo hkqC1OnB57b4HaRA2dpTuuyxfJVspmALalu+PxDHGSqVdPEBzPSpuoF7nvIU78DaYSDX ImibDXa+0U7XRrxheHsScrMO5omwkd5UG5V9Gd/7wjxex9ymNZARhLLatjUuFW8mVdOS EIJP/OW6FwPf6V3AAdPe8YMGe/j7GiM4EebBzToFijKSJEyko85/qKBrC5gyfJ9umISN mP60QT8Crqu1ppIpWQ6DTspjbkcLrcw1tGSfpvvmAqGIlZOia1yjf2QlwwfulGLznyJG pl/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id p5-v6si16818720plo.7.2018.11.20.15.25.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:38 -0800 (PST) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.93 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 orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 15:25:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="101868625" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003.jf.intel.com with ESMTP; 20 Nov 2018 15:25:37 -0800 Subject: [PATCH v8 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 , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:13:10 -0800 Message-ID: <154275559036.76910.12434636179931292607.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 5e45f0c327a5..3eef989ef035 100644 --- a/kernel/memremap.c +++ b/kernel/memremap.c @@ -98,9 +98,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); @@ -187,17 +193,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; From patchwork Tue Nov 20 23:13: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: 10691437 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 760E216B1 for ; Tue, 20 Nov 2018 23:25:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61A9B2AC4E for ; Tue, 20 Nov 2018 23:25:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55B5C2AC59; Tue, 20 Nov 2018 23:25:47 +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 92AA52AC4E for ; Tue, 20 Nov 2018 23:25:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B9356B2290; Tue, 20 Nov 2018 18:25:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 66A136B2292; Tue, 20 Nov 2018 18:25:45 -0500 (EST) 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 559366B2293; Tue, 20 Nov 2018 18:25:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 093EF6B2290 for ; Tue, 20 Nov 2018 18:25:45 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 3-v6so4203049plc.18 for ; Tue, 20 Nov 2018 15:25:45 -0800 (PST) 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=+m3jCKO9Qw5y2sbVKJ0T14qzWEv63iOzx9LaTQL4wZA=; b=e7pbGJC183C85ed567PftXZ9bRKNzpD/zgjrTyYd5FJLzHhi7AqLRIbuv9t0aM+s5k PYhS7YETENu/opPyrg6HgAp9PsJp1vW/tXuJPJ7fyJs+6pBXcyeXETfkZPEt3MOLnJ/J wmm4O7WDI4vkjWuvkwUOyHsWSdiUosIsTdaWcTXSGt8y8gAiZFzU2qnC+jXHtZZMiZg/ 2FN53r90lSwl0Sw5EglPc1ZCV0/42sRV8pt6LTHxXa59lEqC3ug6w2cLMW1mmLAAxVP1 XFNDdfrBqY4ouMDpflAV98czl/KnLzCfDJUOoQ8Swa4OZmwcbNt5SHEiVVdlso+eLNVg YnRg== 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: AA+aEWYHIk8LafM/0ZvKy3vj5fQByNRtEUxruqqAkHZ1Eh2gybTxqn89 sqgdeTYohcmy94M/0MsENQ/oqR6vvfrA3Pe2doPJSVQtUIf8QH0/1AZcl2B1wyAEN9Qvc/sikW/ ZMi1fuZLt4Rxz4uYiYC0s+BSqdPVmuO4ASyos+GD+OlKPgkrf0DGCpANxMvDT0zzW0w== X-Received: by 2002:a63:f959:: with SMTP id q25mr3786255pgk.315.1542756344648; Tue, 20 Nov 2018 15:25:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/VK2gfq1b0KZ+V5eKXmRDIgJA3n03UhyP2mAT9MBvJruHw10Hg+77gdcNd1Vbv/DpL+J8xL X-Received: by 2002:a63:f959:: with SMTP id q25mr3786187pgk.315.1542756343420; Tue, 20 Nov 2018 15:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756343; cv=none; d=google.com; s=arc-20160816; b=t6gMwpzuaccsAiRR+Tim+oCgSsLQMdOVPj87VkVwWaePQiK1xEs6mmBVl6ytZhRHlN nTkfmwRrb93gIGOWhT4hBTCptSp+pE4BHNBdwqNdMOmp5/b4iNkIjqBdSoFMahIlEwW3 He/G2Q0aVxlrx39QGbuuqbxLuUq7NLKjiNbhiphagecN/XXuNHNJWtmfPZ57KS1pRelI B+SCZRsz1QqWgumuzWczc9QSZHxH6mE0R3l1Orgx9x4AqpvNQR77CSmOaY+hKdnadslB 8osOkZX3oCjsLaScazerkIztyC0zNABji5tahkOgwPbSajAqQTsuvjy5nq5U6tI7NVNL duFQ== 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=+m3jCKO9Qw5y2sbVKJ0T14qzWEv63iOzx9LaTQL4wZA=; b=0MPkZ0s14y/raHCoDA4G+2GazbwIh5H7ZAiIbLJzJ9xUu5UnMqQCmkLL1zfY2SyBq5 sg0Mp9hQUEespLLJAv4W8U5km6CwHTR9jpw9yDiG+4bSbEmdc/ooyqE0VmoxxOEz+pN0 QcdlExdfXF/9z9FouS6qXKM9hNJxSwfNx5xtFmw5pS6YpVbyXEBFm56PdlMoOLiAccxi y9ztCNixl897W1IS4xl6f/z0v7iaTnXhalCYvZk7E1UBCEVh3oKv3Xe8aS+NweK99dc0 lTqCOBXbxd8Lav7JYg8wyFyglNcnLQXvusIqB9nfEMd3+vU/tXlJE8iVMDVi7TIsgsJN 8y4Q== 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 m1si4197265pgi.218.2018.11.20.15.25.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:43 -0800 (PST) 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; 20 Nov 2018 15:25:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="93636103" 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; 20 Nov 2018 15:25:42 -0800 Subject: [PATCH v8 5/7] mm, hmm: Use devm semantics for hmm_devmem_{add, remove} From: Dan Williams To: akpm@linux-foundation.org Cc: Christoph Hellwig , =?utf-8?b?SsOpcsO0bWU=?= Glisse , =?utf-8?b?SsOpcsO0?= =?utf-8?b?bWU=?= Glisse , Logan Gunthorpe , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:13:15 -0800 Message-ID: <154275559545.76910.9186690723515469051.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 devm semantics arrange for resources to be torn down when device-driver-probe fails or when device-driver-release completes. Similar to devm_memremap_pages() there is no need to support an explicit remove operation when the users properly adhere to devm semantics. Note that devm_kzalloc() automatically handles allocating node-local memory. Reviewed-by: Christoph Hellwig Reviewed-by: Jérôme Glisse Cc: "Jérôme Glisse" Cc: Logan Gunthorpe Signed-off-by: Dan Williams --- include/linux/hmm.h | 4 -- mm/hmm.c | 127 ++++++++++----------------------------------------- 2 files changed, 25 insertions(+), 106 deletions(-) diff --git a/include/linux/hmm.h b/include/linux/hmm.h index c6fb869a81c0..ed89fbc525d2 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -512,8 +512,7 @@ struct hmm_devmem { * enough and allocate struct page for it. * * The device driver can wrap the hmm_devmem struct inside a private device - * driver struct. The device driver must call hmm_devmem_remove() before the - * device goes away and before freeing the hmm_devmem struct memory. + * driver struct. */ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, struct device *device, @@ -521,7 +520,6 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, struct device *device, struct resource *res); -void hmm_devmem_remove(struct hmm_devmem *devmem); /* * hmm_devmem_page_set_drvdata - set per-page driver data field diff --git a/mm/hmm.c b/mm/hmm.c index 90c34f3d1243..8510881e7b44 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -987,7 +987,6 @@ static void hmm_devmem_ref_exit(void *data) devmem = container_of(ref, struct hmm_devmem, ref); percpu_ref_exit(ref); - devm_remove_action(devmem->device, &hmm_devmem_ref_exit, data); } static void hmm_devmem_ref_kill(void *data) @@ -998,7 +997,6 @@ static void hmm_devmem_ref_kill(void *data) devmem = container_of(ref, struct hmm_devmem, ref); percpu_ref_kill(ref); wait_for_completion(&devmem->completion); - devm_remove_action(devmem->device, &hmm_devmem_ref_kill, data); } static int hmm_devmem_fault(struct vm_area_struct *vma, @@ -1036,7 +1034,7 @@ static void hmm_devmem_radix_release(struct resource *resource) mutex_unlock(&hmm_devmem_lock); } -static void hmm_devmem_release(struct device *dev, void *data) +static void hmm_devmem_release(void *data) { struct hmm_devmem *devmem = data; struct resource *resource = devmem->resource; @@ -1044,11 +1042,6 @@ static void hmm_devmem_release(struct device *dev, void *data) struct zone *zone; struct page *page; - if (percpu_ref_tryget_live(&devmem->ref)) { - dev_WARN(dev, "%s: page mapping is still live!\n", __func__); - percpu_ref_put(&devmem->ref); - } - /* pages are dead and unused, undo the arch mapping */ start_pfn = (resource->start & ~(PA_SECTION_SIZE - 1)) >> PAGE_SHIFT; npages = ALIGN(resource_size(resource), PA_SECTION_SIZE) >> PAGE_SHIFT; @@ -1174,19 +1167,6 @@ static int hmm_devmem_pages_create(struct hmm_devmem *devmem) return ret; } -static int hmm_devmem_match(struct device *dev, void *data, void *match_data) -{ - struct hmm_devmem *devmem = data; - - return devmem->resource == match_data; -} - -static void hmm_devmem_pages_remove(struct hmm_devmem *devmem) -{ - devres_release(devmem->device, &hmm_devmem_release, - &hmm_devmem_match, devmem->resource); -} - /* * hmm_devmem_add() - hotplug ZONE_DEVICE memory for device memory * @@ -1214,8 +1194,7 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, dev_pagemap_get_ops(); - devmem = devres_alloc_node(&hmm_devmem_release, sizeof(*devmem), - GFP_KERNEL, dev_to_node(device)); + devmem = devm_kzalloc(device, sizeof(*devmem), GFP_KERNEL); if (!devmem) return ERR_PTR(-ENOMEM); @@ -1229,11 +1208,11 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, ret = percpu_ref_init(&devmem->ref, &hmm_devmem_ref_release, 0, GFP_KERNEL); if (ret) - goto error_percpu_ref; + return ERR_PTR(ret); - ret = devm_add_action(device, hmm_devmem_ref_exit, &devmem->ref); + ret = devm_add_action_or_reset(device, hmm_devmem_ref_exit, &devmem->ref); if (ret) - goto error_devm_add_action; + return ERR_PTR(ret); size = ALIGN(size, PA_SECTION_SIZE); addr = min((unsigned long)iomem_resource.end, @@ -1253,16 +1232,12 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, devmem->resource = devm_request_mem_region(device, addr, size, dev_name(device)); - if (!devmem->resource) { - ret = -ENOMEM; - goto error_no_resource; - } + if (!devmem->resource) + return ERR_PTR(-ENOMEM); break; } - if (!devmem->resource) { - ret = -ERANGE; - goto error_no_resource; - } + if (!devmem->resource) + return ERR_PTR(-ERANGE); devmem->resource->desc = IORES_DESC_DEVICE_PRIVATE_MEMORY; devmem->pfn_first = devmem->resource->start >> PAGE_SHIFT; @@ -1271,28 +1246,13 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, ret = hmm_devmem_pages_create(devmem); if (ret) - goto error_pages; - - devres_add(device, devmem); + return ERR_PTR(ret); - ret = devm_add_action(device, hmm_devmem_ref_kill, &devmem->ref); - if (ret) { - hmm_devmem_remove(devmem); + ret = devm_add_action_or_reset(device, hmm_devmem_release, devmem); + if (ret) return ERR_PTR(ret); - } return devmem; - -error_pages: - devm_release_mem_region(device, devmem->resource->start, - resource_size(devmem->resource)); -error_no_resource: -error_devm_add_action: - hmm_devmem_ref_kill(&devmem->ref); - hmm_devmem_ref_exit(&devmem->ref); -error_percpu_ref: - devres_free(devmem); - return ERR_PTR(ret); } EXPORT_SYMBOL(hmm_devmem_add); @@ -1308,8 +1268,7 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, dev_pagemap_get_ops(); - devmem = devres_alloc_node(&hmm_devmem_release, sizeof(*devmem), - GFP_KERNEL, dev_to_node(device)); + devmem = devm_kzalloc(device, sizeof(*devmem), GFP_KERNEL); if (!devmem) return ERR_PTR(-ENOMEM); @@ -1323,12 +1282,12 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, ret = percpu_ref_init(&devmem->ref, &hmm_devmem_ref_release, 0, GFP_KERNEL); if (ret) - goto error_percpu_ref; + return ERR_PTR(ret); - ret = devm_add_action(device, hmm_devmem_ref_exit, &devmem->ref); + ret = devm_add_action_or_reset(device, hmm_devmem_ref_exit, + &devmem->ref); if (ret) - goto error_devm_add_action; - + return ERR_PTR(ret); devmem->pfn_first = devmem->resource->start >> PAGE_SHIFT; devmem->pfn_last = devmem->pfn_first + @@ -1336,59 +1295,21 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, ret = hmm_devmem_pages_create(devmem); if (ret) - goto error_devm_add_action; + return ERR_PTR(ret); - devres_add(device, devmem); + ret = devm_add_action_or_reset(device, hmm_devmem_release, devmem); + if (ret) + return ERR_PTR(ret); - ret = devm_add_action(device, hmm_devmem_ref_kill, &devmem->ref); - if (ret) { - hmm_devmem_remove(devmem); + ret = devm_add_action_or_reset(device, hmm_devmem_ref_kill, + &devmem->ref); + if (ret) return ERR_PTR(ret); - } return devmem; - -error_devm_add_action: - hmm_devmem_ref_kill(&devmem->ref); - hmm_devmem_ref_exit(&devmem->ref); -error_percpu_ref: - devres_free(devmem); - return ERR_PTR(ret); } EXPORT_SYMBOL(hmm_devmem_add_resource); -/* - * hmm_devmem_remove() - remove device memory (kill and free ZONE_DEVICE) - * - * @devmem: hmm_devmem struct use to track and manage the ZONE_DEVICE memory - * - * This will hot-unplug memory that was hotplugged by hmm_devmem_add on behalf - * of the device driver. It will free struct page and remove the resource that - * reserved the physical address range for this device memory. - */ -void hmm_devmem_remove(struct hmm_devmem *devmem) -{ - resource_size_t start, size; - struct device *device; - bool cdm = false; - - if (!devmem) - return; - - device = devmem->device; - start = devmem->resource->start; - size = resource_size(devmem->resource); - - cdm = devmem->resource->desc == IORES_DESC_DEVICE_PUBLIC_MEMORY; - hmm_devmem_ref_kill(&devmem->ref); - hmm_devmem_ref_exit(&devmem->ref); - hmm_devmem_pages_remove(devmem); - - if (!cdm) - devm_release_mem_region(device, start, size); -} -EXPORT_SYMBOL(hmm_devmem_remove); - /* * A device driver that wants to handle multiple devices memory through a * single fake device can use hmm_device to do so. This is purely a helper From patchwork Tue Nov 20 23:13:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10691441 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 D0AF11869 for ; Tue, 20 Nov 2018 23:25:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC05B2AC58 for ; Tue, 20 Nov 2018 23:25:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B02152AC5A; Tue, 20 Nov 2018 23:25:52 +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 DC41A2AC59 for ; Tue, 20 Nov 2018 23:25:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4C6F6B2292; Tue, 20 Nov 2018 18:25:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AFF5B6B2294; Tue, 20 Nov 2018 18:25:50 -0500 (EST) 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 9ED086B2295; Tue, 20 Nov 2018 18:25:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 525B96B2292 for ; Tue, 20 Nov 2018 18:25:50 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id 34-v6so4277333plf.6 for ; Tue, 20 Nov 2018 15:25:50 -0800 (PST) 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=wSKKpZ8lZEeX2815DYiOKgfCRTe02wmiVZ2V/2sbX1Y=; b=tCpB+w4O9i29XvtG6bXesq1LutHpszZvvpHofShk2Gabgk0ijbpCS+7NXJ2/IwWHj8 3oXZvhytE+XEoQTTItOlJv07jHRabOc/EiFBfwv/xABGkIvJm00zXPJAdnF5B+4nv5Tq EALApEwOl4IKI+C+70Ny3fxMdwV8BPkRLXKiczLq54t1EnmFLia/UN5XcrmYfxqOZKbw rE0T0JOUVbCpYJ6Ju3n4yTMtFAescT/vIh0fag9vZiJa9y0oJctkxehc+ffefNTORwUR TlYyfDBOPuh8svJjvkagRr31e1Oy9N82jR6vw3gL53qoBomEHxL5RsGZ8AJ0i2wT171M BAHg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 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: AA+aEWZ1F7/AADQcFsnmz8uq+CoIcJFdHbyVS6dxn1PLXL1tvUfz8sxq N9R7ilsP7u6G8qE2JB8Av3PXuCAF0H4J+B1td/JDkeZ7AmDqnQgQHgR/U5P4Yiy3ZacU2j8kt41 wAEhxGtaSnKKFrP151io/CIkmVegJPT3s+l4Y+pg6po6vXLerypbHH05T1v0Nz8Qxww== X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr4294442plt.153.1542756349929; Tue, 20 Nov 2018 15:25:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vs8u8PkPZaFEmBGCbVsqE615YpC8tnrD7teYgVle4/kxRFGBFP/JQkPK2NF1+AOkyfOY9T X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr4294379plt.153.1542756348749; Tue, 20 Nov 2018 15:25:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756348; cv=none; d=google.com; s=arc-20160816; b=UpUurC6px7M2JFOEiBw4q4Ed+axVhZr+Tic46H/lDwPh/z2MSf9j2UZeJju/mfPZKG YW0EFEx0yePchMFSQ8c2DgAFzzyrCOpmKASvbuEOCSNYUvH25/wKdU8qSUn0pi4OJE6/ DDZ7BS+4XAvmfVLLkn9UDejmPDY4RDz0leRz4TIYYnqswHxru8UC3U2u8Rzt5rSYMB2R NZ8XF3XJW6ZgcyTp8fpi9aoLQm18MT9DHOaoyDGPLM7uo888GO9WF7fT7eugBwL+hts6 U2TgKXbZDdeBU/0HWhMO0CWzN3p3McdSmEdJqDZQTDT5WfjEZAQ7c7svRNNtmOSG8Kv3 +qBA== 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=wSKKpZ8lZEeX2815DYiOKgfCRTe02wmiVZ2V/2sbX1Y=; b=Fx432Yr1tArFGrbNfUQFSXm/Tno59z0A9AQcRJj5BmbYidwXaPrQkhbvqGlDNPszdM bT9jTk4XMSg10GUh3gyTpDiyDERaS/kGr7f7emy4IuA82M1icSDX2gedME+r+8ABNBtJ YKN8bnd3gFXRWmL/ChadsMzJ7TT8ryyCO/V61WRsZLbTKgQf8D8B2qvPtw4ikyyblrTr aGGs1TD9VaC9GedmnMnN7dhsANnhapgquHioNWH+Qe4NQ3dEYQrPirXmcRUyA0O0Nstf pGSeVkpT9OkishhAd9W08wdIyFYQOz8eyd6P9UexI/Wd+z5PRz/O2BJOINq+FmN+MClV tZ9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id o127si9368887pfo.251.2018.11.20.15.25.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:48 -0800 (PST) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 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 fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 15:25:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="90883814" 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; 20 Nov 2018 15:25:47 -0800 Subject: [PATCH v8 6/7] mm, hmm: Replace hmm_devmem_pages_create() with devm_memremap_pages() From: Dan Williams To: akpm@linux-foundation.org Cc: Christoph Hellwig , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Balbir Singh , Logan Gunthorpe , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:13:20 -0800 Message-ID: <154275560053.76910.10870962637383152392.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 Commit e8d513483300 "memremap: change devm_memremap_pages interface to use struct dev_pagemap" refactored devm_memremap_pages() to allow a dev_pagemap instance to be supplied. Passing in a dev_pagemap interface simplifies the design of pgmap type drivers in that they can rely on container_of() to lookup any private data associated with the given dev_pagemap instance. In addition to the cleanups this also gives hmm users multi-order-radix improvements that arrived with commit ab1b597ee0e4 "mm, devm_memremap_pages: use multi-order radix for ZONE_DEVICE lookups" As part of the conversion to the devm_memremap_pages() method of handling the percpu_ref relative to when pages are put, the percpu_ref completion needs to move to hmm_devmem_ref_exit(). See commit 71389703839e ("mm, zone_device: Replace {get, put}_zone_device_page...") for details. Reviewed-by: Christoph Hellwig Reviewed-by: Jérôme Glisse Acked-by: Balbir Singh Cc: Logan Gunthorpe Signed-off-by: Dan Williams --- mm/hmm.c | 196 ++++++++------------------------------------------------------ 1 file changed, 26 insertions(+), 170 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 8510881e7b44..bf2495d9de81 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -986,17 +986,16 @@ static void hmm_devmem_ref_exit(void *data) struct hmm_devmem *devmem; devmem = container_of(ref, struct hmm_devmem, ref); + wait_for_completion(&devmem->completion); percpu_ref_exit(ref); } -static void hmm_devmem_ref_kill(void *data) +static void hmm_devmem_ref_kill(struct percpu_ref *ref) { - struct percpu_ref *ref = data; struct hmm_devmem *devmem; devmem = container_of(ref, struct hmm_devmem, ref); percpu_ref_kill(ref); - wait_for_completion(&devmem->completion); } static int hmm_devmem_fault(struct vm_area_struct *vma, @@ -1019,154 +1018,6 @@ static void hmm_devmem_free(struct page *page, void *data) devmem->ops->free(devmem, page); } -static DEFINE_MUTEX(hmm_devmem_lock); -static RADIX_TREE(hmm_devmem_radix, GFP_KERNEL); - -static void hmm_devmem_radix_release(struct resource *resource) -{ - resource_size_t key; - - mutex_lock(&hmm_devmem_lock); - for (key = resource->start; - key <= resource->end; - key += PA_SECTION_SIZE) - radix_tree_delete(&hmm_devmem_radix, key >> PA_SECTION_SHIFT); - mutex_unlock(&hmm_devmem_lock); -} - -static void hmm_devmem_release(void *data) -{ - struct hmm_devmem *devmem = data; - struct resource *resource = devmem->resource; - unsigned long start_pfn, npages; - struct zone *zone; - struct page *page; - - /* pages are dead and unused, undo the arch mapping */ - start_pfn = (resource->start & ~(PA_SECTION_SIZE - 1)) >> PAGE_SHIFT; - npages = ALIGN(resource_size(resource), PA_SECTION_SIZE) >> PAGE_SHIFT; - - page = pfn_to_page(start_pfn); - zone = page_zone(page); - - mem_hotplug_begin(); - if (resource->desc == IORES_DESC_DEVICE_PRIVATE_MEMORY) - __remove_pages(zone, start_pfn, npages, NULL); - else - arch_remove_memory(start_pfn << PAGE_SHIFT, - npages << PAGE_SHIFT, NULL); - mem_hotplug_done(); - - hmm_devmem_radix_release(resource); -} - -static int hmm_devmem_pages_create(struct hmm_devmem *devmem) -{ - resource_size_t key, align_start, align_size, align_end; - struct device *device = devmem->device; - int ret, nid, is_ram; - - align_start = devmem->resource->start & ~(PA_SECTION_SIZE - 1); - align_size = ALIGN(devmem->resource->start + - resource_size(devmem->resource), - PA_SECTION_SIZE) - align_start; - - is_ram = region_intersects(align_start, align_size, - IORESOURCE_SYSTEM_RAM, - IORES_DESC_NONE); - if (is_ram == REGION_MIXED) { - WARN_ONCE(1, "%s attempted on mixed region %pr\n", - __func__, devmem->resource); - return -ENXIO; - } - if (is_ram == REGION_INTERSECTS) - return -ENXIO; - - if (devmem->resource->desc == IORES_DESC_DEVICE_PUBLIC_MEMORY) - devmem->pagemap.type = MEMORY_DEVICE_PUBLIC; - else - devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; - - devmem->pagemap.res = *devmem->resource; - devmem->pagemap.page_fault = hmm_devmem_fault; - devmem->pagemap.page_free = hmm_devmem_free; - devmem->pagemap.dev = devmem->device; - devmem->pagemap.ref = &devmem->ref; - devmem->pagemap.data = devmem; - - mutex_lock(&hmm_devmem_lock); - align_end = align_start + align_size - 1; - for (key = align_start; key <= align_end; key += PA_SECTION_SIZE) { - struct hmm_devmem *dup; - - dup = radix_tree_lookup(&hmm_devmem_radix, - key >> PA_SECTION_SHIFT); - if (dup) { - dev_err(device, "%s: collides with mapping for %s\n", - __func__, dev_name(dup->device)); - mutex_unlock(&hmm_devmem_lock); - ret = -EBUSY; - goto error; - } - ret = radix_tree_insert(&hmm_devmem_radix, - key >> PA_SECTION_SHIFT, - devmem); - if (ret) { - dev_err(device, "%s: failed: %d\n", __func__, ret); - mutex_unlock(&hmm_devmem_lock); - goto error_radix; - } - } - mutex_unlock(&hmm_devmem_lock); - - nid = dev_to_node(device); - if (nid < 0) - nid = numa_mem_id(); - - mem_hotplug_begin(); - /* - * 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 device public memory, which is accesible by the CPU, we do - * want the linear mapping and thus use arch_add_memory(). - */ - if (devmem->pagemap.type == MEMORY_DEVICE_PUBLIC) - ret = arch_add_memory(nid, align_start, align_size, NULL, - false); - else - ret = add_pages(nid, align_start >> PAGE_SHIFT, - align_size >> PAGE_SHIFT, NULL, false); - if (ret) { - mem_hotplug_done(); - goto error_add_memory; - } - move_pfn_range_to_zone(&NODE_DATA(nid)->node_zones[ZONE_DEVICE], - align_start >> PAGE_SHIFT, - align_size >> PAGE_SHIFT, NULL); - mem_hotplug_done(); - - /* - * Initialization of the pages has been deferred until now in order - * to allow us to do the work while not holding the hotplug lock. - */ - memmap_init_zone_device(&NODE_DATA(nid)->node_zones[ZONE_DEVICE], - align_start >> PAGE_SHIFT, - align_size >> PAGE_SHIFT, &devmem->pagemap); - - return 0; - -error_add_memory: - untrack_pfn(NULL, PHYS_PFN(align_start), align_size); -error_radix: - hmm_devmem_radix_release(devmem->resource); -error: - return ret; -} - /* * hmm_devmem_add() - hotplug ZONE_DEVICE memory for device memory * @@ -1190,6 +1041,7 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, { struct hmm_devmem *devmem; resource_size_t addr; + void *result; int ret; dev_pagemap_get_ops(); @@ -1244,14 +1096,18 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, devmem->pfn_last = devmem->pfn_first + (resource_size(devmem->resource) >> PAGE_SHIFT); - ret = hmm_devmem_pages_create(devmem); - if (ret) - return ERR_PTR(ret); - - ret = devm_add_action_or_reset(device, hmm_devmem_release, devmem); - if (ret) - return ERR_PTR(ret); + devmem->pagemap.type = MEMORY_DEVICE_PRIVATE; + devmem->pagemap.res = *devmem->resource; + devmem->pagemap.page_fault = hmm_devmem_fault; + devmem->pagemap.page_free = hmm_devmem_free; + devmem->pagemap.altmap_valid = false; + devmem->pagemap.ref = &devmem->ref; + devmem->pagemap.data = devmem; + devmem->pagemap.kill = hmm_devmem_ref_kill; + result = devm_memremap_pages(devmem->device, &devmem->pagemap); + if (IS_ERR(result)) + return result; return devmem; } EXPORT_SYMBOL(hmm_devmem_add); @@ -1261,6 +1117,7 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, struct resource *res) { struct hmm_devmem *devmem; + void *result; int ret; if (res->desc != IORES_DESC_DEVICE_PUBLIC_MEMORY) @@ -1293,19 +1150,18 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, devmem->pfn_last = devmem->pfn_first + (resource_size(devmem->resource) >> PAGE_SHIFT); - ret = hmm_devmem_pages_create(devmem); - if (ret) - return ERR_PTR(ret); - - ret = devm_add_action_or_reset(device, hmm_devmem_release, devmem); - if (ret) - return ERR_PTR(ret); - - ret = devm_add_action_or_reset(device, hmm_devmem_ref_kill, - &devmem->ref); - if (ret) - return ERR_PTR(ret); + devmem->pagemap.type = MEMORY_DEVICE_PUBLIC; + devmem->pagemap.res = *devmem->resource; + devmem->pagemap.page_fault = hmm_devmem_fault; + devmem->pagemap.page_free = hmm_devmem_free; + devmem->pagemap.altmap_valid = false; + devmem->pagemap.ref = &devmem->ref; + devmem->pagemap.data = devmem; + devmem->pagemap.kill = hmm_devmem_ref_kill; + result = devm_memremap_pages(devmem->device, &devmem->pagemap); + if (IS_ERR(result)) + return result; return devmem; } EXPORT_SYMBOL(hmm_devmem_add_resource); From patchwork Tue Nov 20 23:13:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10691445 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 7349D16B1 for ; Tue, 20 Nov 2018 23:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EFD82AC58 for ; Tue, 20 Nov 2018 23:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52FCA2AC59; Tue, 20 Nov 2018 23:25:57 +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 D2A6A2AC5C for ; Tue, 20 Nov 2018 23:25:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 952D26B2294; Tue, 20 Nov 2018 18:25:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9014C6B2296; Tue, 20 Nov 2018 18:25:55 -0500 (EST) 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 817246B2297; Tue, 20 Nov 2018 18:25:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 38F5E6B2294 for ; Tue, 20 Nov 2018 18:25:55 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id e68so4127730plb.3 for ; Tue, 20 Nov 2018 15:25:55 -0800 (PST) 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=KwMl5p8j+73VGDeoGja2a8heb8DxLlCZxG1xuU9a2ec=; b=duUlOsZl+mDDd154xCoJDaGS51fY0Z3c5SNJIr3O2NysOyHO0267SCceIvijFzxpV3 iuQ6Hq2YBZ4BuBjnIPtcRola7yxTjydgIl6qdJebVSE7m/lXxUfl2UBuGAfhFPP08coy XauQkeqUOQMKGEKUOkud5NRPRfM0YXYHvYYGTCktL+es9iP8c68h1/HZvKP1wRdx+84r UTpIuZ2leZBNM++ndbqQnCHzXdcJoCiwlFtyD628nWhaRlxgk9i+xn076fvvqlch8BGW ksdJqbEnZJ9jsoYEYrkXv/Z2bNrC+lp6QqfWIt4Oa6fznkqo77QOlrwaG+9lRrcekm1v wDJg== 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: AGRZ1gIpSBbkVyfP4HcehDu1wytye3B24OfBS90oEAgx77SVEwWaFvGt iLpOQ/fVS1AQLNFR/Z00Z4PHk6V2ixNV0Fy4uYscoIOHV0Iulm74CoZdNaDO8zffgGRaTiVZR15 +x887myRdE7BiHVUhax6uKT/D1OgvjEiDUVO1RKoXZYhws5jooJAehAzXOXnGp8z9aQ== X-Received: by 2002:a62:2095:: with SMTP id m21-v6mr4308221pfj.32.1542756354878; Tue, 20 Nov 2018 15:25:54 -0800 (PST) X-Google-Smtp-Source: AJdET5enYo5a6lEAPLlTAVdQhF8/xhdsk79jNhlE8RUYlqx2dAXtrw+2F+XPZWcKUASHYqY+H5le X-Received: by 2002:a62:2095:: with SMTP id m21-v6mr4308164pfj.32.1542756353859; Tue, 20 Nov 2018 15:25:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542756353; cv=none; d=google.com; s=arc-20160816; b=rKhSxUCCasKen4uCe1pxpal72KCfidk2vdPFsxsGfAdzmnHYzE3/v+zcGAjysZJ/KO T1e4M/lq6+2V8suLQCWImqu7P/f3gQSJVSeSqm26SSHFCnVYJ46lPAd7cOGbA/PYX821 AapcjW1tnvZCjzUFbTxdmC214PbuQAPNca0ed+O5CB1ZBh8htgkBy+59+SXl3Wpudm5X ynelRUob+TWIsgglNvYPTYQlJnFpVsfuG/YG93lUNp3hzBGGJVVRHF2bfQS1WL771nGu F9AL7fV+0DnUtd9qUZRVqvsmYMa5t6qPqJOsK2R/oMhp72IJgrSFq2GBaEkXSBLS3dcx Gc5g== 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=KwMl5p8j+73VGDeoGja2a8heb8DxLlCZxG1xuU9a2ec=; b=frKnq8WCPkXqZXxyTF5zLCcyjldtOdxQhujshcwZ6AMYuzhzwjWHjFQtWItOSyTZXG fYdszNK2vNJMU3gQc/KF6viCSK5xla2B6Ge0URtD/NbRw+uL7grLz9CLQj0LPCwG3RPI XqJdftj6nk0xBXqKw8ZlZ2kOVTwaCjLfUlEkKx9e9tokkxdoPhYx4ZECfYFg5zV07Kf5 0ttVlWvmpCMjidLJGHKqNc20kljhKiYOiARypgdtHVj91vYMBvYt4RmwRkO+Ng2YGsLq +b3mUF6YhtHtOvA9FjI69LYmHYVyRvtcRT5PWmdpEFGM4rNQf3fpSzfKQS+qv6MYJyHW Ssew== 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 z129si1576898pfz.13.2018.11.20.15.25.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 15:25:53 -0800 (PST) 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 fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 15:25:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,258,1539673200"; d="scan'208";a="106328848" 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; 20 Nov 2018 15:25:52 -0800 Subject: [PATCH v8 7/7] mm, hmm: Mark hmm_devmem_{add, add_resource} EXPORT_SYMBOL_GPL From: Dan Williams To: akpm@linux-foundation.org Cc: Logan Gunthorpe , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Christoph Hellwig , torvalds@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 20 Nov 2018 15:13:25 -0800 Message-ID: <154275560565.76910.15919297436557795278.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <154275556908.76910.8966087090637564219.stgit@dwillia2-desk3.amr.corp.intel.com> References: <154275556908.76910.8966087090637564219.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 The routines hmm_devmem_add(), and hmm_devmem_add_resource() duplicated devm_memremap_pages() and are now simple now wrappers around the core facility to inject a dev_pagemap instance into the global pgmap_radix and hook page-idle events. The devm_memremap_pages() interface is base infrastructure for HMM. HMM has more and deeper ties into the kernel memory management implementation than base ZONE_DEVICE which is itself a EXPORT_SYMBOL_GPL facility. Originally, the HMM page structure creation routines copied the devm_memremap_pages() code and reused ZONE_DEVICE. A cleanup to unify the implementations was discussed during the initial review: http://lkml.iu.edu/hypermail/linux/kernel/1701.2/00812.html Recent work to extend devm_memremap_pages() for the peer-to-peer-DMA facility enabled this cleanup to move forward. In addition to the integration with devm_memremap_pages() HMM depends on other GPL-only symbols: mmu_notifier_unregister_no_release percpu_ref region_intersects __class_create It goes further to consume / indirectly expose functionality that is not exported to any other driver: alloc_pages_vma walk_page_range HMM is derived from devm_memremap_pages(), and extends deep core-kernel fundamentals. Similar to devm_memremap_pages(), mark its entry points EXPORT_SYMBOL_GPL(). Cc: Logan Gunthorpe Cc: "Jérôme Glisse" Reviewed-by: Christoph Hellwig Signed-off-by: Dan Williams --- mm/hmm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index bf2495d9de81..50fbaf80f95e 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -1110,7 +1110,7 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, return result; return devmem; } -EXPORT_SYMBOL(hmm_devmem_add); +EXPORT_SYMBOL_GPL(hmm_devmem_add); struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, struct device *device, @@ -1164,7 +1164,7 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, return result; return devmem; } -EXPORT_SYMBOL(hmm_devmem_add_resource); +EXPORT_SYMBOL_GPL(hmm_devmem_add_resource); /* * A device driver that wants to handle multiple devices memory through a