virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* add bvec initialization helpers v2
@ 2023-02-03 15:06 Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
                   ` (23 more replies)
  0 siblings, 24 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Hi all,

this series adds the helpers to initalize a bvec.  These remove open coding of
bvec internals and help with experimenting with other representations like
a phys_addr_t instead of page + offset.

Changes since v1:
 - fix a typo
 - simplify the code in ceph's __iter_get_bvecs a little bit further
 - fix two subject prefixes

Diffstat:
 block/bio-integrity.c             |    7 ------
 block/bio.c                       |   12 +----------
 drivers/block/rbd.c               |    7 ++----
 drivers/block/virtio_blk.c        |    4 ---
 drivers/block/zram/zram_drv.c     |   15 +++-----------
 drivers/nvme/host/core.c          |    4 ---
 drivers/nvme/target/io-cmd-file.c |   10 +--------
 drivers/nvme/target/tcp.c         |    5 +---
 drivers/scsi/sd.c                 |   36 ++++++++++++++++------------------
 drivers/target/target_core_file.c |   18 +++++------------
 drivers/vhost/vringh.c            |    5 +---
 fs/afs/write.c                    |    8 ++-----
 fs/ceph/file.c                    |   12 +++--------
 fs/cifs/connect.c                 |    5 ++--
 fs/cifs/fscache.c                 |   16 +++++----------
 fs/cifs/misc.c                    |    5 +---
 fs/cifs/smb2ops.c                 |    6 ++---
 fs/coredump.c                     |    7 +-----
 fs/nfs/fscache.c                  |   16 +++++----------
 fs/orangefs/inode.c               |   22 ++++++--------------
 fs/splice.c                       |    5 +---
 include/linux/bvec.h              |   40 ++++++++++++++++++++++++++++++++++++++
 io_uring/rsrc.c                   |    4 ---
 mm/page_io.c                      |    8 +------
 net/ceph/messenger_v1.c           |    7 +-----
 net/ceph/messenger_v2.c           |   28 ++++++++++----------------
 net/rxrpc/rxperf.c                |    8 ++-----
 net/sunrpc/svcsock.c              |    7 +-----
 net/sunrpc/xdr.c                  |    5 +---
 29 files changed, 142 insertions(+), 190 deletions(-)
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 02/23] block: add a bvec_set_folio helper Christoph Hellwig
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, Johannes Thumshirn, linux-fsdevel, Andrew Morton,
	David S. Miller

Add a helper to initialize a bvec based of a page pointer.  This will help
removing various open code bvec initializations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 block/bio-integrity.c |  7 +------
 block/bio.c           | 12 ++----------
 include/linux/bvec.h  | 15 +++++++++++++++
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 3f5685c00e360b..a3776064c52a16 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -124,23 +124,18 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
 			   unsigned int len, unsigned int offset)
 {
 	struct bio_integrity_payload *bip = bio_integrity(bio);
-	struct bio_vec *iv;
 
 	if (bip->bip_vcnt >= bip->bip_max_vcnt) {
 		printk(KERN_ERR "%s: bip_vec full\n", __func__);
 		return 0;
 	}
 
-	iv = bip->bip_vec + bip->bip_vcnt;
-
 	if (bip->bip_vcnt &&
 	    bvec_gap_to_prev(&bdev_get_queue(bio->bi_bdev)->limits,
 			     &bip->bip_vec[bip->bip_vcnt - 1], offset))
 		return 0;
 
-	iv->bv_page = page;
-	iv->bv_len = len;
-	iv->bv_offset = offset;
+	bvec_set_page(&bip->bip_vec[bip->bip_vcnt], page, len, offset);
 	bip->bip_vcnt++;
 
 	return len;
diff --git a/block/bio.c b/block/bio.c
index d7fbc7adfc50aa..71e411a0c12950 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1029,10 +1029,7 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio,
 	if (bio->bi_vcnt >= queue_max_segments(q))
 		return 0;
 
-	bvec = &bio->bi_io_vec[bio->bi_vcnt];
-	bvec->bv_page = page;
-	bvec->bv_len = len;
-	bvec->bv_offset = offset;
+	bvec_set_page(&bio->bi_io_vec[bio->bi_vcnt], page, len, offset);
 	bio->bi_vcnt++;
 	bio->bi_iter.bi_size += len;
 	return len;
@@ -1108,15 +1105,10 @@ EXPORT_SYMBOL_GPL(bio_add_zone_append_page);
 void __bio_add_page(struct bio *bio, struct page *page,
 		unsigned int len, unsigned int off)
 {
-	struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt];
-
 	WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
 	WARN_ON_ONCE(bio_full(bio, len));
 
-	bv->bv_page = page;
-	bv->bv_offset = off;
-	bv->bv_len = len;
-
+	bvec_set_page(&bio->bi_io_vec[bio->bi_vcnt], page, len, off);
 	bio->bi_iter.bi_size += len;
 	bio->bi_vcnt++;
 }
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 35c25dff651a5e..9e3dac51eb26b6 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -35,6 +35,21 @@ struct bio_vec {
 	unsigned int	bv_offset;
 };
 
+/**
+ * bvec_set_page - initialize a bvec based off a struct page
+ * @bv:		bvec to initialize
+ * @page:	page the bvec should point to
+ * @len:	length of the bvec
+ * @offset:	offset into the page
+ */
+static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
+		unsigned int len, unsigned int offset)
+{
+	bv->bv_page = page;
+	bv->bv_len = len;
+	bv->bv_offset = offset;
+}
+
 struct bvec_iter {
 	sector_t		bi_sector;	/* device address in 512 byte
 						   sectors */
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 02/23] block: add a bvec_set_folio helper
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 03/23] block: add a bvec_set_virt helper Christoph Hellwig
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, Johannes Thumshirn, linux-fsdevel, Andrew Morton,
	David S. Miller

A smaller wrapper around bvec_set_page that takes a folio instead.
There are only two potential users for this in the tree, but the number
will grow in the future.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 include/linux/bvec.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 9e3dac51eb26b6..2bae1134499e7f 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -50,6 +50,19 @@ static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
 	bv->bv_offset = offset;
 }
 
+/**
+ * bvec_set_folio - initialize a bvec based off a struct folio
+ * @bv:		bvec to initialize
+ * @folio:	folio the bvec should point to
+ * @len:	length of the bvec
+ * @offset:	offset into the folio
+ */
+static inline void bvec_set_folio(struct bio_vec *bv, struct folio *folio,
+		unsigned int len, unsigned int offset)
+{
+	bvec_set_page(bv, &folio->page, len, offset);
+}
+
 struct bvec_iter {
 	sector_t		bi_sector;	/* device address in 512 byte
 						   sectors */
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 03/23] block: add a bvec_set_virt helper
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 02/23] block: add a bvec_set_folio helper Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 04/23] sd: factor out a sd_set_special_bvec helper Christoph Hellwig
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, Johannes Thumshirn, linux-fsdevel, Andrew Morton,
	David S. Miller

A small wrapper around bvec_set_page for callers that have a virtual
address.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 include/linux/bvec.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 2bae1134499e7f..f2d22931f3030a 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -63,6 +63,18 @@ static inline void bvec_set_folio(struct bio_vec *bv, struct folio *folio,
 	bvec_set_page(bv, &folio->page, len, offset);
 }
 
+/**
+ * bvec_set_virt - initialize a bvec based on a virtual address
+ * @bv:		bvec to initialize
+ * @vaddr:	virtual address to set the bvec to
+ * @len:	length of the bvec
+ */
+static inline void bvec_set_virt(struct bio_vec *bv, void *vaddr,
+		unsigned int len)
+{
+	bvec_set_page(bv, virt_to_page(vaddr), len, offset_in_page(vaddr));
+}
+
 struct bvec_iter {
 	sector_t		bi_sector;	/* device address in 512 byte
 						   sectors */
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 04/23] sd: factor out a sd_set_special_bvec helper
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (2 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 03/23] block: add a bvec_set_virt helper Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 05/23] target: use bvec_set_page to initialize bvecs Christoph Hellwig
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Add a helper for setting up the special_bvec instead of open coding it
in three place, and use the new bvec_set_page helper to initialize
special_vec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/scsi/sd.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 47dafe6b8a66d1..277960decc104b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -831,6 +831,19 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 	blk_queue_max_discard_sectors(q, max_blocks * (logical_block_size >> 9));
 }
 
+static void *sd_set_special_bvec(struct request *rq, unsigned int data_len)
+{
+	struct page *page;
+
+	page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
+	if (!page)
+		return NULL;
+	clear_highpage(page);
+	bvec_set_page(&rq->special_vec, page, data_len, 0);
+	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
+	return bvec_virt(&rq->special_vec);
+}
+
 static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 {
 	struct scsi_device *sdp = cmd->device;
@@ -841,19 +854,14 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 	unsigned int data_len = 24;
 	char *buf;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	buf = sd_set_special_bvec(rq, data_len);
+	if (!buf)
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 10;
 	cmd->cmnd[0] = UNMAP;
 	cmd->cmnd[8] = 24;
 
-	buf = bvec_virt(&rq->special_vec);
 	put_unaligned_be16(6 + 16, &buf[0]);
 	put_unaligned_be16(16, &buf[2]);
 	put_unaligned_be64(lba, &buf[8]);
@@ -876,13 +884,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
 	u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	if (!sd_set_special_bvec(rq, data_len))
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 16;
 	cmd->cmnd[0] = WRITE_SAME_16;
@@ -908,13 +911,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
 	u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	if (!sd_set_special_bvec(rq, data_len))
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 10;
 	cmd->cmnd[0] = WRITE_SAME;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 05/23] target: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (3 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 04/23] sd: factor out a sd_set_special_bvec helper Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 06/23] nvmet: " Christoph Hellwig
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/target/target_core_file.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index fd584111da45c0..ce0e000b74fc39 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -281,10 +281,8 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 
 	for_each_sg(sgl, sg, sgl_nents, i) {
-		aio_cmd->bvecs[i].bv_page = sg_page(sg);
-		aio_cmd->bvecs[i].bv_len = sg->length;
-		aio_cmd->bvecs[i].bv_offset = sg->offset;
-
+		bvec_set_page(&aio_cmd->bvecs[i], sg_page(sg), sg->length,
+			      sg->offset);
 		len += sg->length;
 	}
 
@@ -329,10 +327,7 @@ static int fd_do_rw(struct se_cmd *cmd, struct file *fd,
 	}
 
 	for_each_sg(sgl, sg, sgl_nents, i) {
-		bvec[i].bv_page = sg_page(sg);
-		bvec[i].bv_len = sg->length;
-		bvec[i].bv_offset = sg->offset;
-
+		bvec_set_page(&bvec[i], sg_page(sg), sg->length, sg->offset);
 		len += sg->length;
 	}
 
@@ -465,10 +460,9 @@ fd_execute_write_same(struct se_cmd *cmd)
 		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 
 	for (i = 0; i < nolb; i++) {
-		bvec[i].bv_page = sg_page(&cmd->t_data_sg[0]);
-		bvec[i].bv_len = cmd->t_data_sg[0].length;
-		bvec[i].bv_offset = cmd->t_data_sg[0].offset;
-
+		bvec_set_page(&bvec[i], sg_page(&cmd->t_data_sg[0]),
+			      cmd->t_data_sg[0].length,
+			      cmd->t_data_sg[0].offset);
 		len += se_dev->dev_attrib.block_size;
 	}
 
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 06/23] nvmet: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (4 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 05/23] target: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 07/23] nvme: use bvec_set_virt to initialize special_vec Christoph Hellwig
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, Johannes Thumshirn, linux-fsdevel, Andrew Morton,
	David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/nvme/target/io-cmd-file.c | 10 ++--------
 drivers/nvme/target/tcp.c         |  5 ++---
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 871c4f32f443f5..2d068439b129c5 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -73,13 +73,6 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
 	return ret;
 }
 
-static void nvmet_file_init_bvec(struct bio_vec *bv, struct scatterlist *sg)
-{
-	bv->bv_page = sg_page(sg);
-	bv->bv_offset = sg->offset;
-	bv->bv_len = sg->length;
-}
-
 static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos,
 		unsigned long nr_segs, size_t count, int ki_flags)
 {
@@ -146,7 +139,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
 
 	memset(&req->f.iocb, 0, sizeof(struct kiocb));
 	for_each_sg(req->sg, sg, req->sg_cnt, i) {
-		nvmet_file_init_bvec(&req->f.bvec[bv_cnt], sg);
+		bvec_set_page(&req->f.bvec[bv_cnt], sg_page(sg), sg->length,
+			      sg->offset);
 		len += req->f.bvec[bv_cnt].bv_len;
 		total_len += req->f.bvec[bv_cnt].bv_len;
 		bv_cnt++;
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index cc05c094de221d..c5759eb503d004 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -321,9 +321,8 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd)
 	while (length) {
 		u32 iov_len = min_t(u32, length, sg->length - sg_offset);
 
-		iov->bv_page = sg_page(sg);
-		iov->bv_len = sg->length;
-		iov->bv_offset = sg->offset + sg_offset;
+		bvec_set_page(iov, sg_page(sg), sg->length,
+				sg->offset + sg_offset);
 
 		length -= iov_len;
 		sg = sg_next(sg);
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 07/23] nvme: use bvec_set_virt to initialize special_vec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (5 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 06/23] nvmet: " Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 08/23] rbd: use bvec_set_page to initialize the copy up bvec Christoph Hellwig
                   ` (16 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, Johannes Thumshirn, linux-fsdevel, Andrew Morton,
	David S. Miller

Use the bvec_set_virt helper to initialize the special_vec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/nvme/host/core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 505e16f20e57fa..7ba1accc3c22a4 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -806,9 +806,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req,
 	cmnd->dsm.nr = cpu_to_le32(segments - 1);
 	cmnd->dsm.attributes = cpu_to_le32(NVME_DSMGMT_AD);
 
-	req->special_vec.bv_page = virt_to_page(range);
-	req->special_vec.bv_offset = offset_in_page(range);
-	req->special_vec.bv_len = alloc_size;
+	bvec_set_virt(&req->special_vec, range, alloc_size);
 	req->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	return BLK_STS_OK;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 08/23] rbd: use bvec_set_page to initialize the copy up bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (6 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 07/23] nvme: use bvec_set_virt to initialize special_vec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 09/23] virtio_blk: use bvec_set_virt to initialize special_vec Christoph Hellwig
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize the copy up bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
---
 drivers/block/rbd.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 04453f4a319cb4..1faca7e07a4d52 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -3068,13 +3068,12 @@ static int setup_copyup_bvecs(struct rbd_obj_request *obj_req, u64 obj_overlap)
 
 	for (i = 0; i < obj_req->copyup_bvec_count; i++) {
 		unsigned int len = min(obj_overlap, (u64)PAGE_SIZE);
+		struct page *page = alloc_page(GFP_NOIO);
 
-		obj_req->copyup_bvecs[i].bv_page = alloc_page(GFP_NOIO);
-		if (!obj_req->copyup_bvecs[i].bv_page)
+		if (!page)
 			return -ENOMEM;
 
-		obj_req->copyup_bvecs[i].bv_offset = 0;
-		obj_req->copyup_bvecs[i].bv_len = len;
+		bvec_set_page(&obj_req->copyup_bvecs[i], page, len, 0);
 		obj_overlap -= len;
 	}
 
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 09/23] virtio_blk: use bvec_set_virt to initialize special_vec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (7 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 08/23] rbd: use bvec_set_page to initialize the copy up bvec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 10/23] zram: use bvec_set_page to initialize bvecs Christoph Hellwig
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_virt helper to initialize the special_vec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/block/virtio_blk.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6a77fa91742880..dc6e9b989910b0 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -170,9 +170,7 @@ static int virtblk_setup_discard_write_zeroes_erase(struct request *req, bool un
 
 	WARN_ON_ONCE(n != segments);
 
-	req->special_vec.bv_page = virt_to_page(range);
-	req->special_vec.bv_offset = offset_in_page(range);
-	req->special_vec.bv_len = sizeof(*range) * segments;
+	bvec_set_virt(&req->special_vec, range, sizeof(*range) * segments);
 	req->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	return 0;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 10/23] zram: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (8 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 09/23] virtio_blk: use bvec_set_virt to initialize special_vec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 11/23] afs: use bvec_set_folio to initialize a bvec Christoph Hellwig
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, Johannes Thumshirn, linux-fsdevel, Andrew Morton,
	David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/block/zram/zram_drv.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e290d6d970474e..bd8ae4822dc3ef 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -703,9 +703,7 @@ static ssize_t writeback_store(struct device *dev,
 	for (; nr_pages != 0; index++, nr_pages--) {
 		struct bio_vec bvec;
 
-		bvec.bv_page = page;
-		bvec.bv_len = PAGE_SIZE;
-		bvec.bv_offset = 0;
+		bvec_set_page(&bvec, page, PAGE_SIZE, 0);
 
 		spin_lock(&zram->wb_limit_lock);
 		if (zram->wb_limit_enable && !zram->bd_wb_limit) {
@@ -1380,12 +1378,9 @@ static void zram_free_page(struct zram *zram, size_t index)
 static int zram_bvec_read_from_bdev(struct zram *zram, struct page *page,
 				    u32 index, struct bio *bio, bool partial_io)
 {
-	struct bio_vec bvec = {
-		.bv_page = page,
-		.bv_len = PAGE_SIZE,
-		.bv_offset = 0,
-	};
+	struct bio_vec bvec;
 
+	bvec_set_page(&bvec, page, PAGE_SIZE, 0);
 	return read_from_bdev(zram, &bvec, zram_get_element(zram, index), bio,
 			      partial_io);
 }
@@ -1652,9 +1647,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
 		memcpy_from_bvec(dst + offset, bvec);
 		kunmap_atomic(dst);
 
-		vec.bv_page = page;
-		vec.bv_len = PAGE_SIZE;
-		vec.bv_offset = 0;
+		bvec_set_page(&vec, page, PAGE_SIZE, 0);
 	}
 
 	ret = __zram_bvec_write(zram, &vec, index, bio);
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 11/23] afs: use bvec_set_folio to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (9 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 10/23] zram: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 12/23] ceph: use bvec_set_page " Christoph Hellwig
                   ` (12 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_folio helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: David Howells <dhowells@redhat.com>
---
 fs/afs/write.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/afs/write.c b/fs/afs/write.c
index 19df10d63323d8..2d17891b618e6e 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -992,7 +992,7 @@ int afs_launder_folio(struct folio *folio)
 {
 	struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
 	struct iov_iter iter;
-	struct bio_vec bv[1];
+	struct bio_vec bv;
 	unsigned long priv;
 	unsigned int f, t;
 	int ret = 0;
@@ -1008,10 +1008,8 @@ int afs_launder_folio(struct folio *folio)
 			t = afs_folio_dirty_to(folio, priv);
 		}
 
-		bv[0].bv_page = &folio->page;
-		bv[0].bv_offset = f;
-		bv[0].bv_len = t - f;
-		iov_iter_bvec(&iter, ITER_SOURCE, bv, 1, bv[0].bv_len);
+		bvec_set_folio(&bv, folio, t - f, f);
+		iov_iter_bvec(&iter, ITER_SOURCE, &bv, 1, bv.bv_len);
 
 		trace_afs_folio_dirty(vnode, tracepoint_string("launder"), folio);
 		ret = afs_store_data(vnode, &iter, folio_pos(folio) + f, true);
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 12/23] ceph: use bvec_set_page to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (10 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 11/23] afs: use bvec_set_folio to initialize a bvec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 13/23] cifs: use bvec_set_page to initialize bvecs Christoph Hellwig
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/ceph/file.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 764598e1efd91f..90b2aa7963bf29 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -103,14 +103,10 @@ static ssize_t __iter_get_bvecs(struct iov_iter *iter, size_t maxsize,
 		size += bytes;
 
 		for ( ; bytes; idx++, bvec_idx++) {
-			struct bio_vec bv = {
-				.bv_page = pages[idx],
-				.bv_len = min_t(int, bytes, PAGE_SIZE - start),
-				.bv_offset = start,
-			};
-
-			bvecs[bvec_idx] = bv;
-			bytes -= bv.bv_len;
+			int len = min_t(int, bytes, PAGE_SIZE - start);
+
+			bvec_set_page(&bvecs[bvec_idx], pages[idx], len, start);
+			bytes -= len;
 			start = 0;
 		}
 	}
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 13/23] cifs: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (11 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 12/23] ceph: use bvec_set_page " Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 14/23] coredump: use bvec_set_page to initialize a bvec Christoph Hellwig
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	Paulo Alcantara, samba-technical, Steve French,
	Sergey Senozhatsky, Chuck Lever, Anna Schumaker, linux-fsdevel,
	Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
---
 fs/cifs/connect.c |  5 +++--
 fs/cifs/fscache.c | 16 ++++++----------
 fs/cifs/misc.c    |  5 ++---
 fs/cifs/smb2ops.c |  6 +++---
 4 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index b2a04b4e89a5e7..e6088d96eb04d2 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -759,8 +759,9 @@ cifs_read_page_from_socket(struct TCP_Server_Info *server, struct page *page,
 	unsigned int page_offset, unsigned int to_read)
 {
 	struct msghdr smb_msg = {};
-	struct bio_vec bv = {
-		.bv_page = page, .bv_len = to_read, .bv_offset = page_offset};
+	struct bio_vec bv;
+
+	bvec_set_page(&bv, page, to_read, page_offset);
 	iov_iter_bvec(&smb_msg.msg_iter, ITER_DEST, &bv, 1, to_read);
 	return cifs_readv_from_socket(server, &smb_msg);
 }
diff --git a/fs/cifs/fscache.c b/fs/cifs/fscache.c
index f6f3a6b75601be..0911327ebfdeb4 100644
--- a/fs/cifs/fscache.c
+++ b/fs/cifs/fscache.c
@@ -143,14 +143,12 @@ static int fscache_fallback_read_page(struct inode *inode, struct page *page)
 	struct netfs_cache_resources cres;
 	struct fscache_cookie *cookie = cifs_inode_cookie(inode);
 	struct iov_iter iter;
-	struct bio_vec bvec[1];
+	struct bio_vec bvec;
 	int ret;
 
 	memset(&cres, 0, sizeof(cres));
-	bvec[0].bv_page		= page;
-	bvec[0].bv_offset	= 0;
-	bvec[0].bv_len		= PAGE_SIZE;
-	iov_iter_bvec(&iter, ITER_DEST, bvec, ARRAY_SIZE(bvec), PAGE_SIZE);
+	bvec_set_page(&bvec, page, PAGE_SIZE, 0);
+	iov_iter_bvec(&iter, ITER_DEST, &bvec, 1, PAGE_SIZE);
 
 	ret = fscache_begin_read_operation(&cres, cookie);
 	if (ret < 0)
@@ -171,16 +169,14 @@ static int fscache_fallback_write_page(struct inode *inode, struct page *page,
 	struct netfs_cache_resources cres;
 	struct fscache_cookie *cookie = cifs_inode_cookie(inode);
 	struct iov_iter iter;
-	struct bio_vec bvec[1];
+	struct bio_vec bvec;
 	loff_t start = page_offset(page);
 	size_t len = PAGE_SIZE;
 	int ret;
 
 	memset(&cres, 0, sizeof(cres));
-	bvec[0].bv_page		= page;
-	bvec[0].bv_offset	= 0;
-	bvec[0].bv_len		= PAGE_SIZE;
-	iov_iter_bvec(&iter, ITER_SOURCE, bvec, ARRAY_SIZE(bvec), PAGE_SIZE);
+	bvec_set_page(&bvec, page, PAGE_SIZE, 0);
+	iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, PAGE_SIZE);
 
 	ret = fscache_begin_write_operation(&cres, cookie);
 	if (ret < 0)
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 2a19c7987c5bd8..95cc4d7dd806d7 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -1054,9 +1054,8 @@ setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw)
 
 		for (i = 0; i < cur_npages; i++) {
 			len = rc > PAGE_SIZE ? PAGE_SIZE : rc;
-			bv[npages + i].bv_page = pages[i];
-			bv[npages + i].bv_offset = start;
-			bv[npages + i].bv_len = len - start;
+			bvec_set_page(&bv[npages + i], pages[i], len - start,
+				      start);
 			rc -= len;
 			start = 0;
 		}
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index e6bcd2baf446a9..cb2deac6b2d70e 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -4598,9 +4598,9 @@ init_read_bvec(struct page **pages, unsigned int npages, unsigned int data_size,
 		return -ENOMEM;
 
 	for (i = 0; i < npages; i++) {
-		bvec[i].bv_page = pages[i];
-		bvec[i].bv_offset = (i == 0) ? cur_off : 0;
-		bvec[i].bv_len = min_t(unsigned int, PAGE_SIZE, data_size);
+		bvec_set_page(&bvec[i], pages[i],
+			      min_t(unsigned int, PAGE_SIZE, data_size),
+			      i == 0 ? cur_off : 0);
 		data_size -= bvec[i].bv_len;
 	}
 
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 14/23] coredump: use bvec_set_page to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (12 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 13/23] cifs: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 15/23] nfs: use bvec_set_page to initialize bvecs Christoph Hellwig
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/coredump.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index de78bde2991beb..0a6873a9c4d0cd 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -840,11 +840,7 @@ static int __dump_skip(struct coredump_params *cprm, size_t nr)
 
 static int dump_emit_page(struct coredump_params *cprm, struct page *page)
 {
-	struct bio_vec bvec = {
-		.bv_page	= page,
-		.bv_offset	= 0,
-		.bv_len		= PAGE_SIZE,
-	};
+	struct bio_vec bvec;
 	struct iov_iter iter;
 	struct file *file = cprm->file;
 	loff_t pos;
@@ -860,6 +856,7 @@ static int dump_emit_page(struct coredump_params *cprm, struct page *page)
 	if (dump_interrupted())
 		return 0;
 	pos = file->f_pos;
+	bvec_set_page(&bvec, page, PAGE_SIZE, 0);
 	iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, PAGE_SIZE);
 	n = __kernel_write_iter(cprm->file, &iter, &pos);
 	if (n != PAGE_SIZE)
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 15/23] nfs: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (13 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 14/23] coredump: use bvec_set_page to initialize a bvec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 16/23] orangefs: use bvec_set_{page, folio} " Christoph Hellwig
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/fscache.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index e731c00a9fcbc3..ea5f2976dfaba4 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -245,14 +245,12 @@ static int fscache_fallback_read_page(struct inode *inode, struct page *page)
 	struct netfs_cache_resources cres;
 	struct fscache_cookie *cookie = nfs_i_fscache(inode);
 	struct iov_iter iter;
-	struct bio_vec bvec[1];
+	struct bio_vec bvec;
 	int ret;
 
 	memset(&cres, 0, sizeof(cres));
-	bvec[0].bv_page		= page;
-	bvec[0].bv_offset	= 0;
-	bvec[0].bv_len		= PAGE_SIZE;
-	iov_iter_bvec(&iter, ITER_DEST, bvec, ARRAY_SIZE(bvec), PAGE_SIZE);
+	bvec_set_page(&bvec, page, PAGE_SIZE, 0);
+	iov_iter_bvec(&iter, ITER_DEST, &bvec, 1, PAGE_SIZE);
 
 	ret = fscache_begin_read_operation(&cres, cookie);
 	if (ret < 0)
@@ -273,16 +271,14 @@ static int fscache_fallback_write_page(struct inode *inode, struct page *page,
 	struct netfs_cache_resources cres;
 	struct fscache_cookie *cookie = nfs_i_fscache(inode);
 	struct iov_iter iter;
-	struct bio_vec bvec[1];
+	struct bio_vec bvec;
 	loff_t start = page_offset(page);
 	size_t len = PAGE_SIZE;
 	int ret;
 
 	memset(&cres, 0, sizeof(cres));
-	bvec[0].bv_page		= page;
-	bvec[0].bv_offset	= 0;
-	bvec[0].bv_len		= PAGE_SIZE;
-	iov_iter_bvec(&iter, ITER_SOURCE, bvec, ARRAY_SIZE(bvec), PAGE_SIZE);
+	bvec_set_page(&bvec, page, PAGE_SIZE, 0);
+	iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, PAGE_SIZE);
 
 	ret = fscache_begin_write_operation(&cres, cookie);
 	if (ret < 0)
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 16/23] orangefs: use bvec_set_{page, folio} to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (14 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 15/23] nfs: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 17/23] splice: use bvec_set_page to initialize a bvec Christoph Hellwig
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page and bvec_set_folio helpers to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/orangefs/inode.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c
index 4df56089438664..215f6cb3dc4129 100644
--- a/fs/orangefs/inode.c
+++ b/fs/orangefs/inode.c
@@ -49,10 +49,8 @@ static int orangefs_writepage_locked(struct page *page,
 	/* Should've been handled in orangefs_invalidate_folio. */
 	WARN_ON(off == len || off + wlen > len);
 
-	bv.bv_page = page;
-	bv.bv_len = wlen;
-	bv.bv_offset = off % PAGE_SIZE;
 	WARN_ON(wlen == 0);
+	bvec_set_page(&bv, page, wlen, off % PAGE_SIZE);
 	iov_iter_bvec(&iter, ITER_SOURCE, &bv, 1, wlen);
 
 	ret = wait_for_direct_io(ORANGEFS_IO_WRITE, inode, &off, &iter, wlen,
@@ -102,15 +100,11 @@ static int orangefs_writepages_work(struct orangefs_writepages *ow,
 
 	for (i = 0; i < ow->npages; i++) {
 		set_page_writeback(ow->pages[i]);
-		ow->bv[i].bv_page = ow->pages[i];
-		ow->bv[i].bv_len = min(page_offset(ow->pages[i]) + PAGE_SIZE,
-		    ow->off + ow->len) -
-		    max(ow->off, page_offset(ow->pages[i]));
-		if (i == 0)
-			ow->bv[i].bv_offset = ow->off -
-			    page_offset(ow->pages[i]);
-		else
-			ow->bv[i].bv_offset = 0;
+		bvec_set_page(&ow->bv[i], ow->pages[i],
+			      min(page_offset(ow->pages[i]) + PAGE_SIZE,
+			          ow->off + ow->len) -
+			      max(ow->off, page_offset(ow->pages[i])),
+			      i == 0 ? ow->off - page_offset(ow->pages[i]) : 0);
 	}
 	iov_iter_bvec(&iter, ITER_SOURCE, ow->bv, ow->npages, ow->len);
 
@@ -300,9 +294,7 @@ static int orangefs_read_folio(struct file *file, struct folio *folio)
 		orangefs_launder_folio(folio);
 
 	off = folio_pos(folio);
-	bv.bv_page = &folio->page;
-	bv.bv_len = folio_size(folio);
-	bv.bv_offset = 0;
+	bvec_set_folio(&bv, folio, folio_size(folio), 0);
 	iov_iter_bvec(&iter, ITER_DEST, &bv, 1, folio_size(folio));
 
 	ret = wait_for_direct_io(ORANGEFS_IO_READ, inode, &off, &iter,
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 17/23] splice: use bvec_set_page to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (15 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 16/23] orangefs: use bvec_set_{page, folio} " Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 18/23] io_uring: " Christoph Hellwig
                   ` (6 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/splice.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/splice.c b/fs/splice.c
index 5969b7a1d353a8..87d9b19349de63 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -675,9 +675,8 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
 				goto done;
 			}
 
-			array[n].bv_page = buf->page;
-			array[n].bv_len = this_len;
-			array[n].bv_offset = buf->offset;
+			bvec_set_page(&array[n], buf->page, this_len,
+				      buf->offset);
 			left -= this_len;
 			n++;
 		}
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 18/23] io_uring: use bvec_set_page to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (16 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 17/23] splice: use bvec_set_page to initialize a bvec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 19/23] swap: use bvec_set_page to initialize bvecs Christoph Hellwig
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 io_uring/rsrc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 18de10c68a151b..a59fc02de5983c 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -1237,9 +1237,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
 		size_t vec_len;
 
 		vec_len = min_t(size_t, size, PAGE_SIZE - off);
-		imu->bvec[i].bv_page = pages[i];
-		imu->bvec[i].bv_len = vec_len;
-		imu->bvec[i].bv_offset = off;
+		bvec_set_page(&imu->bvec[i], pages[i], vec_len, off);
 		off = 0;
 		size -= vec_len;
 	}
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 19/23] swap: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (17 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 18/23] io_uring: " Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 20/23] rxrpc: use bvec_set_page to initialize a bvec Christoph Hellwig
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/page_io.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 3a5f921b932e82..233f6e6eb1c508 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -318,9 +318,7 @@ static int swap_writepage_fs(struct page *page, struct writeback_control *wbc)
 		sio->pages = 0;
 		sio->len = 0;
 	}
-	sio->bvec[sio->pages].bv_page = page;
-	sio->bvec[sio->pages].bv_len = thp_size(page);
-	sio->bvec[sio->pages].bv_offset = 0;
+	bvec_set_page(&sio->bvec[sio->pages], page, thp_size(page), 0);
 	sio->len += thp_size(page);
 	sio->pages += 1;
 	if (sio->pages == ARRAY_SIZE(sio->bvec) || !wbc->swap_plug) {
@@ -432,9 +430,7 @@ static void swap_readpage_fs(struct page *page,
 		sio->pages = 0;
 		sio->len = 0;
 	}
-	sio->bvec[sio->pages].bv_page = page;
-	sio->bvec[sio->pages].bv_len = thp_size(page);
-	sio->bvec[sio->pages].bv_offset = 0;
+	bvec_set_page(&sio->bvec[sio->pages], page, thp_size(page), 0);
 	sio->len += thp_size(page);
 	sio->pages += 1;
 	if (sio->pages == ARRAY_SIZE(sio->bvec) || !plug) {
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 20/23] rxrpc: use bvec_set_page to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (18 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 19/23] swap: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 21/23] sunrpc: use bvec_set_page to initialize bvecs Christoph Hellwig
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: David Howells <dhowells@redhat.com>
---
 net/rxrpc/rxperf.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c
index 16dcabb71ebe16..4a2e90015ca72c 100644
--- a/net/rxrpc/rxperf.c
+++ b/net/rxrpc/rxperf.c
@@ -493,7 +493,7 @@ static int rxperf_deliver_request(struct rxperf_call *call)
 static int rxperf_process_call(struct rxperf_call *call)
 {
 	struct msghdr msg = {};
-	struct bio_vec bv[1];
+	struct bio_vec bv;
 	struct kvec iov[1];
 	ssize_t n;
 	size_t reply_len = call->reply_len, len;
@@ -503,10 +503,8 @@ static int rxperf_process_call(struct rxperf_call *call)
 
 	while (reply_len > 0) {
 		len = min_t(size_t, reply_len, PAGE_SIZE);
-		bv[0].bv_page	= ZERO_PAGE(0);
-		bv[0].bv_offset	= 0;
-		bv[0].bv_len	= len;
-		iov_iter_bvec(&msg.msg_iter, WRITE, bv, 1, len);
+		bvec_set_page(&bv, ZERO_PAGE(0), len, 0);
+		iov_iter_bvec(&msg.msg_iter, WRITE, &bv, 1, len);
 		msg.msg_flags = MSG_MORE;
 		n = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg,
 					   len, rxperf_notify_end_reply_tx);
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 21/23] sunrpc: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (19 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 20/23] rxrpc: use bvec_set_page to initialize a bvec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 22/23] vringh: use bvec_set_page to initialize a bvec Christoph Hellwig
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Chuck Lever <chuck.lever@oracle.com>
Acked-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 net/sunrpc/svcsock.c | 7 ++-----
 net/sunrpc/xdr.c     | 5 ++---
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 815baf308236a9..91252adcae4696 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -252,11 +252,8 @@ static ssize_t svc_tcp_read_msg(struct svc_rqst *rqstp, size_t buflen,
 
 	clear_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
 
-	for (i = 0, t = 0; t < buflen; i++, t += PAGE_SIZE) {
-		bvec[i].bv_page = rqstp->rq_pages[i];
-		bvec[i].bv_len = PAGE_SIZE;
-		bvec[i].bv_offset = 0;
-	}
+	for (i = 0, t = 0; t < buflen; i++, t += PAGE_SIZE)
+		bvec_set_page(&bvec[i], rqstp->rq_pages[i], PAGE_SIZE, 0);
 	rqstp->rq_respages = &rqstp->rq_pages[i];
 	rqstp->rq_next_page = rqstp->rq_respages + 1;
 
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index f7767bf224069f..afe7ec02d23229 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -150,9 +150,8 @@ xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp)
 		if (!buf->bvec)
 			return -ENOMEM;
 		for (i = 0; i < n; i++) {
-			buf->bvec[i].bv_page = buf->pages[i];
-			buf->bvec[i].bv_len = PAGE_SIZE;
-			buf->bvec[i].bv_offset = 0;
+			bvec_set_page(&buf->bvec[i], buf->pages[i], PAGE_SIZE,
+				      0);
 		}
 	}
 	return 0;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 22/23] vringh: use bvec_set_page to initialize a bvec
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (20 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 21/23] sunrpc: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 15:06 ` [PATCH 23/23] libceph: use bvec_set_page to initialize bvecs Christoph Hellwig
  2023-02-03 17:18 ` add bvec initialization helpers v2 Jens Axboe
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize a bvec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vhost/vringh.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 33eb941fcf1546..a1e27da544814a 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -1126,9 +1126,8 @@ static int iotlb_translate(const struct vringh *vrh,
 		size = map->size - addr + map->start;
 		pa = map->addr + addr - map->start;
 		pfn = pa >> PAGE_SHIFT;
-		iov[ret].bv_page = pfn_to_page(pfn);
-		iov[ret].bv_len = min(len - s, size);
-		iov[ret].bv_offset = pa & (PAGE_SIZE - 1);
+		bvec_set_page(&iov[ret], pfn_to_page(pfn), min(len - s, size),
+			      pa & (PAGE_SIZE - 1));
 		s += size;
 		addr += size;
 		++ret;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH 23/23] libceph: use bvec_set_page to initialize bvecs
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (21 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 22/23] vringh: use bvec_set_page to initialize a bvec Christoph Hellwig
@ 2023-02-03 15:06 ` Christoph Hellwig
  2023-02-03 17:18 ` add bvec initialization helpers v2 Jens Axboe
  23 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-02-03 15:06 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Use the bvec_set_page helper to initialize bvecs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
---
 net/ceph/messenger_v1.c |  7 ++-----
 net/ceph/messenger_v2.c | 28 +++++++++++-----------------
 2 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/net/ceph/messenger_v1.c b/net/ceph/messenger_v1.c
index d1787d7d33ef9a..d664cb1593a777 100644
--- a/net/ceph/messenger_v1.c
+++ b/net/ceph/messenger_v1.c
@@ -40,15 +40,12 @@ static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len)
 static int ceph_tcp_recvpage(struct socket *sock, struct page *page,
 		     int page_offset, size_t length)
 {
-	struct bio_vec bvec = {
-		.bv_page = page,
-		.bv_offset = page_offset,
-		.bv_len = length
-	};
+	struct bio_vec bvec;
 	struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
 	int r;
 
 	BUG_ON(page_offset + length > PAGE_SIZE);
+	bvec_set_page(&bvec, page, length, page_offset);
 	iov_iter_bvec(&msg.msg_iter, ITER_DEST, &bvec, 1, length);
 	r = sock_recvmsg(sock, &msg, msg.msg_flags);
 	if (r == -EAGAIN)
diff --git a/net/ceph/messenger_v2.c b/net/ceph/messenger_v2.c
index 3009028c4fa28f..301a991dc6a68e 100644
--- a/net/ceph/messenger_v2.c
+++ b/net/ceph/messenger_v2.c
@@ -149,10 +149,10 @@ static int do_try_sendpage(struct socket *sock, struct iov_iter *it)
 
 	while (iov_iter_count(it)) {
 		/* iov_iter_iovec() for ITER_BVEC */
-		bv.bv_page = it->bvec->bv_page;
-		bv.bv_offset = it->bvec->bv_offset + it->iov_offset;
-		bv.bv_len = min(iov_iter_count(it),
-				it->bvec->bv_len - it->iov_offset);
+		bvec_set_page(&bv, it->bvec->bv_page,
+			      min(iov_iter_count(it),
+				  it->bvec->bv_len - it->iov_offset),
+			      it->bvec->bv_offset + it->iov_offset);
 
 		/*
 		 * sendpage cannot properly handle pages with
@@ -286,9 +286,8 @@ static void set_out_bvec_zero(struct ceph_connection *con)
 	WARN_ON(iov_iter_count(&con->v2.out_iter));
 	WARN_ON(!con->v2.out_zero);
 
-	con->v2.out_bvec.bv_page = ceph_zero_page;
-	con->v2.out_bvec.bv_offset = 0;
-	con->v2.out_bvec.bv_len = min(con->v2.out_zero, (int)PAGE_SIZE);
+	bvec_set_page(&con->v2.out_bvec, ceph_zero_page,
+		      min(con->v2.out_zero, (int)PAGE_SIZE), 0);
 	con->v2.out_iter_sendpage = true;
 	iov_iter_bvec(&con->v2.out_iter, ITER_SOURCE, &con->v2.out_bvec, 1,
 		      con->v2.out_bvec.bv_len);
@@ -863,10 +862,7 @@ static void get_bvec_at(struct ceph_msg_data_cursor *cursor,
 
 	/* get a piece of data, cursor isn't advanced */
 	page = ceph_msg_data_next(cursor, &off, &len);
-
-	bv->bv_page = page;
-	bv->bv_offset = off;
-	bv->bv_len = len;
+	bvec_set_page(bv, page, len, off);
 }
 
 static int calc_sg_cnt(void *buf, int buf_len)
@@ -1855,9 +1851,8 @@ static void prepare_read_enc_page(struct ceph_connection *con)
 	     con->v2.in_enc_resid);
 	WARN_ON(!con->v2.in_enc_resid);
 
-	bv.bv_page = con->v2.in_enc_pages[con->v2.in_enc_i];
-	bv.bv_offset = 0;
-	bv.bv_len = min(con->v2.in_enc_resid, (int)PAGE_SIZE);
+	bvec_set_page(&bv, con->v2.in_enc_pages[con->v2.in_enc_i],
+		      min(con->v2.in_enc_resid, (int)PAGE_SIZE), 0);
 
 	set_in_bvec(con, &bv);
 	con->v2.in_enc_i++;
@@ -2998,9 +2993,8 @@ static void queue_enc_page(struct ceph_connection *con)
 	     con->v2.out_enc_resid);
 	WARN_ON(!con->v2.out_enc_resid);
 
-	bv.bv_page = con->v2.out_enc_pages[con->v2.out_enc_i];
-	bv.bv_offset = 0;
-	bv.bv_len = min(con->v2.out_enc_resid, (int)PAGE_SIZE);
+	bvec_set_page(&bv, con->v2.out_enc_pages[con->v2.out_enc_i],
+		      min(con->v2.out_enc_resid, (int)PAGE_SIZE), 0);
 
 	set_out_bvec(con, &bv, false);
 	con->v2.out_enc_i++;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: add bvec initialization helpers v2
  2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
                   ` (22 preceding siblings ...)
  2023-02-03 15:06 ` [PATCH 23/23] libceph: use bvec_set_page to initialize bvecs Christoph Hellwig
@ 2023-02-03 17:18 ` Jens Axboe
  23 siblings, 0 replies; 33+ messages in thread
From: Jens Axboe @ 2023-02-03 17:18 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller


On Fri, 03 Feb 2023 16:06:11 +0100, Christoph Hellwig wrote:
> this series adds the helpers to initalize a bvec.  These remove open coding of
> bvec internals and help with experimenting with other representations like
> a phys_addr_t instead of page + offset.
> 
> Changes since v1:
>  - fix a typo
>  - simplify the code in ceph's __iter_get_bvecs a little bit further
>  - fix two subject prefixes
> 
> [...]

Applied, thanks!

[01/23] block: factor out a bvec_set_page helper
        commit: d58cdfae6a22e5079656c487aad669597a0635c8
[02/23] block: add a bvec_set_folio helper
        commit: 26db5ee158510108c819aa7be6eb8c75accf85d7
[03/23] block: add a bvec_set_virt helper
        commit: 666e6550cb74e3a7206b5699409c9f31e123887e
[04/23] sd: factor out a sd_set_special_bvec helper
        commit: f1e117cbb01a38f764db2f292174b93eab7c2db2
[05/23] target: use bvec_set_page to initialize bvecs
        commit: 3c7ebe952fefb646c56b60f1c3e3388f3b938cc7
[06/23] nvmet: use bvec_set_page to initialize bvecs
        commit: fc41c97a3a7b08131e6998bc7692f95729f9d359
[07/23] nvme: use bvec_set_virt to initialize special_vec
        commit: 4bee16daf13225d6b109bb95d613fd691b04a757
[08/23] rbd: use bvec_set_page to initialize the copy up bvec
        commit: 7df2af0bb4912cf360045d065f88fe4ed2f702ca
[09/23] virtio_blk: use bvec_set_virt to initialize special_vec
        commit: b831f3a1031664ae2443bab63d35c416ed30c91d
[10/23] zram: use bvec_set_page to initialize bvecs
        commit: 13ae4db0c05107814db4e774856aa83e72e8bf04
[11/23] afs: use bvec_set_folio to initialize a bvec
        commit: a8173be1863e57393edb5c158860ec43a1f21ed7
[12/23] ceph: use bvec_set_page to initialize a bvec
        commit: 5c6542b6612f635eaa001c54af22018f1e996418
[13/23] cifs: use bvec_set_page to initialize bvecs
        commit: 220ae4a5c2ba10333b3b01fbf3dea0d759e77a76
[14/23] coredump: use bvec_set_page to initialize a bvec
        commit: cd598003206839ed1354902805b52c3a4f6ead2e
[15/23] nfs: use bvec_set_page to initialize bvecs
        commit: 8bb7cd842c44b299586bfed6aadde8863c48b415
[16/23] orangefs: use bvec_set_{page,folio} to initialize bvecs
        commit: 8ead80b2c5f8c59d6ca18cd7fb582a3ffc7ea5b7
[17/23] splice: use bvec_set_page to initialize a bvec
        commit: 664e40789abaad892737a696102052dae199a029
[18/23] io_uring: use bvec_set_page to initialize a bvec
        commit: cc342a21930f0e3862c5fd0871cd5a65c5b59e27
[19/23] swap: use bvec_set_page to initialize bvecs
        commit: 8976fa6d79d70502181fa16b5e023645c0f44ec4
[20/23] rxrpc: use bvec_set_page to initialize a bvec
        commit: efde918ac66958c568926120841e7692b1e9bd9d
[21/23] sunrpc: use bvec_set_page to initialize bvecs
        commit: 9088151f1bfe670ae9e28b77095f974196bb2343
[22/23] vringh: use bvec_set_page to initialize a bvec
        commit: 58dfe14073846e416d5b3595314a4f37e1a89c50
[23/23] libceph: use bvec_set_page to initialize bvecs
        commit: 1eb9cd15004fa91b6d1911af9fbaff299d8e9e45

Best regards,
-- 
Jens Axboe



_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-30 17:09   ` Bart Van Assche
  2023-01-30 19:24     ` Bart Van Assche
@ 2023-01-31 13:45     ` Christoph Hellwig
  1 sibling, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-01-31 13:45 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	Christoph Hellwig, io-uring, Mike Marshall, linux-cifs,
	Sagi Grimberg, linux-scsi, Sergey Senozhatsky, linux-afs,
	Jakub Kicinski, Ilya Dryomov, Paolo Abeni, devel, linux-block,
	Keith Busch, ceph-devel, Xiubo Li, Trond Myklebust, Jens Axboe,
	linux-nfs, Martin K. Petersen, netdev, samba-technical,
	Steve French, Minchan Kim, Chuck Lever, Anna Schumaker,
	linux-fsdevel, Andrew Morton, David S. Miller

On Mon, Jan 30, 2023 at 09:09:23AM -0800, Bart Van Assche wrote:
> Has it been considered to use structure assignment instead of introducing 
> bvec_set_page(), e.g. as follows?
>
> bip->bip_vec[bip->bip_vcnt] = (struct bio_vec) {
>       .bv_page = page, .bv_len = len, .bv_offset = offset };

Unless it's hidden behind a macro it doesn't solve the problem of
abstraction away the layout.  I'm also find it less readable.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-31  5:00     ` Matthew Wilcox
@ 2023-01-31  5:28       ` Matthew Wilcox
  0 siblings, 0 replies; 33+ messages in thread
From: Matthew Wilcox @ 2023-01-31  5:28 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	Christoph Hellwig, io-uring, Mike Marshall, linux-cifs,
	Sagi Grimberg, linux-scsi, Sergey Senozhatsky, linux-afs,
	Ilya Dryomov, Paolo Abeni, devel, linux-block, Keith Busch,
	ceph-devel, Xiubo Li, Trond Myklebust, Jens Axboe, linux-nfs,
	Martin K. Petersen, netdev, samba-technical, Steve French,
	Minchan Kim, Chuck Lever, Anna Schumaker, linux-fsdevel,
	Andrew Morton, David S. Miller

On Tue, Jan 31, 2023 at 05:00:32AM +0000, Matthew Wilcox wrote:
> On Mon, Jan 30, 2023 at 08:47:58PM -0800, Jakub Kicinski wrote:
> > kinda random thought but since we're touching this area - could we
> > perhaps move the definition of struct bio_vec and trivial helpers 
> > like this into a new header? bvec.h pulls in mm.h which is a right
> > behemoth :S
> 
> I bet we can drop mm.h now.  It was originally added for nth_page()
> in 3d75ca0adef4 but those were all removed by b8753433fc61.
> 
> A quick smoke test on my default testing config doesn't find any
> problems.  Let me send a patch and see if the build bots complain.

Disappointingly, it doesn't really change anything.  1134 files
depend on mm.h both before and after [1].  Looks like it's due to
arch/x86/include/asm/cacheflush.h pulling in linux/mm.h, judging by the
contents of .build_test_kernel-x86_64/net/ipv6/.inet6_hashtables.o.cmd.
But *lots* of header files pull in mm.h, including scatterlist.h,
vt_kern.h, net.h, nfs_fs.h, sunrpc/svc.h and security.h.

I suppose it may cut down on include loops to drop it here, so I'm
still in favour of the patch I posted, but this illustrates how
deeply entangled our headers still are.

[1] find .build_test_kernel-x86_64/ -name '.*.cmd' |xargs grep 'include/linux/mm.h' |wc -l
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
       [not found]   ` <20230130204758.38f4c6b9@kernel.org>
@ 2023-01-31  5:00     ` Matthew Wilcox
  2023-01-31  5:28       ` Matthew Wilcox
  0 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox @ 2023-01-31  5:00 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	Christoph Hellwig, io-uring, Mike Marshall, linux-cifs,
	Sagi Grimberg, linux-scsi, Sergey Senozhatsky, linux-afs,
	Ilya Dryomov, Paolo Abeni, devel, linux-block, Keith Busch,
	ceph-devel, Xiubo Li, Trond Myklebust, Jens Axboe, linux-nfs,
	Martin K. Petersen, netdev, samba-technical, Steve French,
	Minchan Kim, Chuck Lever, Anna Schumaker, linux-fsdevel,
	Andrew Morton, David S. Miller

On Mon, Jan 30, 2023 at 08:47:58PM -0800, Jakub Kicinski wrote:
> kinda random thought but since we're touching this area - could we
> perhaps move the definition of struct bio_vec and trivial helpers 
> like this into a new header? bvec.h pulls in mm.h which is a right
> behemoth :S

I bet we can drop mm.h now.  It was originally added for nth_page()
in 3d75ca0adef4 but those were all removed by b8753433fc61.

A quick smoke test on my default testing config doesn't find any
problems.  Let me send a patch and see if the build bots complain.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-30 17:09   ` Bart Van Assche
@ 2023-01-30 19:24     ` Bart Van Assche
  2023-01-31 13:45     ` Christoph Hellwig
  1 sibling, 0 replies; 33+ messages in thread
From: Bart Van Assche @ 2023-01-30 19:24 UTC (permalink / raw)
  To: Christoph Hellwig, Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

On 1/30/23 09:09, Bart Van Assche wrote:
> On 1/30/23 01:21, Christoph Hellwig wrote:
>> Add a helper to initialize a bvec based of a page pointer.  This will 
>> help
>> removing various open code bvec initializations.
> 
> Why do you want to remove the open-coded bvec initializations? What is 
> wrong with open-coding bvec initialization? This patch series modifies a 
> lot of code but does not improve code readability. Anyone who encounters 
> code that uses the new function bvec_set_page() has to look up the 
> definition of that function to figure out what it does.

Please ignore the above question - I just noticed that this question has 
been answered in the cover letter.

Bart.

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-30  9:21 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
@ 2023-01-30 17:09   ` Bart Van Assche
  2023-01-30 19:24     ` Bart Van Assche
  2023-01-31 13:45     ` Christoph Hellwig
       [not found]   ` <20230130204758.38f4c6b9@kernel.org>
  1 sibling, 2 replies; 33+ messages in thread
From: Bart Van Assche @ 2023-01-30 17:09 UTC (permalink / raw)
  To: Christoph Hellwig, Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

On 1/30/23 01:21, Christoph Hellwig wrote:
> Add a helper to initialize a bvec based of a page pointer.  This will help
> removing various open code bvec initializations.

Why do you want to remove the open-coded bvec initializations? What is 
wrong with open-coding bvec initialization? This patch series modifies a 
lot of code but does not improve code readability. Anyone who encounters 
code that uses the new function bvec_set_page() has to look up the 
definition of that function to figure out what it does.

> -	iv = bip->bip_vec + bip->bip_vcnt;
> -
>   	if (bip->bip_vcnt &&
>   	    bvec_gap_to_prev(&bdev_get_queue(bio->bi_bdev)->limits,
>   			     &bip->bip_vec[bip->bip_vcnt - 1], offset))
>   		return 0;
>   
> -	iv->bv_page = page;
> -	iv->bv_len = len;
> -	iv->bv_offset = offset;
> +	bvec_set_page(&bip->bip_vec[bip->bip_vcnt], page, len, offset);
>   	bip->bip_vcnt++;

Has it been considered to use structure assignment instead of 
introducing bvec_set_page(), e.g. as follows?

bip->bip_vec[bip->bip_vcnt] = (struct bio_vec) {
       .bv_page = page, .bv_len = len, .bv_offset = offset };

Thanks,

Bart.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-30 10:33 ` David Howells
@ 2023-01-30 10:36   ` Christoph Hellwig
  0 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-01-30 10:36 UTC (permalink / raw)
  To: David Howells
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization, linux-mm,
	Eric Dumazet, target-devel, Marc Dionne, Christoph Hellwig,
	io-uring, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Sergey Senozhatsky, linux-afs, Jakub Kicinski, Ilya Dryomov,
	Paolo Abeni, devel, linux-block, Keith Busch, ceph-devel,
	Xiubo Li, Trond Myklebust, Jens Axboe, linux-nfs,
	Martin K. Petersen, netdev, samba-technical, Steve French,
	Minchan Kim, Chuck Lever, Anna Schumaker, linux-fsdevel,
	Andrew Morton, David S. Miller

On Mon, Jan 30, 2023 at 10:33:36AM +0000, David Howells wrote:
> Christoph Hellwig <hch@lst.de> wrote:
> 
> > +static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
> > +		unsigned int len, unsigned int offset)
> 
> Could you swap len and offset around?  It reads better offset first.  You move
> offset into the page and then do something with len bytes.

This matches bio_add_page and the order inside bio_vec itself.  willy
wanted to switch it around for bio_add_folio but Jens didn't like it,
so I'll stick to the current convention in this area as well.
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-30  9:21 add bvec initialization helpers Christoph Hellwig
  2023-01-30  9:21 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
@ 2023-01-30 10:33 ` David Howells
  2023-01-30 10:36   ` Christoph Hellwig
  1 sibling, 1 reply; 33+ messages in thread
From: David Howells @ 2023-01-30 10:33 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization, dhowells,
	linux-mm, Eric Dumazet, target-devel, Marc Dionne, linux-afs,
	Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Sergey Senozhatsky, io-uring, Jakub Kicinski, Ilya Dryomov,
	Paolo Abeni, devel, linux-block, Keith Busch, ceph-devel,
	Xiubo Li, Trond Myklebust, Jens Axboe, linux-nfs,
	Martin K. Petersen, netdev, samba-technical, Steve French,
	Minchan Kim, Chuck Lever, Anna Schumaker, linux-fsdevel,
	Andrew Morton, David S. Miller

Christoph Hellwig <hch@lst.de> wrote:

> +static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
> +		unsigned int len, unsigned int offset)

Could you swap len and offset around?  It reads better offset first.  You move
offset into the page and then do something with len bytes.

David

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH 01/23] block: factor out a bvec_set_page helper
  2023-01-30  9:21 add bvec initialization helpers Christoph Hellwig
@ 2023-01-30  9:21 ` Christoph Hellwig
  2023-01-30 17:09   ` Bart Van Assche
       [not found]   ` <20230130204758.38f4c6b9@kernel.org>
  2023-01-30 10:33 ` David Howells
  1 sibling, 2 replies; 33+ messages in thread
From: Christoph Hellwig @ 2023-01-30  9:21 UTC (permalink / raw)
  To: Jens Axboe
  Cc: kvm, Michael S. Tsirkin, linux-nvme, virtualization,
	David Howells, linux-mm, Eric Dumazet, target-devel, Marc Dionne,
	linux-afs, Mike Marshall, linux-cifs, Sagi Grimberg, linux-scsi,
	Minchan Kim, io-uring, Jakub Kicinski, Ilya Dryomov, Paolo Abeni,
	devel, linux-block, Keith Busch, ceph-devel, Xiubo Li,
	Trond Myklebust, linux-nfs, Martin K. Petersen, netdev,
	samba-technical, Steve French, Sergey Senozhatsky, Chuck Lever,
	Anna Schumaker, linux-fsdevel, Andrew Morton, David S. Miller

Add a helper to initialize a bvec based of a page pointer.  This will help
removing various open code bvec initializations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/bio-integrity.c |  7 +------
 block/bio.c           | 12 ++----------
 include/linux/bvec.h  | 15 +++++++++++++++
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 3f5685c00e360b..a3776064c52a16 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -124,23 +124,18 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
 			   unsigned int len, unsigned int offset)
 {
 	struct bio_integrity_payload *bip = bio_integrity(bio);
-	struct bio_vec *iv;
 
 	if (bip->bip_vcnt >= bip->bip_max_vcnt) {
 		printk(KERN_ERR "%s: bip_vec full\n", __func__);
 		return 0;
 	}
 
-	iv = bip->bip_vec + bip->bip_vcnt;
-
 	if (bip->bip_vcnt &&
 	    bvec_gap_to_prev(&bdev_get_queue(bio->bi_bdev)->limits,
 			     &bip->bip_vec[bip->bip_vcnt - 1], offset))
 		return 0;
 
-	iv->bv_page = page;
-	iv->bv_len = len;
-	iv->bv_offset = offset;
+	bvec_set_page(&bip->bip_vec[bip->bip_vcnt], page, len, offset);
 	bip->bip_vcnt++;
 
 	return len;
diff --git a/block/bio.c b/block/bio.c
index d7fbc7adfc50aa..71e411a0c12950 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1029,10 +1029,7 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio,
 	if (bio->bi_vcnt >= queue_max_segments(q))
 		return 0;
 
-	bvec = &bio->bi_io_vec[bio->bi_vcnt];
-	bvec->bv_page = page;
-	bvec->bv_len = len;
-	bvec->bv_offset = offset;
+	bvec_set_page(&bio->bi_io_vec[bio->bi_vcnt], page, len, offset);
 	bio->bi_vcnt++;
 	bio->bi_iter.bi_size += len;
 	return len;
@@ -1108,15 +1105,10 @@ EXPORT_SYMBOL_GPL(bio_add_zone_append_page);
 void __bio_add_page(struct bio *bio, struct page *page,
 		unsigned int len, unsigned int off)
 {
-	struct bio_vec *bv = &bio->bi_io_vec[bio->bi_vcnt];
-
 	WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
 	WARN_ON_ONCE(bio_full(bio, len));
 
-	bv->bv_page = page;
-	bv->bv_offset = off;
-	bv->bv_len = len;
-
+	bvec_set_page(&bio->bi_io_vec[bio->bi_vcnt], page, len, off);
 	bio->bi_iter.bi_size += len;
 	bio->bi_vcnt++;
 }
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 35c25dff651a5e..9e3dac51eb26b6 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -35,6 +35,21 @@ struct bio_vec {
 	unsigned int	bv_offset;
 };
 
+/**
+ * bvec_set_page - initialize a bvec based off a struct page
+ * @bv:		bvec to initialize
+ * @page:	page the bvec should point to
+ * @len:	length of the bvec
+ * @offset:	offset into the page
+ */
+static inline void bvec_set_page(struct bio_vec *bv, struct page *page,
+		unsigned int len, unsigned int offset)
+{
+	bv->bv_page = page;
+	bv->bv_len = len;
+	bv->bv_offset = offset;
+}
+
 struct bvec_iter {
 	sector_t		bi_sector;	/* device address in 512 byte
 						   sectors */
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2023-02-03 17:18 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
2023-02-03 15:06 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
2023-02-03 15:06 ` [PATCH 02/23] block: add a bvec_set_folio helper Christoph Hellwig
2023-02-03 15:06 ` [PATCH 03/23] block: add a bvec_set_virt helper Christoph Hellwig
2023-02-03 15:06 ` [PATCH 04/23] sd: factor out a sd_set_special_bvec helper Christoph Hellwig
2023-02-03 15:06 ` [PATCH 05/23] target: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06 ` [PATCH 06/23] nvmet: " Christoph Hellwig
2023-02-03 15:06 ` [PATCH 07/23] nvme: use bvec_set_virt to initialize special_vec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 08/23] rbd: use bvec_set_page to initialize the copy up bvec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 09/23] virtio_blk: use bvec_set_virt to initialize special_vec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 10/23] zram: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06 ` [PATCH 11/23] afs: use bvec_set_folio to initialize a bvec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 12/23] ceph: use bvec_set_page " Christoph Hellwig
2023-02-03 15:06 ` [PATCH 13/23] cifs: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06 ` [PATCH 14/23] coredump: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 15/23] nfs: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06 ` [PATCH 16/23] orangefs: use bvec_set_{page, folio} " Christoph Hellwig
2023-02-03 15:06 ` [PATCH 17/23] splice: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 18/23] io_uring: " Christoph Hellwig
2023-02-03 15:06 ` [PATCH 19/23] swap: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06 ` [PATCH 20/23] rxrpc: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 21/23] sunrpc: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06 ` [PATCH 22/23] vringh: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06 ` [PATCH 23/23] libceph: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 17:18 ` add bvec initialization helpers v2 Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2023-01-30  9:21 add bvec initialization helpers Christoph Hellwig
2023-01-30  9:21 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
2023-01-30 17:09   ` Bart Van Assche
2023-01-30 19:24     ` Bart Van Assche
2023-01-31 13:45     ` Christoph Hellwig
     [not found]   ` <20230130204758.38f4c6b9@kernel.org>
2023-01-31  5:00     ` Matthew Wilcox
2023-01-31  5:28       ` Matthew Wilcox
2023-01-30 10:33 ` David Howells
2023-01-30 10:36   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).