* Re: [PATCH v3 13/24] udmabuf: Convert to the SGT mapping type
[not found] ` <20261120-dma_mapping_type_v4-v3-13-c0183a409bdf@nvidia.com>
@ 2026-11-21 5:58 ` sashiko-bot
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-21 5:58 UTC (permalink / raw)
To: Alistair Popple, dri-devel, intel-xe, amd-gfx, linux-rdma,
linux-nvme
Cc: media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] udmabuf: premature publication of ubuf->sg in
begin_cpu_udmabuf()
--
commit f138ffdf3b226fef46f9eda6001d750e3e320cdd
Author: Alistair Popple <apopple@nvidia.com>
udmabuf: Convert to the SGT mapping type
This commit converts udmabuf to the SGT mapping type by having
get_sg_table() and put_sg_table() operate on a caller-allocated struct
sg_table and embedding the DMA-buf mapping table in struct
dma_buf_sgt_mapping.
> diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
> index df6dd00462423..ef77ae063ae4c 100644
> --- a/drivers/dma-buf/udmabuf.c
> +++ b/drivers/dma-buf/udmabuf.c
[ ... ]
> @@ -226,16 +233,19 @@ static int begin_cpu_udmabuf(struct dma_buf *buf,
> struct device *dev = ubuf->device->this_device;
>
> if (!ubuf->sg) {
> - ubuf->sg = get_sg_table(dev, buf, direction);
> - if (IS_ERR(ubuf->sg)) {
> - int ret;
> + int ret;
> +
> + ubuf->sg = kzalloc_obj(*ubuf->sg);
> + if (!ubuf->sg)
> + return -ENOMEM;
>
> - ret = PTR_ERR(ubuf->sg);
> + ret = get_sg_table(dev, buf, ubuf->sg, direction);
> + if (ret) {
> + kfree(ubuf->sg);
> ubuf->sg = NULL;
> return ret;
> - } else {
> - ubuf->sg_dir = direction;
> }
> + ubuf->sg_dir = direction;
> }
>
> dma_sync_sgtable_for_cpu(dev, ubuf->sg, direction);
[Severity: High]
Can assigning ubuf->sg before get_sg_table() finishes expose an
uninitialized, unmapped, or freed sg_table to concurrent
DMA_BUF_IOCTL_SYNC callers?
dma_buf_ioctl() invokes begin_cpu_udmabuf() and end_cpu_udmabuf() without
holding a lock. Previously, get_sg_table() allocated, populated, and
DMA-mapped a local struct sg_table before returning it to be stored in
ubuf->sg. With ubuf->sg assigned immediately after kzalloc_obj(), a
second thread can observe a non-NULL ubuf->sg while the first thread is
still inside get_sg_table() (or after kfree(ubuf->sg) on the error path):
CPU0 CPU1
begin_cpu_udmabuf()
ubuf->sg = kzalloc_obj(...)
get_sg_table(..., ubuf->sg, ...)
sg_alloc_table_from_pages()
begin_cpu_udmabuf()
if (!ubuf->sg) /* false */
dma_sync_sgtable_for_cpu(...,
ubuf->sg,
...)
/* uninitialized or freed sgt */
If two threads both enter the !ubuf->sg block, the second kzalloc_obj()
also overwrites ubuf->sg while the first thread passes ubuf->sg to
get_sg_table(), leaking the first allocation and initializing the same
struct sg_table concurrently.
Allocating into a local struct sg_table *sg and assigning ubuf->sg only
after get_sg_table() succeeds avoids publishing the table prematurely.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-dma_mapping_type_v4-v3-0-c0183a409bdf@nvidia.com?part=13
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 23/24] dma-buf: Add dma_buf_mapping_map() returning a type-tagged mapping and implement it for sgt
[not found] ` <20261120-dma_mapping_type_v4-v3-23-c0183a409bdf@nvidia.com>
@ 2026-11-21 5:58 ` sashiko-bot
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-21 5:58 UTC (permalink / raw)
To: Alistair Popple, dri-devel, intel-xe, amd-gfx, linux-rdma,
linux-nvme
Cc: media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dma-buf: wrong dma_buf_attach_map_type() doc on
dma_buf_mapping_type.unmap
--
commit bd9afecc501b0a6674a8f68fd07c287949304430
Author: Alistair Popple <apopple@nvidia.com>
dma-buf: Add dma_buf_mapping_map() returning a type-tagged mapping and implement it for sgt
This commit adds generic dma_buf_mapping_map() and dma_buf_mapping_unmap()
entry points that select a mapping type and dispatch through its callbacks,
and converts dma_buf_map_sgt() and dma_buf_unmap_sgt() to use them.
> diff --git a/include/linux/dma-buf-mapping.h b/include/linux/dma-buf-mapping.h
> index 0a1c2934a932a..98d5765cfdba9 100644
> --- a/include/linux/dma-buf-mapping.h
> +++ b/include/linux/dma-buf-mapping.h
> @@ -82,6 +82,32 @@ struct dma_buf_mapping_type {
> */
> void (*debugfs_dump)(struct seq_file *s,
> struct dma_buf_attachment *attach);
> +
> + /**
> + * @map:
> + *
> + * Produce a mapping of this type for @attach, for which this type has
> + * already been selected. Called by dma_buf_mapping_map() with the
> + * dma_resv lock held. The result embeds &struct dma_buf_mapping, which
> + * the core fills in once this returns. A map that may unmap its result
> + * on its own unwind must record the entry in it first, since every
> + * unmap reads it. Responsible for pin-on-map of static importers if
> + * the type supports them.
> + */
> + struct dma_buf_mapping *(*map)(struct dma_buf_attachment *attach,
> + enum dma_data_direction dir);
> +
> + /**
> + * @unmap:
> + *
> + * Release a mapping returned by @map. Called by dma_buf_mapping_unmap()
> + * with the dma_resv lock held and with dma_buf_attach_map_type()
> + * naming the entry the mapping was made with, which need not be the
> + * attachment's current selection.
> + */
> + void (*unmap)(struct dma_buf_attachment *attach,
> + struct dma_buf_mapping *mapping,
> + enum dma_data_direction dir);
> };
[Severity: Low]
Should this @unmap comment refer to mapping->match rather than
dma_buf_attach_map_type()?
dma_buf_attach_map_type() returns &attach->matches[attach->selected_idx],
and dma_buf_mapping_unmap() calls match->type->unmap() without changing
attach->selected_idx, so dma_buf_attach_map_type() still returns the
attachment's current selection while mapping->match holds the entry the
mapping was made with.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-dma_mapping_type_v4-v3-0-c0183a409bdf@nvidia.com?part=23
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 24/24] dma-buf: Add kunit tests for mapping type selection
[not found] ` <20261120-dma_mapping_type_v4-v3-24-c0183a409bdf@nvidia.com>
@ 2026-11-21 5:58 ` sashiko-bot
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-21 5:58 UTC (permalink / raw)
To: Alistair Popple, dri-devel, intel-xe, amd-gfx, linux-rdma,
linux-nvme
Cc: media-ci
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] dma-buf: build failure from mapping2->type access in selection
KUnit tests
- [Low] dma-buf: duplicated mock_type_a and mock_type_b callback setup
across tests
- [Low] dma-buf: commit message omits failed map and pin selection KUnit
tests
--
commit fdd7641c86ac3670b97b442d9f583c8418cdf65b
Author: Alistair Popple <apopple@nvidia.com>
> dma-buf: Add kunit tests for mapping type selection
>
> Add an offer list and a select_mapping() callback to the mock exporter
> along with map/unmap for the two mock types.
>
> Adds tests for the exporter/importer contract.
>
> - test_match_set_is_final: a later importer attaching does not change
> an existing attachment's match set or default. Later attachments
> influence what the exporter selects at pin and map time but not
> previous attachments.
>
> - test_select_at_map: the exporter chooses a non-default entry on first
> map and the result is tagged with it. A pin taken while there is a
> live mapping inherits the type and the choice survives unmap/remap.
> Only dma_buf_invalidate_mappings() allows the exporter to make
> a different selection. An -EBUSY from selection leaves nothing
> established.
>
> - test_select_at_pin: pin selects, and the choice survives map, unmap
> and unpin so a pinned importer that is never invalidated keeps its
> first type for the life of the import.
>
> - test_unmap_uses_own_type: after an invalidate the exporter may select
> another type for the next map. A mapping made with the previous one
> is still live, and each mapping must be torn down with the type it
> was made with.
>
> - test_select_survives_own_invalidate: a pin or map whose exporter
> callback invalidates every attachment still ends up selected, and one
> that invalidates and fails does not.
>
> Signed-off-by: Alistair Popple <apopple@nvidia.com>
[Severity: Low]
This isn't a bug, but the commit message lists five of the new test cases
while omitting test_select_survives_failed_map and
test_select_after_failed_pin.
> diff --git a/drivers/dma-buf/st-dma-mapping.c b/drivers/dma-buf/st-dma-mapping.c
> index 8c69ae212455c..42e6748f0ae65 100644
> --- a/drivers/dma-buf/st-dma-mapping.c
> +++ b/drivers/dma-buf/st-dma-mapping.c
[ ... ]
> @@ -374,6 +407,485 @@ static void test_mock_attach(struct kunit *test)
> +static void test_select_at_map(struct kunit *test)
> +{
> + static const struct dma_buf_mapping_match offer_ab[] = {
> + { .type = &mock_type_a },
> + { .type = &mock_type_b },
> + };
> + struct dma_buf_mapping_match imp[] = {
> + { .type = &mock_type_a },
> + { .type = &mock_type_b },
> + };
> + MOCK_IMPORTER_OPS(importer_ops, imp);
> + struct dma_buf_attachment *attach;
> + struct dma_buf_mapping *mapping;
> + struct dma_buf *dmabuf;
> + struct device *dev;
> +
> + mock_type_a.map = mock_type_map;
> + mock_type_a.unmap = mock_type_unmap;
> + mock_type_b.map = mock_type_map;
> + mock_type_b.unmap = mock_type_unmap;
[ ... ]
> + dma_buf_detach(dmabuf, attach);
> + dma_buf_put(dmabuf);
> +
> + mock_type_a.map = NULL;
> + mock_type_a.unmap = NULL;
> + mock_type_b.map = NULL;
> + mock_type_b.unmap = NULL;
> +}
[Severity: Low]
This isn't a bug, but all six selection tests assign and clear .map and
.unmap on mock_type_a and mock_type_b, and an early KUNIT_ASSERT failure
skips the teardown since reset_mock_state() does not reset them. Can
mock_type_a and mock_type_b initialize .map = mock_type_map and .unmap =
mock_type_unmap statically (or manage them in reset_mock_state())?
> @@ -381,6 +893,190 @@ static const struct dma_exporter dma_exporter_params[] = {
> +static void test_unmap_uses_own_type(struct kunit *test)
> +{
[ ... ]
> + /* Invalidated while that mapping is live: the next map reselects */
> + dma_buf_invalidate_mappings(dmabuf);
> + KUNIT_EXPECT_FALSE(test, attach->selected);
> + mock_select_idx = 0;
> + mapping2 = dma_buf_mapping_map(attach, DMA_BIDIRECTIONAL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mapping2);
> + KUNIT_EXPECT_PTR_EQ(test, mapping2->type, &mock_type_a);
[ ... ]
> +static void test_select_survives_own_invalidate(struct kunit *test)
> +{
[ ... ]
> + /* A second map does not reselect. */
> + mock_select_idx = 0;
> + mapping2 = dma_buf_mapping_map(attach, DMA_BIDIRECTIONAL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, mapping2);
> + KUNIT_EXPECT_PTR_EQ(test, mapping2->type, &mock_type_b);
[Severity: High]
Does accessing mapping2->type break the build when CONFIG_DMABUF_KUNIT_TEST
is enabled?
struct dma_buf_mapping only has a match member, not type, so these two
checks in test_unmap_uses_own_type() and
test_select_survives_own_invalidate() should use
dma_buf_mapping_type_of(mapping2).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-dma_mapping_type_v4-v3-0-c0183a409bdf@nvidia.com?part=24
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 5:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261120-dma_mapping_type_v4-v3-0-c0183a409bdf@nvidia.com>
[not found] ` <20261120-dma_mapping_type_v4-v3-13-c0183a409bdf@nvidia.com>
2026-11-21 5:58 ` [PATCH v3 13/24] udmabuf: Convert to the SGT mapping type sashiko-bot
[not found] ` <20261120-dma_mapping_type_v4-v3-23-c0183a409bdf@nvidia.com>
2026-11-21 5:58 ` [PATCH v3 23/24] dma-buf: Add dma_buf_mapping_map() returning a type-tagged mapping and implement it for sgt sashiko-bot
[not found] ` <20261120-dma_mapping_type_v4-v3-24-c0183a409bdf@nvidia.com>
2026-11-21 5:58 ` [PATCH v3 24/24] dma-buf: Add kunit tests for mapping type selection sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox