pci-bridge: avoid linking a single downstream port more than once
PATCH v4 1/1 pci-bridge: avoid linking a single downstream port more than once
Since the downstream port is not checked, two slots can be linked to a single port. However, this can prevent the driver from detecting the device properly.
It is necessary to ensure that a downstream port is not linked more than once.
---
V3[3] -> V4:
- make the error message more readable
- fix the downstream port check error
V2[2] -> V3:
- Move this check into pcie_cap_init()
V1[1] -> V2:
- Move downstream port check forward
[1] https://lore.kernel.org/qemu-devel/[email protected]
[2] https://lore.kernel.org/qemu-devel/[email protected]
[3] https://lore.kernel.org/qemu-devel/[email protected]
--- hw/pci/pcie.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/pci/pcie.c +7 -0
@@ -192,6 +192,13 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset,assert (pci_is_express (dev)); +if ((type ==PCI_EXP_TYPE_DOWNSTREAM || type ==PCI_EXP_TYPE_ROOT_PORT ) && +pcie_find_port_by_pn (pci_get_bus (dev), port)) { +error_setg (errp,"The port %d is already in use, please select " +"another port" , port); +return -EBUSY ; + } + pos =pci_add_capability (dev,PCI_CAP_ID_EXP , offset,PCI_EXP_VER2_SIZEOF , errp);if (pos <0 ) {
Signature · 1 line
2.41.0
ping.
Quoted 65 lines
-----Original Message-----
From: Yao Xingtao <[email protected]>
Sent: Thursday, July 25, 2024 5:38 PM
To: [email protected]; [email protected]
Cc: [email protected]; Yao, Xingtao/姚 幸涛 <[email protected]>
Subject: [PATCH v4] pci-bridge: avoid linking a single downstream port more than onceSince the downstream port is not checked, two slots can be linked to a single port. However, this can prevent the driver from detecting the device properly.
It is necessary to ensure that a downstream port is not linked more than once.
Links:
https://lore.kernel.org/qemu-devel/OSZPR01MB6453BC61D2FF4035F18084EF8D
[email protected]Signed-off-by Yao Xingtao <[email protected]>---
V3[3] -> V4:
- make the error message more readable
- fix the downstream port check errorV2[2] -> V3:
- Move this check intopcie_cap_init()V1[1] -> V2:
- Move downstream port check forward[1]
https://lore.kernel.org/qemu-devel/[email protected]
m
[2]
https://lore.kernel.org/qemu-devel/[email protected]
om
[3]
https://lore.kernel.org/qemu-devel/[email protected]
om--- hw/pci/pcie.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/pci/pcie.c +1
-0@@ -192,6 +192,13 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset,assert (pci_is_express (dev)); + if ((type == PCI_EXP_TYPE_DOWNSTREAM || type ==
PCI_EXP_TYPE_ROOT_PORT) &&hw/pci/pcie.c +6
-1+ pcie_find_port_by_pn(pci_get_bus(dev), port)) { +error_setg (errp,"The port %d is already in use, please select " +"another port" , port); +return -EBUSY ; + } + pos =pci_add_capability (dev,PCI_CAP_ID_EXP , offset,PCI_EXP_VER2_SIZEOF , errp);if (pos <0 ) { --2.41.0
Quoted 36 lines · Yao Xingtao
Since the downstream port is not checked, two slots can be linked to a single port. However, this can prevent the driver from detecting the device properly.
It is necessary to ensure that a downstream port is not linked more than once.
Signed-off-by Yao Xingtao <[email protected]>---
V3[3] -> V4:
- make the error message more readable
- fix the downstream port check errorV2[2] -> V3:
- Move this check intopcie_cap_init()V1[1] -> V2:
- Move downstream port check forward[1] https://lore.kernel.org/qemu-devel/[email protected]
[2] https://lore.kernel.org/qemu-devel/[email protected]
[3] https://lore.kernel.org/qemu-devel/[email protected]--- hw/pci/pcie.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/pci/pcie.c +0
-0@@ -192,6 +192,13 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset,assert (pci_is_express (dev));
hw/pci/pcie.c int pcie_cap_init(PCIDevice *dev, uint8_t offset, · line 204
Quoted 10 lines
hw/pci/pcie.c +7
-0+if ((type ==PCI_EXP_TYPE_DOWNSTREAM || type ==PCI_EXP_TYPE_ROOT_PORT ) && +pcie_find_port_by_pn (pci_get_bus (dev), port)) { +error_setg (errp,"The port %d is already in use, please select " +"another port" , port); +return -EBUSY ; + } + pos =pci_add_capability (dev,PCI_CAP_ID_EXP , offset,PCI_EXP_VER2_SIZEOF , errp);if (pos <0 ) {
But can't there be two functions of a multi-function device, sharing a port?
Quoted 2 lines
Signature · 1 line
2.41.0
Quoted 68 lines
-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Tuesday, September 10, 2024 11:17 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v4] pci-bridge: avoid linking a single downstream port more than onceQuoted 8 lines · Yao Xingtao
Since the downstream port is not checked, two slots can be linked to a single port. However, this can prevent the driver from detecting the device properly.
It is necessary to ensure that a downstream port is not linked more than once.
Links:
https://lore.kernel.org/qemu-devel/OSZPR01MB6453BC61D2FF4035F18084EF8D
[email protected]Quoted 7 lines
Signed-off-by Yao Xingtao <[email protected]>---
V3[3] -> V4:
- make the error message more readable
- fix the downstream port check errorQuoted 7 lines
V2[2] -> V3:
- Move this check intopcie_cap_init()V1[1] -> V2:
- Move downstream port check forward[1]
https://lore.kernel.org/qemu-devel/[email protected]
mQuoted 1 line
[2]
https://lore.kernel.org/qemu-devel/[email protected]
omQuoted 1 line
[3]
https://lore.kernel.org/qemu-devel/[email protected]
omhw/pci/pcie.c int pcie_cap_init(PCIDevice *dev, uint8_t offset, · line 195
Quoted 13 lines
--- hw/pci/pcie.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/pci/pcie.c +1
-0@@ -192,6 +192,13 @@ int pcie_cap_init(PCIDevice *dev, uint8_t offset,assert (pci_is_express (dev)); + if ((type == PCI_EXP_TYPE_DOWNSTREAM || type ==
PCI_EXP_TYPE_ROOT_PORT) &&hw/pci/pcie.c int pcie_cap_init(PCIDevice *dev, uint8_t offset, · line 204
Quoted 9 lines
hw/pci/pcie.c +6
-0+ pcie_find_port_by_pn(pci_get_bus(dev), port)) { +error_setg (errp,"The port %d is already in use, please select " +"another port" , port); +return -EBUSY ; + } + pos =pci_add_capability (dev,PCI_CAP_ID_EXP , offset,PCI_EXP_VER2_SIZEOF , errp);if (pos <0 ) {
Quoted 2 lines
But can't there be two functions of a multi-function device, sharing a port?
Good question.
But I am not good at PCIe protocol, can anyone give me some advice when using the mulit-function feature?
Quoted 3 lines
Quoted 3 lines
--
2.41.0