qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Xiao Guangrong <guangrong.xiao@linux.intel.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>,
	Yumei Huang <yuhuang@redhat.com>, KVM <kvm@vger.kernel.org>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] DAX can not work on virtual nvdimm device
Date: Wed, 31 Aug 2016 16:44:47 +0800	[thread overview]
Message-ID: <25098f37-53f7-6d5d-0b1a-8469bab51a9f@linux.intel.com> (raw)
In-Reply-To: <CAPcyv4hrFSxNcmmVLVZT4fK3+hspPCDKW0rVBj1=3GkJRgZ29Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]



On 08/31/2016 01:09 AM, Dan Williams wrote:

>
> Can you post your exact reproduction steps?  This test is not failing for me.
>

Sure.

1. make the guest kernel based on your tree, the top commit is
    10d7902fa0e82b (dax: unmap/truncate on device shutdown) and
    the config file can be found in this thread.

2. add guest kernel command line: memmap=6G!10G

3: start the guest:
    x86_64-softmmu/qemu-system-x86_64 -machine pc,nvdimm --enable-kvm \
    -smp 16 -m 32G,maxmem=100G,slots=100 /other/VMs/centos6.img -monitor stdio

4: in guest:
    mkfs.ext4 /dev/pmem0
    mount -o dax /dev/pmem0  /mnt/pmem/
    echo > /mnt/pmem/xxx
    ./mmap /mnt/pmem/xxx
    ./read /mnt/pmem/xxx

   The source code of mmap and read has been attached in this mail.

   Hopefully, you can detect the error triggered by read test.

Thanks!

[-- Attachment #2: read.c --]
[-- Type: text/x-csrc, Size: 763 bytes --]

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
	char *filename;

	if (argc < 2) {
		printf("arg: filename.\n");
		return -1;
	}

	filename = argv[1];
	printf("test on %s.\n", filename);

	int fd = open(filename, O_RDWR);

	if (fd < 0) {
		perror("open");
		return -1;
	}

	int count = 0;

	while (1) {
		ssize_t ret;
		char buf;

		ret = read(fd, &buf, sizeof(buf));
		if (ret < 0) {
			perror("READ");
			return -1;
		}

		if (ret == 0)
			break;
		if (ret != sizeof(buf)) {
			printf("Count %x Ret %lx sizeof(buf) %lx.\n",
				count, ret, sizeof(buf));
			return -1;
		}

		count++;
		printf("%c", buf);
	}

	printf("\n Good Read.\n");
	return 0;
}

[-- Attachment #3: mmap.c --]
[-- Type: text/x-csrc, Size: 2063 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>

static void write_test(char *buf, int size)
{
	int i;

	printf("Try to write %p for %x size.\n", buf, size);
	for (i = 0; i < size; i++)
		buf[i] = (char)(i & 0xFF);
	printf("Write Done.\n");
}

static void read_test(char *buf, int size)
{
	int i;

	printf("Try to read %p for %x size.\n", buf, size);
	for (i = 0; i < size; i++)
		if (buf[i] != (char)(i & 0xFF)) {
			printf("Read Check failed.\n");
			printf("Index %x, %c expect %x.\n", i, buf[i], i & 0xFF);
			exit(-1);
		}
	printf("Read Done.\n");
}

static void fread_test(int fd, int size)
{
	char buf;
	int i;

	i = lseek(fd, 0, SEEK_END);
	printf("End: %x.\n", i);

	i = lseek(fd, 0, SEEK_SET);
	if (i != 0) {
		perror("seek");
		exit(-1);
	}

	printf("Try to fread fd=%d size %x sizeof(buf) %ld.\n", fd, size,
		sizeof(buf));

	for (i = 0; i < size; i++) {
		int ret;

		ret = read(fd, &buf, sizeof(buf));
		if (ret != sizeof(buf)) {
			printf("Read failed, offset %x, ret %d ftell %ld.\n",
				i, ret, lseek(fd, 0, SEEK_CUR));
			perror("read");
			exit(-1);
		}
		if (buf != (char)(i & 0xFF)) {
			printf("Read Check failed.\n");
			printf("Index %x, %c expect %x.\n", i, buf, i & 0xFF);
			exit (-1);
		}
	}

	printf("Fread Done.\n");
}

int main(int argc, char *argv[])
{
	char *filename;
	char *buf;
	int fd;

	if (argc < 2) {
		printf("arg: filename.\n");
		return -1;
	}

	filename = argv[1];
	printf("mmap test on %s.\n", filename);

	fd = open(filename, O_RDWR);
	if (fd < 0) {
		perror("open");
		return -1;
	}

	if (lseek(fd, 0x1000, SEEK_SET) != 0x1000) {
		perror("seek");
		return -1;
	}

	if (ftruncate(fd, 0x1000) != 0) {
		perror("ftruncate");
		return -1;
	}

//	return 0;

	buf = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (buf == MAP_FAILED) {
		perror("mmap");
		return -1;
	}

	write_test(buf, 0x1000);
	read_test(buf, 0x1000);
	msync(buf, 0x1000, MS_SYNC);
	fread_test(fd, 0x1000);

	close(fd);

	return 0;
}

  reply	other threads:[~2016-08-31  8:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-19 11:19 [Qemu-devel] DAX can not work on virtual nvdimm device Xiao Guangrong
2016-08-19 14:59 ` Dan Williams
2016-08-19 18:30   ` Ross Zwisler
2016-08-21  9:55     ` Boaz Harrosh
2016-08-29  7:54     ` Xiao Guangrong
2016-08-29 19:30       ` Ross Zwisler
2016-08-30  6:53         ` Xiao Guangrong
2016-08-30 17:09           ` Dan Williams
2016-08-31  8:44             ` Xiao Guangrong [this message]
2016-08-31 16:46               ` Ross Zwisler
2016-09-02  2:57               ` Ross Zwisler
2016-09-06 15:06                 ` Jan Kara
2016-09-08 20:47                   ` Ross Zwisler
2016-09-09  9:19                     ` Jan Kara
2016-09-09 14:03                       ` Theodore Ts'o
2016-09-09 16:34                         ` Ross Zwisler

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=25098f37-53f7-6d5d-0b1a-8469bab51a9f@linux.intel.com \
    --to=guangrong.xiao@linux.intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.org \
    --cc=qemu-devel@nongnu.org \
    --cc=ross.zwisler@linux.intel.com \
    --cc=stefanha@redhat.com \
    --cc=yuhuang@redhat.com \
    /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 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).