All of lore.kernel.org
 help / color / mirror / Atom feed
* mmap dio write failure
@ 2017-01-20  4:40 Xiong Zhou
       [not found] ` <20170120044007.kwevjo7nawwolagy-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Xiong Zhou @ 2017-01-20  4:40 UTC (permalink / raw)
  To: linux-nvdimm-y27Ovi1pjclAfugRpC6u6w; +Cc: eguan-H+wXaHxf7aLQT0dZR+AlfA

Hi,

At first, I am not sure whether this is an issue.

mmap a file in a DAX mountpoint, open another file
in a non-DAX mountpoint with O_DIRECT, write the
mapped area to the other file.

This write Success on pmem ramdisk(memmap=2G!20G like)
This write Fail(Bad address) on nvdimm pmem devices.
This write Fail(Bad address) on brd based ramdisk.

If we skip the O_DIRECT flag, all tests pass.

If we write from DAX to DAX, all tests pass.
If we write from non-DAX to DAX, all tests pass.

Kernel version: Linus tree commit 44b4b46.

I have checked back to v4.6 testing on nvdimm devices,
all the same results. I do remember that this test
passed on nvdimms back to May 2016 and i have some
notes for that. However things changed a lot, test
scripts, kernel code, even the nvdimm and machine
firmweare.

Thanks,
Xiong

sh-4.2# cat tbad.sh
#!/bin/bash
[ -z "$1" ] && exit 1
DEV="$1"
MNT=/tbdmnt
cc t_mmap_dio.c
mkdir -p $MNT
wipefs -af $DEV
mkfs.xfs -fq $DEV && \
mount -o dax $DEV $MNT && \
xfs_io -f -c "w -W 0 268435456" $MNT/ts > /dev/null && \
xfs_io -f -c "w -W 0 268435456" ./td > /dev/null
if ./a.out $MNT/ts ./td 16777216 "$DEV" ; then
	echo PASS
else
	echo FAIL
fi
umount $MNT

sh-4.2# cat t_mmap_dio.c 
/*
 * This programme was originally written by
 *     Jeff Moyer <jmoyer-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
 */
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <libaio.h>
#include <errno.h>
#include <sys/time.h>

void usage(char *prog)
{
	fprintf(stderr,
		"usage: %s <src file> <dest file> <size> <msg>\n",
		prog);
	exit(1);
}

void err_exit(char *op, unsigned long len, char *s)
{
	fprintf(stderr, "%s(%s) len %lu %s\n",
		op, strerror(errno), len, s);
	exit(1);
}

int main(int argc, char **argv)
{
	int fd, fd2, ret;
	char *map;
	unsigned long len;

	if (argc < 4)
		usage(basename(argv[0]));

	len = strtoul(argv[3], NULL, 10);
	if (errno == ERANGE)
		err_exit("strtoul", 0, argv[4]);

	/* Open source file and mmap*/
	fd = open(argv[1], O_RDWR, 0644);
	if (fd < 0)
		err_exit("open s", len, argv[4]);

	map = (char *)mmap(NULL, len,
		PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	if (map == MAP_FAILED)
		err_exit("mmap", len, argv[4]);

	/* Open dest file with O_DIRECT */
	fd2 = open(argv[2], O_RDWR|O_DIRECT, 0644);
	if (fd2 < 0)
		err_exit("open d", len, argv[4]);

	/* First, test storing to dest file from source mapping */
	ret = write(fd2, map, len);
	if (ret != len)
		err_exit("write", len, argv[4]);

	ret = (int)lseek(fd2, 0, SEEK_SET);
	if (ret == -1)
		err_exit("lseek", len, argv[4]);

	/* Next, test reading from dest file into source mapping */
	ret = read(fd2, map, len);
	if (ret != len)
		err_exit("read", len, argv[4]);
	ret = msync(map, len, MS_SYNC);
	if (ret < 0)
		err_exit("msync", len, argv[4]);

	ret = munmap(map, len);
	if (ret < 0)
		err_exit("munmap", len, argv[4]);

	ret = close(fd);
	if (ret < 0)
		err_exit("clsoe fd", len, argv[4]);

	ret = close(fd2);
	if (ret < 0)
		err_exit("close fd2", len, argv[4]);

	exit(0);
}

sh-4.2# ndctl list -N
[
  {
    "dev":"namespace3.0",
    "mode":"raw",
    "size":8589934592,
    "blockdev":"pmem3"
  },
  {
    "dev":"namespace2.0",
    "mode":"raw",
    "size":8589934592,
    "blockdev":"pmem2"
  },
  {
    "dev":"namespace1.0",
    "mode":"memory",
    "size":2147483648,
    "blockdev":"pmem1"
  },
  {
    "dev":"namespace0.0",
    "mode":"memory",
    "size":2147483648,
    "blockdev":"pmem0"
  }
]

sh-4.2# modinfo brd
filename:       /lib/modules/4.10.0-rc4-master-44b4b46+/kernel/drivers/block/brd.ko
alias:          rd
alias:          block-major-1-*
license:        GPL
srcversion:     25AABF2EF57F6A37AFFEBA6
depends:        
intree:         Y
vermagic:       4.10.0-rc4-master-44b4b46+ SMP mod_unload modversions 
parm:           rd_nr:Maximum number of brd devices (int)
parm:           rd_size:Size of each RAM disk in kbytes. (ulong)
parm:           max_part:Num Minors to reserve between devices (int)

sh-4.2# uname -r
4.10.0-rc4-master-44b4b46+

sh-4.2# bash tbad.sh /dev/pmem0
/dev/pmem0: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42
PASS

sh-4.2# bash tbad.sh /dev/pmem2
/dev/pmem2: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42
write(Bad address) len 16777216 /dev/pmem2
FAIL

sh-4.2# bash tbad.sh /dev/ram0
/dev/ram0: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42
write(Bad address) len 16777216 /dev/ram0
FAIL

sh-4.2# df .
Filesystem                              1K-blocks     Used Available Use% Mounted on
/dev/mapper/rhxxxxxxxxxxxxxxxxx-01-root  52399104 43658792   8740312  84% /
sh-4.2# 

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

end of thread, other threads:[~2017-02-23  9:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20  4:40 mmap dio write failure Xiong Zhou
     [not found] ` <20170120044007.kwevjo7nawwolagy-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2017-01-20  6:04   ` Dan Williams
2017-02-07 10:01     ` Xiong Zhou
2017-02-08  3:51   ` read failure (was Re: mmap dio write failure) Xiong Zhou
     [not found]     ` <20170208035105.lvewz5ce7xbu5zud-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2017-02-08  4:10       ` Dan Williams
     [not found]         ` <CAPcyv4iF2xH=9FHDMqb8OYMFO45GkiEEKf1y73Q7scGQSJniag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-08  4:49           ` Xiong Zhou
     [not found]             ` <20170208044959.rq3ofmsjth2oeu2u-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2017-02-08  5:05               ` Dan Williams
     [not found]                 ` <CAPcyv4iCz9SqJkoKYr-RWxV4FmqPB1Wfkx_A_jE-S5Unpo-5Pw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-08  6:56                   ` Xiong Zhou
     [not found]                     ` <20170208065651.ab74cytferq4ha57-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2017-02-08  7:09                       ` Xiong Zhou
     [not found]                         ` <20170208070907.m6cwwz47hrow5vui-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2017-02-08  7:22                           ` Xiong Zhou
     [not found]                             ` <20170208072253.erl4esloglvq2zet-E9dkjZ7ERC1QcClZ3XN9yxcY2uh10dtjAL8bYrjMMd8@public.gmane.org>
2017-02-22 23:05                               ` Dan Williams
     [not found]                                 ` <CAPcyv4gKtLp07ta6PmWKrFJa9RZOPhShFmBcXiRS2izturw4QQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-23  9:53                                   ` Xiong Zhou

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.