From patchwork Tue Oct 6 06:55:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11818143 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4FEB112E for ; Tue, 6 Oct 2020 07:13:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5989E20760 for ; Tue, 6 Oct 2020 07:13:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5989E20760 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 704EE6B006C; Tue, 6 Oct 2020 03:13:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6B4DE6B006E; Tue, 6 Oct 2020 03:13:35 -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 5F3186B0070; Tue, 6 Oct 2020 03:13:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 322186B006C for ; Tue, 6 Oct 2020 03:13:35 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id ABCF18249980 for ; Tue, 6 Oct 2020 07:13:34 +0000 (UTC) X-FDA: 77340635148.15.loss99_3615164271c4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 8729C1814B0C8 for ; Tue, 6 Oct 2020 07:13:34 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,dan.j.williams@intel.com,,RULES_HIT:30003:30029:30054:30064:30075,0,RBL:192.55.52.88:@intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95;04yrqu6k5b7xk1wefgobcm45penheyp8dhmqcfs9a1qp6encppqi7carzcp9mqn.9q5k3wmj7y5nqkubi8zqq4o3uz8f95e6oqy8e7nm33rs1xbudmtycodq4t9c37s.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: loss99_3615164271c4 X-Filterd-Recvd-Size: 7124 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 6 Oct 2020 07:13:32 +0000 (UTC) IronPort-SDR: Th1K1aEiAFowOPofYlSWbt1iUTO0Kyph2HN94wiA6IDrR3TRzhWggFh3LbxxeB3A7G7frktkTm gk97CQHq4pEg== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="181838816" X-IronPort-AV: E=Sophos;i="5.77,342,1596524400"; d="scan'208";a="181838816" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 00:13:31 -0700 IronPort-SDR: Lpburd44iz5IWPN6MOMltmCFpFdExXzrzkx+2xwoR0GxQaypnhjpuB9lSPS6Xi4GWoUFMZ/d8S kDUNUAjjIeYg== X-IronPort-AV: E=Sophos;i="5.77,342,1596524400"; d="scan'208";a="315498301" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 00:13:31 -0700 Subject: [PATCH v6 03/11] device-dax/kmem: move resource tracking to drvdata From: Dan Williams To: akpm@linux-foundation.org Cc: David Hildenbrand , Vishal Verma , Dave Hansen , Pavel Tatashin , Brice Goglin , Dave Jiang , David Hildenbrand , Ira Weiny , Jia He , Joao Martins , Jonathan Cameron , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, david@redhat.com, joao.m.martins@oracle.com Date: Mon, 05 Oct 2020 23:55:02 -0700 Message-ID: <160196730203.2166475.10332959995680506711.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <160196728453.2166475.12832711415715687418.stgit@dwillia2-desk3.amr.corp.intel.com> References: <160196728453.2166475.12832711415715687418.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c 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: Towards removing the mode specific @dax_kmem_res attribute from the generic 'struct dev_dax', and preparing for multi-range support, move resource tracking to driver data. The memory for the resource name needs to have its own lifetime separate from the device bind lifetime for cases where the driver is unbound, but the kmem range could not be unplugged from the page allocator. The resource reservation also needs to be released manually via release_resource() given the awkward manipulation of the IORESOURCE_BUSY flag. Cc: David Hildenbrand Cc: Vishal Verma Cc: Dave Hansen Cc: Pavel Tatashin Cc: Brice Goglin Cc: Dave Jiang Cc: David Hildenbrand Cc: Ira Weiny Cc: Jia He Cc: Joao Martins Cc: Jonathan Cameron Signed-off-by: Dan Williams Reviewed-by: David Hildenbrand --- drivers/dax/dax-private.h | 3 -- drivers/dax/kmem.c | 55 +++++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index fbaea36938ae..0668b58c64aa 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -42,8 +42,6 @@ struct dax_region { * @dev - device core * @pgmap - pgmap for memmap setup / lifetime (driver owned) * @range: resource range for the instance - * @dax_mem_res: physical address range of hotadded DAX memory - * @dax_mem_name: name for hotadded DAX memory via add_memory_driver_managed() */ struct dev_dax { struct dax_region *region; @@ -52,7 +50,6 @@ struct dev_dax { struct device dev; struct dev_pagemap *pgmap; struct range range; - struct resource *dax_kmem_res; }; static inline struct dev_dax *to_dev_dax(struct device *dev) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index b0d6a99cf12d..a415bc239db4 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -29,14 +29,19 @@ static struct range dax_kmem_range(struct dev_dax *dev_dax) return range; } +struct dax_kmem_data { + const char *res_name; + struct resource *res; +}; + int dev_dax_kmem_probe(struct device *dev) { struct dev_dax *dev_dax = to_dev_dax(dev); struct range range = dax_kmem_range(dev_dax); + struct dax_kmem_data *data; struct resource *new_res; - const char *new_res_name; + int rc = -ENOMEM; int numa_node; - int rc; /* * Ensure good NUMA information for the persistent memory. @@ -51,17 +56,22 @@ int dev_dax_kmem_probe(struct device *dev) return -EINVAL; } - new_res_name = kstrdup(dev_name(dev), GFP_KERNEL); - if (!new_res_name) + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) return -ENOMEM; + data->res_name = kstrdup(dev_name(dev), GFP_KERNEL); + if (!data->res_name) + goto err_res_name; + /* Region is permanently reserved if hotremove fails. */ - new_res = request_mem_region(range.start, range_len(&range), new_res_name); + new_res = request_mem_region(range.start, range_len(&range), data->res_name); if (!new_res) { dev_warn(dev, "could not reserve region [%#llx-%#llx]\n", range.start, range.end); - kfree(new_res_name); - return -EBUSY; + rc = -EBUSY; + goto err_request_mem; } + data->res = new_res; /* * Set flags appropriate for System RAM. Leave ..._BUSY clear @@ -77,15 +87,21 @@ int dev_dax_kmem_probe(struct device *dev) */ rc = add_memory_driver_managed(numa_node, new_res->start, resource_size(new_res), kmem_name); - if (rc) { - release_resource(new_res); - kfree(new_res); - kfree(new_res_name); - return rc; - } - dev_dax->dax_kmem_res = new_res; + if (rc) + goto err_add_memory; + + dev_set_drvdata(dev, data); return 0; + +err_add_memory: + release_resource(data->res); + kfree(data->res); +err_request_mem: + kfree(data->res_name); +err_res_name: + kfree(data); + return rc; } #ifdef CONFIG_MEMORY_HOTREMOVE @@ -93,8 +109,7 @@ static int dev_dax_kmem_remove(struct device *dev) { struct dev_dax *dev_dax = to_dev_dax(dev); struct range range = dax_kmem_range(dev_dax); - struct resource *res = dev_dax->dax_kmem_res; - const char *res_name = res->name; + struct dax_kmem_data *data = dev_get_drvdata(dev); int rc; /* @@ -112,10 +127,10 @@ static int dev_dax_kmem_remove(struct device *dev) } /* Release and free dax resources */ - release_resource(res); - kfree(res); - kfree(res_name); - dev_dax->dax_kmem_res = NULL; + release_resource(data->res); + kfree(data->res); + kfree(data->res_name); + kfree(data); return 0; }