Skip to content

Commit 73954d3

Browse files
stellarhopperakpm00
authored andcommitted
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>
1 parent 42d9358 commit 73954d3

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
@@ -1349,6 +1349,48 @@ static ssize_t numa_node_show(struct device *dev,
13491349
}
13501350
static DEVICE_ATTR_RO(numa_node);
13511351

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

0 commit comments

Comments
 (0)