All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fabrice Gasnier" <fabrice.gasnier@foss.st.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v6 01/11] usb: dwc2: fix recovery after PM domain off
Date: Wed, 25 Nov 2026 16:58:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-233789@kernel.org> (raw)
In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-1-d5df33b93eaf@foss.st.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: dwc2: stale gr_backup.valid after resume without PM domain
  power loss
- [High] usb: dwc2: dwc2_restore_critical_registers() overwrites resume
  config
--

commit c2d1c8f60a77ed180c814b0a57e8097e8be203f6
Author: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

usb: dwc2: fix recovery after PM domain off

This commit backs up critical registers when entering clock gating, skips the
backup in dwc2_suspend() if a valid backup already exists, and moves register
restoration in dwc2_resume() after STM32 ID/VBUS detection and dual-role
restoration.

> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 3df9b198d1b22..7f3436e6a1538 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -649,6 +649,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
>  static int __maybe_unused dwc2_suspend(struct device *dev)
>  {
>  	struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev);
> +	struct dwc2_gregs_backup *gr;
> +	unsigned long flags;
>  	bool is_device_mode;
>  	int ret = 0;
>  
> @@ -692,10 +694,15 @@ static int __maybe_unused dwc2_suspend(struct device *dev)
>  		regulator_disable(dwc2->usb33d);
>  	}
>  
> -	if (is_device_mode)
> -		ret = dwc2_gadget_backup_critical_registers(dwc2);
> -	else
> -		ret = dwc2_host_backup_critical_registers(dwc2);
> +	spin_lock_irqsave(&dwc2->lock, flags);
> +	gr = &dwc2->gr_backup;
> +	if (!gr->valid) {
> +		if (is_device_mode)
> +			ret = dwc2_gadget_backup_critical_registers(dwc2);
> +		else
> +			ret = dwc2_host_backup_critical_registers(dwc2);
> +	}
> +	spin_unlock_irqrestore(&dwc2->lock, flags);

[Severity: High]
Can gr->valid remain true across normal operation after a suspend/resume
cycle where the power domain is not turned off?

When dwc2_suspend() runs while the controller is not in clock gating (for
example, in device mode in DWC2_L0, in host mode with no device connected on
the root port, or when params.no_clock_gating is set), the backup here sets
gr->valid = true.  If the power domain stays powered during that suspend,
dwc2_resume() sees GUSBCFG_TOUTCAL_MASK still set and skips
dwc2_restore_critical_registers(), while neither
dwc2_gadget_exit_clock_gating() nor dwc2_host_exit_clock_gating() runs to
clear gr->valid.

Because gr->valid stays true in DWC2_L0, subsequent dwc2_suspend() calls skip
backing up current registers.  If a later suspend powers off the PM domain,
dwc2_resume() restores stale register values from the earlier suspend, or
restores the wrong mode's registers if an OTG role switch occurred in between.

[ ... ]

> @@ -786,6 +782,20 @@ static int __maybe_unused dwc2_resume(struct device *dev)
>  		dwc2_drd_resume(dwc2);
>  	}
>  
> +	/*
> +	 * During suspend it's possible that the power domain for the
> +	 * DWC2 controller is disabled and all register values get lost.
> +	 * In case the GUSBCFG register is not initialized, it's clear the
> +	 * registers must be restored.
> +	 */
> +	if (!(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK)) {
> +		spin_lock_irqsave(&dwc2->lock, flags);
> +		ret = dwc2_restore_critical_registers(dwc2);
> +		spin_unlock_irqrestore(&dwc2->lock, flags);
> +		if (ret)
> +			return ret;
> +	}

[Severity: High]
Does calling dwc2_restore_critical_registers() after the STM32 ID/VBUS
detection block and dwc2_force_dr_mode() / dwc2_drd_resume() overwrite the
GOTGCTL, GINTMSK, and GUSBCFG values just configured for resume?

drivers/usb/dwc2/core.c:dwc2_restore_global_registers() {
    ...
	dwc2_writel(hsotg, gr->gotgctl, GOTGCTL);
	dwc2_writel(hsotg, gr->gintmsk, GINTMSK);
	dwc2_writel(hsotg, gr->gusbcfg, GUSBCFG);
    ...
}

In dwc2_suspend(), dwc2_drd_suspend() masks GINTSTS_CONIDSTSCHNG in GINTMSK,
and the activate_stm_id_vb_detection path forces the mode in GUSBCFG and sets
session and debounce overrides in GOTGCTL before the !gr->valid backup saves
those registers into gr_backup.  When the power domain is lost, running
dwc2_restore_critical_registers() after the resume steps clobbers the restored
GOTGCTL, GINTMSK, and GUSBCFG settings with the pre-suspend or suspend-time
snapshot, breaking OTG and dual-role detection after resume.

Even with commit "usb: dwc2: platform: fix stm32mp15 detection logic power
management" and commit "usb: dwc2: restore peripheral mode on low-level
enable" later in the series, dwc2_drd_suspend() still masks
GINTSTS_CONIDSTSCHNG before the backup in dwc2_suspend(), and
dwc2_force_dr_mode() and dwc2_drd_resume() still have their GUSBCFG, GOTGCTL,
and GINTMSK updates overwritten by dwc2_restore_global_registers().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com?part=1

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

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 16:32 [PATCH v6 00/11] usb: dwc2: fix low power issues found on stm32mp1 Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 01/11] usb: dwc2: fix recovery after PM domain off Fabrice Gasnier
2026-11-25 16:58   ` sashiko-bot [this message]
2026-11-25 16:32 ` [PATCH v6 02/11] usb: dwc2: keep TOUTCAL canary valid after PHY init Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 03/11] usb: dwc2: drop stale state after register restore on resume Fabrice Gasnier
2026-11-25 17:09   ` sashiko-bot
2026-11-25 16:32 ` [PATCH v6 04/11] usb: dwc2: clean up old role on mode change during suspend Fabrice Gasnier
2026-11-25 16:57   ` sashiko-bot
2026-11-25 16:32 ` [PATCH v6 05/11] usb: dwc2: fix a possible interrupt storm in hcd resume Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 06/11] usb: dwc2: fix a possible interrupt storm on stm32mp1 Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 07/11] usb: dwc2: hcd: fix possible successive vbus supply enables Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 08/11] usb: dwc2: hcd: don't disable external vbus in system suspend Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 09/11] usb: dwc2: restore peripheral mode on low-level enable Fabrice Gasnier
2026-11-25 17:08   ` sashiko-bot
2026-11-25 16:32 ` [PATCH v6 10/11] usb: dwc2: platform: fix stm32mp15 detection logic power management Fabrice Gasnier
2026-11-25 16:32 ` [PATCH v6 11/11] usb: dwc2: drop redundant ll_hw_enabled checks in suspend/resume Fabrice Gasnier
2026-11-25 17:09 ` [PATCH v6 00/11] usb: dwc2: fix low power issues found on stm32mp1 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-233789@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fabrice.gasnier@foss.st.com \
    --cc=linux-usb@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 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.