From patchwork Mon Oct 22 20:13:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 10652425 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 BB12513BF for ; Mon, 22 Oct 2018 20:18:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3AFB28EC3 for ; Mon, 22 Oct 2018 20:18:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EEE728EC4; Mon, 22 Oct 2018 20:18:46 +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 ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E515E28ED4 for ; Mon, 22 Oct 2018 20:18:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DBEE32194D3B8; Mon, 22 Oct 2018 13:18:45 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=dave.hansen@linux.intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 340242117B57B for ; Mon, 22 Oct 2018 13:18:44 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2018 13:18:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,413,1534834800"; d="scan'208";a="90396632" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by FMSMGA003.fm.intel.com with ESMTP; 22 Oct 2018 13:18:42 -0700 Subject: [PATCH 5/9] dax/kmem: add more nd dax kmem infrastructure To: linux-kernel@vger.kernel.org From: Dave Hansen Date: Mon, 22 Oct 2018 13:13:26 -0700 References: <20181022201317.8558C1D8@viggo.jf.intel.com> In-Reply-To: <20181022201317.8558C1D8@viggo.jf.intel.com> Message-Id: <20181022201326.5E3F2752@viggo.jf.intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.lendacky@amd.com, mhocko@suse.com, linux-nvdimm@lists.01.org, Dave Hansen , ying.huang@intel.com, linux-mm@kvack.org, zwisler@kernel.org, fengguang.wu@intel.com, akpm@linux-foundation.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Each DAX mode has a set of wrappers and helpers. Add them for the kmem mode. Cc: Dan Williams Cc: Dave Jiang Cc: Ross Zwisler Cc: Vishal Verma Cc: Tom Lendacky Cc: Andrew Morton Cc: Michal Hocko Cc: linux-nvdimm@lists.01.org Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: Huang Ying Cc: Fengguang Wu --- b/drivers/nvdimm/bus.c | 2 ++ b/drivers/nvdimm/dax_devs.c | 35 +++++++++++++++++++++++++++++++++++ b/drivers/nvdimm/nd.h | 6 ++++++ 3 files changed, 43 insertions(+) diff -puN drivers/nvdimm/bus.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem drivers/nvdimm/bus.c --- a/drivers/nvdimm/bus.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem 2018-10-22 13:12:23.024930389 -0700 +++ b/drivers/nvdimm/bus.c 2018-10-22 13:12:23.031930389 -0700 @@ -46,6 +46,8 @@ static int to_nd_device_type(struct devi return ND_DEVICE_REGION_BLK; else if (is_nd_dax(dev)) return ND_DEVICE_DAX_PMEM; + else if (is_nd_dax_kmem(dev)) + return ND_DEVICE_DAX_KMEM; else if (is_nd_region(dev->parent)) return nd_region_to_nstype(to_nd_region(dev->parent)); diff -puN drivers/nvdimm/dax_devs.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem drivers/nvdimm/dax_devs.c --- a/drivers/nvdimm/dax_devs.c~dax-kmem-try-again-2018-4-bus-dev-type-kmem 2018-10-22 13:12:23.026930389 -0700 +++ b/drivers/nvdimm/dax_devs.c 2018-10-22 13:12:23.031930389 -0700 @@ -51,6 +51,41 @@ struct nd_dax *to_nd_dax(struct device * } EXPORT_SYMBOL(to_nd_dax); +/* nd_dax_kmem */ +static void nd_dax_kmem_release(struct device *dev) +{ + struct nd_region *nd_region = to_nd_region(dev->parent); + struct nd_dax_kmem *nd_dax_kmem = to_nd_dax_kmem(dev); + struct nd_pfn *nd_pfn = &nd_dax_kmem->nd_pfn; + + dev_dbg(dev, "trace\n"); + nd_detach_ndns(dev, &nd_pfn->ndns); + ida_simple_remove(&nd_region->dax_ida, nd_pfn->id); + kfree(nd_pfn->uuid); + kfree(nd_dax_kmem); +} + +static struct device_type nd_dax_kmem_device_type = { + .name = "nd_dax_kmem", + .release = nd_dax_kmem_release, +}; + +bool is_nd_dax_kmem(struct device *dev) +{ + return dev ? dev->type == &nd_dax_kmem_device_type : false; +} +EXPORT_SYMBOL(is_nd_dax_kmem); + +struct nd_dax_kmem *to_nd_dax_kmem(struct device *dev) +{ + struct nd_dax_kmem *nd_dax_kmem = container_of(dev, struct nd_dax_kmem, nd_pfn.dev); + + WARN_ON(!is_nd_dax_kmem(dev)); + return nd_dax_kmem; +} +EXPORT_SYMBOL(to_nd_dax_kmem); +/* end nd_dax_kmem */ + static const struct attribute_group *nd_dax_attribute_groups[] = { &nd_pfn_attribute_group, &nd_device_attribute_group, diff -puN drivers/nvdimm/nd.h~dax-kmem-try-again-2018-4-bus-dev-type-kmem drivers/nvdimm/nd.h --- a/drivers/nvdimm/nd.h~dax-kmem-try-again-2018-4-bus-dev-type-kmem 2018-10-22 13:12:23.027930389 -0700 +++ b/drivers/nvdimm/nd.h 2018-10-22 13:12:23.031930389 -0700 @@ -215,6 +215,10 @@ struct nd_dax { struct nd_pfn nd_pfn; }; +struct nd_dax_kmem { + struct nd_pfn nd_pfn; +}; + enum nd_async_mode { ND_SYNC, ND_ASYNC, @@ -318,9 +322,11 @@ static inline int nd_pfn_validate(struct #endif struct nd_dax *to_nd_dax(struct device *dev); +struct nd_dax_kmem *to_nd_dax_kmem(struct device *dev); #if IS_ENABLED(CONFIG_NVDIMM_DAX) int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns); bool is_nd_dax(struct device *dev); +bool is_nd_dax_kmem(struct device *dev); struct device *nd_dax_create(struct nd_region *nd_region); #else static inline int nd_dax_probe(struct device *dev,