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.ji...@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