All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: dan.j.williams@intel.com
Cc: linux-nvdimm@lists.01.org
Subject: [PATCH] ndctl: daxctl: fix mmap size
Date: Fri, 10 Nov 2017 12:45:11 -0700	[thread overview]
Message-ID: <151034311187.59853.17265892705257743788.stgit@djiang5-desk3.ch.intel.com> (raw)

The size for mmap needs to be aligned to the region alignment. Add helper
funciton to determine the actual size to be mmap'd.

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

diff --git a/daxctl/io.c b/daxctl/io.c
index 2f8cb4a..97a4169 100644
--- a/daxctl/io.c
+++ b/daxctl/io.c
@@ -80,9 +80,26 @@ static bool is_stdinout(struct io_dev *io_dev)
 			io_dev->fd == STDOUT_FILENO) ? true : false;
 }
 
+static int get_mmap_size(struct io_dev *io_dev, size_t size, size_t *map_size)
+{
+	unsigned long align;
+
+	align = ndctl_dax_get_align(io_dev->dax);
+	if (align == ULLONG_MAX)
+		return -ERANGE;
+
+	if (size <= align)
+		*map_size = align;
+	else
+		*map_size = (size / align) * align;
+
+	return 0;
+}
+
 static int setup_device(struct io_dev *io_dev, size_t size)
 {
 	int flags, rc;
+	size_t map_size;
 
 	if (is_stdinout(io_dev))
 		return 0;
@@ -104,8 +121,12 @@ static int setup_device(struct io_dev *io_dev, size_t size)
 	if (!io_dev->is_dax)
 		return 0;
 
+	rc = get_mmap_size(io_dev, size, &map_size);
+	if (rc < 0)
+		return rc;
+
 	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, map_size, flags, MAP_SHARED, io_dev->fd, 0);
 	if (io_dev->mmap == MAP_FAILED) {
 		rc = -errno;
 		perror("mmap");

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

             reply	other threads:[~2017-11-10 19:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 19:45 Dave Jiang [this message]
2017-11-12 18:10 ` [PATCH] ndctl: daxctl: fix mmap size Dan Williams
2017-11-12 18:11   ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151034311187.59853.17265892705257743788.stgit@djiang5-desk3.ch.intel.com \
    --to=dave.jiang@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.