Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Atharva Tiwari" <atharvatiwarilinuxdev@gmail.com>
Cc: "open list:PCI SUBSYSTEM" <linux-pci@vger.kernel.org>,
	"open list:RADEON and AMDGPU DRM DRIVERS"
	<amd-gfx@lists.freedesktop.org>,
	"open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v2 11/12] drm/amdgpu: Skip AC/DC notification while the GPU is runtime suspended
Date: Sat, 14 Nov 2026 16:53:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-214789@kernel.org> (raw)
In-Reply-To: <20261114160731.3756-12-atharvatiwarilinuxdev@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/amdgpu: missed AC/DC SMU update in
  amdgpu_pm_acpi_event_handler() race
- [Medium] drm/amd/pm: negative pm_runtime_get_if_active() treated as
  suspended
- [Medium] drm/amdgpu: missing SMU7 AC notification on resume in
  hwmgr_resume()
--

commit 2d835db57775c3299d3a931908d4d082aae8da4d
Author: Andre Eikmeyer <dev@deq.rocks>

drm/amdgpu: Skip AC/DC notification while the GPU is runtime suspended

This commit acquires a runtime PM reference with pm_runtime_get_if_active() in
amdgpu_pm_acpi_event_handler() and skips notifying the SMU of AC/DC changes
when the device is not runtime active.

> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
> index 808be6c425bff..3c6dde3868006 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c

[ ... ]

> @@ -498,19 +499,27 @@ int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev,
>  
>  void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
>  {
> +	int active = 0;
> +
>  	if (adev->pm.dpm_enabled) {
>  		mutex_lock(&adev->pm.mutex);
> +		active = pm_runtime_get_if_active(adev->dev);
> +
>  		if (power_supply_is_system_supplied() > 0)
>  			adev->pm.ac_power = true;
>  		else
>  			adev->pm.ac_power = false;
>  
> -		if (adev->powerplay.pp_funcs &&
> -		    adev->powerplay.pp_funcs->notify_ac_dc)
> -			amdgpu_dpm_notify_ac_dc(adev);
> +		if (active > 0) {

[Severity: Medium]
Can an AC/DC event racing with runtime resume or an aborted runtime suspend
drop the SMU power-source update?

During rpm_resume(), dev->power.runtime_status stays RPM_RESUMING until
amdgpu_pmops_runtime_resume() returns, so pm_runtime_get_if_active() returns
0 (or -EINVAL while hotplug probing increments disable_depth):

CPU0                                  CPU1
rpm_resume()
  dev->power.runtime_status = RPM_RESUMING
  amdgpu_pmops_runtime_resume()
    amdgpu_device_resume()
      amdgpu_device_ip_late_init()
        smu_late_init()
          smu_set_ac_dc()
                                      amdgpu_pm_acpi_event_handler()
                                        pm_runtime_get_if_active() -> 0
                                        adev->pm.ac_power = ...
                                        /* skips smu_set_ac_dc() */
      flush_delayed_work()
  dev->power.runtime_status = RPM_ACTIVE
                                        <-- GPU runs with stale AC/DC state

The same drop occurs if the event arrives during rpm_suspend() while
runtime_status is RPM_SUSPENDING and amdgpu_pmops_runtime_suspend() later
aborts with -EBUSY, which reverts runtime_status to RPM_ACTIVE without
running resume.  In addition, hwmgr_resume() and hwmgr_suspend() invoke
smu7_apply_state_adjust_rules() and vega10_apply_state_adjust_rules()
without holding adev->pm.mutex, reading adev->pm.ac_power twice while
amdgpu_pm_acpi_event_handler() can update it concurrently.

[Severity: Medium]
Does checking active > 0 also skip AC/DC notifications when runtime PM or
CONFIG_PM is disabled?

pm_runtime_get_if_active() returns -EINVAL when CONFIG_PM is disabled or
when runtime PM is disabled on adev->dev (disable_depth > 0).  With
active > 0, amdgpu_pm_acpi_event_handler() treats -EINVAL as suspended and
never notifies the SMU or DPM even though the GPU is active and no runtime
resume will follow.  Other callers in this subsystem such as
amdgpu_pm_get_access_if_active() check active != 0 to allow hardware access
and only call pm_runtime_put() when active > 0.

> +			if (adev->powerplay.pp_funcs &&
> +			    adev->powerplay.pp_funcs->notify_ac_dc)
> +				amdgpu_dpm_notify_ac_dc(adev);

[Severity: Medium]
If AC power is connected while an SMU7 GPU is runtime suspended, will the
resume path ever send PPSMC_MSG_RunningOnAC to the SMU?

On SMU7 GPUs with PHM_PlatformCaps_AutomaticDCTransition, smu7_notify_ac_dc()
is the only place that sends PPSMC_MSG_RunningOnAC when adev->pm.ac_power is
true:

drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c:smu7_notify_ac_dc() {
	...
	if (adev->pm.ac_power &&
	    phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
			    PHM_PlatformCaps_AutomaticDCTransition))
		smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunningOnAC, NULL);
	...
}

Unlike swSMU, which calls smu_set_ac_dc() in smu_late_init(), neither
hwmgr_resume() nor pp_late_init() invokes notify_ac_dc() or sends
PPSMC_MSG_RunningOnAC.  When SMU firmware stays running across BACO runtime
suspend, skipping amdgpu_dpm_notify_ac_dc() here leaves the SMU in DC mode
after resume.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114160731.3756-1-atharvatiwarilinuxdev@gmail.com?part=11

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

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 16:06 [PATCH v2 00/12] Fixes for apple-gmux and runtime support Atharva Tiwari
2026-11-14 16:06 ` [PATCH v2 01/12] platform/apple-gmux: Fix power for MMIO systems Atharva Tiwari
2026-11-14 16:42   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 02/12] PCI: Disable pcie port on specific amd devices Atharva Tiwari
2026-11-14 16:34   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 03/12] platform/apple-gmux: Fix MMIO interface Atharva Tiwari
2026-11-14 16:17   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 04/12] platform/apple-gmux: Fix Interrupts for MMIO systems Atharva Tiwari
2026-11-14 16:27   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 05/12] platform/apple-gmux: Write switch state to EFI on MMIO devices Atharva Tiwari
2026-11-14 16:25   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 06/12] platform/apple-gmux: Add check to detect FSS Atharva Tiwari
2026-11-14 16:17   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 07/12] platform/apple-gmux: Add documentation about iMacs Atharva Tiwari
2026-11-14 16:40   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 08/12] drm/amdgpu: Add Apple GMUX runtime PM support Atharva Tiwari
2026-11-14 16:44   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 09/12] drm/amdgpu: Catch register access while GMUX keeps the GPU off Atharva Tiwari
2026-11-14 16:33   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 10/12] drm/amd/display: Refuse DP AUX " Atharva Tiwari
2026-11-14 16:34   ` sashiko-bot
2026-11-14 16:06 ` [PATCH v2 11/12] drm/amdgpu: Skip AC/DC notification while the GPU is runtime suspended Atharva Tiwari
2026-11-14 16:53   ` sashiko-bot [this message]
2026-11-14 16:06 ` [PATCH v2 12/12] drm/amd/display: Skip panel power savings on eDP links without a panel Atharva Tiwari
2026-11-14 16:37   ` 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-214789@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=atharvatiwarilinuxdev@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-pci@vger.kernel.org \
    --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