From: Benjamin Block <bblock@linux.ibm.com>
To: Farhan Ali <alifm@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
alex.williamson@redhat.com, helgaas@kernel.org, clg@redhat.com,
schnelle@linux.ibm.com, mjrosato@linux.ibm.com
Subject: Re: [PATCH v4 01/10] PCI: Avoid saving error values for config space
Date: Thu, 2 Oct 2025 11:16:13 +0200 [thread overview]
Message-ID: <20251002091613.GD408411@p1gen4-pw042f0m> (raw)
In-Reply-To: <ae5b191d-ffc6-4d40-a44b-d08e04cac6be@linux.ibm.com>
On Wed, Oct 01, 2025 at 10:12:03AM -0700, Farhan Ali wrote:
>
> On 10/1/2025 8:15 AM, Benjamin Block wrote:
> > On Wed, Sep 24, 2025 at 10:16:19AM -0700, Farhan Ali wrote:
> >> @@ -1792,6 +1798,14 @@ static void pci_restore_pcix_state(struct pci_dev *dev)
> >> int pci_save_state(struct pci_dev *dev)
> >> {
> >> int i;
> >> + u32 val;
> >> +
> >> + pci_read_config_dword(dev, PCI_COMMAND, &val);
> >> + if (PCI_POSSIBLE_ERROR(val)) {
> >> + pci_warn(dev, "Device config space inaccessible, will only be partially restored\n");
> >> + return -EIO;
> >
> > Should it set `dev->state_saved` to `false`, to be on the save side?
> > Not sure whether we run a risk of restoring an old, outdated state otherwise.
>
> AFAIU if the state_saved flag was set to true then any state that we
> have saved should be valid and should be okay to be restored from. We
> just want to avoid saving any invalid data.
Hmm, so I dug a bit more, and I see
void pci_restore_state(struct pci_dev *dev) {}
has `dev->state_saved = false` at the end, so I guess if a device is put into
suspend, and then later woken again, the flag gets reset every time.
And then there is also code like this:
static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
{
...
err = pci_enable_device_mem(pdev);
if (err) {
...
} else {
pdev->state_saved = true;
pci_restore_state(pdev);
I don't know..
But I see Alex suggested this before.
> >> + }
> >> +
> >> /* XXX: 100% dword access ok here? */
> >> for (i = 0; i < 16; i++) {
> >> pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]);
> >> @@ -1854,6 +1868,14 @@ static void pci_restore_config_space_range(struct pci_dev *pdev,
> >>
> >> static void pci_restore_config_space(struct pci_dev *pdev)
> >> {
> >> + if (!pdev->state_saved) {
> >> + pci_warn(pdev, "No saved config space, restoring BARs\n");
> >> + pci_restore_bars(pdev);
> >> + pci_write_config_word(pdev, PCI_COMMAND,
> >> + PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
> >
> > Is this really something that ought to be universally enabled? I thought this
> > depends on whether attached resources are IO and/or MEM?
> >
> > int pci_enable_resources(struct pci_dev *dev, int mask)
> > {
> > ...
> > pci_dev_for_each_resource(dev, r, i) {
> > ...
> > if (r->flags & IORESOURCE_IO)
> > cmd |= PCI_COMMAND_IO;
> > if (r->flags & IORESOURCE_MEM)
> > cmd |= PCI_COMMAND_MEMORY;
> > }
> > ...
> > }
> >
> > Also IIRC, especially on s390, we never have IO resources?
> >
> > int zpci_setup_bus_resources(struct zpci_dev *zdev)
> > {
> > ...
> > for (i = 0; i < PCI_STD_NUM_BARS; i++) {
> > ...
> > /* only MMIO is supported */
> > flags = IORESOURCE_MEM;
> > if (zdev->bars[i].val & 8)
> > flags |= IORESOURCE_PREFETCH;
> > if (zdev->bars[i].val & 4)
> > flags |= IORESOURCE_MEM_64;
> > ...
> > }
> > ...
> > }
> >
> > So I guess this would have to have some form of the same logic as in
> > `pci_enable_resources()`, after restoring the BARs.
> >
> > Or am I missing something?
>
> As per my understanding of the spec, setting both I/O Space and Memory
> Space should be safe. The spec also mentions if a function doesn't
> support IO/Memory space access it could hardwire the bit to zero. We
> could add the logic to iterate through all the resources and set the
> bits accordingly, but in this case trying a best effort restoration it
> should be fine?
>
> Also I didn't see any issues testing on s390x with the NVMe, RoCE and
> NETD devices, but I could have missed something.
Well, just taking a coarse look at how some other PCI device drivers use the
Command register (this being non-s390 specific after all); some of them base
decisions on whether either/or these flags are set in config space. Now that
this sets both flags, this might have surprising side-effects.
On the other hand, iterating over the resources might not even be enough
with some device-drivers, since they base their decision on whether to enable
either/or on other knowledge.
So I don't know. Enabling both just in case might be a good compromise.
--
Best Regards, Benjamin Block / Linux on IBM Z Kernel Development
IBM Deutschland Research & Development GmbH / https://www.ibm.com/privacy
Vors. Aufs.-R.: Wolfgang Wendt / Geschäftsführung: David Faller
Sitz der Ges.: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294
next prev parent reply other threads:[~2025-10-02 9:16 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 17:16 [PATCH v4 00/10] Error recovery for vfio-pci devices on s390x Farhan Ali
2025-09-24 17:16 ` [PATCH v4 01/10] PCI: Avoid saving error values for config space Farhan Ali
2025-10-01 15:15 ` Benjamin Block
2025-10-01 17:12 ` Farhan Ali
2025-10-02 9:16 ` Benjamin Block [this message]
2025-10-04 14:54 ` Lukas Wunner
2025-10-06 17:54 ` Farhan Ali
2025-10-06 19:26 ` Lukas Wunner
2025-10-06 21:35 ` Farhan Ali
2025-10-08 13:34 ` Lukas Wunner
2025-10-08 17:56 ` Farhan Ali
2025-10-08 18:14 ` Lukas Wunner
2025-10-08 21:55 ` Farhan Ali
2025-10-09 4:52 ` Lukas Wunner
2025-10-09 17:02 ` Farhan Ali
2025-10-12 6:43 ` Lukas Wunner
2025-10-09 9:12 ` Niklas Schnelle
2025-10-12 6:34 ` Lukas Wunner
2025-10-14 12:07 ` Niklas Schnelle
2025-10-16 21:00 ` Farhan Ali
2025-10-19 14:34 ` Lukas Wunner
2025-10-20 8:59 ` Niklas Schnelle
2025-11-22 10:58 ` Lukas Wunner
2025-09-24 17:16 ` [PATCH v4 02/10] PCI: Add additional checks for flr reset Farhan Ali
2025-09-30 10:03 ` Benjamin Block
2025-09-30 17:04 ` Farhan Ali
2025-10-01 8:33 ` Benjamin Block
2025-10-01 14:37 ` Benjamin Block
2025-09-24 17:16 ` [PATCH v4 03/10] PCI: Allow per function PCI slots Farhan Ali
2025-10-01 14:34 ` Benjamin Block
2025-09-24 17:16 ` [PATCH v4 04/10] s390/pci: Add architecture specific resource/bus address translation Farhan Ali
2025-09-25 10:54 ` Niklas Schnelle
2025-10-01 16:04 ` Benjamin Block
2025-10-01 18:01 ` Farhan Ali
2025-10-02 12:58 ` Niklas Schnelle
2025-10-02 17:00 ` Bjorn Helgaas
2025-10-02 17:16 ` Ilpo Järvinen
2025-10-02 18:14 ` Niklas Schnelle
2025-09-24 17:16 ` [PATCH v4 05/10] s390/pci: Restore IRQ unconditionally for the zPCI device Farhan Ali
2025-09-24 17:16 ` [PATCH v4 06/10] s390/pci: Update the logic for detecting passthrough device Farhan Ali
2025-09-24 17:16 ` [PATCH v4 07/10] s390/pci: Store PCI error information for passthrough devices Farhan Ali
2025-09-25 14:28 ` Niklas Schnelle
2025-09-25 16:29 ` Farhan Ali
2025-09-24 17:16 ` [PATCH v4 08/10] vfio-pci/zdev: Add a device feature for error information Farhan Ali
2025-09-25 8:04 ` kernel test robot
2025-09-24 17:16 ` [PATCH v4 09/10] vfio: Add a reset_done callback for vfio-pci driver Farhan Ali
2025-09-24 17:16 ` [PATCH v4 10/10] vfio: Remove the pcie check for VFIO_PCI_ERR_IRQ_INDEX Farhan Ali
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=20251002091613.GD408411@p1gen4-pw042f0m \
--to=bblock@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=alifm@linux.ibm.com \
--cc=clg@redhat.com \
--cc=helgaas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=schnelle@linux.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox