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

Conversation

fanchen2
Copy link

iommufd-backed VFIO, for example:
-object iommufd,id=iommufd0
-device vfio-pci,host=01:00.0,iommufd=iommufd0
Multiple pcie device can use the same iommufd.

Signed-off-by: Farrah Chen <[email protected]>
Signed-off-by: Xudong Hao <[email protected]>

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.

@@ -4031,9 +4031,25 @@ def hostdev_define_by_params(self, name, params, bus=None):
"failover_pair_id": params.get("vm_hostdev_failover_pair_id"),
}
)
# Use hard code 'iommufd0' here, multiple devices use the same iommufd
Copy link
Contributor

Choose a reason for hiding this comment

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

As you mentioned here, multiple devices can use the same one. How about checking the iommufd as an ID? If the iommufd device exists with the same ID, reuse it; if not, create a new one, cause we should also support using different iommufd devices, what do you think?

@@ -4031,9 +4031,25 @@ def hostdev_define_by_params(self, name, params, bus=None):
"failover_pair_id": params.get("vm_hostdev_failover_pair_id"),
}
)
# Use hard code 'iommufd0' here, multiple devices use the same iommufd
if params.get("iommufd") == "yes":
Copy link
Contributor

Choose a reason for hiding this comment

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

In this code block, all parameters use vm_hostdev prefix, I would suggest align with this.

@@ -4031,9 +4031,25 @@ def hostdev_define_by_params(self, name, params, bus=None):
"failover_pair_id": params.get("vm_hostdev_failover_pair_id"),
}
)
# Use hard code 'iommufd0' here, multiple devices use the same iommufd
if params.get("iommufd") == "yes":
dev_params["iommufd"] = "iommufd0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, the iommufd is only used for VFIO devices, so I have an idea here,

devs = []
...
...
fd_id = params.get("vm_hostdev_iommufd")
if fd_id and not self.get_by_qid(fd_id):
    iommufd = iommufd_object_define_by_params()
    dev_params["iommufd"] = fd_id
    devs.append(iommufd)
...
...
dev = qdevices.QDevice(driver, dev_params, parent_bus=dev_bus)
devs.append(dev)
return devs

If you have any concern, please don't hesitate to raise them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants