mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:17 +00:00
iommufd: Extend attach/detach_hwpt callbacks to support pasid
Same for the two wrappers and their call sites. Suggested-by: Shameer Kolothum Thodi <skolothumtho@nvidia.com> Suggested-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Reviewed-by: Shameer Kolothum <skolothumtho@nvidia.com> Tested-by: Xudong Hao <xudong.hao@intel.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260527054658.1021096-3-zhenzhong.duan@intel.com>
This commit is contained in:
committed by
Michael S. Tsirkin
parent
1179c4dfc0
commit
20fb2f6961
@@ -539,23 +539,24 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, uint32_t viommu_id,
|
||||
}
|
||||
|
||||
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t hwpt_id, Error **errp)
|
||||
{
|
||||
HostIOMMUDeviceIOMMUFDClass *hiodic =
|
||||
HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
|
||||
|
||||
g_assert(hiodic->attach_hwpt);
|
||||
return hiodic->attach_hwpt(hiodi, hwpt_id, errp);
|
||||
}
|
||||
|
||||
bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t pasid, uint32_t hwpt_id,
|
||||
Error **errp)
|
||||
{
|
||||
HostIOMMUDeviceIOMMUFDClass *hiodic =
|
||||
HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
|
||||
|
||||
g_assert(hiodic->attach_hwpt);
|
||||
return hiodic->attach_hwpt(hiodi, pasid, hwpt_id, errp);
|
||||
}
|
||||
|
||||
bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t pasid, Error **errp)
|
||||
{
|
||||
HostIOMMUDeviceIOMMUFDClass *hiodic =
|
||||
HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi);
|
||||
|
||||
g_assert(hiodic->detach_hwpt);
|
||||
return hiodic->detach_hwpt(hiodi, errp);
|
||||
return hiodic->detach_hwpt(hiodi, pasid, errp);
|
||||
}
|
||||
|
||||
static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
|
||||
|
||||
@@ -300,7 +300,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevice *sdev, int sid,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) {
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
|
||||
errp)) {
|
||||
if (s1_hwpt) {
|
||||
iommufd_backend_free_id(hiodi->iommufd, s1_hwpt->hwpt_id);
|
||||
g_free(s1_hwpt);
|
||||
@@ -575,7 +576,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
|
||||
/* Attach a HWPT based on SMMUv3 GBPA.ABORT value */
|
||||
hwpt_id = smmuv3_accel_gbpa_hwpt(s, accel);
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) {
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
|
||||
errp)) {
|
||||
goto free_veventq;
|
||||
}
|
||||
return true;
|
||||
@@ -665,7 +667,8 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus, void *opaque,
|
||||
hiodi = accel_dev->hiodi;
|
||||
accel = accel_dev->s_accel;
|
||||
/* Re-attach the default s2 hwpt id */
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id, NULL)) {
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID,
|
||||
hiodi->hwpt_id, NULL)) {
|
||||
error_report("Unable to attach the default HW pagetable: hiodi devid "
|
||||
"0x%x", hiodi->devid);
|
||||
}
|
||||
@@ -879,7 +882,8 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Error **errp)
|
||||
|
||||
hwpt_id = smmuv3_accel_gbpa_hwpt(s, accel);
|
||||
QLIST_FOREACH(accel_dev, &accel->device_list, next) {
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, hwpt_id,
|
||||
if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi,
|
||||
IOMMU_NO_PASID, hwpt_id,
|
||||
&local_err)) {
|
||||
error_append_hint(&local_err, "Failed to attach GBPA hwpt %u for "
|
||||
"hiodi devid %u", hwpt_id,
|
||||
|
||||
@@ -121,8 +121,9 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
|
||||
}
|
||||
}
|
||||
|
||||
ret = host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp);
|
||||
trace_vtd_device_attach_hwpt(hiodi->devid, vtd_as->pasid, hwpt_id, ret);
|
||||
ret = host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt_id,
|
||||
errp);
|
||||
trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, ret);
|
||||
if (ret) {
|
||||
/* Destroy old fs_hwpt if it's a replacement */
|
||||
vtd_destroy_old_fs_hwpt(hiodi, vtd_as);
|
||||
@@ -141,22 +142,22 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
|
||||
{
|
||||
HostIOMMUDeviceIOMMUFD *hiodi = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
|
||||
IntelIOMMUState *s = vtd_as->iommu_state;
|
||||
uint32_t pasid = vtd_as->pasid;
|
||||
bool ret;
|
||||
|
||||
if (s->dmar_enabled && s->root_scalable) {
|
||||
ret = host_iommu_device_iommufd_detach_hwpt(hiodi, errp);
|
||||
trace_vtd_device_detach_hwpt(hiodi->devid, pasid, ret);
|
||||
ret = host_iommu_device_iommufd_detach_hwpt(hiodi, IOMMU_NO_PASID,
|
||||
errp);
|
||||
trace_vtd_device_detach_hwpt(hiodi->devid, IOMMU_NO_PASID, ret);
|
||||
} else {
|
||||
/*
|
||||
* If DMAR remapping is disabled or guest switches to legacy mode,
|
||||
* we fallback to the default HWPT which contains shadow page table.
|
||||
* So guest DMA could still work.
|
||||
*/
|
||||
ret = host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id,
|
||||
errp);
|
||||
trace_vtd_device_reattach_def_hwpt(hiodi->devid, pasid, hiodi->hwpt_id,
|
||||
ret);
|
||||
ret = host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID,
|
||||
hiodi->hwpt_id, errp);
|
||||
trace_vtd_device_reattach_def_hwpt(hiodi->devid, IOMMU_NO_PASID,
|
||||
hiodi->hwpt_id, ret);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
|
||||
@@ -934,21 +934,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass *klass, const void *data)
|
||||
|
||||
static bool
|
||||
host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t hwpt_id, Error **errp)
|
||||
{
|
||||
VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
|
||||
|
||||
return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID,
|
||||
hwpt_id, errp);
|
||||
}
|
||||
|
||||
static bool
|
||||
host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t pasid, uint32_t hwpt_id,
|
||||
Error **errp)
|
||||
{
|
||||
VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
|
||||
|
||||
return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, errp);
|
||||
return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, pasid, hwpt_id, errp);
|
||||
}
|
||||
|
||||
static bool
|
||||
host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t pasid, Error **errp)
|
||||
{
|
||||
VFIODevice *vbasedev = HOST_IOMMU_DEVICE(hiodi)->agent;
|
||||
|
||||
return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, pasid, errp);
|
||||
}
|
||||
|
||||
static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
|
||||
|
||||
@@ -138,14 +138,16 @@ struct HostIOMMUDeviceIOMMUFDClass {
|
||||
*
|
||||
* @hiodi: host IOMMU device backed by IOMMUFD backend.
|
||||
*
|
||||
* @pasid: target pasid of the device to be attached.
|
||||
*
|
||||
* @hwpt_id: ID of IOMMUFD hardware page table.
|
||||
*
|
||||
* @errp: pass an Error out when attachment fails.
|
||||
*
|
||||
* Returns: true on success, false on failure.
|
||||
*/
|
||||
bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id,
|
||||
Error **errp);
|
||||
bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid,
|
||||
uint32_t hwpt_id, Error **errp);
|
||||
/**
|
||||
* @detach_hwpt: detach host IOMMU device from IOMMUFD hardware page table.
|
||||
* VFIO and VDPA device can have different implementation.
|
||||
@@ -154,15 +156,19 @@ struct HostIOMMUDeviceIOMMUFDClass {
|
||||
*
|
||||
* @hiodi: host IOMMU device backed by IOMMUFD backend.
|
||||
*
|
||||
* @errp: pass an Error out when attachment fails.
|
||||
* @pasid: target pasid of the device to be detached.
|
||||
*
|
||||
* @errp: pass an Error out when detachment fails.
|
||||
*
|
||||
* Returns: true on success, false on failure.
|
||||
*/
|
||||
bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp);
|
||||
bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid,
|
||||
Error **errp);
|
||||
};
|
||||
|
||||
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t hwpt_id, Error **errp);
|
||||
bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t pasid, uint32_t hwpt_id,
|
||||
Error **errp);
|
||||
bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi,
|
||||
uint32_t pasid, Error **errp);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user