From: "pstanner@redhat.com" <pstanner@redhat.com>
To: weidongw@illinois.edu, Damien Le Moal <dlemoal@kernel.org>,
Niklas Cassel <cassel@kernel.org>
Cc: linux-ide@vger.kernel.org, "Bjorn Helgaas" <bhelgaas@google.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] ata: libata-core: Do not use pcim_enable_device() on PCI resume
Date: Mon, 30 Nov 2026 14:00:42 +0100 [thread overview]
Message-ID: <022e98e0c153e1e306fd06bf9198c25f32645389.camel@redhat.com> (raw)
In-Reply-To: <20261128-kbug-l080-v1-1-90f7309990ea@illinois.edu>
Hi, thx for the patch.
On Sat, 2026-11-28 at 21:11 -0600, Weidong Wang via B4 Relay wrote:
> From: Weidong Wang <weidongw@illinois.edu>
>
[…]
>
> The fix and this changelog were drafted with AI assistance (Claude Code,
> with a second review by OpenAI Codex), then reviewed by the submitter.
That's evident from the *very* verbose commit message, which I think
should be slimmed down a bit :)
>
> Fixes: f748a07a0b64 ("PCI: Remove legacy pcim_release()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Weidong Wang <weidongw@illinois.edu>
> ---
> The case of a detach while the device is still disabled (failed resume)
> is left out, see the commit message: it would need a pci_is_enabled()
> check in pcim_disable_device(). I can send that as a separate patch if
> the PCI side agrees.
That's not a good idea. This intertwining makes the API inconsistent.
Instead, pcim_disable_device() should not exist / should be deprecated.
See below.
>
> pata_mpiix never enables the device at probe but uses these helpers;
> that older imbalance is not touched here.
>
> Testing:
> - Compile-tested on x86_64 (allmodconfig, W=1):
> drivers/ata/libata-core.o drivers/ata/pata_cs5520.o; no new warnings.
> - checkpatch.pl --strict: no errors or warnings.
> ---
> drivers/ata/libata-core.c | 8 +++++++-
> drivers/ata/pata_cs5520.c | 12 ++++++++----
> 2 files changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index f41ab71fc9e2..587a393d2753 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -6622,7 +6622,13 @@ int ata_pci_device_do_resume(struct pci_dev *pdev)
> pci_set_power_state(pdev, PCI_D0);
> pci_restore_state(pdev);
>
> - rc = pcim_enable_device(pdev);
> + /*
> + * Balance the pci_disable_device() done on suspend. The devres action
> + * registered by pcim_enable_device() at probe time is still in place,
> + * so do not use pcim_enable_device() here or one more disable action
> + * would be added on every resume.
> + */
> + rc = pci_enable_device(pdev);
So will pcim_enable_device() still be called somewhere else?
I have thought about the pcim_ API a while ago, and my opinion by now
is that drivers must either fully use pcim_, never undoing the actions,
or should *only* use the pci_ functions.
IOW, who wants unmanaged behavior should not use the managed functions.
Especially, functions like pcim_disable_device() should not exist IMO.
If you want to disable the device at any other point in time than
driver unbind, then use pci_enable_device() + pci_disable_device().
> if (rc) {
> dev_err(&pdev->dev,
> "failed to enable device after resume (%d)\n", rc);
> diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
> index 3163c8d9cef5..4337db7f9359 100644
> --- a/drivers/ata/pata_cs5520.c
> +++ b/drivers/ata/pata_cs5520.c
ata_pci_device_do_resume() is used in 28 files. Will the parties other
than cs5520 be affected by this change? That seems quite likely.
> @@ -225,11 +225,15 @@ static int cs5520_reinit_one(struct pci_dev *pdev)
> {
> struct ata_host *host = pci_get_drvdata(pdev);
> u8 pcicfg;
> - int rc;
>
> - rc = ata_pci_device_do_resume(pdev);
> - if (rc)
> - return rc;
> + /*
> + * The device was not disabled on suspend, so do not enable it again
> + * as ata_pci_device_do_resume() would: that would leave the enable
> + * count unbalanced.
> + */
> + pci_set_power_state(pdev, PCI_D0);
> + pci_restore_state(pdev);
> + pci_set_master(pdev);
That change looks suspicious. I would expect it to be unnecessary if
all that were changed in ATA were replacing the pcim_ functions with
the pci_ ones.
Regards
P.
prev parent reply other threads:[~2026-11-30 13:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 3:11 Weidong Wang via B4 Relay
2026-11-30 13:00 ` pstanner [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=022e98e0c153e1e306fd06bf9198c25f32645389.camel@redhat.com \
--to=pstanner@redhat.com \
--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=stable@vger.kernel.org \
--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®