All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH daxctl v2 0/5] daxctl: device align support
@ 2020-12-16 22:48 Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 1/5] daxctl: add daxctl_dev_{get,set}_align() Joao Martins
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Joao Martins @ 2020-12-16 22:48 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: 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;

 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(-)

-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH daxctl v2 1/5] daxctl: add daxctl_dev_{get,set}_align()
  2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
@ 2020-12-16 22:48 ` Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 2/5] util/json: Print device align Joao Martins
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Joao Martins @ 2020-12-16 22:48 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Joao Martins

Add support for changing devices alignment.

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

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 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(+)

diff --git a/daxctl/lib/libdaxctl-private.h b/daxctl/lib/libdaxctl-private.h
index 9f9c70d6024f..b307a8bc9438 100644
--- a/daxctl/lib/libdaxctl-private.h
+++ b/daxctl/lib/libdaxctl-private.h
@@ -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;
diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index 9b43b68facfe..39871427c799 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -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;
diff --git a/daxctl/lib/libdaxctl.sym b/daxctl/lib/libdaxctl.sym
index 33c926411037..c3d08179c9fd 100644
--- a/daxctl/lib/libdaxctl.sym
+++ b/daxctl/lib/libdaxctl.sym
@@ -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;
diff --git a/daxctl/libdaxctl.h b/daxctl/libdaxctl.h
index 2b14faad1895..b0bb5d78d357 100644
--- a/daxctl/libdaxctl.h
+++ b/daxctl/libdaxctl.h
@@ -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);
-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH daxctl v2 2/5] util/json: Print device align
  2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 1/5] daxctl: add daxctl_dev_{get,set}_align() Joao Martins
@ 2020-12-16 22:48 ` Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 3/5] daxctl: add align support in reconfigure-device Joao Martins
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Joao Martins @ 2020-12-16 22:48 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Joao Martins

Fetch device align and include it on listings.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 util/json.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/util/json.c b/util/json.c
index 77bd4781551d..357dff20d6be 100644
--- a/util/json.c
+++ b/util/json.c
@@ -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
-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH daxctl v2 3/5] daxctl: add align support in reconfigure-device
  2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 1/5] daxctl: add daxctl_dev_{get,set}_align() Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 2/5] util/json: Print device align Joao Martins
@ 2020-12-16 22:48 ` Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 4/5] daxctl: add align support in create-device Joao Martins
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Joao Martins @ 2020-12-16 22:48 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: 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.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 Documentation/daxctl/daxctl-reconfigure-device.txt | 12 +++++++++++
 daxctl/device.c                                    | 24 +++++++++++++++++-----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/Documentation/daxctl/daxctl-reconfigure-device.txt b/Documentation/daxctl/daxctl-reconfigure-device.txt
index 8caae436faae..272d5d80222d 100644
--- a/Documentation/daxctl/daxctl-reconfigure-device.txt
+++ b/Documentation/daxctl/daxctl-reconfigure-device.txt
@@ -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.
diff --git a/daxctl/device.c b/daxctl/device.c
index 05293d6c38ee..a5394577908d 100644
--- a/daxctl/device.c
+++ b/daxctl/device.c
@@ -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;
-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH daxctl v2 4/5] daxctl: add align support in create-device
  2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
                   ` (2 preceding siblings ...)
  2020-12-16 22:48 ` [PATCH daxctl v2 3/5] daxctl: add align support in reconfigure-device Joao Martins
@ 2020-12-16 22:48 ` Joao Martins
  2020-12-16 22:48 ` [PATCH daxctl v2 5/5] daxctl/test: Add a test for daxctl-create with align Joao Martins
  2020-12-17  0:48 ` [PATCH daxctl v2 0/5] daxctl: device align support Verma, Vishal L
  5 siblings, 0 replies; 7+ messages in thread
From: Joao Martins @ 2020-12-16 22:48 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: Joao Martins

Allow changing devices alignment when creating
a new child device.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 Documentation/daxctl/daxctl-create-device.txt | 8 ++++++++
 daxctl/device.c                               | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/Documentation/daxctl/daxctl-create-device.txt b/Documentation/daxctl/daxctl-create-device.txt
index 648d2541f833..adc7b395125e 100644
--- a/Documentation/daxctl/daxctl-create-device.txt
+++ b/Documentation/daxctl/daxctl-create-device.txt
@@ -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
diff --git a/daxctl/device.c b/daxctl/device.c
index a5394577908d..3c2d4e3d8b48 100644
--- a/daxctl/device.c
+++ b/daxctl/device.c
@@ -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;
-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH daxctl v2 5/5] daxctl/test: Add a test for daxctl-create with align
  2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
                   ` (3 preceding siblings ...)
  2020-12-16 22:48 ` [PATCH daxctl v2 4/5] daxctl: add align support in create-device Joao Martins
@ 2020-12-16 22:48 ` Joao Martins
  2020-12-17  0:48 ` [PATCH daxctl v2 0/5] daxctl: device align support Verma, Vishal L
  5 siblings, 0 replies; 7+ messages in thread
From: Joao Martins @ 2020-12-16 22:48 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: 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.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 test/daxctl-create.sh | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/test/daxctl-create.sh b/test/daxctl-create.sh
index 0d35112b4119..5598e5a89aaf 100755
--- a/test/daxctl-create.sh
+++ b/test/daxctl-create.sh
@@ -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
-- 
1.8.3.1
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH daxctl v2 0/5] daxctl: device align support
  2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
                   ` (4 preceding siblings ...)
  2020-12-16 22:48 ` [PATCH daxctl v2 5/5] daxctl/test: Add a test for daxctl-create with align Joao Martins
@ 2020-12-17  0:48 ` Verma, Vishal L
  5 siblings, 0 replies; 7+ messages in thread
From: Verma, Vishal L @ 2020-12-17  0:48 UTC (permalink / raw)
  To: linux-nvdimm, joao.m.martins; +Cc: Williams, Dan J

On Wed, 2020-12-16 at 22:48 +0000, Joao Martins wrote:
> 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;
> 

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!

> 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(-)
> 

_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-12-17  0:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 22:48 [PATCH daxctl v2 0/5] daxctl: device align support Joao Martins
2020-12-16 22:48 ` [PATCH daxctl v2 1/5] daxctl: add daxctl_dev_{get,set}_align() Joao Martins
2020-12-16 22:48 ` [PATCH daxctl v2 2/5] util/json: Print device align Joao Martins
2020-12-16 22:48 ` [PATCH daxctl v2 3/5] daxctl: add align support in reconfigure-device Joao Martins
2020-12-16 22:48 ` [PATCH daxctl v2 4/5] daxctl: add align support in create-device Joao Martins
2020-12-16 22:48 ` [PATCH daxctl v2 5/5] daxctl/test: Add a test for daxctl-create with align Joao Martins
2020-12-17  0:48 ` [PATCH daxctl v2 0/5] daxctl: device align support Verma, Vishal L

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.