From patchwork Thu Jun 7 04:18:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10451131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5E38C60375 for ; Thu, 7 Jun 2018 04:28:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D12729D07 for ; Thu, 7 Jun 2018 04:28:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A37F29D9B; Thu, 7 Jun 2018 04:28:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 78DBD29D07 for ; Thu, 7 Jun 2018 04:28:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 41A5421194870; Wed, 6 Jun 2018 21:28:36 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7F69D2119486B for ; Wed, 6 Jun 2018 21:28:34 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2018 21:28:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="61085513" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004.fm.intel.com with ESMTP; 06 Jun 2018 21:28:34 -0700 Subject: [ndctl PATCH] test: Add device-dax MADV_HWPOISON test From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 06 Jun 2018 21:18:37 -0700 Message-ID: <152834511700.12835.4831071398400754767.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Reuse test_dax_poison() for triggering memory_failure() on device-dax huge/gigantic page mappings. Signed-off-by: Dan Williams --- test.h | 4 ++++ test/dax-pmd.c | 34 +++++++++++++++++++++++++--------- test/device-dax.c | 28 +++++++++++++++++++--------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/test.h b/test.h index 5f2d6293c104..ce873f51f7aa 100644 --- a/test.h +++ b/test.h @@ -12,6 +12,8 @@ */ #ifndef __TEST_H__ #define __TEST_H__ +#include + struct ndctl_test; struct ndctl_ctx; struct ndctl_test *ndctl_test_new(unsigned int kver); @@ -36,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_poison(int dax_fd, unsigned long align, void *dax_addr, + off_t offset, bool fsdax); int test_dpa_alloc(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); int test_dsm_fail(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); int test_libndctl(int loglevel, struct ndctl_test *test, struct ndctl_ctx *ctx); diff --git a/test/dax-pmd.c b/test/dax-pmd.c index abff4f9fd199..65110b7c6a4c 100644 --- a/test/dax-pmd.c +++ b/test/dax-pmd.c @@ -27,6 +27,7 @@ #include #include #include +#include #define NUM_EXTENTS 5 #define fail() fprintf(stderr, "%s: failed at: %d (%s)\n", \ @@ -217,8 +218,8 @@ static void sigbus_hdl(int sig, siginfo_t *si, void *ptr) siglongjmp(sj_env, 1); } -static int test_dax_poison(int dax_fd, unsigned long align, void *dax_addr, - off_t offset) +int test_dax_poison(int dax_fd, unsigned long align, void *dax_addr, + off_t offset, bool fsdax) { unsigned char *addr = MAP_FAILED; struct sigaction act; @@ -226,6 +227,13 @@ static int test_dax_poison(int dax_fd, unsigned long align, void *dax_addr, void *buf; int rc; + /* + * MADV_HWPOISON must be page aligned, and this routine assumes + * align is >= 8K + */ + if (align < SZ_2M) + return 0; + if (posix_memalign(&buf, 4096, 4096) != 0) return -ENOMEM; @@ -240,13 +248,15 @@ static int test_dax_poison(int dax_fd, unsigned long align, void *dax_addr, } /* dirty the block on disk to bypass the default zero page */ - rc = pwrite(dax_fd, buf, 4096, offset + align / 2); - if (rc < 4096) { - fail(); - rc = -ENXIO; - goto out; + if (fsdax) { + rc = pwrite(dax_fd, buf, 4096, offset + align / 2); + if (rc < 4096) { + fail(); + rc = -ENXIO; + goto out; + } + fsync(dax_fd); } - fsync(dax_fd); addr = mmap(dax_addr, 2*align, PROT_READ|PROT_WRITE, MAP_SHARED_VALIDATE|MAP_POPULATE|MAP_SYNC, dax_fd, offset); @@ -281,6 +291,11 @@ clear_error: goto out; } + if (!fsdax) { + rc = 0; + goto out; + } + rc = fallocate(dax_fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, offset + align / 2, 4096); if (rc) { @@ -312,6 +327,7 @@ out: static int test_pmd(int fd) { unsigned long long m_align, p_align, pmd_off; + static const bool fsdax = true; struct fiemap_extent *ext; void *base, *pmd_addr; struct fiemap *map; @@ -371,7 +387,7 @@ static int test_pmd(int fd) if (rc) goto err_directio; - rc = test_dax_poison(fd, HPAGE_SIZE, pmd_addr, pmd_off); + rc = test_dax_poison(fd, HPAGE_SIZE, pmd_addr, pmd_off, fsdax); err_directio: err_extent: diff --git a/test/device-dax.c b/test/device-dax.c index 0a42a327c96d..712c247adfb2 100644 --- a/test/device-dax.c +++ b/test/device-dax.c @@ -151,15 +151,6 @@ static int __test_device_dax(unsigned long align, int loglevel, struct daxctl_region *dax_region; char *buf, path[100], data[VERIFY_BUF_SIZE]; - memset (&act, 0, sizeof(act)); - act.sa_sigaction = sigbus; - act.sa_flags = SA_SIGINFO; - - if (sigaction(SIGBUS, &act, 0)) { - perror("sigaction"); - return 1; - } - ndctl_set_log_priority(ctx, loglevel); ndns = ndctl_get_test_dev(ctx); @@ -276,6 +267,7 @@ static int __test_device_dax(unsigned long align, int loglevel, * otherwise not supported. */ if (ndctl_test_attempt(test, KERNEL_VERSION(4, 9, 0))) { + static const bool devdax = false; int fd2; rc = test_dax_directio(fd, align, NULL, 0); @@ -285,6 +277,15 @@ static int __test_device_dax(unsigned long align, int loglevel, goto out; } + fprintf(stderr, "%s: test dax poison\n", + ndctl_namespace_get_devname(ndns)); + rc = test_dax_poison(fd, align, NULL, 0, devdax); + if (rc) { + fprintf(stderr, "%s: failed dax poison\n", + ndctl_namespace_get_devname(ndns)); + goto out; + } + fd2 = open("/proc/self/smaps", O_RDONLY); if (fd2 < 0) { fprintf(stderr, "%s: failed smaps open\n", @@ -312,6 +313,15 @@ static int __test_device_dax(unsigned long align, int loglevel, goto out; } + 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)) { /* got sigbus, success */