From patchwork Fri Nov 10 20:39:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10053729 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 BD15560631 for ; Fri, 10 Nov 2017 20:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A61F32B43C for ; Fri, 10 Nov 2017 20:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9ABBB2B442; Fri, 10 Nov 2017 20:47:27 +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=-1.9 required=2.0 tests=BAYES_00, 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 1068D2B43C for ; Fri, 10 Nov 2017 20:47:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E110E21B00DD4; Fri, 10 Nov 2017 12:43:22 -0800 (PST) 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.88; helo=mga01.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 832372034D83F for ; Fri, 10 Nov 2017 12:43:21 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Nov 2017 12:47:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,376,1505804400"; d="scan'208";a="683654" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by FMSMGA003.fm.intel.com with ESMTP; 10 Nov 2017 12:47:24 -0800 Subject: [ndctl PATCH] ndctl, test: improve dax gup test coverage From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 10 Nov 2017 12:39:09 -0800 Message-ID: <151034634989.27121.6767031057018403016.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 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 Add tests for read-only to read-write conversions of dax mappings and for the gup slow path where the initial fault is a write fault. The gup-slow-path write fault path has been broken for the pud case since it was introduced upstream. Cc: Dave Jiang Signed-off-by: Dan Williams --- test/dax-pmd.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/test/dax-pmd.c b/test/dax-pmd.c index 6276913a0fda..1a296aff32ea 100644 --- a/test/dax-pmd.c +++ b/test/dax-pmd.c @@ -27,8 +27,10 @@ #include #define NUM_EXTENTS 5 -#define fail() fprintf(stderr, "%s: failed at: %d\n", __func__, __LINE__) -#define faili(i) fprintf(stderr, "%s: failed at: %d: %d\n", __func__, __LINE__, i) +#define fail() fprintf(stderr, "%s: failed at: %d (%s)\n", \ + __func__, __LINE__, strerror(errno)) +#define faili(i) fprintf(stderr, "%s: failed at: %d: %d (%s)\n", \ + __func__, __LINE__, i, strerror(errno)) #define TEST_FILE "test_dax_data" int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t offset) @@ -39,7 +41,7 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off if (posix_memalign(&buf, 4096, 4096) != 0) return -ENOMEM; - for (i = 0; i < 3; i++) { + for (i = 0; i < 5; i++) { void *addr = mmap(dax_addr, 2*align, PROT_READ|PROT_WRITE, MAP_SHARED, dax_fd, offset); @@ -62,11 +64,20 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off fprintf(stderr, "%s: test: %d\n", __func__, i); rc = 0; switch (i) { - case 0: /* test O_DIRECT of unfaulted address */ + case 0: /* test O_DIRECT read of unfaulted address */ if (write(fd2, addr, 4096) != 4096) { faili(i); rc = -ENXIO; } + + /* + * test O_DIRECT write of pre-faulted read-only + * address + */ + if (pread(fd2, addr, 4096, 0) != 4096) { + faili(i); + rc = -ENXIO; + } break; case 1: /* test O_DIRECT of pre-faulted address */ sprintf(addr, "odirect data"); @@ -100,6 +111,26 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off } else faili(i); break; + case 3: /* convert ro mapping to rw */ + rc = *(volatile int *) addr; + *(volatile int *) addr = rc; + rc = 0; + break; + case 4: /* test O_DIRECT write of unfaulted address */ + sprintf(buf, "O_DIRECT write of unfaulted address\n"); + if (pwrite(fd2, buf, 4096, 0) < 4096) { + faili(i); + rc = -ENXIO; + break; + } + + if (pread(fd2, addr, 4096, 0) < 4096) { + faili(i); + rc = -ENXIO; + break; + } + rc = 0; + break; default: faili(i); rc = -ENXIO;