From: Pavel Begunkov <asml.silence@gmail.com>
To: Nitesh Shetty <nj.shetty@samsung.com>
Cc: linux-block@vger.kernel.org, io-uring@vger.kernel.org,
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>,
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, 22 Jan 2026 11:46:59 +0000 [thread overview]
Message-ID: <d3389449-f344-48ae-ab13-697e01d1cc46@gmail.com> (raw)
In-Reply-To: <20260121073724.dja6wyqyf5apkdcx@green245.gost>
On 1/21/26 07:37, Nitesh Shetty wrote:
> On 23/11/25 10:51PM, Pavel Begunkov wrote:
>> Add blk-mq infrastructure to handle dmabuf tokens. There are two main
>> objects. The first is struct blk_mq_dma_token, which is an extension of
>> struct dma_token and passed in an iterator. The second is struct
>> blk_mq_dma_map, which keeps the actual mapping and unlike the token, can
>> be ejected (e.g. by move_notify) and recreated.
>>
>> The token keeps an rcu protected pointer to the mapping, so when it
>> resolves a token into a mapping to pass it to a request, it'll do an rcu
>> protected lookup and get a percpu reference to the mapping.
>>
>> If there is no current mapping attached to a token, it'll need to be
>> created by calling the driver (e.g. nvme) via a new callback. It
>> requires waiting, thefore can't be done for nowait requests and couldn't
>> happen deeper in the stack, e.g. during nvme request submission.
>>
>> The structure split is needed because move_notify can request to
>> invalidate the dma mapping at any moment, and we need a way to
>> concurrently remove it and wait for the inflight requests using the
>> previous mapping to complete.
>>
>> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
>> ---
>> block/Makefile | 1 +
>> block/bdev.c | 14 ++
>> block/blk-mq-dma-token.c | 236 +++++++++++++++++++++++++++++++
>> block/blk-mq.c | 20 +++
>> block/fops.c | 1 +
>> include/linux/blk-mq-dma-token.h | 60 ++++++++
>> include/linux/blk-mq.h | 21 +++
>> include/linux/blkdev.h | 3 +
>> 8 files changed, 356 insertions(+)
>> create mode 100644 block/blk-mq-dma-token.c
>> create mode 100644 include/linux/blk-mq-dma-token.h
>>
>> diff --git a/block/Makefile b/block/Makefile
>> index c65f4da93702..0190e5aa9f00 100644
...
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index f2650c97a75e..1ff3a7e3191b 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -29,6 +29,7 @@
>> #include <linux/blk-crypto.h>
>> #include <linux/part_stat.h>
>> #include <linux/sched/isolation.h>
>> +#include <linux/blk-mq-dma-token.h>
>>
>> #include <trace/events/block.h>
>>
>> @@ -439,6 +440,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
>> rq->nr_integrity_segments = 0;
>> rq->end_io = NULL;
>> rq->end_io_data = NULL;
>> + rq->dma_map = NULL;
>>
>> blk_crypto_rq_set_defaults(rq);
>> INIT_LIST_HEAD(&rq->queuelist);
>> @@ -794,6 +796,7 @@ static void __blk_mq_free_request(struct request *rq)
>> blk_pm_mark_last_busy(rq);
>> rq->mq_hctx = NULL;
>>
>> + blk_rq_drop_dma_map(rq);
> blk_rq_drop_dma_map(rq), needs to be added in blk_mq_end_request_batch
> as well[1], otherwise I am seeing we leave with increased reference
> count in dma-buf exporter side.
>
> Thanks,
> Nitesh
>
> [1]
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -1214,6 +1214,7 @@ void blk_mq_end_request_batch(struct io_comp_batch *iob)
>
> blk_crypto_free_request(rq);
> blk_pm_mark_last_busy(rq);
> + blk_rq_drop_dma_map(rq);
Ah yes, thanks Nitesh
--
Pavel Begunkov
next prev parent reply other threads:[~2026-01-22 11:47 UTC|newest]
Thread overview: 54+ 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
2026-01-04 1:42 ` Ming Lei
2026-01-06 19:51 ` Pavel Begunkov
2026-01-07 6:18 ` Christoph Hellwig
2026-01-07 15:56 ` Christian König
2026-01-07 16:01 ` Christoph Hellwig
2026-01-08 2:19 ` Ming Lei
2026-01-08 10:17 ` Christoph Hellwig
2026-01-09 2:10 ` Ming Lei
2026-01-09 5:58 ` 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-12-12 20:10 ` Jens Axboe
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
2025-12-12 1:56 ` Pavel Begunkov
2025-12-04 13:08 ` Christoph Hellwig
2026-01-21 7:37 ` Nitesh Shetty
2026-01-22 11:46 ` Pavel Begunkov [this message]
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
2026-01-04 1:46 ` Ming Lei
2026-01-06 19:32 ` 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
2025-12-12 19:37 ` (subset) " Jens Axboe
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=d3389449-f344-48ae-ab13-697e01d1cc46@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--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=nj.shetty@samsung.com \
--cc=sagi@grimberg.me \
--cc=viro@zeniv.linux.org.uk \
/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