dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pavel Begunkov" <asml.silence@gmail.com>
Cc: media-ci@linuxtv.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 01/13] dma-buf: introduce initial file I/O infrastructure
Date: Mon, 28 Sep 2026 13:46:29 +0000	[thread overview]
Message-ID: <20260928134630.2CF781F000FF@smtp.kernel.org> (raw)
In-Reply-To: <c33046bbadce5a2f14aa1874270ec2d10def58ef.1790602223.git.asml.silence@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] dma-buf: map leak and deadlock on invalid min_seg_shift
- [Medium] dma-buf: memory leak in dma_buf_io_ctx_create() dev_ops validation
--

commit cebbd64805f3eac146806ef3dc1344fdf0a76c98
Author: Pavel Begunkov <asml.silence@gmail.com>

dma-buf: introduce initial file I/O infrastructure

This patch adds basic building blocks serving as an API between drivers and
upper layer subsystems to natively use dma-buf in the IO paths. It introduces
the dma_buf_io_ctx and dma_buf_io_map structures to handle mapping, unmapping,
and invalidation operations.

> diff --git a/drivers/dma-buf/dma-buf-io.c b/drivers/dma-buf/dma-buf-io.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/dma-buf/dma-buf-io.c
[ ... ]
> +struct dma_buf_io_map *dma_buf_io_create_map(struct dma_buf_io_ctx *ctx)
> +{
[ ... ]
> +	map = ctx->dev_ops->map(ctx);
> +	if (!IS_ERR(map)) {
> +		atomic_inc(&ctx->active_maps);
> +		atomic_inc(&ctx->all_maps);
> +	}
> +	dma_resv_unlock(dmabuf->resv);
> +
> +	if (IS_ERR(map))
> +		return map;
> +	if (WARN_ON_ONCE(!map->min_seg_shift))
> +		return ERR_PTR(-EFAULT);

[Severity: High]
Does this error path leak the map and deadlock the system?

If map->min_seg_shift evaluates to 0 (for example, if an odd-length DMA
segment causes __ffs() to return 0), the WARN_ON_ONCE check will trigger.

Since atomic_inc(&ctx->active_maps) and atomic_inc(&ctx->all_maps) have
already executed for a valid map, returning ERR_PTR(-EFAULT) here skips
dropping the map's percpu_ref count and leaves the atomic counters
permanently elevated. 

Could subsequent cleanup calls to dma_buf_io_wait_active_maps() or
dma_buf_io_wait_maps() then block forever waiting for the counters to reach
zero?

[ ... ]
> +int dma_buf_io_ctx_create(struct file *file,
> +			   struct dma_buf *dmabuf,
> +			   enum dma_data_direction dir,
> +			   struct dma_buf_io_ctx **out_ctx)
> +{
[ ... ]
> +	ret = file->f_op->init_dma_buf_io_ctx(file, ctx);
> +	if (ret) {
> +		kfree(ctx);
> +		dma_buf_put(dmabuf);
> +		return ret;
> +	}
> +
> +	if (WARN_ON_ONCE(!ctx->dev_ops ||
> +			 !ctx->dev_ops->map ||
> +			 !ctx->dev_ops->unmap ||
> +			 !ctx->dev_ops->release))
> +		return -EINVAL;

[Severity: Medium]
Can this early return leak the context and the dma-buf reference?

If the init_dma_buf_io_ctx callback succeeds but fails to populate the
required dev_ops, this path returns -EINVAL immediately.

It appears to skip the kfree(ctx) and dma_buf_put(dmabuf) teardown
operations that are present in the preceding error handling block.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1790602223.git.asml.silence@gmail.com?part=1

  reply	other threads:[~2026-09-28 13:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 13:32 [PATCH v7 00/13] Add dmabuf read/write via io_uring Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 01/13] dma-buf: introduce initial file I/O infrastructure Pavel Begunkov
2026-09-28 13:46   ` sashiko-bot [this message]
2026-09-29 16:12   ` Christophe JAILLET
2026-09-28 13:32 ` [PATCH v7 02/13] iov_iter: add iterator type for dmabuf maps Pavel Begunkov
2026-09-28 13:49   ` sashiko-bot
     [not found]   ` <20261005091008.GA10727@lst.de>
2026-10-05 11:44     ` Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 03/13] block: always adjust bi_offset on bio_advance_iter Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 04/13] block: introduce dma map backed bio type Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 05/13] block: add dma-buf support for raw bdev Pavel Begunkov
2026-09-28 13:46   ` sashiko-bot
     [not found]   ` <20261005091111.GB10727@lst.de>
2026-10-05 11:43     ` Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 06/13] nvme-pci: implement dma-buf backed requests Pavel Begunkov
2026-09-28 14:02   ` sashiko-bot
2026-09-28 14:41     ` Pavel Begunkov
2026-09-29 15:45   ` Christophe JAILLET
2026-09-30 10:09     ` Pavel Begunkov
     [not found]   ` <20261005091554.GD10727@lst.de>
2026-10-05 11:45     ` Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 07/13] nvme-pci: rename nvme_pci_sgl_set_data to nvme_pci_dma_iter_set_sgl Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 08/13] nvme-pci: add SGL support for the dmabuf path Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 09/13] io_uring/rsrc: introduce buf registration structure Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 10/13] io_uring/rsrc: extend buffer update Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 11/13] io_uring/rsrc: add uncloneable regbuf flag Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 12/13] io_uring/rsrc: add regbuf import flags Pavel Begunkov
2026-09-28 13:32 ` [PATCH v7 13/13] io_uring/rsrc: add dmabuf backed registered buffers Pavel Begunkov
2026-09-28 14:03   ` sashiko-bot

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=20260928134630.2CF781F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=asml.silence@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=media-ci@linuxtv.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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