mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
iommufd: Move igroup allocation to a function
So it can be reused in the next patch which allows binding to noiommu device. Link: https://patch.msgid.link/r/6bc8e5eaee89e1dc5f07d13dff69b9670b55923a.1783360051.git.jacob.pan@linux.microsoft.com Reviewed-by: Samiullah Khawaja <skhawaja@google.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Jacob Pan <jacob.pan@linux.microsoft.com> Fixes: 2c6cf6ab1564 ("iommufd: Allow binding to a noiommu device") Reviewed-by: Pranjal Shrivastava <praan@google.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
parent
17ea9f74bb
commit
cfa8214875
|
|
@ -56,6 +56,30 @@ static bool iommufd_group_try_get(struct iommufd_group *igroup,
|
|||
return kref_get_unless_zero(&igroup->ref);
|
||||
}
|
||||
|
||||
static struct iommufd_group *iommufd_alloc_group(struct iommufd_ctx *ictx,
|
||||
struct iommu_group *group)
|
||||
{
|
||||
struct iommufd_group *new_igroup;
|
||||
|
||||
new_igroup = kzalloc_obj(*new_igroup, GFP_KERNEL);
|
||||
if (!new_igroup)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
kref_init(&new_igroup->ref);
|
||||
mutex_init(&new_igroup->lock);
|
||||
xa_init(&new_igroup->pasid_attach);
|
||||
new_igroup->sw_msi_start = PHYS_ADDR_MAX;
|
||||
/* group reference moves into new_igroup */
|
||||
new_igroup->group = group;
|
||||
|
||||
/*
|
||||
* The ictx is not additionally refcounted here because all objects using
|
||||
* an igroup must put it before their destroy completes.
|
||||
*/
|
||||
new_igroup->ictx = ictx;
|
||||
return new_igroup;
|
||||
}
|
||||
|
||||
/*
|
||||
* iommufd needs to store some more data for each iommu_group, we keep a
|
||||
* parallel xarray indexed by iommu_group id to hold this instead of putting it
|
||||
|
|
@ -87,25 +111,12 @@ static struct iommufd_group *iommufd_get_group(struct iommufd_ctx *ictx,
|
|||
}
|
||||
xa_unlock(&ictx->groups);
|
||||
|
||||
new_igroup = kzalloc_obj(*new_igroup);
|
||||
if (!new_igroup) {
|
||||
new_igroup = iommufd_alloc_group(ictx, group);
|
||||
if (IS_ERR(new_igroup)) {
|
||||
iommu_group_put(group);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
return new_igroup;
|
||||
}
|
||||
|
||||
kref_init(&new_igroup->ref);
|
||||
mutex_init(&new_igroup->lock);
|
||||
xa_init(&new_igroup->pasid_attach);
|
||||
new_igroup->sw_msi_start = PHYS_ADDR_MAX;
|
||||
/* group reference moves into new_igroup */
|
||||
new_igroup->group = group;
|
||||
|
||||
/*
|
||||
* The ictx is not additionally refcounted here becase all objects using
|
||||
* an igroup must put it before their destroy completes.
|
||||
*/
|
||||
new_igroup->ictx = ictx;
|
||||
|
||||
/*
|
||||
* We dropped the lock so igroup is invalid. NULL is a safe and likely
|
||||
* value to assume for the xa_cmpxchg algorithm.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user