linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Cc: vishal.l.verma@intel.com
Subject: [ndctl PATCH 16/16] test/ndctl: mremap pmd confusion
Date: Mon, 06 Jul 2020 19:41:43 -0700	[thread overview]
Message-ID: <159408970344.2386154.3822093364134233478.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <159408961822.2386154.888266173771881937.stgit@dwillia2-desk3.amr.corp.intel.com>

mremap() fails to check for pmd_devmap() entries in some kernels leading to
a case where move_page_tables() interprets a pmd_devmap() entry as a page
table and not a leaf entry. Reproduce this failing condition across
device-dax and fileystem-dax.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test.h            |    2 +
 test/dax-dev.c    |    4 ++
 test/dax-pmd.c    |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 test/device-dax.c |    7 ++++
 4 files changed, 108 insertions(+), 4 deletions(-)

diff --git a/test.h b/test.h
index fa0c0cff9daf..3f6212e067fc 100644
--- a/test.h
+++ b/test.h
@@ -38,6 +38,8 @@ struct ndctl_ctx;
 int test_parent_uuid(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
 int test_multi_pmem(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx);
 int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t offset);
+int test_dax_remap(struct ndctl_test *test, int dax_fd, unsigned long align, void *dax_addr,
+		off_t offset, bool fsdax);
 #ifdef ENABLE_POISON
 int test_dax_poison(struct ndctl_test *test, int dax_fd, unsigned long align,
 		void *dax_addr, off_t offset, bool fsdax);
diff --git a/test/dax-dev.c b/test/dax-dev.c
index 49ccaa334e31..ab6b35a67183 100644
--- a/test/dax-dev.c
+++ b/test/dax-dev.c
@@ -60,6 +60,10 @@ struct ndctl_namespace *ndctl_get_test_dev(struct ndctl_ctx *ctx)
 	if (!ndns)
 		goto out;
 
+	rc = ndctl_namespace_enable(ndns);
+	if (rc)
+		goto out;
+
 	mode = ndctl_namespace_get_mode(ndns);
 	if (mode >= 0 && mode != NDCTL_NS_MODE_MEMORY)
 		goto out;
diff --git a/test/dax-pmd.c b/test/dax-pmd.c
index 0c95b20707c2..df3219639a6d 100644
--- a/test/dax-pmd.c
+++ b/test/dax-pmd.c
@@ -27,6 +27,7 @@
 #include <test.h>
 #include <util/size.h>
 #include <linux/fiemap.h>
+#include <linux/version.h>
 
 #define NUM_EXTENTS 5
 #define fail() fprintf(stderr, "%s: failed at: %d (%s)\n", \
@@ -35,6 +36,92 @@
 	__func__, __LINE__, i, strerror(errno))
 #define TEST_FILE "test_dax_data"
 
+#define REGION_MEM_SIZE 4096*4
+#define REGION_PM_SIZE        4096*512
+#define REMAP_SIZE      4096
+
+static sigjmp_buf sj_env;
+
+static void sigbus(int sig, siginfo_t *siginfo, void *d)
+{
+	siglongjmp(sj_env, 1);
+}
+
+int test_dax_remap(struct ndctl_test *test, int dax_fd, unsigned long align, void *dax_addr,
+		off_t offset, bool fsdax)
+{
+	void *anon, *remap, *addr;
+	struct sigaction act;
+	int rc, val;
+
+	if ((fsdax || align == SZ_2M) && !ndctl_test_attempt(test, KERNEL_VERSION(5, 8, 0))) {
+		/* kernel's prior to 5.8 may crash on this test */
+		fprintf(stderr, "%s: SKIP mremap() test\n", __func__);
+		return 0;
+	}
+
+	anon = mmap(NULL, REGION_MEM_SIZE, PROT_READ|PROT_WRITE,
+			MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+
+	addr = mmap(dax_addr, 2*align,
+			PROT_READ|PROT_WRITE, MAP_SHARED, dax_fd, offset);
+
+	fprintf(stderr, "%s: addr: %p size: %#lx\n", __func__, addr, 2*align);
+
+	if (addr == MAP_FAILED) {
+		rc = -errno;
+		faili(0);
+		return rc;
+	}
+
+	memset(anon, 'a', REGION_MEM_SIZE);
+	memset(addr, 'i', align*2);
+
+	remap = mremap(addr, REMAP_SIZE, REMAP_SIZE, MREMAP_MAYMOVE|MREMAP_FIXED, anon);
+
+	if (remap != anon) {
+		rc = -ENXIO;
+		perror("mremap");
+		faili(1);
+		return rc;
+	}
+
+	fprintf(stderr, "%s: addr: %p size: %#x\n", __func__, remap, REMAP_SIZE);
+
+	memset(&act, 0, sizeof(act));
+	act.sa_sigaction = sigbus;
+	act.sa_flags = SA_SIGINFO;
+	if (sigaction(SIGBUS, &act, 0)) {
+		perror("sigaction");
+		rc = EXIT_FAILURE;
+		goto out;
+	}
+
+	/* test fault after device-dax instance disabled */
+	if (sigsetjmp(sj_env, 1)) {
+		if (!fsdax && align > SZ_4K) {
+			fprintf(stderr, "got expected SIGBUS after mremap() of device-dax\n");
+			rc = 0;
+		} else {
+			fprintf(stderr, "unpexpected SIGBUS after mremap()\n");
+			rc = -EIO;
+		}
+		goto out;
+	}
+
+	*(int *) anon = 0xAA;
+	val = *(int *) anon;
+
+	if (val != 0xAA) {
+		faili(2);
+		return -ENXIO;
+	}
+
+	rc = 0;
+out:
+	return rc;
+}
+
 int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t offset)
 {
 	int i, rc = -ENXIO;
@@ -254,15 +341,19 @@ static int test_pmd(struct ndctl_test *test, int fd)
 
 	pmd_addr = (char *) base + m_align;
 	pmd_off =  ext->fe_logical + p_align;
+	rc = test_dax_remap(test, fd, HPAGE_SIZE, pmd_addr, pmd_off, fsdax);
+	if (rc)
+		goto err_test;
+
 	rc = test_dax_directio(fd, HPAGE_SIZE, pmd_addr, pmd_off);
 	if (rc)
-		goto err_directio;
+		goto err_test;
 
 	rc = test_dax_poison(test, fd, HPAGE_SIZE, pmd_addr, pmd_off, fsdax);
 
- err_directio:
- err_extent:
- err_mmap:
+err_test:
+err_extent:
+err_mmap:
 	free(map);
 	return rc;
 }
diff --git a/test/device-dax.c b/test/device-dax.c
index b19c1ed0b535..9de10682e34d 100644
--- a/test/device-dax.c
+++ b/test/device-dax.c
@@ -268,6 +268,13 @@ static int __test_device_dax(unsigned long align, int loglevel,
 					ndctl_namespace_get_devname(ndns));
 			goto out;
 		}
+
+		rc = test_dax_remap(test, fd, align, NULL, 0, devdax);
+		if (rc) {
+			fprintf(stderr, "%s: failed dax remap\n",
+					ndctl_namespace_get_devname(ndns));
+			goto out;
+		}
 		close(fd);
 
 		fprintf(stderr, "%s: test dax poison\n",
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

      parent reply	other threads:[~2020-07-07  2:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07  2:40 [ndctl PATCH 00/16] Firmware Activation and Test Updates Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 01/16] ndctl/build: Fix zero-length array warnings Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 02/16] ndctl/dimm: Fix chatty status messages Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 03/16] ndctl/list: Indicate firmware update capability Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 04/16] ndctl/dimm: Detect firmware-update vs ARS conflict Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 05/16] ndctl/dimm: Improve firmware-update failure message Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 06/16] ndctl/dimm: Prepare to emit dimm json object after firmware update Dan Williams
2020-07-07  2:40 ` [ndctl PATCH 07/16] ndctl/dimm: Emit dimm firmware details after update Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 08/16] ndctl/list: Add firmware activation enumeration Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 09/16] ndctl/dimm: Auto-arm firmware activation Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 10/16] ndctl/bus: Add 'activate-firmware' command Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 11/16] ndctl/docs: Update copyright date Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 12/16] ndctl/test: Test firmware-activation interface Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 13/16] test: Validate strict iomem protections of pmem Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 14/16] ndctl: Refactor nfit.h to acpi.h Dan Williams
2020-07-07  2:41 ` [ndctl PATCH 15/16] daxctl: Add 'split-acpi' command to generate custom ACPI tables Dan Williams
2020-07-07  2:41 ` Dan Williams [this message]

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=159408970344.2386154.3822093364134233478.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.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).