All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Zhang" <yidong.zhang@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH V3 19/19] accel/amdxdna: Implement runtime suspend and resume support
Date: Thu, 08 Oct 2026 04:22:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-163609@kernel.org> (raw)
In-Reply-To: <20261008032348.2044667-20-yidong.zhang@amd.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] amdxdna: PM deadlock in probe error path via pm_runtime_forbid()
- [High] amdxdna: missing PM reference in AIE4 hwctx_init causes hardware access while suspended
- [Low] pm: Unconditional external PM callbacks defeat dead code elimination
--

commit cc7f853ee4ac4c49242812a5366af4f77504c2a6
Author: David Zhang <yidong.zhang@amd.com>
Subject: accel/amdxdna: Implement runtime suspend and resume support

This commit adds runtime suspend and resume handlers for the AIE4 classic
device by wrapping its system PM handlers. It also attempts to discard
dev_pm_ops and associated callbacks by using the pm_ptr() wrapper when
CONFIG_PM is disabled.

> diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c
> index a368bd3c257f5..ee64a5f3405dd 100644
> --- a/drivers/accel/amdxdna/aie4_pci.c
> +++ b/drivers/accel/amdxdna/aie4_pci.c
> @@ -1040,6 +1040,7 @@ static int aie4_classic_init(struct amdxdna_dev *xdna)
>  	if (ret)
>  		goto free_work_buf;
>  
> +	amdxdna_pm_init(xdna);

[Severity: High]
Does enabling runtime PM autosuspend here expose a missing wake-up in the
context creation path?

If the device autosuspends, and a user application calls the context creation
ioctl, aie4_hwctx_init() invokes aie4_hwctx_create(), which calls
aie_send_mgmt_msg_wait() to send a message via the hardware doorbell ring.

Unlike aie2_hwctx_init() which takes a PM reference, aie4_hwctx_init() does
not, which could lead to a synchronous external abort or system hang when
accessing the powered-down PCI device.

>  	return 0;
>  
>  free_work_buf:

[ ... ]

> @@ -1403,4 +1405,6 @@ const struct amdxdna_dev_ops aie4_classic_ops = {
>  	.set_aie_state		= aie4_set_state,
>  	.resume			= aie4_classic_resume,
>  	.suspend		= aie4_classic_suspend,
> +	.runtime_resume		= aie4_classic_resume,
> +	.runtime_suspend	= aie4_classic_suspend,

[Severity: Low]
Will these callbacks actually be discarded as dead code when CONFIG_PM is
disabled?

Since aie4_classic_suspend and aie4_classic_resume are unconditionally
assigned to the globally visible aie4_classic_ops structure, they will remain
referenced and cannot be eliminated by the compiler.

>  };

> diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.c b/drivers/accel/amdxdna/amdxdna_pci_drv.c
> index f5f7831c4e802..cb78f145ffa1f 100644
> --- a/drivers/accel/amdxdna/amdxdna_pci_drv.c
> +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.c
> @@ -484,7 +484,7 @@ static struct pci_driver amdxdna_pci_driver = {
>  	.id_table = pci_ids,
>  	.probe = amdxdna_probe,
>  	.remove = amdxdna_remove,
> -	.driver.pm = &amdxdna_pm_ops,
> +	.driver.pm = pm_ptr(&amdxdna_pm_ops),

[Severity: Low]
Does this pm_ptr() actually prevent the PM callbacks from being compiled into
the kernel when CONFIG_PM is disabled?

Because amdxdna_pm_runtime_suspend and amdxdna_pm_runtime_resume are defined
unconditionally with external linkage in amdxdna_pm.c, the compiler cannot
eliminate them across translation units even when amdxdna_pm_ops is dropped.

>  	.sriov_configure = amdxdna_sriov_configure,
>  };

> diff --git a/drivers/accel/amdxdna/amdxdna_pm.c b/drivers/accel/amdxdna/amdxdna_pm.c
> index b1fafddd7ad59..7d7bc965342dc 100644
> --- a/drivers/accel/amdxdna/amdxdna_pm.c
> +++ b/drivers/accel/amdxdna/amdxdna_pm.c
> @@ -37,11 +37,40 @@ int amdxdna_pm_resume(struct device *dev)
>  	return ret;
>  }
>  

[ ... ]

> +int amdxdna_pm_runtime_resume(struct device *dev)
> +{
> +	struct amdxdna_dev *xdna = to_xdna_dev(dev_get_drvdata(dev));
> +	int ret = -EOPNOTSUPP;
> +
> +	guard(mutex)(&xdna->dev_lock);

[Severity: High]
Can this dev_lock acquisition cause a deadlock during the probe error path?

If amdxdna_probe() encounters an error after initialization (like a sysfs
or DRM registration failure), the error path calls xdna->dev_info->ops->fini()
with dev_lock held:

amdxdna_pci_drv.c:amdxdna_probe() {
    ...
failed_dev_fini:
	mutex_lock(&xdna->dev_lock);
	xdna->dev_info->ops->fini(xdna);
	mutex_unlock(&xdna->dev_lock);
    ...
}

This fini handler maps to aie4_classic_fini(), which now calls
amdxdna_pm_fini().

amdxdna_pm_fini() calls pm_runtime_forbid(). If the device has autosuspended
in the background, pm_runtime_forbid() synchronously resumes it, calling
amdxdna_pm_runtime_resume().

This leads to a second attempt to acquire dev_lock, deadlocking the probe
thread.

> +	if (xdna->dev_info->ops->runtime_resume)
> +		ret = xdna->dev_info->ops->runtime_resume(xdna);
> +
> +	XDNA_DBG(xdna, "Runtime resume done ret %d", ret);
> +	return ret;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261008032348.2044667-1-yidong.zhang@amd.com?part=19

      reply	other threads:[~2026-10-08  4:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08  3:23 [PATCH V3 00/19] accel/amdxdna: Kernel submission and PM for AIE4 David Zhang
2026-10-08  3:23 ` [PATCH V3 01/19] accel/amdxdna: Rename NPU3 firmware files David Zhang
2026-10-08 16:23   ` Lizhi Hou
2026-10-08  3:23 ` [PATCH V3 02/19] accel/amdxdna: Remove mmap for doorbell David Zhang
2026-10-08  3:23 ` [PATCH V3 03/19] accel/amdxdna: Add CERT firmware version support David Zhang
2026-10-08 17:12   ` Lizhi Hou
2026-10-08 17:26     ` Zhang, Yidong (David)
2026-10-08  3:23 ` [PATCH V3 04/19] accel/amdxdna: Upgrade firmware version to 6.0 David Zhang
2026-10-08 17:15   ` Lizhi Hou
2026-10-08  3:23 ` [PATCH V3 05/19] accel/amdxdna: Add NPU3 classic device support David Zhang
2026-10-08  3:44   ` sashiko-bot
2026-10-08 17:25     ` Zhang, Yidong (David)
2026-10-08  3:23 ` [PATCH V3 06/19] accel/amdxdna: Add AIE version query to aie4_get_info David Zhang
2026-10-08  3:23 ` [PATCH V3 07/19] accel/amdxdna: Add get and set power_mode for AIE4 David Zhang
2026-10-08  3:23 ` [PATCH V3 08/19] accel/amdxdna: Add clock, DPM frequency, and resource info queries " David Zhang
2026-10-08  3:48   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 09/19] accel/amdxdna: Add context switch hysteresis with debugfs control David Zhang
2026-10-08  3:23 ` [PATCH V3 10/19] accel/amdxdna: Refactor AIE4 hardware initialization sequence David Zhang
2026-10-08  3:23 ` [PATCH V3 11/19] accel/amdxdna: Decouple AIE4 doorbell and MSI-X notify transport hooks David Zhang
2026-10-08  3:51   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 12/19] accel/amdxdna: Implement AIE4 kernel queue lifecycle and memory layout David Zhang
2026-10-08  3:59   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 13/19] accel/amdxdna: Prepare for AIE4 command submission David Zhang
2026-10-08  4:04   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 14/19] accel/amdxdna: Move HMM invalidate wait into common GEM code David Zhang
2026-10-08  3:56   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 15/19] accel/amdxdna: Make populate_range common for AIE2 and AIE4 David Zhang
2026-10-08  3:23 ` [PATCH V3 16/19] accel/amdxdna: Implement AIE4 command packet building and submission David Zhang
2026-10-08  4:10   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 17/19] accel/amdxdna: Enable AIE4 firmware logging to DRAM David Zhang
2026-10-08  3:23 ` [PATCH V3 18/19] accel/amdxdna: Implement AIE4 suspend and resume David Zhang
2026-10-08  4:10   ` sashiko-bot
2026-10-08  3:23 ` [PATCH V3 19/19] accel/amdxdna: Implement runtime suspend and resume support David Zhang
2026-10-08  4:22   ` sashiko-bot [this message]

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-163609@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yidong.zhang@amd.com \
    /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.