From patchwork Thu Sep 28 20:30:11 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: 13403514 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 39535E743C0 for ; Thu, 28 Sep 2023 20:31:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 305B68D00DE; Thu, 28 Sep 2023 16:30:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2AADB8D0053; Thu, 28 Sep 2023 16:30:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14CBD8D00DE; Thu, 28 Sep 2023 16:30:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F3BF38D0053 for ; Thu, 28 Sep 2023 16:30:58 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BA4F61A0A05 for ; Thu, 28 Sep 2023 20:30:58 +0000 (UTC) X-FDA: 81287150196.12.8FD4166 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by imf01.hostedemail.com (Postfix) with ESMTP id 364AD40024 for ; Thu, 28 Sep 2023 20:30:55 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=n8oBIXOX; spf=pass (imf01.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.126 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=1695933055; 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=vFgf1IEQyRFkWFGKi1TTSuKtokiG4/ccGifKmDse5Oc=; b=E/wbI52+OBYwAc0F5B2I3MHadr1RdogyWdu5JufnSs9kabpvk397gUIybp+xS38vix1/g6 3joCfyqjj7GjUPtBgtX+1+aar+w1bXFMZBjcR0euiWJMr7Yid8ofENz59RLhqDf6JT9UbD rKm9ahTWD4ST3ecmPHuOwnikdURIJgY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695933055; a=rsa-sha256; cv=none; b=eTWd/PlP6BYI/e2VKopV65NBybHp79driGfFcf9TM8aWxubagogDILUX9ljW+Wz3Xea3De L4Ttc4wegF1czBOsWAtuiyXUYHJGBZ3rNfyTnHvfXwDkq4XXY8guzTOjFnQ5Zhvq1EeK+C 8cyLKMvLm3bzzc6eTPJJQzI3hL2AqJ8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=n8oBIXOX; spf=pass (imf01.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.126 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=1695933055; x=1727469055; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=vr4yVCTT0Ug5tj83kbU0iH+2ATewvlAUFs0OqOZ9pYo=; b=n8oBIXOXzo3D+jEZbrFdh7yQA76Kqyz+/Chgts6A+Xg/2qC1wt8dI6uk wvVFm6V+9xUiezv4CEitJ+wQHlJccGatiRIZgdC8w/yFFqDaZlymHZUpj y+8GowOI+9io8Yh2Jvz4GmNCtmsZ6YzJ9VP1gcXMu3VItXN4p2weUYPKg bwtUxWkj/+UmsXdnwLoV0m1GDDf05j7VYDWQSnP5mVn1KAmUAXOECZioV eIQf1/qb7kNia3EqlSYDuf/zu1NqBksmnfJLj+0JofIP1hKm87gh4kfNu exaBsJ4l/UY8I3XFJ4AlTdh6uss2wu4s5KYY74SUvg0sUpX+uHqWIOE2Z A==; X-IronPort-AV: E=McAfee;i="6600,9927,10847"; a="367229689" X-IronPort-AV: E=Sophos;i="6.03,185,1694761200"; d="scan'208";a="367229689" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 13:30:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10847"; a="815374363" X-IronPort-AV: E=Sophos;i="6.03,185,1694761200"; d="scan'208";a="815374363" Received: from bdsebast-mobl1.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.125.211]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2023 13:30:31 -0700 From: Vishal Verma Date: Thu, 28 Sep 2023 14:30:11 -0600 Subject: [PATCH v4 2/2] dax/kmem: allow kmem to add memory with memmap_on_memory MIME-Version: 1.0 Message-Id: <20230928-vv-kmem_memmap-v4-2-6ff73fec519a@intel.com> References: <20230928-vv-kmem_memmap-v4-0-6ff73fec519a@intel.com> In-Reply-To: <20230928-vv-kmem_memmap-v4-0-6ff73fec519a@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=6393; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=vr4yVCTT0Ug5tj83kbU0iH+2ATewvlAUFs0OqOZ9pYo=; b=owGbwMvMwCXGf25diOft7jLG02pJDKmij9I6HhqsZr2d+tb0l8SvmKX50aodnsfPvec6urJv+ 7aenSWTO0pYGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjCRKZsYGSadL24tmKJzmHfK mUZeY2eVgORi5TOr7ALrJVKrFh126GT4XjHFKuuhU9kVLYFDb+RvWu6x4l4mxfegO8Cg7ra/MhM jAA== X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Stat-Signature: 5jfj3s6ouyokt3q853c4rz7xhcsos35w X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 364AD40024 X-Rspam-User: X-HE-Tag: 1695933055-18164 X-HE-Meta: U2FsdGVkX18VWlGdWUC8P4VIsAkbYROMsAnW2u0j7i9ACW8DjA6uojG11SzioFp64AOjIgI8gBr5yzfSmaFpt7Izb10ObV5yyt3wbQmMWMKkVpKfFBCwqyg+UrEpm9iGyG4fIr/z2QUUN9LEaDMV8MkUlWXjMhUSL8sNqjruaICjn8flKnqdAipyHiqem+Ppr96ckZxM24n/SM1Pw/zL1T5PA/ogNXruoCA56gzp1VzIHydhMQKFqUdOMUKWApXUyTZ2fl+zaaaspEWOnU9orL0bfhadRpsGoAJyEbvsDQ1Kaw5TCs8fI8M/2eNy2ShFNTp++2ODAsZuxSsgZgueoFZ2Wa4Kd4LXiD0M9HUbWULHhQ2jozU/MbyZ9P4d1peKrmXs0kkmEob+aii7w6nvUzP+aB7E+Lph3qgFnVewfZEMognQPngujV2AxHeU1MUwNPWu3FNAcWA7LjolzwAE8fnjgfvyWzAMVhxFv2x3q5i9P4fovdfjvfDGghqDX6AlxgLYkellsx22kW0NrTa9TSR4zGEo23yKTG3njTWFTYUTRDpeCCvlf1PoRf0E60/yCFzahPZEwGaP1A8ubmLwu/4rTeu4aslRNa66xMfW2pU+a5M8uG6oeGRMqggqezESRd4ql1NtbyOqJC8m1xxLycLVyZd5IDElAlvDUmo1dyoVwbkQuI2x7+OzlqSuf82tsPBzOzxUQubzo0lKAHn1fj2tR+jzoxiwR+wiKz0ZAol40YNmHWdvP83alW3CsXzy9+RL+qZhdsSAFYoYpfnMSGsNyC3w/40Y9kAuhSVHYgINjy5NltZ4OoAozrhO1IslHZaE2UZxHv2j0Z7eGyRizReQZDl0w7C/UhSCT/OHXyzLZfFRxFy3lwSnCzpvApKsy+NfA7lllz/Qv2va0pcZ742NCYRkA1HkxtKgLV+fTjlT/O0lAieR401InQ1EGBQlMJpOm391KnImIWiQKPd uNPzHgCR DQ8+Fvy4AEbf7kKz5WVpGdxM27d2S6MgGTz9OU82YJzIaFdeW9RsW3NAf0lmNiZvB2BnhBSEY/Koi2Edk4BsdJRQFdnjp5nl7YYb6jR4x7hvztSukELIHOLGx0IndMepFdq/NI9lhuiwBsqou+ZTqX+rn474cmANS+BjbMf9x13a1jNwWEDh0Kfzf6hJdhF39jaAtd2CBp/gXUXnEoS0okr++0W7XuX/O+xc8/erWlUgpNNa5G4FkrC0tPRtbNeU2EykSvLiaqkF/UxVk+Xwel3xireZ+FcawhSkemF9sHzBt8zXNrnCpvoB5cSadXq8/DGr5dTl7BTvF9Z/xq4q2V15oYcxRAY/Z6gohjq1zP2MCmh8kaXjavt6zIUrC4pUV1ipt 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 Signed-off-by: Vishal Verma Reviewed-by: David Hildenbrand --- 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..81351eb69884 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 rc == 0 ? len : rc; +} +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);