PCI: Correct PCIe port type field encoding
PATCH 1/1 PCI: Correct PCIe port type field encoding
set_pcie_port_type() validates PCIe port topology and corrects invalid upstream/downstream port type information in the cached pcie_flags_reg value.
When performing these corrections, the code updates PCI_EXP_FLAGS_TYPE using PCI_EXP_TYPE_UPSTREAM or PCI_EXP_TYPE_DOWNSTREAM directly. The PCI_EXP_TYPE_* values are decoded port type numbers, not values encoded for the PCI_EXP_FLAGS_TYPE bitfield, so the corrected type is stored in the wrong bit position.
As a result, a device whose type has been corrected may subsequently be reported as PCI_EXP_TYPE_ENDPOINT instead of the intended upstream or downstream port type.
Use FIELD_MODIFY() to update PCI_EXP_FLAGS_TYPE so the corrected port type is encoded consistently with the format used in the PCI Express Capabilities Register.
--- drivers/pci/probe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/probe.c +4 -4
@@ -1673,8 +1673,8 @@ void set_pcie_port_type(struct pci_dev *pdev)*/ if (pcie_downstream_port (parent)) {pci_info (pdev,"claims to be downstream port but is acting as upstream port, correcting type\n" ); - pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE ; - pdev->pcie_flags_reg |=PCI_EXP_TYPE_UPSTREAM ; +FIELD_MODIFY (PCI_EXP_FLAGS_TYPE , &pdev->pcie_flags_reg, +PCI_EXP_TYPE_UPSTREAM ); } }else if (type ==PCI_EXP_TYPE_UPSTREAM ) {/*
@@ -1684,8 +1684,8 @@ void set_pcie_port_type(struct pci_dev *pdev)*/ if (pci_pcie_type (parent) ==PCI_EXP_TYPE_UPSTREAM ) {pci_info (pdev,"claims to be upstream port but is acting as downstream port, correcting type\n" ); - pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE ; - pdev->pcie_flags_reg |=PCI_EXP_TYPE_DOWNSTREAM ; +FIELD_MODIFY (PCI_EXP_FLAGS_TYPE , &pdev->pcie_flags_reg, +PCI_EXP_TYPE_DOWNSTREAM ); } } }
Signature · 1 line
2.54.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 15 lines
set_pcie_port_type()validates PCIe port topology and corrects invalid upstream/downstream port type information in the cachedpcie_flags_regvalue.When performing these corrections, the code updates
PCI_EXP_FLAGS_TYPEusingPCI_EXP_TYPE_UPSTREAMorPCI_EXP_TYPE_DOWNSTREAMdirectly. The PCI_EXP_TYPE_* values are decoded port type numbers, not values encoded for thePCI_EXP_FLAGS_TYPEbitfield, so the corrected type is stored in the wrong bit position.As a result, a device whose type has been corrected may subsequently be reported as
PCI_EXP_TYPE_ENDPOINTinstead of the intended upstream or downstream port type.
Quoted 8 lines
Use
FIELD_MODIFY()to updatePCI_EXP_FLAGS_TYPEso the corrected port type is encoded consistently with the format used in the PCI Express Capabilities Register.Fixes ca78410403dd ("PCI: Get rid of dev->has_secondary_link flag")Reported-by Gowthami Thiagarajan <[email protected]>Signed-off-by Gokulkrishna Sekar <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Bjorn Helgaas
AppliedQuoted 15 lines · Gokulkrishna Sekar
set_pcie_port_type()validates PCIe port topology and corrects invalid upstream/downstream port type information in the cachedpcie_flags_regvalue.When performing these corrections, the code updates
PCI_EXP_FLAGS_TYPEusingPCI_EXP_TYPE_UPSTREAMorPCI_EXP_TYPE_DOWNSTREAMdirectly. The PCI_EXP_TYPE_* values are decoded port type numbers, not values encoded for thePCI_EXP_FLAGS_TYPEbitfield, so the corrected type is stored in the wrong bit position.As a result, a device whose type has been corrected may subsequently be reported as
PCI_EXP_TYPE_ENDPOINTinstead of the intended upstream or downstream port type.
Quoted 8 lines
Use
FIELD_MODIFY()to updatePCI_EXP_FLAGS_TYPEso the corrected port type is encoded consistently with the format used in the PCI Express Capabilities Register.Fixes ca78410403dd ("PCI: Get rid of dev->has_secondary_link flag")Reported-by Gowthami Thiagarajan <[email protected]>Signed-off-by Gokulkrishna Sekar <[email protected]>
Applied to pci/enumeration for v7.5, thank you!
Quoted 33 lines
--- drivers/pci/probe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/pci/probe.c +4
-4@@ -1673,8 +1673,8 @@ void set_pcie_port_type(struct pci_dev *pdev)*/ if (pcie_downstream_port (parent)) {pci_info (pdev,"claims to be downstream port but is acting as upstream port, correcting type\n" ); - pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE ; - pdev->pcie_flags_reg |=PCI_EXP_TYPE_UPSTREAM ; +FIELD_MODIFY (PCI_EXP_FLAGS_TYPE , &pdev->pcie_flags_reg, +PCI_EXP_TYPE_UPSTREAM ); } }else if (type ==PCI_EXP_TYPE_UPSTREAM ) {/* @@ -1684,8 +1684,8 @@ void set_pcie_port_type(struct pci_dev *pdev)*/ if (pci_pcie_type (parent) ==PCI_EXP_TYPE_UPSTREAM ) {pci_info (pdev,"claims to be upstream port but is acting as downstream port, correcting type\n" ); - pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE ; - pdev->pcie_flags_reg |=PCI_EXP_TYPE_DOWNSTREAM ; +FIELD_MODIFY (PCI_EXP_FLAGS_TYPE , &pdev->pcie_flags_reg, +PCI_EXP_TYPE_DOWNSTREAM ); } } }Signature · 1 line
2.54.0