Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp63352pxu; Tue, 6 Oct 2020 00:16:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIiJsKuwHPWKkrXzNVDSBZfgDvsjDtpZV4HVHH1fMUSQRZi95u9+hlTAr3BsCRgJVxCGfH X-Received: by 2002:aa7:c3c7:: with SMTP id l7mr3834220edr.213.1601968617702; Tue, 06 Oct 2020 00:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601968617; cv=none; d=google.com; s=arc-20160816; b=TwqnBHXhxakzqe6Iyr422Bd52Ss3iua7ElBWw+1C/FHPQ3Sm3TJCrzOnDdnhsVXhHA E15jmE9++PtGBZ41jPxG/acQ39CbxtueyhoIr2KPViP0kqmHQsqJSBX5WmCWVs+DNZf+ ufIP6yV5Rc5hMRS5ldUi7zhZ6TdUjjaK4t3FhA2KshoL5xjYjyj45KywubDDuAYkh4+n S0hp7YoSzE4r0Uql6GQzA0EPQy3OC93LUdlfYJcB+hp+UdEMrdJzTHaP+itdByiSYfFh 7gkjIpyzCmAbzvzFRnqBlCNuGLKYZIaLmPlqcZ4UfW+BUGyYlIJz8eWN98UaCEyLjn1j MvqA== 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=WR1OcGMdhWvy2Kl8AR3YfOpfH0UeUw1UTJQuR6VS0g0=; b=hhH1MogRiUt9P8yXD+vLzgMOtPPhccD+bH2WbVoKTUIj5iSoFBWHsryYpzMTZWAQh0 Ln7qD2g24hQAv04AF3oLwdKZ+9ms2Z3f6iV5oopPmFkWMiu5sYl6biElDoPfKoPIDKMu rS5c+sbIQl0eZtxwI3A8BUa/K0E+ZLA8skD3E8M9++U+QSTjEQrR6S7I7t9yy2Cnkset rjaM68LHC9Q3RSt/irlP3w5OJ3avShH/w7e/zaSkB4EfmDcsc8zEY9159+qSvWopqYvo 6SCKkSGM37A95eCWlJM9WmRdXJJKBzPYjN4KLQC72YYw/lPYnBKMkW5LYTGUL7jjz/Q7 BEDg== 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 qq26si1364330ejb.103.2020.10.06.00.16.34; Tue, 06 Oct 2020 00:16:57 -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 S1727074AbgJFHN3 (ORCPT + 99 others); Tue, 6 Oct 2020 03:13:29 -0400 Received: from mga14.intel.com ([192.55.52.115]:23369 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbgJFHN0 (ORCPT ); Tue, 6 Oct 2020 03:13:26 -0400 IronPort-SDR: Kf5TlwXw2RWdjNCXgZENNBwzBG1vhgSRwPp7L6LFnVkelYURJDYS3SbDh4oLbqLGlkQAntTfLs gNreELyADiuQ== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="163620305" X-IronPort-AV: E=Sophos;i="5.77,342,1596524400"; d="scan'208";a="163620305" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 00:13:26 -0700 IronPort-SDR: XivimXtqlVbpdgrXaCu3isyj/RVjyclZa0SqHgnuigdrm4auQgTCKcnqROf8o+nB3rX6iuGMHA cD57abKZmLNw== X-IronPort-AV: E=Sophos;i="5.77,342,1596524400"; d="scan'208";a="342009084" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.25]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 00:13:25 -0700 Subject: [PATCH v6 02/11] device-dax/kmem: introduce dax_kmem_range() From: Dan Williams To: akpm@linux-foundation.org Cc: David Hildenbrand , Vishal Verma , Dave Hansen , Pavel Tatashin , Brice Goglin , Dave Jiang , Ira Weiny , Jia He , Joao Martins , Jonathan Cameron , David Hildenbrand , 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:54:56 -0700 Message-ID: <160196729611.2166475.17062304475053542512.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, teach the driver to calculate the hotplug range from the device range. The hotplug range is the trivially calculated memory-block-size aligned version of the device range. Cc: David Hildenbrand Cc: Vishal Verma Cc: Dave Hansen Cc: Pavel Tatashin Cc: Brice Goglin Cc: Dave Jiang Cc: Ira Weiny Cc: Jia He Cc: Joao Martins Cc: Jonathan Cameron Reviewed-by: David Hildenbrand Signed-off-by: Dan Williams --- drivers/dax/kmem.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index 5bb133df147d..b0d6a99cf12d 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -19,13 +19,20 @@ static const char *kmem_name; /* Set if any memory will remain added when the driver will be unloaded. */ static bool any_hotremove_failed; +static struct range dax_kmem_range(struct dev_dax *dev_dax) +{ + struct range range; + + /* memory-block align the hotplug range */ + range.start = ALIGN(dev_dax->range.start, memory_block_size_bytes()); + range.end = ALIGN_DOWN(dev_dax->range.end + 1, memory_block_size_bytes()) - 1; + return range; +} + int dev_dax_kmem_probe(struct device *dev) { struct dev_dax *dev_dax = to_dev_dax(dev); - struct range *range = &dev_dax->range; - resource_size_t kmem_start; - resource_size_t kmem_size; - resource_size_t kmem_end; + struct range range = dax_kmem_range(dev_dax); struct resource *new_res; const char *new_res_name; int numa_node; @@ -44,25 +51,14 @@ int dev_dax_kmem_probe(struct device *dev) return -EINVAL; } - /* Hotplug starting at the beginning of the next block: */ - kmem_start = ALIGN(range->start, memory_block_size_bytes()); - - kmem_size = range_len(range); - /* Adjust the size down to compensate for moving up kmem_start: */ - kmem_size -= kmem_start - range->start; - /* Align the size down to cover only complete blocks: */ - kmem_size &= ~(memory_block_size_bytes() - 1); - kmem_end = kmem_start + kmem_size; - new_res_name = kstrdup(dev_name(dev), GFP_KERNEL); if (!new_res_name) return -ENOMEM; /* Region is permanently reserved if hotremove fails. */ - new_res = request_mem_region(kmem_start, kmem_size, new_res_name); + new_res = request_mem_region(range.start, range_len(&range), new_res_name); if (!new_res) { - dev_warn(dev, "could not reserve region [%pa-%pa]\n", - &kmem_start, &kmem_end); + dev_warn(dev, "could not reserve region [%#llx-%#llx]\n", range.start, range.end); kfree(new_res_name); return -EBUSY; } @@ -96,9 +92,8 @@ int dev_dax_kmem_probe(struct device *dev) 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; - resource_size_t kmem_start = res->start; - resource_size_t kmem_size = resource_size(res); const char *res_name = res->name; int rc; @@ -108,12 +103,11 @@ static int dev_dax_kmem_remove(struct device *dev) * there is no way to hotremove this memory until reboot because device * unbind will succeed even if we return failure. */ - rc = remove_memory(dev_dax->target_node, kmem_start, kmem_size); + rc = remove_memory(dev_dax->target_node, range.start, range_len(&range)); if (rc) { any_hotremove_failed = true; - dev_err(dev, - "DAX region %pR cannot be hotremoved until the next reboot\n", - res); + dev_err(dev, "%#llx-%#llx cannot be hotremoved until the next reboot\n", + range.start, range.end); return rc; }