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: 10652439 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 F2A6E13BF for ; Mon, 22 Oct 2018 20:18:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD7162916E for ; Mon, 22 Oct 2018 20:18:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1A2629182; Mon, 22 Oct 2018 20:18:56 +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=unavailable 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 64F1A2916E for ; Mon, 22 Oct 2018 20:18:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 086116B0010; Mon, 22 Oct 2018 16:18:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 034056B0266; Mon, 22 Oct 2018 16:18:45 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E677E6B0269; Mon, 22 Oct 2018 16:18:45 -0400 (EDT) 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 A02526B0010 for ; Mon, 22 Oct 2018 16:18:45 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id s24-v6so31286776plp.12 for ; Mon, 22 Oct 2018 13:18:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:to:cc :from:date:references:in-reply-to:message-id; bh=YZQu2PAToEfu/CwqUQmMm3p8NDieJe9WhunaKTrrkBU=; b=sFk2G9LVN44vYvBVKZrUA2dba6I9c3dKc0M8E54ET/18ewHSTIRg9fcCFTcPfpielU HHgs6IsepWkW2pE+OBV4rCU2YAG8A2aX/CC8ckSb5LPw5+DDxlzMw1zXeir5XppQ10mf 3Iw4EOcqa86VEqBQCVePiKIXwRCxapU7pWBVlXdpW18lkz/8NQUlsMH62Rgj8PBw36fw HCrLO6JK6ROmzv4CYgDO3LLnnYS2wTxzT4Pjho80bDapMH6ET0Y9XwgX1kDXEUNkW8ni RjwDYjSfe8CJNjISm/wW8mwPT867Fh77X8xbJMDybA2Jw2kVn4XuloacjZ2wxgxu39aO J3QQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ABuFfogvlOf0429R5i//TtC/0Pio/y5J5dmQON7fShldXlE+jSUvfFfk upxqB8naoh+cjHYjB2UpUXqC5YlSQOKZt3cuTa5ly5qoJh4bOR9/KQ04B6KKkKj40o/9nYZAZEM TqDLpiCUzH9t+QkuczSvfxJptaBXstVnSoyWkcfTW5VuJ/XgodKisTtpg5uN3dyojvQ== X-Received: by 2002:a63:4658:: with SMTP id v24-v6mr44938464pgk.425.1540239525319; Mon, 22 Oct 2018 13:18:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV606GLXHMS5z8uJAX2ulEsR7EPXz6LjIuZKC4fhOhb6Gasdk8L2Os7C+H+n3hga2I+XMnln5 X-Received: by 2002:a63:4658:: with SMTP id v24-v6mr44938427pgk.425.1540239524651; Mon, 22 Oct 2018 13:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540239524; cv=none; d=google.com; s=arc-20160816; b=jJKfdvNtbEHc3lqmz9nnDDjCIAZI7cMgjgrfXBXQJLsoy2SUg4cyZVFz4WQsjga/Uf qacavDqapkzw1bGkhwghyG3Scynmw3w+I0h11hPE/twfiD0hBckEUgYEY/x7Z/ErM9uf c3N4xHlGnDDbnvWJugoyiD2b0ealXn1nWsxSN7Is/uLbhfbuiOSlnHXnqK/cICTueMaY jK7ILEnNhsV7VfcAO+ZByXj7VcoDN9l0eQtkynXABz60/71+X0FDFZxVRiTT7o02MZ1k GRdNgT8hzLTNaqsHg403ta+aDD+N56Bof64npRIMTXBv2eVXC8kLcZmRjbRBU5AtA8n0 CpKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:in-reply-to:references:date:from:cc:to:subject; bh=YZQu2PAToEfu/CwqUQmMm3p8NDieJe9WhunaKTrrkBU=; b=uTk/4nQO4kIfVo+C8HLZoZyQGhLZWoKNa4Nkv+rgrAwbxm0WZ5SCHFiimd/bmuozZS P6aNy8iHgClPelu064u8sLOw+ngeULeA65C5AEsCVyOfhDGmL53tGIURSlksX4y0NzZ3 n3QF2LvhnLExVkdjhIA0UurxoA8lmjAOlQFYcmL7+ypdrzTVJi88OZ6wAIjPh5KGnrED Z0AcCy+QUuwUG+zWZfnVHGZ/+M+6fdLXm+gM2NSNV8K+W79TgeefBZeDoaqotZk0whus s1Zp1OvXOHuovWzTiauX3JLEyLzoa1JQ0kyBFy/X/Few35KQ5WYAj+24LajWnR+1F6y3 ohWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id m13-v6si36529525pfd.123.2018.10.22.13.18.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Oct 2018 13:18:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.31 as permitted sender) client-ip=134.134.136.31; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dave.hansen@linux.intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dave.hansen@linux.intel.com; dmarc=fail (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 fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.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 Cc: Dave Hansen ,dan.j.williams@intel.com,dave.jiang@intel.com,zwisler@kernel.org,vishal.l.verma@intel.com,thomas.lendacky@amd.com,akpm@linux-foundation.org,mhocko@suse.com,linux-nvdimm@lists.01.org,linux-mm@kvack.org,ying.huang@intel.com,fengguang.wu@intel.com 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-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 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,