Message ID | 20220208133425.1096-7-shameerali.kolothum.thodi@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vfio/hisilicon: add ACC live migration driver | expand |
On Tue, Feb 08, 2022 at 01:34:23PM +0000, Shameer Kolothum wrote: > +struct hisi_qm *hisi_qm_get_pf_qm(struct pci_dev *pdev) > +{ > + struct hisi_qm *pf_qm; > + struct pci_driver *(*fn)(void) = NULL; > + > + if (!pdev->is_virtfn) > + return NULL; > + > + switch (pdev->device) { > + case PCI_DEVICE_ID_HUAWEI_SEC_VF: > + fn = symbol_get(hisi_sec_get_pf_driver); > + break; > + case PCI_DEVICE_ID_HUAWEI_HPRE_VF: > + fn = symbol_get(hisi_hpre_get_pf_driver); > + break; > + case PCI_DEVICE_ID_HUAWEI_ZIP_VF: > + fn = symbol_get(hisi_zip_get_pf_driver); > + break; > + default: > + return NULL; > + } > + > + if (!fn) > + return NULL; > + > + pf_qm = pci_iov_get_pf_drvdata(pdev, fn()); > + > + if (pdev->device == PCI_DEVICE_ID_HUAWEI_SEC_VF) > + symbol_put(hisi_sec_get_pf_driver); > + else if (pdev->device == PCI_DEVICE_ID_HUAWEI_HPRE_VF) > + symbol_put(hisi_hpre_get_pf_driver); > + else > + symbol_put(hisi_zip_get_pf_driver); > + > + return !IS_ERR(pf_qm) ? pf_qm : NULL; > +} > +EXPORT_SYMBOL_GPL(hisi_qm_get_pf_qm); Why put this in this driver, why not in the vfio driver? And why use symbol_get ? Jason
> -----Original Message----- > From: Jason Gunthorpe [mailto:jgg@nvidia.com] > Sent: 08 February 2022 14:25 > To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com> > Cc: kvm@vger.kernel.org; linux-kernel@vger.kernel.org; > linux-crypto@vger.kernel.org; alex.williamson@redhat.com; > cohuck@redhat.com; mgurtovoy@nvidia.com; yishaih@nvidia.com; Linuxarm > <linuxarm@huawei.com>; liulongfang <liulongfang@huawei.com>; Zengtao (B) > <prime.zeng@hisilicon.com>; Jonathan Cameron > <jonathan.cameron@huawei.com>; Wangzhou (B) <wangzhou1@hisilicon.com> > Subject: Re: [RFC v4 6/8] crypto: hisilicon/qm: Add helper to retrieve the PF > qm data > > On Tue, Feb 08, 2022 at 01:34:23PM +0000, Shameer Kolothum wrote: > > > +struct hisi_qm *hisi_qm_get_pf_qm(struct pci_dev *pdev) > > +{ > > + struct hisi_qm *pf_qm; > > + struct pci_driver *(*fn)(void) = NULL; > > + > > + if (!pdev->is_virtfn) > > + return NULL; > > + > > + switch (pdev->device) { > > + case PCI_DEVICE_ID_HUAWEI_SEC_VF: > > + fn = symbol_get(hisi_sec_get_pf_driver); > > + break; > > + case PCI_DEVICE_ID_HUAWEI_HPRE_VF: > > + fn = symbol_get(hisi_hpre_get_pf_driver); > > + break; > > + case PCI_DEVICE_ID_HUAWEI_ZIP_VF: > > + fn = symbol_get(hisi_zip_get_pf_driver); > > + break; > > + default: > > + return NULL; > > + } > > + > > + if (!fn) > > + return NULL; > > + > > + pf_qm = pci_iov_get_pf_drvdata(pdev, fn()); > > + > > + if (pdev->device == PCI_DEVICE_ID_HUAWEI_SEC_VF) > > + symbol_put(hisi_sec_get_pf_driver); > > + else if (pdev->device == PCI_DEVICE_ID_HUAWEI_HPRE_VF) > > + symbol_put(hisi_hpre_get_pf_driver); > > + else > > + symbol_put(hisi_zip_get_pf_driver); > > + > > + return !IS_ERR(pf_qm) ? pf_qm : NULL; > > +} > > +EXPORT_SYMBOL_GPL(hisi_qm_get_pf_qm); > > Why put this in this driver, why not in the vfio driver? And why use > symbol_get ? QM driver provides a generic common interface for all HiSilicon ACC drivers. So thought of placing it here. And symbol_get/put is used to avoid having dependency of all the ACC drivers being built along with the vfio driver. Is there a better way to retrieve the struct pci_driver * associated with each ACC PF driver? Please let me know. Thanks, Shameer
On Tue, Feb 08, 2022 at 02:49:48PM +0000, Shameerali Kolothum Thodi wrote: > > > +EXPORT_SYMBOL_GPL(hisi_qm_get_pf_qm); > > > > Why put this in this driver, why not in the vfio driver? And why use > > symbol_get ? > > QM driver provides a generic common interface for all HiSilicon ACC > drivers. So thought of placing it here. And symbol_get/put is used > to avoid having dependency of all the ACC drivers being built along > with the vfio driver. Is there a better way to retrieve the struct pci_driver * > associated with each ACC PF driver? Please let me know. No, this is the way, but it seems better to put the function that is only ever called by vfio in VFIO and avoid the symbol get - what is the issue with loading some small modules? Jason
diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c index ba4043447e53..80fb9ef8c571 100644 --- a/drivers/crypto/hisilicon/hpre/hpre_main.c +++ b/drivers/crypto/hisilicon/hpre/hpre_main.c @@ -1189,6 +1189,12 @@ static struct pci_driver hpre_pci_driver = { .driver.pm = &hpre_pm_ops, }; +struct pci_driver *hisi_hpre_get_pf_driver(void) +{ + return &hpre_pci_driver; +} +EXPORT_SYMBOL(hisi_hpre_get_pf_driver); + static void hpre_register_debugfs(void) { if (!debugfs_initialized()) diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c index 8c29f9fba573..b2858a6f925a 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -5999,6 +5999,44 @@ void hisi_qm_put_dfx_access(struct hisi_qm *qm) } EXPORT_SYMBOL_GPL(hisi_qm_put_dfx_access); +struct hisi_qm *hisi_qm_get_pf_qm(struct pci_dev *pdev) +{ + struct hisi_qm *pf_qm; + struct pci_driver *(*fn)(void) = NULL; + + if (!pdev->is_virtfn) + return NULL; + + switch (pdev->device) { + case PCI_DEVICE_ID_HUAWEI_SEC_VF: + fn = symbol_get(hisi_sec_get_pf_driver); + break; + case PCI_DEVICE_ID_HUAWEI_HPRE_VF: + fn = symbol_get(hisi_hpre_get_pf_driver); + break; + case PCI_DEVICE_ID_HUAWEI_ZIP_VF: + fn = symbol_get(hisi_zip_get_pf_driver); + break; + default: + return NULL; + } + + if (!fn) + return NULL; + + pf_qm = pci_iov_get_pf_drvdata(pdev, fn()); + + if (pdev->device == PCI_DEVICE_ID_HUAWEI_SEC_VF) + symbol_put(hisi_sec_get_pf_driver); + else if (pdev->device == PCI_DEVICE_ID_HUAWEI_HPRE_VF) + symbol_put(hisi_hpre_get_pf_driver); + else + symbol_put(hisi_zip_get_pf_driver); + + return !IS_ERR(pf_qm) ? pf_qm : NULL; +} +EXPORT_SYMBOL_GPL(hisi_qm_get_pf_qm); + /** * hisi_qm_pm_init() - Initialize qm runtime PM. * @qm: pointer to accelerator device. diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c index ab806fb481ac..d8fb5c2b3482 100644 --- a/drivers/crypto/hisilicon/sec2/sec_main.c +++ b/drivers/crypto/hisilicon/sec2/sec_main.c @@ -1087,6 +1087,12 @@ static struct pci_driver sec_pci_driver = { .driver.pm = &sec_pm_ops, }; +struct pci_driver *hisi_sec_get_pf_driver(void) +{ + return &sec_pci_driver; +} +EXPORT_SYMBOL(hisi_sec_get_pf_driver); + static void sec_register_debugfs(void) { if (!debugfs_initialized()) diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c index f4a517728385..b6ccc7e8f37e 100644 --- a/drivers/crypto/hisilicon/zip/zip_main.c +++ b/drivers/crypto/hisilicon/zip/zip_main.c @@ -1010,6 +1010,12 @@ static struct pci_driver hisi_zip_pci_driver = { .driver.pm = &hisi_zip_pm_ops, }; +struct pci_driver *hisi_zip_get_pf_driver(void) +{ + return &hisi_zip_pci_driver; +} +EXPORT_SYMBOL(hisi_zip_get_pf_driver); + static void hisi_zip_register_debugfs(void) { if (!debugfs_initialized()) diff --git a/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h index 8befb59c6fb3..6dbc5df2923b 100644 --- a/include/linux/hisi_acc_qm.h +++ b/include/linux/hisi_acc_qm.h @@ -476,4 +476,10 @@ void hisi_qm_pm_init(struct hisi_qm *qm); int hisi_qm_get_dfx_access(struct hisi_qm *qm); void hisi_qm_put_dfx_access(struct hisi_qm *qm); void hisi_qm_regs_dump(struct seq_file *s, struct debugfs_regset32 *regset); + +/* Used by VFIO ACC live migration driver */ +struct hisi_qm *hisi_qm_get_pf_qm(struct pci_dev *pdev); +struct pci_driver *hisi_sec_get_pf_driver(void); +struct pci_driver *hisi_hpre_get_pf_driver(void); +struct pci_driver *hisi_zip_get_pf_driver(void); #endif
Provides a new interface to retrieve the PF QM data associated with a ACC VF dev. This makes use of the pci_iov_get_pf_drvdata() to get PF drvdata safely. Introduces helpers to retrieve the ACC PF dev struct pci_driver pointers as this is an input into the pci_iov_get_pf_drvdata(). Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> --- drivers/crypto/hisilicon/hpre/hpre_main.c | 6 ++++ drivers/crypto/hisilicon/qm.c | 38 +++++++++++++++++++++++ drivers/crypto/hisilicon/sec2/sec_main.c | 6 ++++ drivers/crypto/hisilicon/zip/zip_main.c | 6 ++++ include/linux/hisi_acc_qm.h | 6 ++++ 5 files changed, 62 insertions(+)