Re: [PATCH v2 01/17] PCI/DPC: Allocate the DPC save buffer during device setup

From: David Matlack

Date: Fri Dec 04 2026 - 17:53:14 EST


On Fri Dec 4, 2026 at 3:43 AM PST, Lukas Wunner wrote:
> On Fri, Nov 06, 2026 at 12:42:02AM +0000, David Matlack wrote:
>> Allocate the DPC capability's save buffer in pci_dpc_init() rather than
>> in dpc_probe(), and report an allocation failure, which dpc_probe()
>> ignored.
>
> Good catch, could you amend dpc_probe() to handle the allocation failure?

As you pointed out in your follow-up, a failure there only means DPC
Control isn't saved and restored, and the per-capability buffers go away
later in the series anyway. So I'll leave dpc_probe() as is in the next
version.

>> dpc_probe() runs when the portdrv DPC service binds to a port, which is
>> long after the device has been added, and does not happen at all if the
>> service is not enabled. Until then pci_save_dpc_state() silently saves
>> nothing, so a reset in that window loses the DPC Control register.
>
> That shouldn't hurt. I think the expectation is that until the
> DPC port service driver binds, the DPC Extended Capability is in
> power-on reset state and it's not managed by the kernel. So the
> kernel doesn't have to care about restoring it.
>
> Moreover according to PCI Firmware Spec r3.3 table 4-6 bit 7,
> the kernel is not supposed to modify the DPC Extended Capability
> unless it has been granted control by platform firmware.
> It seems this is violated by moving the allocation to pci_dpc_init().

You're right, thanks for catching this. I missed that the existence of
the save buffer was also what kept the kernel from touching DPC Control
when firmware hasn't granted control. With this patch, and through the
rest of the series, pci_restore_dpc_state() writes DPC Control on every
port with a DPC capability.

> So my impression is that this patch isn't needed

Yeah. I'll drop this patch in v3.

My plan is to keep reserving DPC Control in pci_dpc_init() and have
pci_restore_dpc_state() skip the write unless the kernel owns DPC, via a
flag set in dpc_probe() and cleared in dpc_remove(). That keeps today's
behavior of restoring DPC Control only after the DPC service has bound
to the port.

The one difference is that pci_save_state() would read DPC Control on
every port with a DPC capability, since saving reads every reserved
register. My understanding is that a read doesn't count as modifying the
capability, but I could gate the save on the same flag if you'd prefer.