From: Yi Liu <yi.l.liu@intel.com>
To: alex.williamson@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org
Cc: david@gibson.dropbear.id.au, thuth@redhat.com,
farman@linux.ibm.com, mjrosato@linux.ibm.com,
akrowiak@linux.ibm.com, pasic@linux.ibm.com,
jjherne@linux.ibm.com, jasowang@redhat.com, kvm@vger.kernel.org,
jgg@nvidia.com, nicolinc@nvidia.com, eric.auger@redhat.com,
eric.auger.pro@gmail.com, kevin.tian@intel.com,
yi.l.liu@intel.com, chao.p.peng@intel.com, yi.y.sun@intel.com,
peterx@redhat.com, shameerali.kolothum.thodi@huawei.com,
zhangfei.gao@linaro.org, berrange@redhat.com
Subject: [RFC v2 15/15] vfio/as: Allow the selection of a given iommu backend
Date: Wed, 8 Jun 2022 05:31:39 -0700 [thread overview]
Message-ID: <20220608123139.19356-16-yi.l.liu@intel.com> (raw)
In-Reply-To: <20220608123139.19356-1-yi.l.liu@intel.com>
From: Eric Auger <eric.auger@redhat.com>
Now we support two types of iommu backends, let's add the capability
to select one of them. This depends on whether an iommufd object has
been linked with the vfio-pci device:
if the user wants to use the legacy backend, it shall not
link the vfio-pci device with any iommufd object:
-device vfio-pci,host=0000:02:00.0
This is called the legacy mode/backend.
If the user wants to use the iommufd backend (/dev/iommu) it
shall pass an iommufd object id in the vfio-pci device options:
-object iommufd,id=iommufd0
-device vfio-pci,host=0000:02:00.0,iommufd=iommufd0
Note the /dev/iommu device may have been pre-opened by a
management tool such as libvirt. This mode is no more considered
for the legacy backend. So let's remove the "TODO" comment.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Suggested-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/vfio/as.c | 9 ++++++---
hw/vfio/pci.c | 19 ++++++++++++++-----
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/hw/vfio/as.c b/hw/vfio/as.c
index 56485f9299..e799750104 100644
--- a/hw/vfio/as.c
+++ b/hw/vfio/as.c
@@ -1007,6 +1007,8 @@ vfio_get_container_ops(VFIOIOMMUBackendType be)
switch (be) {
case VFIO_IOMMU_BACKEND_TYPE_LEGACY:
return &legacy_container_ops;
+ case VFIO_IOMMU_BACKEND_TYPE_IOMMUFD:
+ return &iommufd_container_ops;
default:
return NULL;
}
@@ -1016,9 +1018,10 @@ int vfio_attach_device(VFIODevice *vbasedev, AddressSpace *as, Error **errp)
{
const VFIOContainerOps *ops;
- ops = vfio_get_container_ops(VFIO_IOMMU_BACKEND_TYPE_LEGACY);
- if (!ops) {
- return -ENOENT;
+ if (vbasedev->iommufd) {
+ ops = vfio_get_container_ops(VFIO_IOMMU_BACKEND_TYPE_IOMMUFD);
+ } else {
+ ops = vfio_get_container_ops(VFIO_IOMMU_BACKEND_TYPE_LEGACY);
}
return ops->attach_device(vbasedev, as, errp);
}
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 6d10e86331..7efd3382ca 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -42,6 +42,7 @@
#include "qapi/error.h"
#include "migration/blocker.h"
#include "migration/qemu-file.h"
+#include "sysemu/iommufd.h"
#define TYPE_VFIO_PCI_NOHOTPLUG "vfio-pci-nohotplug"
@@ -2852,6 +2853,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
int i, ret;
bool is_mdev;
+ if (vbasedev->iommufd) {
+ iommufd_backend_connect(vbasedev->iommufd, errp);
+ if (*errp) {
+ return;
+ }
+ }
+
if (!vbasedev->sysfsdev) {
if (!(~vdev->host.domain || ~vdev->host.bus ||
~vdev->host.slot || ~vdev->host.function)) {
@@ -3134,6 +3142,7 @@ error:
static void vfio_instance_finalize(Object *obj)
{
VFIOPCIDevice *vdev = VFIO_PCI(obj);
+ VFIODevice *vbasedev = &vdev->vbasedev;
vfio_display_finalize(vdev);
vfio_bars_finalize(vdev);
@@ -3146,6 +3155,9 @@ static void vfio_instance_finalize(Object *obj)
*
* g_free(vdev->igd_opregion);
*/
+ if (vbasedev->iommufd) {
+ iommufd_backend_disconnect(vbasedev->iommufd);
+ }
vfio_put_device(vdev);
}
@@ -3281,11 +3293,8 @@ static Property vfio_pci_dev_properties[] = {
qdev_prop_nv_gpudirect_clique, uint8_t),
DEFINE_PROP_OFF_AUTO_PCIBAR("x-msix-relocation", VFIOPCIDevice, msix_relo,
OFF_AUTOPCIBAR_OFF),
- /*
- * TODO - support passed fds... is this necessary?
- * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name),
- * DEFINE_PROP_STRING("vfiogroupfd, VFIOPCIDevice, vfiogroupfd_name),
- */
+ DEFINE_PROP_LINK("iommufd", VFIOPCIDevice, vbasedev.iommufd,
+ TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *),
DEFINE_PROP_END_OF_LIST(),
};
--
2.27.0
prev parent reply other threads:[~2022-06-08 13:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-08 12:31 [RFC v2 00/15] vfio: Adopt iommufd Yi Liu
2022-06-08 12:31 ` [RFC v2 01/15] scripts/update-linux-headers: Add iommufd.h Yi Liu
2022-06-08 12:31 ` [RFC v2 02/15] linux-headers: Import latest vfio.h and iommufd.h Yi Liu
2022-06-08 12:31 ` [RFC v2 03/15] vfio/common: Split common.c into common.c, container.c and as.c Yi Liu
2022-06-08 12:31 ` [RFC v2 04/15] vfio: Add base container Yi Liu
2022-06-08 12:31 ` [RFC v2 05/15] vfio/container: Introduce vfio_[attach/detach]_device Yi Liu
2022-06-08 12:31 ` [RFC v2 06/15] vfio/platform: Use vfio_[attach/detach]_device Yi Liu
2022-06-08 12:31 ` [RFC v2 07/15] vfio/ap: " Yi Liu
2022-06-08 12:31 ` [RFC v2 08/15] vfio/ccw: " Yi Liu
2022-06-08 12:31 ` [RFC v2 09/15] vfio/container-base: Introduce [attach/detach]_device container callbacks Yi Liu
2022-06-08 12:31 ` [RFC v2 10/15] vfio/container-base: Introduce VFIOContainer reset callback Yi Liu
2022-06-08 12:31 ` [RFC v2 11/15] backends/iommufd: Introduce the iommufd object Yi Liu
2022-06-08 12:31 ` [RFC v2 12/15] util/char_dev: Add open_cdev() Yi Liu
2022-06-08 12:31 ` [RFC v2 13/15] vfio/iommufd: Implement the iommufd backend Yi Liu
2022-10-04 6:47 ` Alistair Popple
2022-10-05 9:02 ` Eric Auger
2022-06-08 12:31 ` [RFC v2 14/15] vfio/iommufd: Add IOAS_COPY_DMA support Yi Liu
2022-06-08 12:31 ` Yi Liu [this message]
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=20220608123139.19356-16-yi.l.liu@intel.com \
--to=yi.l.liu@intel.com \
--cc=akrowiak@linux.ibm.com \
--cc=alex.williamson@redhat.com \
--cc=berrange@redhat.com \
--cc=chao.p.peng@intel.com \
--cc=cohuck@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=eric.auger.pro@gmail.com \
--cc=eric.auger@redhat.com \
--cc=farman@linux.ibm.com \
--cc=jasowang@redhat.com \
--cc=jgg@nvidia.com \
--cc=jjherne@linux.ibm.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=nicolinc@nvidia.com \
--cc=pasic@linux.ibm.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=thuth@redhat.com \
--cc=yi.y.sun@intel.com \
--cc=zhangfei.gao@linaro.org \
/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;
as well as URLs for NNTP newsgroup(s).