lkml.org 
[lkml]   [2019]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC v1 2/2] vfio/pci: expose only mdev interface if in pci-mdev mode
Date
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
\
 
 \ /
  Last update: 2019-03-04 14:14    [W:0.059 / U:8.568 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site