mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
Cc: "Damien Le Moal" <dlemoal@kernel.org>,
	"Niklas Cassel" <cassel@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Philipp Stanner" <phasta@kernel.org>,
	linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Weidong Wang" <weidongw@illinois.edu>,
	linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	"Vaibhav Gupta" <vaibhavgupta40@gmail.com>
Subject: Re: [PATCH] ata: pata_macio: Do not disable the PCI device on suspend
Date: Thu, 3 Dec 2026 10:00:10 -0600	[thread overview]
Message-ID: <20261203160010.GA809615@bhelgaas> (raw)
In-Reply-To: <20261201-s2p-d104-v1-1-df4a9ef2b79d@mbzuai.ac.ae>

[+cc Vaibhav]

On Tue, Dec 01, 2026 at 11:17:11PM +0400, Arina Kharlamova wrote:
> pata_macio_suspend() disables the PCI device with pci_disable_device(),
> and pata_macio_reset_hw() enables it again on resume with
> pcim_enable_device(). Since commit f748a07a0b64 ("PCI: Remove legacy
> pcim_release()") every pcim_enable_device() call adds a
> pcim_disable_device() devres action, so each suspend and resume leaves
> one more action behind. On unbind they all run, and every one after
> the first warns about disabling an already disabled device.
> 
> The device is enabled with pcim_enable_device() in probe and stays
> managed until unbind, so the driver should not disable and enable it by
> hand. On suspend, clear only the bus master bit, which is all that
> pci_disable_device() did on this hardware, and set it again on resume
> without enabling the device.
> 
> Fixes: f748a07a0b64 ("PCI: Remove legacy pcim_release()")
> Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
> ---
> I found this while checking the other drivers that call
> pcim_enable_device() again on resume, after the discussion of the t7xx
> fix:
> https://lore.kernel.org/all/20261201-s2p-d64-v1-1-c9147b2eedb0@mbzuai.ac.ae/
> 
> Weidong Wang's patch for ata_pci_device_do_resume() fixes the same
> problem in libata core by switching resume to pci_enable_device():
> https://lore.kernel.org/all/20261128-kbug-l080-v1-1-90f7309990ea@illinois.edu/
> Philipp replied there that a driver should either use only pcim_ and
> never undo it, or use only the pci_ functions. This patch takes the
> first way, so the device is no longer disabled on suspend.
> 
> With the help of an AI coding assistant (Claude); I reviewed the
> analysis and the fix. Not triggered at runtime. Compile-tested only
> (powerpc pmac32_defconfig), not tested on hardware.
> ---
>  drivers/ata/pata_macio.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/ata/pata_macio.c b/drivers/ata/pata_macio.c
> index a11a1eae2ae8..ba946a4116c3 100644
> --- a/drivers/ata/pata_macio.c
> +++ b/drivers/ata/pata_macio.c
> @@ -788,16 +788,8 @@ static void pata_macio_reset_hw(struct pata_macio_priv *priv, int resume)
>  
>  	/* If resuming a PCI device, restore the config space here */
>  	if (priv->pdev && resume) {
> -		int rc;
> -
>  		pci_restore_state(priv->pdev);
> -		rc = pcim_enable_device(priv->pdev);
> -		if (rc)
> -			dev_err(&priv->pdev->dev,
> -				"Failed to enable device after resume (%d)\n",
> -				rc);
> -		else
> -			pci_set_master(priv->pdev);
> +		pci_set_master(priv->pdev);
>  	}
>  
>  	/* On Kauai, initialize the FCR. We don't perform a reset, doesn't really
> @@ -898,7 +890,7 @@ static int pata_macio_do_suspend(struct pata_macio_priv *priv, pm_message_t mesg
>  	 */
>  	if (priv->pdev) {
>  		pci_save_state(priv->pdev);
> -		pci_disable_device(priv->pdev);
> +		pci_clear_master(priv->pdev);
>  	}
>  
>  	/* Disable the bus on older machines and the cell on kauai */

This driver uses legacy PCI power management, i.e.,
pci_driver.suspend() and .resume().  If converted to generic power
management (pci_driver.driver.pm hooks), it probably wouldn't need any
of the pci_save_state() and related gunk because the PCI core would
take care of it.

For example:

  d5376026f926 ("gpio: bt8xx: use generic power management")
  892bb0740b02 ("firewire: ohci: use generic power management")
  0aeddbd0cb07 ("via-agp: convert to generic power management")

Bjorn

      parent reply	other threads:[~2026-12-03 16:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:17 Arina Kharlamova via B4 Relay
2026-12-02  7:05 ` Damien Le Moal
2026-12-03 11:30   ` Arina Kharlamova
2026-12-03 16:00 ` Bjorn Helgaas [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=20261203160010.GA809615@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=arina.kharlamova@mbzuai.ac.ae \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=kwilczynski@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=phasta@kernel.org \
    --cc=vaibhavgupta40@gmail.com \
    --cc=weidongw@illinois.edu \
    /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

all inboxes | Powered by JetHome®