Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1398533pxk; Fri, 25 Sep 2020 13:47:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4Gh6GV95hiimUn2B/C4dBykOVwupWUat4grWOKzpGZPxi0yvEs6sDW1b1fB1cncb+fykd X-Received: by 2002:a17:906:6007:: with SMTP id o7mr4827308ejj.550.1601066837573; Fri, 25 Sep 2020 13:47:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601066837; cv=none; d=google.com; s=arc-20160816; b=0gE0i7fxG8BWsU7xjBeLN81dbB/ptH65u9Fl1FQ5iKAgKk2R772INuFSDIUqM7V9OW 0YOq0ReWXJrUEWIIskmGXnvt8hkl7D7HtHUuM5iZrALuiBczkZ6bPVmK5vGE+CErIW4t G+AWrRGE51i0fez+72RxbU+ks52ebvpW0RgEfT1y4CukQooCcUmHSgjaopb7iVdFYpI+ HpofxIVbPjnE3oREAyLf4fqruG9uzDHMZyjtsQ0tKj/xDkPm/fsXGbLoetUqIYtvV9Lc nrp9amkYXlUsQd/Exvft6LZfFyx8HQvpBngg3XMls6isZChYmVgheylAMbNXqJdLDm/l v+RQ== 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=9T1VatbRXYeN2zYxnZ4BdCgiu33K23nDUjp2SMgV5lw=; b=n/4zUZ9NERfP2ONyijxobHkNI4fL1EvcsZllvxyQzqaH5sCuVrKonA3JUF+StX8kwR MSYlb3kWAIa04x7Yw53MKsyOp+welYfD11uT9czXUSGGw92inAQ1yUtuym2VPR4XGvA/ iDhEc+34Hu5NM6npXog0nYGXp1ZIlWI6gDYrEyOFv2xCqwyhyVSPaDG14qHPAzPO0cQ/ jSl84dLz7kyR91B0rrU4oc4iys/PF9jH9hXkwLdjrcWOIRpr3mBjwTc9+hQLm7jeGq9p SXzcnbJw+3vCqPVw3OlG2IDn9l/4C1Iyy45HrelPFU3P5SDLQs7r2p4N/xpy/M3VgWH8 ChXw== 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 ba30si2881074edb.44.2020.09.25.13.46.54; Fri, 25 Sep 2020 13:47:17 -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 S1729020AbgIYUpR (ORCPT + 99 others); Fri, 25 Sep 2020 16:45:17 -0400 Received: from mga03.intel.com ([134.134.136.65]:46756 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727495AbgIYUpQ (ORCPT ); Fri, 25 Sep 2020 16:45:16 -0400 IronPort-SDR: hGuau1/GXGEknWYN83sb85OwcIxGrG8bRI23Sg70nAUkWP//76CDKhCrryu1N3hamSri0OxKoL mv8PXLu3Qkkw== X-IronPort-AV: E=McAfee;i="6000,8403,9755"; a="161701310" X-IronPort-AV: E=Sophos;i="5.77,303,1596524400"; d="scan'208";a="161701310" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 12:30:12 -0700 IronPort-SDR: XSvlghnB1tJsZcOX7krYgEDRiotpg6HKhmkknI0fihWB4dCKWvZG16kjNyhrZAcDdM6AdS6X3A q+g3Atacrn8A== X-IronPort-AV: E=Sophos;i="5.77,303,1596524400"; d="scan'208";a="306390388" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 12:30:11 -0700 Subject: [PATCH v5 02/17] 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 , David Hildenbrand , Ira Weiny , Jia He , Joao Martins , Jonathan Cameron , linux-mm@kvack.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Fri, 25 Sep 2020 12:11:51 -0700 Message-ID: <160106111109.30709.3173462396758431559.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <160106109960.30709.7379926726669669398.stgit@dwillia2-desk3.amr.corp.intel.com> References: <160106109960.30709.7379926726669669398.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: David Hildenbrand Cc: Ira Weiny Cc: Jia He Cc: Joao Martins Cc: Jonathan Cameron 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; }