Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1398992pxk; Fri, 25 Sep 2020 13:48:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+1s7P+jA8uvNVkb0sTs4MnBl6E1WlK0N5WTLF6kQLpnD3xwOgEt2OcfPFazAlLmjCAjsa X-Received: by 2002:a50:fb99:: with SMTP id e25mr3286481edq.281.1601066894736; Fri, 25 Sep 2020 13:48:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601066894; cv=none; d=google.com; s=arc-20160816; b=LPIO1WdqUQmf10PCO9DGHNtijdS8V7nRPTU92iUVH7CwYriOouTjHbZFW1CUxf+q/c aBqQmpdIcOdg3oPeP4AQY4V6sApfrvyZgcZVw+FcJvuF0iQpZkPETwc4xUkoj5RX6KJr 5mF5cnltWlIVxFyA63FchZCj8fEM7f0EWY22Xtjt0cVzk+c+aIJHxk2+h83GGFAE4H9g Dn0jnFQE1TUxGdX0bbMoUUOwRV+EbLT/d75Cwk9NVKOn+2h91vEouaHCMFPbADSkJK24 Z4/xqe2oSN++j0vK+3ceXrN9aJCsqBEgVfegdsU1OrK+LmAAofPIOJStnnzHs2k/JElz /DEw== 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=Q2SRqUYdZpwUtE1ZVFqECWML0SnMcom7k6DUwIuF0ns=; b=vuJCTB2bN4NmfsjB5K/2My6x08f++9hx/qcT86r0Fl4h6IQnzM/i6Uat2ksegoq35n RIpLLIiPNuX5zR5HW5QNY1qYy+Pz4PJbiTCFYJObr+NbsZKkZFfY/70iB8yizwNUTmbX 6phQcnW5h3i0x3wklvREwnFm6Q3dSX9DbkbLOPYwl2TowjlgQIr00lAqNcTKPutVlL3/ 5SbViZ1aEe9enr+GsKHF5rqJG/wdEDbsj1uLLyQGM8FegRldhVeRxasktnvNhSw1QKfi eHvz0AiBf4y81KU2GW6p/AuANI5vMaUVLNGyqJoqx4IaVUQOO+nOjNA8bxw+zobmQ+69 AqHg== 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 bi17si2612731edb.582.2020.09.25.13.47.51; Fri, 25 Sep 2020 13:48:14 -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 S1727569AbgIYUpq (ORCPT + 99 others); Fri, 25 Sep 2020 16:45:46 -0400 Received: from mga06.intel.com ([134.134.136.31]:13951 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727015AbgIYUpk (ORCPT ); Fri, 25 Sep 2020 16:45:40 -0400 IronPort-SDR: pJxCBJ8C9DHYJCmpJllKclI/37zP6KWRkx83+hkEsT1B7pvTwPpU/rj9yZGcz2fcrwM22NGzuI omD05Spx4sJw== X-IronPort-AV: E=McAfee;i="6000,8403,9755"; a="223215846" X-IronPort-AV: E=Sophos;i="5.77,303,1596524400"; d="scan'208";a="223215846" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 12:31:36 -0700 IronPort-SDR: VMbc7ZmBQB/F8HKZReuENs4o+rZepmL6hLQ53EkUQItqX8nx6NIeOUZnodDC+yf9ejTO0Iw0Rz xkvwopeQ9iCQ== X-IronPort-AV: E=Sophos;i="5.77,303,1596524400"; d="scan'208";a="349880741" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2020 12:31:36 -0700 Subject: [PATCH v5 17/17] device-dax: add a range mapping allocation attribute From: Dan Williams To: akpm@linux-foundation.org Cc: Joao Martins , vishal.l.verma@intel.com, dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org Date: Fri, 25 Sep 2020 12:13:15 -0700 Message-ID: <160106119570.30709.4548889722645210610.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 From: Joao Martins Add a sysfs attribute which denotes a range from the dax region to be allocated. It's an write only @mapping sysfs attribute in the format of '-' to allocate a range. @start and @end use hexadecimal values and the @pgoff is implicitly ordered wrt to previous writes to @mapping sysfs e.g. a write of a range of length 1G the pgoff is 0..1G(-4K), a second write will use @pgoff for 1G+4K... This range mapping interface is useful for: 1) Application which want to implement its own allocation logic, and thus pick the desired ranges from dax_region. 2) For use cases like VMM fast restart[0] where after kexec we want to the same gpa<->phys mappings (as originally created before kexec). [0] https://static.sched.com/hosted_files/kvmforum2019/66/VMM-fast-restart_kvmforum2019.pdf Link: https://lkml.kernel.org/r/159643106970.4062302.10402616567780784722.stgit@dwillia2-desk3.amr.corp.intel.com Link: https://lore.kernel.org/r/20200716172913.19658-5-joao.m.martins@oracle.com Signed-off-by: Joao Martins Signed-off-by: Dan Williams --- drivers/dax/bus.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 0ac4a9c0fd18..27513d311242 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1043,6 +1043,67 @@ static ssize_t size_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(size); +static ssize_t range_parse(const char *opt, size_t len, struct range *range) +{ + unsigned long long addr = 0; + char *start, *end, *str; + ssize_t rc = EINVAL; + + str = kstrdup(opt, GFP_KERNEL); + if (!str) + return rc; + + end = str; + start = strsep(&end, "-"); + if (!start || !end) + goto err; + + rc = kstrtoull(start, 16, &addr); + if (rc) + goto err; + range->start = addr; + + rc = kstrtoull(end, 16, &addr); + if (rc) + goto err; + range->end = addr; + +err: + kfree(str); + return rc; +} + +static ssize_t mapping_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t len) +{ + struct dev_dax *dev_dax = to_dev_dax(dev); + struct dax_region *dax_region = dev_dax->region; + size_t to_alloc; + struct range r; + ssize_t rc; + + rc = range_parse(buf, len, &r); + if (rc) + return rc; + + rc = -ENXIO; + device_lock(dax_region->dev); + if (!dax_region->dev->driver) { + device_unlock(dax_region->dev); + return rc; + } + device_lock(dev); + + to_alloc = range_len(&r); + if (alloc_is_aligned(dev_dax, to_alloc)) + rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc); + device_unlock(dev); + device_unlock(dax_region->dev); + + return rc == 0 ? len : rc; +} +static DEVICE_ATTR_WO(mapping); + static ssize_t align_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1175,6 +1236,8 @@ static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n) return 0; if (a == &dev_attr_numa_node.attr && !IS_ENABLED(CONFIG_NUMA)) return 0; + if (a == &dev_attr_mapping.attr && is_static(dax_region)) + return 0; if ((a == &dev_attr_align.attr || a == &dev_attr_size.attr) && is_static(dax_region)) return 0444; @@ -1184,6 +1247,7 @@ static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n) static struct attribute *dev_dax_attributes[] = { &dev_attr_modalias.attr, &dev_attr_size.attr, + &dev_attr_mapping.attr, &dev_attr_target_node.attr, &dev_attr_align.attr, &dev_attr_resource.attr,