linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ndctl: daxctl: fix mmap size
@ 2017-11-13 18:19 Dave Jiang
  2017-11-13 18:19 ` [PATCH v2 2/2] ndctl: make mmap start at the offset Dave Jiang
  2017-11-13 23:40 ` [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dan Williams
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Jiang @ 2017-11-13 18:19 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm

The size for mmap needs to be aligned to the region alignment. Fix the
mapping size so that it satisfy the alignment requirement.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 daxctl/io.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/daxctl/io.c b/daxctl/io.c
index 2f8cb4a..e739d0e 100644
--- a/daxctl/io.c
+++ b/daxctl/io.c
@@ -55,6 +55,7 @@ struct io_dev {
 	struct ndctl_region *region;
 	struct ndctl_dax *dax;
 	uint64_t size;
+	uint64_t mmap_size;
 };
 
 static struct {
@@ -83,6 +84,7 @@ static bool is_stdinout(struct io_dev *io_dev)
 static int setup_device(struct io_dev *io_dev, size_t size)
 {
 	int flags, rc;
+	unsigned long align;
 
 	if (is_stdinout(io_dev))
 		return 0;
@@ -104,8 +106,14 @@ static int setup_device(struct io_dev *io_dev, size_t size)
 	if (!io_dev->is_dax)
 		return 0;
 
+	align = ndctl_dax_get_align(io_dev->dax);
+	if (align == ULLONG_MAX)
+		return -ERANGE;
+
+	io_dev->mmap_size = ALIGN(size, align);
 	flags = (io_dev->direction == IO_READ) ? PROT_READ : PROT_WRITE;
-	io_dev->mmap = mmap(NULL, size, flags, MAP_SHARED, io_dev->fd, 0);
+	io_dev->mmap = mmap(NULL, io_dev->mmap_size, flags,
+			MAP_SHARED, io_dev->fd, 0);
 	if (io_dev->mmap == MAP_FAILED) {
 		rc = -errno;
 		perror("mmap");
@@ -501,6 +509,8 @@ static void cleanup(void)
 	for (i = 0; i < 2; i++) {
 		if (is_stdinout(&io.dev[i]))
 			continue;
+		if (io.dev[i].mmap_size)
+			munmap(io.dev[i].mmap, io.dev[i].mmap_size);
 		close(io.dev[i].fd);
 	}
 }

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* [PATCH v2 2/2] ndctl: make mmap start at the offset
  2017-11-13 18:19 [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dave Jiang
@ 2017-11-13 18:19 ` Dave Jiang
  2017-11-13 23:40 ` [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dan Williams
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Jiang @ 2017-11-13 18:19 UTC (permalink / raw)
  To: dan.j.williams; +Cc: linux-nvdimm

Instead of mmap at the beginning of the DAX region, map at the offset
that is aligned down. This reduces the mmap size we need to create.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 daxctl/io.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/daxctl/io.c b/daxctl/io.c
index e739d0e..ce02f28 100644
--- a/daxctl/io.c
+++ b/daxctl/io.c
@@ -46,6 +46,7 @@ struct io_dev {
 	const char *parm_path;
 	char *real_path;
 	uint64_t offset;
+	int offset_diff;
 	enum io_direction direction;
 	bool is_dax;
 	bool is_char;
@@ -84,7 +85,7 @@ static bool is_stdinout(struct io_dev *io_dev)
 static int setup_device(struct io_dev *io_dev, size_t size)
 {
 	int flags, rc;
-	unsigned long align;
+	unsigned long align, offset;
 
 	if (is_stdinout(io_dev))
 		return 0;
@@ -112,8 +113,11 @@ static int setup_device(struct io_dev *io_dev, size_t size)
 
 	io_dev->mmap_size = ALIGN(size, align);
 	flags = (io_dev->direction == IO_READ) ? PROT_READ : PROT_WRITE;
+	offset = ALIGN_DOWN(io_dev->offset, align);
+	io_dev->offset_diff = io_dev->offset - offset;
+
 	io_dev->mmap = mmap(NULL, io_dev->mmap_size, flags,
-			MAP_SHARED, io_dev->fd, 0);
+			MAP_SHARED, io_dev->fd, offset);
 	if (io_dev->mmap == MAP_FAILED) {
 		rc = -errno;
 		perror("mmap");
@@ -372,17 +376,17 @@ static int64_t __do_io(struct io_dev *dst_dev, struct io_dev *src_dev,
 	ssize_t rc, count = 0;
 
 	if (zero && dst_dev->is_dax) {
-		dst = (uint8_t *)dst_dev->mmap + dst_dev->offset;
+		dst = (uint8_t *)dst_dev->mmap + dst_dev->offset_diff;
 		memset(dst, 0, len);
 		pmem_persist(dst, len);
 		rc = len;
 	} else if (dst_dev->is_dax && src_dev->is_dax) {
-		src = (uint8_t *)src_dev->mmap + src_dev->offset;
-		dst = (uint8_t *)dst_dev->mmap + dst_dev->offset;
+		src = (uint8_t *)src_dev->mmap + src_dev->offset_diff;
+		dst = (uint8_t *)dst_dev->mmap + dst_dev->offset_diff;
 		pmem_memcpy_persist(dst, src, len);
 		rc = len;
 	} else if (src_dev->is_dax) {
-		src = (uint8_t *)src_dev->mmap + src_dev->offset;
+		src = (uint8_t *)src_dev->mmap + src_dev->offset_diff;
 		if (dst_dev->offset) {
 			rc = lseek(dst_dev->fd, dst_dev->offset, SEEK_SET);
 			if (rc < 0) {
@@ -407,7 +411,7 @@ static int64_t __do_io(struct io_dev *dst_dev, struct io_dev *src_dev,
 			printf("Requested size %lu larger than source.\n",
 					len);
 	} else if (dst_dev->is_dax) {
-		dst = (uint8_t *)dst_dev->mmap + dst_dev->offset;
+		dst = (uint8_t *)dst_dev->mmap + dst_dev->offset_diff;
 		if (src_dev->offset) {
 			rc = lseek(src_dev->fd, src_dev->offset, SEEK_SET);
 			if (rc < 0) {

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH v2 1/2] ndctl: daxctl: fix mmap size
  2017-11-13 18:19 [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dave Jiang
  2017-11-13 18:19 ` [PATCH v2 2/2] ndctl: make mmap start at the offset Dave Jiang
@ 2017-11-13 23:40 ` Dan Williams
  2017-11-13 23:49   ` Dave Jiang
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Williams @ 2017-11-13 23:40 UTC (permalink / raw)
  To: Dave Jiang; +Cc: linux-nvdimm

On Mon, Nov 13, 2017 at 10:19 AM, Dave Jiang <dave.jiang@intel.com> wrote:
> The size for mmap needs to be aligned to the region alignment. Fix the
> mapping size so that it satisfy the alignment requirement.
>
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  daxctl/io.c |   12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/daxctl/io.c b/daxctl/io.c
> index 2f8cb4a..e739d0e 100644
> --- a/daxctl/io.c
> +++ b/daxctl/io.c
> @@ -55,6 +55,7 @@ struct io_dev {
>         struct ndctl_region *region;
>         struct ndctl_dax *dax;
>         uint64_t size;
> +       uint64_t mmap_size;
>  };
>
>  static struct {
> @@ -83,6 +84,7 @@ static bool is_stdinout(struct io_dev *io_dev)
>  static int setup_device(struct io_dev *io_dev, size_t size)
>  {
>         int flags, rc;
> +       unsigned long align;
>
>         if (is_stdinout(io_dev))
>                 return 0;
> @@ -104,8 +106,14 @@ static int setup_device(struct io_dev *io_dev, size_t size)
>         if (!io_dev->is_dax)
>                 return 0;
>
> +       align = ndctl_dax_get_align(io_dev->dax);
> +       if (align == ULLONG_MAX)

Isn't this always false because 'align' is 'unsigned long', not
'unsigned long long'?

Otherwise the rest of this looks good.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH v2 1/2] ndctl: daxctl: fix mmap size
  2017-11-13 23:40 ` [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dan Williams
@ 2017-11-13 23:49   ` Dave Jiang
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Jiang @ 2017-11-13 23:49 UTC (permalink / raw)
  To: Dan Williams; +Cc: linux-nvdimm



On 11/13/2017 04:40 PM, Dan Williams wrote:
> On Mon, Nov 13, 2017 at 10:19 AM, Dave Jiang <dave.jiang@intel.com> wrote:
>> The size for mmap needs to be aligned to the region alignment. Fix the
>> mapping size so that it satisfy the alignment requirement.
>>
>> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
>> ---
>>  daxctl/io.c |   12 +++++++++++-
>>  1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/daxctl/io.c b/daxctl/io.c
>> index 2f8cb4a..e739d0e 100644
>> --- a/daxctl/io.c
>> +++ b/daxctl/io.c
>> @@ -55,6 +55,7 @@ struct io_dev {
>>         struct ndctl_region *region;
>>         struct ndctl_dax *dax;
>>         uint64_t size;
>> +       uint64_t mmap_size;
>>  };
>>
>>  static struct {
>> @@ -83,6 +84,7 @@ static bool is_stdinout(struct io_dev *io_dev)
>>  static int setup_device(struct io_dev *io_dev, size_t size)
>>  {
>>         int flags, rc;
>> +       unsigned long align;
>>
>>         if (is_stdinout(io_dev))
>>                 return 0;
>> @@ -104,8 +106,14 @@ static int setup_device(struct io_dev *io_dev, size_t size)
>>         if (!io_dev->is_dax)
>>                 return 0;
>>
>> +       align = ndctl_dax_get_align(io_dev->dax);
>> +       if (align == ULLONG_MAX)
> 
> Isn't this always false because 'align' is 'unsigned long', not
> 'unsigned long long'?
> 
> Otherwise the rest of this looks good.
> 

Ok I'll send out v3 if you don't have issues with the other patch.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2017-11-13 23:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 18:19 [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dave Jiang
2017-11-13 18:19 ` [PATCH v2 2/2] ndctl: make mmap start at the offset Dave Jiang
2017-11-13 23:40 ` [PATCH v2 1/2] ndctl: daxctl: fix mmap size Dan Williams
2017-11-13 23:49   ` Dave Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).