From: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
"mgurtovoy@nvidia.com" <mgurtovoy@nvidia.com>,
liulongfang <liulongfang@huawei.com>,
"Zengtao (B)" <prime.zeng@hisilicon.com>,
"Jonathan Cameron" <jonathan.cameron@huawei.com>,
"Wangzhou (B)" <wangzhou1@hisilicon.com>
Subject: RE: [PATCH v3 6/6] hisi_acc_vfio_pci: Add support for VFIO live migration
Date: Wed, 15 Sep 2021 13:28:47 +0000 [thread overview]
Message-ID: <fe5d6659e28244da82b7028b403e11ae@huawei.com> (raw)
In-Reply-To: <20210915130742.GJ4065468@nvidia.com>
> -----Original Message-----
> From: Jason Gunthorpe [mailto:jgg@nvidia.com]
> Sent: 15 September 2021 14:08
> 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;
> mgurtovoy@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: [PATCH v3 6/6] hisi_acc_vfio_pci: Add support for VFIO live
> migration
>
> On Wed, Sep 15, 2021 at 10:50:37AM +0100, Shameer Kolothum wrote:
> > +/*
> > + * HiSilicon ACC VF dev MMIO space contains both the functional register
> > + * space and the migration control register space. We hide the migration
> > + * control space from the Guest. But to successfully complete the live
> > + * migration, we still need access to the functional MMIO space assigned
> > + * to the Guest. To avoid any potential security issues, we need to be
> > + * careful not to access this region while the Guest vCPUs are running.
> > + *
> > + * Hence check the device state before we map the region.
> > + */
>
> The prior patch prevents mapping this area into the guest at all,
> right?
That’s right. It will prevent Guest from mapping this area.
> So why the comment and logic? If the MMIO area isn't mapped then there
> is nothing to do, right?
>
> The only risk is P2P transactions from devices in the same IOMMU
> group, and you might do well to mitigate that by asserting that the
> device is in a singleton IOMMU group?
This was added as an extra protection. I will add the singleton check instead.
> > +static int hisi_acc_vfio_pci_init(struct vfio_pci_core_device *vdev)
> > +{
> > + struct acc_vf_migration *acc_vf_dev;
> > + struct pci_dev *pdev = vdev->pdev;
> > + struct pci_dev *pf_dev, *vf_dev;
> > + struct hisi_qm *pf_qm;
> > + int vf_id, ret;
> > +
> > + pf_dev = pdev->physfn;
> > + vf_dev = pdev;
> > +
> > + pf_qm = pci_get_drvdata(pf_dev);
> > + if (!pf_qm) {
> > + pr_err("HiSi ACC qm driver not loaded\n");
> > + return -EINVAL;
> > + }
>
> Nope, this is locked wrong and has no lifetime management.
Ok. Holding the device_lock() sufficient here?
>
> > + if (pf_qm->ver < QM_HW_V3) {
> > + dev_err(&pdev->dev,
> > + "Migration not supported, hw version: 0x%x\n",
> > + pf_qm->ver);
> > + return -ENODEV;
> > + }
> > +
> > + vf_id = PCI_FUNC(vf_dev->devfn);
> > + acc_vf_dev = kzalloc(sizeof(*acc_vf_dev), GFP_KERNEL);
> > + if (!acc_vf_dev)
> > + return -ENOMEM;
>
> Don't do the memory like this, the entire driver should have a global
> struct, not one that is allocated/freed around open/close_device
>
> struct hisi_acc_vfio_device {
> struct vfio_pci_core_device core_device;
> [put acc_vf_migration here]
> [put required state from mig_ctl here, don't allocate again]
> struct acc_vf_data mig_data; // Don't use wonky pointer maths
> }
>
> Then leave the releae function on the reg ops NULL and consistently
> pass the hisi_acc_vfio_device everywhere instead of
> acc_vf_migration. This way all the functions get all the needed
> information, eg if they want to log or something.
>
> The mlx5 driver that should be posted soon will show how to structure
> most of this well and include several more patches you'll want to be
> using here.
Ok. Thanks for taking a look. I will take a closer look at the mlx5 driver and
rework based on it.
Thanks,
Shameer
next prev parent reply other threads:[~2021-09-15 13:28 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-15 9:50 [PATCH v3 0/6] vfio/hisilicon: add acc live migration driver Shameer Kolothum
2021-09-15 9:50 ` [PATCH v3 1/6] crypto: hisilicon/qm: Move the QM header to include/linux Shameer Kolothum
2021-09-15 12:49 ` Jason Gunthorpe
2021-09-15 9:50 ` [PATCH v3 2/6] crypto: hisilicon/qm: Move few definitions to common header Shameer Kolothum
2021-09-15 9:50 ` [PATCH v3 3/6] hisi_acc_qm: Move PCI device IDs " Shameer Kolothum
2021-09-22 15:11 ` Max Gurtovoy
2021-09-24 8:18 ` Shameerali Kolothum Thodi
2021-09-15 9:50 ` [PATCH v3 4/6] hisi-acc-vfio-pci: add new vfio_pci driver for HiSilicon ACC devices Shameer Kolothum
2021-09-15 12:51 ` Jason Gunthorpe
2021-09-15 13:35 ` Shameerali Kolothum Thodi
2021-09-15 9:50 ` [PATCH v3 5/6] hisi_acc_vfio_pci: Restrict access to VF dev BAR2 migration region Shameer Kolothum
2021-09-15 9:50 ` [PATCH v3 6/6] hisi_acc_vfio_pci: Add support for VFIO live migration Shameer Kolothum
2021-09-15 13:07 ` Jason Gunthorpe
2021-09-15 13:28 ` Shameerali Kolothum Thodi [this message]
2021-09-16 13:58 ` Jason Gunthorpe
2021-09-27 13:46 ` Shameerali Kolothum Thodi
2021-09-27 15:01 ` Jason Gunthorpe
2021-09-27 15:27 ` Shameerali Kolothum Thodi
2021-09-27 16:00 ` Leon Romanovsky
2021-09-27 16:06 ` Jason Gunthorpe
2021-09-27 18:17 ` Leon Romanovsky
2021-09-27 18:22 ` Jason Gunthorpe
2021-09-27 18:30 ` Leon Romanovsky
2021-09-27 18:32 ` Jason Gunthorpe
2021-09-29 3:57 ` [PATCH v3 0/6] vfio/hisilicon: add acc live migration driver Tian, Kevin
2021-09-29 8:34 ` Shameerali Kolothum Thodi
2021-09-29 9:05 ` Tian, Kevin
2021-09-29 9:16 ` Shameerali Kolothum Thodi
2021-09-30 0:42 ` Tian, Kevin
2021-09-30 6:34 ` Shameerali Kolothum Thodi
2021-10-15 5:53 ` Tian, Kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fe5d6659e28244da82b7028b403e11ae@huawei.com \
--to=shameerali.kolothum.thodi@huawei.com \
--cc=alex.williamson@redhat.com \
--cc=jgg@nvidia.com \
--cc=jonathan.cameron@huawei.com \
--cc=kvm@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=mgurtovoy@nvidia.com \
--cc=prime.zeng@hisilicon.com \
--cc=wangzhou1@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.