From: Christoph Hellwig <hch@infradead.org>
To: Pavel Begunkov <asml.silence@gmail.com>
Cc: linux-block@vger.kernel.org, io-uring@vger.kernel.org,
"Vishal Verma" <vishal1.verma@intel.com>,
tushar.gohad@intel.com, "Keith Busch" <kbusch@kernel.org>,
"Jens Axboe" <axboe@kernel.dk>, "Christoph Hellwig" <hch@lst.de>,
"Sagi Grimberg" <sagi@grimberg.me>,
"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>,
linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [RFC v2 05/11] block: add infra to handle dmabuf tokens
Date: Thu, 4 Dec 2025 02:56:59 -0800 [thread overview]
Message-ID: <aTFo-7ufbyZnEUzd@infradead.org> (raw)
In-Reply-To: <51cddd97b31d80ec8842a88b9f3c9881419e8a7b.1763725387.git.asml.silence@gmail.com>
On Sun, Nov 23, 2025 at 10:51:25PM +0000, Pavel Begunkov wrote:
> Add blk-mq infrastructure to handle dmabuf tokens. There are two main
Please spell out infrastructure in the subject as well.
> +struct dma_token *blkdev_dma_map(struct file *file,
> + struct dma_token_params *params)
> +{
> + struct request_queue *q = bdev_get_queue(file_bdev(file));
> +
> + if (!(file->f_flags & O_DIRECT))
> + return ERR_PTR(-EINVAL);
Shouldn't the O_DIRECT check be in the caller?
> +++ b/block/blk-mq-dma-token.c
Missing SPDX and Copyright statement.
> @@ -0,0 +1,236 @@
> +#include <linux/blk-mq-dma-token.h>
> +#include <linux/dma-resv.h>
> +
> +struct blk_mq_dma_fence {
> + struct dma_fence base;
> + spinlock_t lock;
> +};
And a high-level comment explaining the fencing logic would be nice
as well.
> + struct blk_mq_dma_map *map = container_of(ref, struct blk_mq_dma_map, refs);
Overly long line.
> +static struct blk_mq_dma_map *blk_mq_alloc_dma_mapping(struct blk_mq_dma_token *token)
Another one. Also kinda inconsistent between _map in the data structure
and _mapping in the function name.
> +static inline
> +struct blk_mq_dma_map *blk_mq_get_token_map(struct blk_mq_dma_token *token)
Really odd return value / scope formatting.
> +{
> + struct blk_mq_dma_map *map;
> +
> + guard(rcu)();
> +
> + map = rcu_dereference(token->map);
> + if (unlikely(!map || !percpu_ref_tryget_live_rcu(&map->refs)))
> + return NULL;
> + return map;
Please use good old rcu_read_unlock to make this readable.
> + guard(mutex)(&token->mapping_lock);
Same.
> +
> + map = blk_mq_get_token_map(token);
> + if (map)
> + return map;
> +
> + map = blk_mq_alloc_dma_mapping(token);
> + if (IS_ERR(map))
> + return NULL;
> +
> + dma_resv_lock(dmabuf->resv, NULL);
> + ret = dma_resv_wait_timeout(dmabuf->resv, DMA_RESV_USAGE_BOOKKEEP,
> + true, MAX_SCHEDULE_TIMEOUT);
> + ret = ret ? ret : -ETIME;
if (!ret)
ret = -ETIME;
> +blk_status_t blk_rq_assign_dma_map(struct request *rq,
> + struct blk_mq_dma_token *token)
> +{
> + struct blk_mq_dma_map *map;
> +
> + map = blk_mq_get_token_map(token);
> + if (map)
> + goto complete;
> +
> + if (rq->cmd_flags & REQ_NOWAIT)
> + return BLK_STS_AGAIN;
> +
> + map = blk_mq_create_dma_map(token);
> + if (IS_ERR(map))
> + return BLK_STS_RESOURCE;
Having a few comments, that say this is creating the map lazily
would probably helper the reader. Also why not keep the !map
case in the branch, as the map case should be the fast path and
thus usually be straight line in the function?
> +void blk_mq_dma_map_move_notify(struct blk_mq_dma_token *token)
> +{
> + blk_mq_dma_map_remove(token);
> +}
Is there a good reason for having this blk_mq_dma_map_move_notify
wrapper?
> + if (bio_flagged(bio, BIO_DMA_TOKEN)) {
> + struct blk_mq_dma_token *token;
> + blk_status_t ret;
> +
> + token = dma_token_to_blk_mq(bio->dma_token);
> + ret = blk_rq_assign_dma_map(rq, token);
> + if (ret) {
> + if (ret == BLK_STS_AGAIN) {
> + bio_wouldblock_error(bio);
> + } else {
> + bio->bi_status = BLK_STS_RESOURCE;
> + bio_endio(bio);
> + }
> + goto queue_exit;
> + }
> + }
Any reason to not just keep the dma_token_to_blk_mq? Also why is this
overriding non-BLK_STS_AGAIN errors with BLK_STS_RESOURCE?
(I really wish we could make all BLK_STS_AGAIN errors be quiet without
the explicit setting of BIO_QUIET, which is a bit annoying, but that's
not for this patch).
> +static inline
> +struct blk_mq_dma_token *dma_token_to_blk_mq(struct dma_token *token)
More odd formatting.
next prev parent reply other threads:[~2025-12-04 10:57 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-23 22:51 [RFC v2 00/11] Add dmabuf read/write via io_uring Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 01/11] file: add callback for pre-mapping dmabuf Pavel Begunkov
2025-12-04 10:42 ` Christoph Hellwig
2025-12-12 1:02 ` Pavel Begunkov
2025-12-04 10:46 ` Christian König
2025-12-04 11:07 ` Christoph Hellwig
2025-12-04 11:09 ` Christian König
2025-12-04 13:10 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 02/11] iov_iter: introduce iter type for pre-registered dma Pavel Begunkov
2025-12-04 10:43 ` Christoph Hellwig
2025-12-12 1:06 ` Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 03/11] block: move around bio flagging helpers Pavel Begunkov
2025-12-04 10:43 ` Christoph Hellwig
2025-12-12 1:08 ` Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 04/11] block: introduce dma token backed bio type Pavel Begunkov
2025-12-04 10:48 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 05/11] block: add infra to handle dmabuf tokens Pavel Begunkov
2025-11-24 13:38 ` Anuj gupta
2025-12-04 10:56 ` Christoph Hellwig [this message]
2025-12-12 1:56 ` Pavel Begunkov
2025-12-04 13:08 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 06/11] nvme-pci: add support for dmabuf reggistration Pavel Begunkov
2025-11-24 13:40 ` Anuj gupta
2025-12-04 11:00 ` Christoph Hellwig
2025-12-04 19:07 ` Keith Busch
2025-11-23 22:51 ` [RFC v2 07/11] nvme-pci: implement dma_token backed requests Pavel Begunkov
2025-12-04 11:04 ` Christoph Hellwig
2025-11-23 22:51 ` [RFC v2 08/11] io_uring/rsrc: add imu flags Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 09/11] io_uring/rsrc: extended reg buffer registration Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 10/11] io_uring/rsrc: add dmabuf-backed buffer registeration Pavel Begunkov
2025-11-23 22:51 ` [RFC v2 11/11] io_uring/rsrc: implement dmabuf regbuf import Pavel Begunkov
2025-11-24 10:33 ` [RFC v2 00/11] Add dmabuf read/write via io_uring Christian König
2025-11-24 11:30 ` Pavel Begunkov
2025-11-24 14:17 ` Christian König
2025-11-25 13:52 ` Pavel Begunkov
2025-11-25 14:21 ` Christian König
2025-11-25 19:40 ` Pavel Begunkov
2025-11-24 13:35 ` Anuj gupta
2025-11-25 12:35 ` 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=aTFo-7ufbyZnEUzd@infradead.org \
--to=hch@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@lst.de \
--cc=io-uring@vger.kernel.org \
--cc=kbusch@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-block@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=sagi@grimberg.me \
--cc=sumit.semwal@linaro.org \
--cc=tushar.gohad@intel.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vishal1.verma@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;
as well as URLs for NNTP newsgroup(s).