Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7351662imu; Mon, 3 Dec 2018 11:26:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/XgFHxtIPw4kmCD7KLLizvauSKysd/GV2T7jDnYM157xgSNT18DUeDyLlKIgvcAmLw4qfDn X-Received: by 2002:a63:bc02:: with SMTP id q2mr14427465pge.116.1543865200600; Mon, 03 Dec 2018 11:26:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543865200; cv=none; d=google.com; s=arc-20160816; b=zOyTkj9Kh4H1golnAg7IXI9X8q0SnlsPiBQ24tq3Ka+pVZiHAJn41RIXSEUuZ7JNBG 7XUCteKryM1WAHWWfMejwSgv2tnXHPflkyt6fsiLiwGuDh0E4sYF7T9kbKiBOvb6WgTG bcxGJH3WiGVgaYRViNGALnJ5xFpF+TIRb6VLEiSvE5maQUN8RPk/i/b0jlFLGyt1MM2g ywKDwNk3OiIRtcKSXnPF0ARkEDJvJueIayunFDdf8Q5vTnsXiqwSNwhzOeLCv0Oqujzg 58xbbhZNKjCy2y2ykvgZESU2I2B2uajQlTGaDuEtYeW1RZmQJQuERui8SY06pNGYkPv5 vY5w== 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:cc:to:from :subject; bh=+JW37OLA1PzhppomMkQAHxM+9jcH+WF9d6PlioQUTMQ=; b=l0mIxUek7N71UuKPb/rv1hH1/Cbo17Tj5ntg4QDy2Nk9jYaI+mEkMCMFXYyaOCJx/R u/k3XxcdT2590pIBA8ph7I8zweNKoj9GDRQ7wxu2An9LMgd0WVUrCT8o5yRFdNTWI3td pYGJ5AZH6a50OV8TFHelY3YqtWMYLKcFHbJ/djnAWJK7V7b5xOpDUM7zy2zVYYXj7ck6 T9FHgXogezGyINwnAwIbX76jhtv7Iw5HNgtowpASbpj0iHF+ehqFkq2izpFmipKbN+YR iDMBP3Ay52UfUAR+MLwUHry3APElSauH2Dd8MMvMgSnXhjtAXuUV1DBuLfOoi4602sVW iHCQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c5si13691869pgq.434.2018.12.03.11.26.25; Mon, 03 Dec 2018 11:26:40 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726165AbeLCTZg (ORCPT + 99 others); Mon, 3 Dec 2018 14:25:36 -0500 Received: from mga14.intel.com ([192.55.52.115]:36607 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbeLCTZg (ORCPT ); Mon, 3 Dec 2018 14:25:36 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2018 11:25:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,311,1539673200"; d="scan'208";a="115600505" Received: from ahduyck-desk1.amr.corp.intel.com ([10.7.198.76]) by orsmga001.jf.intel.com with ESMTP; 03 Dec 2018 11:25:31 -0800 Subject: [PATCH RFC 2/3] mm: Add support for exposing if dev_pagemap supports refcount pinning From: Alexander Duyck To: dan.j.williams@intel.com, pbonzini@redhat.com, yi.z.zhang@linux.intel.com, brho@google.com, kvm@vger.kernel.org, linux-nvdimm@lists.01.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dave.jiang@intel.com, yu.c.zhang@intel.com, pagupta@redhat.com, david@redhat.com, jack@suse.cz, hch@lst.de, rkrcmar@redhat.com, jglisse@redhat.com Date: Mon, 03 Dec 2018 11:25:31 -0800 Message-ID: <154386513120.27193.7977541941078967487.stgit@ahduyck-desk1.amr.corp.intel.com> In-Reply-To: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> References: <154386493754.27193.1300965403157243427.stgit@ahduyck-desk1.amr.corp.intel.com> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a means of exposing if a pagemap supports refcount pinning. I am doing this to expose if a given pagemap has backing struct pages that will allow for the reference count of the page to be incremented to lock the page into place. The KVM code already has several spots where it was trying to use a pfn_valid check combined with a PageReserved check to determien if it could take a reference on the page. I am adding this check so in the case of the page having the reserved flag checked we can check the pagemap for the page to determine if we might fall into the special DAX case. Signed-off-by: Alexander Duyck --- drivers/nvdimm/pfn_devs.c | 2 ++ include/linux/memremap.h | 5 ++++- include/linux/mm.h | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c index 6f22272e8d80..7a4a85bcf7f4 100644 --- a/drivers/nvdimm/pfn_devs.c +++ b/drivers/nvdimm/pfn_devs.c @@ -640,6 +640,8 @@ static int __nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap) } else return -ENXIO; + pgmap->support_refcount_pinning = true; + return 0; } diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 55db66b3716f..6e7b85542208 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -109,6 +109,8 @@ typedef void (*dev_page_free_t)(struct page *page, void *data); * @page_fault: callback when CPU fault on an unaddressable device page * @page_free: free page callback when page refcount reaches 1 * @altmap: pre-allocated/reserved memory for vmemmap allocations + * @altmap_valid: bitflag indicating if altmap is valid + * @support_refcount_pinning: bitflag indicating if we support refcount pinning * @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 @@ -120,7 +122,8 @@ struct dev_pagemap { dev_page_fault_t page_fault; dev_page_free_t page_free; struct vmem_altmap altmap; - bool altmap_valid; + bool altmap_valid:1; + bool support_refcount_pinning:1; struct resource res; struct percpu_ref *ref; void (*kill)(struct percpu_ref *ref); diff --git a/include/linux/mm.h b/include/linux/mm.h index 3eb3bf7774f1..5faf66dd4559 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -970,6 +970,12 @@ static inline bool is_pci_p2pdma_page(const struct page *page) } #endif /* CONFIG_PCI_P2PDMA */ +static inline bool is_device_pinnable_page(const struct page *page) +{ + return is_zone_device_page(page) && + page->pgmap->support_refcount_pinning; +} + #else /* CONFIG_DEV_PAGEMAP_OPS */ static inline void dev_pagemap_get_ops(void) { @@ -998,6 +1004,11 @@ static inline bool is_pci_p2pdma_page(const struct page *page) { return false; } + +static inline bool is_device_pinnable_page(const struct page *page) +{ + return false; +} #endif /* CONFIG_DEV_PAGEMAP_OPS */ static inline void get_page(struct page *page)