[PATCH v3 24/24] dma-buf: Add kunit tests for mapping type selection

sashiko-bot at kernel.org sashiko-bot at kernel.org
Fri Nov 20 21:58:48 PST 2026


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 at 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 at 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



More information about the Linux-nvme mailing list