On Wed, Oct 09, 2024 at 09:38:07AM -0700, Nicolin Chen wrote:
For an iommu_dev that can unplug (so far only this selftest does so), the viommu->iommu_dev pointer has no guarantee of its life cycle after it is copied from the idev->dev->iommu->iommu_dev.
Track the user count of the iommu_dev. Delay the exit routine if refcount is unbalanced. The refcount inc/dec will be added in the following patch.
Signed-off-by: Nicolin Chen nicolinc@nvidia.com
drivers/iommu/iommufd/selftest.c | 33 ++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index f4be87b49447..a89a865617db 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -508,14 +508,17 @@ static bool mock_domain_capable(struct device *dev, enum iommu_cap cap) static struct iopf_queue *mock_iommu_iopf_queue; -static struct iommu_device mock_iommu_device = { -}; +static struct mock_iommu_device {
- struct iommu_device iommu_dev;
- wait_queue_head_t wait;
Just use a completion instead of a wait_queue, a few more bytes but it is easier to code. This has some subtle issue where the device memory could be freed while a concurrent thread is going to trigger the wait.
Jason