From nobody Tue Feb 10 05:17:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531468478583787.4032105116805; Fri, 13 Jul 2018 00:54:38 -0700 (PDT) Received: from localhost ([::1]:35718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdsuK-0000nx-TC for importer@patchew.org; Fri, 13 Jul 2018 03:54:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdssl-0008QL-99 for qemu-devel@nongnu.org; Fri, 13 Jul 2018 03:52:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdssk-0003tu-6I for qemu-devel@nongnu.org; Fri, 13 Jul 2018 03:52:51 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45338 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fdssk-0003sG-0S for qemu-devel@nongnu.org; Fri, 13 Jul 2018 03:52:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3882014B3AE; Fri, 13 Jul 2018 07:52:49 +0000 (UTC) Received: from dhcp201-121.englab.pnq.redhat.com (dhcp193-70.pnq.redhat.com [10.65.193.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1B2B2026D6B; Fri, 13 Jul 2018 07:52:43 +0000 (UTC) From: Pankaj Gupta To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, qemu-devel@nongnu.org, linux-nvdimm@ml01.01.org Date: Fri, 13 Jul 2018 13:22:30 +0530 Message-Id: <20180713075232.9575-2-pagupta@redhat.com> In-Reply-To: <20180713075232.9575-1-pagupta@redhat.com> References: <20180713075232.9575-1-pagupta@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 13 Jul 2018 07:52:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 13 Jul 2018 07:52:49 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pagupta@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC v3 1/2] libnvdimm: Add flush callback for virtio pmem 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: kwolf@redhat.com, haozhong.zhang@intel.com, jack@suse.cz, xiaoguangrong.eric@gmail.com, riel@surriel.com, pagupta@redhat.com, niteshnarayanlal@hotmail.com, david@redhat.com, ross.zwisler@intel.com, lcapitulino@redhat.com, hch@infradead.org, mst@redhat.com, stefanha@redhat.com, imammedo@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com, nilal@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds functionality to perform flush from guest to host over VIRTIO. We are registering a callback based on 'nd_region' type. As virtio_pmem driver requires this special flush interface, for rest of the region types we are registering existing flush function. Also report the error returned by virtio flush interface. Signed-off-by: Pankaj Gupta --- drivers/nvdimm/nd.h | 1 + drivers/nvdimm/pmem.c | 4 ++-- drivers/nvdimm/region_devs.c | 24 ++++++++++++++++++------ include/linux/libnvdimm.h | 5 ++++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 32e0364..1b62f79 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -159,6 +159,7 @@ struct nd_region { struct badblocks bb; struct nd_interleave_set *nd_set; struct nd_percpu_lane __percpu *lane; + int (*flush)(struct device *dev); struct nd_mapping mapping[0]; }; =20 diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 9d71492..29fd2cd 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -180,7 +180,7 @@ static blk_qc_t pmem_make_request(struct request_queue = *q, struct bio *bio) struct nd_region *nd_region =3D to_region(pmem); =20 if (bio->bi_opf & REQ_FLUSH) - nvdimm_flush(nd_region); + bio->bi_status =3D nvdimm_flush(nd_region); =20 do_acct =3D nd_iostat_start(bio, &start); bio_for_each_segment(bvec, bio, iter) { @@ -196,7 +196,7 @@ static blk_qc_t pmem_make_request(struct request_queue = *q, struct bio *bio) nd_iostat_end(bio, start); =20 if (bio->bi_opf & REQ_FUA) - nvdimm_flush(nd_region); + bio->bi_status =3D nvdimm_flush(nd_region); =20 bio_endio(bio); return BLK_QC_T_NONE; diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index a612be6..124aae7 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -1025,6 +1025,7 @@ static struct nd_region *nd_region_create(struct nvdi= mm_bus *nvdimm_bus, dev->of_node =3D ndr_desc->of_node; nd_region->ndr_size =3D resource_size(ndr_desc->res); nd_region->ndr_start =3D ndr_desc->res->start; + nd_region->flush =3D ndr_desc->flush; nd_device_register(dev); =20 return nd_region; @@ -1065,13 +1066,10 @@ struct nd_region *nvdimm_volatile_region_create(str= uct nvdimm_bus *nvdimm_bus, } EXPORT_SYMBOL_GPL(nvdimm_volatile_region_create); =20 -/** - * nvdimm_flush - flush any posted write queues between the cpu and pmem m= edia - * @nd_region: blk or interleaved pmem region - */ -void nvdimm_flush(struct nd_region *nd_region) +void pmem_flush(struct device *dev) { - struct nd_region_data *ndrd =3D dev_get_drvdata(&nd_region->dev); + struct nd_region_data *ndrd =3D dev_get_drvdata(dev); + struct nd_region *nd_region =3D to_nd_region(dev); int i, idx; =20 /* @@ -1094,6 +1092,20 @@ void nvdimm_flush(struct nd_region *nd_region) writeq(1, ndrd_get_flush_wpq(ndrd, i, idx)); wmb(); } + +/** + * nvdimm_flush - flush any posted write queues between the cpu and pmem m= edia + * @nd_region: blk or interleaved pmem region + */ +int nvdimm_flush(struct nd_region *nd_region) +{ + if (nd_region->flush) + return(nd_region->flush(&nd_region->dev)); + + pmem_flush(&nd_region->dev); + + return 0; +} EXPORT_SYMBOL_GPL(nvdimm_flush); =20 /** diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index 097072c..33b617f 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -126,6 +126,7 @@ struct nd_region_desc { int numa_node; unsigned long flags; struct device_node *of_node; + int (*flush)(struct device *dev); }; =20 struct device; @@ -201,7 +202,9 @@ unsigned long nd_blk_memremap_flags(struct nd_blk_regio= n *ndbr); unsigned int nd_region_acquire_lane(struct nd_region *nd_region); void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane= ); u64 nd_fletcher64(void *addr, size_t len, bool le); -void nvdimm_flush(struct nd_region *nd_region); +int nvdimm_flush(struct nd_region *nd_region); +void pmem_set_flush(struct nd_region *nd_region, void (*flush) + (struct device *)); int nvdimm_has_flush(struct nd_region *nd_region); int nvdimm_has_cache(struct nd_region *nd_region); =20 --=20 2.9.3