Skip to contentSkip to conversation

daxctl: device align support

PATCH In review Joao Martins 2 participants 7 messages Dec 16, 2020 – Dec 17, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover daxctl: device align support

Hey,

This series adds support for:

1) {create,reconfigure}-device for selecting @align (hugepage size). Here we add a '-a|--align 4K|2M|1G' option to the existing commands;

2) Listing now displays align (if supported).

Testing requires a 5.10+ kernel.

v1 -> v2:
* Fix listing of dax devices on kernels that don't support align;
* Adds a unit test for align;
* Remove the mapping part to a later series;

Joao Martins (5):
daxctl: add daxctl_dev_{get,set}_align() util/json: Print device align
daxctl: add align support in reconfigure-device
daxctl: add align support in create-device daxctl/test: Add a test for daxctl-create with align

 Documentation/daxctl/daxctl-create-device.txt      |  8 +++++
 Documentation/daxctl/daxctl-reconfigure-device.txt | 12 ++++++++
 daxctl/device.c                                    | 32 ++++++++++++++++---
 daxctl/lib/libdaxctl-private.h                     |  1 +
 daxctl/lib/libdaxctl.c                             | 36 ++++++++++++++++++++++
 daxctl/lib/libdaxctl.sym                           |  2 ++
 daxctl/libdaxctl.h                                 |  2 ++
 test/daxctl-create.sh                              | 29 +++++++++++++++++
 util/json.c                                        |  9 +++++-
 9 files changed, 125 insertions(+), 6 deletions(-)
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#1 lore raw

PATCH v2 1/5 daxctl: add daxctl_dev_{get,set}_align()

Add support for changing devices alignment.

On kernels that do not support per-device align sysfs property we set it to 0.

---
 daxctl/lib/libdaxctl-private.h |  1 +
 daxctl/lib/libdaxctl.c         | 36 ++++++++++++++++++++++++++++++++++++
 daxctl/lib/libdaxctl.sym       |  2 ++
 daxctl/libdaxctl.h             |  2 ++
 4 files changed, 41 insertions(+)
daxctl/lib/libdaxctl-private.h +1 -0
index 9f9c70d6024f..b307a8bc9438 100644
@@ -99,6 +99,7 @@ struct daxctl_dev {
 	struct list_node list;
 	unsigned long long resource;
 	unsigned long long size;
+	unsigned long align;
 	struct kmod_module *module;
 	struct daxctl_region *region;
 	struct daxctl_memory *mem;
daxctl/lib/libdaxctl.c +36 -0
index 9b43b68facfe..39871427c799 100644
@@ -498,6 +498,13 @@ static void *add_dax_dev(void *parent, int id, const char *daxdev_base)
 		goto err_read;
 	dev->size = strtoull(buf, NULL, 0);
 
+	/* Device align attribute is only available in v5.10 or up */
+	sprintf(path, "%s/align", daxdev_base);
+	if (!sysfs_read_attr(ctx, path, buf))
+		dev->align = strtoull(buf, NULL, 0);
+	else
+		dev->align = 0;
+
 	dev->dev_path = strdup(daxdev_base);
 	if (!dev->dev_path)
 		goto err_read;
@@ -1086,6 +1093,35 @@ DAXCTL_EXPORT int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long
 	return 0;
 }
 
+DAXCTL_EXPORT unsigned long daxctl_dev_get_align(struct daxctl_dev *dev)
+{
+	return dev->align;
+}
+
+DAXCTL_EXPORT int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align)
+{
+	struct daxctl_ctx *ctx = daxctl_dev_get_ctx(dev);
+	char buf[SYSFS_ATTR_SIZE];
+	char *path = dev->dev_buf;
+	int len = dev->buf_len;
+
+	if (snprintf(path, len, "%s/align", dev->dev_path) >= len) {
+		err(ctx, "%s: buffer too small!\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
+	}
+
+	sprintf(buf, "%#lx\n", align);
+	if (sysfs_write_attr(ctx, path, buf) < 0) {
+		err(ctx, "%s: failed to set align\n",
+				daxctl_dev_get_devname(dev));
+		return -ENXIO;
+	}
+
+	dev->align = align;
+	return 0;
+}
+
 DAXCTL_EXPORT int daxctl_dev_get_target_node(struct daxctl_dev *dev)
 {
 	return dev->target_node;
daxctl/lib/libdaxctl.sym +2 -0
index 33c926411037..c3d08179c9fd 100644
@@ -81,4 +81,6 @@ global:
 	daxctl_dev_set_size;
 	daxctl_region_create_dev;
 	daxctl_region_destroy_dev;
+	daxctl_dev_get_align;
+	daxctl_dev_set_align;
 } LIBDAXCTL_7;
daxctl/libdaxctl.h +2 -0
index 2b14faad1895..b0bb5d78d357 100644
@@ -71,6 +71,8 @@ int daxctl_dev_get_minor(struct daxctl_dev *dev);
 unsigned long long daxctl_dev_get_resource(struct daxctl_dev *dev);
 unsigned long long daxctl_dev_get_size(struct daxctl_dev *dev);
 int daxctl_dev_set_size(struct daxctl_dev *dev, unsigned long long size);
+unsigned long daxctl_dev_get_align(struct daxctl_dev *dev);
+int daxctl_dev_set_align(struct daxctl_dev *dev, unsigned long align);
 struct daxctl_ctx *daxctl_dev_get_ctx(struct daxctl_dev *dev);
 int daxctl_dev_is_enabled(struct daxctl_dev *dev);
 int daxctl_dev_disable(struct daxctl_dev *dev);
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#2 lore raw

PATCH v2 2/5 util/json: Print device align

In reply to Joao Martins

Fetch device align and include it on listings.

---
 util/json.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
util/json.c +8 -1
index 77bd4781551d..357dff20d6be 100644
@@ -455,7 +455,7 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,
 	struct daxctl_memory *mem = daxctl_dev_get_memory(dev);
 	const char *devname = daxctl_dev_get_devname(dev);
 	struct json_object *jdev, *jobj;
-	int node, movable;
+	int node, movable, align;
 
 	jdev = json_object_new_object();
 	if (!devname || !jdev)
@@ -476,6 +476,13 @@ struct json_object *util_daxctl_dev_to_json(struct daxctl_dev *dev,
 			json_object_object_add(jdev, "target_node", jobj);
 	}
 
+	align = daxctl_dev_get_align(dev);
+	if (align > 0) {
+		jobj = util_json_object_size(daxctl_dev_get_align(dev), flags);
+		if (jobj)
+			json_object_object_add(jdev, "align", jobj);
+	}
+
 	if (mem)
 		jobj = json_object_new_string("system-ram");
 	else
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#3 lore raw

PATCH v2 3/5 daxctl: add align support in reconfigure-device

In reply to Joao Martins

Add an alignment option to reconfigure-device and use the newly added libdaxctl API to set the alignment of the device prior to setting size.

---
 Documentation/daxctl/daxctl-reconfigure-device.txt | 12 +++++++++++
 daxctl/device.c                                    | 24 +++++++++++++++++-----
 2 files changed, 31 insertions(+), 5 deletions(-)
Documentation/daxctl/daxctl-reconfigure-device.txt +12 -0
index 8caae436faae..272d5d80222d 100644
@@ -136,6 +136,18 @@ OPTIONS
 
 	The size must be a multiple of the region alignment.
 
+	This option is mutually exclusive with -m or --mode.
+
+-a::
+--align::
+	Applications that want to establish dax memory mappings with
+	page table entries greater than system base page size (4K on
+	x86) need a device that is sufficiently aligned. This defaults
+	to 2M. Note that "devdax" mode enforces all mappings to be
+	aligned to this value, i.e. it fails unaligned mapping attempts.
+
+	This option is mutually exclusive with -m or --mode.
+
 -m::
 --mode=::
 	Specify the mode to which the dax device(s) should be reconfigured.
daxctl/device.c +19 -5
index 05293d6c38ee..a5394577908d 100644
@@ -22,6 +22,7 @@ static struct {
 	const char *mode;
 	const char *region;
 	const char *size;
+	const char *align;
 	bool no_online;
 	bool no_movable;
 	bool force;
@@ -36,6 +37,7 @@ enum dev_mode {
 };
 
 static enum dev_mode reconfig_mode = DAXCTL_DEV_MODE_UNKNOWN;
+static long long align = -1;
 static long long size = -1;
 static unsigned long flags;
 
@@ -68,7 +70,8 @@ OPT_BOOLEAN('f', "force", &param.force, \
 		"attempt to offline memory sections before reconfiguration")
 
 #define CREATE_OPTIONS() \
-OPT_STRING('s', "size", &param.size, "size", "size to switch the device to")
+OPT_STRING('s', "size", &param.size, "size", "size to switch the device to"), \
+OPT_STRING('a', "align", &param.align, "align", "alignment to switch the device to")
 
 #define DESTROY_OPTIONS() \
 OPT_BOOLEAN('f', "force", &param.force, \
@@ -185,13 +188,18 @@ static const char *parse_device_options(int argc, const char **argv,
 	/* Handle action-specific options */
 	switch (action) {
 	case ACTION_RECONFIG:
-		if (!param.size && !param.mode) {
-			fprintf(stderr, "error: a 'mode' or 'size' option is required\n");
+		if (!param.size &&
+		    !param.align &&
+		    !param.mode) {
+			fprintf(stderr, "error: a 'align', 'mode' or 'size' option is required\n");
 			usage_with_options(u, reconfig_options);
 			rc = -EINVAL;
 		}
-		if (param.size) {
-			size = __parse_size64(param.size, &units);
+		if (param.size || param.align) {
+			if (param.size)
+				size = __parse_size64(param.size, &units);
+			if (param.align)
+				align = __parse_size64(param.align, &units);
 		} else if (strcmp(param.mode, "system-ram") == 0) {
 			reconfig_mode = DAXCTL_DEV_MODE_RAM;
 			if (param.no_movable)
@@ -558,6 +566,12 @@ static int do_reconfig(struct daxctl_dev *dev, enum dev_mode mode,
 	struct json_object *jdev;
 	int rc = 0;
 
+	if (align > 0) {
+		rc = daxctl_dev_set_align(dev, align);
+		if (rc < 0)
+			return rc;
+	}
+
 	if (size >= 0) {
 		rc = dev_resize(dev, size);
 		return rc;
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#4 lore raw

PATCH v2 4/5 daxctl: add align support in create-device

In reply to Joao Martins

Allow changing devices alignment when creating
a new child device.

---
 Documentation/daxctl/daxctl-create-device.txt | 8 ++++++++
 daxctl/device.c                               | 8 ++++++++
 2 files changed, 16 insertions(+)
Documentation/daxctl/daxctl-create-device.txt +8 -0
index 648d2541f833..adc7b395125e 100644
@@ -87,6 +87,14 @@ OPTIONS
 
 	The size must be a multiple of the region alignment.
 
+-a::
+--align::
+	Applications that want to establish dax memory mappings with
+	page table entries greater than system base page size (4K on
+	x86) need a device that is sufficiently aligned. This defaults
+	to 2M. Note that "devdax" mode enforces all mappings to be
+	aligned to this value, i.e. it fails unaligned mapping attempts.
+
 -u::
 --human::
 	By default the command will output machine-friendly raw-integer
daxctl/device.c +8 -0
index a5394577908d..3c2d4e3d8b48 100644
@@ -216,6 +216,8 @@ static const char *parse_device_options(int argc, const char **argv,
 	case ACTION_CREATE:
 		if (param.size)
 			size = __parse_size64(param.size, &units);
+		if (param.align)
+			align = __parse_size64(param.align, &units);
 		/* fall through */
 	case ACTION_ONLINE:
 		if (param.no_movable)
@@ -538,6 +540,12 @@ static int do_create(struct daxctl_region *region, long long val,
 	if (val <= 0)
 		return -ENOSPC;
 
+	if (align > 0) {
+		rc = daxctl_dev_set_align(dev, align);
+		if (rc < 0)
+			return rc;
+	}
+
 	rc = daxctl_dev_set_size(dev, val);
 	if (rc < 0)
 		return rc;
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
#5 lore raw

PATCH v2 5/5 daxctl/test: Add a test for daxctl-create with align

In reply to Joao Martins

Add a test which uses the newly added --align property which allows a device created with daxctl create-device to select its page size. If the available size is bigger than 1G then use 1G as page size, otherwise use 2M.

---
 test/daxctl-create.sh | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
test/daxctl-create.sh +29 -0
index 0d35112b4119..5598e5a89aaf 100755
@@ -281,6 +281,34 @@ daxctl_test5()
 	test_pass
 }
 
+# Test 6: align
+# Successfully creates a device with a align property
+daxctl_test6()
+{
+	local daxdev
+	local align
+	local size
+
+	# Available size
+	size=$available
+
+	# Use 2M by default or 1G if supported
+	align=2097152
+	if [[ $((available >= 1073741824 )) ]]; then
+		align=1073741824
+		size=$align
+	fi
+
+	daxdev=$("$DAXCTL" create-device -r 0 -s $size -a $align | jq -er '.[].chardev')
+
+	test -n "$daxdev"
+
+	"$DAXCTL" disable-device "$daxdev" && "$DAXCTL" destroy-device "$daxdev"
+
+	clear_dev
+	test_pass
+}
+
 find_testdev
 rc=1
 setup_dev
@@ -290,5 +318,6 @@ daxctl_test2
 daxctl_test3
 daxctl_test4
 daxctl_test5
+daxctl_test6
 reset_dev
 exit 0
Signature · 4 lines
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
maintainer
#6 lore raw
In reply to Joao Martins
Quoted 7 lines · Joao Martins

Hey,

This series adds support for:

1) {create,reconfigure}-device for selecting @align (hugepage size). Here we add a '-a|--align 4K|2M|1G' option to the existing commands;

Quoted 9 lines

2) Listing now displays align (if supported).

Testing requires a 5.10+ kernel.

v1 -> v2:
* Fix listing of dax devices on kernels that don't support align;
* Adds a unit test for align;
* Remove the mapping part to a later series;

These all look good to me, I've applied them and pushed a branch out, 'jm/devdax_subdiv'. As Dan mentioned in the other thread, if you had a respin of the provisioning flows patches, we can add them in.

Thanks for the quick turnaround on these!

Quoted 7 lines

Joao Martins (5):
daxctl: add daxctl_dev_{get,set}_align() util/json: Print device align
daxctl: add align support in reconfigure-device
daxctl: add align support in create-device daxctl/test: Add a test for daxctl-create with align

Quoted 11 lines
 Documentation/daxctl/daxctl-create-device.txt      |  8 +++++
 Documentation/daxctl/daxctl-reconfigure-device.txt | 12 ++++++++
 daxctl/device.c                                    | 32 ++++++++++++++++---
 daxctl/lib/libdaxctl-private.h                     |  1 +
 daxctl/lib/libdaxctl.c                             | 36 ++++++++++++++++++++++
 daxctl/lib/libdaxctl.sym                           |  2 ++
 daxctl/libdaxctl.h                                 |  2 ++
 test/daxctl-create.sh                              | 29 +++++++++++++++++
 util/json.c                                        |  9 +++++-
 9 files changed, 125 insertions(+), 6 deletions(-)

_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]