Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp62502pxu; Tue, 6 Oct 2020 00:15:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEBfb3CZnPiCXnMxhPzwAamRrBfAlDQfX7FBoOeZ1WDLpbj7gOdDiswd4zYp0pcayPc/Ia X-Received: by 2002:a05:6402:32f:: with SMTP id q15mr3892025edw.230.1601968516463; Tue, 06 Oct 2020 00:15:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601968516; cv=none; d=google.com; s=arc-20160816; b=Qcok7jrAn02EljtxBRsSv0R/P6/Y4DdlS4Xba+xBTpbBK+uLUKN/PNg6g1qHwVHwqR ZINnX/CJChkHbr7Z5rYf8R9U0OVl1hEtSeI6hSxEC85XvxCmguQQbupkyOYfqBys3QwT 8PIjyknMgCsTfKvoy4qBnijkdVH7TQ2my1ZycL2ZSelBAJSAk7r7tfNsSqFKSr9hyskb T5jFtM5AVjix1RJxdezNja63hZcEPhiygb0DeX1geTCCbEzr2fYMU7YXXORUy9u9e/LG F2bfFEVwqtEUR4YVFK+dzz5ti1zpEWse2Bue+WXuBGGBlu0xAqsMotVm042Cno0Fl3Qj 5ong== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=bbEFMJ2g6iLnYUErlQgC25GCe1HI1WsrfL0g5g2423c=; b=QqCm5GX5x0RHw9aCI0ZPnzVCI7igSgzTndFzOUKPV8gt2EGYtszzapDY+0LrfWUU+K SQ7Kdcdhw73dH8VNZ0rboOuMwDhmHpIOD4gP89JiocJWJyDuWhFw4/biGD+KnW5TbfSK uA5GGCKGZA9P5DtREeuFa0lHIyLhOf8Ev0RIO+FxgaoRTLUjjE11Qr6I6UDRb8CBsa+X 1598MFQtyAfH75zDYTcVQfgh/MOadwAAiRHMR7rqCnkLp+GfGIOj5P3t9/uOgy7L6SaS H2/zT87UiwvgoYlVwsIwn/ABgPlAaCfP2jg2i9QpqP5CmOiIzrdb1KDnVEmdF/MYpmut A3lA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id x8si1345066ejf.748.2020.10.06.00.14.53; Tue, 06 Oct 2020 00:15:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727162AbgJFHNd (ORCPT + 99 others); Tue, 6 Oct 2020 03:13:33 -0400 Received: from mga14.intel.com ([192.55.52.115]:23379 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbgJFHNd (ORCPT ); Tue, 6 Oct 2020 03:13:33 -0400 IronPort-SDR: NAAcnTQX2qWUraI5Zmj8mE0ZIUkgKJHrvp32Vigr3wOKr5gcj9ZTUlpJ186OqnJLcCbz+7ovDK pfeQdoO7iahg== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="163620322" X-IronPort-AV: E=Sophos;i="5.77,342,1596524400"; d="scan'208";a="163620322" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 00:13:32 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; }