From: Dan Williams <dan.j.williams@intel.com>
To: vishal.l.verma@intel.com
Cc: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 4/4] ndctl/test: Exercise soft_offline_page() corner cases
Date: Tue, 12 Jan 2021 23:15:14 -0800 [thread overview]
Message-ID: <161052211455.1804207.13884321454837200896.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <161052209289.1804207.11599120961607513911.stgit@dwillia2-desk3.amr.corp.intel.com>
Test soft-offline injection into PMEM namespace metadata and user mapped
space. Both attempts should fail on kernels with a pfn_to_online_page()
implementation that considers subsection ZONE_DEVICE ranges.
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
test/dax-poison.c | 19 +++++++++++++++++++
test/device-dax.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/test/dax-poison.c b/test/dax-poison.c
index a4ef12eca1be..4e09761f0a5e 100644
--- a/test/dax-poison.c
+++ b/test/dax-poison.c
@@ -5,6 +5,7 @@
#include <signal.h>
#include <setjmp.h>
#include <sys/mman.h>
+#include <linux/mman.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
@@ -49,6 +50,7 @@ int test_dax_poison(struct ndctl_test *test, int dax_fd, unsigned long align,
unsigned char *addr = MAP_FAILED;
struct sigaction act;
unsigned x = x;
+ FILE *smaps;
void *buf;
int rc;
@@ -94,6 +96,9 @@ int test_dax_poison(struct ndctl_test *test, int dax_fd, unsigned long align,
goto out;
}
+ fprintf(stderr, "%s: mmap got %p align: %ld offset: %zd\n",
+ __func__, addr, align, offset);
+
if (sigsetjmp(sj_env, 1)) {
if (sig_mcerr_ar) {
fprintf(stderr, "madvise triggered 'action required' sigbus\n");
@@ -104,6 +109,20 @@ int test_dax_poison(struct ndctl_test *test, int dax_fd, unsigned long align,
}
}
+ rc = madvise(addr + align / 2, 4096, MADV_SOFT_OFFLINE);
+ if (rc == 0) {
+ fprintf(stderr, "softoffline should always fail for dax\n");
+ smaps = fopen("/proc/self/smaps", "r");
+ do {
+ rc = fread(buf, 1, 4096, smaps);
+ fwrite(buf, 1, rc, stderr);
+ } while (rc);
+ fclose(smaps);
+ fail();
+ rc = -ENXIO;
+ goto out;
+ }
+
rc = madvise(addr + align / 2, 4096, MADV_HWPOISON);
if (rc) {
fail();
diff --git a/test/device-dax.c b/test/device-dax.c
index 5f0da297f28e..aad8fa5f1cb1 100644
--- a/test/device-dax.c
+++ b/test/device-dax.c
@@ -128,6 +128,44 @@ static int verify_data(struct daxctl_dev *dev, char *dax_buf,
return 0;
}
+static int test_dax_soft_offline(struct ndctl_test *test, struct ndctl_namespace *ndns)
+{
+ unsigned long long resource = ndctl_namespace_get_resource(ndns);
+ int fd, rc;
+ char *buf;
+
+ if (resource == ULLONG_MAX) {
+ fprintf(stderr, "failed to get resource: %s\n",
+ ndctl_namespace_get_devname(ndns));
+ return -ENXIO;
+ }
+
+ fd = open("/sys/devices/system/memory/soft_offline_page", O_WRONLY);
+ if (fd < 0) {
+ fprintf(stderr, "failed to open soft_offline_page\n");
+ return -ENOENT;
+ }
+
+ rc = asprintf(&buf, "%#llx\n", resource);
+ if (rc < 0) {
+ fprintf(stderr, "failed to alloc resource\n");
+ close(fd);
+ return -ENOMEM;
+ }
+
+ fprintf(stderr, "%s: try to offline page @%#llx\n", __func__, resource);
+ rc = write(fd, buf, rc);
+ free(buf);
+ close(fd);
+
+ if (rc >= 0) {
+ fprintf(stderr, "%s: should have failed\n", __func__);
+ return -ENXIO;
+ }
+
+ return 0;
+}
+
static int __test_device_dax(unsigned long align, int loglevel,
struct ndctl_test *test, struct ndctl_ctx *ctx)
{
@@ -278,6 +316,13 @@ static int __test_device_dax(unsigned long align, int loglevel,
goto out;
}
+ rc = test_dax_soft_offline(test, ndns);
+ if (rc) {
+ fprintf(stderr, "%s: failed dax soft offline\n",
+ ndctl_namespace_get_devname(ndns));
+ goto out;
+ }
+
rc = test_dax_poison(test, fd, align, NULL, 0, devdax);
if (rc) {
fprintf(stderr, "%s: failed dax poison\n",
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
prev parent reply other threads:[~2021-01-13 7:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-13 7:14 [ndctl PATCH 0/4] ndctl/test: softoffline, mremap, and misc fixups Dan Williams
2021-01-13 7:14 ` [ndctl PATCH 1/4] ndctl/test: Fix btt expect table compile warning Dan Williams
2021-01-13 7:15 ` [ndctl PATCH 2/4] ndctl/test: Cleanup unnecessary out label Dan Williams
2021-01-13 7:15 ` [ndctl PATCH 3/4] ndctl/test: Fix device-dax mremap() test Dan Williams
2021-01-13 7:15 ` 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=161052211455.1804207.13884321454837200896.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).