From patchwork Thu Oct 5 18:31:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13410615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A7CEE92725 for ; Thu, 5 Oct 2023 18:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 556AF8E0008; Thu, 5 Oct 2023 14:32:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52CE88E0007; Thu, 5 Oct 2023 14:32:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F42F8E0008; Thu, 5 Oct 2023 14:32:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 320298E0007 for ; Thu, 5 Oct 2023 14:32:07 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E5872A0377 for ; Thu, 5 Oct 2023 18:32:06 +0000 (UTC) X-FDA: 81312252252.14.288436B Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by imf02.hostedemail.com (Postfix) with ESMTP id 9BCB180017 for ; Thu, 5 Oct 2023 18:32:04 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LVBfAiVu; spf=pass (imf02.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696530724; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RmxXppi107uDu2rBa7tN0eETDD29jKNqd+LtByEXgBQ=; b=SuJ3+X2EDtHQSiao/tOdkaAhrMb3Rfzu4ZT4wCT6b0wQZnNvf8pdel7oKPxjExUu1QbLoX Fv+TyyrV2xV3zI006CAYzYwzCl8mX2z6yn66WSKEO2AKvwnZ6lnGpEEDUa2V1K0LghyuN8 y7KfljbUrmwhkV7CDvKSj+egkxPfbS0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696530724; a=rsa-sha256; cv=none; b=l6w8SHIeQCGxxjIkP9Dh0EQMh0H8mXKZiIHdicH6wcVaC8hgCrfdZs39RT7ihMC4h3TK90 /zLfX6VDUx5WeDLUzrGDnDQ3FosfwhImKNA/a9OkT2jPCdWl3J6Jl7TuiZBD+7bxGu4Qsz kcOWixlnMf49Hc8luJii+1Frzc582bA= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LVBfAiVu; spf=pass (imf02.hostedemail.com: domain of vishal.l.verma@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696530724; x=1728066724; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=6MPyfJ9TCOOWqIqYtO0O+rswGranA361S3pLp//iGZE=; b=LVBfAiVuzDVdwdLp9P148x/BuvvbOU3F6Hv3hl/C6I/H3XhNaz1BP7M0 Zv1jlfdDUWbYRX2OmDIuqi1aKAIQ2nr+7rwS7hSdsMCt2Dv0kXVFxgzwV Pog9rEjoDUHm6giiHZYZuXKvRBHQM043f5vizm9DEIOGpepgZQqtgFsaF KdrpAIdz8oPHcHA6iIhaG0IuMiLic9b6r5BrXBJiT8DLKioGGcuUaL5wy j8v6WTxrClzn4mSOmNuVeosEE+Gi6m6ljbjzuOxSfpHxIjjjaUUDxHeND /sJTVXtiL1ioVfYlQqp0RhHoH9Gu3M1Sw9F8HPi+7pIKFmeS4aVsKptU8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="363860747" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="363860747" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 11:31:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="781342843" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="781342843" Received: from amykuo-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.12.247]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 11:31:54 -0700 From: Vishal Verma Date: Thu, 05 Oct 2023 12:31:40 -0600 Subject: [PATCH v5 2/2] dax/kmem: allow kmem to add memory with memmap_on_memory MIME-Version: 1.0 Message-Id: <20231005-vv-kmem_memmap-v5-2-a54d1981f0a3@intel.com> References: <20231005-vv-kmem_memmap-v5-0-a54d1981f0a3@intel.com> In-Reply-To: <20231005-vv-kmem_memmap-v5-0-a54d1981f0a3@intel.com> To: Andrew Morton , David Hildenbrand , Oscar Salvador , Dan Williams , Dave Jiang Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Huang Ying , Dave Hansen , "Aneesh Kumar K.V" , Michal Hocko , Jonathan Cameron , Jeff Moyer , Vishal Verma , Jonathan Cameron X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6429; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=6MPyfJ9TCOOWqIqYtO0O+rswGranA361S3pLp//iGZE=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnyjBJZMtvzxY/rnZRnS5B6+WzZG5k0I03eqFmzWPlE1 cIS7t/oKGVhEONikBVTZPm75yPjMbnt+TyBCY4wc1iZQIYwcHEKwEQ4fzL8sxL8VRjvf69bNlib 57zYhYK3GvWrD3OvLEkq+ro53MRJl+F/8UOVGYFydm9mF+84vt5AfMbKXSJ/HtWz9LQ/7dnsEP6 YCwA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Stat-Signature: a9rqwdgx8sphsd1umy5g96yiaeoa81dc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9BCB180017 X-Rspam-User: X-HE-Tag: 1696530724-333234 X-HE-Meta: U2FsdGVkX1+csmDgxHNCOKZvGjnZQk4Ztb6fPyaY8zy8g75nFB87hISDNnj8Pmt0Wvu2wCLttdvMLnGYZsZICAxvbDuBP2X01OGe71pGcko9iHft8tzwRWzkBEsHoRHghy6tOr6FQXeD8H9lufwmSadawBhL6doOFNpnF6KHKm6A+KsO4CfRh+qosq6qIz4oum4OVvskhcIyg1IKhAuaqJTMr7P6Qie43Yei2ADrN5mwdCXfnRb0eWtJIixJFEYpZpzsBWlcMsbAOy4z5WG6sI52maYFH7pQqp9Oyn4ijvp6/uPDEnaq/0uPIr6nbLhYdTaYDJSrPe+Wx0ib8FEeytkkL6o9R2zOcaFmM86ARrR0joQvXpcXpBNSCbXpz/LVEvNMNnHeb8ki7trwVUCMNk+ildbZu+AZj04FHycsWaWcQG3H5lxJB+lj81uao9leyx84GfYMbel1sTD/zKqYM2tQNPt7kBLktMyHKoN4clpUxlSgHSdjrZV2RpEcvqBbWkdnC8KpfCnv1ByNW2Kl61Y9YM4dTUub6lFBaoSnlFfW5EyDMQHyDQrngPcy6HYfZqMCvrBJgdmL1APcLYGCjZNQSpB/uuNNRYoaMkAoYZmGoiIoQGlyGwAaMMuIsrzcKcJQXDxtARk09ZFC6wmmIoIaoK7qFh5Q3pjpwvZ4sxiWf+IQFxGcuPRxkndTQAZLuCBwqnonZxcaRvh1Bo4S98YbhPcJ/jloJjTYww9THwzWjR/FfFY8jvK9jdd7Jdbyv7KTxvMiy/F1aUW1ArTisTl71Df0EYuHXnB0JcxldFdMi28GfCkZPdZaszgUtVov+yQvVaxtRi75OxQ93S3Bo6iTr39b/Ik3o7jTL36fiuI6SeIjnrWDZA7B8XDBAkG610ySzCgPNfXXXe0lMp7nvRhex6ELLzbqoKX7klf8NP23Tw7HKYx9O/FkHVYUcuPxaJ/Rv7jcbTrmxMTrOv0 SyM6dsQs RuODFJZ2NLDXe/lCnKlkXqyPjOassXcnm3iyjL4EQwdsim9ucT7804BSnE1P59on5AFOQNJsjTUOcLJkXpxsDEitxk53nmBGAgenLVdB8Kqpub806fiUDf5pEDo/hvY4XbCcijsUOXw72pFio06scYq+MD9OHKDGRtH3gR+4LlHS3Vmm/JmBrksIVrAoSZgtzB8x1k5Rd4TRB800rLvrqspuxL0JwpODR7WL2uFlxxEyuheXmImV5v3FA6URC5IMRWFkGe9BHfuCtTtzvaaLE87n300lJim9cFCSa2/WZuQQQXmf3EwyH50HMcDbzFmCQzwhxrF7zwaKxLJ6GMG7MbCYuUdBFLUYPs7DY/HnlD8EvjYKwimUUTOuPzAzj/o6eEYoW 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: Large amounts of memory managed by the kmem driver may come in via CXL, and it is often desirable to have the memmap for this memory on the new memory itself. Enroll kmem-managed memory for memmap_on_memory semantics if the dax region originates via CXL. For non-CXL dax regions, retain the existing default behavior of hot adding without memmap_on_memory semantics. Add a sysfs override under the dax device to control this behavior and override either default. Cc: Andrew Morton Cc: David Hildenbrand Cc: Michal Hocko Cc: Oscar Salvador Cc: Dan Williams Cc: Dave Jiang Cc: Dave Hansen Cc: Huang Ying Reviewed-by: Jonathan Cameron Reviewed-by: David Hildenbrand Signed-off-by: Vishal Verma --- drivers/dax/bus.h | 1 + drivers/dax/dax-private.h | 1 + drivers/dax/bus.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/dax/cxl.c | 1 + drivers/dax/hmem/hmem.c | 1 + drivers/dax/kmem.c | 8 +++++++- drivers/dax/pmem.c | 1 + 7 files changed, 50 insertions(+), 1 deletion(-) diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index 1ccd23360124..cbbf64443098 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -23,6 +23,7 @@ struct dev_dax_data { struct dev_pagemap *pgmap; resource_size_t size; int id; + bool memmap_on_memory; }; struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data); diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index 27cf2daaaa79..446617b73aea 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -70,6 +70,7 @@ struct dev_dax { struct ida ida; struct device dev; struct dev_pagemap *pgmap; + bool memmap_on_memory; int nr_range; struct dev_dax_range { unsigned long pgoff; diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 0ee96e6fc426..43be95a231c9 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -367,6 +367,7 @@ static ssize_t create_store(struct device *dev, struct device_attribute *attr, .dax_region = dax_region, .size = 0, .id = -1, + .memmap_on_memory = false, }; struct dev_dax *dev_dax = devm_create_dev_dax(&data); @@ -1269,6 +1270,40 @@ static ssize_t numa_node_show(struct device *dev, } static DEVICE_ATTR_RO(numa_node); +static ssize_t memmap_on_memory_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct dev_dax *dev_dax = to_dev_dax(dev); + + return sprintf(buf, "%d\n", dev_dax->memmap_on_memory); +} + +static ssize_t memmap_on_memory_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; + ssize_t rc; + bool val; + + rc = kstrtobool(buf, &val); + if (rc) + return rc; + + device_lock(dax_region->dev); + if (!dax_region->dev->driver) { + device_unlock(dax_region->dev); + return -ENXIO; + } + + dev_dax->memmap_on_memory = val; + + device_unlock(dax_region->dev); + return len; +} +static DEVICE_ATTR_RW(memmap_on_memory); + static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n) { struct device *dev = container_of(kobj, struct device, kobj); @@ -1295,6 +1330,7 @@ static struct attribute *dev_dax_attributes[] = { &dev_attr_align.attr, &dev_attr_resource.attr, &dev_attr_numa_node.attr, + &dev_attr_memmap_on_memory.attr, NULL, }; @@ -1400,6 +1436,8 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data) dev_dax->align = dax_region->align; ida_init(&dev_dax->ida); + dev_dax->memmap_on_memory = data->memmap_on_memory; + inode = dax_inode(dax_dev); dev->devt = inode->i_rdev; dev->bus = &dax_bus_type; diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index 8bc9d04034d6..c696837ab23c 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -26,6 +26,7 @@ static int cxl_dax_region_probe(struct device *dev) .dax_region = dax_region, .id = -1, .size = range_len(&cxlr_dax->hpa_range), + .memmap_on_memory = true, }; return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data)); diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index 5d2ddef0f8f5..b9da69f92697 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -36,6 +36,7 @@ static int dax_hmem_probe(struct platform_device *pdev) .dax_region = dax_region, .id = -1, .size = region_idle ? 0 : range_len(&mri->range), + .memmap_on_memory = false, }; return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data)); diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index c57acb73e3db..0aa6c45a4e5a 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "dax-private.h" #include "bus.h" @@ -56,6 +57,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) unsigned long total_len = 0; struct dax_kmem_data *data; int i, rc, mapped = 0; + mhp_t mhp_flags; int numa_node; /* @@ -136,12 +138,16 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) */ res->flags = IORESOURCE_SYSTEM_RAM; + mhp_flags = MHP_NID_IS_MGID; + if (dev_dax->memmap_on_memory) + mhp_flags |= MHP_MEMMAP_ON_MEMORY; + /* * Ensure that future kexec'd kernels will not treat * this as RAM automatically. */ rc = add_memory_driver_managed(data->mgid, range.start, - range_len(&range), kmem_name, MHP_NID_IS_MGID); + range_len(&range), kmem_name, mhp_flags); if (rc) { dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n", diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index ae0cb113a5d3..f3c6c67b8412 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -63,6 +63,7 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev) .id = id, .pgmap = &pgmap, .size = range_len(&range), + .memmap_on_memory = false, }; return devm_create_dev_dax(&data);