From: Pavel Begunkov <asml.silence@gmail.com>
To: Jens Axboe <axboe@kernel.dk>, Keith Busch <kbusch@kernel.org>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org,
io-uring@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Cc: asml.silence@gmail.com,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Nitesh Shetty" <nj.shetty@samsung.com>,
"Kanchan Joshi" <joshi.k@samsung.com>,
"Anuj Gupta" <anuj20.g@samsung.com>,
"Tushar Gohad" <tushar.gohad@intel.com>,
"William Power" <william.power@intel.com>,
"Phil Cayton" <phil.cayton@intel.com>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Damien Le Moal" <dlemoal@kernel.org>,
"Alasdair Kergon" <agk@redhat.com>,
"Mike Snitzer" <snitzer@kernel.org>,
"Mikulas Patocka" <mpatocka@redhat.com>,
"Benjamin Marzinski" <bmarzins@redhat.com>,
"Vishal Verma" <vishal.l.verma@intel.com>,
"David Sterba" <dsterba@suse.com>,
"Ilya Dryomov" <idryomov@gmail.com>,
dm-devel@lists.linux.dev, nvdimm@lists.linux.dev,
linux-btrfs@vger.kernel.org, ceph-devel@vger.kernel.org
Subject: [PATCH v5 06/16] block: introduce bio_iov_iter_set()
Date: Sat, 1 Aug 2026 16:46:18 +0100 [thread overview]
Message-ID: <4686a0e47fc14f3f888967a80d45a6f66044f1e0.1785596451.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1785596451.git.asml.silence@gmail.com>
In preparation to supporting dma-buf backed iterators and bios,
introduce bio_iov_iter_set() which attempts to set up the bio directly
from the given iterator. For now, it only supports bvec and expects
users to check the result and fall back to other means if fails, but
later we'll add more types.
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
block/bio.c | 13 ++++++++-----
block/blk-map.c | 2 +-
block/fops.c | 16 +++++++---------
include/linux/bio.h | 2 +-
4 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index 00f99d03ac91..898b2f5ef8c8 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1181,8 +1181,11 @@ void __bio_release_pages(struct bio *bio, bool mark_dirty)
}
EXPORT_SYMBOL_GPL(__bio_release_pages);
-void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter)
+bool bio_iov_iter_set(struct bio *bio, const struct iov_iter *iter)
{
+ if (!iov_iter_is_bvec(iter))
+ return false;
+
WARN_ON_ONCE(bio->bi_max_vecs);
bio->bi_io_vec = (struct bio_vec *)iter->bvec;
@@ -1190,6 +1193,7 @@ void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter)
bio->bi_iter.bi_offset = iter->iov_offset;
bio->bi_iter.bi_size = iov_iter_count(iter);
bio_set_flag(bio, BIO_CLONED);
+ return true;
}
/*
@@ -1284,10 +1288,9 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
if (WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)))
return -EIO;
- if (iov_iter_is_bvec(iter)) {
- bio_iov_bvec_set(bio, iter);
-
- if (!bio_iov_bvec_aligned(bio, mem_align_mask))
+ if (bio_iov_iter_set(bio, iter)) {
+ if (iov_iter_is_bvec(iter) &&
+ !bio_iov_bvec_aligned(bio, mem_align_mask))
return -EINVAL;
iov_iter_advance(iter, bio->bi_iter.bi_size);
diff --git a/block/blk-map.c b/block/blk-map.c
index 615d29bb840e..9cb9605d1f62 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -473,7 +473,7 @@ static int blk_rq_map_user_bvec(struct request *rq, const struct iov_iter *iter)
bio = blk_rq_map_bio_alloc(rq, 0, GFP_KERNEL);
if (!bio)
return -ENOMEM;
- bio_iov_bvec_set(bio, iter);
+ bio_iov_iter_set(bio, iter);
ret = blk_rq_append_bio(rq, bio);
if (ret)
diff --git a/block/fops.c b/block/fops.c
index 3c2099dfef1d..d11923053afe 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -342,15 +342,13 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
bio->bi_end_io = blkdev_bio_end_io_async;
bio->bi_ioprio = iocb->ki_ioprio;
- if (iov_iter_is_bvec(iter)) {
- /*
- * Users don't rely on the iterator being in any particular
- * state for async I/O returning -EIOCBQUEUED, hence we can
- * avoid expensive iov_iter_advance(). Bypass
- * bio_iov_iter_get_pages() and set the bvec directly.
- */
- bio_iov_bvec_set(bio, iter);
- } else {
+ /*
+ * Users don't rely on the iterator being in any particular
+ * state for async I/O returning -EIOCBQUEUED, hence we can
+ * avoid expensive iov_iter_advance(). Bypass
+ * bio_iov_iter_get_pages() and set the bvec directly.
+ */
+ if (!bio_iov_iter_set(bio, iter)) {
ret = blkdev_iov_iter_get_pages(bio, iter, bdev);
if (unlikely(ret))
goto out_bio_put;
diff --git a/include/linux/bio.h b/include/linux/bio.h
index f9b8903c6a87..0d27e0c72905 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -522,7 +522,7 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
unsigned mem_align_mask, unsigned len_align_mask);
-void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter);
+bool bio_iov_iter_set(struct bio *bio, const struct iov_iter *iter);
void __bio_release_pages(struct bio *bio, bool mark_dirty);
extern void bio_set_pages_dirty(struct bio *bio);
extern void bio_check_pages_dirty(struct bio *bio);
--
2.54.0
next prev parent reply other threads:[~2026-08-01 15:49 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-01 15:46 [PATCH v5 00/16] Add dmabuf read/write via io_uring Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 01/16] dma-buf: introduce initial file I/O infrastructure Pavel Begunkov
2026-08-04 16:24 ` Christoph Hellwig
2026-08-08 7:42 ` Sidong Yang
2026-09-21 13:44 ` Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 02/16] iov_iter: add iterator type for dmabuf maps Pavel Begunkov
2026-08-03 13:20 ` Anuj gupta
2026-08-04 8:39 ` Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 03/16] block: rename bi_bvec_done Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 04/16] block: always adjust bi_offset on bio_advance_iter Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 05/16] block: move bvec init into __bio_clone Pavel Begunkov
2026-08-01 15:46 ` Pavel Begunkov [this message]
2026-08-04 16:20 ` [PATCH v5 06/16] block: introduce bio_iov_iter_set() Christoph Hellwig
2026-08-01 15:46 ` [PATCH v5 07/16] block: introduce dma map backed bio type Pavel Begunkov
2026-08-04 16:24 ` Christoph Hellwig
2026-08-04 17:19 ` Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 08/16] block: add dma-buf support for raw bdev Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 09/16] nvme-pci: implement dma-buf backed requests Pavel Begunkov
2026-08-04 7:29 ` Anuj Gupta/Anuj Gupta
2026-08-04 8:41 ` Pavel Begunkov
2026-08-04 16:26 ` Christoph Hellwig
2026-08-01 15:46 ` [PATCH v5 10/16] nvme-pci: rename nvme_pci_sgl_set_data to nvme_pci_dma_iter_set_sgl Pavel Begunkov
2026-08-04 16:26 ` Christoph Hellwig
2026-08-01 15:46 ` [PATCH v5 11/16] nvme-pci: add SGL support for the dmabuf path Pavel Begunkov
2026-08-04 16:27 ` Christoph Hellwig
2026-08-01 15:46 ` [PATCH v5 12/16] io_uring/rsrc: introduce buf registration structure Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 13/16] io_uring/rsrc: extend buffer update Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 14/16] io_uring/rsrc: add uncloneable regbuf flag Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 15/16] io_uring/rsrc: add regbuf import flags Pavel Begunkov
2026-08-01 15:46 ` [PATCH v5 16/16] io_uring/rsrc: add dmabuf backed registered buffers Pavel Begunkov
2026-08-16 0:01 ` (subset) [PATCH v5 00/16] Add dmabuf read/write via io_uring Jens Axboe
2026-09-10 20:55 ` Jens Axboe
2026-09-10 20:58 ` Jens Axboe
2026-09-12 12:57 ` Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4686a0e47fc14f3f888967a80d45a6f66044f1e0.1785596451.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=agk@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=anuj20.g@samsung.com \
--cc=axboe@kernel.dk \
--cc=bmarzins@redhat.com \
--cc=brauner@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=christian.koenig@amd.com \
--cc=dlemoal@kernel.org \
--cc=dm-devel@lists.linux.dev \
--cc=dri-devel@lists.freedesktop.org \
--cc=dsterba@suse.com \
--cc=hch@lst.de \
--cc=idryomov@gmail.com \
--cc=io-uring@vger.kernel.org \
--cc=jgg@nvidia.com \
--cc=joshi.k@samsung.com \
--cc=kbusch@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=mpatocka@redhat.com \
--cc=nj.shetty@samsung.com \
--cc=nvdimm@lists.linux.dev \
--cc=phil.cayton@intel.com \
--cc=sagi@grimberg.me \
--cc=snitzer@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tushar.gohad@intel.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vishal.l.verma@intel.com \
--cc=william.power@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®