Skip to contentSkip to conversation

PCIe resets/restore and lack of CRS wait

DISCUSSION Benjamin Herrenschmidt 3 participants 10 messages Mar 22, 2018 PCI

lore
Share & tools
lore
#0 lore raw

Hi Folks !

So while chasing some issues in our EEH error handling, we noticed that the generic code has about a bazillion of "reset" path for devices, most of them seemingly missing a wait for CRS after the reset.

That includes PM based resets or wakeups (can a D3->D0 transition cause CRS to be returned ? Unclear but we should try to be safe), but mostly it includes anything that resets the pcie port (PERST) or the secondary bridge reset (hot resets).

For example take __pci_reset_function_locked(...), it can call pci_parent_bus_reset() which will perform a hot reset but will *not* wait for CRS.

There are a plethora of reset path in there that are similar, it's actually hard to figure out which is what, but they all have in common that they don't wait for CRS with the notable exception of the FLR case.

I'm keen on doing a rather "blanket" fix by adding a CRS wait inside pci_dev_restore(). Would you guys agree ?

Also why does pci_flr_wait() not use vendor/device ID but instead waits on the COMMAND register being all 1's ? It's not clear to me ... VID/DID will give a very specific signature for CRS which is ffff0001 while COMMAND could return all 1's for other reasons (device unplugged for example).

Cheers,
Ben.

#1 lore raw
Quoted 11 lines · Benjamin Herrenschmidt

Hi Folks !

So while chasing some issues in our EEH error handling, we noticed that the generic code has about a bazillion of "reset" path for devices, most of them seemingly missing a wait for CRS after the reset.

That includes PM based resets or wakeups (can a D3->D0 transition cause CRS to be returned ? Unclear but we should try to be safe), but mostly it includes anything that resets the pcie port (PERST) or the secondary bridge reset (hot resets).

Quoted 8 lines

For example take __pci_reset_function_locked(...), it can call pci_parent_bus_reset() which will perform a hot reset but will *not* wait for CRS.

There are a plethora of reset path in there that are similar, it's actually hard to figure out which is what, but they all have in common that they don't wait for CRS with the notable exception of the FLR case.

Bjorn merged my change for 4.17. Kernel should handle these now.

Quoted 10 lines

I'm keen on doing a rather "blanket" fix by adding a CRS wait inside pci_dev_restore(). Would you guys agree ?

Also why does pci_flr_wait() not use vendor/device ID but instead waits on the COMMAND register being all 1's ? It's not clear to me ... VID/DID will give a very specific signature for CRS which is ffff0001 while COMMAND could return all 1's for other reasons (device unplugged for example).

Because if you read vendor id of a virtual function, you get 0xffffffff

Quoted 2 lines

Cheers,
Ben.

#2 lore raw
Quoted 16 lines · On Thu, 2018-03-22 at 00:36 -0400, [email protected] wrote:
Quoted 15 lines · Benjamin Herrenschmidt

Hi Folks !

So while chasing some issues in our EEH error handling, we noticed that the generic code has about a bazillion of "reset" path for devices, most of them seemingly missing a wait for CRS after the reset.

That includes PM based resets or wakeups (can a D3->D0 transition cause CRS to be returned ? Unclear but we should try to be safe), but mostly it includes anything that resets the pcie port (PERST) or the secondary bridge reset (hot resets).

For example take __pci_reset_function_locked(...), it can call pci_parent_bus_reset() which will perform a hot reset but will *not* wait for CRS.

Quoted 6 lines
Quoted 4 lines

There are a plethora of reset path in there that are similar, it's actually hard to figure out which is what, but they all have in common that they don't wait for CRS with the notable exception of the FLR case.

Bjorn merged my change for 4.17. Kernel should handle these now.

Ah nice ! I'll check that out, I was checking 4.16-rc6 !

Quoted 11 lines
Quoted 9 lines

I'm keen on doing a rather "blanket" fix by adding a CRS wait inside pci_dev_restore(). Would you guys agree ?

Also why does pci_flr_wait() not use vendor/device ID but instead waits on the COMMAND register being all 1's ? It's not clear to me ... VID/DID will give a very specific signature for CRS which is ffff0001 while COMMAND could return all 1's for other reasons (device unplugged for example).

Because if you read vendor id of a virtual function, you get 0xffffffff

Ah indeed, I forgot about that...

Thanks !

Cheers,
Ben.

#3 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 11 lines
Quoted 10 lines

I'm keen on doing a rather "blanket" fix by adding a CRS wait inside pci_dev_restore(). Would you guys agree ?

Also why does pci_flr_wait() not use vendor/device ID but instead waits on the COMMAND register being all 1's ? It's not clear to me ... VID/DID will give a very specific signature for CRS which is ffff0001 while COMMAND could return all 1's for other reasons (device unplugged for example).

Quoted 3 lines
Quoted 1 line

Because if you read vendor id of a virtual function, you get 0xffffffff

Ah indeed, I forgot about that...

Actually, that makes me a bit nervous, I wonder if we should limit that "trick" to VFs and otherwise do the right thing. As per PCIe spec 3.1a (I haven't looked at 4.0 yet)

<<
stalled while the device completes its self-initialization. Software that intends to take advantage of
this mechanism must ensure that the first access made to a device following a valid reset condition is
a Configuration Read Request accessing both bytes of the Vendor ID field in the device’s
Configuration Space header. For this case only, the Root Complex, if enabled, will synthesize a
special read-data value for the Vendor ID field to indicate to software that CRS Completion Status
has been returned by the device. For other Configuration Requests, or when CRS Software
Visibility is not enabled, the Root Complex will generally re-issue the Configuration Request until it
completes with a status other than CRS as described in Section 2.3.2.

Quoted 1 line
Quoted 1 line

That tells me that there is no guarantee by spec that we'll get ffff's, instead we might get HW stalls, or other really nasty effects when probing a register other than 0 (VID/DID) for CRS.

Cheers,
Ben.

#4 lore raw
Quoted 38 lines · Benjamin Herrenschmidt
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 11 lines
Quoted 10 lines

I'm keen on doing a rather "blanket" fix by adding a CRS wait inside pci_dev_restore(). Would you guys agree ?

Also why does pci_flr_wait() not use vendor/device ID but instead waits on the COMMAND register being all 1's ? It's not clear to me ... VID/DID will give a very specific signature for CRS which is ffff0001 while COMMAND could return all 1's for other reasons (device unplugged for example).

Quoted 3 lines
Quoted 1 line

Because if you read vendor id of a virtual function, you get 0xffffffff

Ah indeed, I forgot about that...

Actually, that makes me a bit nervous, I wonder if we should limit that "trick" to VFs and otherwise do the right thing. As per PCIe spec 3.1a (I haven't looked at 4.0 yet)

<<
stalled while the device completes its self-initialization. Software that intends to take advantage of
this mechanism must ensure that the first access made to a device following a valid reset condition is
a Configuration Read Request accessing both bytes of the Vendor ID field in the device’s
Configuration Space header. For this case only, the Root Complex, if enabled, will synthesize a
special read-data value for the Vendor ID field to indicate to software that CRS Completion Status
has been returned by the device. For other Configuration Requests, or when CRS Software
Visibility is not enabled, the Root Complex will generally re-issue the Configuration Request until it
completes with a status other than CRS as described in Section 2.3.2.

Quoted 1 line
Quoted 1 line
Quoted 3 lines

That tells me that there is no guarantee by spec that we'll get ffff's, instead we might get HW stalls, or other really nasty effects when probing a register other than 0 (VID/DID) for CRS.

AFAIK, spec also mentions that sw needs to observe 0xffffffff for all other registers other than vendor id during CRS period.

Quoted 3 lines

Cheers,
Ben.

#5 lore raw
Quoted 8 lines · On Thu, 2018-03-22 at 07:25 -0400, [email protected] wrote:
Quoted 5 lines
Quoted 1 line
Quoted 1 line

That tells me that there is no guarantee by spec that we'll get ffff's, instead we might get HW stalls, or other really nasty effects when probing a register other than 0 (VID/DID) for CRS.

AFAIK, spec also mentions that sw needs to observe 0xffffffff for all other registers other than vendor id during CRS period.

This isnt what's in the 3.1a spec at least ... section 2.3.2 explains the specified behaviour which is, for any register other than 0 (VID/DID), to re-issue the request...

Now, it can have a timeout, and thus might be completed as a failed transaction after a while, but it's a sub-optimal way (ie, we'll end up hogging the CPU on loads) and it's not 100% clear that a failed transaction returns as all 1's (it should but ...).

I can make sure it happens the way the code expects on powerpc, I'm not too worried about that, but I think for such a generic function, it would make sense to stick a bit closer to the spec.

Cheers,
Ben.

#6 lore raw
Quoted 7 lines · Benjamin Herrenschmidt
Quoted 6 lines · On Thu, 2018-03-22 at 07:25 -0400, [email protected] wrote:
Quoted 5 lines
Quoted 1 line
Quoted 1 line

That tells me that there is no guarantee by spec that we'll get ffff's, instead we might get HW stalls, or other really nasty effects when probing a register other than 0 (VID/DID) for CRS.

Quoted 7 lines
Quoted 2 lines

AFAIK, spec also mentions that sw needs to observe 0xffffffff for all other registers other than vendor id during CRS period.

This isnt what's in the 3.1a spec at least ... section 2.3.2 explains the specified behaviour which is, for any register other than 0 (VID/DID), to re-issue the request...

I don't have any hard preference on this. Bjorn wanted code to work for systems with and without CRS capability. That was the reason we stayed away from 0xffff0001.

CRS just gives you HW implementation defined retries for non vendor-id register like you mentioned. If device does not reply in this period of polling time, you should get all 1s eventually back.

All 1s is the spec way of saying device doesn't exist for config transactions.

Some HW can poll indefinitely or other HW can return immediately.

If CRS visibility is supported & enabled, polling indefinitely and hogging the CPU wouldn't be the best HW implementation.

Quoted 12 lines

Now, it can have a timeout, and thus might be completed as a failed transaction after a while, but it's a sub-optimal way (ie, we'll end up hogging the CPU on loads) and it's not 100% clear that a failed transaction returns as all 1's (it should but ...).

I can make sure it happens the way the code expects on powerpc, I'm not too worried about that, but I think for such a generic function, it would make sense to stick a bit closer to the spec.
Cheers,
Ben.

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#7 lore raw
Quoted 9 lines · Sinan Kaya
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · On Thu, 2018-03-22 at 07:25 -0400, [email protected] wrote:
Quoted 3 lines

That tells me that there is no guarantee by spec that we'll get ffff's, instead we might get HW stalls, or other really nasty effects when probing a register other than 0 (VID/DID) for CRS.

AFAIK, spec also mentions that sw needs to observe 0xffffffff for all other registers other than vendor id during CRS period.

Quoted 7 lines
Quoted 3 lines

This isnt what's in the 3.1a spec at least ... section 2.3.2 explains the specified behaviour which is, for any register other than 0 (VID/DID), to re-issue the request...

I don't have any hard preference on this. Bjorn wanted code to work for systems with and without CRS capability. That was the reason we stayed away from 0xffff0001.

CRS SV is optional, so the code has to work when it's absent. But we can tell whether it's supported, so if we need to, we can do something different when it's absent.

Quoted 6 lines

CRS just gives you HW implementation defined retries for non vendor-id register like you mentioned. If device does not reply in this period of polling time, you should get all 1s eventually back.

All 1s is the spec way of saying device doesn't exist for config transactions.

I remember implementation notes mentioning all 1's data returns, e.g., PCIe r4.0, sec 2.3.2, but I don't *think* there's actually a spec requirement that CRS or other errors be reported that way. So if there's a way to avoid relying on all 1's data, I think that would be a good thing.

Bjorn

#8 lore raw

Ben,

Quoted 3 lines · Bjorn Helgaas

CRS SV is optional, so the code has to work when it's absent. But we can tell whether it's supported, so if we need to, we can do something different when it's absent.

Let us know if you want to work on this or not. Otherwise, I'll add to the list of things I'm doing.

Sinan

Signature · 3 lines
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
#9 lore raw
Quoted 9 lines · Sinan Kaya

Ben,

Quoted 3 lines · Bjorn Helgaas

CRS SV is optional, so the code has to work when it's absent. But we can tell whether it's supported, so if we need to, we can do something different when it's absent.

Let us know if you want to work on this or not. Otherwise, I'll add to the list of things I'm doing.

On my side (powerpc) I'll make sure we do get ffff's and that our retry timeouts aren't too high. I just need to makes sure we don't end up triggering an EEH failure on the timeout though.

Cheers,
Ben.