pci-bridge: avoid linking a single downstream port more than once
PATCH v2 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.
---
V1[1] -> V2:
- Move downstream port check forward
[1] https://lore.kernel.org/qemu-devel/[email protected]
--- hw/pci-bridge/cxl_downstream.c | 5 +++++ hw/pci-bridge/pcie_root_port.c | 5 +++++ hw/pci-bridge/xio3130_downstream.c | 5 +++++ 3 files changed, 15 insertions(+)
hw/pci-bridge/cxl_downstream.c +5 -0
@@ -142,6 +142,11 @@ static void cxl_dsp_realize(PCIDevice *d, Error **errp)MemoryRegion *component_bar = &cregs->component_registers;int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ; + } +pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);
hw/pci-bridge/pcie_root_port.c +5 -0
@@ -67,6 +67,11 @@ static void rp_realize(PCIDevice *d, Error **errp)PCIERootPortClass *rpc =PCIE_ROOT_PORT_GET_CLASS (d);int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ; + } +pci_config_set_interrupt_pin (d->config,1 );if (d->cap_present &QEMU_PCIE_CAP_CXL ) {pci_bridge_initfn (d,TYPE_CXL_BUS );
hw/pci-bridge/xio3130_downstream.c +5 -0
@@ -69,6 +69,11 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp)PCIESlot *s =PCIE_SLOT (d);int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ; + } +pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);
Signature · 1 line
2.37.3
Hi Yao,
Quoted 26 lines · Yao Xingtao via
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]>---
V1[1] -> V2:
- Move downstream port check forward[1] https://lore.kernel.org/qemu-devel/[email protected]
--- hw/pci-bridge/cxl_downstream.c | 5 +++++ hw/pci-bridge/pcie_root_port.c | 5 +++++ hw/pci-bridge/xio3130_downstream.c | 5 +++++ 3 files changed, 15 insertions(+)hw/pci-bridge/cxl_downstream.c +0
-0
hw/pci-bridge/cxl_downstream.c static void cxl_dsp_realize(PCIDevice *d, Error **errp) · line 147
Quoted 6 lines
hw/pci-bridge/cxl_downstream.c +3
-0@@ -142,6 +142,11 @@ static void cxl_dsp_realize(PCIDevice *d, Error **errp)MemoryRegion *component_bar = &cregs->component_registers;int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ;
Could pcie_cap_slot_init() be a good place to check for that?
Otherwise IMHO we should add a helper in "hw/pci/pcie.h" and call it here, not duplicate this code in each model.
Quoted 4 lines
hw/pci-bridge/cxl_downstream.c +2
-0+ } +pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);
Quoted 48 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Wednesday, July 17, 2024 6:18 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v2] pci-bridge: avoid linking a single downstream port more than onceHi Yao,
Quoted 8 lines · Yao Xingtao via
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]>---
V1[1] -> V2:
- Move downstream port check forward[1]
https://lore.kernel.org/qemu-devel/[email protected]
mReview
Quoted 7 lines
--- hw/pci-bridge/cxl_downstream.c | 5 +++++ hw/pci-bridge/pcie_root_port.c | 5 +++++ hw/pci-bridge/xio3130_downstream.c | 5 +++++ 3 files changed, 15 insertions(+)(quoted diff) +0
-0
b/hw/pci-bridge/cxl_downstream.cQuoted 7 lines
index
742da07a015a..af81ddfeec13100644hw/pci-bridge/cxl_downstream.c +0
-0@@ -142,6 +142,11 @@ static void cxl_dsp_realize(PCIDevice *d, Error **errp)MemoryRegion *component_bar = &cregs->component_registers;int rc;
Quoted 8 lines
hw/pci-bridge/cxl_downstream.c static void cxl_dsp_realize(PCIDevice *d, Error **errp) · line 147
Quoted 3 lines
hw/pci-bridge/cxl_downstream.c +3
-0+if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ;Could
pcie_cap_slot_init()be a good place to check for that?Otherwise IMHO we should add a helper in "
hw/pci/pcie.h" and call it here, not duplicate this code in each model.
Yes, thanks for your comment.
I think pcie_cap_init() may be better.
Quoted 5 lines
Quoted 5 lines
hw/pci-bridge/cxl_downstream.c +2
-0+ } +pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);
Quoted 9 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]>
You also need to take ARI into account.
That can look like slot != 0.
Quoted 61 lines
---
V1[1] -> V2:
- Move downstream port check forward[1] https://lore.kernel.org/qemu-devel/[email protected]
--- hw/pci-bridge/cxl_downstream.c | 5 +++++ hw/pci-bridge/pcie_root_port.c | 5 +++++ hw/pci-bridge/xio3130_downstream.c | 5 +++++ 3 files changed, 15 insertions(+)hw/pci-bridge/cxl_downstream.c +5
-0@@ -142,6 +142,11 @@ static void cxl_dsp_realize(PCIDevice *d, Error **errp)MemoryRegion *component_bar = &cregs->component_registers;int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ; + } +pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);hw/pci-bridge/pcie_root_port.c +5
-0@@ -67,6 +67,11 @@ static void rp_realize(PCIDevice *d, Error **errp)PCIERootPortClass *rpc =PCIE_ROOT_PORT_GET_CLASS (d);int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ; + } +pci_config_set_interrupt_pin (d->config,1 );if (d->cap_present &QEMU_PCIE_CAP_CXL ) {pci_bridge_initfn (d,TYPE_CXL_BUS );hw/pci-bridge/xio3130_downstream.c +5
-0@@ -69,6 +69,11 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp)PCIESlot *s =PCIE_SLOT (d);int rc; +if (pcie_find_port_by_pn (pci_get_bus (d), p->port) !=NULL ) { +error_setg (errp,"Can't link port, error %d" , -EBUSY ); +return ; + } +pci_bridge_initfn (d,TYPE_PCIE_BUS );pcie_port_init_reg (d);Signature · 1 line
2.37.3
Quoted 19 lines
-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Wednesday, July 17, 2024 8:04 PM
To: Yao, Xingtao/姚 幸涛 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] pci-bridge: avoid linking a single downstream port more than onceQuoted 7 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.
Quoted 7 lines
Quoted 1 line
Links:
https://lore.kernel.org/qemu-devel/OSZPR01MB6453BC61D2FF4035F18084EF8D
[email protected]Quoted 1 line
Signed-off-by Yao Xingtao <[email protected]>You also need to take ARI into account. That can look like slot != 0.
Sorry, I'm not familiar with the PCIe protocol, could you explain it in detail?