From patchwork Fri Dec 15 05:25:29 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: 13494001 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 61D7EC4167D for ; Fri, 15 Dec 2023 05:25:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D1E98D0116; Fri, 15 Dec 2023 00:25:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 882DE8D0103; Fri, 15 Dec 2023 00:25:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FC7E8D0116; Fri, 15 Dec 2023 00:25:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5C2838D0103 for ; Fri, 15 Dec 2023 00:25:45 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2ECF4120C5E for ; Fri, 15 Dec 2023 05:25:45 +0000 (UTC) X-FDA: 81567915450.11.C609ED0 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf15.hostedemail.com (Postfix) with ESMTP id 8F3F7A0008 for ; Fri, 15 Dec 2023 05:25:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SYHz9Jah; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702617943; a=rsa-sha256; cv=none; b=1HLjDdyfaQLP3nqs6t2RYqHtqMVi+xIWtDRFyRNqbhSNIZWL1T9Fb6vO1XOE3qTmLS5pw1 SQMQKkNiD1106Zd3LXZrtz5UB3t/z1m89Z8RN1NgpWqFQ6QIwtuvUrQVcWvXa58JhCxi7T bxqfHxi0SJzQXiSYWtxSZ4BWYcFW7i4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SYHz9Jah; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of vishal.l.verma@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=vishal.l.verma@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702617943; 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=ypOKwW1hPaXDtU75GzRcGaliD9n4629vuU0d5YGt1I4=; b=GAdwNcopyNZsEOVpRX5s90PjscthCOUX2n9VUIc8BZvTodVnCSsElZCQaJzlcKrr/k3olV wu8eNHVEL4m/qh2K0MIGsaITkNtdo7vdNoPkp+jCkZU4VvMKe28eOAu18o5OFmo98oZUrV smPej2RZV4HV1T0+Jt4svqLRSa3eq+U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702617943; x=1734153943; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=8AydkZIRYE6htCOriMTQ/LIKTv23UzbFF+2Jgw5CRZ8=; b=SYHz9JahnQbB+Y2xvLYuvG8mMuIqyLWYiL/SHKpSZp37Tb4QcMNggx16 ukk6+U/OzZkA8Q9D5gGEI+Oome3mD1qPZZNGlUmUMYkb00x069jyeovP8 w2Re+drG2keD2PZfGdPD4lNmIQ1rrATft9PJ6UtHbEKMo2GpZDeXBZxvD cTyFiIh1UTRdcKrUyAuXdCLdzW8lZL5X4Tt5RhqrMKI7L+Q5Xqt4IgeP7 3rgV5ftLHJy7iZ46qJpRIvR0fcHG1Szl+2pkTmp9vqTuHQnzRKn1D1zbQ kCvppaw3pp94+Xn6OrAp91k8ZKOnAl02pa9b3MXqyhbhlzguwkUtDesND w==; X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="461695047" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="461695047" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10924"; a="808847952" X-IronPort-AV: E=Sophos;i="6.04,277,1695711600"; d="scan'208";a="808847952" Received: from mmtakalk-mobl.amr.corp.intel.com (HELO [192.168.1.200]) ([10.212.109.101]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 21:25:39 -0800 From: Vishal Verma Date: Thu, 14 Dec 2023 22:25:29 -0700 Subject: [PATCH v6 4/4] dax: add a sysfs knob to control memmap_on_memory behavior MIME-Version: 1.0 Message-Id: <20231214-vv-dax_abi-v6-4-ad900d698438@intel.com> References: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> In-Reply-To: <20231214-vv-dax_abi-v6-0-ad900d698438@intel.com> To: Dan Williams , Vishal Verma , Dave Jiang , Andrew Morton , Oscar Salvador Cc: linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, David Hildenbrand , Dave Hansen , Huang Ying , Greg Kroah-Hartman , linux-mm@kvack.org, Li Zhijian , Jonathan Cameron X-Mailer: b4 0.13-dev-433a8 X-Developer-Signature: v=1; a=openpgp-sha256; l=3850; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=8AydkZIRYE6htCOriMTQ/LIKTv23UzbFF+2Jgw5CRZ8=; b=owGbwMvMwCXGf25diOft7jLG02pJDKnVjwPMrpyut8x1v9xyeMKEi/HFHefXVb0r+zd5yfV7o h28Z3iUO0pZGMS4GGTFFFn+7vnIeExuez5PYIIjzBxWJpAhDFycAjARkWpGhjNf+ITlduxj1Trv ej864P87z0kCPQrNscmyYadszWv/rWP47z0rq7qGh41zMU9LWP5txanfJ8q82v08OECBd+ldtwf VHAA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8F3F7A0008 X-Stat-Signature: rmsg83qp1zaijxib64kxf17wbik3894i X-HE-Tag: 1702617942-334064 X-HE-Meta: U2FsdGVkX1/j1a/cgBX0m8hk8JS4VtyGtCzn7pkGFU4SdmhGgig5+GEp6e3EmyPgzq8Jq2C+he8vDbvjFBRQjqtm/IlXYGDAi8ys9c+3/EZOQFX53MhcvjBuyXdS9whb3fyxqBWQ+oivvwXaWYFqRQ5BxlOMKyS7EnMaciQ4UAFeODaj4B/kgxPRPkGvkLsYFWIx/0mtOE4oTY+2iGISe4Mk101R/rkOPDyc88GZLctiCCU/Q9U+Xurf4LIKNLEsOWGY6kLfFgthy1jyrD/UF6HojJsRKNEEcLrBnE4f5+F9IW5tHHKMqh+TLzlL6iUkhjKil7GKpuAk9zm8Pha1wd/nl9vmkUE84/70OKLJuM0IOnGwj+NbJTnXZ/t+uKepSPxZFzsE4jDF4GFb1A/KL96Pvgqd/qcHeNJoWawBuIkDcNqfS9BqOCMuIh/QkTnwVLbM5sIAMlIy4gBHP05vSnWJXt0EKz2eg9KcecKEbOReux72aXVr/NQePy7XWN1UekJcAYw29/HkRy8LLHclWB35c89fG+BjUZ1nae9Uf2ang3R8lFikl5v/2GftVlfpjQAgq18BpO3fBWsx4tKKyucTIpnrI/l+Chp4hAu1Kp+6KdawAYspWELYu8HrKwKztqDHVo187YqAfe594/Vtwz2TOdtdWzDDU6+7XwTzuHAN+tmt53xcMuwZgKH6CAzYAPlqbgQVE+L5fNpNOC+k6KQ4UJogQBWRYuBt4PL/s/9ExrQxiGP5NR58KdfYD9MsHNS3RBzgOLKbFqfEJUAI8zfmSygZL/Zc84okGWxlnJy+rWneY1kR70Vw+XA9BV3Q/NGwDHEC+R6xfDvKPSbwQ12n8Jn/ImjxoDYGtom8njZMkUy3x9ywT8eMzksoDnXCkAdgQQZ17mH5qpR9DOfizndmctFdAH8kdWwjmEfjONMaBNnoHQZcVfU0EsHpNbAlM0vwwPrP1nEUXS1DqTG U4G6F1Eb n1uzFnjCNUH/6/izpn2bmykbwYwbsejYQkFJcB1Mn19y0uWAwdwWpE+fJPfQuV7dnm2bzw+iIHG0c9qo7rqCax+4P6kKIHien1I0PFR3qRnuw3LV8ChqA8k02RT2D1+XAGILnlxkTU/8+HM49bvTb3w+4/QR2rt0kM5s8u6dnxsj4pkWJw1yG4FuOe8OMC1SgpHB6NtKPmdKaPtvWhurns4P6keQ7owv1J9sim6y8UmYQzTUrWvFWgCuDql5Mtc+q0oteQBB9ZX+kiO7LA3lhkPFjiPflLVUnU2MWe13DAZyvDPco0q5c+ZCfGUCb8pNLIlMg 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: List-Subscribe: List-Unsubscribe: Add a sysfs knob for dax devices to control the memmap_on_memory setting if the dax device were to be hotplugged as system memory. The default memmap_on_memory setting for dax devices originating via pmem or hmem is set to 'false' - i.e. no memmap_on_memory semantics, to preserve legacy behavior. For dax devices via CXL, the default is on. The sysfs control allows the administrator to override the above defaults if needed. Cc: David Hildenbrand Cc: Dan Williams Cc: Dave Jiang Cc: Dave Hansen Cc: Huang Ying Tested-by: Li Zhijian Reviewed-by: Jonathan Cameron Reviewed-by: David Hildenbrand Signed-off-by: Vishal Verma Reviewed-by: "Huang, Ying" --- drivers/dax/bus.c | 36 +++++++++++++++++++++++++++++++++ Documentation/ABI/testing/sysfs-bus-dax | 17 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6226de131d17..3622b3d1c0de 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1245,6 +1245,41 @@ 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 sysfs_emit(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); + ssize_t rc; + bool val; + + rc = kstrtobool(buf, &val); + if (rc) + return rc; + + if (val == true && !mhp_supports_memmap_on_memory()) { + dev_dbg(dev, "memmap_on_memory is not available\n"); + return -EOPNOTSUPP; + } + + guard(device)(dev); + if (dev_dax->memmap_on_memory != val && dev->driver && + to_dax_drv(dev->driver)->type == DAXDRV_KMEM_TYPE) + return -EBUSY; + dev_dax->memmap_on_memory = val; + + 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); @@ -1271,6 +1306,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, }; diff --git a/Documentation/ABI/testing/sysfs-bus-dax b/Documentation/ABI/testing/sysfs-bus-dax index 6359f7bc9bf4..b34266bfae49 100644 --- a/Documentation/ABI/testing/sysfs-bus-dax +++ b/Documentation/ABI/testing/sysfs-bus-dax @@ -134,3 +134,20 @@ KernelVersion: v5.1 Contact: nvdimm@lists.linux.dev Description: (RO) The id attribute indicates the region id of a dax region. + +What: /sys/bus/dax/devices/daxX.Y/memmap_on_memory +Date: January, 2024 +KernelVersion: v6.8 +Contact: nvdimm@lists.linux.dev +Description: + (RW) Control the memmap_on_memory setting if the dax device + were to be hotplugged as system memory. This determines whether + the 'altmap' for the hotplugged memory will be placed on the + device being hotplugged (memmap_on_memory=1) or if it will be + placed on regular memory (memmap_on_memory=0). This attribute + must be set before the device is handed over to the 'kmem' + driver (i.e. hotplugged into system-ram). Additionally, this + depends on CONFIG_MHP_MEMMAP_ON_MEMORY, and a globally enabled + memmap_on_memory parameter for memory_hotplug. This is + typically set on the kernel command line - + memory_hotplug.memmap_on_memory set to 'true' or 'force'."