* [PATCH v4] pci-bridge: avoid linking a single downstream port more than once
@ 2024-07-25 9:38 Yao Xingtao via
2024-08-20 3:20 ` Xingtao Yao (Fujitsu) via
2024-09-10 15:16 ` Michael S. Tsirkin
0 siblings, 2 replies; 4+ messages in thread
From: Yao Xingtao via @ 2024-07-25 9:38 UTC (permalink / raw)
To: mst, marcel.apfelbaum; +Cc: qemu-devel, 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/OSZPR01MB6453BC61D2FF4035F18084EF8DDC2@OSZPR01MB6453.jpnprd01.prod.outlook.com
Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
---
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/20240704033834.3362-1-yaoxt.fnst@fujitsu.com
[2] https://lore.kernel.org/qemu-devel/20240717085621.55315-1-yaoxt.fnst@fujitsu.com
[3] https://lore.kernel.org/qemu-devel/20240725032731.13032-1-yaoxt.fnst@fujitsu.com
---
hw/pci/pcie.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 4b2f0805c6e0..1e53be1bc7c5 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -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) {
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH v4] pci-bridge: avoid linking a single downstream port more than once
2024-07-25 9:38 [PATCH v4] pci-bridge: avoid linking a single downstream port more than once Yao Xingtao via
@ 2024-08-20 3:20 ` Xingtao Yao (Fujitsu) via
2024-09-10 15:16 ` Michael S. Tsirkin
1 sibling, 0 replies; 4+ messages in thread
From: Xingtao Yao (Fujitsu) via @ 2024-08-20 3:20 UTC (permalink / raw)
To: Xingtao Yao (Fujitsu), mst@redhat.com, marcel.apfelbaum@gmail.com
Cc: qemu-devel@nongnu.org
ping.
> -----Original Message-----
> From: Yao Xingtao <yaoxt.fnst@fujitsu.com>
> Sent: Thursday, July 25, 2024 5:38 PM
> To: mst@redhat.com; marcel.apfelbaum@gmail.com
> Cc: qemu-devel@nongnu.org; Yao, Xingtao/姚 幸涛 <yaoxt.fnst@fujitsu.com>
> Subject: [PATCH v4] 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.
>
> Links:
> https://lore.kernel.org/qemu-devel/OSZPR01MB6453BC61D2FF4035F18084EF8D
> DC2@OSZPR01MB6453.jpnprd01.prod.outlook.com
> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
>
> ---
> 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/20240704033834.3362-1-yaoxt.fnst@fujitsu.co
> m
> [2]
> https://lore.kernel.org/qemu-devel/20240717085621.55315-1-yaoxt.fnst@fujitsu.c
> om
> [3]
> https://lore.kernel.org/qemu-devel/20240725032731.13032-1-yaoxt.fnst@fujitsu.c
> om
> ---
> hw/pci/pcie.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 4b2f0805c6e0..1e53be1bc7c5 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -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) {
> --
> 2.41.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4] pci-bridge: avoid linking a single downstream port more than once
2024-07-25 9:38 [PATCH v4] pci-bridge: avoid linking a single downstream port more than once Yao Xingtao via
2024-08-20 3:20 ` Xingtao Yao (Fujitsu) via
@ 2024-09-10 15:16 ` Michael S. Tsirkin
2024-09-12 2:41 ` Xingtao Yao (Fujitsu) via
1 sibling, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2024-09-10 15:16 UTC (permalink / raw)
To: Yao Xingtao; +Cc: marcel.apfelbaum, qemu-devel
On Thu, Jul 25, 2024 at 05:38:19AM -0400, Yao Xingtao wrote:
> 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/OSZPR01MB6453BC61D2FF4035F18084EF8DDC2@OSZPR01MB6453.jpnprd01.prod.outlook.com
> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
>
> ---
> 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/20240704033834.3362-1-yaoxt.fnst@fujitsu.com
> [2] https://lore.kernel.org/qemu-devel/20240717085621.55315-1-yaoxt.fnst@fujitsu.com
> [3] https://lore.kernel.org/qemu-devel/20240725032731.13032-1-yaoxt.fnst@fujitsu.com
> ---
> hw/pci/pcie.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 4b2f0805c6e0..1e53be1bc7c5 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -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) {
But can't there be two functions of a multi-function device,
sharing a port?
> --
> 2.41.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v4] pci-bridge: avoid linking a single downstream port more than once
2024-09-10 15:16 ` Michael S. Tsirkin
@ 2024-09-12 2:41 ` Xingtao Yao (Fujitsu) via
0 siblings, 0 replies; 4+ messages in thread
From: Xingtao Yao (Fujitsu) via @ 2024-09-12 2:41 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: marcel.apfelbaum@gmail.com, qemu-devel@nongnu.org
> -----Original Message-----
> From: Michael S. Tsirkin <mst@redhat.com>
> Sent: Tuesday, September 10, 2024 11:17 PM
> To: Yao, Xingtao/姚 幸涛 <yaoxt.fnst@fujitsu.com>
> Cc: marcel.apfelbaum@gmail.com; qemu-devel@nongnu.org
> Subject: Re: [PATCH v4] pci-bridge: avoid linking a single downstream port more
> than once
>
> On Thu, Jul 25, 2024 at 05:38:19AM -0400, Yao Xingtao wrote:
> > 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
> DC2@OSZPR01MB6453.jpnprd01.prod.outlook.com
> > Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
> >
> > ---
> > 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/20240704033834.3362-1-yaoxt.fnst@fujitsu.co
> m
> > [2]
> https://lore.kernel.org/qemu-devel/20240717085621.55315-1-yaoxt.fnst@fujitsu.c
> om
> > [3]
> https://lore.kernel.org/qemu-devel/20240725032731.13032-1-yaoxt.fnst@fujitsu.c
> om
> > ---
> > hw/pci/pcie.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> > index 4b2f0805c6e0..1e53be1bc7c5 100644
> > --- a/hw/pci/pcie.c
> > +++ b/hw/pci/pcie.c
> > @@ -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) {
>
>
> 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?
>
> > --
> > 2.41.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-12 2:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-25 9:38 [PATCH v4] pci-bridge: avoid linking a single downstream port more than once Yao Xingtao via
2024-08-20 3:20 ` Xingtao Yao (Fujitsu) via
2024-09-10 15:16 ` Michael S. Tsirkin
2024-09-12 2:41 ` Xingtao Yao (Fujitsu) via
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.