ndctl/0006-ndctl-test-Exercise-soft_offline_page-corner-cases.patch

135 lines
3.8 KiB
Diff
Raw Normal View History

From 940acf65a61595e8c0db3aebe1c74307acbbef68 Mon Sep 17 00:00:00 2001
From: Dan Williams <dan.j.williams@intel.com>
Date: Tue, 12 Jan 2021 23:15:14 -0800
Subject: [PATCH 006/217] ndctl/test: Exercise soft_offline_page() corner cases
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>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/161052211455.1804207.13884321454837200896.stgit@dwillia2-desk3.amr.corp.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 a4ef12e..4e09761 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 5f0da29..aad8fa5 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",
--
2.27.0