Re: [PATCH v20 6/9] PCI: Cache PCI DSN into pci_dev->dsn during probe
From: Lukas Wunner
Date: Wed Sep 09 2026 - 11:27:44 EST
On Wed, Sep 02, 2026 at 08:39:30AM -0500, Terry Bowman wrote:
> Subsequent CXL error-reporting code paths need to log the PCI Device
> Serial Number (DSN) as part of trace events emitted from interrupt or
> panic context. Computing the DSN there via pci_get_dsn() requires PCI
> configuration space reads, which are slow, can fail when the link is
> down or frozen, and may not be safe in some contexts.
>
> Add a u64 dsn field to struct pci_dev and populate it from pci_get_dsn()
> during pci_init_capabilities() at probe time via pci_dsn_init(). Only
> write dev->dsn when the read succeeds. The zero initial value from
> pci_dev allocation already represents 'no DSN available.'
[...]
> Signed-off-by: Terry Bowman <terry.bowman@xxxxxxx>
> Reviewed-by: Dave Jiang <dave.jiang@xxxxxxxxx>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>
> Reviewed-by: Alison Schofield <alison.schofield@xxxxxxxxx>
Reviewed-by: Lukas Wunner <lukas@xxxxxxxxx>
> +++ b/drivers/pci/probe.c
> @@ -2638,6 +2638,22 @@ void pcie_report_downtraining(struct pci_dev *dev)
> __pcie_print_link_status(dev, false);
> }
>
> +/*
> + * Cache the Device Serial Number for use in contexts where config-space reads
> + * are unsafe (interrupt, panic). Process-context callers that need a fresh
> + * value (e.g. hotplug device replacement) call pci_get_dsn() and compare it
> + * against this cached pdev->dsn to detect a changed device. Note pdev->dsn
> + * is 0 for devices without the DSN capability, so such a comparison cannot
> + * distinguish a replacement.
> + */
A value of 0 is not a valid serial number in the first place:
PCIe r7.0 sec 7.9.3.2 defines the Device Serial Number as an EUI-64.
In the corresponding IEEE spec on EUIs on page 11 in section
"Unassigned and NULL EUI values", it says:
"Many applications have found it useful to define a distinct null
identifier, most often indicating the absence of a valid EUI-48 or
EUI-64 value. As an example, a null value might be the power-on state
for an integrated circuit register, until the hardware or firmware
initializes the register with a valid EUI.
[...]
The all-zeros EUI-48 value (00-00-00-00-00-00) and EUI-64 value
(00-00-00-00-00-00-00-00), though assigned to an organization,
have not been and will not be used by that assignee as an EUI.
(They can be considered as assigned to the IEEE Registration Authority.)"
https://standards.ieee.org/content/dam/ieee-standards/standards/web/documents/tutorials/eui.pdf
Thanks,
Lukas