All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karunika Choo" <karunika.choo@arm.com>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 14/28] drm/panthor: Add AM_PARTITION_CONTROL support
Date: Tue, 10 Nov 2026 16:10:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-207343@kernel.org> (raw)
In-Reply-To: <20261110153907.3241978-15-karunika.choo@arm.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] drm/panthor: TOCTOU race from multiple AM_PART_STATE reads in
  window helpers
- [Medium] drm/panthor: panthor_partition_control_term() fails on
  in-progress state transitions
- [Low] drm/panthor: unused devm allocations in partition_control_init()
  on -ENODEV
- [Low] drm/panthor: unchecked devm_kasprintf() in
  partition_control_init()
--

commit 9f7b5a10199859069acf5b5904f5b9aca326fc89
Author: Karunika Choo <karunika.choo@arm.com>

drm/panthor: Add AM_PARTITION_CONTROL support

This commit adds the Panthor arbitration platform driver and partition
control support to manage access windows on Mali v15 AM GPUs.

Link: https://lore.kernel.org/all/20260922205802.1AC3E1F000FF@smtp.kernel.org/

> diff --git a/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c b/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c
> new file mode 100644
> index 0000000000000..330d0bf5fd375
> --- /dev/null
> +++ b/drivers/gpu/drm/panthor/arbitration/panthor_partition_control.c

[ ... ]

> +static u32 partition_state_get(struct panthor_partition_control *pc)
> +{
> +	const u32 state = gpu_read(pc->iomem, AM_PART_STATE);
> +
> +	return AM_PART_STATE_GET(state);
> +}
> +
> +static u8 partition_aw_get(struct panthor_partition_control *pc)
> +{
> +	const u32 state = gpu_read(pc->iomem, AM_PART_STATE);
> +
> +	return AM_PART_STATE_WINDOW_GET(state);
> +}

[ ... ]

> +static int yield_now(struct panthor_partition_control *pc)
> +{
> +	guard(spinlock_irqsave)(&pc->lock);
> +
> +	if (partition_state_get(pc) == PART_STATE_RESET)
> +		return 0;
> +
> +	if (partition_state_get(pc) != PART_STATE_WINDOW_OPEN)
> +		return -EAGAIN;
> +
> +	gpu_write(pc->iomem, AM_PART_COMMAND,
> +		  AM_PART_SET_COMMAND(PART_CMD_YIELD_NOW));
> +
> +	return 0;
> +}
> +
> +static int yield_idle(struct panthor_partition_control *pc)
> +{
> +	guard(spinlock_irqsave)(&pc->lock);
> +
> +	if (partition_state_get(pc) == PART_STATE_RESET)
> +		return 0;
> +
> +	if (partition_state_get(pc) != PART_STATE_WINDOW_OPEN)
> +		return -EAGAIN;
> +
> +	gpu_write(pc->iomem, AM_PART_COMMAND,
> +		  AM_PART_SET_COMMAND(PART_CMD_YIELD_IDLE));
> +
> +	return 0;
> +}
> +
> +static int window_close(struct panthor_partition_control *pc)
> +{
> +	guard(spinlock_irqsave)(&pc->lock);
> +
> +	if (partition_state_get(pc) == PART_STATE_RESET)
> +		return 0;
> +
> +	if (partition_state_get(pc) != PART_STATE_WINDOW_OPEN)
> +		return -EAGAIN;
> +
> +	pc->closing = true;
> +
> +	gpu_write(pc->iomem, AM_PART_COMMAND,
> +		  AM_PART_SET_COMMAND(PART_CMD_CLOSE_WINDOW));
> +
> +	return 0;
> +}
> +
> +static int window_open(struct panthor_partition_control *pc, u8 aw_id)
> +{
> +	if (aw_id >= AM_ARB_MAX_AW_COUNT)
> +		return -EINVAL;
> +
> +	guard(spinlock_irqsave)(&pc->lock);
> +
> +	if (partition_state_get(pc) == PART_STATE_WINDOW_OPEN) {
> +		u8 cur_aw = partition_aw_get(pc);
> +
> +		if (cur_aw == aw_id)
> +			return 0;
> +
> +		dev_warn(pc->dev,
> +			 "%s: OPEN_WINDOW(%u): Already opened for aw=%u, state=%u. Closing...",
> +			 pc->name, aw_id, cur_aw, partition_state_get(pc));
> +
> +		return -EBUSY;
> +	}

[Severity: Medium]
Can an asynchronous hardware state transition between these back-to-back
AM_PART_STATE reads cause yield_now(), yield_idle(), window_close(), and
window_open() to act on inconsistent state?

Each call to partition_state_get() and partition_aw_get() performs a
separate MMIO read of AM_PART_STATE.  If the partition finishes closing or
yielding and transitions into PART_STATE_RESET between the first and
second partition_state_get() in yield_now(), yield_idle(), or
window_close(), the first check is false and the second sees
PART_STATE_RESET != PART_STATE_WINDOW_OPEN, returning -EAGAIN instead of 0
(which in panthor_partition_control_term() triggers WARN_ON() and skips
partition_state_wait()).  In window_open(), if the partition resets
between partition_state_get() and partition_aw_get(), cur_aw reads as 0;
when aw_id is 0, window_open() returns 0 without issuing
PART_CMD_OPEN_WINDOW.

Also, the dev_warn() in window_open() performs a third MMIO read of
AM_PART_STATE and still says "Closing..." even though window_open() no
longer closes the window.  Reading AM_PART_STATE once into a local
variable under pc->lock and extracting both fields from that value would
avoid these races.

[ ... ]

> +void panthor_partition_control_term(struct panthor_arbitration *adev)
> +{
> +	for (int i = 0; i < AM_ARB_MAX_PC_COUNT; i++) {
> +		struct panthor_partition_control *pc = adev->pc[i];
> +
> +		if (!pc)
> +			continue;
> +
> +		partition_irq_suspend(pc);
> +
> +		if (!pm_runtime_status_suspended(pc->dev))
> +			if (!WARN_ON(window_close(pc) < 0))
> +				WARN_ON(partition_state_wait(pc, PART_STATE_RESET));
> +	}
> +}

[Severity: Medium]
What happens in panthor_partition_control_term() if a partition is already
transitioning through PART_STATE_WINDOW_CLOSED or
PART_STATE_WINDOW_OPENING when teardown runs?

window_open(), window_close(), yield_now(), and yield_idle() issue
commands without waiting for the state transition to complete, and
window_close() returns -EAGAIN for any state other than PART_STATE_RESET
and PART_STATE_WINDOW_OPEN.  If a transition is still in flight when
panthor_partition_control_term() runs, window_close() returns -EAGAIN,
triggering WARN_ON() and skipping partition_state_wait() while the
hardware is still active.  Commit "drm/panthor: Reset partitions before
starting arbitration" later in this series adds partition_ensure_reset()
to handle in-progress states during init, so calling it here as well would
ensure teardown waits for the reset to complete.

> +static int partition_control_init(struct panthor_arbitration *adev, int i)
> +{
> +	struct panthor_partition_control *pc;
> +	struct device *dev = adev->dev;
> +	struct irq_data *irqdata;
> +	struct resource *res;
> +	void __iomem *iomem;
> +	u32 irq_flags = 0;
> +	char *name;
> +	int irq;
> +	int ret;
> +
> +	if (adev->pc[i])
> +		return dev_warn_probe(dev, -ENODEV,
> +				      "partition %u already present", i);
> +
> +	pc = devm_kzalloc(dev, sizeof(*pc), GFP_KERNEL);
> +	if (!pc)
> +		return -ENOMEM;
> +
> +	name = devm_kasprintf(dev, GFP_KERNEL, "pc%d", i);
> +	if (!name)
> +		return -ENOMEM;
> +
> +	res = platform_get_resource_byname(to_platform_device(dev),
> +					   IORESOURCE_MEM, name);
> +	if (!res)
> +		return -ENODEV;

[Severity: Low]
When platform_get_resource_byname() finds no resource and returns -ENODEV,
panthor_partition_control_init() ignores -ENODEV and probe succeeds,
leaving pc and name allocated on dev until the driver unbinds.  Could
pc be allocated after looking up res (or the unused devm allocations be
freed before returning -ENODEV)?

[ ... ]

> +	ret = devm_request_irq(
> +		dev, irq, partition_irq_raw_handler, irq_flags | IRQF_SHARED,
> +		devm_kasprintf(dev, GFP_KERNEL, "panthor-%s-irq", name), pc);
> +	if (ret)
> +		return ret;

[Severity: Low]
Can devm_kasprintf() return NULL here and pass a NULL devname into
devm_request_irq() instead of failing with -ENOMEM?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110153907.3241978-1-karunika.choo@arm.com?part=14

  reply	other threads:[~2026-11-10 16:10 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 15:38 [PATCH v2 00/28] drm/panthor: Add Mali v15 virtualization support Karunika Choo
2026-11-10 15:38 ` [PATCH v2 01/28] drm/panthor: Ignore -EOPNOTSUPP for shader-present nvmem lookup Karunika Choo
2026-11-10 15:38 ` [PATCH v2 02/28] drm/panthor: Rename neural accelerator feature macro to NX Karunika Choo
2026-11-10 15:47   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 03/28] drm/panthor: Move register access helpers out of panthor_device.h Karunika Choo
2026-11-10 15:38 ` [PATCH v2 04/28] drm/panthor: Parse and store GPU_ID fields Karunika Choo
2026-11-10 15:38 ` [PATCH v2 05/28] drm/panthor: Add 64-bit GPU_ID decoding for v15 GPUs Karunika Choo
2026-11-10 15:38 ` [PATCH v2 06/28] drm/panthor: Move register base offsets to the HW description Karunika Choo
2026-11-10 15:38 ` [PATCH v2 07/28] drm/panthor: Derive MMU AS register addresses from base and stride Karunika Choo
2026-11-10 15:38 ` [PATCH v2 08/28] dt-bindings: gpu: mali-gen5-am: Add Mali 5th-Gen AM schema Karunika Choo
2026-11-11  8:33   ` Krzysztof Kozlowski
2026-11-11 10:32     ` Karunika Choo
2026-11-11 10:41       ` Krzysztof Kozlowski
2026-11-11 11:04         ` Karunika Choo
2026-11-12  8:36           ` Krzysztof Kozlowski
2026-11-10 15:38 ` [PATCH v2 09/28] drm/panthor: Add Mali v15 hardware support Karunika Choo
2026-11-10 15:38 ` [PATCH v2 10/28] drm/panthor: Skip devfreq when no OPP table is present Karunika Choo
2026-11-10 16:03   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 11/28] dt-bindings: gpu: panthor: Document AM system bindings Karunika Choo
2026-11-11  8:29   ` Krzysztof Kozlowski
2026-11-11 10:43     ` Karunika Choo
2026-11-12  8:32       ` Krzysztof Kozlowski
2026-11-10 15:38 ` [PATCH v2 12/28] drm/panthor: Add AM_SYSTEM platform driver Karunika Choo
2026-11-10 15:57   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 13/28] dt-bindings: gpu: panthor: Document panthor-arbitration bindings Karunika Choo
2026-11-10 15:38 ` [PATCH v2 14/28] drm/panthor: Add AM_PARTITION_CONTROL support Karunika Choo
2026-11-10 16:10   ` sashiko-bot [this message]
2026-11-11  5:43   ` kernel test robot
2026-11-10 15:38 ` [PATCH v2 15/28] drm/panthor: Add AM message helpers Karunika Choo
2026-11-10 15:38 ` [PATCH v2 16/28] drm/panthor: Add AM_RESOURCE_GROUP support Karunika Choo
2026-11-10 16:07   ` sashiko-bot
2026-11-11  8:30   ` kernel test robot
2026-11-10 15:38 ` [PATCH v2 17/28] drm/panthor: Add arbitration scheduler Karunika Choo
2026-11-10 16:05   ` sashiko-bot
2026-11-11  0:43   ` kernel test robot
2026-11-10 15:38 ` [PATCH v2 18/28] drm/panthor: Route arbitration events Karunika Choo
2026-11-10 16:19   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 19/28] drm/panthor: Add AW assignment tracking Karunika Choo
2026-11-10 16:03   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 20/28] drm/panthor: Handle partition control INVALID_COMMAND interrupt Karunika Choo
2026-11-10 16:16   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 21/28] drm/panthor: Request AW to yield GPU access on idle Karunika Choo
2026-11-10 16:15   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 22/28] drm/panthor: Add access-window support Karunika Choo
2026-11-10 16:20   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 23/28] drm/panthor: Synchronize HW component PM transitions Karunika Choo
2026-11-10 16:23   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 24/28] drm/panthor: Quiesce scheduler tick during system suspend Karunika Choo
2026-11-10 16:24   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 25/28] drm/panthor: Route HW component PM through access windows Karunika Choo
2026-11-10 16:50   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 26/28] drm/panthor: Tolerate access-window loss during HW waits Karunika Choo
2026-11-10 16:30   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 27/28] drm/panthor: Prevent missed post-yield cleanup due to reset Karunika Choo
2026-11-10 16:44   ` sashiko-bot
2026-11-10 15:38 ` [PATCH v2 28/28] drm/panthor: Reset partitions before starting arbitration Karunika Choo
2026-11-10 16:22   ` 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=sashiko-outbox-207343@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karunika.choo@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.