Skip to content

Commit 0774dcc

Browse files
committed
dax: add a sysfs knob to control memmap_on_memory behavior
JIRA: https://issues.redhat.com/browse/RHEL-23824 commit 73954d3 Author: Vishal Verma <vishal.l.verma@intel.com> Date: Wed Jan 24 12:03:50 2024 -0800 dax: add a sysfs knob to control memmap_on_memory behavior 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. Link: https://lkml.kernel.org/r/20240124-vv-dax_abi-v7-5-20d16cb8d23d@intel.com Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> Tested-by: Li Zhijian <lizhijian@fujitsu.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Huang, Ying <ying.huang@intel.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Jiang <dave.jiang@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Oscar Salvador <osalvador@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
1 parent 64f47c3 commit 0774dcc

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Documentation/ABI/testing/sysfs-bus-dax

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,20 @@ KernelVersion: v5.1
134134
Contact: nvdimm@lists.linux.dev
135135
Description:
136136
(RO) The id attribute indicates the region id of a dax region.
137+
138+
What: /sys/bus/dax/devices/daxX.Y/memmap_on_memory
139+
Date: January, 2024
140+
KernelVersion: v6.8
141+
Contact: nvdimm@lists.linux.dev
142+
Description:
143+
(RW) Control the memmap_on_memory setting if the dax device
144+
were to be hotplugged as system memory. This determines whether
145+
the 'altmap' for the hotplugged memory will be placed on the
146+
device being hotplugged (memmap_on_memory=1) or if it will be
147+
placed on regular memory (memmap_on_memory=0). This attribute
148+
must be set before the device is handed over to the 'kmem'
149+
driver (i.e. hotplugged into system-ram). Additionally, this
150+
depends on CONFIG_MHP_MEMMAP_ON_MEMORY, and a globally enabled
151+
memmap_on_memory parameter for memory_hotplug. This is
152+
typically set on the kernel command line -
153+
memory_hotplug.memmap_on_memory set to 'true' or 'force'."

drivers/dax/bus.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,48 @@ static ssize_t numa_node_show(struct device *dev,
13511351
}
13521352
static DEVICE_ATTR_RO(numa_node);
13531353

1354+
static ssize_t memmap_on_memory_show(struct device *dev,
1355+
struct device_attribute *attr, char *buf)
1356+
{
1357+
struct dev_dax *dev_dax = to_dev_dax(dev);
1358+
1359+
return sysfs_emit(buf, "%d\n", dev_dax->memmap_on_memory);
1360+
}
1361+
1362+
static ssize_t memmap_on_memory_store(struct device *dev,
1363+
struct device_attribute *attr,
1364+
const char *buf, size_t len)
1365+
{
1366+
struct dev_dax *dev_dax = to_dev_dax(dev);
1367+
bool val;
1368+
int rc;
1369+
1370+
rc = kstrtobool(buf, &val);
1371+
if (rc)
1372+
return rc;
1373+
1374+
if (val == true && !mhp_supports_memmap_on_memory()) {
1375+
dev_dbg(dev, "memmap_on_memory is not available\n");
1376+
return -EOPNOTSUPP;
1377+
}
1378+
1379+
rc = down_write_killable(&dax_dev_rwsem);
1380+
if (rc)
1381+
return rc;
1382+
1383+
if (dev_dax->memmap_on_memory != val && dev->driver &&
1384+
to_dax_drv(dev->driver)->type == DAXDRV_KMEM_TYPE) {
1385+
up_write(&dax_dev_rwsem);
1386+
return -EBUSY;
1387+
}
1388+
1389+
dev_dax->memmap_on_memory = val;
1390+
up_write(&dax_dev_rwsem);
1391+
1392+
return len;
1393+
}
1394+
static DEVICE_ATTR_RW(memmap_on_memory);
1395+
13541396
static umode_t dev_dax_visible(struct kobject *kobj, struct attribute *a, int n)
13551397
{
13561398
struct device *dev = container_of(kobj, struct device, kobj);
@@ -1377,6 +1419,7 @@ static struct attribute *dev_dax_attributes[] = {
13771419
&dev_attr_align.attr,
13781420
&dev_attr_resource.attr,
13791421
&dev_attr_numa_node.attr,
1422+
&dev_attr_memmap_on_memory.attr,
13801423
NULL,
13811424
};
13821425

0 commit comments

Comments
 (0)