From patchwork Wed Apr 4 22:01:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10323453 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 B18E460390 for ; Wed, 4 Apr 2018 22:01:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BD1E29039 for ; Wed, 4 Apr 2018 22:01:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CD9E2903C; Wed, 4 Apr 2018 22:01: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=-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 070B029039 for ; Wed, 4 Apr 2018 22:01:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5BAC9225264A5; Wed, 4 Apr 2018 15:01: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=134.134.136.100; helo=mga07.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 DABC0225264A3 for ; Wed, 4 Apr 2018 15:01:35 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Apr 2018 15:01:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,408,1517904000"; d="scan'208";a="44119752" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by fmsmga001.fm.intel.com with ESMTP; 04 Apr 2018 15:01:34 -0700 Subject: [PATCH] dax: adding fsync/msync support for device DAX From: Dave Jiang To: dan.j.williams@intel.com Date: Wed, 04 Apr 2018 15:01:34 -0700 Message-ID: <152287929452.28903.15383389230749046740.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty 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: , Cc: linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When msync() is called on a device dax region, eventually ops->fsync() is called. By providing fsync in the device dax file operations, we can provide support for both. nvdimm_flush() for the nd_region is called when msync/fsync is called in order to provide deep flush to the user app through standard POSIX calls. Signed-off-by: Dave Jiang --- drivers/dax/dax-private.h | 1 + drivers/dax/device-dax.h | 2 ++ drivers/dax/device.c | 19 +++++++++++++++++++ drivers/dax/pmem.c | 10 ++++++++++ 4 files changed, 32 insertions(+) diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index b6fc4f04636d..5fc20191c89e 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -35,6 +35,7 @@ struct dax_region { unsigned int align; struct resource res; unsigned long pfn_flags; + void (*sync)(struct device *); }; /** diff --git a/drivers/dax/device-dax.h b/drivers/dax/device-dax.h index 688b051750bd..651f2e763058 100644 --- a/drivers/dax/device-dax.h +++ b/drivers/dax/device-dax.h @@ -22,4 +22,6 @@ struct dax_region *alloc_dax_region(struct device *parent, void *addr, unsigned long flags); struct dev_dax *devm_create_dev_dax(struct dax_region *dax_region, int id, struct resource *res, int count); +void dax_set_sync(struct dax_region *dax_region, void (*sync)(struct device *dev)); + #endif /* __DEVICE_DAX_H__ */ diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 37be5a306c8f..5341760cc987 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -523,6 +523,24 @@ static int dax_release(struct inode *inode, struct file *filp) return 0; } +void dax_set_sync(struct dax_region *dax_region, void (*sync)(struct device *)) +{ + dax_region->sync = sync; +} +EXPORT_SYMBOL_GPL(dax_set_sync); + +static int dax_fsync(struct file *filp, loff_t start, loff_t end, int datasync) +{ + struct dev_dax *dev_dax = filp->private_data; + struct dax_region *dax_region = dev_dax->region; + + if (!dax_region->sync) + return -EOPNOTSUPP; + + dax_region->sync(dax_region->dev); + return 0; +} + static const struct file_operations dax_fops = { .llseek = noop_llseek, .owner = THIS_MODULE, @@ -530,6 +548,7 @@ static const struct file_operations dax_fops = { .release = dax_release, .get_unmapped_area = dax_get_unmapped_area, .mmap = dax_mmap, + .fsync = dax_fsync, }; static void dev_dax_release(struct device *dev) diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index fd49b24fd6af..2b47b4dd2671 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -57,6 +57,14 @@ static void dax_pmem_percpu_kill(void *data) percpu_ref_kill(ref); } +static void dax_pmem_sync(struct device *dev) +{ + struct nd_namespace_common *ndns; + + ndns = to_ndns(dev); + nvdimm_flush(to_nd_region(ndns->dev.parent)); +} + static int dax_pmem_probe(struct device *dev) { void *addr; @@ -133,6 +141,8 @@ static int dax_pmem_probe(struct device *dev) if (!dax_region) return -ENOMEM; + dax_set_sync(dax_region, dax_pmem_sync); + /* TODO: support for subdividing a dax region... */ dev_dax = devm_create_dev_dax(dax_region, id, &res, 1);