dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregory Williams" <gregory.williams@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver
Date: Wed, 18 Nov 2026 23:45:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-222210@kernel.org> (raw)
In-Reply-To: <20261118233211.4121361-13-gregory.williams@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] accel/amd-ai-engine: memory leak and lifetime bug in
  aie_part_create()
- [Low] accel/amd-ai-engine: dead code, unused exports, and missing
  accel integration
--

commit 9d0271621aaf2e78655cf01aa521aa41dffc506a
Author: Gregory Williams <gregory.williams@amd.com>

accel/amd-ai-engine: Add AMD AI Engine device driver

This commit adds the initial AMD Versal AI Engine platform driver under
drivers/accel/amd-ai-engine, including device probing, column resource
tracking, and partition request and release APIs.

> diff --git a/drivers/accel/amd-ai-engine/Kconfig b/drivers/accel/amd-ai-engine/Kconfig
> new file mode 100644
> index 0000000000000..7f32928cb20f2
> --- /dev/null
> +++ b/drivers/accel/amd-ai-engine/Kconfig
> @@ -0,0 +1,15 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config DRM_ACCEL_AMDAIE
> +	tristate "AMD Versal AI Engine"
> +	depends on ARM64 || COMPILE_TEST
> +	depends on ZYNQMP_FIRMWARE
> +	depends on DRM_ACCEL
> +	help
> +	  This option enables support for the AMD AI engine driver.
> +	  One AMD AI engine device can have multiple partitions (groups of
> +	  AI engine tiles). AMD AI engine device driver instance manages
> +	  AI engine partitions. Applications access its partitions through
> +	  AI engine partition device instance.
> +
> +	  If unsure, say N.

[Severity: Low]
Why is this driver placed under drivers/accel/ with a dependency on
DRM_ACCEL when it does not register a drm_device with DRIVER_COMPUTE_ACCEL
or expose any userspace interface across the series?

Also, aie_partition_request() and aie_partition_release() in
ai-engine-dev.c are exported with EXPORT_SYMBOL_GPL() without any in-tree
callers in the series, and aie_resource_check_region() in ai-engine-res.c
is never called.

> diff --git a/drivers/accel/amd-ai-engine/ai-engine-part.c b/drivers/accel/amd-ai-engine/ai-engine-part.c
> new file mode 100644
> index 0000000000000..f80a6fa433aa1
> --- /dev/null
> +++ b/drivers/accel/amd-ai-engine/ai-engine-part.c

[ ... ]

> @@ -0,0 +1,77 @@

[ ... ]

> +void aie_part_release(struct aie_partition *apart)
> +{
> +	struct aie_device *adev = apart->adev;
> +
> +	list_del(&apart->node);
> +	aie_resource_put_region(&adev->cols_res,
> +				apart->range.start.col -
> +				adev->range.start.col,
> +				apart->range.size.col);
> +	device_unregister(&apart->dev);
> +}
> +
> +static void aie_part_release_device(struct device *dev)
> +{
> +	(void)dev;
> +}
> +
> +/**
> + * aie_part_create() - create AI engine partition instance
> + * @adev: AI engine device
> + * @start_col: start column of AI engine partition
> + * @num_col: number of columns of AI engine partition
> + *
> + * Return: created AI engine partition pointer for success, and PTR_ERR
> + *	   for failure.
> + */
> +struct aie_partition *aie_part_create(struct aie_device *adev,
> +				      u8 start_col, u8 num_col)
> +{
> +	struct aie_partition *apart;
> +	struct device *dev;
> +
> +	apart = devm_kzalloc(adev->dev, sizeof(*apart), GFP_KERNEL);
> +	if (!apart)
> +		return ERR_PTR(-ENOMEM);
> +
> +	apart->adev = adev;
> +	mutex_init(&apart->mlock);
> +	apart->range.start.col = start_col;
> +	apart->range.size.col = num_col;
> +	apart->range.start.row = adev->range.start.row;
> +	apart->range.size.row = adev->range.size.row;
> +
> +	/* create partition device */
> +	dev = &apart->dev;
> +	dev->parent = apart->adev->dev;
> +	dev_set_name(dev, "aiepart_%u_%u", apart->range.start.col,
> +		     apart->range.size.col);
> +	dev_set_drvdata(dev, apart);
> +	dev->release = aie_part_release_device;
> +
> +	if (device_register(&apart->dev)) {
> +		dev_err(adev->dev, "failed to register partition device\n");
> +		put_device(dev);
> +		return ERR_PTR(-ENODEV);
> +	}
> +
> +	return apart;
> +}

[Severity: High]
Does allocating apart with devm_kzalloc(adev->dev, ...) and using a no-op
dev->release callback leak struct aie_partition across runtime partition
request and release cycles?

Every call to aie_partition_release() (as well as the device_register()
error path in aie_part_create()) drops the reference on apart->dev without
freeing apart, leaving it allocated on adev->dev's devres list until the
parent driver unbinds.  In addition, tying a structure that embeds a
reference-counted struct device to parent devres frees apart on parent
unbind even if external references to apart->dev are still held, causing a
use-after-free when the last reference is dropped.

Allocating apart with kzalloc() and freeing it with kfree() in
aie_part_release_device() would tie its lifetime to apart->dev;
aie_partition_release() in ai-engine-dev.c would then also need to save
apart->adev in a local variable before calling aie_part_release(apart) so
that mutex_unlock(&adev->mlock) does not dereference apart after
device_unregister(&apart->dev) frees it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=12

  reply	other threads:[~2026-11-18 23:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
2026-11-18 23:45   ` sashiko-bot
2026-11-19 10:59   ` Krzysztof Kozlowski
2026-11-18 23:32 ` [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver Gregory Williams
2026-11-18 23:45   ` sashiko-bot [this message]
2026-11-18 23:32 ` [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls Gregory Williams
2026-11-18 23:46   ` sashiko-bot
2026-11-18 23:32 ` [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks Gregory Williams
2026-11-18 23:45   ` sashiko-bot
2026-11-18 23:32 ` [PATCH 15/15] accel/amd-ai-engine: Add reset operations Gregory Williams
2026-11-18 23:51   ` sashiko-bot
2026-11-19  8:19 ` [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Jerome Brunet

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=sashiko-outbox-222210@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregory.williams@amd.com \
    --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