From: "Liu, Yi L" <yi.l.liu@intel.com>
To: alex.williamson@redhat.com, kwankhede@nvidia.com
Cc: kevin.tian@intel.com, baolu.lu@linux.intel.com, joro@8bytes.org,
jean-philippe.brucker@arm.com, peterx@redhat.com,
linux-kernel@vger.kernel.org, yi.l.liu@intel.com,
yi.y.sun@intel.com, Liu@vger.kernel.org
Subject: [RFC v1 2/2] vfio/pci: expose only mdev interface if in pci-mdev mode
Date: Sun, 3 Mar 2019 20:58:01 +0800 [thread overview]
Message-ID: <1551617881-8520-3-git-send-email-yi.l.liu@intel.com> (raw)
In-Reply-To: <1551617881-8520-1-git-send-email-yi.l.liu@intel.com>
If a pci device is wrapped as a mediated device. Then user should
only passthru it via vfio mdev framework. If not, there would be
conflict during the device access. This patch prevents user from
using legacy vfio-pci passthru interface. vfio-pci driver will only
expose mdev interface when working in pci-mdev mode. Thus could
prevent user from passthru device in legacy manner.
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: Liu, Yi L <yi.l.liu@intel.com>
---
drivers/vfio/pci/vfio_pci.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index d1c3fe6..422a3ff 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -1273,11 +1273,15 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
mutex_init(&vdev->ioeventfds_lock);
INIT_LIST_HEAD(&vdev->ioeventfds_list);
- ret = vfio_add_group_dev(&pdev->dev, &vfio_pci_ops, vdev);
- if (ret) {
- vfio_iommu_group_put(group, &pdev->dev);
- kfree(vdev);
- return ret;
+ if (vfio_pci_mdev_mode) {
+ pci_set_drvdata(pdev, vdev);
+ } else {
+ ret = vfio_add_group_dev(&pdev->dev, &vfio_pci_ops, vdev);
+ if (ret) {
+ vfio_iommu_group_put(group, &pdev->dev);
+ kfree(vdev);
+ return ret;
+ }
}
ret = vfio_pci_reflck_attach(vdev);
@@ -1329,7 +1333,10 @@ static void vfio_pci_remove(struct pci_dev *pdev)
{
struct vfio_pci_device *vdev;
- vdev = vfio_del_group_dev(&pdev->dev);
+ if (vfio_pci_mdev_mode)
+ vdev = pci_get_drvdata(pdev);
+ else
+ vdev = vfio_del_group_dev(&pdev->dev);
if (!vdev)
return;
--
2.7.4
next prev parent reply other threads:[~2019-03-04 13:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-03 12:57 [RFC v1 0/2] vfio/pci: wrap pci device as mdev with vfio-pci driver Liu, Yi L
2019-03-03 12:58 ` [RFC v1 1/2] vfio/pci: register vfio-pci driver to mdev framework Liu, Yi L
2019-03-03 12:58 ` Liu, Yi L [this message]
2019-03-07 20:39 ` [RFC v1 0/2] vfio/pci: wrap pci device as mdev with vfio-pci driver Alex Williamson
2019-03-08 11:33 ` Liu, Yi L
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=1551617881-8520-3-git-send-email-yi.l.liu@intel.com \
--to=yi.l.liu@intel.com \
--cc=Liu@vger.kernel.org \
--cc=alex.williamson@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=jean-philippe.brucker@arm.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=yi.y.sun@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®