Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable IOMMUFD for VM device passthrough #4004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4031,9 +4031,32 @@ def hostdev_define_by_params(self, name, params, bus=None):
"failover_pair_id": params.get("vm_hostdev_failover_pair_id"),
}
)

devs = []
iommufd_id = params.get("vm_hostdev_iommufd")
if iommufd_id:
dev_params["iommufd"] = iommufd_id
if not self.get_by_qid(iommufd_id):
iommufd = self.iommufd_object_define_by_params(iommufd_id)
devs.append(iommufd)

# TODO: Support vfio-ap and vfio-ccw, currently only for pci devices
dev_bus = bus or {"aobject": params.get("pci_bus", "pci.0")}
dev = qdevices.QDevice(driver, dev_params, parent_bus=dev_bus)
for ext_k, ext_v in params.get_dict("vm_hostdev_extra_params").items():
dev.set_param(ext_k, ext_v)
return dev
devs.append(dev)
return devs

def iommufd_object_define_by_params(self, obj_id):
"""
Create iommufd object device by params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before creating an iommufd device, it is better to check that /dev/iommu exists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick response, will do.


The iommufd objects cmdlines:
-object iommufd,id=iommufd0

:param obj_id: The id of the QObject device, e.g. iommufd0
:return: the iommufd QObject device
"""
backend, properties = "iommufd", {"id": obj_id}
return qdevices.QObject(backend, properties)