Re: [PATCH v10 vfio 3/7] vfio/pds: register with the pds_core PF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/15/2023 2:05 PM, Shameerali Kolothum Thodi wrote:
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.


-----Original Message-----
From: Brett Creeley [mailto:brett.creeley@xxxxxxx]
Sent: 02 June 2023 23:03
To: kvm@xxxxxxxxxxxxxxx; netdev@xxxxxxxxxxxxxxx;
alex.williamson@xxxxxxxxxx; jgg@xxxxxxxxxx; yishaih@xxxxxxxxxx;
Shameerali Kolothum Thodi <shameerali.kolothum.thodi@xxxxxxxxxx>;
kevin.tian@xxxxxxxxx
Cc: brett.creeley@xxxxxxx; shannon.nelson@xxxxxxx
Subject: [PATCH v10 vfio 3/7] vfio/pds: register with the pds_core PF

The pds_core driver will supply adminq services, so find the PF
and register with the DSC services.

Use the following commands to enable a VF:
echo 1 > /sys/bus/pci/drivers/pds_core/$PF_BDF/sriov_numvfs

Signed-off-by: Brett Creeley <brett.creeley@xxxxxxx>
Signed-off-by: Shannon Nelson <shannon.nelson@xxxxxxx>
---
  drivers/vfio/pci/pds/Makefile   |  1 +
  drivers/vfio/pci/pds/cmds.c     | 43
+++++++++++++++++++++++++++++++++
  drivers/vfio/pci/pds/cmds.h     | 10 ++++++++
  drivers/vfio/pci/pds/pci_drv.c  | 19 +++++++++++++++
  drivers/vfio/pci/pds/pci_drv.h  |  9 +++++++
  drivers/vfio/pci/pds/vfio_dev.c | 11 +++++++++
  drivers/vfio/pci/pds/vfio_dev.h |  6 +++++
  include/linux/pds/pds_common.h  |  2 ++
  8 files changed, 101 insertions(+)
  create mode 100644 drivers/vfio/pci/pds/cmds.c
  create mode 100644 drivers/vfio/pci/pds/cmds.h
  create mode 100644 drivers/vfio/pci/pds/pci_drv.h

diff --git a/drivers/vfio/pci/pds/Makefile b/drivers/vfio/pci/pds/Makefile
index e1a55ae0f079..87581111fa17 100644
--- a/drivers/vfio/pci/pds/Makefile
+++ b/drivers/vfio/pci/pds/Makefile
@@ -4,5 +4,6 @@
  obj-$(CONFIG_PDS_VFIO_PCI) += pds_vfio.o

  pds_vfio-y := \
+     cmds.o          \
       pci_drv.o       \
       vfio_dev.o
diff --git a/drivers/vfio/pci/pds/cmds.c b/drivers/vfio/pci/pds/cmds.c
new file mode 100644
index 000000000000..ae01f5df2f5c
--- /dev/null
+++ b/drivers/vfio/pci/pds/cmds.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
+
+#include <linux/io.h>
+#include <linux/types.h>
+
+#include <linux/pds/pds_common.h>
+#include <linux/pds/pds_core_if.h>
+#include <linux/pds/pds_adminq.h>
+
+#include "vfio_dev.h"
+#include "cmds.h"
+
+int pds_vfio_register_client_cmd(struct pds_vfio_pci_device *pds_vfio)
+{
+     struct pci_dev *pdev = pds_vfio_to_pci_dev(pds_vfio);
+     char devname[PDS_DEVNAME_LEN];
+     int ci;
+
+     snprintf(devname, sizeof(devname), "%s.%d-%u", PDS_LM_DEV_NAME,
+              pci_domain_nr(pdev->bus), pds_vfio->pci_id);
+
+     ci = pds_client_register(pci_physfn(pdev), devname);
+     if (ci <= 0)
+             return ci;

So 0 is not a valid id I guess but we return 0 here. But below where
pds_vfio_register_client_cmd() is called, 0 return is treated as success.

Note: Also in drivers..../auxbus.c the comment says the function returns 0
on success!.

Please check.

Thanks,
Shameer

Hey Shameer,

Thanks for catching these issues. It looks like there are a couple things that need to be fixed.

[1] pds_vfio_register_client_cmd() needs to always return negative on error, which includes ci == 0. I don't think we would ever hit this case because drivers..../auxbus.c returns -EIO when ci == 0, but best to fix it in case that ever changes.

[2] Documentation for pds_client_register in drivers..../auxbus.c needs to be updated to say something like the following:

Return: Client ID on succes, or negative for error

I will fix [1] in the next rev of this series. For [2] we will submit a separate follow on patch to clean up the wording.

Thanks for the review,

Brett
+
+     pds_vfio->client_id = ci;
+
+     return 0;
+}
+
+void pds_vfio_unregister_client_cmd(struct pds_vfio_pci_device *pds_vfio)
+{
+     struct pci_dev *pdev = pds_vfio_to_pci_dev(pds_vfio);
+     int err;
+
+     err = pds_client_unregister(pci_physfn(pdev), pds_vfio->client_id);
+     if (err)
+             dev_err(&pdev->dev, "unregister from DSC failed: %pe\n",
+                     ERR_PTR(err));
+
+     pds_vfio->client_id = 0;
+}
diff --git a/drivers/vfio/pci/pds/cmds.h b/drivers/vfio/pci/pds/cmds.h
new file mode 100644
index 000000000000..4c592afccf89
--- /dev/null
+++ b/drivers/vfio/pci/pds/cmds.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
+
+#ifndef _CMDS_H_
+#define _CMDS_H_
+
+int pds_vfio_register_client_cmd(struct pds_vfio_pci_device *pds_vfio);
+void pds_vfio_unregister_client_cmd(struct pds_vfio_pci_device *pds_vfio);
+
+#endif /* _CMDS_H_ */
diff --git a/drivers/vfio/pci/pds/pci_drv.c b/drivers/vfio/pci/pds/pci_drv.c
index 0e84249069d4..a49420aa9736 100644
--- a/drivers/vfio/pci/pds/pci_drv.c
+++ b/drivers/vfio/pci/pds/pci_drv.c
@@ -8,9 +8,13 @@
  #include <linux/types.h>
  #include <linux/vfio.h>

+#include <linux/pds/pds_common.h>
  #include <linux/pds/pds_core_if.h>
+#include <linux/pds/pds_adminq.h>

  #include "vfio_dev.h"
+#include "pci_drv.h"
+#include "cmds.h"

  #define PDS_VFIO_DRV_DESCRIPTION     "AMD/Pensando VFIO Device
Driver"
  #define PCI_VENDOR_ID_PENSANDO               0x1dd8
@@ -27,13 +31,27 @@ static int pds_vfio_pci_probe(struct pci_dev *pdev,
               return PTR_ERR(pds_vfio);

       dev_set_drvdata(&pdev->dev, &pds_vfio->vfio_coredev);
+     pds_vfio->pdsc = pdsc_get_pf_struct(pdev);
+     if (IS_ERR_OR_NULL(pds_vfio->pdsc)) {
+             err = PTR_ERR(pds_vfio->pdsc) ?: -ENODEV;
+             goto out_put_vdev;
+     }

       err = vfio_pci_core_register_device(&pds_vfio->vfio_coredev);
       if (err)
               goto out_put_vdev;

+     err = pds_vfio_register_client_cmd(pds_vfio);
+     if (err) {
+             dev_err(&pdev->dev, "failed to register as client: %pe\n",
+                     ERR_PTR(err));
+             goto out_unregister_coredev;
+     }
+
       return 0;

+out_unregister_coredev:
+     vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev);
  out_put_vdev:
       vfio_put_device(&pds_vfio->vfio_coredev.vdev);
       return err;
@@ -43,6 +61,7 @@ static void pds_vfio_pci_remove(struct pci_dev *pdev)
  {
       struct pds_vfio_pci_device *pds_vfio = pds_vfio_pci_drvdata(pdev);

+     pds_vfio_unregister_client_cmd(pds_vfio);
       vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev);
       vfio_put_device(&pds_vfio->vfio_coredev.vdev);
  }
diff --git a/drivers/vfio/pci/pds/pci_drv.h b/drivers/vfio/pci/pds/pci_drv.h
new file mode 100644
index 000000000000..e79bed12ed14
--- /dev/null
+++ b/drivers/vfio/pci/pds/pci_drv.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2023 Advanced Micro Devices, Inc. */
+
+#ifndef _PCI_DRV_H
+#define _PCI_DRV_H
+
+#include <linux/pci.h>
+
+#endif /* _PCI_DRV_H */
diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index 4038dac90a97..39771265b78f 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -6,6 +6,11 @@

  #include "vfio_dev.h"

+struct pci_dev *pds_vfio_to_pci_dev(struct pds_vfio_pci_device *pds_vfio)
+{
+     return pds_vfio->vfio_coredev.pdev;
+}
+
  struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev)
  {
       struct vfio_pci_core_device *core_device =
dev_get_drvdata(&pdev->dev);
@@ -29,6 +34,12 @@ static int pds_vfio_init_device(struct vfio_device
*vdev)
       pds_vfio->vf_id = pci_iov_vf_id(pdev);
       pds_vfio->pci_id = PCI_DEVID(pdev->bus->number, pdev->devfn);

+     dev_dbg(&pdev->dev,
+             "%s: PF %#04x VF %#04x (%d) vf_id %d domain %d
pds_vfio %p\n",
+             __func__, pci_dev_id(pdev->physfn), pds_vfio->pci_id,
+             pds_vfio->pci_id, pds_vfio->vf_id, pci_domain_nr(pdev->bus),
+             pds_vfio);
+
       return 0;
  }

diff --git a/drivers/vfio/pci/pds/vfio_dev.h b/drivers/vfio/pci/pds/vfio_dev.h
index 66cfcab5b5bf..92e8ff241ca8 100644
--- a/drivers/vfio/pci/pds/vfio_dev.h
+++ b/drivers/vfio/pci/pds/vfio_dev.h
@@ -7,14 +7,20 @@
  #include <linux/pci.h>
  #include <linux/vfio_pci_core.h>

+struct pdsc;
+
  struct pds_vfio_pci_device {
       struct vfio_pci_core_device vfio_coredev;
+     struct pdsc *pdsc;

       int vf_id;
       int pci_id;
+     u16 client_id;
  };

  const struct vfio_device_ops *pds_vfio_ops_info(void);
  struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev);

+struct pci_dev *pds_vfio_to_pci_dev(struct pds_vfio_pci_device *pds_vfio);
+
  #endif /* _VFIO_DEV_H_ */
diff --git a/include/linux/pds/pds_common.h
b/include/linux/pds/pds_common.h
index 060331486d50..721453bdf975 100644
--- a/include/linux/pds/pds_common.h
+++ b/include/linux/pds/pds_common.h
@@ -39,6 +39,8 @@ enum pds_core_vif_types {
  #define PDS_DEV_TYPE_RDMA_STR        "RDMA"
  #define PDS_DEV_TYPE_LM_STR  "LM"

+#define PDS_LM_DEV_NAME              PDS_CORE_DRV_NAME "."
PDS_DEV_TYPE_LM_STR
+
  #define PDS_CORE_IFNAMSIZ            16

  /**
--
2.17.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux