From nobody Fri Apr 26 20:59:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557846034; cv=none; d=zoho.com; s=zohoarc; b=WbIIyftnJUd4rq4WZFHfabLuhM4L9H3cQk+nMmS5kzzvxyJP5aF9lK9vRFUT/hq4V13G2ZHcxLJojST2vbGniPI4Y2q21rQB/k8BJMOInRvxCSkmj0mjYc4/4BCl88R88zlI+wJm2zHrSVNxmLfwfjO5pN9FmLMhmsD0quyxI9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557846034; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=UJrEqy3Kbv6iTyPQF4RtuHygfmTah/KpOBtjmKkEFEQ=; b=Jn3g08HFAul2B1qmDhnm/5EAElUm1kuCav96NnsYF4HrgQFCTW+0zqvoQnl4iL13xRPZu6TY0vLQJx3b0DL0+mvTS3G7fmY9MJC6xD5XaNqpuxfKl+RZsKlrBdcxLATZ4u67oeNqEVZN4YByYwat2rw22QhquI4xYjvROFfPR40= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557846034370405.1778442206647; Tue, 14 May 2019 08:00:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:49499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQYut-0006Sk-Bd for importer@patchew.org; Tue, 14 May 2019 11:00:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQYrt-0004Oh-R4 for qemu-devel@nongnu.org; Tue, 14 May 2019 10:57:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQYrs-0007gT-FR for qemu-devel@nongnu.org; Tue, 14 May 2019 10:57:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hQYrs-0007fY-7V for qemu-devel@nongnu.org; Tue, 14 May 2019 10:57:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 240BE81E07; Tue, 14 May 2019 14:57:23 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (unknown [10.65.16.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 891195D6A6; Tue, 14 May 2019 14:57:00 +0000 (UTC) From: Pankaj Gupta To: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-acpi@vger.kernel.org, qemu-devel@nongnu.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org Date: Tue, 14 May 2019 20:24:18 +0530 Message-Id: <20190514145422.16923-4-pagupta@redhat.com> In-Reply-To: <20190514145422.16923-1-pagupta@redhat.com> References: <20190514145422.16923-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 14 May 2019 14:57:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 3/7] libnvdimm: add dax_dev sync flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pagupta@redhat.com, jack@suse.cz, mst@redhat.com, jasowang@redhat.com, david@fromorbit.com, lcapitulino@redhat.com, adilger.kernel@dilger.ca, zwisler@kernel.org, aarcange@redhat.com, dave.jiang@intel.com, jstaron@google.com, darrick.wong@oracle.com, vishal.l.verma@intel.com, david@redhat.com, willy@infradead.org, hch@infradead.org, jmoyer@redhat.com, nilal@redhat.com, lenb@kernel.org, kilobyte@angband.pl, riel@surriel.com, yuval.shaia@oracle.com, stefanha@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, kwolf@redhat.com, tytso@mit.edu, xiaoguangrong.eric@gmail.com, cohuck@redhat.com, rjw@rjwysocki.net, imammedo@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds 'DAXDEV_SYNC' flag which is set for nd_region doing synchronous flush. This later is used to disable MAP_SYNC functionality for ext4 & xfs filesystem for devices don't support synchronous flush. Signed-off-by: Pankaj Gupta --- drivers/dax/bus.c | 2 +- drivers/dax/super.c | 19 ++++++++++++++++++- drivers/md/dm.c | 3 ++- drivers/nvdimm/pmem.c | 5 ++++- drivers/nvdimm/region_devs.c | 7 +++++++ include/linux/dax.h | 9 +++++++-- include/linux/libnvdimm.h | 1 + 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 2109cfe80219..5f184e751c82 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -388,7 +388,7 @@ struct dev_dax *__devm_create_dev_dax(struct dax_region= *dax_region, int id, * No 'host' or dax_operations since there is no access to this * device outside of mmap of the resulting character device. */ - dax_dev =3D alloc_dax(dev_dax, NULL, NULL); + dax_dev =3D alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC); if (!dax_dev) goto err; =20 diff --git a/drivers/dax/super.c b/drivers/dax/super.c index bbd57ca0634a..93b3718b5cfa 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -186,6 +186,8 @@ enum dax_device_flags { DAXDEV_ALIVE, /* gate whether dax_flush() calls the low level flush routine */ DAXDEV_WRITE_CACHE, + /* flag to check if device supports synchronous flush */ + DAXDEV_SYNC, }; =20 /** @@ -354,6 +356,18 @@ bool dax_write_cache_enabled(struct dax_device *dax_de= v) } EXPORT_SYMBOL_GPL(dax_write_cache_enabled); =20 +bool dax_synchronous(struct dax_device *dax_dev) +{ + return test_bit(DAXDEV_SYNC, &dax_dev->flags); +} +EXPORT_SYMBOL_GPL(dax_synchronous); + +void set_dax_synchronous(struct dax_device *dax_dev) +{ + set_bit(DAXDEV_SYNC, &dax_dev->flags); +} +EXPORT_SYMBOL_GPL(set_dax_synchronous); + bool dax_alive(struct dax_device *dax_dev) { lockdep_assert_held(&dax_srcu); @@ -508,7 +522,7 @@ static void dax_add_host(struct dax_device *dax_dev, co= nst char *host) } =20 struct dax_device *alloc_dax(void *private, const char *__host, - const struct dax_operations *ops) + const struct dax_operations *ops, unsigned long flags) { struct dax_device *dax_dev; const char *host; @@ -531,6 +545,9 @@ struct dax_device *alloc_dax(void *private, const char = *__host, dax_add_host(dax_dev, host); dax_dev->ops =3D ops; dax_dev->private =3D private; + if (flags & DAXDEV_F_SYNC) + set_dax_synchronous(dax_dev); + return dax_dev; =20 err_dev: diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 043f0761e4a0..ee007b75d9fd 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1969,7 +1969,8 @@ static struct mapped_device *alloc_dev(int minor) sprintf(md->disk->disk_name, "dm-%d", minor); =20 if (IS_ENABLED(CONFIG_DAX_DRIVER)) { - dax_dev =3D alloc_dax(md, md->disk->disk_name, &dm_dax_ops); + dax_dev =3D alloc_dax(md, md->disk->disk_name, &dm_dax_ops, + DAXDEV_F_SYNC); if (!dax_dev) goto bad; } diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 0279eb1da3ef..bdbd2b414d3d 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -365,6 +365,7 @@ static int pmem_attach_disk(struct device *dev, struct gendisk *disk; void *addr; int rc; + unsigned long flags =3D 0UL; =20 pmem =3D devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL); if (!pmem) @@ -462,7 +463,9 @@ static int pmem_attach_disk(struct device *dev, nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_res); disk->bb =3D &pmem->bb; =20 - dax_dev =3D alloc_dax(pmem, disk->disk_name, &pmem_dax_ops); + if (is_nvdimm_sync(nd_region)) + flags =3D DAXDEV_F_SYNC; + dax_dev =3D alloc_dax(pmem, disk->disk_name, &pmem_dax_ops, flags); if (!dax_dev) { put_disk(disk); return -ENOMEM; diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index b4ef7d9ff22e..f3ea5369d20a 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -1197,6 +1197,13 @@ int nvdimm_has_cache(struct nd_region *nd_region) } EXPORT_SYMBOL_GPL(nvdimm_has_cache); =20 +bool is_nvdimm_sync(struct nd_region *nd_region) +{ + return is_nd_pmem(&nd_region->dev) && + !test_bit(ND_REGION_ASYNC, &nd_region->flags); +} +EXPORT_SYMBOL_GPL(is_nvdimm_sync); + struct conflict_context { struct nd_region *nd_region; resource_size_t start, size; diff --git a/include/linux/dax.h b/include/linux/dax.h index 0dd316a74a29..2b106752b1b8 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -7,6 +7,9 @@ #include #include =20 +/* Flag for synchronous flush */ +#define DAXDEV_F_SYNC (1UL << 0) + typedef unsigned long dax_entry_t; =20 struct iomap_ops; @@ -32,18 +35,20 @@ extern struct attribute_group dax_attribute_group; #if IS_ENABLED(CONFIG_DAX) struct dax_device *dax_get_by_host(const char *host); struct dax_device *alloc_dax(void *private, const char *host, - const struct dax_operations *ops); + const struct dax_operations *ops, unsigned long flags); void put_dax(struct dax_device *dax_dev); void kill_dax(struct dax_device *dax_dev); void dax_write_cache(struct dax_device *dax_dev, bool wc); bool dax_write_cache_enabled(struct dax_device *dax_dev); +bool dax_synchronous(struct dax_device *dax_dev); +void set_dax_synchronous(struct dax_device *dax_dev); #else static inline struct dax_device *dax_get_by_host(const char *host) { return NULL; } static inline struct dax_device *alloc_dax(void *private, const char *host, - const struct dax_operations *ops) + const struct dax_operations *ops, unsigned long flags) { /* * Callers should check IS_ENABLED(CONFIG_DAX) to know if this diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index feb342d026f2..3238a206e563 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -264,6 +264,7 @@ void nvdimm_flush(struct nd_region *nd_region); int nvdimm_has_flush(struct nd_region *nd_region); int nvdimm_has_cache(struct nd_region *nd_region); int nvdimm_in_overwrite(struct nvdimm *nvdimm); +bool is_nvdimm_sync(struct nd_region *nd_region); =20 static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void= *buf, unsigned int buf_len, int *cmd_rc) --=20 2.20.1